Repository navigation
Expand file tree
/
Copy pathtests.js
More file actions
69 lines (54 loc) · 1.79 KB
/
Copy pathtests.js
File metadata and controls
69 lines (54 loc) · 1.79 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
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.",
});
});
it("should correctly unescape multiple single quotes in the same string", () => {
const phpArray = `
return [
'key' => 'Joining adds you to this academy\\'s roster. You\\'ll be eligible.'
];
`;
const objectExport = loader(phpArray, {}, {});
const json = objectExport.substr("module.exports = ".length).trim();
const object = JSON.parse(json);
should(object).be.eql({
key: "Joining adds you to this academy's roster. You'll be eligible.",
});
});
});