@@ -40,6 +40,7 @@ test "named_colors" {
4040 }
4141
4242 {
43+ // Named colors and their hex color notations.
4344 const test_data = [_ ][2 ][]const u8 {
4445 .{ "aliceblue" , "#f0f8ff" },
4546 .{ "antiquewhite" , "#faebd7" },
@@ -215,6 +216,7 @@ test "named_colors" {
215216 {
216217 const float_types = [_ ]type { f16 , f32 , f64 , f80 , f128 };
217218 inline for (float_types ) | ft | {
219+ // Colors without names.
218220 const test_data = [_ ]Color (ft ){
219221 Color (ft ).init (0.7 , 0.8 , 0.9 , 1.0 ),
220222 Color (ft ).init (1.0 , 0.5 , 0.0 , 1.0 ),
@@ -225,4 +227,336 @@ test "named_colors" {
225227 }
226228 }
227229 }
230+
231+ {
232+ // 8 digits fully opaque hex color notations and their named colors.
233+ const test_data = [_ ][2 ][]const u8 {
234+ .{ "#f0f8ffff" , "aliceblue" },
235+ .{ "#faebd7ff" , "antiquewhite" },
236+ .{ "#00ffffff" , "aqua" },
237+ .{ "#7fffd4ff" , "aquamarine" },
238+ .{ "#f0ffffff" , "azure" },
239+ .{ "#f5f5dcff" , "beige" },
240+ .{ "#ffe4c4ff" , "bisque" },
241+ .{ "#000000ff" , "black" },
242+ .{ "#ffebcdff" , "blanchedalmond" },
243+ .{ "#0000ffff" , "blue" },
244+ .{ "#8a2be2ff" , "blueviolet" },
245+ .{ "#a52a2aff" , "brown" },
246+ .{ "#deb887ff" , "burlywood" },
247+ .{ "#5f9ea0ff" , "cadetblue" },
248+ .{ "#7fff00ff" , "chartreuse" },
249+ .{ "#d2691eff" , "chocolate" },
250+ .{ "#ff7f50ff" , "coral" },
251+ .{ "#6495edff" , "cornflowerblue" },
252+ .{ "#fff8dcff" , "cornsilk" },
253+ .{ "#dc143cff" , "crimson" },
254+ .{ "#00ffffff" , "cyan" },
255+ .{ "#00008bff" , "darkblue" },
256+ .{ "#008b8bff" , "darkcyan" },
257+ .{ "#b8860bff" , "darkgoldenrod" },
258+ .{ "#a9a9a9ff" , "darkgray" },
259+ .{ "#006400ff" , "darkgreen" },
260+ .{ "#a9a9a9ff" , "darkgrey" },
261+ .{ "#bdb76bff" , "darkkhaki" },
262+ .{ "#8b008bff" , "darkmagenta" },
263+ .{ "#556b2fff" , "darkolivegreen" },
264+ .{ "#ff8c00ff" , "darkorange" },
265+ .{ "#9932ccff" , "darkorchid" },
266+ .{ "#8b0000ff" , "darkred" },
267+ .{ "#e9967aff" , "darksalmon" },
268+ .{ "#8fbc8fff" , "darkseagreen" },
269+ .{ "#483d8bff" , "darkslateblue" },
270+ .{ "#2f4f4fff" , "darkslategray" },
271+ .{ "#2f4f4fff" , "darkslategrey" },
272+ .{ "#00ced1ff" , "darkturquoise" },
273+ .{ "#9400d3ff" , "darkviolet" },
274+ .{ "#ff1493ff" , "deeppink" },
275+ .{ "#00bfffff" , "deepskyblue" },
276+ .{ "#696969ff" , "dimgray" },
277+ .{ "#696969ff" , "dimgrey" },
278+ .{ "#1e90ffff" , "dodgerblue" },
279+ .{ "#b22222ff" , "firebrick" },
280+ .{ "#fffaf0ff" , "floralwhite" },
281+ .{ "#228b22ff" , "forestgreen" },
282+ .{ "#ff00ffff" , "fuchsia" },
283+ .{ "#dcdcdcff" , "gainsboro" },
284+ .{ "#f8f8ffff" , "ghostwhite" },
285+ .{ "#ffd700ff" , "gold" },
286+ .{ "#daa520ff" , "goldenrod" },
287+ .{ "#808080ff" , "gray" },
288+ .{ "#008000ff" , "green" },
289+ .{ "#adff2fff" , "greenyellow" },
290+ .{ "#808080ff" , "grey" },
291+ .{ "#f0fff0ff" , "honeydew" },
292+ .{ "#ff69b4ff" , "hotpink" },
293+ .{ "#cd5c5cff" , "indianred" },
294+ .{ "#4b0082ff" , "indigo" },
295+ .{ "#fffff0ff" , "ivory" },
296+ .{ "#f0e68cff" , "khaki" },
297+ .{ "#e6e6faff" , "lavender" },
298+ .{ "#fff0f5ff" , "lavenderblush" },
299+ .{ "#7cfc00ff" , "lawngreen" },
300+ .{ "#fffacdff" , "lemonchiffon" },
301+ .{ "#add8e6ff" , "lightblue" },
302+ .{ "#f08080ff" , "lightcoral" },
303+ .{ "#e0ffffff" , "lightcyan" },
304+ .{ "#fafad2ff" , "lightgoldenrodyellow" },
305+ .{ "#d3d3d3ff" , "lightgray" },
306+ .{ "#90ee90ff" , "lightgreen" },
307+ .{ "#d3d3d3ff" , "lightgrey" },
308+ .{ "#ffb6c1ff" , "lightpink" },
309+ .{ "#ffa07aff" , "lightsalmon" },
310+ .{ "#20b2aaff" , "lightseagreen" },
311+ .{ "#87cefaff" , "lightskyblue" },
312+ .{ "#778899ff" , "lightslategray" },
313+ .{ "#778899ff" , "lightslategrey" },
314+ .{ "#b0c4deff" , "lightsteelblue" },
315+ .{ "#ffffe0ff" , "lightyellow" },
316+ .{ "#00ff00ff" , "lime" },
317+ .{ "#32cd32ff" , "limegreen" },
318+ .{ "#faf0e6ff" , "linen" },
319+ .{ "#ff00ffff" , "magenta" },
320+ .{ "#800000ff" , "maroon" },
321+ .{ "#66cdaaff" , "mediumaquamarine" },
322+ .{ "#0000cdff" , "mediumblue" },
323+ .{ "#ba55d3ff" , "mediumorchid" },
324+ .{ "#9370dbff" , "mediumpurple" },
325+ .{ "#3cb371ff" , "mediumseagreen" },
326+ .{ "#7b68eeff" , "mediumslateblue" },
327+ .{ "#00fa9aff" , "mediumspringgreen" },
328+ .{ "#48d1ccff" , "mediumturquoise" },
329+ .{ "#c71585ff" , "mediumvioletred" },
330+ .{ "#191970ff" , "midnightblue" },
331+ .{ "#f5fffaff" , "mintcream" },
332+ .{ "#ffe4e1ff" , "mistyrose" },
333+ .{ "#ffe4b5ff" , "moccasin" },
334+ .{ "#ffdeadff" , "navajowhite" },
335+ .{ "#000080ff" , "navy" },
336+ .{ "#fdf5e6ff" , "oldlace" },
337+ .{ "#808000ff" , "olive" },
338+ .{ "#6b8e23ff" , "olivedrab" },
339+ .{ "#ffa500ff" , "orange" },
340+ .{ "#ff4500ff" , "orangered" },
341+ .{ "#da70d6ff" , "orchid" },
342+ .{ "#eee8aaff" , "palegoldenrod" },
343+ .{ "#98fb98ff" , "palegreen" },
344+ .{ "#afeeeeff" , "paleturquoise" },
345+ .{ "#db7093ff" , "palevioletred" },
346+ .{ "#ffefd5ff" , "papayawhip" },
347+ .{ "#ffdab9ff" , "peachpuff" },
348+ .{ "#cd853fff" , "peru" },
349+ .{ "#ffc0cbff" , "pink" },
350+ .{ "#dda0ddff" , "plum" },
351+ .{ "#b0e0e6ff" , "powderblue" },
352+ .{ "#800080ff" , "purple" },
353+ .{ "#663399ff" , "rebeccapurple" },
354+ .{ "#ff0000ff" , "red" },
355+ .{ "#bc8f8fff" , "rosybrown" },
356+ .{ "#4169e1ff" , "royalblue" },
357+ .{ "#8b4513ff" , "saddlebrown" },
358+ .{ "#fa8072ff" , "salmon" },
359+ .{ "#f4a460ff" , "sandybrown" },
360+ .{ "#2e8b57ff" , "seagreen" },
361+ .{ "#fff5eeff" , "seashell" },
362+ .{ "#a0522dff" , "sienna" },
363+ .{ "#c0c0c0ff" , "silver" },
364+ .{ "#87ceebff" , "skyblue" },
365+ .{ "#6a5acdff" , "slateblue" },
366+ .{ "#708090ff" , "slategray" },
367+ .{ "#708090ff" , "slategrey" },
368+ .{ "#fffafaff" , "snow" },
369+ .{ "#00ff7fff" , "springgreen" },
370+ .{ "#4682b4ff" , "steelblue" },
371+ .{ "#d2b48cff" , "tan" },
372+ .{ "#008080ff" , "teal" },
373+ .{ "#d8bfd8ff" , "thistle" },
374+ .{ "#ff6347ff" , "tomato" },
375+ .{ "#40e0d0ff" , "turquoise" },
376+ .{ "#ee82eeff" , "violet" },
377+ .{ "#f5deb3ff" , "wheat" },
378+ .{ "#ffffffff" , "white" },
379+ .{ "#f5f5f5ff" , "whitesmoke" },
380+ .{ "#ffff00ff" , "yellow" },
381+ .{ "#9acd32ff" , "yellowgreen" },
382+ };
383+
384+ const float_types = [_ ]type { f32 , f64 };
385+ inline for (float_types ) | ft | {
386+ outer : for (test_data ) | td | {
387+ const c = try Color (ft ).parse (td [0 ]);
388+
389+ for (skip_list ) | nc | {
390+ if (ascii .eqlIgnoreCase (td [1 ], nc )) continue :outer ;
391+ }
392+ for (gray_list ) | nc | {
393+ if (ascii .indexOfIgnoreCase (td [1 ], nc ) != null ) continue :outer ;
394+ }
395+
396+ try testing .expectEqualStrings (td [1 ], c .name ().? );
397+ }
398+ }
399+ }
400+
401+ {
402+ // Hex color notations that are not fully opaque.
403+ const test_data = [_ ][]const u8 {
404+ "#f0f8ff00" ,
405+ "#faebd702" ,
406+ "#00ffff04" ,
407+ "#7fffd406" ,
408+ "#f0ffff08" ,
409+ "#f5f5dc0a" ,
410+ "#ffe4c40c" ,
411+ "#0000000e" ,
412+ "#ffebcd10" ,
413+ "#0000ff12" ,
414+ "#8a2be214" ,
415+ "#a52a2a16" ,
416+ "#deb88718" ,
417+ "#5f9ea01a" ,
418+ "#7fff001c" ,
419+ "#d2691e1e" ,
420+ "#ff7f5020" ,
421+ "#6495ed22" ,
422+ "#fff8dc24" ,
423+ "#dc143c26" ,
424+ "#00ffff28" ,
425+ "#00008b2a" ,
426+ "#008b8b2c" ,
427+ "#b8860b2e" ,
428+ "#a9a9a930" ,
429+ "#00640032" ,
430+ "#a9a9a934" ,
431+ "#bdb76b36" ,
432+ "#8b008b38" ,
433+ "#556b2f3a" ,
434+ "#ff8c003c" ,
435+ "#9932cc3e" ,
436+ "#8b000040" ,
437+ "#e9967a42" ,
438+ "#8fbc8f44" ,
439+ "#483d8b46" ,
440+ "#2f4f4f48" ,
441+ "#2f4f4f4a" ,
442+ "#00ced14c" ,
443+ "#9400d34e" ,
444+ "#ff149350" ,
445+ "#00bfff52" ,
446+ "#69696954" ,
447+ "#69696956" ,
448+ "#1e90ff58" ,
449+ "#b222225a" ,
450+ "#fffaf05c" ,
451+ "#228b225e" ,
452+ "#ff00ff60" ,
453+ "#dcdcdc62" ,
454+ "#f8f8ff64" ,
455+ "#ffd70066" ,
456+ "#daa52068" ,
457+ "#8080806a" ,
458+ "#0080006c" ,
459+ "#adff2f6e" ,
460+ "#80808070" ,
461+ "#f0fff072" ,
462+ "#ff69b474" ,
463+ "#cd5c5c76" ,
464+ "#4b008278" ,
465+ "#fffff07a" ,
466+ "#f0e68c7c" ,
467+ "#e6e6fa7e" ,
468+ "#fff0f580" ,
469+ "#7cfc0082" ,
470+ "#fffacd84" ,
471+ "#add8e686" ,
472+ "#f0808088" ,
473+ "#e0ffff8a" ,
474+ "#fafad28c" ,
475+ "#d3d3d38e" ,
476+ "#90ee9090" ,
477+ "#d3d3d392" ,
478+ "#ffb6c194" ,
479+ "#ffa07a96" ,
480+ "#20b2aa98" ,
481+ "#87cefa9a" ,
482+ "#7788999c" ,
483+ "#7788999e" ,
484+ "#b0c4dea0" ,
485+ "#ffffe0a2" ,
486+ "#00ff00a4" ,
487+ "#32cd32a6" ,
488+ "#faf0e6a8" ,
489+ "#ff00ffaa" ,
490+ "#800000ac" ,
491+ "#66cdaaae" ,
492+ "#0000cdb0" ,
493+ "#ba55d3b2" ,
494+ "#9370dbb4" ,
495+ "#3cb371b6" ,
496+ "#7b68eeb8" ,
497+ "#00fa9aba" ,
498+ "#48d1ccbc" ,
499+ "#c71585be" ,
500+ "#191970c0" ,
501+ "#f5fffac2" ,
502+ "#ffe4e1c4" ,
503+ "#ffe4b5c6" ,
504+ "#ffdeadc8" ,
505+ "#000080ca" ,
506+ "#fdf5e6cc" ,
507+ "#808000ce" ,
508+ "#6b8e23d0" ,
509+ "#ffa500d2" ,
510+ "#ff4500d4" ,
511+ "#da70d6d6" ,
512+ "#eee8aad8" ,
513+ "#98fb98da" ,
514+ "#afeeeedc" ,
515+ "#db7093de" ,
516+ "#ffefd5e0" ,
517+ "#ffdab9e2" ,
518+ "#cd853fe4" ,
519+ "#ffc0cbe6" ,
520+ "#dda0dde8" ,
521+ "#b0e0e6ea" ,
522+ "#800080ec" ,
523+ "#663399ee" ,
524+ "#ff0000f0" ,
525+ "#bc8f8ff2" ,
526+ "#4169e1f4" ,
527+ "#8b4513f6" ,
528+ "#fa8072f8" ,
529+ "#f4a460fa" ,
530+ "#2e8b57fc" ,
531+ "#fff5eefe" ,
532+ "#a0522d00" ,
533+ "#c0c0c002" ,
534+ "#87ceeb04" ,
535+ "#6a5acd06" ,
536+ "#70809008" ,
537+ "#7080900a" ,
538+ "#fffafa0c" ,
539+ "#00ff7f0e" ,
540+ "#4682b410" ,
541+ "#d2b48c12" ,
542+ "#00808014" ,
543+ "#d8bfd816" ,
544+ "#ff634718" ,
545+ "#40e0d01a" ,
546+ "#ee82ee1c" ,
547+ "#f5deb31e" ,
548+ "#ffffff20" ,
549+ "#f5f5f522" ,
550+ "#ffff0024" ,
551+ "#9acd3226" ,
552+ };
553+
554+ const float_types = [_ ]type { f32 , f64 };
555+ inline for (float_types ) | ft | {
556+ for (test_data ) | td | {
557+ const c = try Color (ft ).parse (td );
558+ try testing .expectEqual (null , c .name ());
559+ }
560+ }
561+ }
228562}
0 commit comments