diff --git a/lib/DDG/Goodie/BirthStone.pm b/lib/DDG/Goodie/BirthStone.pm index 84c60a699..67aeb2ebc 100644 --- a/lib/DDG/Goodie/BirthStone.pm +++ b/lib/DDG/Goodie/BirthStone.pm @@ -30,13 +30,17 @@ handle remainder => sub { return unless $month; my $stone = $birthstones{$month}; return unless $stone; - + return $month . " birthstone: $stone", - structured_answer => { - input => [$month], - operation => 'Birthstone', - result => $stone - }; + structured_answer => { + data => { + title => $stone, + subtitle => 'Birthstone for '.$month + }, + templates => { + group => "text", + } + } }; 1; diff --git a/lib/DDG/Goodie/Braille.pm b/lib/DDG/Goodie/Braille.pm index 158f91aad..3930dd16a 100644 --- a/lib/DDG/Goodie/Braille.pm +++ b/lib/DDG/Goodie/Braille.pm @@ -7,7 +7,7 @@ use DDG::Goodie; use Convert::Braille; use utf8; -triggers query_raw => qr/\p{Braille}|braille/i; +triggers query_raw => qr/\p{Braille}|( in| to){1} braille$|^braille:/i; zci is_cached => 1; @@ -16,22 +16,29 @@ my $braille_space = '⠀'; # the braille unicode space (U+2800) handle query_raw => sub { my $query = $_; - $query =~ s/translate to braille |( in)? braille$|^braille //; + $query =~ s/( in| to){1} braille$|^braille:\s?//; return unless $query; - my $result; + my $response; + my $type; if ($query =~ /\p{Braille}/) { - $result = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query)); + $response = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query)); + $type = "Ascii/Unicode"; } else { - $result = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query)); + $response = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query)); + $type = "Braille"; } - return $result . ' (Braille)', + return $response, structured_answer => { - input => [html_enc($query)], - operation => 'Braille translation', - result => html_enc($result), + data => { + title => $response, + subtitle => 'Braille translation: ' . html_enc($query), + }, + templates => { + group => 'text', + }, }; }; diff --git a/lib/DDG/Goodie/CheatSheets.pm b/lib/DDG/Goodie/CheatSheets.pm index b23e127e7..985fde5b6 100644 --- a/lib/DDG/Goodie/CheatSheets.pm +++ b/lib/DDG/Goodie/CheatSheets.pm @@ -45,12 +45,23 @@ sub generate_triggers { my %triggers; # This will contain a lookup from triggers to categories and/or files. my %trigger_lookup; + # This will contain all the ignored phrases and their associated categories. + my %ignore_phrases; while (my ($name, $trigger_setsh) = each %spec_triggers) { + my $ignore_phrases = delete $trigger_setsh->{ignore}; while (my ($trigger_type, $triggersh) = each %$trigger_setsh) { foreach my $trigger (@{$triggersh}) { # Add trigger to global triggers. $triggers{$trigger_type}{$trigger} = 1; + # Handle ignored components - these will be stripped + # from query and not be included in final trigger. + if (defined $ignore_phrases) { + my %new_ignore_phrases = map { $_ => 1 } + (keys %{$ignore_phrases{$trigger} || {}}, + @$ignore_phrases); + $ignore_phrases{$trigger} = \%new_ignore_phrases; + } my %new_triggers = map { $_ => 1} (keys %{$trigger_lookup{$trigger}}); if ($name !~ /cheat_sheet$/) { @@ -65,7 +76,7 @@ sub generate_triggers { while (my ($trigger_type, $triggers) = each %triggers) { triggers $trigger_type => (keys %{$triggers}); } - return %trigger_lookup; + return (\%ignore_phrases, %trigger_lookup); } # Initialize aliases. @@ -100,15 +111,17 @@ sub get_aliases { my $aliases = get_aliases(); -my %trigger_lookup = generate_triggers($aliases); +my ($trigger_ignore, %trigger_lookup) = generate_triggers($aliases); -handle remainder => sub { - my $remainder = shift; +handle remainder_lc => sub { + my @query_parts = split /\s+/o, shift; my $trigger = join(' ', split /\s+/o, lc($req->matched_trigger)); my $lookup = $trigger_lookup{$trigger}; - - my $file = $aliases->{join(' ', split /\s+/o, lc($remainder))} or return; + my $alias = join ' ', exists $trigger_ignore->{$trigger} + ? grep { not exists $trigger_ignore->{$trigger}{$_} } @query_parts + : @query_parts; + my $file = $aliases->{$alias} or return; open my $fh, $file or return; my $json = do { local $/; <$fh> }; my $data = decode_json($json) or return; diff --git a/lib/DDG/Goodie/Combination.pm b/lib/DDG/Goodie/Combination.pm old mode 100644 new mode 100755 index 4999ddd2c..0e248f28c --- a/lib/DDG/Goodie/Combination.pm +++ b/lib/DDG/Goodie/Combination.pm @@ -51,11 +51,14 @@ handle query => sub { my $formatted_result = $style->for_display($result); - return $formatted_result, - structured_answer => { - input => [$style->for_display($n) . " $operation " . $style->for_display($k)], - operation => 'Calculate', - result => $formatted_result, + return $formatted_result, structured_answer => { + data => { + title => $formatted_result, + subtitle => $style->for_display($n) . " $operation " . $style->for_display($k) + }, + templates => { + group => 'text' + } }; }; diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index dd130ebac..f9d088e63 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -8,6 +8,7 @@ with 'DDG::GoodieRole::NumberStyler'; use Math::Round qw/nearest/; use utf8; use YAML::XS 'LoadFile'; +use List::Util qw(any); zci answer_type => 'conversions'; zci is_cached => 1; @@ -16,10 +17,15 @@ use bignum; my @types = LoadFile(share('ratios.yml')); +my %unit_to_plural = (); my @units = (); +my %plural_to_unit = (); foreach my $type (@types) { push(@units, $type->{'unit'}); + push(@units, $type->{'plural'}) unless lc $type->{'unit'} eq lc $type->{'plural'}; push(@units, @{$type->{'aliases'}}); + $unit_to_plural{lc $type->{'unit'}} = $type->{'plural'}; + $plural_to_unit{lc $type->{'plural'}} = $type->{'unit'}; } # build triggers based on available conversion units: @@ -35,32 +41,6 @@ my $question_prefix = qr/(?convert|what (?:is|are|does)|how (?:much|many my $factor_re = join('|', ('a', 'an', number_style_regex())); my $guard = qr/^(?$question_prefix)\s?(?$factor_re*)\s?(?$keys)\s(?in|to|into|(?:in to)|from)?\s?(?$factor_re*)\s?(?:of\s)?(?$keys)[\?]?$/i; -# exceptions for pluralized forms: -my %plural_exceptions = ( - 'stone' => 'stone', - 'foot' => 'feet', - 'inch' => 'inches', - 'pounds per square inch' => 'pounds per square inch', - 'ton of TNT' => 'tons of TNT', - 'metric horsepower' => 'metric horsepower', - 'horsepower' => 'horsepower', - 'electrical horsepower' => 'electrical horsepower', - 'pounds force' => 'pounds force', - '坪' => '坪', - 'km/h' => 'km/h', - 'mph' => 'mph', - 'm/s' => 'm/s', - 'ft/s' => 'ft/s', - 'dram avoirdupois' => 'drams avoirdupois', - 'thousandth of an inch' => 'thousandths of an inch', - 'century' => 'centuries', - 'millennium' => 'millennia', - 'mmHg' => 'mmHg', - 'torr' => 'torr', - 'cubic inch' => 'cubic inches' -); -my %singular_exceptions = reverse %plural_exceptions; - # fix precision and rounding: my $precision = 3; my $nearest = '.' . ('0' x ($precision-1)) . '1'; @@ -132,8 +112,7 @@ handle query_lc => sub { && "" eq $+{'right_num'} && $+{'question'} !~ qr/convert/i && !looks_plural($+{'right_unit'}) - && $+{'connecting_word'} !~ qr/to/i - && $factor1[0] > $factor2[0])) + && $+{'connecting_word'} !~ qr/to/i )) { $factor = $+{'right_num'}; @matches = ($matches[1], $matches[0]); @@ -193,31 +172,31 @@ handle query_lc => sub { }; $factor = $styler->for_display($factor); - return $factor . " $result->{'from_unit'} = $result->{'result'} $result->{'to_unit'}", - structured_answer => { - data => { - raw_input => $styler->for_computation($factor), - raw_answer => $styler->for_computation($result->{'result'}), - left_unit => $result->{'from_unit'}, - right_unit => $result->{'to_unit'}, - markup_input => $styler->with_html($factor), - styled_output => $styler->with_html($result->{'result'}), - physical_quantity => $result->{'type'} - }, - templates => { - group => 'text', - options => { - content => 'DDH.conversions.content' - } - } + return "$factor $result->{'from_unit'} = $result->{'result'} $result->{'to_unit'}", + structured_answer => { + data => { + raw_input => $styler->for_computation($factor), + raw_answer => $styler->for_computation($result->{'result'}), + left_unit => $result->{'from_unit'}, + right_unit => $result->{'to_unit'}, + markup_input => $styler->with_html($factor), + styled_output => $styler->with_html($result->{'result'}), + physical_quantity => $result->{'type'} + }, + templates => { + group => 'text', + options => { + content => 'DDH.conversions.content' + } + } }; }; sub looks_plural { - my ($unit) = @_; - my @unit_letters = split //, $unit; - return exists $singular_exceptions{$unit} || $unit_letters[-1] eq 's'; + my ($input) = @_; + return defined $plural_to_unit{lc $input}; } + sub convert_temperatures { my ($from, $to, $in_temperature) = @_; @@ -243,11 +222,10 @@ sub convert_temperatures { } sub get_matches { my @input_matches = @_; - my @output_matches = (); foreach my $match (@input_matches) { foreach my $type (@types) { - if (lc $match eq $type->{'unit'} || grep { $_ eq lc $match } @{$type->{'aliases'}}) { + if (lc $match eq $type->{'unit'} || lc $match eq lc $type->{'plural'} || grep { $_ eq lc $match } @{$type->{'aliases'}}) { push(@output_matches,{ type => $type->{'type'}, factor => $type->{'factor'}, @@ -266,6 +244,7 @@ sub convert { my @matches = get_matches($conversion->{'from_unit'}, $conversion->{'to_unit'}); return if $conversion->{'factor'} < 0 && !($matches[0]->{'can_be_negative'}); + # matches must be of the same type (e.g., can't convert mass to length): return if ($matches[0]->{'type'} ne $matches[1]->{'type'}); @@ -285,19 +264,11 @@ sub convert { "type" => $matches[0]->{'type'} }; } + sub set_unit_pluralisation { my ($unit, $count) = @_; - my $proper_unit = $unit; - - my $already_plural = looks_plural($unit); - - if ($already_plural && $count == 1) { - $proper_unit = $singular_exceptions{$unit} || substr($unit, 0, -1); - } elsif (!$already_plural && $count != 1) { - $proper_unit = $plural_exceptions{$unit} || $unit . 's'; - } - - return $proper_unit; + $unit = $unit_to_plural{lc $unit} if ($count != 1 && !looks_plural($unit)); + return $unit; } 1; diff --git a/lib/DDG/Goodie/CountryCodes.pm b/lib/DDG/Goodie/CountryCodes.pm index 3bef07382..520d06ff8 100644 --- a/lib/DDG/Goodie/CountryCodes.pm +++ b/lib/DDG/Goodie/CountryCodes.pm @@ -36,9 +36,13 @@ handle remainder => sub { return 'ISO 3166: '. ucfirst $input .' - '. $answer[0], structured_answer => { - input => [ucfirst $input], - operation => 'ISO 3166 Country code', - result => ($answer[0]), + data => { + title => $answer[0], + subtitle => "ISO 3166 Country code: " . ucfirst ($input) + }, + templates => { + group => "text" + } }; }; diff --git a/lib/DDG/Goodie/Factors.pm b/lib/DDG/Goodie/Factors.pm old mode 100644 new mode 100755 index 9b7e13415..66b6a7b6d --- a/lib/DDG/Goodie/Factors.pm +++ b/lib/DDG/Goodie/Factors.pm @@ -17,12 +17,15 @@ handle remainder => sub { my $factors = join ', ', divisors($query); - return "Factors of $query: $factors", - structured_answer => { - input => [$query], - operation => 'Factors', - result => $factors - }; + return "Factors of $query: $factors", structured_answer => { + data => { + title => $factors, + subtitle => "Factors of: $query" + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/FlipText.pm b/lib/DDG/Goodie/FlipText.pm index a3a4cd6c8..baeb543f3 100644 --- a/lib/DDG/Goodie/FlipText.pm +++ b/lib/DDG/Goodie/FlipText.pm @@ -20,9 +20,13 @@ handle remainder => sub { return $result, structured_answer => { - input => [html_enc($input)], - operation => 'Flip text', - result => html_enc($result), + data => { + title => $result, + subtitle => "Flip text $input" + }, + templates => { + group => 'text', + } }; }; diff --git a/lib/DDG/Goodie/Fortune.pm b/lib/DDG/Goodie/Fortune.pm old mode 100644 new mode 100755 index b343e1180..7fce452d6 --- a/lib/DDG/Goodie/Fortune.pm +++ b/lib/DDG/Goodie/Fortune.pm @@ -18,12 +18,15 @@ handle remainder => sub { my $output = $fortune_file->get_random_fortune(); $output =~ s/\n/ /g; - return $output, - structured_answer => { - input => [], - operation => 'Random fortune', - result => $output - }; + return $output, structured_answer => { + data => { + title => $output, + subtitle => "Random Fortune" + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/GenerateMAC.pm b/lib/DDG/Goodie/GenerateMAC.pm old mode 100644 new mode 100755 index b73c8559c..c621911a9 --- a/lib/DDG/Goodie/GenerateMAC.pm +++ b/lib/DDG/Goodie/GenerateMAC.pm @@ -20,12 +20,15 @@ handle remainder => sub { my $address = join(':', map { sprintf '%0.2X', rand(255) } (1 .. 6)); - return "Here's a random MAC address: $address", - structured_answer => { - input => [], - operation => 'Random MAC address', - result => $address - }; + return "Here's a random MAC address: $address", structured_answer => { + data => { + title => $address, + subtitle => 'Random MAC Address' + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/GreatestCommonFactor.pm b/lib/DDG/Goodie/GreatestCommonFactor.pm index 329b07d01..9d2363ba6 100644 --- a/lib/DDG/Goodie/GreatestCommonFactor.pm +++ b/lib/DDG/Goodie/GreatestCommonFactor.pm @@ -3,6 +3,7 @@ package DDG::Goodie::GreatestCommonFactor; use strict; use DDG::Goodie; +use Math::BigInt try => 'GMP'; zci answer_type => "greatest_common_factor"; zci is_cached => 1; @@ -22,23 +23,18 @@ handle remainder => sub { my $formatted_numbers = join(', ', @numbers); $formatted_numbers =~ s/, ([^,]*)$/ and $1/; - my $result = shift @numbers; - foreach (@numbers) { - $result = gcf($result, $_) - } + my $result = Math::BigInt::bgcd(@numbers); return "Greatest common factor of $formatted_numbers is $result.", structured_answer => { - input => [$formatted_numbers], - operation => 'Greatest common factor', - result => $result + data => { + title => "$result", + subtitle => "Greatest common factor: $formatted_numbers" + }, + templates => { + group => "text", + } }; }; -sub gcf { - my ($x, $y) = @_; - ($x, $y) = ($y, $x % $y) while $y; - return $x; -} - 1; diff --git a/lib/DDG/Goodie/HexToDec.pm b/lib/DDG/Goodie/HexToDec.pm old mode 100644 new mode 100755 index b28edf5c8..7ae59b633 --- a/lib/DDG/Goodie/HexToDec.pm +++ b/lib/DDG/Goodie/HexToDec.pm @@ -17,10 +17,14 @@ handle query_raw => sub { my $decimal = Math::BigInt->from_hex($hex); return "$hex base 16 = $decimal base 10", structured_answer => { - input => ['0x' . $hex], - operation => 'Hex to decimal', - result => "$decimal", # Quoted for display precision as string. + data => { + title => "$decimal", # Quoted for display precision as string. + subtitle => "Hex to decimal: 0x" . $hex + }, + templates => { + group => 'text', + } }; }; -0x41414141; +0x01; diff --git a/lib/DDG/Goodie/Lowercase.pm b/lib/DDG/Goodie/Lowercase.pm old mode 100644 new mode 100755 index e9594dd32..7b50aa97e --- a/lib/DDG/Goodie/Lowercase.pm +++ b/lib/DDG/Goodie/Lowercase.pm @@ -18,12 +18,15 @@ handle remainder => sub { return if ($lower eq $input); - return $lower, - structured_answer => { - input => [html_enc($input)], - operation => 'Lowercase', - result => html_enc($lower) - }; + return $lower, structured_answer => { + data => { + title => html_enc($lower), + subtitle => "Lowercase: " . html_enc($input) + }, + templates => { + group => 'text', + } + }; }; 1; diff --git a/lib/DDG/Goodie/POTUS.pm b/lib/DDG/Goodie/POTUS.pm old mode 100644 new mode 100755 index 73a295c91..847e134f5 --- a/lib/DDG/Goodie/POTUS.pm +++ b/lib/DDG/Goodie/POTUS.pm @@ -37,12 +37,15 @@ handle remainder => sub { my $the_guy = $presidents[$index]; my $which = ordinate($num); - return "$the_guy $fact $which $POTUS.", - structured_answer => { - input => [$which], - operation => $POTUS, - result => $the_guy, - }; + return "$the_guy $fact $which $POTUS.", structured_answer => { + data => { + title => $the_guy, + subtitle => "$which $POTUS", + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/RandomNumber.pm b/lib/DDG/Goodie/RandomNumber.pm index bbe7ad0a7..ea1347848 100644 --- a/lib/DDG/Goodie/RandomNumber.pm +++ b/lib/DDG/Goodie/RandomNumber.pm @@ -38,11 +38,15 @@ handle query_lc => sub { $rand = int($rand) + $start; } - return $rand . " (random number)", + return "$rand (random number)", structured_answer => { - input => [$start, $end], - operation => 'Random number between', - result => $rand + data => { + title => $rand, + subtitle => "Random number between $start - $end" + }, + templates => { + group => "text", + } }; }; diff --git a/lib/DDG/Goodie/TitleCase.pm b/lib/DDG/Goodie/TitleCase.pm old mode 100644 new mode 100755 index cf4835515..b2986a510 --- a/lib/DDG/Goodie/TitleCase.pm +++ b/lib/DDG/Goodie/TitleCase.pm @@ -29,12 +29,15 @@ handle remainder => sub { } @words ); - return $title_case, - structured_answer => { - input => [html_enc($input)], - operation => 'Title case', - result => html_enc($title_case), - }; + return $title_case, structured_answer => { + data => { + title => html_enc($title_case), + subtitle => 'Title case: '.html_enc($input) + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/UnixTime.pm b/lib/DDG/Goodie/UnixTime.pm index f129d8f3f..985bfa756 100644 --- a/lib/DDG/Goodie/UnixTime.pm +++ b/lib/DDG/Goodie/UnixTime.pm @@ -8,7 +8,7 @@ use DateTime; use List::MoreUtils qw( uniq ); use Try::Tiny; -my @trigger_words = ("unixtime", "datetime", "unix timestamp", "unix time stamp", "unix epoch", "epoch", "timestamp", "unix time", "utc time", "utc now", "current utc", "time since epoch"); +my @trigger_words = ("unixtime", "datetime", "unix timestamp", "unix time stamp", "unix epoch", "epoch", "timestamp", "unix time", "utc time", "utc now", "current utc", "time since epoch", "epoch converter", "epoch time converter"); triggers startend => @trigger_words; zci answer_type => "time_conversion"; diff --git a/lib/DDG/Goodie/Uppercase.pm b/lib/DDG/Goodie/Uppercase.pm old mode 100644 new mode 100755 index 1bd383eac..27478dbf2 --- a/lib/DDG/Goodie/Uppercase.pm +++ b/lib/DDG/Goodie/Uppercase.pm @@ -20,12 +20,15 @@ handle remainder => sub { my $upper = uc $input; - return $upper, - structured_answer => { - input => [html_enc($input)], - operation => 'Uppercase', - result => html_enc($upper), - }; + return $upper, structured_answer => { + data => { + title => html_enc($upper), + subtitle => "Uppercase: ".html_enc($input) + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/lib/DDG/Goodie/ValarMorghulis.pm b/lib/DDG/Goodie/ValarMorghulis.pm index 0e0aa5750..90521008c 100644 --- a/lib/DDG/Goodie/ValarMorghulis.pm +++ b/lib/DDG/Goodie/ValarMorghulis.pm @@ -17,9 +17,13 @@ handle remainder => sub { return $answer, structured_answer => { - input => ['Valar morghulis'], - operation => 'Code phrase', - result => $answer + data => { + title => $answer, + subtitle => 'Code phrase: Valar morghulis' + }, + templates => { + group => 'text' + } }; }; diff --git a/lib/DDG/Goodie/ZappBrannigan.pm b/lib/DDG/Goodie/ZappBrannigan.pm index 34b6721bb..3c470ec3e 100644 --- a/lib/DDG/Goodie/ZappBrannigan.pm +++ b/lib/DDG/Goodie/ZappBrannigan.pm @@ -22,9 +22,17 @@ handle query => sub { return join("\n", @quote), structured_answer => { - input => [], - operation => 'Zapp Brannigan quote', - result => join('
', @quote)}; + data => { + content => join("
", @quote), + subtitle => 'Zapp Brannigan quote' + }, + templates => { + group => "text", + options => { + content => 'DDH.zapp_brannigan.content' + } + } + }; }; -1; +1; \ No newline at end of file diff --git a/share/goodie/cheat_sheets/json/backbonejs.json b/share/goodie/cheat_sheets/json/backbone-js.json similarity index 99% rename from share/goodie/cheat_sheets/json/backbonejs.json rename to share/goodie/cheat_sheets/json/backbone-js.json index fec562ccf..ee646dcff 100644 --- a/share/goodie/cheat_sheets/json/backbonejs.json +++ b/share/goodie/cheat_sheets/json/backbone-js.json @@ -1,5 +1,5 @@ { - "id": "backbonejs_cheat_sheet", + "id": "backbone_js_cheat_sheet", "name": "Backbone.js", "description": "A quick reference for Backbone.js, a JavaScript framework with a RESTful JSON interface and is based on the model–view–presenter (MVP) application design paradigm", "metadata": { @@ -8,7 +8,7 @@ }, "aliases": [ "backbone.js", - "backbone js", + "backbonejs", "backbone" ], "template_type": "terminal", @@ -162,4 +162,4 @@ "key": "Backbone.setDomLibrary(jQueryNew);" }] } -} \ No newline at end of file +} diff --git a/share/goodie/cheat_sheets/json/c.json b/share/goodie/cheat_sheets/json/c.json index 235d1dd4a..e4fb4ee54 100644 --- a/share/goodie/cheat_sheets/json/c.json +++ b/share/goodie/cheat_sheets/json/c.json @@ -23,18 +23,6 @@ ], "sections": { "Arithmetic Operators": [ - { - "val": "Basic assignment", - "key": "a = b" - }, - { - "val": "Addition", - "key": "a + b" - }, - { - "val": "Subtraction", - "key": "a - b" - }, { "val": "Unary plus (integer promotion)", "key": "+a" @@ -43,18 +31,6 @@ "val": "Unary minus (additive inverse)", "key": "-a" }, - { - "val": "Multiplication", - "key": "a * b" - }, - { - "val": "Division", - "key": "a / b" - }, - { - "val": "Modulo (integer remainder)", - "key": "a % b" - }, { "val": "Increment Prefix", "key": "++a" @@ -70,6 +46,30 @@ { "val": "Decrement Postfix", "key": "a--" + }, + { + "val": "Multiplication", + "key": "a * b" + }, + { + "val": "Division", + "key": "a / b" + }, + { + "val": "Modulo (integer remainder)", + "key": "a % b" + }, + { + "val": "Addition", + "key": "a + b" + }, + { + "val": "Subtraction", + "key": "a - b" + }, + { + "val": "Basic assignment", + "key": "a = b" } ], "Comparison Operators": [ @@ -78,21 +78,21 @@ "key": "a < b" }, { - "val": "a equal to b", - "key": "a == b" + "val": "a less than equal to b", + "key": "a <= b" }, { "val": "a greater than b", "key": "a > b" }, - { - "val": "a less than equal to b", - "key": "a <= b" - }, { "val": "a greater than equal to b", "key": "a >= b" }, + { + "val": "a equal to b", + "key": "a == b" + }, { "val": "a not equal to b", "key": "a != b" @@ -117,18 +117,6 @@ "val": "Bitwise NOT / One's Complement", "key": "~a" }, - { - "val": "Bitwise AND", - "key": "a & b" - }, - { - "val": "Bitwise OR", - "key": "a | b" - }, - { - "val": "Bitwise XOR", - "key": "a ^ b" - }, { "val": "Bitwise left shift", "key": "a << b" @@ -136,6 +124,18 @@ { "val": "Bitwise right shift", "key": "a >> b" + }, + { + "val": "Bitwise AND", + "key": "a & b" + }, + { + "val": "Bitwise XOR", + "key": "a ^ b" + }, + { + "val": "Bitwise OR", + "key": "a | b" } ], "Other Operators": [ @@ -275,4 +275,4 @@ } ] } -} +} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/json/css.json b/share/goodie/cheat_sheets/json/css.json index e79903f4b..9402db08e 100644 --- a/share/goodie/cheat_sheets/json/css.json +++ b/share/goodie/cheat_sheets/json/css.json @@ -138,7 +138,7 @@ "val": "Specifies the type of positioning method used for an element", "key": "position:" }, { - "val": "Specifies the stack order of an elemen", + "val": "Specifies the stack order of an element", "key": "z-index:" }], "Background Properties": [{ diff --git a/share/goodie/cheat_sheets/json/emacs-evil-mode.json b/share/goodie/cheat_sheets/json/emacs-evil-mode.json new file mode 100644 index 000000000..9eb7b0941 --- /dev/null +++ b/share/goodie/cheat_sheets/json/emacs-evil-mode.json @@ -0,0 +1,192 @@ +{ + "id": "emacs_evil_mode_cheat_sheet", + "name": "Evil-Mode for Emacs", + "description": "Shortcuts for the Evil-mode of the Emacs editor", + "metadata": { + "sourceName": "GitHub", + "sourceUrl": "https://github.com/amirrajan/devbox/wiki/EMACS-Evil-Cheat-Sheet" + }, + "template_type": "keyboard", + "aliases": [ + "evil emacs", + "emacs evil-mode", + "evil-mode emacs", + "evil-mode for emacs", + "evil mode for emacs", + "evil emacs mode" + ], + "section_order": [ + "Editing Text", + "Window Navigation", + "Discovery" + ], + "sections": { + "Editing Text": [ + { + "key": "ESC", + "val": "Command Mode" + }, + { + "key": ":w", + "val": "save" + }, + { + "key": ":q", + "val": "quit" + }, + { + "key": ":wq", + "val": "save and quit" + }, + { + "key": ":wqa", + "val": "save quit all" + }, + { + "key": "hjkl", + "val": "to navigate" + }, + { + "key": "w", + "val": "to move forward by one word" + }, + { + "key": "b", + "val": "to move back by one word" + }, + { + "key": "shift+[", + "val": "move up by new lines" + }, + { + "key": "shift+]", + "val": "to move down by new lines" + }, + { + "key": "yy", + "val": "copy line" + }, + { + "key": "dd", + "val": "delete line" + }, + { + "key": "cc", + "val": "change line" + }, + { + "key": "Y", + "val": "copy till the end of line" + }, + { + "key": "D", + "val": "delete till the end of line" + }, + { + "key": "C", + "val": "change till the end of line" + }, + { + "key": "yw", + "val": "yank word" + }, + { + "key": "dw", + "val": "delete word" + }, + { + "key": "cw", + "val": "change word" + }, + { + "key": "gg", + "val": "go to top of file" + }, + { + "key": "G", + "val": "goto bottom of file" + } + + ], + "Window Navigation": [ + { + "key": ",g", + "val": "go to file" + }, + { + "key": ",b", + "val": "view recently visited files" + }, + { + "key": ",m", + "val": "new vertical split" + }, + { + "key": ":split", + "val": "new horizontal split" + }, + { + "key": ",.", + "val": "open current directory" + }, + { + "key": "C-h , C-j ,C-k ,C-l", + "val": "navigate between windows" + }, + { + "key": ",)", + "val": "previous buffer" + }, + { + "key": ",(", + "val": "next buffer" + }, + { + "key": ":ack ENT", + "val": "search across files" + }, + { + "key": ",f", + "val": "next search result" + }, + { + "key": ",d", + "val": "previous search result" + }, + { + "key": "CTRL+v", + "val": "visula block mode" + }, + { + "key": "While in visual Block Mode shift + i", + "val": "Insert Mode to append text to selection from Visual Block Mode" + } + ], + "Discovery": [ + { + "key": ":describe-char", + "val": "describes the char underneath the cursor, allows you to change color theme from there" + }, + { + "key": ":customize-face", + "val": "editor for changing all color themes use tab and shift+tab to navigate" + }, + { + "key": "F1 k KEYSTROKE", + "val": "press F1 followed by k, then enter a key stroke to find information about what editor method was invoked" + }, + { + "key": "F1 f METHODNAME", + "val": "gives information about an editor method" + }, + { + "key": "F1 a SEARCH", + "val": "search for an editor method containing the search term" + }, + { + "key": ":METHODNAME", + "val": "invoke editor method" + } + ] + } +} diff --git a/share/goodie/cheat_sheets/json/erlang.json b/share/goodie/cheat_sheets/json/erlang.json index 30d54450f..e1a022030 100644 --- a/share/goodie/cheat_sheets/json/erlang.json +++ b/share/goodie/cheat_sheets/json/erlang.json @@ -120,6 +120,9 @@ }, { "val": "repeat the expression in query ", "key": "e(N)." + }, { + "val": "forget variable binding ", + "key": "f(N)." }, { "val": "forget all variable bindings", "key": "f()." diff --git a/share/goodie/cheat_sheets/json/finnish.json b/share/goodie/cheat_sheets/json/finnish.json index fcdbcdcad..662d27d94 100644 --- a/share/goodie/cheat_sheets/json/finnish.json +++ b/share/goodie/cheat_sheets/json/finnish.json @@ -2,7 +2,6 @@ "id": "finnish_cheat_sheet", "name": "Finnish Cheat Sheet", "description": "Basic Finnish words and phrases", - "aliases": ["english to finnish", "basic finnish"], "template_type": "language", "section_order": ["Basics", "Getting Help", "Travelling", "Etiquette", "Going out for dinner", "Numbers"], "sections": { diff --git a/share/goodie/cheat_sheets/json/high-valyrian.json b/share/goodie/cheat_sheets/json/high-valyrian.json index 1043cfc77..e325b206d 100644 --- a/share/goodie/cheat_sheets/json/high-valyrian.json +++ b/share/goodie/cheat_sheets/json/high-valyrian.json @@ -9,7 +9,7 @@ }, "aliases": [ - "valyrian", "game of thrones language", "valyrian language" + "valyrian" ], "template_type": "language", diff --git a/share/goodie/cheat_sheets/json/language/kannada.json b/share/goodie/cheat_sheets/json/language/kannada.json index c931821a8..fc041c8db 100644 --- a/share/goodie/cheat_sheets/json/language/kannada.json +++ b/share/goodie/cheat_sheets/json/language/kannada.json @@ -8,10 +8,6 @@ "sourceUrl" : "http://www.omniglot.com/language/phrases/kannada.php" }, - "aliases": [ - "basic kannada" - ], - "template_type": "language", "section_order": [ diff --git a/share/goodie/cheat_sheets/json/language/spanish.json b/share/goodie/cheat_sheets/json/language/spanish.json index 224d5a46f..1215a60d4 100644 --- a/share/goodie/cheat_sheets/json/language/spanish.json +++ b/share/goodie/cheat_sheets/json/language/spanish.json @@ -9,7 +9,7 @@ }, "aliases": [ - "spanish words", "spanish to english", "spanish greetings", "basic spanish", "spanish questions" + "spanish words", "spanish greetings", "spanish questions" ], "template_type": "language", @@ -330,4 +330,4 @@ } ] } -} \ No newline at end of file +} diff --git a/share/goodie/cheat_sheets/json/language/telugu.json b/share/goodie/cheat_sheets/json/language/telugu.json index 310eec17f..2567621f0 100644 --- a/share/goodie/cheat_sheets/json/language/telugu.json +++ b/share/goodie/cheat_sheets/json/language/telugu.json @@ -6,10 +6,6 @@ "sourceName":"Wikitravel", "sourceUrl":"http://wikitravel.org/en/Telugu_phrasebook" }, - "aliases":[ - "english to telugu", - "basic telugu" - ], "template_type":"language", "section_order":[ "Basics", @@ -269,4 +265,4 @@ } ] } -} \ No newline at end of file +} diff --git a/share/goodie/cheat_sheets/json/logarithms.json b/share/goodie/cheat_sheets/json/logarithms.json index 78df4ec6a..04f5010ea 100644 --- a/share/goodie/cheat_sheets/json/logarithms.json +++ b/share/goodie/cheat_sheets/json/logarithms.json @@ -1,7 +1,7 @@ { "id": "logarithms_cheat_sheet", "name": "Logarithms", - "description": "displayed as subtitle of the AnswerBar; optional", + "description": "List of logarithmic rules and formulae.", "metadata": { "sourceName": "SCRIBD", @@ -9,7 +9,10 @@ }, "aliases": [ - "logarithmic identities", "logarithms rules" + "logarithmic identities", "logarithms rules", + "logarithm identities", "logarithm rules", + "log identities", "log rules", + "logarithm" ], "template_type": "reference", diff --git a/share/goodie/cheat_sheets/json/perl.json b/share/goodie/cheat_sheets/json/perl.json index ecde6e453..986969a44 100644 --- a/share/goodie/cheat_sheets/json/perl.json +++ b/share/goodie/cheat_sheets/json/perl.json @@ -132,7 +132,7 @@ }], "Basic Syntax": [{ "val": "Read command line params", - "key": "($a, $b) = shift(@ARGV);" + "key": "($a, $b) = @ARGV;" }, { "val": "Define subroutine", "key": "sub p\\{my $var = shift; ...\\}" diff --git a/share/goodie/cheat_sheets/json/sql.json b/share/goodie/cheat_sheets/json/sql.json index 0b8cc90b7..e2e11f03b 100644 --- a/share/goodie/cheat_sheets/json/sql.json +++ b/share/goodie/cheat_sheets/json/sql.json @@ -236,9 +236,6 @@ }, { "key": "FOREIGN KEY", "val": "Ensure the referential integrity of the data in one table to match values in another table" - }, { - "key": "FOREIGN KEY", - "val": "Ensure the referential integrity of the data in one table to match values in another table" }, { "key": "DEFAULT", "val": "Specifies a default value for a column" diff --git a/share/goodie/cheat_sheets/json/vim.json b/share/goodie/cheat_sheets/json/vim.json index b144df7d4..b5c52ec5a 100644 --- a/share/goodie/cheat_sheets/json/vim.json +++ b/share/goodie/cheat_sheets/json/vim.json @@ -8,13 +8,13 @@ }, "template_type": "keyboard", "section_order": [ + "Exiting", "Cursor movement", "Insert mode - inserting/appending text", "Editing", "Marking text (visual mode)", "Visual commands", "Cut and paste", - "Exiting", "Search and replace", "Working with multiple files", "Tabs", diff --git a/share/goodie/cheat_sheets/visual-studio.json b/share/goodie/cheat_sheets/json/visual-studio.json similarity index 98% rename from share/goodie/cheat_sheets/visual-studio.json rename to share/goodie/cheat_sheets/json/visual-studio.json index c109b4572..aefe038c4 100644 --- a/share/goodie/cheat_sheets/visual-studio.json +++ b/share/goodie/cheat_sheets/json/visual-studio.json @@ -5,6 +5,7 @@ "sourceName": "Microsoft", "sourceUrl": "https://msdn.microsoft.com/en-us/library/da5kh0wa.aspx" }, + "template_type": "keyboard", "section_order": ["Edit","Debug","Build","Project"], "sections": { "Edit": [{ diff --git a/share/goodie/cheat_sheets/json/wget.json b/share/goodie/cheat_sheets/json/wget.json new file mode 100644 index 000000000..97ad65566 --- /dev/null +++ b/share/goodie/cheat_sheets/json/wget.json @@ -0,0 +1,61 @@ +{ + "id": "wget_cheat_sheet", + "name": "Wget", + "description": "A computer program that retrieves content from web servers via HTTP, HTTPS, and FTP protocols", + + "metadata": { + "sourceName": "GNU", + "sourceUrl" : "https://www.gnu.org/manual/manual.html" + }, + + "aliases": [ + "gnu wget" + ], + + "template_type": "terminal", + + "section_order": [ + "Useful Commands" + ], + + "sections": { + "Useful Commands": [ + { + "key": "wget ", + "val": "Download single file and stores in a current directory" + }, + { + "key": "-O (uppercase)", + "val": "Download file with different name" + }, + { + "key": "http:// , ftp://", + "val": "Download multiple file with http and ftp protocol" + }, + { + "key": "wget -i /wget/tmp.txt", + "val": "Read URL’s from a file" + }, + { + "key": "wget -c", + "val": "Resume uncompleted download" + }, + { + "key": "wget -b", + "val": "Download files in background" + }, + { + "key": "wget -c --limit-rate=100k", + "val": "Restrict download speed limits" + }, + { + "key": "wget --http-user=narad --http-password=password", + "val": "Restricted FTP and HTTP downloads with username and password" + }, + { + "key": "wget --version", + "val": "Find wget version" + } + ] + } +} diff --git a/share/goodie/cheat_sheets/json/youtubedl.json b/share/goodie/cheat_sheets/json/youtubedl.json new file mode 100644 index 000000000..7468b6ecf --- /dev/null +++ b/share/goodie/cheat_sheets/json/youtubedl.json @@ -0,0 +1,110 @@ +{ + "id": "youtubedl_cheat_sheet", + "name": "Youtube-dl", + "description": "Small command-line program to download videos from YouTube.com and other video sites", + + "metadata": { + "sourceName": "Github", + "sourceUrl": "https://github.com/rg3/youtube-dl/blob/master/README.md#readme" + }, + + "aliases": [ + "youtube-dl", "youtube dl" + ], + + "template_type": "terminal", + + "section_order": [ + "Network Options", + "Video Selection", + "Download Options", + "Filesystem Options", + "Video Format Options" + ], + + "sections": { + "Network Options": [{ + "key": "--proxy URL", + "val": "Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy ) for direct connection" + }, { + "key": "-4, --force-ipv4", + "val": " Make all connections via IPv4" + }, { + "key": "-6, --force-ipv6", + "val": " Make all connections via IPv6" + }, { + "key": "--source-address IP ", + "val": "Client-side IP address to bind to" + }], + "Video Selection": [{ + "key": "--playlist-start NUMBER", + "val": "Playlist video to start at (default is 1)" + }, { + "key": "--playlist-end NUMBER", + "val": "Playlist video to end at (default is last)" + }, { + "key": "--max-downloads NUMBER", + "val": "Abort after downloading NUMBER files" + }, { + "key": "--include-ads", + "val": "Download advertisements as well" + }, { + "key": "--yes-playlist", + "val": "Download the playlist, if the URL refers to a video and a playlist" + }], + "Download Options": [{ + "key": "-r, --rate-limit LIMIT", + "val": "Maximum download rate in bytes per second" + }, { + "key": "-R, --retries RETRIES", + "val": "Number of retries (default is 10), or infinite" + }, { + "key": "--buffer-size SIZE", + "val": "Size of download buffer (e.g. 1024 or 16K)" + }, { + "key": "--external-downloader COMMAND", + "val": "Use the specified external downloader Currently supports" + }, { + "key": "--external-downloader-args ARGS", + "val": "Give these arguments to the external downloader" + }], + "Filesystem Options": [{ + "key": "-a, --batch-file FILE", + "val": "File containing URLs to download" + }, { + "key": "--id", + "val": "Use only video ID in file name" + }, { + "key": "--autonumber-size NUMBER", + "val": "Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given" + }, { + "key": "-c, --continue", + "val": "Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible." + }, { + "key": "--no-continue", + "val": "Do not resume partially downloaded files" + }, { + "key": "--cookies FILE", + "val": "File to read cookies from and dump cookie jar in" + }], + "Video Format Options": [{ + "key": "-f, --format FORMAT", + "val": "Video format code, see the FORMAT SELECTION for all the info" + }, { + "key": "--all-formats", + "val": "Download all available video formats" + }, { + "key": "--prefer-free-formats", + "val": "Prefer free video formats unless a specific one is requested" + }, { + "key": "-F, --list-formats", + "val": "List all available formats of requested videos" + }, { + "key": "--youtube-skip-dash-manifest", + "val": "Do not download the DASH manifests and related data on YouTube videos" + }, { + "key": "--merge-output-format FORMAT", + "val": "If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv. Ignored if no merge is required" + }] + } +} \ No newline at end of file diff --git a/share/goodie/cheat_sheets/json/zfs.json b/share/goodie/cheat_sheets/json/zfs.json new file mode 100644 index 000000000..6f79c2de7 --- /dev/null +++ b/share/goodie/cheat_sheets/json/zfs.json @@ -0,0 +1,112 @@ +{ + "id": "zfs_cheat_sheet", + "name": "ZFS", + "description": "The combined file system and logical volume manager. Data are important - be careful with it.", + "metadata": { + "sourceName": "FreeBSD handbook - The Z File System (ZFS)", + "sourceUrl": "https://www.freebsd.org/doc/handbook/zfs.html" + }, + "aliases": [ + "z file system", + "zpool" + ], + "template_type": "terminal", + "section_order": [ + "Pools", + "Datasets" + ], + "sections": { + "Pools": [ + { + "key": "zpool list", + "val": "Lists the given pools." + }, + { + "key": "zpool status \\[$POOLNAME\\]", + "val": "Displays the detailed health status." + }, + { + "key": "zpool get all $POOLNAME", + "val": "Retrieves the all properties for the pool." + }, + { + "key": "zpool set $PROPERTY=$VALUE $POOLNAME", + "val": "Sets the given property on the pool." + }, + { + "key": "zpool create \\[$POOLTYPE\\] $POOLNAME $DEVICE1", + "val": "Create a pool (Pool types: _ | spare | mirror | raidz)." + }, + { + "key": "zpool replace $POOLNAME $DEV_OLD \\[$DEV_NEW\\]", + "val": "Replaces the old device with new one." + }, + { + "key": "zpool destroy $POOLNAME", + "val": "Destroys the given pool." + }, + { + "key": "zpool remove $POOLNAME $DEVICE", + "val": "Remove a physical device from the pool." + }, + { + "key": "zpool online $POOLNAME $DEVICE", + "val": "Device is online and functioning." + }, + { + "key": "zpool offline $POOLNAME $DEVICE", + "val": "Take device explicitly offline." + }, + { + "key": "zpool scrub $POOLNAME", + "val": "Begin to examines all data in the pool to verify that checksums are correctly." + }, + { + "key": "zpool \\[attach|detach\\] $POOLNAME $DEVICE", + "val": "Attach or Detaches device from a pool." + }, + { + "key": "zpool iostat \\[$POOLNAME\\]", + "val": "Displays I/O statistics for the given pool." + } + ], + "Datasets": [ + { + "key": "zfs list", + "val": "Lists the properties for the given datasets." + }, + { + "key": "zfs list -t snapshot /\\[$DATASET\\]", + "val": "Display a list of snapshots from /[] directory." + }, + { + "key": "zfs snaphot \\[-r\\] $POOLNAME/$DATASET@$SNAPSHOTNAME", + "val": "Takes a [recursiv] snaphot of dataset." + }, + { + "key": "zfs set $OPTION=$VALUE $POOLNAME/$DATASET", + "val": "Set the property to the given value for a dataset." + }, + { + "key": "zfs clone $POOLNAME/$DATASET@$SNAPSHOTNAME $POOLNAME/$CLONE", + "val": "Creates a clone of the given snapshot." + }, + { + "key": "zfs rollback \\[-rR\\] $POOLNAME/$DATASET@$SNAPSHOTNAME", + "val": "Roll back the given dataset to a previous snapshot." + }, + { + "key": "zfs destroy $POOLNAME/$DATASET@$SNAPSHOTNAME", + "val": "Destroys the given dataset." + }, + { + "key": "zfs mount $POOLNAME", + "val": "Mounts of the ZFS file systems." + }, + { + "key": "zfs umount $POOLNAME\\[/$MOUNTPOINT\\]", + "val": "Unmounts currently mounted ZFS file systems." + } + ] + } +} diff --git a/share/goodie/cheat_sheets/triggers.yaml b/share/goodie/cheat_sheets/triggers.yaml index 9e542e790..bb7881e29 100644 --- a/share/goodie/cheat_sheets/triggers.yaml +++ b/share/goodie/cheat_sheets/triggers.yaml @@ -36,6 +36,8 @@ categories: - "cheat codes" - "cheats" - "secrets" + ignore: + - "game" # Describes or introduces syntax of a programming language. code: startend: @@ -61,17 +63,26 @@ categories: - "keyboard shortcuts" - "keys" - "shortcuts" + ignore: + - "default" # Introduces basic translations for a human language. language: startend: - "phrases" - "translations" + ignore: + - "basic" + - "english to" + - "language" # Shows links to other sites. links: startend: - "links" - "sites" - "websites" + ignore: + - "list" + - "list of" # Shows mathematical equations. math: startend: @@ -82,8 +93,9 @@ categories: reference: startend: - "help" - - "quick reference" - "reference" + ignore: + - "quick" # Describes commands that can be entered at a terminal. terminal: startend: diff --git a/share/goodie/constants/constants.yml b/share/goodie/constants/constants.yml index 9ac93c59a..57aa6b647 100644 --- a/share/goodie/constants/constants.yml +++ b/share/goodie/constants/constants.yml @@ -80,16 +80,26 @@ bohr magneton: html: '9.27400968 × 10−24 J T−1' boltzmann constant: - name: The Stefan Boltzmann Constant + name: The Boltzmann Constant aliases: - - stefan boltzmann constant - - the stefan boltzmann constant - symbol: + - the boltzmann constant + symbol: k wiki: value: plain: '1.3806503 × 10^-23 m^2 kg s^-2 K^-1' html: '1.3806503 × 10-23 m2 kg s-2 K-1' +stefan-boltzmann constant: + name: The Stefan-Boltzmann Constant + aliases: + - the stefan boltzmann constant + - stefan boltzmann constant + symbol: σ + wiki: + value: + plain: '5.670367 × 10^−8 W m^−2 K^−4' + html: '5.670367 × 10−8 W m−2 K−4' + elementary electric charge: name: Elementary Electric Charge aliases: diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml old mode 100755 new mode 100644 index ed12cadca..ab389584f --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -4,7 +4,7 @@ aliases: - t - mt - te - - metric tons + - metric tonnes - tonnes - ts - mts @@ -12,26 +12,27 @@ aliases: factor: 1 type: mass unit: metric ton +plural: metric tons --- aliases: - oz - - ounces - ozs factor: 35274 type: mass unit: ounce +plural: ounces --- aliases: - lb - lbm - pound mass - - pounds - lbs - lbms - pounds mass factor: 2204.62 type: mass unit: pound +plural: pounds --- aliases: - st @@ -40,6 +41,7 @@ aliases: factor: 157.473 type: mass unit: stone +plural: stone --- aliases: - weight ton @@ -50,72 +52,73 @@ aliases: factor: 0.984207 type: mass unit: long ton +plural: long tons --- aliases: - mcg - - micrograms - mcgs - µg factor: 1000000000000 type: mass unit: microgram +plural: micrograms --- aliases: - kg - kilo - kilogramme - - kilograms - kgs - kilos - kilogrammes factor: 1000 type: mass unit: kilogram +plural: kilograms --- aliases: - g - gm - gramme - - grams - gs - gms - grammes factor: 1000000 type: mass unit: gram +plural: grams --- aliases: - mg - - milligrams - mgs factor: 1000000000 type: mass unit: milligram +plural: milligrams --- aliases: - short ton - short tons - - tons factor: 1.10231 type: mass unit: ton +plural: tons --- aliases: - grain - - grains - gr - troy grain - troy grains factor: 15432358.3529414 type: mass unit: grain +plural: grains --- aliases: - carat - - carats factor: 5000000 type: mass unit: carat +plural: carats --- aliases: - dram @@ -125,19 +128,19 @@ aliases: - avoirdupois dram factor: 564383.3912 type: mass -unit: drams avoirdupois +unit: dram avoirdupois +plural: drams avoirdupois --- aliases: - - meters - metre - metres - m factor: 1 type: length unit: meter +plural: meters --- aliases: - - kilometers - kilometre - kilometres - km @@ -147,9 +150,9 @@ aliases: factor: 0.001 type: length unit: kilometer +plural: kilometers --- aliases: - - centimeters - centimetre - centimetres - cm @@ -157,9 +160,9 @@ aliases: factor: 100 type: length unit: centimeter +plural: centimeters --- aliases: - - millimeters - millimetre - millimetres - mm @@ -167,6 +170,7 @@ aliases: factor: 1000 type: length unit: millimeter +plural: millimeters --- aliases: - thou @@ -174,13 +178,12 @@ aliases: - mil - mils - thousandth of an inch - - thousandths of an inch factor: 39370.1 type: length unit: thousandth of an inch +plural: thousandths of an inch --- aliases: - - miles - mi - statute mile - statute miles @@ -189,18 +192,18 @@ aliases: factor: 0.000621371192237334 type: length unit: mile +plural: miles --- aliases: - - yards - yd - yds - yrds factor: 1.0936132983377077865266841644794 type: length unit: yard +plural: yards --- aliases: - - feet - ft - international foot - international feet @@ -209,17 +212,17 @@ aliases: factor: 3.2808398950131233595800524934383 type: length unit: foot +plural: feet --- aliases: - - inches - in - ins factor: 39.37007874015748031496062992126 type: length unit: inch +plural: inches --- aliases: - - nautical miles - n - ns - nm @@ -229,92 +232,94 @@ aliases: factor: 0.000539957 type: length unit: nautical mile +plural: nautical miles --- aliases: - - furlongs + - furlng factor: 0.00497096953789867 type: length unit: furlong +plural: furlongs --- aliases: - gunter's chains - - chains factor: 0.0497096953789867 type: length unit: chain +plural: chains --- aliases: - gunter's links - - links factor: 4.97096953789867 type: length unit: link +plural: links --- aliases: - - rods + - rd factor: 0.198838781515947 type: length unit: rod +plural: rods --- aliases: - - fathoms - ftm - ftms factor: 0.539611824837685 type: length unit: fathom +plural: fathoms --- -aliases: - - leagues +aliases: [] factor: 0.000207123730745778 type: length unit: league +plural: leagues --- -aliases: - - cables +aliases: [] factor: 0.00539611824837685 type: length unit: cable +plural: cables --- aliases: - - light years - ly - lys factor: 1.05700083402462e-16 type: length unit: light year +plural: light years --- aliases: - - parsecs - pc - pcs factor: 3.24077923047971e-17 type: length unit: parsec +plural: parsecs --- aliases: - - astronomical units - au - aus factor: 6.68458712226845e-12 type: length unit: astronomical unit +plural: astronomical units --- aliases: - - hectares - ha factor: 1 type: area unit: hectare +plural: hectares --- -aliases: - - acres +aliases: [] factor: 2.4710439 type: area unit: acre +plural: acres --- aliases: - - square meters - metre^2 - meter^2 - metres^2 @@ -326,9 +331,9 @@ aliases: factor: 10000 type: area unit: square meter +plural: square meters --- aliases: - - square kilometers - square kilometre - square kilometres - km^2 @@ -336,9 +341,9 @@ aliases: factor: 0.01 type: area unit: square kilometer +plural: square kilometers --- aliases: - - square centimeters - square centimetre - square centimetres - cm^2 @@ -346,9 +351,9 @@ aliases: factor: 100000000 type: area unit: square centimeter +plural: square centimeters --- aliases: - - square millimeters - square millimetre - square millimetres - mm^2 @@ -356,9 +361,9 @@ aliases: factor: 10000000000 type: area unit: square millimeter +plural: square millimeters --- aliases: - - square miles - sq mi - square statute mile - square statute miles @@ -369,9 +374,9 @@ aliases: factor: 0.00386102160083284 type: area unit: square mile +plural: square miles --- aliases: - - square yards - yard^2 - yard² - yards² @@ -383,9 +388,9 @@ aliases: factor: 11959.9 type: area unit: square yard +plural: square yards --- aliases: - - square feet - feet^2 - feet² - foot^2 @@ -395,9 +400,9 @@ aliases: factor: 107639.1 type: area unit: square foot +plural: square feet --- aliases: - - square inches - inch^2 - inches^2 - squinch @@ -406,16 +411,17 @@ aliases: factor: 15500031 type: area unit: square inch +plural: square inches --- aliases: - ping factor: 3024.80338778 type: area unit: 坪 +plural: 坪 --- aliases: - liter - - litres - liters - l - litter @@ -423,19 +429,19 @@ aliases: factor: 1 type: volume unit: litre +plural: litres --- aliases: - milliliter - - millilitres - milliliters - ml factor: 1000 type: volume unit: millilitre +plural: millilitres --- aliases: - cubic inch - - cubic inches - cubic in - cu inch - cu in @@ -445,6 +451,7 @@ aliases: factor: 61.024 type: volume unit: cubic inch +plural: cubic inches --- aliases: - metre^3 @@ -456,6 +463,7 @@ aliases: factor: 0.001 type: volume unit: cubic metre +plural: cubic metres --- aliases: - centimetre^3 @@ -468,9 +476,12 @@ aliases: - ccm factor: 1000 type: volume -unit: cubic centimetre +unit: cubic centimeter +plural: cubic centimeters --- aliases: + - cubic millimetre + - cubic millimetres - millimetre^3 - millimeter^3 - millimetres^3 @@ -479,83 +490,86 @@ aliases: - mm³ factor: 1000000 type: volume -unit: cubic millimetre +unit: cubic millimeter +plural: cubic millimeters --- aliases: - - liquid pints - us pints - us liquid pint - us liquid pints factor: 2.11337641886519 type: volume unit: liquid pint +plural: liquid pints --- aliases: - - dry pints + - pints dry factor: 1.81616596853771 type: volume unit: dry pint +plural: dry pints --- aliases: - pints - pint - - imperial pints - uk pint - british pint - pts factor: 1.7597539863927 type: volume unit: imperial pint +plural: imperial pints --- aliases: - - imperial gallon - uk gallon - british gallon - british gallons - uk gallons + - gb gallons + - gb gallon factor: 0.219969248299088 type: volume unit: imperial gallon +plural: imperial gallons --- aliases: - fluid gallon - us fluid gallon - fluid gallons - - us gallons - gallon - gallons factor: 0.264172052358148 type: volume unit: us gallon +plural: us gallons --- aliases: - liquid quart - us quart - us quarts - - quarts - liquid quarts factor: 1.05668820943259 type: volume unit: quart +plural: quarts --- aliases: - - imperial quarts - british quarts - british quart factor: 7.03901594557081 type: volume unit: imperial quart +plural: imperial quarts --- aliases: - - imperial fluid ounces - imperial fl oz - imperial fluid oz factor: 28.1560637822832 type: volume unit: imperial fluid ounce +plural: imperial fluid ounces --- aliases: - - us fluid ounces - us fl oz - fl oz - fl. oz @@ -563,14 +577,65 @@ aliases: factor: 33.814022701843 type: volume unit: us fluid ounce +plural: us fluid ounces --- aliases: - - us cups - cups - cup factor: 4.2267528 type: volume unit: us cup +plural: us cups +--- +aliases: + - us tsp + - us tsp. + - teaspoons + - teaspoon + - tsp + - tsp. +factor: 202.88413621 +type: volume +unit: us teaspoon +plural: us teaspoons +--- +aliases: + - metric tsp + - metric tsp. +factor: 200 +type: volume +unit: metric teaspoon +plural: metric teaspoons +--- +aliases: + - us tbsp + - us tbsp. + - tablespoons + - tablespoon + - tbsp + - tbsp. +factor: 67.6280454 +type: volume +unit: us tablespoon +plural: us tablespoons +--- +aliases: + - metric tbsp + - metric tbsp. +factor: 66.6666666 +type: volume +unit: metric tablespoon +plural: metric tablespoons +--- +aliases: + - dessert spoons + - dessert spoon + - dstspn + - dstspn. +factor: 100 +type: volume +unit: metric dessert spoon +plural: metric dessert spoons --- aliases: - days @@ -580,166 +645,165 @@ aliases: factor: 1 type: duration unit: day +plural: days --- aliases: - - seconds - sec - s factor: 86400 type: duration unit: second +plural: seconds --- aliases: - - milliseconds - millisec - millisecs - ms factor: 86400000 type: duration unit: millisecond +plural: milliseconds --- aliases: - - microseconds - microsec - microsecs - µs factor: 86400000000 type: duration unit: microsecond +plural: microseconds --- aliases: - - nanoseconds - nanosec - nanosecs - ns factor: 86400000000000 type: duration unit: nanosecond +plural: nanoseconds --- aliases: - - minutes - min - mins factor: 1440 type: duration unit: minute +plural: minutes --- aliases: - - hours - hr - hrs - h factor: 24 type: duration unit: hour +plural: hours --- aliases: - - weeks - wks - wk factor: 0.142857142857143 type: duration unit: week +plural: weeks --- aliases: [] factor: 0.0714285714285714 type: duration unit: fortnight +plural: fortnights --- aliases: - - months - mons - mns - mn factor: 0.0328767123287671 type: duration unit: month +plural: months --- aliases: - - years - yr - yrs factor: 0.00273972602739726 type: duration unit: year +plural: years --- -aliases: - - decade - - decades +aliases: [] factor: 0.000273972602739726 type: duration unit: decade +plural: decades --- -aliases: - - century - - centuries +aliases: [] factor: 0.0000273972602739726 type: duration unit: century +plural: centuries --- -aliases: - - millennium - - millennia +aliases: [] factor: 0.00000273972602739726 type: duration unit: millennium +plural: millennia --- aliases: - - leap years - leapyear - leapyr - leapyrs factor: 0.00273224043715847 type: duration unit: leap year +plural: leap years --- aliases: - - pascals - pa - pas factor: 1 type: pressure unit: pascal +plural: pascals --- aliases: - - kilopascals - kpa - kpas factor: 0.001 type: pressure unit: kilopascal +plural: kilopascals --- aliases: - - megapascals - megapa - megapas factor: 1e-06 type: pressure unit: megapascal +plural: megapascals --- aliases: - - gigapascals - gpa - gpas factor: 1e-09 type: pressure unit: gigapascal +plural: gigapascals --- aliases: - - bars - pa - pas factor: 1e-05 type: pressure unit: bar +plural: bars --- aliases: - - atmospheres - atm - atms factor: 9.86923266716013e-06 type: pressure unit: atmosphere +plural: atmospheres --- aliases: - psis @@ -749,28 +813,29 @@ aliases: - p.s.i factor: 0.000145036839357197 type: pressure -unit: pounds per square inch +unit: pound per square inch +plural: pounds per square inch --- aliases: - mmhg factor: 0.00750061683 type: pressure unit: mmHg +plural: mmHg --- -aliases: - - torr - - torrs +aliases: [] factor: 0.00750062 type: pressure unit: torr +plural: torr --- aliases: - - joules - j - js factor: 1 type: energy unit: joule +plural: joules --- aliases: - watt second @@ -779,6 +844,7 @@ aliases: factor: 1 type: energy unit: watt-second +plural: watt-seconds --- aliases: - watt hour @@ -787,6 +853,7 @@ aliases: factor: 0.000277777777777778 type: energy unit: watt-hour +plural: watt-hours --- aliases: - kilowatt hour @@ -795,35 +862,36 @@ aliases: factor: 2.77777777777778e-07 type: energy unit: kilowatt-hour +plural: kilowatt-hours --- aliases: - ergon - - ergs - ergons factor: 1e-07 type: energy unit: erg +plural: ergs --- aliases: - electronvolt - - electron volts + - electronvolts - ev - evs factor: 6.2415096e+18 type: energy unit: electron volt +plural: electron volts --- aliases: - small calories - - thermochemical gram calories - chemical calorie - chemical calories factor: 0.239005736137667 type: energy unit: thermochemical gram calorie +plural: thermochemical gran calories --- aliases: - - large calories - food calorie - food calories - kcals @@ -831,92 +899,94 @@ aliases: factor: 0.000239005736137667 type: energy unit: large calorie +plural: large calories --- aliases: - - british thermal units - btu - btus factor: 0.000948316737790422 type: energy unit: british thermal unit +plural: british thermal units --- aliases: - tnt equivilent - tonnes of tnt - tnt - - tons of tnt factor: 2.39005736137667e-10 type: energy unit: ton of TNT +plural: tons of TNT --- aliases: - - watts - w factor: 1 type: power unit: watt +plural: watts --- aliases: - - kilowatts - kw factor: 0.001 type: power unit: kilowatt +plural: kilowatts --- aliases: - - megawatts - mw factor: 1e-06 type: power unit: megawatt +plural: megawatts --- aliases: - - gigawatts - jiggawatts - gw factor: 1e-09 type: power unit: gigawatt +plural: gigawatts --- aliases: - - terawatts - tw factor: 1e-12 type: power unit: terawatt +plural: terawatts --- aliases: - - petawatts - pw factor: 1e-15 type: power unit: petawatt +plural: petawatts --- -aliases: - - milliwatts +aliases: [] factor: 1000 type: power unit: milliwatt +plural: milliwatts --- aliases: - - microwatts + - μwatts factor: 1000000 type: power unit: microwatt +plural: microwatts --- aliases: - - nanowatts - nw factor: 1000000000 type: power unit: nanowatt +plural: nanowatts --- aliases: - - picowatts - pw factor: 1000000000000 type: power unit: picowatt +plural: picowatts --- aliases: - metric horsepowers @@ -930,9 +1000,10 @@ aliases: factor: 0.0013596216173039 type: power unit: metric horsepower +plural: metric horsepower --- aliases: - - mechnical horsepower + - mechanical horsepower - horsepower - hp - hp @@ -940,33 +1011,34 @@ aliases: factor: 0.00134102208959503 type: power unit: horsepower +plural: horsepower --- aliases: - - electical horsepowers + - electrical horsepowers - hp - hp factor: 0.00134048257372654 type: power -unit: electical horsepower +unit: electrical horsepower +plural: electrical horsepower --- aliases: - - degrees - deg - degs factor: 1 type: angle unit: degree +plural: degrees --- aliases: - - radians - rad - rads factor: 0.0174532925199433 type: angle unit: radian +plural: radians --- aliases: - - gradians - grad - grads - gon @@ -976,93 +1048,95 @@ aliases: factor: 1.11111111111111 type: angle unit: gradian +plural: gradians --- aliases: - - quadrants - quads - quad factor: 0.0111111111111111 type: angle unit: quadrant +plural: quadrants --- aliases: - semi circle - semicircle - semi circles - semicircles - - semi-circles factor: 0.00555555555555556 type: angle unit: semi-circle +plural: semi-circles --- aliases: - - revolutions - circle - circles - revs factor: 0.00277777777777778 type: angle unit: revolution +plural: revolutions --- aliases: - - newtons - n factor: 1 type: force unit: newton +plural: newtons --- aliases: - - kilonewtons - kn factor: 0.001 type: force -unit: kilonewton +unit: kilonewtons +plural: kilonewtons --- aliases: - - meganewtons - mn factor: 1e-06 type: force unit: meganewton +plural: meganewtons --- aliases: - - giganewtons - gn factor: 1e-09 type: force unit: giganewton +plural: giganewtons --- -aliases: - - dynes +aliases: [] factor: 1e-05 type: force unit: dyne +plural: dynes --- -aliases: - - kilodynes +aliases: [] factor: 0.01 type: force unit: kilodyne +plural: kildynes --- -aliases: - - megadynes +aliases: [] factor: 10 type: force unit: megadyne +plural: megadynes --- aliases: - lbs force - - pounds force + - lb force factor: 0.224808943099711 type: force -unit: pounds force +unit: pound force +plural: pounds force --- aliases: - - poundals - pdl factor: 7.23301385120989 type: force unit: poundal +plural: poundals --- aliases: - f @@ -1071,6 +1145,7 @@ can_be_negative: 1 factor: 1 type: temperature unit: fahrenheit +plural: fahrenheit --- aliases: - c @@ -1079,18 +1154,21 @@ can_be_negative: 1 factor: 1 type: temperature unit: celsius +plural: celsius --- aliases: - k factor: 1 type: temperature unit: kelvin +plural: kelvin --- aliases: - r factor: 1 type: temperature unit: rankine +plural: rankine --- aliases: - re @@ -1098,274 +1176,275 @@ can_be_negative: 1 factor: 1 type: temperature unit: reaumur +plural: reamur --- -aliases: - - bits +aliases: [] factor: 1 type: digital unit: bit +plural: bits --- aliases: - kbit - kbits - - kilobits factor: 0.001 type: digital unit: kilobit +plural: kilobits --- aliases: - mbit - mbits - - megabits factor: 1e-06 type: digital unit: megabit +plural: megabits --- aliases: - gbit - - gigabits - gbits factor: 1e-09 type: digital unit: gigabit +plural: gigabits --- aliases: - tbit - tbits - - terabits factor: 1e-12 type: digital unit: terabit +plural: terabits --- aliases: - pbit - pbits - - petabits factor: 1e-15 type: digital unit: petabit +plural: petabits --- aliases: - ebit - ebits - - exabits factor: 1e-18 type: digital unit: exabit +plural: exabits --- aliases: - zbit - zbits - - zettabits factor: 1e-21 type: digital unit: zettabit +plural: zettabits --- aliases: - ybit - ybits - - yottabits factor: 1e-24 type: digital unit: yottabit +plural: yottabits --- aliases: - kibit - kibits - - kibibits factor: 0.0009765625 type: digital unit: kibibit +plural: kibibits --- aliases: - mibit - mibits - - mebibits factor: 9.5367431640625e-07 type: digital unit: mebibit +plural: mebibits --- aliases: - gibit - gibits - - gibibits factor: 9.31322574615479e-10 type: digital unit: gibibit +plural: gibibits --- aliases: - tibit - tibits - - tebibits factor: 9.09494701772928e-13 type: digital unit: tebibit +plural: tebibits --- aliases: - pibit - pibits - - pebibits factor: 8.88178419700125e-16 type: digital unit: pebibit +plural: pebibits --- aliases: - eibit - eibits - - exbibits factor: 8.67361737988404e-19 type: digital unit: exbibit +plural: exbibits --- aliases: - zibit - zibits - - zebibits factor: 8.470329472543e-22 type: digital unit: zebibit +plural: zebibits --- aliases: - yibit - yibits - - yobibits factor: 8.27180612553028e-25 type: digital unit: yobibit +plural: yobibits --- -aliases: - - bytes +aliases: [] factor: 0.125 type: digital unit: byte +plural: bytes --- aliases: - kb - kbs - - kilobytes factor: 0.000125 type: digital unit: kilobyte +plural: kilobytes --- aliases: - mb - mbs - - megabytes factor: 1.25e-07 type: digital unit: megabyte +plural: megabytes --- aliases: - gb - gbs - - gigabytes factor: 1.25e-10 type: digital unit: gigabyte +plural: gigabytes --- aliases: - tb - tbs - - terabytes factor: 1.25e-13 type: digital unit: terabyte +plural: terabytes --- aliases: - pb - pbs - - petabytes factor: 1.25e-16 type: digital unit: petabyte +plural: petabytes --- aliases: - eb - ebs - - exabytes factor: 1.25e-19 type: digital unit: exabyte +plural: exabytes --- aliases: - zb - zbs - - zettabytes factor: 1.25e-22 type: digital unit: zettabyte +plural: zettabytes --- aliases: - yb - ybs - - yottabytes factor: 1.25e-25 type: digital unit: yottabyte +plural: yottabytes --- aliases: - kib - kibs - - kibibytes factor: 0.0001220703125 type: digital unit: kibibyte +plural: kibibytes --- aliases: - mib - mibs - - mebibytes factor: 1.19209289550781e-07 type: digital unit: mebibyte +plural: mebibytes --- aliases: - gib - gibs - - gibibytes factor: 1.16415321826935e-10 type: digital unit: gibibyte +plural: gibibytes --- aliases: - tib - tibs - - tebibytes factor: 1.13686837721616e-13 type: digital unit: tebibyte +plural: tebibytes --- aliases: - pib - pibs - - pebibytes factor: 1.11022302462516e-16 type: digital unit: pebibyte +plural: pebibytes --- aliases: - eib - eibs - - exbibytes factor: 1.0842021724855e-19 type: digital unit: exbibyte +plural: exbibytes --- aliases: - zib - zibs - - zebibytes factor: 1.05879118406788e-22 type: digital unit: zebibyte +plural: zebibytes --- aliases: - yib - yibs - - yobibytes factor: 1.03397576569129e-25 type: digital unit: yobibyte +plural: yobibytes --- aliases: - mi/h @@ -1375,6 +1454,7 @@ aliases: factor: 2.236941851939304 type: speed unit: mph +plural: mph --- aliases: - meters per second @@ -1389,6 +1469,7 @@ aliases: factor: 1 type: speed unit: m/s +plural: m/s --- aliases: - feet per second @@ -1403,6 +1484,7 @@ aliases: factor: 3.280839895013123 type: speed unit: ft/s +plural: ft/s --- aliases: - kilometer per hour @@ -1414,11 +1496,12 @@ aliases: factor: 3.6 type: speed unit: km/h +plural: km/h --- aliases: - - knots - kt - nmi/h factor: 1.943844492440605 type: speed unit: knot +plural: knots diff --git a/share/goodie/zapp_brannigan/content.handlebars b/share/goodie/zapp_brannigan/content.handlebars new file mode 100644 index 000000000..b2f25cf9e --- /dev/null +++ b/share/goodie/zapp_brannigan/content.handlebars @@ -0,0 +1 @@ +

