-
-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathinputType_spec.js
More file actions
95 lines (79 loc) · 2.95 KB
/
Copy pathinputType_spec.js
File metadata and controls
95 lines (79 loc) · 2.95 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
85
86
87
88
89
90
91
92
93
94
95
"use strict";
import fs from "fs";
import path from "path";
import { fileURLToPath } from 'url';
import { dirname } from 'path';
// Get the file URL of the current module
const __filename = fileURLToPath(import.meta.url);
// Derive the directory name
const __dirname = dirname(__filename);
import {XMLParser, XMLValidator} from "../src/fxp.js";
describe("XMLParser", function() {
it("should parse when Buffer is given as input", function() {
const fileNamePath = path.join(__dirname, "assets/mini-sample.xml");
const xmlData = fs.readFileSync(fileNamePath);
const expected = {
"?xml": '',
"any_name": {
"person": [
{
"phone": [
122233344550,
122233344551
],
"name": "Jack",
"age": 33,
"emptyNode": "",
"booleanNode": [
false,
true
],
"selfclosing": ""
},
{
"phone": [
122233344553,
122233344554
],
"name": "Boris"
}
]
}
};
const parser = new XMLParser();
let result = parser.parse(xmlData);
// console.log(JSON.stringify(result,null,4));
expect(result).toEqual(expected);
});
// xit("should not parse when invalid value is given", function() {
// const parser = new XMLParser();
// const result = parser.parse(23);
// // console.log(result)
// expect(result).toEqual({});
// });
// xit("should not parse when invalid value is given", function() {
// const parser = new XMLParser();
// const result = parser.parse([]);
// // console.log(result)
// expect(result).toBeUndefined();
// });
// xit("should not parse when invalid value is given", function() {
// const parser = new XMLParser( { preserveOrder: true});
// const result = parser.parse([]);
// expect(result).toBeUndefined();
// });
// xit("should not parse when null", function() {
// const parser = new XMLParser( { preserveOrder: true});
// expect(() => {
// parser.parse(null);
// // console.log(result);
// }).toThrowError("Cannot read properties of null (reading 'toString')");
// });
// xit("should not parse when undefined", function() {
// const parser = new XMLParser( { preserveOrder: true});
// expect(() => {
// parser.parse();
// // console.log(result);
// }).toThrowError("Cannot read properties of undefined (reading 'toString')");
// });
});