diff --git a/test/test_text_check.rb b/test/test_text_check.rb new file mode 100644 index 00000000..d4076edf --- /dev/null +++ b/test/test_text_check.rb @@ -0,0 +1,92 @@ +# 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