|
| 1 | +require "test/unit" |
| 2 | +require "rexml/document" |
| 3 | + |
| 4 | +module REXMLTests |
| 5 | + class TestParseComment < Test::Unit::TestCase |
| 6 | + def parse(xml) |
| 7 | + REXML::Document.new(xml) |
| 8 | + end |
| 9 | + |
| 10 | + class TestInvalid < self |
| 11 | + def test_toplevel_unclosed_comment |
| 12 | + exception = assert_raise(REXML::ParseException) do |
| 13 | + parse("<!--") |
| 14 | + end |
| 15 | + assert_equal(<<~DETAIL, exception.to_s) |
| 16 | + Unclosed comment |
| 17 | + Line: 1 |
| 18 | + Position: 4 |
| 19 | + Last 80 unconsumed characters: |
| 20 | + DETAIL |
| 21 | + end |
| 22 | + |
| 23 | + def test_toplevel_malformed_comment_inner |
| 24 | + exception = assert_raise(REXML::ParseException) do |
| 25 | + parse("<!-- -- -->") |
| 26 | + end |
| 27 | + assert_equal(<<~DETAIL, exception.to_s) |
| 28 | + Malformed comment |
| 29 | + Line: 1 |
| 30 | + Position: 11 |
| 31 | + Last 80 unconsumed characters: |
| 32 | + DETAIL |
| 33 | + end |
| 34 | + |
| 35 | + def test_toplevel_malformed_comment_end |
| 36 | + exception = assert_raise(REXML::ParseException) do |
| 37 | + parse("<!-- --->") |
| 38 | + end |
| 39 | + assert_equal(<<~DETAIL, exception.to_s) |
| 40 | + Malformed comment |
| 41 | + Line: 1 |
| 42 | + Position: 9 |
| 43 | + Last 80 unconsumed characters: |
| 44 | + DETAIL |
| 45 | + end |
| 46 | + |
| 47 | + def test_doctype_malformed_comment_inner |
| 48 | + exception = assert_raise(REXML::ParseException) do |
| 49 | + parse("<!DOCTYPE foo [<!-- -- -->") |
| 50 | + end |
| 51 | + assert_equal(<<~DETAIL, exception.to_s) |
| 52 | + Malformed comment |
| 53 | + Line: 1 |
| 54 | + Position: 26 |
| 55 | + Last 80 unconsumed characters: |
| 56 | + DETAIL |
| 57 | + end |
| 58 | + |
| 59 | + def test_doctype_malformed_comment_end |
| 60 | + exception = assert_raise(REXML::ParseException) do |
| 61 | + parse("<!DOCTYPE foo [<!-- --->") |
| 62 | + end |
| 63 | + assert_equal(<<~DETAIL, exception.to_s) |
| 64 | + Malformed comment |
| 65 | + Line: 1 |
| 66 | + Position: 24 |
| 67 | + Last 80 unconsumed characters: |
| 68 | + DETAIL |
| 69 | + end |
| 70 | + |
| 71 | + def test_after_doctype_malformed_comment_inner |
| 72 | + exception = assert_raise(REXML::ParseException) do |
| 73 | + parse("<a><!-- -- -->") |
| 74 | + end |
| 75 | + assert_equal(<<~DETAIL, exception.to_s) |
| 76 | + Malformed comment |
| 77 | + Line: 1 |
| 78 | + Position: 14 |
| 79 | + Last 80 unconsumed characters: |
| 80 | + DETAIL |
| 81 | + end |
| 82 | + |
| 83 | + def test_after_doctype_malformed_comment_end |
| 84 | + exception = assert_raise(REXML::ParseException) do |
| 85 | + parse("<a><!-- --->") |
| 86 | + end |
| 87 | + assert_equal(<<~DETAIL, exception.to_s) |
| 88 | + Malformed comment |
| 89 | + Line: 1 |
| 90 | + Position: 12 |
| 91 | + Last 80 unconsumed characters: |
| 92 | + DETAIL |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | +end |
0 commit comments