New error message when table overwrites existing key definition

This commit is contained in:
moandji.ezana 2015-04-13 13:04:10 +02:00
parent 1a6ddbd5ac
commit 0795127266
2 changed files with 20 additions and 1 deletions

View file

@ -21,6 +21,14 @@ class Results {
.append(table)
.append("]\n");
}
public void tableDuplicatesKey(String table, AtomicInteger line) {
sb.append("Key already exists for table definition on line ")
.append(line.get())
.append(": [")
.append(table)
.append("]\n");
}
void emptyImplicitTable(String table, int line) {
sb.append("Invalid table definition due to empty implicit table name: ")
@ -216,7 +224,11 @@ class Results {
} else if (currentContainer.accepts(tablePart)) {
startTable(tablePart, line);
} else {
errors.duplicateTable(tableName, -1);
if (currentContainer.get(tablePart) instanceof Container) {
errors.duplicateTable(tableName, line.get());
} else {
errors.tableDuplicatesKey(tablePart, line);
}
break;
}
}

View file

@ -120,4 +120,11 @@ public class ErrorMessagesTest {
new Toml().parse("k = [ 1,\n 1.1 ]");
}
@Test
public void should_fail_when_key_itn_root_is_overwritten_by_table() throws Exception {
e.expectMessage("Key already exists for table definition on line 2: [a]");
new Toml().parse("a=1\n [a]");
}
}