Skip to content

Commit

Permalink
Add tests for REXML::Text.check
Browse files Browse the repository at this point in the history
This patch will add missing REXML::Text.check tests.
This is the tests for the part that is checked using a regular expression.
https://github.com/ruby/rexml/blob/b2ec329dc1dc7635b224a6d61687c24b1e1db6fd/lib/rexml/text.rb#L155-L172
  • Loading branch information
Watson1978 committed Jul 10, 2024
1 parent b2ec329 commit 7768883
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/test_text_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: false

module REXMLTests
class TextCheckTester < Test::Unit::TestCase
include REXML

def test_valid_pattern
chars = ['&A;', '&:;', '&_;', '&:A;', '&AA.bb-00;']
chars.each do |token|
text = Text.new(token, false, nil, true)
assert_equal(token, text.to_s)
end

character_entities = ['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&nbsp;', '&Psi;']
character_entities.each do |token|
text = Text.new(token, false, nil, true)
assert_equal(token, text.to_s)
end

numeric_entities = ['&#13;', '&#34;', '&#9830;', '&#0000000013;', '&#0000000162;', '&#x10FFFF;', '&#1114111;']
numeric_entities.each do |token|
text = Text.new(token, false, nil, true)
assert_equal(token, text.to_s)
end

unicode_entities = ['&#x9;', '&#xa;', '&#xD;', '&#x84;', '&#x9F;', '&#xFDEF;', '&#x10FFFF;', '&#x000000007f;']
unicode_entities.each do |token|
text = Text.new(token, false, nil, true)
assert_equal(token, text.to_s)
end

unicodes = ["&\u00C0;", "&\uFDF0;", "&\u{10000};", "&\u00D6\u0300\u0300;"]
unicodes.each do |unicode|
text = Text.new(unicode, false, nil, true)
assert_equal(unicode, text.to_s)
end
end

def test_invalid_pattern
chars = ['<', '<;', '&amp', '&42;','&#A;', '&#8;', '&#xB;', '&#x1f;', '&#xD800;', '&#xFFFE;', '&#x110000;', '&#1114112;']
chars.each do |token|
assert_raise(RuntimeError) { Text.new(token, false, nil, true) }
end
end
end
end

0 comments on commit 7768883

Please sign in to comment.