diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-12-11 00:17:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-12-11 00:17:53 +0000 |
| commit | 6f11bbeab6957974b3b30018deb46ef8ecde258f (patch) | |
| tree | 00cd403eb6fb15e62d8d9b5bf92bd88ad5d8be8f /src/test/java | |
| parent | f68860bbe29064318869cca0eaa4b2a2f39bddac (diff) | |
Move field positionality from struct field to struct
Diffstat (limited to 'src/test/java')
8 files changed, 33 insertions, 33 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java index 0fe33eaa..bfa2564b 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java @@ -222,7 +222,7 @@ public class Typed { String name, TypedTypeLevelExpressionNode<Type> type ) { - return new TypedStructFieldDefinitionNode(name, type, false, Sources.NULL); + return new TypedStructFieldDefinitionNode(name, type, Sources.NULL); } public static TypedSumTypeDefinitionNode sumTypeDefinition(SimpleSumType sumType) { diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java index aeb8d3ee..c9a10623 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructDefinitionNodeMatcher.java @@ -9,6 +9,7 @@ import org.zwobble.precisely.Matcher; import static org.shedlang.compiler.types.TypeMatchers.isConstructorNotType; import static org.shedlang.compiler.types.TypeMatchers.isTypeNotConstructor; +import static org.zwobble.precisely.Matchers.equalTo; import static org.zwobble.precisely.Matchers.has; public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< @@ -55,4 +56,14 @@ public class TypedStructDefinitionNodeMatcher extends MatcherBuilder< ) { return with(has("fields", x -> x.fields(), fields)); } + + public TypedStructDefinitionNodeMatcher withFieldsArePositional( + boolean fieldsArePositional + ) { + return with(has( + "fieldsArePositional", + x -> x.fieldsArePositional(), + equalTo(fieldsArePositional) + )); + } } diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java index 7053bd26..f8ba23ae 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedStructFieldDefinitionNodeMatcher.java @@ -42,10 +42,4 @@ public class TypedStructFieldDefinitionNodeMatcher extends MatcherBuilder< ) { return with(has("type", x -> x.type(), type)); } - - public TypedStructFieldDefinitionNodeMatcher withIsPositional( - boolean isPositional - ) { - return with(has("isPositional", x -> x.isPositional(), equalTo(isPositional))); - } } diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java index 480e63a4..2eacfade 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/Untyped.java @@ -189,14 +189,7 @@ public class Untyped { String name, UntypedTypeLevelExpressionNode type ) { - return new UntypedStructFieldDefinitionNode(name, type, false, Sources.NULL); - } - - public static UntypedStructFieldDefinitionNode structFieldDefinitionPositional( - String name, - UntypedTypeLevelExpressionNode type - ) { - return new UntypedStructFieldDefinitionNode(name, type, true, Sources.NULL); + return new UntypedStructFieldDefinitionNode(name, type, Sources.NULL); } public static UntypedBinaryOperationNode sub( diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java index ba87b50f..0c1090b2 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java @@ -44,6 +44,16 @@ public class UntypedStructDefinitionNodeMatcher extends MatcherBuilder<UntypedNa return with(has("fields", x -> x.fields(), fields)); } + public UntypedStructDefinitionNodeMatcher withFieldsArePositional( + boolean fieldsArePositional + ) { + return with(has( + "fieldsArePositional", + x -> x.fieldsArePositional(), + equalTo(fieldsArePositional) + )); + } + public UntypedStructDefinitionNodeMatcher withVisibility(Visibility visibility) { return with(has("visibility", x -> x.visibility(), equalTo(visibility))); } diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java index 5ca0d994..2e0f1d63 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedStructFieldDefinitionNodeMatcher.java @@ -34,8 +34,4 @@ public class UntypedStructFieldDefinitionNodeMatcher extends MatcherBuilder<Unty public UntypedStructFieldDefinitionNodeMatcher withType(Matcher<UntypedTypeLevelExpressionNode> type) { return with(has("type", x -> x.type(), type)); } - - public UntypedStructFieldDefinitionNodeMatcher withIsPositional(boolean isPositional) { - return with(has("isPositional", x -> x.isPositional(), equalTo(isPositional))); - } } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java index f5a77ab3..665da1e5 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java @@ -42,12 +42,10 @@ public class ParserStructDefinitionTests { .withFields(isSequence( isUntypedStructFieldDefinitionNode() .withName("name") - .withType(isUntypedTypeLevelReferenceNode("String")) - .withIsPositional(false), + .withType(isUntypedTypeLevelReferenceNode("String")), isUntypedStructFieldDefinitionNode() .withName("accessLevel") .withType(isUntypedTypeLevelReferenceNode("AccessLevel")) - .withIsPositional(false) )) ); } @@ -67,12 +65,10 @@ public class ParserStructDefinitionTests { .withFields(isSequence( isUntypedStructFieldDefinitionNode() .withName("name") - .withType(isUntypedTypeLevelReferenceNode("String")) - .withIsPositional(true), + .withType(isUntypedTypeLevelReferenceNode("String")), isUntypedStructFieldDefinitionNode() .withName("accessLevel") .withType(isUntypedTypeLevelReferenceNode("AccessLevel")) - .withIsPositional(true) )) ); } diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java index f09f51b4..49833148 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -146,6 +146,7 @@ public class TypeCheckerStructDefinitionTests { .withName("ExampleStruct") .addField(Untyped.structFieldDefinition("b", Untyped.typeLevelReference("Bool"))) .addField(Untyped.structFieldDefinition("a", Untyped.typeLevelReference("Int"))) + .withFieldsArePositional(false) .build(); var context = TypeCheckerContext.EMPTY .enterGlobal(P.map( @@ -162,13 +163,12 @@ public class TypeCheckerStructDefinitionTests { .withFields(isSequence( isTypedStructFieldDefinitionNode() .withName("b") - .withType(isTypedTypeLevelReferenceNode("Bool", Types.BOOL)) - .withIsPositional(false), + .withType(isTypedTypeLevelReferenceNode("Bool", Types.BOOL)), isTypedStructFieldDefinitionNode() .withName("a") .withType(isTypedTypeLevelReferenceNode("Int", Types.INT)) - .withIsPositional(false) )) + .withFieldsArePositional(false) ); } @@ -176,8 +176,9 @@ public class TypeCheckerStructDefinitionTests { public void canTypeCheckStructDefinitionWithPositionalFields() { var untyped = UntypedStructDefinitionNode.builder() .withName("ExampleStruct") - .addField(Untyped.structFieldDefinitionPositional("b", Untyped.typeLevelReference("Bool"))) - .addField(Untyped.structFieldDefinitionPositional("a", Untyped.typeLevelReference("Int"))) + .addField(Untyped.structFieldDefinition("b", Untyped.typeLevelReference("Bool"))) + .addField(Untyped.structFieldDefinition("a", Untyped.typeLevelReference("Int"))) + .withFieldsArePositional(true) .build(); var context = TypeCheckerContext.EMPTY .enterGlobal(P.map( @@ -194,13 +195,12 @@ public class TypeCheckerStructDefinitionTests { .withFields(isSequence( isTypedStructFieldDefinitionNode() .withName("b") - .withType(isTypedTypeLevelReferenceNode("Bool", Types.BOOL)) - .withIsPositional(true), + .withType(isTypedTypeLevelReferenceNode("Bool", Types.BOOL)), isTypedStructFieldDefinitionNode() .withName("a") .withType(isTypedTypeLevelReferenceNode("Int", Types.INT)) - .withIsPositional(true) )) + .withFieldsArePositional(true) ); } |
