(text)
| 251 | * @returns {{ data: string, document: string | null, fragment: string | null, scriptMode: string | null }[]} cases |
| 252 | */ |
| 253 | const parseDat = (text) => { |
| 254 | const cases = []; |
| 255 | const lines = text.split("\n"); |
| 256 | let i = 0; |
| 257 | const n = lines.length; |
| 258 | const readSection = () => { |
| 259 | i++; |
| 260 | const out = []; |
| 261 | while (i < n && !lines[i].startsWith("#")) { |
| 262 | out.push(lines[i]); |
| 263 | i++; |
| 264 | } |
| 265 | return out; |
| 266 | }; |
| 267 | while (i < n) { |
| 268 | if (lines[i] !== "#data") { |
| 269 | i++; |
| 270 | continue; |
| 271 | } |
| 272 | const test = { |
| 273 | data: "", |
| 274 | document: null, |
| 275 | fragment: null, |
| 276 | scriptMode: null |
| 277 | }; |
| 278 | |
| 279 | test.data = readSection().join("\n"); |
| 280 | |
| 281 | while (i < n && lines[i].startsWith("#") && lines[i] !== "#data") { |
| 282 | const tag = lines[i]; |
| 283 | if (tag === "#document-fragment") { |
| 284 | test.fragment = readSection().join("\n").trim(); |
| 285 | } else if (tag === "#script-on") { |
| 286 | test.scriptMode = "on"; |
| 287 | |
| 288 | i++; |
| 289 | } else if (tag === "#script-off") { |
| 290 | test.scriptMode = "off"; |
| 291 | |
| 292 | i++; |
| 293 | } else if (tag === "#document") { |
| 294 | i++; |
| 295 | const doc = []; |
| 296 | while (i < n) { |
| 297 | if (lines[i] === "" && (i + 1 >= n || lines[i + 1] === "#data")) { |
| 298 | i++; |
| 299 | break; |
| 300 | } |
| 301 | doc.push(lines[i]); |
| 302 | i++; |
| 303 | } |
| 304 | while (doc.length && doc[doc.length - 1] === "") doc.pop(); |
| 305 | |
| 306 | test.document = doc.join("\n"); |
| 307 | } else { |
| 308 | readSection(); |
| 309 | } |
| 310 | } |
no test coverage detected