Skip to content

Commit

Permalink
some customizations and more tests in aim of getting test suite for 2…
Browse files Browse the repository at this point in the history
….0 the way i want
  • Loading branch information
rsl committed Mar 22, 2013
1 parent 2d8d484 commit bb441c1
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/stringex/localization/conversion_expressions.rb
Expand Up @@ -66,7 +66,7 @@ module ConversionExpressions
:double_quote => %w{#34 #822[012] quot ldquo rdquo dbquo},
:ellipsis => %w{#8230 hellip},
:en_dash => %w{#8211 ndash},
:em_dash => %w{#8212 emdash},
:em_dash => %w{#8212 mdash},
:frac14 => %w{#188 frac14},
:frac12 => %w{#189 frac12},
:frac34 => %w{#190 frac34},
Expand Down
1 change: 1 addition & 0 deletions lib/stringex/localization/converter.rb
Expand Up @@ -94,6 +94,7 @@ def html_entities
expressions.html_entities.each do |key, expression|
string.gsub! expression, translate(key, :html_entities)
end
string.squeeze! ' '
end

def vulgar_fractions
Expand Down
8 changes: 4 additions & 4 deletions lib/stringex/localization/default_conversions.rb
Expand Up @@ -7,7 +7,7 @@ module DefaultConversions
:and => "and",
:at => "at",
:degrees => "degrees",
:divide => "divide",
:divide => "divided by",
:dot => '\1 dot \2',
:ellipsis => "dot dot dot",
:equals => "equals",
Expand Down Expand Up @@ -36,7 +36,7 @@ module DefaultConversions
:cent => " cents",
:copy => "(c)",
:deg => " degrees ",
:divide => "divide",
:divide => " divided by ",
:double_quote => '"',
:ellipsis => "...",
:en_dash => "-",
Expand All @@ -47,12 +47,12 @@ module DefaultConversions
:gt => ">",
:lt => "<",
:nbsp => " ",
:pound => " pounds",
:pound => " pounds ",
:reg => "(r)",
:single_quote => "'",
:times => "x",
:trade => "(tm)",
:yen => " yen"
:yen => " yen "
}

TRANSLITERATIONS = {}
Expand Down
128 changes: 97 additions & 31 deletions test/localization/default_test.rb
Expand Up @@ -9,40 +9,106 @@ def setup
Stringex::Localization.backend = :internal
end

def test_convert_miscellaneous_characters
{
"Foo & bar make foobar" => "Foo and bar make foobar",
"Breakdown #9" => "Breakdown number 9",
"foo@bar.com" => "foo at bar dot com",
"100% of yr love" => "100 percent of yr love",
"Kisses are $3.25 each" => "Kisses are 3 dollars 25 cents each",
"That CD is £3.25 plus tax" => "That CD is 3 pounds 25 pence plus tax",
"This CD is ¥1000 instead" => "This CD is 1000 yen instead",
"In Europe you can buy it for €2 or €4.10" => "In Europe you can buy it for 2 euros or 4 euros 10 cents",
"Food+Drink" => "Food plus Drink",
"this & that #2 @ bla.bla for $3" => "this and that number 2 at bla dot bla for 3 dollars",
"three + four ÷ 40 ° fahrenheit... end" => "three plus four divide 40 degrees fahrenheit dot dot dot end",
"£4 but ¥5 * 100% = two" => "4 pounds but 5 yen star 100 percent equals two",
"N.A.S.A. is cool" => "NASA is cool",
"That's not fair" => "Thats not fair",
"That`s not fair either" => "Thats not fair either",
" whitespace maintained " => " whitespace maintained ",
}.each do |misc, plain|
assert_equal plain, misc.convert_miscellaneous_characters
{
"foo & bar" => "foo and bar",
"AT&T" => "AT and T",
"99° is normal" => "99 degrees is normal",
"4 ÷ 2 is 2" => "4 divided by 2 is 2",
"webcrawler.com" => "webcrawler dot com",
"Well..." => "Well dot dot dot",
"x=1" => "x equals 1",
"a #2 pencil" => "a number 2 pencil",
"100%" => "100 percent",
"cost+tax" => "cost plus tax",
"batman/robin fan fiction" => "batman slash robin fan fiction",
"dial *69" => "dial star 69",
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
}.each do |original, converted|
define_method "test_character_conversion: '#{original}'" do
assert_equal converted, original.convert_miscellaneous_characters
end
end

def test_convert_miscellaneous_html_entities
{
"America&#8482;" => "America(tm)",
"Tea &amp; Sympathy" => "Tea and Sympathy",
"To be continued&#8230;" => "To be continued...",
"Foo&nbsp;Bar" => "Foo Bar",
"100&#163;" => "100 pounds",
"35&deg;" => "35 degrees",
" whitespace maintained " => " whitespace maintained ",
}.each do |entitied, plain|
assert_equal plain, entitied.convert_miscellaneous_html_entities
{
"$100" => "100 dollars",
"$19.99" => "19 dollars 99 cents",
"£100" => "100 pounds",
"£19.99" => "19 pounds 99 pence",
"€100" => "100 euros",
"€19.99" => "19 euros 99 cents",
"¥1000" => "1000 yen"
}.each do |original, converted|
define_method "test_currency_conversion: '#{original}'" do
assert_equal converted, original.convert_miscellaneous_characters
end
end

{
"Tea &amp; Sympathy" => "Tea and Sympathy",
"10&cent;" => "10 cents",
"&copy;2000" => "(c)2000",
"98&deg; is fine" => "98 degrees is fine",
"10&divide;5" => "10 divided by 5",
"&quot;quoted&quot;" => '"quoted"',
"to be continued&hellip;" => "to be continued...",
"2000&ndash;2004" => "2000-2004",
"I wish&mdash;oh, never mind" => "I wish--oh, never mind",
"&frac12; ounce of gold" => "half ounce of gold",
"1 and &frac14; ounces of silver" => "1 and one fourth ounces of silver",
"9 and &frac34; ounces of platinum" => "9 and three fourths ounces of platinum",
"3&gt;2" => "3>2",
"2&lt;3" => "2<3",
"two&nbsp;words" => "two words",
"&pound;100" => "pounds 100",
"Walmart&reg;" => "Walmart(r)",
"&apos;single quoted&apos;" => "'single quoted'",
"2&times;4" => "2x4",
"Programming&trade;" => "Programming(tm)",
"&yen;20000" => "yen 20000",
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
}.each do |original, converted|
define_method "test_html_entity_conversion: '#{original}'" do
assert_equal converted, original.convert_miscellaneous_html_entities
end
end

{
"&frac12;" => "half",
"½" => "half",
"&#189;" => "half",
"⅓" => "one third",
"&#8531;" => "one third",
"⅔" => "two thirds",
"&#8532;" => "two thirds",
"&frac14;" => "one fourth",
"¼" => "one fourth",
"&#188;" => "one fourth",
"&frac34;" => "three fourths",
"¾" => "three fourths",
"&#190;" => "three fourths",
"⅕" => "one fifth",
"&#8533;" => "one fifth",
"⅖" => "two fifths",
"&#8534;" => "two fifths",
"⅗" => "three fifths",
"&#8535;" => "three fifths",
"⅘" => "four fifths",
"&#8536;" => "four fifths",
"⅙" => "one sixth",
"&#8537;" => "one sixth",
"⅚" => "five sixths",
"&#8538;" => "five sixths",
"⅛" => "one eighth",
"&#8539;" => "one eighth",
"⅜" => "three eighths",
"&#8540;" => "three eighths",
"⅝" => "five eighths",
"&#8541;" => "five eighths",
"⅞" => "seven eighths",
"&#8542;" => "seven eighths"
}.each do |original, converted|
define_method "test_vulgar_fractions_conversion: #{original}" do
assert_equal converted, original.convert_vulgar_fractions
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/string_extensions_test.rb
Expand Up @@ -53,7 +53,7 @@ def test_to_url
"21'17ʼ51" =>
"21-17-51",
"ITCZ÷1 (21°17ʼ51.78”N / 89°35ʼ28.18”O / 26-04-08 / 09:00 am)" =>
"itcz-divide-1-21-degrees-17-51-dot-78-n-slash-89-degrees-35-28-dot-18-o-slash-26-04-08-slash-09-00-am",
"itcz-divided-by-1-21-degrees-17-51-dot-78-n-slash-89-degrees-35-28-dot-18-o-slash-26-04-08-slash-09-00-am",
"/" =>
"slash",
"私はガラスを食べられます。それは私を傷つけません。" =>
Expand Down

0 comments on commit bb441c1

Please sign in to comment.