From 0d1abb904e9eda11dfed19181553725764a3d950 Mon Sep 17 00:00:00 2001 From: kou Date: Thu, 20 Dec 2018 02:49:10 +0000 Subject: rexml: upgrade to 3.1.8 See https://github.com/ruby/rexml/blob/master/NEWS.md for change summary. Changes for spec/ has been reported: https://github.com/ruby/spec/pull/639 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rexml/data/t75.xml | 2 +- test/rexml/formatter/test_default.rb | 19 ++++ test/rexml/parse/test_element.rb | 38 +++++++ test/rexml/parse/test_processing_instruction.rb | 25 +++++ test/rexml/parser/test_tree.rb | 2 +- test/rexml/parser/test_ultra_light.rb | 2 +- test/rexml/test_attribute.rb | 14 +++ test/rexml/test_core.rb | 13 +-- test/rexml/test_doctype.rb | 134 ++++++++++++++++-------- test/rexml/test_instruction.rb | 14 +++ test/rexml/test_stream.rb | 4 +- test/rexml/test_text.rb | 52 +++++++++ test/rexml/test_xml_declaration.rb | 12 ++- 13 files changed, 275 insertions(+), 56 deletions(-) create mode 100644 test/rexml/formatter/test_default.rb create mode 100644 test/rexml/parse/test_element.rb create mode 100644 test/rexml/parse/test_processing_instruction.rb create mode 100644 test/rexml/test_attribute.rb create mode 100644 test/rexml/test_instruction.rb (limited to 'test/rexml') diff --git a/test/rexml/data/t75.xml b/test/rexml/data/t75.xml index 0911fb1b1a..eb3cccee4b 100644 --- a/test/rexml/data/t75.xml +++ b/test/rexml/data/t75.xml @@ -1,4 +1,4 @@ - + ", format(instruction)) + end + end + end +end diff --git a/test/rexml/parse/test_element.rb b/test/rexml/parse/test_element.rb new file mode 100644 index 0000000000..aad915fe7b --- /dev/null +++ b/test/rexml/parse/test_element.rb @@ -0,0 +1,38 @@ +require "test/unit" +require "rexml/document" + +module REXMLTests + class TestParseElement < Test::Unit::TestCase + def parse(xml) + REXML::Document.new(xml) + end + + class TestInvalid < self + def test_no_end_tag + exception = assert_raise(REXML::ParseException) do + parse("") + end + assert_equal(<<-DETAIL.chomp, exception.to_s) +Invalid attribute name: <:a=""> +Line: 1 +Position: 9 +Last 80 unconsumed characters: + + DETAIL + end + end + end +end diff --git a/test/rexml/parse/test_processing_instruction.rb b/test/rexml/parse/test_processing_instruction.rb new file mode 100644 index 0000000000..a23513fc6e --- /dev/null +++ b/test/rexml/parse/test_processing_instruction.rb @@ -0,0 +1,25 @@ +require "test/unit" +require "rexml/document" + +module REXMLTests + class TestParseProcessinInstruction < Test::Unit::TestCase + def parse(xml) + REXML::Document.new(xml) + end + + class TestInvalid < self + def test_no_name + exception = assert_raise(REXML::ParseException) do + parse("") + end + assert_equal(<<-DETAIL.chomp, exception.to_s) +Invalid processing instruction node +Line: 1 +Position: 4 +Last 80 unconsumed characters: + + DETAIL + end + end + end +end diff --git a/test/rexml/parser/test_tree.rb b/test/rexml/parser/test_tree.rb index 7ab0addca1..8a5d9d1223 100644 --- a/test/rexml/parser/test_tree.rb +++ b/test/rexml/parser/test_tree.rb @@ -12,7 +12,7 @@ class TestTreeParser < Test::Unit::TestCase parse(xml) end assert_equal(<<-MESSAGE, exception.to_s) -Missing end tag for 'root' (got "not-root") +Missing end tag for 'root' (got 'not-root') Line: 1 Position: #{xml.bytesize} Last 80 unconsumed characters: diff --git a/test/rexml/parser/test_ultra_light.rb b/test/rexml/parser/test_ultra_light.rb index c48a13d311..8f4a3980d5 100644 --- a/test/rexml/parser/test_ultra_light.rb +++ b/test/rexml/parser/test_ultra_light.rb @@ -55,7 +55,7 @@ class TestUltraLightParser < Test::Unit::TestCase normalized_doctype[1] = normalized_parent normalized_doctype when :start_element - tag, parent, name, attributes, *children = child + tag, _parent, name, attributes, *children = child normalized_parent = :parent normalized_children = children.collect do |sub_child| normalize_child(sub_child) diff --git a/test/rexml/test_attribute.rb b/test/rexml/test_attribute.rb new file mode 100644 index 0000000000..5175bd4454 --- /dev/null +++ b/test/rexml/test_attribute.rb @@ -0,0 +1,14 @@ +require_relative "rexml_test_utils" + +module REXMLTests + class AttributeTest < Test::Unit::TestCase + def test_empty_prefix + error = assert_raise(ArgumentError) do + REXML::Attribute.new(":x") + end + assert_equal("name must be " + + "\#{PREFIX}:\#{LOCAL_NAME} or \#{LOCAL_NAME}: <\":x\">", + error.message) + end + end +end diff --git a/test/rexml/test_core.rb b/test/rexml/test_core.rb index b2e5299f39..46036d7f12 100644 --- a/test/rexml/test_core.rb +++ b/test/rexml/test_core.rb @@ -1274,14 +1274,15 @@ EOL def test_ticket_21 src = "" - assert_raise( ParseException, "invalid XML should be caught" ) { + exception = assert_raise(ParseException) do Document.new(src) - } - begin - Document.new(src) - rescue - assert_match( /missing attribute quote/, $!.message ) end + assert_equal(<<-DETAIL, exception.to_s) +Missing attribute value start quote: +Line: 1 +Position: 16 +Last 80 unconsumed characters: + DETAIL end def test_ticket_63 diff --git a/test/rexml/test_doctype.rb b/test/rexml/test_doctype.rb index 91de05b05f..7f42669170 100644 --- a/test/rexml/test_doctype.rb +++ b/test/rexml/test_doctype.rb @@ -1,68 +1,92 @@ # frozen_string_literal: false -require 'test/unit' -require 'rexml/document' + +require_relative "rexml_test_utils" module REXMLTests class TestDocTypeAccessor < Test::Unit::TestCase - def setup @sysid = "urn:x-test:sysid1" - @notid1 = "urn:x-test:notation1" - @notid2 = "urn:x-test:notation2" - document_string1 = <<-"XMLEND" - - + @notation_id1 = "urn:x-test:notation1" + @notation_id2 = "urn:x-test:notation2" + xml_system = <<-XML + + ]> - - XMLEND - @doctype1 = REXML::Document.new(document_string1).doctype + + XML + @doc_type_system = REXML::Document.new(xml_system).doctype @pubid = "TEST_ID" - document_string2 = <<-"XMLEND" - - - XMLEND - @doctype2 = REXML::Document.new(document_string2).doctype + xml_public = <<-XML + + + XML + @doc_type_public = REXML::Document.new(xml_public).doctype + + xml_public_system = <<-XML + + + XML + @doc_type_public_system = REXML::Document.new(xml_public_system).doctype + end - document_string3 = <<-"XMLEND" - - - XMLEND - @doctype3 = REXML::Document.new(document_string3).doctype + def test_public + assert_equal([ + nil, + @pubid, + @pubid, + ], + [ + @doc_type_system.public, + @doc_type_public.public, + @doc_type_public_system.public, + ]) + end + def test_to_s + assert_equal("", + @doc_type_public_system.to_s) end - def test_public - assert_equal(nil, @doctype1.public) - assert_equal(@pubid, @doctype2.public) - assert_equal(@pubid, @doctype3.public) + def test_to_s_apostrophe + @doc_type_public_system.parent.context[:prologue_quote] = :apostrophe + assert_equal("", + @doc_type_public_system.to_s) end def test_system - assert_equal(@sysid, @doctype1.system) - assert_equal(nil, @doctype2.system) - assert_equal(@sysid, @doctype3.system) + assert_equal([ + @sysid, + nil, + @sysid, + ], + [ + @doc_type_system.system, + @doc_type_public.system, + @doc_type_public_system.system, + ]) end def test_notation - assert_equal(@notid1, @doctype1.notation("n1").system) - assert_equal(@notid2, @doctype1.notation("n2").system) + assert_equal([ + @notation_id1, + @notation_id2, + ], + [ + @doc_type_system.notation("n1").system, + @doc_type_system.notation("n2").system, + ]) end def test_notations - notations = @doctype1.notations - assert_equal(2, notations.length) - assert_equal(@notid1, find_notation(notations, "n1").system) - assert_equal(@notid2, find_notation(notations, "n2").system) - end - - def find_notation(notations, name) - notations.find { |notation| - name == notation.name - } + notations = @doc_type_system.notations + assert_equal([ + @notation_id1, + @notation_id2, + ], + notations.collect(&:system)) end - end class TestNotationDeclPublic < Test::Unit::TestCase @@ -82,6 +106,19 @@ module REXMLTests decl(@id, @uri).to_s) end + def test_to_s_apostrophe + document = REXML::Document.new(<<-XML) + + + XML + document.context[:prologue_quote] = :apostrophe + notation = document.doctype.notations[0] + assert_equal("", + notation.to_s) + end + private def decl(id, uri) REXML::NotationDecl.new(@name, "PUBLIC", id, uri) @@ -99,6 +136,19 @@ module REXMLTests decl(@id).to_s) end + def test_to_s_apostrophe + document = REXML::Document.new(<<-XML) + + + XML + document.context[:prologue_quote] = :apostrophe + notation = document.doctype.notations[0] + assert_equal("", + notation.to_s) + end + private def decl(id) REXML::NotationDecl.new(@name, "SYSTEM", id, nil) diff --git a/test/rexml/test_instruction.rb b/test/rexml/test_instruction.rb new file mode 100644 index 0000000000..96fa909e17 --- /dev/null +++ b/test/rexml/test_instruction.rb @@ -0,0 +1,14 @@ +require_relative "rexml_test_utils" + +module REXMLTests + class InstructionTest < Test::Unit::TestCase + def test_target_nil + error = assert_raise(ArgumentError) do + REXML::Instruction.new(nil) + end + assert_equal("processing instruction target must be String or " + + "REXML::Instruction: ", + error.message) + end + end +end diff --git a/test/rexml/test_stream.rb b/test/rexml/test_stream.rb index d7ceedc70e..08d4462ef9 100644 --- a/test/rexml/test_stream.rb +++ b/test/rexml/test_stream.rb @@ -15,8 +15,8 @@ module REXMLTests def test_listener data = %Q{\n} - b = RequestReader.new( data ) - b = RequestReader.new( data ) + RequestReader.new( data ) + RequestReader.new( data ) end def test_ticket_49 diff --git a/test/rexml/test_text.rb b/test/rexml/test_text.rb index 3f8036eee3..a27701fce5 100644 --- a/test/rexml/test_text.rb +++ b/test/rexml/test_text.rb @@ -5,6 +5,52 @@ module REXMLTests class TextTester < Test::Unit::TestCase include REXML + def test_new_text_response_whitespace_default + text = Text.new("a b\t\tc", true) + assert_equal("a b\tc", Text.new(text).to_s) + end + + def test_new_text_response_whitespace_true + text = Text.new("a b\t\tc", true) + assert_equal("a b\t\tc", Text.new(text, true).to_s) + end + + def test_new_text_raw_default + text = Text.new("&lt;", false, nil, true) + assert_equal("&lt;", Text.new(text).to_s) + end + + def test_new_text_raw_false + text = Text.new("&lt;", false, nil, true) + assert_equal("&amp;lt;", Text.new(text, false, nil, false).to_s) + end + + def test_new_text_entity_filter_default + document = REXML::Document.new(<<-XML) + + +]> + + XML + text = Text.new("aaa bbb", false, document.root, nil, ["a"]) + assert_equal("aaa &b;", + Text.new(text, false, document.root).to_s) + end + + def test_new_text_entity_filter_custom + document = REXML::Document.new(<<-XML) + + +]> + + XML + text = Text.new("aaa bbb", false, document.root, nil, ["a"]) + assert_equal("&a; bbb", + Text.new(text, false, document.root, nil, ["b"]).to_s) + end + def test_shift_operator_chain text = Text.new("original\r\n") text << "append1\r\n" << "append2\r\n" @@ -18,5 +64,11 @@ module REXMLTests text << "append3\r\n" << "append4\r\n" assert_equal("original\nappend1\nappend2\nappend3\nappend4\n", text.to_s) end + + def test_clone + text = Text.new("&lt; <") + assert_equal(text.to_s, + text.clone.to_s) + end end end diff --git a/test/rexml/test_xml_declaration.rb b/test/rexml/test_xml_declaration.rb index a4d97c41d0..1d5a6d312f 100644 --- a/test/rexml/test_xml_declaration.rb +++ b/test/rexml/test_xml_declaration.rb @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # frozen_string_literal: false # # Created by Henrik MÃ¥rtensson on 2007-02-18. @@ -10,11 +9,11 @@ require "test/unit" module REXMLTests class TestXmlDeclaration < Test::Unit::TestCase def setup - xml = <<-'END_XML' + xml = <<-XML - END_XML + XML @doc = REXML::Document.new xml @root = @doc.root @xml_declaration = @doc.children[0] @@ -32,5 +31,12 @@ module REXMLTests assert_kind_of(REXML::XMLDecl, @root.previous_sibling.previous_sibling) assert_kind_of(REXML::Element, @xml_declaration.next_sibling.next_sibling) end + + def test_write_prologue_quote + @doc.context[:prologue_quote] = :quote + assert_equal("", + @xml_declaration.to_s) + end end end -- cgit v1.2.3