summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java
index 0110de3..a482612 100644
--- a/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java
+++ b/examples/11-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java
@@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -194,37 +195,44 @@ public class Transient0Tests {
@Test
public void structWithShared() throws IOException {
- var value = new StructWithShared(List.of(
- new StructWithInt32(10, 25)
- ));
+ var a = new StructWithInt32(10, 25);
+ var b = new StructWithInt32(42, 47);
- assertRoundTripEncoding(
+ var value = new StructWithShared(List.of(a, a, b, a, b));
+
+ var decodedValue = assertRoundTripEncoding(
value,
HobgoblinTransient0Data::encodeStructWithShared,
HobgoblinTransient0Data::decodeStructWithShared
);
+ Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(1));
+ Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(3));
+ Assertions.assertSame(decodedValue.inner().get(2), decodedValue.inner().get(4));
}
- private <T> void assertRoundTripEncoding(
+ private <T> T assertRoundTripEncoding(
T value,
Encoder<T> encoder,
Decoder<T> decoder
) throws IOException {
var outputStream = new ByteArrayOutputStream();
+ // TODO: should this use IdentityHashMap? Leave it up the caller?
encoder.encode(value, outputStream, new HashMap<>());
var bytes = outputStream.toByteArray();
var inputStream = new ByteArrayInputStream(bytes);
- var decodedValue = decoder.decode(inputStream, new HashMap<>());
+ var decodedValue = decoder.decode(inputStream, new ArrayList<>());
Assertions.assertEquals(value, decodedValue);
+
+ return decodedValue;
}
private interface Encoder<T> {
- void encode(T value, OutputStream outputStream, Map<String, Object> sharedValues) throws IOException;
+ void encode(T value, OutputStream outputStream, Map<Object, Long> sharedValues) throws IOException;
}
private interface Decoder<T> {
- T decode(InputStream inputStream, Map<String, Object> sharedValues) throws IOException;
+ T decode(InputStream inputStream, List<Object> sharedValues) throws IOException;
}
}