tests: update Events/07 test to clarify interpretation of tag end slashes #1046
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains suggested enhancements to the
Events/07-self-closing.json
test.It also suggests a testing strategy that can be applied in other cases: a set of tests 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.
No worries if this isn't merged. Also happy to make any changes desired changes.
Test 07 enhancements
The original
07-self-closing.json
covered two cases:a tag ending in
/>
but where the/
is in fact part of the attribute value -- thus not a self-closing tagan HTML void element,
<hr>
, in XHTML self-closing style.One flaw with this test is that
hr
is also a void element: While the test passes because the expectedclosetag
event occurs, one doesn't know if it occurs because of the end slash or because it is a void element.The test
07-self-closing.json
only included a self-closing tag for a void element. This made the test ambiguous in purpose if you didn't know that htmlparser2 followed the above distinction.The new
07a
to07h
tests cover much more:base name for all these tests is "end slash" rather than "self-closing" because what's being tested is how that end slash is interpreted in different contexts, e.g. as the mark of a self-closing tag, a part of the attribute, or ignored entirely.
each of the 8 tests represents one isolated change compared to one or more of the others:
xmlMode
off vs onrecognizeSelfClosing
off vs onThis allows one to diff the event streams to see the effect of that isolated change. For example, you can compare:
<hr/>
generates aclosetag
event while<xx/>
does not. The former is a void element and the latter is not.recognizeSelfClosing
test coverage and test demonstrated semanticsThis option was introduced in #74 but without any tests nor any documentation.
I confirmed there is no test coverage by:
Temporarily adding the following line to
Parser.ts
's constructor:Ran the tests. No tests failed. The above change inverted the option for every test, and would have caused any test covering this option to fail.
I added coverage via case
07f
There is no clear documentation on the semantics of
recognizeSelfClosing
, but based on the new07
tests and diffing their outputs, I was able to surmise the following: