-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.spec.js
111 lines (95 loc) · 2.92 KB
/
plugin.spec.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// @ts-check
const prettier = require("prettier");
const plugin = require("./plugin");
/**
* @param {string} text
* @param {boolean} singleQuote
* @returns {string}
*/
const format = (text, singleQuote) =>
prettier.format(text, {
parser: "jsp",
plugins: [plugin],
pluginSearchDirs: false,
singleQuote,
});
const EOF = "\n";
/**
* @param {string} text
* @param {string} toBe
*/
const expectFormat = (text, toBe) => {
expect(format(text, false)).toBe(toBe + EOF);
};
/**
* @param {string} text
* @param {string} toBe
*/
const expectFormatSingle = (text, toBe) => {
expect(format(text, true)).toBe(toBe + EOF);
};
it("should format JSP Scriptlet tag", () => {
expectFormat(
'<%@ page contentType = "text/html" %>',
'<%@ page contentType="text/html" %>'
);
});
it("should format JSP Comments", () => {
expectFormat(
"<%-- This is JSP comment --%>",
"<%-- This is JSP comment --%>"
);
expectFormat(
"<!-- It was a HTML comment -->",
"<%-- It was a HTML comment --%>"
);
expectFormat("<%-- <div v-if='true'> --%>", "<%-- <div v-if='true'> --%>");
});
it("should format Self-Closing tags", () => {
expectFormat(
'<link rel="stylesheet" href="${commonResourcePath}/style.css">',
'<link rel="stylesheet" href="${commonResourcePath}/style.css" />'
);
expectFormat("<br>", "<br />");
expectFormat("<hr>", "<hr />");
expectFormat(
'<img src="${commonResourcePath}/image.png" \n>',
'<img src="${commonResourcePath}/image.png" />'
);
});
it("should format custom tags", () => {
expectFormat(
'<c:if test="${not empty uncompress}">\n<br><hr>\n</c:if>',
'<c:if test="${not empty uncompress}">\n <br />\n <hr />\n</c:if>'
);
expectFormat("<multi-checkout />", "<multi-checkout />");
expectFormat("<multi-checkout:do />", "<multi-checkout:do />");
});
it("should format interpolated attributes", () => {
expectFormat(
`<img src='\${a ? 'b' : null}/image.png' />`,
`<img src="\${a ? 'b' : null}/image.png" />`
);
expectFormat(
`<option class='test' \${empty selected ? 'selected' : ''}>value</option>`,
`<option class="test" \${empty selected ? 'selected' : ''}>value</option>`
);
expectFormat(
`<div class="page-wrap \${opticsProduct ? 'optic-product' : '' }"></div>`,
`<div class="page-wrap \${opticsProduct ? 'optic-product' : '' }"></div>`
);
expectFormatSingle(
`<div class='\${(!hasSuperPharmCart && !hasMedicines )?'two-steps':'' }'></div>`,
`<div class="\${(!hasSuperPharmCart && !hasMedicines )?'two-steps':'' }"></div>`
);
});
it("should format interpolated attributes with single quotes", () => {
expectFormatSingle(
`<input \${store.checked ? 'checked' : ''} />`,
`<input \${store.checked ? 'checked' : ''} />`
);
expectFormatSingle(
`<div style="\${cond?'display:block':'display:hidden'}"></div>`,
`<div style="\${cond?'display:block':'display:hidden'}"></div>`
);
});