@alloy-js/csharp 0.18.0-dev.16 → 0.18.0-dev.18

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 (60) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +14 -1
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +12 -25
  4. package/dist/src/components/ClassMethod.d.ts +14 -0
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +11 -1
  7. package/dist/src/components/index.d.ts +2 -0
  8. package/dist/src/components/index.d.ts.map +1 -1
  9. package/dist/src/components/index.js +3 -1
  10. package/dist/src/components/interface/declaration.d.ts +14 -1
  11. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  12. package/dist/src/components/interface/declaration.js +12 -25
  13. package/dist/src/components/interface/declaration.test.js +84 -0
  14. package/dist/src/components/interface/method.d.ts +14 -0
  15. package/dist/src/components/interface/method.d.ts.map +1 -1
  16. package/dist/src/components/interface/method.js +11 -1
  17. package/dist/src/components/interface/method.test.js +79 -0
  18. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  19. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  20. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  21. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  22. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  23. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  24. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  25. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  26. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  27. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  28. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  29. package/dist/src/components/type-parameters/type-parameters.js +65 -0
  30. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  31. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  32. package/dist/src/components/type-parameters/type-parameters.test.js +26 -0
  33. package/dist/src/components/var/declaration.d.ts +35 -0
  34. package/dist/src/components/var/declaration.d.ts.map +1 -0
  35. package/dist/src/components/var/declaration.js +40 -0
  36. package/dist/src/components/var/declaration.test.d.ts +2 -0
  37. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  38. package/dist/src/components/var/declaration.test.js +73 -0
  39. package/dist/src/name-policy.d.ts +1 -1
  40. package/dist/src/name-policy.d.ts.map +1 -1
  41. package/dist/test/class-declaration.test.js +79 -33
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +2 -2
  44. package/src/components/ClassDeclaration.tsx +23 -27
  45. package/src/components/ClassMethod.tsx +25 -1
  46. package/src/components/index.ts +2 -0
  47. package/src/components/interface/declaration.test.tsx +87 -0
  48. package/src/components/interface/declaration.tsx +23 -27
  49. package/src/components/interface/method.test.tsx +78 -0
  50. package/src/components/interface/method.tsx +24 -1
  51. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  52. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  53. package/src/components/type-parameters/type-parameter.tsx +35 -0
  54. package/src/components/type-parameters/type-parameters.test.tsx +19 -0
  55. package/src/components/type-parameters/type-parameters.tsx +72 -0
  56. package/src/components/var/declaration.test.tsx +59 -0
  57. package/src/components/var/declaration.tsx +47 -0
  58. package/src/name-policy.ts +1 -0
  59. package/temp/api.json +415 -23
  60. package/test/class-declaration.test.tsx +75 -25
