@@ -253,4 +253,84 @@ void main() {
253253 () => expect (colorToHex (color, enableAlpha: false , toUpperCase: false ), string.toLowerCase ()),
254254 ));
255255 });
256+
257+ group ('Test ColorExtension2.toHexString:' , () {
258+ final Map <Color , String > colorsMap = {
259+ const Color (0xffffffff ): 'FFFFFF' ,
260+ const Color (0x00000000 ): '000000' ,
261+ const Color (0xF0F0F0F0 ): 'F0F0F0'
262+ };
263+
264+ colorsMap.forEach ((color, string) {
265+ final String transparency = string.substring (4 );
266+ test (
267+ 'It should convert $color : to ${transparency + string }' ,
268+ () => expect (color.toHexString (), transparency + string),
269+ );
270+ });
271+
272+ colorsMap.forEach ((color, string) {
273+ final String transparency = string.substring (4 );
274+ test (
275+ 'It should convert $color : to #${transparency + string } with hash' ,
276+ () => expect (
277+ color.toHexString (includeHashSign: true ), '#$transparency $string ' ),
278+ );
279+ });
280+
281+ colorsMap.forEach ((color, string) {
282+ final String transparency = string.substring (4 ).toLowerCase ();
283+ test (
284+ 'It should convert $color : to #${transparency + string .toLowerCase ()}, with hash, to lower case' ,
285+ () => expect (
286+ color.toHexString (includeHashSign: true , toUpperCase: false ),
287+ '#$transparency ${string .toLowerCase ()}' ),
288+ );
289+ });
290+
291+ colorsMap.forEach ((color, string) {
292+ final String transparency = string.substring (4 ).toLowerCase ();
293+ test (
294+ 'It should convert $color to ${transparency + string .toLowerCase ()}, with lower case' ,
295+ () => expect (
296+ color.toHexString (toUpperCase: false ),
297+ transparency + string.toLowerCase (),
298+ ),
299+ );
300+ });
301+
302+ colorsMap.forEach ((color, string) => test (
303+ 'It should convert $color : to $string , with alpha disabled' ,
304+ () => expect (
305+ color.toHexString (enableAlpha: false ),
306+ string,
307+ ),
308+ ));
309+
310+ colorsMap.forEach ((color, string) => test (
311+ 'It should convert $color : to #$string , with alpha disabled and hash' ,
312+ () => expect (
313+ color.toHexString (enableAlpha: false , includeHashSign: true ),
314+ '#$string ' ),
315+ ));
316+
317+ colorsMap.forEach ((color, string) => test (
318+ 'It should convert $color : to #${string .toLowerCase ()}, with alpha disabled and hash, to lower case' ,
319+ () => expect (
320+ color.toHexString (
321+ enableAlpha: false ,
322+ includeHashSign: true ,
323+ toUpperCase: false ,
324+ ),
325+ '#$string ' .toLowerCase (),
326+ ),
327+ ));
328+
329+ colorsMap.forEach ((color, string) => test (
330+ 'It should convert $color to ${string .toLowerCase ()}, with alpha disabled, to lower case' ,
331+ () => expect (
332+ color.toHexString (enableAlpha: false , toUpperCase: false ),
333+ string.toLowerCase ()),
334+ ));
335+ });
256336}
0 commit comments