mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 11:40:27 +00:00
New error message when table overwrites existing key definition
This commit is contained in:
parent
1a6ddbd5ac
commit
0795127266
2 changed files with 20 additions and 1 deletions
|
@ -21,6 +21,14 @@ class Results {
|
||||||
.append(table)
|
.append(table)
|
||||||
.append("]\n");
|
.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) {
|
void emptyImplicitTable(String table, int line) {
|
||||||
sb.append("Invalid table definition due to empty implicit table name: ")
|
sb.append("Invalid table definition due to empty implicit table name: ")
|
||||||
|
@ -216,7 +224,11 @@ class Results {
|
||||||
} else if (currentContainer.accepts(tablePart)) {
|
} else if (currentContainer.accepts(tablePart)) {
|
||||||
startTable(tablePart, line);
|
startTable(tablePart, line);
|
||||||
} else {
|
} else {
|
||||||
errors.duplicateTable(tableName, -1);
|
if (currentContainer.get(tablePart) instanceof Container) {
|
||||||
|
errors.duplicateTable(tableName, line.get());
|
||||||
|
} else {
|
||||||
|
errors.tableDuplicatesKey(tablePart, line);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,4 +120,11 @@ public class ErrorMessagesTest {
|
||||||
|
|
||||||
new Toml().parse("k = [ 1,\n 1.1 ]");
|
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]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue