@@ -4,6 +4,9 @@ package com.amazon.ion.bytecode.bin11
44
55import com.amazon.ion.TextToBinaryUtils.hexStringToByteArray
66import 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
710import com.amazon.ion.impl.bin.PrimitiveEncoder
811import org.junit.jupiter.api.Assertions.assertArrayEquals
912import org.junit.jupiter.api.Assertions.assertEquals
@@ -14,6 +17,39 @@ import java.nio.charset.StandardCharsets
1417
1518internal 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" ,
0 commit comments