Skip to content

Commit 8d8c8a0

Browse files
committed
tests: add basic tests for parsing iso 8601 strs
1 parent f627488 commit 8d8c8a0

File tree

1 file changed

+76
-71
lines changed

1 file changed

+76
-71
lines changed

src/interval_parse/iso_8601.rs

Lines changed: 76 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -145,129 +145,134 @@ mod tests {
145145
use pg_interval::Interval;
146146

147147
#[test]
148-
fn test_iso_1() {
148+
fn test_from_iso_1() {
149149
let interval = Interval::from_iso("P1Y").unwrap();
150150
let interval_exp = Interval::new(12, 0, 0);
151151
assert_eq!(interval, interval_exp);
152152
}
153153

154-
/*
154+
155155
#[test]
156-
fn test_8601_2() {
157-
let interval = Interval::new(13, 0, 0);
158-
let output = interval.to_iso_8601();
159-
assert_eq!(String::from("P1Y1M"), output);
156+
fn test_from_8601_2() {
157+
let interval = Interval::from_iso("P1Y1M").unwrap();
158+
let interval_exp = Interval::new(13, 0, 0);
159+
assert_eq!(interval, interval_exp);
160160
}
161161

162+
162163
#[test]
163-
fn test_8601_3() {
164-
let interval = Interval::new(13, 1, 0);
165-
let output = interval.to_iso_8601();
166-
assert_eq!(String::from("P1Y1M1D"), output);
164+
fn test_from_8601_3() {
165+
let interval = Interval::from_iso("P1Y1M1D").unwrap();
166+
let interval_exp = Interval::new(13, 1, 0);
167+
assert_eq!(interval, interval_exp);
167168
}
168169

169170
#[test]
170-
fn test_8601_4() {
171-
let interval = Interval::new(13, 1, 3600000000);
172-
let output = interval.to_iso_8601();
173-
assert_eq!(String::from("P1Y1M1DT1H"), output);
171+
fn test_from_8601_4() {
172+
let interval = Interval::from_iso("P1Y1M1DT1H").unwrap();
173+
let interval_exp = Interval::new(13, 1, 3600000000);
174+
assert_eq!(interval, interval_exp);
174175
}
175176

177+
176178
#[test]
177-
fn test_8601_5() {
178-
let interval = Interval::new(13, 1, 4200000000);
179-
let output = interval.to_iso_8601();
180-
assert_eq!(String::from("P1Y1M1DT1H10M"), output);
179+
fn test_from_8601_5() {
180+
let interval = Interval::from_iso("P1Y1M1DT1H10M").unwrap();
181+
let interval_exp = Interval::new(13, 1, 4200000000);
182+
assert_eq!(interval, interval_exp);
181183
}
182184

185+
183186
#[test]
184-
fn test_8601_6() {
185-
let interval = Interval::new(13, 1, 4215000000);
186-
let output = interval.to_iso_8601();
187-
assert_eq!(String::from("P1Y1M1DT1H10M15S"), output);
187+
fn test_from_8601_6() {
188+
let interval = Interval::from_iso("P1Y1M1DT1H10M15S").unwrap();
189+
let interval_exp = Interval::new(13, 1, 4215000000);
190+
assert_eq!(interval, interval_exp);
188191
}
189192

190193
#[test]
191-
fn test_8601_7() {
192-
let interval = Interval::new(0, 0, 3600000000);
193-
let output = interval.to_iso_8601();
194-
assert_eq!(String::from("PT1H"), output);
194+
fn test_from_8601_7() {
195+
let interval = Interval::from_iso("PT1H").unwrap();
196+
let interval_exp = Interval::new(0, 0, 3600000000);
197+
assert_eq!(interval, interval_exp);
195198
}
196199

197200
#[test]
198-
fn test_8601_8() {
199-
let interval = Interval::new(0, 0, 4200000000);
200-
let output = interval.to_iso_8601();
201-
assert_eq!(String::from("PT1H10M"), output);
201+
fn test_from_8601_8() {
202+
let interval = Interval::from_iso("PT1H10M").unwrap();
203+
let interval_exp = Interval::new(0, 0, 4200000000);
204+
assert_eq!(interval, interval_exp);
202205
}
203206

207+
204208
#[test]
205-
fn test_8601_9() {
206-
let interval = Interval::new(0, 0, 4215000000);
207-
let output = interval.to_iso_8601();
208-
assert_eq!(String::from("PT1H10M15S"), output);
209+
fn test_from_8601_9() {
210+
let interval = Interval::from_iso("PT1H10M15S").unwrap();
211+
let interval_exp = Interval::new(0, 0, 4215000000);
212+
assert_eq!(interval, interval_exp);
209213
}
210214

211215
#[test]
212-
fn test_8601_10() {
213-
let interval = Interval::new(-12, 0, 0);
214-
let output = interval.to_iso_8601();
215-
assert_eq!(String::from("P-1Y"), output);
216+
fn test_from_8601_10() {
217+
let interval = Interval::from_iso("P-1Y").unwrap();
218+
let interval_exp = Interval::new(-12, 0, 0);
219+
assert_eq!(interval, interval_exp);
216220
}
217221

222+
218223
#[test]
219-
fn test_8601_11() {
220-
let interval = Interval::new(-13, 0, 0);
221-
let output = interval.to_iso_8601();
222-
assert_eq!(String::from("P-1Y-1M"), output);
224+
fn test_from_8601_11() {
225+
let interval = Interval::from_iso("P-1Y-1M").unwrap();
226+
let interval_exp = Interval::new(-13, 0, 0);
227+
assert_eq!(interval, interval_exp);
223228
}
224229

225230
#[test]
226-
fn test_8601_12() {
227-
let interval = Interval::new(-13, -1, 0);
228-
let output = interval.to_iso_8601();
229-
assert_eq!(String::from("P-1Y-1M-1D"), output);
231+
fn test_from_8601_12() {
232+
let interval = Interval::from_iso("P-1Y-1M-1D").unwrap();
233+
let interval_exp = Interval::new(-13, -1, 0);
234+
assert_eq!(interval, interval_exp);
230235
}
231236

232237
#[test]
233-
fn test_8601_13() {
234-
let interval = Interval::new(-13, -1, -3600000000);
235-
let output = interval.to_iso_8601();
236-
assert_eq!(String::from("P-1Y-1M-1DT-1H"), output);
238+
fn test_from_8601_13() {
239+
let interval = Interval::from_iso("P-1Y-1M-1DT-1H").unwrap();
240+
let interval_exp = Interval::new(-13, -1, -3600000000);
241+
assert_eq!(interval, interval_exp);
237242
}
238243

239244
#[test]
240-
fn test_8601_14() {
241-
let interval = Interval::new(-13, -1, -4200000000);
242-
let output = interval.to_iso_8601();
243-
assert_eq!(String::from("P-1Y-1M-1DT-1H-10M"), output);
245+
fn test_from_8601_14() {
246+
let interval = Interval::from_iso("P-1Y-1M-1DT-1H-10M").unwrap();
247+
let interval_exp = Interval::new(-13, -1, -4200000000);
248+
assert_eq!(interval, interval_exp);
244249
}
245250

246251
#[test]
247-
fn test_8601_15() {
248-
let interval = Interval::new(-13, -1, -4215000000);
249-
let output = interval.to_iso_8601();
250-
assert_eq!(String::from("P-1Y-1M-1DT-1H-10M-15S"), output);
252+
fn test_from_8601_15() {
253+
let interval = Interval::from_iso("P-1Y-1M-1DT-1H-10M-15S").unwrap();
254+
let interval_exp = Interval::new(-13, -1, -4215000000);
255+
assert_eq!(interval, interval_exp);
251256
}
252257

253258
#[test]
254-
fn test_8601_16() {
255-
let interval = Interval::new(0, 0, -3600000000);
256-
let output = interval.to_iso_8601();
257-
assert_eq!(String::from("PT-1H"), output);
259+
fn test_from_8601_16() {
260+
let interval = Interval::from_iso("PT-1H").unwrap();
261+
let interval_exp = Interval::new(0, 0, -3600000000);
262+
assert_eq!(interval, interval_exp);
258263
}
259264

260265
#[test]
261-
fn test_8601_17() {
262-
let interval = Interval::new(0, 0, -4200000000);
263-
let output = interval.to_iso_8601();
264-
assert_eq!(String::from("PT-1H-10M"), output);
266+
fn test_from_8601_17() {
267+
let interval = Interval::from_iso("PT-1H-10M").unwrap();
268+
let interval_exp = Interval::new(0, 0, -4200000000);
269+
assert_eq!(interval, interval_exp);
265270
}
266271

267272
#[test]
268-
fn test_8601_18() {
269-
let interval = Interval::new(0, 0, -4215000000);
270-
let output = interval.to_iso_8601();
271-
assert_eq!(String::from("PT-1H-10M-15S"), output);
272-
} */
273+
fn test_from_8601_18() {
274+
let interval = Interval::from_iso("PT-1H-10M-15S").unwrap();
275+
let interval_exp = Interval::new(0, 0, -4215000000);
276+
assert_eq!(interval, interval_exp);
277+
}
273278
}

0 commit comments

Comments
 (0)