@alloy-js/csharp 0.18.0-dev.9 → 0.18.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/src/components/ClassDeclaration.d.ts +39 -2
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  4. package/dist/src/components/ClassDeclaration.js +35 -34
  5. package/dist/src/components/ClassMethod.d.ts +33 -1
  6. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  7. package/dist/src/components/ClassMethod.js +22 -7
  8. package/dist/src/components/SourceFile.d.ts.map +1 -1
  9. package/dist/src/components/SourceFile.js +1 -0
  10. package/dist/src/components/attributes/attributes.d.ts +39 -0
  11. package/dist/src/components/attributes/attributes.d.ts.map +1 -0
  12. package/dist/src/components/attributes/attributes.js +62 -0
  13. package/dist/src/components/attributes/attributes.test.d.ts +2 -0
  14. package/dist/src/components/attributes/attributes.test.d.ts.map +1 -0
  15. package/dist/src/components/attributes/attributes.test.js +75 -0
  16. package/dist/src/components/index.d.ts +7 -1
  17. package/dist/src/components/index.d.ts.map +1 -1
  18. package/dist/src/components/index.js +8 -2
  19. package/dist/src/components/interface/declaration.d.ts +32 -1
  20. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  21. package/dist/src/components/interface/declaration.js +18 -25
  22. package/dist/src/components/interface/declaration.test.js +102 -0
  23. package/dist/src/components/interface/method.d.ts +33 -1
  24. package/dist/src/components/interface/method.d.ts.map +1 -1
  25. package/dist/src/components/interface/method.js +22 -7
  26. package/dist/src/components/interface/method.test.js +169 -0
  27. package/dist/src/components/interface/property.d.ts +36 -1
  28. package/dist/src/components/interface/property.d.ts.map +1 -1
  29. package/dist/src/components/interface/property.js +18 -4
  30. package/dist/src/components/interface/property.test.js +24 -0
  31. package/dist/src/components/parameters/parameters.d.ts +19 -0
  32. package/dist/src/components/parameters/parameters.d.ts.map +1 -0
  33. package/dist/src/components/parameters/parameters.js +43 -0
  34. package/dist/src/components/property/property.d.ts +80 -0
  35. package/dist/src/components/property/property.d.ts.map +1 -0
  36. package/dist/src/components/property/property.js +76 -0
  37. package/dist/src/components/property/property.test.d.ts +2 -0
  38. package/dist/src/components/property/property.test.d.ts.map +1 -0
  39. package/dist/src/components/property/property.test.js +242 -0
  40. package/dist/src/components/record/declaration.d.ts +35 -0
  41. package/dist/src/components/record/declaration.d.ts.map +1 -0
  42. package/dist/src/components/record/declaration.js +90 -0
  43. package/dist/src/components/record/declaration.test.d.ts +2 -0
  44. package/dist/src/components/record/declaration.test.d.ts.map +1 -0
  45. package/dist/src/components/record/declaration.test.js +94 -0
  46. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  47. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  48. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  49. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  50. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  51. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  52. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  53. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  54. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  55. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  56. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  57. package/dist/src/components/type-parameters/type-parameters.js +54 -0
  58. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  59. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  60. package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
  61. package/dist/src/components/var/declaration.d.ts +35 -0
  62. package/dist/src/components/var/declaration.d.ts.map +1 -0
  63. package/dist/src/components/var/declaration.js +40 -0
  64. package/dist/src/components/var/declaration.test.d.ts +2 -0
  65. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  66. package/dist/src/components/var/declaration.test.js +73 -0
  67. package/dist/src/name-policy.d.ts +1 -1
  68. package/dist/src/name-policy.d.ts.map +1 -1
  69. package/dist/src/name-policy.js +1 -0
  70. package/dist/test/class-declaration.test.d.ts +2 -0
  71. package/dist/test/class-declaration.test.d.ts.map +1 -0
  72. package/dist/test/{class.test.js → class-declaration.test.js} +161 -33
  73. package/dist/test/project-directory.test.d.ts +2 -0
  74. package/dist/test/project-directory.test.d.ts.map +1 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +6 -6
  77. package/src/components/ClassDeclaration.tsx +65 -33
  78. package/src/components/ClassMethod.tsx +46 -4
  79. package/src/components/SourceFile.tsx +1 -0
  80. package/src/components/attributes/attributes.test.tsx +61 -0
  81. package/src/components/attributes/attributes.tsx +100 -0
  82. package/src/components/index.ts +7 -1
  83. package/src/components/interface/declaration.test.tsx +102 -0
  84. package/src/components/interface/declaration.tsx +43 -27
  85. package/src/components/interface/method.test.tsx +173 -0
  86. package/src/components/interface/method.tsx +45 -5
  87. package/src/components/interface/property.test.tsx +21 -0
  88. package/src/components/interface/property.tsx +43 -6
  89. package/src/components/parameters/parameters.tsx +74 -0
  90. package/src/components/property/property.test.tsx +209 -0
  91. package/src/components/property/property.tsx +172 -0
  92. package/src/components/record/declaration.test.tsx +73 -0
  93. package/src/components/record/declaration.tsx +109 -0
  94. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  95. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  96. package/src/components/type-parameters/type-parameter.tsx +35 -0
  97. package/src/components/type-parameters/type-parameters.test.tsx +46 -0
  98. package/src/components/type-parameters/type-parameters.tsx +63 -0
  99. package/src/components/var/declaration.test.tsx +59 -0
  100. package/src/components/var/declaration.tsx +47 -0
  101. package/src/name-policy.ts +3 -0
  102. package/temp/api.json +4722 -2384
  103. package/test/{class.test.tsx → class-declaration.test.tsx} +144 -26
  104. package/dist/src/components/Parameters.d.ts +0 -13
  105. package/dist/src/components/Parameters.d.ts.map +0 -1
  106. package/dist/src/components/Parameters.js +0 -34
  107. package/dist/test/class.test.d.ts +0 -2
  108. package/dist/test/class.test.d.ts.map +0 -1
  109. package/dist/test/projectdirectory.test.d.ts +0 -2
  110. package/dist/test/projectdirectory.test.d.ts.map +0 -1
  111. package/src/components/Parameters.tsx +0 -51
  112. /package/dist/test/{projectdirectory.test.js → project-directory.test.js} +0 -0
  113. /package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +0 -0
