parent
3271e24856
commit
c20ee800b8
|
@ -15,8 +15,8 @@ import static com.rusefi.ReaderState.MULT_TOKEN;
|
||||||
* 3/30/2015
|
* 3/30/2015
|
||||||
*/
|
*/
|
||||||
public class VariableRegistry {
|
public class VariableRegistry {
|
||||||
private static final String _16_HEX_SUFFIX = "_16_hex";
|
public static final String _16_HEX_SUFFIX = "_16_hex";
|
||||||
private static final String _HEX_SUFFIX = "_hex";
|
public static final String _HEX_SUFFIX = "_hex";
|
||||||
private static final String HEX_PREFIX = "0x";
|
private static final String HEX_PREFIX = "0x";
|
||||||
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
||||||
|
|
|
@ -102,6 +102,7 @@ public class ConfigFieldParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useCustomType() throws IOException {
|
public void useCustomType() throws IOException {
|
||||||
|
VariableRegistry.INSTANCE.clear();
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
String test = "struct pid_s\n" +
|
String test = "struct pid_s\n" +
|
||||||
"#define ERROR_BUFFER_SIZE 120\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" +
|
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",
|
"\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 120, FieldType.INT16);\n",
|
||||||
javaFieldsConsumer.getJavaFieldsWriter());
|
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
|
@Test
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.rusefi.test;
|
||||||
import com.rusefi.VariableRegistry;
|
import com.rusefi.VariableRegistry;
|
||||||
import org.junit.Test;
|
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;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,8 +22,8 @@ public class VariableRegistryTest {
|
||||||
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
||||||
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
||||||
// both decimal and hex values here
|
// 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 + "@@"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue