-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { SaxEventType, SAXParser, Text } from '../saxWasm'; | ||
import { readFileSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
import { deepStrictEqual, strictEqual } from 'assert'; | ||
|
||
const saxWasm = readFileSync(resolve(__dirname, '../../../lib/sax-wasm.wasm')); | ||
describe('When parsing XML, the SaxWasm', () => { | ||
let parser: SAXParser; | ||
let _event: SaxEventType; | ||
let _data: Text[]; | ||
|
||
before(async () => { | ||
parser = new SAXParser(SaxEventType.Doctype); | ||
_data = []; | ||
_event = 0; | ||
|
||
parser.eventHandler = function (event, data) { | ||
_event = event; | ||
_data.push(data as Text); | ||
}; | ||
return parser.prepareWasm(saxWasm); | ||
}); | ||
|
||
beforeEach(() => { | ||
_data = []; | ||
}); | ||
|
||
afterEach(() => { | ||
parser.end(); | ||
}); | ||
|
||
it('should report DOCTYPE (upper case) correctly', () => { | ||
parser.write(Buffer.from('<!DOCTYPE html>\n<body><div>Hello HTML!</div></body>')); | ||
const {start, end, value} = _data[0]; | ||
deepStrictEqual(JSON.parse(JSON.stringify(start)), { line: 0, character: 2 }); | ||
deepStrictEqual(JSON.parse(JSON.stringify(end)), { line: 0, character: 14 }); | ||
strictEqual(value, 'html'); | ||
}); | ||
|
||
it('should report doctype (lower case) correctly', () => { | ||
parser.write(Buffer.from('<!doctype html>\n<body><div>Hello HTML!</div></body>')); | ||
const {start, end, value} = _data[0]; | ||
deepStrictEqual(JSON.parse(JSON.stringify(start)), { line: 0, character: 2 }); | ||
deepStrictEqual(JSON.parse(JSON.stringify(end)), { line: 0, character: 14 }); | ||
strictEqual(value, 'html'); | ||
}); | ||
|
||
it('should report DocType (mixed case) correctly', () => { | ||
parser.write(Buffer.from('<!DocType html>\n<body><div>Hello HTML!</div></body>')); | ||
const {start, end, value} = _data[0]; | ||
deepStrictEqual(JSON.parse(JSON.stringify(start)), { line: 0, character: 2 }); | ||
deepStrictEqual(JSON.parse(JSON.stringify(end)), { line: 0, character: 14 }); | ||
strictEqual(value, 'html'); | ||
}); | ||
}); |
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