Skip to content

Commit 39294f3

Browse files
committed
Add generator tests
1 parent 2cac7a2 commit 39294f3

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/test/java/com/amazon/ion/bytecode/bin11/ByteArrayBytecodeGenerator11Test.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package com.amazon.ion.bytecode.bin11
44

55
import com.amazon.ion.TextToBinaryUtils.hexStringToByteArray
66
import com.amazon.ion.Timestamp
7+
import com.amazon.ion.bytecode.GeneratorTestUtil.shouldGenerate
8+
import com.amazon.ion.bytecode.ir.Instructions
9+
import com.amazon.ion.bytecode.ir.Instructions.packInstructionData
710
import com.amazon.ion.impl.bin.PrimitiveEncoder
811
import org.junit.jupiter.api.Assertions.assertArrayEquals
912
import org.junit.jupiter.api.Assertions.assertEquals
@@ -14,6 +17,39 @@ import java.nio.charset.StandardCharsets
1417

1518
internal object ByteArrayBytecodeGenerator11Test {
1619

20+
@ParameterizedTest
21+
@ValueSource(
22+
strings = [
23+
"64 4F 97 21 C5 " + // int32 -987654321
24+
"86 35 7D CB 12 2E 22 1B " + // short TS reference to 2023-10-15T11:22:33.444555-00:00
25+
"8F 0C " + // null struct
26+
"6A " + // float 0e0
27+
"6D 18 2D 44 54 FB 21 09 40 " + // float64 3.141592653589793
28+
"FE 31 49 20 61 70 70 6c 61 75 64 20 79 6f 75 72 20 63 75 72 69 6f 73 69 74 79 " + // 24-byte blob
29+
"6F " // false
30+
]
31+
)
32+
fun `generator can compile input containing multiple simple opcodes`(inputBytesString: String) {
33+
val f64pi = 3.141592653589793
34+
val expectedBytecode = intArrayOf(
35+
Instructions.I_INT_I32, -987654321,
36+
Instructions.I_SHORT_TIMESTAMP_REF.packInstructionData(0x86), 6,
37+
Instructions.I_NULL_STRUCT,
38+
Instructions.I_FLOAT_F32, 0,
39+
Instructions.I_FLOAT_F64, f64pi.toRawBits().ushr(32).and(0xFFFFFFFF).toInt(), f64pi.toRawBits().toInt(),
40+
Instructions.I_BLOB_REF.packInstructionData(24), 27,
41+
Instructions.I_BOOL.packInstructionData(0),
42+
Instructions.I_END_OF_INPUT
43+
)
44+
45+
val bytes = inputBytesString.hexStringToByteArray()
46+
val generator = ByteArrayBytecodeGenerator11(bytes, 0)
47+
generator.shouldGenerate(expectedBytecode)
48+
}
49+
50+
// TODO: add tests cases for more complicated cases like nested containers, macro compilation, annots., etc.
51+
// once those features are implemented
52+
1753
@ParameterizedTest
1854
@CsvSource(
1955
"80 35, 2023T",

src/test/java/com/amazon/ion/bytecode/bin11/bytearray/TimestampDecoderTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TimestampDecoderTest {
2727
"8A 35 7D CB EA 85 BC 01, 2023-10-15T11:22:33.444+01:15",
2828
"8B 35 7D CB EA 85 8B C8 06, 2023-10-15T11:22:33.444555+01:15",
2929
"8C 35 7D CB EA 85 92 61 7F 1A, 2023-10-15T11:22:33.444555666+01:15",
30+
// TODO: add min/max values, other extremes
3031
)
3132
fun `short timestamps are decoded correctly`(input: String, expectedValue: String) {
3233
val data = input.hexStringToByteArray()

0 commit comments

Comments
 (0)