qunit.test.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Typography.js : QUnit Tests</title>
  6. <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" media="screen" />
  7. <script src="http://code.jquery.com/jquery-git1.js"></script>
  8. <script src="http://code.jquery.com/qunit/qunit-git.js"></script>
  9. <script src="../typogr.min.js"></script>
  10. <script>
  11. $(document).ready(function(){
  12. var tp = typogr;
  13. test('amp', function(){
  14. equal(tp.amp('One & two' ), 'One <span class="amp">&amp;</span> two');
  15. equal(tp.amp('One &amp; two'), 'One <span class="amp">&amp;</span> two');
  16. equal(tp.amp('One &#38; two'), 'One <span class="amp">&amp;</span> two');
  17. equal(tp.amp('One&nbsp;&amp;&nbsp;two'),
  18. 'One&nbsp;<span class="amp">&amp;</span>&nbsp;two');
  19. // It won't mess up & that are already wrapped, in entities or URLs
  20. equal(tp.amp('One <span class="amp">&amp;</span> two'),
  21. 'One <span class="amp">&amp;</span> two');
  22. equal(tp.amp('&ldquo;this&rdquo; & <a href="/?that&amp;test">that</a>'),
  23. '&ldquo;this&rdquo; <span class="amp">&amp;</span> <a href="/?that&amp;test">that</a>');
  24. // It should ignore standalone amps that are in attributes
  25. equal(tp.amp('<link href="xyz.html" title="One & Two">xyz</link>'),
  26. '<link href="xyz.html" title="One & Two">xyz</link>');
  27. });
  28. test('ord', function(){
  29. equal(tp.ord('1st'), '1<span class="ord">st</span>');
  30. equal(tp.ord('2nd'), '2<span class="ord">nd</span>');
  31. equal(tp.ord('3rd'), '3<span class="ord">rd</span>');
  32. equal(tp.ord('10th'), '10<span class="ord">th</span>');
  33. equal(tp.ord('37th'), '37<span class="ord">th</span>');
  34. equal(tp.ord('1000th'), '1000<span class="ord">th</span>');
  35. // Make sure it does not happen within attributes
  36. equal(tp.ord('<span data-test="1st">1st</span>'), '<span data-test="1st">1<span class="ord">st</span></span>');
  37. });
  38. test('quotes', function(){
  39. equal(tp.initQuotes('"With primes"'), '<span class="dquo">"</span>With primes"');
  40. equal(tp.initQuotes("'With single primes'"), '<span class="quo">\'</span>With single primes\'');
  41. equal(tp.initQuotes('<a href="#">"With primes and a link"</a>'),
  42. '<a href="#"><span class="dquo">"</span>With primes and a link"</a>');
  43. equal(tp.initQuotes('&#8220;With smartypanted quotes&#8221;'),
  44. '<span class="dquo">&#8220;</span>With smartypanted quotes&#8221;');
  45. equal(tp.initQuotes('<h1> <strong>&lsquo;With</strong> single primes ...</h1>'),
  46. '<h1> <strong><span class="quo">&lsquo;</span>With</strong> single primes ...</h1>');
  47. equal(tp.initQuotes('<h2> &#8220;Jayhawks&#8221; & KU fans ... </h2>'),
  48. '<h2> <span class="dquo">&#8220;</span>Jayhawks&#8221; & KU fans ... </h2>');
  49. });
  50. test('widont', function(){
  51. equal(tp.widont('A very simple test'), 'A very simple<span class="widont">&nbsp;</span>test');
  52. // Single word items shouldn't be changed
  53. equal(tp.widont('Test'), 'Test');
  54. equal(tp.widont(' Test'), ' Test');
  55. equal(tp.widont('<ul><li>Test</p></li><ul>'), '<ul><li>Test</p></li><ul>');
  56. equal(tp.widont('<ul><li> Test</p></li><ul>'), '<ul><li> Test</p></li><ul>');
  57. equal(tp.widont('<p>In a couple of paragraphs</p><p>paragraph two</p>'),
  58. '<p>In a couple of<span class="widont">&nbsp;</span>paragraphs</p><p>paragraph<span class="widont">&nbsp;</span>two</p>');
  59. equal(tp.widont('<h1><a href="#">In a link inside a heading</i> </a></h1>'),
  60. '<h1><a href="#">In a link inside a<span class="widont">&nbsp;</span>heading</i> </a></h1>');
  61. equal(tp.widont('<h1><a href="#">In a link</a> followed by other text</h1>'),
  62. '<h1><a href="#">In a link</a> followed by other<span class="widont">&nbsp;</span>text</h1>');
  63. // Empty HTMLs shouldn't error
  64. equal(tp.widont('<h1><a href="#"></a></h1>'), '<h1><a href="#"></a></h1>');
  65. equal(tp.widont('<div>Divs get no love!</div>'), '<div>Divs get no love!</div>');
  66. equal(tp.widont('<pre>Neither do PREs</pre>'), '<pre>Neither do PREs</pre>');
  67. equal(tp.widont('<div><p>But divs with paragraphs do!</p></div>'),
  68. '<div><p>But divs with paragraphs<span class="widont">&nbsp;</span>do!</p></div>');
  69. // It should ignore inline tags
  70. equal(tp.widont('<p>Testing with a tag at <strong>the end</strong>.</p>'),
  71. '<p>Testing with a tag at <strong>the<span class="widont">&nbsp;</span>end</strong>.</p>');
  72. equal(tp.widont('<p>Testing with <strong>multiple inline</strong> tags at <a href="#"><strong><em>the end</em></strong></a>.</p>'),
  73. '<p>Testing with <strong>multiple inline</strong> tags at <a href="#"><strong><em>the<span class="widont">&nbsp;</span>end</em></strong></a>.</p>');
  74. // It should also take commas into consideration
  75. equal(tp.widont('<p>Start of the paragraph ... before they get deleted-I mean, published.</p>'),
  76. '<p>Start of the paragraph ... before they get deleted-I mean,<span class="widont">&nbsp;</span>published.</p>');
  77. });
  78. test('caps', function(){
  79. equal(tp.caps('A message from KU'),
  80. 'A message from <span class="caps">KU</span>');
  81. // Uses the smartypants tokenizer to not screw with HTML or with tags it shouldn't.
  82. equal(tp.caps('<PRE>CAPS</pre> more CAPS'),
  83. '<PRE>CAPS</pre> more <span class="caps">CAPS</span>');
  84. equal(tp.caps('A message from 2KU2 with digits'),
  85. 'A message from <span class="caps">2KU2</span> with digits');
  86. equal(tp.caps('Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.'),
  87. 'Dotted caps followed by spaces should never include them in the wrap <span class="caps">D.O.T.</span> like so.');
  88. // All caps with with apostrophes in them shouldn't break. Only handles dump apostrophes though.
  89. equal(tp.caps("JIMMY'S"),
  90. '<span class="caps">JIMMY\'S</span>');
  91. equal(tp.caps("<i>D.O.T.</i>HE34T<b>RFID</b>"),
  92. '<i><span class="caps">D.O.T.</span></i><span class="caps">HE34T</span><b><span class="caps">RFID</span></b>');
  93. });
  94. test('tokenize', function(){
  95. deepEqual( tp.tokenize('<h1>test header</h1>'+
  96. '<p>some <b>other</b> text</p> '+
  97. 'and appendix ...'),
  98. [ { type: 'tag', txt: '<h1>' },
  99. { type: 'text', txt: 'test header' },
  100. { type: 'tag', txt: '</h1>' },
  101. { type: 'tag', txt: '<p>' },
  102. { type: 'text', txt: 'some ' },
  103. { type: 'tag', txt: '<b>' },
  104. { type: 'text', txt: 'other' },
  105. { type: 'tag', txt: '</b>' },
  106. { type: 'text', txt: ' text' },
  107. { type: 'tag', txt: '</p>' },
  108. { type: 'text', txt: ' and appendix ...' } ]
  109. );
  110. });
  111. test('smartEscapes', function(){
  112. equal( tp.smartEscapes( '\\" : \\\' : \\- : \\. : \\\\ : \\`'),
  113. '&#34; : &#39; : &#45; : &#46; : &#92; : &#96;');
  114. });
  115. test('smartDashes', function(){
  116. equal( tp.smartDashes( '-- : --- : -- : ---'),
  117. '&#8211; : &#8212; : &#8211; : &#8212;');
  118. equal( tp.smartDashes( '<!--:-->:<!-- valid html comment -->'),
  119. '<!--:-->:<!-- valid html comment -->:');
  120. });
  121. test('smartEscapes', function(){
  122. equal( tp.smartEllipses( '. ... : . . . .'),
  123. '. &#8230; : &#8230; .');
  124. });
  125. test('smartBackticks', function(){
  126. equal( tp.smartBackticks( "``Isn't this fun?''"),
  127. "&#8220;Isn't this fun?&#8221;");
  128. });
  129. test('smartQuotes', function(){
  130. equal( tp.smartQuotes( '"Isn\'t this fun?"'),
  131. '&#8220;Isn&#8217;t this fun?&#8221;');
  132. });
  133. test('smartypants', function(){
  134. equal( tp.smartypants( 'The "Green" man'),
  135. 'The &#8220;Green&#8221; man');
  136. equal( tp.smartypants( '"<a href="http://example.com">switched off</a>".'),
  137. '&#8220;<a href="http://example.com">switched off</a>&#8221;.');
  138. equal( tp.smartypants('<a href="">markdown</a>\'s popularity is growing'),
  139. '<a href="">markdown</a>&#8217;s popularity is growing');
  140. });
  141. test('typogrify', function(){
  142. equal( tp.typogrify(
  143. '<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>'),
  144. '<h2><span class="dquo">&#8220;</span>Jayhawks&#8221; <span class="amp">&amp;</span> <span class=\"caps\">KU</span> fans act extremely<span class="widont">&nbsp;</span>obnoxiously</h2>');
  145. equal( tp('<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>').typogrify(),
  146. '<h2><span class="dquo">&#8220;</span>Jayhawks&#8221; <span class="amp">&amp;</span> <span class=\"caps\">KU</span> fans act extremely<span class="widont">&nbsp;</span>obnoxiously</h2>');
  147. equal( tp('<h2>"Jayhawks" & KU fans act extremely obnoxiously</h2>').chain().typogrify().value(),
  148. '<h2><span class="dquo">&#8220;</span>Jayhawks&#8221; <span class="amp">&amp;</span> <span class=\"caps\">KU</span> fans act extremely<span class="widont">&nbsp;</span>obnoxiously</h2>');
  149. });
  150. });
  151. </script>
  152. </head>
  153. <body>
  154. <h1 id="qunit-header">QUnit Test Suite</h1>
  155. <h2 id="qunit-banner"></h2>
  156. <div id="qunit-testrunner-toolbar"></div>
  157. <h2 id="qunit-userAgent"></h2>
  158. <ol id="qunit-tests"></ol>
  159. <div id="qunit-fixture">test markup</div>
  160. </body>
  161. </html>