@@ -3,15 +3,21 @@ import { UsageFlags } from "@azure-tools/typespec-client-generator-core";
3
3
import { strictEqual } from "assert" ;
4
4
import { beforeEach , describe , it } from "vitest" ;
5
5
import { createModel } from "@typespec/http-client-csharp" ;
6
- import { createCSharpSdkContext , createEmitterContext , createEmitterTestHost , typeSpecCompile , } from "./test-util.js" ;
6
+ import {
7
+ createCSharpSdkContext ,
8
+ createEmitterContext ,
9
+ createEmitterTestHost ,
10
+ typeSpecCompile
11
+ } from "./test-util.js" ;
7
12
8
13
describe ( "Test GetInputType for enum" , ( ) => {
9
- let runner : TestHost ;
10
- beforeEach ( async ( ) => {
11
- runner = await createEmitterTestHost ( ) ;
12
- } ) ;
13
- it ( "Fixed string enum" , async ( ) => {
14
- const program = await typeSpecCompile ( `
14
+ let runner : TestHost ;
15
+ beforeEach ( async ( ) => {
16
+ runner = await createEmitterTestHost ( ) ;
17
+ } ) ;
18
+ it ( "Fixed string enum" , async ( ) => {
19
+ const program = await typeSpecCompile (
20
+ `
15
21
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator."
16
22
@doc("fixed string enum")
17
23
@fixed
@@ -26,31 +32,40 @@ describe("Test GetInputType for enum", () => {
26
32
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace."
27
33
@doc("test fixed enum.")
28
34
op test(@doc("fixed enum as input.")@body input: SimpleEnum): string[];
29
- ` , runner , { IsNamespaceNeeded : true } ) ;
30
- const context = createEmitterContext ( program ) ;
31
- const sdkContext = await createCSharpSdkContext ( context ) ;
32
- const root = createModel ( sdkContext ) ;
33
- const inputParamArray = root . Clients [ 0 ] . Operations [ 0 ] . Parameters . filter ( ( p ) => p . Name === "input" ) ;
34
- strictEqual ( 1 , inputParamArray . length ) ;
35
- const type = inputParamArray [ 0 ] . Type ;
36
- strictEqual ( type . kind , "enum" ) ;
37
- strictEqual ( type . name , "SimpleEnum" ) ;
38
- strictEqual ( type . isFixed , true ) ;
39
- strictEqual ( type . doc , "fixed string enum" ) ;
40
- strictEqual ( type . crossLanguageDefinitionId , "Azure.Csharp.Testing.SimpleEnum" ) ;
41
- strictEqual ( type . access , undefined ) ;
42
- strictEqual ( type . valueType . kind , "string" ) ;
43
- strictEqual ( type . values . length , 3 ) ;
44
- strictEqual ( type . values [ 0 ] . name , "One" ) ;
45
- strictEqual ( type . values [ 0 ] . value , "1" ) ;
46
- strictEqual ( type . values [ 1 ] . name , "Two" ) ;
47
- strictEqual ( type . values [ 1 ] . value , "2" ) ;
48
- strictEqual ( type . values [ 2 ] . name , "Four" ) ;
49
- strictEqual ( type . values [ 2 ] . value , "4" ) ;
50
- strictEqual ( type . usage , UsageFlags . Input | UsageFlags . Json ) ;
51
- } ) ;
52
- it ( "Fixed int enum" , async ( ) => {
53
- const program = await typeSpecCompile ( `
35
+ ` ,
36
+ runner ,
37
+ { IsNamespaceNeeded : true }
38
+ ) ;
39
+ const context = createEmitterContext ( program ) ;
40
+ const sdkContext = await createCSharpSdkContext ( context ) ;
41
+ const root = createModel ( sdkContext ) ;
42
+ const inputParamArray = root . Clients [ 0 ] . Operations [ 0 ] . Parameters . filter (
43
+ ( p ) => p . Name === "input"
44
+ ) ;
45
+ strictEqual ( 1 , inputParamArray . length ) ;
46
+ const type = inputParamArray [ 0 ] . Type ;
47
+ strictEqual ( type . kind , "enum" ) ;
48
+ strictEqual ( type . name , "SimpleEnum" ) ;
49
+ strictEqual ( type . isFixed , true ) ;
50
+ strictEqual ( type . doc , "fixed string enum" ) ;
51
+ strictEqual (
52
+ type . crossLanguageDefinitionId ,
53
+ "Azure.Csharp.Testing.SimpleEnum"
54
+ ) ;
55
+ strictEqual ( type . access , undefined ) ;
56
+ strictEqual ( type . valueType . kind , "string" ) ;
57
+ strictEqual ( type . values . length , 3 ) ;
58
+ strictEqual ( type . values [ 0 ] . name , "One" ) ;
59
+ strictEqual ( type . values [ 0 ] . value , "1" ) ;
60
+ strictEqual ( type . values [ 1 ] . name , "Two" ) ;
61
+ strictEqual ( type . values [ 1 ] . value , "2" ) ;
62
+ strictEqual ( type . values [ 2 ] . name , "Four" ) ;
63
+ strictEqual ( type . values [ 2 ] . value , "4" ) ;
64
+ strictEqual ( type . usage , UsageFlags . Input | UsageFlags . Json ) ;
65
+ } ) ;
66
+ it ( "Fixed int enum" , async ( ) => {
67
+ const program = await typeSpecCompile (
68
+ `
54
69
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "Enums should be defined without the @fixed decorator."
55
70
@doc("Fixed int enum")
56
71
@fixed
@@ -65,29 +80,37 @@ describe("Test GetInputType for enum", () => {
65
80
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "Operation 'test' should be defined using a signature from the Azure.Core namespace."
66
81
@doc("test fixed enum.")
67
82
op test(@doc("fixed enum as input.")@body input: FixedIntEnum): string[];
68
- ` , runner , { IsNamespaceNeeded : true } ) ;
69
- const context = createEmitterContext ( program ) ;
70
- const sdkContext = await createCSharpSdkContext ( context ) ;
71
- const root = createModel ( sdkContext ) ;
72
- const inputParamArray = root . Clients [ 0 ] . Operations [ 0 ] . Parameters . filter ( ( p ) => p . Name === "input" ) ;
73
- strictEqual ( 1 , inputParamArray . length ) ;
74
- const type = inputParamArray [ 0 ] . Type ;
75
- strictEqual ( type . kind , "enum" ) ;
76
- strictEqual ( type . name , "FixedIntEnum" ) ;
77
- strictEqual ( type . crossLanguageDefinitionId , "Azure.Csharp.Testing.FixedIntEnum" ) ;
78
- strictEqual ( type . access , undefined ) ;
79
- strictEqual ( type . doc , "Fixed int enum" ) ;
80
- strictEqual ( type . valueType . crossLanguageDefinitionId , "TypeSpec.int32" ) ;
81
- strictEqual ( type . valueType . kind , "int32" ) ;
82
- strictEqual ( type . values . length , 3 ) ;
83
- strictEqual ( type . values [ 0 ] . name , "One" ) ;
84
- strictEqual ( type . values [ 0 ] . value , 1 ) ;
85
- strictEqual ( type . values [ 1 ] . name , "Two" ) ;
86
- strictEqual ( type . values [ 1 ] . value , 2 ) ;
87
- strictEqual ( type . values [ 2 ] . name , "Four" ) ;
88
- strictEqual ( type . values [ 2 ] . value , 4 ) ;
89
- strictEqual ( type . isFixed , true ) ;
90
- strictEqual ( type . usage , UsageFlags . Input | UsageFlags . Json ) ;
91
- } ) ;
83
+ ` ,
84
+ runner ,
85
+ { IsNamespaceNeeded : true }
86
+ ) ;
87
+ const context = createEmitterContext ( program ) ;
88
+ const sdkContext = await createCSharpSdkContext ( context ) ;
89
+ const root = createModel ( sdkContext ) ;
90
+ const inputParamArray = root . Clients [ 0 ] . Operations [ 0 ] . Parameters . filter (
91
+ ( p ) => p . Name === "input"
92
+ ) ;
93
+ strictEqual ( 1 , inputParamArray . length ) ;
94
+ const type = inputParamArray [ 0 ] . Type ;
95
+ strictEqual ( type . kind , "enum" ) ;
96
+ strictEqual ( type . name , "FixedIntEnum" ) ;
97
+ strictEqual (
98
+ type . crossLanguageDefinitionId ,
99
+ "Azure.Csharp.Testing.FixedIntEnum"
100
+ ) ;
101
+ strictEqual ( type . access , undefined ) ;
102
+ strictEqual ( type . doc , "Fixed int enum" ) ;
103
+ strictEqual ( type . valueType . crossLanguageDefinitionId , "TypeSpec.int32" ) ;
104
+ strictEqual ( type . valueType . kind , "int32" ) ;
105
+ strictEqual ( type . values . length , 3 ) ;
106
+ strictEqual ( type . values [ 0 ] . name , "One" ) ;
107
+ strictEqual ( type . values [ 0 ] . value , 1 ) ;
108
+ strictEqual ( type . values [ 1 ] . name , "Two" ) ;
109
+ strictEqual ( type . values [ 1 ] . value , 2 ) ;
110
+ strictEqual ( type . values [ 2 ] . name , "Four" ) ;
111
+ strictEqual ( type . values [ 2 ] . value , 4 ) ;
112
+ strictEqual ( type . isFixed , true ) ;
113
+ strictEqual ( type . usage , UsageFlags . Input | UsageFlags . Json ) ;
114
+ } ) ;
92
115
} ) ;
93
- //# sourceMappingURL=property-type.test.js.map
116
+ //# sourceMappingURL=property-type.test.js.map
0 commit comments