diff options
Diffstat (limited to 'test/rexml/test_doctype.rb')
-rw-r--r-- | test/rexml/test_doctype.rb | 134 |
1 files changed, 92 insertions, 42 deletions
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" - <!DOCTYPE r SYSTEM "#{@sysid}" [ - <!NOTATION n1 SYSTEM "#{@notid1}"> - <!NOTATION n2 SYSTEM "#{@notid2}"> + @notation_id1 = "urn:x-test:notation1" + @notation_id2 = "urn:x-test:notation2" + xml_system = <<-XML + <!DOCTYPE root SYSTEM "#{@sysid}" [ + <!NOTATION n1 SYSTEM "#{@notation_id1}"> + <!NOTATION n2 SYSTEM "#{@notation_id2}"> ]> - <r/> - XMLEND - @doctype1 = REXML::Document.new(document_string1).doctype + <root/> + XML + @doc_type_system = REXML::Document.new(xml_system).doctype @pubid = "TEST_ID" - document_string2 = <<-"XMLEND" - <!DOCTYPE r PUBLIC "#{@pubid}"> - <r/> - XMLEND - @doctype2 = REXML::Document.new(document_string2).doctype + xml_public = <<-XML + <!DOCTYPE root PUBLIC "#{@pubid}"> + <root/> + XML + @doc_type_public = REXML::Document.new(xml_public).doctype + + xml_public_system = <<-XML + <!DOCTYPE root PUBLIC "#{@pubid}" "#{@sysid}"> + <root/> + XML + @doc_type_public_system = REXML::Document.new(xml_public_system).doctype + end - document_string3 = <<-"XMLEND" - <!DOCTYPE r PUBLIC "#{@pubid}" "#{@sysid}"> - <r/> - 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("<!DOCTYPE root PUBLIC \"#{@pubid}\" \"#{@sysid}\">", + @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("<!DOCTYPE root PUBLIC '#{@pubid}' '#{@sysid}'>", + @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) + <!DOCTYPE root SYSTEM "urn:x-test:sysid" [ + #{decl(@id, @uri).to_s} + ]> + <root/> + XML + document.context[:prologue_quote] = :apostrophe + notation = document.doctype.notations[0] + assert_equal("<!NOTATION #{@name} PUBLIC '#{@id}' '#{@uri}'>", + 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) + <!DOCTYPE root SYSTEM "urn:x-test:sysid" [ + #{decl(@id).to_s} + ]> + <root/> + XML + document.context[:prologue_quote] = :apostrophe + notation = document.doctype.notations[0] + assert_equal("<!NOTATION #{@name} SYSTEM '#{@id}'>", + notation.to_s) + end + private def decl(id) REXML::NotationDecl.new(@name, "SYSTEM", id, nil) |