{{{content}}}

\ No newline at end of file diff --git a/t/ABC.t b/t/ABC.t index 0d4601bdb..759095b78 100755 --- a/t/ABC.t +++ b/t/ABC.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'choice'; @@ -12,7 +13,7 @@ sub create_structured_answer { my $data = shift; return { - data => $data, #'-ANY-', + data => $data, #ignore(), templates => { group => 'text', moreAt => 0 @@ -30,28 +31,28 @@ ddg_goodie_test( 'choose his or or her house' => undef, 'choose from products like turkey or venison' => undef, 'choose pick or axe' => test_zci( - qr/(pick|axe) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(pick|axe) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'choose yes or no' => test_zci( - qr/(yes|no) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(yes|no) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'choose this or that or none' => test_zci( - qr/(this|that|none) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(this|that|none) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'pick this or that or none' => test_zci( - qr/(this|that|none) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(this|that|none) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'select heads or tails' => test_zci( - qr/(heads|tails) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(heads|tails) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'choose heads or tails' => test_zci( - qr/(heads|tails) \(Random\)/, - structured_answer => create_structured_answer('-ANY-') + re(qr/(heads|tails) \(Random\)/), + structured_answer => create_structured_answer(ignore()) ), 'choose duckduckgo or google or bing or something' => test_zci( 'duckduckgo (Non-random)', @@ -70,4 +71,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/AltCalendars.t b/t/AltCalendars.t index c38016a41..876e33b15 100644 --- a/t/AltCalendars.t +++ b/t/AltCalendars.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'date_conversion'; diff --git a/t/Anagram.t b/t/Anagram.t index 54d158988..562a55ccc 100644 --- a/t/Anagram.t +++ b/t/Anagram.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'anagram'; diff --git a/t/AspectRatio.t b/t/AspectRatio.t index a5df07e7a..c4f2a466a 100644 --- a/t/AspectRatio.t +++ b/t/AspectRatio.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'aspect_ratio'; diff --git a/t/Atbash.t b/t/Atbash.t index dabe896b5..b84b9a7ac 100755 --- a/t/Atbash.t +++ b/t/Atbash.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'atbash'; diff --git a/t/Average.t b/t/Average.t index 48afc131a..ea25210ab 100644 --- a/t/Average.t +++ b/t/Average.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'average'; @@ -42,4 +43,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/BPMToMs.t b/t/BPMToMs.t index 97402e616..3314f1a51 100644 --- a/t/BPMToMs.t +++ b/t/BPMToMs.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "bpmto_ms"; @@ -30,49 +31,49 @@ ddg_goodie_test( "120 beats per minute to ms" => test_zci( $plaintext_120, structured_answer => { - data => '-ANY-', + data => ignore(), # [ # { # note_type => "Whole Note", # triplet => 1333, # dotted => 3000, # milliseconds => 2000, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "Half Note", # triplet => 667, # dotted => 1500, # milliseconds => 1000, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "Quarter Note", # triplet => 333, # dotted => 750, # milliseconds => 500, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/8 Note", # triplet => 167, # dotted => 375, # milliseconds => 250, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/16 Note", # triplet => 83, # dotted => 188, # milliseconds => 125, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/32 Note", # triplet => 42, # dotted => 94, # milliseconds => 63, -# image => qr/.*/ +# image => re(qr/.*/) # } # ], meta => { @@ -92,49 +93,49 @@ ddg_goodie_test( "61 beats per minute to ms" => test_zci( $plaintext_61, structured_answer => { - data => '-ANY-', + data => ignore(), # [ # { # note_type => "Whole Note", # triplet => 2623, # dotted => 5902, # milliseconds => 3934, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "Half Note", # triplet => 1311, # dotted => 2951, # milliseconds => 1967, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "Quarter Note", # triplet => 656, # dotted => 1475, # milliseconds => 984, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/8 Note", # triplet => 328, # dotted => 738, # milliseconds => 492, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/16 Note", # triplet => 164, # dotted => 369, # milliseconds => 246, -# image => qr/.*/ +# image => re(qr/.*/) # }, # { # note_type => "1/32 Note", # triplet => 82, # dotted => 184, # milliseconds => 123, -# image => qr/.*/ +# image => re(qr/.*/) # } # ], meta => { diff --git a/t/BRT.t b/t/BRT.t index 9a90bb1ad..47557da8e 100644 --- a/t/BRT.t +++ b/t/BRT.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "brt"; diff --git a/t/Base.t b/t/Base.t index 24e282f42..d36921eaa 100644 --- a/t/Base.t +++ b/t/Base.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'conversion'; @@ -39,4 +40,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Base64.t b/t/Base64.t index 413a402b9..3e580a208 100644 --- a/t/Base64.t +++ b/t/Base64.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'base64_conversion'; diff --git a/t/BashPrimaryExpressions.t b/t/BashPrimaryExpressions.t index dbc107bd7..b03598adb 100644 --- a/t/BashPrimaryExpressions.t +++ b/t/BashPrimaryExpressions.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'expression_description'; @@ -12,7 +13,7 @@ ddg_goodie_test( 'DDG::Goodie::BashPrimaryExpressions' ], "bash [ -a b ]" => test_zci( - qr/.+ true if b exists./, + re(qr/.+ true if b exists./), structured_answer => { data => { intro => "[ -a b ]", @@ -39,9 +40,9 @@ ddg_goodie_test( } ), 'bash [[ "abc" < "cba" ]]' => test_zci( - qr/.+ true if "abc" string-sorts before "cba" in the current locale./, + re(qr/.+ true if "abc" string-sorts before "cba" in the current locale./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -52,9 +53,9 @@ ddg_goodie_test( } ), 'bash [ 2 -gt 1 ]' => test_zci( - qr/.+ true if 2 is numerically greater than 1./, + re(qr/.+ true if 2 is numerically greater than 1./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -65,9 +66,9 @@ ddg_goodie_test( } ), 'bash [ ! hello == world ]' => test_zci( - qr/.+ false if the strings hello and world are equal./, + re(qr/.+ false if the strings hello and world are equal./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -78,9 +79,9 @@ ddg_goodie_test( } ), 'bash [[ /tmp/hello -nt /etc/test ]]' => test_zci ( - qr#.+ true if /tmp/hello has been changed more recently than /etc/test or if /tmp/hello exists and /etc/test does not.#, + re(qr#.+ true if /tmp/hello has been changed more recently than /etc/test or if /tmp/hello exists and /etc/test does not.#), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -91,9 +92,9 @@ ddg_goodie_test( } ), 'bash [ -z hello ]' => test_zci( - qr/.+ true if the length of 'hello' is zero./, + re(qr/.+ true if the length of 'hello' is zero./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -104,9 +105,9 @@ ddg_goodie_test( } ), 'bash if [[ "abc" -lt "cba" ]]' => test_zci( - qr/.+ true if "abc" is numerically less than "cba"./, + re(qr/.+ true if "abc" is numerically less than "cba"./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, diff --git a/t/BeamMeUpScotty.t b/t/BeamMeUpScotty.t index f1a645a01..022b10c03 100644 --- a/t/BeamMeUpScotty.t +++ b/t/BeamMeUpScotty.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "beam_me_up_scotty"; diff --git a/t/Bin2Unicode.t b/t/Bin2Unicode.t index 5ff9bf030..da9f4c2e1 100644 --- a/t/Bin2Unicode.t +++ b/t/Bin2Unicode.t @@ -1,6 +1,7 @@ #!/usr/bin/env perl use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/Binary.t b/t/Binary.t index d4225b10c..625a38cc2 100644 --- a/t/Binary.t +++ b/t/Binary.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'binary_conversion'; diff --git a/t/BinaryLogic.t b/t/BinaryLogic.t index fbcb2d420..9a9e89b58 100755 --- a/t/BinaryLogic.t +++ b/t/BinaryLogic.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/BirthStone.t b/t/BirthStone.t index f819252bf..758fc3d00 100644 --- a/t/BirthStone.t +++ b/t/BirthStone.t @@ -3,53 +3,37 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "birth_stone"; zci is_cached => 1; +sub get_structured_answer { + my($month, $birthstone) = @_; + return $month . " birthstone: $birthstone", + structured_answer => { + data => { + title => $birthstone, + subtitle => 'Birthstone for '.$month + }, + templates => { + group => "text", + } + } +} + +sub build_test { + test_zci(get_structured_answer(@_)); +} + ddg_goodie_test( [qw( DDG::Goodie::BirthStone )], - 'april birth stone' => test_zci( - 'April birthstone: Diamond', - structured_answer => { - input => ['April'], - operation => 'Birthstone', - result => 'Diamond' - } - ), - 'birthstone JUNE' => test_zci( - 'June birthstone: Pearl', - structured_answer => { - input => ['June'], - operation => 'Birthstone', - result => 'Pearl' - } - ), - 'DecEmber birthstone' => test_zci( - 'December birthstone: Turquoise', - structured_answer => { - input => ['December'], - operation => 'Birthstone', - result => 'Turquoise' - } - ), - 'birthstone april' => test_zci( - 'April birthstone: Diamond', - structured_answer => { - input => ['April'], - operation => 'Birthstone', - result => 'Diamond' - } - ), - 'may birth stone' => test_zci( - 'May birthstone: Emerald', - structured_answer => { - input => ['May'], - operation => 'Birthstone', - result => 'Emerald' - } - ), + 'april birth stone' => build_test('April', 'Diamond'), + 'birthstone JUNE' => build_test('June', 'Pearl'), + 'DecEmber birthstone' => build_test('December', 'Turquoise'), + 'birthstone april' => build_test('April', 'Diamond'), + 'may birth stone' => build_test('May', 'Emerald') ); done_testing; diff --git a/t/Bitsum.t b/t/Bitsum.t index 9762c5155..17e61b97b 100644 --- a/t/Bitsum.t +++ b/t/Bitsum.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "bitsum"; diff --git a/t/BloodDonor.t b/t/BloodDonor.t index 7f326b865..cc75b7df7 100755 --- a/t/BloodDonor.t +++ b/t/BloodDonor.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "blood_donor"; diff --git a/t/Braille.t b/t/Braille.t index 1cf9054dc..7c2d7163a 100644 --- a/t/Braille.t +++ b/t/Braille.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Convert::Braille; use utf8; @@ -10,62 +11,37 @@ use utf8; zci answer_type => 'braille'; zci is_cached => 1; +sub build_structured_answer { + my ($query, $response) = @_; + return $response, + structured_answer => { + data => { + title => $response, + subtitle => 'Braille translation: ' . $query, + }, + templates => { + group => 'text', + } + }, +} + +sub build_test { test_zci(build_structured_answer(@_)) } + ddg_goodie_test( [qw( DDG::Goodie::Braille)], - 'hello in braille' => test_zci( - "⠓⠑⠇⠇⠕ (Braille)", - structured_answer => { - input => ['hello'], - operation => 'Braille translation', - result => '⠓⠑⠇⠇⠕' - } - ), - '⠓⠑⠇⠇⠕' => test_zci( - "hello (Braille)", - structured_answer => { - input => ['⠓⠑⠇⠇⠕'], - operation => 'Braille translation', - result => 'hello' - } - ), - 'translate to braille translate to braille' => test_zci( - "⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑ (Braille)", - structured_answer => { - input => ['translate to braille'], - operation => 'Braille translation', - result => - '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' - } - ), - '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' => test_zci( - "translate to braille (Braille)", - structured_answer => { - input => [ - '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' - ], - operation => 'Braille translation', - result => 'translate to braille' - } - - ), - 'braille asdf k' => test_zci( - "⠁⠎⠙⠋⠀⠅ (Braille)", - structured_answer => { - input => ['asdf k'], - operation => 'Braille translation', - result => '⠁⠎⠙⠋⠀⠅' - } - - ), - '⠁⠎⠙⠋⠀⠅' => test_zci( - "asdf k (Braille)", - structured_answer => { - input => ['⠁⠎⠙⠋⠀⠅'], - operation => 'Braille translation', - result => 'asdf k' - } - - ), + # Ascii/Unicode -> Braille + 'hello in braille' => build_test('hello', '⠓⠑⠇⠇⠕'), + 'hello to braille' => build_test('hello', '⠓⠑⠇⠇⠕'), + 'translate to braille to braille' => build_test('translate to braille', '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑'), + 'braille: asdf k' => build_test('asdf k', '⠁⠎⠙⠋⠀⠅'), + # Braille -> Ascii/Unicode + '⠓⠑⠀⠇⠇⠕' => build_test('⠓⠑⠀⠇⠇⠕', 'he llo'), + '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' => build_test('⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑', 'translate to braille'), + '⠁⠎⠙⠋⠀⠅' => build_test('⠁⠎⠙⠋⠀⠅', 'asdf k'), + # Invalid Queries + 'braille asdf k' => undef, + 'how long to learn braille' => undef, + 'braille to braille is good' => undef, ); done_testing; diff --git a/t/CaesarCipher.t b/t/CaesarCipher.t index e7eedede5..129e0b2e8 100644 --- a/t/CaesarCipher.t +++ b/t/CaesarCipher.t @@ -3,13 +3,14 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'caesar_cipher'; zci is_cached => 1; my $decode_response = { - data => '-ANY-', # We only need to check it is the right template. + data => ignore(), # We only need to check it is the right template. meta => { sourceUrl => 'https://en.wikipedia.org/wiki/Caesar_cipher', sourceName => 'Wikipedia', diff --git a/t/CalcRoots.t b/t/CalcRoots.t index ef1149ee8..974cc745f 100644 --- a/t/CalcRoots.t +++ b/t/CalcRoots.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'root'; diff --git a/t/Calculator.t b/t/Calculator.t index 86313a896..78c66a25b 100644 --- a/t/Calculator.t +++ b/t/Calculator.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use DDG::Goodie::Calculator; # For function subtests. use utf8; @@ -18,7 +19,7 @@ ddg_goodie_test( structured_answer => { input => ['2 - 2'], operation => 'Calculate', - result => qr/>0 re(qr/>0 test_zci( @@ -27,7 +28,7 @@ ddg_goodie_test( structured_answer => { input => ['2 + 2'], operation => 'Calculate', - result => qr/>4 re(qr/>4 test_zci( @@ -36,7 +37,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 8'], operation => 'Calculate', - result => qr/>256 re(qr/>256 test_zci( @@ -45,7 +46,7 @@ ddg_goodie_test( structured_answer => { input => ['2 * 7'], operation => 'Calculate', - result => qr/>14 re(qr/>14 test_zci( @@ -54,7 +55,7 @@ ddg_goodie_test( structured_answer => { input => ['4 * 5'], operation => 'Calculate', - result => qr/>20 re(qr/>20 test_zci( @@ -63,7 +64,7 @@ ddg_goodie_test( structured_answer => { input => ['6 * 7'], operation => 'Calculate', - result => qr/>42 re(qr/>42 test_zci( @@ -72,7 +73,7 @@ ddg_goodie_test( structured_answer => { input => ['3 * dozen'], operation => 'Calculate', - result => qr/>36 re(qr/>36 test_zci( @@ -81,7 +82,7 @@ ddg_goodie_test( structured_answer => { input => ['dozen / 4'], operation => 'Calculate', - result => qr/>3 re(qr/>3 test_zci( @@ -90,7 +91,7 @@ ddg_goodie_test( structured_answer => { input => ['1 dozen * 2'], operation => 'Calculate', - result => qr/>24 re(qr/>24 test_zci( @@ -99,7 +100,7 @@ ddg_goodie_test( structured_answer => { input => ['dozen + dozen'], operation => 'Calculate', - result => qr/>24 re(qr/>24 test_zci( @@ -108,7 +109,7 @@ ddg_goodie_test( structured_answer => { input => ['2 divided by 4'], operation => 'Calculate', - result => qr/>0.5 re(qr/>0.5 test_zci( @@ -117,7 +118,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 2'], operation => 'Calculate', - result => qr/>4 re(qr/>4 test_zci( @@ -126,7 +127,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 0.2'], operation => 'Calculate', - result => qr/>1\.14869835499704 re(qr/>1\.14869835499704 test_zci( @@ -135,7 +136,7 @@ ddg_goodie_test( structured_answer => { input => ['cos(0)'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -144,7 +145,7 @@ ddg_goodie_test( structured_answer => { input => ['tan(1)'], operation => 'Calculate', - result => qr/>1\.5574077246549 re(qr/>1\.5574077246549 test_zci( @@ -153,7 +154,7 @@ ddg_goodie_test( structured_answer => { input => ['tanh(1)'], operation => 'Calculate', - result => qr/>0\.761594155955765 re(qr/>0\.761594155955765 test_zci( @@ -162,7 +163,7 @@ ddg_goodie_test( structured_answer => { input => ['cotan(1)'], operation => 'Calculate', - result => qr/>0\.642092615934331 re(qr/>0\.642092615934331 test_zci( @@ -171,7 +172,7 @@ ddg_goodie_test( structured_answer => { input => ['sin(1)'], operation => 'Calculate', - result => qr/>0\.841470984807897 re(qr/>0\.841470984807897 test_zci( @@ -180,7 +181,7 @@ ddg_goodie_test( structured_answer => { input => ['csc(1)'], operation => 'Calculate', - result => qr/>1\.18839510577812 re(qr/>1\.18839510577812 test_zci( @@ -189,7 +190,7 @@ ddg_goodie_test( structured_answer => { input => ['sec(1)'], operation => 'Calculate', - result => qr/>1\.85081571768093 re(qr/>1\.85081571768093 test_zci( @@ -198,7 +199,7 @@ ddg_goodie_test( structured_answer => { input => ['log(3)'], operation => 'Calculate', - result => qr/>1\.09861228866811 re(qr/>1\.09861228866811 test_zci( @@ -207,7 +208,7 @@ ddg_goodie_test( structured_answer => { input => ['log(3)'], operation => 'Calculate', - result => qr/>1\.09861228866811 re(qr/>1\.09861228866811 test_zci( @@ -216,7 +217,7 @@ ddg_goodie_test( structured_answer => { input => ['log10(100.00)'], operation => 'Calculate', - result => qr/>2 re(qr/>2 test_zci( @@ -225,7 +226,7 @@ ddg_goodie_test( structured_answer => { input => ['log_10(100.00)'], operation => 'Calculate', - result => qr/>2 re(qr/>2 test_zci( @@ -234,7 +235,7 @@ ddg_goodie_test( structured_answer => { input => ['log_2(16)'], operation => 'Calculate', - result => qr/>4 re(qr/>4 test_zci( @@ -243,7 +244,7 @@ ddg_goodie_test( structured_answer => { input => ['log_23(25)'], operation => 'Calculate', - result => qr/>1\.0265928122321 re(qr/>1\.0265928122321 test_zci( @@ -252,7 +253,7 @@ ddg_goodie_test( structured_answer => { input => ['log23(25)'], operation => 'Calculate', - result => qr/>1\.0265928122321 re(qr/>1\.0265928122321 test_zci( @@ -261,7 +262,7 @@ ddg_goodie_test( structured_answer => { input => ['$3.43 + $34.45'], operation => 'Calculate', - result => qr/>\$37\.88 re(qr/>\$37\.88 test_zci( @@ -270,7 +271,7 @@ ddg_goodie_test( structured_answer => { input => ['$3.45 + $34.45'], operation => 'Calculate', - result => qr/>\$37\.90 re(qr/>\$37\.90 test_zci( @@ -279,7 +280,7 @@ ddg_goodie_test( structured_answer => { input => ['$3 + $34'], operation => 'Calculate', - result => qr/>\$37\.00 re(qr/>\$37\.00 test_zci( @@ -288,7 +289,7 @@ ddg_goodie_test( structured_answer => { input => ['$3,4 + $34,4'], operation => 'Calculate', - result => qr/>\$37,80 re(qr/>\$37,80 test_zci( @@ -297,7 +298,7 @@ ddg_goodie_test( structured_answer => { input => ['64 * 343'], operation => 'Calculate', - result => qr/>21,952 re(qr/>21,952 test_zci( @@ -306,7 +307,7 @@ ddg_goodie_test( structured_answer => { input => ['(1 * 10 ^ 2) + 1'], operation => 'Calculate', - result => qr/>101 re(qr/>101 test_zci( @@ -315,7 +316,7 @@ ddg_goodie_test( structured_answer => { input => ['1 + (1 * 10 ^ 2)'], operation => 'Calculate', - result => qr/>101 re(qr/>101 test_zci( @@ -324,7 +325,7 @@ ddg_goodie_test( structured_answer => { input => ['2 * 3 + (1 * 10 ^ 2)'], operation => 'Calculate', - result => qr/>106 re(qr/>106 test_zci( @@ -333,7 +334,7 @@ ddg_goodie_test( structured_answer => { input => ['(1 * 10 ^ 2) + 2 * 3'], operation => 'Calculate', - result => qr/>106 re(qr/>106 test_zci( @@ -342,7 +343,7 @@ ddg_goodie_test( structured_answer => { input => ['(1 * 10 ^ 2) / 2'], operation => 'Calculate', - result => qr/>50 re(qr/>50 test_zci( @@ -351,7 +352,7 @@ ddg_goodie_test( structured_answer => { input => ['2 / (1 * 10 ^ 2)'], operation => 'Calculate', - result => qr/>0\.02 re(qr/>0\.02 test_zci( @@ -360,7 +361,7 @@ ddg_goodie_test( structured_answer => { input => ['424334 + 2253828'], operation => 'Calculate', - result => qr/>2,678,162 re(qr/>2,678,162 test_zci( @@ -369,7 +370,7 @@ ddg_goodie_test( structured_answer => { input => ['4.243,34 + 22.538,28'], operation => 'Calculate', - result => qr/>26\.781,62 re(qr/>26\.781,62 test_zci( @@ -378,7 +379,7 @@ ddg_goodie_test( structured_answer => { input => ['sin(1,0) + 1,05'], operation => 'Calculate', - result => qr/>1,8914709848079 re(qr/>1,8914709848079 test_zci( @@ -387,7 +388,7 @@ ddg_goodie_test( structured_answer => { input => ['21 + 15 * 0 + 5'], operation => 'Calculate', - result => qr/>26 re(qr/>26 test_zci( @@ -396,7 +397,7 @@ ddg_goodie_test( structured_answer => { input => ['0.8158 - 0.8157'], operation => 'Calculate', - result => qr/>0\.0001 re(qr/>0\.0001 test_zci( @@ -405,7 +406,7 @@ ddg_goodie_test( structured_answer => { input => ['2,90 + 4,6'], operation => 'Calculate', - result => qr/>7,50 re(qr/>7,50 test_zci( @@ -414,7 +415,7 @@ ddg_goodie_test( structured_answer => { input => ['2,90 + sec(4,6)'], operation => 'Calculate', - result => qr/>-6,01642861135959 re(qr/>-6,01642861135959 test_zci( @@ -423,7 +424,7 @@ ddg_goodie_test( structured_answer => { input => ['100 - 96.54'], operation => 'Calculate', - result => qr/>3\.46 re(qr/>3\.46 test_zci( @@ -432,7 +433,7 @@ ddg_goodie_test( structured_answer => { input => ['1. + 1.'], operation => 'Calculate', - result => qr/>2 re(qr/>2 test_zci( @@ -441,7 +442,7 @@ ddg_goodie_test( structured_answer => { input => ['1 + sin(pi)'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -450,7 +451,7 @@ ddg_goodie_test( structured_answer => { input => ['1 - 1'], operation => 'Calculate', - result => qr/>0 re(qr/>0 test_zci( @@ -459,7 +460,7 @@ ddg_goodie_test( structured_answer => { input => ['sin(pi / 2)'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -468,7 +469,7 @@ ddg_goodie_test( structured_answer => { input => ['sin(pi)'], operation => 'Calculate', - result => qr/>0 re(qr/>0 test_zci( @@ -477,7 +478,7 @@ ddg_goodie_test( structured_answer => { input => ['cos(2 pi)'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -486,7 +487,7 @@ ddg_goodie_test( structured_answer => { input => ['5 ^ 2'], operation => 'Calculate', - result => qr/>25 re(qr/>25 test_zci( @@ -495,7 +496,7 @@ ddg_goodie_test( structured_answer => { input => ['sqrt(4)'], operation => 'Calculate', - result => qr/>2 re(qr/>2 test_zci( @@ -504,7 +505,7 @@ ddg_goodie_test( structured_answer => { input => ['1.0 + 5 ^ 2'], operation => 'Calculate', - result => qr/>26 re(qr/>26 test_zci( @@ -513,7 +514,7 @@ ddg_goodie_test( structured_answer => { input => ['3 ^ 2 + 4 ^ 2'], operation => 'Calculate', - result => qr/>25 re(qr/>25 test_zci( @@ -522,7 +523,7 @@ ddg_goodie_test( structured_answer => { input => ['2,2 ^ 2'], operation => 'Calculate', - result => qr/>4,84 re(qr/>4,84 test_zci( @@ -531,7 +532,7 @@ ddg_goodie_test( structured_answer => { input => ['0.8 ^ 2 + 0.6 ^ 2'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -540,7 +541,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 2 ^ 3'], operation => 'Calculate', - result => qr/>256 re(qr/>256 test_zci( @@ -549,7 +550,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 2 ^ 3.06'], operation => 'Calculate', - result => qr/>323\.972172143725 re(qr/>323\.972172143725 test_zci( @@ -558,7 +559,7 @@ ddg_goodie_test( structured_answer => { input => ['2 ^ 3 ^ 2'], operation => 'Calculate', - result => qr/>512 re(qr/>512 test_zci( @@ -567,7 +568,7 @@ ddg_goodie_test( structured_answer => { input => ['sqrt(2)'], operation => 'Calculate', - result => qr/>1\.4142135623731 re(qr/>1\.4142135623731 test_zci( @@ -576,7 +577,7 @@ ddg_goodie_test( structured_answer => { input => ['sqrt(3 pi / 4 + 1) + 1'], operation => 'Calculate', - result => qr/>2\.83199194599549 re(qr/>2\.83199194599549 test_zci( @@ -585,7 +586,7 @@ ddg_goodie_test( structured_answer => { input => ['4 score + 7'], operation => 'Calculate', - result => qr/>87 re(qr/>87 test_zci( @@ -594,7 +595,7 @@ ddg_goodie_test( structured_answer => { input => ['418.1 / 2'], operation => 'Calculate', - result => qr/>209\.05 re(qr/>209\.05 test_zci( @@ -603,7 +604,7 @@ ddg_goodie_test( structured_answer => { input => ['418.005 / 8'], operation => 'Calculate', - result => qr/>52\.250625 re(qr/>52\.250625 test_zci( @@ -612,7 +613,7 @@ ddg_goodie_test( structured_answer => { input => ['(pi ^ 4 + pi ^ 5) ^ (1 / 6)'], operation => 'Calculate', - result => qr/>2\.71828180861191 re(qr/>2\.71828180861191 test_zci( @@ -621,7 +622,7 @@ ddg_goodie_test( structured_answer => { input => ['(pi ^ 4 + pi ^ 5) ^ (1 / 6) + 1'], operation => 'Calculate', - result => qr/>3\.71828180861191 re(qr/>3\.71828180861191 test_zci( @@ -630,7 +631,7 @@ ddg_goodie_test( structured_answer => { input => ['5 ^ 4 ^ (3 - 2) ^ 1'], operation => 'Calculate', - result => qr/>625 re(qr/>625 test_zci( @@ -639,7 +640,7 @@ ddg_goodie_test( structured_answer => { input => ['(5 - 4) ^ (3 - 2) ^ 1'], operation => 'Calculate', - result => qr/>1 re(qr/>1 test_zci( @@ -648,7 +649,7 @@ ddg_goodie_test( structured_answer => { input => ['(5 + 4 - 3) ^ (2 - 1)'], operation => 'Calculate', - result => qr/>6 re(qr/>6 test_zci( @@ -657,7 +658,7 @@ ddg_goodie_test( structured_answer => { input => ['5 ^ ((4 - 3) * (2 + 1)) + 6'], operation => 'Calculate', - result => qr/>131 re(qr/>131 test_zci( @@ -666,7 +667,7 @@ ddg_goodie_test( structured_answer => { input => ['20 * 07'], operation => 'Calculate', - result => qr/>140 re(qr/>140 test_zci( @@ -675,7 +676,7 @@ ddg_goodie_test( structured_answer => { input => ['83.166.167.160 / 33'], operation => 'Calculate', - result => qr/>2\.520\.186\.883,63636 re(qr/>2\.520\.186\.883,63636 test_zci( @@ -684,7 +685,7 @@ ddg_goodie_test( structured_answer => { input => ['123.123.123.123 / 255.255.255.256'], operation => 'Calculate', - result => qr/>0,482352941174581 re(qr/>0,482352941174581 test_zci( @@ -693,7 +694,7 @@ ddg_goodie_test( structured_answer => { input => ['(4 * 10 ^ 5) + 1'], operation => 'Calculate', - result => qr/>400,001 re(qr/>400,001 test_zci( @@ -702,7 +703,7 @@ ddg_goodie_test( structured_answer => { input => ['(4 * 10 ^ 5) + 1'], operation => 'Calculate', - result => qr/>400,001 re(qr/>400,001 test_zci( @@ -711,7 +712,7 @@ ddg_goodie_test( structured_answer => { input => ['(3 * 10 ^- 2) * 9'], operation => 'Calculate', - result => qr/>0.27 re(qr/>0.27 test_zci( @@ -720,7 +721,7 @@ ddg_goodie_test( structured_answer => { input => ['(7 * 10 ^- 4) * 8'], operation => 'Calculate', - result => qr/>0.0056 re(qr/>0.0056 test_zci( @@ -729,7 +730,7 @@ ddg_goodie_test( structured_answer => { input => ['6 * (2 * 10 ^- 11)'], operation => 'Calculate', - result => qr/>1\.2 \* 10-10<\/sup> re(qr/>1\.2 \* 10-10<\/sup> test_zci( @@ -738,7 +739,7 @@ ddg_goodie_test( structured_answer => { input => ['7 + (7 * 10 ^- 7)'], operation => 'Calculate', - result => qr/>7.0000007 re(qr/>7.0000007 test_zci( @@ -747,7 +748,7 @@ ddg_goodie_test( structured_answer => { input => ['1 * 7 + e - 7'], operation => 'Calculate', - result => qr/>2.71828182845905 re(qr/>2.71828182845905 test_zci( @@ -756,7 +757,7 @@ ddg_goodie_test( structured_answer => { input => ['7 * e - 5'], operation => 'Calculate', - result => qr/>14.0279727992134 re(qr/>14.0279727992134 test_zci( @@ -765,7 +766,7 @@ ddg_goodie_test( structured_answer => { input => ['pi / (1 * 10 ^ 9)'], operation => 'Calculate', - result => qr/>3\.14159265358979 \* 10-9<\/sup> re(qr/>3\.14159265358979 \* 10-9<\/sup> test_zci( @@ -774,7 +775,7 @@ ddg_goodie_test( structured_answer => { input => ['pi * (1 * 10 ^ 9)'], operation => 'Calculate', - result => qr/>3,141,592,653\.58979 re(qr/>3,141,592,653\.58979 test_zci( @@ -783,7 +784,7 @@ ddg_goodie_test( structured_answer => { input => ['1234 + 5432'], operation => 'Calculate', - result => qr/6,666/ + result => re(qr/6,666/) } ), '1_234 + 5_432' => test_zci( @@ -792,7 +793,7 @@ ddg_goodie_test( structured_answer => { input => ['1234 + 5432'], operation => 'Calculate', - result => qr/6,666/ + result => re(qr/6,666/) } ), '(0.4e^(0))*cos(0)' => test_zci( @@ -801,7 +802,7 @@ ddg_goodie_test( structured_answer => { input => ['(0.4e ^ (0)) * cos(0)'], operation => 'Calculate', - result => qr'0.4' + result => re(qr'0.4') } ), '2pi' => test_zci( @@ -810,7 +811,7 @@ ddg_goodie_test( structured_answer => { input => ['2 pi'], operation => 'Calculate', - result => qr"6.28318530717958" + result => re(qr"6.28318530717958") } ), 'fact(3)' => test_zci( @@ -819,7 +820,7 @@ ddg_goodie_test( structured_answer => { input => ['fact(3)'], operation => 'Calculate', - result => qr/>6 re(qr/>6 test_zci( @@ -828,7 +829,7 @@ ddg_goodie_test( structured_answer => { input => ['fact(3)'], operation => 'Calculate', - result => qr/>6 re(qr/>6 undef, diff --git a/t/CalendarConversion.t b/t/CalendarConversion.t index 059a0cdb2..be92dd615 100644 --- a/t/CalendarConversion.t +++ b/t/CalendarConversion.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'calendar_conversion'; diff --git a/t/CalendarToday.t b/t/CalendarToday.t index 8fd3a0ab1..6c33fa98a 100755 --- a/t/CalendarToday.t +++ b/t/CalendarToday.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); @@ -14,9 +15,9 @@ ddg_goodie_test( DDG::Goodie::CalendarToday )], 'calendar' => test_zci( - qr/\nS M T W T F S[ ]+[A-Za-z]+ [0-9]{4}\n.+/, + re(qr/\nS M T W T F S[ ]+[A-Za-z]+ [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -27,9 +28,9 @@ ddg_goodie_test( } ), 'calendar november' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -40,9 +41,9 @@ ddg_goodie_test( } ), 'calendar november 12th' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -53,9 +54,9 @@ ddg_goodie_test( } ), 'calendar last november' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -66,9 +67,9 @@ ddg_goodie_test( } ), 'calendar next november' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -217,7 +218,7 @@ S M T W T F S November 2009 29 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -236,7 +237,7 @@ S M T W T F S November 2015 |29| 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -255,7 +256,7 @@ S M T W T F S November 2015 |29| 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -275,7 +276,7 @@ S M T W T F S November 1980 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -294,7 +295,7 @@ S M T W T F S November 2009 29 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -305,9 +306,9 @@ S M T W T F S November 2009 } ), 'next november on a calendar' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -318,9 +319,9 @@ S M T W T F S November 2009 } ), 'calendar for november' => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -339,7 +340,7 @@ S M T W T F S November 2009 29 30 ", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -351,9 +352,9 @@ S M T W T F S November 2009 ), '22/8/2003 to the hijri calendar' => undef, "today's calendar" => test_zci( - qr/\nS M T W T F S [A-Z][a-z]+ [0-9]{4}\n.+/, + re(qr/\nS M T W T F S [A-Z][a-z]+ [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -364,9 +365,9 @@ S M T W T F S November 2009 } ), "november's calendar" => test_zci( - qr/\nS M T W T F S November [0-9]{4}\n.+/, + re(qr/\nS M T W T F S November [0-9]{4}\n.+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -379,14 +380,14 @@ S M T W T F S November 2009 ); # Special focus on relative dates, examining the "today" circle -my $test_location_tz = qr/\(EDT, UTC-4\)/; +my $test_location_tz = re(qr/\(EDT, UTC-4\)/); set_fixed_time("2014-06-11T09:45:56"); ddg_goodie_test( [qw( DDG::Goodie::CalendarToday )], "calendar yesterday" => test_zci( - qr/June 2014.*\|10\|/s, + re(qr/June 2014.*\|10\|/s), structured_answer => { data => { month_year => "June 2014", @@ -445,7 +446,7 @@ ddg_goodie_test( } ), "calendar today" => test_zci( - qr/June 2014.*\|11\|/s, + re(qr/June 2014.*\|11\|/s), structured_answer => { data => { month_year => "June 2014", @@ -504,7 +505,7 @@ ddg_goodie_test( } ), "calendar tomorrow" => test_zci( - qr/June 2014.*\|12\|/s, + re(qr/June 2014.*\|12\|/s), structured_answer => { data => { month_year => "June 2014", @@ -563,7 +564,7 @@ ddg_goodie_test( } ), "calendar 20 days ago" => test_zci( - qr/May 2014.*\|22\|/s, + re(qr/May 2014.*\|22\|/s), structured_answer => { data => { month_year => "May 2014", @@ -627,7 +628,7 @@ ddg_goodie_test( } ), "calendar in 20 days" => test_zci( - qr/July 2014.*\| 1\|/s, + re(qr/July 2014.*\| 1\|/s), structured_answer => { data => { month_year => "July 2014", @@ -689,7 +690,7 @@ ddg_goodie_test( } ), "calendar last week" => test_zci( - qr/June 2014.*\| 4\|/s, + re(qr/June 2014.*\| 4\|/s), structured_answer => { data => { month_year => "June 2014", @@ -748,7 +749,7 @@ ddg_goodie_test( } ), "calendar next week" => - test_zci(qr/June 2014.*\|18\|/s, + test_zci(re(qr/June 2014.*\|18\|/s), structured_answer => { data => { month_year => "June 2014", @@ -807,7 +808,7 @@ ddg_goodie_test( } ), "calendar last year" => - test_zci(qr/June 2013.*\|11\|/s, + test_zci(re(qr/June 2013.*\|11\|/s), structured_answer => { data => { month_year => "June 2013", @@ -874,7 +875,7 @@ ddg_goodie_test( } ), "calendar next year" => - test_zci(qr/June 2015.*\|11\|/s, + test_zci(re(qr/June 2015.*\|11\|/s), structured_answer => { data => { month_year => "June 2015", @@ -937,4 +938,3 @@ ddg_goodie_test( restore_time(); done_testing; - diff --git a/t/CallingCodes.t b/t/CallingCodes.t index eff0e6b86..ba16a1aba 100644 --- a/t/CallingCodes.t +++ b/t/CallingCodes.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "calling_codes"; diff --git a/t/CamelCase.t b/t/CamelCase.t index ebff437f1..3151f19a0 100644 --- a/t/CamelCase.t +++ b/t/CamelCase.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "camel_case"; diff --git a/t/Chars.t b/t/Chars.t index 8ec7f022c..10f977bd5 100644 --- a/t/Chars.t +++ b/t/Chars.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'chars'; @@ -103,4 +104,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/CheatSheets/CheatSheetsJSON.t b/t/CheatSheets/CheatSheetsJSON.t index 4b3384b7f..6b2f1d038 100755 --- a/t/CheatSheets/CheatSheetsJSON.t +++ b/t/CheatSheets/CheatSheetsJSON.t @@ -13,6 +13,7 @@ use IO::All; use List::Util qw(first none all any max); use YAML::XS qw(LoadFile); use File::Find::Rule; +use DDG::Meta::Data; my $json_dir = "share/goodie/cheat_sheets/json"; @@ -40,6 +41,7 @@ sub id_to_file_name { sub check_aliases_for_triggers { my ($aliases, $trigger_types) = @_; my @aliases = @$aliases; + my %bad_aliases; while (my ($trigger_type, $triggers) = each %{$trigger_types}) { my @triggers = @$triggers; foreach my $alias (@aliases) { @@ -50,11 +52,32 @@ sub check_aliases_for_triggers { || ($trigger_type =~ /end$/ && ($trigger = first { $alias =~ /$_$/ } @triggers)) ) { - return ($alias, $trigger); + $bad_aliases{$alias} = $trigger; } } } - return; + return %bad_aliases; +} + +sub check_aliases_for_ignore { + my ($aliases, $ignore) = @_; + my @ignore = @$ignore; + my %bad_aliases; + foreach my $alias (@$aliases) { + if (my $contained_ignore = first { $alias =~ $_ } @ignore) { + $bad_aliases{$alias} = $ignore; + } + } + return %bad_aliases; +} + +sub verify_meta { + my $json = shift; + my @tests; + my $id = $json->{id}; + my $meta = DDG::Meta::Data->get_ia(id => $id); + push(@tests, {msg => "No Instant Answer page found with ID '$id'", critical => 1, pass => defined $meta}); + return @tests; } my @fnames = @ARGV ? map { "$_.json" } @ARGV : ("*.json"); @@ -62,8 +85,16 @@ my @test_paths = File::Find::Rule->file()->name(@fnames)->in($json_dir); my $max_name_len = max map { $_ =~ /.+\/(.+)\.json$/; length $1 } @test_paths; +sub cmp_base { + $a =~ qr{/([^/]+)$}; + my $base1 = $1; + $b =~ qr{/([^/]+)$}; + my $base2 = $1; + return $base1 cmp $base2; +} + # Iterate over all Cheat Sheet JSON files... -foreach my $path (@test_paths) { +foreach my $path (sort { cmp_base } @test_paths) { my ($file_name) = $path =~ /$json_dir\/(.+)/; my ($name) = $path =~ /.+\/(.+)\.json$/; @@ -136,13 +167,22 @@ foreach my $path (@test_paths) { # Make sure aliases don't contain any category triggers. while (my ($category, $trigger_types) = each %{$triggers_yaml->{categories}}) { my $critical = $categories{$category}; - if (my ($alias, $trigger) = check_aliases_for_triggers(\@aliases, $trigger_types)) { + my %bad_aliases = check_aliases_for_triggers(\@aliases, $trigger_types); + while (my ($alias, $trigger) = each %bad_aliases) { push(@tests, {msg => "Alias ($alias) contains a trigger ($trigger) defined in the '$category' category", critical => $critical}); } + # Critical if they have aliases that contain ignored phrases. + if ($critical and my $ignored = $trigger_types->{ignore}) { + my %bad_aliases = check_aliases_for_ignore(\@aliases, $ignored); + while (my ($alias, $ignore) = each %bad_aliases) { + push (@tests, {msg => "Alias ($alias) contains a phrase ($ignore) that is ignored and may be omitted", critical => 1}); + } + } } # Make sure aliases don't contain any custom triggers for the cheat sheet. if (my $custom = $triggers_yaml->{custom_triggers}{$cheat_id}) { - if (my ($alias, $trigger) = check_aliases_for_triggers(\@aliases, $custom)) { + my %bad_aliases = check_aliases_for_triggers(\@aliases, $custom); + while (my ($alias, $trigger) = each %bad_aliases) { push(@tests, {msg => "Alias ($alias) contains a custom trigger ($trigger)", critical => 1}); } } @@ -224,6 +264,8 @@ foreach my $path (@test_paths) { } } + push @tests, verify_meta($json); + PRINT_RESULTS: my $result = print_results($name, \@tests); diff --git a/t/Chess960.t b/t/Chess960.t index 8831bf2eb..d8f26bae3 100644 --- a/t/Chess960.t +++ b/t/Chess960.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'chess960_position'; @@ -15,7 +16,7 @@ ddg_goodie_test( 'chess960 random' => test_zci( 'Chess 960', structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => "text", item => 0, @@ -28,4 +29,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/ChineseZodiac.t b/t/ChineseZodiac.t index 39b2f3f95..e1d71f598 100644 --- a/t/ChineseZodiac.t +++ b/t/ChineseZodiac.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::MockTime qw( :all ); use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -132,4 +133,3 @@ ddg_goodie_test( restore_time(); done_testing; - diff --git a/t/CoffeeToWaterRatio.t b/t/CoffeeToWaterRatio.t index 575717f22..8eb165c35 100644 --- a/t/CoffeeToWaterRatio.t +++ b/t/CoffeeToWaterRatio.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "coffee_to_water_ratio"; diff --git a/t/Coin.t b/t/Coin.t index 7c64ed250..e3f5baccb 100644 --- a/t/Coin.t +++ b/t/Coin.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'coin'; @@ -11,83 +12,83 @@ zci is_cached => 0; ddg_goodie_test( [qw( DDG::Goodie::Coin )], 'flip a coin' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'flip coin' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'flip 1 coin' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'flip 2 coins' => test_zci( - qr/(heads|tails), (heads|tails) \(random\)/, + re(qr/(heads|tails), (heads|tails) \(random\)/), structured_answer => { input => [2], operation => 'Flip coin', - result => qr/(heads|tails), / + result => re(qr/(heads|tails), /) } ), 'toss a coin' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'toss 1 coin' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'toss 2 coins' => test_zci( - qr/(heads|tails), (heads|tails) \(random\)/, + re(qr/(heads|tails), (heads|tails) \(random\)/), structured_answer => { input => [2], operation => 'Flip coin', - result => qr/(heads|tails), / + result => re(qr/(heads|tails), /) } ), 'heads or tails' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'heads or tails?' => test_zci( - qr/(heads|tails) \(random\)/, + re(qr/(heads|tails) \(random\)/), structured_answer => { input => [1], operation => 'Flip coin', - result => qr/^(heads|tails)$/ + result => re(qr/^(heads|tails)$/) } ), 'flip 4 coins' => test_zci( - qr/((heads|tails),? ){4}\(random\)/, + re(qr/((heads|tails),? ){4}\(random\)/), structured_answer => { input => [4], operation => 'Flip coin', - result => qr/(heads|tails),? / + result => re(qr/(heads|tails),? /) } ), ); diff --git a/t/ColorCodes.t b/t/ColorCodes.t index da241cc03..f5fc64b89 100755 --- a/t/ColorCodes.t +++ b/t/ColorCodes.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'color_code'; @@ -13,7 +14,7 @@ my $green_answer = 'Hex: #00FF00 ~ RGBA(0, 255, 0, 1) ~ RGB(0%, 100%, 0%) ~ HSL( my %basic_answer = ( structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -110,4 +111,4 @@ ddg_goodie_test( 'wield color' => undef, ); -done_testing; \ No newline at end of file +done_testing; diff --git a/t/Combination.t b/t/Combination.t old mode 100644 new mode 100755 index 36e31e79e..b90bace60 --- a/t/Combination.t +++ b/t/Combination.t @@ -3,55 +3,35 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "combination"; zci is_cached => 1; +sub build_test +{ + my ($answer, $question) = @_; + return test_zci( + $answer, structured_answer => { + data => { + title => $answer, + subtitle => $question + }, + templates => { + group => 'text' + } + } + ); +} ddg_goodie_test( [qw( DDG::Goodie::Combination )], - '10 choose 3' => test_zci('120', - structured_answer => { - input => ['10 choose 3'], - operation => 'Calculate', - result => '120', - } - ), - '10 nCr 3' => test_zci('120', - structured_answer => { - input => ['10 choose 3'], - operation => 'Calculate', - result => '120', - } - ), - '25 permute 16' => test_zci('4.27447366714368 * 10^19', - structured_answer => { - input => ['25 permute 16'], - operation => 'Calculate', - result => '4.27447366714368 * 10^19' - } - ), - '16 permutation 3' => test_zci('3,360', - structured_answer => { - input => ['16 permute 3'], - operation => 'Calculate', - result => '3,360' - } - ), - '15 permutation 0' => test_zci('1', - structured_answer => { - input => ['15 permute 0'], - operation => 'Calculate', - result => '1' - } - ), - '1,000 choose 2' => test_zci('499,500', - structured_answer => { - input => ['1,000 choose 2'], - operation => 'Calculate', - result => '499,500' - } - ), + '10 choose 3' => build_test('120', '10 choose 3'), + '10 nCr 3' => build_test('120', '10 choose 3'), + '25 permute 16' => build_test('4.27447366714368 * 10^19', '25 permute 16'), + '16 permutation 3' => build_test('3,360', '16 permute 3'), + '15 permutation 0' => build_test('1', '15 permute 0'), + '1,000 choose 2' => build_test('499,500', '1,000 choose 2'), '0 choose 100' => undef, '10 choose 100' => undef, '10.5 choose 1' => undef, diff --git a/t/Constants.t b/t/Constants.t index c2a743637..95ceb80be 100644 --- a/t/Constants.t +++ b/t/Constants.t @@ -4,6 +4,7 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "constants"; diff --git a/t/Conversions.t b/t/Conversions.t index 7411f0b92..39acabdae 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; zci answer_type => 'conversions'; @@ -359,6 +360,18 @@ ddg_goodie_test( physical_quantity => 'pressure' }) ), + '0.01933677566613741911668448550544 psi in mmHg' => test_zci( + '0.01933677566613741911668448550544 pounds per square inch = 1 mmHg', + structured_answer => make_answer({ + markup_input => '0.01933677566613741911668448550544', + raw_input => '0.01933677566613741911668448550544', + from_unit => 'pounds per square inch', + styled_output => '1', + raw_answer => '1', + to_unit => 'mmHg', + physical_quantity => 'pressure' + }) + ), '2 thou to mm' => test_zci( '2 thousandths of an inch = 0.051 millimeters', structured_answer => make_answer({ @@ -599,6 +612,18 @@ ddg_goodie_test( physical_quantity => 'energy' }) ), + '1000000 kcal in tons of tnt' => test_zci( + '1,000,000 large calories = 1 ton of TNT', + structured_answer => make_answer({ + markup_input => '1,000,000', + raw_input => '1000000', + from_unit => 'large calories', + styled_output => '1', + raw_answer => '1', + to_unit => 'ton of TNT', + physical_quantity => 'energy' + }) + ), '90 ps in watts' => test_zci( '90 metric horsepower = 66,194.888 watts', structured_answer => make_answer({ @@ -984,14 +1009,14 @@ ddg_goodie_test( }) ), 'ml in gallons' => test_zci( - '1 millilitre = 0.000264 us gallons', + '1 us gallon = 3,785.412 millilitres',, structured_answer => make_answer({ markup_input => '1', raw_input => '1', - from_unit => 'millilitre', - styled_output => '0.000264', - raw_answer => '0.000264', - to_unit => 'us gallons', + from_unit => 'us gallon', + styled_output => '3,785.412', + raw_answer => '3785.412', + to_unit => 'millilitres', physical_quantity => 'volume' }) ), @@ -1431,14 +1456,14 @@ ddg_goodie_test( }) ), 'how many cm in metres?' => test_zci( - '1 centimeter = 0.010 meters', + '1 meter = 100 centimeters', structured_answer => make_answer({ markup_input => '1', raw_input => '1', - from_unit => 'centimeter', - styled_output => '0.010', - raw_answer => '0.010', - to_unit => 'meters', + from_unit => 'meter', + styled_output => '100', + raw_answer => '100', + to_unit => 'centimeters', physical_quantity => 'length' }) ), @@ -2755,7 +2780,18 @@ ddg_goodie_test( physical_quantity => 'speed' }) ), - + 'acre square feet' => test_zci( + '1 acre = 43,560.173 square feet', + structured_answer => make_answer({ + markup_input => '1', + raw_input => '1', + from_unit => 'acre', + styled_output => '43,560.173', + raw_answer => '43560.173', + to_unit => 'square feet', + physical_quantity => 'area' + }) + ), # Intentionally untriggered diff --git a/t/ConvertLatLon.t b/t/ConvertLatLon.t index 2f308600d..9cf973e6b 100644 --- a/t/ConvertLatLon.t +++ b/t/ConvertLatLon.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -102,14 +103,14 @@ ddg_goodie_test( 'convert 39.75 degrees to farenheit' => undef, #Check for to-format name - '16.5° S, 68.15° W dms' => test_zci(qr/./, + '16.5° S, 68.15° W dms' => test_zci(re(qr/./), structured_answer => { input => ["16.5° S", "68.15° W"], operation => "Convert to DMS", result => "16° 30′ S, 68° 9′ W", } ), - '16° 30′ S, 68° 9′ W decimal' => test_zci(qr/./, + '16° 30′ S, 68° 9′ W decimal' => test_zci(re(qr/./), structured_answer => { input => ["16° 30′ S", "68° 9′ W"], operation => "Convert to decimal", @@ -119,4 +120,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/CountryCodes.t b/t/CountryCodes.t index 614c0c01d..43ec72e8a 100644 --- a/t/CountryCodes.t +++ b/t/CountryCodes.t @@ -4,121 +4,45 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "country_codes"; zci is_cached => 1; -my $text = '
ISO 3166 Country code for'; +sub build_structured_answer{ + my ($country, $response) = @_; + return 'ISO 3166: '. ucfirst $country .' - '. $response, + structured_answer => { + data => { + title => $response, + subtitle => "ISO 3166 Country code: " . ucfirst ($country), + }, + templates => { + group => "text", + }, + }, +} + +sub build_test { test_zci(build_structured_answer(@_)) } ddg_goodie_test( [ 'DDG::Goodie::CountryCodes' ], - "country code Japan" => test_zci( - qq(ISO 3166: Japan - jp), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jp' - } - ), - "3 letter country code Japan" => test_zci( - qq(ISO 3166: Japan - jpn), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jpn' - } - ), - "3 letter country code of China" => test_zci( - qq(ISO 3166: China - chn), - structured_answer => { - input => ['China'], - operation => 'ISO 3166 Country code', - result => 'chn' - } - ), - "Japan 3 letter country code" => test_zci( - qq(ISO 3166: Japan - jpn), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jpn' - } - ), - "Russia two letter country code" => test_zci( - qq(ISO 3166: Russia - ru), - structured_answer => { - input => ['Russia'], - operation => 'ISO 3166 Country code', - result => 'ru' - } - ), - "two letter country code Japan" => test_zci( - qq(ISO 3166: Japan - jp), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jp' - } - ), - "three letter country code for Japan" => test_zci( - qq(ISO 3166: Japan - jpn), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jpn' - } - ), - "numerical iso code japan" => test_zci( - qq(ISO 3166: Japan - 392), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => '392' - } - ), - "iso code for spain" => test_zci( - qq(ISO 3166: Spain - es), - structured_answer => { - input => ['Spain'], - operation => 'ISO 3166 Country code', - result => 'es' - } - ), - "country code jp" => test_zci( - qq(ISO 3166: Japan - jp), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => 'jp' - } - ), - "japan numerical iso 3166" => test_zci( - qq(ISO 3166: Japan - 392), - structured_answer => { - input => ['Japan'], - operation => 'ISO 3166 Country code', - result => '392' - } - ), - "united states of america iso code" => test_zci( - qq(ISO 3166: United states of america - us), - structured_answer => { - input => ['United states of america'], - operation => 'ISO 3166 Country code', - result => 'us' - } - ), - "3 letter iso code isle of man" => test_zci( - qq(ISO 3166: Isle of man - imn), - structured_answer => { - input => ['Isle of man'], - operation => 'ISO 3166 Country code', - result => 'imn' - } - ), - 'country code for gelgamek' => undef, - 'iso code for english' => undef, + "country code Japan" => build_test("Japan","jp"), + "3 letter country code Japan" => build_test("Japan","jpn"), + "3 letter country code of China" => build_test("China","chn"), + "Japan 3 letter country code" => build_test("Japan","jpn"), + "Russia two letter country code" => build_test("Russia","ru"), + "two letter country code Japan" => build_test("Japan","jp"), + "three letter country code for Japan" => build_test("Japan","jpn"), + "numerical iso code japan" => build_test("Japan",392), + "iso code for spain" => build_test("Spain","es"), + "country code jp" => build_test("Japan","jp"), + "japan numerical iso 3166" => build_test("Japan",392), + "united states of america iso code" => build_test("United states of america","us"), + "3 letter iso code isle of man" => build_test("Isle of man","imn"), + 'country code for gelgamek' => undef, + 'iso code for english' => undef, ); done_testing; diff --git a/t/CryptHashCheck.t b/t/CryptHashCheck.t index b0e5ff548..76b6747d0 100644 --- a/t/CryptHashCheck.t +++ b/t/CryptHashCheck.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'crypthashcheck'; @@ -171,4 +172,3 @@ ddg_goodie_test( done_testing; - diff --git a/t/CurrencyIn.t b/t/CurrencyIn.t index 5034b5f63..6a78eafda 100644 --- a/t/CurrencyIn.t +++ b/t/CurrencyIn.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'currency_in'; diff --git a/t/Cusip.t b/t/Cusip.t index 440562c68..a9687f580 100644 --- a/t/Cusip.t +++ b/t/Cusip.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "cusip"; @@ -56,7 +57,7 @@ ddg_goodie_test( ), 'cusip check 037833100' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -64,7 +65,7 @@ ddg_goodie_test( ), 'cusip 844741108' => test_zci("844741108 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -72,7 +73,7 @@ ddg_goodie_test( ), '037833100 cusip' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -80,7 +81,7 @@ ddg_goodie_test( ), '037833100 cusip check' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -90,7 +91,7 @@ ddg_goodie_test( # starting white space should be stripped 'cusip 037833100' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -100,7 +101,7 @@ ddg_goodie_test( # ending white space should be stripped 'cusip 037833100 ' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -110,7 +111,7 @@ ddg_goodie_test( # starting and ending white space should be stripped 'cusip 037833100 ' => test_zci("037833100 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -120,7 +121,7 @@ ddg_goodie_test( # same AAPL queries with an incorrect check digit 'cusip 03783310A' => test_zci("03783310A is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -128,7 +129,7 @@ ddg_goodie_test( ), 'cusip 03783310A' => test_zci("03783310A is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -136,7 +137,7 @@ ddg_goodie_test( ), 'cusip 03783310A ' => test_zci("03783310A is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -144,7 +145,7 @@ ddg_goodie_test( ), 'cusip 03783310A ' => test_zci("03783310A is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -154,7 +155,7 @@ ddg_goodie_test( # check CUSIP IDs with capital letters (these are for GOOG and Blackberry) 'cusip 38259P706' => test_zci("38259P706 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -162,7 +163,7 @@ ddg_goodie_test( ), 'cusip 38259P508' => test_zci("38259P508 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -170,7 +171,7 @@ ddg_goodie_test( ), 'cusip 09228F103' => test_zci("09228F103 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -180,7 +181,7 @@ ddg_goodie_test( # check the same CUSIP IDs with lower case letters 'cusip 38259p706' => test_zci("38259P706 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -188,7 +189,7 @@ ddg_goodie_test( ), 'cusip 38259p508' => test_zci("38259P508 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -196,7 +197,7 @@ ddg_goodie_test( ), 'cusip 09228f103' => test_zci("09228F103 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -208,7 +209,7 @@ ddg_goodie_test( # if possible, these tests should be replaced with verified CUSIP IDs 'cusip 037833*00' => test_zci("037833*00 is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -216,7 +217,7 @@ ddg_goodie_test( ), 'cusip 037833*02' => test_zci("037833*02 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -224,7 +225,7 @@ ddg_goodie_test( ), 'cusip 0378331#0' => test_zci("0378331#0 is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -232,7 +233,7 @@ ddg_goodie_test( ), 'cusip 0378331#7' => test_zci("0378331#7 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -240,7 +241,7 @@ ddg_goodie_test( ), 'cusip 037833@00' => test_zci("037833\@00 is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -248,7 +249,7 @@ ddg_goodie_test( ), 'cusip 037833@01' => test_zci("037833\@01 is a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -259,7 +260,7 @@ ddg_goodie_test( # even though they are always invalid IDs 'cusip 03783310*' => test_zci("03783310* is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -267,7 +268,7 @@ ddg_goodie_test( ), 'cusip 03783310#' => test_zci("03783310# is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -275,7 +276,7 @@ ddg_goodie_test( ), 'cusip 03783310@' => test_zci("03783310\@ is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -285,7 +286,7 @@ ddg_goodie_test( # Odd CUSIP IDs should not break the IA 'cusip ********8' => test_zci("********8 is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -293,7 +294,7 @@ ddg_goodie_test( ), 'cusip ########9' => test_zci("########9 is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -301,7 +302,7 @@ ddg_goodie_test( ), 'cusip @#*@#*@#*' => test_zci("\@#*\@#*\@#* is not a properly formatted CUSIP number.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', } @@ -310,4 +311,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/DHL.t b/t/DHL.t index a6b24e6a8..6ce5c32ef 100644 --- a/t/DHL.t +++ b/t/DHL.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'dhl'; @@ -28,4 +29,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/DateMath.t b/t/DateMath.t index 061556d84..70ce47974 100755 --- a/t/DateMath.t +++ b/t/DateMath.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use Test::MockTime qw( :all ); use DDG::Test::Goodie; use DDG::Test::Location; diff --git a/t/DayOfWeek.t b/t/DayOfWeek.t index dbd96b2c9..90253b3d3 100644 --- a/t/DayOfWeek.t +++ b/t/DayOfWeek.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); diff --git a/t/DaysBetween.t b/t/DaysBetween.t index b6c95a8f9..db0d664ed 100755 --- a/t/DaysBetween.t +++ b/t/DaysBetween.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); @@ -76,57 +77,57 @@ ddg_goodie_test( }, ), 'days between jan 1 and jan 15 inclusive' => test_zci( - qr/^There are 15 days between.+inclusive\.$/, + re(qr/^There are 15 days between.+inclusive\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between, inclusive', result => 15 }, ), 'days between jan 1 and 15th feb' => test_zci( - qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/, + re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 45 }, ), 'number of days between jan 1 and 15th feb' => test_zci( - qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/, + re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 45 }, ), 'number of days from jan 1 and 15th feb' => test_zci( - qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/, + re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 45 }, ), 'days from jan 1 and 15th feb' => test_zci( - qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/, + re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 45 }, ), 'days between today and tomorrow' => test_zci( - qr/^There are 1 days between.+ and.+\.$/, + re(qr/^There are 1 days between.+ and.+\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 1 }, ), 'how many days between feb 2 and feb 17' => test_zci( - qr/^There are 15 days between.+ and.+\.$/, + re(qr/^There are 15 days between.+ and.+\.$/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Days between', result => 15 }, diff --git a/t/Dessert.t b/t/Dessert.t index 3c0dd720d..165bb40ad 100644 --- a/t/Dessert.t +++ b/t/Dessert.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'dessert'; @@ -13,81 +14,81 @@ ddg_goodie_test( 'DDG::Goodie::Dessert' ], 'desserts beginning with a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'desserts beginning with A' => test_zci( - qr/(.*?) is a dessert that begins with 'A'\.$/, + re(qr/(.*?) is a dessert that begins with 'A'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'dessert start with a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'desserts starting with a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'dessert starts with a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'desserts beginning with z' => test_zci( - qr/(.*?) is a dessert that begins with 'z'\.$/, + re(qr/(.*?) is a dessert that begins with 'z'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'a dessert that begins with a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'a dessert that starts with the letter a' => test_zci( - qr/(.*?) is a dessert that begins with 'a'\.$/, + re(qr/(.*?) is a dessert that begins with 'a'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } } ), 'dessert that begins with the letter z' => test_zci( - qr/(.*?) is a dessert that begins with 'z'\.$/, + re(qr/(.*?) is a dessert that begins with 'z'\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'info', } diff --git a/t/Dewey.t b/t/Dewey.t index f86e88eda..b20a7bea9 100644 --- a/t/Dewey.t +++ b/t/Dewey.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'dewey_decimal'; @@ -17,7 +18,7 @@ ddg_goodie_test( 'dewey decimal system 640s' => test_zci("", html => '
641 Food & drink
642 Meals & table service
643 Housing & household equipment
644 Household utilities
645 Household furnishings
646 Sewing, clothing, personal living
647 Management of public households
648 Housekeeping
649 Child rearing & home care of sick
'), '#1 in the dewey decimal system' => test_zci("001 is knowledge in the Dewey Decimal System.", html => '001 is knowledge in the Dewey Decimal System.'), 'dewey decimal system naturalism' => test_zci("146 is naturalism and related systems in the Dewey Decimal System.", html => '146 is naturalism and related systems in the Dewey Decimal System.'), - 'etymology in the dewey decimal system' => test_zci("", html => qr{^.*
$}), + 'etymology in the dewey decimal system' => test_zci("", html => re(qr{^.*
$})), 'dewey 644' => test_zci('644 is household utilities in the Dewey Decimal System.', html => '644 is household utilities in the Dewey Decimal System.'), ); diff --git a/t/Dice.t b/t/Dice.t index c08259297..5e2c12789 100644 --- a/t/Dice.t +++ b/t/Dice.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'dice_roll'; @@ -17,9 +18,9 @@ ddg_goodie_test( # Check trigger kicks in. 'throw dice' => test_zci( - qr/^., .$/, + re(qr/^., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -29,9 +30,9 @@ ddg_goodie_test( } ), 'throw dices' => test_zci( - qr/^., .$/, + re(qr/^., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -41,9 +42,9 @@ ddg_goodie_test( } ), 'roll dice' => test_zci( - qr/^., .$/, + re(qr/^., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -53,9 +54,9 @@ ddg_goodie_test( } ), 'throw die' => test_zci( - qr/^.$/, + re(qr/^.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -68,9 +69,9 @@ ddg_goodie_test( # Simple "dice" query "roll 5 dice" => test_zci( - qr/., ., ., ., .$/, + re(qr/., ., ., ., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -82,9 +83,9 @@ ddg_goodie_test( # Simple shorthand query "roll 2d6" => test_zci( - qr/^\d (\+|-) \d$/, + re(qr/^\d (\+|-) \d$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -96,9 +97,9 @@ ddg_goodie_test( # Query with numbers as words "roll five dice" => test_zci( - qr/., ., ., ., .$/, + re(qr/., ., ., ., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -108,9 +109,9 @@ ddg_goodie_test( } ), "roll twenty five dice" => test_zci( - qr/., ., ., ., .$/, + re(qr/., ., ., ., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -120,9 +121,9 @@ ddg_goodie_test( } ), "roll fifty-four dice" => test_zci( - qr/., ., ., ., .$/, + re(qr/., ., ., ., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -132,9 +133,9 @@ ddg_goodie_test( } ), "roll seven dices" => test_zci( - qr/., ., ., ., .$/, + re(qr/., ., ., ., .$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -147,9 +148,9 @@ ddg_goodie_test( "roll foo dice" => undef, "throw 1d20" => test_zci( - qr/^\d{1,2}$/, + re(qr/^\d{1,2}$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -159,9 +160,9 @@ ddg_goodie_test( } ), "roll d20" => test_zci( - qr/^\d{1,2}$/, + re(qr/^\d{1,2}$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -173,9 +174,9 @@ ddg_goodie_test( # Simple shorthand queries with +- "roll 3d12 + 4" => test_zci( - qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2}$/, + re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2}$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -185,9 +186,9 @@ ddg_goodie_test( } ), "roll 3d8 - 8" => test_zci( - qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d$/, + re(qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -197,9 +198,9 @@ ddg_goodie_test( } ), "roll 4d6-l" => test_zci( - qr/^([1-6] \+ ){3}[1-6] - [1-6]$/, + re(qr/^([1-6] \+ ){3}[1-6] - [1-6]$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -211,9 +212,9 @@ ddg_goodie_test( # Simple conjunctive "dice" query "throw 2 dice and 3 dice" => test_zci( - qr/., .., ., .Total: \d+$/, + re(qr/., .., ., .Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -225,9 +226,9 @@ ddg_goodie_test( # Shorthand conjunctive query "roll 2w6 and d20" => test_zci( - qr/^\d (\+|-) \d = \d+\d+Total: \d+$/, + re(qr/^\d (\+|-) \d = \d+\d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -239,9 +240,9 @@ ddg_goodie_test( # Shorthand conjunctive queries with +- "roll 2d6 and 3d12 + 4" => test_zci( - qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/, + re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -251,9 +252,9 @@ ddg_goodie_test( } ), "roll 2d6 and 3d12 - 4" => test_zci( - qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d+Total: \d+$/, + re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -263,9 +264,9 @@ ddg_goodie_test( } ), "throw 3d12 - 4 and 2d6" => test_zci( - qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d{1,2}\d (\+|-) \d = \d+Total: \d+$/, + re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d{1,2}\d (\+|-) \d = \d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -275,9 +276,9 @@ ddg_goodie_test( } ), "throw 2d6 and 3d12 + 4" => test_zci( - qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/, + re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -287,9 +288,9 @@ ddg_goodie_test( } ), "roll 2d6 and 4w6-l" => test_zci( - qr/^\d (\+|-) \d = \d+([1-6] \+ ){3}[1-6] - [1-6] = \d{1,2}Total: \d+$/, + re(qr/^\d (\+|-) \d = \d+([1-6] \+ ){3}[1-6] - [1-6] = \d{1,2}Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -299,9 +300,9 @@ ddg_goodie_test( } ), "roll 2 dice and 3d5 + 4" => test_zci( - qr/^., .\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/, + re(qr/^., .\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -325,9 +326,9 @@ ddg_goodie_test( "roll 2d3 and 2d4-a" => undef, "throw die" => test_zci( - qr/^.$/, + re(qr/^.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -338,9 +339,9 @@ ddg_goodie_test( ), 'roll 3d12' => test_zci( - qr/\d{1,2} \+ \d{1,2} \+ \d{1,2}/, + re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2}/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', options => { @@ -350,9 +351,9 @@ ddg_goodie_test( } ), 'roll 3d12 and 2d4' => test_zci( - qr/\d{1,2} \+ \d{1,2} \+ \d{1,2} = \d+[1-4]+ \+ [1-4]+ = \dTotal: \d+/, + re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2} = \d+[1-4]+ \+ [1-4]+ = \dTotal: \d+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -362,9 +363,9 @@ ddg_goodie_test( } ), 'roll 2 dice and 3d5' => test_zci( - qr/[1-5]+ \+ [1-5]+ \+ [1-5]+ = \d+Total: \d+/, + re(qr/[1-5]+ \+ [1-5]+ \+ [1-5]+ = \d+Total: \d+/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { diff --git a/t/DuckDuckGo.t b/t/DuckDuckGo.t index 24937e376..03ba8dd74 100644 --- a/t/DuckDuckGo.t +++ b/t/DuckDuckGo.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'duckduckgo'; @@ -174,4 +175,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/EmToPx.t b/t/EmToPx.t index eeffc5b0b..ab89961b1 100644 --- a/t/EmToPx.t +++ b/t/EmToPx.t @@ -1,6 +1,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'conversion'; diff --git a/t/EmailValidator.t b/t/EmailValidator.t index 814e7bed1..c491fda5c 100644 --- a/t/EmailValidator.t +++ b/t/EmailValidator.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'email_validation'; @@ -11,60 +12,60 @@ zci is_cached => 1; ddg_goodie_test( ['DDG::Goodie::EmailValidator'], 'validate my email foo@example.com' => test_zci( - qr/appears to be valid/, + re(qr/appears to be valid/), structured_answer => { input => ['foo@example.com'], operation => 'Email address validation', - result => qr/appears to be valid/ + result => re(qr/appears to be valid/) } ), 'validate my email foo+abc@example.com' => test_zci( - qr/appears to be valid/, + re(qr/appears to be valid/), structured_answer => { input => ['foo+abc@example.com'], operation => 'Email address validation', - result => qr/appears to be valid/ + result => re(qr/appears to be valid/) } ), 'validate my email foo.bar@example.com' => test_zci( - qr/appears to be valid/, + re(qr/appears to be valid/), structured_answer => { input => ['foo.bar@example.com'], operation => 'Email address validation', - result => qr/appears to be valid/ + result => re(qr/appears to be valid/) } ), 'validate user@exampleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com' => test_zci( - qr/Please check the address/, + re(qr/Please check the address/), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Email address validation', - result => qr/Please check the address/, + result => re(qr/Please check the address/), } ), 'validate foo@example.com' => test_zci( - qr/appears to be valid/, + re(qr/appears to be valid/), structured_answer => { input => ['foo@example.com'], operation => 'Email address validation', - result => qr/appears to be valid/ + result => re(qr/appears to be valid/) } ), 'validate foo@!!!.com' => test_zci( - qr/Please check the fully qualified domain name/, + re(qr/Please check the fully qualified domain name/), structured_answer => { input => ['foo@!!!.com'], operation => 'Email address validation', - result => qr/Please check the fully qualified domain name/, + result => re(qr/Please check the fully qualified domain name/), } ), 'validate foo@example.lmnop' => test_zci( - qr/Please check the top-level domain/, + re(qr/Please check the top-level domain/), structured_answer => { input => ['foo@example.lmnop'], operation => 'Email address validation', - result => qr/Please check the top-level domain/, + result => re(qr/Please check the top-level domain/), } ), 'validate foo' => undef, diff --git a/t/FIGlet.t b/t/FIGlet.t index 9969bc75e..ff5d66351 100644 --- a/t/FIGlet.t +++ b/t/FIGlet.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'figlet'; diff --git a/t/Factors.t b/t/Factors.t old mode 100644 new mode 100755 index ddd11f206..289df363f --- a/t/Factors.t +++ b/t/Factors.t @@ -3,45 +3,32 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "factors"; zci is_cached => 1; +sub build_test +{ + my ($text_answer, $input, $answer) = @_; + return test_zci($text_answer, structured_answer =>{ + data => { + title => $answer, + subtitle => "Factors of: $input" + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::Factors)], - '30 factors' => test_zci( - 'Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', - structured_answer => { - input => ['30'], - operation => 'Factors', - result => '1, 2, 3, 5, 6, 10, 15, 30' - } - ), - 'factors of 72' => test_zci( - 'Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', - structured_answer => { - input => ['72'], - operation => 'Factors', - result => '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72' - } - ), - 'factors of 30' => test_zci( - 'Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', - structured_answer => { - input => ['30'], - operation => 'Factors', - result => '1, 2, 3, 5, 6, 10, 15, 30' - } - ), - '72 factors' => test_zci( - 'Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', - structured_answer => { - input => ['72'], - operation => 'Factors', - result => '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72' - } - ), + '30 factors' => build_test('Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', '30', '1, 2, 3, 5, 6, 10, 15, 30'), + 'factors of 72' => build_test('Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', '72', '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'), + 'factors of 30' => build_test('Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', '30', '1, 2, 3, 5, 6, 10, 15, 30'), + '72 factors' => build_test('Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', '72', '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'), ); done_testing; diff --git a/t/FedEx.t b/t/FedEx.t index bf55ceef7..5f9cefad4 100644 --- a/t/FedEx.t +++ b/t/FedEx.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'fedex'; diff --git a/t/FenViewer.t b/t/FenViewer.t index 409ac0716..0f27dbf5c 100644 --- a/t/FenViewer.t +++ b/t/FenViewer.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "fen_viewer"; diff --git a/t/Fibonacci.t b/t/Fibonacci.t index d20894bb4..f1cc398ce 100644 --- a/t/Fibonacci.t +++ b/t/Fibonacci.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'fibonacci'; diff --git a/t/FirefoxOS.t b/t/FirefoxOS.t index 3f33b7c3b..fce49ffdf 100644 --- a/t/FirefoxOS.t +++ b/t/FirefoxOS.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "firefoxos"; @@ -10,7 +11,7 @@ zci is_cached => 1; #Structured answer template data my $templateData = { - data => '-ANY-', + data => ignore(), meta => { sourceName => "Mozilla Developer Network", sourceUrl => "https://developer.mozilla.org/en-US/Apps/Reference/Firefox_OS_device_APIs" diff --git a/t/FlipText.t b/t/FlipText.t index 1b251f5c1..56941e3f5 100644 --- a/t/FlipText.t +++ b/t/FlipText.t @@ -4,45 +4,39 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'flip_text'; zci is_cached => 1; +sub build_structured_answer{ + my ($input,$result) = @_; + return $result, + structured_answer => { + data => { + title => $result, + subtitle => "Flip text $input" + }, + templates => { + group => 'text', + } + } +} + +sub build_test{ test_zci(build_structured_answer(@_)) } + ddg_goodie_test( [qw( DDG::Goodie::FlipText)], - 'flip text test' => test_zci( - "\x{0287}\x{0073}\x{01DD}\x{0287}", - structured_answer => { - input => ['test'], - operation => 'Flip text', - result => 'ʇsǝʇ' - } - ), - 'mirror text test' => test_zci( - "\x{0287}\x{0073}\x{01DD}\x{0287}", - structured_answer => { - input => ['test'], - operation => 'Flip text', - result => 'ʇsǝʇ' - } - ), - 'flip text my sentence' => test_zci( - 'ǝɔuǝʇuǝs ʎɯ', - structured_answer => { - input => ['my sentence'], - operation => 'Flip text', - result => 'ǝɔuǝʇuǝs ʎɯ' - } - ), - 'mirror text text' => test_zci( - 'ʇxǝʇ', - structured_answer => { - input => ['text'], - operation => 'Flip text', - result => 'ʇxǝʇ' - } - ), + 'flip text test' => build_test('test','ʇsǝʇ'), + 'mirror text test' => build_test('test','ʇsǝʇ'), + 'flip text my sentence' => build_test('my sentence','ǝɔuǝʇuǝs ʎɯ'), + 'mirror text text' => build_test('text','ʇxǝʇ'), + 'flip text ' => build_test('',''), + 'rotate text "hello world"' => build_test('"hello world"','„pʃɹoʍ oʃʃǝɥ„'), + 'spin text ;hello world;' => build_test(';hello world;','؛pʃɹoʍ oʃʃǝɥ؛'), + 'spin text [\'hello\']' => build_test('[\'hello\']','[,oʃʃǝɥ,]'), + 'spin text <<"hello\' % & * () = + . #@!^(/world">>' => build_test('<<"hello\' % & * () = + . #@!^(/world">>','<<„pʃɹoʍ/)∨¡@# ˙ + = () ⁎ ⅋ % ,oʃʃǝɥ„>>'), ); done_testing; diff --git a/t/Fortune.t b/t/Fortune.t old mode 100644 new mode 100755 index f960e9b87..11c3a6c06 --- a/t/Fortune.t +++ b/t/Fortune.t @@ -3,29 +3,34 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'fortune'; zci is_cached => 0; -my @fortune = ( - '-ANY-', - structured_answer => { - input => [], - operation => 'Random fortune', - result => '-ANY-' - }); +sub build_test +{ + return test_zci(re(qr/.+/), structured_answer => { + data => { + title => re(qr/.+/), + subtitle => 'Random Fortune' + }, + templates => { + group => 'text' + } + }) +} ddg_goodie_test( [qw( DDG::Goodie::Fortune )], - 'gimmie a fortune cookie' => test_zci(@fortune), - 'gimmie a unix fortune' => test_zci(@fortune), - 'give me a fortune cookie' => test_zci(@fortune), - 'give me a unix fortune' => test_zci(@fortune), - 'unix fortune cookie' => test_zci(@fortune), + 'gimmie a fortune cookie' => build_test(), + 'gimmie a unix fortune' => build_test(), + 'give me a fortune cookie' => build_test(), + 'give me a unix fortune' => build_test(), + 'unix fortune cookie' => build_test(), 'how do I make a fortune overnight' => undef, "bill gates' fortune" => undef, ); done_testing; - diff --git a/t/Frequency.t b/t/Frequency.t index 7b2e74462..d3bd56535 100644 --- a/t/Frequency.t +++ b/t/Frequency.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci is_cached => 1; diff --git a/t/FrequencySpectrum.t b/t/FrequencySpectrum.t index 0ad605e6f..b299a6e74 100644 --- a/t/FrequencySpectrum.t +++ b/t/FrequencySpectrum.t @@ -8,6 +8,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'frequency_spectrum'; @@ -18,10 +19,10 @@ ddg_goodie_test( #Primary example '50 hz' => test_zci( - #qr/radio.+SLF.+audible.+double-bass.+piano.+tuba/, - qr/radio/, + #re(qr/radio.+SLF.+audible.+double-bass.+piano.+tuba/), + re(qr/radio/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -34,9 +35,9 @@ ddg_goodie_test( #Secondary example '400 thz' => test_zci( - qr/infrared/, + re(qr/infrared/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -49,10 +50,10 @@ ddg_goodie_test( #Misc '1,000 hz' => test_zci( - #qr/radio.+audible.+human.+voice.+viola.+violin.+guitar.+mandolin.+banjo.+piano.+saxophone.+flute.+clarinet.+oboe/, - qr/radio/, + #re(qr/radio.+audible.+human.+voice.+viola.+violin.+guitar.+mandolin.+banjo.+piano.+saxophone.+flute.+clarinet.+oboe/), + re(qr/radio/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -63,9 +64,9 @@ ddg_goodie_test( } ), '1000000.99 hz' => test_zci( - qr/radio.+MF/, + re(qr/radio.+MF/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -76,9 +77,9 @@ ddg_goodie_test( } ), '29.1 hz' => test_zci( - qr/radio.+ELF/, + re(qr/radio.+ELF/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -91,10 +92,10 @@ ddg_goodie_test( #No whitespace between number and unit '50hz' => test_zci( - #qr/radio.+SLF.+audible.+double-bass.+piano.+tuba/, - qr/radio/, + #re(qr/radio.+SLF.+audible.+double-bass.+piano.+tuba/), + re(qr/radio/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -105,9 +106,9 @@ ddg_goodie_test( } ), '400terahertz' => test_zci( - qr/infrared/, + re(qr/infrared/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -120,9 +121,9 @@ ddg_goodie_test( #Mixed case '400 THz' => test_zci( - qr/infrared/, + re(qr/infrared/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -134,10 +135,10 @@ ddg_goodie_test( ), '1000 HZ' => test_zci( - #qr/radio.+audible.+human.+voice.+viola.+violin.+guitar.+mandolin.+banjo.+piano.+saxophone.+flute.+clarinet.+oboe/, - qr/radio/, + #re(qr/radio.+audible.+human.+voice.+viola.+violin.+guitar.+mandolin.+banjo.+piano.+saxophone.+flute.+clarinet.+oboe/), + re(qr/radio/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -150,9 +151,9 @@ ddg_goodie_test( #Commas in number '1,000,000.99 hz' => test_zci( - qr/radio.+MF/, + re(qr/radio.+MF/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -165,9 +166,9 @@ ddg_goodie_test( #Can you test with all the colours of the wind? '650 nm' => test_zci( - qr/visible.+red/, + re(qr/visible.+red/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -178,9 +179,9 @@ ddg_goodie_test( } ), '610 nanometers' => test_zci( - qr/visible.+orange/, + re(qr/visible.+orange/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -191,9 +192,9 @@ ddg_goodie_test( } ), '580 nanometres' => test_zci( - qr/visible.+yellow/, + re(qr/visible.+yellow/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -204,9 +205,9 @@ ddg_goodie_test( } ), '536 nanometer' => test_zci( - qr/visible.+green/, + re(qr/visible.+green/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -217,9 +218,9 @@ ddg_goodie_test( } ), '478.1 nm' => test_zci( - qr/visible.+blue/, + re(qr/visible.+blue/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -230,9 +231,9 @@ ddg_goodie_test( } ), '380.000000000 nanometres' => test_zci( - qr/visible.+violet/, + re(qr/visible.+violet/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, diff --git a/t/GUID.t b/t/GUID.t index a40e130e6..85a8172a6 100644 --- a/t/GUID.t +++ b/t/GUID.t @@ -2,8 +2,8 @@ use strict; use warnings; -use Test::Deep; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'guid'; diff --git a/t/Game2048.t b/t/Game2048.t index 0c5cc0acd..a299b4f0b 100644 --- a/t/Game2048.t +++ b/t/Game2048.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 2048; @@ -16,7 +17,7 @@ ddg_goodie_test( 'Play 2048', structured_answer => { - data => '-ANY-', + data => ignore(), # data => [{ # dimension => 4, @@ -35,7 +36,7 @@ ddg_goodie_test( 'Play 256', structured_answer => { - data => '-ANY-', + data => ignore(), # data => [{ # dimension => 7, diff --git a/t/GenerateMAC.t b/t/GenerateMAC.t old mode 100644 new mode 100755 index a6e6c351a..17c42c159 --- a/t/GenerateMAC.t +++ b/t/GenerateMAC.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "MAC Address"; @@ -11,22 +12,27 @@ zci is_cached => 0; my $mac_regxp = "([0-9A-F]{2}[:-]){5}([0-9A-F]{2})"; my $text_start = "Here's a random MAC address: "; -my @answer = ( - qr/^$text_start$mac_regxp$/, - structured_answer => { - input => [], - operation => 'Random MAC address', - result => qr/$mac_regxp/ +sub build_test +{ + return test_zci(re(qr/^$text_start$mac_regxp$/), structured_answer => { + data => { + title => re($mac_regxp), + subtitle => "Random MAC Address" + }, + templates => { + group => 'text' + } }); +} #regexp from http://stackoverflow.com/questions/4260467/what-is-a-regular-expression-for-a-mac-address ddg_goodie_test( ['DDG::Goodie::GenerateMAC'], - 'generate mac address' => test_zci(@answer), - 'generate mac addr' => test_zci(@answer), - 'random mac address' => test_zci(@answer), - 'random mac addr' => test_zci(@answer), - 'please generate mac address' => test_zci(@answer), + 'generate mac address' => build_test(), + 'generate mac addr' => build_test(), + 'random mac address' => build_test(), + 'random mac addr' => build_test(), + 'please generate mac address' => build_test(), ); done_testing; diff --git a/t/GibberishGenerator.t b/t/GibberishGenerator.t index 6bef76272..8239f86ea 100644 --- a/t/GibberishGenerator.t +++ b/t/GibberishGenerator.t @@ -1,6 +1,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -9,8 +10,8 @@ zci is_cached => 0; sub build_result { my $result = shift; - return $result, structured_answer => { - data => "-ANY-", + return re($result), structured_answer => { + data => ignore(), templates => { group => 'info', options => { diff --git a/t/GoldenRatio.t b/t/GoldenRatio.t index aa7835357..b5f11dd16 100644 --- a/t/GoldenRatio.t +++ b/t/GoldenRatio.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'golden_ratio'; diff --git a/t/GreatestCommonFactor.t b/t/GreatestCommonFactor.t index f6f872317..cbf160c2f 100644 --- a/t/GreatestCommonFactor.t +++ b/t/GreatestCommonFactor.t @@ -3,133 +3,48 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "greatest_common_factor"; zci is_cached => 1; +# Build a structured answer that should match the response from the +# Perl file. +sub build_structured_answer { + my ($numbers, $result) = @_; + + return "Greatest common factor of $numbers is $result.", + structured_answer => { + data => { + title => $result, + subtitle => "Greatest common factor: $numbers" + }, + templates => { + group => "text" + } + }; +} + +sub build_test { test_zci(build_structured_answer(@_)) } + ddg_goodie_test( [qw( DDG::Goodie::GreatestCommonFactor )], - 'gcf 9 81' => test_zci( - 'Greatest common factor of 9 and 81 is 9.', - structured_answer => { - input => ['9 and 81'], - operation => 'Greatest common factor', - result => 9 - } - ), - '1000 100 greatest common factor' => test_zci( - 'Greatest common factor of 100 and 1000 is 100.', - structured_answer => { - input => ['100 and 1000'], - operation => 'Greatest common factor', - result => 100 - } - ), - 'GCF 12 76' => test_zci( - 'Greatest common factor of 12 and 76 is 4.', - structured_answer => { - input => ['12 and 76'], - operation => 'Greatest common factor', - result => 4 - } - ), - 'GCF 121 11' => test_zci( - 'Greatest common factor of 11 and 121 is 11.', - structured_answer => { - input => ['11 and 121'], - operation => 'Greatest common factor', - result => 11 - } - ), - '99 9 greatest common factor' => test_zci( - 'Greatest common factor of 9 and 99 is 9.', - structured_answer => { - input => ['9 and 99'], - operation => 'Greatest common factor', - result => 9 - } - ), - 'greatest common divisor 4 6' => test_zci( - 'Greatest common factor of 4 and 6 is 2.', - structured_answer => { - input => ['4 and 6'], - operation => 'Greatest common factor', - result => 2 - } - ), - 'gcd 4 6' => test_zci( - 'Greatest common factor of 4 and 6 is 2.', - structured_answer => { - input => ['4 and 6'], - operation => 'Greatest common factor', - result => 2 - } - ), - 'gcd 2' => test_zci( - 'Greatest common factor of 2 is 2.', - structured_answer => { - input => ['2'], - operation => 'Greatest common factor', - result => 2 - } - ), - 'gcd 12 18 24' => test_zci( - 'Greatest common factor of 12, 18 and 24 is 6.', - structured_answer => { - input => ['12, 18 and 24'], - operation => 'Greatest common factor', - result => 6 - } - ), - 'gcd 25 20 15 10 5' => test_zci( - 'Greatest common factor of 5, 10, 15, 20 and 25 is 5.', - structured_answer => { - input => ['5, 10, 15, 20 and 25'], - operation => 'Greatest common factor', - result => 5 - } - ), - 'gcd 6, 9, ,,,, 12 15' => test_zci( - 'Greatest common factor of 6, 9, 12 and 15 is 3.', - structured_answer => { - input => ['6, 9, 12 and 15'], - operation => 'Greatest common factor', - result => 3 - } - ), - 'gcd 2 3' => test_zci( - 'Greatest common factor of 2 and 3 is 1.', - structured_answer => { - input => ['2 and 3'], - operation => 'Greatest common factor', - result => 1 - } - ), - 'gcd 2 3 5' => test_zci( - 'Greatest common factor of 2, 3 and 5 is 1.', - structured_answer => { - input => ['2, 3 and 5'], - operation => 'Greatest common factor', - result => 1 - } - ), - 'gcd 0 2' => test_zci( - 'Greatest common factor of 0 and 2 is 2.', - structured_answer => { - input => ['0 and 2'], - operation => 'Greatest common factor', - result => 2 - } - ), - 'gcd 0 0' => test_zci( - 'Greatest common factor of 0 and 0 is 0.', - structured_answer => { - input => ['0 and 0'], - operation => 'Greatest common factor', - result => 0 - } - ), + 'gcf 9 81' => build_test('9 and 81', 9), + '1000 100 greatest common factor' => build_test('100 and 1000', 100), + 'GCF 12 76' => build_test('12 and 76', 4), + 'GCF 121 11' => build_test('11 and 121', 11), + '99 9 greatest common factor' => build_test('9 and 99', 9), + 'greatest common divisor 4 6' => build_test('4 and 6', 2), + 'gcd 4 6' => build_test('4 and 6', 2), + 'gcd 2' => build_test('2', 2), + 'gcd 12 18 24' => build_test('12, 18 and 24', 6), + 'gcd 25 20 15 10 5' => build_test('5, 10, 15, 20 and 25', 5), + 'gcd 6, 9, ,,,, 12 15' => build_test('6, 9, 12 and 15', 3), + 'gcd 2 3' => build_test('2 and 3', 1), + 'gcd 2 3 5' => build_test('2, 3 and 5', 1), + 'gcd 0 2' => build_test('0 and 2', 2), + 'gcd 0 0' => build_test('0 and 0', 0), ); done_testing; diff --git a/t/GuitarChords.t b/t/GuitarChords.t index bfcf508aa..9149be520 100644 --- a/t/GuitarChords.t +++ b/t/GuitarChords.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'guitarchord'; @@ -14,32 +15,32 @@ ddg_goodie_test( 'G#m6 guitar chord' => test_zci( 'G#m6', heading=>'G#m6', - html => qr#.*Guitar chord diagram for G\#m6.*#s + html => re(qr#.*Guitar chord diagram for G\#m6.*#s) ), 'Abaug7 guitar chord' => test_zci( 'Abaug7', heading=>'Abaug7', - html => qr#.*Guitar chord diagram for Abaug7.*#s + html => re(qr#.*Guitar chord diagram for Abaug7.*#s) ), 'A7/b9 guitar chord' => test_zci( 'A7(b9)', heading=>'A7(b9)', - html => qr#.*Guitar chord diagram for A7\(b9\).*#s + html => re(qr#.*Guitar chord diagram for A7\(b9\).*#s) ), 'guitar chord Cm7' => test_zci( 'Cm7', heading=>'Cm7', - html => qr#.*Guitar chord diagram for Cm7.*#s + html => re(qr#.*Guitar chord diagram for Cm7.*#s) ), 'guitar chord Db7sus4' => test_zci( 'Db7sus4', heading=>'Db7sus4', - html => qr#.*Guitar chord diagram for Db7sus4.*#s + html => re(qr#.*Guitar chord diagram for Db7sus4.*#s) ), 'guitar chord f min' => test_zci( 'Fm', heading=>'Fm', - html => qr#.*Guitar chord diagram for Fm.*#s + html => re(qr#.*Guitar chord diagram for Fm.*#s) ), # check that certain things don't trigger it: 'C# programming' => undef, diff --git a/t/HKDK.t b/t/HKDK.t index 0c73e99f5..0b59b18fa 100644 --- a/t/HKDK.t +++ b/t/HKDK.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'hkdk'; @@ -23,4 +24,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/HTMLEntitiesDecode.t b/t/HTMLEntitiesDecode.t index 681016276..4017eaf49 100755 --- a/t/HTMLEntitiesDecode.t +++ b/t/HTMLEntitiesDecode.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'html_entity'; @@ -10,8 +11,8 @@ zci is_cached => 1; sub any_structured_answer { return { - input => '-ANY-', - result => '-ANY-', + input => ignore(), + result => ignore(), operation => "HTML Entity Decode" }; } @@ -36,9 +37,9 @@ ddg_goodie_test( 'htmlentity for #x3c' => test_zci("Decoded HTML Entity: <", structured_answer => any_structured_answer()), # "¢" succeeds - 'html decode ¢' => test_zci(qr/.*/, structured_answer => any_structured_answer()), + 'html decode ¢' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()), # "¢" also succeeds (missing back ";" is OK) - 'html decode ¢' => test_zci(qr/.*/, structured_answer => any_structured_answer()), + 'html decode ¢' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()), # "cent" fails during the regex match because of the missing front "&" (stricter for text to eliminate false positive encoding hits) 'html decode cent' => undef, # "cent;" fails during the regex match for the same reasons as above @@ -55,11 +56,11 @@ ddg_goodie_test( 'html decode apostrophe' => undef, # natural querying - 'What is the decoded html entity for π?' => test_zci(qr/.*/, structured_answer => any_structured_answer()), + 'What is the decoded html entity for π?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()), # natural querying - 'what is decoded html entity for #960 ?' => test_zci(qr/.*/, structured_answer => any_structured_answer()), + 'what is decoded html entity for #960 ?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()), # no "html" in query - 'the decoded entity for ō is?' => test_zci(qr/.*/, structured_answer => any_structured_answer()), + 'the decoded entity for ō is?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()), ); done_testing; diff --git a/t/HTMLEntitiesEncode.t b/t/HTMLEntitiesEncode.t index 191f23f3f..9fb709679 100755 --- a/t/HTMLEntitiesEncode.t +++ b/t/HTMLEntitiesEncode.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -12,7 +13,7 @@ zci is_cached => 1; sub make_structured_answer { my ($qr) = @_; return { - input => '-ANY-', + input => ignore(), operation => "HTML Entity Encode", result => $qr, }; @@ -40,26 +41,26 @@ ddg_goodie_test( [qw(DDG::Goodie::HTMLEntitiesEncode)], # Simple tests - 'html code em dash' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(qr/mdash/)), - 'html em dash' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(qr/mdash/)), - 'em-dash html' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(qr/mdash/)), # hyphens ignored - 'html encode "em-dash"' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(qr/mdash/)), # quotes ignored - 'ApoSTrophe escapehtml' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(qr/#39/)), # mixed cases in query + 'html code em dash' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(re(qr/mdash/))), + 'html em dash' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(re(qr/mdash/))), + 'em-dash html' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(re(qr/mdash/))), # hyphens ignored + 'html encode "em-dash"' => test_zci("Encoded HTML Entity: —", structured_answer => make_structured_answer(re(qr/mdash/))), # quotes ignored + 'ApoSTrophe escapehtml' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(re(qr/#39/))), # mixed cases in query # Basic varieties in querying accented chars - 'html entity A-acute' => test_zci("Encoded HTML Entity: Á",structured_answer => make_structured_answer(qr/Aacute/)), - 'html entity for E Grave' => test_zci("Encoded HTML Entity: È", structured_answer => make_structured_answer(qr/Egrave/)), - 'html Ograve' => test_zci("Encoded HTML Entity: Ò", structured_answer => make_structured_answer(qr/Ograve/)), + 'html entity A-acute' => test_zci("Encoded HTML Entity: Á",structured_answer => make_structured_answer(re(qr/Aacute/))), + 'html entity for E Grave' => test_zci("Encoded HTML Entity: È", structured_answer => make_structured_answer(re(qr/Egrave/))), + 'html Ograve' => test_zci("Encoded HTML Entity: Ò", structured_answer => make_structured_answer(re(qr/Ograve/))), # Single typed-in character queries - 'html escape &' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(qr/amp/)), # & - 'html escape "' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(qr/quot/)), # " - 'how to html escape &?' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(qr/amp/)), # ? - 'how to html escape "&"?' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(qr/amp/)), # & - 'how to html escape ??' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(qr/#63/)), # ? - 'how do you html escape a "?"?' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(qr/#63/)), # ? - 'html escape """' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(qr/quot/)), # " - '$ sign htmlentity' => test_zci("Encoded HTML Entity: $", structured_answer => make_structured_answer(qr/#36/)), # $ + 'html escape &' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(re(qr/amp/))), # & + 'html escape "' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(re(qr/quot/))), # " + 'how to html escape &?' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(re(qr/amp/))), # ? + 'how to html escape "&"?' => test_zci("Encoded HTML Entity: &", structured_answer => make_structured_answer(re(qr/amp/))), # & + 'how to html escape ??' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(re(qr/#63/))), # ? + 'how do you html escape a "?"?' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(re(qr/#63/))), # ? + 'html escape """' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(re(qr/quot/))), # " + '$ sign htmlentity' => test_zci("Encoded HTML Entity: $", structured_answer => make_structured_answer(re(qr/#36/))), # $ # Return two matching entities for ambiguous query 'pound symbol html encode ' => test_zci( @@ -71,9 +72,9 @@ ddg_goodie_test( ), # Ignore words and whitespace - 'html code of pilcrow sign' => test_zci("Encoded HTML Entity: ¶", structured_answer => make_structured_answer(qr/#182/)), # of, sign - 'html escape greater than symbol' => test_zci("Encoded HTML Entity: >", structured_answer => make_structured_answer(qr/gt/)), # symbol - 'space html character code' => test_zci("Encoded HTML Entity:  ", structured_answer => make_structured_answer(qr/nbsp/)), # Ignore extra whitespace + 'html code of pilcrow sign' => test_zci("Encoded HTML Entity: ¶", structured_answer => make_structured_answer(re(qr/#182/))), # of, sign + 'html escape greater than symbol' => test_zci("Encoded HTML Entity: >", structured_answer => make_structured_answer(re(qr/gt/))), # symbol + 'space html character code' => test_zci("Encoded HTML Entity:  ", structured_answer => make_structured_answer(re(qr/nbsp/))), # Ignore extra whitespace # Better hash hits substitutions # 'right angle brackets' should work even though the defined key contains the singular 'bracket' @@ -85,7 +86,7 @@ ddg_goodie_test( }, ["Single right pointing angle quote (›)", "Double right pointing angle quote (»)"], "right angle brackets") ), # 'double quotes' should work even though the defined key contains the singular 'quote' - 'double quotes htmlescape' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(qr/quot/)), + 'double quotes htmlescape' => test_zci("Encoded HTML Entity: "", structured_answer => make_structured_answer(re(qr/quot/))), # Should not work 'html encode +' => undef, @@ -93,24 +94,24 @@ ddg_goodie_test( 'html encode is it magic' => undef, # Natural querying - 'What is the html character code for pi' => test_zci("Encoded HTML Entity: π", structured_answer => make_structured_answer(qr/#960/)), - 'whatis html entity for en-dash' => test_zci("Encoded HTML Entity: –", structured_answer => make_structured_answer(qr/ndash/)), # whatis spelling - 'how do I escape the greater-than symbol html' => test_zci("Encoded HTML Entity: >", structured_answer => make_structured_answer(qr/gt/)), + 'What is the html character code for pi' => test_zci("Encoded HTML Entity: π", structured_answer => make_structured_answer(re(qr/#960/))), + 'whatis html entity for en-dash' => test_zci("Encoded HTML Entity: –", structured_answer => make_structured_answer(re(qr/ndash/))), # whatis spelling + 'how do I escape the greater-than symbol html' => test_zci("Encoded HTML Entity: >", structured_answer => make_structured_answer(re(qr/gt/))), # the "a/A" belonging to "acute" matters, but the "a" immediately after "character" is removed - 'How to get a a acute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(qr/aacute/)), - 'how to get a a-acute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(qr/aacute/)), - 'how to get a aacute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(qr/aacute/)), - 'how to get a A acute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(qr/Aacute/)), - 'how to get a A-acute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(qr/Aacute/)), - 'how to get a Aacute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(qr/Aacute/)), + 'How to get a a acute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(re(qr/aacute/))), + 'how to get a a-acute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(re(qr/aacute/))), + 'how to get a aacute character in html code' => test_zci("Encoded HTML Entity: á", structured_answer => make_structured_answer(re(qr/aacute/))), + 'how to get a A acute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(re(qr/Aacute/))), + 'how to get a A-acute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(re(qr/Aacute/))), + 'how to get a Aacute character in html code' => test_zci("Encoded HTML Entity: Á", structured_answer => make_structured_answer(re(qr/Aacute/))), # Question marks ignored - 'the encoded html entity of apostrophe is?' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(qr/#39/)), - 'how to encode an apostrophe in html ? ' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(qr/#39/)), # spaces around the end + 'the encoded html entity of apostrophe is?' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(re(qr/#39/))), + 'how to encode an apostrophe in html ? ' => test_zci("Encoded HTML Entity: '", structured_answer => make_structured_answer(re(qr/#39/))), # spaces around the end # Question mark matters - 'how to encode "?" in html' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(qr/#63/)), + 'how to encode "?" in html' => test_zci("Encoded HTML Entity: ?", structured_answer => make_structured_answer(re(qr/#63/))), ); done_testing; diff --git a/t/HelpLine.t b/t/HelpLine.t index d0ff672db..bd58893ad 100644 --- a/t/HelpLine.t +++ b/t/HelpLine.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use DDG::Test::Location; use DDG::Request; @@ -48,7 +49,7 @@ ddg_goodie_test( query_raw => "$query", location => test_location("$locations[$_]") ), - test_zci(qr/24 Hour Suicide Hotline/, structured_answer => { input => [], operation => qr/24 Hour Suicide Hotline/, result => qr/[0-9]{2}/}), + test_zci(re(qr/24 Hour Suicide Hotline/), structured_answer => { input => [], operation => re(qr/24 Hour Suicide Hotline/), result => re(qr/[0-9]{2}/)}), } 0 .. scalar @locations - 1 } 0 .. scalar @queries - 1), (map { diff --git a/t/HexToASCII.t b/t/HexToASCII.t index ab1531e0c..ed67fed7e 100644 --- a/t/HexToASCII.t +++ b/t/HexToASCII.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'ascii'; diff --git a/t/HexToDec.t b/t/HexToDec.t old mode 100644 new mode 100755 index f40ca41db..4396a2570 --- a/t/HexToDec.t +++ b/t/HexToDec.t @@ -3,77 +3,49 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'hex_to_dec'; zci is_cached => 1; +sub build_test +{ + my ($text, $title, $subtitle) = @_; + + return test_zci($text, structured_answer => { + data => { + title => $title, + subtitle => "Hex to decimal: $subtitle" + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::HexToDec )], - '0xd1038d2e07b42569' => test_zci( + '0xd1038d2e07b42569' => build_test( 'd1038d2e07b42569 base 16 = 15061036807694329193 base 10', - structured_answer => { - input => ['0xd1038d2e07b42569'], - operation => 'Hex to decimal', - result => 15061036807694329193 - } + 15061036807694329193, + '0xd1038d2e07b42569' ), - '0x44696f21' => test_zci( - '44696f21 base 16 = 1147760417 base 10', - structured_answer => { - input => ['0x44696f21'], - operation => 'Hex to decimal', - result => 1147760417, - } + '0x44696f21' => build_test( + '44696f21 base 16 = 1147760417 base 10', + 1147760417, + '0x44696f21' ), - '0xffffffffffffffffffffff' => test_zci( - 'ffffffffffffffffffffff base 16 = 309485009821345068724781055 base 10', - structured_answer => { - input => ['0xffffffffffffffffffffff'], - operation => 'Hex to decimal', - result => "309485009821345068724781055", - } - ), - '0xff in decimal' => test_zci( - 'ff base 16 = 255 base 10', - structured_answer => { - input => ['0xff'], - operation => 'Hex to decimal', - result => "255", - } - ), - '0xff hex to dec' => test_zci( - 'ff base 16 = 255 base 10', - structured_answer => { - input => ['0xff'], - operation => 'Hex to decimal', - result => "255", - } - ), - '0xff as base 10' => test_zci( - 'ff base 16 = 255 base 10', - structured_answer => { - input => ['0xff'], - operation => 'Hex to decimal', - result => "255", - } - ), - '0xff in base-10' => test_zci( - 'ff base 16 = 255 base 10', - structured_answer => { - input => ['0xff'], - operation => 'Hex to decimal', - result => "255", - } - ), - '0xff hex to base10' => test_zci( - 'ff base 16 = 255 base 10', - structured_answer => { - input => ['0xff'], - operation => 'Hex to decimal', - result => "255", - } + '0xffffffffffffffffffffff' => build_test( + 'ffffffffffffffffffffff base 16 = 309485009821345068724781055 base 10', + "309485009821345068724781055", + '0xffffffffffffffffffffff' ), + '0xff in decimal' => build_test('ff base 16 = 255 base 10', "255", '0xff'), + '0xff hex to dec' => build_test('ff base 16 = 255 base 10', "255", '0xff'), + '0xff as base 10' => build_test('ff base 16 = 255 base 10', "255", '0xff'), + '0xff in base-10' => build_test('ff base 16 = 255 base 10', "255", '0xff'), + '0xff hex to base10' => build_test('ff base 16 = 255 base 10', "255", '0xff'), '0x44696f2Z' => undef, 'ascii 0x74657374' => undef, '0x255 hex' => undef, @@ -91,4 +63,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/IDN.t b/t/IDN.t index 91468d836..c3c39914b 100644 --- a/t/IDN.t +++ b/t/IDN.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -27,4 +28,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/IPS.t b/t/IPS.t index af5d1d536..4d62ddf61 100644 --- a/t/IPS.t +++ b/t/IPS.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'ips'; @@ -28,4 +29,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/ISO639.t b/t/ISO639.t index e8da4eb80..2db1a1197 100644 --- a/t/ISO639.t +++ b/t/ISO639.t @@ -5,6 +5,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "iso639"; diff --git a/t/IndependenceDay.t b/t/IndependenceDay.t index 4e7961c8e..eb7a6d3b4 100644 --- a/t/IndependenceDay.t +++ b/t/IndependenceDay.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Locale::Country; diff --git a/t/Jira.t b/t/Jira.t index c2c4789f8..3f36256ca 100644 --- a/t/Jira.t +++ b/t/Jira.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'jira'; diff --git a/t/JohnCena.t b/t/JohnCena.t index d49d8134d..a758ddd82 100644 --- a/t/JohnCena.t +++ b/t/JohnCena.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "john_cena"; diff --git a/t/Kana.t b/t/Kana.t index 91e76311c..c02acb238 100755 --- a/t/Kana.t +++ b/t/Kana.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/KernelTaint.t b/t/KernelTaint.t index 3cb14d1ec..ad7ebd709 100644 --- a/t/KernelTaint.t +++ b/t/KernelTaint.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'kernel_taint'; diff --git a/t/LaserShip.t b/t/LaserShip.t index 11df69b33..5d417181d 100644 --- a/t/LaserShip.t +++ b/t/LaserShip.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'lasership'; @@ -24,4 +25,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Latex.t b/t/Latex.t index e7b2b08b5..93705e2f5 100644 --- a/t/Latex.t +++ b/t/Latex.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'Latex'; @@ -14,16 +15,16 @@ ddg_goodie_test( )], "latex integral" => test_zci('LaTeX command: \int_lowerbound^upperbound Example: $\int_a^b f(x)dx$', - html => qr/\\int_lowerbound\^upperbound/, + html => re(qr/\\int_lowerbound\^upperbound/), heading => 'Integral (LaTeX)'), "tex integral" => test_zci('LaTeX command: \int_lowerbound^upperbound Example: $\int_a^b f(x)dx$', - html => qr/\\int_lowerbound\^upperbound/, + html => re(qr/\\int_lowerbound\^upperbound/), heading => 'Integral (LaTeX)'), 'latex summation' => test_zci('LaTeX command: \sum_{lower}^{upper} Example: $\sum_{i=0}^{10} x^{2}$', - html => qr/\\sum_\{lower\}\^\{upper\}/, + html => re(qr/\\sum_\{lower\}\^\{upper\}/), heading => 'Summation (LaTeX)'), ); diff --git a/t/LeapYear.t b/t/LeapYear.t index a7eeece34..03e60198a 100755 --- a/t/LeapYear.t +++ b/t/LeapYear.t @@ -5,6 +5,7 @@ use warnings; use Test::MockTime qw( :all ); use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'leap_year'; diff --git a/t/LeetSpeak.t b/t/LeetSpeak.t index 322e140e1..98fdee537 100644 --- a/t/LeetSpeak.t +++ b/t/LeetSpeak.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/Loan.t b/t/Loan.t index 8aca23365..c2ee8a17e 100644 --- a/t/Loan.t +++ b/t/Loan.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use DDG::Test::Location; use DDG::Request; diff --git a/t/LoremIpsum.t b/t/LoremIpsum.t index 71e40b64a..f9939adff 100644 --- a/t/LoremIpsum.t +++ b/t/LoremIpsum.t @@ -1,6 +1,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; @@ -9,8 +10,8 @@ zci is_cached => 0; sub build_result { my $result = shift; - return $result, structured_answer => { - data => "-ANY-", + return re($result), structured_answer => { + data => ignore(), meta => { sourceName => "Lipsum", sourceUrl => "http://lipsum.com/" diff --git a/t/Lowercase.t b/t/Lowercase.t old mode 100644 new mode 100755 index d35c277b6..7a2fbd736 --- a/t/Lowercase.t +++ b/t/Lowercase.t @@ -4,72 +4,38 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'lowercase'; zci is_cached => 1; +sub build_test +{ + my ($text, $subtitle) = @_; + return test_zci($text, structured_answer => { + data => { + title => $text, + subtitle => "Lowercase: $subtitle" + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( ['DDG::Goodie::Lowercase'], 'lowercase foo' => undef, 'lowercase 123' => undef, 'lower case foo123' => undef, - 'lower case foO' => test_zci( - 'foo', - structured_answer => { - input => ['foO'], - operation => 'Lowercase', - result => 'foo' - }, - ), - 'lowercase john Doe' => test_zci( - 'john doe', - structured_answer => { - input => ['john Doe'], - operation => 'Lowercase', - result => 'john doe' - }, - ), - 'lowercase GitHub' => test_zci( - 'github', - structured_answer => { - input => ['GitHub'], - operation => 'Lowercase', - result => 'github' - }, - ), - 'lower case GitHub' => test_zci( - 'github', - structured_answer => { - input => ['GitHub'], - operation => 'Lowercase', - result => 'github' - }, - ), - 'lc GitHub' => test_zci( - 'github', - structured_answer => { - input => ['GitHub'], - operation => 'Lowercase', - result => 'github' - }, - ), - 'strtolower GitHub' => test_zci( - 'github', - structured_answer => { - input => ['GitHub'], - operation => 'Lowercase', - result => 'github' - }, - ), - 'tolower GitHub' => test_zci( - 'github', - structured_answer => { - input => ['GitHub'], - operation => 'Lowercase', - result => 'github' - }, - ), + 'lower case foO' => build_test('foo', 'foO'), + 'lowercase john Doe' => build_test('john doe', 'john Doe'), + 'lowercase GitHub' => build_test('github', 'GitHub'), + 'lower case GitHub' => build_test('github', 'GitHub'), + 'lc GitHub' => build_test('github', 'GitHub'), + 'strtolower GitHub' => build_test('github', 'GitHub'), + 'tolower GitHub' => build_test('github', 'GitHub'), 'how to lowercase text' => undef ); diff --git a/t/MD4.t b/t/MD4.t index a6f29452a..09d52e564 100644 --- a/t/MD4.t +++ b/t/MD4.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "md4"; diff --git a/t/MD5.t b/t/MD5.t index 1d8ec8560..4815fdd27 100644 --- a/t/MD5.t +++ b/t/MD5.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'md5'; diff --git a/t/MacAddress.t b/t/MacAddress.t index 92bd8f181..3d005d149 100644 --- a/t/MacAddress.t +++ b/t/MacAddress.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "mac_address"; diff --git a/t/MagicEightBall.t b/t/MagicEightBall.t index 3794f532d..c91b67515 100644 --- a/t/MagicEightBall.t +++ b/t/MagicEightBall.t @@ -3,14 +3,15 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "magic_eight_ball"; zci is_cached => 0; -my $possibleAnswers = qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/; +my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/); -my $possibleStructuredAnswer = qr/^(?:It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)$/; +my $possibleStructuredAnswer = re(qr/^(?:It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)$/); ddg_goodie_test( [qw( DDG::Goodie::MagicEightBall )], diff --git a/t/MakeMeASandwich.t b/t/MakeMeASandwich.t index 1309c5d25..a0ae7ef5d 100644 --- a/t/MakeMeASandwich.t +++ b/t/MakeMeASandwich.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'xkcd_sandwich'; diff --git a/t/MarkdownReference.t b/t/MarkdownReference.t index f943822f3..8cc4fb4f1 100644 --- a/t/MarkdownReference.t +++ b/t/MarkdownReference.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'markdown_reference'; diff --git a/t/Minecraft.t b/t/Minecraft.t index 375019d5e..701a68454 100644 --- a/t/Minecraft.t +++ b/t/Minecraft.t @@ -4,6 +4,7 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use URI::Escape; diff --git a/t/MoonPhases.t b/t/MoonPhases.t index 0478d15fb..35a0dfd6b 100644 --- a/t/MoonPhases.t +++ b/t/MoonPhases.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'moon_phase'; @@ -14,8 +15,8 @@ my $quarter = qr/(?:First|Third)$space_plus(?:Quarter)/; my $named = qr/(?:New|Full)$space_plus(?:Moon)/; my $phases = qr/$wax_wane|$quarter|$named/; -my $ascii_answer = qr/^The current lunar phase is: $phases$/; -my $html_answer = qr%^The current lunar phase is: $phases$%; +my $ascii_answer = re(qr/^The current lunar phase is: $phases$/); +my $html_answer = re(qr%^The current lunar phase is: $phases$%); ddg_goodie_test( [qw( DDG::Goodie::MoonPhases)], @@ -24,7 +25,7 @@ ddg_goodie_test( structured_answer => { input => [], operation => 'Current lunar phase', - result => $phases, + result => re($phases), } ), 'lunar phase' => test_zci( @@ -32,7 +33,7 @@ ddg_goodie_test( structured_answer => { input => [], operation => 'Current lunar phase', - result => $phases, + result => re($phases), } ), 'phase of the moon' => test_zci( @@ -40,7 +41,7 @@ ddg_goodie_test( structured_answer => { input => [], operation => 'Current lunar phase', - result => $phases, + result => re($phases), } ), 'what is the current lunar phase' => test_zci( @@ -48,7 +49,7 @@ ddg_goodie_test( structured_answer => { input => [], operation => 'Current lunar phase', - result => $phases, + result => re($phases), } ), ); diff --git a/t/Morse.t b/t/Morse.t index 05fe2e18f..a2088eee6 100644 --- a/t/Morse.t +++ b/t/Morse.t @@ -4,6 +4,7 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'morse'; diff --git a/t/NLetterWords.t b/t/NLetterWords.t index f722f128e..391c4be72 100644 --- a/t/NLetterWords.t +++ b/t/NLetterWords.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'nletterwords'; @@ -16,8 +17,8 @@ ddg_goodie_test( '1 char words' => test_zci('Random 1 letter words: a, I.'), '1 character word' => test_zci('Random 1 letter words: a, I.'), 'one letter words' => test_zci('Random 1 letter words: a, I.'), - '5 letter words' => test_zci(qr/Random 5 letter words: ((\w){5},? ?){30}/), - '12 character word' => test_zci(qr/Random 12 letter words: ((\w){12},? ?){30}/), + '5 letter words' => test_zci(re(qr/Random 5 letter words: ((\w){5},? ?){30}/)), + '12 character word' => test_zci(re(qr/Random 12 letter words: ((\w){12},? ?){30}/)), ); done_testing; diff --git a/t/NameDays.t b/t/NameDays.t index a7487c353..9283e4646 100644 --- a/t/NameDays.t +++ b/t/NameDays.t @@ -5,6 +5,7 @@ use strict; use warnings; use Locale::Country; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "name_days"; diff --git a/t/NoteFrequency.t b/t/NoteFrequency.t index 37d353184..ac77cb4f9 100644 --- a/t/NoteFrequency.t +++ b/t/NoteFrequency.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "note_frequency"; diff --git a/t/OnionAddress.t b/t/OnionAddress.t index e9fa03c8f..605f06af7 100644 --- a/t/OnionAddress.t +++ b/t/OnionAddress.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use URI::Escape; diff --git a/t/POTUS.t b/t/POTUS.t old mode 100644 new mode 100755 index 1b490583e..bc6720bde --- a/t/POTUS.t +++ b/t/POTUS.t @@ -3,95 +3,42 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'potus'; zci is_cached => 1; +sub build_test +{ + my ($who, $article, $number) = @_; + + return test_zci("$who $article the $number President of the United States.", structured_answer => { + data => { + title => $who, + subtitle => "$number President of the United States" + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::POTUS)], - 'who is president of the united states' => test_zci( - 'Barack Obama is the 44th President of the United States.', - structured_answer => { - input => ['44th'], - operation => 'President of the United States', - result => 'Barack Obama' - } - ), - 'who is the fourth president of the united states' => test_zci( - 'James Madison was the 4th President of the United States.', - structured_answer => { - input => ['4th'], - operation => 'President of the United States', - result => 'James Madison' - } - ), - 'who is the nineteenth president of the united states' => test_zci( - 'Rutherford B. Hayes was the 19th President of the United States.', - structured_answer => { - input => ['19th'], - operation => 'President of the United States', - result => 'Rutherford B. Hayes' - } - ), - 'who was the 1st president of the united states' => test_zci( - 'George Washington was the 1st President of the United States.', - structured_answer => { - input => ['1st'], - operation => 'President of the United States', - result => 'George Washington' - } - ), - 'who was the 31 president of the united states' => test_zci( - 'Herbert Hoover was the 31st President of the United States.', - structured_answer => { - input => ['31st'], - operation => 'President of the United States', - result => 'Herbert Hoover' - } - ), - 'who was the 22 president of the united states' => test_zci( - 'Grover Cleveland was the 22nd President of the United States.', - structured_answer => { - input => ['22nd'], - operation => 'President of the United States', - result => 'Grover Cleveland' - } - ), - 'potus 11' => test_zci( - 'James K. Polk was the 11th President of the United States.', - structured_answer => { - input => ['11th'], - operation => 'President of the United States', - result => 'James K. Polk' - } - ), - 'POTUS 24' => test_zci( - 'Grover Cleveland was the 24th President of the United States.', - structured_answer => { - input => ['24th'], - operation => 'President of the United States', - result => 'Grover Cleveland' - } - ), - 'who was the twenty-second POTUS?' => test_zci( - 'Grover Cleveland was the 22nd President of the United States.', - structured_answer => { - input => ['22nd'], - operation => 'President of the United States', - result => 'Grover Cleveland' - } - ), - 'potus 16' => test_zci( - 'Abraham Lincoln was the 16th President of the United States.', - structured_answer => { - input => ['16th'], - operation => 'President of the United States', - result => 'Abraham Lincoln' - } - ), + 'who is president of the united states' => build_test('Barack Obama', 'is',"44th"), + 'who is the fourth president of the united states' => build_test('James Madison', 'was', '4th'), + 'who is the nineteenth president of the united states' => build_test('Rutherford B. Hayes', 'was','19th'), + 'who was the 1st president of the united states' => build_test('George Washington', 'was', '1st'), + 'who was the 31 president of the united states' => build_test('Herbert Hoover', 'was', '31st'), + 'who was the 22 president of the united states' => build_test('Grover Cleveland', 'was','22nd'), + 'potus 11' => build_test('James K. Polk', 'was','11th'), + 'POTUS 24' => build_test('Grover Cleveland', 'was', '24th'), + 'who was the twenty-second POTUS?' => build_test('Grover Cleveland', 'was', '22nd'), + 'potus 16' => build_test('Abraham Lincoln', 'was', '16th'), 'who is the vice president of the united states?' => undef, - 'vice president of the united states' => undef + 'vice president of the united states' => undef, + 'VPOTUS' => undef ); done_testing; diff --git a/t/PaleoIngredientCheck.t b/t/PaleoIngredientCheck.t index 87b4e560a..a06a4921b 100644 --- a/t/PaleoIngredientCheck.t +++ b/t/PaleoIngredientCheck.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "paleo_ingredient_check"; @@ -56,4 +57,4 @@ ddg_goodie_test( 'paleo recipes' => undef, ); -done_testing; \ No newline at end of file +done_testing; diff --git a/t/Palindrome.t b/t/Palindrome.t index 4f528d494..655e02a3d 100644 --- a/t/Palindrome.t +++ b/t/Palindrome.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'palindrome'; @@ -22,4 +23,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Paper.t b/t/Paper.t index ab959e309..7410bcee3 100644 --- a/t/Paper.t +++ b/t/Paper.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'paper'; diff --git a/t/Parcelforce.t b/t/Parcelforce.t index ce4255b48..dc0799eb9 100644 --- a/t/Parcelforce.t +++ b/t/Parcelforce.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'parcelforce'; @@ -31,4 +32,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/ParseCron.t b/t/ParseCron.t index 7d21d243e..83fcaebc3 100644 --- a/t/ParseCron.t +++ b/t/ParseCron.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'parsecron'; diff --git a/t/Passphrase.t b/t/Passphrase.t index 95ad3610c..a25aa6446 100644 --- a/t/Passphrase.t +++ b/t/Passphrase.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'random_passphrase'; @@ -46,11 +47,11 @@ sub count_words { my $words_re = qr/(?:\s?\b[a-z]+\b){$count}/; return ( - qr/^random passphrase: $words_re$/, + re(qr/^random passphrase: $words_re$/), structured_answer => { input => [($count > 1) ? $count . ' words' : '1 word'], operation => 'Random passphrase', - result => qr/^$words_re$/, + result => re(qr/^$words_re$/), }); } diff --git a/t/Password.t b/t/Password.t index c1b1a0862..3391cfb2d 100644 --- a/t/Password.t +++ b/t/Password.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'pw'; @@ -11,157 +12,157 @@ zci is_cached => 0; ddg_goodie_test( [qw( DDG::Goodie::Password)], 'pw 15 average' => test_zci( - qr/.{15} \(random password\)/, + re(qr/.{15} \(random password\)/), structured_answer => { input => ['15 characters', 'average strength'], operation => 'Random password', - result => qr/^.{15}$/ + result => re(qr/^.{15}$/) } ), 'password normal 15' => test_zci( - qr/.{15} \(random password\)/, + re(qr/.{15} \(random password\)/), structured_answer => { input => ['15 characters', 'average strength'], operation => 'Random password', - result => qr/^.{15}$/ + result => re(qr/^.{15}$/) } ), 'random pw 15 AVG' => test_zci( - qr/.{15} \(random password\)/, + re(qr/.{15} \(random password\)/), structured_answer => { input => ['15 characters', 'average strength'], operation => 'Random password', - result => qr/^.{15}$/ + result => re(qr/^.{15}$/) } ), 'pwgen strong 25' => test_zci( - qr/.{25} \(random password\)/, + re(qr/.{25} \(random password\)/), structured_answer => { input => ['25 characters', 'high strength'], operation => 'Random password', - result => qr/^.{25}$/ + result => re(qr/^.{25}$/) } ), 'password 25 hard' => test_zci( - qr/.{25} \(random password\)/, + re(qr/.{25} \(random password\)/), structured_answer => { input => ['25 characters', 'high strength'], operation => 'Random password', - result => qr/^.{25}$/ + result => re(qr/^.{25}$/) } ), 'Password High 25' => test_zci( - qr/.{25} \(random password\)/, + re(qr/.{25} \(random password\)/), structured_answer => { input => ['25 characters', 'high strength'], operation => 'Random password', - result => qr/^.{25}$/ + result => re(qr/^.{25}$/) } ), # Example queries 'random password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'password strong 15' => test_zci( - qr/.{15} \(random password\)/, + re(qr/.{15} \(random password\)/), structured_answer => { input => ['15 characters', 'high strength'], operation => 'Random password', - result => qr/^.{15}$/ + result => re(qr/^.{15}$/) } ), 'pw' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), # Add some triggers (issue #1565) 'generate password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'generate strong password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'high strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'generate random password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'password generator' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'random password generator' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'random strong password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'high strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'random password 16 characters' => test_zci( - qr/.{16} \(random password\)/, + re(qr/.{16} \(random password\)/), structured_answer => { input => ['16 characters', 'average strength'], operation => 'Random password', - result => qr/^.{16}$/ + result => re(qr/^.{16}$/) } ), 'create random password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'average strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'strong random password' => test_zci( - qr/.{8} \(random password\)/, + re(qr/.{8} \(random password\)/), structured_answer => { input => ['8 characters', 'high strength'], operation => 'Random password', - result => qr/^.{8}$/ + result => re(qr/^.{8}$/) } ), 'random password strong 15' => test_zci( - qr/.{15} \(random password\)/, + re(qr/.{15} \(random password\)/), structured_answer => { input => ['15 characters', 'high strength'], operation => 'Random password', - result => qr/^.{15}$/ + result => re(qr/^.{15}$/) } ), 'password 65' => undef, diff --git a/t/PercentError.t b/t/PercentError.t index d57e942e6..bb15048aa 100644 --- a/t/PercentError.t +++ b/t/PercentError.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'percent_error'; @@ -86,4 +87,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/PercentOf.t b/t/PercentOf.t index 08360cefe..563daead1 100644 --- a/t/PercentOf.t +++ b/t/PercentOf.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "percent_of"; diff --git a/t/Perimeter.t b/t/Perimeter.t index dab532e7b..efc2d8d44 100644 --- a/t/Perimeter.t +++ b/t/Perimeter.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'perimeter'; diff --git a/t/PeriodicTable.t b/t/PeriodicTable.t index dac26bcaa..d2df81173 100644 --- a/t/PeriodicTable.t +++ b/t/PeriodicTable.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "periodic_table"; diff --git a/t/PhoneAlphabet.t b/t/PhoneAlphabet.t index 6371b3c0e..aa9c9f790 100644 --- a/t/PhoneAlphabet.t +++ b/t/PhoneAlphabet.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "phone_alphabet"; diff --git a/t/Phonetic.t b/t/Phonetic.t index 7d90c0dae..b74536249 100644 --- a/t/Phonetic.t +++ b/t/Phonetic.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'phonetic'; diff --git a/t/Pi.t b/t/Pi.t index 9b5ebbb1f..7fe3f9ead 100644 --- a/t/Pi.t +++ b/t/Pi.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/PigLatin.t b/t/PigLatin.t index 1712528a6..aec622a6f 100644 --- a/t/PigLatin.t +++ b/t/PigLatin.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'translation'; diff --git a/t/Poker.t b/t/Poker.t index 010876f6c..0069b0d1a 100644 --- a/t/Poker.t +++ b/t/Poker.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "poker"; diff --git a/t/PrimeFactors.t b/t/PrimeFactors.t index 379c66f66..08bd5ae26 100644 --- a/t/PrimeFactors.t +++ b/t/PrimeFactors.t @@ -5,6 +5,7 @@ use warnings; use utf8; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "prime_factors"; diff --git a/t/PrimeNumber.t b/t/PrimeNumber.t index acfeabe15..b643bb400 100644 --- a/t/PrimeNumber.t +++ b/t/PrimeNumber.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "prime"; diff --git a/t/PrivateNetwork.t b/t/PrivateNetwork.t index bc079cbbb..78e8be4a8 100644 --- a/t/PrivateNetwork.t +++ b/t/PrivateNetwork.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'private_network'; @@ -30,7 +31,7 @@ Benchmarks: 198.18.0.1 - 198.19.255.255 | 198.18.0.0/15 Private network IPv6 addresses (rfc4193): Unique local addresses: fd00::/8 ', - html => qr#.*# + html => re(qr#.*#) )) } ( 'private network', 'private networks', 'private ips' ) ); diff --git a/t/PublicDNS.t b/t/PublicDNS.t index 3ff625c27..03b341320 100644 --- a/t/PublicDNS.t +++ b/t/PublicDNS.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "public_dns"; @@ -11,13 +12,13 @@ zci is_cached => 1; # We don't want to test too specifically on the included data, so just confirm # we got an answer with something approaching the correct form. # Hopefully, some one has eyeballed the output to make sure its got the right data. -my $text_table = qr#^\+-+.*-+\+#m; +my $text_table = re(qr#^\+-+.*-+\+#m); ddg_goodie_test([qw( DDG::Goodie::PublicDNS)], 'public dns' => test_zci( $text_table, structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -29,7 +30,7 @@ ddg_goodie_test([qw( DDG::Goodie::PublicDNS)], 'dns servers' => test_zci( $text_table, structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { diff --git a/t/RIPEMD.t b/t/RIPEMD.t index 7efd28f6d..eebae4665 100644 --- a/t/RIPEMD.t +++ b/t/RIPEMD.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "ripemd"; @@ -422,4 +423,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Rafl.t b/t/Rafl.t index 1e4c83519..3f3f619f1 100644 --- a/t/Rafl.t +++ b/t/Rafl.t @@ -3,12 +3,13 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'rafl'; zci is_cached => 1; -my $intro = qr/^rafl is so everywhere, /; +my $intro = re(qr/^rafl is so everywhere, /); my @rafl = ( $intro, structured_answer => { diff --git a/t/Randagram.t b/t/Randagram.t index fecd224f5..b32ffdbe4 100644 --- a/t/Randagram.t +++ b/t/Randagram.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'randagram'; @@ -10,8 +11,8 @@ zci is_cached => 0; ddg_goodie_test( [qw(DDG::Goodie::Randagram)], - 'randagram algorithm' => test_zci(qr/Randagram of "algorithm": [algorithm]/), - 'randagram jazz hands' => test_zci(qr/Randagram of "jazz hands": [jazz hands]/), + 'randagram algorithm' => test_zci(re(qr/Randagram of "algorithm": [algorithm]/)), + 'randagram jazz hands' => test_zci(re(qr/Randagram of "jazz hands": [jazz hands]/)), ); done_testing; diff --git a/t/RandomName.t b/t/RandomName.t index 8301b6a28..5c4e71c1f 100644 --- a/t/RandomName.t +++ b/t/RandomName.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci is_cached => 0; @@ -12,10 +13,10 @@ ddg_goodie_test( [ 'DDG::Goodie::RandomName' ], - 'random Name' => test_zci (qr/\w\w \(random\)/), - 'random name' => test_zci (qr/\w\w \(random\)/), + 'random Name' => test_zci (re(qr/\w\w \(random\)/)), + 'random name' => test_zci (re(qr/\w\w \(random\)/)), 'random person' => - test_zci (qr/Name: [\w\s]+\nGender: (?:Male|Female)\nDate of birth: \d{4}\-\d{2}\-\d{2}\nAge: \d+/, + test_zci (re(qr/Name: [\w\s]+\nGender: (?:Male|Female)\nDate of birth: \d{4}\-\d{2}\-\d{2}\nAge: \d+/), heading => 'Random Person'), 'random domain name' => undef, 'random city name' => undef, diff --git a/t/RandomNumber.t b/t/RandomNumber.t index b73380d9e..8fe555c9f 100644 --- a/t/RandomNumber.t +++ b/t/RandomNumber.t @@ -3,53 +3,41 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; +use Regexp::Common; zci answer_type => 'rand'; zci is_cached => 0; +sub build_structured_answer { + my ($number_one, $number_two, $response) = @_; + return re(qr/^$response \(random number\)$/), + structured_answer => { + data => { + title => re(qr/^$response$/), + subtitle => "Random number between $number_one - $number_two" + }, + templates => { + group => "text", + } + } +} + +sub build_test { + test_zci(build_structured_answer(@_)); +} + ddg_goodie_test( [qw( DDG::Goodie::RandomNumber )], - 'random number between 12 and 45' => test_zci( - qr/\d{2} \(random number\)/, - structured_answer => { - input => [12, 45], - operation => 'Random number between', - result => qr/^\d{2}$/ - } - ), - 'random number' => test_zci(qr/\d{1}\.\d+ \(random number\)/, - structured_answer => { - input => [0, 1], - operation => 'Random number between', - result => qr/\d{1}\.\d+/, - } - ), - 'random number between 0 and 1' => test_zci( - qr/\d{1} \(random number\)/, - structured_answer => { - input => [0, 1], - operation => 'Random number between', - result => qr/^\d{1}\.\d+$/ - } - ), - 'random number between 0 and 10' => test_zci( - qr/\d{1,2} \(random number\)/, - structured_answer => { - input => [0, 10], - operation => 'Random number between', - result => qr/^\d{1,2}$/ - } - ), - 'random number between 0 and 100' => test_zci( - qr/\d{1,3} \(random number\)/, - structured_answer => { - input => [0, 100], - operation => 'Random number between', - result => qr/^\d{1,3}$/ - } - ), - 'random day' => undef, - 'random access' => undef, + + 'random number between 12 and 45' => build_test(12, 45, qr/\d{2}/), + 'random number' => build_test(0, 1, qr/$RE{num}{real}/), + 'random number between 0 and 1' => build_test(0, 1, qr/$RE{num}{real}/), + 'random number between 0 and 10' => build_test(0, 10, qr/\d{1,2}/), + 'random number between 0 and 100' => build_test(0, 100, qr/\d{1,3}/), + 'random day' => undef, + 'random access' => undef ); -done_testing + +done_testing; diff --git a/t/Rc4.t b/t/Rc4.t index 62e1f0fcf..f84a141c1 100644 --- a/t/Rc4.t +++ b/t/Rc4.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "rc4"; diff --git a/t/Regexp.t b/t/Regexp.t index 633cfaa6f..1096f3614 100644 --- a/t/Regexp.t +++ b/t/Regexp.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'regexp'; diff --git a/t/ResistorColors.t b/t/ResistorColors.t index 62a84bba6..ebfc38e99 100644 --- a/t/ResistorColors.t +++ b/t/ResistorColors.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "resistor_colors"; @@ -35,7 +36,7 @@ sub get_structured_answer { sourceName => "resisto.rs", sourceUrl => "http://resisto.rs/#" . $_[0] }, - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -142,4 +143,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Reverse.t b/t/Reverse.t index e6aceda4c..00ff2845f 100644 --- a/t/Reverse.t +++ b/t/Reverse.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'reverse'; @@ -44,4 +45,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/ReverseComplement.t b/t/ReverseComplement.t index cb3b58587..330b167ce 100644 --- a/t/ReverseComplement.t +++ b/t/ReverseComplement.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'reverse_complement'; @@ -97,4 +98,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/ReverseResistorColours.t b/t/ReverseResistorColours.t index 517d7c62b..1942270d7 100644 --- a/t/ReverseResistorColours.t +++ b/t/ReverseResistorColours.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/Roman.t b/t/Roman.t index 4ce2a1616..dad59be6b 100644 --- a/t/Roman.t +++ b/t/Roman.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'roman_numeral_conversion'; diff --git a/t/Rot13.t b/t/Rot13.t index 2519c5d59..69b4c2c6c 100644 --- a/t/Rot13.t +++ b/t/Rot13.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'rot13'; diff --git a/t/RouterPasswords.t b/t/RouterPasswords.t index 31c34b181..7b6b3a1e4 100644 --- a/t/RouterPasswords.t +++ b/t/RouterPasswords.t @@ -5,6 +5,7 @@ use warnings; # These modules are necessary for the functions we'll be running. use Test::More; +use Test::Deep; use DDG::Test::Goodie; # These zci attributes aren't necessary, but if you specify them inside your diff --git a/t/RubiksCubePatterns.t b/t/RubiksCubePatterns.t index 48f7601f3..882a64181 100644 --- a/t/RubiksCubePatterns.t +++ b/t/RubiksCubePatterns.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'rubiks_cube'; diff --git a/t/SHA3.t b/t/SHA3.t index 82555e4f9..04438a7dd 100644 --- a/t/SHA3.t +++ b/t/SHA3.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "sha3"; @@ -349,4 +350,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/Scramble.t b/t/Scramble.t index a489c8c13..beb99062e 100644 --- a/t/Scramble.t +++ b/t/Scramble.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "scramble"; @@ -15,7 +16,7 @@ ddg_goodie_test( structured_answer => { input => ['filter'], operation => 'Scramble of', - result => '-ANY-', + result => ignore(), } ), 'scramble of' => undef, diff --git a/t/ScreenResolution.t b/t/ScreenResolution.t index 99e2dd852..0f97f217d 100644 --- a/t/ScreenResolution.t +++ b/t/ScreenResolution.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "screen_resolution"; diff --git a/t/SecurityAddons.t b/t/SecurityAddons.t index 822dd4c24..5bc34b0c9 100644 --- a/t/SecurityAddons.t +++ b/t/SecurityAddons.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "security_addons"; diff --git a/t/Sha.t b/t/Sha.t index a9d07f922..b32da27ca 100644 --- a/t/Sha.t +++ b/t/Sha.t @@ -4,6 +4,7 @@ use utf8; use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'sha'; diff --git a/t/Shruggie.t b/t/Shruggie.t index 6cc35fd51..95c2c5b53 100644 --- a/t/Shruggie.t +++ b/t/Shruggie.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; # needed to properly use the various unicode characters in the emoticons diff --git a/t/SigFigs.t b/t/SigFigs.t index 228eb4550..46de3f9d1 100644 --- a/t/SigFigs.t +++ b/t/SigFigs.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'sig_figs'; diff --git a/t/SolarSystem.t b/t/SolarSystem.t index 5aa629cf8..21f4da127 100644 --- a/t/SolarSystem.t +++ b/t/SolarSystem.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use DDG::Test::Location; @@ -11,7 +12,7 @@ zci is_cached => 1; #Structured answer template data my $templateData = { - data => '-ANY-', + data => ignore(), meta => { sourceUrl => "https://solarsystem.nasa.gov/planets/index.cfm", sourceName => "NASA" @@ -110,4 +111,4 @@ ddg_goodie_test( 'radius of orange' => undef ); -done_testing; \ No newline at end of file +done_testing; diff --git a/t/Sort.t b/t/Sort.t index 043e6546e..89a246977 100644 --- a/t/Sort.t +++ b/t/Sort.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'sort'; diff --git a/t/Stardate.t b/t/Stardate.t index 9628640bb..8b458e4ea 100644 --- a/t/Stardate.t +++ b/t/Stardate.t @@ -3,15 +3,16 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "stardate"; zci is_cached => 0; sub build_structured_answer { - return qr/[0-9]{8}\.[0-9]{1,5}/, + return re(qr/[0-9]{8}\.[0-9]{1,5}/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', }, diff --git a/t/SubnetCalc.t b/t/SubnetCalc.t index cf12eea1b..3be44a0ce 100755 --- a/t/SubnetCalc.t +++ b/t/SubnetCalc.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'subnet_calc'; diff --git a/t/Sudoku.t b/t/Sudoku.t index 054bf8782..8aebe0630 100644 --- a/t/Sudoku.t +++ b/t/Sudoku.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'sudoku'; @@ -14,30 +15,30 @@ ddg_goodie_test( 'DDG::Goodie::Sudoku' ], "sudoku" => test_zci( - qr/^[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/^[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), "play sudoku" => test_zci( - qr/^[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/^[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), "easy sudoku" => test_zci( - qr/^[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/^[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), "sudoku hard" => test_zci( - qr/^[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/^[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), "generate sudoku" => test_zci( - qr/^[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/^[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), "sudoku party" => undef, "sudoku toys" => undef, 'sudoku easy' => test_zci( - qr/[0-9_].*[0-9_]$/s, - html => qr/.*\.*/s, + re(qr/[0-9_].*[0-9_]$/s), + html => re(qr/.*\.*/s), ), ); diff --git a/t/SumOfNaturalNumbers.t b/t/SumOfNaturalNumbers.t index 29db10daf..e65c1f48d 100644 --- a/t/SumOfNaturalNumbers.t +++ b/t/SumOfNaturalNumbers.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci is_cached => 1; diff --git a/t/SunInfo.t b/t/SunInfo.t index f558ca850..a47849e96 100755 --- a/t/SunInfo.t +++ b/t/SunInfo.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; use Test::MockTime qw(set_fixed_time); @@ -12,9 +13,9 @@ zci is_cached => 0; set_fixed_time('2014-08-01T00:00:00Z'); # Presume sun will rise in the morning and set at night year round in PA. -my @now = (qr/^On.*Phoenixville, Pennsylvania.*AM.*PM\.$/, +my @now = (re(qr/^On.*Phoenixville, Pennsylvania.*AM.*PM\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -25,9 +26,9 @@ my @now = (qr/^On.*Phoenixville, Pennsylvania.*AM.*PM\.$/, } } ); -my @aug = (qr/^On 30 Aug.*AM.*PM\.$/, +my @aug = (re(qr/^On 30 Aug.*AM.*PM\.$/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -73,9 +74,9 @@ ddg_goodie_test( 'sunset on 2015-01-01' => test_zci(@exact), 'what time is sunrise on 2015-01-01?' => test_zci(@exact), 'January 1st, 2015 sunrise' => test_zci(@exact), - q{sunrise at 39°57'N 5°10'W} => test_zci(qr"On.*Coordinates .*AM.*PM", + q{sunrise at 39°57'N 5°10'W} => test_zci(re(qr"On.*Coordinates .*AM.*PM"), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -86,9 +87,9 @@ ddg_goodie_test( } } ), - 'sunset at 1S 1W' => test_zci(qr"On .*, sunrise in Coordinates -1°N -1°E is at .*AM; sunset at .*PM.", + 'sunset at 1S 1W' => test_zci(re(qr"On .*, sunrise in Coordinates -1°N -1°E is at .*AM; sunset at .*PM."), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -101,7 +102,7 @@ ddg_goodie_test( ), 'sunset at 53N 2E on 2014-01-01' => test_zci("On 01 Jan 2014, sunrise in Coordinates 53°N 2°E is at 3:05 AM; sunset at 10:46 AM.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, @@ -114,7 +115,7 @@ ddg_goodie_test( ), 'sunset at 53N 2W on 2014-01-08' => test_zci("On 08 Jan 2014, sunrise in Coordinates 53°N -2°E is at 3:18 AM; sunset at 11:11 AM.", structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'text', item => 0, diff --git a/t/Teredo.t b/t/Teredo.t index a423b3152..4f2b99600 100644 --- a/t/Teredo.t +++ b/t/Teredo.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'teredo'; diff --git a/t/TimezoneConverter.t b/t/TimezoneConverter.t index 8a3cc6111..abff5945c 100644 --- a/t/TimezoneConverter.t +++ b/t/TimezoneConverter.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); @@ -210,35 +211,35 @@ ddg_goodie_test( }, ), '11:22am cest in my timezone' => - test_zci(qr/5:22 AM EDT/, + test_zci(re(qr/5:22 AM EDT/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/5:22 AM EDT/, + result => re(qr/5:22 AM EDT/), }, ), '11:22am cest in localtime' => - test_zci(qr/5:22 AM EDT/, + test_zci(re(qr/5:22 AM EDT/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/5:22 AM EDT/, + result => re(qr/5:22 AM EDT/), }, ), '11:22am cest in my local timezone' => - test_zci(qr/5:22 AM EDT/, + test_zci(re(qr/5:22 AM EDT/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/5:22 AM EDT/, + result => re(qr/5:22 AM EDT/), }, ), '11:22am cest' => - test_zci(qr/5:22 AM EDT/, + test_zci(re(qr/5:22 AM EDT/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/5:22 AM EDT/, + result => re(qr/5:22 AM EDT/), }, ), '12pm my time in CEST' => @@ -314,19 +315,19 @@ ddg_goodie_test( }, ), '11:22am cest in my timezone' => - test_zci(qr/4:22 AM EST/, + test_zci(re(qr/4:22 AM EST/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/4:22 AM EST/, + result => re(qr/4:22 AM EST/), }, ), '11:22am cest in localtime' => - test_zci(qr/4:22 AM EST/, + test_zci(re(qr/4:22 AM EST/), structured_answer => { input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/], operation => 'Convert Timezone', - result => qr/4:22 AM EST/, + result => re(qr/4:22 AM EST/), }, ), '11:22am cest in my local timezone' => @@ -370,7 +371,7 @@ ddg_goodie_test( }, ), '12am my timezone in UTC' => - test_zci(qr/5:00 AM UTC/, + test_zci(re(qr/5:00 AM UTC/), structured_answer => { input => [qq/Midnight $test_location_tz to UTC/], operation => 'Convert Timezone', @@ -378,7 +379,7 @@ ddg_goodie_test( }, ), '12am local time in UTC' => - test_zci(qr/5:00 AM UTC/, + test_zci(re(qr/5:00 AM UTC/), structured_answer => { input => [qq/Midnight $test_location_tz to UTC/], operation => 'Convert Timezone', @@ -386,7 +387,7 @@ ddg_goodie_test( }, ), '12am in UTC' => - test_zci(qr/5:00 AM UTC/, + test_zci(re(qr/5:00 AM UTC/), structured_answer => { input => [qq/Midnight $test_location_tz to UTC/], operation => 'Convert Timezone', diff --git a/t/Tips.t b/t/Tips.t index 7169359e5..8f8eb1cd7 100644 --- a/t/Tips.t +++ b/t/Tips.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'tip'; diff --git a/t/TitleCase.t b/t/TitleCase.t old mode 100644 new mode 100755 index e355371c5..54078e0aa --- a/t/TitleCase.t +++ b/t/TitleCase.t @@ -3,61 +3,35 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'title_case'; zci is_cached => 1; +sub build_test +{ + my ($text, $input) = @_; + + return test_zci($text, structured_answer => { + data => { + title => $text, + subtitle => 'Title case: '.$input + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::TitleCase)], - 'titlecase test this out' => test_zci( - 'Test This Out', - structured_answer => { - input => ['test this out'], - operation => 'Title case', - result => 'Test This Out' - }, - ), - 'titlecase this is a walk in the park' => test_zci( - 'This Is a Walk in the Park', - structured_answer => { - input => ['this is a walk in the park'], - operation => 'Title case', - result => 'This Is a Walk in the Park' - }, - ), - 'titlecase a good day to die hard' => test_zci( - 'A Good Day to Die Hard', - structured_answer => { - input => ['a good day to die hard'], - operation => 'Title case', - result => 'A Good Day to Die Hard' - }, - ), - 'titlecase A GOOD DAY TO DIE HARD' => test_zci( - 'A Good Day to Die Hard', - structured_answer => { - input => ['A GOOD DAY TO DIE HARD'], - operation => 'Title case', - result => 'A Good Day to Die Hard' - }, - ), - 'titlecase here i am testing-hyphenated-words' => test_zci( - 'Here I Am Testing-Hyphenated-Words', - structured_answer => { - input => ['here i am testing-hyphenated-words'], - operation => 'Title case', - result => 'Here I Am Testing-Hyphenated-Words' - }, - ), - 'titlecase test' => test_zci( - 'Test', - structured_answer => { - input => ['test'], - operation => 'Title case', - result => 'Test' - }, - ), + 'titlecase test this out' => build_test('Test This Out', 'test this out'), + 'titlecase this is a walk in the park' => build_test('This Is a Walk in the Park', 'this is a walk in the park'), + 'titlecase a good day to die hard' => build_test('A Good Day to Die Hard', 'a good day to die hard'), + 'titlecase A GOOD DAY TO DIE HARD' => build_test('A Good Day to Die Hard', 'A GOOD DAY TO DIE HARD'), + 'titlecase here i am testing-hyphenated-words' => build_test('Here I Am Testing-Hyphenated-Words', 'here i am testing-hyphenated-words'), + 'titlecase test' => build_test('Test', 'test'), 'how do i make something titlecase' => undef, ); diff --git a/t/TwelveOclock.t b/t/TwelveOclock.t index 89ccb971e..2d7a0255f 100644 --- a/t/TwelveOclock.t +++ b/t/TwelveOclock.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "twelve_oclock"; diff --git a/t/UN.t b/t/UN.t index 81ebd0737..96ff83ab2 100644 --- a/t/UN.t +++ b/t/UN.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'united_nations'; @@ -64,4 +65,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/UPS.t b/t/UPS.t index f958ec6ce..d61211811 100644 --- a/t/UPS.t +++ b/t/UPS.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'ups'; @@ -31,4 +32,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/URLDecode.t b/t/URLDecode.t index 996fdbe33..b10bc549d 100755 --- a/t/URLDecode.t +++ b/t/URLDecode.t @@ -4,6 +4,7 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use HTML::Entities; use DDG::Test::Goodie; diff --git a/t/URLEncode.t b/t/URLEncode.t index 38940744b..f0526c984 100644 --- a/t/URLEncode.t +++ b/t/URLEncode.t @@ -4,6 +4,7 @@ use strict; use warnings; use utf8; use Test::More; +use Test::Deep; use HTML::Entities; use DDG::Test::Goodie; diff --git a/t/USPS.t b/t/USPS.t index bf36bce60..6858c7951 100644 --- a/t/USPS.t +++ b/t/USPS.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'usps'; @@ -40,4 +41,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/UltimateAnswer.t b/t/UltimateAnswer.t index 6e48663b9..3000c2f81 100644 --- a/t/UltimateAnswer.t +++ b/t/UltimateAnswer.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "ultimate_answer"; diff --git a/t/Unicode.t b/t/Unicode.t index 9ffb77e90..dc1b28c55 100644 --- a/t/Unicode.t +++ b/t/Unicode.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'unicode_conversion'; diff --git a/t/UnicodeFuzzySearch.t b/t/UnicodeFuzzySearch.t index f778ec541..0c72eb7b4 100644 --- a/t/UnicodeFuzzySearch.t +++ b/t/UnicodeFuzzySearch.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci is_cached => 1; diff --git a/t/Unicornify.t b/t/Unicornify.t index 4ad143135..24dcd4494 100644 --- a/t/Unicornify.t +++ b/t/Unicornify.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Unicornify::URL; diff --git a/t/Unidecode.t b/t/Unidecode.t index 45c3a0945..0a263c615 100644 --- a/t/Unidecode.t +++ b/t/Unidecode.t @@ -3,6 +3,7 @@ use utf8; use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'convert_to_ascii'; @@ -19,4 +20,3 @@ ddg_goodie_test( ); done_testing; - diff --git a/t/UnixPermissions.t b/t/UnixPermissions.t index b5f51028e..e14d051f3 100644 --- a/t/UnixPermissions.t +++ b/t/UnixPermissions.t @@ -1,6 +1,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'unix_permissions'; diff --git a/t/UnixTime.t b/t/UnixTime.t index 832b5886d..ff8609993 100644 --- a/t/UnixTime.t +++ b/t/UnixTime.t @@ -3,12 +3,13 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'time_conversion'; zci is_cached => 0; -my @zero = (qr/Thu Jan 01 00:00:00 1970 UTC/, +my @zero = (re(qr/Thu Jan 01 00:00:00 1970 UTC/), structured_answer => { data => { record_data => { @@ -26,7 +27,7 @@ my @zero = (qr/Thu Jan 01 00:00:00 1970 UTC/, } } ); -my @zeroi = (qr/Thu Jan 01 00:00:00 1970 UTC/, +my @zeroi = (re(qr/Thu Jan 01 00:00:00 1970 UTC/), structured_answer => { data => { record_data => { @@ -45,9 +46,9 @@ my @zeroi = (qr/Thu Jan 01 00:00:00 1970 UTC/, } ); -my @now = (qr/Unix Epoch./, +my @now = (re(qr/Unix Epoch./), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -56,9 +57,9 @@ my @now = (qr/Unix Epoch./, } } ); -my @then = (qr/Tue Nov 18 00:28:30 1930 UTC/, +my @then = (re(qr/Tue Nov 18 00:28:30 1930 UTC/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -67,9 +68,9 @@ my @then = (qr/Tue Nov 18 00:28:30 1930 UTC/, } } ); -my @later = (qr/Tue Jan 19 03:14:07 2038 UTC/, +my @later = (re(qr/Tue Jan 19 03:14:07 2038 UTC/), structured_answer => { - data => '-ANY-', + data => ignore(), templates => { group => 'list', options => { @@ -83,28 +84,29 @@ ddg_goodie_test([qw( DDG::Goodie::UnixTime ) ], - 'unix time 0000000000000' => test_zci(@zero), - 'epoch 0' => test_zci(@zeroi), - 'utc time 0' => test_zci(@zeroi), - 'epoch 2147483647' => test_zci(@later), - '2147483647 epoch' => test_zci(@later), - 'timestamp 2147483647' => test_zci(@later), - 'utc time 2147483647' => test_zci(@later), - 'datetime' => test_zci(@now), - 'unix time' => test_zci(@now), - 'unix epoch' => test_zci(@now), - 'utc time' => test_zci(@now), - 'utc now' => test_zci(@now), - 'current utc' => test_zci(@now), - 'time since epoch' => test_zci(@now), - 'epoch -1234567890' => test_zci(@then), - '-1234567890 epoch' => test_zci(@then), - 'timestamp -1234567890' => test_zci(@then), - 'utc time -1234567890' => test_zci(@then), - 'timestamp' => undef, - 'time' => undef, - 'epoch' => undef, - 'unix time info' => undef, + 'unix time 0000000000000' => test_zci(@zero), + 'epoch 0' => test_zci(@zeroi), + 'utc time 0' => test_zci(@zeroi), + 'epoch 2147483647' => test_zci(@later), + '2147483647 epoch' => test_zci(@later), + 'timestamp 2147483647' => test_zci(@later), + 'utc time 2147483647' => test_zci(@later), + 'epoch converter 2147483647' => test_zci(@later), + 'datetime' => test_zci(@now), + 'unix time' => test_zci(@now), + 'unix epoch' => test_zci(@now), + 'utc time' => test_zci(@now), + 'utc now' => test_zci(@now), + 'current utc' => test_zci(@now), + 'time since epoch' => test_zci(@now), + 'epoch -1234567890' => test_zci(@then), + '-1234567890 epoch' => test_zci(@then), + 'timestamp -1234567890' => test_zci(@then), + 'utc time -1234567890' => test_zci(@then), + 'timestamp' => undef, + 'time' => undef, + 'epoch' => undef, + 'unix time info' => undef, ); done_testing; diff --git a/t/Uppercase.t b/t/Uppercase.t old mode 100644 new mode 100755 index 149d33d59..4e8177ed3 --- a/t/Uppercase.t +++ b/t/Uppercase.t @@ -3,37 +3,31 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'uppercase'; zci is_cached => 1; +sub build_test +{ + my ($text, $subtitle) = @_; + return test_zci($text, structured_answer => { + data => { + title => $text, + subtitle => "Uppercase: $subtitle" + }, + templates => { + group => 'text' + } + }); +} + ddg_goodie_test( [qw( DDG::Goodie::Uppercase)], - 'upper case this' => test_zci( - 'THIS', - structured_answer => { - input => ['this'], - operation => 'Uppercase', - result => 'THIS' - } - ), - 'uppercase that' => test_zci( - 'THAT', - structured_answer => { - input => ['that'], - operation => 'Uppercase', - result => 'THAT' - } - ), - 'allcaps this string' => test_zci( - 'THIS STRING', - structured_answer => { - input => ['this string'], - operation => 'Uppercase', - result => 'THIS STRING' - } - ), + 'upper case this' => build_test('THIS', 'this'), + 'uppercase that' => build_test('THAT', 'that'), + 'allcaps this string' => build_test('THIS STRING','this string'), 'that string all caps' => undef, 'is this uppercase, sir?' => undef, 'uppercase HELLO' => undef, diff --git a/t/Uptime.t b/t/Uptime.t index 54fc5f407..15235ae82 100644 --- a/t/Uptime.t +++ b/t/Uptime.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "uptime"; diff --git a/t/VIN.t b/t/VIN.t index 7733280d5..da7a178ac 100644 --- a/t/VIN.t +++ b/t/VIN.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'vin'; diff --git a/t/ValarMorghulis.t b/t/ValarMorghulis.t index c97855886..5ef5e1e67 100644 --- a/t/ValarMorghulis.t +++ b/t/ValarMorghulis.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'valar_morghulis'; @@ -14,9 +15,13 @@ ddg_goodie_test( 'valar morghulis' => test_zci( 'Valar dohaeris', structured_answer => { - input => ['Valar morghulis'], - operation => 'Code phrase', - result => 'Valar dohaeris' + data => { + title => 'Valar dohaeris', + subtitle => 'Code phrase: Valar morghulis' + }, + templates => { + group => 'text' + } } ), 'what is valar morghulis' => undef, diff --git a/t/Wavelength.t b/t/Wavelength.t index 6c80c045c..c52230ffd 100644 --- a/t/Wavelength.t +++ b/t/Wavelength.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use utf8; diff --git a/t/Week.t b/t/Week.t index a020ab139..d01aba334 100755 --- a/t/Week.t +++ b/t/Week.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); @@ -10,11 +11,11 @@ zci answer_type => "week"; zci is_cached => 1; my @current_week = ( - qr/We are currently in the \d{1,2}\w{2} week of \d{4}./, + re(qr/We are currently in the \d{1,2}\w{2} week of \d{4}./), structured_answer => { input => [], operation => 'Assuming the week starts on Monday', - result => qr/We are currently in the \d{1,2}\w{2} week of \d{4}./, + result => re(qr/We are currently in the \d{1,2}\w{2} week of \d{4}./), }); @@ -95,14 +96,14 @@ ddg_goodie_test( ), # Nth Week Queries "what was the 5th week of this year" => test_zci( - qr/The \d{1,2}\w{2} week of \d{4} (begins|began) on January \d{1,2}\w{2}\./, + re(qr/The \d{1,2}\w{2} week of \d{4} (begins|began) on January \d{1,2}\w{2}\./), structured_answer => { input => [], operation => "Assuming the week starts on Monday", - result => qr/The \d{1,2}\w{2} week of \d{4} (begins|began) on January \d{1,2}\w{2}\./, + result => re(qr/The \d{1,2}\w{2} week of \d{4} (begins|began) on January \d{1,2}\w{2}\./), } ) ); restore_time(); -done_testing; \ No newline at end of file +done_testing; diff --git a/t/WeekdaysBetween.t b/t/WeekdaysBetween.t index 12ddca463..42fd71129 100755 --- a/t/WeekdaysBetween.t +++ b/t/WeekdaysBetween.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'weekdays_between'; diff --git a/t/Weight.t b/t/Weight.t index 82824e090..2965f613c 100644 --- a/t/Weight.t +++ b/t/Weight.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => "weight"; diff --git a/t/WhereAmI.t b/t/WhereAmI.t index ee5d3db0a..f9b30626e 100644 --- a/t/WhereAmI.t +++ b/t/WhereAmI.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'where_am_i'; diff --git a/t/WorkdaysBetween.t b/t/WorkdaysBetween.t index 9e077a407..0110502ab 100755 --- a/t/WorkdaysBetween.t +++ b/t/WorkdaysBetween.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all ); @@ -213,20 +214,20 @@ ddg_goodie_test( DDG::Goodie::WorkdaysBetween )], 'business days between jan 10 and jan 20' => test_zci( - qr"There are [1-9] Workdays between 10 Jan [0-9]{4} and 20 Jan [0-9]{4}\.", + re(qr"There are [1-9] Workdays between 10 Jan [0-9]{4} and 20 Jan [0-9]{4}\."), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Workdays between', - result => qr/[1-9]/, + result => re(qr/[1-9]/), } ), 'business days between january and february' => test_zci( - qr"There are [1-9][0-9] Workdays between 01 Jan [0-9]{4} and 01 Feb [0-9]{4}\.", + re(qr"There are [1-9][0-9] Workdays between 01 Jan [0-9]{4} and 01 Feb [0-9]{4}\."), structured_answer => { - input => '-ANY-', + input => ignore(), operation => 'Workdays between', - result => qr/[1-9][0-9]/, + result => re(qr/[1-9][0-9]/), } ), ); diff --git a/t/ZappBrannigan.t b/t/ZappBrannigan.t index 836f092c2..90c70b034 100644 --- a/t/ZappBrannigan.t +++ b/t/ZappBrannigan.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; zci answer_type => 'zapp_brannigan'; @@ -11,11 +12,18 @@ zci is_cached => 0; ddg_goodie_test( [qw( DDG::Goodie::ZappBrannigan )], 'zapp brannigan quote' => test_zci( - qr/Zapp Brannigan: /, + re('Zapp Brannigan: '), structured_answer => { - input => [], - operation => 'Zapp Brannigan quote', - result => qr/Zapp Brannigan: /, + data => { + subtitle => 'Zapp Brannigan quote', + content => re('Zapp Brannigan: ') + }, + templates => { + group => "text", + options => { + content => 'DDH.zapp_brannigan.content' + } + } }, ), ); diff --git a/t/Zodiac.t b/t/Zodiac.t index a4e5ad8ac..699ccc056 100644 --- a/t/Zodiac.t +++ b/t/Zodiac.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; use DDG::Test::Goodie; use Test::MockTime qw( :all );