From 16c8b409e6091932c40fd7a452de048dfa6aaae0 Mon Sep 17 00:00:00 2001 From: "moandji.ezana" Date: Fri, 10 Oct 2014 11:45:22 +0200 Subject: [PATCH] Added test to confirm that out-of-order table arrays are supported. cf. https://github.com/toml-lang/toml/issues/252 --- .../com/moandjiezana/toml/TableArrayTest.java | 17 +++++++++++++++++ .../should_parse_table_array_out_of_order.toml | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/test/java/com/moandjiezana/toml/should_parse_table_array_out_of_order.toml diff --git a/src/test/java/com/moandjiezana/toml/TableArrayTest.java b/src/test/java/com/moandjiezana/toml/TableArrayTest.java index 095e17c..b41a6ca 100644 --- a/src/test/java/com/moandjiezana/toml/TableArrayTest.java +++ b/src/test/java/com/moandjiezana/toml/TableArrayTest.java @@ -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 tables = toml.getTables("product"); + List 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 { diff --git a/src/test/java/com/moandjiezana/toml/should_parse_table_array_out_of_order.toml b/src/test/java/com/moandjiezana/toml/should_parse_table_array_out_of_order.toml new file mode 100644 index 0000000..7688f6b --- /dev/null +++ b/src/test/java/com/moandjiezana/toml/should_parse_table_array_out_of_order.toml @@ -0,0 +1,8 @@ +[[product]] +price = 9.99 + +[[employee]] +name = "Marinus van der Lubbe" + +[[product]] +type = "ZX80"