-
-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathcomments_spec.js
More file actions
85 lines (75 loc) · 2.11 KB
/
Copy pathcomments_spec.js
File metadata and controls
85 lines (75 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {XMLParser, XMLBuilder, XMLValidator} from "../src/fxp.js";
describe("Comments", function() {
it("should parse comment and build them back", function() {
const XMLdata = `
<!--Students grades are uploaded by months-->
<class_list>
<student>
<!--Student details-->
<!--A second comment-->
<!-- A third comment -->
<name>Tanmay</name>
<!-->> ISO DICTIONARY TYPES <<-->
<grade>A</grade>
</student>
</class_list>`;
const options = {
ignoreAttributes: false,
format: true,
commentPropName: "#comment",
preserveOrder: true
};
const parser = new XMLParser(options);
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));
const builder = new XMLBuilder(options);
const output = builder.build(result);
// console.log(output);
expect(output.replace(/\s+/g, "")).toEqual(XMLdata.replace(/\s+/g, ""));
});
it("should build XML with Comments without parseOrder", function() {
const input = {
"any_name": {
"person": {
"phone": [
122233344550,
122233344551,
""
],
"name": [
`<some>Jack</some>Jack`,
`<some>Mohan</some>`
],
"blank": "",
"another": {
"phone": "1245789",
}
}
}
};
const expected = `
<any_name>
<person>
<!--122233344550-->
<!--122233344551-->
<!---->
<name><some>Jack</some>Jack</name>
<name><some>Mohan</some></name>
<blank></blank>
<another>
<!--1245789-->
</another>
</person>
</any_name>`;
const options = {
processEntities:false,
format: true,
ignoreAttributes: false,
commentPropName: "phone"
};
const builder = new XMLBuilder(options);
const xmlOutput = builder.build(input);
// console.log(xmlOutput);
expect(xmlOutput.replace(/\s+/g, "")).toEqual(expected.replace(/\s+/g, ""));
});
});