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/typed/TypedFunctionExpressionNodeMatcher.java59
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedParamNodeMatcher.java53
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java39
3 files changed, 151 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedFunctionExpressionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedFunctionExpressionNodeMatcher.java
new file mode 100644
index 0000000..175ab05
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedFunctionExpressionNodeMatcher.java
@@ -0,0 +1,59 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.typed;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher imports
+
+public final class TypedFunctionExpressionNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher isTypedFunctionExpressionNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>> submatchers;
+
+ private TypedFunctionExpressionNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>> 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.typed.TypedFunctionExpressionNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>> params) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode::params, (org.zwobble.precisely.Matcher) params));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher withBody(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedExpressionNode> body) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode::body, (org.zwobble.precisely.Matcher) body));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.types.Type> type) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode::type, (org.zwobble.precisely.Matcher) type));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedParamNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedParamNodeMatcher.java
new file mode 100644
index 0000000..5efa568
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedParamNodeMatcher.java
@@ -0,0 +1,53 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.typed;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher imports
+
+public final class TypedParamNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher isTypedParamNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>> submatchers;
+
+ private TypedParamNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>> 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.typed.TypedParamNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher withName(org.zwobble.precisely.Matcher<? super String> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.types.Type> type) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode::type, (org.zwobble.precisely.Matcher) type));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
new file mode 100644
index 0000000..f927b95
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
@@ -0,0 +1,39 @@
+package org.zwobble.hobgoblin.compiler.typechecker;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode;
+import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
+import org.zwobble.hobgoblin.compiler.sources.NullSource;
+import org.zwobble.hobgoblin.compiler.types.NamespaceName;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.zwobble.hobgoblin.compiler.ast.typed.TypedFunctionExpressionNodeMatcher.isTypedFunctionExpressionNode;
+import static org.zwobble.hobgoblin.compiler.ast.typed.TypedReferenceNodeMatcher.isTypedReferenceNode;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class TypeCheckerFunctionExpressionTests {
+ @Test
+ public void bodyOfFunctionExpressionIsTypeChecked() {
+ var untyped = UntypedFunctionExpressionNode.arbitrary()
+ .withParams(List.of())
+ .withBody(UntypedReferenceNode.arbitrary().withName("a"))
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+ namespaceContext.declare("a", NativeTypes.INT_32, NullSource.INSTANCE);
+
+ var typed = TypeChecker.typeCheckExpression(untyped, Optional.empty(), namespaceContext);
+
+ // TODO: assert type
+ assertThat(typed, isTypedFunctionExpressionNode()
+ .withParams(isSequence())
+ .withBody(isTypedReferenceNode().withName(equalTo("a")).withType(equalTo(NativeTypes.INT_32)))
+ );
+ }
+}