mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 03:30:00 +00:00
Improved error message when key overwrites table
This commit is contained in:
parent
0795127266
commit
8cae6c2e32
3 changed files with 25 additions and 10 deletions
|
@ -23,12 +23,20 @@ class Results {
|
|||
}
|
||||
|
||||
public void tableDuplicatesKey(String table, AtomicInteger line) {
|
||||
sb.append("Key already exists for table definition on line ")
|
||||
sb.append("Key already exists for table defined on line ")
|
||||
.append(line.get())
|
||||
.append(": [")
|
||||
.append(table)
|
||||
.append("]\n");
|
||||
}
|
||||
|
||||
public void keyDuplicatesTable(String key, AtomicInteger line) {
|
||||
sb.append("Table already exists for key defined on line ")
|
||||
.append(line.get())
|
||||
.append(": ")
|
||||
.append(key)
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
void emptyImplicitTable(String table, int line) {
|
||||
sb.append("Invalid table definition due to empty implicit table name: ")
|
||||
|
@ -158,7 +166,11 @@ class Results {
|
|||
} else if (currentTable.accepts(key)) {
|
||||
currentTable.put(key, value);
|
||||
} else {
|
||||
errors.duplicateKey(key, line != null ? line.get() : -1);
|
||||
if (currentTable.get(key) instanceof Container) {
|
||||
errors.keyDuplicatesTable(key, line);
|
||||
} else {
|
||||
errors.duplicateKey(key, line != null ? line.get() : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,11 +236,7 @@ class Results {
|
|||
} else if (currentContainer.accepts(tablePart)) {
|
||||
startTable(tablePart, line);
|
||||
} else {
|
||||
if (currentContainer.get(tablePart) instanceof Container) {
|
||||
errors.duplicateTable(tableName, line.get());
|
||||
} else {
|
||||
errors.tableDuplicatesKey(tablePart, line);
|
||||
}
|
||||
errors.tableDuplicatesKey(tablePart, line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,9 +122,16 @@ public class ErrorMessagesTest {
|
|||
}
|
||||
|
||||
@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]");
|
||||
public void should_message_key_in_root_is_overwritten_by_table() throws Exception {
|
||||
e.expectMessage("Key already exists for table defined on line 2: [a]");
|
||||
|
||||
new Toml().parse("a=1\n [a]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_message_table_is_overwritten_by_key() throws Exception {
|
||||
e.expectMessage("Table already exists for key defined on line 3: b");
|
||||
|
||||
new Toml().parse("[a.b]\n [a]\n b=1");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ public class InlineTableTest {
|
|||
@Test
|
||||
public void should_fail_when_duplicated_by_other_key() throws Exception {
|
||||
e.expect(IllegalStateException.class);
|
||||
e.expectMessage("Duplicate key on line 2: tbl");
|
||||
e.expectMessage("Table already exists for key defined on line 2: tbl");
|
||||
|
||||
new Toml().parse("tbl = { a = 1 }\n tbl = 1");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue