Permalink
Browse files

handle #000000-style colorcodes and add tests

  • Loading branch information...
1 parent c90910d commit 09e8ad8dfa5b9768f92190cc4dee261b03d4cc57 @crazedpsyc crazedpsyc committed Jun 3, 2012
Showing with 4 additions and 0 deletions.
  1. +2 −0 lib/DDG/Goodie/ColorCodes.pm
  2. +2 −0 t/ColorCodes.t
@@ -16,9 +16,11 @@ my %types = ( # hash of keyword => Convert::Color prefix
cmy => 'cmy',
cmyk => 'cmyk',
cmyb => 'cmyb',
+ '#' => 'rgb8',
);
my $typestr = join '|', keys %types;
+$typestr =~ s/([#\^\$\*\+\?])/\\$1/g;
triggers query_raw => qr/^
(?:(.+)\s+(.+)\s+colou?r(?:\s+code)| # handles "rgb red color code", "red rgb color code", etc
View
@@ -15,6 +15,8 @@ ddg_goodie_test(
'hex color code for cyan' => test_zci("Hex: #00ffff, Red: 0, Green: 255, Blue: 255 ~ Hue: 180, Saturation: 1.00, Value: 0.50 ~ Cyan: 1.00, Magenta: 0.00, Yellow: 0.00, Black: 0.00", html => '<div style="background:#00ffff;border:2px solid #999;height:30px;width:30px;margin:5px;margin-right:10px;margin-top:3px;float:left;"></div>Hex: #00ffff, Red: 0, Green: 255, Blue: 255 ~ Hue: 180, Saturation: 1.00, Value: 0.50 ~ Cyan: 1.00, Magenta: 0.00, Yellow: 0.00, Black: 0.00'),
'rgb(173,216,230)' => test_zci("Hex: #add8e6, Red: 173, Green: 216, Blue: 230 ~ Hue: 194, Saturation: 0.53, Value: 0.79 ~ Cyan: 0.25, Magenta: 0.06, Yellow: 0.00, Black: 0.10", html => '<div style="background:#add8e6;border:2px solid #999;height:30px;width:30px;margin:5px;margin-right:10px;margin-top:3px;float:left;"></div>Hex: #add8e6, Red: 173, Green: 216, Blue: 230 ~ Hue: 194, Saturation: 0.53, Value: 0.79 ~ Cyan: 0.25, Magenta: 0.06, Yellow: 0.00, Black: 0.10'),
'hsl 194 0.53 0.79' => test_zci("Hex: #add8e5, Red: 173, Green: 216, Blue: 229 ~ Hue: 194, Saturation: 0.53, Value: 0.79 ~ Cyan: 0.25, Magenta: 0.06, Yellow: 0.00, Black: 0.10", html => '<div style="background:#add8e5;border:2px solid #999;height:30px;width:30px;margin:5px;margin-right:10px;margin-top:3px;float:left;"></div>Hex: #add8e5, Red: 173, Green: 216, Blue: 229 ~ Hue: 194, Saturation: 0.53, Value: 0.79 ~ Cyan: 0.25, Magenta: 0.06, Yellow: 0.00, Black: 0.10'),
+ 'cmyk(0.12, 0, 0, 0)' => test_zci('Hex: #e0ffff, Red: 224, Green: 255, Blue: 255 ~ Hue: 180, Saturation: 1.00, Value: 0.94 ~ Cyan: 0.12, Magenta: 0.00, Yellow: 0.00, Black: 0.00', html => '<div style="background:#e0ffff;border:2px solid #999;height:30px;width:30px;margin:5px;margin-right:10px;margin-top:3px;float:left;"></div>Hex: #e0ffff, Red: 224, Green: 255, Blue: 255 ~ Hue: 180, Saturation: 1.00, Value: 0.94 ~ Cyan: 0.12, Magenta: 0.00, Yellow: 0.00, Black: 0.00'),
+ '#00ff00' => test_zci('Hex: #00ff00, Red: 0, Green: 255, Blue: 0 ~ Hue: 120, Saturation: 1.00, Value: 0.50 ~ Cyan: 1.00, Magenta: 0.00, Yellow: 1.00, Black: 0.00', html => '<div style="background:#00ff00;border:2px solid #999;height:30px;width:30px;margin:5px;margin-right:10px;margin-top:3px;float:left;"></div>Hex: #00ff00, Red: 0, Green: 255, Blue: 0 ~ Hue: 120, Saturation: 1.00, Value: 0.50 ~ Cyan: 1.00, Magenta: 0.00, Yellow: 1.00, Black: 0.00'),
);
done_testing;

0 comments on commit 09e8ad8

Please sign in to comment.