Skip to content
This repository
Browse code

some customizations and more tests in aim of getting test suite for 2…

….0 the way i want
  • Loading branch information...
commit bb441c14fbbed3b59182bcaa0b038931170fcb67 1 parent 2d8d484
Russell Norris authored
2  lib/stringex/localization/conversion_expressions.rb
@@ -66,7 +66,7 @@ module ConversionExpressions
66 66 :double_quote => %w{#34 #822[012] quot ldquo rdquo dbquo},
67 67 :ellipsis => %w{#8230 hellip},
68 68 :en_dash => %w{#8211 ndash},
69   - :em_dash => %w{#8212 emdash},
  69 + :em_dash => %w{#8212 mdash},
70 70 :frac14 => %w{#188 frac14},
71 71 :frac12 => %w{#189 frac12},
72 72 :frac34 => %w{#190 frac34},
1  lib/stringex/localization/converter.rb
@@ -94,6 +94,7 @@ def html_entities
94 94 expressions.html_entities.each do |key, expression|
95 95 string.gsub! expression, translate(key, :html_entities)
96 96 end
  97 + string.squeeze! ' '
97 98 end
98 99
99 100 def vulgar_fractions
8 lib/stringex/localization/default_conversions.rb
@@ -7,7 +7,7 @@ module DefaultConversions
7 7 :and => "and",
8 8 :at => "at",
9 9 :degrees => "degrees",
10   - :divide => "divide",
  10 + :divide => "divided by",
11 11 :dot => '\1 dot \2',
12 12 :ellipsis => "dot dot dot",
13 13 :equals => "equals",
@@ -36,7 +36,7 @@ module DefaultConversions
36 36 :cent => " cents",
37 37 :copy => "(c)",
38 38 :deg => " degrees ",
39   - :divide => "divide",
  39 + :divide => " divided by ",
40 40 :double_quote => '"',
41 41 :ellipsis => "...",
42 42 :en_dash => "-",
@@ -47,12 +47,12 @@ module DefaultConversions
47 47 :gt => ">",
48 48 :lt => "<",
49 49 :nbsp => " ",
50   - :pound => " pounds",
  50 + :pound => " pounds ",
51 51 :reg => "(r)",
52 52 :single_quote => "'",
53 53 :times => "x",
54 54 :trade => "(tm)",
55   - :yen => " yen"
  55 + :yen => " yen "
56 56 }
57 57
58 58 TRANSLITERATIONS = {}
128 test/localization/default_test.rb
@@ -9,40 +9,106 @@ def setup
9 9 Stringex::Localization.backend = :internal
10 10 end
11 11
12   - def test_convert_miscellaneous_characters
13   - {
14   - "Foo & bar make foobar" => "Foo and bar make foobar",
15   - "Breakdown #9" => "Breakdown number 9",
16   - "foo@bar.com" => "foo at bar dot com",
17   - "100% of yr love" => "100 percent of yr love",
18   - "Kisses are $3.25 each" => "Kisses are 3 dollars 25 cents each",
19   - "That CD is £3.25 plus tax" => "That CD is 3 pounds 25 pence plus tax",
20   - "This CD is ¥1000 instead" => "This CD is 1000 yen instead",
21   - "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",
22   - "Food+Drink" => "Food plus Drink",
23   - "this & that #2 @ bla.bla for $3" => "this and that number 2 at bla dot bla for 3 dollars",
24   - "three + four ÷ 40 ° fahrenheit... end" => "three plus four divide 40 degrees fahrenheit dot dot dot end",
25   - "£4 but ¥5 * 100% = two" => "4 pounds but 5 yen star 100 percent equals two",
26   - "N.A.S.A. is cool" => "NASA is cool",
27   - "That's not fair" => "Thats not fair",
28   - "That`s not fair either" => "Thats not fair either",
29   - " whitespace maintained " => " whitespace maintained ",
30   - }.each do |misc, plain|
31   - assert_equal plain, misc.convert_miscellaneous_characters
  12 + {
  13 + "foo & bar" => "foo and bar",
  14 + "AT&T" => "AT and T",
  15 + "99° is normal" => "99 degrees is normal",
  16 + "4 ÷ 2 is 2" => "4 divided by 2 is 2",
  17 + "webcrawler.com" => "webcrawler dot com",
  18 + "Well..." => "Well dot dot dot",
  19 + "x=1" => "x equals 1",
  20 + "a #2 pencil" => "a number 2 pencil",
  21 + "100%" => "100 percent",
  22 + "cost+tax" => "cost plus tax",
  23 + "batman/robin fan fiction" => "batman slash robin fan fiction",
  24 + "dial *69" => "dial star 69",
  25 + " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
  26 + }.each do |original, converted|
  27 + define_method "test_character_conversion: '#{original}'" do
  28 + assert_equal converted, original.convert_miscellaneous_characters
32 29 end
33 30 end
34 31
35   - def test_convert_miscellaneous_html_entities
36   - {
37   - "America&#8482;" => "America(tm)",
38   - "Tea &amp; Sympathy" => "Tea and Sympathy",
39   - "To be continued&#8230;" => "To be continued...",
40   - "Foo&nbsp;Bar" => "Foo Bar",
41   - "100&#163;" => "100 pounds",
42   - "35&deg;" => "35 degrees",
43   - " whitespace maintained " => " whitespace maintained ",
44   - }.each do |entitied, plain|
45   - assert_equal plain, entitied.convert_miscellaneous_html_entities
  32 + {
  33 + "$100" => "100 dollars",
  34 + "$19.99" => "19 dollars 99 cents",
  35 + "£100" => "100 pounds",
  36 + "£19.99" => "19 pounds 99 pence",
  37 + "€100" => "100 euros",
  38 + "€19.99" => "19 euros 99 cents",
  39 + "¥1000" => "1000 yen"
  40 + }.each do |original, converted|
  41 + define_method "test_currency_conversion: '#{original}'" do
  42 + assert_equal converted, original.convert_miscellaneous_characters
  43 + end
  44 + end
  45 +
  46 + {
  47 + "Tea &amp; Sympathy" => "Tea and Sympathy",
  48 + "10&cent;" => "10 cents",
  49 + "&copy;2000" => "(c)2000",
  50 + "98&deg; is fine" => "98 degrees is fine",
  51 + "10&divide;5" => "10 divided by 5",
  52 + "&quot;quoted&quot;" => '"quoted"',
  53 + "to be continued&hellip;" => "to be continued...",
  54 + "2000&ndash;2004" => "2000-2004",
  55 + "I wish&mdash;oh, never mind" => "I wish--oh, never mind",
  56 + "&frac12; ounce of gold" => "half ounce of gold",
  57 + "1 and &frac14; ounces of silver" => "1 and one fourth ounces of silver",
  58 + "9 and &frac34; ounces of platinum" => "9 and three fourths ounces of platinum",
  59 + "3&gt;2" => "3>2",
  60 + "2&lt;3" => "2<3",
  61 + "two&nbsp;words" => "two words",
  62 + "&pound;100" => "pounds 100",
  63 + "Walmart&reg;" => "Walmart(r)",
  64 + "&apos;single quoted&apos;" => "'single quoted'",
  65 + "2&times;4" => "2x4",
  66 + "Programming&trade;" => "Programming(tm)",
  67 + "&yen;20000" => "yen 20000",
  68 + " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
  69 + }.each do |original, converted|
  70 + define_method "test_html_entity_conversion: '#{original}'" do
  71 + assert_equal converted, original.convert_miscellaneous_html_entities
  72 + end
  73 + end
  74 +
  75 + {
  76 + "&frac12;" => "half",
  77 + "½" => "half",
  78 + "&#189;" => "half",
  79 + "⅓" => "one third",
  80 + "&#8531;" => "one third",
  81 + "⅔" => "two thirds",
  82 + "&#8532;" => "two thirds",
  83 + "&frac14;" => "one fourth",
  84 + "¼" => "one fourth",
  85 + "&#188;" => "one fourth",
  86 + "&frac34;" => "three fourths",
  87 + "¾" => "three fourths",
  88 + "&#190;" => "three fourths",
  89 + "⅕" => "one fifth",
  90 + "&#8533;" => "one fifth",
  91 + "⅖" => "two fifths",
  92 + "&#8534;" => "two fifths",
  93 + "⅗" => "three fifths",
  94 + "&#8535;" => "three fifths",
  95 + "⅘" => "four fifths",
  96 + "&#8536;" => "four fifths",
  97 + "⅙" => "one sixth",
  98 + "&#8537;" => "one sixth",
  99 + "⅚" => "five sixths",
  100 + "&#8538;" => "five sixths",
  101 + "⅛" => "one eighth",
  102 + "&#8539;" => "one eighth",
  103 + "⅜" => "three eighths",
  104 + "&#8540;" => "three eighths",
  105 + "⅝" => "five eighths",
  106 + "&#8541;" => "five eighths",
  107 + "⅞" => "seven eighths",
  108 + "&#8542;" => "seven eighths"
  109 + }.each do |original, converted|
  110 + define_method "test_vulgar_fractions_conversion: #{original}" do
  111 + assert_equal converted, original.convert_vulgar_fractions
46 112 end
47 113 end
48 114
2  test/string_extensions_test.rb
@@ -53,7 +53,7 @@ def test_to_url
53 53 "21'17ʼ51" =>
54 54 "21-17-51",
55 55 "ITCZ÷1 (21°17ʼ51.78”N / 89°35ʼ28.18”O / 26-04-08 / 09:00 am)" =>
56   - "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",
  56 + "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",
57 57 "/" =>
58 58 "slash",
59 59 "私はガラスを食べられます。それは私を傷つけません。" =>

0 comments on commit bb441c1

Please sign in to comment.
Something went wrong with that request. Please try again.