1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
# frozen_string_literal: false
require 'test/unit'
require 'rexml/document'
module REXMLTests
class TestParseNotationDeclaration < Test::Unit::TestCase
private
def xml(internal_subset)
<<-XML
<!DOCTYPE r SYSTEM "urn:x-henrikmartensson:test" [
#{internal_subset}
]>
<r/>
XML
end
def parse(internal_subset)
REXML::Document.new(xml(internal_subset)).doctype
end
class TestCommon < self
def test_name
doctype = parse("<!NOTATION name PUBLIC 'urn:public-id'>")
assert_equal("name", doctype.notation("name").name)
end
def test_no_name
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: name is missing
Line: 5
Position: 72
Last 80 unconsumed characters:
<!NOTATION> ]> <r/>
DETAIL
end
def test_invalid_name
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION '>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: invalid name
Line: 5
Position: 74
Last 80 unconsumed characters:
'> ]> <r/>
DETAIL
end
def test_no_id_type
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: invalid ID type
Line: 5
Position: 77
Last 80 unconsumed characters:
> ]> <r/>
DETAIL
end
def test_invalid_id_type
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name INVALID>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: invalid ID type
Line: 5
Position: 85
Last 80 unconsumed characters:
INVALID> ]> <r/>
DETAIL
end
end
class TestExternalID < self
class TestSystem < self
def test_no_literal
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: system literal is missing
Line: 5
Position: 84
Last 80 unconsumed characters:
SYSTEM> ]> <r/>
DETAIL
end
def test_garbage_after_literal
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM 'system-literal'x'>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: garbage before end >
Line: 5
Position: 103
Last 80 unconsumed characters:
x'> ]> <r/>
DETAIL
end
def test_single_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM 'system-literal'>
INTERNAL_SUBSET
assert_equal("system-literal", doctype.notation("name").system)
end
def test_double_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name SYSTEM "system-literal">
INTERNAL_SUBSET
assert_equal("system-literal", doctype.notation("name").system)
end
end
class TestPublic < self
class TestPublicIDLiteral < self
def test_content_double_quote
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'double quote " is invalid' "system-literal">
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: invalid public ID literal
Line: 5
Position: 129
Last 80 unconsumed characters:
PUBLIC 'double quote " is invalid' "system-literal"> ]> <r/>
DETAIL
end
def test_single_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'public-id-literal' "system-literal">
INTERNAL_SUBSET
assert_equal("public-id-literal", doctype.notation("name").public)
end
def test_double_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" "system-literal">
INTERNAL_SUBSET
assert_equal("public-id-literal", doctype.notation("name").public)
end
end
class TestSystemLiteral < self
def test_garbage_after_literal
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'public-id-literal' 'system-literal'x'>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: garbage before end >
Line: 5
Position: 123
Last 80 unconsumed characters:
x'> ]> <r/>
DETAIL
end
def test_single_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" 'system-literal'>
INTERNAL_SUBSET
assert_equal("system-literal", doctype.notation("name").system)
end
def test_double_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal" "system-literal">
INTERNAL_SUBSET
assert_equal("system-literal", doctype.notation("name").system)
end
end
end
class TestMixed < self
def test_system_public
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION system-name SYSTEM "system-literal">
<!NOTATION public-name PUBLIC "public-id-literal" 'system-literal'>
INTERNAL_SUBSET
assert_equal(["system-name", "public-name"],
doctype.notations.collect(&:name))
end
def test_public_system
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION public-name PUBLIC "public-id-literal" 'system-literal'>
<!NOTATION system-name SYSTEM "system-literal">
INTERNAL_SUBSET
assert_equal(["public-name", "system-name"],
doctype.notations.collect(&:name))
end
end
end
class TestPublicID < self
def test_no_literal
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: public ID literal is missing
Line: 5
Position: 84
Last 80 unconsumed characters:
PUBLIC> ]> <r/>
DETAIL
end
def test_literal_content_double_quote
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'double quote " is invalid in PubidLiteral'>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: invalid public ID literal
Line: 5
Position: 128
Last 80 unconsumed characters:
PUBLIC 'double quote \" is invalid in PubidLiteral'> ]> <r/>
DETAIL
end
def test_garbage_after_literal
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'public-id-literal'x'>
INTERNAL_SUBSET
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
Malformed notation declaration: garbage before end >
Line: 5
Position: 106
Last 80 unconsumed characters:
x'> ]> <r/>
DETAIL
end
def test_literal_single_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC 'public-id-literal'>
INTERNAL_SUBSET
assert_equal("public-id-literal", doctype.notation("name").public)
end
def test_literal_double_quote
doctype = parse(<<-INTERNAL_SUBSET)
<!NOTATION name PUBLIC "public-id-literal">
INTERNAL_SUBSET
assert_equal("public-id-literal", doctype.notation("name").public)
end
end
end
end
|