mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 11:40:27 +00:00
Improved float handling
This commit is contained in:
parent
922408e979
commit
155781b5e2
5 changed files with 36 additions and 2 deletions
|
@ -15,7 +15,7 @@ class ValueAnalysis {
|
|||
private static final List<Object> INVALID_ARRAY = new ArrayList<Object>();
|
||||
|
||||
private static final Pattern BOOLEAN_REGEX = Pattern.compile("(true|false)(.*)");
|
||||
private static final Pattern FLOAT_REGEX = Pattern.compile("(-?[0-9\\.]*)(.*)");
|
||||
private static final Pattern FLOAT_REGEX = Pattern.compile("(-?\\d+\\.\\d+)(.*)");
|
||||
private static final Pattern INTEGER_REGEX = Pattern.compile("(-?[0-9]*)(.*)");
|
||||
private static final Pattern DATE_REGEX = Pattern.compile("(\\d{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z)(.*)");
|
||||
private static final Pattern UNICODE_REGEX = Pattern.compile("\\\\u(.*)");
|
||||
|
|
|
@ -149,6 +149,16 @@ public class BurntSushiTest {
|
|||
public void datetime_malformed_no_leads() throws Exception {
|
||||
runInvalidTest("datetime-malformed-no-leads");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void float_no_leading_zero() throws Exception {
|
||||
runInvalidTest("float-no-leading-zero");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void float_no_trailing_digits() throws Exception {
|
||||
runInvalidTest("float-no-trailing-digits");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws IOException {
|
||||
|
|
|
@ -347,12 +347,32 @@ public class TomlTest {
|
|||
public void should_fail_when_illegal_characters_after_table() throws Exception {
|
||||
new Toml().parse("[error] if you didn't catch this, your parser is broken");
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void should_fail_when_illegal_characters_after_key() throws Exception {
|
||||
new Toml().parse("number = 3.14 pi");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void should_fail_on_float_without_leading_0() {
|
||||
new Toml().parse("answer = .12345");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void should_fail_on_negative_float_without_leading_0() {
|
||||
new Toml().parse("answer = -.12345");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void should_fail_on_float_without_digits_after_dot() {
|
||||
new Toml().parse("answer = 1.");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void should_fail_on_negative_float_without_digits_after_dot() {
|
||||
new Toml().parse("answer = -1.");
|
||||
}
|
||||
|
||||
private File file(String file) {
|
||||
return new File(getClass().getResource(file + ".toml").getFile());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
answer = .12345
|
||||
neganswer = -.12345
|
|
@ -0,0 +1,2 @@
|
|||
answer = 1.
|
||||
neganswer = -1.
|
Loading…
Reference in a new issue