summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumDefinitionNodeMatcher.java46
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumVariantDefinitionNodeMatcher.java38
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java86
3 files changed, 170 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumDefinitionNodeMatcher.java
new file mode 100644
index 0000000..414c059
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumDefinitionNodeMatcher.java
@@ -0,0 +1,46 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+public class UntypedEnumDefinitionNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher isUntypedEnumDefinitionNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode>> submatchers;
+
+ private UntypedEnumDefinitionNodeMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode>> submatchers) {
+ this.submatchers = submatchers;
+ }
+
+ public org.zwobble.precisely.MatchResult match(java.lang.Object actual) {
+ return this.toMatcher().match(actual);
+ }
+
+ public org.zwobble.precisely.TextTree describe() {
+ return this.toMatcher().describe();
+ }
+
+ private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() {
+ return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher withName(org.zwobble.precisely.Matcher<? super String> name) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode::name, name))).toList());
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher withVariants(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode>> variants) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("variants", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode::variants, variants))).toList());
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher withDocComment(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.DocComment> docComment) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode::docComment, docComment))).toList());
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNode::source, source))).toList());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumVariantDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumVariantDefinitionNodeMatcher.java
new file mode 100644
index 0000000..4bc5a03
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedEnumVariantDefinitionNodeMatcher.java
@@ -0,0 +1,38 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+public class UntypedEnumVariantDefinitionNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher isUntypedEnumVariantDefinitionNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode>> submatchers;
+
+ private UntypedEnumVariantDefinitionNodeMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode>> submatchers) {
+ this.submatchers = submatchers;
+ }
+
+ public org.zwobble.precisely.MatchResult match(java.lang.Object actual) {
+ return this.toMatcher().match(actual);
+ }
+
+ public org.zwobble.precisely.TextTree describe() {
+ return this.toMatcher().describe();
+ }
+
+ private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() {
+ return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher withName(org.zwobble.precisely.Matcher<? super String> name) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode::name, name))).toList());
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNode::source, source))).toList());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java
new file mode 100644
index 0000000..925077f
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserEnumDefinitionTests.java
@@ -0,0 +1,86 @@
+package org.zwobble.hobgoblin.compiler.parser;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.ast.DocComment;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNode;
+
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumDefinitionNodeMatcher.isUntypedEnumDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedEnumVariantDefinitionNodeMatcher.isUntypedEnumVariantDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNodeMatcher.isUntypedStructFieldDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumDefinitionNodeMatcher.isUntypedSumDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNodeMatcher.isUntypedTypeLevelReferenceNode;
+import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.*;
+
+public class ParserEnumDefinitionTests {
+ @Test
+ public void nameIsParsed() {
+ var source = """
+ enum SmallNumber {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedEnumDefinitionNode()
+ .withName(equalTo("SmallNumber"))
+ );
+ }
+
+ @Test
+ public void emptyEnumHasNoVariants() {
+ var source = """
+ enum SmallNumber {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedEnumDefinitionNode()
+ .withVariants(isSequence())
+ );
+ }
+
+ @Test
+ public void enumWithVariants() {
+ var source = """
+ enum SmallNumber {
+ variant zero;
+ variant one;
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedEnumDefinitionNode()
+ .withVariants(isSequence(
+ isUntypedEnumVariantDefinitionNode().withName(equalTo("zero")),
+ isUntypedEnumVariantDefinitionNode().withName(equalTo("one"))
+ ))
+ );
+ }
+
+ @Test
+ public void enumWithDocComment() {
+ var source = """
+ /// A small number.
+ enum SmallNumber {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedEnumDefinitionNode()
+ .withDocComment(equalTo(new DocComment("A small number.\n")))
+ );
+ }
+}