aaa_string_test.rb 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. # encoding: utf-8
  2. require 'test_helper'
  3. # rubocop:disable TrailingWhitespace
  4. class AaaStringTest < ActiveSupport::TestCase
  5. test 'to_filename ref' do
  6. modul = 'test'
  7. result = 'test'
  8. modul.to_filename
  9. assert_equal(result, modul)
  10. modul = 'Some::File'
  11. result = 'Some::File'
  12. modul.to_filename
  13. assert_equal(result, modul)
  14. end
  15. test 'to_filename function' do
  16. modul = 'test'
  17. result = 'test'
  18. assert_equal(result, modul.to_filename)
  19. modul = 'Some::File'
  20. result = 'some/file'
  21. assert_equal(result, modul.to_filename)
  22. end
  23. test 'to_classname ref' do
  24. modul = 'test'
  25. result = 'test'
  26. modul.to_filename
  27. assert_equal(result, modul)
  28. modul = 'some/file'
  29. result = 'some/file'
  30. modul.to_filename
  31. assert_equal(result, modul)
  32. end
  33. test 'to_classname function' do
  34. modul = 'test'
  35. result = 'Test'
  36. assert_equal(result, modul.to_classname)
  37. modul = 'some/file'
  38. result = 'Some::File'
  39. assert_equal(result, modul.to_classname)
  40. modul = 'some/files'
  41. result = 'Some::Files'
  42. assert_equal(result, modul.to_classname)
  43. modul = 'some_test/files'
  44. result = 'SomeTest::Files'
  45. assert_equal(result, modul.to_classname)
  46. end
  47. test 'html2text ref' do
  48. html = 'test'
  49. result = 'test'
  50. html.html2text
  51. assert_equal(result, html)
  52. html = '<div>test</div>'
  53. result = '<div>test</div>'
  54. html.html2text
  55. assert_equal(result, html)
  56. end
  57. test 'html2text function' do
  58. html = 'test'
  59. result = 'test'
  60. assert_equal(result, html.html2text)
  61. html = ' test '
  62. result = 'test'
  63. assert_equal(result, html.html2text)
  64. html = "\n\n test \n\n\n"
  65. result = 'test'
  66. assert_equal(result, html.html2text)
  67. html = '<div>test</div>'
  68. result = 'test'
  69. assert_equal(result, html.html2text)
  70. html = '<div>test<br></div>'
  71. result = 'test'
  72. assert_equal(result, html.html2text)
  73. html = "<div>test<br><br><br>\n<br>\n<br>\n</div>"
  74. result = 'test'
  75. assert_equal(result, html.html2text)
  76. html = "<pre>test\n\ntest</pre>"
  77. result = "test\ntest"
  78. assert_equal(result, html.html2text)
  79. html = "<code>test\n\ntest</code>"
  80. result = "test\ntest"
  81. assert_equal(result, html.html2text)
  82. html = '<table><tr><td>test</td><td>col</td></td></tr><tr><td>test</td><td>4711</td></tr></table>'
  83. result = "test col \ntest 4711"
  84. assert_equal(result, html.html2text)
  85. html = "<p><span>Was\nsoll verbessert werden:</span></p>"
  86. result = 'Was soll verbessert werden:'
  87. assert_equal(result, html.html2text)
  88. html = "<!-- some comment -->
  89. <div>
  90. test<br><br><br>\n<br>\n<br>\n
  91. </div>"
  92. result = 'test'
  93. assert_equal(result, html.html2text)
  94. html = "\n<div><a href=\"http://zammad.org\">Best Tool of the World</a>
  95. some other text</div>
  96. <div>"
  97. result = "[1] Best Tool of the Worldsome other text\n\n\n[1] http://zammad.org"
  98. assert_equal(result, html.html2text)
  99. html = "<!-- some comment -->
  100. <div>
  101. test<br><br><br>\n<hr/>\n<br>\n
  102. </div>"
  103. result = "test\n\n___"
  104. assert_equal(result, html.html2text)
  105. html = ' line&nbsp;1<br>
  106. you<br/>
  107. -----&amp;'
  108. should = 'line 1
  109. you
  110. -----&'
  111. assert_equal( should, html.html2text)
  112. html = ' <ul><li>#1</li><li>#2</li></ul>'
  113. should = '* #1
  114. * #2'
  115. assert_equal( should, html.html2text)
  116. html = '<!DOCTYPE html>
  117. <html>
  118. <head>
  119. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  120. <head>
  121. <body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">
  122. <div>&gt; Welcome!</div><div>&gt;</div><div>&gt; Thank you for installing Zammad.</div><div>&gt;</div>
  123. </body>
  124. </html>'
  125. should = '> Welcome!
  126. >
  127. > Thank you for installing Zammad.
  128. >'
  129. assert_equal( should, html.html2text)
  130. html = ' <style type="text/css">
  131. body {
  132. width:90% !important;
  133. -webkit-text-size-adjust:90%;
  134. -ms-text-size-adjust:90%;
  135. font-family:\'helvetica neue\', helvetica, arial, geneva, sans-serif; f=
  136. ont-size: 12px;;
  137. }
  138. img {
  139. outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;
  140. }
  141. a img {
  142. border:none;
  143. }
  144. table td {
  145. border-collapse: collapse;
  146. }
  147. table {
  148. border-collapse: collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;
  149. }
  150. p, table, div, td {
  151. max-width: 600px;
  152. }
  153. p {
  154. margin: 0;
  155. }
  156. blockquote, pre {
  157. margin: 0px;
  158. padding: 8px 12px 8px 12px;
  159. }
  160. </style><p>some other content</p>'
  161. should = 'some other content'
  162. assert_equal( should, html.html2text)
  163. html = ' IT-Infrastruktur</span><br>
  164. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  165. <meta name="Generator" content="Microsoft Word 14 (filtered
  166. medium)">
  167. <!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
  168. o\:* {behavior:url(#default#VML);}
  169. w\:* {behavior:url(#default#VML);}
  170. .shape {behavior:url(#default#VML);}
  171. </style><![endif]-->
  172. <style><!--
  173. @font-face
  174. {font-family:calibri;
  175. panose-1:2 15 5 2 2 2 4 3 2 4;}
  176. @font-face
  177. {font-family:tahoma;
  178. panose-1:2 11 6 4 3 5 4 4 2 4;}
  179. p.msonormal, li.msonormal, div.msonormal
  180. {margin:0cm;
  181. margin-bottom:.0001pt;
  182. font-size:11.0pt;
  183. font-family:"calibri","sans-serif";
  184. mso-fareast-language:en-us;}
  185. a:link, span.msohyperlink
  186. {mso-style-priority:99;
  187. color:blue;
  188. text-decoration:underline;}
  189. a:visited, span.msohyperlinkfollowed
  190. {mso-style-priority:99;
  191. color:purple;
  192. text-decoration:underline;}
  193. p.msoacetate, li.msoacetate, div.msoacetate
  194. {mso-style-priority:99;
  195. mso-style-link:"sprechblasentext zchn";
  196. margin:0cm;
  197. margin-bottom:.0001pt;
  198. font-size:8.0pt;
  199. font-family:"tahoma","sans-serif";
  200. mso-fareast-language:en-us;}
  201. span.e-mailformatvorlage17
  202. {mso-style-type:personal;
  203. font-family:"calibri","sans-serif";
  204. color:windowtext;}
  205. span.sprechblasentextzchn
  206. {mso-style-name:"sprechblasentext zchn";
  207. mso-style-priority:99;
  208. mso-style-link:sprechblasentext;
  209. font-family:"tahoma","sans-serif";}
  210. .msochpdefault
  211. {mso-style-type:export-only;
  212. font-family:"calibri","sans-serif";
  213. mso-fareast-language:en-us;}
  214. @page wordsection1
  215. {size:612.0pt 792.0pt;
  216. margin:70.85pt 70.85pt 2.0cm 70.85pt;}
  217. div.wordsection1
  218. {page:wordsection1;}
  219. --></style><!--[if gte mso 9]><xml>
  220. <o:shapedefaults v:ext="edit" spidmax="1026" />
  221. </xml><![endif]--><!--[if gte mso 9]><xml>
  222. <o:shapelayout v:ext="edit">
  223. <o:idmap v:ext="edit" data="1" />
  224. </o:shapelayout></xml><![endif]-->'
  225. should = 'IT-Infrastruktur'
  226. assert_equal( should, html.html2text)
  227. html = "<h1>some head</h1>
  228. some content
  229. <blockquote>
  230. <p>line 1</p>
  231. <p>line 2</p>
  232. </blockquote>
  233. <p>some text later</p>"
  234. result = 'some head
  235. some content
  236. > line 1
  237. > line 2
  238. some text later'
  239. assert_equal(result, html.html2text)
  240. html = "<h1>some head</h1>
  241. some content
  242. <blockquote>
  243. line 1<br/>
  244. line 2<br>
  245. </blockquote>
  246. <p>some text later</p>"
  247. result = 'some head
  248. some content
  249. > line 1
  250. > line 2
  251. some text later'
  252. assert_equal(result, html.html2text)
  253. html = "<h1>some head</h1>
  254. some content
  255. <blockquote>
  256. <div><div>line 1</div><br></div>
  257. <div><div>line 2</div><br></div>
  258. </blockquote>
  259. some text later"
  260. result = 'some head
  261. some content
  262. > line 1
  263. >
  264. > line 2
  265. some text later'
  266. assert_equal(result, html.html2text)
  267. html = "<p>Best regards,</p>
  268. <p><i>Your Team Team</i></p>
  269. <p>P.S.: You receive this e-mail because you are listed in our database as person who ordered a Team license. Please click <a href=\"http://www.teamviewer.example/en/company/unsubscribe.aspx?id=1009645&ident=xxx\">here</a> to unsubscribe from further e-mails.</p>
  270. -----------------------------
  271. <br />"
  272. result = 'Best regards,
  273. Your Team Team
  274. P.S.: You receive this e-mail because you are listed in our database as person who ordered a Team license. Please click [1] here to unsubscribe from further e-mails.
  275. -----------------------------
  276. [1] http://www.teamviewer.example/en/company/unsubscribe.aspx?id=1009645&ident=xxx'
  277. assert_equal(result, html.html2text)
  278. html = "<div><br>Dave and leaned her
  279. days adam.</div><span style=\"color:#F7F3FF; font-size:8px\">Maybe we
  280. want any help me that.<br>Next morning charlie saw at their
  281. father.<br>Well as though adam took out here. Melvin will be more money.
  282. Called him into this one last thing.<br>Men-----------------------
  283. <br />"
  284. result = 'Dave and leaned her days adam.
  285. Maybe we want any help me that.
  286. Next morning charlie saw at their father.
  287. Well as though adam took out here. Melvin will be more money. Called him into this one last thing.
  288. Men-----------------------'
  289. assert_equal(result, html.html2text)
  290. end
  291. end