@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.3

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 (168) hide show
  1. package/dist/src/components/Class.d.ts +26 -0
  2. package/dist/src/components/Class.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → Class.js} +38 -70
  4. package/dist/src/components/ClassMethod.d.ts +5 -44
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +9 -33
  7. package/dist/src/components/Enum.d.ts +15 -0
  8. package/dist/src/components/Enum.d.ts.map +1 -0
  9. package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
  10. package/dist/src/components/Parameters.d.ts +13 -0
  11. package/dist/src/components/Parameters.d.ts.map +1 -0
  12. package/dist/src/components/Parameters.js +34 -0
  13. package/dist/src/components/SourceFile.d.ts.map +1 -1
  14. package/dist/src/components/SourceFile.js +0 -1
  15. package/dist/src/components/index.d.ts +4 -14
  16. package/dist/src/components/index.d.ts.map +1 -1
  17. package/dist/src/components/index.js +5 -15
  18. package/dist/src/components/stc/index.d.ts +2 -2
  19. package/dist/src/components/stc/index.d.ts.map +1 -1
  20. package/dist/src/components/stc/index.js +2 -2
  21. package/dist/src/modifiers.d.ts +4 -10
  22. package/dist/src/modifiers.d.ts.map +1 -1
  23. package/dist/src/modifiers.js +32 -9
  24. package/dist/src/name-policy.d.ts +1 -1
  25. package/dist/src/name-policy.d.ts.map +1 -1
  26. package/dist/src/name-policy.js +0 -2
  27. package/dist/test/class-method.test.js +14 -37
  28. package/dist/test/class.test.d.ts +2 -0
  29. package/dist/test/class.test.d.ts.map +1 -0
  30. package/dist/test/class.test.js +298 -0
  31. package/dist/test/enum.test.js +12 -12
  32. package/dist/test/namespace.test.js +8 -8
  33. package/dist/test/projectdirectory.test.d.ts +2 -0
  34. package/dist/test/projectdirectory.test.d.ts.map +1 -0
  35. package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
  36. package/dist/test/sourcefile.test.js +4 -4
  37. package/dist/test/using.test.js +9 -9
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +3 -4
  40. package/src/components/Class.tsx +149 -0
  41. package/src/components/ClassMethod.tsx +15 -74
  42. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
  43. package/src/components/Parameters.tsx +51 -0
  44. package/src/components/SourceFile.tsx +0 -1
  45. package/src/components/index.ts +4 -14
  46. package/src/components/stc/index.ts +2 -2
  47. package/src/modifiers.ts +42 -25
  48. package/src/name-policy.ts +0 -5
  49. package/temp/api.json +1298 -6463
  50. package/test/class-method.test.tsx +14 -24
  51. package/test/class.test.tsx +292 -0
  52. package/test/enum.test.tsx +11 -11
  53. package/test/namespace.test.tsx +4 -4
  54. package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
  55. package/test/sourcefile.test.tsx +2 -2
  56. package/test/using.test.tsx +9 -9
  57. package/vitest.config.ts +0 -3
  58. package/dist/src/components/ClassDeclaration.d.ts +0 -92
  59. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  60. package/dist/src/components/EnumDeclaration.d.ts +0 -34
  61. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  62. package/dist/src/components/attributes/attributes.d.ts +0 -39
  63. package/dist/src/components/attributes/attributes.d.ts.map +0 -1
  64. package/dist/src/components/attributes/attributes.js +0 -62
  65. package/dist/src/components/attributes/attributes.test.d.ts +0 -2
  66. package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
  67. package/dist/src/components/attributes/attributes.test.js +0 -75
  68. package/dist/src/components/doc/comment.d.ts +0 -70
  69. package/dist/src/components/doc/comment.d.ts.map +0 -1
  70. package/dist/src/components/doc/comment.js +0 -88
  71. package/dist/src/components/doc/comment.test.d.ts +0 -2
  72. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  73. package/dist/src/components/doc/comment.test.js +0 -348
  74. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  75. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  76. package/dist/src/components/doc/from-markdown.js +0 -58
  77. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  78. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  79. package/dist/src/components/doc/from-markdown.test.js +0 -83
  80. package/dist/src/components/interface/declaration.d.ts +0 -65
  81. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  82. package/dist/src/components/interface/declaration.js +0 -83
  83. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  84. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  85. package/dist/src/components/interface/declaration.test.js +0 -171
  86. package/dist/src/components/interface/method.d.ts +0 -50
  87. package/dist/src/components/interface/method.d.ts.map +0 -1
  88. package/dist/src/components/interface/method.js +0 -74
  89. package/dist/src/components/interface/method.test.d.ts +0 -2
  90. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  91. package/dist/src/components/interface/method.test.js +0 -300
  92. package/dist/src/components/interface/property.d.ts +0 -56
  93. package/dist/src/components/interface/property.d.ts.map +0 -1
  94. package/dist/src/components/interface/property.js +0 -73
  95. package/dist/src/components/interface/property.test.d.ts +0 -2
  96. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  97. package/dist/src/components/interface/property.test.js +0 -189
  98. package/dist/src/components/parameters/parameters.d.ts +0 -19
  99. package/dist/src/components/parameters/parameters.d.ts.map +0 -1
  100. package/dist/src/components/parameters/parameters.js +0 -43
  101. package/dist/src/components/property/property.d.ts +0 -80
  102. package/dist/src/components/property/property.d.ts.map +0 -1
  103. package/dist/src/components/property/property.js +0 -76
  104. package/dist/src/components/property/property.test.d.ts +0 -2
  105. package/dist/src/components/property/property.test.d.ts.map +0 -1
  106. package/dist/src/components/property/property.test.js +0 -242
  107. package/dist/src/components/record/declaration.d.ts +0 -35
  108. package/dist/src/components/record/declaration.d.ts.map +0 -1
  109. package/dist/src/components/record/declaration.js +0 -90
  110. package/dist/src/components/record/declaration.test.d.ts +0 -2
  111. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  112. package/dist/src/components/record/declaration.test.js +0 -94
  113. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  114. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  115. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  116. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  117. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  118. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  119. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  120. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  121. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  122. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  123. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  124. package/dist/src/components/type-parameters/type-parameters.js +0 -54
  125. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  126. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  127. package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
  128. package/dist/src/components/var/declaration.d.ts +0 -35
  129. package/dist/src/components/var/declaration.d.ts.map +0 -1
  130. package/dist/src/components/var/declaration.js +0 -40
  131. package/dist/src/components/var/declaration.test.d.ts +0 -2
  132. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  133. package/dist/src/components/var/declaration.test.js +0 -73
  134. package/dist/test/class-declaration.test.d.ts +0 -2
  135. package/dist/test/class-declaration.test.d.ts.map +0 -1
  136. package/dist/test/class-declaration.test.js +0 -481
  137. package/dist/test/project-directory.test.d.ts +0 -2
  138. package/dist/test/project-directory.test.d.ts.map +0 -1
  139. package/dist/test/vitest.setup.d.ts +0 -2
  140. package/dist/test/vitest.setup.d.ts.map +0 -1
  141. package/dist/test/vitest.setup.js +0 -1
  142. package/src/components/ClassDeclaration.tsx +0 -233
  143. package/src/components/attributes/attributes.test.tsx +0 -61
  144. package/src/components/attributes/attributes.tsx +0 -100
  145. package/src/components/doc/comment.test.tsx +0 -337
  146. package/src/components/doc/comment.tsx +0 -152
  147. package/src/components/doc/from-markdown.test.tsx +0 -103
  148. package/src/components/doc/from-markdown.tsx +0 -58
  149. package/src/components/interface/declaration.test.tsx +0 -158
  150. package/src/components/interface/declaration.tsx +0 -125
  151. package/src/components/interface/method.test.tsx +0 -293
  152. package/src/components/interface/method.tsx +0 -122
  153. package/src/components/interface/property.test.tsx +0 -165
  154. package/src/components/interface/property.tsx +0 -127
  155. package/src/components/parameters/parameters.tsx +0 -74
  156. package/src/components/property/property.test.tsx +0 -209
  157. package/src/components/property/property.tsx +0 -172
  158. package/src/components/record/declaration.test.tsx +0 -73
  159. package/src/components/record/declaration.tsx +0 -109
  160. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  161. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  162. package/src/components/type-parameters/type-parameter.tsx +0 -35
  163. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  164. package/src/components/type-parameters/type-parameters.tsx +0 -63
  165. package/src/components/var/declaration.test.tsx +0 -59
  166. package/src/components/var/declaration.tsx +0 -47
  167. package/test/class-declaration.test.tsx +0 -430
  168. package/test/vitest.setup.ts +0 -1
