@alloy-js/csharp 0.23.0 → 0.24.0-dev.1

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 (29) hide show
  1. package/dist/dev/src/components/access-expression/access-expression.test.js +59 -58
  2. package/dist/dev/src/components/access-expression/access-expression.test.js.map +1 -1
  3. package/dist/dev/src/components/class/declaration.test.js +146 -165
  4. package/dist/dev/src/components/class/declaration.test.js.map +1 -1
  5. package/dist/dev/src/components/enum/declaration.test.js +71 -57
  6. package/dist/dev/src/components/enum/declaration.test.js.map +1 -1
  7. package/dist/dev/src/components/enum/member.test.js +61 -52
  8. package/dist/dev/src/components/enum/member.test.js.map +1 -1
  9. package/dist/dev/test/utils.js +2 -85
  10. package/dist/dev/test/utils.js.map +1 -1
  11. package/dist/src/components/access-expression/access-expression.test.js +6 -5
  12. package/dist/src/components/access-expression/access-expression.test.js.map +1 -1
  13. package/dist/src/components/class/declaration.test.js +44 -59
  14. package/dist/src/components/class/declaration.test.js.map +1 -1
  15. package/dist/src/components/enum/declaration.test.js +36 -34
  16. package/dist/src/components/enum/declaration.test.js.map +1 -1
  17. package/dist/src/components/enum/member.test.js +29 -28
  18. package/dist/src/components/enum/member.test.js.map +1 -1
  19. package/dist/test/utils.d.ts +0 -4
  20. package/dist/test/utils.d.ts.map +1 -1
  21. package/dist/test/utils.js +0 -63
  22. package/dist/test/utils.js.map +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +8 -8
  25. package/src/components/access-expression/access-expression.test.tsx +8 -5
  26. package/src/components/class/declaration.test.tsx +34 -43
  27. package/src/components/enum/declaration.test.tsx +22 -27
  28. package/src/components/enum/member.test.tsx +17 -22
  29. package/test/utils.tsx +0 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/csharp",
3
- "version": "0.23.0",
3
+ "version": "0.24.0-dev.1",
4
4
  "description": "Alloy components for CSharp language.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,23 +43,23 @@
43
43
  "author": "jhendrix@microsoft.com",
44
44
  "license": "MIT",
45
45
  "dependencies": {
46
+ "@alloy-js/core": "~0.23.1 || >= 0.24.0-dev.7",
47
+ "@alloy-js/msbuild": "~0.23.0 || >= 0.24.0-dev.0",
46
48
  "change-case": "^5.4.4",
47
49
  "marked": "^16.1.1",
48
- "pathe": "^2.0.3",
49
- "@alloy-js/core": "~0.23.0",
50
- "@alloy-js/msbuild": "~0.23.0"
50
+ "pathe": "^2.0.3"
51
51
  },
52
52
  "devDependencies": {
53
+ "@alloy-js/cli": "~0.23.0 || >= 0.24.0-dev.1",
54
+ "@alloy-js/rollup-plugin": "~0.1.1 || >= 0.1.2-dev.2",
55
+ "@alloy-js/typescript": "~0.23.0 || >= 0.24.0-dev.1",
53
56
  "@microsoft/api-extractor": "~7.52.8",
54
57
  "@rollup/plugin-typescript": "^12.1.2",
55
58
  "@types/js-yaml": "^4.0.9",
56
59
  "concurrently": "^9.2.0",
57
60
  "js-yaml": "^4.1.0",
58
61
  "typescript": "^5.8.3",
59
- "vitest": "3.2.4",
60
- "@alloy-js/rollup-plugin": "~0.1.1",
61
- "@alloy-js/cli": "~0.23.0",
62
- "@alloy-js/typescript": "~0.23.0"
62
+ "vitest": "3.2.4"
63
63
  },
64
64
  "type": "module",
65
65
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  import { ClassDeclaration } from "#components/class/declaration.jsx";
2
2
  import { Method } from "#components/method/method.jsx";
3
3
  import { TestNamespace } from "#test/utils.jsx";
4
- import { List, namekey, printTree, renderTree } from "@alloy-js/core";
4
+ import { List, namekey } from "@alloy-js/core";
5
5
  import { describe, expect, it } from "vitest";
6
6
  import { CSharpSymbol } from "../../symbols/csharp.js";
7
7
  import { AccessExpression } from "./access-expression.jsx";
