-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathstringify.js
More file actions
154 lines (146 loc) · 3.81 KB
/
Copy pathstringify.js
File metadata and controls
154 lines (146 loc) · 3.81 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var test = require("tape");
var parse = require("../lib/parse");
var stringify = require("../lib/stringify");
var tests = [
{
message: "Should correctly add quotes",
fixture:
"bold italic 12px/3 'Open Sans', Arial, \"Helvetica Neue\", sans-serif"
},
{
message: "Should not close unclosed strings",
fixture: '" 12, 54, 65 '
},
{
message: "Should correctly add brackets",
fixture: " rgba( 12, 54, 65) "
},
{
message: "Should not close unclosed functions",
fixture: " rgba( 12, 54, 65 "
},
{
message: "Should correctly process advanced gradients",
fixture:
"background-image:linear-gradient(45deg,transparent 25%,hsla(0,0%,100%,.2) 25%,hsla(0,0%,100%,.2) 75%,transparent 75%,transparent 25%,hsla(0,0%,100%,.2) 75%,transparent 75%,transparent),linear-gradient(45deg,transparent 25%,hsla(0,0%,100%,.2))"
},
{
message: "Should correctly add comments",
fixture: "/!*comment*!/ 1px /!* unclosed "
},
{
message: "Should correctly process comments inside functions",
fixture:
"/!*before*!/ rgb( /!*red component*!/ 12, 54 /!*green component*!/, /!* blue *!/ 65)/!* after *!/ "
},
{
message: "Should correctly process empty url",
fixture: "url()"
},
{
message: "Should correctly process empty url with space",
fixture: "url( )"
},
{
message: "Should correctly process empty url with spaces",
fixture: "url( )"
},
{
message: "Should correctly process empty url with tab",
fixture: "url(\t)"
},
{
message: "Should correctly process empty url with newline (LF)",
fixture: "url(\n)"
},
{
message: "Should correctly process interpolation",
fixture: "#{url(\n)}",
options: {
interpolationPrefix: "#"
}
},
{
message: "Should correctly process empty url with newline (LF)",
fixture: "url(\n\n\n)"
},
{
message: "Should correctly process empty url with multiple newlines (CRLF)",
fixture: "url(\r\n)"
},
{
message: "Should correctly process empty url with multiple newlines (CRLF)",
fixture: "url(\r\n\r\n\r\n)"
},
{
message: "Should correctly process empty url whitespace characters",
fixture: "url( \n \t \n )"
},
{
message: "Should correctly process unicode-range (single codepoint)",
fixture: "U+26"
},
{
message: "Should correctly process unicode-range (codepoint range)",
fixture: "U+0025-00FF"
},
{
message: "Should correctly process unicode-range (wildcard range)",
fixture: "U+4??"
},
{
message: "Should correctly process unicode-range (multiple values)",
fixture: "U+0025-00FF, U+4??"
}
];
test("Stringify", function(t) {
t.plan(tests.length + 4);
tests.forEach(function(opts) {
t.equal(
stringify(parse(opts.fixture, opts.options)),
opts.fixture,
opts.message
);
});
var tokens = parse(" rgba(12, 54, 65 ) ");
t.equal(
stringify(tokens, function(node) {
if (node.type === "function") {
return (
node.value +
"[" +
[node.nodes[0].value, node.nodes[2].value, node.nodes[4].value].join(
","
) +
"]"
);
}
}),
" rgba[12,54,65] "
);
t.equal(
stringify(tokens[1], function(node) {
if (node.type === "function") {
return (
node.value +
"[" +
[node.nodes[0].value, node.nodes[2].value, node.nodes[4].value].join(
","
) +
"]"
);
}
}),
"rgba[12,54,65]"
);
tokens[1].type = "word";
t.equal(stringify(tokens), " rgba ", "Shouldn't process nodes of work type");
t.equal(
stringify(parse("calc(1px + var(--bar))"), function(node) {
if (node.type === "function" && node.value === "var") {
return "10px";
}
}),
"calc(1px + 10px)"
);
});