zeroclickinfo-goodies/t/ColorPicker.t

93 lines
3.1 KiB
Perl
Raw Normal View History

2016-07-08 06:13:08 -07:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
2016-07-22 12:53:58 -07:00
zci answer_type => 'color_picker';
2016-07-08 06:13:08 -07:00
zci is_cached => 1;
# Build a structured answer that should match the response from the
# Perl file.
2016-07-15 12:34:15 -07:00
my $goodie_version = $DDG::GoodieBundle::OpenSourceDuckDuckGo::VERSION // 999;
2016-07-08 06:13:08 -07:00
2016-07-15 12:34:15 -07:00
sub build_structured_answer {
my $color = shift;
2016-07-22 12:53:58 -07:00
my $path = "/share/goodie/color_picker/$goodie_version/";
2016-07-15 12:34:15 -07:00
return 'Color Picker',
2016-07-08 06:13:08 -07:00
structured_answer => {
data => {
2016-07-15 12:34:15 -07:00
color => $color,
saturation_value_path => "${path}saturation_value_gradient.png",
hue_path => "${path}hue_gradient.png"
2016-07-08 06:13:08 -07:00
},
templates => {
2016-07-20 00:03:46 -07:00
group => 'text',
options => {
2016-07-22 12:53:58 -07:00
content => "DDH.color_picker.content"
2016-07-20 00:03:46 -07:00
}
2016-07-08 06:13:08 -07:00
}
};
}
# Use this to build expected results for your tests.
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
2016-07-22 12:53:58 -07:00
[qw( DDG::Goodie::ColorPicker )],
2016-07-15 12:40:22 -07:00
2016-07-15 13:53:36 -07:00
# Testing no color mentioned
2016-07-15 12:40:22 -07:00
'colorpicker' => build_test(undef),
'color picker' => build_test(undef),
'colourpicker' => build_test(undef),
'colour picker' => build_test(undef),
2016-07-15 13:53:36 -07:00
# Testing Hex Color Codes Full
2016-07-15 12:40:22 -07:00
'colorpicker #474747' => build_test('#474747'),
2016-07-15 13:53:36 -07:00
'color picker #474747' => build_test('#474747'),
'colourpicker #474747' => build_test('#474747'),
'colour picker #474747' => build_test('#474747'),
# Testing Hex Color Shorthand
'colorpicker #474' => build_test('#474'),
'color picker #474' => build_test('#474'),
'colourpicker #474' => build_test('#474'),
'colour picker #474' => build_test('#474'),
# Testing RGB
'colorpicker rgb(240,100,141)' => build_test('rgb,240,100,141'),
'color picker rgb(240,100,141)' => build_test('rgb,240,100,141'),
'colourpicker rgb(240,100,141)' => build_test('rgb,240,100,141'),
'colour picker rgb(240,100,141)' => build_test('rgb,240,100,141'),
# Testing HSV
'colorpicker hsv(50,40,30)' => build_test('hsv,50,40,30'),
'color picker hsv(50,40,30)' => build_test('hsv,50,40,30'),
'colourpicker hsv(50,40,30)' => build_test('hsv,50,40,30'),
'colour picker hsv(50,40,30)' => build_test('hsv,50,40,30'),
# Testing CMYK
'colorpicker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
'color picker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
'colourpicker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
'colour picker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
2016-07-15 13:25:32 -07:00
# Queries to ignore.
2016-07-15 12:40:22 -07:00
'hello there colorpicker' => undef,
2016-07-15 13:25:32 -07:00
'hello there colourpicker' => undef,
'hello there colour picker' => undef,
'hello there color picker' => undef,
'testing color picker #e4e4e4' => undef,
'testing colour picker #e4e4e4' => undef,
'testing colourpicker #e4e4e4' => undef,
'testing colorpicker #e4e4e4' => undef,
'color picker download' => undef,
'colour picker download' => undef,
'color picker tutorial' => undef,
'colour picker tutorial' => undef
2016-07-08 06:13:08 -07:00
);
done_testing;