1 | var sax = require("../lib/sax"),
|
2 | assert = require("assert")
|
3 |
|
4 | function testPosition(chunks, expectedEvents) {
|
5 | var parser = sax.parser();
|
6 | expectedEvents.forEach(function(expectation) {
|
7 | parser['on' + expectation[0]] = function() {
|
8 | for (var prop in expectation[1]) {
|
9 | assert.equal(parser[prop], expectation[1][prop]);
|
10 | }
|
11 | }
|
12 | });
|
13 | chunks.forEach(function(chunk) {
|
14 | parser.write(chunk);
|
15 | });
|
16 | };
|
17 |
|
18 | testPosition(['<div>abcdefgh</div>'],
|
19 | [ ['opentag', { position: 5, startTagPosition: 1 }]
|
20 | , ['text', { position: 19, startTagPosition: 14 }]
|
21 | , ['closetag', { position: 19, startTagPosition: 14 }]
|
22 | ]);
|
23 |
|
24 | testPosition(['<div>abcde','fgh</div>'],
|
25 | [ ['opentag', { position: 5, startTagPosition: 1 }]
|
26 | , ['text', { position: 19, startTagPosition: 14 }]
|
27 | , ['closetag', { position: 19, startTagPosition: 14 }]
|
28 | ]);
|