@@ -1,6 +1,10 @@
1
+ import { refkey } from "@alloy-js/core";
1
2
  import { Children } from "@alloy-js/core/jsx-runtime";
2
3
  import { describe, expect, it } from "vitest";
3
4
  import { TestNamespace } from "../../../test/utils.jsx";
5
+ import { Attribute } from "../attributes/attributes.jsx";
6
+ import { SourceFile } from "../SourceFile.jsx";
7
+ import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
4
8
  import { InterfaceDeclaration } from "./declaration.jsx";
5
9
  import { InterfaceMethod } from "./method.jsx";
6
10
 
@@ -103,6 +107,58 @@ it("defines params and return type", () => {
103
107
  `);
104
108
  });
105
109
 
110
+ it("defines optional param", () => {
111
+ const res = (
112
+ <Wrapper>
113
+ <InterfaceMethod
114
+ public
115
+ name="MethodOne"
116
+ parameters={[
117
+ {
118
+ name: "intParam",
119
+ type: "int",
120
+ optional: true,
121
+ },
122
+ ]}
123
+ returns="string"
124
+ />
125
+ </Wrapper>
126
+ );
127
+
128
+ expect(res).toRenderTo(`
129
+ public interface TestInterface
130
+ {
131
+ public string MethodOne(int? intParam);
132
+ }
133
+ `);
134
+ });
135
+
136
+ it("defines optional param with default", () => {
137
+ const res = (
138
+ <Wrapper>
139
+ <InterfaceMethod
140
+ public
141
+ name="MethodOne"
142
+ parameters={[
143
+ {
144
+ name: "intParam",
145
+ type: "int",
146
+ default: 12,
147
+ },
148
+ ]}
149
+ returns="string"
150
+ />
151
+ </Wrapper>
152
+ );
153
+
154
+ expect(res).toRenderTo(`
155
+ public interface TestInterface
156
+ {
157
+ public string MethodOne(int intParam = 12);
158
+ }
159
+ `);
160
+ });
161
+
106
162
  it("specify doc comment", () => {
107
163
  expect(
108
164
  <TestNamespace>
@@ -118,3 +174,120 @@ it("specify doc comment", () => {
118
174
  }
119
175
  `);
120
176
  });
