summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rexml/parser/test_ultra_light.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/rexml/parser/test_ultra_light.rb
Fresh start
Diffstat (limited to 'jni/ruby/test/rexml/parser/test_ultra_light.rb')
-rw-r--r--jni/ruby/test/rexml/parser/test_ultra_light.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/jni/ruby/test/rexml/parser/test_ultra_light.rb b/jni/ruby/test/rexml/parser/test_ultra_light.rb
new file mode 100644
index 0000000..4960fc1
--- /dev/null
+++ b/jni/ruby/test/rexml/parser/test_ultra_light.rb
@@ -0,0 +1,69 @@
+require "test/unit"
+require "rexml/parsers/ultralightparser"
+
+module REXMLTests
+class TestUltraLightParser < Test::Unit::TestCase
+ class TestDocumentTypeDeclaration < self
+ def test_entity_declaration
+ assert_equal([
+ [
+ :start_doctype,
+ :parent,
+ "root",
+ "SYSTEM",
+ "urn:x-test",
+ nil,
+ [:entitydecl, "name", "value"]
+ ],
+ [:text, "\n"],
+ [:start_element, :parent, "root", {}],
+ [:text, "\n"],
+ ],
+ parse(<<-INTERNAL_SUBSET))
+<!ENTITY name "value">
+ INTERNAL_SUBSET
+ end
+
+ private
+ def xml(internal_subset)
+ <<-XML
+<!DOCTYPE root SYSTEM "urn:x-test" [
+#{internal_subset}
+]>
+<root/>
+ XML
+ end
+
+ def parse(internal_subset)
+ parser = REXML::Parsers::UltraLightParser.new(xml(internal_subset))
+ normalize(parser.parse)
+ end
+
+ def normalize(root)
+ root.collect do |child|
+ normalize_child(child)
+ end
+ end
+
+ def normalize_child(child)
+ tag = child.first
+ case tag
+ when :start_doctype
+ normalized_parent = :parent
+ normalized_doctype = child.dup
+ normalized_doctype[1] = normalized_parent
+ normalized_doctype
+ when :start_element
+ tag, parent, name, attributes, *children = child
+ normalized_parent = :parent
+ normalized_children = children.collect do |sub_child|
+ normalize_child(sub_child)
+ end
+ [tag, normalized_parent, name, attributes, *normalized_children]
+ else
+ child
+ end
+ end
+ end
+end
+end