summaryrefslogtreecommitdiff
path: root/jni/ruby/tool/test/test_jisx0208.rb
blob: d323c84745bf70cdf683c84f0cbe090b97a7142b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'test/unit'

require '../tool/jisx0208'

class Test_JISX0208_Char < Test::Unit::TestCase
  def test_create_with_row_cell
    assert_equal JISX0208::Char.new(0x2121), JISX0208::Char.new(1, 1)
  end

  def test_succ
    assert_equal JISX0208::Char.new(0x2221), JISX0208::Char.new(0x217e).succ
    assert_equal JISX0208::Char.new(2, 1), JISX0208::Char.new(1, 94).succ
    assert_equal JISX0208::Char.new(0x7f21), JISX0208::Char.new(0x7e7e).succ
  end

  def test_to_shift_jis
    assert_equal 0x895C, JISX0208::Char.new(0x313D).to_sjis
    assert_equal 0x895C, JISX0208::Char.from_sjis(0x895C).to_sjis
    assert_equal 0xF3DE, JISX0208::Char.from_sjis(0xF3DE).to_sjis
    assert_equal 0xFC40, JISX0208::Char.from_sjis(0xFC40).to_sjis
  end

  def test_from_sjis
    assert_raise(ArgumentError) { JISX0208::Char.from_sjis(-1) }
    assert_raise(ArgumentError) { JISX0208::Char.from_sjis(0x10000) }
    assert_nothing_raised { JISX0208::Char.from_sjis(0x8140) }
    assert_nothing_raised { JISX0208::Char.from_sjis(0xFCFC) }
    assert_equal JISX0208::Char.new(0x313D), JISX0208::Char.from_sjis(0x895C)
  end

  def test_row
    assert_equal 1, JISX0208::Char.new(0x2121).row
    assert_equal 94, JISX0208::Char.new(0x7E7E).row
  end

  def test_cell
    assert_equal 1, JISX0208::Char.new(0x2121).cell
    assert_equal 94, JISX0208::Char.new(0x7E7E).cell
  end
end