Config generation handles padding after packed booleans (bits) wrong #1057

everything should start with a unit test
This commit is contained in:
rusefi 2019-12-14 14:46:20 -05:00
parent 1ab4bfc16f
commit d6780909f5
2 changed files with 42 additions and 0 deletions

View File

@ -46,6 +46,8 @@ public class ReaderState {
}
ConfigField bitField = new ConfigField(state, bitName, comment, null, BOOLEAN_T, 0, null, false, false, null, -1);
if (state.stack.isEmpty())
throw new IllegalStateException("Parent structure expected");
state.stack.peek().addBoth(bitField);
}

View File

@ -0,0 +1,40 @@
package com.rusefi.test;
import com.rusefi.ReaderState;
import com.rusefi.output.JavaFieldsConsumer;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
public class ConfigFieldParserIssue1057Test {
@Test
public void testBitsPadding() throws IOException {
ReaderState state = new ReaderState();
JavaFieldsConsumer javaFieldsConsumer = new JavaFieldsConsumer(state) {
@Override
public void startFile() {
}
@Override
public void endFile() {
}
};
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +
"int fieldName;\n" +
"end_struct\n";
BufferedReader reader = new BufferedReader(new StringReader(inputString));
state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer));
assertEquals("\tpublic static final Field ACTIVATEAUXPID1 = Field.create(\"ACTIVATEAUXPID1\", 0, FieldType.BIT, 0);\n" +
"\tpublic static final Field FIELDNAME = Field.create(\"FIELDNAME\", 4, FieldType.INT);\n",
javaFieldsConsumer.getJavaFieldsWriter());
}
}