@@ -1,20 +1,43 @@
1
1
  // the possible C# access modifiers
2
2
  // https://learn.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
3
3
 
4
- /** Access modifiers. */
4
+ // maps the above access modifier value to its C# syntax.
5
+ // note that the C# keyword includes a trailing space
6
+ const accessModifierLookup = {
7
+ public: "public ",
8
+ protected: "protected ",
9
+ private: "private ",
10
+ internal: "internal ",
11
+ "protected-internal": "protected internal ",
12
+ "private-protected": "private protected ",
13
+ file: "file "
14
+ };
5
15
 
6
- export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
16
+ // returns the C# syntax for the specified access modifier.
17
+ // if no access modifier is specified, the empty string is returned.
18
+ export function getAccessModifier(accessModifier) {
19
+ return accessModifier ? accessModifierLookup[accessModifier] : "";
20
+ }
21
+ // maps the above method modifier value to its C# syntax.
22
+ // note that the C# keyword includes a trailing space
23
+ const methodModifierLookup = {
24
+ abstract: "abstract ",
25
+ sealed: "sealed ",
26
+ static: "static ",
27
+ virtual: "virtual "
28
+ };
29
+
30
+ // returns the C# syntax for the specified method modifier.
31
+ // if no method modifier is specified, the empty string is returned.
32
+ export function getMethodModifier(methodModifier) {
33
+ return methodModifier ? methodModifierLookup[methodModifier] : "";
34
+ }
7
35
  export function getAsyncModifier(async) {
8
- return async ? "async" : "";
36
+ return async ? "async " : "";
9
37
  }
