Skip to content

Commit 64919a7

Browse files
committed
added test
1 parent d0703e5 commit 64919a7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/java/com/igormaznitsa/jbbp/JBBPParserTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,27 @@ public JBBPAbstractField readVarField(final JBBPBitInputStream inStream, final J
353353
assertEquals(0x22, parsed.findFieldForNameAndType("b", JBBPFieldUByte.class).getAsInt());
354354
}
355355

356+
@Test
357+
public void testParse_VarArray_ExtraNumericFieldAsExpression() throws Exception {
358+
final JBBPParser parser = JBBPParser.prepare("ubyte s; ubyte a; var:(a/21) [s*2] vvv; ubyte b;");
359+
final JBBPFieldStruct parsed = parser.parse(new byte[]{4, (byte) 123, 0x12, 0x34, 0x11, 0x22, 0x56}, new JBBPVarFieldProcessor() {
360+
361+
public JBBPAbstractArrayField<? extends JBBPAbstractField> readVarArray(JBBPBitInputStream inStream, int arraySize, JBBPNamedFieldInfo fieldName, int extraValue, JBBPByteOrder byteOrder, JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
362+
inStream.skip(3);
363+
assertEquals(123 / 21, extraValue);
364+
assertEquals(8, arraySize);
365+
return new JBBPFieldArrayByte(fieldName, new byte[]{1,2,3,4,5,6,7,8});
366+
}
367+
368+
public JBBPAbstractField readVarField(final JBBPBitInputStream inStream, final JBBPNamedFieldInfo fieldName, final int extraValue, final JBBPByteOrder byteOrder, JBBPNamedNumericFieldMap numericFieldMap) throws IOException {
369+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
370+
}
371+
}, null);
372+
assertEquals(123, parsed.findFieldForNameAndType("a", JBBPFieldUByte.class).getAsInt());
373+
assertArrayEquals(new byte[]{1,2,3,4,5,6,7,8}, parsed.findFieldForNameAndType("vvv", JBBPFieldArrayByte.class).getArray());
374+
assertEquals(0x22, parsed.findFieldForNameAndType("b", JBBPFieldUByte.class).getAsInt());
375+
}
376+
356377
@Test
357378
public void testParse_NamedVarWithCustomOrder() throws Exception {
358379
final JBBPParser parser = JBBPParser.prepare("short k; <var:-12345 Some; int;");

0 commit comments

Comments
 (0)