sax 1.1.0 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -32
- package/lib/sax.js +1450 -1317
- package/package.json +16 -4
- package/AUTHORS +0 -10
- package/CONTRIBUTING.md +0 -14
- package/examples/big-not-pretty.xml +0 -8002
- package/examples/example.js +0 -29
- package/examples/get-products.js +0 -58
- package/examples/hello-world.js +0 -4
- package/examples/not-pretty.xml +0 -8
- package/examples/pretty-print.js +0 -74
- package/examples/shopping.xml +0 -2
- package/examples/strict.dtd +0 -870
- package/examples/test.html +0 -15
- package/examples/test.xml +0 -1254
- package/test/attribute-name.js +0 -33
- package/test/attribute-no-space.js +0 -75
- package/test/bom.js +0 -44
- package/test/buffer-overrun.js +0 -26
- package/test/case.js +0 -50
- package/test/cdata-chunked.js +0 -11
- package/test/cdata-end-split.js +0 -15
- package/test/cdata-fake-end.js +0 -28
- package/test/cdata-multiple.js +0 -15
- package/test/cdata.js +0 -10
- package/test/cyrillic.js +0 -8
- package/test/duplicate-attribute.js +0 -13
- package/test/emoji.js +0 -12
- package/test/end_empty_stream.js +0 -5
- package/test/entities.js +0 -10
- package/test/entity-mega.js +0 -16
- package/test/flush.js +0 -13
- package/test/index.js +0 -86
- package/test/issue-23.js +0 -43
- package/test/issue-30.js +0 -24
- package/test/issue-35.js +0 -15
- package/test/issue-47.js +0 -12
- package/test/issue-49.js +0 -31
- package/test/issue-84.js +0 -13
- package/test/issue-86.js +0 -30
- package/test/parser-position.js +0 -28
- package/test/script-close-better.js +0 -12
- package/test/script.js +0 -12
- package/test/self-closing-child-strict.js +0 -44
- package/test/self-closing-child.js +0 -44
- package/test/self-closing-tag.js +0 -25
- package/test/stand-alone-comment.js +0 -11
- package/test/stray-ending.js +0 -17
- package/test/trailing-attribute-no-value.js +0 -10
- package/test/trailing-non-whitespace.js +0 -18
- package/test/unclosed-root.js +0 -11
- package/test/unquoted.js +0 -18
- package/test/utf8-split.js +0 -34
- package/test/xml_entities.js +0 -11
- package/test/xmlns-as-tag-name.js +0 -15
- package/test/xmlns-issue-41.js +0 -68
- package/test/xmlns-rebinding.js +0 -63
- package/test/xmlns-strict.js +0 -74
- package/test/xmlns-unbound-element.js +0 -33
- package/test/xmlns-unbound.js +0 -15
- package/test/xmlns-xml-default-ns.js +0 -31
- package/test/xmlns-xml-default-prefix-attribute.js +0 -36
- package/test/xmlns-xml-default-prefix.js +0 -21
- package/test/xmlns-xml-default-redefine.js +0 -41
package/test/attribute-name.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require(__dirname).test(
|
|
2
|
-
{ xml: "<root length='12345'></root>"
|
|
3
|
-
, expect: [
|
|
4
|
-
["attribute", {
|
|
5
|
-
name: "length"
|
|
6
|
-
, value: "12345"
|
|
7
|
-
, prefix: ""
|
|
8
|
-
, local: "length"
|
|
9
|
-
, uri: ""
|
|
10
|
-
}]
|
|
11
|
-
, ["opentag", {
|
|
12
|
-
name: "root"
|
|
13
|
-
, prefix: ""
|
|
14
|
-
, local: "root"
|
|
15
|
-
, uri: ""
|
|
16
|
-
, attributes: {
|
|
17
|
-
length: {
|
|
18
|
-
name: "length"
|
|
19
|
-
, value: "12345"
|
|
20
|
-
, prefix: ""
|
|
21
|
-
, local: "length"
|
|
22
|
-
, uri: ""
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
, ns: {}
|
|
26
|
-
, isSelfClosing: false
|
|
27
|
-
}]
|
|
28
|
-
, ["closetag", "root"]
|
|
29
|
-
]
|
|
30
|
-
, strict: true
|
|
31
|
-
, opt: { xmlns: true }
|
|
32
|
-
}
|
|
33
|
-
)
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// non-strict: no error
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : '<root attr1="first"attr2="second"/>'
|
|
4
|
-
|
|
5
|
-
, expect :
|
|
6
|
-
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
7
|
-
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
8
|
-
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
9
|
-
, [ "closetag", "root" ]
|
|
10
|
-
]
|
|
11
|
-
, strict : false
|
|
12
|
-
, opt : { lowercase: true }
|
|
13
|
-
}
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
// strict: should give an error, but still parse
|
|
17
|
-
require(__dirname).test
|
|
18
|
-
( { xml : '<root attr1="first"attr2="second"/>'
|
|
19
|
-
|
|
20
|
-
, expect :
|
|
21
|
-
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
22
|
-
, [ "error", "No whitespace between attributes\nLine: 0\nColumn: 20\nChar: a" ]
|
|
23
|
-
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
24
|
-
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
25
|
-
, [ "closetag", "root" ]
|
|
26
|
-
]
|
|
27
|
-
, strict : true
|
|
28
|
-
, opt : { }
|
|
29
|
-
}
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
// strict: other cases should still pass
|
|
33
|
-
require(__dirname).test
|
|
34
|
-
( { xml : '<root attr1="first" attr2="second"/>'
|
|
35
|
-
|
|
36
|
-
, expect :
|
|
37
|
-
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
38
|
-
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
39
|
-
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
40
|
-
, [ "closetag", "root" ]
|
|
41
|
-
]
|
|
42
|
-
, strict : true
|
|
43
|
-
, opt : { }
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
// strict: other cases should still pass
|
|
48
|
-
require(__dirname).test
|
|
49
|
-
( { xml : '<root attr1="first"\nattr2="second"/>'
|
|
50
|
-
|
|
51
|
-
, expect :
|
|
52
|
-
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
53
|
-
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
54
|
-
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
55
|
-
, [ "closetag", "root" ]
|
|
56
|
-
]
|
|
57
|
-
, strict : true
|
|
58
|
-
, opt : { }
|
|
59
|
-
}
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
// strict: other cases should still pass
|
|
63
|
-
require(__dirname).test
|
|
64
|
-
( { xml : '<root attr1="first" attr2="second"/>'
|
|
65
|
-
|
|
66
|
-
, expect :
|
|
67
|
-
[ [ "attribute", { name: 'attr1', value: 'first' } ]
|
|
68
|
-
, [ "attribute", { name: 'attr2', value: 'second' } ]
|
|
69
|
-
, [ "opentag", { name: "root", attributes: {attr1: 'first', attr2: 'second'}, isSelfClosing: true } ]
|
|
70
|
-
, [ "closetag", "root" ]
|
|
71
|
-
]
|
|
72
|
-
, strict : true
|
|
73
|
-
, opt : { }
|
|
74
|
-
}
|
|
75
|
-
)
|
package/test/bom.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// BOM at the very begining of the stream should be ignored
|
|
2
|
-
require(__dirname).test({
|
|
3
|
-
xml: '\uFEFF<P></P>',
|
|
4
|
-
expect: [
|
|
5
|
-
['opentag', {'name':'P', attributes:{}, isSelfClosing: false}],
|
|
6
|
-
['closetag', 'P']
|
|
7
|
-
]
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
// In all other places it should be consumed
|
|
11
|
-
require(__dirname).test({
|
|
12
|
-
xml: '\uFEFF<P BOM="\uFEFF">\uFEFFStarts and ends with BOM\uFEFF</P>',
|
|
13
|
-
expect: [
|
|
14
|
-
['attribute', {'name':'BOM', 'value':'\uFEFF'}],
|
|
15
|
-
['opentag', {'name':'P', attributes:{'BOM':'\uFEFF'}, isSelfClosing: false}],
|
|
16
|
-
['text', '\uFEFFStarts and ends with BOM\uFEFF'],
|
|
17
|
-
['closetag', 'P']
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// BOM after a whitespace is an error
|
|
22
|
-
require(__dirname).test({
|
|
23
|
-
xml: ' \uFEFF<P></P>',
|
|
24
|
-
expect: [
|
|
25
|
-
['error', 'Non-whitespace before first tag.\nLine: 0\nColumn: 2\nChar: \uFEFF'],
|
|
26
|
-
['text', '\uFEFF'],
|
|
27
|
-
['opentag', {'name': 'P', attributes: {}, isSelfClosing: false}],
|
|
28
|
-
['closetag', 'P'],
|
|
29
|
-
],
|
|
30
|
-
strict: true
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// There is only one BOM allowed at the start
|
|
34
|
-
require(__dirname).test({
|
|
35
|
-
xml: '\uFEFF\uFEFF<P></P>',
|
|
36
|
-
expect: [
|
|
37
|
-
['error', 'Non-whitespace before first tag.\nLine: 0\nColumn: 2\nChar: \uFEFF'],
|
|
38
|
-
['text', '\uFEFF'],
|
|
39
|
-
['opentag', {'name': 'P', attributes: {}, isSelfClosing: false}],
|
|
40
|
-
['closetag', 'P'],
|
|
41
|
-
],
|
|
42
|
-
strict: true
|
|
43
|
-
});
|
|
44
|
-
|
package/test/buffer-overrun.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// set this really low so that I don't have to put 64 MB of xml in here.
|
|
2
|
-
var sax = require("../lib/sax")
|
|
3
|
-
var bl = sax.MAX_BUFFER_LENGTH
|
|
4
|
-
sax.MAX_BUFFER_LENGTH = 5;
|
|
5
|
-
|
|
6
|
-
require(__dirname).test({
|
|
7
|
-
expect : [
|
|
8
|
-
["error", "Max buffer length exceeded: tagName\nLine: 0\nColumn: 15\nChar: "],
|
|
9
|
-
["error", "Max buffer length exceeded: tagName\nLine: 0\nColumn: 30\nChar: "],
|
|
10
|
-
["error", "Max buffer length exceeded: tagName\nLine: 0\nColumn: 45\nChar: "],
|
|
11
|
-
["opentag", {
|
|
12
|
-
"name": "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
13
|
-
"attributes": {},
|
|
14
|
-
"isSelfClosing": false
|
|
15
|
-
}],
|
|
16
|
-
["text", "yo"],
|
|
17
|
-
["closetag", "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
|
18
|
-
]
|
|
19
|
-
}).write("<abcdefghijklmn")
|
|
20
|
-
.write("opqrstuvwxyzABC")
|
|
21
|
-
.write("DEFGHIJKLMNOPQR")
|
|
22
|
-
.write("STUVWXYZ>")
|
|
23
|
-
.write("yo")
|
|
24
|
-
.write("</abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ>")
|
|
25
|
-
.close();
|
|
26
|
-
sax.MAX_BUFFER_LENGTH = bl
|
package/test/case.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// default to uppercase
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml :
|
|
4
|
-
"<span class=\"test\" hello=\"world\"></span>"
|
|
5
|
-
, expect :
|
|
6
|
-
[ [ "attribute", { name: "CLASS", value: "test" } ]
|
|
7
|
-
, [ "attribute", { name: "HELLO", value: "world" } ]
|
|
8
|
-
, [ "opentag", { name: "SPAN",
|
|
9
|
-
attributes: { CLASS: "test", HELLO: "world" },
|
|
10
|
-
isSelfClosing: false } ]
|
|
11
|
-
, [ "closetag", "SPAN" ]
|
|
12
|
-
]
|
|
13
|
-
, strict : false
|
|
14
|
-
, opt : {}
|
|
15
|
-
}
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
// lowercase option : lowercase tag/attribute names
|
|
19
|
-
require(__dirname).test
|
|
20
|
-
( { xml :
|
|
21
|
-
"<span class=\"test\" hello=\"world\"></span>"
|
|
22
|
-
, expect :
|
|
23
|
-
[ [ "attribute", { name: "class", value: "test" } ]
|
|
24
|
-
, [ "attribute", { name: "hello", value: "world" } ]
|
|
25
|
-
, [ "opentag", { name: "span",
|
|
26
|
-
attributes: { class: "test", hello: "world" },
|
|
27
|
-
isSelfClosing: false } ]
|
|
28
|
-
, [ "closetag", "span" ]
|
|
29
|
-
]
|
|
30
|
-
, strict : false
|
|
31
|
-
, opt : {lowercase:true}
|
|
32
|
-
}
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// backward compatibility with old lowercasetags opt
|
|
36
|
-
require(__dirname).test
|
|
37
|
-
( { xml :
|
|
38
|
-
"<span class=\"test\" hello=\"world\"></span>"
|
|
39
|
-
, expect :
|
|
40
|
-
[ [ "attribute", { name: "class", value: "test" } ]
|
|
41
|
-
, [ "attribute", { name: "hello", value: "world" } ]
|
|
42
|
-
, [ "opentag", { name: "span",
|
|
43
|
-
attributes: { class: "test", hello: "world" },
|
|
44
|
-
isSelfClosing: false } ]
|
|
45
|
-
, [ "closetag", "span" ]
|
|
46
|
-
]
|
|
47
|
-
, strict : false
|
|
48
|
-
, opt : {lowercasetags:true}
|
|
49
|
-
}
|
|
50
|
-
)
|
package/test/cdata-chunked.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require(__dirname).test({
|
|
3
|
-
expect : [
|
|
4
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
5
|
-
["opencdata", undefined],
|
|
6
|
-
["cdata", " this is character data "],
|
|
7
|
-
["closecdata", undefined],
|
|
8
|
-
["closetag", "R"]
|
|
9
|
-
]
|
|
10
|
-
}).write("<r><![CDATA[ this is ").write("character data ").write("]]></r>").close();
|
|
11
|
-
|
package/test/cdata-end-split.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require(__dirname).test({
|
|
3
|
-
expect : [
|
|
4
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
5
|
-
["opencdata", undefined],
|
|
6
|
-
["cdata", " this is "],
|
|
7
|
-
["closecdata", undefined],
|
|
8
|
-
["closetag", "R"]
|
|
9
|
-
]
|
|
10
|
-
})
|
|
11
|
-
.write("<r><![CDATA[ this is ]")
|
|
12
|
-
.write("]>")
|
|
13
|
-
.write("</r>")
|
|
14
|
-
.close();
|
|
15
|
-
|
package/test/cdata-fake-end.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var p = require(__dirname).test({
|
|
3
|
-
expect : [
|
|
4
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
5
|
-
["opencdata", undefined],
|
|
6
|
-
["cdata", "[[[[[[[[]]]]]]]]"],
|
|
7
|
-
["closecdata", undefined],
|
|
8
|
-
["closetag", "R"]
|
|
9
|
-
]
|
|
10
|
-
})
|
|
11
|
-
var x = "<r><![CDATA[[[[[[[[[]]]]]]]]]]></r>"
|
|
12
|
-
for (var i = 0; i < x.length ; i ++) {
|
|
13
|
-
p.write(x.charAt(i))
|
|
14
|
-
}
|
|
15
|
-
p.close();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var p2 = require(__dirname).test({
|
|
19
|
-
expect : [
|
|
20
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
21
|
-
["opencdata", undefined],
|
|
22
|
-
["cdata", "[[[[[[[[]]]]]]]]"],
|
|
23
|
-
["closecdata", undefined],
|
|
24
|
-
["closetag", "R"]
|
|
25
|
-
]
|
|
26
|
-
})
|
|
27
|
-
var x = "<r><![CDATA[[[[[[[[[]]]]]]]]]]></r>"
|
|
28
|
-
p2.write(x).close();
|
package/test/cdata-multiple.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require(__dirname).test({
|
|
3
|
-
expect : [
|
|
4
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
5
|
-
["opencdata", undefined],
|
|
6
|
-
["cdata", " this is "],
|
|
7
|
-
["closecdata", undefined],
|
|
8
|
-
["opencdata", undefined],
|
|
9
|
-
["cdata", "character data "],
|
|
10
|
-
["closecdata", undefined],
|
|
11
|
-
["closetag", "R"]
|
|
12
|
-
]
|
|
13
|
-
}).write("<r><![CDATA[ this is ]]>").write("<![CDA").write("T").write("A[")
|
|
14
|
-
.write("character data ").write("]]></r>").close();
|
|
15
|
-
|
package/test/cdata.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require(__dirname).test({
|
|
2
|
-
xml : "<r><![CDATA[ this is character data ]]></r>",
|
|
3
|
-
expect : [
|
|
4
|
-
["opentag", {"name": "R","attributes": {}, "isSelfClosing": false}],
|
|
5
|
-
["opencdata", undefined],
|
|
6
|
-
["cdata", " this is character data "],
|
|
7
|
-
["closecdata", undefined],
|
|
8
|
-
["closetag", "R"]
|
|
9
|
-
]
|
|
10
|
-
});
|
package/test/cyrillic.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require(__dirname).test
|
|
2
|
-
( { xml :
|
|
3
|
-
"<span id=\"hello\" id=\"there\"></span>"
|
|
4
|
-
, expect :
|
|
5
|
-
[ [ "attribute", { name: "ID", value: "hello" } ]
|
|
6
|
-
, [ "opentag", { name: "SPAN",
|
|
7
|
-
attributes: { ID: "hello" }, isSelfClosing: false } ]
|
|
8
|
-
, [ "closetag", "SPAN" ]
|
|
9
|
-
]
|
|
10
|
-
, strict : false
|
|
11
|
-
, opt : {}
|
|
12
|
-
}
|
|
13
|
-
)
|
package/test/emoji.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// split high-order numeric attributes into surrogate pairs
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : '<a>🔥</a>'
|
|
4
|
-
, expect :
|
|
5
|
-
[ [ 'opentag', { name: 'A', attributes: {}, isSelfClosing: false } ]
|
|
6
|
-
, [ 'text', '\ud83d\udd25' ]
|
|
7
|
-
, [ 'closetag', 'A' ]
|
|
8
|
-
]
|
|
9
|
-
, strict : false
|
|
10
|
-
, opt : {}
|
|
11
|
-
}
|
|
12
|
-
)
|
package/test/end_empty_stream.js
DELETED
package/test/entities.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require(__dirname).test({
|
|
2
|
-
xml: '<r>⌋ ' +
|
|
3
|
-
'♠ © → & ' +
|
|
4
|
-
'< < < < < > ℜ ℘ €</r>',
|
|
5
|
-
expect: [
|
|
6
|
-
['opentag', {'name':'R', attributes:{}, isSelfClosing: false}],
|
|
7
|
-
['text', '⌋ ♠ © → & < < < < < > ℜ ℘ €'],
|
|
8
|
-
['closetag', 'R']
|
|
9
|
-
]
|
|
10
|
-
});
|
package/test/entity-mega.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var sax = require('../');
|
|
2
|
-
var xml = '<r>';
|
|
3
|
-
var text = '';
|
|
4
|
-
for (var i in sax.ENTITIES) {
|
|
5
|
-
xml += '&' + i + ';'
|
|
6
|
-
text += sax.ENTITIES[i]
|
|
7
|
-
}
|
|
8
|
-
xml += '</r>'
|
|
9
|
-
require(__dirname).test({
|
|
10
|
-
xml: xml,
|
|
11
|
-
expect: [
|
|
12
|
-
['opentag', {'name':'R', attributes:{}, isSelfClosing: false}],
|
|
13
|
-
['text', text],
|
|
14
|
-
['closetag', 'R']
|
|
15
|
-
]
|
|
16
|
-
});
|
package/test/flush.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var parser = require(__dirname).test({
|
|
2
|
-
expect: [
|
|
3
|
-
['opentag', {'name':'T', attributes:{}, isSelfClosing: false}],
|
|
4
|
-
['text', 'flush'],
|
|
5
|
-
['text', 'rest'],
|
|
6
|
-
['closetag', 'T'],
|
|
7
|
-
]
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
parser.write('<T>flush');
|
|
11
|
-
parser.flush();
|
|
12
|
-
parser.write('rest</T>');
|
|
13
|
-
parser.close();
|
package/test/index.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
var globalsBefore = JSON.stringify(Object.keys(global))
|
|
2
|
-
, util = require("util")
|
|
3
|
-
, assert = require("assert")
|
|
4
|
-
, fs = require("fs")
|
|
5
|
-
, path = require("path")
|
|
6
|
-
, sax = require("../lib/sax")
|
|
7
|
-
|
|
8
|
-
exports.sax = sax
|
|
9
|
-
|
|
10
|
-
// handy way to do simple unit tests
|
|
11
|
-
// if the options contains an xml string, it'll be written and the parser closed.
|
|
12
|
-
// otherwise, it's assumed that the test will write and close.
|
|
13
|
-
exports.test = function test (options) {
|
|
14
|
-
var xml = options.xml
|
|
15
|
-
, parser = sax.parser(options.strict, options.opt)
|
|
16
|
-
, expect = options.expect
|
|
17
|
-
, e = 0
|
|
18
|
-
sax.EVENTS.forEach(function (ev) {
|
|
19
|
-
parser["on" + ev] = function (n) {
|
|
20
|
-
if (process.env.DEBUG) {
|
|
21
|
-
console.error({ expect: expect[e]
|
|
22
|
-
, actual: [ev, n] })
|
|
23
|
-
}
|
|
24
|
-
if (e >= expect.length && (ev === "end" || ev === "ready")) return
|
|
25
|
-
assert.ok( e < expect.length,
|
|
26
|
-
"expectation #"+e+" "+util.inspect(expect[e])+"\n"+
|
|
27
|
-
"Unexpected event: "+ev+" "+(n ? util.inspect(n) : ""))
|
|
28
|
-
var inspected = n instanceof Error ? "\n"+ n.message : util.inspect(n)
|
|
29
|
-
assert.equal(ev, expect[e][0],
|
|
30
|
-
"expectation #"+e+"\n"+
|
|
31
|
-
"Didn't get expected event\n"+
|
|
32
|
-
"expect: "+expect[e][0] + " " +util.inspect(expect[e][1])+"\n"+
|
|
33
|
-
"actual: "+ev+" "+inspected+"\n")
|
|
34
|
-
if (ev === "error") assert.equal(n.message, expect[e][1])
|
|
35
|
-
else assert.deepEqual(n, expect[e][1],
|
|
36
|
-
"expectation #"+e+"\n"+
|
|
37
|
-
"Didn't get expected argument\n"+
|
|
38
|
-
"expect: "+expect[e][0] + " " +util.inspect(expect[e][1])+"\n"+
|
|
39
|
-
"actual: "+ev+" "+inspected+"\n")
|
|
40
|
-
e++
|
|
41
|
-
if (ev === "error") parser.resume()
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
if (xml) parser.write(xml).close()
|
|
45
|
-
return parser
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (module === require.main) {
|
|
49
|
-
var running = true
|
|
50
|
-
, failures = 0
|
|
51
|
-
|
|
52
|
-
function fail (file, er) {
|
|
53
|
-
util.error("Failed: "+file)
|
|
54
|
-
util.error(er.stack || er.message)
|
|
55
|
-
failures ++
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fs.readdir(__dirname, function (error, files) {
|
|
59
|
-
files = files.filter(function (file) {
|
|
60
|
-
return (/\.js$/.exec(file) && file !== 'index.js')
|
|
61
|
-
})
|
|
62
|
-
var n = files.length
|
|
63
|
-
, i = 0
|
|
64
|
-
console.log("0.." + n)
|
|
65
|
-
files.forEach(function (file) {
|
|
66
|
-
// run this test.
|
|
67
|
-
try {
|
|
68
|
-
require(path.resolve(__dirname, file))
|
|
69
|
-
var globalsAfter = JSON.stringify(Object.keys(global))
|
|
70
|
-
if (globalsAfter !== globalsBefore) {
|
|
71
|
-
var er = new Error("new globals introduced\n"+
|
|
72
|
-
"expected: "+globalsBefore+"\n"+
|
|
73
|
-
"actual: "+globalsAfter)
|
|
74
|
-
globalsBefore = globalsAfter
|
|
75
|
-
throw er
|
|
76
|
-
}
|
|
77
|
-
console.log("ok " + (++i) + " - " + file)
|
|
78
|
-
} catch (er) {
|
|
79
|
-
console.log("not ok "+ (++i) + " - " + file)
|
|
80
|
-
fail(file, er)
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
if (!failures) return console.log("#all pass")
|
|
84
|
-
else return console.error(failures + " failure" + (failures > 1 ? "s" : ""))
|
|
85
|
-
})
|
|
86
|
-
}
|
package/test/issue-23.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml :
|
|
4
|
-
"<compileClassesResponse>"+
|
|
5
|
-
"<result>"+
|
|
6
|
-
"<bodyCrc>653724009</bodyCrc>"+
|
|
7
|
-
"<column>-1</column>"+
|
|
8
|
-
"<id>01pG0000002KoSUIA0</id>"+
|
|
9
|
-
"<line>-1</line>"+
|
|
10
|
-
"<name>CalendarController</name>"+
|
|
11
|
-
"<success>true</success>"+
|
|
12
|
-
"</result>"+
|
|
13
|
-
"</compileClassesResponse>"
|
|
14
|
-
|
|
15
|
-
, expect :
|
|
16
|
-
[ [ "opentag", { name: "COMPILECLASSESRESPONSE", attributes: {}, isSelfClosing: false } ]
|
|
17
|
-
, [ "opentag", { name : "RESULT", attributes: {}, isSelfClosing: false } ]
|
|
18
|
-
, [ "opentag", { name: "BODYCRC", attributes: {}, isSelfClosing: false } ]
|
|
19
|
-
, [ "text", "653724009" ]
|
|
20
|
-
, [ "closetag", "BODYCRC" ]
|
|
21
|
-
, [ "opentag", { name: "COLUMN", attributes: {}, isSelfClosing: false } ]
|
|
22
|
-
, [ "text", "-1" ]
|
|
23
|
-
, [ "closetag", "COLUMN" ]
|
|
24
|
-
, [ "opentag", { name: "ID", attributes: {}, isSelfClosing: false } ]
|
|
25
|
-
, [ "text", "01pG0000002KoSUIA0" ]
|
|
26
|
-
, [ "closetag", "ID" ]
|
|
27
|
-
, [ "opentag", {name: "LINE", attributes: {}, isSelfClosing: false } ]
|
|
28
|
-
, [ "text", "-1" ]
|
|
29
|
-
, [ "closetag", "LINE" ]
|
|
30
|
-
, [ "opentag", {name: "NAME", attributes: {}, isSelfClosing: false } ]
|
|
31
|
-
, [ "text", "CalendarController" ]
|
|
32
|
-
, [ "closetag", "NAME" ]
|
|
33
|
-
, [ "opentag", {name: "SUCCESS", attributes: {}, isSelfClosing: false } ]
|
|
34
|
-
, [ "text", "true" ]
|
|
35
|
-
, [ "closetag", "SUCCESS" ]
|
|
36
|
-
, [ "closetag", "RESULT" ]
|
|
37
|
-
, [ "closetag", "COMPILECLASSESRESPONSE" ]
|
|
38
|
-
]
|
|
39
|
-
, strict : false
|
|
40
|
-
, opt : {}
|
|
41
|
-
}
|
|
42
|
-
)
|
|
43
|
-
|
package/test/issue-30.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// https://github.com/isaacs/sax-js/issues/33
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : "<xml>\n"+
|
|
4
|
-
"<!-- \n"+
|
|
5
|
-
" comment with a single dash- in it\n"+
|
|
6
|
-
"-->\n"+
|
|
7
|
-
"<data/>\n"+
|
|
8
|
-
"</xml>"
|
|
9
|
-
|
|
10
|
-
, expect :
|
|
11
|
-
[ [ "opentag", { name: "xml", attributes: {}, isSelfClosing: false } ]
|
|
12
|
-
, [ "text", "\n" ]
|
|
13
|
-
, [ "comment", " \n comment with a single dash- in it\n" ]
|
|
14
|
-
, [ "text", "\n" ]
|
|
15
|
-
, [ "opentag", { name: "data", attributes: {}, isSelfClosing: true } ]
|
|
16
|
-
, [ "closetag", "data" ]
|
|
17
|
-
, [ "text", "\n" ]
|
|
18
|
-
, [ "closetag", "xml" ]
|
|
19
|
-
]
|
|
20
|
-
, strict : true
|
|
21
|
-
, opt : {}
|
|
22
|
-
}
|
|
23
|
-
)
|
|
24
|
-
|
package/test/issue-35.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// https://github.com/isaacs/sax-js/issues/35
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : "<xml>

\n"+
|
|
4
|
-
"</xml>"
|
|
5
|
-
|
|
6
|
-
, expect :
|
|
7
|
-
[ [ "opentag", { name: "xml", attributes: {}, isSelfClosing: false } ]
|
|
8
|
-
, [ "text", "\r\r\n" ]
|
|
9
|
-
, [ "closetag", "xml" ]
|
|
10
|
-
]
|
|
11
|
-
, strict : true
|
|
12
|
-
, opt : {}
|
|
13
|
-
}
|
|
14
|
-
)
|
|
15
|
-
|
package/test/issue-47.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// https://github.com/isaacs/sax-js/issues/47
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : '<a href="query.svc?x=1&y=2&z=3"/>'
|
|
4
|
-
, expect : [
|
|
5
|
-
[ "attribute", { name:'HREF', value:"query.svc?x=1&y=2&z=3"} ],
|
|
6
|
-
[ "opentag", { name: "A", attributes: { HREF:"query.svc?x=1&y=2&z=3"}, isSelfClosing: true } ],
|
|
7
|
-
[ "closetag", "A" ]
|
|
8
|
-
]
|
|
9
|
-
, opt : {}
|
|
10
|
-
}
|
|
11
|
-
)
|
|
12
|
-
|
package/test/issue-49.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// https://github.com/isaacs/sax-js/issues/49
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : "<xml><script>hello world</script></xml>"
|
|
4
|
-
, expect :
|
|
5
|
-
[ [ "opentag", { name: "xml", attributes: {}, isSelfClosing: false } ]
|
|
6
|
-
, [ "opentag", { name: "script", attributes: {}, isSelfClosing: false } ]
|
|
7
|
-
, [ "text", "hello world" ]
|
|
8
|
-
, [ "closetag", "script" ]
|
|
9
|
-
, [ "closetag", "xml" ]
|
|
10
|
-
]
|
|
11
|
-
, strict : false
|
|
12
|
-
, opt : { lowercasetags: true, noscript: true }
|
|
13
|
-
}
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
require(__dirname).test
|
|
17
|
-
( { xml : "<xml><script><![CDATA[hello world]]></script></xml>"
|
|
18
|
-
, expect :
|
|
19
|
-
[ [ "opentag", { name: "xml", attributes: {}, isSelfClosing: false } ]
|
|
20
|
-
, [ "opentag", { name: "script", attributes: {}, isSelfClosing: false } ]
|
|
21
|
-
, [ "opencdata", undefined ]
|
|
22
|
-
, [ "cdata", "hello world" ]
|
|
23
|
-
, [ "closecdata", undefined ]
|
|
24
|
-
, [ "closetag", "script" ]
|
|
25
|
-
, [ "closetag", "xml" ]
|
|
26
|
-
]
|
|
27
|
-
, strict : false
|
|
28
|
-
, opt : { lowercasetags: true, noscript: true }
|
|
29
|
-
}
|
|
30
|
-
)
|
|
31
|
-
|
package/test/issue-84.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// https://github.com/isaacs/sax-js/issues/49
|
|
2
|
-
require(__dirname).test
|
|
3
|
-
( { xml : "<?has unbalanced \"quotes?><xml>body</xml>"
|
|
4
|
-
, expect :
|
|
5
|
-
[ [ "processinginstruction", { name: "has", body: "unbalanced \"quotes" } ],
|
|
6
|
-
[ "opentag", { name: "xml", attributes: {}, isSelfClosing: false } ]
|
|
7
|
-
, [ "text", "body" ]
|
|
8
|
-
, [ "closetag", "xml" ]
|
|
9
|
-
]
|
|
10
|
-
, strict : false
|
|
11
|
-
, opt : { lowercasetags: true, noscript: true }
|
|
12
|
-
}
|
|
13
|
-
)
|