@alloy-js/csharp 0.21.0-dev.20 → 0.21.0-dev.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/attributes/attributes.test.js.map +1 -1
- package/dist/testing/create-wrapper.d.ts +3 -0
- package/dist/testing/create-wrapper.d.ts.map +1 -0
- package/dist/testing/create-wrapper.js +12 -0
- package/dist/testing/create-wrapper.js.map +1 -0
- package/dist/testing/create-wrapper.test.d.ts +2 -0
- package/dist/testing/create-wrapper.test.d.ts.map +1 -0
- package/dist/testing/create-wrapper.test.js +212 -0
- package/dist/testing/create-wrapper.test.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/src/components/attributes/attributes.test.tsx +0 -1
- package/testing/create-wrapper.test.tsx +145 -0
- package/testing/create-wrapper.tsx +12 -0
- package/testing/index.ts +1 -0
- package/tsconfig.json +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/csharp",
|
|
3
|
-
"version": "0.21.0-dev.
|
|
3
|
+
"version": "0.21.0-dev.21",
|
|
4
4
|
"description": "Alloy components for CSharp language.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"./global/*": {
|
|
13
13
|
"import": "./dist/src/builtins/*/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./testing/*": {
|
|
16
|
+
"import": "./dist/testing/index.js"
|
|
14
17
|
}
|
|
15
18
|
},
|
|
16
19
|
"imports": {
|
|
@@ -29,7 +32,7 @@
|
|
|
29
32
|
"author": "jhendrix@microsoft.com",
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.
|
|
35
|
+
"@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.9",
|
|
33
36
|
"@alloy-js/msbuild": "~0.20.0 || >= 0.20.1-dev.1",
|
|
34
37
|
"change-case": "^5.4.4",
|
|
35
38
|
"marked": "^16.1.1",
|
|
@@ -38,7 +41,7 @@
|
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@alloy-js/cli": "~0.20.0 || >= 0.21.0-dev.0",
|
|
40
43
|
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
|
|
41
|
-
"@alloy-js/typescript": "~0.20.0 || >= 0.21.0-dev.
|
|
44
|
+
"@alloy-js/typescript": "~0.20.0 || >= 0.21.0-dev.6",
|
|
42
45
|
"@microsoft/api-extractor": "~7.52.8",
|
|
43
46
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
44
47
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -4,7 +4,6 @@ import { TestNamespace } from "#test/utils.jsx";
|
|
|
4
4
|
import { List, namekey } from "@alloy-js/core";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
6
6
|
import { Attribute, AttributeList } from "./attributes.jsx";
|
|
7
|
-
|
|
8
7
|
it("define attribute", () => {
|
|
9
8
|
expect(<Attribute name="Test" />).toRenderTo(`
|
|
10
9
|
[Test]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassDeclaration,
|
|
3
|
+
Method,
|
|
4
|
+
Property,
|
|
5
|
+
StructDeclaration,
|
|
6
|
+
} from "#components/index.js";
|
|
7
|
+
import { List, Refkey } from "@alloy-js/core";
|
|
8
|
+
import { d } from "@alloy-js/core/testing";
|
|
9
|
+
import { expect, it } from "vitest";
|
|
10
|
+
import { createCSharpTestWrapper } from "./create-wrapper.jsx";
|
|
11
|
+
|
|
12
|
+
it("should render defkey inline", async () => {
|
|
13
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
14
|
+
|
|
15
|
+
expect(<Wrapper>return {defkey("myResult")};</Wrapper>).toRenderTo(
|
|
16
|
+
`return myResult;`,
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("emits a single declaration per unique name", () => {
|
|
21
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
22
|
+
const a = defkey("MyType");
|
|
23
|
+
const b = defkey("MyType");
|
|
24
|
+
expect(a).toBe(b);
|
|
25
|
+
|
|
26
|
+
expect(
|
|
27
|
+
<Wrapper>
|
|
28
|
+
return {a} {b};
|
|
29
|
+
</Wrapper>,
|
|
30
|
+
).toRenderTo(`return MyType MyType;`); // Ensure only one 'class/struct/interface' (whatever default is) declaration appears above if that's the behavior.
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("reuses declarations across multiple usage sites", () => {
|
|
34
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
35
|
+
const T = defkey("Thing");
|
|
36
|
+
const R = defkey("Result");
|
|
37
|
+
|
|
38
|
+
expect(
|
|
39
|
+
<Wrapper>
|
|
40
|
+
<ClassDeclaration abstract name="A">
|
|
41
|
+
<List>
|
|
42
|
+
<Method
|
|
43
|
+
abstract
|
|
44
|
+
name="a"
|
|
45
|
+
returns={R}
|
|
46
|
+
parameters={[{ name: "x", type: T }]}
|
|
47
|
+
/>
|
|
48
|
+
<Method
|
|
49
|
+
abstract
|
|
50
|
+
name="b"
|
|
51
|
+
returns={R}
|
|
52
|
+
parameters={[{ name: "y", type: T }]}
|
|
53
|
+
/>
|
|
54
|
+
</List>
|
|
55
|
+
</ClassDeclaration>
|
|
56
|
+
</Wrapper>,
|
|
57
|
+
).toRenderTo(d`
|
|
58
|
+
abstract class A
|
|
59
|
+
{
|
|
60
|
+
abstract Result a(Thing x);
|
|
61
|
+
abstract Result b(Thing y);
|
|
62
|
+
}`);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("reuses declarations across multiple defkeys", () => {
|
|
66
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
67
|
+
|
|
68
|
+
expect(
|
|
69
|
+
<Wrapper>
|
|
70
|
+
<ClassDeclaration abstract name="A">
|
|
71
|
+
<List>
|
|
72
|
+
<Method
|
|
73
|
+
abstract
|
|
74
|
+
name="a"
|
|
75
|
+
returns={defkey("Result")}
|
|
76
|
+
parameters={[{ name: "x", type: defkey("Thing") }]}
|
|
77
|
+
/>
|
|
78
|
+
<Method
|
|
79
|
+
abstract
|
|
80
|
+
name="b"
|
|
81
|
+
returns={defkey("Result")}
|
|
82
|
+
parameters={[{ name: "y", type: defkey("Thing") }]}
|
|
83
|
+
/>
|
|
84
|
+
</List>
|
|
85
|
+
</ClassDeclaration>
|
|
86
|
+
</Wrapper>,
|
|
87
|
+
).toRenderTo(d`
|
|
88
|
+
abstract class A
|
|
89
|
+
{
|
|
90
|
+
abstract Result a(Thing x);
|
|
91
|
+
abstract Result b(Thing y);
|
|
92
|
+
}`);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should render defkey in nested component", async () => {
|
|
96
|
+
function TestComponent(props: { returnTypeRef: Refkey }) {
|
|
97
|
+
return <Method name="foo" returns={props.returnTypeRef} />;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
101
|
+
|
|
102
|
+
expect(
|
|
103
|
+
<Wrapper>
|
|
104
|
+
<ClassDeclaration name="MyClass">
|
|
105
|
+
<TestComponent returnTypeRef={defkey("MyType")} />
|
|
106
|
+
</ClassDeclaration>
|
|
107
|
+
</Wrapper>,
|
|
108
|
+
).toRenderTo(d`
|
|
109
|
+
class MyClass
|
|
110
|
+
{
|
|
111
|
+
MyType foo() {}
|
|
112
|
+
}`);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should render defkey in class property", async () => {
|
|
116
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
117
|
+
|
|
118
|
+
expect(
|
|
119
|
+
<Wrapper>
|
|
120
|
+
<ClassDeclaration name="TestClass">
|
|
121
|
+
<Property name="MyProperty" type={defkey("MyType")} get set />
|
|
122
|
+
</ClassDeclaration>
|
|
123
|
+
</Wrapper>,
|
|
124
|
+
).toRenderTo(d`
|
|
125
|
+
class TestClass
|
|
126
|
+
{
|
|
127
|
+
MyType MyProperty { get; set; }
|
|
128
|
+
}`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should render defkey in struct property", async () => {
|
|
132
|
+
const { Wrapper, defkey } = createCSharpTestWrapper();
|
|
133
|
+
|
|
134
|
+
expect(
|
|
135
|
+
<Wrapper>
|
|
136
|
+
<StructDeclaration name="TestStruct">
|
|
137
|
+
<Property name="MyProperty" type={defkey("MyType")} get set />
|
|
138
|
+
</StructDeclaration>
|
|
139
|
+
</Wrapper>,
|
|
140
|
+
).toRenderTo(d`
|
|
141
|
+
struct TestStruct
|
|
142
|
+
{
|
|
143
|
+
MyType MyProperty { get; set; }
|
|
144
|
+
}`);
|
|
145
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SourceFile } from "#components/index.js";
|
|
2
|
+
import { createTestWrapper, type TestWrapper } from "@alloy-js/core/testing";
|
|
3
|
+
import { CSharpSymbol, useSourceFileScope } from "../src/index.js";
|
|
4
|
+
|
|
5
|
+
export function createCSharpTestWrapper(): TestWrapper {
|
|
6
|
+
return createTestWrapper({
|
|
7
|
+
filePath: "test.cs",
|
|
8
|
+
useScope: useSourceFileScope,
|
|
9
|
+
makeSymbol: (nk, scope) => new CSharpSymbol(nk, scope.spaces),
|
|
10
|
+
SourceFile,
|
|
11
|
+
});
|
|
12
|
+
}
|
package/testing/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-wrapper.jsx";
|