Browse code
Finish splitting up the parser file
fiddlerwoaroof authored on 28/04/2016 03:31:43
Showing 3 changed files
Showing 3 changed files
... | ... |
@@ -263,24 +263,6 @@ |
263 | 263 |
(day (parse-integer day))) |
264 | 264 |
(.identity (make-date-obj dow year month day))))) |
265 | 265 |
|
266 |
-(st:deftest date-test () |
|
267 |
- |
|
268 |
- (st:should be == nil |
|
269 |
- (caar (smug:run (.date) "Monday 2020/01-01"))) |
|
270 |
- |
|
271 |
- |
|
272 |
- (st:should be == (make-date-obj "Monday" 2020 01 01) |
|
273 |
- (caar (smug:run (.date) "Monday, 2020-01-01"))) |
|
274 |
- |
|
275 |
- |
|
276 |
- (st:should be == (make-date-obj "Monday" 2020 01 01) |
|
277 |
- (caar (smug:run (.date) "Monday 2020-01-01"))) |
|
278 |
- |
|
279 |
- |
|
280 |
- (st:should be == (make-date-obj "Monday" 2020 01 01) |
|
281 |
- (caar (smug:run (.date) "Monday 2020/01/01"))) |
|
282 |
- ) |
|
283 |
- |
|
284 | 266 |
(defun .date-start () |
285 | 267 |
(.string= "-- ")) |
286 | 268 |
|
... | ... |
@@ -308,297 +290,3 @@ |
308 | 290 |
;; we don't care about the parser's output. |
309 | 291 |
(defun cdar-equal (a b) (== (cdar a) (cdar b))) |
310 | 292 |
|
311 |
-(st:deftest initial-space () |
|
312 |
- (st:should signal invalid-whitespace |
|
313 |
- (smug:parse (.initial-space) " ")) |
|
314 |
- |
|
315 |
- (st:should signal invalid-whitespace |
|
316 |
- (smug:parse (.initial-space) (concatenate 'string |
|
317 |
- (string #\tab) |
|
318 |
- " "))) |
|
319 |
- |
|
320 |
- (st:should signal invalid-whitespace |
|
321 |
- (smug:parse (.initial-space) (concatenate 'string |
|
322 |
- (string #\tab) |
|
323 |
- (string #\tab)))) |
|
324 |
- |
|
325 |
- (st:should signal invalid-whitespace |
|
326 |
- (smug:parse (.initial-space) (concatenate 'string |
|
327 |
- (string #\tab) |
|
328 |
- " "))) |
|
329 |
- |
|
330 |
- (st:should be == (string #\tab) |
|
331 |
- (smug:parse (.initial-space) (string #\tab))) |
|
332 |
- |
|
333 |
- (st:should be == " " |
|
334 |
- (smug:parse (.initial-space) " "))) |
|
335 |
- |
|
336 |
-(st:deftest memo-test () |
|
337 |
- (st:should be == '(("asdf" . "")) |
|
338 |
- (run (.client-name) "asdf:")) |
|
339 |
- |
|
340 |
- (st:should be == '(("asdf" . "")) |
|
341 |
- (run (.memo) (format nil " asdf"))) |
|
342 |
- |
|
343 |
- (st:should be == '((("asdf" "asdf") . "")) |
|
344 |
- (run (.memo-line) (format nil " asdf: asdf")))) |
|
345 |
- |
|
346 |
-(st:deftest time-line-test () |
|
347 |
- (st:should be cdar-equal '((" start@" . "")) |
|
348 |
- (run (.time-line-start) " start@")) |
|
349 |
- |
|
350 |
- (st:should be == '(((((0 0 0))) . "")) |
|
351 |
- (run (.time-line) (format nil " start@00:00:00--~%"))) |
|
352 |
- |
|
353 |
- (st:should be == '(((((0 0 0) (1 0 0))) . "")) |
|
354 |
- (run (.time-line) (format nil " start@00:00:00--01:00:00~%"))) |
|
355 |
- |
|
356 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
357 |
- ((2 0 0))) |
|
358 |
- . "")) |
|
359 |
- (run (.time-line) (format nil " start@00:00:00--01:00:00,02:00:00--~%"))) |
|
360 |
- |
|
361 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
362 |
- ((2 0 0) (3 0 0))) |
|
363 |
- . "")) |
|
364 |
- (run (.time-line) (format nil " start@00:00:00--01:00:00,02:00:00--03:00:00~%"))) |
|
365 |
- |
|
366 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
367 |
- ((2 0 0))) |
|
368 |
- . "")) |
|
369 |
- (run (.time-line) (format nil " start@00:00:00--01:00:00, 02:00:00--~%")))) |
|
370 |
- |
|
371 |
-(should-test:deftest range-list-test () |
|
372 |
- (st:should be == '((#\, . "")) |
|
373 |
- (run (.range-list-separator) ",")) |
|
374 |
- |
|
375 |
- (st:should signal invalid-time |
|
376 |
- (run (.range-list) "30:00:00")) |
|
377 |
- |
|
378 |
- (st:should be == nil |
|
379 |
- (run (.range-list) "00:00:00")) |
|
380 |
- |
|
381 |
- (st:should be == nil |
|
382 |
- (run (.range-list) "00:00:00--,00:00:00")) |
|
383 |
- |
|
384 |
- (st:should be == '(((((0 0 0))) . "")) |
|
385 |
- (run (.range-list) (format nil "00:00:00--~%"))) |
|
386 |
- |
|
387 |
- (st:should be == '(((((0 0 0) (1 0 0))) . "")) |
|
388 |
- (run (.range-list) (format nil "00:00:00--01:00:00~%"))) |
|
389 |
- |
|
390 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
391 |
- ((2 0 0))) |
|
392 |
- . "")) |
|
393 |
- (run (.range-list) (format nil "00:00:00--01:00:00,02:00:00--~%"))) |
|
394 |
- |
|
395 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
396 |
- ((2 0 0) (3 0 0))) |
|
397 |
- . "")) |
|
398 |
- (run (.range-list) (format nil "00:00:00--01:00:00,02:00:00--03:00:00~%"))) |
|
399 |
- |
|
400 |
- (st:should be == `(((((0 0 0) (1 0 0) ,(make-time-mod -10 "mins")) |
|
401 |
- ((2 0 0) (3 0 0)) |
|
402 |
- ) |
|
403 |
- . "")) |
|
404 |
- (run (.range-list) (format nil "00:00:00--01:00:00-10mins,02:00:00--03:00:00~%"))) |
|
405 |
- |
|
406 |
- (st:should be == `(((((0 0 0) (1 0 0) ,(make-time-mod 10 "mins")) |
|
407 |
- ((2 0 0) (3 0 0)) |
|
408 |
- ) |
|
409 |
- . "")) |
|
410 |
- (run (.range-list) (format nil "00:00:00--01:00:00+10mins,02:00:00--03:00:00~%"))) |
|
411 |
- |
|
412 |
- (st:should be == '(((((0 0 0) (1 0 0)) |
|
413 |
- ((2 0 0))) |
|
414 |
- . "")) |
|
415 |
- (run (.range-list) (format nil "00:00:00--01:00:00, 02:00:00--~%")))) ;; space allowed between ranges |
|
416 |
- |
|
417 |
-(should-test:deftest time-range-test () |
|
418 |
- (st:should be == '(("--" . "")) |
|
419 |
- (run (.time-range-separator) "--")) |
|
420 |
- |
|
421 |
- (st:should be == nil |
|
422 |
- (run (.time-range) "30:00:00")) |
|
423 |
- |
|
424 |
- (st:should be == nil |
|
425 |
- (run (.time-range) "00:00:00")) |
|
426 |
- |
|
427 |
- (st:should be == nil |
|
428 |
- (run (.time-range) "00:00:00--,01:00:00--")) |
|
429 |
- |
|
430 |
- (st:should be == '((((0 0 0)) . "")) |
|
431 |
- (run (.time-range) "00:00:00--")) |
|
432 |
- |
|
433 |
- (st:should be == '((((0 0 0) (1 0 0)) . "")) |
|
434 |
- (run (.time-range) "00:00:00--01:00:00"))) |
|
435 |
- |
|
436 |
-(should-test:deftest time-test () |
|
437 |
- (st:should signal invalid-time |
|
438 |
- (run (.time) "00:0a:00")) |
|
439 |
- |
|
440 |
- (st:should be == '(((0 0 0) . "")) |
|
441 |
- (handler-bind ((invalid-time |
|
442 |
- (lambda (x) x |
|
443 |
- (smug:replace-invalid "00:0a:00" "00:00:00")))) |
|
444 |
- (run (.time) "00:0a:00"))) |
|
445 |
- |
|
446 |
- (st:should be == '((#\: . "")) |
|
447 |
- (run (.time-separator) ":")) |
|
448 |
- |
|
449 |
- (st:should signal invalid-time |
|
450 |
- (run (.time) "30:00:00")) |
|
451 |
- |
|
452 |
- (st:should be == '(((0 0 0) . "")) |
|
453 |
- (run (.time) "00:00:00"))) |
|
454 |
- |
|
455 |
-(should-test:deftest digit-test () |
|
456 |
- (loop for char in '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) |
|
457 |
- do (st:should be == `((,char . "")) |
|
458 |
- (run (.digit) (make-string 1 :initial-element char)))) ) |
|
459 |
- |
|
460 |
-(should-test:deftest minute-test () |
|
461 |
- (st:should be == nil |
|
462 |
- (run (.first-minute-char) "a")) |
|
463 |
- (st:should be == nil |
|
464 |
- (run (.first-minute-char) "6")) |
|
465 |
- (st:should be == nil |
|
466 |
- (run (.first-minute-char) "-1")) |
|
467 |
- (loop for char in '(#\0 #\1 #\2 #\3 #\4 #\5) |
|
468 |
- do (st:should be == `((,char . "")) |
|
469 |
- (run (.first-minute-char) (make-string 1 :initial-element char)))) |
|
470 |
- |
|
471 |
- (st:should be == nil |
|
472 |
- (run (.minute-or-second) "61")) |
|
473 |
- |
|
474 |
- (st:should be == nil |
|
475 |
- (run (.minute-or-second) "71")) |
|
476 |
- |
|
477 |
- (st:should be == nil |
|
478 |
- (run (.minute-or-second) "0")) ;; one digit |
|
479 |
- |
|
480 |
- (st:should be == nil |
|
481 |
- (run (.minute-or-second) "aa")) |
|
482 |
- |
|
483 |
- (st:should be == `(("01" . "")) |
|
484 |
- (run (.minute-or-second) "01"))) |
|
485 |
- |
|
486 |
- |
|
487 |
-(should-test:deftest hour-test () |
|
488 |
- (st:should be == nil |
|
489 |
- (run (.first-hour-char) "a")) |
|
490 |
- (st:should be == nil |
|
491 |
- (run (.first-hour-char) "3")) |
|
492 |
- (st:should be == nil |
|
493 |
- (run (.first-hour-char) "-1")) |
|
494 |
- |
|
495 |
- (st:should be eq T |
|
496 |
- (every #'identity |
|
497 |
- (loop for char in '(#\0 #\1 #\2) |
|
498 |
- collect (== `((,char . "")) |
|
499 |
- (run (.first-hour-char) (make-string 1 :initial-element char)))))) |
|
500 |
- |
|
501 |
- (st:should be == nil |
|
502 |
- (run (.hour) "24")) |
|
503 |
- |
|
504 |
- (st:should be == nil |
|
505 |
- (run (.hour) "71")) |
|
506 |
- |
|
507 |
- (st:should be == nil |
|
508 |
- (run (.hour) "0")) |
|
509 |
- |
|
510 |
- (st:should be == nil |
|
511 |
- (run (.hour) "aa")) |
|
512 |
- |
|
513 |
- (st:should be == `(("20" . "")) |
|
514 |
- (run (.prog1 (.hour) (.not (.item))) "20")) |
|
515 |
- |
|
516 |
- (st:should be == `(("01" . "")) |
|
517 |
- (run (.prog1 (.hour) (.not (.item))) "01"))) |
|
518 |
- |
|
519 |
-(should-test:deftest month-test () |
|
520 |
- (st:should be == nil |
|
521 |
- (run (.first-month-char) "a")) |
|
522 |
- (st:should be == nil |
|
523 |
- (run (.first-month-char) "4")) |
|
524 |
- (st:should be == nil |
|
525 |
- (run (.first-month-char) "-1")) |
|
526 |
- |
|
527 |
- (loop for char in '(#\0 #\1 #\2 #\3) |
|
528 |
- do (st:should be == `((,char . "")) |
|
529 |
- (run (.first-month-char) (make-string 1 :initial-element char)))) |
|
530 |
- |
|
531 |
- (st:should be == nil |
|
532 |
- (run (.month) "32")) |
|
533 |
- |
|
534 |
- (st:should be == nil |
|
535 |
- (run (.month) "71")) |
|
536 |
- |
|
537 |
- (st:should be == nil |
|
538 |
- (run (.month) "0")) |
|
539 |
- |
|
540 |
- (st:should be == nil |
|
541 |
- (run (.month) "aa")) |
|
542 |
- |
|
543 |
- (st:should be == `(("30" . "")) |
|
544 |
- (run (.prog1 (.month) (.not (.item))) "30")) |
|
545 |
- (st:should be == `(("20" . "")) |
|
546 |
- (run (.prog1 (.month) (.not (.item))) "20")) |
|
547 |
- (st:should be == `(("10" . "")) |
|
548 |
- (run (.prog1 (.month) (.not (.item))) "10")) |
|
549 |
- (st:should be == `(("01" . "")) |
|
550 |
- (run (.prog1 (.month) (.not (.item))) "01"))) |
|
551 |
- |
|
552 |
-(st:deftest time-range-test () |
|
553 |
- |
|
554 |
- (st:should be == nil |
|
555 |
- (run (.time-range) "00:00:00")) |
|
556 |
- |
|
557 |
- (st:should be == `(( (,(make-time-obj 0 0 0)) . "")) |
|
558 |
- (run (.time-range) "00:00:00--")) |
|
559 |
- |
|
560 |
- (st:should be == `(( (,(make-time-obj 0 0 0)) . "")) |
|
561 |
- (run (.time-range) "00:00--")) |
|
562 |
- |
|
563 |
- (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0)) . "")) |
|
564 |
- (run (.time-range) "00:00:00--01:00:00")) |
|
565 |
- |
|
566 |
- (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0)) . "")) |
|
567 |
- (run (.time-range) "00:00--01:00")) |
|
568 |
- |
|
569 |
- (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0) ,(make-time-mod 10 "mins")) . "")) |
|
570 |
- (run (.time-range) "00:00--01:00+10mins")) |
|
571 |
- |
|
572 |
- (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0) ,(make-time-mod -10 "mins")) . "")) |
|
573 |
- (run (.time-range) "00:00--01:00-10mins"))) |
|
574 |
- |
|
575 |
-(st:deftest generic-eq () |
|
576 |
- "Note: this really should be in the equality package with the name == |
|
577 |
- should-test only checks tests for _internal_ symbols." |
|
578 |
- (st:should be eql t (== #\1 #\1)) |
|
579 |
- (st:should be eql t (== 1 1)) |
|
580 |
- (st:should be eql t (== "1" "1")) |
|
581 |
- (st:should be eql t (== '("1") '("1"))) |
|
582 |
- (st:should be eql t (== #("1") #("1"))) |
|
583 |
- (st:should be eql t (== '(1 . 2) '(1 . 2))) |
|
584 |
- (st:should be eql t (== '((1 . 2)) '((1 . 2)))) |
|
585 |
- (st:should be eql t (== #1=(make-date-obj "Monday" 2020 01 01) #1#)) |
|
586 |
- |
|
587 |
- (st:should be eql t |
|
588 |
- (== (make-date-obj "Monday" 2012 01 01) |
|
589 |
- (make-date-obj "Monday" 2012 01 01))) |
|
590 |
- |
|
591 |
- (st:should be eql t |
|
592 |
- (== (make-time-obj 00 00 00) |
|
593 |
- (make-time-obj 00 00 00))) |
|
594 |
- |
|
595 |
- (st:should be eql t |
|
596 |
- (== (make-time-mod 3 "mins") |
|
597 |
- (make-time-mod 3 "mins"))) |
|
598 |
- (st:should be eql t |
|
599 |
- (== (list (make-time-mod 3 "mins")) |
|
600 |
- (list (make-time-mod 3 "mins")))) |
|
601 |
- (st:should be eql t |
|
602 |
- (== #((make-time-mod 3 "mins")) |
|
603 |
- #((make-time-mod 3 "mins"))))) |
|
604 |
- |
... | ... |
@@ -61,20 +61,6 @@ |
61 | 61 |
. "")) |
62 | 62 |
(run (.range-list) (format nil "00:00:00--01:00:00, 02:00:00--~%")))) ;; space allowed between ranges |
63 | 63 |
|
64 |
-(st:deftest time-range-test () |
|
65 |
- (st:should be == '(("--" . "")) |
|
66 |
- (run (.time-range-separator) "--")) |
|
67 |
- (st:should be == nil |
|
68 |
- (run (.time-range) "30:00:00")) |
|
69 |
- (st:should be == nil |
|
70 |
- (run (.time-range) "00:00:00")) |
|
71 |
- (st:should be == nil |
|
72 |
- (run (.time-range) "00:00:00--,01:00:00--")) |
|
73 |
- (st:should be == '((((0 0 0)) . "")) |
|
74 |
- (run (.time-range) "00:00:00--")) |
|
75 |
- (st:should be == '((((0 0 0) (1 0 0)) . "")) |
|
76 |
- (run (.time-range) "00:00:00--01:00:00"))) |
|
77 |
- |
|
78 | 64 |
(st:deftest time-test () |
79 | 65 |
(st:should signal invalid-time |
80 | 66 |
(run (.time) "00:0a:00")) |
... | ... |
@@ -169,6 +155,19 @@ |
169 | 155 |
(run (.prog1 (.month) (.not (.item))) "01"))) |
170 | 156 |
|
171 | 157 |
(st:deftest time-range-test () |
158 |
+ (st:should be == '(("--" . "")) |
|
159 |
+ (run (.time-range-separator) "--")) |
|
160 |
+ (st:should be == nil |
|
161 |
+ (run (.time-range) "30:00:00")) |
|
162 |
+ (st:should be == nil |
|
163 |
+ (run (.time-range) "00:00:00")) |
|
164 |
+ (st:should be == nil |
|
165 |
+ (run (.time-range) "00:00:00--,01:00:00--")) |
|
166 |
+ (st:should be == '((((0 0 0)) . "")) |
|
167 |
+ (run (.time-range) "00:00:00--")) |
|
168 |
+ (st:should be == '((((0 0 0) (1 0 0)) . "")) |
|
169 |
+ (run (.time-range) "00:00:00--01:00:00")) |
|
170 |
+ |
|
172 | 171 |
(st:should be == nil |
173 | 172 |
(run (.time-range) "00:00:00")) |
174 | 173 |
(st:should be == `(( (,(make-time-obj 0 0 0)) . "")) |
... | ... |
@@ -192,7 +191,7 @@ |
192 | 191 |
(st:should be == '((("asdf" "asdf") . "")) |
193 | 192 |
(run (.memo-line) (format nil " asdf: asdf")))) |
194 | 193 |
|
195 |
-(st:deftest initial-space () |
|
194 |
+(st:deftest initial-space-test () |
|
196 | 195 |
(st:should signal invalid-whitespace |
197 | 196 |
(smug:parse (.initial-space) " ")) |
198 | 197 |
(st:should signal invalid-whitespace |
... | ... |
@@ -212,7 +211,7 @@ |
212 | 211 |
(st:should be == " " |
213 | 212 |
(smug:parse (.initial-space) " "))) |
214 | 213 |
|
215 |
-(st:deftest make-time-mod () |
|
214 |
+(st:deftest make-time-mod-test () |
|
216 | 215 |
(st:should be == |
217 | 216 |
(make-instance 'time-mod :unit :hour :amount 0) |
218 | 217 |
(make-time-mod 0 "hours")) |
... | ... |
@@ -247,7 +246,7 @@ |
247 | 246 |
(st:should be == (make-date-obj "Monday" 2020 01 01) |
248 | 247 |
(caar (smug:run (.date) "Monday 2020/01/01")))) |
249 | 248 |
|
250 |
-(st:deftest generic-eq () |
|
249 |
+(st:deftest generic-eq-test () |
|
251 | 250 |
"Note: this really should be in the equality package with the name == |
252 | 251 |
should-test only checks tests for _internal_ symbols." |
253 | 252 |
(st:should be eql t (== #\1 #\1)) |