2015-01-22 12:39:08 +00:00
|
|
|
package com.moandjiezana.toml;
|
|
|
|
|
2015-01-25 12:31:17 +00:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2015-01-22 12:39:08 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class BareKeysTest {
|
|
|
|
|
2015-01-25 12:31:17 +00:00
|
|
|
@Test
|
|
|
|
public void should_ignore_spaces_around_key_segments() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
Toml toml = new Toml().read("[ a . b . c ] \n key = \"a\"");
|
2015-01-25 12:31:17 +00:00
|
|
|
|
|
|
|
assertEquals("a", toml.getString("a.b.c.key"));
|
|
|
|
}
|
2015-01-22 12:39:08 +00:00
|
|
|
|
2015-02-12 09:21:00 +00:00
|
|
|
@Test
|
|
|
|
public void should_support_underscores_in_key_names() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
Toml toml = new Toml().read("a_a = 1");
|
2015-02-12 09:21:00 +00:00
|
|
|
|
|
|
|
assertEquals(1, toml.getLong("a_a").intValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void should_support_underscores_in_table_names() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
Toml toml = new Toml().read("[group_a]\na = 1");
|
2015-02-12 09:21:00 +00:00
|
|
|
|
|
|
|
assertEquals(1, toml.getLong("group_a.a").intValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void should_support_numbers_in_key_names() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
Toml toml = new Toml().read("a1 = 1");
|
2015-02-12 09:21:00 +00:00
|
|
|
|
|
|
|
assertEquals(1, toml.getLong("a1").intValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void should_support_numbers_in_table_names() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
Toml toml = new Toml().read("[group1]\na = 1");
|
2015-02-12 09:21:00 +00:00
|
|
|
|
|
|
|
assertEquals(1, toml.getLong("group1.a").intValue());
|
|
|
|
}
|
|
|
|
|
2015-02-09 14:29:20 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
2015-01-23 13:17:50 +00:00
|
|
|
public void should_fail_when_characters_outside_accept_range_are_used_in_table_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[~]");
|
2015-01-22 12:39:08 +00:00
|
|
|
}
|
2015-02-12 20:38:17 +00:00
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_when_characters_outside_accept_range_are_used_in_table_array_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[~]]");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
2015-02-12 09:21:00 +00:00
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_when_dots_in_key_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("a.b = 1");
|
2015-02-12 09:21:00 +00:00
|
|
|
}
|
2015-01-22 12:39:08 +00:00
|
|
|
|
2015-02-09 14:29:20 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
2015-01-23 13:17:50 +00:00
|
|
|
public void should_fail_when_characters_outside_accept_range_are_used_in_key_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("~ = 1");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 14:29:20 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
2015-01-23 13:17:50 +00:00
|
|
|
public void should_fail_on_sharp_sign_in_table_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[group#]\nkey=1");
|
2015-01-22 12:39:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 14:29:20 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
2015-01-23 13:17:50 +00:00
|
|
|
public void should_fail_on_spaces_in_table_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[valid key]");
|
2015-01-22 12:39:08 +00:00
|
|
|
}
|
2015-01-23 13:17:50 +00:00
|
|
|
|
2015-02-12 20:38:17 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_sharp_sign_in_table_array_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[group#]]\nkey=1");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_spaces_in_table_array_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[valid key]]");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 13:17:50 +00:00
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_question_marks_in_key_name() throws Exception {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("key?=true");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[]");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_name_ending_with_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[a.]");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_name_containing_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[a..b]");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_name_starting_with_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[.b]");
|
2015-01-23 13:17:50 +00:00
|
|
|
}
|
2015-02-12 20:38:17 +00:00
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_array_name_ending_with_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[a.]]");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_array_name_containing_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[a..b]]");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void should_fail_on_nested_table_array_name_starting_with_empty_table_name() {
|
2015-08-14 09:12:08 +00:00
|
|
|
new Toml().read("[[.b]]");
|
2015-02-12 20:38:17 +00:00
|
|
|
}
|
2015-01-22 12:39:08 +00:00
|
|
|
}
|