Skip to content

Commit

Permalink
Make tokenizer state a const enum again
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Jan 13, 2022
1 parent 9c73b72 commit 5ba2990
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/parse5/lib/tokenizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const C1_CONTROLS_REFERENCE_REPLACEMENTS = new Map([
const HIBERNATION_TOKEN: Token = { type: TokenType.HIBERNATION, location: null };

//States
export enum State {
const enum State {
DATA,
RCDATA,
RAWTEXT,
Expand Down
16 changes: 8 additions & 8 deletions test/utils/generate-tokenization-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'node:assert';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { Tokenizer, TokenizerMode, State as TokenizerState } from 'parse5/dist/tokenizer/index.js';
import { Tokenizer, TokenizerMode } from 'parse5/dist/tokenizer/index.js';
import { makeChunks } from './common.js';
import { TokenType, Token } from 'parse5/dist/common/token.js';

Expand Down Expand Up @@ -151,6 +151,7 @@ interface LoadedTest {
input: string;
expected: HtmlLibToken[];
initialState: Tokenizer['state'];
initialStateName: string;
lastStartTag: string;
expectedErrors: string[];
}
Expand Down Expand Up @@ -187,14 +188,15 @@ function loadTests(dataDirPath: string): LoadedTest[] {

const expected = descr.output;

for (const initialState of descr.initialStates) {
for (const initialStateName of descr.initialStates) {
tests.push({
idx: ++testIdx,
setName,
name: descr.description,
input: descr.input,
expected: concatCharacterTokens(expected),
initialState: getTokenizerSuitableStateName(initialState),
initialState: getTokenizerSuitableStateName(initialStateName),
initialStateName,
lastStartTag: descr.lastStartTag,
expectedErrors: descr.errors || [],
});
Expand All @@ -212,16 +214,14 @@ export function generateTokenizationTests(
createTokenSource: TokenSourceCreator
): void {
for (const testData of loadTests(testSuite)) {
const testName = `${prefix} - ${testData.idx}.${testData.setName} - ${testData.name} - Initial state: ${
TokenizerState[testData.initialState]
}`;
const testName = `${prefix} - ${testData.idx}.${testData.setName} - ${testData.name} - Initial state: ${testData.initialStateName}`;

it(testName, () => {
const chunks = makeChunks(testData.input);
const result = tokenize(
createTokenSource,
chunks,
testData.initialState as TokenizerState,
testData.initialState as Tokenizer['state'],
testData.lastStartTag
);

Expand All @@ -234,7 +234,7 @@ export function generateTokenizationTests(
*/
if (
testName ===
'Tokenizer - 57.entities - Undefined named entity in attribute value ending in semicolon and whose name starts with a known entity name. - Initial state: DATA'
'Tokenizer - 57.entities - Undefined named entity in attribute value ending in semicolon and whose name starts with a known entity name. - Initial state: Data state'
) {
assert.deepEqual(result.errors, [{ code: 'unknown-named-character-reference', col: 12, line: 1 }]);
} else {
Expand Down

0 comments on commit 5ba2990

Please sign in to comment.