n.c.
[chise/ruby.git] / test / test-parser.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 require "common"
5
6 class TestParser < Test::Unit::TestCase
7   def setup
8     @pa = CHISE::CharacterParser.new
9   end
10
11   def test_parse
12     assert_raise(RuntimeError){ @pa.parse(nil) }
13     assert_equal(65, @pa.parse(0x41))
14     assert_raise(RuntimeError){ @pa.parse(Object.new) }
15     assert_equal(65, @pa.parse("65"))
16     assert_equal(20175, @pa.parse("?\344\273\217"))
17     assert_raise(RuntimeError){ @pa.parse("nosuchcharacter") }
18     assert_raise(RuntimeError){ @pa.parse("\344\273\217") }
19   end
20
21   def test_parse_er
22     assert_equal(true, @pa.contain_er?("&#x41;"))
23     assert_equal(true, @pa.contain_er?("This is &#x41; er."))
24     assert_equal(true, @pa.is_er?("&#x41;"))
25     assert_equal(false, @pa.is_er?("This is &#x41; er."))
26     assert_equal(0xe001, @pa.parse("&my-1;"))
27     assert_raise(RuntimeError){ @pa.parse_er("&nosucher;") }
28     assert_raise(RuntimeError){ @pa.parse_er("nosucher") }
29
30     assert_equal(23383, @pa.parse("&MCS-00005B57;"))
31     assert_equal(23383, @pa.parse("&U5B57;"))
32     assert_equal(23383, @pa.parse("&U-5B57;"))
33     assert_equal(23383, @pa.parse("&U+5B57;"))
34     assert_equal(23383, @pa.parse("&#x5B57;"))
35     assert_equal(23383, @pa.parse("&#23383;"))
36   end
37
38   def test_parse_ccs
39     assert_equal(23383, @pa.parse("&J90-3B7A;"))
40     assert_equal(23383, @pa.parse("&I-J90-3B7A;"))
41     assert_equal(23383, @pa.parse("&MCS-00005B57;"))
42     assert_equal(23383, @pa.parse("&M-06942;"))
43   end
44
45   def test_comples_ccs
46     assert_equal(28193, @pa.parse("&C1-602E;")) # 渡
47     assert_equal(15542221, @pa.parse("&C1-6030;")) # unknown
48
49     # test_ccs_etc
50     assert_equal(131636, @pa.parse("&HZK01-C947;")) # =hanziku-1
51     assert_equal(1644203214, @pa.parse("&CDP-8CCE;")) # CDP
52     assert_equal(1644202927, @pa.parse("&CDP-8BAF;"))
53     assert_equal(1644210346, @pa.parse("&B-A8AA;")) # =big5
54     assert_equal(1644202869, @pa.parse("&RUI6-E00E;")) # =ruimoku-v6
55     assert_equal(15225021, @pa.parse("&JC3-50BD;")) # =jef-china3
56     assert_equal(1644202692, @pa.parse("&CB00008;"))
57     assert_equal(14820071, @pa.parse("&CB08935;"))
58     #assert_equal(0, @pa.parse("&CB08661;")) # what?
59   end
60
61   def test_de_er
62     @pa = CHISE::EntityReferenceParser.new
63     assert_equal("This is A.", @pa.de_er("This is &#x41;."))
64     assert_equal("A\345\255\227B", @pa.de_er("A&U5B57;B"))
65     assert_equal("A\345\255\227B", @pa.de_er("A&J90-3B7A;B"))
66 #    assert_equal("A\345\255\227B", @pa.de_er("&CB00002;"))
67   end
68 end