style: make hint messages clearer

This commit is contained in:
ToruNiina
2019-06-19 12:56:21 +09:00
parent 53a185e7a9
commit dee32e7d5e
2 changed files with 25 additions and 25 deletions

View File

@@ -150,13 +150,13 @@ the malformed files in [the language agnostic test suite](https://github.com/Bur
is shown below. is shown below.
```console ```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 --> ./datetime-malformed-no-secs.toml
1 | no-secs = 1987-07-05T17:45Z 1 | no-secs = 1987-07-05T17:45Z
| ^------- HH:MM:SS.subsec | ^------- HH:MM:SS.subsec
| |
Hint: OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999 Hint: pass: 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: fail: 1979-05-27T7:32:00, 1979-05-27 17:32
``` ```
You can find other examples in a job named `output_result` on You can find other examples in a job named `output_result` on

View File

@@ -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", return err(format_underline("[error] bad offset: should be [+-]HH:MM or Z",
{{std::addressof(loc), "[+-]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); return ok(value_t::LocalDatetime);
} }
@@ -1451,15 +1451,15 @@ 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", return err(format_underline("[error] bad time: should be HH:MM:SS.subsec",
{{std::addressof(loc), "HH:MM:SS.subsec"}}, {{std::addressof(loc), "HH:MM:SS.subsec"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999", {"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"})); "fail: 1979-05-27T7:32:00, 1979-05-27 17:32"}));
} }
if('0' <= c && c <= '9') if('0' <= c && c <= '9')
{ {
return err(format_underline("[error] bad time: missing T", return err(format_underline("[error] bad time: missing T",
{{std::addressof(loc), "T or space required here"}}, {{std::addressof(loc), "T or space required here"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999", {"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"})); "fail: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
} }
if(c == ' ' && std::next(loc.iter()) != loc.end() && if(c == ' ' && std::next(loc.iter()) != loc.end() &&
('0' <= *std::next(loc.iter()) && *std::next(loc.iter())<= '9')) ('0' <= *std::next(loc.iter()) && *std::next(loc.iter())<= '9'))
@@ -1467,8 +1467,8 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
loc.advance(); loc.advance();
return err(format_underline("[error] bad time: should be HH:MM:SS.subsec", return err(format_underline("[error] bad time: should be HH:MM:SS.subsec",
{{std::addressof(loc), "HH:MM:SS.subsec"}}, {{std::addressof(loc), "HH:MM:SS.subsec"}},
{"OK: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999", {"pass: 1979-05-27T07:32:00, 1979-05-27 07:32:00.999999",
"NG: 1979-05-27T7:32:00, 1979-05-27 7:32"})); "fail: 1979-05-27T7:32:00, 1979-05-27 7:32"}));
} }
} }
return ok(value_t::LocalDate); return ok(value_t::LocalDate);
@@ -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", return err(format_underline("[error] bad float: `_` should be surrounded by digits",
{{std::addressof(loc), "here"}}, {{std::addressof(loc), "here"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan", {"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"})); "fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
} }
return ok(value_t::Float); return ok(value_t::Float);
} }
@@ -1500,8 +1500,8 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
{ {
return err(format_underline("[error] bad integer: `_` should be surrounded by digits", return err(format_underline("[error] bad integer: `_` should be surrounded by digits",
{{std::addressof(loc), "here"}}, {{std::addressof(loc), "here"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755", {"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"})); "fail: 1__000, 0123"}));
} }
if('0' <= c && c <= '9') if('0' <= c && c <= '9')
{ {
@@ -1509,22 +1509,22 @@ result<value_t, std::string> guess_number_type(const location<Container>& l)
loc.retrace(); loc.retrace();
return err(format_underline("[error] bad integer: leading zero", return err(format_underline("[error] bad integer: leading zero",
{{std::addressof(loc), "here"}}, {{std::addressof(loc), "here"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755", {"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"})); "fail: 1__000, 0123"}));
} }
if(c == ':' || c == '-') if(c == ':' || c == '-')
{ {
return err(format_underline("[error] bad datetime: invalid format", return err(format_underline("[error] bad datetime: invalid format",
{{std::addressof(loc), "here"}}, {{std::addressof(loc), "here"}},
{"OK: 1979-05-27T07:32:00-07:00, 1979-05-27 07:32:00.999999Z", {"pass: 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"})); "fail: 1979-05-27T7:32:00-7:00, 1979-05-27 7:32-00:30"}));
} }
if(c == '.' || c == 'e' || c == 'E') if(c == '.' || c == 'e' || c == 'E')
{ {
return err(format_underline("[error] bad float: invalid format", return err(format_underline("[error] bad float: invalid format",
{{std::addressof(loc), "here"}}, {{std::addressof(loc), "here"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan", {"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"})); "fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
} }
} }
return ok(value_t::Integer); return ok(value_t::Integer);
@@ -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", return err(format_underline("[error] bad float: invalid format",
{{std::addressof(loc), "integer part required before this"}}, {{std::addressof(loc), "integer part required before this"}},
{"OK: +1.0, -2e-2, 3.141_592_653_589, inf, nan", {"pass: +1.0, -2e-2, 3.141_592_653_589, inf, nan",
"NG: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"})); "fail: .0, 1., _1.0, 1.0_, 1_.0, 1.0__0"}));
} }
if(loc.iter() != loc.end() && *loc.iter() == '_') if(loc.iter() != loc.end() && *loc.iter() == '_')
{ {
return err(format_underline("[error] bad number: `_` should be surrounded by digits", return err(format_underline("[error] bad number: `_` should be surrounded by digits",
{{std::addressof(loc), "`_` is not surrounded by digits"}}, {{std::addressof(loc), "`_` is not surrounded by digits"}},
{"OK: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755", {"pass: -42, 1_000, 1_2_3_4_5, 0xC0FFEE, 0b0010, 0o755",
"NG: 1__000, 0123"})); "fail: 1__000, 0123"}));
} }
return err(format_underline("[error] bad format: unknown value appeared", return err(format_underline("[error] bad format: unknown value appeared",
{{std::addressof(loc), "here"}})); {{std::addressof(loc), "here"}}));