From 0c6fcd1176ce4223cdfb546ffb8cac18716353e1 Mon Sep 17 00:00:00 2001 From: Vas Sudanagunta Date: Tue, 14 Dec 2021 14:51:15 -0800 Subject: [PATCH] tests: update Events/07 test to clarify interpretation of tag end slashes 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. --- .../Events/07a-end_slash--void.json | 48 +++++++++++++++++ .../Events/07b-end_slash--void_without.json | 48 +++++++++++++++++ .../07c-end_slash--void_without--xmlMode.json | 53 ++++++++++++++++++ .../Events/07d-end_slash--non_void.json | 48 +++++++++++++++++ .../07e-end_slash--non_void--xmlmode.json | 53 ++++++++++++++++++ ...ash--non_void--recognize_self_closing.json | 53 ++++++++++++++++++ ...ash--consumed_by_attrib_value_in_void.json | 54 +++++++++++++++++++ ...consumed_by_attrib_value_in_non_void.json} | 32 +++++------ 8 files changed, 373 insertions(+), 16 deletions(-) create mode 100644 src/__fixtures__/Events/07a-end_slash--void.json create mode 100644 src/__fixtures__/Events/07b-end_slash--void_without.json create mode 100644 src/__fixtures__/Events/07c-end_slash--void_without--xmlMode.json create mode 100644 src/__fixtures__/Events/07d-end_slash--non_void.json create mode 100644 src/__fixtures__/Events/07e-end_slash--non_void--xmlmode.json create mode 100644 src/__fixtures__/Events/07f-end_slash--non_void--recognize_self_closing.json create mode 100644 src/__fixtures__/Events/07g-end_slash--consumed_by_attrib_value_in_void.json rename src/__fixtures__/Events/{07-self-closing.json => 07h-end_slash--consumed_by_attrib_value_in_non_void.json} (63%) diff --git a/src/__fixtures__/Events/07a-end_slash--void.json b/src/__fixtures__/Events/07a-end_slash--void.json new file mode 100644 index 000000000..83385bee6 --- /dev/null +++ b/src/__fixtures__/Events/07a-end_slash--void.json @@ -0,0 +1,48 @@ +{ + "name": "end slash: void element ending with />", + "input": "

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] + } + ] +} diff --git a/src/__fixtures__/Events/07b-end_slash--void_without.json b/src/__fixtures__/Events/07b-end_slash--void_without.json new file mode 100644 index 000000000..5a832cb68 --- /dev/null +++ b/src/__fixtures__/Events/07b-end_slash--void_without.json @@ -0,0 +1,48 @@ +{ + "name": "end slash: void element ending with >", + "input": "


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] + } + ] +} diff --git a/src/__fixtures__/Events/07c-end_slash--void_without--xmlMode.json b/src/__fixtures__/Events/07c-end_slash--void_without--xmlMode.json new file mode 100644 index 000000000..ae6e25ebf --- /dev/null +++ b/src/__fixtures__/Events/07c-end_slash--void_without--xmlMode.json @@ -0,0 +1,53 @@ +{ + "name": "end slash: void element ending with >, xmlMode=true", + "input": "


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] + } + ] +} diff --git a/src/__fixtures__/Events/07d-end_slash--non_void.json b/src/__fixtures__/Events/07d-end_slash--non_void.json new file mode 100644 index 000000000..44fc4fdb5 --- /dev/null +++ b/src/__fixtures__/Events/07d-end_slash--non_void.json @@ -0,0 +1,48 @@ +{ + "name": "end slash: non-void element ending with />", + "input": "

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] + } + ] +} diff --git a/src/__fixtures__/Events/07e-end_slash--non_void--xmlmode.json b/src/__fixtures__/Events/07e-end_slash--non_void--xmlmode.json new file mode 100644 index 000000000..a3144f095 --- /dev/null +++ b/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": "

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] + } + ] +} diff --git a/src/__fixtures__/Events/07f-end_slash--non_void--recognize_self_closing.json b/src/__fixtures__/Events/07f-end_slash--non_void--recognize_self_closing.json new file mode 100644 index 000000000..623dafd49 --- /dev/null +++ b/src/__fixtures__/Events/07f-end_slash--non_void--recognize_self_closing.json @@ -0,0 +1,53 @@ +{ + "name": "end slash: non-void element ending with />, recognizeSelfClosing=true", + "input": "

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] + } + ] +} diff --git a/src/__fixtures__/Events/07g-end_slash--consumed_by_attrib_value_in_void.json b/src/__fixtures__/Events/07g-end_slash--consumed_by_attrib_value_in_void.json new file mode 100644 index 000000000..03acab400 --- /dev/null +++ b/src/__fixtures__/Events/07g-end_slash--consumed_by_attrib_value_in_void.json @@ -0,0 +1,54 @@ +{ + "name": "end slash: as part of attrib value of void element", + "input": "

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] + } + ] +} diff --git a/src/__fixtures__/Events/07-self-closing.json b/src/__fixtures__/Events/07h-end_slash--consumed_by_attrib_value_in_non_void.json similarity index 63% rename from src/__fixtures__/Events/07-self-closing.json rename to src/__fixtures__/Events/07h-end_slash--consumed_by_attrib_value_in_non_void.json index d3d1c3392..2ae995955 100644 --- a/src/__fixtures__/Events/07-self-closing.json +++ b/src/__fixtures__/Events/07h-end_slash--consumed_by_attrib_value_in_non_void.json @@ -1,6 +1,6 @@ { - "name": "Self-closing tags", - "input": "Foo


", + "name": "end slash: as part of attrib value of non-void element", + "input": "Foo

Hold the line.", "expected": [ { "event": "opentagname", @@ -18,13 +18,7 @@ "event": "opentag", "startIndex": 0, "endIndex": 24, - "data": [ - "a", - { - "href": "http://test.com/" - }, - false - ] + "data": ["a", {"href": "http://test.com/"}, false] }, { "event": "text", @@ -41,20 +35,26 @@ { "event": "opentagname", "startIndex": 32, - "endIndex": 35, - "data": ["hr"] + "endIndex": 34, + "data": ["p"] }, { "event": "opentag", "startIndex": 32, - "endIndex": 38, - "data": ["hr", {}, false] + "endIndex": 34, + "data": ["p", {}, false] + }, + { + "event": "text", + "startIndex": 35, + "endIndex": 48, + "data": ["Hold the line."] }, { "event": "closetag", - "startIndex": 32, - "endIndex": 38, - "data": ["hr", true] + "startIndex": 49, + "endIndex": 49, + "data": ["p", true] } ] }