10
38
 
11
39
  /** Resolve the modifier prefix */
12
40
  export function computeModifiersPrefix(modifiers) {
13
41
  const resolved = modifiers.filter(x => x);
14
- return resolved.length > 0 ? resolved.join(" ") + " " : "";
15
- }
16
- export function makeModifiers(obj) {
17
- return data => {
18
- return obj.map(key => data[key] ? key : undefined).filter(x => x).join(" ");
19
- };
42
+ return resolved.length > 0 ? resolved.join("") : "";
20
43
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
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";
2
+ export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "class-member-private" | "class-member-public" | "class-method" | "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,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,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAiBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
@@ -11,11 +11,9 @@ export function createCSharpNamePolicy() {
11
11
  case "enum":
12
12
  case "enum-member":
13
13
  case "interface":
14
- case "record":
15
14
  case "class-member-public":
16
15
  case "class-method":
17
16
  case "type-parameter":
18
- case "class-property":
19
17
  return changecase.pascalCase(name);
20
18
  case "constant":
21
19
  return changecase.constantCase(name);
@@ -1,11 +1,11 @@
1
- import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import { describe, expect, it } from "vitest";
3
- import { ClassDeclaration, ClassMethod } from "../src/index.js";
3
+ import { Class, ClassMethod } from "../src/index.js";
4
4
  import { TestNamespace } from "./utils.js";
5
5
  const Wrapper = props => _$createComponent(TestNamespace, {
6
6
  get children() {
7
- return _$createComponent(ClassDeclaration, {
8
- "public": true,
7
+ return _$createComponent(Class, {
8
+ accessModifier: "public",
9
9
  name: "TestClass",
10
10
  get children() {
11
11
  return props.children;
@@ -18,11 +18,10 @@ describe("modifiers", () => {
18
18
  it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
19
19
  expect(_$createComponent(Wrapper, {
20
20
  get children() {
21
- return _$createComponent(ClassMethod, _$mergeProps({
22
- [accessModifier]: true
23
- }, {
21
+ return _$createComponent(ClassMethod, {
22
+ accessModifier: accessModifier,
24
23
  name: "MethodOne"
25
- }));
24
+ });
26
25
  }
27
26
  })).toRenderTo(`
28
27
  public class TestClass
@@ -36,11 +35,10 @@ describe("modifiers", () => {
36
35
  it.each(["static", "virtual", "sealed"])("%s", methodModifier => {
37
36
  expect(_$createComponent(Wrapper, {
38
37
  get children() {
39
- return _$createComponent(ClassMethod, _$mergeProps({
40
- [methodModifier]: true
41
- }, {
38
+ return _$createComponent(ClassMethod, {
39
+ methodModifier: methodModifier,
42
40
  name: "MethodOne"
43
- }));
41
+ });
44
42
  }
45
43
  })).toRenderTo(`
46
44
  public class TestClass
@@ -53,7 +51,7 @@ describe("modifiers", () => {
53
51
  expect(_$createComponent(Wrapper, {
54
52
  get children() {
55
53
  return _$createComponent(ClassMethod, {
56
- abstract: true,
54
+ methodModifier: "abstract",
57
55
  name: "MethodOne"
58
56
  });
59
57
  }
@@ -86,8 +84,8 @@ describe("modifiers", () => {
86
84
  return _$createComponent(ClassMethod, {
87
85
  async: true,
88
86
  returns: "Task",
89
- "public": true,
90
- abstract: true,
87
+ accessModifier: "public",
88
+ methodModifier: "abstract",
91
89
  name: "MethodOne"
92
90
  });
93
91
  }
@@ -124,7 +122,7 @@ it("defines params and return type", () => {
124
122
  const res = _$createComponent(Wrapper, {
125
123
  get children() {
126
124
  return _$createComponent(ClassMethod, {
127
- "public": true,
125
+ accessModifier: "public",
128
126
  name: "MethodOne",
129
127
  parameters: params,
130
128
  returns: "string"
@@ -137,25 +135,4 @@ it("defines params and return type", () => {
137
135
  public string MethodOne(int intParam, string stringParam) {}
138
136
  }
139
137
  `);
140
- });
141
- it("specify doc comment", () => {
142
- expect(_$createComponent(TestNamespace, {
143
- get children() {
144
- return _$createComponent(ClassDeclaration, {
145
- name: "Test",
146
- get children() {
147
- return _$createComponent(ClassMethod, {
148
- name: "Method",
149
- doc: "This is a test"
150
- });
151
- }
152
- });
153
- }
154
- })).toRenderTo(`
155
- class Test
156
- {
157
- /// This is a test
158
- void Method() {}
159
- }
160
- `);
161
138
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=class.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.test.d.ts","sourceRoot":"","sources":["../../test/class.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,298 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import * as core from "@alloy-js/core";
3
+ import * as coretest from "@alloy-js/core/testing";
4
+ import { expect, it } from "vitest";
5
+ import * as csharp from "../src/index.js";
6
+ import * as utils from "./utils.js";
7
+ it("declares class with no members", () => {
8
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
9
+ accessModifier: "public",
10
+ name: "TestClass"
11
+ }));
12
+ expect(res).toBe(coretest.d`
13
+ namespace TestCode
14
+ {
15
+ public class TestClass;
16
+ }
17
+ `);
18
+ });
19
+ it("declares class with some members", () => {
20
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
21
+ accessModifier: "public",
22
+ name: "TestClass",
23
+ get children() {
24
+ return _$createComponent(core.StatementList, {
25
+ get children() {
26
+ return [_$createComponent(csharp.ClassMember, {
27
+ accessModifier: "public",
28
+ name: "MemberOne",
29
+ type: "string"
30
+ }), _$createComponent(csharp.ClassMember, {
31
+ accessModifier: "private",
32
+ name: "MemberTwo",
33
+ type: "int"
34
+ })];
35
+ }
36
+ });
37
+ }
38
+ }));
39
+ expect(res).toBe(coretest.d`
40
+ namespace TestCode
41
+ {
42
+ public class TestClass
43
+ {
44
+ public string MemberOne;
45
+ private int memberTwo;
46
+ }
47
+ }
48
+ `);
49
+ });
50
+ it("declares class with some methods", () => {
51
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
52
+ accessModifier: "public",
53
+ name: "TestClass",
54
+ get children() {
55
+ return _$createComponent(core.List, {
56
+ get children() {
57
+ return [_$createComponent(csharp.ClassMethod, {
58
+ accessModifier: "public",
59
+ name: "MethodOne"
60
+ }), _$createComponent(csharp.ClassMethod, {
61
+ accessModifier: "private",
62
+ methodModifier: "virtual",
63
+ name: "MethodTwo"
64
+ })];
65
+ }
66
+ });
67
+ }
68
+ }));
69
+ expect(res).toBe(coretest.d`
70
+ namespace TestCode
71
+ {
72
+ public class TestClass
73
+ {
74
+ public void MethodOne() {}
75
+ private virtual void MethodTwo() {}
76
+ }
77
+ }
78
+ `);
79
+ });
80
+ it("uses refkeys for members, params, and return type", () => {
81
+ const inputTypeRefkey = core.refkey();
82
+ const testResultTypeRefkey = core.refkey();
83
+ const enumTypeRefkey = core.refkey();
84
+ const params = [{
85
+ name: "IntParam",
86
+ type: "int"
87
+ }, {
88
+ name: "BodyParam",
89
+ type: inputTypeRefkey
90
+ }];
91
+ const res = core.render(_$createComponent(core.Output, {
92
+ get namePolicy() {
93
+ return csharp.createCSharpNamePolicy();
94
+ },
95
+ get children() {
96
+ return _$createComponent(csharp.Namespace, {
97
+ name: "TestCode",
98
+ get children() {
99
+ return _$createComponent(csharp.SourceFile, {
100
+ path: "Test.cs",
101
+ get children() {
102
+ return [_$createComponent(csharp.Enum, {
103
+ accessModifier: "public",
104
+ name: "TestEnum",
105
+ refkey: enumTypeRefkey,
106
+ get children() {
107
+ return _$createComponent(core.List, {
108
+ comma: true,
109
+ hardline: true,
110
+ get children() {
111
+ return [_$createComponent(csharp.EnumMember, {
112
+ name: "One"
113
+ }), _$createComponent(csharp.EnumMember, {
114
+ name: "Two"
115
+ })];
116
+ }
117
+ });
118
+ }
119
+ }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Class, {
120
+ accessModifier: "public",
121
+ name: "TestInput",
122
+ refkey: inputTypeRefkey
123
+ }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Class, {
124
+ accessModifier: "public",
125
+ name: "TestResult",
126
+ refkey: testResultTypeRefkey
127
+ }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Class, {
128
+ accessModifier: "public",
129
+ name: "TestClass",
130
+ get children() {
131
+ return [_$createComponent(csharp.ClassMember, {
132
+ accessModifier: "private",
133
+ name: "MemberOne",
134
+ type: enumTypeRefkey
135
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMethod, {
136
+ accessModifier: "public",
137
+ name: "MethodOne",
138
+ parameters: params,
139
+ returns: testResultTypeRefkey,
140
+ get children() {
141
+ return ["return new ", testResultTypeRefkey, "();"];
142
+ }
143
+ })];
144
+ }
145
+ })];
146
+ }
147
+ });
148
+ }
149
+ });
150
+ }
151
+ }));
152
+ expect(res.contents[0].contents).toBe(coretest.d`
153
+ namespace TestCode
154
+ {
155
+ public enum TestEnum
156
+ {
157
+ One,
158
+ Two
159
+ }
160
+ public class TestInput;
161
+ public class TestResult;
162
+ public class TestClass
163
+ {
164
+ private TestEnum memberOne;
165
+ public TestResult MethodOne(int intParam, TestInput bodyParam)
166
+ {
167
+ return new TestResult();
168
+ }
169
+ }
170
+ }
171
+ `);
172
+ });
173
+ it("declares class with generic parameters", () => {
174
+ const typeParameters = {
175
+ T: core.refkey(),
176
+ U: core.refkey()
177
+ };
178
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
179
+ accessModifier: "public",
180
+ name: "TestClass",
181
+ typeParameters: typeParameters,
182
+ get children() {
183
+ return [_$createComponent(csharp.ClassMember, {
184
+ accessModifier: "public",
185
+ name: "memberOne",
186
+ get type() {
187
+ return typeParameters.T;
188
+ }
189
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
190
+ accessModifier: "private",
191
+ name: "memberTwo",
192
+ get type() {
193
+ return typeParameters.U;
194
+ }
195
+ }), ";"];
196
+ }
197
+ }));
198
+ expect(res).toBe(coretest.d`
199
+ namespace TestCode
200
+ {
201
+ public class TestClass<T, U>
202
+ {
203
+ public T MemberOne;
204
+ private U memberTwo;
205
+ }
206
+ }
207
+ `);
208
+ });
209
+ it("declares class with invalid members", () => {
210
+ const decl = _$createComponent(csharp.Class, {
211
+ accessModifier: "public",
212
+ name: "TestClass",
213
+ get children() {
214
+ return [_$createComponent(csharp.EnumMember, {
215
+ name: "One"
216
+ }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
217
+ name: "Two"
218
+ })];
219
+ }
220
+ });
221
+ expect(() => utils.toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
222
+ });
223
+ it("declares class with constructor", () => {
224
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
225
+ accessModifier: "public",
226
+ name: "TestClass",
227
+ get children() {
228
+ return _$createComponent(csharp.ClassConstructor, {
229
+ accessModifier: "public"
230
+ });
231
+ }
232
+ }));
233
+ expect(res).toBe(coretest.d`
234
+ namespace TestCode
235
+ {
236
+ public class TestClass
237
+ {
238
+ public TestClass() {}
239
+ }
240
+ }
241
+ `);
242
+ });
243
+ it("declares class with constructor params and assigns values to fields", () => {
244
+ const thisNameRefkey = core.refkey();
245
+ const thisSizeRefkey = core.refkey();
246
+ const paramNameRefkey = core.refkey();
247
+ const paramSizeRefkey = core.refkey();
248
+ const ctorParams = [{
249
+ name: "name",
250
+ type: "string",
251
+ refkey: paramNameRefkey
252
+ }, {
253
+ name: "size",
254
+ type: "int",
255
+ refkey: paramSizeRefkey
256
+ }];
257
+ const res = utils.toSourceText(_$createComponent(csharp.Class, {
258
+ accessModifier: "public",
259
+ name: "TestClass",
260
+ get children() {
261
+ return [_$createComponent(csharp.ClassMember, {
262
+ accessModifier: "private",
263
+ name: "name",
264
+ type: "string",
265
+ refkey: thisNameRefkey
266
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
267
+ accessModifier: "private",
268
+ name: "size",
269
+ type: "int",
270
+ refkey: thisSizeRefkey
271
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassConstructor, {
272
+ accessModifier: "public",
273
+ parameters: ctorParams,
274
+ get children() {
275
+ return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
276
+ }
277
+ })];
278
+ }
279
+ }));
280
+
281
+ // TODO: assignments to members should have this. prefix
282
+ // e.g. this.name = name;
283
+ expect(res).toBe(coretest.d`
284
+ namespace TestCode
285
+ {
286
+ public class TestClass
287
+ {
288
+ private string name;
289
+ private int size;
290
+ public TestClass(string name, int size)
291
+ {
292
+ name = name;
293
+ size = size;
294
+ }
295
+ }
296
+ }
297
+ `);
298
+ });
@@ -5,8 +5,8 @@ import { expect, it } from "vitest";
5
5
  import * as csharp from "../src/index.js";
6
6
  import * as utils from "./utils.js";
7
7
  it("declares enum with no members", () => {
8
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
9
- "public": true,
8
+ const res = utils.toSourceText(_$createComponent(csharp.Enum, {
9
+ accessModifier: "public",
10
10
  name: "TestEnum"
11
11
  }));
12
12
  expect(res).toBe(coretest.d`
@@ -17,8 +17,8 @@ it("declares enum with no members", () => {
17
17
  `);
18
18
  });
19
19
  it("declares enum with members", () => {
20
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
21
- "public": true,
20
+ const res = utils.toSourceText(_$createComponent(csharp.Enum, {
21
+ accessModifier: "public",
22
22
  name: "TestEnum",
23
23
  get children() {
24
24
  return [_$createComponent(csharp.EnumMember, {
@@ -40,8 +40,8 @@ it("declares enum with members", () => {
40
40
  `);
41
41
  });
42
42
  it("applies naming policy to enum and members", () => {
43
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
44
- "public": true,
43
+ const res = utils.toSourceText(_$createComponent(csharp.Enum, {
44
+ accessModifier: "public",
45
45
  name: "testEnum",
46
46
  get children() {
47
47
  return [_$createComponent(csharp.EnumMember, {
@@ -73,8 +73,8 @@ it("can reference things by refkey", () => {
73
73
  return _$createComponent(csharp.SourceFile, {
74
74
  path: "Test.cs",
75
75
  get children() {
76
- return [_$createComponent(csharp.EnumDeclaration, {
77
- "public": true,
76
+ return [_$createComponent(csharp.Enum, {
77
+ accessModifier: "public",
78
78
  name: "TestEnum",
79
79
  refkey: enumRK,
80
80
  get children() {
@@ -116,8 +116,8 @@ it("can reference things by refkey across files", () => {
116
116
  return [_$createComponent(csharp.SourceFile, {
117
117
  path: "Test.cs",
118
118
  get children() {
119
- return [_$createComponent(csharp.EnumDeclaration, {
120
- "public": true,
119
+ return [_$createComponent(csharp.Enum, {
120
+ accessModifier: "public",
121
121
  name: "TestEnum",
122
122
  get children() {
123
123
  return [_$createComponent(csharp.EnumMember, {
@@ -131,8 +131,8 @@ it("can reference things by refkey across files", () => {
131
131
  }), _$createComponent(csharp.SourceFile, {
132
132
  path: "Other.cs",
133
133
  get children() {
134
- return [_$createComponent(csharp.EnumDeclaration, {
135
- "public": true,
134
+ return [_$createComponent(csharp.Enum, {
135
+ accessModifier: "public",
136
136
  name: "OtherEnum",
137
137
  refkey: enumRK,
138
138
  get children() {
@@ -12,16 +12,16 @@ it("defines multiple namespaces and source files with unique content", () => {
12
12
  return [_$createComponent(csharp.SourceFile, {
13
13
  path: "Model1.cs",
14
14
  get children() {
15
- return _$createComponent(csharp.ClassDeclaration, {
16
- "public": true,
15
+ return _$createComponent(csharp.Class, {
16
+ accessModifier: "public",
17
17
  name: "Model1"
18
18
  });
19
19
  }
20
20
  }), _$createComponent(csharp.SourceFile, {
21
21
  path: "Model2.cs",
22
22
  get children() {
23
- return _$createComponent(csharp.ClassDeclaration, {
24
- "public": true,
23
+ return _$createComponent(csharp.Class, {
24
+ accessModifier: "public",
25
25
  name: "Model2"
26
26
  });
27
27
  }
@@ -33,16 +33,16 @@ it("defines multiple namespaces and source files with unique content", () => {
33
33
  return [_$createComponent(csharp.SourceFile, {
34
34
  path: "Model3.cs",
35
35
  get children() {
36
- return _$createComponent(csharp.ClassDeclaration, {
37
- "public": true,
36
+ return _$createComponent(csharp.Class, {
37
+ accessModifier: "public",
38
38
  name: "Model3"
39
39
  });
40
40
  }
41
41
  }), _$createComponent(csharp.SourceFile, {
42
42
  path: "Model4.cs",
43
43
  get children() {
44
- return _$createComponent(csharp.ClassDeclaration, {
45
- "public": true,
44
+ return _$createComponent(csharp.Class, {
45
+ accessModifier: "public",
46
46
  name: "Model4"
47
47
  });
48
48
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=projectdirectory.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectdirectory.test.d.ts","sourceRoot":"","sources":["../../test/projectdirectory.test.tsx"],"names":[],"mappings":""}
@@ -18,16 +18,16 @@ it("defines a project directory file with multiple source files", () => {
18
18
  return [_$createComponent(csharp.SourceFile, {
19
19
  path: "Test1.cs",
20
20
  get children() {
21
- return _$createComponent(csharp.ClassDeclaration, {
22
- "public": true,
21
+ return _$createComponent(csharp.Class, {
22
+ accessModifier: "public",
23
23
  name: "TestClass1"
24
24
  });
25
25
  }
26
26
  }), _$createComponent(csharp.SourceFile, {
27
27
  path: "Test2.cs",
28
28
  get children() {
29
- return _$createComponent(csharp.ClassDeclaration, {
30
- "public": true,
29
+ return _$createComponent(csharp.Class, {
30
+ accessModifier: "public",
31
31
  name: "TestClass2"
32
32
  });
33
33
  }
@@ -82,16 +82,16 @@ it("defines a project directory file with multiple source files and a custom TFM
82
82
  return [_$createComponent(csharp.SourceFile, {
83
83
  path: "Test1.cs",
84
84
  get children() {
85
- return _$createComponent(csharp.ClassDeclaration, {
86
- "public": true,
85
+ return _$createComponent(csharp.Class, {
86
+ accessModifier: "public",
87
87
  name: "TestClass1"
88
88
  });
89
89
  }
90
90
  }), _$createComponent(csharp.SourceFile, {
91
91
  path: "Test2.cs",
92
92
  get children() {
93
- return _$createComponent(csharp.ClassDeclaration, {
94
- "public": true,
93
+ return _$createComponent(csharp.Class, {
94
+ accessModifier: "public",
95
95
  name: "TestClass2"
96
96
  });
97
97
  }
@@ -12,16 +12,16 @@ it("defines multiple source files with unique content", () => {
12
12
  return [_$createComponent(csharp.SourceFile, {
13
13
  path: "Test1.cs",
14
14
  get children() {
15
- return _$createComponent(csharp.ClassDeclaration, {
16
- "public": true,
15
+ return _$createComponent(csharp.Class, {
16
+ accessModifier: "public",
17
17
  name: "TestClass1"
18
18
  });
19
19
  }
20
20
  }), _$createComponent(csharp.SourceFile, {
21
21
  path: "Test2.cs",
22
22
  get children() {
23
- return _$createComponent(csharp.ClassDeclaration, {
24
- "public": true,
23
+ return _$createComponent(csharp.Class, {
24
+ accessModifier: "public",
25
25
  name: "TestClass2"
26
26
  });
27
27
  }