Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
var htmlparser2 = require(".."),
2
assert = require("assert");
3
4
describe("API", function(){
5
6
it("should load all modules", function(){
7
var Stream = require("../lib/Stream.js");
8
assert.strictEqual(htmlparser2.Stream, Stream, "should load module");
9
assert.strictEqual(htmlparser2.Stream, Stream, "should load it again (cache)");
10
11
var ProxyHandler = require("../lib/ProxyHandler.js");
12
assert.strictEqual(htmlparser2.ProxyHandler, ProxyHandler, "should load module");
13
assert.strictEqual(htmlparser2.ProxyHandler, ProxyHandler, "should load it again (cache)");
14
});
15
16
it("should work without callbacks", function(){
17
var p = new htmlparser2.Parser(null, {xmlMode: true, lowerCaseAttributeNames: true});
18
19
p.end("<a foo><bar></a><!-- --><![CDATA[]]]><?foo?><!bar><boo/>boohay");
20
p.write("foo");
21
22
//check for an error
23
p.end();
24
var err = false;
25
p._cbs.onerror = function(){ err = true; };
26
p.write("foo");
27
assert(err);
28
err = false;
29
p.end();
30
assert(err);
31
32
p.reset();
33
34
//remove method
35
p._cbs.onopentag = function(){};
36
p.write("<a foo");
37
p._cbs.onopentag = null;
38
p.write(">");
39
40
//pause/resume
41
var processed = false;
42
p._cbs.ontext = function(t){
43
assert.equal(t, "foo");
44
processed = true;
45
};
46
p.pause();
47
p.write("foo");
48
assert(!processed);
49
p.resume();
50
assert(processed);
51
processed = false;
52
p.pause();
53
assert(!processed);
54
p.resume();
55
assert(!processed);
56
p.pause();
57
p.end("foo");
58
assert(!processed);
59
p.resume();
60
assert(processed);
61
62
});
63
64
it("should update the position", function(){
65
var p = new htmlparser2.Parser(null);
66
67
p.write("foo");
68
69
assert.equal(p.startIndex, 0);
70
71
p.write("<bar>");
72
73
assert.equal(p.startIndex, 3);
74
});
75
});
76