summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjculkin <bjculkin@localhost>2023-10-25 23:00:44 +0000
committerbjculkin <bjculkin@localhost>2023-10-25 23:00:44 +0000
commitcbf4dda5cc09dc6d2c3c10329e7941923cc04e2e (patch)
tree87d199f6b7eb45046ddb2489c6b8d85d846cab6c
parent0f958b08b3446a866418aa485bb60c208d952033 (diff)
Tweak for new setup
Also, add some tests for Context
-rw-r--r--.classpath15
-rw-r--r--.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--pom.xml4
-rw-r--r--src/main/java/bjc/data/Contexts.java17
-rw-r--r--src/main/java/bjc/typeclasses/FunList.java2
-rw-r--r--src/main/java/module-info.java1
-rw-r--r--src/test/java/bjc/test/TestUtils.java20
-rw-r--r--src/test/java/bjc/test/data/ContextsTest.java64
8 files changed, 122 insertions, 7 deletions
diff --git a/.classpath b/.classpath
index 595e52c..314d6f1 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/example/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@@ -24,5 +24,18 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="data">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="optional" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="test" value="true"/>
+ <attribute name="optional" value="true"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index cf2cd45..2af1e7b 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
-org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=17
+org.eclipse.jdt.core.compiler.source=11
diff --git a/pom.xml b/pom.xml
index b190388..662d5d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,8 +24,8 @@
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
</properties>
diff --git a/src/main/java/bjc/data/Contexts.java b/src/main/java/bjc/data/Contexts.java
index 699a450..7de1b5f 100644
--- a/src/main/java/bjc/data/Contexts.java
+++ b/src/main/java/bjc/data/Contexts.java
@@ -117,4 +117,21 @@ class ContextImpl implements Context {
public Context getParent() {
return parent;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(objects, parent);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ContextImpl other = (ContextImpl) obj;
+ return Objects.equals(objects, other.objects) && Objects.equals(parent, other.parent);
+ }
} \ No newline at end of file
diff --git a/src/main/java/bjc/typeclasses/FunList.java b/src/main/java/bjc/typeclasses/FunList.java
index cd16c82..555b2c7 100644
--- a/src/main/java/bjc/typeclasses/FunList.java
+++ b/src/main/java/bjc/typeclasses/FunList.java
@@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
-public sealed interface FunList<A, B> permits FunList.Done<A, B>, FunList.More<A, B> {
+public /*sealed*/ interface FunList<A, B> /*permits FunList.Done<A, B>, FunList.More<A, B>*/ {
public final class Done<A, B> implements FunList<A, B> {
private final B val;
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index edae185..227f9b3 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -28,4 +28,5 @@ module esodata {
exports bjc.funcdata.bst;
exports bjc.funcdata.theory;
exports bjc.funcdata;
+ exports bjc.typeclasses;
} \ No newline at end of file
diff --git a/src/test/java/bjc/test/TestUtils.java b/src/test/java/bjc/test/TestUtils.java
index 04cdf70..664aaef 100644
--- a/src/test/java/bjc/test/TestUtils.java
+++ b/src/test/java/bjc/test/TestUtils.java
@@ -144,4 +144,24 @@ public class TestUtils {
public static <T> void assertStackEquals(bjc.esodata.Stack<T> src, T... exps) {
assertArrayEquals(exps, src.toArray());
}
+
+ public static <T> void assertOneOf(T actual, T... expecteds) {
+ for (T expected : expecteds) {
+ if (expected.equals(actual)) return;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("Value '");
+ builder.append(actual.toString());
+ builder.append("' was not one of the expected values: ");
+ for (T expected : expecteds) {
+ builder.append("'");
+ builder.append(expected.toString());
+ builder.append("', ");
+ }
+ builder.deleteCharAt(builder.length() - 1);
+ builder.deleteCharAt(builder.length() - 1);
+
+ assertFalse("Value '%' was no", true);
+ }
}
diff --git a/src/test/java/bjc/test/data/ContextsTest.java b/src/test/java/bjc/test/data/ContextsTest.java
new file mode 100644
index 0000000..cff6e06
--- /dev/null
+++ b/src/test/java/bjc/test/data/ContextsTest.java
@@ -0,0 +1,64 @@
+package bjc.test.data;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import bjc.data.Context;
+import bjc.data.Contexts;
+import bjc.test.TestUtils;
+
+public class ContextsTest {
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testNull() {
+ Context ctx = Contexts.NULL;
+ ctx.register("a", "b");
+ }
+ @Test
+ public void testCreate() {
+ Context ctx = Contexts.create();
+
+ assertTrue(ctx.getParent() == Contexts.NULL);
+
+ ctx.register("a", "b");
+
+ assertEquals("b", ctx.get("a"));
+ assertEquals("b", ctx.get(String.class));
+ assertEquals("b", ctx.get("a", String.class));
+ }
+
+ @Test
+ public void testCreateContext() {
+ Context parent = Contexts.create();
+
+ assertTrue(parent.getParent() == Contexts.NULL);
+
+ parent.register("a", "1");
+
+ Context child1 = Contexts.create(parent);
+ Context child2 = Contexts.create(parent);
+
+ Context child11 = Contexts.create(child1);
+ Context child22 = Contexts.create(child2);
+
+ child1.register("b", "2");
+ child1.register("c", "3");
+
+ child2.register("d", "4");
+ child2.register("e", "5");
+
+ child11.register("a", "6");
+
+ child22.register("a", "7");
+ child22.register("f", "8");
+
+ assertEquals("2", child1.get("b"));
+ assertEquals("1", child1.get("a"));
+ assertEquals("6", child11.get("a"));
+ assertEquals("7", child22.get("a"));
+
+ TestUtils.assertOneOf(child1.get(String.class), "1", "2", "3");
+ }
+
+}