diff --git a/test/test_document.rb b/test/test_document.rb
index 7fccbacb..33cf4002 100644
--- a/test/test_document.rb
+++ b/test/test_document.rb
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: false
-require 'core_assertions'
-
module REXMLTests
class TestDocument < Test::Unit::TestCase
- include Test::Unit::CoreAssertions
-
def test_version_attributes_to_s
doc = REXML::Document.new(<<~eoxml)
@@ -202,13 +198,6 @@ def test_xml_declaration_standalone
assert_equal('no', doc.stand_alone?, bug2539)
end
- def test_gt_linear_performance_attribute_value
- seq = [10000, 50000, 100000, 150000, 200000]
- assert_linear_performance(seq, rehearsal: 10) do |n|
- REXML::Document.new('" * n + '">')
- end
- end
-
def test_each_recursive
xml_source = <<~XML
@@ -237,7 +226,7 @@ def test_each_recursive
document = REXML::Document.new(xml_source)
# Node#each_recursive iterates elements only.
- # This does not iterate XML declerations, comments, attributes, CDATA sections, etc.
+ # This does not iterate XML declarations, comments, attributes, CDATA sections, etc.
actual_names = []
document.each_recursive do |element|
actual_names << element.attributes["name"]
@@ -247,7 +236,7 @@ def test_each_recursive
class WriteTest < Test::Unit::TestCase
def setup
- @document = REXML::Document.new(<<-EOX)
+ @document = REXML::Document.new(<<-EOX.chomp)
Hello world!
EOX
@@ -257,7 +246,7 @@ class ArgumentsTest < self
def test_output
output = ""
@document.write(output)
- assert_equal(<<-EOX, output)
+ assert_equal(<<-EOX.chomp, output)
Hello world!
EOX
@@ -280,7 +269,7 @@ def test_transitive
indent = 2
transitive = true
@document.write(output, indent, transitive)
- assert_equal(<<-EOX, output)
+ assert_equal(<<-EOX.chomp, output)
Hello world!
#{japanese_text}
EOX
@@ -320,7 +309,7 @@ class OptionsTest < self
def test_output
output = ""
@document.write(:output => output)
- assert_equal(<<-EOX, output)
+ assert_equal(<<-EOX.chomp, output)
Hello world!
EOX
@@ -340,7 +329,7 @@ def test_indent
def test_transitive
output = ""
@document.write(:output => output, :indent => 2, :transitive => true)
- assert_equal(<<-EOX, output)
+ assert_equal(<<-EOX.chomp, output)
Hello world! output, :encoding => encoding)
- assert_equal(<<-EOX.encode(encoding), output)
+ assert_equal(<<-EOX.chomp.encode(encoding), output)
#{japanese_text}
EOX
@@ -446,7 +435,7 @@ def test_utf_16
actual_xml = ""
document.write(actual_xml)
- expected_xml = <<-EOX.encode("UTF-16BE")
+ expected_xml = <<-EOX.chomp.encode("UTF-16BE")
\ufeff
Hello world!
EOX
diff --git a/test/test_light.rb b/test/test_light.rb
index 54b2c52e..c556c978 100644
--- a/test/test_light.rb
+++ b/test/test_light.rb
@@ -62,7 +62,7 @@ def test_access_child_elements
assert_equal( 'c', a[1].name )
end
- def test_itterate_over_children
+ def test_iterate_over_children
foo = make_small_document
ctr = 0
foo[0].each { ctr += 1 }
diff --git a/test/test_pullparser.rb b/test/test_pullparser.rb
index 53a985ba..096e8b7f 100644
--- a/test/test_pullparser.rb
+++ b/test/test_pullparser.rb
@@ -62,6 +62,63 @@ def test_entity_replacement
end
end
+ def test_character_references
+ source = 'AB'
+ parser = REXML::Parsers::PullParser.new( source )
+
+ events = {}
+ element_name = ''
+ while parser.has_next?
+ event = parser.pull
+ case event.event_type
+ when :start_element
+ element_name = event[0]
+ when :text
+ events[element_name] = event[1]
+ end
+ end
+
+ assert_equal('A', events['a'])
+ assert_equal("B", events['b'])
+ end
+
+ def test_text_entity_references
+ source = '<P> <I> <B> Text </B> </I>'
+ parser = REXML::Parsers::PullParser.new( source )
+
+ events = []
+ while parser.has_next?
+ event = parser.pull
+ case event.event_type
+ when :text
+ events << event[1]
+ end
+ end
+
+ assert_equal([" Text "], events)
+ end
+
+ def test_text_content_with_line_breaks
+ source = "AB\nC\r\n"
+ parser = REXML::Parsers::PullParser.new( source )
+
+ events = {}
+ element_name = ''
+ while parser.has_next?
+ event = parser.pull
+ case event.event_type
+ when :start_element
+ element_name = event[0]
+ when :text
+ events[element_name] = event[1]
+ end
+ end
+
+ assert_equal('A', events['a'])
+ assert_equal("B\n", events['b'])
+ assert_equal("C\n", events['c'])
+ end
+
def test_peek_unshift
source = ""
REXML::Parsers::PullParser.new(source)
diff --git a/test/test_sax.rb b/test/test_sax.rb
index c2255bf3..5a3f5e4e 100644
--- a/test/test_sax.rb
+++ b/test/test_sax.rb
@@ -31,6 +31,17 @@ def test_entity_replacement
assert_equal '--1234--', results[1]
end
+ def test_characters_predefined_entities
+ source = '<P> <I> <B> Text </B> </I>'
+
+ sax = Parsers::SAX2Parser.new( source )
+ results = []
+ sax.listen(:characters) {|x| results << x }
+ sax.parse
+
+ assert_equal(["
Text "], results)
+ end
+
def test_sax2
File.open(fixture_path("documentation.xml")) do |f|
parser = Parsers::SAX2Parser.new( f )
@@ -140,7 +151,7 @@ def test_simple_doctype_listener
# test doctype with missing name, should throw ParseException
# submitted by Jeff Barczewseki
- def test_doctype_with_mising_name_throws_exception
+ def test_doctype_with_missing_name_throws_exception
xml = <<~END
diff --git a/test/test_text_check.rb b/test/test_text_check.rb
new file mode 100644
index 00000000..11cf65a3
--- /dev/null
+++ b/test/test_text_check.rb
@@ -0,0 +1,121 @@
+# frozen_string_literal: false
+
+module REXMLTests
+ class TextCheckTester < Test::Unit::TestCase
+
+ def check(string)
+ REXML::Text.check(string, REXML::Text::NEEDS_A_SECOND_CHECK, nil)
+ end
+
+ def assert_check(string)
+ assert_nothing_raised { check(string) }
+ end
+
+ def assert_check_failed(string, illegal_part)
+ message = "Illegal character #{illegal_part.inspect} in raw string #{string.inspect}"
+ assert_raise(RuntimeError.new(message)) do
+ check(string)
+ end
+ end
+
+ class TestValid < self
+ def test_entity_name_start_char_colon
+ assert_check("&:;")
+ end
+
+ def test_entity_name_start_char_under_score
+ assert_check("&_;")
+ end
+
+ def test_entity_name_mix
+ assert_check("&A.b-0123;")
+ end
+
+ def test_character_reference_decimal
+ assert_check("¢")
+ end
+
+ def test_character_reference_hex
+ assert_check("")
+ end
+
+ def test_entity_name_non_ascii
+ # U+3042 HIRAGANA LETTER A
+ # U+3044 HIRAGANA LETTER I
+ assert_check("&\u3042\u3044;")
+ end
+
+ def test_normal_string
+ assert_check("foo")
+ end
+ end
+
+ class TestInvalid < self
+ def test_lt
+ assert_check_failed("<;", "<")
+ end
+
+ def test_lt_mix
+ assert_check_failed("ab 1]").size
assert_equal 3, REXML::XPath.match(doc, "//b[number(@id) >= 1]").size
assert_equal 1, REXML::XPath.match(doc, "//b[number(@id) <= 1]").size