@typespec/emitter-framework 0.9.0-dev.7 → 0.9.0-dev.9
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/csharp/components/class/declaration.test.js +100 -115
- package/dist/src/csharp/components/{enum-declaration.d.ts → enum/declaration.d.ts} +1 -1
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/{enum-declaration.js → enum/declaration.js} +4 -4
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +1 -1
- package/dist/src/csharp/components/index.js +1 -1
- package/dist/src/csharp/components/property/property.test.js +14 -14
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts +33 -0
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +69 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts +2 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +80 -0
- package/dist/src/testing/scenario-test/harness.d.ts +2 -2
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.js +69 -158
- package/dist/src/testing/scenario-test/index.d.ts +0 -1
- package/dist/src/testing/scenario-test/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/index.js +1 -2
- package/dist/src/testing/scenario-test/snippet-extractor.d.ts +1 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js +1 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js +3 -3
- package/dist/test/testing/snippet-extractor-java.test.js +3 -3
- package/dist/test/testing/snippet-extractor-python.test.js +2 -2
- package/dist/test/testing/snippet-extractor-typescript.test.js +3 -3
- package/package.json +8 -6
- package/src/csharp/components/class/declaration.test.tsx +106 -168
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/{enum-declaration.tsx → enum/declaration.tsx} +4 -4
- package/src/csharp/components/index.ts +1 -1
- package/src/csharp/components/property/property.test.tsx +14 -14
- package/src/testing/scenario-test/code-block-expectation.test.ts +95 -0
- package/src/testing/scenario-test/code-block-expectation.ts +115 -0
- package/src/testing/scenario-test/harness.ts +91 -236
- package/src/testing/scenario-test/index.ts +0 -1
- package/src/testing/scenario-test/snippet-extractor.ts +1 -1
- package/test/testing/snippet-extractor-csharp.test.ts +3 -3
- package/test/testing/snippet-extractor-java.test.ts +3 -3
- package/test/testing/snippet-extractor-python.test.ts +2 -2
- package/test/testing/snippet-extractor-typescript.test.ts +3 -3
- package/dist/src/csharp/components/enum-declaration.d.ts.map +0 -1
- package/dist/src/testing/scenario-test/test-host.d.ts +0 -8
- package/dist/src/testing/scenario-test/test-host.d.ts.map +0 -1
- package/dist/src/testing/scenario-test/test-host.js +0 -49
- package/dist/test/csharp/components/enum-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/enum-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.js +0 -403
- package/dist/test/csharp/test-host.d.ts +0 -11
- package/dist/test/csharp/test-host.d.ts.map +0 -1
- package/dist/test/csharp/test-host.js +0 -32
- package/dist/test/csharp/utils.d.ts +0 -3
- package/dist/test/csharp/utils.d.ts.map +0 -1
- package/dist/test/csharp/utils.js +0 -6
- package/src/testing/scenario-test/test-host.ts +0 -83
- package/test/csharp/components/enum-declaration.test.tsx +0 -337
- package/test/csharp/test-host.ts +0 -42
- package/test/csharp/utils.ts +0 -8
|
@@ -92,7 +92,7 @@ export interface LanguageConfiguration {
|
|
|
92
92
|
|
|
93
93
|
await Parser.init();
|
|
94
94
|
|
|
95
|
-
export function
|
|
95
|
+
export function createSnippetExtractor(
|
|
96
96
|
languageConfiguration: LanguageConfiguration,
|
|
97
97
|
): SnippetExtractor {
|
|
98
98
|
return new SnippetExtractorImpl(languageConfiguration);
|
|
@@ -2,14 +2,14 @@ import { d } from "@alloy-js/core/testing";
|
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
createCSharpExtractorConfig,
|
|
5
|
-
|
|
5
|
+
createSnippetExtractor,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
describe("C# Snippet Extractor", () => {
|
|
9
9
|
let extractor: SnippetExtractor;
|
|
10
10
|
|
|
11
11
|
beforeEach(async () => {
|
|
12
|
-
extractor =
|
|
12
|
+
extractor = createSnippetExtractor(await createCSharpExtractorConfig());
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should extract a class", () => {
|
|
@@ -66,7 +66,7 @@ describe("C# Snippet Extractor - Enums", () => {
|
|
|
66
66
|
let extractor: SnippetExtractor;
|
|
67
67
|
|
|
68
68
|
beforeEach(async () => {
|
|
69
|
-
extractor =
|
|
69
|
+
extractor = createSnippetExtractor(await createCSharpExtractorConfig());
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it("should extract a basic enum", async () => {
|
|
@@ -2,7 +2,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
createJavaExtractorConfig,
|
|
5
|
-
|
|
5
|
+
createSnippetExtractor,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ describe("Java Snippet Extractor", () => {
|
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
12
|
beforeEach(async () => {
|
|
13
|
-
extractor =
|
|
13
|
+
extractor = createSnippetExtractor(await createJavaExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -67,7 +67,7 @@ describe("Java Snippet Extractor - Enums", () => {
|
|
|
67
67
|
let extractor: SnippetExtractor;
|
|
68
68
|
|
|
69
69
|
beforeEach(async () => {
|
|
70
|
-
extractor =
|
|
70
|
+
extractor = createSnippetExtractor(await createJavaExtractorConfig());
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("should extract a basic enum", async () => {
|
|
@@ -2,7 +2,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
createPythonExtractorConfig,
|
|
5
|
-
|
|
5
|
+
createSnippetExtractor,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ describe("Python Snippet Extractor", () => {
|
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
12
|
beforeEach(async () => {
|
|
13
|
-
extractor =
|
|
13
|
+
extractor = createSnippetExtractor(await createPythonExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d } from "@alloy-js/core/testing";
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
createSnippetExtractor,
|
|
5
5
|
createTypeScriptExtractorConfig,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
describe("TypeScript Snippet Extractor", () => {
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
beforeEach(async () => {
|
|
12
|
-
extractor =
|
|
12
|
+
extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should extract a class", async () => {
|
|
@@ -138,7 +138,7 @@ describe("TypeScript Snippet Extractor", () => {
|
|
|
138
138
|
describe("TypeScript Snippet Extractor - Enums", () => {
|
|
139
139
|
let extractor: SnippetExtractor;
|
|
140
140
|
beforeEach(async () => {
|
|
141
|
-
extractor =
|
|
141
|
+
extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it("should extract a basic enum", async () => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAO,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,QAAQ,CA0CrE"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import { type TypeSpecTestLibrary } from "@typespec/compiler/testing";
|
|
3
|
-
export interface EmittedFile {
|
|
4
|
-
path: string;
|
|
5
|
-
content: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function emitWithDiagnostics(testLibrary: TypeSpecTestLibrary, emitterOutputDir: string, code: string): Promise<[EmittedFile[], readonly Diagnostic[]]>;
|
|
8
|
-
//# sourceMappingURL=test-host.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAKL,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,mBAAmB,EAChC,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAOjD"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createTestHost, createTestWrapper } from "@typespec/compiler/testing";
|
|
2
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
3
|
-
import { RestTestLibrary } from "@typespec/rest/testing";
|
|
4
|
-
import { join, relative } from "path";
|
|
5
|
-
async function createEmitterTestRunner(testLibrary, options = {}) {
|
|
6
|
-
const libraries = options.testHostConfig?.libraries ?? [testLibrary, HttpTestLibrary, RestTestLibrary];
|
|
7
|
-
const host = await createTestHost({
|
|
8
|
-
libraries
|
|
9
|
-
});
|
|
10
|
-
return createTestWrapper(host, {
|
|
11
|
-
autoImports: options.autoImports ?? ["@typespec/http", "@typespec/rest"],
|
|
12
|
-
autoUsings: options.autoUsings ?? ["TypeSpec.Http", "TypeSpec.Rest"],
|
|
13
|
-
compilerOptions: options.compilerOptions ?? {
|
|
14
|
-
noEmit: false,
|
|
15
|
-
emit: [testLibrary.name]
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export async function emitWithDiagnostics(testLibrary, emitterOutputDir, code) {
|
|
20
|
-
const runner = await createEmitterTestRunner(testLibrary);
|
|
21
|
-
await runner.compileAndDiagnose(code, {
|
|
22
|
-
outputDir: "tsp-output"
|
|
23
|
-
});
|
|
24
|
-
const result = await readFilesRecursively(emitterOutputDir, emitterOutputDir, runner);
|
|
25
|
-
return [result, runner.program.diagnostics];
|
|
26
|
-
}
|
|
27
|
-
async function readFilesRecursively(currentDir, emitterOutputDir, runner) {
|
|
28
|
-
const entries = await runner.program.host.readDir(currentDir);
|
|
29
|
-
const result = [];
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
const fullPath = join(currentDir, entry);
|
|
32
|
-
const stat = await runner.program.host.stat(fullPath);
|
|
33
|
-
if (stat.isDirectory()) {
|
|
34
|
-
// Recursively read files in the directory
|
|
35
|
-
const nestedFiles = await readFilesRecursively(fullPath, emitterOutputDir, runner);
|
|
36
|
-
result.push(...nestedFiles);
|
|
37
|
-
} else if (stat.isFile()) {
|
|
38
|
-
// Read the file
|
|
39
|
-
// Read the file and store it with a relative path
|
|
40
|
-
const relativePath = relative(emitterOutputDir, fullPath);
|
|
41
|
-
const fileContent = await runner.program.host.readFile(fullPath);
|
|
42
|
-
result.push({
|
|
43
|
-
path: relativePath,
|
|
44
|
-
content: fileContent.text
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum-declaration.test.d.ts","sourceRoot":"","sources":["../../../../test/csharp/components/enum-declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { render } from "@alloy-js/core";
|
|
3
|
-
import { d } from "@alloy-js/core/testing";
|
|
4
|
-
import * as cs from "@alloy-js/csharp";
|
|
5
|
-
import { Namespace, SourceFile } from "@alloy-js/csharp";
|
|
6
|
-
import { beforeEach, it } from "vitest";
|
|
7
|
-
import { Output } from "../../../src/core/index.js";
|
|
8
|
-
import { EnumDeclaration } from "../../../src/csharp/index.js";
|
|
9
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
10
|
-
import { assertFileContents } from "../utils.js";
|
|
11
|
-
let runner;
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
runner = await createEmitterFrameworkTestRunner();
|
|
14
|
-
});
|
|
15
|
-
it("renders a basic enum declaration", async () => {
|
|
16
|
-
const {
|
|
17
|
-
TestEnum
|
|
18
|
-
} = await runner.compile(`
|
|
19
|
-
@test enum TestEnum {
|
|
20
|
-
Value1;
|
|
21
|
-
Value2;
|
|
22
|
-
Value3;
|
|
23
|
-
}
|
|
24
|
-
`);
|
|
25
|
-
const res = render(_$createComponent(Output, {
|
|
26
|
-
get program() {
|
|
27
|
-
return runner.program;
|
|
28
|
-
},
|
|
29
|
-
get children() {
|
|
30
|
-
return _$createComponent(Namespace, {
|
|
31
|
-
name: "TestNamespace",
|
|
32
|
-
get children() {
|
|
33
|
-
return _$createComponent(SourceFile, {
|
|
34
|
-
path: "test.cs",
|
|
35
|
-
get children() {
|
|
36
|
-
return _$createComponent(EnumDeclaration, {
|
|
37
|
-
type: TestEnum
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
assertFileContents(res, d`
|
|
46
|
-
namespace TestNamespace
|
|
47
|
-
{
|
|
48
|
-
enum TestEnum
|
|
49
|
-
{
|
|
50
|
-
Value1,
|
|
51
|
-
Value2,
|
|
52
|
-
Value3
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
it("renders an empty enum declaration", async () => {
|
|
58
|
-
const {
|
|
59
|
-
TestEnum
|
|
60
|
-
} = await runner.compile(`
|
|
61
|
-
@test enum TestEnum {}
|
|
62
|
-
`);
|
|
63
|
-
const res = render(_$createComponent(Output, {
|
|
64
|
-
get program() {
|
|
65
|
-
return runner.program;
|
|
66
|
-
},
|
|
67
|
-
get children() {
|
|
68
|
-
return _$createComponent(Namespace, {
|
|
69
|
-
name: "TestNamespace",
|
|
70
|
-
get children() {
|
|
71
|
-
return _$createComponent(SourceFile, {
|
|
72
|
-
path: "test.cs",
|
|
73
|
-
get children() {
|
|
74
|
-
return _$createComponent(EnumDeclaration, {
|
|
75
|
-
type: TestEnum
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
assertFileContents(res, d`
|
|
84
|
-
namespace TestNamespace
|
|
85
|
-
{
|
|
86
|
-
enum TestEnum
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
`);
|
|
92
|
-
});
|
|
93
|
-
it("can override enum name", async () => {
|
|
94
|
-
const {
|
|
95
|
-
TestEnum
|
|
96
|
-
} = await runner.compile(`
|
|
97
|
-
@test enum TestEnum {
|
|
98
|
-
Value1;
|
|
99
|
-
Value2;
|
|
100
|
-
}
|
|
101
|
-
`);
|
|
102
|
-
const res = render(_$createComponent(Output, {
|
|
103
|
-
get program() {
|
|
104
|
-
return runner.program;
|
|
105
|
-
},
|
|
106
|
-
get children() {
|
|
107
|
-
return _$createComponent(Namespace, {
|
|
108
|
-
name: "TestNamespace",
|
|
109
|
-
get children() {
|
|
110
|
-
return _$createComponent(SourceFile, {
|
|
111
|
-
path: "test.cs",
|
|
112
|
-
get children() {
|
|
113
|
-
return _$createComponent(EnumDeclaration, {
|
|
114
|
-
type: TestEnum,
|
|
115
|
-
name: "CustomEnumName"
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
|
-
assertFileContents(res, d`
|
|
124
|
-
namespace TestNamespace
|
|
125
|
-
{
|
|
126
|
-
enum CustomEnumName
|
|
127
|
-
{
|
|
128
|
-
Value1,
|
|
129
|
-
Value2
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
`);
|
|
133
|
-
});
|
|
134
|
-
it("renders an enum with access modifiers", async () => {
|
|
135
|
-
const {
|
|
136
|
-
TestEnum
|
|
137
|
-
} = await runner.compile(`
|
|
138
|
-
@test enum TestEnum {
|
|
139
|
-
Value1;
|
|
140
|
-
Value2;
|
|
141
|
-
}
|
|
142
|
-
`);
|
|
143
|
-
const res = render(_$createComponent(Output, {
|
|
144
|
-
get program() {
|
|
145
|
-
return runner.program;
|
|
146
|
-
},
|
|
147
|
-
get children() {
|
|
148
|
-
return _$createComponent(Namespace, {
|
|
149
|
-
name: "TestNamespace",
|
|
150
|
-
get children() {
|
|
151
|
-
return _$createComponent(SourceFile, {
|
|
152
|
-
path: "test.cs",
|
|
153
|
-
get children() {
|
|
154
|
-
return _$createComponent(EnumDeclaration, {
|
|
155
|
-
type: TestEnum,
|
|
156
|
-
internal: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}));
|
|
164
|
-
assertFileContents(res, d`
|
|
165
|
-
namespace TestNamespace
|
|
166
|
-
{
|
|
167
|
-
internal enum TestEnum
|
|
168
|
-
{
|
|
169
|
-
Value1,
|
|
170
|
-
Value2
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
`);
|
|
174
|
-
});
|
|
175
|
-
it("renders enum with C# naming conventions", async () => {
|
|
176
|
-
const {
|
|
177
|
-
TestEnum
|
|
178
|
-
} = await runner.compile(`
|
|
179
|
-
@test enum TestEnum {
|
|
180
|
-
value_one;
|
|
181
|
-
value_two;
|
|
182
|
-
value_three;
|
|
183
|
-
}
|
|
184
|
-
`);
|
|
185
|
-
const res = render(_$createComponent(Output, {
|
|
186
|
-
get program() {
|
|
187
|
-
return runner.program;
|
|
188
|
-
},
|
|
189
|
-
get namePolicy() {
|
|
190
|
-
return cs.createCSharpNamePolicy();
|
|
191
|
-
},
|
|
192
|
-
get children() {
|
|
193
|
-
return _$createComponent(Namespace, {
|
|
194
|
-
name: "TestNamespace",
|
|
195
|
-
get children() {
|
|
196
|
-
return _$createComponent(SourceFile, {
|
|
197
|
-
path: "test.cs",
|
|
198
|
-
get children() {
|
|
199
|
-
return _$createComponent(EnumDeclaration, {
|
|
200
|
-
type: TestEnum
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}));
|
|
208
|
-
assertFileContents(res, d`
|
|
209
|
-
namespace TestNamespace
|
|
210
|
-
{
|
|
211
|
-
enum TestEnum
|
|
212
|
-
{
|
|
213
|
-
ValueOne,
|
|
214
|
-
ValueTwo,
|
|
215
|
-
ValueThree
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
`);
|
|
219
|
-
});
|
|
220
|
-
it("renders enum with single value", async () => {
|
|
221
|
-
const {
|
|
222
|
-
TestEnum
|
|
223
|
-
} = await runner.compile(`
|
|
224
|
-
@test enum TestEnum {
|
|
225
|
-
OnlyValue;
|
|
226
|
-
}
|
|
227
|
-
`);
|
|
228
|
-
const res = render(_$createComponent(Output, {
|
|
229
|
-
get program() {
|
|
230
|
-
return runner.program;
|
|
231
|
-
},
|
|
232
|
-
get children() {
|
|
233
|
-
return _$createComponent(Namespace, {
|
|
234
|
-
name: "TestNamespace",
|
|
235
|
-
get children() {
|
|
236
|
-
return _$createComponent(SourceFile, {
|
|
237
|
-
path: "test.cs",
|
|
238
|
-
get children() {
|
|
239
|
-
return _$createComponent(EnumDeclaration, {
|
|
240
|
-
type: TestEnum
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}));
|
|
248
|
-
assertFileContents(res, d`
|
|
249
|
-
namespace TestNamespace
|
|
250
|
-
{
|
|
251
|
-
enum TestEnum
|
|
252
|
-
{
|
|
253
|
-
OnlyValue
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
`);
|
|
257
|
-
});
|
|
258
|
-
it("renders enum with numeric-like member names", async () => {
|
|
259
|
-
const {
|
|
260
|
-
TestEnum
|
|
261
|
-
} = await runner.compile(`
|
|
262
|
-
@test enum TestEnum {
|
|
263
|
-
Value0;
|
|
264
|
-
Value1;
|
|
265
|
-
Value10;
|
|
266
|
-
Value100;
|
|
267
|
-
}
|
|
268
|
-
`);
|
|
269
|
-
const res = render(_$createComponent(Output, {
|
|
270
|
-
get program() {
|
|
271
|
-
return runner.program;
|
|
272
|
-
},
|
|
273
|
-
get children() {
|
|
274
|
-
return _$createComponent(Namespace, {
|
|
275
|
-
name: "TestNamespace",
|
|
276
|
-
get children() {
|
|
277
|
-
return _$createComponent(SourceFile, {
|
|
278
|
-
path: "test.cs",
|
|
279
|
-
get children() {
|
|
280
|
-
return _$createComponent(EnumDeclaration, {
|
|
281
|
-
type: TestEnum
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}));
|
|
289
|
-
assertFileContents(res, d`
|
|
290
|
-
namespace TestNamespace
|
|
291
|
-
{
|
|
292
|
-
enum TestEnum
|
|
293
|
-
{
|
|
294
|
-
Value0,
|
|
295
|
-
Value1,
|
|
296
|
-
Value10,
|
|
297
|
-
Value100
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
`);
|
|
301
|
-
});
|
|
302
|
-
it("renders multiple enums in the same namespace", async () => {
|
|
303
|
-
const {
|
|
304
|
-
TestEnum1,
|
|
305
|
-
TestEnum2
|
|
306
|
-
} = await runner.compile(`
|
|
307
|
-
@test enum TestEnum1 {
|
|
308
|
-
Value1;
|
|
309
|
-
Value2;
|
|
310
|
-
}
|
|
311
|
-
@test enum TestEnum2 {
|
|
312
|
-
OptionA;
|
|
313
|
-
OptionB;
|
|
314
|
-
OptionC;
|
|
315
|
-
}
|
|
316
|
-
`);
|
|
317
|
-
const res = render(_$createComponent(Output, {
|
|
318
|
-
get program() {
|
|
319
|
-
return runner.program;
|
|
320
|
-
},
|
|
321
|
-
get children() {
|
|
322
|
-
return _$createComponent(Namespace, {
|
|
323
|
-
name: "TestNamespace",
|
|
324
|
-
get children() {
|
|
325
|
-
return _$createComponent(SourceFile, {
|
|
326
|
-
path: "test.cs",
|
|
327
|
-
get children() {
|
|
328
|
-
return [_$createComponent(EnumDeclaration, {
|
|
329
|
-
type: TestEnum1
|
|
330
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(EnumDeclaration, {
|
|
331
|
-
type: TestEnum2
|
|
332
|
-
})];
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}));
|
|
339
|
-
assertFileContents(res, d`
|
|
340
|
-
namespace TestNamespace
|
|
341
|
-
{
|
|
342
|
-
enum TestEnum1
|
|
343
|
-
{
|
|
344
|
-
Value1,
|
|
345
|
-
Value2
|
|
346
|
-
}
|
|
347
|
-
enum TestEnum2
|
|
348
|
-
{
|
|
349
|
-
OptionA,
|
|
350
|
-
OptionB,
|
|
351
|
-
OptionC
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
`);
|
|
355
|
-
});
|
|
356
|
-
it("renders an enum with doc comments", async () => {
|
|
357
|
-
const {
|
|
358
|
-
TestEnum
|
|
359
|
-
} = await runner.compile(`
|
|
360
|
-
@test enum TestEnum {
|
|
361
|
-
@doc("This is value one")
|
|
362
|
-
Value1;
|
|
363
|
-
/** This is value two */
|
|
364
|
-
Value2;
|
|
365
|
-
}
|
|
366
|
-
`);
|
|
367
|
-
const res = render(_$createComponent(Output, {
|
|
368
|
-
get program() {
|
|
369
|
-
return runner.program;
|
|
370
|
-
},
|
|
371
|
-
get children() {
|
|
372
|
-
return _$createComponent(Namespace, {
|
|
373
|
-
name: "TestNamespace",
|
|
374
|
-
get children() {
|
|
375
|
-
return _$createComponent(SourceFile, {
|
|
376
|
-
path: "test.cs",
|
|
377
|
-
get children() {
|
|
378
|
-
return _$createComponent(EnumDeclaration, {
|
|
379
|
-
type: TestEnum
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
}));
|
|
387
|
-
assertFileContents(res, d`
|
|
388
|
-
namespace TestNamespace
|
|
389
|
-
{
|
|
390
|
-
enum TestEnum
|
|
391
|
-
{
|
|
392
|
-
/// <summary>
|
|
393
|
-
/// This is value one
|
|
394
|
-
/// </summary>
|
|
395
|
-
Value1,
|
|
396
|
-
/// <summary>
|
|
397
|
-
/// This is value two
|
|
398
|
-
/// </summary>
|
|
399
|
-
Value2
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
`);
|
|
403
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Program } from "@typespec/compiler";
|
|
2
|
-
export declare function createTypespecCliTestHost(options?: {
|
|
3
|
-
libraries: "Http"[];
|
|
4
|
-
}): Promise<import("@typespec/compiler/testing").TestHost>;
|
|
5
|
-
export declare function createEmitterFrameworkTestRunner(options?: {
|
|
6
|
-
autoUsings?: string[];
|
|
7
|
-
}): Promise<import("@typespec/compiler/testing").BasicTestRunner>;
|
|
8
|
-
export declare function getProgram(code: string, options?: {
|
|
9
|
-
libraries: "Http"[];
|
|
10
|
-
}): Promise<Program>;
|
|
11
|
-
//# sourceMappingURL=test-host.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../test/csharp/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AASlD,wBAAsB,yBAAyB,CAC7C,OAAO,GAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAsB,0DASrD;AAED,wBAAsB,gCAAgC,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iEAK7F;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAsB,GACnD,OAAO,CAAC,OAAO,CAAC,CAUlB"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createTestHost, createTestWrapper, expectDiagnosticEmpty } from "@typespec/compiler/testing";
|
|
2
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
3
|
-
export async function createTypespecCliTestHost(options = {
|
|
4
|
-
libraries: []
|
|
5
|
-
}) {
|
|
6
|
-
const libraries = [];
|
|
7
|
-
if (options.libraries.includes("Http")) {
|
|
8
|
-
libraries.push(HttpTestLibrary);
|
|
9
|
-
}
|
|
10
|
-
return createTestHost({
|
|
11
|
-
libraries
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export async function createEmitterFrameworkTestRunner(options = {}) {
|
|
15
|
-
const host = await createTypespecCliTestHost();
|
|
16
|
-
return createTestWrapper(host, {
|
|
17
|
-
autoUsings: options.autoUsings
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export async function getProgram(code, options = {
|
|
21
|
-
libraries: []
|
|
22
|
-
}) {
|
|
23
|
-
const host = await createTypespecCliTestHost(options);
|
|
24
|
-
const wrapper = createTestWrapper(host, {
|
|
25
|
-
compilerOptions: {
|
|
26
|
-
noEmit: true
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
|
|
30
|
-
expectDiagnosticEmpty(diagnostics);
|
|
31
|
-
return wrapper.program;
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../test/csharp/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,QAIxE"}
|