Console commands are broken #1671

code generator test coverage
This commit is contained in:
rusefi 2020-08-05 19:27:23 -04:00
parent 3271e24856
commit c20ee800b8
3 changed files with 23 additions and 4 deletions

View File

@ -15,8 +15,8 @@ import static com.rusefi.ReaderState.MULT_TOKEN;
* 3/30/2015
*/
public class VariableRegistry {
private static final String _16_HEX_SUFFIX = "_16_hex";
private static final String _HEX_SUFFIX = "_hex";
public static final String _16_HEX_SUFFIX = "_16_hex";
public static final String _HEX_SUFFIX = "_hex";
private static final String HEX_PREFIX = "0x";
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
public static final VariableRegistry INSTANCE = new VariableRegistry();

View File

@ -102,6 +102,7 @@ public class ConfigFieldParserTest {
@Test
public void useCustomType() throws IOException {
VariableRegistry.INSTANCE.clear();
ReaderState state = new ReaderState();
String test = "struct pid_s\n" +
"#define ERROR_BUFFER_SIZE 120\n" +
@ -118,7 +119,23 @@ public class ConfigFieldParserTest {
assertEquals("\tpublic static final Field VAR = Field.create(\"VAR\", 0, 120, FieldType.STRING);\n" +
"\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 120, FieldType.INT16);\n",
javaFieldsConsumer.getJavaFieldsWriter());
}
@Test
public void testDefineChar() throws IOException {
VariableRegistry.INSTANCE.clear();
ReaderState state = new ReaderState();
String test =
"#define SD_r 'r'\n" +
"";
BufferedReader reader = new BufferedReader(new StringReader(test));
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer));
assertEquals("\tpublic static final char SD_r = 'r';\n" +
"",
VariableRegistry.INSTANCE.getJavaConstants());
}
@Test

View File

@ -3,6 +3,8 @@ package com.rusefi.test;
import com.rusefi.VariableRegistry;
import org.junit.Test;
import static com.rusefi.VariableRegistry._16_HEX_SUFFIX;
import static com.rusefi.VariableRegistry._HEX_SUFFIX;
import static org.junit.Assert.assertEquals;
/**
@ -20,8 +22,8 @@ public class VariableRegistryTest {
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
// both decimal and hex values here
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var" + _HEX_SUFFIX + "@@fff"));
assertEquals("\\x01\\x00", VariableRegistry.INSTANCE.applyVariables("@@var_16_hex@@"));
assertEquals("\\x01\\x00", VariableRegistry.INSTANCE.applyVariables("@@var" + _16_HEX_SUFFIX + "@@"));
}
}