n.c.
[chise/ruby.git] / test / test-parser.rb
index 54c1211..3a29516 100755 (executable)
@@ -14,6 +14,7 @@ class TestParser < Test::Unit::TestCase
     assert_equal(65, @pa.parse("65"))
     assert_equal(20175, @pa.parse("?\344\273\217"))
     assert_raise(RuntimeError){ @pa.parse("nosuchcharacter") }
+    assert_raise(RuntimeError){ @pa.parse("\344\273\217") }
 
     # test_parse_er
     assert_equal(true, @pa.contain_er?("&#x41;"))
@@ -21,15 +22,31 @@ class TestParser < Test::Unit::TestCase
     assert_equal(true, @pa.is_er?("&#x41;"))
     assert_equal(false, @pa.is_er?("This is &#x41; er."))
     assert_raise(RuntimeError){ @pa.parse_er("nosucher") }
-    assert_equal(65, @pa.parse("&MCS-00000041;"))
-    assert_equal(65, @pa.parse("&U-0041;"))
-    assert_equal(65, @pa.parse("&U+0041;"))
-    assert_equal(65, @pa.parse("&#x0041;"))
-    assert_equal(65, @pa.parse("&#x41;"))
-    assert_equal(65, @pa.parse("&#65;"))
     assert_equal(0xe001, @pa.parse("&my-1;"))
-#    assert_equal(23383, @pa.parse("&J90-3B7A;"))
-#    assert_equal(23383, @pa.parse("&I-J90-3B7A;"))
-#   assert_raise(RuntimeError){ @pa.parse_er("&nosucher;") }
+
+    assert_equal(23383, @pa.parse("&MCS-00005B57;"))
+    assert_equal(23383, @pa.parse("&U5B57;"))
+    assert_equal(23383, @pa.parse("&U-5B57;"))
+    assert_equal(23383, @pa.parse("&U+5B57;"))
+    assert_equal(23383, @pa.parse("&#x5B57;"))
+    assert_equal(23383, @pa.parse("&#23383;"))
+
+    # test_get_ccs
+    assert_equal(23383, @pa.parse("&J90-3B7A;"))
+    assert_equal(23383, @pa.parse("&I-J90-3B7A;"))
+    assert_equal(23383, @pa.parse("&MCS-00005B57;"))
+    assert_equal(23383, @pa.parse("&M-06942;"))
+    assert_raise(RuntimeError){ @pa.parse_er("&nosucher;") }
+
+    assert_equal(28193, @pa.parse("&C1-602E;")) # 渡
+    assert_equal(15542221, @pa.parse("&C1-6030;")) # unknown
+  end
+
+  def test_de_er
+    @pa = CHISE::EntityReferenceParser.new
+    assert_equal("This is A.", @pa.de_er("This is &#x41;."))
+    assert_equal("A\345\255\227B", @pa.de_er("A&U5B57;B"))
+    assert_equal("A\345\255\227B", @pa.de_er("A&J90-3B7A;B"))
+#    assert_equal("A\345\255\227B", @pa.de_er("&CB00002;"))
   end
 end