-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
51 lines (41 loc) · 1.24 KB
/
tests.js
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
const should = require("should");
const loader = require("./index");
describe("php-array-loader", () => {
it("should produce json object", () => {
const phpArray = `
return [
"key1" => "value1",
'key2' => 'value2'
"key3" => 100,
"key4" => true,
"key5" => false
];
`;
const objectExport = loader(phpArray, {}, {});
const json = objectExport.substr("module.exports = ".length).trim();
const object = JSON.parse(json);
should(object).be.eql({
key1: "value1",
key2: "value2",
key3: 100,
key4: true,
key5: false,
});
});
it("should correctly unescape single quote", () => {
/**
* Webpack loads string: 'Don'\t' with double backslash/
*/
const phpArray = `
return [
'key' => 'Don\\'t.'
];
`;
const objectExport = loader(phpArray, {}, {});
const json = objectExport.substr("module.exports = ".length).trim();
const object = JSON.parse(json);
should(object).be.eql({
key: "Don't.",
});
});
});