cda-schematron-validator 1.0.4 → 1.0.7

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/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
  }