Allow leading '#' for hex colors

master
Ben Moon 2016-07-05 11:49:19 +01:00
parent 942c87147b
commit 67460e170d
2 changed files with 9 additions and 5 deletions

View File

@ -18,7 +18,7 @@ triggers any => 'color', 'colour';
triggers start => 'mix';
my $scolor = 'colou?r';
my $color_re = '\p{XDigit}{6}';
my $color_re = '#?\p{XDigit}{6}';
#############
# Helpers #

View File

@ -68,6 +68,11 @@ sub build_test { test_zci(build_structured_answer(@_)) }
# Test Cases #
################
my $tc_mix_white_black = build_test('mix',
input_colors => ['#000000', '#ffffff'],
result_color => '#7f7f7f',
);
ddg_goodie_test(
[qw( DDG::Goodie::RgbColor )],
# Random colors
@ -76,10 +81,9 @@ ddg_goodie_test(
# Using 'colour'
'random colour' => build_test('random'),
# Mixing colors
'mix 000000 ffffff' => build_test('mix',
input_colors => ['#000000', '#ffffff'],
result_color => '#7f7f7f',
),
'mix 000000 ffffff' => $tc_mix_white_black,
# # With leading '#'
'mix #000000 #ffffff' => $tc_mix_white_black,
# Invalid queries
'color' => undef,
'color ffffff' => undef,