@@ -34,7 +34,7 @@ import {
3434 DEFAULT_OPACITY ,
3535} from '../src/constants' ;
3636
37- import { toRgba } from '../src/utils' ;
37+ import { toRgba , isNormFloatArray } from '../src/utils' ;
3838
3939import {
4040 asyncForEach ,
@@ -1706,6 +1706,36 @@ test('select()', async (t) => {
17061706
17071707/* --------------------------------- Utils ---------------------------------- */
17081708
1709+ test ( 'isNormFloatArray()' , async ( t ) => {
1710+ t . ok (
1711+ ! isNormFloatArray ( [ 255 , 0 , 0 , 255 ] ) ,
1712+ 'should not be a normalized RGBA value'
1713+ ) ;
1714+ t . ok (
1715+ ! isNormFloatArray ( [ 1 , 2 , 3 , 4 ] ) ,
1716+ 'should not be a normalized RGBA value'
1717+ ) ;
1718+
1719+ t . ok ( isNormFloatArray ( [ 0 , 0 , 0 , 0.5 ] ) , 'should be a normalized RGBA value' ) ;
1720+ t . ok (
1721+ isNormFloatArray ( [ 0.5 , 1 , 0.005 , 1 ] ) ,
1722+ 'should be a normalized RGBA value'
1723+ ) ;
1724+
1725+ // Inconclusive
1726+ // [0, 0, 0, 1] could be [0, 0, 0, 1] or [0, 0, 0, 1/255]
1727+ t . ok (
1728+ isNormFloatArray ( [ 0 , 0 , 0 , 1 ] ) ,
1729+ 'should treat inconclusive RGBA value as a normalized RGBA value'
1730+ ) ;
1731+
1732+ // [1, 1, 1, 1] could be [1, 1, 1, 1] or [1/255, 1/255, 1/255, 1/255]
1733+ t . ok (
1734+ isNormFloatArray ( [ 1 , 1 , 1 , 1 ] ) ,
1735+ 'should treat inconclusive RGBA value as a normalized RGBA value'
1736+ ) ;
1737+ } ) ;
1738+
17091739test ( 'toRgba()' , async ( t ) => {
17101740 t . equal ( toRgba ( '#ff0000' ) , [ 255 , 0 , 0 , 255 ] , 'should convert HEX to RGBA' ) ;
17111741
0 commit comments