-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(zmodel): check cyclic inheritance (#1931)
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/schema/tests/schema/validation/cyclic-inheritance.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { loadModelWithError } from '../../utils'; | ||
|
||
describe('Cyclic inheritance', () => { | ||
it('abstract inheritance', async () => { | ||
const errors = await loadModelWithError( | ||
` | ||
abstract model A extends B {} | ||
abstract model B extends A {} | ||
model C extends B { | ||
id Int @id | ||
} | ||
` | ||
); | ||
expect(errors).toContain('Circular inheritance detected: A -> B -> A'); | ||
expect(errors).toContain('Circular inheritance detected: B -> A -> B'); | ||
expect(errors).toContain('Circular inheritance detected: C -> B -> A -> B'); | ||
}); | ||
|
||
it('delegate inheritance', async () => { | ||
const errors = await loadModelWithError( | ||
` | ||
model A extends B { | ||
typeA String | ||
@@delegate(typeA) | ||
} | ||
model B extends A { | ||
typeB String | ||
@@delegate(typeB) | ||
} | ||
model C extends B { | ||
id Int @id | ||
} | ||
` | ||
); | ||
expect(errors).toContain('Circular inheritance detected: A -> B -> A'); | ||
expect(errors).toContain('Circular inheritance detected: B -> A -> B'); | ||
expect(errors).toContain('Circular inheritance detected: C -> B -> A -> B'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters