-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve code coverage (#517)
- Loading branch information
Showing
11 changed files
with
128 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,51 @@ | ||
import { Tokenizer } from 'parse5'; | ||
import { generateTokenizationTests } from 'parse5-test-utils/utils/generate-tokenization-tests.js'; | ||
import * as assert from 'node:assert'; | ||
|
||
const dataPath = new URL('../../../../test/data/html5lib-tests/tokenizer', import.meta.url); | ||
const tokenizerOpts = { | ||
sourceCodeLocationInfo: true, | ||
}; | ||
|
||
generateTokenizationTests('Tokenizer', dataPath.pathname, (handler) => new Tokenizer(tokenizerOpts, handler)); | ||
|
||
function noop(): void { | ||
// Noop | ||
} | ||
|
||
describe('Tokenizer methods', () => { | ||
it('should pause and resume', () => { | ||
let count = 0; | ||
const tokenizer = new Tokenizer(tokenizerOpts, { | ||
onComment(t): void { | ||
assert.strictEqual(t.data, 'INIT'); | ||
assert.strictEqual(count++, 0); | ||
|
||
tokenizer.pause(); | ||
tokenizer.write('<!doctype foo>', false); | ||
}, | ||
onDoctype(t): void { | ||
assert.strictEqual(t.name, 'foo'); | ||
assert.strictEqual(count++, 2); | ||
|
||
expect(() => tokenizer.resume()).toThrow('Parser was already resumed'); | ||
tokenizer.write('<next>', true); | ||
}, | ||
onStartTag(t): void { | ||
assert.strictEqual(count++, 3); | ||
assert.strictEqual(t.tagName, 'next'); | ||
}, | ||
onEndTag: noop, | ||
onEof: noop, | ||
onCharacter: noop, | ||
onNullCharacter: noop, | ||
onWhitespaceCharacter: noop, | ||
}); | ||
|
||
tokenizer.write('<!--INIT-->', false); | ||
assert.strictEqual(count++, 1); | ||
expect(tokenizer).toHaveProperty('paused', true); | ||
|
||
tokenizer.resume(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters