@typespec/emitter-framework 0.9.0-dev.7 → 0.9.0-dev.8
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/dist/src/csharp/components/class/declaration.test.js +100 -115
- package/dist/src/csharp/components/{enum-declaration.d.ts → enum/declaration.d.ts} +1 -1
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/{enum-declaration.js → enum/declaration.js} +4 -4
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +1 -1
- package/dist/src/csharp/components/index.js +1 -1
- package/dist/src/csharp/components/property/property.test.js +14 -14
- package/package.json +7 -4
- package/src/csharp/components/class/declaration.test.tsx +106 -168
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/{enum-declaration.tsx → enum/declaration.tsx} +4 -4
- package/src/csharp/components/index.ts +1 -1
- package/src/csharp/components/property/property.test.tsx +14 -14
- package/dist/src/csharp/components/enum-declaration.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/enum-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.js +0 -403
- package/dist/test/csharp/test-host.d.ts +0 -11
- package/dist/test/csharp/test-host.d.ts.map +0 -1
- package/dist/test/csharp/test-host.js +0 -32
- package/dist/test/csharp/utils.d.ts +0 -3
- package/dist/test/csharp/utils.d.ts.map +0 -1
- package/dist/test/csharp/utils.js +0 -6
- package/test/csharp/components/enum-declaration.test.tsx +0 -337
- package/test/csharp/test-host.ts +0 -42
- package/test/csharp/utils.ts +0 -8
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Tester } from "#test/test-host.js";
|
|
3
|
+
import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
+
import { t } from "@typespec/compiler/testing";
|
|
5
|
+
import { beforeEach, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../core/index.js";
|
|
7
|
+
import { EnumDeclaration } from "../../index.js";
|
|
8
|
+
let runner;
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
runner = await Tester.createInstance();
|
|
11
|
+
});
|
|
12
|
+
function Wrapper(props) {
|
|
13
|
+
const policy = createCSharpNamePolicy();
|
|
14
|
+
return _$createComponent(Output, {
|
|
15
|
+
get program() {
|
|
16
|
+
return runner.program;
|
|
17
|
+
},
|
|
18
|
+
namePolicy: policy,
|
|
19
|
+
get children() {
|
|
20
|
+
return _$createComponent(Namespace, {
|
|
21
|
+
name: "TestNamespace",
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(SourceFile, {
|
|
24
|
+
path: "test.cs",
|
|
25
|
+
get children() {
|
|
26
|
+
return props.children;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
it("renders a basic enum declaration", async () => {
|
|
35
|
+
const {
|
|
36
|
+
TestEnum
|
|
37
|
+
} = await runner.compile(t.code`
|
|
38
|
+
@test enum ${t.enum("TestEnum")} {
|
|
39
|
+
Value1;
|
|
40
|
+
Value2;
|
|
41
|
+
Value3;
|
|
42
|
+
}
|
|
43
|
+
`);
|
|
44
|
+
expect(_$createComponent(Wrapper, {
|
|
45
|
+
get children() {
|
|
46
|
+
return _$createComponent(EnumDeclaration, {
|
|
47
|
+
type: TestEnum
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
})).toRenderTo(`
|
|
51
|
+
namespace TestNamespace
|
|
52
|
+
{
|
|
53
|
+
enum TestEnum
|
|
54
|
+
{
|
|
55
|
+
Value1,
|
|
56
|
+
Value2,
|
|
57
|
+
Value3
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
it("renders an empty enum declaration", async () => {
|
|
63
|
+
const {
|
|
64
|
+
TestEnum
|
|
65
|
+
} = await runner.compile(t.code`
|
|
66
|
+
@test enum ${t.enum("TestEnum")} {}
|
|
67
|
+
`);
|
|
68
|
+
expect(_$createComponent(Wrapper, {
|
|
69
|
+
get children() {
|
|
70
|
+
return _$createComponent(EnumDeclaration, {
|
|
71
|
+
type: TestEnum
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
})).toRenderTo(`
|
|
75
|
+
namespace TestNamespace
|
|
76
|
+
{
|
|
77
|
+
enum TestEnum
|
|
78
|
+
{
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`);
|
|
83
|
+
});
|
|
84
|
+
it("can override enum name", async () => {
|
|
85
|
+
const {
|
|
86
|
+
TestEnum
|
|
87
|
+
} = await runner.compile(t.code`
|
|
88
|
+
@test enum ${t.enum("TestEnum")} {
|
|
89
|
+
Value1;
|
|
90
|
+
Value2;
|
|
91
|
+
}
|
|
92
|
+
`);
|
|
93
|
+
expect(_$createComponent(Wrapper, {
|
|
94
|
+
get children() {
|
|
95
|
+
return _$createComponent(EnumDeclaration, {
|
|
96
|
+
type: TestEnum,
|
|
97
|
+
name: "CustomEnumName"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
})).toRenderTo(`
|
|
101
|
+
namespace TestNamespace
|
|
102
|
+
{
|
|
103
|
+
enum CustomEnumName
|
|
104
|
+
{
|
|
105
|
+
Value1,
|
|
106
|
+
Value2
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
`);
|
|
110
|
+
});
|
|
111
|
+
it("renders an enum with access modifiers", async () => {
|
|
112
|
+
const {
|
|
113
|
+
TestEnum
|
|
114
|
+
} = await runner.compile(t.code`
|
|
115
|
+
@test enum ${t.enum("TestEnum")} {
|
|
116
|
+
Value1;
|
|
117
|
+
Value2;
|
|
118
|
+
}
|
|
119
|
+
`);
|
|
120
|
+
expect(_$createComponent(Wrapper, {
|
|
121
|
+
get children() {
|
|
122
|
+
return _$createComponent(EnumDeclaration, {
|
|
123
|
+
type: TestEnum,
|
|
124
|
+
internal: true
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
})).toRenderTo(`
|
|
128
|
+
namespace TestNamespace
|
|
129
|
+
{
|
|
130
|
+
internal enum TestEnum
|
|
131
|
+
{
|
|
132
|
+
Value1,
|
|
133
|
+
Value2
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
`);
|
|
137
|
+
});
|
|
138
|
+
it("renders enum with C# naming conventions", async () => {
|
|
139
|
+
const {
|
|
140
|
+
TestEnum
|
|
141
|
+
} = await runner.compile(t.code`
|
|
142
|
+
@test enum ${t.enum("TestEnum")} {
|
|
143
|
+
value_one;
|
|
144
|
+
value_two;
|
|
145
|
+
value_three;
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
expect(_$createComponent(Output, {
|
|
149
|
+
get program() {
|
|
150
|
+
return runner.program;
|
|
151
|
+
},
|
|
152
|
+
get namePolicy() {
|
|
153
|
+
return createCSharpNamePolicy();
|
|
154
|
+
},
|
|
155
|
+
get children() {
|
|
156
|
+
return _$createComponent(Namespace, {
|
|
157
|
+
name: "TestNamespace",
|
|
158
|
+
get children() {
|
|
159
|
+
return _$createComponent(SourceFile, {
|
|
160
|
+
path: "test.cs",
|
|
161
|
+
get children() {
|
|
162
|
+
return _$createComponent(EnumDeclaration, {
|
|
163
|
+
type: TestEnum
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
})).toRenderTo(`
|
|
171
|
+
namespace TestNamespace
|
|
172
|
+
{
|
|
173
|
+
enum TestEnum
|
|
174
|
+
{
|
|
175
|
+
ValueOne,
|
|
176
|
+
ValueTwo,
|
|
177
|
+
ValueThree
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
`);
|
|
181
|
+
});
|
|
182
|
+
it("renders enum with single value", async () => {
|
|
183
|
+
const {
|
|
184
|
+
TestEnum
|
|
185
|
+
} = await runner.compile(t.code`
|
|
186
|
+
@test enum ${t.enum("TestEnum")} {
|
|
187
|
+
OnlyValue;
|
|
188
|
+
}
|
|
189
|
+
`);
|
|
190
|
+
expect(_$createComponent(Wrapper, {
|
|
191
|
+
get children() {
|
|
192
|
+
return _$createComponent(EnumDeclaration, {
|
|
193
|
+
type: TestEnum
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
})).toRenderTo(`
|
|
197
|
+
namespace TestNamespace
|
|
198
|
+
{
|
|
199
|
+
enum TestEnum
|
|
200
|
+
{
|
|
201
|
+
OnlyValue
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
`);
|
|
205
|
+
});
|
|
206
|
+
it("renders enum with numeric-like member names", async () => {
|
|
207
|
+
const {
|
|
208
|
+
TestEnum
|
|
209
|
+
} = await runner.compile(t.code`
|
|
210
|
+
@test enum ${t.enum("TestEnum")} {
|
|
211
|
+
Value0;
|
|
212
|
+
Value1;
|
|
213
|
+
Value10;
|
|
214
|
+
Value100;
|
|
215
|
+
}
|
|
216
|
+
`);
|
|
217
|
+
expect(_$createComponent(Wrapper, {
|
|
218
|
+
get children() {
|
|
219
|
+
return _$createComponent(EnumDeclaration, {
|
|
220
|
+
type: TestEnum
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
})).toRenderTo(`
|
|
224
|
+
namespace TestNamespace
|
|
225
|
+
{
|
|
226
|
+
enum TestEnum
|
|
227
|
+
{
|
|
228
|
+
Value0,
|
|
229
|
+
Value1,
|
|
230
|
+
Value10,
|
|
231
|
+
Value100
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
`);
|
|
235
|
+
});
|
|
236
|
+
it("renders multiple enums in the same namespace", async () => {
|
|
237
|
+
const {
|
|
238
|
+
TestEnum1,
|
|
239
|
+
TestEnum2
|
|
240
|
+
} = await runner.compile(t.code`
|
|
241
|
+
@test enum ${t.enum("TestEnum1")} {
|
|
242
|
+
Value1;
|
|
243
|
+
Value2;
|
|
244
|
+
}
|
|
245
|
+
@test enum ${t.enum("TestEnum2")} {
|
|
246
|
+
OptionA;
|
|
247
|
+
OptionB;
|
|
248
|
+
OptionC;
|
|
249
|
+
}
|
|
250
|
+
`);
|
|
251
|
+
expect(_$createComponent(Wrapper, {
|
|
252
|
+
get children() {
|
|
253
|
+
return [_$createComponent(EnumDeclaration, {
|
|
254
|
+
type: TestEnum1
|
|
255
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(EnumDeclaration, {
|
|
256
|
+
type: TestEnum2
|
|
257
|
+
})];
|
|
258
|
+
}
|
|
259
|
+
})).toRenderTo(`
|
|
260
|
+
namespace TestNamespace
|
|
261
|
+
{
|
|
262
|
+
enum TestEnum1
|
|
263
|
+
{
|
|
264
|
+
Value1,
|
|
265
|
+
Value2
|
|
266
|
+
}
|
|
267
|
+
enum TestEnum2
|
|
268
|
+
{
|
|
269
|
+
OptionA,
|
|
270
|
+
OptionB,
|
|
271
|
+
OptionC
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
`);
|
|
275
|
+
});
|
|
276
|
+
it("renders an enum with doc comments", async () => {
|
|
277
|
+
const {
|
|
278
|
+
TestEnum
|
|
279
|
+
} = await runner.compile(t.code`
|
|
280
|
+
@test enum ${t.enum("TestEnum")} {
|
|
281
|
+
@doc("This is value one")
|
|
282
|
+
Value1;
|
|
283
|
+
/** This is value two */
|
|
284
|
+
Value2;
|
|
285
|
+
}
|
|
286
|
+
`);
|
|
287
|
+
expect(_$createComponent(Wrapper, {
|
|
288
|
+
get children() {
|
|
289
|
+
return _$createComponent(EnumDeclaration, {
|
|
290
|
+
type: TestEnum
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
})).toRenderTo(`
|
|
294
|
+
namespace TestNamespace
|
|
295
|
+
{
|
|
296
|
+
enum TestEnum
|
|
297
|
+
{
|
|
298
|
+
/// <summary>
|
|
299
|
+
/// This is value one
|
|
300
|
+
/// </summary>
|
|
301
|
+
Value1,
|
|
302
|
+
/// <summary>
|
|
303
|
+
/// This is value two
|
|
304
|
+
/// </summary>
|
|
305
|
+
Value2
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
`);
|
|
309
|
+
});
|
|
@@ -53,10 +53,10 @@ it("maps prop: string | null to nullable property", async () => {
|
|
|
53
53
|
})).toRenderTo(`
|
|
54
54
|
namespace TestNamespace
|
|
55
55
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
class Test
|
|
57
|
+
{
|
|
58
|
+
public required string? Prop1 { get; set; }
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
`);
|
|
62
62
|
});
|
|
@@ -79,11 +79,11 @@ describe("jsonAttributes", () => {
|
|
|
79
79
|
})).toRenderTo(`
|
|
80
80
|
namespace TestNamespace
|
|
81
81
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
class Test
|
|
83
|
+
{
|
|
84
|
+
[System.Text.Json.JsonPropertyName("prop1")]
|
|
85
|
+
public required string Prop1 { get; set; }
|
|
86
|
+
}
|
|
87
87
|
}
|
|
88
88
|
`);
|
|
89
89
|
});
|
|
@@ -106,11 +106,11 @@ describe("jsonAttributes", () => {
|
|
|
106
106
|
})).toRenderTo(`
|
|
107
107
|
namespace TestNamespace
|
|
108
108
|
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
class Test
|
|
110
|
+
{
|
|
111
|
+
[System.Text.Json.JsonPropertyName("prop_1")]
|
|
112
|
+
public required string Prop1 { get; set; }
|
|
113
|
+
}
|
|
114
114
|
}
|
|
115
115
|
`);
|
|
116
116
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/emitter-framework",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"imports": {
|
|
25
|
-
"#test/*": "./test/*"
|
|
25
|
+
"#test/*": "./test/*",
|
|
26
|
+
"#core/*": "./src/core/*",
|
|
27
|
+
"#csharp/*": "./src/csharp/*",
|
|
28
|
+
"#typescript/*": "./src/typescript/*"
|
|
26
29
|
},
|
|
27
30
|
"keywords": [],
|
|
28
31
|
"author": "",
|
|
29
32
|
"license": "MIT",
|
|
30
33
|
"description": "",
|
|
31
34
|
"peerDependencies": {
|
|
32
|
-
"@alloy-js/core": "^0.18.
|
|
35
|
+
"@alloy-js/core": "^0.18.2",
|
|
33
36
|
"@alloy-js/typescript": "^0.18.0",
|
|
34
37
|
"@alloy-js/csharp": "^0.18.0",
|
|
35
38
|
"@typespec/compiler": "^1.1.0",
|
|
@@ -39,7 +42,7 @@
|
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"@alloy-js/cli": "^0.18.0",
|
|
41
44
|
"@alloy-js/rollup-plugin": "^0.1.0",
|
|
42
|
-
"@alloy-js/core": "^0.18.
|
|
45
|
+
"@alloy-js/core": "^0.18.2",
|
|
43
46
|
"@alloy-js/typescript": "^0.18.0",
|
|
44
47
|
"@types/minimist": "^1.2.5",
|
|
45
48
|
"@typespec/compiler": "^1.1.0",
|