Skip to content

Commit

Permalink
style: make hint messages clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
ToruNiina committed Jun 19, 2019
1 parent 53a185e commit dee32e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -150,13 +150,13 @@ the malformed files in [the language agnostic test suite](https://github.com/Bur
is shown below.

```console
what(): [error] bad time: should be HH:MM:SS.subsec
what(): [error] bad time: should be HH:MM:SS.subsec
--> ./datetime-malformed-no-secs.toml
1 | no-secs = 1987-07-05T17:45Z
| ^------- HH:MM:SS.subsec
|
Hint: OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999
Hint: NG: 1979-05-27T7:32:00, 1979-05-27 7:32
|
Hint: pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999
Hint: fail: 1979-05-27T7:32:00, 1979-05-27 17:32
```

You can find other examples in a job named `output_result` on
Expand Down
42 changes: 21 additions & 21 deletions toml/parser.hpp
Expand Up @@ -1431,7 +1431,7 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{
return err(format_underline("[error] bad offset: should be [+-]HH:MM or Z",
{{std::addressof(loc), "[+-]HH:MM or Z"}},
{"OK: +09:00, -05:30", "NG: +9:00, -5:30"}));
{"pass: +09:00, -05:30", "fail: +9:00, -5:30"}));
}
return ok(value_t::LocalDatetime);
}
Expand All @@ -1451,24 +1451,24 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{
return err(format_underline("[error] bad time: should be HH:MM:SS.subsec",
{{std::addressof(loc), "HH:MM:SS.subsec"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
{"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"fail: 1979-05-27T7:32:00, 1979-05-27 17:32"}));
}
if('0' <= c && c <= '9')
{
return err(format_underline("[error] bad time: missing T",
{{std::addressof(loc), "T or space required here"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
{"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"fail: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
}
if(c == ' ' && std::next(loc.iter()) != loc.end() &&
('0' <= *std::next(loc.iter()) && *std::next(loc.iter())<= '9'))
{
loc.advance();
return err(format_underline("[error] bad time: should be HH:MM:SS.subsec",
{{std::addressof(loc), "HH:MM:SS.subsec"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
{"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"fail: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
}
}
return ok(value_t::LocalDate);
Expand All @@ -1484,8 +1484,8 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{
return err(format_underline("[error] bad float: `_` should be surrounded by digits",
{{std::addressof(loc), "here"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
{"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
}
return ok(value_t::Float);
}
Expand All @@ -1500,31 +1500,31 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{
return err(format_underline("[error] bad integer: `_` should be surrounded by digits",
{{std::addressof(loc), "here"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"}));
{"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"fail: 1__000, 0123"}));
}
if('0' <= c && c <= '9')
{
// leading zero. point '0'
loc.retrace();
return err(format_underline("[error] bad integer: leading zero",
{{std::addressof(loc), "here"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"}));
{"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"fail: 1__000, 0123"}));
}
if(c == ':' || c == '-')
{
return err(format_underline("[error] bad datetime: invalid format",
{{std::addressof(loc), "here"}},
{"OK: 1979-05-27T07:32:00-07:00, 1979-05-27 07:32:00.999999Z",
"NG: 1979-05-27T7:32:00-7:00, 1979-05-27 7:32-00:30"}));
{"pass: 1979-05-27T07:32:00-07:00, 1979-05-27 07:32:00.999999Z",
"fail: 1979-05-27T7:32:00-7:00, 1979-05-27 7:32-00:30"}));
}
if(c == '.' || c == 'e' || c == 'E')
{
return err(format_underline("[error] bad float: invalid format",
{{std::addressof(loc), "here"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
{"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
}
}
return ok(value_t::Integer);
Expand All @@ -1533,15 +1533,15 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{
return err(format_underline("[error] bad float: invalid format",
{{std::addressof(loc), "integer part required before this"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
{"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
}
if(loc.iter() != loc.end() && *loc.iter() == '_')
{
return err(format_underline("[error] bad number: `_` should be surrounded by digits",
{{std::addressof(loc), "`_` is not surrounded by digits"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"}));
{"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"fail: 1__000, 0123"}));
}
return err(format_underline("[error] bad format: unknown value appeared",
{{std::addressof(loc), "here"}}));
Expand Down

0 comments on commit dee32e7

Please sign in to comment.