177
+
178
+ it("specify attributes", () => {
179
+ expect(
180
+ <Wrapper>
181
+ <InterfaceMethod name="Test" attributes={[<Attribute name="Test" />]} />
182
+ </Wrapper>,
183
+ ).toRenderTo(`
184
+ public interface TestInterface
185
+ {
186
+ [Test]
187
+ void Test();
188
+ }
189
+ `);
190
+ });
191
+
192
+ describe("with type parameters", () => {
193
+ it("reference parameters", () => {
194
+ const typeParameters: TypeParameterProps[] = [
195
+ {
196
+ name: "T",
197
+ refkey: refkey(),
198
+ },
199
+ {
200
+ name: "U",
201
+ refkey: refkey(),
202
+ },
203
+ ];
204
+
205
+ expect(
206
+ <TestNamespace>
207
+ <SourceFile path="TestFile.cs">
208
+ <InterfaceDeclaration public name="TestInterface">
209
+ <InterfaceMethod
210
+ name="Test"
211
+ public
212
+ typeParameters={typeParameters}
213
+ parameters={[
214
+ {
215
+ name: "paramA",
216
+ type: typeParameters[0].refkey,
217
+ },
218
+ ]}
219
+ returns={typeParameters[0].refkey}
220
+ />
221
+ </InterfaceDeclaration>
222
+ </SourceFile>
223
+ </TestNamespace>,
224
+ ).toRenderTo(`
225
+ namespace TestCode
226
+ {
227
+ public interface TestInterface
228
+ {
229
+ public T Test<T, U>(T paramA);
230
+ }
231
+ }
232
+ `);
233
+ });
234
+
235
+ it("defines with constraints", () => {
236
+ const typeParameters: TypeParameterProps[] = [
237
+ {
238
+ name: "T",
239
+ constraints: "IFoo",
240
+ },
241
+ {
242
+ name: "U",
243
+ constraints: "IBar",
244
+ },
245
+ ];
246
+
247
+ expect(
248
+ <Wrapper>
249
+ <InterfaceMethod public name="Test" typeParameters={typeParameters}>
250
+ // Body
251
+ </InterfaceMethod>
252
+ </Wrapper>,
253
+ ).toRenderTo(`
254
+ public interface TestInterface
255
+ {
256
+ public void Test<T, U>()
257
+ where T : IFoo
258
+ where U : IBar
259
+ {
260
+ // Body
261
+ }
262
+ }
263
+ `);
264
+ });
265
+ });
266
+
267
+ describe("formatting", () => {
268
+ it("Split parameters before type parameters", () => {
269
+ expect(
270
+ <Wrapper>
271
+ <InterfaceMethod
272
+ public
273
+ name="Handle"
274
+ parameters={[
275
+ {
276
+ name: "message",
277
+ type: "Some.Quite.Long.Type.That.Will.Split",
278
+ },
279
+ ]}
280
+ typeParameters={["T"]}
281
+ returns="Some.Quite.Long.Type.That.Will.Split"
282
+ />
283
+ </Wrapper>,
284
+ ).toRenderTo(`
285
+ public interface TestInterface
286
+ {
287
+ public Some.Quite.Long.Type.That.Will.Split Handle<T>(
288
+ Some.Quite.Long.Type.That.Will.Split message
289
+ );
290
+ }
291
+ `);
292
+ });
293
+ });
@@ -15,8 +15,12 @@ import {
15
15
  import { useCSharpNamePolicy } from "../../name-policy.js";
16
16
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
17
17
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
18
- import { ParameterProps, Parameters } from "../Parameters.jsx";
18
+ import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
19
19
  import { DocWhen } from "../doc/comment.jsx";
20
+ import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
21
+ import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.jsx";
22
+ import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
23
+ import { TypeParameters } from "../type-parameters/type-parameters.jsx";
20
24
 
21
25
  /** Method modifiers. Can only be one. */
22
26
  export interface InterfaceMethodModifiers {
@@ -33,10 +37,41 @@ export interface InterfaceMethodProps
33
37
  refkey?: Refkey;
34
38
  children?: Children;
35
39
  parameters?: Array<ParameterProps>;
40
+ /**
41
+ * Type parameters for the method
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <InterfaceMethod name="Test" typeParameters={["T"]} />
46
+ * ```
47
+ * This will produce:
48
+ * ```csharp
49
+ * public void Test<T>()
50
+ * ```
51
+ */
52
+ typeParameters?: (TypeParameterProps | string)[];
36
53
  returns?: Children;
37
54
 
38
55
  /** Doc comment */
39
56
  doc?: Children;
57
+
58
+ /**
59
+ * Define attributes to attach
60
+ * @example
61
+ * ```tsx
62
+ * <InterfaceMethod name="MyMethod" attributes={[
63
+ * <Attribute name="Test" />
64
+ * <Attribute name="Test2" args={["arg1", "arg2"]} />
65
+ * ]} />
66
+ * ```
67
+ * This will produce:
68
+ * ```csharp
69
+ * [Test]
70
+ * [Test2("arg1", "arg2")]
71
+ * void MyMethod();
72
+ * ```
73
+ */
74
+ attributes?: AttributesProp;
40
75
  }
41
76
 
42
77
  // a C# interface method
@@ -59,9 +94,6 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
59
94
  owner: methodSymbol,
60
95
  });
