PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/jruby-1.7.3/test/externals/ruby1.9/ruby/test_transcode.rb

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Ruby | 914 lines | 854 code | 43 blank | 17 comment | 0 complexity | c13fb7c92c4638858e5245ec6457e493 MD5 | raw file
  1. # encoding: ASCII-8BIT # make sure this runs in binary mode
  2. # some of the comments are in UTF-8
  3. require 'test/unit'
  4. class TestTranscode < Test::Unit::TestCase
  5. def test_errors
  6. assert_raise(Encoding::ConverterNotFoundError) { 'abc'.encode('foo', 'bar') }
  7. assert_raise(Encoding::ConverterNotFoundError) { 'abc'.encode!('foo', 'bar') }
  8. assert_raise(Encoding::ConverterNotFoundError) { 'abc'.force_encoding('utf-8').encode('foo') }
  9. assert_raise(Encoding::ConverterNotFoundError) { 'abc'.force_encoding('utf-8').encode!('foo') }
  10. assert_raise(Encoding::UndefinedConversionError) { "\x80".encode('utf-8','ASCII-8BIT') }
  11. assert_raise(Encoding::InvalidByteSequenceError) { "\x80".encode('utf-8','US-ASCII') }
  12. assert_raise(Encoding::UndefinedConversionError) { "\xA5".encode('utf-8','iso-8859-3') }
  13. assert_raise(RuntimeError) { 'hello'.freeze.encode!('iso-8859-1') }
  14. assert_raise(RuntimeError) { '\u3053\u3093\u306b\u3061\u306f'.freeze.encode!('iso-8859-1') } # こんにちは
  15. end
  16. def test_arguments
  17. assert_equal('abc', 'abc'.force_encoding('utf-8').encode('iso-8859-1'))
  18. # check that encoding is kept when no conversion is done
  19. assert_equal('abc'.force_encoding('Shift_JIS'), 'abc'.force_encoding('Shift_JIS').encode('Shift_JIS'))
  20. assert_equal('abc'.force_encoding('Shift_JIS'), 'abc'.force_encoding('Shift_JIS').encode!('Shift_JIS'))
  21. # assert that encoding is correctly set
  22. assert_equal("D\u00FCrst".encoding, "D\xFCrst".force_encoding('iso-8859-1').encode('utf-8').encoding)
  23. # check that Encoding can be used as parameter
  24. assert_equal("D\u00FCrst", "D\xFCrst".encode('utf-8', Encoding.find('ISO-8859-1')))
  25. assert_equal("D\u00FCrst", "D\xFCrst".encode(Encoding.find('utf-8'), 'ISO-8859-1'))
  26. assert_equal("D\u00FCrst", "D\xFCrst".encode(Encoding.find('utf-8'), Encoding.find('ISO-8859-1')))
  27. end
  28. def test_noargument
  29. default_default_internal = Encoding.default_internal
  30. Encoding.default_internal = nil
  31. assert_equal("\u3042".encode, "\u3042")
  32. assert_equal("\xE3\x81\x82\x81".force_encoding("utf-8").encode,
  33. "\xE3\x81\x82\x81".force_encoding("utf-8"))
  34. Encoding.default_internal = 'EUC-JP'
  35. assert_equal("\u3042".encode, "\xA4\xA2".force_encoding('EUC-JP'))
  36. assert_equal("\xE3\x81\x82\x81".force_encoding("utf-8").encode,
  37. "\xA4\xA2?".force_encoding('EUC-JP'))
  38. Encoding.default_internal = default_default_internal
  39. end
  40. def test_length
  41. assert_equal("\u20AC"*20, ("\xA4"*20).encode('utf-8', 'iso-8859-15'))
  42. assert_equal("\u20AC"*20, ("\xA4"*20).encode!('utf-8', 'iso-8859-15'))
  43. assert_equal("\u20AC"*2000, ("\xA4"*2000).encode('utf-8', 'iso-8859-15'))
  44. assert_equal("\u20AC"*2000, ("\xA4"*2000).encode!('utf-8', 'iso-8859-15'))
  45. assert_equal("\u20AC"*200000, ("\xA4"*200000).encode('utf-8', 'iso-8859-15'))
  46. assert_equal("\u20AC"*200000, ("\xA4"*200000).encode!('utf-8', 'iso-8859-15'))
  47. end
  48. def check_both_ways(utf8, raw, encoding)
  49. assert_equal(utf8.force_encoding('utf-8'), raw.encode('utf-8', encoding),utf8.dump)
  50. assert_equal(raw.force_encoding(encoding), utf8.encode(encoding, 'utf-8'))
  51. end
  52. def check_both_ways2(str1, enc1, str2, enc2)
  53. assert_equal(str1.force_encoding(enc1), str2.encode(enc1, enc2))
  54. assert_equal(str2.force_encoding(enc2), str1.encode(enc2, enc1))
  55. end
  56. def test_encodings
  57. check_both_ways("\u307E\u3064\u3082\u3068 \u3086\u304D\u3072\u308D",
  58. "\x82\xdc\x82\xc2\x82\xe0\x82\xc6 \x82\xe4\x82\xab\x82\xd0\x82\xeb", 'shift_jis') # まつもと ゆきひろ
  59. check_both_ways("\u307E\u3064\u3082\u3068 \u3086\u304D\u3072\u308D",
  60. "\xa4\xde\xa4\xc4\xa4\xe2\xa4\xc8 \xa4\xe6\xa4\xad\xa4\xd2\xa4\xed", 'euc-jp')
  61. check_both_ways("\u677E\u672C\u884C\u5F18", "\x8f\xbc\x96\x7b\x8d\x73\x8d\x4f", 'shift_jis') # 松本行弘
  62. check_both_ways("\u677E\u672C\u884C\u5F18", "\xbe\xbe\xcb\xdc\xb9\xd4\xb9\xb0", 'euc-jp')
  63. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-1') # Dürst
  64. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-2')
  65. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-3')
  66. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-4')
  67. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-9')
  68. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-10')
  69. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-13')
  70. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-14')
  71. check_both_ways("D\u00FCrst", "D\xFCrst", 'iso-8859-15')
  72. check_both_ways("r\u00E9sum\u00E9", "r\xE9sum\xE9", 'iso-8859-1') # résumé
  73. check_both_ways("\u0065\u006C\u0151\u00ED\u0072\u00E1\u0073", "el\xF5\xEDr\xE1s", 'iso-8859-2') # előírás
  74. check_both_ways("\u043F\u0435\u0440\u0435\u0432\u043E\u0434",
  75. "\xDF\xD5\xE0\xD5\xD2\xDE\xD4", 'iso-8859-5') # перевод
  76. check_both_ways("\u0643\u062A\u0628", "\xE3\xCA\xC8", 'iso-8859-6') # كتب
  77. check_both_ways("\u65E5\u8A18", "\x93\xFA\x8BL", 'shift_jis') # 日記
  78. check_both_ways("\u65E5\u8A18", "\xC6\xFC\xB5\xAD", 'euc-jp')
  79. check_both_ways("\uC560\uC778\uAD6C\uD568\u0020\u6734\uC9C0\uC778",
  80. "\xBE\xD6\xC0\xCE\xB1\xB8\xC7\xD4\x20\xDA\xD3\xC1\xF6\xC0\xCE", 'euc-kr') # 애인구함 朴지인
  81. check_both_ways("\uC544\uD58F\uD58F\u0020\uB620\uBC29\uD6BD\uB2D8\u0020\uC0AC\uB791\uD716",
  82. "\xBE\xC6\xC1\x64\xC1\x64\x20\x8C\x63\xB9\xE6\xC4\x4F\xB4\xD4\x20\xBB\xE7\xB6\xFB\xC5\x42", 'cp949') # 아햏햏 똠방횽님 사랑휖
  83. assert_equal(Encoding::ISO_8859_1, "D\xFCrst".force_encoding('iso-8859-2').encode('iso-8859-1', 'iso-8859-1').encoding)
  84. end
  85. def test_twostep
  86. assert_equal("D\xFCrst".force_encoding('iso-8859-2'), "D\xFCrst".encode('iso-8859-2', 'iso-8859-1'))
  87. end
  88. def test_ascii_range
  89. encodings = [
  90. 'US-ASCII', 'ASCII-8BIT',
  91. 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3',
  92. 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6',
  93. 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
  94. 'ISO-8859-10', 'ISO-8859-11', 'ISO-8859-13',
  95. 'ISO-8859-14', 'ISO-8859-15',
  96. 'EUC-JP', 'SHIFT_JIS', 'EUC-KR'
  97. ]
  98. all_ascii = (0..127).to_a.pack 'C*'
  99. encodings.each do |enc|
  100. test_start = all_ascii
  101. assert_equal(test_start, test_start.encode('UTF-8',enc).encode(enc).force_encoding('ASCII-8BIT'))
  102. end
  103. end
  104. def test_all_bytes
  105. encodings_8859 = [
  106. 'ISO-8859-1', 'ISO-8859-2',
  107. #'ISO-8859-3', # not all bytes used
  108. 'ISO-8859-4', 'ISO-8859-5',
  109. #'ISO-8859-6', # not all bytes used
  110. #'ISO-8859-7', # not all bytes used
  111. #'ISO-8859-8', # not all bytes used
  112. 'ISO-8859-9', 'ISO-8859-10',
  113. #'ISO-8859-11', # not all bytes used
  114. #'ISO-8859-12', # not available
  115. 'ISO-8859-13','ISO-8859-14','ISO-8859-15',
  116. #'ISO-8859-16', # not available
  117. ]
  118. all_bytes = (0..255).to_a.pack 'C*'
  119. encodings_8859.each do |enc|
  120. test_start = all_bytes
  121. assert_equal(test_start, test_start.encode('UTF-8',enc).encode(enc).force_encoding('ASCII-8BIT'))
  122. end
  123. end
  124. def test_windows_874
  125. check_both_ways("\u20AC", "\x80", 'windows-874') #
  126. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-874') }
  127. assert_raise(Encoding::UndefinedConversionError) { "\x84".encode("utf-8", 'windows-874') }
  128. check_both_ways("\u2026", "\x85", 'windows-874') #
  129. assert_raise(Encoding::UndefinedConversionError) { "\x86".encode("utf-8", 'windows-874') }
  130. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'windows-874') }
  131. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-874') }
  132. check_both_ways("\u2018", "\x91", 'windows-874') #
  133. check_both_ways("\u2014", "\x97", 'windows-874') #
  134. assert_raise(Encoding::UndefinedConversionError) { "\x98".encode("utf-8", 'windows-874') }
  135. assert_raise(Encoding::UndefinedConversionError) { "\x9F".encode("utf-8", 'windows-874') }
  136. check_both_ways("\u00A0", "\xA0", 'windows-874') # non-breaking space
  137. check_both_ways("\u0E0F", "\xAF", 'windows-874') #
  138. check_both_ways("\u0E10", "\xB0", 'windows-874') #
  139. check_both_ways("\u0E1F", "\xBF", 'windows-874') #
  140. check_both_ways("\u0E20", "\xC0", 'windows-874') #
  141. check_both_ways("\u0E2F", "\xCF", 'windows-874') #
  142. check_both_ways("\u0E30", "\xD0", 'windows-874') #
  143. check_both_ways("\u0E3A", "\xDA", 'windows-874') #
  144. assert_raise(Encoding::UndefinedConversionError) { "\xDB".encode("utf-8", 'windows-874') }
  145. assert_raise(Encoding::UndefinedConversionError) { "\xDE".encode("utf-8", 'windows-874') }
  146. check_both_ways("\u0E3F", "\xDF", 'windows-874') # ฿
  147. check_both_ways("\u0E40", "\xE0", 'windows-874') #
  148. check_both_ways("\u0E4F", "\xEF", 'windows-874') #
  149. check_both_ways("\u0E50", "\xF0", 'windows-874') #
  150. check_both_ways("\u0E5B", "\xFB", 'windows-874') #
  151. assert_raise(Encoding::UndefinedConversionError) { "\xFC".encode("utf-8", 'windows-874') }
  152. assert_raise(Encoding::UndefinedConversionError) { "\xFF".encode("utf-8", 'windows-874') }
  153. end
  154. def test_windows_1250
  155. check_both_ways("\u20AC", "\x80", 'windows-1250') #
  156. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1250') }
  157. check_both_ways("\u201A", "\x82", 'windows-1250') #
  158. assert_raise(Encoding::UndefinedConversionError) { "\x83".encode("utf-8", 'windows-1250') }
  159. check_both_ways("\u201E", "\x84", 'windows-1250') #
  160. check_both_ways("\u2021", "\x87", 'windows-1250') #
  161. assert_raise(Encoding::UndefinedConversionError) { "\x88".encode("utf-8", 'windows-1250') }
  162. check_both_ways("\u2030", "\x89", 'windows-1250') #
  163. check_both_ways("\u0179", "\x8F", 'windows-1250') # Ź
  164. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1250') }
  165. check_both_ways("\u2018", "\x91", 'windows-1250') #
  166. check_both_ways("\u2014", "\x97", 'windows-1250') #
  167. assert_raise(Encoding::UndefinedConversionError) { "\x98".encode("utf-8", 'windows-1250') }
  168. check_both_ways("\u2122", "\x99", 'windows-1250') #
  169. check_both_ways("\u00A0", "\xA0", 'windows-1250') # non-breaking space
  170. check_both_ways("\u017B", "\xAF", 'windows-1250') # Ż
  171. check_both_ways("\u00B0", "\xB0", 'windows-1250') # °
  172. check_both_ways("\u017C", "\xBF", 'windows-1250') # ż
  173. check_both_ways("\u0154", "\xC0", 'windows-1250') # Ŕ
  174. check_both_ways("\u010E", "\xCF", 'windows-1250') # Ď
  175. check_both_ways("\u0110", "\xD0", 'windows-1250') # Đ
  176. check_both_ways("\u00DF", "\xDF", 'windows-1250') # ß
  177. check_both_ways("\u0155", "\xE0", 'windows-1250') # ŕ
  178. check_both_ways("\u010F", "\xEF", 'windows-1250') # ď
  179. check_both_ways("\u0111", "\xF0", 'windows-1250') # đ
  180. check_both_ways("\u02D9", "\xFF", 'windows-1250') # ˙
  181. end
  182. def test_windows_1251
  183. check_both_ways("\u0402", "\x80", 'windows-1251') # Ђ
  184. check_both_ways("\u20AC", "\x88", 'windows-1251') #
  185. check_both_ways("\u040F", "\x8F", 'windows-1251') # Џ
  186. check_both_ways("\u0452", "\x90", 'windows-1251') # ђ
  187. assert_raise(Encoding::UndefinedConversionError) { "\x98".encode("utf-8", 'windows-1251') }
  188. check_both_ways("\u045F", "\x9F", 'windows-1251') # џ
  189. check_both_ways("\u00A0", "\xA0", 'windows-1251') # non-breaking space
  190. check_both_ways("\u0407", "\xAF", 'windows-1251') # Ї
  191. check_both_ways("\u00B0", "\xB0", 'windows-1251') # °
  192. check_both_ways("\u0457", "\xBF", 'windows-1251') # ї
  193. check_both_ways("\u0410", "\xC0", 'windows-1251') # А
  194. check_both_ways("\u041F", "\xCF", 'windows-1251') # П
  195. check_both_ways("\u0420", "\xD0", 'windows-1251') # Р
  196. check_both_ways("\u042F", "\xDF", 'windows-1251') # Я
  197. check_both_ways("\u0430", "\xE0", 'windows-1251') # а
  198. check_both_ways("\u043F", "\xEF", 'windows-1251') # п
  199. check_both_ways("\u0440", "\xF0", 'windows-1251') # р
  200. check_both_ways("\u044F", "\xFF", 'windows-1251') # я
  201. end
  202. def test_windows_1252
  203. check_both_ways("\u20AC", "\x80", 'windows-1252') #
  204. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1252') }
  205. check_both_ways("\u201A", "\x82", 'windows-1252') #
  206. check_both_ways("\u0152", "\x8C", 'windows-1252') # >Œ
  207. assert_raise(Encoding::UndefinedConversionError) { "\x8D".encode("utf-8", 'windows-1252') }
  208. check_both_ways("\u017D", "\x8E", 'windows-1252') # Ž
  209. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'windows-1252') }
  210. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1252') }
  211. check_both_ways("\u2018", "\x91", 'windows-1252') #
  212. check_both_ways("\u0153", "\x9C", 'windows-1252') # œ
  213. assert_raise(Encoding::UndefinedConversionError) { "\x9D".encode("utf-8", 'windows-1252') }
  214. check_both_ways("\u017E", "\x9E", 'windows-1252') # ž
  215. check_both_ways("\u00A0", "\xA0", 'windows-1252') # non-breaking space
  216. check_both_ways("\u00AF", "\xAF", 'windows-1252') # ¯
  217. check_both_ways("\u00B0", "\xB0", 'windows-1252') # °
  218. check_both_ways("\u00BF", "\xBF", 'windows-1252') # ¿
  219. check_both_ways("\u00C0", "\xC0", 'windows-1252') # À
  220. check_both_ways("\u00CF", "\xCF", 'windows-1252') # Ï
  221. check_both_ways("\u00D0", "\xD0", 'windows-1252') # Ð
  222. check_both_ways("\u00DF", "\xDF", 'windows-1252') # ß
  223. check_both_ways("\u00E0", "\xE0", 'windows-1252') # à
  224. check_both_ways("\u00EF", "\xEF", 'windows-1252') # ï
  225. check_both_ways("\u00F0", "\xF0", 'windows-1252') # ð
  226. check_both_ways("\u00FF", "\xFF", 'windows-1252') # ÿ
  227. end
  228. def test_windows_1253
  229. check_both_ways("\u20AC", "\x80", 'windows-1253') #
  230. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1253') }
  231. check_both_ways("\u201A", "\x82", 'windows-1253') #
  232. check_both_ways("\u2021", "\x87", 'windows-1253') #
  233. assert_raise(Encoding::UndefinedConversionError) { "\x88".encode("utf-8", 'windows-1253') }
  234. check_both_ways("\u2030", "\x89", 'windows-1253') #
  235. assert_raise(Encoding::UndefinedConversionError) { "\x8A".encode("utf-8", 'windows-1253') }
  236. check_both_ways("\u2039", "\x8B", 'windows-1253') #
  237. assert_raise(Encoding::UndefinedConversionError) { "\x8C".encode("utf-8", 'windows-1253') }
  238. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'windows-1253') }
  239. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1253') }
  240. check_both_ways("\u2018", "\x91", 'windows-1253') #
  241. check_both_ways("\u2014", "\x97", 'windows-1253') #
  242. assert_raise(Encoding::UndefinedConversionError) { "\x98".encode("utf-8", 'windows-1253') }
  243. check_both_ways("\u2122", "\x99", 'windows-1253') #
  244. assert_raise(Encoding::UndefinedConversionError) { "\x9A".encode("utf-8", 'windows-1253') }
  245. check_both_ways("\u203A", "\x9B", 'windows-1253') #
  246. assert_raise(Encoding::UndefinedConversionError) { "\x9C".encode("utf-8", 'windows-1253') }
  247. assert_raise(Encoding::UndefinedConversionError) { "\x9F".encode("utf-8", 'windows-1253') }
  248. check_both_ways("\u00A0", "\xA0", 'windows-1253') # non-breaking space
  249. check_both_ways("\u2015", "\xAF", 'windows-1253') #
  250. check_both_ways("\u00B0", "\xB0", 'windows-1253') # °
  251. check_both_ways("\u038F", "\xBF", 'windows-1253') # Ώ
  252. check_both_ways("\u0390", "\xC0", 'windows-1253') # ΐ
  253. check_both_ways("\u039F", "\xCF", 'windows-1253') # Ο
  254. check_both_ways("\u03A0", "\xD0", 'windows-1253') # Π
  255. check_both_ways("\u03A1", "\xD1", 'windows-1253') # Ρ
  256. assert_raise(Encoding::UndefinedConversionError) { "\xD2".encode("utf-8", 'windows-1253') }
  257. check_both_ways("\u03A3", "\xD3", 'windows-1253') # Σ
  258. check_both_ways("\u03AF", "\xDF", 'windows-1253') # ί
  259. check_both_ways("\u03B0", "\xE0", 'windows-1253') # ΰ
  260. check_both_ways("\u03BF", "\xEF", 'windows-1253') # ο
  261. check_both_ways("\u03C0", "\xF0", 'windows-1253') # π
  262. check_both_ways("\u03CE", "\xFE", 'windows-1253') # ώ
  263. assert_raise(Encoding::UndefinedConversionError) { "\xFF".encode("utf-8", 'windows-1253') }
  264. end
  265. def test_windows_1254
  266. check_both_ways("\u20AC", "\x80", 'windows-1254') #
  267. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1254') }
  268. check_both_ways("\u201A", "\x82", 'windows-1254') #
  269. check_both_ways("\u0152", "\x8C", 'windows-1254') # Œ
  270. assert_raise(Encoding::UndefinedConversionError) { "\x8D".encode("utf-8", 'windows-1254') }
  271. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'windows-1254') }
  272. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1254') }
  273. check_both_ways("\u2018", "\x91", 'windows-1254') #
  274. check_both_ways("\u0153", "\x9C", 'windows-1254') # œ
  275. assert_raise(Encoding::UndefinedConversionError) { "\x9D".encode("utf-8", 'windows-1254') }
  276. assert_raise(Encoding::UndefinedConversionError) { "\x9E".encode("utf-8", 'windows-1254') }
  277. check_both_ways("\u0178", "\x9F", 'windows-1254') # Ÿ
  278. check_both_ways("\u00A0", "\xA0", 'windows-1254') # non-breaking space
  279. check_both_ways("\u00AF", "\xAF", 'windows-1254') # ¯
  280. check_both_ways("\u00B0", "\xB0", 'windows-1254') # °
  281. check_both_ways("\u00BF", "\xBF", 'windows-1254') # ¿
  282. check_both_ways("\u00C0", "\xC0", 'windows-1254') # À
  283. check_both_ways("\u00CF", "\xCF", 'windows-1254') # Ï
  284. check_both_ways("\u011E", "\xD0", 'windows-1254') # Ğ
  285. check_both_ways("\u00DF", "\xDF", 'windows-1254') # ß
  286. check_both_ways("\u00E0", "\xE0", 'windows-1254') # à
  287. check_both_ways("\u00EF", "\xEF", 'windows-1254') # ï
  288. check_both_ways("\u011F", "\xF0", 'windows-1254') # ğ
  289. check_both_ways("\u00FF", "\xFF", 'windows-1254') # ÿ
  290. end
  291. def test_windows_1255
  292. check_both_ways("\u20AC", "\x80", 'windows-1255') #
  293. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1255') }
  294. check_both_ways("\u201A", "\x82", 'windows-1255') #
  295. check_both_ways("\u2030", "\x89", 'windows-1255') #
  296. assert_raise(Encoding::UndefinedConversionError) { "\x8A".encode("utf-8", 'windows-1255') }
  297. check_both_ways("\u2039", "\x8B", 'windows-1255') #
  298. assert_raise(Encoding::UndefinedConversionError) { "\x8C".encode("utf-8", 'windows-1255') }
  299. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'windows-1255') }
  300. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1255') }
  301. check_both_ways("\u2018", "\x91", 'windows-1255') #
  302. check_both_ways("\u2122", "\x99", 'windows-1255') #
  303. assert_raise(Encoding::UndefinedConversionError) { "\x9A".encode("utf-8", 'windows-1255') }
  304. check_both_ways("\u203A", "\x9B", 'windows-1255') #
  305. assert_raise(Encoding::UndefinedConversionError) { "\x9C".encode("utf-8", 'windows-1255') }
  306. assert_raise(Encoding::UndefinedConversionError) { "\x9F".encode("utf-8", 'windows-1255') }
  307. check_both_ways("\u00A0", "\xA0", 'windows-1255') # non-breaking space
  308. check_both_ways("\u00A1", "\xA1", 'windows-1255') # ¡
  309. check_both_ways("\u00D7", "\xAA", 'windows-1255') # ×
  310. check_both_ways("\u00AF", "\xAF", 'windows-1255') # ¯
  311. check_both_ways("\u00B0", "\xB0", 'windows-1255') # °
  312. check_both_ways("\u00B8", "\xB8", 'windows-1255') # ¸
  313. check_both_ways("\u00F7", "\xBA", 'windows-1255') # ÷
  314. check_both_ways("\u00BF", "\xBF", 'windows-1255') # ¿
  315. check_both_ways("\u05B0", "\xC0", 'windows-1255') # ְ
  316. check_both_ways("\u05B9", "\xC9", 'windows-1255') # ֹ
  317. assert_raise(Encoding::UndefinedConversionError) { "\xCA".encode("utf-8", 'windows-1255') }
  318. check_both_ways("\u05BB", "\xCB", 'windows-1255') # ֻ
  319. check_both_ways("\u05BF", "\xCF", 'windows-1255') # ֿ
  320. check_both_ways("\u05C0", "\xD0", 'windows-1255') # ׀
  321. check_both_ways("\u05F3", "\xD7", 'windows-1255') # ׳
  322. check_both_ways("\u05F4", "\xD8", 'windows-1255') # ״
  323. assert_raise(Encoding::UndefinedConversionError) { "\xD9".encode("utf-8", 'windows-1255') }
  324. assert_raise(Encoding::UndefinedConversionError) { "\xDF".encode("utf-8", 'windows-1255') }
  325. check_both_ways("\u05D0", "\xE0", 'windows-1255') # א
  326. check_both_ways("\u05DF", "\xEF", 'windows-1255') # ן
  327. check_both_ways("\u05E0", "\xF0", 'windows-1255') # נ
  328. check_both_ways("\u05EA", "\xFA", 'windows-1255') # ת
  329. assert_raise(Encoding::UndefinedConversionError) { "\xFB".encode("utf-8", 'windows-1255') }
  330. assert_raise(Encoding::UndefinedConversionError) { "\xFC".encode("utf-8", 'windows-1255') }
  331. check_both_ways("\u200E", "\xFD", 'windows-1255') # left-to-right mark
  332. check_both_ways("\u200F", "\xFE", 'windows-1255') # right-to-left mark
  333. assert_raise(Encoding::UndefinedConversionError) { "\xFF".encode("utf-8", 'windows-1255') }
  334. end
  335. def test_windows_1256
  336. check_both_ways("\u20AC", "\x80", 'windows-1256') #
  337. check_both_ways("\u0679", "\x8A", 'windows-1256') # ٹ
  338. check_both_ways("\u0688", "\x8F", 'windows-1256') # ڈ
  339. check_both_ways("\u06AF", "\x90", 'windows-1256') # گ
  340. check_both_ways("\u06A9", "\x98", 'windows-1256') # ک
  341. check_both_ways("\u0691", "\x9A", 'windows-1256') # ڑ
  342. check_both_ways("\u06BA", "\x9F", 'windows-1256') # ں
  343. check_both_ways("\u00A0", "\xA0", 'windows-1256') # non-breaking space
  344. check_both_ways("\u06BE", "\xAA", 'windows-1256') # ھ
  345. check_both_ways("\u00AF", "\xAF", 'windows-1256') # ¯
  346. check_both_ways("\u00B0", "\xB0", 'windows-1256') # °
  347. check_both_ways("\u061F", "\xBF", 'windows-1256') # ؟
  348. check_both_ways("\u06C1", "\xC0", 'windows-1256') # ہ
  349. check_both_ways("\u062F", "\xCF", 'windows-1256') # د
  350. check_both_ways("\u0630", "\xD0", 'windows-1256') # ذ
  351. check_both_ways("\u0643", "\xDF", 'windows-1256') # ك
  352. check_both_ways("\u00E0", "\xE0", 'windows-1256') # à
  353. check_both_ways("\u00EF", "\xEF", 'windows-1256') # ï
  354. check_both_ways("\u064B", "\xF0", 'windows-1256') # ًً
  355. check_both_ways("\u06D2", "\xFF", 'windows-1256') # ے
  356. end
  357. def test_windows_1257
  358. check_both_ways("\u20AC", "\x80", 'windows-1257') #
  359. assert_raise(Encoding::UndefinedConversionError) { "\x81".encode("utf-8", 'windows-1257') }
  360. check_both_ways("\u201A", "\x82", 'windows-1257') #
  361. assert_raise(Encoding::UndefinedConversionError) { "\x83".encode("utf-8", 'windows-1257') }
  362. check_both_ways("\u201E", "\x84", 'windows-1257') #
  363. check_both_ways("\u2021", "\x87", 'windows-1257') #
  364. assert_raise(Encoding::UndefinedConversionError) { "\x88".encode("utf-8", 'windows-1257') }
  365. check_both_ways("\u2030", "\x89", 'windows-1257') #
  366. assert_raise(Encoding::UndefinedConversionError) { "\x8A".encode("utf-8", 'windows-1257') }
  367. check_both_ways("\u2039", "\x8B", 'windows-1257') #
  368. assert_raise(Encoding::UndefinedConversionError) { "\x8C".encode("utf-8", 'windows-1257') }
  369. check_both_ways("\u00A8", "\x8D", 'windows-1257') # ¨
  370. check_both_ways("\u02C7", "\x8E", 'windows-1257') # ˇ
  371. check_both_ways("\u00B8", "\x8F", 'windows-1257') # ¸
  372. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'windows-1257') }
  373. check_both_ways("\u2018", "\x91", 'windows-1257') #
  374. check_both_ways("\u2014", "\x97", 'windows-1257') #
  375. assert_raise(Encoding::UndefinedConversionError) { "\x98".encode("utf-8", 'windows-1257') }
  376. check_both_ways("\u2122", "\x99", 'windows-1257') #
  377. assert_raise(Encoding::UndefinedConversionError) { "\x9A".encode("utf-8", 'windows-1257') }
  378. check_both_ways("\u203A", "\x9B", 'windows-1257') #
  379. assert_raise(Encoding::UndefinedConversionError) { "\x9C".encode("utf-8", 'windows-1257') }
  380. check_both_ways("\u00AF", "\x9D", 'windows-1257') # ¯
  381. check_both_ways("\u02DB", "\x9E", 'windows-1257') # ˛
  382. assert_raise(Encoding::UndefinedConversionError) { "\x9F".encode("utf-8", 'windows-1257') }
  383. check_both_ways("\u00A0", "\xA0", 'windows-1257') # non-breaking space
  384. assert_raise(Encoding::UndefinedConversionError) { "\xA1".encode("utf-8", 'windows-1257') }
  385. check_both_ways("\u00A2", "\xA2", 'windows-1257') # ¢
  386. check_both_ways("\u00A4", "\xA4", 'windows-1257') # ¤
  387. assert_raise(Encoding::UndefinedConversionError) { "\xA5".encode("utf-8", 'windows-1257') }
  388. check_both_ways("\u00A6", "\xA6", 'windows-1257') # ¦
  389. check_both_ways("\u00C6", "\xAF", 'windows-1257') # Æ
  390. check_both_ways("\u00B0", "\xB0", 'windows-1257') # °
  391. check_both_ways("\u00E6", "\xBF", 'windows-1257') # æ
  392. check_both_ways("\u0104", "\xC0", 'windows-1257') # Ą
  393. check_both_ways("\u013B", "\xCF", 'windows-1257') # Ļ
  394. check_both_ways("\u0160", "\xD0", 'windows-1257') # Š
  395. check_both_ways("\u00DF", "\xDF", 'windows-1257') # ß
  396. check_both_ways("\u0105", "\xE0", 'windows-1257') # ą
  397. check_both_ways("\u013C", "\xEF", 'windows-1257') # ļ
  398. check_both_ways("\u0161", "\xF0", 'windows-1257') # š
  399. check_both_ways("\u02D9", "\xFF", 'windows-1257') # ˙
  400. end
  401. def test_IBM437
  402. check_both_ways("\u00C7", "\x80", 'IBM437') # Ç
  403. check_both_ways("\u00C5", "\x8F", 'IBM437') # Å
  404. check_both_ways("\u00C9", "\x90", 'IBM437') # É
  405. check_both_ways("\u0192", "\x9F", 'IBM437') # ƒ
  406. check_both_ways("\u00E1", "\xA0", 'IBM437') # á
  407. check_both_ways("\u00BB", "\xAF", 'IBM437') # »
  408. check_both_ways("\u2591", "\xB0", 'IBM437') #
  409. check_both_ways("\u2510", "\xBF", 'IBM437') #
  410. check_both_ways("\u2514", "\xC0", 'IBM437') #
  411. check_both_ways("\u2567", "\xCF", 'IBM437') #
  412. check_both_ways("\u2568", "\xD0", 'IBM437') #
  413. check_both_ways("\u2580", "\xDF", 'IBM437') #
  414. check_both_ways("\u03B1", "\xE0", 'IBM437') # α
  415. check_both_ways("\u2229", "\xEF", 'IBM437') #
  416. check_both_ways("\u2261", "\xF0", 'IBM437') #
  417. check_both_ways("\u00A0", "\xFF", 'IBM437') # non-breaking space
  418. end
  419. def test_IBM775
  420. check_both_ways("\u0106", "\x80", 'IBM775') # Ć
  421. check_both_ways("\u00C5", "\x8F", 'IBM775') # Å
  422. check_both_ways("\u00C9", "\x90", 'IBM775') # É
  423. check_both_ways("\u00A4", "\x9F", 'IBM775') # ¤
  424. check_both_ways("\u0100", "\xA0", 'IBM775') # Ā
  425. check_both_ways("\u00BB", "\xAF", 'IBM775') # »
  426. check_both_ways("\u2591", "\xB0", 'IBM775') #
  427. check_both_ways("\u2510", "\xBF", 'IBM775') #
  428. check_both_ways("\u2514", "\xC0", 'IBM775') #
  429. check_both_ways("\u017D", "\xCF", 'IBM775') # Ž
  430. check_both_ways("\u0105", "\xD0", 'IBM775') # ą
  431. check_both_ways("\u2580", "\xDF", 'IBM775') #
  432. check_both_ways("\u00D3", "\xE0", 'IBM775') # Ó
  433. check_both_ways("\u2019", "\xEF", 'IBM775') #
  434. check_both_ways("\u00AD", "\xF0", 'IBM775') # osft hyphen
  435. check_both_ways("\u00A0", "\xFF", 'IBM775') # non-breaking space
  436. end
  437. def test_IBM852
  438. check_both_ways("\u00C7", "\x80", 'IBM852') # Ç
  439. check_both_ways("\u0106", "\x8F", 'IBM852') # Ć
  440. check_both_ways("\u00C9", "\x90", 'IBM852') # É
  441. check_both_ways("\u010D", "\x9F", 'IBM852') # č
  442. check_both_ways("\u00E1", "\xA0", 'IBM852') # á
  443. check_both_ways("\u00BB", "\xAF", 'IBM852') # »
  444. check_both_ways("\u2591", "\xB0", 'IBM852') #
  445. check_both_ways("\u2510", "\xBF", 'IBM852') #
  446. check_both_ways("\u2514", "\xC0", 'IBM852') #
  447. check_both_ways("\u00A4", "\xCF", 'IBM852') # ¤
  448. check_both_ways("\u0111", "\xD0", 'IBM852') # đ
  449. check_both_ways("\u2580", "\xDF", 'IBM852') #
  450. check_both_ways("\u00D3", "\xE0", 'IBM852') # Ó
  451. check_both_ways("\u00B4", "\xEF", 'IBM852') # ´
  452. check_both_ways("\u00AD", "\xF0", 'IBM852') # osft hyphen
  453. check_both_ways("\u00A0", "\xFF", 'IBM852') # non-breaking space
  454. end
  455. def test_IBM855
  456. check_both_ways("\u0452", "\x80", 'IBM855') # ђ
  457. check_both_ways("\u0408", "\x8F", 'IBM855') # Ј
  458. check_both_ways("\u0459", "\x90", 'IBM855') # љ
  459. check_both_ways("\u042A", "\x9F", 'IBM855') # Ъ
  460. check_both_ways("\u0430", "\xA0", 'IBM855') # а
  461. check_both_ways("\u00BB", "\xAF", 'IBM855') # »
  462. check_both_ways("\u2591", "\xB0", 'IBM855') #
  463. check_both_ways("\u2510", "\xBF", 'IBM855') #
  464. check_both_ways("\u2514", "\xC0", 'IBM855') #
  465. check_both_ways("\u00A4", "\xCF", 'IBM855') # ¤
  466. check_both_ways("\u043B", "\xD0", 'IBM855') # л
  467. check_both_ways("\u2580", "\xDF", 'IBM855') #
  468. check_both_ways("\u042F", "\xE0", 'IBM855') # Я
  469. check_both_ways("\u2116", "\xEF", 'IBM855') #
  470. check_both_ways("\u00AD", "\xF0", 'IBM855') # osft hyphen
  471. check_both_ways("\u00A0", "\xFF", 'IBM855') # non-breaking space
  472. end
  473. def test_IBM857
  474. check_both_ways("\u00C7", "\x80", 'IBM857') # Ç
  475. check_both_ways("\u00C5", "\x8F", 'IBM857') # Å
  476. check_both_ways("\u00C9", "\x90", 'IBM857') # É
  477. check_both_ways("\u015F", "\x9F", 'IBM857') # ş
  478. check_both_ways("\u00E1", "\xA0", 'IBM857') # á
  479. check_both_ways("\u00BB", "\xAF", 'IBM857') # »
  480. check_both_ways("\u2591", "\xB0", 'IBM857') #
  481. check_both_ways("\u2510", "\xBF", 'IBM857') #
  482. check_both_ways("\u2514", "\xC0", 'IBM857') #
  483. check_both_ways("\u00A4", "\xCF", 'IBM857') # ¤
  484. check_both_ways("\u00BA", "\xD0", 'IBM857') # º
  485. check_both_ways("\u00C8", "\xD4", 'IBM857') # È
  486. assert_raise(Encoding::UndefinedConversionError) { "\xD5".encode("utf-8", 'IBM857') }
  487. check_both_ways("\u00CD", "\xD6", 'IBM857') # Í
  488. check_both_ways("\u2580", "\xDF", 'IBM857') #
  489. check_both_ways("\u00D3", "\xE0", 'IBM857') # Ó
  490. check_both_ways("\u00B5", "\xE6", 'IBM857') # µ
  491. assert_raise(Encoding::UndefinedConversionError) { "\xE7".encode("utf-8", 'IBM857') }
  492. check_both_ways("\u00D7", "\xE8", 'IBM857') # ×
  493. check_both_ways("\u00B4", "\xEF", 'IBM857') # ´
  494. check_both_ways("\u00AD", "\xF0", 'IBM857') # soft hyphen
  495. check_both_ways("\u00B1", "\xF1", 'IBM857') # ±
  496. assert_raise(Encoding::UndefinedConversionError) { "\xF2".encode("utf-8", 'IBM857') }
  497. check_both_ways("\u00BE", "\xF3", 'IBM857') # ¾
  498. check_both_ways("\u00A0", "\xFF", 'IBM857') # non-breaking space
  499. end
  500. def test_IBM860
  501. check_both_ways("\u00C7", "\x80", 'IBM860') # Ç
  502. check_both_ways("\u00C2", "\x8F", 'IBM860') # Â
  503. check_both_ways("\u00C9", "\x90", 'IBM860') # É
  504. check_both_ways("\u00D3", "\x9F", 'IBM860') # Ó
  505. check_both_ways("\u00E1", "\xA0", 'IBM860') # á
  506. check_both_ways("\u00BB", "\xAF", 'IBM860') # »
  507. check_both_ways("\u2591", "\xB0", 'IBM860') #
  508. check_both_ways("\u2510", "\xBF", 'IBM860') #
  509. check_both_ways("\u2514", "\xC0", 'IBM860') #
  510. check_both_ways("\u2567", "\xCF", 'IBM860') #
  511. check_both_ways("\u2568", "\xD0", 'IBM860') #
  512. check_both_ways("\u2580", "\xDF", 'IBM860') #
  513. check_both_ways("\u03B1", "\xE0", 'IBM860') # α
  514. check_both_ways("\u2229", "\xEF", 'IBM860') #
  515. check_both_ways("\u2261", "\xF0", 'IBM860') #
  516. check_both_ways("\u00A0", "\xFF", 'IBM860') # non-breaking space
  517. end
  518. def test_IBM861
  519. check_both_ways("\u00C7", "\x80", 'IBM861') # Ç
  520. check_both_ways("\u00C5", "\x8F", 'IBM861') # Å
  521. check_both_ways("\u00C9", "\x90", 'IBM861') # É
  522. check_both_ways("\u0192", "\x9F", 'IBM861') # ƒ
  523. check_both_ways("\u00E1", "\xA0", 'IBM861') # á
  524. check_both_ways("\u00BB", "\xAF", 'IBM861') # »
  525. check_both_ways("\u2591", "\xB0", 'IBM861') #
  526. check_both_ways("\u2510", "\xBF", 'IBM861') #
  527. check_both_ways("\u2514", "\xC0", 'IBM861') #
  528. check_both_ways("\u2567", "\xCF", 'IBM861') #
  529. check_both_ways("\u2568", "\xD0", 'IBM861') #
  530. check_both_ways("\u2580", "\xDF", 'IBM861') #
  531. check_both_ways("\u03B1", "\xE0", 'IBM861') # α
  532. check_both_ways("\u2229", "\xEF", 'IBM861') #
  533. check_both_ways("\u2261", "\xF0", 'IBM861') #
  534. check_both_ways("\u00A0", "\xFF", 'IBM861') # non-breaking space
  535. end
  536. def test_IBM862
  537. check_both_ways("\u05D0", "\x80", 'IBM862') # א
  538. check_both_ways("\u05DF", "\x8F", 'IBM862') # ן
  539. check_both_ways("\u05E0", "\x90", 'IBM862') # נ
  540. check_both_ways("\u0192", "\x9F", 'IBM862') # ƒ
  541. check_both_ways("\u00E1", "\xA0", 'IBM862') # á
  542. check_both_ways("\u00BB", "\xAF", 'IBM862') # »
  543. check_both_ways("\u2591", "\xB0", 'IBM862') #
  544. check_both_ways("\u2510", "\xBF", 'IBM862') #
  545. check_both_ways("\u2514", "\xC0", 'IBM862') #
  546. check_both_ways("\u2567", "\xCF", 'IBM862') #
  547. check_both_ways("\u2568", "\xD0", 'IBM862') #
  548. check_both_ways("\u2580", "\xDF", 'IBM862') #
  549. check_both_ways("\u03B1", "\xE0", 'IBM862') # α
  550. check_both_ways("\u2229", "\xEF", 'IBM862') #
  551. check_both_ways("\u2261", "\xF0", 'IBM862') #
  552. check_both_ways("\u00A0", "\xFF", 'IBM862') # non-breaking space
  553. end
  554. def test_IBM863
  555. check_both_ways("\u00C7", "\x80", 'IBM863') # Ç
  556. check_both_ways("\u00A7", "\x8F", 'IBM863') # §
  557. check_both_ways("\u00C9", "\x90", 'IBM863') # É
  558. check_both_ways("\u0192", "\x9F", 'IBM863') # ƒ
  559. check_both_ways("\u00A6", "\xA0", 'IBM863') # ¦
  560. check_both_ways("\u00BB", "\xAF", 'IBM863') # »
  561. check_both_ways("\u2591", "\xB0", 'IBM863') #
  562. check_both_ways("\u2510", "\xBF", 'IBM863') #
  563. check_both_ways("\u2514", "\xC0", 'IBM863') #
  564. check_both_ways("\u2567", "\xCF", 'IBM863') #
  565. check_both_ways("\u2568", "\xD0", 'IBM863') #
  566. check_both_ways("\u2580", "\xDF", 'IBM863') #
  567. check_both_ways("\u03B1", "\xE0", 'IBM863') # α
  568. check_both_ways("\u2229", "\xEF", 'IBM863') #
  569. check_both_ways("\u2261", "\xF0", 'IBM863') #
  570. check_both_ways("\u00A0", "\xFF", 'IBM863') # non-breaking space
  571. end
  572. def test_IBM865
  573. check_both_ways("\u00C7", "\x80", 'IBM865') # Ç
  574. check_both_ways("\u00C5", "\x8F", 'IBM865') # Å
  575. check_both_ways("\u00C9", "\x90", 'IBM865') # É
  576. check_both_ways("\u0192", "\x9F", 'IBM865') # ƒ
  577. check_both_ways("\u00E1", "\xA0", 'IBM865') # á
  578. check_both_ways("\u00A4", "\xAF", 'IBM865') # ¤
  579. check_both_ways("\u2591", "\xB0", 'IBM865') #
  580. check_both_ways("\u2510", "\xBF", 'IBM865') #
  581. check_both_ways("\u2514", "\xC0", 'IBM865') #
  582. check_both_ways("\u2567", "\xCF", 'IBM865') #
  583. check_both_ways("\u2568", "\xD0", 'IBM865') #
  584. check_both_ways("\u2580", "\xDF", 'IBM865') #
  585. check_both_ways("\u03B1", "\xE0", 'IBM865') # α
  586. check_both_ways("\u2229", "\xEF", 'IBM865') #
  587. check_both_ways("\u2261", "\xF0", 'IBM865') #
  588. check_both_ways("\u00A0", "\xFF", 'IBM865') # non-breaking space
  589. end
  590. def test_IBM866
  591. check_both_ways("\u0410", "\x80", 'IBM866') # А
  592. check_both_ways("\u041F", "\x8F", 'IBM866') # П
  593. check_both_ways("\u0420", "\x90", 'IBM866') # Р
  594. check_both_ways("\u042F", "\x9F", 'IBM866') # Я
  595. check_both_ways("\u0430", "\xA0", 'IBM866') # а
  596. check_both_ways("\u043F", "\xAF", 'IBM866') # п
  597. check_both_ways("\u2591", "\xB0", 'IBM866') #
  598. check_both_ways("\u2510", "\xBF", 'IBM866') #
  599. check_both_ways("\u2514", "\xC0", 'IBM866') #
  600. check_both_ways("\u2567", "\xCF", 'IBM866') #
  601. check_both_ways("\u2568", "\xD0", 'IBM866') #
  602. check_both_ways("\u2580", "\xDF", 'IBM866') #
  603. check_both_ways("\u0440", "\xE0", 'IBM866') # р
  604. check_both_ways("\u044F", "\xEF", 'IBM866') # я
  605. check_both_ways("\u0401", "\xF0", 'IBM866') # Ё
  606. check_both_ways("\u00A0", "\xFF", 'IBM866') # non-breaking space
  607. end
  608. def test_IBM869
  609. assert_raise(Encoding::UndefinedConversionError) { "\x80".encode("utf-8", 'IBM869') }
  610. assert_raise(Encoding::UndefinedConversionError) { "\x85".encode("utf-8", 'IBM869') }
  611. check_both_ways("\u0386", "\x86", 'IBM869') # Ά
  612. assert_raise(Encoding::UndefinedConversionError) { "\x87".encode("utf-8", 'IBM869') }
  613. check_both_ways("\u00B7", "\x88", 'IBM869') # ·
  614. check_both_ways("\u0389", "\x8F", 'IBM869') # Ή
  615. check_both_ways("\u038A", "\x90", 'IBM869') # Ί
  616. check_both_ways("\u038C", "\x92", 'IBM869') # Ό
  617. assert_raise(Encoding::UndefinedConversionError) { "\x93".encode("utf-8", 'IBM869') }
  618. assert_raise(Encoding::UndefinedConversionError) { "\x94".encode("utf-8", 'IBM869') }
  619. check_both_ways("\u038E", "\x95", 'IBM869') # Ύ
  620. check_both_ways("\u03AF", "\x9F", 'IBM869') # ί
  621. check_both_ways("\u03CA", "\xA0", 'IBM869') # ϊ
  622. check_both_ways("\u00BB", "\xAF", 'IBM869') # »
  623. check_both_ways("\u2591", "\xB0", 'IBM869') #
  624. check_both_ways("\u2510", "\xBF", 'IBM869') #
  625. check_both_ways("\u2514", "\xC0", 'IBM869') #
  626. check_both_ways("\u03A3", "\xCF", 'IBM869') # Σ
  627. check_both_ways("\u03A4", "\xD0", 'IBM869') # Τ
  628. check_both_ways("\u2580", "\xDF", 'IBM869') #
  629. check_both_ways("\u03B6", "\xE0", 'IBM869') # ζ
  630. check_both_ways("\u0384", "\xEF", 'IBM869') # ΄
  631. check_both_ways("\u00AD", "\xF0", 'IBM869') # soft hyphen
  632. check_both_ways("\u00A0", "\xFF", 'IBM869') # non-breaking space
  633. end
  634. def test_macCroatian
  635. check_both_ways("\u00C4", "\x80", 'macCroatian') # Ä
  636. check_both_ways("\u00E8", "\x8F", 'macCroatian') # è
  637. check_both_ways("\u00EA", "\x90", 'macCroatian') # ê
  638. check_both_ways("\u00FC", "\x9F", 'macCroatian') # ü
  639. check_both_ways("\u2020", "\xA0", 'macCroatian') #
  640. check_both_ways("\u00D8", "\xAF", 'macCroatian') # Ø
  641. check_both_ways("\u221E", "\xB0", 'macCroatian') #
  642. check_both_ways("\u00F8", "\xBF", 'macCroatian') # ø
  643. check_both_ways("\u00BF", "\xC0", 'macCroatian') # ¿
  644. check_both_ways("\u0153", "\xCF", 'macCroatian') # œ
  645. check_both_ways("\u0110", "\xD0", 'macCroatian') # Đ
  646. check_both_ways("\u00A9", "\xD9", 'macCroatian') # ©
  647. check_both_ways("\u2044", "\xDA", 'macCroatian') #
  648. check_both_ways("\u203A", "\xDD", 'macCroatian') #
  649. check_both_ways("\u00C6", "\xDE", 'macCroatian') # Æ
  650. check_both_ways("\u00BB", "\xDF", 'macCroatian') # »
  651. check_both_ways("\u2013", "\xE0", 'macCroatian') #
  652. check_both_ways("\u00B7", "\xE1", 'macCroatian') # ·
  653. check_both_ways("\u00C2", "\xE5", 'macCroatian') # Â
  654. check_both_ways("\u0107", "\xE6", 'macCroatian') # ć
  655. check_both_ways("\u00C1", "\xE7", 'macCroatian') # Á
  656. check_both_ways("\u010D", "\xE8", 'macCroatian') # č
  657. check_both_ways("\u00C8", "\xE9", 'macCroatian') # È
  658. check_both_ways("\u00D4", "\xEF", 'macCroatian') # Ô
  659. check_both_ways("\u0111", "\xF0", 'macCroatian') # đ
  660. check_both_ways("\u00D2", "\xF1", 'macCroatian') # Ò
  661. check_both_ways("\u00AF", "\xF8", 'macCroatian') # ¯
  662. check_both_ways("\u03C0", "\xF9", 'macCroatian') # π
  663. check_both_ways("\u00CB", "\xFA", 'macCroatian') # Ë
  664. check_both_ways("\u00CA", "\xFD", 'macCroatian') # Ê
  665. check_both_ways("\u00E6", "\xFE", 'macCroatian') # æ
  666. check_both_ways("\u02C7", "\xFF", 'macCroatian') # ˇ
  667. end
  668. def test_macCyrillic
  669. check_both_ways("\u0410", "\x80", 'macCyrillic') # А
  670. check_both_ways("\u041F", "\x8F", 'macCyrillic') # П
  671. check_both_ways("\u0420", "\x90", 'macCyrillic') # Р
  672. check_both_ways("\u042F", "\x9F", 'macCyrillic') # Я
  673. check_both_ways("\u2020", "\xA0", 'macCyrillic') #
  674. check_both_ways("\u0453", "\xAF", 'macCyrillic') # ѓ
  675. check_both_ways("\u221E", "\xB0", 'macCyrillic') #
  676. check_both_ways("\u045A", "\xBF", 'macCyrillic') # њ
  677. check_both_ways("\u0458", "\xC0", 'macCyrillic') # ј
  678. check_both_ways("\u0455", "\xCF", 'macCyrillic') # ѕ
  679. check_both_ways("\u2013", "\xD0", 'macCyrillic') #
  680. check_both_ways("\u044F", "\xDF", 'macCyrillic') # я
  681. check_both_ways("\u0430", "\xE0", 'macCyrillic') # а
  682. check_both_ways("\u043F", "\xEF", 'macCyrillic') # п
  683. check_both_ways("\u0440", "\xF0", 'macCyrillic') # р
  684. check_both_ways("\u00A4", "\xFF", 'macCyrillic') # ¤
  685. end
  686. def test_macGreek
  687. check_both_ways("\u00C4", "\x80", 'macGreek') # Ä
  688. check_both_ways("\u00E8", "\x8F", 'macGreek') # è
  689. check_both_ways("\u00EA", "\x90", 'macGreek') # ê
  690. check_both_ways("\u00FC", "\x9F", 'macGreek') # ü
  691. check_both_ways("\u2020", "\xA0", 'macGreek') #
  692. check_both_ways("\u0393", "\xA1", 'macGreek') # Γ
  693. check_both_ways("\u0387", "\xAF", 'macGreek') # ·
  694. check_both_ways("\u0391", "\xB0", 'macGreek') # Α
  695. check_both_ways("\u03A9", "\xBF", 'macGreek') # Ω
  696. check_both_ways("\u03AC", "\xC0", 'macGreek') # ά
  697. check_both_ways("\u0153", "\xCF", 'macGreek') # œ
  698. check_both_ways("\u2013", "\xD0", 'macGreek') #
  699. check_both_ways("\u038F", "\xDF", 'macGreek') # Ώ
  700. check_both_ways("\u03CD", "\xE0", 'macGreek') # ύ
  701. check_both_ways("\u03BF", "\xEF", 'macGreek') # ο
  702. check_both_ways("\u03C0", "\xF0", 'macGreek') # π
  703. check_both_ways("\u03B0", "\xFE", 'macGreek') # ΰ
  704. assert_raise(Encoding::UndefinedConversionError) { "\xFF".encode("utf-8", 'macGreek') }
  705. end
  706. def test_macIceland
  707. check_both_ways("\u00C4", "\x80", 'macIceland') # Ä
  708. check_both_ways("\u00E8", "\x8F", 'macIceland') # è
  709. check_both_ways("\u00EA", "\x90", 'macIceland') # ê
  710. check_both_ways("\u00FC", "\x9F", 'macIceland') # ü
  711. check_both_ways("\u00DD", "\xA0", 'macIceland') # Ý
  712. check_both_ways("\u00D8", "\xAF", 'macIceland') # Ø
  713. check_both_ways("\u221E", "\xB0", 'macIceland') #
  714. check_both_ways("\u00F8", "\xBF", 'macIceland') # ø
  715. check_both_ways("\u00BF", "\xC0", 'macIceland') # ¿
  716. check_both_ways("\u0153", "\xCF", 'macIceland') # œ
  717. check_both_ways("\u2013", "\xD0", 'macIceland') #
  718. check_both_ways("\u00FE", "\xDF", 'macIceland') # þ
  719. check_both_ways("\u00FD", "\xE0", 'macIceland') # ý
  720. check_both_ways("\u00D4", "\xEF", 'macIceland') # Ô
  721. #check_both_ways("\uF8FF", "\xF0", 'macIceland') # Apple logo
  722. check_both_ways("\u02C7", "\xFF", 'macIceland') # ˇ
  723. end
  724. def test_macRoman
  725. check_both_ways("\u00C4", "\x80", 'macRoman') # Ä
  726. check_both_ways("\u00E8", "\x8F", 'macRoman') # è
  727. check_both_ways("\u00EA", "\x90", 'macRoman') # ê
  728. check_both_ways("\u00FC", "\x9F", 'macRoman') # ü
  729. check_both_ways("\u2020", "\xA0", 'macRoman') #
  730. #check_both_ways("\u00DB", "\xAF", 'macRoman') # Ø
  731. check_both_ways("\u221E", "\xB0", 'macRoman') #
  732. check_both_ways("\u00F8", "\xBF", 'macRoman') # ø
  733. check_both_ways("\u00BF", "\xC0", 'macRoman') # ¿
  734. check_both_ways("\u0153", "\xCF", 'macRoman') # œ
  735. check_both_ways("\u2013", "\xD0", 'macRoman') #
  736. check_both_ways("\u00A4", "\xDB", 'macRoman') # ¤
  737. check_both_ways("\uFB02", "\xDF", 'macRoman') #
  738. check_both_ways("\u2021", "\xE0", 'macRoman') #
  739. check_both_ways("\u00D4", "\xEF", 'macRoman') # Ô
  740. #check_both_ways("\uF8FF", "\xF0", 'macRoman') # Apple logo
  741. check_both_ways("\u02C7", "\xFF", 'macRoman') # ˇ
  742. end
  743. def test_macRomania
  744. check_both_ways("\u00C4", "\x80", 'macRomania') # Ä
  745. check_both_ways("\u00E8", "\x8F", 'macRomania') # è
  746. check_both_ways("\u00EA", "\x90", 'macRomania') # ê
  747. check_both_ways("\u00FC", "\x9F", 'macRomania') # ü
  748. check_both_ways("\u2020", "\xA0", 'macRomania') #
  749. check_both_ways("\u015E", "\xAF", 'macRomania') # Ş
  750. check_both_ways("\u221E", "\xB0", 'macRomania') #
  751. check_both_ways("\u015F", "\xBF", 'macRomania') # ş
  752. check_both_ways("\u00BF", "\xC0", 'macRomania') # ¿
  753. check_both_ways("\u0153", "\xCF", 'macRomania') # œ
  754. check_both_ways("\u2013", "\xD0", 'macRomania') #
  755. check_both_ways("\u00A4", "\xDB", 'macRomania') #
  756. check_both_ways("\u0163", "\xDF", 'macRomania') # ţ
  757. check_both_ways("\u2021", "\xE0", 'macRomania') #
  758. check_both_ways("\u00D4", "\xEF", 'macRomania') # Ô
  759. #check_both_ways("\uF8FF", "\xF0", 'macRomania') # Apple logo
  760. check_both_ways("\u02C7", "\xFF", 'macRomania') # ˇ
  761. end
  762. def test_macTurkish
  763. check_both_ways("\u00C4", "\x80", 'macTurkish') # Ä
  764. check_both_ways("\u00E8", "\x8F", 'macTurkish') # è
  765. check_both_ways("\u00EA", "\x90", 'macTurkish') # ê
  766. check_both_ways("\u00FC", "\x9F", 'macTurkish') # ü
  767. check_both_ways("\u2020", "\xA0", 'macTurkish') #
  768. check_both_ways("\u00D8", "\xAF", 'macTurkish') # Ø
  769. check_both_ways("\u221E", "\xB0", 'macTurkish') #
  770. check_both_ways("\u00F8", "\xBF", 'macTurkish') # ø
  771. check_both_ways("\u00BF", "\xC0", 'macTurkish') # ¿
  772. check_both_ways("\u0153", "\xCF", 'macTurkish') # œ
  773. check_both_ways("\u2013", "\xD0", 'macTurkish') #
  774. check_both_ways("\u015F", "\xDF", 'macTurkish') # ş
  775. check_both_ways("\u2021", "\xE0", 'macTurkish') #
  776. check_both_ways("\u00D4", "\xEF", 'macTurkish') # Ô
  777. #check_both_ways("\uF8FF", "\xF0", 'macTurkish') # Apple logo
  778. check_both_ways("\u00D9", "\xF4", 'macTurkish') # Ù
  779. assert_raise(Encoding::UndefinedConversionError) { "\xF5".encode("utf-8", 'macTurkish') }
  780. check_both_ways("\u02C6", "\xF6", 'macTurkish') # ˆ
  781. check_both_ways("\u02C7", "\xFF", 'macTurkish') # ˇ
  782. end
  783. def test_macUkraine
  784. check_both_ways("\u0410", "\x80", 'macUkraine') # А
  785. check_both_ways("\u041F", "\x8F", 'macUkraine') # П
  786. check_both_ways("\u0420", "\x90", 'macUkraine') # Р
  787. check_both_ways("\u042F", "\x9F", 'macUkraine') # Я
  788. check_both_ways("\u2020", "\xA0", 'macUkraine') #
  789. check_both_ways("\u0453", "\xAF", 'macUkraine') # ѓ
  790. check_both_ways("\u221E", "\xB0", 'macUkraine') #
  791. check_both_ways("\u045A", "\xBF", 'macUkraine') # њ
  792. check_both_ways("\u0458", "\xC0", 'macUkraine') # ј
  793. check_both_ways("\u0455", "\xCF", 'macUkraine') # ѕ
  794. check_both_ways("\u2013", "\xD0", 'macUkraine') #
  795. check_both_ways("\u044F", "\xDF", 'macUkraine') # я
  796. check_both_ways("\u0430", "\xE0", 'macUkraine') # а
  797. check_both_ways("\u043F", "\xEF", 'macUkraine') # п
  798. check_both_ways("\u0440", "\xF0", 'macUkraine') # р
  799. check_both_ways("\u00A4", "\xFF", 'macUkraine') # ¤
  800. end
  801. def test_koi8_u
  802. check_both_ways("\u2500", "\x80", 'KOI8-U') #
  803. check_both_ways("\u2590", "\x8F", 'KOI8-U') #
  804. check_both_ways("\u2591", "\x90", 'KOI8-U') #
  805. check_both_ways("\u00F7", "\x9F", 'KOI8-U') # ÷
  806. check_both_ways("\u2550", "\xA0", 'KOI8-U') #
  807. check_both_ways("\u0454", "\xA4", 'KOI8-U') # є
  808. check_both_ways("\u0456", "\xA6", 'KOI8-U') # і
  809. check_both_ways("\u0457", "\xA7", 'KOI8-U') # ї
  810. check_both_ways("\u0491", "\xAD", 'KOI8-U') # ґ
  811. check_both_ways("\u255E", "\xAF", 'KOI8-U') #
  812. check_both_ways("\u255F", "\xB0", 'KOI8-U') #
  813. check_both_ways("\u0404", "\xB4", 'KOI8-U') # Є
  814. check_both_ways("\u0406", "\xB6", 'KOI8-U') # І
  815. check_both_ways("\u0407", "\xB7", 'KOI8-U') # Ї
  816. check_both_ways("\u0490", "\xBD", 'KOI8-U') # Ґ
  817. check_both_ways("\u00A9", "\xBF", 'KOI8-U') # ©
  818. check_both_ways("\u044E", "\xC0", 'KOI8-U') # ю
  819. check_both_ways("\u043E", "\xCF", 'KOI8-U') # о
  820. check_both_ways("\u043F", "\xD0", 'KOI8-U') # п
  821. check_both_ways("\u044A", "\xDF", 'KOI8-U') # ъ
  822. check_both_ways("\u042E", "\xE0", 'KOI8-U') # Ю
  823. check_both_ways("\u041E", "\xEF", 'KOI8-U') # О
  824. check_both_ways("\u041F", "\xF0", 'KOI8-U') # П
  825. check_both_ways("\u042A", "\xFF", 'KOI8-U') # Ъ
  826. end
  827. def test_koi8_r
  828. check_both_ways("\u2500", "\x80", 'KOI8-R') #
  829. check_both_ways("\u2590", "\x8F", 'KOI8-R') #
  830. check_both_ways("\u2591", "\x90", 'KOI8-R') #
  831. check_both_ways("\u00F7", "\x9F", 'KOI8-R') # ÷
  832. check_both_ways("\u2550", "\xA0", 'KOI8-R') #
  833. check_both_ways("\u255E", "\xAF", 'KOI8-R') #
  834. check_both_ways("\u255F", "\xB0", 'KOI8-R') #
  835. check_both_ways("\u00A9", "\xBF", 'KOI8-R') # ©
  836. check_both_ways("\u044E", "\xC0", 'KOI8-R') # ю
  837. check_both_ways("\u043E", "\xCF", 'KOI8-R') # о
  838. check_both_ways("\u043F", "\xD0", 'KOI8-R') # п
  839. check_both_ways("\u044A", "\xDF", 'KOI8-R') # ъ
  840. check_both_ways("\u042E", "\xE0", 'KOI8-R') # Ю
  841. check_both_ways("\u041E", "\xEF", 'KOI8-R') # О
  842. check_both_ways("\u041F", "\xF0", 'KOI8-R') # П
  843. check_both_ways("\u042A", "\xFF", 'KOI8-R') # Ъ
  844. end
  845. def test_TIS_620
  846. assert_raise(Encoding::UndefinedConversionError) { "\x80".encode("utf-8", 'TIS-620') }
  847. assert_raise(Encoding::UndefinedConversionError) { "\x8F".encode("utf-8", 'TIS-620') }
  848. assert_raise(Encoding::UndefinedConversionError) { "\x90".encode("utf-8", 'TIS-620') }
  849. assert_raise(Encoding::UndefinedConversionError) { "\x9F".encode("utf-8", 'TIS-620') }
  850. assert_raise(Encoding::UndefinedConversionError) { "\xA0".encode("utf-8", 'TIS-620') }
  851. check_both_ways("\u0E01", "\xA1", 'TIS-620') #
  852. check_both_ways("\u0E0F", "\xAF", 'TIS-620') #
  853. check_both_ways("\u0E10", "\xB0", 'TIS-620') #
  854. check_both_ways("\u0E1F", "\xBF", 'TIS-620') #
  855. check_both_ways("\u0E20", "\xC0", 'TIS-620') #
  856. check_both_ways("\u0E2F", "\xCF", 'TIS-620') #
  857. check_both_ways("\u0E30", "\xD0", 'TIS-620') #
  858. check_both_ways("\u0E3A", "\xDA", 'TIS-620') #
  859. assert_raise(Encoding::UndefinedConversionError) { "\xDB".encode("utf-8", 'TIS-620') }
  860. assert_raise(Encoding::UndefinedConversionError) { "\xDE".encode("utf-8", 'TIS-620') }
  861. check_both_ways("\u0E3F", "\xDF", 'TIS-620') # ฿
  862. check_both_ways("\u0E40", "\xE0", 'TIS-620') #
  863. check_both_ways("\u0E4F", "\xEF", 'TIS-620') #
  864. check_both_ways("\u0E50", "\xF0", 'TIS-620') #
  865. check_both_ways("\u0E5B", "\xFB", 'TIS-620') #
  866. assert_raise(Encoding::UndefinedConversionError) { "\xFC".encode("utf-8", 'TIS-620') }
  867. assert_raise(Encoding::UndefinedConversionError) { "\xFF".encode("utf-8", 'TIS-620') }
  868. end
  869. def test_CP850
  870. check_both_ways("\u00C7", "\x80", 'CP850') # Ç
  871. check_both_ways("\u00C5