Skip to content

Commit 3b42243

Browse files
committed
include passing/failing scenarios for unions
1 parent ca236c8 commit 3b42243

1 file changed

Lines changed: 261 additions & 0 deletions

File tree

packages/http-server-csharp/test/generation.test.ts

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,3 +3445,264 @@ it("emits class for model extending another model with no additional properties"
34453445
],
34463446
);
34473447
});
3448+
// test passing
3449+
it("generates extensible enum for named union with string base and named variants", async () => {
3450+
await compileAndValidateMultiple(
3451+
tester,
3452+
`
3453+
/** Reasoning effort level */
3454+
union ReasoningEffort {
3455+
string,
3456+
3457+
/** No reasoning effort. */
3458+
none: "none",
3459+
3460+
/** Minimal reasoning effort. */
3461+
minimal: "minimal",
3462+
3463+
/** Low reasoning effort - faster responses with less reasoning. */
3464+
low: "low",
3465+
3466+
/** Medium reasoning effort - balanced between speed and reasoning depth. */
3467+
medium: "medium",
3468+
3469+
/** High reasoning effort - more thorough reasoning, may take longer. */
3470+
high: "high",
3471+
3472+
/** Extra high reasoning effort - maximum reasoning depth. */
3473+
xhigh: "xhigh",
3474+
}
3475+
3476+
/** A simple test model */
3477+
model Foo {
3478+
/** effort level */
3479+
effort?: ReasoningEffort;
3480+
}
3481+
3482+
@route("/foo") @get op getFoo(): Foo;
3483+
`,
3484+
[
3485+
[
3486+
"ReasoningEffort.cs",
3487+
[
3488+
"public enum ReasoningEffort",
3489+
"[JsonConverter(typeof(JsonStringEnumConverter))]",
3490+
`[JsonStringEnumMemberName("none")]`,
3491+
"None,",
3492+
`[JsonStringEnumMemberName("minimal")]`,
3493+
"Minimal,",
3494+
`[JsonStringEnumMemberName("low")]`,
3495+
"Low,",
3496+
`[JsonStringEnumMemberName("medium")]`,
3497+
"Medium,",
3498+
`[JsonStringEnumMemberName("high")]`,
3499+
"High,",
3500+
`[JsonStringEnumMemberName("xhigh")]`,
3501+
"Xhigh",
3502+
],
3503+
],
3504+
[
3505+
"Foo.cs",
3506+
[
3507+
"public partial class Foo",
3508+
"ReasoningEffort",
3509+
"Effort",
3510+
],
3511+
],
3512+
],
3513+
);
3514+
});
3515+
// test failing
3516+
it("generates non-empty model for named union of string literals with null", async () => {
3517+
await compileAndValidateMultiple(
3518+
tester,
3519+
`
3520+
/** Reasoning effort level */
3521+
union ReasoningEffort {
3522+
"none",
3523+
"minimal",
3524+
"low",
3525+
"medium",
3526+
"high",
3527+
"xhigh",
3528+
null,
3529+
}
3530+
3531+
/** A simple test model */
3532+
model Foo {
3533+
/** effort level */
3534+
effort?: ReasoningEffort;
3535+
}
3536+
3537+
@route("/foo") @get op getFoo(): Foo;
3538+
`,
3539+
[
3540+
[
3541+
"ReasoningEffort.cs",
3542+
[
3543+
"ReasoningEffort",
3544+
],
3545+
],
3546+
[
3547+
"Foo.cs",
3548+
[
3549+
"public partial class Foo",
3550+
"Effort",
3551+
],
3552+
],
3553+
],
3554+
);
3555+
});
3556+
// test failing
3557+
it("generates enum for named union of unnamed string literals without null", async () => {
3558+
await compileAndValidateMultiple(
3559+
tester,
3560+
`
3561+
/** Priority level */
3562+
union Priority {
3563+
"low",
3564+
"medium",
3565+
"high",
3566+
}
3567+
3568+
/** A simple test model */
3569+
model Foo {
3570+
/** priority */
3571+
priority?: Priority;
3572+
}
3573+
3574+
@route("/foo") @get op getFoo(): Foo;
3575+
`,
3576+
[
3577+
[
3578+
"Priority.cs",
3579+
[
3580+
"Priority",
3581+
],
3582+
],
3583+
[
3584+
"Foo.cs",
3585+
[
3586+
"public partial class Foo",
3587+
"Priority",
3588+
],
3589+
],
3590+
],
3591+
);
3592+
});
3593+
// test failing
3594+
it("generates enum for named union with named variants and null", async () => {
3595+
await compileAndValidateMultiple(
3596+
tester,
3597+
`
3598+
/** Reasoning effort level */
3599+
union ReasoningEffort {
3600+
/** No reasoning effort. */
3601+
none: "none",
3602+
3603+
/** Medium reasoning effort. */
3604+
medium: "medium",
3605+
3606+
/** High reasoning effort. */
3607+
high: "high",
3608+
3609+
/** Null value */
3610+
null,
3611+
}
3612+
3613+
/** A simple test model */
3614+
model Foo {
3615+
/** effort level */
3616+
effort?: ReasoningEffort;
3617+
}
3618+
3619+
@route("/foo") @get op getFoo(): Foo;
3620+
`,
3621+
[
3622+
[
3623+
"ReasoningEffort.cs",
3624+
[
3625+
"ReasoningEffort",
3626+
],
3627+
],
3628+
[
3629+
"Foo.cs",
3630+
[
3631+
"public partial class Foo",
3632+
"Effort",
3633+
],
3634+
],
3635+
],
3636+
);
3637+
});
3638+
// test failing
3639+
it("generates enum for extensible union with string base, named variants, and null", async () => {
3640+
await compileAndValidateMultiple(
3641+
tester,
3642+
`
3643+
/** Reasoning effort level */
3644+
union ReasoningEffort {
3645+
string,
3646+
3647+
/** No reasoning effort. */
3648+
none: "none",
3649+
3650+
/** Medium reasoning effort. */
3651+
medium: "medium",
3652+
3653+
/** High reasoning effort. */
3654+
high: "high",
3655+
3656+
/** Null value */
3657+
null,
3658+
}
3659+
3660+
/** A simple test model */
3661+
model Foo {
3662+
/** effort level */
3663+
effort?: ReasoningEffort;
3664+
}
3665+
3666+
@route("/foo") @get op getFoo(): Foo;
3667+
`,
3668+
[
3669+
[
3670+
"ReasoningEffort.cs",
3671+
[
3672+
"ReasoningEffort",
3673+
],
3674+
],
3675+
[
3676+
"Foo.cs",
3677+
[
3678+
"public partial class Foo",
3679+
"Effort",
3680+
],
3681+
],
3682+
],
3683+
);
3684+
});
3685+
// test passing
3686+
it("generates nullable property for inline union of string literals with null", async () => {
3687+
await compileAndValidateMultiple(
3688+
tester,
3689+
`
3690+
/** A simple test model */
3691+
model Foo {
3692+
/** effort level */
3693+
effort?: "low" | "medium" | "high" | null;
3694+
}
3695+
3696+
@route("/foo") @get op getFoo(): Foo;
3697+
`,
3698+
[
3699+
[
3700+
"Foo.cs",
3701+
[
3702+
"public partial class Foo",
3703+
"Effort",
3704+
],
3705+
],
3706+
],
3707+
);
3708+
});

0 commit comments

Comments
 (0)