diff --git a/test/test_text_check.rb b/test/test_text_check.rb new file mode 100644 index 00000000..e7aea3bc --- /dev/null +++ b/test/test_text_check.rb @@ -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 = ['&', '<', '>', '"', ''', ' ', 'Ψ'] + character_entities.each do |token| + text = Text.new(token, false, nil, true) + assert_equal(token, text.to_s) + end + + numeric_entities = [' ', '"', '♦', ' ', '¢', '􏿿', '􏿿'] + numeric_entities.each do |token| + text = Text.new(token, false, nil, true) + assert_equal(token, text.to_s) + end + + unicode_entities = [' ', ' ', ' ', '„', 'Ÿ', '﷯', '􏿿', ''] + 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 = ['<', '<;', '&', '&42;','&#A;', '', ' ', '', '�', '￾', '�', '�'] + chars.each do |token| + assert_raise(RuntimeError) { Text.new(token, false, nil, true) } + end + end + end +end