Skip to content

Commit

Permalink
tests: update Events/07 test to clarify interpretation of tag end sla…
Browse files Browse the repository at this point in the history
…shes

Enhancements to the `Events/07-self-closing.json` test to better cover and
demonstrate the interpretation of tag end slashes (e.g. `/>`)

`07-self-closing.json` is replaced with a set of tests 07a to 07h where
the input and context are identical except for one isolated change. The
outputs can thereby be diffed, showing the effect of the isolated change.

Adds test coverage for the `recognizeSelfClosing` option.
  • Loading branch information
vassudanagunta committed Dec 14, 2021
1 parent 40ac4c4 commit 0c6fcd1
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 16 deletions.
48 changes: 48 additions & 0 deletions src/__fixtures__/Events/07a-end_slash--void.json
@@ -0,0 +1,48 @@
{
"name": "end slash: void element ending with />",
"input": "<hr / ><p>Hold the line.",
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["hr"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["hr", {}, false]
},
{
"event": "closetag",
"startIndex": 0,
"endIndex": 6,
"data": ["hr", true]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
}
]
}
48 changes: 48 additions & 0 deletions src/__fixtures__/Events/07b-end_slash--void_without.json
@@ -0,0 +1,48 @@
{
"name": "end slash: void element ending with >",
"input": "<hr ><p>Hold the line.",
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["hr"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["hr", {}, false]
},
{
"event": "closetag",
"startIndex": 0,
"endIndex": 6,
"data": ["hr", true]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
}
]
}
53 changes: 53 additions & 0 deletions src/__fixtures__/Events/07c-end_slash--void_without--xmlMode.json
@@ -0,0 +1,53 @@
{
"name": "end slash: void element ending with >, xmlMode=true",
"input": "<hr ><p>Hold the line.",
"options": {
"parser": {
"xmlMode": true
}
},
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["hr"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["hr", {}, false]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["hr", true]
}
]
}
48 changes: 48 additions & 0 deletions src/__fixtures__/Events/07d-end_slash--non_void.json
@@ -0,0 +1,48 @@
{
"name": "end slash: non-void element ending with />",
"input": "<xx / ><p>Hold the line.",
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["xx"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["xx", {}, false]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["xx", true]
}
]
}
53 changes: 53 additions & 0 deletions src/__fixtures__/Events/07e-end_slash--non_void--xmlmode.json
@@ -0,0 +1,53 @@
{
"name": "end slash: non-void element ending with />, xmlMode=true",
"input": "<xx / ><p>Hold the line.",
"options": {
"parser": {
"xmlMode": true
}
},
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["xx"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["xx", {}, false]
},
{
"event": "closetag",
"startIndex": 0,
"endIndex": 6,
"data": ["xx", true]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
}
]
}
@@ -0,0 +1,53 @@
{
"name": "end slash: non-void element ending with />, recognizeSelfClosing=true",
"input": "<xx / ><p>Hold the line.",
"options": {
"parser": {
"recognizeSelfClosing": true
}
},
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 3,
"data": ["xx"]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 6,
"data": ["xx", {}, false]
},
{
"event": "closetag",
"startIndex": 0,
"endIndex": 6,
"data": ["xx", true]
},
{
"event": "opentagname",
"startIndex": 7,
"endIndex": 9,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 7,
"endIndex": 9,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 10,
"endIndex": 23,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 24,
"endIndex": 24,
"data": ["p", true]
}
]
}
@@ -0,0 +1,54 @@
{
"name": "end slash: as part of attrib value of void element",
"input": "<img src=gif.com/123/><p>Hold the line.",
"expected": [
{
"event": "opentagname",
"startIndex": 0,
"endIndex": 4,
"data": ["img"]
},
{
"event": "attribute",
"startIndex": 5,
"endIndex": 21,
"data": ["src", "gif.com/123/", null]
},
{
"event": "opentag",
"startIndex": 0,
"endIndex": 21,
"data": ["img", {"src": "gif.com/123/"}, false]
},
{
"event": "closetag",
"startIndex": 0,
"endIndex": 21,
"data": ["img", true]
},
{
"event": "opentagname",
"startIndex": 22,
"endIndex": 24,
"data": ["p"]
},
{
"event": "opentag",
"startIndex": 22,
"endIndex": 24,
"data": ["p", {}, false]
},
{
"event": "text",
"startIndex": 25,
"endIndex": 38,
"data": ["Hold the line."]
},
{
"event": "closetag",
"startIndex": 39,
"endIndex": 39,
"data": ["p", true]
}
]
}

0 comments on commit 0c6fcd1

Please sign in to comment.