Read empty string followed by new line.

Fix #3 https://github.com/mwanji/toml4j/issues/3
This commit is contained in:
moandji.ezana 2014-07-21 13:00:35 +02:00
parent 14ec051e22
commit e36b8dbe8e
3 changed files with 14 additions and 17 deletions

View file

@ -114,7 +114,7 @@ class TomlParser extends BaseParser<Object> {
}
Rule AnyCharacter() {
return Sequence(ANY, pushCharacter(match()));
return Sequence(TestNot(NewLine()), ANY, pushCharacter(match()));
}
@SuppressNode

View file

@ -1,15 +0,0 @@
package com.moandjiezana.toml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.io.File;
public class EmptyStringTest {
@Test
public void should_parse_multiple_sections() {
Toml toml = new Toml().parse("str1 = \"\"\nstr2 = \"Hello, world!\"");
assertEquals("", toml.getString("str1"));
assertEquals("Hello, world!", toml.getString("str2"));
}
}

View file

@ -25,6 +25,18 @@ public class TomlTest {
assertEquals("a", toml.getString("a"));
}
@Test
public void should_get_empty_string() {
Toml toml = new Toml().parse("a = \"\"");
assertEquals("", toml.getString("a"));
}
@Test
public void should_get_empty_string_with_trailing_new_line() {
Toml toml = new Toml().parse("a = \"\"\n");
assertEquals("", toml.getString("a"));
}
@Test
public void should_get_number() throws Exception {
Toml toml = new Toml().parse("b = 1001");
@ -226,7 +238,7 @@ public class TomlTest {
@Test
public void should_support_unicode_characters_in_strings() throws Exception {
Toml toml = new Toml().parse("key=\"\\u00B1\"");
Toml toml = new Toml().parse("key=\"\\u00B1\"\n");
assertEquals("±", toml.getString("key"));
}