summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java39
2 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java
index a198802..d559c0d 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructDefinitionNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedStructDefinitionNodeMatcher implements org.zwobble.pre
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNodeMatcher withTypeParams(org.zwobble.precisely.Matcher<? super java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeParamNode>>> typeParams) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("typeParams", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode::typeParams, typeParams));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNodeMatcher withFields(org.zwobble.precisely.Matcher<? super java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode>>> fields) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("fields", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode::fields, fields));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
index 0b8ba5e..2b2fe33 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserStructDefinitionTests.java
@@ -6,6 +6,8 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNodeMatcher.isUntypedStructDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeParamNodeMatcher.isUntypedTypeParamNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.*;
@@ -30,6 +32,43 @@ public class ParserStructDefinitionTests {
}
@Test
+ public void oneTypeParam() {
+ var source = """
+ struct A[B] {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedStructDefinitionNode()
+ .withTypeParams(isOptionalOf(isSequence(
+ isUntypedTypeParamNode().withName(equalTo("B"))
+ )))
+ );
+ }
+
+ @Test
+ public void manyTypeParams() {
+ var source = """
+ struct A[B, C] {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedStructDefinitionNode()
+ .withTypeParams(isOptionalOf(isSequence(
+ isUntypedTypeParamNode().withName(equalTo("B")),
+ isUntypedTypeParamNode().withName(equalTo("C"))
+ )))
+ );
+ }
+
+ @Test
public void structWithFields() {
var source = """
struct Point {