@@ -0,0 +1,67 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { expect, it } from "vitest";
3
+ import { TypeParameterConstraints } from "./type-parameter-constraints.js";
4
+ it("renders nothing if there is no constraints", () => {
5
+ expect(_$createComponent(TypeParameterConstraints, {
6
+ parameters: ["A", "B"]
7
+ })).toRenderTo(``);
8
+ });
9
+ it("renders inline if there is only one", () => {
10
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
11
+ parameters: [{
12
+ name: "A",
13
+ constraints: "string"
14
+ }]
15
+ })]).toRenderTo(`
16
+ code() where A : string
17
+ `);
18
+ });
19
+ it("renders multiple constraints", () => {
20
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
21
+ parameters: [{
22
+ name: "A",
23
+ constraints: ["string", "int"]
24
+ }]
25
+ })]).toRenderTo(`
26
+ code() where A : string, int
27
+ `);
28
+ });
29
+ it("renders newline if constraint is very long", () => {
30
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
31
+ parameters: [{
32
+ name: "ThisIsQuiteALongName",
33
+ constraints: "VeryLongBuilderFactorySingletonThatShouldBeSplit"
34
+ }]
35
+ })]).toRenderTo(`
36
+ code()
37
+ where ThisIsQuiteALongName : VeryLongBuilderFactorySingletonThatShouldBeSplit
38
+ `);
39
+ });
40
+ it("renders multiple constraints on new lines if they are very long", () => {
41
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
42
+ parameters: [{
43
+ name: "A",
44
+ constraints: ["IVeryLongBuilderFactorySingletonThatShouldBeSplitA", "IVeryLongBuilderFactorySingletonThatShouldBeSplitB"]
45
+ }]
46
+ })]).toRenderTo(`
47
+ code()
48
+ where A :
49
+ IVeryLongBuilderFactorySingletonThatShouldBeSplitA,
50
+ IVeryLongBuilderFactorySingletonThatShouldBeSplitB
51
+ `);
52
+ });
53
+ it("declare type parameters using parameters", () => {
54
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
55
+ parameters: [{
56
+ name: "A",
57
+ constraints: "string"
58
+ }, {
59
+ name: "B",
60
+ constraints: "string"
61
+ }]
62
+ })]).toRenderTo(`
63
+ code()
64
+ where A : string
65
+ where B : string
66
+ `);
67
+ });
@@ -0,0 +1,20 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ /**
3
+ * Information for a TypeScript generic type parameter.
4
+ */
5
+ export interface TypeParameterProps {
6
+ /**
7
+ * The name of the type parameter.
8
+ */
9
+ readonly name: string;
10
+ /**
11
+ * The parameter constraint
12
+ */
13
+ readonly constraints?: Children | Children[];
14
+ /**
15
+ * A refkey or array of refkeys for this type parameter.
16
+ */
17
+ readonly refkey?: Refkey | Refkey[];
18
+ }
19
+ export declare function TypeParameter(props: TypeParameterProps): Children;
20
+ //# sourceMappingURL=type-parameter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameter.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACrC;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAStD"}
@@ -0,0 +1,22 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { MemberDeclaration, refkey } from "@alloy-js/core";
3
+ import { useCSharpNamePolicy } from "../../name-policy.js";
4
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
5
+ import { useCSharpScope } from "../../symbols/scopes.js";
6
+
7
+ /**
8
+ * Information for a TypeScript generic type parameter.
9
+ */
10
+
11
+ export function TypeParameter(props) {
12
+ const name = useCSharpNamePolicy().getName(props.name, "type-parameter");
13
+ const scope = useCSharpScope();
14
+ const symbol = new CSharpOutputSymbol(name, {
15
+ scope,
16
+ refkeys: props.refkey ?? refkey(props.name)
17
+ });
18
+ return _$createComponent(MemberDeclaration, {
19
+ symbol: symbol,
20
+ children: name
21
+ });
22
+ }
@@ -0,0 +1,17 @@
1
+ import { TypeParameterProps } from "./type-parameter.jsx";
2
+ export declare const typeParametersTag: unique symbol;
3
+ export interface TypeParametersProps {
4
+ /** Parameters */
5
+ parameters: (TypeParameterProps | string)[];
6
+ }
7
+ /**
8
+ * Represent type parameters
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * <A, B extends string>
13
+ * ```
14
+ */
15
+ export declare const TypeParameters: import("@alloy-js/core").Component<TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<TypeParametersProps>, "tag">>;
16
+ export declare function normalizeParameters(parameters: (TypeParameterProps | string)[]): TypeParameterProps[];
17
+ //# sourceMappingURL=type-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameters.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,eAAO,MAAM,iBAAiB,eAAuC,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IA4B1B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,GAC1C,kBAAkB,EAAE,CAOtB"}
@@ -0,0 +1,65 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { For, Indent, taggedComponent } from "@alloy-js/core";
3
+ import { TypeParameter } from "./type-parameter.js";
4
+ export const typeParametersTag = Symbol.for("csharp.type-parameters");
5
+ /**
6
+ * Represent type parameters
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * <A, B extends string>
11
+ * ```
12
+ */
13
+ export const TypeParameters = taggedComponent(typeParametersTag, function TypeParameters(props) {
14
+ const typeParameters = normalizeParameters(props.parameters);
15
+
16
+ // const typeParameters = normalizeAndDeclareParameters(props.parameters);
17
+
18
+ // onCleanup(() => {
19
+ // for (const param of typeParameters) {
20
+ // param.symbol.delete();
21
+ // }
22
+ // });
23
+
24
+ return ["<", _$createIntrinsic("group", {
25
+ get children() {
26
+ return _$createComponent(Indent, {
27
+ softline: true,
28
+ get children() {
29
+ return [_$createComponent(For, {
30
+ each: typeParameters,
31
+ comma: true,
32
+ line: true,
33
+ children: param => _$createComponent(TypeParameter, param)
34
+ }), _$createIntrinsic("ifBreak", {
35
+ children: ","
36
+ })];
37
+ }
38
+ });
39
+ }
40
+ }), ">"];
41
+ });
42
+ export function normalizeParameters(parameters) {
43
+ return parameters.map(param => {
44
+ if (typeof param === "string") {
45
+ return {
46
+ name: param
47
+ };
48
+ }
49
+ return param;
50
+ });
51
+ }
52
+
53
+ // export function declareParameter(
54
+ // parameters: TypeParameterProps[],
55
+ // ): TypeParameterProps[] {
56
+ // return parameters.map((param) => {
57
+ // return {
58
+ // ...param,
59
+ // symbol: new CSharpOutputSymbol(entry[0], {
60
+ // scope: thisClassScope,
61
+ // refkeys: entry[1],
62
+ // }),
63
+ // };
64
+ // });
65
+ // }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-parameters.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameters.test.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameters.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { TypeParameters } from "./type-parameters.js";
5
+ it("declare type parameters using parameters names", () => {
6
+ expect(_$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(TypeParameters, {
9
+ parameters: ["A", "B"]
10
+ });
11
+ }
12
+ })).toRenderTo(`<A, B>`);
13
+ });
14
+ it("declare type parameters using parameters", () => {
15
+ expect(_$createComponent(TestNamespace, {
16
+ get children() {
17
+ return _$createComponent(TypeParameters, {
18
+ parameters: [{
19
+ name: "A"
20
+ }, {
21
+ name: "B"
22
+ }]
23
+ });
24
+ }
25
+ })).toRenderTo(`<A, B>`);
26
+ });
@@ -0,0 +1,35 @@
1
+ import { Children, DeclarationProps, Refkey } from "@alloy-js/core";
2
+ /** Props for {@link VarDeclaration} component */
3
+ export interface VarDeclarationProps extends Omit<DeclarationProps, "nameKind"> {
4
+ /** Variable name */
5
+ name: string;
6
+ /** Type of the variable declaration. If not specified, defaults to "var" */
7
+ type?: Children;
8
+ /** Variable refkey */
9
+ refkey?: Refkey;
10
+ /** Variable value */
11
+ children?: Children;
12
+ }
13
+ /**
14
+ * Render a variable declaration
15
+ *
16
+ * @example with var
17
+ * ```tsx
18
+ * <VarDeclaration name="myVar">42</VarDeclaration>
19
+ * ```
20
+ * This will render:
21
+ * ```csharp
22
+ * var myVar = 42;
23
+ * ```
24
+ *
25
+ * @example with type
26
+ * ```tsx
27
+ * <VarDeclaration name="myVar" type="int">42</VarDeclaration>
28
+ * ```
29
+ * This will render:
30
+ * ```csharp
31
+ * int myVar = 42;
32
+ * ```
33
+ */
34
+ export declare function VarDeclaration(props: VarDeclarationProps): Children;
35
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/var/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAQ,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI1E,iDAAiD;AACjD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC;IAC1C,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YAQxD"}
@@ -0,0 +1,40 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Name } from "@alloy-js/core";
3
+ import { useCSharpNamePolicy } from "../../name-policy.js";
4
+ import { Declaration } from "../Declaration.js";
5
+
6
+ /** Props for {@link VarDeclaration} component */
7
+
8
+ /**
9
+ * Render a variable declaration
10
+ *
11
+ * @example with var
12
+ * ```tsx
13
+ * <VarDeclaration name="myVar">42</VarDeclaration>
14
+ * ```
15
+ * This will render:
16
+ * ```csharp
17
+ * var myVar = 42;
18
+ * ```
19
+ *
20
+ * @example with type
21
+ * ```tsx
22
+ * <VarDeclaration name="myVar" type="int">42</VarDeclaration>
23
+ * ```
24
+ * This will render:
25
+ * ```csharp
26
+ * int myVar = 42;
27
+ * ```
28
+ */
29
+ export function VarDeclaration(props) {
30
+ const name = useCSharpNamePolicy().getName(props.name, "variable");
31
+ return _$createComponent(Declaration, {
32
+ name: name,
33
+ get refkey() {
34
+ return props.refkey;
35
+ },
36
+ get children() {
37
+ return [_$memo(() => props.type ?? "var"), " ", _$createComponent(Name, {}), " = ", _$memo(() => props.children), ";"];
38
+ }
39
+ });
40
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/var/declaration.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,73 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { List, refkey } from "@alloy-js/core";
3
+ import { expect, it } from "vitest";
4
+ import { TestNamespace } from "../../../test/utils.js";
5
+ import { SourceFile } from "../SourceFile.js";
6
+ import { VarDeclaration } from "./declaration.js";
7
+ it("declares var without type", () => {
8
+ expect(_$createComponent(TestNamespace, {
9
+ get children() {
10
+ return _$createComponent(VarDeclaration, {
11
+ name: "testVar",
12
+ children: "42"
13
+ });
14
+ }
15
+ })).toRenderTo(`
16
+ var testVar = 42;
17
+ `);
18
+ });
19
+ it("declares var with type", () => {
20
+ expect(_$createComponent(TestNamespace, {
21
+ get children() {
22
+ return _$createComponent(VarDeclaration, {
23
+ name: "testVar",
24
+ type: "int",
25
+ children: "42"
26
+ });
27
+ }
28
+ })).toRenderTo(`
29
+ int testVar = 42;
30
+ `);
31
+ });
32
+ it("name variables camel case", () => {
33
+ expect(_$createComponent(TestNamespace, {
34
+ get children() {
35
+ return _$createComponent(VarDeclaration, {
36
+ name: "test_var",
37
+ children: "42"
38
+ });
39
+ }
40
+ })).toRenderTo(`
41
+ var testVar = 42;
42
+ `);
43
+ });
44
+ it("links refkey", () => {
45
+ const key = refkey();
46
+ expect(_$createComponent(TestNamespace, {
47
+ get children() {
48
+ return _$createComponent(SourceFile, {
49
+ path: "test.cs",
50
+ get children() {
51
+ return _$createComponent(List, {
52
+ get children() {
53
+ return [_$createComponent(VarDeclaration, {
54
+ name: "testVar",
55
+ refkey: key,
56
+ children: "42"
57
+ }), _$createComponent(VarDeclaration, {
58
+ name: "testVar2",
59
+ children: key
60
+ })];
61
+ }
62
+ });
63
+ }
64
+ });
65
+ }
66
+ })).toRenderTo(`
67
+ namespace TestCode
68
+ {
69
+ var testVar = 42;
70
+ var testVar2 = testVar;
71
+ }
72
+ `);
73
+ });
@@ -1,5 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
2
- export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
2
+ export type CSharpElements = "class" | "constant" | "variable" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
3
3
  export declare function createCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
4
4
  export declare function useCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
5
5
  //# sourceMappingURL=name-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAmBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
1
+ {"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAmBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
@@ -1,9 +1,10 @@
1
1
  import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
+ import { List, refkey } from "@alloy-js/core";
3
4
  import * as coretest from "@alloy-js/core/testing";
4
5
  import { describe, expect, it } from "vitest";
5
6
  import * as csharp from "../src/index.js";
6
- import { ClassDeclaration, ClassMember } from "../src/index.js";
7
+ import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
7
8
  import * as utils from "./utils.js";
8
9
  it("declares class with no members", () => {
9
10
  expect(_$createComponent(utils.TestNamespace, {
@@ -251,41 +252,86 @@ it("uses refkeys for members, params, and return type", () => {
251
252
  }
252
253
  `);
253
254
  });
254
- it("declares class with generic parameters", () => {
255
- const typeParameters = {
256
- T: core.refkey(),
257
- U: core.refkey()
258
- };
259
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
260
- "public": true,
261
- name: "TestClass",
262
- typeParameters: typeParameters,
263
- get children() {
264
- return [_$createComponent(csharp.ClassMember, {
265
- "public": true,
266
- name: "memberOne",
267
- get type() {
268
- return typeParameters.T;
269
- }
270
- }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
271
- "private": true,
272
- name: "memberTwo",
273
- get type() {
274
- return typeParameters.U;
275
- }
276
- }), ";"];
277
- }
278
- }));
279
- expect(res).toBe(coretest.d`
280
- namespace TestCode
281
- {
255
+ describe("with type parameters", () => {
256
+ it("reference parameters", () => {
257
+ const typeParameters = [{
258
+ name: "T",
259
+ refkey: refkey()
260
+ }, {
261
+ name: "U",
262
+ refkey: refkey()
263
+ }];
264
+ expect(_$createComponent(utils.TestNamespace, {
265
+ get children() {
266
+ return _$createComponent(SourceFile, {
267
+ path: "Test.cs",
268
+ get children() {
269
+ return _$createComponent(ClassDeclaration, {
270
+ "public": true,
271
+ name: "TestClass",
272
+ typeParameters: typeParameters,
273
+ get children() {
274
+ return _$createComponent(List, {
275
+ get children() {
276
+ return [_$createComponent(Property, {
277
+ name: "PropA",
278
+ get type() {
279
+ return typeParameters[0].refkey;
280
+ },
281
+ get: true,
282
+ set: true
283
+ }), _$createComponent(Property, {
284
+ name: "PropB",
285
+ get type() {
286
+ return typeParameters[1].refkey;
287
+ },
288
+ get: true,
289
+ set: true
290
+ })];
291
+ }
292
+ });
293
+ }
294
+ });
295
+ }
296
+ });
297
+ }
298
+ })).toRenderTo(`
299
+ namespace TestCode
300
+ {
282
301
  public class TestClass<T, U>
283
302
  {
284
- public T MemberOne;
285
- private U memberTwo;
303
+ T PropA { get; set; }
304
+ U PropB { get; set; }
286
305
  }
287
- }
288
- `);
306
+ }
307
+ `);
308
+ });
309
+ it("defines with constraints", () => {
310
+ const typeParameters = [{
311
+ name: "T",
312
+ constraints: "IFoo"
313
+ }, {
314
+ name: "U",
315
+ constraints: "IBar"
316
+ }];
317
+ expect(_$createComponent(utils.TestNamespace, {
318
+ get children() {
319
+ return _$createComponent(ClassDeclaration, {
320
+ "public": true,
321
+ name: "TestClass",
322
+ typeParameters: typeParameters,
323
+ children: "// Body"
324
+ });
325
+ }
326
+ })).toRenderTo(`
327
+ public class TestClass<T, U>
328
+ where T : IFoo
329
+ where U : IBar
330
+ {
331
+ // Body
332
+ }
333
+ `);
334
+ });
289
335
  });
290
336
  it("declares class with invalid members", () => {
291
337
  const decl = _$createComponent(csharp.ClassDeclaration, {