aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-12-19 16:30:17 +0000
committerMichael Williamson <mike@zwobble.org>2024-12-19 16:30:17 +0000
commit4f8135071ae6faf7abfbc2f4765101ce9c0bb287 (patch)
tree466ce9540538e5f3a193b0b82fde30796651de0f /src/test/java/org/shedlang/compiler/parser
parentcbe45599f7b46d7a0674a62d424b9485e7735d45 (diff)
Define methods directly on struct
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java47
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java65
2 files changed, 65 insertions, 47 deletions
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java b/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java
deleted file mode 100644
index 6652a46e..00000000
--- a/src/test/java/org/shedlang/compiler/parser/ParserExtendInlineTests.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.shedlang.compiler.parser;
-
-import org.junit.jupiter.api.Test;
-
-import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.*;
-import static org.shedlang.compiler.parser.ParserTesting.parseString;
-import static org.zwobble.precisely.AssertThat.assertThat;
-import static org.zwobble.precisely.Matchers.isSequence;
-
-public class ParserExtendInlineTests {
- @Test
- public void canParseExtendInlineWithNoMethods() {
- var source = """
- extend Count {}
- """;
-
- var node = parseString(source, Parser::parseNamespaceStatement);
-
- assertThat(
- node,
- isUntypedExtendInlineNode()
- .withExtendedType(isUntypedTypeLevelReferenceNode("Count"))
- .withMethods(isSequence())
- );
- }
-
- @Test
- public void canParseExtendInlineWithSingleMethod() {
- var source = """
- extend Count {
- fun message(this) {
- }
- }
- """;
-
- var node = parseString(source, Parser::parseNamespaceStatement);
-
- assertThat(
- node,
- isUntypedExtendInlineNode()
- .withExtendedType(isUntypedTypeLevelReferenceNode("Count"))
- .withMethods(isSequence(
- isUntypedFunctionDefinitionNode().withName("message")
- ))
- );
- }
-}
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java
index b450506e..9380c64a 100644
--- a/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java
+++ b/src/test/java/org/shedlang/compiler/parser/ParserStructDefinitionTests.java
@@ -178,4 +178,69 @@ public class ParserStructDefinitionTests {
)))
);
}
+
+
+ @Test
+ public void canParseStructWithNoMethods() {
+ var source = """
+ struct X() {}
+ """;
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(
+ node,
+ isUntypedStructDefinitionNode()
+ .withMethods(isSequence())
+ );
+ }
+
+ @Test
+ public void canParseExtendInlineWithSingleMethod() {
+ var source = """
+ struct X() {
+ fun a(this) {
+ }
+ }
+ """;
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(
+ node,
+ isUntypedStructDefinitionNode()
+ .withMethods(isSequence(
+ isUntypedFunctionDefinitionNode().withName("a")
+ ))
+ );
+ }
+
+ @Test
+ public void canParseExtendInlineWithMultipleMethods() {
+ var source = """
+ struct X() {
+ fun a(this) {
+ }
+
+ fun b(this) {
+ }
+
+ fun c(this) {
+ }
+
+ }
+ """;
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(
+ node,
+ isUntypedStructDefinitionNode()
+ .withMethods(isSequence(
+ isUntypedFunctionDefinitionNode().withName("a"),
+ isUntypedFunctionDefinitionNode().withName("b"),
+ isUntypedFunctionDefinitionNode().withName("c")
+ ))
+ );
+ }
}