61
96
 
62
- const params =
63
- props.parameters ? <Parameters parameters={props.parameters} /> : "";
64
-
65
97
  const modifiers = computeModifiersPrefix([
66
98
  getAccessModifier(props),
67
99
  getMethodModifier(props),
@@ -71,8 +103,16 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
71
103
  <MemberDeclaration symbol={methodSymbol}>
72
104
  <Scope value={methodScope}>
73
105
  <DocWhen doc={props.doc} />
106
+ <AttributeList attributes={props.attributes} endline />
74
107
  {modifiers}
75
- {props.returns ?? "void"} {name}({params})
108
+ {props.returns ?? "void"} {name}
109
+ {props.typeParameters && (
110
+ <TypeParameters parameters={props.typeParameters} />
111
+ )}
112
+ <Parameters parameters={props.parameters} />
113
+ {props.typeParameters && (
114
+ <TypeParameterConstraints parameters={props.typeParameters} />
115
+ )}
76
116
  {props.children ?
77
117
  <Block newline>{props.children}</Block>
78
118
  : ";"}
@@ -1,6 +1,7 @@
1
1
  import { Children } from "@alloy-js/core/jsx-runtime";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
+ import { Attribute } from "../attributes/attributes.jsx";
4
5
  import { InterfaceDeclaration } from "./declaration.jsx";
5
6
  import { InterfaceProperty } from "./property.jsx";
6
7
 
@@ -142,3 +143,23 @@ it("specify doc comment", () => {
142
143
  }
143
144
  `);
144
145
  });
146
+
147
+ it("specify attributes", () => {
148
+ expect(
149
+ <Wrapper>
150
+ <InterfaceProperty
151
+ name="Test"
152
+ type="int"
153
+ attributes={[<Attribute name="Test" />]}
154
+ get
155
+ set
156
+ />
157
+ </Wrapper>,
158
+ ).toRenderTo(`
159
+ public interface TestInterface
160
+ {
161
+ [Test]
162
+ int Test { get; set; }
163
+ }
164
+ `);
165
+ });
@@ -16,6 +16,7 @@ import {
16
16
  import { useCSharpNamePolicy } from "../../name-policy.js";
17
17
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
18
18
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
19
+ import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
19
20
  import { DocWhen } from "../doc/comment.jsx";
20
21
 
21
22
  /** Method modifiers. Can only be one. */
@@ -23,9 +24,7 @@ export interface InterfacePropertyModifiers {
23
24
  readonly new?: boolean;
24
25
  }
25
26
 
26
- export const getMethodModifier = makeModifiers<InterfacePropertyModifiers>([
27
- "new",
28
- ]);
27
+ const getModifiers = makeModifiers<InterfacePropertyModifiers>(["new"]);
29
28
 
30
29
  // properties for creating a method
31
30
  export interface InterfacePropertyProps
@@ -45,9 +44,45 @@ export interface InterfacePropertyProps
45
44
 
46
45
  /** Doc comment */
47
46
  doc?: Children;
47
+
48
+ /**
49
+ * Property initializer
50
+ * @example `<ClassProperty name="My" get set nullable />`
51
+ *
52
+ * ```cs
53
+ * int? My { get; set; };
54
+ * ```
55
+ */
56
+ nullable?: boolean;
57
+
58
+ /**
59
+ * Define attributes to attach
60
+ * @example
61
+ * ```tsx
62
+ * <InterfaceProperty name="MyProp" attributes={[
63
+ * <Attribute name="Test" />
64
+ * <Attribute name="Test2" args={["arg1", "arg2"]} />
65
+ * ]} />
66
+ * ```
67
+ * This will produce:
68
+ * ```csharp
69
+ * [Test]
70
+ * [Test2("arg1", "arg2")]
71
+ * int MyProp { get; set; }
72
+ * ```
73
+ */
74
+ attributes?: AttributesProp;
48
75
  }
49
76
 
50
- // a C# interface property
77
+ /**
78
+ * Render a C# interface property.
79
+ *
80
+ * @example `<InterfaceProperty public name="My" get set />`
81
+ *
82
+ * ```cs
83
+ * public int My { get; set; };
84
+ * ```
85
+ */
51
86
  export function InterfaceProperty(props: InterfacePropertyProps) {
52
87
  const name = useCSharpNamePolicy().getName(props.name, "class-property");
53
88
  const scope = useCSharpScope();
@@ -69,15 +104,17 @@ export function InterfaceProperty(props: InterfacePropertyProps) {
69
104
 
70
105
  const modifiers = computeModifiersPrefix([
71
106
  getAccessModifier(props),
72
- getMethodModifier(props),
107
+ getModifiers(props),
73
108
  ]);
74
109
  // note that scope wraps the method decl so that the params get the correct scope
75
110
  return (
76
111
  <MemberDeclaration symbol={propertySymbol}>
77
112
  <Scope value={propertyScope}>
78
113
  <DocWhen doc={props.doc} />
114
+ <AttributeList attributes={props.attributes} endline />
79
115
  {modifiers}
80
- {props.type} {name}{" "}
116
+ {props.type}
117
+ {props.nullable && "?"} {name}{" "}
81
118
  <Block newline inline>
82
119
  <List joiner=" ">
83
120
  {props.get && "get;"}
@@ -0,0 +1,74 @@
1
+ import {
2
+ Children,
3
+ code,
4
+ Declaration,
5
+ For,
6
+ Indent,
7
+ OutputSymbol,
8
+ refkey,
9
+ Refkey,
10
+ } from "@alloy-js/core";
11
+ import { useCSharpNamePolicy } from "../../name-policy.js";
12
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
13
+ import { useCSharpScope } from "../../symbols/scopes.js";
14
+ import { Name } from "../Name.jsx";
15
+
16
+ export interface ParameterProps {
17
+ name: string;
18
+ type: Children;
19
+ /** If the parmaeter is optional(without default value) */
20
+ optional?: boolean;
21
+ /** Default value for the parameter */
22
+ default?: Children;
23
+ refkey?: Refkey;
24
+ symbol?: OutputSymbol;
25
+ }
26
+
27
+ /** Define a parameter to be used in class or interface method. */
28
+ export function Parameter(props: ParameterProps) {
29
+ const name = useCSharpNamePolicy().getName(props.name, "parameter");
30
+ const scope = useCSharpScope();
31
+ if (
32
+ scope.kind !== "member" ||
33
+ (scope.name !== "constructor-decl" && scope.name !== "method-decl")
34
+ ) {
35
+ throw new Error(
36
+ "can't define a parameter outside of a constructor-decl or method-decl scope",
37
+ );
38
+ }
39
+
40
+ const memberSymbol = new CSharpOutputSymbol(name, {
41
+ scope,
42
+ refkeys: props.refkey ?? refkey(props.name),
43
+ });
44
+
45
+ return (
46
+ <Declaration symbol={memberSymbol}>
47
+ {props.type}
48
+ {props.optional ? "?" : ""} <Name />
49
+ {props.default ? code` = ${props.default}` : ""}
50
+ </Declaration>
51
+ );
52
+ }
53
+
54
+ export interface ParametersProps {
55
+ parameters: ParameterProps[] | undefined;
56
+ }
57
+
58
+ /** Render a collection of parameters */
59
+ export function Parameters(props: ParametersProps) {
60
+ return (
61
+ <group>
62
+ {"("}
63
+ {props.parameters && (
64
+ <Indent softline>
65
+ <For each={props.parameters} joiner={", "}>
66
+ {(param) => <Parameter {...param} />}
67
+ </For>
68
+ </Indent>
69
+ )}
70
+ <softline />
71
+ {")"}
72
+ </group>
73
+ );
74
+ }
@@ -0,0 +1,209 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.jsx";
4
+ import { Attribute } from "../attributes/attributes.jsx";
5
+ import { ClassDeclaration } from "../ClassDeclaration.jsx";
6
+ import { Property } from "./property.jsx";
7
+
8
+ const Wrapper = (props: { children: Children }) => (
9
+ <TestNamespace>
10
+ <ClassDeclaration public name="TestClass">
11
+ {props.children}
12
+ </ClassDeclaration>
13
+ </TestNamespace>
14
+ );
15
+
16
+ describe("modifiers", () => {
17
+ describe("access modifiers", () => {
18
+ it.each(["public", "private", "protected", "internal"] as const)(
19
+ "%s",
20
+ (accessModifier) => {
21
+ expect(
22
+ <Wrapper>
23
+ <Property
24
+ {...{ [accessModifier]: true }}
25
+ name="TestProp"
26
+ type="string"
27
+ get
28
+ />
29
+ </Wrapper>,
30
+ ).toRenderTo(`
31
+ public class TestClass
32
+ {
33
+ ${accessModifier} string TestProp { get; }
34
+ }
35
+ `);
36
+ },
37
+ );
38
+ });
39
+
40
+ describe("property modifiers", () => {
41
+ it.each([
42
+ "new",
43
+ "static",
44
+ "virtual",
45
+ "sealed",
46
+ "override",
47
+ "abstract",
48
+ "extern",
49
+ "readonly",
50
+ "required",
51
+ ] as const)("%s", (methodModifier) => {
52
+ expect(
53
+ <Wrapper>
54
+ <Property
55
+ {...{ [methodModifier]: true }}
56
+ name="TestProp"
57
+ type="string"
58
+ get
59
+ />
60
+ </Wrapper>,
61
+ ).toRenderTo(`
62
+ public class TestClass
63
+ {
64
+ ${methodModifier} string TestProp { get; }
65
+ }
66
+ `);
67
+ });
68
+ });
69
+
70
+ it("combine modifiers", () => {
71
+ expect(
72
+ <Wrapper>
73
+ <Property public new name="TestProp" type="string" get />
74
+ </Wrapper>,
75
+ ).toRenderTo(`
76
+ public class TestClass
77
+ {
78
+ public new string TestProp { get; }
79
+ }
80
+ `);
81
+ });
82
+ });
83
+
84
+ it("applies PascalCase naming policy", () => {
85
+ expect(
86
+ <Wrapper>
87
+ <Property name="test_prop" type="string" get />
88
+ </Wrapper>,
89
+ ).toRenderTo(`
90
+ public class TestClass
91
+ {
92
+ string TestProp { get; }
93
+ }
94
+ `);
95
+ });
96
+
97
+ it("has getter only", () => {
98
+ expect(
99
+ <Wrapper>
100
+ <Property name="TestProp" type="string" get />
101
+ </Wrapper>,
102
+ ).toRenderTo(`
103
+ public class TestClass
104
+ {
105
+ string TestProp { get; }
106
+ }
107
+ `);
108
+ });
109
+
110
+ it("has setter only", () => {
111
+ expect(
112
+ <Wrapper>
113
+ <Property name="TestProp" type="string" set />
114
+ </Wrapper>,
115
+ ).toRenderTo(`
116
+ public class TestClass
117
+ {
118
+ string TestProp { set; }
119
+ }
120
+ `);
121
+ });
122
+
123
+ it("has getter and setter", () => {
124
+ expect(
125
+ <Wrapper>
126
+ <Property name="TestProp" type="string" get set />
127
+ </Wrapper>,
128
+ ).toRenderTo(`
129
+ public class TestClass
130
+ {
131
+ string TestProp { get; set; }
132
+ }
133
+ `);
134
+ });
135
+
136
+ it("has getter and init", () => {
137
+ expect(
138
+ <Wrapper>
139
+ <Property name="TestProp" type="string" get init />
140
+ </Wrapper>,
141
+ ).toRenderTo(`
142
+ public class TestClass
143
+ {
144
+ string TestProp { get; init; }
145
+ }
146
+ `);
147
+ });
148
+
149
+ it("specify doc comment", () => {
150
+ expect(
151
+ <TestNamespace>
152
+ <ClassDeclaration name="Test">
153
+ <Property name="Method" type="string" get set doc="This is a test" />
154
+ </ClassDeclaration>
155
+ </TestNamespace>,
156
+ ).toRenderTo(`
157
+ class Test
158
+ {
159
+ /// This is a test
160
+ string Method { get; set; }
161
+ }
162
+ `);
163
+ });
164
+
165
+ it("specify nullable property", () => {
166
+ expect(
167
+ <Wrapper>
168
+ <Property name="TestProp" type="string" nullable get set />
169
+ </Wrapper>,
170
+ ).toRenderTo(`
171
+ public class TestClass
172
+ {
173
+ string? TestProp { get; set; }
174
+ }
175
+ `);
176
+ });
177
+
178
+ it("specify initializer", () => {
179
+ expect(
180
+ <Wrapper>
181
+ <Property name="TestProp" type="string" get set initializer={`"abc"`} />
182
+ </Wrapper>,
183
+ ).toRenderTo(`
184
+ public class TestClass
185
+ {
186
+ string TestProp { get; set; } = "abc";
187
+ }
188
+ `);
189
+ });
190
+
191
+ it("specify attributes", () => {
192
+ expect(
193
+ <Wrapper>
194
+ <Property
195
+ name="Test"
196
+ type="int"
197
+ attributes={[<Attribute name="Test" />]}
198
+ get
199
+ set
200
+ />
201
+ </Wrapper>,
202
+ ).toRenderTo(`
203
+ public class TestClass
204
+ {
205
+ [Test]
206
+ int Test { get; set; }
207
+ }
208
+ `);
209
+ });