@@ -49,15 +49,18 @@ it("makes an id part from a symbol", () => {
49
49
 
50
50
  it("makes an id part from a symbol reactively", () => {
51
51
  const symbol = new CSharpSymbol("Symbol", undefined);
52
- const tree = renderTree(
52
+ const template = (
53
53
  <AccessExpression>
54
54
  <AccessExpression.Part id="Foo" />
55
55
  <AccessExpression.Part symbol={symbol} />
56
- </AccessExpression>,
56
+ </AccessExpression>
57
57
  );
58
- expect(printTree(tree)).toEqual("Foo.Symbol");
58
+
59
+ expect(template).toRenderTo("Foo.Symbol");
60
+
61
+ const tree = template;
59
62
  symbol.name = "Bar";
60
- expect(printTree(tree)).toEqual("Foo.Bar");
63
+ expect(tree).toRenderTo("Foo.Bar");
61
64
  });
62
65
 
63
66
  it("makes an id part from refkey, where the first part is a full reference, and subsequent parts are just the id", () => {
@@ -2,30 +2,23 @@ import { Constructor } from "#components/constructor/constructor.jsx";
2
2
  import { EnumDeclaration } from "#components/enum/declaration.jsx";
3
3
  import { EnumMember } from "#components/enum/member.jsx";
4
4
  import {
5
- Children,
6
5
  code,
7
6
  createNamePolicy,
8
7
  List,
9
8
  NamePolicyContext,
10
- Output,
11
9
  refkey,
10
+ render,
12
11
  } from "@alloy-js/core";
13
12
  import * as coretest from "@alloy-js/core/testing";
14
13
  import { describe, expect, it } from "vitest";
15
- import { TestNamespace, toSourceText } from "../../../test/utils.jsx";
16
- import { createCSharpNamePolicy } from "../../name-policy.js";
14
+ import { TestNamespace } from "../../../test/utils.jsx";
17
15
  import { Attribute } from "../attributes/attributes.jsx";
18
16
  import { Field } from "../field/field.jsx";
19
17
  import { Method } from "../method/method.jsx";
20
18
  import { Property } from "../property/property.jsx";
21
- import { SourceFile } from "../source-file/source-file.jsx";
22
19
  import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
23
20
  import { ClassDeclaration } from "./declaration.jsx";
24
21
 
25
- function Wrapper({ children }: { children: Children }) {
26
- return <TestNamespace>{children}</TestNamespace>;
27
- }
28
-
29
22
  it("declares class with no members", () => {
30
23
  expect(
31
24
  <TestNamespace>
@@ -181,37 +174,35 @@ it("uses refkeys for members, params, and return type", () => {
181
174
  ];
182
175
 
183
176
  expect(
184
- <Output namePolicy={createCSharpNamePolicy()}>
185
- <SourceFile path="Test.cs">
186
- <EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
187
- <List comma hardline>
188
- <EnumMember name="One" />
189
- <EnumMember name="Two" />
190
- </List>
191
- </EnumDeclaration>
192
- <hbr />
193
- <ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
177
+ <TestNamespace>
178
+ <EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
179
+ <List comma hardline>
180
+ <EnumMember name="One" />
181
+ <EnumMember name="Two" />
182
+ </List>
183
+ </EnumDeclaration>
184
+ <hbr />
185
+ <ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
186
+ <hbr />
187
+ <ClassDeclaration
188
+ public
189
+ name="TestResult"
190
+ refkey={testResultTypeRefkey}
191
+ />
192
+ <hbr />
193
+ <ClassDeclaration public name="TestClass">
194
+ <Field private name="MemberOne" type={enumTypeRefkey} />
194
195
  <hbr />
195
- <ClassDeclaration
196
+ <Method
196
197
  public
197
- name="TestResult"
198
- refkey={testResultTypeRefkey}
199
- />
200
- <hbr />
201
- <ClassDeclaration public name="TestClass">
202
- <Field private name="MemberOne" type={enumTypeRefkey} />
203
- <hbr />
204
- <Method
205
- public
206
- name="MethodOne"
207
- parameters={params}
208
- returns={testResultTypeRefkey}
209
- >
210
- return new {testResultTypeRefkey}();
211
- </Method>
212
- </ClassDeclaration>
213
- </SourceFile>
214
- </Output>,
198
+ name="MethodOne"
199
+ parameters={params}
200
+ returns={testResultTypeRefkey}
201
+ >
202
+ return new {testResultTypeRefkey}();
203
+ </Method>
204
+ </ClassDeclaration>
205
+ </TestNamespace>,
215
206
  ).toRenderTo(`
216
207
  public enum TestEnum
217
208
  {
@@ -307,7 +298,7 @@ it("declares class with invalid members", () => {
307
298
  </ClassDeclaration>
308
299
  );
309
300
 
310
- expect(() => toSourceText(decl)).toThrow(
301
+ expect(() => render(<TestNamespace>{decl}</TestNamespace>)).toThrow(
311
302
  "EnumMember must be used within an EnumDeclaration.",
312
303
  );
313
304
  });
@@ -398,7 +389,7 @@ describe("constructor", () => {
398
389
  ];
399
390
 
400
391
  expect(
401
- <Wrapper>
392
+ <TestNamespace>
402
393
  <ClassDeclaration
403
394
  public
404
395
  name="TestClass"
@@ -411,7 +402,7 @@ describe("constructor", () => {
411
402
  initializer={code`$"{${paramNameRefkey}} {${paramSizeRefkey}}"`}
412
403
  />
413
404
  </ClassDeclaration>
414
- </Wrapper>,
405
+ </TestNamespace>,
415
406
  ).toRenderTo(`
416
407
  public class TestClass(string name, int size)
417
408
  {
@@ -424,7 +415,7 @@ describe("constructor", () => {
424
415
  const ctorParams = [{ name: "name", type: "string" }];
425
416
 
426
417
  expect(
427
- <Wrapper>
418
+ <TestNamespace>
428
419
  <NamePolicyContext.Provider value={createNamePolicy((x) => x)}>
429
420
  <ClassDeclaration
430
421
  public
@@ -434,7 +425,7 @@ describe("constructor", () => {
434
425
  <Field name="name" type="string" />
435
426
  </ClassDeclaration>
436
427
  </NamePolicyContext.Provider>
437
- </Wrapper>,
428
+ </TestNamespace>,
438
429
  ).toRenderTo(`
439
430
  public class TestClass(string name)
440
431
  {
@@ -1,31 +1,28 @@
1
- import { TestNamespace, toSourceText } from "#test/utils.jsx";
1
+ import { TestNamespace } from "#test/utils.jsx";
2
2
  import { namekey } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
4
3
  import { expect, it } from "vitest";
5
4
  import { EnumDeclaration } from "./declaration.jsx";
6
5
  import { EnumMember } from "./member.jsx";
7
6
 
8
7
  it("declares enum with no members", () => {
9
- const res = toSourceText(<EnumDeclaration public name="TestEnum" />);
10
-
11
- expect(res).toBe(d`
12
- namespace TestCode;
13
-
8
+ expect(
9
+ <TestNamespace>
10
+ <EnumDeclaration public name="TestEnum" />
11
+ </TestNamespace>,
12
+ ).toRenderTo(`
14
13
  public enum TestEnum;
15
14
  `);
16
15
  });
17
16
 
18
17
  it("applies naming policy to enum and members", () => {
19
- const res = toSourceText(
20
- <EnumDeclaration public name="testEnum">
21
- <EnumMember name="one" />,<hbr />
22
- <EnumMember name="two" />
23
- </EnumDeclaration>,
24
- );
25
-
26
- expect(res).toBe(d`
27
- namespace TestCode;
28
-
18
+ expect(
19
+ <TestNamespace>
20
+ <EnumDeclaration public name="testEnum">
21
+ <EnumMember name="one" />,<hbr />
22
+ <EnumMember name="two" />
23
+ </EnumDeclaration>
24
+ </TestNamespace>,
25
+ ).toRenderTo(`
29
26
  public enum TestEnum
30
27
  {
31
28
  One,
@@ -47,16 +44,14 @@ it("takes a namekey", () => {
47
44
  });
48
45
 
49
46
  it("renders doc comment", () => {
50
- const res = toSourceText(
51
- <EnumDeclaration public name="TestEnum" doc="This is a test enum">
52
- <EnumMember name="One" />,<hbr />
53
- <EnumMember name="Two" />
54
- </EnumDeclaration>,
55
- );
56
-
57
- expect(res).toBe(d`
58
- namespace TestCode;
59
-
47
+ expect(
48
+ <TestNamespace>
49
+ <EnumDeclaration public name="TestEnum" doc="This is a test enum">
50
+ <EnumMember name="One" />,<hbr />
51
+ <EnumMember name="Two" />
52
+ </EnumDeclaration>
53
+ </TestNamespace>,
54
+ ).toRenderTo(`
60
55
  /// This is a test enum
61
56
  public enum TestEnum
62
57
  {
@@ -1,21 +1,18 @@
1
- import { TestNamespace, toSourceText } from "#test/utils.jsx";
1
+ import { TestNamespace } from "#test/utils.jsx";
2
2
  import { namekey } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
4
3
  import { expect, it } from "vitest";
5
4
  import { EnumDeclaration } from "./declaration.jsx";
6
5
  import { EnumMember } from "./member.jsx";
7
6
 
8
7
  it("declares enum with members", () => {
9
- const res = toSourceText(
10
- <EnumDeclaration public name="TestEnum">
11
- <EnumMember name="One" />,<hbr />
12
- <EnumMember name="Two" />
13
- </EnumDeclaration>,
14
- );
15
-
16
- expect(res).toBe(d`
17
- namespace TestCode;
18
-
8
+ expect(
9
+ <TestNamespace>
10
+ <EnumDeclaration public name="TestEnum">
11
+ <EnumMember name="One" />,<hbr />
12
+ <EnumMember name="Two" />
13
+ </EnumDeclaration>
14
+ </TestNamespace>,
15
+ ).toRenderTo(`
19
16
  public enum TestEnum
20
17
  {
21
18
  One,
@@ -45,16 +42,14 @@ it("takes a namekey", () => {
45
42
  });
46
43
 
47
44
  it("renders doc comment", () => {
48
- const res = toSourceText(
49
- <EnumDeclaration public name="TestEnum">
50
- <EnumMember name="One" doc="First value" />,<hbr />
51
- <EnumMember name="Two" doc="Second value" />
52
- </EnumDeclaration>,
53
- );
54
-
55
- expect(res).toBe(d`
56
- namespace TestCode;
57
-
45
+ expect(
46
+ <TestNamespace>
47
+ <EnumDeclaration public name="TestEnum">
48
+ <EnumMember name="One" doc="First value" />,<hbr />
49
+ <EnumMember name="Two" doc="Second value" />
50
+ </EnumDeclaration>
51
+ </TestNamespace>,
52
+ ).toRenderTo(`
58
53
  public enum TestEnum
59
54
  {
60
55
  /// First value
package/test/utils.tsx CHANGED
@@ -1,6 +1,4 @@
1
1
  import * as core from "@alloy-js/core";
2
- import * as coretest from "@alloy-js/core/testing";
3
- import { expect } from "vitest";
4
2
  import * as csharp from "../src/index.js";
5
3
 
6
4
  export interface TestNamespaceProps extends csharp.CSharpFormatOptions {
@@ -15,66 +13,3 @@ export function TestNamespace(props: TestNamespaceProps): core.Children {
15
13
  </core.Output>
16
14
  );
17
15
  }
18
- export function toSourceText(c: core.Children): string {
19
- const res = core.render(
20
- <core.Output namePolicy={csharp.createCSharpNamePolicy()}>
21
- <csharp.Namespace name="TestCode">
22
- <csharp.SourceFile path="Test.cs">{c}</csharp.SourceFile>
23
- </csharp.Namespace>
24
- </core.Output>,
25
- { insertFinalNewLine: false },
26
- );
27
-
28
- const file = findFile(res, "Test.cs");
29
- return file.contents;
30
- }
31
-
32
- export function testRender(c: core.Children): core.OutputDirectory {
33
- return core.render(
34
- <core.Output>
35
- <csharp.Namespace name="TestCode">{c}</csharp.Namespace>
36
- </core.Output>,
37
- );
38
- }
39
-
40
- export function findFile(
41
- res: core.OutputDirectory,
42
- path: string,
43
- ): core.ContentOutputFile {
44
- const result = findFileWorker(res, path);
45
-
46
- if (!result) {
47
- throw new Error("Expected to find file " + path);
48
- }
49
- return result as core.ContentOutputFile;
50
-
51
- function findFileWorker(
52
- res: core.OutputDirectory,
53
- path: string,
54
- ): core.OutputFile | null {
55
- for (const item of res.contents) {
56
- if (item.kind === "file") {
57
- if (item.path.includes(path)) {
58
- return item;
59
- }
60
- continue;
61
- } else {
62
- const found = findFileWorker(item, path);
63
- if (found) {
64
- return found;
65
- }
66
- }
67
- }
68
- return null;
69
- }
70
- }
71
-
72
- export function assertFileContents(
73
- res: core.OutputDirectory,
74
- expectedFiles: Record<string, string>,
75
- ): void {
76
- for (const [path, contents] of Object.entries(expectedFiles)) {
77
- const file = findFile(res, path);
78
- expect(file.contents).toBe(coretest.dedent(contents));
79
- }
80
- }