-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for REXML::Text.check (#165)
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
1 parent
5e140ed
commit 6d6400c
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<cd', '<') | ||
end | ||
|
||
def test_entity_reference_missing_colon | ||
assert_check_failed('&', '&') | ||
end | ||
|
||
def test_character_reference_decimal_invalid_value | ||
# U+0008 BACKSPACE | ||
assert_check_failed('', '') | ||
end | ||
|
||
def test_character_reference_format_hex_0x | ||
# U+0041 LATIN CAPITAL LETTER A | ||
assert_check_failed('�x41;', '�x41;') | ||
end | ||
|
||
def test_character_reference_format_hex_00x | ||
# U+0041 LATIN CAPITAL LETTER A | ||
assert_check_failed('�x41;', '�x41;') | ||
end | ||
|
||
def test_character_reference_hex_surrogate_block | ||
# U+0D800 SURROGATE PAIR | ||
assert_check_failed('�', '�') | ||
end | ||
|
||
def test_entity_name_non_ascii_symbol | ||
# U+00BF INVERTED QUESTION MARK | ||
assert_check_failed('&\u00BF;', '&') | ||
end | ||
end | ||
end | ||
end |