-
Notifications
You must be signed in to change notification settings - Fork 0
/
dedent.test.ts
228 lines (183 loc) · 3.62 KB
/
dedent.test.ts
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { assertEquals } from "jsr:@std/[email protected]";
import { dedent } from "./dedent.ts";
const it = Deno.test;
it("handle escaped linebreak", () => {
const text = dedent`one-\
\u{9820}
two`;
assertEquals(text, "one-頠\ntwo");
});
it("should dedent simple multiline blocks", () => {
const text = dedent`
this
is
easy
`;
assertEquals("\nthis\nis\neasy\n", text);
});
it("should dedent with the common level", () => {
const text = dedent`
this
is
a
test
`;
assertEquals("\nthis\n is\na\n test\n", text);
});
it("should dedent as expected if begins with text", () => {
const text = dedent`testing
multi
lines
`;
assertEquals("testing\nmulti\n lines\n", text);
});
it("should not dedent with space before text on first line", () => {
const text = dedent` testing
multi
lines
`;
assertEquals(" testing\nmulti\n lines\n", text);
});
it("should not dedent a single line", () => {
const text = dedent` testing`;
assertEquals(" testing", text);
});
it("should dedent no lines", () => {
const text = dedent` testing
skip me
`;
assertEquals(" testing\nskip me\n ", text);
});
it("should dedent with blank line support", () => {
const text = dedent`
this
is
blank
`;
assertEquals("\nthis\nis\n\nblank\n", text);
});
it("should not trim trailing whitespace with content", () => {
const text = dedent`
trailing
whitespace `;
assertEquals("\ntrailing\nwhitespace ", text);
});
it("should not dedent interpolated content", () => {
const value = ` test\n value`;
const text = dedent`
interpolated
${value}
`;
assertEquals("\ninterpolated\n test\n value\n", text);
});
it("should work as expected with nested dedent", () => {
const value = dedent`
test
value
`;
const text = dedent`
interpolated
${value}
`;
assertEquals("\ninterpolated\n\ntest\nvalue\n\n", text);
});
it("should strip indent based on smallest indent", () => {
const text = dedent`
indented
here
`;
assertEquals("\n indented\nhere\n", text);
});
it("should do nothing when there's no indent", () => {
const text = dedent`
no
indent
`;
assertEquals("\nno\n indent\n ", text);
});
it("should support usage as a function", () => {
const text = dedent(`
test
value
`);
assertEquals("\ntest\nvalue\n", text);
});
it("should support strings array", () => {
const input = ["\n", "\t\t2-two\n", "\t\t\t3-three\n"];
const text = dedent(input);
assertEquals("\n2-two\n\t3-three\n", text);
});
it("should remove escaped tabs", () => {
const input = "\n\t\t2-two\n\t\t\t3-three\n";
const text = dedent(input);
assertEquals("\n2-two\n\t3-three\n", text);
});
it("should handle expressions", () => {
const text = dedent`
---
color: green
numbers:
- 1
- 2
- ${1 + 2}
`;
assertEquals(
`
---
color: green
numbers:
- 1
- 2
- 3
`,
text,
);
});
it("should handle complex expressions", () => {
const text = dedent` ${"first-line"}
color: green
numbers:
- 1->${1 + 1}->3
`;
assertEquals(
` first-line
color: green
numbers:
- 1->2->3
`,
text,
);
});
it("should collapse escaped new line", () => {
const text = dedent`
line: 1
line: 2
`;
assertEquals("\nline: 1\nline: 2\n", text);
});
it("should do nothing for escaped newlines in template tag", () => {
const text = dedent`${"one "}\
two
three
`;
assertEquals("one two\nthree\n", text);
});
it("should handle YAML", () => {
const text = dedent`
---
a: 1
b: 2
c: 3
d: 4
`;
assertEquals(
`
---
a: 1
b: 2
c: 3
d: 4
`,
text,
);
});