diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-01-13 17:31:04 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-01-13 17:31:04 +0000 |
| commit | f5ba39cf70de72ae727c23df49b842a608dd4aaf (patch) | |
| tree | ea8e7d7606e54309abeb89b7fadce2cc7e88b4bb /src/test/java | |
| parent | 8f95317595dba4397c525b59cf8c2bae3658c03e (diff) | |
Add TypeInfos.subtypes()
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/typechecker/TypeInfosTests.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeInfosTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeInfosTests.java index 71386dfd..9697ef50 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeInfosTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeInfosTests.java @@ -44,4 +44,37 @@ public class TypeInfosTests { equalTo(Types.TOP) )); } + @Test + public void subtypesOfTypeIncludeThatTypeAndBottom() { + var typeInfos = TypeInfos.EMPTY; + + var supertypes = typeInfos.subtypes(Types.INT); + + assertThat(supertypes, isSequence( + equalTo(Types.INT), + equalTo(Types.BOTTOM) + )); + } + + @Test + public void subtypesOfSumIncludeVariants() { + var namespaceName = NamespaceName.of("Example", "Project"); + var sumType = Types.sum(namespaceName, "Sum"); + var variantType1 = Types.struct(namespaceName, "Variant1"); + var variantType2 = Types.struct(namespaceName, "Variant2"); + var typeInfos = TypeInfos.EMPTY + .addSumTypeInfo(sumType, new SumTypeInfo(P.orderedSet( + variantType1, + variantType2 + ))); + + var supertypes = typeInfos.subtypes(sumType); + + assertThat(supertypes, isSequence( + equalTo(sumType), + equalTo(variantType1), + equalTo(variantType2), + equalTo(Types.BOTTOM) + )); + } } |
