3a29516d578fa5b1712c12b4e2c195626cc3b6c9
[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 test_parser
8     @pa = CHISE::CharacterParser.new
9
10     # test_parse
11     assert_raise(RuntimeError){ @pa.parse(nil) }
12     assert_equal(65, @pa.parse(0x41))
13     assert_raise(RuntimeError){ @pa.parse(Object.new) }
14     assert_equal(65, @pa.parse("65"))
15     assert_equal(20175, @pa.parse("?\344\273\217"))
16     assert_raise(RuntimeError){ @pa.parse("nosuchcharacter") }
17     assert_raise(RuntimeError){ @pa.parse("\344\273\217") }
18
19     # test_parse_er
20     assert_equal(true, @pa.contain_er?("&#x41;"))
21     assert_equal(true, @pa.contain_er?("This is &#x41; er."))
22     assert_equal(true, @pa.is_er?("&#x41;"))
23     assert_equal(false, @pa.is_er?("This is &#x41; er."))
24     assert_raise(RuntimeError){ @pa.parse_er("nosucher") }
25     assert_equal(0xe001, @pa.parse("&my-1;"))
26
27     assert_equal(23383, @pa.parse("&MCS-00005B57;"))
28     assert_equal(23383, @pa.parse("&U5B57;"))
29     assert_equal(23383, @pa.parse("&U-5B57;"))
30     assert_equal(23383, @pa.parse("&U+5B57;"))
31     assert_equal(23383, @pa.parse("&#x5B57;"))
32     assert_equal(23383, @pa.parse("&#23383;"))
33
34     # test_get_ccs
35     assert_equal(23383, @pa.parse("&J90-3B7A;"))
36     assert_equal(23383, @pa.parse("&I-J90-3B7A;"))
37     assert_equal(23383, @pa.parse("&MCS-00005B57;"))
38     assert_equal(23383, @pa.parse("&M-06942;"))
39     assert_raise(RuntimeError){ @pa.parse_er("&nosucher;") }
40
41     assert_equal(28193, @pa.parse("&C1-602E;")) # 渡
42     assert_equal(15542221, @pa.parse("&C1-6030;")) # unknown
43   end
44
45   def test_de_er
46     @pa = CHISE::EntityReferenceParser.new
47     assert_equal("This is A.", @pa.de_er("This is &#x41;."))
48     assert_equal("A\345\255\227B", @pa.de_er("A&U5B57;B"))
49     assert_equal("A\345\255\227B", @pa.de_er("A&J90-3B7A;B"))
50 #    assert_equal("A\345\255\227B", @pa.de_er("&CB00002;"))
51   end
52 end