1use serde_json::Value;
2
3macro_rules! bad {
4 ($toml:expr, $msg:expr) => {
5 match basic_toml::from_str::<Value>($toml) {
6 Ok(s) => panic!("parsed to: {:#?}", s),
7 Err(e) => assert_eq!(e.to_string(), $msg),
8 }
9 };
10}
11
12#[test]
13fn times() {
14 fn multi_bad(s: &str, msg: &str) {
15 bad!(s, msg);
16 bad!(&s.replace('T', " "), msg);
17 bad!(&s.replace('T', "t"), msg);
18 bad!(&s.replace('Z', "z"), msg);
19 }
20
21 multi_bad(
22 "foo = 1997-09-09T09:09:09Z",
23 "invalid number at line 1 column 7",
24 );
25 multi_bad(
26 "foo = 1997-09-09T09:09:09+09:09",
27 "invalid number at line 1 column 7",
28 );
29 multi_bad(
30 "foo = 1997-09-09T09:09:09-09:09",
31 "invalid number at line 1 column 7",
32 );
33 multi_bad(
34 "foo = 1997-09-09T09:09:09",
35 "invalid number at line 1 column 7",
36 );
37 multi_bad("foo = 1997-09-09", "invalid number at line 1 column 7");
38 bad!("foo = 1997-09-09 ", "invalid number at line 1 column 7");
39 bad!(
40 "foo = 1997-09-09 # comment",
41 "invalid number at line 1 column 7"
42 );
43 multi_bad("foo = 09:09:09", "invalid number at line 1 column 8");
44 multi_bad(
45 "foo = 1997-09-09T09:09:09.09Z",
46 "invalid number at line 1 column 7",
47 );
48 multi_bad(
49 "foo = 1997-09-09T09:09:09.09+09:09",
50 "invalid number at line 1 column 7",
51 );
52 multi_bad(
53 "foo = 1997-09-09T09:09:09.09-09:09",
54 "invalid number at line 1 column 7",
55 );
56 multi_bad(
57 "foo = 1997-09-09T09:09:09.09",
58 "invalid number at line 1 column 7",
59 );
60 multi_bad("foo = 09:09:09.09", "invalid number at line 1 column 8");
61}
62
63#[test]
64fn bad_times() {
65 bad!("foo = 199-09-09", "invalid number at line 1 column 7");
66 bad!("foo = 199709-09", "invalid number at line 1 column 7");
67 bad!("foo = 1997-9-09", "invalid number at line 1 column 7");
68 bad!("foo = 1997-09-9", "invalid number at line 1 column 7");
69 bad!(
70 "foo = 1997-09-0909:09:09",
71 "invalid number at line 1 column 7"
72 );
73 bad!(
74 "foo = 1997-09-09T09:09:09.",
75 "invalid number at line 1 column 7"
76 );
77 bad!(
78 "foo = T",
79 "invalid TOML value, did you mean to use a quoted string? at line 1 column 7"
80 );
81 bad!(
82 "foo = T.",
83 "invalid TOML value, did you mean to use a quoted string? at line 1 column 7"
84 );
85 bad!(
86 "foo = TZ",
87 "invalid TOML value, did you mean to use a quoted string? at line 1 column 7"
88 );
89 bad!(
90 "foo = 1997-09-09T09:09:09.09+",
91 "invalid number at line 1 column 7"
92 );
93 bad!(
94 "foo = 1997-09-09T09:09:09.09+09",
95 "invalid number at line 1 column 7"
96 );
97 bad!(
98 "foo = 1997-09-09T09:09:09.09+09:9",
99 "invalid number at line 1 column 7"
100 );
101 bad!(
102 "foo = 1997-09-09T09:09:09.09+0909",
103 "invalid number at line 1 column 7"
104 );
105 bad!(
106 "foo = 1997-09-09T09:09:09.09-",
107 "invalid number at line 1 column 7"
108 );
109 bad!(
110 "foo = 1997-09-09T09:09:09.09-09",
111 "invalid number at line 1 column 7"
112 );
113 bad!(
114 "foo = 1997-09-09T09:09:09.09-09:9",
115 "invalid number at line 1 column 7"
116 );
117 bad!(
118 "foo = 1997-09-09T09:09:09.09-0909",
119 "invalid number at line 1 column 7"
120 );
121
122 bad!(
123 "foo = 1997-00-09T09:09:09.09Z",
124 "invalid number at line 1 column 7"
125 );
126 bad!(
127 "foo = 1997-09-00T09:09:09.09Z",
128 "invalid number at line 1 column 7"
129 );
130 bad!(
131 "foo = 1997-09-09T30:09:09.09Z",
132 "invalid number at line 1 column 7"
133 );
134 bad!(
135 "foo = 1997-09-09T12:69:09.09Z",
136 "invalid number at line 1 column 7"
137 );
138 bad!(
139 "foo = 1997-09-09T12:09:69.09Z",
140 "invalid number at line 1 column 7"
141 );
142}
143