Added test to confirm that out-of-order table arrays are supported.

cf. https://github.com/toml-lang/toml/issues/252
This commit is contained in:
moandji.ezana 2014-10-10 11:45:22 +02:00
parent ccca314649
commit 16c8b409e6
2 changed files with 25 additions and 0 deletions

View file

@ -1,7 +1,10 @@
package com.moandjiezana.toml;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.List;
@ -29,6 +32,20 @@ public class TableArrayTest {
assertEquals(284758393L, products.get(2).getLong("sku").longValue());
assertEquals("gray", products.get(2).getString("color"));
}
@Test
public void should_parse_table_array_out_of_order() throws Exception {
Toml toml = new Toml().parse(file("should_parse_table_array_out_of_order"));
List<Toml> tables = toml.getTables("product");
List<Toml> employees = toml.getTables("employee");
assertThat(tables, hasSize(2));
assertThat(tables.get(0).getDouble("price"), equalTo(9.99));
assertThat(tables.get(1).getString("type"), equalTo("ZX80"));
assertThat(employees, hasSize(1));
assertThat(employees.get(0).getString("name"), equalTo("Marinus van der Lubbe"));
}
@Test
public void should_parse_nested_table_arrays() throws Exception {

View file

@ -0,0 +1,8 @@
[[product]]
price = 9.99
[[employee]]
name = "Marinus van der Lubbe"
[[product]]
type = "ZX80"