Skip to content

Commit

Permalink
tests covering token types
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Jun 17, 2013
1 parent 52fda49 commit f32e3cd
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions packages/html5-tokenizer/tokenizer_tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
Tinytest.add("html5-tokenizer - basic", function (test) {

test.equal(HTML5Tokenizer.tokenize('<p>foo'),
[ { type: 'StartTag', name: 'p', data: [] },
{ type: 'Characters', data: 'foo' },
{ type: 'EOF', data: 'End of File' } ]);
var run = function (input, expectedTokens) {
test.equal(HTML5Tokenizer.tokenize(input),
expectedTokens);
};

run('<p>foo',
[ { type: 'StartTag', name: 'p', data: [] },
{ type: 'Characters', data: 'foo' },
{ type: 'EOF', data: 'End of File' } ]);

run('<!DOCTYPE html>',
[ { type: 'Doctype', name: 'html', correct: true,
publicId: null, systemId: null },
{ type: 'EOF', data: 'End of File' } ]);

run('<a b c=d> </a>',
[ { type: 'StartTag', name: 'a',
data: [{nodeName: 'b', nodeValue: ''},
{nodeName: 'c', nodeValue: 'd'}] },
{ type: 'SpaceCharacters', data: ' ' },
{ type: 'EndTag', name: 'a', data: [] },
{ type: 'EOF', data: 'End of File' } ]);

run('<3',
[{ type: 'ParseError', data: 'expected-tag-name' },
{ type: 'Characters', data: '<' },
{ type: 'Characters', data: '3' },
{ type: 'EOF', data: 'End of File' } ]);

run('<!--foo-->',
[{ type: 'Comment', data: 'foo' },
{ type: 'EOF', data: 'End of File' } ]);

});

0 comments on commit f32e3cd

Please sign in to comment.