@alloy-js/core 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/babel.config.cjs +4 -1
- package/dist/src/binder.d.ts +20 -13
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +33 -15
- package/dist/src/binder.js.map +1 -1
- package/dist/src/code.d.ts +2 -2
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/code.js +4 -4
- package/dist/src/code.js.map +1 -1
- package/dist/src/components/Block.d.ts +25 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +25 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +1 -1
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +4 -0
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/For.d.ts +44 -0
- package/dist/src/components/For.d.ts.map +1 -0
- package/dist/src/components/For.js +41 -0
- package/dist/src/components/For.js.map +1 -0
- package/dist/src/components/Indent.d.ts +6 -10
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js +7 -18
- package/dist/src/components/Indent.js.map +1 -1
- package/dist/src/components/List.d.ts +38 -0
- package/dist/src/components/List.d.ts.map +1 -0
- package/dist/src/components/List.js +40 -0
- package/dist/src/components/List.js.map +1 -0
- package/dist/src/components/MemberDeclaration.d.ts +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/MemberName.d.ts +1 -1
- package/dist/src/components/MemberName.d.ts.map +1 -1
- package/dist/src/components/MemberName.js +1 -1
- package/dist/src/components/MemberName.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts +1 -1
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js.map +1 -1
- package/dist/src/components/Name.d.ts +1 -1
- package/dist/src/components/Name.d.ts.map +1 -1
- package/dist/src/components/Name.js +1 -1
- package/dist/src/components/Name.js.map +1 -1
- package/dist/src/components/Output.d.ts +3 -2
- package/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +12 -2
- package/dist/src/components/Output.js.map +1 -1
- package/dist/src/components/Scope.d.ts +1 -1
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Scope.js.map +1 -1
- package/dist/src/components/Show.d.ts +8 -0
- package/dist/src/components/Show.d.ts.map +1 -0
- package/dist/src/components/Show.js +4 -0
- package/dist/src/components/Show.js.map +1 -0
- package/dist/src/components/SourceDirectory.d.ts +2 -2
- package/dist/src/components/SourceDirectory.d.ts.map +1 -1
- package/dist/src/components/SourceDirectory.js +1 -0
- package/dist/src/components/SourceDirectory.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +4 -8
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +6 -13
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/StatementList.d.ts +9 -0
- package/dist/src/components/StatementList.d.ts.map +1 -0
- package/dist/src/components/StatementList.js +17 -0
- package/dist/src/components/StatementList.js.map +1 -0
- package/dist/src/components/Switch.d.ts +41 -0
- package/dist/src/components/Switch.d.ts.map +1 -0
- package/dist/src/components/Switch.js +41 -0
- package/dist/src/components/Switch.js.map +1 -0
- package/dist/src/components/Wrap.d.ts +20 -0
- package/dist/src/components/Wrap.d.ts.map +1 -0
- package/dist/src/components/Wrap.js +15 -0
- package/dist/src/components/Wrap.js.map +1 -0
- package/dist/src/components/index.d.ts +8 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +89 -18
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +17 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/context/index.d.ts +0 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +0 -1
- package/dist/src/context/index.js.map +1 -1
- package/dist/src/context/member-declaration.d.ts +1 -0
- package/dist/src/context/member-declaration.d.ts.map +1 -1
- package/dist/src/context/member-declaration.js +4 -1
- package/dist/src/context/member-declaration.js.map +1 -1
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +3 -3
- package/dist/src/context.js.map +1 -1
- package/dist/src/index.browser.d.ts +3 -0
- package/dist/src/index.browser.d.ts.map +1 -0
- package/dist/src/index.browser.js +3 -0
- package/dist/src/index.browser.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +151 -7
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +113 -12
- package/dist/src/jsx-runtime.js.map +1 -1
- package/dist/src/render.d.ts +107 -132
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +272 -178
- package/dist/src/render.js.map +1 -1
- package/dist/src/stc.d.ts +14 -0
- package/dist/src/stc.d.ts.map +1 -0
- package/dist/src/stc.js +52 -0
- package/dist/src/stc.js.map +1 -0
- package/dist/src/tap.d.ts +19 -0
- package/dist/src/tap.d.ts.map +1 -0
- package/dist/src/tap.js +39 -0
- package/dist/src/tap.js.map +1 -0
- package/dist/src/utils.d.ts +22 -15
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +95 -59
- package/dist/src/utils.js.map +1 -1
- package/dist/test/browser-build.test.d.ts +2 -0
- package/dist/test/browser-build.test.d.ts.map +1 -0
- package/dist/test/components/block.test.d.ts +2 -0
- package/dist/test/components/block.test.d.ts.map +1 -0
- package/dist/test/components/declaration.test.d.ts +2 -0
- package/dist/test/components/declaration.test.d.ts.map +1 -0
- package/dist/test/components/list.test.d.ts +2 -0
- package/dist/test/components/list.test.d.ts.map +1 -0
- package/dist/test/components/wrap.test.d.ts +2 -0
- package/dist/test/components/wrap.test.d.ts.map +1 -0
- package/dist/test/control-flow/for.test.d.ts +2 -0
- package/dist/test/control-flow/for.test.d.ts.map +1 -0
- package/dist/test/control-flow/match.test.d.ts +2 -0
- package/dist/test/control-flow/match.test.d.ts.map +1 -0
- package/dist/test/control-flow/show.test.d.ts +2 -0
- package/dist/test/control-flow/show.test.d.ts.map +1 -0
- package/dist/test/reactivity/cleanup.test.d.ts +2 -0
- package/dist/test/reactivity/cleanup.test.d.ts.map +1 -0
- package/dist/test/reactivity/memo.test.d.ts +2 -0
- package/dist/test/reactivity/memo.test.d.ts.map +1 -0
- package/dist/test/reactivity/untrack.test.d.ts +2 -0
- package/dist/test/reactivity/untrack.test.d.ts.map +1 -0
- package/dist/test/rendering/formatting.test.d.ts +2 -0
- package/dist/test/rendering/formatting.test.d.ts.map +1 -0
- package/dist/test/rendering/memoization.test.d.ts +2 -0
- package/dist/test/rendering/memoization.test.d.ts.map +1 -0
- package/dist/test/split-props.test.d.ts +2 -0
- package/dist/test/split-props.test.d.ts.map +1 -0
- package/dist/test/stc.test.d.ts.map +1 -1
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/testing/extend-expect.js +4 -4
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/testing/render.d.ts +2 -3
- package/dist/testing/render.d.ts.map +1 -1
- package/dist/testing/render.js +2 -4
- package/dist/testing/render.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -9
- package/src/binder.ts +60 -50
- package/src/code.ts +17 -12
- package/src/components/Block.tsx +44 -0
- package/src/components/Declaration.tsx +10 -4
- package/src/components/For.tsx +81 -0
- package/src/components/Indent.tsx +20 -27
- package/src/components/List.tsx +94 -0
- package/src/components/MemberDeclaration.tsx +9 -6
- package/src/components/MemberScope.tsx +4 -2
- package/src/components/Output.tsx +27 -14
- package/src/components/Scope.tsx +4 -2
- package/src/components/Show.tsx +11 -0
- package/src/components/SourceDirectory.tsx +6 -2
- package/src/components/SourceFile.tsx +13 -17
- package/src/components/StatementList.tsx +16 -0
- package/src/components/Switch.tsx +62 -0
- package/src/components/Wrap.tsx +29 -0
- package/src/components/index.tsx +8 -1
- package/src/components/stc/index.ts +18 -1
- package/src/context/index.ts +0 -1
- package/src/context/member-declaration.ts +9 -1
- package/src/context.ts +2 -3
- package/src/index.browser.ts +2 -0
- package/src/index.ts +2 -0
- package/src/jsx-runtime.ts +265 -23
- package/src/render.ts +382 -200
- package/src/stc.ts +95 -0
- package/src/tap.ts +69 -0
- package/src/utils.ts +162 -95
- package/temp/api.json +8042 -1886
- package/test/browser-build.test.ts +91 -0
- package/test/children.test.tsx +8 -10
- package/test/components/block.test.tsx +48 -0
- package/test/components/declaration.test.tsx +37 -0
- package/test/components/list.test.tsx +91 -0
- package/test/components/slot.test.tsx +31 -25
- package/test/components/source-file.test.tsx +11 -31
- package/test/components/wrap.test.tsx +42 -0
- package/test/control-flow/for.test.tsx +194 -0
- package/test/control-flow/match.test.tsx +49 -0
- package/test/control-flow/show.test.tsx +25 -0
- package/test/name-policy.test.tsx +5 -5
- package/test/reactivity/cleanup.test.tsx +91 -0
- package/test/reactivity/memo.test.tsx +17 -0
- package/test/reactivity/ref-rendering.test.tsx +3 -8
- package/test/reactivity/test.test.tsx +7 -6
- package/test/reactivity/untrack.test.ts +33 -0
- package/test/rendering/basic.test.tsx +25 -47
- package/test/rendering/code.test.tsx +3 -3
- package/test/rendering/formatting.test.tsx +487 -0
- package/test/rendering/indent.test.tsx +42 -529
- package/test/rendering/memoization.test.tsx +30 -0
- package/test/split-props.test.ts +87 -0
- package/test/stc.test.tsx +29 -8
- package/test/symbols.test.ts +132 -3
- package/test/utils.test.tsx +129 -20
- package/testing/extend-expect.ts +14 -4
- package/testing/render.ts +2 -4
- package/testing/vitest.d.ts +6 -1
- package/vitest.config.ts +1 -1
- package/dist/src/context/indent.d.ts +0 -5
- package/dist/src/context/indent.d.ts.map +0 -1
- package/dist/src/context/indent.js +0 -8
- package/dist/src/context/indent.js.map +0 -1
- package/dist/test/rendering/linebreaks.test.d.ts +0 -2
- package/dist/test/rendering/linebreaks.test.d.ts.map +0 -1
- package/src/context/indent.ts +0 -17
- package/test/rendering/linebreaks.test.tsx +0 -72
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { For, Output, render, SourceFile } from "../../src/index.js";
|
|
3
|
+
import "../../testing/extend-expect.js";
|
|
4
|
+
import { d } from "../../testing/render.js";
|
|
5
|
+
|
|
6
|
+
describe("group", () => {
|
|
7
|
+
it("breaks when shouldBreak is passed", () => {
|
|
8
|
+
expect(
|
|
9
|
+
<group shouldBreak>
|
|
10
|
+
hi
|
|
11
|
+
<sbr />
|
|
12
|
+
bye
|
|
13
|
+
</group>,
|
|
14
|
+
).toRenderTo(
|
|
15
|
+
`
|
|
16
|
+
hi
|
|
17
|
+
bye
|
|
18
|
+
`,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("indent", () => {
|
|
23
|
+
it("indents its children", () => {
|
|
24
|
+
expect(
|
|
25
|
+
<>
|
|
26
|
+
a
|
|
27
|
+
<indent>
|
|
28
|
+
<hardline />b
|
|
29
|
+
</indent>
|
|
30
|
+
</>,
|
|
31
|
+
).toRenderTo(`
|
|
32
|
+
a
|
|
33
|
+
b
|
|
34
|
+
`);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("dedent and markAsRoot", () => {
|
|
39
|
+
it("dedents its children", () => {
|
|
40
|
+
expect(
|
|
41
|
+
<>
|
|
42
|
+
base
|
|
43
|
+
<indent>
|
|
44
|
+
<hbr />a
|
|
45
|
+
<dedent>
|
|
46
|
+
<hardline />b
|
|
47
|
+
</dedent>
|
|
48
|
+
</indent>
|
|
49
|
+
</>,
|
|
50
|
+
).toRenderTo(`
|
|
51
|
+
base
|
|
52
|
+
a
|
|
53
|
+
b
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("dedentToRoot and setRoot", () => {
|
|
59
|
+
it("dedents to the indent level marked by the root when not marked", () => {
|
|
60
|
+
expect(
|
|
61
|
+
<>
|
|
62
|
+
base
|
|
63
|
+
<indent>
|
|
64
|
+
<hbr />a
|
|
65
|
+
<dedentToRoot>
|
|
66
|
+
<hbr />b
|
|
67
|
+
</dedentToRoot>
|
|
68
|
+
</indent>
|
|
69
|
+
</>,
|
|
70
|
+
).toRenderTo(`
|
|
71
|
+
base
|
|
72
|
+
a
|
|
73
|
+
b
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
it("dedents to the indent level marked by the root when marked", () => {
|
|
77
|
+
expect(
|
|
78
|
+
<>
|
|
79
|
+
base
|
|
80
|
+
<indent>
|
|
81
|
+
<hbr />
|
|
82
|
+
root
|
|
83
|
+
<markAsRoot>
|
|
84
|
+
<indent>
|
|
85
|
+
<hbr />a
|
|
86
|
+
<dedentToRoot>
|
|
87
|
+
<hbr />b
|
|
88
|
+
</dedentToRoot>
|
|
89
|
+
</indent>
|
|
90
|
+
</markAsRoot>
|
|
91
|
+
</indent>
|
|
92
|
+
</>,
|
|
93
|
+
).toRenderTo(`
|
|
94
|
+
base
|
|
95
|
+
root
|
|
96
|
+
a
|
|
97
|
+
b
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("softline", () => {
|
|
103
|
+
it("breaks to to a new line when needed", () => {
|
|
104
|
+
expect(
|
|
105
|
+
<group>
|
|
106
|
+
1234567890
|
|
107
|
+
<softline />
|
|
108
|
+
1234567890
|
|
109
|
+
</group>,
|
|
110
|
+
).toRenderTo(`12345678901234567890`, { printWidth: 25 });
|
|
111
|
+
expect(
|
|
112
|
+
<group>
|
|
113
|
+
1234567890
|
|
114
|
+
<softline />
|
|
115
|
+
1234567890
|
|
116
|
+
</group>,
|
|
117
|
+
).toRenderTo(
|
|
118
|
+
`
|
|
119
|
+
1234567890
|
|
120
|
+
1234567890
|
|
121
|
+
`,
|
|
122
|
+
{ printWidth: 15 },
|
|
123
|
+
);
|
|
124
|
+
expect(
|
|
125
|
+
<group>
|
|
126
|
+
1234567890
|
|
127
|
+
<sbr />
|
|
128
|
+
1234567890
|
|
129
|
+
</group>,
|
|
130
|
+
).toRenderTo(`12345678901234567890`, { printWidth: 25 });
|
|
131
|
+
expect(
|
|
132
|
+
<group>
|
|
133
|
+
1234567890
|
|
134
|
+
<sbr />
|
|
135
|
+
1234567890
|
|
136
|
+
</group>,
|
|
137
|
+
).toRenderTo(
|
|
138
|
+
`
|
|
139
|
+
1234567890
|
|
140
|
+
1234567890
|
|
141
|
+
`,
|
|
142
|
+
{ printWidth: 15 },
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("hardline", () => {
|
|
148
|
+
it("always breaks to a new line", () => {
|
|
149
|
+
expect(
|
|
150
|
+
<group>
|
|
151
|
+
1234567890
|
|
152
|
+
<hardline />
|
|
153
|
+
1234567890
|
|
154
|
+
</group>,
|
|
155
|
+
).toRenderTo(
|
|
156
|
+
`
|
|
157
|
+
1234567890
|
|
158
|
+
1234567890
|
|
159
|
+
`,
|
|
160
|
+
);
|
|
161
|
+
expect(
|
|
162
|
+
<group>
|
|
163
|
+
1234567890
|
|
164
|
+
<hbr />
|
|
165
|
+
1234567890
|
|
166
|
+
</group>,
|
|
167
|
+
).toRenderTo(
|
|
168
|
+
`
|
|
169
|
+
1234567890
|
|
170
|
+
1234567890
|
|
171
|
+
`,
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("line", () => {
|
|
177
|
+
it("creates a new line when needed, is otherwise space", () => {
|
|
178
|
+
expect(
|
|
179
|
+
<group>
|
|
180
|
+
1234567890
|
|
181
|
+
<line />
|
|
182
|
+
1234567890
|
|
183
|
+
</group>,
|
|
184
|
+
).toRenderTo(`1234567890 1234567890`, { printWidth: 25 });
|
|
185
|
+
expect(
|
|
186
|
+
<group>
|
|
187
|
+
1234567890
|
|
188
|
+
<line />
|
|
189
|
+
1234567890
|
|
190
|
+
</group>,
|
|
191
|
+
).toRenderTo(
|
|
192
|
+
`
|
|
193
|
+
1234567890
|
|
194
|
+
1234567890
|
|
195
|
+
`,
|
|
196
|
+
{ printWidth: 15 },
|
|
197
|
+
);
|
|
198
|
+
expect(
|
|
199
|
+
<group>
|
|
200
|
+
1234567890
|
|
201
|
+
<br />
|
|
202
|
+
1234567890
|
|
203
|
+
</group>,
|
|
204
|
+
).toRenderTo(`1234567890 1234567890`, { printWidth: 25 });
|
|
205
|
+
expect(
|
|
206
|
+
<group>
|
|
207
|
+
1234567890
|
|
208
|
+
<br />
|
|
209
|
+
1234567890
|
|
210
|
+
</group>,
|
|
211
|
+
).toRenderTo(
|
|
212
|
+
`
|
|
213
|
+
1234567890
|
|
214
|
+
1234567890
|
|
215
|
+
`,
|
|
216
|
+
{ printWidth: 15 },
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("literalline", () => {
|
|
222
|
+
it("always creates a new line", () => {
|
|
223
|
+
expect(
|
|
224
|
+
<>
|
|
225
|
+
base
|
|
226
|
+
<indent>
|
|
227
|
+
<hbr />
|
|
228
|
+
1234567890
|
|
229
|
+
<literalline />
|
|
230
|
+
1234567890
|
|
231
|
+
<hbr />x
|
|
232
|
+
</indent>
|
|
233
|
+
</>,
|
|
234
|
+
).toRenderTo(
|
|
235
|
+
`
|
|
236
|
+
base
|
|
237
|
+
1234567890
|
|
238
|
+
1234567890
|
|
239
|
+
x
|
|
240
|
+
`,
|
|
241
|
+
);
|
|
242
|
+
expect(
|
|
243
|
+
<>
|
|
244
|
+
base
|
|
245
|
+
<indent>
|
|
246
|
+
<hbr />
|
|
247
|
+
1234567890
|
|
248
|
+
<lbr />
|
|
249
|
+
1234567890
|
|
250
|
+
<hbr />x
|
|
251
|
+
</indent>
|
|
252
|
+
</>,
|
|
253
|
+
).toRenderTo(
|
|
254
|
+
`
|
|
255
|
+
base
|
|
256
|
+
1234567890
|
|
257
|
+
1234567890
|
|
258
|
+
x
|
|
259
|
+
`,
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe("lineSuffix and lineSuffixBoundary", () => {
|
|
265
|
+
it("adds a line suffix", () => {
|
|
266
|
+
expect(
|
|
267
|
+
<>
|
|
268
|
+
hello<lineSuffix>// comment</lineSuffix> there
|
|
269
|
+
<hbr />
|
|
270
|
+
how<lineSuffix>// another comment</lineSuffix> are{" "}
|
|
271
|
+
<lineSuffixBoundary />
|
|
272
|
+
you
|
|
273
|
+
</>,
|
|
274
|
+
).toRenderTo(
|
|
275
|
+
`
|
|
276
|
+
hello there// comment
|
|
277
|
+
how are // another comment
|
|
278
|
+
you
|
|
279
|
+
`,
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("breakParent", () => {
|
|
285
|
+
it("breaks the parent group", () => {
|
|
286
|
+
expect(
|
|
287
|
+
<group>
|
|
288
|
+
<breakParent />
|
|
289
|
+
one
|
|
290
|
+
<sbr />
|
|
291
|
+
two
|
|
292
|
+
</group>,
|
|
293
|
+
).toRenderTo(
|
|
294
|
+
`
|
|
295
|
+
one
|
|
296
|
+
two
|
|
297
|
+
`,
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe("ifBreak", () => {
|
|
303
|
+
it("renders the children when broken", () => {
|
|
304
|
+
expect(
|
|
305
|
+
<group>
|
|
306
|
+
<ifBreak flatContents="bye">hi</ifBreak>
|
|
307
|
+
</group>,
|
|
308
|
+
).toRenderTo(`bye`);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("renders the children when not broken", () => {
|
|
312
|
+
expect(
|
|
313
|
+
<group>
|
|
314
|
+
<ifBreak flatContents="bye">hi</ifBreak>
|
|
315
|
+
<breakParent />
|
|
316
|
+
</group>,
|
|
317
|
+
).toRenderTo(`hi`);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("renders flatContents that are elements", () => {
|
|
321
|
+
function Foo() {
|
|
322
|
+
return "Foo";
|
|
323
|
+
}
|
|
324
|
+
const contents = (
|
|
325
|
+
<>
|
|
326
|
+
<Foo />
|
|
327
|
+
<Foo />
|
|
328
|
+
</>
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
expect(
|
|
332
|
+
<group>
|
|
333
|
+
<ifBreak flatContents={contents}>hi</ifBreak>
|
|
334
|
+
</group>,
|
|
335
|
+
).toRenderTo(`FooFoo`);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("works with a group id", () => {
|
|
339
|
+
const id = Symbol();
|
|
340
|
+
expect(
|
|
341
|
+
<>
|
|
342
|
+
<group id={id}>
|
|
343
|
+
a<hbr />b<hbr />
|
|
344
|
+
</group>
|
|
345
|
+
<ifBreak groupId={id}>c</ifBreak>
|
|
346
|
+
</>,
|
|
347
|
+
).toRenderTo(`a\nb\nc`);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe("fill", () => {
|
|
352
|
+
it("fills the group with its children", () => {
|
|
353
|
+
const items = ["one", "two", "three", "four", "five", "six"];
|
|
354
|
+
// place a <br /> after every item except the last
|
|
355
|
+
const filledItems = items.map((item, index) => (
|
|
356
|
+
<>
|
|
357
|
+
{item}
|
|
358
|
+
{index < items.length - 1 && <br />}
|
|
359
|
+
</>
|
|
360
|
+
));
|
|
361
|
+
|
|
362
|
+
expect(<fill>{filledItems}</fill>).toRenderTo(
|
|
363
|
+
`one two three four\nfive six`,
|
|
364
|
+
{ printWidth: 20 },
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
describe("align", () => {
|
|
370
|
+
it("aligns contents with a number of spaces", () => {
|
|
371
|
+
expect(
|
|
372
|
+
<>
|
|
373
|
+
base
|
|
374
|
+
<align width={4}>
|
|
375
|
+
<hbr />
|
|
376
|
+
hi
|
|
377
|
+
</align>
|
|
378
|
+
</>,
|
|
379
|
+
).toRenderTo(
|
|
380
|
+
`
|
|
381
|
+
base
|
|
382
|
+
hi
|
|
383
|
+
`,
|
|
384
|
+
);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("aligns contents with a string", () => {
|
|
388
|
+
expect(
|
|
389
|
+
<>
|
|
390
|
+
base
|
|
391
|
+
<align string="XXXX">
|
|
392
|
+
<hbr />
|
|
393
|
+
hi
|
|
394
|
+
</align>
|
|
395
|
+
</>,
|
|
396
|
+
).toRenderTo(
|
|
397
|
+
`
|
|
398
|
+
base
|
|
399
|
+
XXXXhi
|
|
400
|
+
`,
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("all works together", () => {
|
|
406
|
+
const argCount = 2;
|
|
407
|
+
const args = Array.from({ length: argCount }, (_, i) => `arg${i + 1}`);
|
|
408
|
+
expect(
|
|
409
|
+
<>
|
|
410
|
+
<group>
|
|
411
|
+
async function foo(
|
|
412
|
+
<indent>
|
|
413
|
+
<sbr />
|
|
414
|
+
<For
|
|
415
|
+
each={args}
|
|
416
|
+
joiner={
|
|
417
|
+
<>
|
|
418
|
+
,<br />
|
|
419
|
+
</>
|
|
420
|
+
}
|
|
421
|
+
>
|
|
422
|
+
{(arg) => <>{arg}: string</>}
|
|
423
|
+
</For>
|
|
424
|
+
</indent>
|
|
425
|
+
<sbr />)
|
|
426
|
+
</group>
|
|
427
|
+
: void {"{"}
|
|
428
|
+
<indent>
|
|
429
|
+
<hbr />
|
|
430
|
+
// function body
|
|
431
|
+
</indent>
|
|
432
|
+
<hbr />
|
|
433
|
+
{"}"}
|
|
434
|
+
</>,
|
|
435
|
+
).toRenderTo(
|
|
436
|
+
`
|
|
437
|
+
async function foo(arg1: string, arg2: string): void {
|
|
438
|
+
// function body
|
|
439
|
+
}
|
|
440
|
+
`,
|
|
441
|
+
{ printWidth: 80 },
|
|
442
|
+
);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("formats based on the output component props", () => {
|
|
446
|
+
const template = (
|
|
447
|
+
<Output printWidth={5}>
|
|
448
|
+
<SourceFile path="foo.txt" filetype="text/plain">
|
|
449
|
+
<group>
|
|
450
|
+
1<br />2<br />3<br />4<br />5<br />6
|
|
451
|
+
</group>
|
|
452
|
+
</SourceFile>
|
|
453
|
+
</Output>
|
|
454
|
+
);
|
|
455
|
+
|
|
456
|
+
const tree = render(template);
|
|
457
|
+
expect(tree.contents[0].contents).toEqual(d`
|
|
458
|
+
1
|
|
459
|
+
2
|
|
460
|
+
3
|
|
461
|
+
4
|
|
462
|
+
5
|
|
463
|
+
6
|
|
464
|
+
`);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("formats based on the source file component props", () => {
|
|
468
|
+
const template = (
|
|
469
|
+
<Output>
|
|
470
|
+
<SourceFile path="foo.txt" filetype="text/plain" printWidth={5}>
|
|
471
|
+
<group>
|
|
472
|
+
1<br />2<br />3<br />4<br />5<br />6
|
|
473
|
+
</group>
|
|
474
|
+
</SourceFile>
|
|
475
|
+
</Output>
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
const tree = render(template);
|
|
479
|
+
expect(tree.contents[0].contents).toEqual(d`
|
|
480
|
+
1
|
|
481
|
+
2
|
|
482
|
+
3
|
|
483
|
+
4
|
|
484
|
+
5
|
|
485
|
+
6
|
|
486
|
+
`);
|
|
487
|
+
});
|