class TestUtilCharset

Public Instance Methods

test_bug() click to toggle source
# File vendor/qwik/lib/qwik/util-charset.rb, line 323
def test_bug
  # $KCODE = 'u'
  assert_equal "~", "~".to_utf8
  assert_equal "\342\200\276", "~".set_sjis.to_utf8 # annoying...
  #assert_equal "\343\200\234", "~".to_utf8
  #assert_equal "\343\200\234", "~".set_sjis.to_utf8
end
test_charset() click to toggle source
# File vendor/qwik/lib/qwik/util-charset.rb, line 303
    def test_charset
      s = "\202\240"
      assert_equal nil, s.charset
      assert_equal "\202\240", s.set_charset('Shift_JIS')
      assert_equal 'Shift_JIS', s.charset

      # test_guess
      assert_equal 'UTF-8', "\343\201\202".guess_charset
      assert_equal 'Shift_JIS', "\202\240".guess_charset        # あ
#      assert_equal 'EUC-JP', "\244\242".guess_charset
      assert_equal 'ISO-2022-JP', "\e$B$\"\e(B".guess_charset

      # test_to
      s = "\202\240".set_sjis
      assert_equal "\343\201\202", s.to_utf8
      assert_equal "\202\240", s.to_sjis
      assert_equal "\244\242", s.to_euc
      assert_equal "\e$B$\"\e(B", s.to_jis
    end
test_iconv() click to toggle source
# File vendor/qwik/lib/qwik/util-charset.rb, line 253
def test_iconv
  assert_equal '字', '字'.sjistou8.u8tosjis
  assert_equal '字', '字'.sjistoeuc.euctou8.u8toeuc.euctosjis
  assert_equal '字', '字'.sjistojis.jistou8.u8tojis.jistosjis

  # test_sjistou8
  assert_equal "\343\201\202", 'あ'.sjistou8
  assert_equal 'UTF-8', 'あ'.sjistou8.charset

  assert_equal "\342\200\276", '~'.sjistou8

  # test_u8tosjis
  assert_equal "\202\240", "\343\201\202".u8tosjis
  assert_equal 'Shift_JIS', "\343\201\202".u8tosjis.charset

  # test_sjistoeuc
  assert_equal "\244\242", 'あ'.sjistoeuc
  assert_equal 'EUC-JP', 'あ'.sjistoeuc.charset

  # test_euctou8
  assert_equal "\343\201\202", "\244\242".euctou8
  assert_equal 'UTF-8', "\244\242".euctou8.charset

  # test_u8toeuc
  assert_equal "\244\242", "\343\201\202".u8toeuc
  assert_equal 'EUC-JP', "\343\201\202".u8toeuc.charset

  # test_sjistojis
  assert_equal "\e$B$\"\e(B", "あ".sjistojis
  assert_equal 'ISO-2022-JP', "あ".sjistojis.charset

  # test_jistou8
  assert_equal "\343\201\202", "\e$B$\"\e(B".jistou8
  assert_equal 'UTF-8', "\e$B$\"\e(B".jistou8.charset

  # test_u8tojis
  assert_equal "\e$B$\"\e(B", "\343\201\202".u8tojis
  assert_equal 'ISO-2022-JP', "\343\201\202".u8tojis.charset

  # test_illegal_sequence
  # last \202 is illegal
  assert_equal "\202\240?", "\343\201\202\202".u8tosjis
  # first \202 is illegal
  assert_equal "?\202\240", "\202\343\201\202".u8tosjis

  # test_annoying_character
  assert_equal "\343\200\234", '~'.sjistou8
  assert_equal '~', "\343\200\234".u8tosjis
end
test_kconv() click to toggle source
# File vendor/qwik/lib/qwik/util-charset.rb, line 224
def test_kconv
  # test_sjistoeuc
  assert_equal "\244\242", 'あ'.sjistoeuc
  assert_equal 'EUC-JP', 'あ'.sjistoeuc.charset

  # test_euctosjis
  assert_equal 'あ', "\244\242".euctosjis
  assert_equal 'Shift_JIS', "\244\242".euctosjis.charset

  # test_sjistojis
  assert_equal "\e$B$\"\e(B", 'あ'.sjistojis
  assert_equal 'ISO-2022-JP', 'あ'.sjistojis.charset

  # test_jistosjis
  assert_equal 'あ', "\e$B$\"\e(B".jistosjis
  assert_equal 'Shift_JIS', "\e$B$\"\e(B".jistosjis.charset

  # test_euctojis
  assert_equal "\e$B$\"\e(B", "\244\242".euctojis
  assert_equal 'ISO-2022-JP', "\244\242".euctojis.charset

  # test_jistoeuc
  assert_equal "\244\242", "\e$B$\"\e(B".jistoeuc
  assert_equal 'EUC-JP', "\e$B$\"\e(B".jistoeuc.charset

  # test_some_characters
  assert_equal "\e$B4A;z\e(B", '漢字'.sjistojis
end