cda-schematron-validator 1.0.4 → 1.0.5
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/.jshintrc +96 -96
- package/.vscode/launch.json +17 -17
- package/README.md +132 -132
- package/includeExternalDocument.js +108 -108
- package/package.json +4 -11
- package/parseSchematron.js +121 -121
- package/test/test.sch +46 -46
- package/test/test.xml +79 -79
- package/test/tests.js +141 -141
- package/testAssertion.js +72 -72
- package/validator.js +233 -233
package/test/test.xml
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
<xml xmlns="urn:dh">
|
|
2
|
-
<!-- count of elements -->
|
|
3
|
-
<test root="A">
|
|
4
|
-
<element>true</element>
|
|
5
|
-
</test>
|
|
6
|
-
<test root="A">
|
|
7
|
-
<element>false</element>
|
|
8
|
-
<element>false</element>
|
|
9
|
-
</test>
|
|
10
|
-
<!-- attibute equivalence -->
|
|
11
|
-
<test root="B">
|
|
12
|
-
<element atttribute="ok">true</element>
|
|
13
|
-
</test>
|
|
14
|
-
<test root="B">
|
|
15
|
-
<element atttribute="notok">false</element>
|
|
16
|
-
</test>
|
|
17
|
-
<!-- child presence -->
|
|
18
|
-
<test root="C">
|
|
19
|
-
<element>
|
|
20
|
-
<child>true</child>
|
|
21
|
-
</element>
|
|
22
|
-
</test>
|
|
23
|
-
<test root="C">
|
|
24
|
-
<element>
|
|
25
|
-
<notchild>false</notchild>
|
|
26
|
-
</element>
|
|
27
|
-
</test>
|
|
28
|
-
<!-- conditional child presence -->
|
|
29
|
-
<test root="D">
|
|
30
|
-
<element attribute="needChild">
|
|
31
|
-
<child>true</child>
|
|
32
|
-
</element>
|
|
33
|
-
</test>
|
|
34
|
-
<test root="D">
|
|
35
|
-
<element attribute="needNoChild">true</element>
|
|
36
|
-
</test>
|
|
37
|
-
<test root="D">
|
|
38
|
-
<element attribute="needChild">false</element>
|
|
39
|
-
</test>
|
|
40
|
-
<!-- OR presence -->
|
|
41
|
-
<test root="E">
|
|
42
|
-
<element>
|
|
43
|
-
<firstChild>true</firstChild>
|
|
44
|
-
</element>
|
|
45
|
-
</test>
|
|
46
|
-
<test root="E">
|
|
47
|
-
<element>
|
|
48
|
-
<secondChild>true</secondChild>
|
|
49
|
-
</element>
|
|
50
|
-
</test>
|
|
51
|
-
<test root="E">
|
|
52
|
-
<element>
|
|
53
|
-
<notChild>false</notChild>
|
|
54
|
-
</element>
|
|
55
|
-
</test>
|
|
56
|
-
<!-- AND presence -->
|
|
57
|
-
<test root="F">
|
|
58
|
-
<element>
|
|
59
|
-
<firstChild>true</firstChild>
|
|
60
|
-
<secondChild>true</secondChild>
|
|
61
|
-
</element>
|
|
62
|
-
</test>
|
|
63
|
-
<test root="F">
|
|
64
|
-
<element>
|
|
65
|
-
<secondChild>false</secondChild>
|
|
66
|
-
</element>
|
|
67
|
-
</test>
|
|
68
|
-
<test root="F">
|
|
69
|
-
<element>
|
|
70
|
-
<notChild>false</notChild>
|
|
71
|
-
</element>
|
|
72
|
-
</test>
|
|
73
|
-
<!-- Element value -->
|
|
74
|
-
<test root="G">
|
|
75
|
-
<element>true</element>
|
|
76
|
-
</test>
|
|
77
|
-
<test root="G">
|
|
78
|
-
<element>false</element>
|
|
79
|
-
</test>
|
|
1
|
+
<xml xmlns="urn:dh">
|
|
2
|
+
<!-- count of elements -->
|
|
3
|
+
<test root="A">
|
|
4
|
+
<element>true</element>
|
|
5
|
+
</test>
|
|
6
|
+
<test root="A">
|
|
7
|
+
<element>false</element>
|
|
8
|
+
<element>false</element>
|
|
9
|
+
</test>
|
|
10
|
+
<!-- attibute equivalence -->
|
|
11
|
+
<test root="B">
|
|
12
|
+
<element atttribute="ok">true</element>
|
|
13
|
+
</test>
|
|
14
|
+
<test root="B">
|
|
15
|
+
<element atttribute="notok">false</element>
|
|
16
|
+
</test>
|
|
17
|
+
<!-- child presence -->
|
|
18
|
+
<test root="C">
|
|
19
|
+
<element>
|
|
20
|
+
<child>true</child>
|
|
21
|
+
</element>
|
|
22
|
+
</test>
|
|
23
|
+
<test root="C">
|
|
24
|
+
<element>
|
|
25
|
+
<notchild>false</notchild>
|
|
26
|
+
</element>
|
|
27
|
+
</test>
|
|
28
|
+
<!-- conditional child presence -->
|
|
29
|
+
<test root="D">
|
|
30
|
+
<element attribute="needChild">
|
|
31
|
+
<child>true</child>
|
|
32
|
+
</element>
|
|
33
|
+
</test>
|
|
34
|
+
<test root="D">
|
|
35
|
+
<element attribute="needNoChild">true</element>
|
|
36
|
+
</test>
|
|
37
|
+
<test root="D">
|
|
38
|
+
<element attribute="needChild">false</element>
|
|
39
|
+
</test>
|
|
40
|
+
<!-- OR presence -->
|
|
41
|
+
<test root="E">
|
|
42
|
+
<element>
|
|
43
|
+
<firstChild>true</firstChild>
|
|
44
|
+
</element>
|
|
45
|
+
</test>
|
|
46
|
+
<test root="E">
|
|
47
|
+
<element>
|
|
48
|
+
<secondChild>true</secondChild>
|
|
49
|
+
</element>
|
|
50
|
+
</test>
|
|
51
|
+
<test root="E">
|
|
52
|
+
<element>
|
|
53
|
+
<notChild>false</notChild>
|
|
54
|
+
</element>
|
|
55
|
+
</test>
|
|
56
|
+
<!-- AND presence -->
|
|
57
|
+
<test root="F">
|
|
58
|
+
<element>
|
|
59
|
+
<firstChild>true</firstChild>
|
|
60
|
+
<secondChild>true</secondChild>
|
|
61
|
+
</element>
|
|
62
|
+
</test>
|
|
63
|
+
<test root="F">
|
|
64
|
+
<element>
|
|
65
|
+
<secondChild>false</secondChild>
|
|
66
|
+
</element>
|
|
67
|
+
</test>
|
|
68
|
+
<test root="F">
|
|
69
|
+
<element>
|
|
70
|
+
<notChild>false</notChild>
|
|
71
|
+
</element>
|
|
72
|
+
</test>
|
|
73
|
+
<!-- Element value -->
|
|
74
|
+
<test root="G">
|
|
75
|
+
<element>true</element>
|
|
76
|
+
</test>
|
|
77
|
+
<test root="G">
|
|
78
|
+
<element>false</element>
|
|
79
|
+
</test>
|
|
80
80
|
</xml>
|
package/test/tests.js
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const expect = require('chai').expect;
|
|
3
|
-
|
|
4
|
-
const validator = require('../validator');
|
|
5
|
-
|
|
6
|
-
// Which xml file to test
|
|
7
|
-
const xmlPath = './test/test.xml';
|
|
8
|
-
// Which schematron to test against
|
|
9
|
-
const schematronPath = './test/test.sch';
|
|
10
|
-
|
|
11
|
-
const xml = fs.readFileSync(xmlPath, 'utf-8').toString();
|
|
12
|
-
const schematron = fs.readFileSync(schematronPath, 'utf-8').toString();
|
|
13
|
-
|
|
14
|
-
describe('Validator should', function() {
|
|
15
|
-
let results;
|
|
16
|
-
it('return results', function(done) {
|
|
17
|
-
results = validator.validate(xml, schematron);
|
|
18
|
-
expect(results).to.be.an('object');
|
|
19
|
-
done();
|
|
20
|
-
});
|
|
21
|
-
it('return errorCount', function(done) {
|
|
22
|
-
expect(results.errorCount).to.be.a('number');
|
|
23
|
-
done();
|
|
24
|
-
});
|
|
25
|
-
it('return warningCount', function(done) {
|
|
26
|
-
expect(results.warningCount).to.be.a('number');
|
|
27
|
-
done();
|
|
28
|
-
});
|
|
29
|
-
it('return ignoredCount', function(done) {
|
|
30
|
-
expect(results.ignoredCount).to.be.a('number');
|
|
31
|
-
done();
|
|
32
|
-
});
|
|
33
|
-
it('return errors array', function(done) {
|
|
34
|
-
expect(results.errors).to.be.a('array');
|
|
35
|
-
done();
|
|
36
|
-
});
|
|
37
|
-
it('return warnings array', function(done) {
|
|
38
|
-
expect(results.warnings).to.be.a('array');
|
|
39
|
-
done();
|
|
40
|
-
});
|
|
41
|
-
it('return ignored array', function(done) {
|
|
42
|
-
expect(results.ignored).to.be.a('array');
|
|
43
|
-
done();
|
|
44
|
-
});
|
|
45
|
-
it('return matching errorCount', function(done) {
|
|
46
|
-
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
47
|
-
done();
|
|
48
|
-
});
|
|
49
|
-
it('return matching warningCount', function(done) {
|
|
50
|
-
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
51
|
-
done();
|
|
52
|
-
});
|
|
53
|
-
it('return matching ignoredCount', function(done) {
|
|
54
|
-
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
55
|
-
done();
|
|
56
|
-
});
|
|
57
|
-
it('return correct number of errors', function(done) {
|
|
58
|
-
expect(results.errorCount).to.be.equal(16);
|
|
59
|
-
done();
|
|
60
|
-
});
|
|
61
|
-
it('return correct number of warnings', function(done) {
|
|
62
|
-
expect(results.warningCount).to.be.equal(15);
|
|
63
|
-
done();
|
|
64
|
-
});
|
|
65
|
-
it('return correct number of ignored', function(done) {
|
|
66
|
-
expect(results.ignoredCount).to.be.equal(1);
|
|
67
|
-
done();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('return similar results without warnings', function(done) {
|
|
71
|
-
results = validator.validate(xml, schematron, { includeWarnings: false });
|
|
72
|
-
expect(results).to.be.an('object');
|
|
73
|
-
expect(results.errorCount).to.be.a('number');
|
|
74
|
-
expect(results.warningCount).to.be.a('number');
|
|
75
|
-
expect(results.ignoredCount).to.be.a('number');
|
|
76
|
-
expect(results.errors).to.be.a('array');
|
|
77
|
-
expect(results.warnings).to.be.a('array');
|
|
78
|
-
expect(results.ignored).to.be.a('array');
|
|
79
|
-
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
80
|
-
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
81
|
-
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
82
|
-
expect(results.errorCount).to.be.equal(16);
|
|
83
|
-
expect(results.warningCount).to.be.equal(0);
|
|
84
|
-
expect(results.ignoredCount).to.be.equal(1);
|
|
85
|
-
done();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('return similar results given xml filepath', function(done) {
|
|
89
|
-
results = validator.validate(xmlPath, schematron);
|
|
90
|
-
expect(results).to.be.an('object');
|
|
91
|
-
expect(results.errorCount).to.be.a('number');
|
|
92
|
-
expect(results.warningCount).to.be.a('number');
|
|
93
|
-
expect(results.ignoredCount).to.be.a('number');
|
|
94
|
-
expect(results.errors).to.be.a('array');
|
|
95
|
-
expect(results.warnings).to.be.a('array');
|
|
96
|
-
expect(results.ignored).to.be.a('array');
|
|
97
|
-
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
98
|
-
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
99
|
-
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
100
|
-
expect(results.errorCount).to.be.equal(16);
|
|
101
|
-
expect(results.warningCount).to.be.equal(15);
|
|
102
|
-
expect(results.ignoredCount).to.be.equal(1);
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('return similar results given schematron filepath', function(done) {
|
|
107
|
-
results = validator.validate(xml, schematronPath);
|
|
108
|
-
expect(results).to.be.an('object');
|
|
109
|
-
expect(results.errorCount).to.be.a('number');
|
|
110
|
-
expect(results.warningCount).to.be.a('number');
|
|
111
|
-
expect(results.ignoredCount).to.be.a('number');
|
|
112
|
-
expect(results.errors).to.be.a('array');
|
|
113
|
-
expect(results.warnings).to.be.a('array');
|
|
114
|
-
expect(results.ignored).to.be.a('array');
|
|
115
|
-
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
116
|
-
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
117
|
-
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
118
|
-
expect(results.errorCount).to.be.equal(16);
|
|
119
|
-
expect(results.warningCount).to.be.equal(15);
|
|
120
|
-
expect(results.ignoredCount).to.be.equal(1);
|
|
121
|
-
done();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('return similar results given xml filepath and schematron filepath', function(done) {
|
|
125
|
-
results = validator.validate(xmlPath, schematronPath);
|
|
126
|
-
expect(results).to.be.an('object');
|
|
127
|
-
expect(results.errorCount).to.be.a('number');
|
|
128
|
-
expect(results.warningCount).to.be.a('number');
|
|
129
|
-
expect(results.ignoredCount).to.be.a('number');
|
|
130
|
-
expect(results.errors).to.be.a('array');
|
|
131
|
-
expect(results.warnings).to.be.a('array');
|
|
132
|
-
expect(results.ignored).to.be.a('array');
|
|
133
|
-
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
134
|
-
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
135
|
-
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
136
|
-
expect(results.errorCount).to.be.equal(16);
|
|
137
|
-
expect(results.warningCount).to.be.equal(15);
|
|
138
|
-
expect(results.ignoredCount).to.be.equal(1);
|
|
139
|
-
done();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const expect = require('chai').expect;
|
|
3
|
+
|
|
4
|
+
const validator = require('../validator');
|
|
5
|
+
|
|
6
|
+
// Which xml file to test
|
|
7
|
+
const xmlPath = './test/test.xml';
|
|
8
|
+
// Which schematron to test against
|
|
9
|
+
const schematronPath = './test/test.sch';
|
|
10
|
+
|
|
11
|
+
const xml = fs.readFileSync(xmlPath, 'utf-8').toString();
|
|
12
|
+
const schematron = fs.readFileSync(schematronPath, 'utf-8').toString();
|
|
13
|
+
|
|
14
|
+
describe('Validator should', function() {
|
|
15
|
+
let results;
|
|
16
|
+
it('return results', function(done) {
|
|
17
|
+
results = validator.validate(xml, schematron);
|
|
18
|
+
expect(results).to.be.an('object');
|
|
19
|
+
done();
|
|
20
|
+
});
|
|
21
|
+
it('return errorCount', function(done) {
|
|
22
|
+
expect(results.errorCount).to.be.a('number');
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
it('return warningCount', function(done) {
|
|
26
|
+
expect(results.warningCount).to.be.a('number');
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
it('return ignoredCount', function(done) {
|
|
30
|
+
expect(results.ignoredCount).to.be.a('number');
|
|
31
|
+
done();
|
|
32
|
+
});
|
|
33
|
+
it('return errors array', function(done) {
|
|
34
|
+
expect(results.errors).to.be.a('array');
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
it('return warnings array', function(done) {
|
|
38
|
+
expect(results.warnings).to.be.a('array');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
it('return ignored array', function(done) {
|
|
42
|
+
expect(results.ignored).to.be.a('array');
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
it('return matching errorCount', function(done) {
|
|
46
|
+
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
47
|
+
done();
|
|
48
|
+
});
|
|
49
|
+
it('return matching warningCount', function(done) {
|
|
50
|
+
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
it('return matching ignoredCount', function(done) {
|
|
54
|
+
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
55
|
+
done();
|
|
56
|
+
});
|
|
57
|
+
it('return correct number of errors', function(done) {
|
|
58
|
+
expect(results.errorCount).to.be.equal(16);
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
it('return correct number of warnings', function(done) {
|
|
62
|
+
expect(results.warningCount).to.be.equal(15);
|
|
63
|
+
done();
|
|
64
|
+
});
|
|
65
|
+
it('return correct number of ignored', function(done) {
|
|
66
|
+
expect(results.ignoredCount).to.be.equal(1);
|
|
67
|
+
done();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('return similar results without warnings', function(done) {
|
|
71
|
+
results = validator.validate(xml, schematron, { includeWarnings: false });
|
|
72
|
+
expect(results).to.be.an('object');
|
|
73
|
+
expect(results.errorCount).to.be.a('number');
|
|
74
|
+
expect(results.warningCount).to.be.a('number');
|
|
75
|
+
expect(results.ignoredCount).to.be.a('number');
|
|
76
|
+
expect(results.errors).to.be.a('array');
|
|
77
|
+
expect(results.warnings).to.be.a('array');
|
|
78
|
+
expect(results.ignored).to.be.a('array');
|
|
79
|
+
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
80
|
+
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
81
|
+
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
82
|
+
expect(results.errorCount).to.be.equal(16);
|
|
83
|
+
expect(results.warningCount).to.be.equal(0);
|
|
84
|
+
expect(results.ignoredCount).to.be.equal(1);
|
|
85
|
+
done();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('return similar results given xml filepath', function(done) {
|
|
89
|
+
results = validator.validate(xmlPath, schematron);
|
|
90
|
+
expect(results).to.be.an('object');
|
|
91
|
+
expect(results.errorCount).to.be.a('number');
|
|
92
|
+
expect(results.warningCount).to.be.a('number');
|
|
93
|
+
expect(results.ignoredCount).to.be.a('number');
|
|
94
|
+
expect(results.errors).to.be.a('array');
|
|
95
|
+
expect(results.warnings).to.be.a('array');
|
|
96
|
+
expect(results.ignored).to.be.a('array');
|
|
97
|
+
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
98
|
+
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
99
|
+
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
100
|
+
expect(results.errorCount).to.be.equal(16);
|
|
101
|
+
expect(results.warningCount).to.be.equal(15);
|
|
102
|
+
expect(results.ignoredCount).to.be.equal(1);
|
|
103
|
+
done();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('return similar results given schematron filepath', function(done) {
|
|
107
|
+
results = validator.validate(xml, schematronPath);
|
|
108
|
+
expect(results).to.be.an('object');
|
|
109
|
+
expect(results.errorCount).to.be.a('number');
|
|
110
|
+
expect(results.warningCount).to.be.a('number');
|
|
111
|
+
expect(results.ignoredCount).to.be.a('number');
|
|
112
|
+
expect(results.errors).to.be.a('array');
|
|
113
|
+
expect(results.warnings).to.be.a('array');
|
|
114
|
+
expect(results.ignored).to.be.a('array');
|
|
115
|
+
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
116
|
+
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
117
|
+
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
118
|
+
expect(results.errorCount).to.be.equal(16);
|
|
119
|
+
expect(results.warningCount).to.be.equal(15);
|
|
120
|
+
expect(results.ignoredCount).to.be.equal(1);
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('return similar results given xml filepath and schematron filepath', function(done) {
|
|
125
|
+
results = validator.validate(xmlPath, schematronPath);
|
|
126
|
+
expect(results).to.be.an('object');
|
|
127
|
+
expect(results.errorCount).to.be.a('number');
|
|
128
|
+
expect(results.warningCount).to.be.a('number');
|
|
129
|
+
expect(results.ignoredCount).to.be.a('number');
|
|
130
|
+
expect(results.errors).to.be.a('array');
|
|
131
|
+
expect(results.warnings).to.be.a('array');
|
|
132
|
+
expect(results.ignored).to.be.a('array');
|
|
133
|
+
expect(results.errorCount).to.be.equal(results.errors.length);
|
|
134
|
+
expect(results.warningCount).to.be.equal(results.warnings.length);
|
|
135
|
+
expect(results.ignoredCount).to.be.equal(results.ignored.length);
|
|
136
|
+
expect(results.errorCount).to.be.equal(16);
|
|
137
|
+
expect(results.warningCount).to.be.equal(15);
|
|
138
|
+
expect(results.ignoredCount).to.be.equal(1);
|
|
139
|
+
done();
|
|
140
|
+
});
|
|
141
|
+
});
|
package/testAssertion.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
// jshint node:true
|
|
2
|
-
// jshint shadow:true
|
|
3
|
-
module.exports = testAssertion;
|
|
4
|
-
|
|
5
|
-
function testAssertion(test, selected, select, xmlDoc, resourceDir, xmlSnippetMaxLength) {
|
|
6
|
-
let results = [];
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < selected.length; i++) {
|
|
9
|
-
try {
|
|
10
|
-
let result = select('boolean(' + test + ')', selected[i]);
|
|
11
|
-
let lineNumber = null;
|
|
12
|
-
let xmlSnippet = null;
|
|
13
|
-
if (selected[i].lineNumber) {
|
|
14
|
-
lineNumber = selected[i].lineNumber;
|
|
15
|
-
xmlSnippet = selected[i].toString();
|
|
16
|
-
}
|
|
17
|
-
let maxLength = (xmlSnippetMaxLength || 1e308);
|
|
18
|
-
if (xmlSnippet && xmlSnippet.length > maxLength) {
|
|
19
|
-
xmlSnippet = xmlSnippet.slice(0, maxLength) + '...';
|
|
20
|
-
}
|
|
21
|
-
results.push({ result: result, line: lineNumber, path: getXPath(selected[i]), xml: xmlSnippet });
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
return { ignored: true, errorMessage: err.message };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < results.length; i++) {
|
|
29
|
-
if (results[i].result !== true && results[i].result !== false) {
|
|
30
|
-
return { ignored: true, errorMessage: 'Test returned non-boolean result' };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getXPath(node, path) {
|
|
37
|
-
let top = !path ? true : false;
|
|
38
|
-
path = path || [];
|
|
39
|
-
if (node.parentNode) {
|
|
40
|
-
path = getXPath(node.parentNode, path);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let count = 1;
|
|
44
|
-
if (node.previousSibling) {
|
|
45
|
-
let sibling = node.previousSibling;
|
|
46
|
-
do {
|
|
47
|
-
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
48
|
-
count++;
|
|
49
|
-
}
|
|
50
|
-
sibling = sibling.previousSibling;
|
|
51
|
-
} while (sibling);
|
|
52
|
-
if (count === 1) {
|
|
53
|
-
count = null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (node.nextSibling) {
|
|
57
|
-
let sibling = node.nextSibling;
|
|
58
|
-
do {
|
|
59
|
-
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
60
|
-
count = 1;
|
|
61
|
-
sibling = null;
|
|
62
|
-
} else {
|
|
63
|
-
count = null;
|
|
64
|
-
sibling = sibling.previousSibling;
|
|
65
|
-
}
|
|
66
|
-
} while (sibling);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (node.nodeType === 1) {
|
|
70
|
-
path.push(node.nodeName + ('[' + (count || 1) + ']'));
|
|
71
|
-
}
|
|
72
|
-
return top ? '/' + path.join('/') : path;
|
|
1
|
+
// jshint node:true
|
|
2
|
+
// jshint shadow:true
|
|
3
|
+
module.exports = testAssertion;
|
|
4
|
+
|
|
5
|
+
function testAssertion(test, selected, select, xmlDoc, resourceDir, xmlSnippetMaxLength) {
|
|
6
|
+
let results = [];
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < selected.length; i++) {
|
|
9
|
+
try {
|
|
10
|
+
let result = select('boolean(' + test + ')', selected[i]);
|
|
11
|
+
let lineNumber = null;
|
|
12
|
+
let xmlSnippet = null;
|
|
13
|
+
if (selected[i].lineNumber) {
|
|
14
|
+
lineNumber = selected[i].lineNumber;
|
|
15
|
+
xmlSnippet = selected[i].toString();
|
|
16
|
+
}
|
|
17
|
+
let maxLength = (xmlSnippetMaxLength || 1e308);
|
|
18
|
+
if (xmlSnippet && xmlSnippet.length > maxLength) {
|
|
19
|
+
xmlSnippet = xmlSnippet.slice(0, maxLength) + '...';
|
|
20
|
+
}
|
|
21
|
+
results.push({ result: result, line: lineNumber, path: getXPath(selected[i]), xml: xmlSnippet });
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return { ignored: true, errorMessage: err.message };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < results.length; i++) {
|
|
29
|
+
if (results[i].result !== true && results[i].result !== false) {
|
|
30
|
+
return { ignored: true, errorMessage: 'Test returned non-boolean result' };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getXPath(node, path) {
|
|
37
|
+
let top = !path ? true : false;
|
|
38
|
+
path = path || [];
|
|
39
|
+
if (node.parentNode) {
|
|
40
|
+
path = getXPath(node.parentNode, path);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let count = 1;
|
|
44
|
+
if (node.previousSibling) {
|
|
45
|
+
let sibling = node.previousSibling;
|
|
46
|
+
do {
|
|
47
|
+
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
48
|
+
count++;
|
|
49
|
+
}
|
|
50
|
+
sibling = sibling.previousSibling;
|
|
51
|
+
} while (sibling);
|
|
52
|
+
if (count === 1) {
|
|
53
|
+
count = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (node.nextSibling) {
|
|
57
|
+
let sibling = node.nextSibling;
|
|
58
|
+
do {
|
|
59
|
+
if (sibling.nodeType === 1 && sibling.nodeName === node.nodeName) {
|
|
60
|
+
count = 1;
|
|
61
|
+
sibling = null;
|
|
62
|
+
} else {
|
|
63
|
+
count = null;
|
|
64
|
+
sibling = sibling.previousSibling;
|
|
65
|
+
}
|
|
66
|
+
} while (sibling);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (node.nodeType === 1) {
|
|
70
|
+
path.push(node.nodeName + ('[' + (count || 1) + ']'));
|
|
71
|
+
}
|
|
72
|
+
return top ? '/' + path.join('/') : path;
|
|
73
73
|
}
|