Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
ColourCodes: Fixing handling on RGB with values > 0 (#4480)
Browse files Browse the repository at this point in the history
* ColourCode: Rough failing test for #4479; not correct test-case but at least not ffffff

* Updating test to be bang-on-accurate

* ColourCodes: Fixes #4479
  • Loading branch information
mintsoft authored and moollaza committed Sep 7, 2017
1 parent 0ad6de9 commit 48a1f33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/DDG/Goodie/ColorCodes.pm
Expand Up @@ -70,14 +70,12 @@ handle query_lc => sub {
s/\sto\s(?:$typestr)?//g;

$_ =~ $trigger_and_guard;

$type = lc $+{'type'} if defined $+{'type'} and exists $types{lc $+{'type'}};
$type = $types{lc $+{'type'}} if defined $+{'type'} and exists $types{lc $+{'type'}};

$color = "$+{'r'} $+{'g'} $+{'b'}" if defined $+{'r'} and defined $+{'g'} and defined $+{'b'};
$color = lc $+{'color'} if defined $+{'color'};

$inverse = 1 if defined $+{'inv'};

$color =~ s/,?\s+/,/g;
$color =~ s/([0-9]+,[0-9]+,[0-9]+),([0]?\.[0-9]+)/$alpha = $2; $1/e;

Expand All @@ -92,7 +90,6 @@ handle query_lc => sub {
}

my $col = try { Convert::Color->new("$type:$color") };

return unless $col;

if ($inverse) {
Expand Down
4 changes: 4 additions & 0 deletions t/ColorCodes.t
Expand Up @@ -110,6 +110,10 @@ ddg_goodie_test(
'Hex: #633CB0 ~ RGBA(99, 60, 176, 1) ~ RGB(39%, 24%, 69%) ~ HSL(260, 49%, 46%) ~ CMYB(44%, 66%, 0%, 31%)'."\n".'Complementary: #89B03C'."\n".'Analogous: #9D3CB0, #3C4FB0',
%basic_answer
),
'rgb(217,37,50)' => test_zci(
'Hex: #D92532 ~ RGBA(217, 37, 50, 1) ~ RGB(85%, 15%, 20%) ~ HSL(356, 71%, 50%) ~ CMYB(0%, 83%, 77%, 15%)'."\n".'Complementary: #25D9CD'."\n".'Analogous: #D97325, #D9258B',
%basic_answer
),
# Check the content of the structured answer. Just once.
'hsl 194 0.53 0.79' => test_zci(
'Hex: #ADD8E5 ~ RGBA(173, 216, 229, 1) ~ RGB(68%, 85%, 90%) ~ HSL(194, 53%, 79%) ~ CMYB(25%, 6%, 0%, 10%)'."\n".'Complementary: #E6BBAE'."\n".'Analogous: #AEBDE6, #AEE6D7',
Expand Down

0 comments on commit 48a1f33

Please sign in to comment.