aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-22 22:31:24 +0100
committerMichael Williamson <mike@zwobble.org>2023-10-22 22:31:24 +0100
commit6f4afccfe077fa305d5cabe24c1a133bc8c20fcc (patch)
treeda541836a8e1a1fe258773df642238e090de97f6 /src/test/java
parentd1d0984bc8a157a2f001d3c991dae5c9498cd790 (diff)
Add proper description of function type
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/types/FunctionTypeTests.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/types/FunctionTypeTests.java b/src/test/java/org/shedlang/compiler/types/FunctionTypeTests.java
new file mode 100644
index 00000000..d182ce19
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/types/FunctionTypeTests.java
@@ -0,0 +1,90 @@
+package org.shedlang.compiler.types;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class FunctionTypeTests {
+ @Test
+ public void descriptionIncludesReturnType() {
+ var functionType = new FunctionType(
+ List.of(),
+ List.of(),
+ Effects.NONE,
+ Types.STRING
+ );
+
+ var result = functionType.describe();
+
+ assertThat(result, equalTo("fn () -> String"));
+ }
+
+ @Test
+ public void descriptionIncludesPositionalParams() {
+ var functionType = new FunctionType(
+ List.of(
+ Types.INT,
+ Types.BOOL
+ ),
+ List.of(),
+ Effects.NONE,
+ Types.STRING
+ );
+
+ var result = functionType.describe();
+
+ assertThat(result, equalTo("fn (Int, Bool) -> String"));
+ }
+
+ @Test
+ public void descriptionIncludesNamedParams() {
+ var functionType = new FunctionType(
+ List.of(),
+ List.of(
+ new NamedParam("a", Types.INT),
+ new NamedParam("b", Types.BOOL)
+ ),
+ Effects.NONE,
+ Types.STRING
+ );
+
+ var result = functionType.describe();
+
+ assertThat(result, equalTo("fn (.a: Int, .b: Bool) -> String"));
+ }
+
+ @Test
+ public void positionalParamsAndNamedParamsAreCommaSeparated() {
+ var functionType = new FunctionType(
+ List.of(
+ Types.INT
+ ),
+ List.of(
+ new NamedParam("b", Types.BOOL)
+ ),
+ Effects.NONE,
+ Types.STRING
+ );
+
+ var result = functionType.describe();
+
+ assertThat(result, equalTo("fn (Int, .b: Bool) -> String"));
+ }
+
+ @Test
+ public void descriptionIncludesEffect() {
+ var functionType = new FunctionType(
+ List.of(),
+ List.of(),
+ Effects.IO,
+ Types.STRING
+ );
+
+ var result = functionType.describe();
+
+ assertThat(result, equalTo("fn () ! Io -> String"));
+ }
+}