PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/test/ruby/test_transcode.rb

http://github.com/ruby/ruby
Ruby | 2268 lines | 2145 code | 89 blank | 34 comment | 0 complexity | c15189a37de3cb325d5f3b99c587bec2 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file