Skip to content

Commit

Permalink
Add more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Nov 21, 2023
1 parent 53239c6 commit 32c98ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function $onValidate(program: Program) {
if (typeChangedFrom !== undefined) {
validateMultiTypeReference(program, prop);
} else {
// FIXME: This is broken.
validateReference(program, prop, prop.type);
}

Expand Down
29 changes: 28 additions & 1 deletion packages/versioning/test/incompatible-versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ describe("versioning: validate incompatible references", () => {
});
});

it("emit diagnostic when unversioned op has a versioned parameter", async () => {
const diagnostics = await runner.diagnose(`
model Foo {}
op test(param: string, @added(Versions.v2) newParam: Foo): void;
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
message:
"'TestService.test' is referencing versioned type 'TestService.Foo' but is not versioned itself.",
});
});

it("emit diagnostic when unversioned op based on a template has a versioned model as a parameter", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
Expand All @@ -133,7 +146,7 @@ describe("versioning: validate incompatible references", () => {
});
});

it("emit diagnostic when when op was added before parameter", async () => {
it("emit diagnostic when when op was added before parameter type", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
model Foo {}
Expand All @@ -148,6 +161,20 @@ describe("versioning: validate incompatible references", () => {
});
});

it("emit diagnostic when when op was added before parameter", async () => {
const diagnostics = await runner.diagnose(`
model Foo {}
@added(Versions.v1)
op test(@added(Versions.v2) param: Foo): void;
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
message:
"'TestService.test' was added in version 'v1' but referencing type 'TestService.(anonymous model).param' added in version 'v2'.",
});
});

it("emit diagnostic when op based on a template was added before parameter", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
Expand Down

0 comments on commit 32c98ed

Please sign in to comment.