diff --git a/lib/DDG/Goodie/Loan.pm b/lib/DDG/Goodie/Loan.pm index 5a7e67f1c..5e77db5ac 100644 --- a/lib/DDG/Goodie/Loan.pm +++ b/lib/DDG/Goodie/Loan.pm @@ -50,9 +50,7 @@ sub normalize_formatted_currency_string { my $decimal_separator = decimal_separator($currency_code) // '.'; $str =~ s/\Q$thousands_separator//g; - if ($decimal_separator ne ".") { - $str =~ s/\Q$decimal_separator/\./g; - } + $str =~ s/\Q$decimal_separator/\./g if ($decimal_separator ne "."); return $str; } @@ -73,17 +71,15 @@ handle remainder => sub { # Check if query contains number of years for loan, if so, save value and remove it if ($query =~ /(\d+) ?(?:year|yr)s?/) { - $years = $1; - $query =~ s/(\d+) ?(?:year|yr)s?//; + $years = $1; + $query =~ s/(\d+) ?(?:year|yr)s?//; } # Try to extract the interest rate and remove it. Interest rate is required. - if ($query =~ /(\d+\.?\d*)%/) { - $rate = $1; - $query =~ s/(\d+\.?\d*)%//; - } else { - return; - } + return unless ($query =~ /(\d+\.?\d*)%/); + + $rate = $1; + $query =~ s/(\d+\.?\d*)%//; # Downpayment information that may be discovered. It will be combined with the discovered currency. my $downpayment_in_query = 0; @@ -92,56 +88,63 @@ handle remainder => sub { # Check if query contains downpayment information if ($query =~ /(\p{Currency_Symbol})?(\d+)\s?([A-Za-z]{3})?(%)? down/) { - $downpayment_in_query = 1; - $downpayment_is_in_cash = ! (defined $4); - $downpayment_without_units = $2; - $query =~ s/(\p{Currency_Symbol})?(\d+)\s?([A-Za-z]{3})?(%)? down//; + $downpayment_in_query = 1; + $downpayment_is_in_cash = ! (defined $4); + $downpayment_without_units = $2; + $query =~ s/(\p{Currency_Symbol})?(\d+)\s?([A-Za-z]{3})?(%)? down//; } # At a minimum, query should contain some amount of money if ($query =~ /(\p{Currency_Symbol})?([\d\.,]+)\s?([A-Za-z]{3})?/) { - my $symbol = $1; - my $principal = $2; - my $input_currency_code = $3; - my $downpayment = 0; + my $symbol = $1; + my $principal = $2; + my $input_currency_code = $3; + my $downpayment = 0; - if (defined $input_currency_code) { - $input_currency_code = uc($input_currency_code); - } + $input_currency_code = uc($input_currency_code) if (defined $input_currency_code); - # Apply localization, default to US if unknown - my $currency_code = "USD"; - if (defined $input_currency_code && exists $supported_currency_codes{$input_currency_code}) { - $currency_code = $input_currency_code; - } elsif (defined $symbol) { - $currency_code = convert_symbol_to_currency($symbol, lc $loc->country_code); - } elsif (defined $loc->country_code) { - $currency_code = $country_to_currency{lc $loc->country_code} || $country_to_currency{"us"}; - $symbol = currency_symbol($currency_code); - } + # Apply localization, default to US if unknown + my $currency_code = "USD"; + if (defined $input_currency_code && exists $supported_currency_codes{$input_currency_code}) { + $currency_code = $input_currency_code; + } elsif (defined $symbol) { + $currency_code = convert_symbol_to_currency($symbol, lc $loc->country_code); + } elsif (defined $loc->country_code) { + $currency_code = $country_to_currency{lc $loc->country_code} || $country_to_currency{"us"}; + $symbol = currency_symbol($currency_code); + } - # Given the country code and currency formatting rules, the input can be made ready to convert - # to a useable number. - $principal = normalize_formatted_currency_string($principal, $currency_code); + # Given the country code and currency formatting rules, the input can be made ready to convert + # to a useable number. + $principal = normalize_formatted_currency_string($principal, $currency_code); - # Deal with downpayment information if it was found in the query - if ($downpayment_in_query) { - if ($downpayment_is_in_cash) { - # Downpayment expresses in an amount of currency - $downpayment = normalize_formatted_currency_string($downpayment_without_units, $currency_code); - } else { - # Downpayment expressed as a percentage of principal - $downpayment = $principal * .01 * $downpayment_without_units; - } - } + # Deal with downpayment information if it was found in the query + if ($downpayment_in_query) { + if ($downpayment_is_in_cash) { + # Downpayment expresses in an amount of currency + $downpayment = normalize_formatted_currency_string($downpayment_without_units, $currency_code); + } else { + # Downpayment expressed as a percentage of principal + $downpayment = $principal * .01 * $downpayment_without_units; + } + } - my $loan_amount = $principal - $downpayment; - my $monthly_payment = loan_monthly_payment($loan_amount, $rate / 12 * .01, $years * 12); - my $total_interest = ($monthly_payment * 12 * $years) - $loan_amount; + my $loan_amount = $principal - $downpayment; + my $monthly_payment = loan_monthly_payment($loan_amount, $rate / 12 * .01, $years * 12); + my $total_interest = ($monthly_payment * 12 * $years) - $loan_amount; - return "Monthly Payment is " . currency_format($currency_code, $monthly_payment, FMT_SYMBOL) . - " for $years years. Total interest paid is " . - currency_format($currency_code, $total_interest, FMT_SYMBOL); + my $title = currency_format($currency_code, $monthly_payment, FMT_SYMBOL) . " for $years years"; + my $subtitle = "Total interest paid is " . currency_format($currency_code, $total_interest, FMT_SYMBOL); + my $string_answer = "Montly payment is " . $title . ". " . $subtitle; + return $string_answer, structured_answer => { + data => { + title => $title, + subtitle => $subtitle, + }, + templates => { + group => 'text' + } + } } return; @@ -152,484 +155,484 @@ handle remainder => sub { # has also not been updated since 2007. If the mapping between any country and currency needs to be # changed, this is where to change it. %country_to_currency = ( - 'ad' => 'EUR', - 'ae' => 'AED', - 'af' => 'AFA', - 'ag' => 'XCD', - 'ai' => 'XCD', - 'al' => 'ALL', - 'am' => 'AMD', - 'an' => 'ANG', - 'ao' => 'AOA', - 'aq' => '000', - 'ar' => 'ARS', - 'as' => 'USD', - 'at' => 'EUR', - 'au' => 'AUD', - 'aw' => 'AWG', - 'az' => 'AZM', - 'ba' => 'BAM', - 'bb' => 'BBD', - 'bd' => 'BDT', - 'be' => 'EUR', - 'bf' => 'XOF', - 'bg' => 'BGL', - 'bh' => 'BHD', - 'bi' => 'BIF', - 'bj' => 'XOF', - 'bm' => 'BMD', - 'bn' => 'BND', - 'bo' => 'BOB', - 'br' => 'BRL', - 'bs' => 'BSD', - 'bt' => 'BTN', - 'bv' => 'NOK', - 'bw' => 'BWP', - 'by' => 'BYR', - 'bz' => 'BZD', - 'ca' => 'CAD', - 'cc' => 'AUD', - 'cd' => 'CDF', - 'cf' => 'XAF', - 'cg' => 'XAF', - 'ch' => 'CHF', - 'ci' => 'XOF', - 'ck' => 'NZD', - 'cl' => 'CLP', - 'cm' => 'XAF', - 'cn' => 'CNY', - 'co' => 'COP', - 'cr' => 'CRC', - 'cu' => 'CUP', - 'cv' => 'CVE', - 'cx' => 'AUD', - 'cy' => 'CYP', - 'cz' => 'CZK', - 'de' => 'EUR', - 'dj' => 'DJF', - 'dk' => 'DKK', - 'dm' => 'XCD', - 'do' => 'DOP', - 'dz' => 'DZD', - 'ec' => 'ECS', - 'ee' => 'EEK', - 'eg' => 'EGP', - 'eh' => 'MAD', - 'er' => 'ERN', - 'es' => 'EUR', - 'et' => 'ETB', - 'fi' => 'EUR', - 'fj' => 'FJD', - 'fk' => 'FKP', - 'fm' => 'USD', - 'fo' => 'DKK', - 'fr' => 'EUR', - 'fx' => 'EUR', - 'ga' => 'XAF', - 'gb' => 'GBP', - 'gd' => 'XCD', - 'ge' => 'GEL', - 'gf' => 'EUR', - 'gh' => 'GHC', - 'gi' => 'GIP', - 'gl' => 'DKK', - 'gm' => 'GMD', - 'gn' => 'GNF', - 'gp' => 'EUR', - 'gq' => 'GQE', - 'gr' => 'EUR', - 'gs' => 'GBP', - 'gt' => 'GTQ', - 'gu' => 'USD', - 'gw' => 'XOF', - 'gy' => 'GYD', - 'hk' => 'HKD', - 'hm' => 'AUD', - 'hn' => 'HNL', - 'hr' => 'HRK', - 'ht' => 'HTG', - 'hu' => 'HUF', - 'id' => 'IDR', - 'ie' => 'EUR', - 'il' => 'ILS', - 'in' => 'INR', - 'io' => 'GBP', - 'iq' => 'IQD', - 'ir' => 'IRR', - 'is' => 'ISK', - 'it' => 'EUR', - 'jm' => 'JMD', - 'jo' => 'JOD', - 'jp' => 'JPY', - 'ke' => 'KES', - 'kg' => 'KGS', - 'kh' => 'KHR', - 'ki' => 'AUD', - 'km' => 'KMF', - 'kn' => 'XCD', - 'kp' => 'KPW', - 'kr' => 'KRW', - 'kw' => 'KWD', - 'ky' => 'KYD', - 'kz' => 'KZT', - 'la' => 'LAK', - 'lb' => 'LBP', - 'lc' => 'XCD', - 'li' => 'CHF', - 'lk' => 'LKR', - 'lr' => 'LRD', - 'ls' => 'LSL', - 'lt' => 'LTL', - 'lu' => 'EUR', - 'lv' => 'LVL', - 'ly' => 'LYD', - 'ma' => 'MAD', - 'mc' => 'EUR', - 'md' => 'MDL', - 'me' => 'YUM', - 'mg' => 'MGF', - 'mh' => 'USD', - 'mk' => 'MKD', - 'ml' => 'XOF', - 'mm' => 'MMK', - 'mn' => 'MNT', - 'mo' => 'MOP', - 'mp' => 'USD', - 'mq' => 'EUR', - 'mr' => 'MRO', - 'ms' => 'XCD', - 'mt' => 'MTL', - 'mu' => 'MUR', - 'mv' => 'MVR', - 'mw' => 'MWK', - 'mx' => 'MXN', - 'my' => 'MYR', - 'mz' => 'MZM', - 'na' => 'NAD', - 'nc' => 'XPF', - 'ne' => 'XOF', - 'nf' => 'AUD', - 'ng' => 'NGN', - 'ni' => 'NIO', - 'nl' => 'EUR', - 'no' => 'NOK', - 'np' => 'NPR', - 'nr' => 'AUD', - 'nu' => 'NZD', - 'nz' => 'NZD', - 'om' => 'OMR', - 'pa' => 'PAB', - 'pe' => 'PEN', - 'pf' => 'XPF', - 'pg' => 'PGK', - 'ph' => 'PHP', - 'pk' => 'PKR', - 'pl' => 'PLN', - 'pm' => 'EUR', - 'pn' => 'NZD', - 'pr' => 'USD', - 'ps' => 'ILS', - 'pt' => 'EUR', - 'pw' => 'USD', - 'py' => 'PYG', - 'qa' => 'QAR', - 're' => 'EUR', - 'ro' => 'ROL', - 'rs' => 'YUM', - 'ru' => 'RUB', - 'rw' => 'RWF', - 'sa' => 'SAR', - 'sb' => 'SBD', - 'sc' => 'SCR', - 'sd' => 'SDP', - 'se' => 'SEK', - 'sg' => 'SGD', - 'sh' => 'SHP', - 'si' => 'SIT', - 'sj' => 'NOK', - 'sk' => 'SKK', - 'sl' => 'SLL', - 'sm' => 'EUR', - 'sn' => 'XOF', - 'so' => 'SOS', - 'sr' => 'SRG', - 'st' => 'STD', - 'sv' => 'SVC', - 'sy' => 'SYP', - 'sz' => 'SZL', - 'tc' => 'USD', - 'td' => 'XAF', - 'tf' => 'EUR', - 'tg' => 'XOF', - 'th' => 'THB', - 'tj' => 'TJS', - 'tk' => 'NZD', - 'tl' => 'IDR', - 'tm' => 'TMM', - 'tn' => 'TND', - 'to' => 'TOP', - 'tr' => 'TRL', - 'tt' => 'TTD', - 'tv' => 'AUD', - 'tw' => 'TWD', - 'tz' => 'TZS', - 'ua' => 'UAH', - 'ug' => 'UGX', - 'um' => 'USD', - 'us' => 'USD', - 'uy' => 'UYU', - 'uz' => 'UZS', - 'va' => 'EUR', - 'vc' => 'XCD', - 've' => 'VEB', - 'vg' => 'USD', - 'vi' => 'USD', - 'vn' => 'VND', - 'vu' => 'VUV', - 'wf' => 'XPF', - 'ws' => 'WST', - 'ye' => 'YER', - 'yt' => 'EUR', - 'yu' => 'YUM', - 'za' => 'ZAR', - 'zm' => 'ZMK', - 'zr' => 'XAF', - 'zw' => 'ZWD'); + 'ad' => 'EUR', + 'ae' => 'AED', + 'af' => 'AFA', + 'ag' => 'XCD', + 'ai' => 'XCD', + 'al' => 'ALL', + 'am' => 'AMD', + 'an' => 'ANG', + 'ao' => 'AOA', + 'aq' => '000', + 'ar' => 'ARS', + 'as' => 'USD', + 'at' => 'EUR', + 'au' => 'AUD', + 'aw' => 'AWG', + 'az' => 'AZM', + 'ba' => 'BAM', + 'bb' => 'BBD', + 'bd' => 'BDT', + 'be' => 'EUR', + 'bf' => 'XOF', + 'bg' => 'BGL', + 'bh' => 'BHD', + 'bi' => 'BIF', + 'bj' => 'XOF', + 'bm' => 'BMD', + 'bn' => 'BND', + 'bo' => 'BOB', + 'br' => 'BRL', + 'bs' => 'BSD', + 'bt' => 'BTN', + 'bv' => 'NOK', + 'bw' => 'BWP', + 'by' => 'BYR', + 'bz' => 'BZD', + 'ca' => 'CAD', + 'cc' => 'AUD', + 'cd' => 'CDF', + 'cf' => 'XAF', + 'cg' => 'XAF', + 'ch' => 'CHF', + 'ci' => 'XOF', + 'ck' => 'NZD', + 'cl' => 'CLP', + 'cm' => 'XAF', + 'cn' => 'CNY', + 'co' => 'COP', + 'cr' => 'CRC', + 'cu' => 'CUP', + 'cv' => 'CVE', + 'cx' => 'AUD', + 'cy' => 'CYP', + 'cz' => 'CZK', + 'de' => 'EUR', + 'dj' => 'DJF', + 'dk' => 'DKK', + 'dm' => 'XCD', + 'do' => 'DOP', + 'dz' => 'DZD', + 'ec' => 'ECS', + 'ee' => 'EEK', + 'eg' => 'EGP', + 'eh' => 'MAD', + 'er' => 'ERN', + 'es' => 'EUR', + 'et' => 'ETB', + 'fi' => 'EUR', + 'fj' => 'FJD', + 'fk' => 'FKP', + 'fm' => 'USD', + 'fo' => 'DKK', + 'fr' => 'EUR', + 'fx' => 'EUR', + 'ga' => 'XAF', + 'gb' => 'GBP', + 'gd' => 'XCD', + 'ge' => 'GEL', + 'gf' => 'EUR', + 'gh' => 'GHC', + 'gi' => 'GIP', + 'gl' => 'DKK', + 'gm' => 'GMD', + 'gn' => 'GNF', + 'gp' => 'EUR', + 'gq' => 'GQE', + 'gr' => 'EUR', + 'gs' => 'GBP', + 'gt' => 'GTQ', + 'gu' => 'USD', + 'gw' => 'XOF', + 'gy' => 'GYD', + 'hk' => 'HKD', + 'hm' => 'AUD', + 'hn' => 'HNL', + 'hr' => 'HRK', + 'ht' => 'HTG', + 'hu' => 'HUF', + 'id' => 'IDR', + 'ie' => 'EUR', + 'il' => 'ILS', + 'in' => 'INR', + 'io' => 'GBP', + 'iq' => 'IQD', + 'ir' => 'IRR', + 'is' => 'ISK', + 'it' => 'EUR', + 'jm' => 'JMD', + 'jo' => 'JOD', + 'jp' => 'JPY', + 'ke' => 'KES', + 'kg' => 'KGS', + 'kh' => 'KHR', + 'ki' => 'AUD', + 'km' => 'KMF', + 'kn' => 'XCD', + 'kp' => 'KPW', + 'kr' => 'KRW', + 'kw' => 'KWD', + 'ky' => 'KYD', + 'kz' => 'KZT', + 'la' => 'LAK', + 'lb' => 'LBP', + 'lc' => 'XCD', + 'li' => 'CHF', + 'lk' => 'LKR', + 'lr' => 'LRD', + 'ls' => 'LSL', + 'lt' => 'LTL', + 'lu' => 'EUR', + 'lv' => 'LVL', + 'ly' => 'LYD', + 'ma' => 'MAD', + 'mc' => 'EUR', + 'md' => 'MDL', + 'me' => 'YUM', + 'mg' => 'MGF', + 'mh' => 'USD', + 'mk' => 'MKD', + 'ml' => 'XOF', + 'mm' => 'MMK', + 'mn' => 'MNT', + 'mo' => 'MOP', + 'mp' => 'USD', + 'mq' => 'EUR', + 'mr' => 'MRO', + 'ms' => 'XCD', + 'mt' => 'MTL', + 'mu' => 'MUR', + 'mv' => 'MVR', + 'mw' => 'MWK', + 'mx' => 'MXN', + 'my' => 'MYR', + 'mz' => 'MZM', + 'na' => 'NAD', + 'nc' => 'XPF', + 'ne' => 'XOF', + 'nf' => 'AUD', + 'ng' => 'NGN', + 'ni' => 'NIO', + 'nl' => 'EUR', + 'no' => 'NOK', + 'np' => 'NPR', + 'nr' => 'AUD', + 'nu' => 'NZD', + 'nz' => 'NZD', + 'om' => 'OMR', + 'pa' => 'PAB', + 'pe' => 'PEN', + 'pf' => 'XPF', + 'pg' => 'PGK', + 'ph' => 'PHP', + 'pk' => 'PKR', + 'pl' => 'PLN', + 'pm' => 'EUR', + 'pn' => 'NZD', + 'pr' => 'USD', + 'ps' => 'ILS', + 'pt' => 'EUR', + 'pw' => 'USD', + 'py' => 'PYG', + 'qa' => 'QAR', + 're' => 'EUR', + 'ro' => 'ROL', + 'rs' => 'YUM', + 'ru' => 'RUB', + 'rw' => 'RWF', + 'sa' => 'SAR', + 'sb' => 'SBD', + 'sc' => 'SCR', + 'sd' => 'SDP', + 'se' => 'SEK', + 'sg' => 'SGD', + 'sh' => 'SHP', + 'si' => 'SIT', + 'sj' => 'NOK', + 'sk' => 'SKK', + 'sl' => 'SLL', + 'sm' => 'EUR', + 'sn' => 'XOF', + 'so' => 'SOS', + 'sr' => 'SRG', + 'st' => 'STD', + 'sv' => 'SVC', + 'sy' => 'SYP', + 'sz' => 'SZL', + 'tc' => 'USD', + 'td' => 'XAF', + 'tf' => 'EUR', + 'tg' => 'XOF', + 'th' => 'THB', + 'tj' => 'TJS', + 'tk' => 'NZD', + 'tl' => 'IDR', + 'tm' => 'TMM', + 'tn' => 'TND', + 'to' => 'TOP', + 'tr' => 'TRL', + 'tt' => 'TTD', + 'tv' => 'AUD', + 'tw' => 'TWD', + 'tz' => 'TZS', + 'ua' => 'UAH', + 'ug' => 'UGX', + 'um' => 'USD', + 'us' => 'USD', + 'uy' => 'UYU', + 'uz' => 'UZS', + 'va' => 'EUR', + 'vc' => 'XCD', + 've' => 'VEB', + 'vg' => 'USD', + 'vi' => 'USD', + 'vn' => 'VND', + 'vu' => 'VUV', + 'wf' => 'XPF', + 'ws' => 'WST', + 'ye' => 'YER', + 'yt' => 'EUR', + 'yu' => 'YUM', + 'za' => 'ZAR', + 'zm' => 'ZMK', + 'zr' => 'XAF', + 'zw' => 'ZWD'); %symbol_to_currency = ( - "\x{20a1}" => [ - "CRC", - ], - "Ls" => [ - "LVL", - ], - "TT\$" => [ - "TTD", - ], - "\x{20ae}" => [ - "MNT", - ], - "\x{043b}\x{0432}" => [ - "BGN", - "KZT", - "KGS", - "UZS", - ], - "Z\$" => [ - "ZWD", - ], - "\x{0e3f}" => [ - "THB", - ], - "CHF" => [ - "CHF", - ], - "\x{0434}\x{0435}\x{043d}" => [ - "MKD", - ], - "p." => [ - "BYR", - ], - "\x{20a9}" => [ - "KPW", - "KRW", - "KPW", - "KRW", - ], - "S/." => [ - "PEN", - ], - "NT\$" => [ - "TWD", - ], - "\x{0414}\x{0438}\x{043d}." => [ - "RSD", - ], - "Bs" => [ - "VEF", - ], - "K\x{010d}" => [ - "CZK", - ], - "\x{fdfc}" => [ - "IRR", - "OMR", - "QAR", - "SAR", - "YER", - ], - "J\$" => [ - "JMD", - ], - "\x{00a2}" => [ - "GHC", - ], - "\x{17db}" => [ - "KHR", - ], - "lei" => [ - "RON", - ], - "R" => [ - "ZAR", - ], - "\x{043c}\x{0430}\x{043d}" => [ - "AZN", - ], - "\x{20b1}" => [ - "CUP", - "PHP", - ], - "Gs" => [ - "PYG", - ], - "\$" => [ - "USD", - "ARS", - "AUD", - "BSD", - "BBD", - "BMD", - "BND", - "CAD", - "KYD", - "CLP", - "COP", - "XCD", - "SVC", - "FJD", - "GYD", - "HKD", - "LRD", - "MXN", - "NAD", - "NZD", - "SGD", - "SBD", - "SRD", - "TVD", - ], - "\x{20a6}" => [ - "NGN", - ], - "kn" => [ - "HRK", - ], - "\x{0192}" => [ - "AWG", - "ANG", - ], - "kr" => [ - "DKK", - "EEK", - "ISK", - "NOK", - "SEK", - ], - "S" => [ - "SOS", - ], - "\x{20ab}" => [ - "VND", - ], - "Lek" => [ - "ALL", - ], - "P" => [ - "BWP", - ], - "BZ\$" => [ - "BZD", - ], - "R\$" => [ - "BRL", - ], - "\x{20aa}" => [ - "ILS", - ], - "MT" => [ - "MZN", - ], - "Rp" => [ - "IDR", - ], - "\$b" => [ - "BOB", - ], - "Lt" => [ - "LTL", - ], - "Ft" => [ - "HUF", - ], - "C\$" => [ - "NIO", - ], - "\x{00a3}" => [ - "GBP", - "EGP", - "FKP", - "GIP", - "GGP", - "IMP", - "JEP", - "LBP", - "SHP", - "SYP", - ], - "\x{20a8}" => [ - "MUR", - "NPR", - "PKR", - "SCR", - "LKR", - ], - "\x{00a5}" => [ - "CNY", - "JPY", - ], - "\x{20ad}" => [ - "LAK", - ], - "z\x{0142}" => [ - "PLN", - ], - "\x{20b4}" => [ - "UAH", - ], - "B/." => [ - "PAB", - ], - "\x{060b}" => [ - "AFN", - ], - "\x{20ac}" => [ - "EUR", - ], - "L" => [ - "HNL", - ], - "RD\$" => [ - "DOP", - ], - "KM" => [ - "BAM", - ], - "\$U" => [ - "UYU", - ], - "\x{20a4}" => [ - "TRL", - ], - "Q" => [ - "GTQ", - ], - "RM" => [ - "MYR", - ], - "\x{0440}\x{0443}\x{0431}" => [ - "RUB", - ], + "\x{20a1}" => [ + "CRC", + ], + "Ls" => [ + "LVL", + ], + "TT\$" => [ + "TTD", + ], + "\x{20ae}" => [ + "MNT", + ], + "\x{043b}\x{0432}" => [ + "BGN", + "KZT", + "KGS", + "UZS", + ], + "Z\$" => [ + "ZWD", + ], + "\x{0e3f}" => [ + "THB", + ], + "CHF" => [ + "CHF", + ], + "\x{0434}\x{0435}\x{043d}" => [ + "MKD", + ], + "p." => [ + "BYR", + ], + "\x{20a9}" => [ + "KPW", + "KRW", + "KPW", + "KRW", + ], + "S/." => [ + "PEN", + ], + "NT\$" => [ + "TWD", + ], + "\x{0414}\x{0438}\x{043d}." => [ + "RSD", + ], + "Bs" => [ + "VEF", + ], + "K\x{010d}" => [ + "CZK", + ], + "\x{fdfc}" => [ + "IRR", + "OMR", + "QAR", + "SAR", + "YER", + ], + "J\$" => [ + "JMD", + ], + "\x{00a2}" => [ + "GHC", + ], + "\x{17db}" => [ + "KHR", + ], + "lei" => [ + "RON", + ], + "R" => [ + "ZAR", + ], + "\x{043c}\x{0430}\x{043d}" => [ + "AZN", + ], + "\x{20b1}" => [ + "CUP", + "PHP", + ], + "Gs" => [ + "PYG", + ], + "\$" => [ + "USD", + "ARS", + "AUD", + "BSD", + "BBD", + "BMD", + "BND", + "CAD", + "KYD", + "CLP", + "COP", + "XCD", + "SVC", + "FJD", + "GYD", + "HKD", + "LRD", + "MXN", + "NAD", + "NZD", + "SGD", + "SBD", + "SRD", + "TVD", + ], + "\x{20a6}" => [ + "NGN", + ], + "kn" => [ + "HRK", + ], + "\x{0192}" => [ + "AWG", + "ANG", + ], + "kr" => [ + "DKK", + "EEK", + "ISK", + "NOK", + "SEK", + ], + "S" => [ + "SOS", + ], + "\x{20ab}" => [ + "VND", + ], + "Lek" => [ + "ALL", + ], + "P" => [ + "BWP", + ], + "BZ\$" => [ + "BZD", + ], + "R\$" => [ + "BRL", + ], + "\x{20aa}" => [ + "ILS", + ], + "MT" => [ + "MZN", + ], + "Rp" => [ + "IDR", + ], + "\$b" => [ + "BOB", + ], + "Lt" => [ + "LTL", + ], + "Ft" => [ + "HUF", + ], + "C\$" => [ + "NIO", + ], + "\x{00a3}" => [ + "GBP", + "EGP", + "FKP", + "GIP", + "GGP", + "IMP", + "JEP", + "LBP", + "SHP", + "SYP", + ], + "\x{20a8}" => [ + "MUR", + "NPR", + "PKR", + "SCR", + "LKR", + ], + "\x{00a5}" => [ + "CNY", + "JPY", + ], + "\x{20ad}" => [ + "LAK", + ], + "z\x{0142}" => [ + "PLN", + ], + "\x{20b4}" => [ + "UAH", + ], + "B/." => [ + "PAB", + ], + "\x{060b}" => [ + "AFN", + ], + "\x{20ac}" => [ + "EUR", + ], + "L" => [ + "HNL", + ], + "RD\$" => [ + "DOP", + ], + "KM" => [ + "BAM", + ], + "\$U" => [ + "UYU", + ], + "\x{20a4}" => [ + "TRL", + ], + "Q" => [ + "GTQ", + ], + "RM" => [ + "MYR", + ], + "\x{0440}\x{0443}\x{0431}" => [ + "RUB", + ], ); foreach my $code (values %country_to_currency) { diff --git a/t/Loan.t b/t/Loan.t index c2ee8a17e..e2e4ea1b5 100644 --- a/t/Loan.t +++ b/t/Loan.t @@ -12,230 +12,247 @@ use utf8; zci answer_type => 'loan'; zci is_cached => 1; +sub build_answer { + my($title, $subtitle) = @_; + return "Montly payment is " . $title . ". " . $subtitle, + structured_answer => { + data => { + title => $title, + subtitle => $subtitle + }, + templates => { + group => 'text', + } + }; +} + +sub build_test { test_zci(build_answer(@_)) } + ddg_goodie_test ( - [ - 'DDG::Goodie::Loan' - ], - 'loan 400000 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'loan $400000 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'loan $500000 at 4.5% with 20% down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'loan $500000 at 4.5% with $100000 down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'loan $250000 3% interest 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'loan $300000 at 3% interest with $50000 downpayment for 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'loan $300000 3% $50000 down 15 year' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'loan €400000 at 4.5%' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'loan £250000 3% interest 15 years' => - test_zci('Monthly Payment is £1,726.45 for 15 years. Total interest paid is £60,761.74'), - 'loan $400,000.00 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'loan €250.000,00 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'loan 250.000,00 EUR 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'loan 500000 EUR at 4.5% 100000 EUR down' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'loan for 23000 with 5000 down and 12% interest' => - test_zci('Monthly Payment is $185.15 for 30 years. Total interest paid is $48,654.10'), - 'loan 50000 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $160.82 for 30 years. Total interest paid is $7,894.96'), - 'loan 5 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $0.01 for 30 years. Total interest paid is $0.63'), - '5 year loan with 3% interest on $23,000 1000 down' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), - 'loan with $1000 down at 3% for $23,000 for 5 years' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), - 'borrow 400000 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'borrow $400000 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'borrow $500000 at 4.5% with 20% down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'borrow $500000 at 4.5% with $100000 down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'borrow $250000 3% interest 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'borrow $300000 at 3% interest with $50000 downpayment for 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'borrow $300000 3% $50000 down 15 year' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'borrow €400000 at 4.5%' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'borrow £250000 3% interest 15 years' => - test_zci('Monthly Payment is £1,726.45 for 15 years. Total interest paid is £60,761.74'), - 'borrow $400,000.00 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'borrow €250.000,00 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'borrow 250.000,00 EUR 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'borrow 500000 EUR at 4.5% 100000 EUR down' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'borrow for 23000 with 5000 down and 12% interest' => - test_zci('Monthly Payment is $185.15 for 30 years. Total interest paid is $48,654.10'), - 'borrow 50000 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $160.82 for 30 years. Total interest paid is $7,894.96'), - 'borrow 5 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $0.01 for 30 years. Total interest paid is $0.63'), - '5 year borrow with 3% interest on $23,000 1000 down' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), - 'borrow with $1000 down at 3% for $23,000 for 5 years' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), - 'mortgage 400000 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'mortgage $400000 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'mortgage $500000 at 4.5% with 20% down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'mortgage $500000 at 4.5% with $100000 down' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'mortgage $250000 3% interest 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'mortgage $300000 at 3% interest with $50000 downpayment for 15 years' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'mortgage $300000 3% $50000 down 15 year' => - test_zci('Monthly Payment is $1,726.45 for 15 years. Total interest paid is $60,761.74'), - 'mortgage €400000 at 4.5%' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'mortgage £250000 3% interest 15 years' => - test_zci('Monthly Payment is £1,726.45 for 15 years. Total interest paid is £60,761.74'), - 'mortgage $400,000.00 at 4.5%' => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - 'mortgage €250.000,00 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'mortgage 250.000,00 EUR 3% interest 15 years' => - test_zci('Monthly Payment is €1.726,45 for 15 years. Total interest paid is €60.761,74'), - 'mortgage 500000 EUR at 4.5% 100000 EUR down' => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - 'mortgage for 23000 with 5000 down and 12% interest' => - test_zci('Monthly Payment is $185.15 for 30 years. Total interest paid is $48,654.10'), - 'mortgage 50000 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $160.82 for 30 years. Total interest paid is $7,894.96'), - 'mortgage 5 usd at 1% 1 usd down' => - test_zci('Monthly Payment is $0.01 for 30 years. Total interest paid is $0.63'), - '5 year mortgage with 3% interest on $23,000 1000 down' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), - 'loan with $1000 down at 3% for $23,000 for 5 years' => - test_zci('Monthly Payment is $395.31 for 5 years. Total interest paid is $1,718.67'), + [ + 'DDG::Goodie::Loan' + ], + 'loan 400000 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'loan $400000 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'loan $500000 4.5% with 20% down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'loan $500000 4.5% with $100000 down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'loan $250000 3% interest 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'loan $300000 at 3% interest with $50000 downpayment for 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'loan $300000 3% $50000 down 15 year' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'loan €400000 at 4.5%' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'loan £250000 3% interest 15 years' => + build_test('£1,726.45 for 15 years', 'Total interest paid is £60,761.74'), + 'loan $400,000.00 at 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'loan €250.000,00 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'loan 250.000,00 EUR 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'loan 500000 EUR at 4.5% 100000 EUR down' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'loan for 23000 with 5000 down and 12% interest' => + build_test('$185.15 for 30 years', 'Total interest paid is $48,654.10'), + 'loan 50000 usd at 1% 1 usd down' => + build_test('$160.82 for 30 years', 'Total interest paid is $7,894.96'), + 'loan 5 usd at 1% 1 usd down' => + build_test('$0.01 for 30 years', 'Total interest paid is $0.63'), + '5 year loan with 3% interest on $23,000 1000 down' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), + 'loan with $1000 down at 3% for $23,000 for 5 years' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), + 'borrow 400000 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'borrow $400000 at 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'borrow $500000 at 4.5% with 20% down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'borrow $500000 at 4.5% with $100000 down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'borrow $250000 3% interest 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'borrow $300000 at 3% interest with $50000 downpayment for 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'borrow $300000 3% $50000 down 15 year' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'borrow €400000 at 4.5%' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'borrow £250000 3% interest 15 years' => + build_test('£1,726.45 for 15 years', 'Total interest paid is £60,761.74'), + 'borrow $400,000.00 at 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'borrow €250.000,00 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'borrow 250.000,00 EUR 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'borrow 500000 EUR at 4.5% 100000 EUR down' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'borrow for 23000 with 5000 down and 12% interest' => + build_test('$185.15 for 30 years', 'Total interest paid is $48,654.10'), + 'borrow 50000 usd at 1% 1 usd down' => + build_test('$160.82 for 30 years', 'Total interest paid is $7,894.96'), + 'borrow 5 usd at 1% 1 usd down' => + build_test('$0.01 for 30 years', 'Total interest paid is $0.63'), + '5 year borrow with 3% interest on $23,000 1000 down' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), + 'borrow with $1000 down at 3% for $23,000 for 5 years' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), + 'mortgage 400000 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'mortgage $400000 at 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'mortgage $500000 at 4.5% with 20% down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'mortgage $500000 at 4.5% with $100000 down' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'mortgage $250000 3% interest 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'mortgage $300000 at 3% interest with $50000 downpayment for 15 years' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'mortgage $300000 3% $50000 down 15 year' => + build_test('$1,726.45 for 15 years', 'Total interest paid is $60,761.74'), + 'mortgage €400000 at 4.5%' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'mortgage £250000 3% interest 15 years' => + build_test('£1,726.45 for 15 years', 'Total interest paid is £60,761.74'), + 'mortgage $400,000.00 at 4.5%' => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + 'mortgage €250.000,00 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'mortgage 250.000,00 EUR 3% interest 15 years' => + build_test('€1.726,45 for 15 years', 'Total interest paid is €60.761,74'), + 'mortgage 500000 EUR at 4.5% 100000 EUR down' => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + 'mortgage for 23000 with 5000 down and 12% interest' => + build_test('$185.15 for 30 years', 'Total interest paid is $48,654.10'), + 'mortgage 50000 usd at 1% 1 usd down' => + build_test('$160.82 for 30 years', 'Total interest paid is $7,894.96'), + 'mortgage 5 usd at 1% 1 usd down' => + build_test('$0.01 for 30 years', 'Total interest paid is $0.63'), + '5 year mortgage with 3% interest on $23,000 1000 down' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), + 'loan with $1000 down at 3% for $23,000 for 5 years' => + build_test('$395.31 for 5 years', 'Total interest paid is $1,718.67'), - # Test a few cases of inferring user's location with 'loan' trigger word - DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("in")) => - test_zci('Monthly Payment is ₨2,026.74 for 30 years. Total interest paid is ₨329,626.85'), + # Test a few cases of inferring user's location with 'loan' trigger word + DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("de")) => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("in")) => + build_test('₨2,026.74 for 30 years', 'Total interest paid is ₨329,626.85'), # Given a common currency symbol and location, make sure we get the correct currency - DDG::Request->new(query_raw => "loan \$400000 4.5%", location => test_location("au")) => - test_zci('Monthly Payment is $2 026.74 for 30 years. Total interest paid is $329 626.85'), - # Malaysia has no symbol, just the currency code after the amounts - DDG::Request->new(query_raw => "loan 400000 MYR at 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - # Test that symbol overrides user's location - DDG::Request->new(query_raw => "loan \$400,000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - # Imagine a new country later appears, test defaulting to USD because we don't know about it - DDG::Request->new(query_raw => "loan 400000 4.5%", location => DDG::Location->new( - { - country_code => 'LL', - country_code3 => 'LLA', - country_name => 'Llama Land', - region => '9', - region_name => 'Llama Region', - city => 'New Llama City', - latitude => '90.0000', - longitude => '0.0000', - time_zone => 'America/New_York', - area_code => 0, - continent_code => 'NA', - metro_code => 0 - } - )) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), + DDG::Request->new(query_raw => "loan \$400000 4.5%", location => test_location("au")) => + build_test('$2 026.74 for 30 years', 'Total interest paid is $329 626.85'), + # Malaysia has no symbol, just the currency code after the amounts + DDG::Request->new(query_raw => "loan 400000 MYR at 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + DDG::Request->new(query_raw => "loan 400000 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + # Test that symbol overrides user's location + DDG::Request->new(query_raw => "loan \$400,000 4.5%", location => test_location("de")) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + # Imagine a new country later appears, test defaulting to USD because we don't know about it + DDG::Request->new(query_raw => "loan 400000 4.5%", location => DDG::Location->new( + { + country_code => 'LL', + country_code3 => 'LLA', + country_name => 'Llama Land', + region => '9', + region_name => 'Llama Region', + city => 'New Llama City', + latitude => '90.0000', + longitude => '0.0000', + time_zone => 'America/New_York', + area_code => 0, + continent_code => 'NA', + metro_code => 0 + } + )) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), - # Test a few cases of inferring user's location with 'borrow' trigger word - DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("in")) => - test_zci('Monthly Payment is ₨2,026.74 for 30 years. Total interest paid is ₨329,626.85'), + # Test a few cases of inferring user's location with 'borrow' trigger word + DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("de")) => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("in")) => + build_test('₨2,026.74 for 30 years', 'Total interest paid is ₨329,626.85'), # Given a common currency symbol and location, make sure we get the correct currency - DDG::Request->new(query_raw => "borrow \$400000 4.5%", location => test_location("au")) => - test_zci('Monthly Payment is $2 026.74 for 30 years. Total interest paid is $329 626.85'), - # Malaysia has no symbol, just the currency code after the amounts - DDG::Request->new(query_raw => "borrow 400000 MYR at 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - # Test that symbol overrides user's location - DDG::Request->new(query_raw => "borrow \$400,000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - # Imagine a new country later appears, test defaulting to USD because we don't know about it - DDG::Request->new(query_raw => "borrow 400000 4.5%", location => DDG::Location->new( - { - country_code => 'LL', - country_code3 => 'LLA', - country_name => 'Llama Land', - region => '9', - region_name => 'Llama Region', - city => 'New Llama City', - latitude => '90.0000', - longitude => '0.0000', - time_zone => 'America/New_York', - area_code => 0, - continent_code => 'NA', - metro_code => 0 - } - )) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), + DDG::Request->new(query_raw => "borrow \$400000 4.5%", location => test_location("au")) => + build_test('$2 026.74 for 30 years', 'Total interest paid is $329 626.85'), + # Malaysia has no symbol, just the currency code after the amounts + DDG::Request->new(query_raw => "borrow 400000 MYR at 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + DDG::Request->new(query_raw => "borrow 400000 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + # Test that symbol overrides user's location + DDG::Request->new(query_raw => "borrow \$400,000 4.5%", location => test_location("de")) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + # Imagine a new country later appears, test defaulting to USD because we don't know about it + DDG::Request->new(query_raw => "borrow 400000 4.5%", location => DDG::Location->new( + { + country_code => 'LL', + country_code3 => 'LLA', + country_name => 'Llama Land', + region => '9', + region_name => 'Llama Region', + city => 'New Llama City', + latitude => '90.0000', + longitude => '0.0000', + time_zone => 'America/New_York', + area_code => 0, + continent_code => 'NA', + metro_code => 0 + } + )) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), - # Test a few cases of inferring user's location with 'mortgage' trigger word - DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is €2.026,74 for 30 years. Total interest paid is €329.626,85'), - DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("in")) => - test_zci('Monthly Payment is ₨2,026.74 for 30 years. Total interest paid is ₨329,626.85'), + # Test a few cases of inferring user's location with 'mortgage' trigger word + DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("de")) => + build_test('€2.026,74 for 30 years', 'Total interest paid is €329.626,85'), + DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("in")) => + build_test('₨2,026.74 for 30 years', 'Total interest paid is ₨329,626.85'), # Given a common currency symbol and location, make sure we get the correct currency - DDG::Request->new(query_raw => "mortgage \$400000 4.5%", location => test_location("au")) => - test_zci('Monthly Payment is $2 026.74 for 30 years. Total interest paid is $329 626.85'), - # Malaysia has no symbol, just the currency code after the amounts - DDG::Request->new(query_raw => "mortgage 400000 MYR at 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("my")) => - test_zci('Monthly Payment is 2,026.74 MYR for 30 years. Total interest paid is 329,626.85 MYR'), - # Test that symbol overrides user's location - DDG::Request->new(query_raw => "mortgage \$400,000 4.5%", location => test_location("de")) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), - # Imagine a new country later appears, test defaulting to USD because we don't know about it - DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => DDG::Location->new( - { - country_code => 'LL', - country_code3 => 'LLA', - country_name => 'Llama Land', - region => '9', - region_name => 'Llama Region', - city => 'New Llama City', - latitude => '90.0000', - longitude => '0.0000', - time_zone => 'America/New_York', - area_code => 0, - continent_code => 'NA', - metro_code => 0 - } - )) => - test_zci('Monthly Payment is $2,026.74 for 30 years. Total interest paid is $329,626.85'), + DDG::Request->new(query_raw => "mortgage \$400000 4.5%", location => test_location("au")) => + build_test('$2 026.74 for 30 years', 'Total interest paid is $329 626.85'), + # Malaysia has no symbol, just the currency code after the amounts + DDG::Request->new(query_raw => "mortgage 400000 MYR at 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => test_location("my")) => + build_test('2,026.74 MYR for 30 years', 'Total interest paid is 329,626.85 MYR'), + # Test that symbol overrides user's location + DDG::Request->new(query_raw => "mortgage \$400,000 4.5%", location => test_location("de")) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), + # Imagine a new country later appears, test defaulting to USD because we don't know about it + DDG::Request->new(query_raw => "mortgage 400000 4.5%", location => DDG::Location->new( + { + country_code => 'LL', + country_code3 => 'LLA', + country_name => 'Llama Land', + region => '9', + region_name => 'Llama Region', + city => 'New Llama City', + latitude => '90.0000', + longitude => '0.0000', + time_zone => 'America/New_York', + area_code => 0, + continent_code => 'NA', + metro_code => 0 + } + )) => + build_test('$2,026.74 for 30 years', 'Total interest paid is $329,626.85'), 'loan $500000 at 4.5% with 20% down 15 years' => - test_zci('Monthly Payment is $3,059.97 for 15 years. Total interest paid is $150,795.17'), + build_test('$3,059.97 for 15 years', 'Total interest paid is $150,795.17'), 'borrow $500000 4.5%' => - test_zci('Monthly Payment is $2,533.43 for 30 years. Total interest paid is $412,033.56'), + build_test('$2,533.43 for 30 years', 'Total interest paid is $412,033.56'), 'mortgage $500000 4.5% 20% down 15 years' => - test_zci('Monthly Payment is $3,059.97 for 15 years. Total interest paid is $150,795.17'), + build_test('$3,059.97 for 15 years', 'Total interest paid is $150,795.17'), ); done_testing; +