• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revisionec665ba07999e79e65f7a5c0dcde922ecd2e616d (tree)
Time2020-10-11 21:04:40
Authormiyakawataku
Commitermiyakawataku

Log Message

add CallStackSlice

Change Summary

Incremental Difference

diff -r 6208b8d17482 -r ec665ba07999 src/main/java/org/kink_lang/kink/internal/callstack/CallStackSlice.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/kink_lang/kink/internal/callstack/CallStackSlice.java Sun Oct 11 21:04:40 2020 +0900
@@ -0,0 +1,60 @@
1+package org.kink_lang.kink.internal.callstack;
2+
3+import java.util.Arrays;
4+import java.util.List;
5+import java.util.Locale;
6+
7+/**
8+ * Slice of call stack.
9+ */
10+public final class CallStackSlice {
11+
12+ /** Call stack elements of the slice. */
13+ private final Cse[] cses;
14+
15+ /**
16+ * Constructs a slice.
17+ *
18+ * @param cses call stack elements of the slice.
19+ */
20+ public CallStackSlice(Cse[] cses) {
21+ this.cses = cses;
22+ }
23+
24+ /**
25+ * Retunrs the call stack elements of the slice.
26+ *
27+ * @return the call stack elements of the slice.
28+ */
29+ public Cse[] getCallStackElements() {
30+ return this.cses;
31+ }
32+
33+ @Override
34+ public String toString() {
35+ return String.format(Locale.ROOT, "CallStackSlice(%s)",
36+ Arrays.asList(cses).toString());
37+ }
38+
39+ /**
40+ * Returns the equality properties of the slice.
41+ */
42+ private List<Object> getProperties() {
43+ return List.of(Arrays.asList(cses));
44+ }
45+
46+ @Override
47+ public int hashCode() {
48+ return getProperties().hashCode();
49+ }
50+
51+ @Override
52+ public boolean equals(Object arg) {
53+ return arg == this
54+ || arg instanceof CallStackSlice
55+ && getProperties().equals(((CallStackSlice) arg).getProperties());
56+ }
57+
58+}
59+
60+// vim: et sw=4 sts=4 fdm=marker
diff -r 6208b8d17482 -r ec665ba07999 src/test/java/org/kink_lang/kink/internal/callstack/CallStackSliceTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/org/kink_lang/kink/internal/callstack/CallStackSliceTest.java Sun Oct 11 21:04:40 2020 +0900
@@ -0,0 +1,47 @@
1+package org.kink_lang.kink.internal.callstack;
2+
3+import org.junit.jupiter.api.AfterAll;
4+import org.junit.jupiter.api.Test;
5+
6+import static org.assertj.core.api.Assertions.assertThat;
7+
8+import org.kink_lang.kink.Vm;
9+import org.kink_lang.kink.internal.test.EqualityVerifier;
10+
11+public class CallStackSliceTest {
12+
13+ private static Vm vm = Vm.newVm();
14+
15+ @AfterAll
16+ public static void nullifyVm() {
17+ CallStackSliceTest.vm = null;
18+ }
19+
20+ @Test
21+ public void test_getCallStackSliceElements() {
22+ Cse[] cses = new Cse[] { new ResetFrame("foo"), new ResetFrame("bar") };
23+ CallStackSlice css = new CallStackSlice(cses);
24+ assertThat(css.getCallStackElements()).isSameAs(cses);
25+ }
26+
27+ @Test
28+ public void test_toString() {
29+ Cse[] cses = new Cse[] { new ResetFrame("foo"), new ResetFrame("bar") };
30+ CallStackSlice css = new CallStackSlice(cses);
31+ assertThat(css.toString()).isEqualTo("CallStackSlice([ResetFrame(foo), ResetFrame(bar)])");
32+ }
33+
34+ @Test
35+ public void test_equality() {
36+ Cse[] fooBar1 = new Cse[] { new ResetFrame("foo"), new ResetFrame("bar") };
37+ Cse[] fooBar2 = new Cse[] { new ResetFrame("foo"), new ResetFrame("bar") };
38+ Cse[] baz = new Cse[] { new ResetFrame("baz") };
39+ EqualityVerifier ev = new EqualityVerifier();
40+ ev.group("[foo bar]", new CallStackSlice(fooBar1), new CallStackSlice(fooBar2));
41+ ev.group("[baz]", new CallStackSlice(baz));
42+ ev.verify();
43+ }
44+
45+}
46+
47+// vim: et sw=4 sts=4 fdm=marker
Show on old repository browser