validate field name duplicates at least sometimes
This commit is contained in:
parent
0dc09447c5
commit
55a6de05ba
|
@ -2104,4 +2104,5 @@ end_struct
|
|||
#define show_test_presets true
|
||||
#define show_Frankenso_presets true
|
||||
|
||||
|
||||
! poke
|
Binary file not shown.
|
@ -1,7 +1,11 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.fathzer.soft.javaluator.Parameters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.rusefi.ConfigField.BOOLEAN_T;
|
||||
|
||||
|
@ -30,6 +34,7 @@ public class ConfigStructure {
|
|||
public final BitState readingBitState = new BitState();
|
||||
|
||||
private ConfigField cPrevField = ConfigField.VOID;
|
||||
private final Set<String> names = new HashSet<>();
|
||||
|
||||
public ConfigStructure(String name, String comment, boolean withPrefix, boolean withConstructor) {
|
||||
this.name = name;
|
||||
|
@ -82,10 +87,14 @@ public class ConfigStructure {
|
|||
}
|
||||
|
||||
public void addC(ConfigField cf) {
|
||||
// skip duplicate names
|
||||
// skip duplicate names - that's the weird use-case of conditional project definition like lambdaTable
|
||||
if (cf.getName().equals(cPrevField.getName()))
|
||||
return;
|
||||
|
||||
boolean isNew = names.add(cf.getName());
|
||||
if (!isNew)
|
||||
throw new IllegalStateException(cf.getName() + " name already used");
|
||||
|
||||
cFields.add(cf);
|
||||
|
||||
cPrevField = cf;
|
||||
|
|
|
@ -33,7 +33,6 @@ public class ReaderState {
|
|||
|
||||
public EnumsReader enumsReader = new EnumsReader();
|
||||
|
||||
|
||||
private static void handleBitLine(ReaderState state, String line) {
|
||||
line = line.substring(BIT.length() + 1).trim();
|
||||
|
||||
|
|
|
@ -48,6 +48,24 @@ public class ConfigFieldParserTest {
|
|||
"; total TS size = 8\n", new String(writer.toCharArray()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testSameFieldTwice() throws IOException {
|
||||
String test = "struct pid_s\n" +
|
||||
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"int afr_type2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||
"end_struct\n";
|
||||
ReaderState state = new ReaderState();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
||||
|
||||
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
|
||||
@Override
|
||||
public void endFile() {
|
||||
}
|
||||
};
|
||||
state.readBufferedReader(reader, Arrays.asList(consumer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEnum() throws IOException {
|
||||
String test = "struct pid_s\n" +
|
||||
|
|
Loading…
Reference in New Issue