typohero 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'minitest/autorun'
2
3
  require 'typohero'
3
4
 
4
5
  class TypoHeroTest < Minitest::Test
5
- def typo(str, orig)
6
+ def assert_enhance(str, orig)
6
7
  # todo test recursive
7
8
  a = TypoHero.enhance(str)
8
9
  #b = TypoHero.enhance(a)
@@ -20,10 +21,10 @@ class TypoHeroTest < Minitest::Test
20
21
  end
21
22
 
22
23
  def test_verbatim
23
- typo "foo!", "foo!"
24
- typo "<div>This is html</div>", "<div>This is&nbsp;html</div>"
25
- typo "<div>This is html with <crap </div> tags>", "<div>This is html with <crap </div> tags>"
26
- typo %q{
24
+ assert_enhance "foo!", "foo!"
25
+ assert_enhance "<div>This is html</div>", "<div>This is&nbsp;html</div>"
26
+ assert_enhance "<div>This is html with <crap </div> tags>", "<div>This is html with <crap </div> tags>"
27
+ assert_enhance %q{
27
28
  multiline
28
29
 
29
30
  <b>html</b>
@@ -38,172 +39,182 @@ multiline
38
39
  }
39
40
  end
40
41
 
42
+ def test_excluded
43
+ assert_enhance "<script>'hello'</script>", "<script>'hello'</script>"
44
+ assert_enhance "<!-- <a>'hello'</a> -->", "<!-- <a>'hello'</a> -->"
45
+ assert_enhance "<![CDATA[<a>'hello'</a>]]>", "<![CDATA[<a>'hello'</a>]]>"
46
+ end
47
+
41
48
  def test_quotes
42
- typo '"A first example"', '<span class="dquo">&#8220;</span>A first&nbsp;example&#8221;'
43
- typo '"A first "nested" example"',
49
+ assert_enhance '"A first example"', '<span class="dquo">&#8220;</span>A first&nbsp;example&#8221;'
50
+ assert_enhance '"A first "nested" example"',
44
51
  '<span class="dquo">&#8220;</span>A first &#8220;nested&#8221;&nbsp;example&#8221;'
45
52
 
46
- typo '".', '&#8221;.'
47
- typo '"a', '<span class="dquo">&#8220;</span>a'
53
+ assert_enhance '".', '&#8221;.'
54
+ assert_enhance '"a', '<span class="dquo">&#8220;</span>a'
48
55
 
49
- typo "'.", '&#8217;.'
50
- typo "'a", '<span class="quo">&#8216;</span>a'
56
+ assert_enhance "'.", '&#8217;.'
57
+ assert_enhance "'a", '<span class="quo">&#8216;</span>a'
51
58
 
52
- typo %{<p>He said, "'Quoted' words in a larger quote."</p>},
59
+ assert_enhance %{<p>He said, "'Quoted' words in a larger quote."</p>},
53
60
  '<p>He said, &#8220;&#8216;Quoted&#8217; words in a larger&nbsp;quote.&#8221;</p>'
54
61
 
55
- typo %{"I like the 70's"}, '<span class="dquo">&#8220;</span>I like the&nbsp;70&#8217;s&#8221;'
56
- typo %{"I like the '70s"}, '<span class="dquo">&#8220;</span>I like the&nbsp;&#8217;70s&#8221;'
57
- typo %{"I like the '70!"}, '<span class="dquo">&#8220;</span>I like the&nbsp;&#8216;70!&#8221;'
62
+ assert_enhance %{"I like the 70's"}, '<span class="dquo">&#8220;</span>I like the&nbsp;70&#8217;s&#8221;'
63
+ assert_enhance %{"I like the '70s"}, '<span class="dquo">&#8220;</span>I like the&nbsp;&#8217;70s&#8221;'
64
+ assert_enhance %{"I like the '70!"}, '<span class="dquo">&#8220;</span>I like the&nbsp;&#8216;70!&#8221;'
58
65
 
59
- typo 'pre"post', 'pre&#8221;post'
60
- typo 'pre "post', 'pre&nbsp;&#8220;post'
61
- typo 'pre&nbsp;"post', 'pre&nbsp;&#8220;post'
62
- typo 'pre--"post', 'pre &#8211;&nbsp;&#8220;post'
63
- typo 'pre--"!', 'pre &#8211;&nbsp;&#8221;!'
66
+ assert_enhance 'pre"post', 'pre&#8221;post'
67
+ assert_enhance 'pre "post', 'pre&nbsp;&#8220;post'
68
+ assert_enhance 'pre&nbsp;"post', 'pre&nbsp;&#8220;post'
69
+ assert_enhance 'pre--"post', 'pre&nbsp;&#8211;&nbsp;&#8220;post'
70
+ assert_enhance 'pre--"!', 'pre&nbsp;&#8211;&nbsp;&#8221;!'
64
71
 
65
- typo "pre'post", 'pre&#8217;post'
66
- typo "pre 'post", 'pre&nbsp;&#8216;post'
67
- typo "pre&nbsp;'post", 'pre&nbsp;&#8216;post'
68
- typo "pre--'post", 'pre &#8211;&nbsp;&#8216;post'
69
- typo "pre--'!", 'pre &#8211;&nbsp;&#8217;!'
72
+ assert_enhance "pre'post", 'pre&#8217;post'
73
+ assert_enhance "pre 'post", 'pre&nbsp;&#8216;post'
74
+ assert_enhance "pre&nbsp;'post", 'pre&nbsp;&#8216;post'
75
+ assert_enhance "pre--'post", 'pre&nbsp;&#8211;&nbsp;&#8216;post'
76
+ assert_enhance "pre--'!", 'pre&nbsp;&#8211;&nbsp;&#8217;!'
70
77
 
71
- typo "<b>'</b>", '<b><span class="quo">&#8216;</span></b>'
72
- typo "foo<b>'</b>", "foo<b>&#8217;</b>"
78
+ assert_enhance "<b>'</b>", '<b><span class="quo">&#8216;</span></b>'
79
+ assert_enhance "foo<b>'</b>", "foo<b>&#8217;</b>"
73
80
 
74
- typo '<b>"</b>', '<b><span class="dquo">&#8220;</span></b>'
75
- typo 'foo<b>"</b>', "foo<b>&#8221;</b>"
81
+ assert_enhance '<b>"</b>', '<b><span class="dquo">&#8220;</span></b>'
82
+ assert_enhance 'foo<b>"</b>', "foo<b>&#8221;</b>"
76
83
  end
77
84
 
78
85
  def test_dashes
79
- typo "foo--bar", 'foo &#8211;&nbsp;bar'
80
- typo "foo---bar", "foo\u2009\u2014&nbsp;bar"
86
+ assert_enhance "foo--bar", 'foo&nbsp;&#8211;&nbsp;bar'
87
+ assert_enhance "foo - bar", 'foo&nbsp;&#8211;&nbsp;bar'
88
+ assert_enhance "foo---bar", "foo\u202F\u2014\u202Fbar"
81
89
  end
82
90
 
83
91
  def test_ellipses
84
- typo "foo..bar", 'foo..bar'
85
- typo "foo...bar", 'foo&#8230;bar'
86
- typo "foo....bar", 'foo&#8230;.bar'
92
+ assert_enhance "foo..bar", 'foo..bar'
93
+ assert_enhance "foo...bar", 'foo&#8230;bar'
94
+ assert_enhance "foo....bar", 'foo&#8230;.bar'
87
95
 
88
- typo "foo. . ..bar", 'foo&#8230;.bar'
89
- typo "foo. . ...bar", 'foo&#8230;..bar'
90
- typo "foo. . ....bar", 'foo&#8230;&#8230;bar'
96
+ assert_enhance "foo. . ..bar", 'foo&#8230;.bar'
97
+ assert_enhance "foo. . ...bar", 'foo&#8230;..bar'
98
+ assert_enhance "foo. . ....bar", 'foo&#8230;&#8230;bar'
91
99
  end
92
100
 
93
101
  def test_backticks
94
- typo "pre``post", 'pre&#8220;post'
95
- typo "pre ``post", 'pre&nbsp;&#8220;post'
96
- typo "pre&nbsp;``post", 'pre&nbsp;&#8220;post'
97
- typo "pre--``post", 'pre &#8211;&nbsp;&#8220;post'
98
- typo "pre--``!", 'pre &#8211;&nbsp;&#8220;!'
99
-
100
- typo "pre''post", 'pre&#8221;post'
101
- typo "pre ''post", 'pre&nbsp;&#8221;post'
102
- typo "pre&nbsp;''post", 'pre&nbsp;&#8221;post'
103
- typo "pre--''post", 'pre &#8211;&nbsp;&#8221;post'
104
- typo "pre--''!", 'pre &#8211;&nbsp;&#8221;!'
102
+ assert_enhance "pre``post", 'pre&#8220;post'
103
+ assert_enhance "pre ``post", 'pre&nbsp;&#8220;post'
104
+ assert_enhance "pre&nbsp;``post", 'pre&nbsp;&#8220;post'
105
+ assert_enhance "pre--``post", 'pre&nbsp;&#8211;&nbsp;&#8220;post'
106
+ assert_enhance "pre--``!", 'pre&nbsp;&#8211;&nbsp;&#8220;!'
107
+
108
+ assert_enhance "pre''post", 'pre&#8221;post'
109
+ assert_enhance "pre ''post", 'pre&nbsp;&#8221;post'
110
+ assert_enhance "pre&nbsp;''post", 'pre&nbsp;&#8221;post'
111
+ assert_enhance "pre--''post", 'pre&nbsp;&#8211;&nbsp;&#8221;post'
112
+ assert_enhance "pre--''!", 'pre&nbsp;&#8211;&nbsp;&#8221;!'
105
113
  end
106
114
 
107
115
  def test_single_backticks
108
- typo "`foo'", '<span class="quo">&#8216;</span>foo&#8217;'
109
-
110
- typo "pre`post", 'pre&#8216;post'
111
- typo "pre `post", 'pre&nbsp;&#8216;post'
112
- typo "pre&nbsp;`post", 'pre&nbsp;&#8216;post'
113
- typo "pre--`post", 'pre &#8211;&nbsp;&#8216;post'
114
- typo "pre--`!", 'pre &#8211;&nbsp;&#8216;!'
115
-
116
- typo "pre'post", 'pre&#8217;post'
117
- typo "pre 'post", 'pre&nbsp;&#8216;post'
118
- typo "pre&nbsp;'post", 'pre&nbsp;&#8216;post'
119
- typo "pre--'post", 'pre &#8211;&nbsp;&#8216;post'
120
- typo "pre--'!", 'pre &#8211;&nbsp;&#8217;!'
116
+ assert_enhance "`foo'", '<span class="quo">&#8216;</span>foo&#8217;'
117
+
118
+ assert_enhance "pre`post", 'pre&#8216;post'
119
+ assert_enhance "pre `post", 'pre&nbsp;&#8216;post'
120
+ assert_enhance "pre&nbsp;`post", 'pre&nbsp;&#8216;post'
121
+ assert_enhance "pre--`post", 'pre&nbsp;&#8211;&nbsp;&#8216;post'
122
+ assert_enhance "pre--`!", 'pre&nbsp;&#8211;&nbsp;&#8216;!'
123
+
124
+ assert_enhance "pre'post", 'pre&#8217;post'
125
+ assert_enhance "pre 'post", 'pre&nbsp;&#8216;post'
126
+ assert_enhance "pre&nbsp;'post", 'pre&nbsp;&#8216;post'
127
+ assert_enhance "pre--'post", 'pre&nbsp;&#8211;&nbsp;&#8216;post'
128
+ assert_enhance "pre--'!", 'pre&nbsp;&#8211;&nbsp;&#8217;!'
121
129
  end
122
130
 
123
131
  def test_process_escapes
124
- typo %q{foo\bar}, "foo\\bar"
125
- typo %q{foo\\\bar}, "foo&#92;bar"
126
- typo %q{foo\\\\\bar}, "foo&#92;\\bar"
127
- typo %q{foo\...bar}, "foo&#46;..bar"
128
- typo %q{foo\.\.\.bar}, "foo&#46;&#46;&#46;bar"
129
-
130
- typo %q{foo\'bar}, "foo&#39;bar"
131
- typo %q{foo\"bar}, "foo&#34;bar"
132
- typo %q{foo\-bar}, "foo&#45;bar"
133
- typo %q{foo\`bar}, "foo&#96;bar"
134
-
135
- typo %q{foo\#bar}, "foo\\#bar"
136
- typo %q{foo\*bar}, "foo\\*bar"
137
- typo %q{foo\&bar}, "foo\\&bar"
132
+ assert_enhance %q{foo\bar}, "foo\\bar"
133
+ assert_enhance %q{foo\\\bar}, "foo\\bar"
134
+ assert_enhance %q{foo\\\\\bar}, "foo\\\\bar"
135
+ assert_enhance %q{foo\...bar}, "foo...bar"
136
+ assert_enhance %q{foo\.\.\.bar}, "foo...bar"
137
+
138
+ assert_enhance %q{foo\'bar}, "foo'bar"
139
+ assert_enhance %q{foo\"bar}, "foo\"bar"
140
+ assert_enhance %q{foo\-bar}, "foo-bar"
141
+ assert_enhance %q{foo\`bar}, "foo`bar"
142
+ assert_enhance %q{foo\,,}, "foo,,"
143
+
144
+ assert_enhance %q{foo\#bar}, "foo\\#bar"
145
+ assert_enhance %q{foo\*bar}, "foo\\*bar"
146
+ assert_enhance %q{foo\&bar}, "foo\\&bar"
147
+ assert_enhance %q{foo\\\theta}, "foo\\theta"
138
148
  end
139
149
 
140
150
  def test_should_replace_amps
141
- typo 'One & two', 'One <span class="amp">&amp;</span>&nbsp;two'
142
- typo 'One &amp; two', 'One <span class="amp">&amp;</span>&nbsp;two'
143
- typo 'One &#38; two', 'One <span class="amp">&amp;</span>&nbsp;two'
144
- typo 'One&nbsp;&amp;&nbsp;two', 'One&nbsp;<span class="amp">&amp;</span>&nbsp;two'
151
+ assert_enhance 'One & two', 'One <span class="amp">&amp;</span>&nbsp;two'
152
+ assert_enhance 'One &amp; two', 'One <span class="amp">&amp;</span>&nbsp;two'
153
+ assert_enhance 'One &#38; two', 'One <span class="amp">&amp;</span>&nbsp;two'
154
+ assert_enhance 'One&nbsp;&amp;&nbsp;two', 'One&nbsp;<span class="amp">&amp;</span>&nbsp;two'
145
155
  end
146
156
 
147
157
  def test_should_ignore_special_amps
148
- typo 'One <span class="amp">&amp;</span> two', 'One <span class="amp">&amp;</span>&nbsp;two'
149
- typo '&ldquo;this&rdquo; & <a href="/?that&amp;test">that</a>', '<span class="dquo">&#8220;</span>this&#8221; <span class="amp">&amp;</span>&nbsp;<a href="/?that&amp;test">that</a>'
158
+ assert_enhance 'One <span class="amp">&amp;</span> two', 'One <span class="amp">&amp;</span>&nbsp;two'
159
+ assert_enhance '&ldquo;this&rdquo; & <a href="/?that&amp;test">that</a>', '<span class="dquo">&#8220;</span>this&#8221; <span class="amp">&amp;</span>&nbsp;<a href="/?that&amp;test">that</a>'
150
160
  end
151
161
 
152
162
  def test_should_replace_caps
153
- typo "A message from KU", 'A message from&nbsp;<span class="caps">KU</span>'
154
- typo 'Replace text <a href=".">IN</a> tags', 'Replace text <a href="."><span class="caps">IN</span></a>&nbsp;tags'
155
- typo 'Replace text <i>IN</i> tags', 'Replace text <i><span class="caps">IN</span></i>&nbsp;tags'
163
+ assert_enhance "A message from KU", 'A message from&nbsp;<span class="caps">KU</span>'
164
+ assert_enhance 'Replace text <a href=".">IN</a> tags', 'Replace text <a href="."><span class="caps">IN</span></a>&nbsp;tags'
165
+ assert_enhance 'Replace text <i>IN</i> tags', 'Replace text <i><span class="caps">IN</span></i>&nbsp;tags'
166
+ assert_enhance 'AB, CD, EF', '<span class="caps">AB</span>, <span class="caps">CD</span>,&nbsp;<span class="caps">EF</span>'
156
167
  end
157
168
 
158
169
  def test_should_ignore_special_case_caps
159
- typo 'It should ignore just numbers like 1234.', 'It should ignore just numbers like&nbsp;1234.'
160
- typo "<pre>CAPS</pre> more CAPS", '<pre>CAPS</pre> more&nbsp;<span class="caps">CAPS</span>'
161
- typo "<Pre>CAPS</PRE> with odd tag names CAPS", '<Pre>CAPS</PRE> with odd tag names&nbsp;<span class="caps">CAPS</span>'
162
- typo "A message from 2KU2 with digits", 'A message from <span class="caps">2KU2</span> with&nbsp;digits'
163
- typo "Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.", 'Dotted caps followed by spaces should never include them in the wrap <span class="caps">D.O.T.</span> like&nbsp;so.'
164
- typo 'Caps in attributes (<span title="Example CAPS">example</span>) should be ignored', 'Caps in attributes (<span title="Example CAPS">example</span>) should be&nbsp;ignored'
165
- typo '<head><title>CAPS Example</title></head>', '<head><title>CAPS Example</title></head>'
170
+ assert_enhance 'It should ignore just numbers like 1234.', 'It should ignore just numbers like&nbsp;1234.'
171
+ assert_enhance "<pre>CAPS</pre> more CAPS", '<pre>CAPS</pre> more&nbsp;<span class="caps">CAPS</span>'
172
+ assert_enhance "<Pre>CAPS</PRE> with odd tag names CAPS", '<Pre>CAPS</PRE> with odd tag names&nbsp;<span class="caps">CAPS</span>'
173
+ assert_enhance "A message from 2KU2 with digits", 'A message from <span class="caps">2KU2</span> with&nbsp;digits'
174
+ assert_enhance "Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.", 'Dotted caps followed by spaces should never include them in the wrap <span class="caps">D.O.T.</span> like&nbsp;so.'
175
+ assert_enhance 'Caps in attributes (<span title="Example CAPS">example</span>) should be ignored', 'Caps in attributes (<span title="Example CAPS">example</span>) should be&nbsp;ignored'
176
+ assert_enhance '<head><title>CAPS Example</title></head>', '<head><title>CAPS Example</title></head>'
166
177
  end
167
178
 
168
179
  def test_should_not_break_caps_with_apostrophes
169
- typo "JIMMY'S", '<span class="caps">JIMMY&#8217;S</span>'
170
- typo "<i>D.O.T.</i>HE34T<b>RFID</b>", '<i><span class="caps">D.O.T.</span></i><span class="caps">HE34T</span><b><span class="caps">RFID</span></b>'
180
+ assert_enhance "JIMMY'S", '<span class="caps">JIMMY&#8217;S</span>'
181
+ assert_enhance "<i>D.O.T.</i>HE34T<b>RFID</b>", '<i><span class="caps">D.O.T.</span></i><span class="caps">HE34T</span><b><span class="caps">RFID</span></b>'
171
182
  end
172
183
 
173
184
  def test_should_not_break_caps_with_ampersands
174
- typo "AT&T", '<span class="caps">AT&T</span>'
175
- typo "AT&amp;T", '<span class="caps">AT&amp;T</span>'
176
- typo "AT&#38;T", '<span class="caps">AT&amp;T</span>'
185
+ assert_enhance "AT&T", '<span class="caps">AT&T</span>'
186
+ assert_enhance "AT&amp;T", '<span class="caps">AT&amp;T</span>'
187
+ assert_enhance "AT&#38;T", '<span class="caps">AT&amp;T</span>'
177
188
  end
178
189
 
179
190
  def test_should_prevent_widows
180
- typo 'A very simple test', 'A very simple&nbsp;test'
191
+ assert_enhance 'A very simple test', 'A very simple&nbsp;test'
181
192
  end
182
193
 
183
194
  def test_should_not_change_single_word_items
184
- typo 'Test', 'Test'
185
- typo ' Test', ' Test'
186
- typo '<ul><li>Test</p></li><ul>', '<ul><li>Test</p></li><ul>'
187
- typo '<ul><li> Test</p></li><ul>', '<ul><li> Test</p></li><ul>'
188
- typo '<p>In a couple of paragraphs</p><p>paragraph two</p>', '<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>'
189
- typo '<h1><a href="#">In a link inside a heading</i> </a></h1>', '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>'
190
- typo '<h1><a href="#">In a link</a> followed by other text</h1>', '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>'
195
+ assert_enhance 'Test', 'Test'
196
+ assert_enhance ' Test', ' Test'
197
+ assert_enhance '<ul><li>Test</p></li><ul>', '<ul><li>Test</p></li><ul>'
198
+ assert_enhance '<ul><li> Test</p></li><ul>', '<ul><li> Test</p></li><ul>'
199
+ assert_enhance '<p>In a couple of paragraphs</p><p>paragraph two</p>', '<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>'
200
+ assert_enhance '<h1><a href="#">In a link inside a heading</i> </a></h1>', '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>'
201
+ assert_enhance '<h1><a href="#">In a link</a> followed by other text</h1>', '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>'
191
202
  end
192
203
 
193
204
  def test_should_not_add_nbsp_before_another
194
- typo 'Sentence with one&nbsp;nbsp', 'Sentence with one&nbsp;nbsp'
205
+ assert_enhance 'Sentence with one&nbsp;nbsp', 'Sentence with one&nbsp;nbsp'
195
206
  end
196
207
 
197
208
  def test_should_not_error_on_empty_html
198
- typo '<h1><a href="#"></a></h1>', '<h1><a href="#"></a></h1>'
209
+ assert_enhance '<h1><a href="#"></a></h1>', '<h1><a href="#"></a></h1>'
199
210
  end
200
211
 
201
212
  def test_should_ignore_widows_in_special_tags
202
- typo '<div>Divs get love!</div>', '<div>Divs get&nbsp;love!</div>'
203
- typo '<pre>Neither do PREs</pre>', '<pre>Neither do PREs</pre>'
204
- typo '<textarea>nor text in textarea</textarea>', '<textarea>nor text in textarea</textarea>'
205
- typo "<script>\nreturn window;\n</script>", "<script>\nreturn window;\n</script>"
206
- typo '<div><p>But divs with paragraphs do!</p></div>', '<div><p>But divs with paragraphs&nbsp;do!</p></div>'
213
+ assert_enhance '<div>Divs get love!</div>', '<div>Divs get&nbsp;love!</div>'
214
+ assert_enhance '<pre>Neither do PREs</pre>', '<pre>Neither do PREs</pre>'
215
+ assert_enhance '<textarea>nor text in textarea</textarea>', '<textarea>nor text in textarea</textarea>'
216
+ assert_enhance "<script>\nreturn window;\n</script>", "<script>\nreturn window;\n</script>"
217
+ assert_enhance '<div><p>But divs with paragraphs do!</p></div>', '<div><p>But divs with paragraphs&nbsp;do!</p></div>'
207
218
  end
208
219
 
209
220
  def test_widont
@@ -213,43 +224,75 @@ multiline
213
224
  <a href="/contact/">Contact</a>
214
225
  </li>
215
226
  </ul>}
216
- typo code, code
227
+ assert_enhance code, code
217
228
  end
218
229
 
219
230
  def test_should_replace_quotes
220
- typo '"With primes"', '<span class="dquo">&#8220;</span>With&nbsp;primes&#8221;'
221
- typo "'With single primes'", '<span class="quo">&#8216;</span>With single&nbsp;primes&#8217;'
222
- typo '<a href="#">"With primes and a link"</a>', '<a href="#"><span class="dquo">&#8220;</span>With primes and a&nbsp;link&#8221;</a>'
223
- typo '&#8220;With smartypanted quotes&#8221;', '<span class="dquo">&#8220;</span>With smartypanted&nbsp;quotes&#8221;'
224
- typo '&lsquo;With manual quotes&rsquo;', '<span class="quo">&#8216;</span>With manual&nbsp;quotes&#8217;'
231
+ assert_enhance '"With primes"', '<span class="dquo">&#8220;</span>With&nbsp;primes&#8221;'
232
+ assert_enhance "'With single primes'", '<span class="quo">&#8216;</span>With single&nbsp;primes&#8217;'
233
+ assert_enhance '<a href="#">"With primes and a link"</a>', '<a href="#"><span class="dquo">&#8220;</span>With primes and a&nbsp;link&#8221;</a>'
234
+ assert_enhance '&#8220;With smartypanted quotes&#8221;', '<span class="dquo">&#8220;</span>With smartypanted&nbsp;quotes&#8221;'
235
+ assert_enhance '&lsquo;With manual quotes&rsquo;', '<span class="quo">&#8216;</span>With manual&nbsp;quotes&#8217;'
225
236
  end
226
237
 
227
238
  def test_should_apply_all_filters
228
- typo '<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>', '<h2><span class="dquo">&#8220;</span>Jayhawks&#8221; <span class="amp">&amp;</span> <span class="caps">KU</span> fans act extremely&nbsp;obnoxiously</h2>'
239
+ assert_enhance '<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>', '<h2><span class="dquo">&#8220;</span>Jayhawks&#8221; <span class="amp">&amp;</span> <span class="caps">KU</span> fans act extremely&nbsp;obnoxiously</h2>'
229
240
  end
230
241
 
231
242
  def test_other_special
232
- typo ',,hello\'\'', "<span class=\"bdquo\">\u201E</span>hello&#8221;"
233
- typo '(tm)', "\u2122"
243
+ assert_enhance ',,hello\'\'', "<span class=\"bdquo\">\u201E</span>hello&#8221;"
244
+ assert_enhance '(tm)', "\u2122"
234
245
  end
235
246
 
236
247
  def test_primes
237
- typo "She's 6'2''", "She&#8217;s&nbsp;6\u20322\u2033"
248
+ assert_enhance "She's 6'2''", "She&#8217;s&nbsp;6\u20322\u2033"
249
+ assert_enhance %{He said "Oslo coordinates are: 59°57'N 10°45'E" and there it is.}, "He said &#8220;Oslo coordinates are: 59°57\u2032N 10°45\u2032E&#8221; and there it&nbsp;is."
238
250
  end
239
251
 
240
252
  def test_ordinals
241
- typo 'I am the 1st', 'I am the&nbsp;1<sup>st</sup>'
253
+ assert_enhance 'I am the 1st', 'I am the&nbsp;1<span class="ord">st</span>'
242
254
  end
243
255
 
244
256
  def test_latex
245
- typo '\\textbackslash', '\\'
257
+ assert_enhance '\\textbackslash', '\\'
258
+ end
259
+
260
+ def test_nobr
261
+ assert_enhance 'T-shirt', '<span class="nobr">T-shirt</span>'
262
+ assert_enhance '2014-01-01', '<span class="nobr">2014-01-01</span>'
246
263
  end
247
264
 
248
265
  def test_ignore_mathjax
249
- typo '$$\\approx$$ outside \\approx', "$$\\approx$$ outside&nbsp;\u2248"
250
- typo '\\(\\approx\\) outside \\approx', "\\(\\approx\\) outside&nbsp;\u2248"
251
- typo '\\[\\approx\\] outside \\approx', "\\[\\approx\\] outside&nbsp;\u2248"
252
- typo '<span>$</span>', '<span>$</span>'
253
- typo '<span>\\</span>', '<span>\\</span>'
266
+ assert_enhance '$$\\approx$$ outside \\approx', "$$\\approx$$ outside&nbsp;\u2248"
267
+ assert_enhance '\) $$\\approx$$ outside \\approx', "\\) $$\\approx$$ outside&nbsp;\u2248"
268
+ assert_enhance '\] $$\\approx$$ outside \\approx', "\\] $$\\approx$$ outside&nbsp;\u2248"
269
+ assert_enhance '\\(\\approx\\) outside \\approx', "\\(\\approx\\) outside&nbsp;\u2248"
270
+ assert_enhance '\\[\\approx\\] outside \\approx', "\\[\\approx\\] outside&nbsp;\u2248"
271
+ assert_enhance '<span>$</span>', '<span>$</span>'
272
+ assert_enhance '<span>\\</span>', '<span>\\</span>'
273
+ end
274
+
275
+ def test_truncate
276
+ assert_equal "<a>a <span>b\u2026</span></a>", TypoHero.truncate('<a>a <span>b c d</span> c</a>', 2)
277
+ assert_equal "<a>a <span>b\u2026</span></a>", TypoHero.truncate('<a>a <span>b!?! c d</span> c</a>', 2)
278
+ assert_equal "<a>a <!--comment--><span>b\u2026</span></a>", TypoHero.truncate('<a>a <!--comment--><span>b </span> c</a>', 2)
279
+ assert_equal "<a>a <!--comment--><span>b\u2026</span></a>", TypoHero.truncate('<a>a <!--comment--><span>b!!! </span> c</a>', 2)
280
+ assert_equal "<!--comment-->a <span>b\u2026</span>", TypoHero.truncate('<!--comment-->a <span>b </span>c', 2)
281
+ assert_equal "<a>a <span><script>b</script> c\u2026</span></a>", TypoHero.truncate('<a>a <span><script>b</script> c d</span> c</a>', 2)
282
+ assert_equal "<p>Lorem ipsum dolor sit amet.</p>", TypoHero.truncate("<p>Lorem ipsum dolor sit amet.</p>", 5)
283
+ assert_equal "<p>Lorem ipsum\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor sit amet.</p>", 5, 'dolor')
284
+ assert_equal "<p>Lorem ipsum dolor\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<!--more--> sit amet.</p>", 5, 'more')
285
+ assert_equal "<p>Lorem ipsum dolor\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<!--more--> sit amet.</p>", 5, '<!--more-->')
286
+ assert_equal "<p>Lorem ipsum dolor\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<!--more--> sit amet.</p>", 5, /more/)
287
+ assert_equal "<p><span>Lorem ipsum dolor\u2026</span></p>", TypoHero.truncate("<p><span>Lorem ipsum dolor</span> sit amet.</p>", 5, '</span>')
288
+ assert_equal "<p>Lorem ipsum dolor\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<span class=\"more\"> sit amet.</span></p>", 5, 'more')
289
+ assert_equal "<p>Lorem ipsum dolor\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<span class=\"more\"> sit amet.</span></p>", 'more', 10)
290
+ assert_equal "<p>Lorem ipsum\u2026</p>", TypoHero.truncate("<p>Lorem ipsum dolor<span class=\"more\"> sit amet.</span></p>", 'more', 2)
291
+ end
292
+
293
+ def test_strip_tags
294
+ assert_equal 'a b c d e', TypoHero.strip_tags('<a>a <span>b c d</span> e</a>')
295
+ assert_equal 'a c d e', TypoHero.strip_tags('<a>a <span><script>b</script> c d</span> e</a>')
296
+ assert_equal 'a \(latex\) text', TypoHero.strip_tags('a <script>\(a b c\)</script><a> <test> \(latex\) text')
254
297
  end
255
298
  end
data/typohero.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.homepage = 'https://github.com/minad/typohero/'
14
14
  s.license = 'MIT'
15
15
 
16
- s.files = `git ls-files`.split("\n")
16
+ s.files = `git ls-files | grep -v bench/*.txt`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = %w(lib)
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typohero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: TypoHero improves web typography by applying various filters (similar
14
14
  to rubypants, typogruby, typogrify).
@@ -24,7 +24,6 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - bench/bench.rb
27
- - bench/bench.txt
28
27
  - bench/profile.rb
29
28
  - hero.jpg
30
29
  - latex.pl