git.fiddlerwoaroof.com
Browse code

Add tests to the parser.

Add some tests to the parser and move package definitions around

fiddlerwoaroof authored on 23/02/2016 04:50:19
Showing 5 changed files
... ...
@@ -1 +1,2 @@
1 1
 .*.swp
2
+buildapp-*/
... ...
@@ -1,3 +1,9 @@
1
+(defpackage #:timesheet.freshbooks
2
+  (:use #:cl #:anaphora #:alexandria #:serapeum #:fwoar.lisputils
3
+        #:timesheet.parser)
4
+  (:import-from #:timesheet #:timesheet)
5
+  (:export #:timesheet))
6
+
1 7
 (in-package :timesheet.freshbooks)
2 8
 
3 9
 (defvar *api-key*)
... ...
@@ -28,10 +28,3 @@
28 28
 (defpackage #:timesheet
29 29
   (:use #:cl #:anaphora #:alexandria #:serapeum #:fwoar.lisputils
30 30
         #:timesheet.parser))
31
-
32
-(defpackage #:timesheet.freshbooks
33
-  (:use #:cl #:anaphora #:alexandria #:serapeum #:fwoar.lisputils
34
-        #:timesheet.parser)
35
-  (:import-from #:timesheet #:timesheet)
36
-  (:export #:timesheet))
37
-
... ...
@@ -291,7 +291,7 @@
291 291
     (.identity (coerce (list fi se th fo) 'string))))
292 292
 
293 293
 (defun .first-month-char ()
294
-  (.or (.char= #\0) (.char= #\1)))
294
+  (.or (.char= #\0) (.char= #\1) (.char= #\2) (.char= #\3)))
295 295
 
296 296
 (defun .first-day-char ()
297 297
   (.or (.char= #\0) (.char= #\1) (.char= #\2) (.char= #\3)))
... ...
@@ -299,9 +299,12 @@
299 299
 (defun .month ()
300 300
   (.let* ((fi (.first-month-char))
301 301
           (se (.digit)))
302
-    (when (and (char= fi #\1) (not (member se '(#\1 #\2))))
303
-      (.fail))
304
-    (.identity (coerce (list fi se) 'string))) )
302
+    (let ((res (when (char= fi #\3)
303
+                 (unless (member se '(#\1 #\0))
304
+                   (.fail)))))
305
+      (if (not res)
306
+        (.identity (coerce (list fi se) 'string))
307
+        res))))
305 308
 
306 309
 (defun .day ()
307 310
   (.let* ((fi (.first-month-char))
... ...
@@ -417,6 +420,18 @@
417 420
                          . ""))
418 421
              (run (.range-list) (format nil "00:00:00--01:00:00,02:00:00--03:00:00~%")))
419 422
 
423
+  (st:should be == `(((((0 0 0) (1 0 0) ,(make-time-mod -10 "mins")) 
424
+                       ((2 0 0) (3 0 0))
425
+                       )
426
+                      . ""))
427
+             (run (.range-list) (format nil "00:00:00--01:00:00-10mins,02:00:00--03:00:00~%")))
428
+
429
+  (st:should be == `(((((0 0 0) (1 0 0) ,(make-time-mod 10 "mins"))  
430
+                       ((2 0 0) (3 0 0))
431
+                       )
432
+                      . ""))
433
+             (run (.range-list) (format nil "00:00:00--01:00:00+10mins,02:00:00--03:00:00~%")))
434
+
420 435
   (st:should be == '(((((0 0 0) (1 0 0))
421 436
                           ((2 0 0)))
422 437
                          . ""))
... ...
@@ -491,9 +506,11 @@
491 506
   (st:should be == nil
492 507
              (run (.first-hour-char) "-1"))
493 508
 
494
-  (loop for char in '(#\0 #\1 #\2)
495
-        do (st:should be == `((,char . ""))
496
-                      (run (.first-hour-char) (make-string 1 :initial-element char))))
509
+  (st:should be eq T
510
+          (every #'identity
511
+                 (loop for char in '(#\0 #\1 #\2)
512
+                       collect (== `((,char . ""))
513
+                                   (run (.first-hour-char) (make-string 1 :initial-element char))))))
497 514
 
498 515
   (st:should be == nil
499 516
              (run (.hour) "24"))
... ...
@@ -507,9 +524,68 @@
507 524
   (st:should be == nil
508 525
              (run (.hour) "aa"))
509 526
 
527
+  (st:should be == `((20 . ""))
528
+             (run (.prog1 (.hour) (.not (.item))) "20")) 
529
+
510 530
   (st:should be == `((1 . ""))
511 531
              (run (.prog1 (.hour) (.not (.item))) "01")))
512 532
 
533
+(should-test:deftest month-test ()
534
+  (st:should be == nil
535
+             (run (.first-month-char) "a"))
536
+  (st:should be == nil
537
+             (run (.first-month-char) "4"))
538
+  (st:should be == nil
539
+             (run (.first-month-char) "-1"))
540
+
541
+  (loop for char in '(#\0 #\1 #\2 #\3)
542
+        do (st:should be == `((,char . ""))
543
+                      (run (.first-month-char) (make-string 1 :initial-element char))))
544
+
545
+  (st:should be == nil
546
+             (run (.month) "32"))
547
+
548
+  (st:should be == nil
549
+             (run (.month) "71"))
550
+
551
+  (st:should be == nil
552
+             (run (.month) "0"))
553
+
554
+  (st:should be == nil
555
+             (run (.month) "aa"))
556
+
557
+  (st:should be == `(("30" . ""))
558
+             (run (.prog1 (.month) (.not (.item))) "30")) 
559
+  (st:should be == `(("20" . ""))
560
+             (run (.prog1 (.month) (.not (.item))) "20")) 
561
+  (st:should be == `(("10" . ""))
562
+             (run (.prog1 (.month) (.not (.item))) "10")) 
563
+  (st:should be == `(("01" . ""))
564
+             (run (.prog1 (.month) (.not (.item))) "01")))
565
+
566
+(st:deftest time-range-test ()
567
+  
568
+  (st:should be == nil
569
+             (run (.time-range) "00:00:00"))
570
+
571
+  (st:should be == `(( (,(make-time-obj 0 0 0)) . ""))
572
+             (run (.time-range) "00:00:00--"))
573
+
574
+  (st:should be == `(( (,(make-time-obj 0 0 0)) . ""))
575
+             (run (.time-range) "00:00--"))
576
+
577
+  (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0)) . ""))
578
+             (run (.time-range) "00:00:00--01:00:00"))
579
+
580
+  (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0)) . ""))
581
+             (run (.time-range) "00:00--01:00"))
582
+
583
+  (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0) ,(make-time-mod 10 "mins")) . ""))
584
+             (run (.time-range) "00:00--01:00+10mins"))
585
+
586
+  (st:should be == `(((,(make-time-obj 0 0 0) ,(make-time-obj 1 0 0) ,(make-time-mod -10 "mins")) . ""))
587
+             (run (.time-range) "00:00--01:00-10mins")))
588
+
513 589
 (st:deftest == ()
514 590
   (st:should be eql t (== #\1 #\1))
515 591
   (st:should be eql t (== 1 1))
516 592
Binary files a/precompiled/timesheet and b/precompiled/timesheet differ