unit test coverage for conditional structure
This commit is contained in:
parent
905760e84e
commit
64354e1d79
|
@ -39,7 +39,7 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
// skip duplicate names
|
||||
// skip duplicate names which happens in case of conditional compilation
|
||||
if (iterator.cf.getName().equals(iterator.prev.getName()) || iterator.cf.isDirective())
|
||||
continue;
|
||||
tsPosition = writeOneField(iterator.cf, prefix, tsPosition, iterator.next, iterator.bitState.get());
|
||||
|
|
|
@ -111,6 +111,7 @@ public class TsOutput {
|
|||
iterator.start(i);
|
||||
|
||||
// if duplicate names, use previous position
|
||||
// we can have same member twice in the
|
||||
if (iterator.cf.getName().equals(iterator.prev.getName())) {
|
||||
tsPosition = prevTsPosition;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -22,7 +23,7 @@ public class ConfigFieldParserIssue1057Test {
|
|||
"end_struct\n";
|
||||
|
||||
|
||||
state.readBufferedReader(inputString, Arrays.asList(javaFieldsConsumer));
|
||||
state.readBufferedReader(inputString, Collections.singletonList(javaFieldsConsumer));
|
||||
|
||||
assertEquals("\tpublic static final Field ACTIVATEAUXPID1 = Field.create(\"ACTIVATEAUXPID1\", 0, FieldType.BIT, 0);\n" +
|
||||
"\tpublic static final Field UNUSEDBIT_1_1 = Field.create(\"UNUSEDBIT_1_1\", 0, FieldType.BIT, 1);\n" +
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import com.rusefi.output.TSProjectConsumer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TSProjectConsumerTest {
|
||||
|
@ -15,4 +21,49 @@ public class TSProjectConsumerTest {
|
|||
assertEquals("12", TSProjectConsumer.removeToken("1@@if_ts 2"));
|
||||
assertEquals("H2\r\n", TSProjectConsumer.removeToken("H@@if_ts 2\r\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalField() throws IOException {
|
||||
String test = "struct pid_s\n" +
|
||||
"custom afr_table_t 4x4 array, U08, @OFFSET@, [4x4],\"deg\",\t {1/10}, 0, 0, 25.0, 1 \n" +
|
||||
"#if LAMBDA\n" +
|
||||
"\tint16_t periodMs2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"#else\n" +
|
||||
"\tint16_t periodMs2;PID dTime;\"ms2\", 1, 0, 0, 3000, 0\n" +
|
||||
"#endif\n" +
|
||||
"#if LAMBDA\n" +
|
||||
"afr_table_t afrTable;\t\t\n" +
|
||||
"#else\n" +
|
||||
"afr_table_t afrTable;\t\t\n" +
|
||||
"#endif\n" +
|
||||
"\tint16_t periodMs;PID dTime;\"ms\", {1/10}, 0, 0, 3000, 0\n" +
|
||||
"end_struct\n" +
|
||||
"";
|
||||
|
||||
CharArrayWriter writer = new CharArrayWriter();
|
||||
ReaderState state = new ReaderState();
|
||||
TSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer(writer, "", state);
|
||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||
|
||||
state.readBufferedReader(test, Arrays.asList(javaFieldsConsumer, tsProjectConsumer));
|
||||
|
||||
assertEquals("#if LAMBDA\n" +
|
||||
"periodMs2 = scalar, S16, 0, \"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"#else\n" +
|
||||
"periodMs2 = scalar, S16, 0, \"ms2\", 1, 0, 0, 3000, 0\n" +
|
||||
"#endif\n" +
|
||||
"#if LAMBDA\n" +
|
||||
"afrTable = array, U08, 2, [4x4],\"deg\", 0.1, 0, 0, 25.0, 1\n" +
|
||||
"#else\n" +
|
||||
"afrTable = array, U08, 2, [4x4],\"deg\", 0.1, 0, 0, 25.0, 1\n" +
|
||||
"#endif\n" +
|
||||
"periodMs = scalar, S16, 18, \"ms\", 0.1, 0, 0, 3000, 0\n" +
|
||||
"; total TS size = 20\n", new String(writer.toCharArray()));
|
||||
|
||||
assertEquals("\tpublic static final Field PERIODMS2 = Field.create(\"PERIODMS2\", 0, FieldType.INT16);\n" +
|
||||
"\tpublic static final Field AFRTABLE = Field.create(\"AFRTABLE\", 2, FieldType.INT);\n" +
|
||||
"\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 18, FieldType.INT16);\n",
|
||||
javaFieldsConsumer.getJavaFieldsWriter());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue