Test msg constructor and line splitter
[tt.git] / tt.rkt
diff --git a/tt.rkt b/tt.rkt
index 986ade1..8ed1243 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
   results)
 
 (module+ test
-         (define n-workers 10)
-         (define given (list
-                         (λ (x) (if (even? x) x #f))
-                         (range 11)))
-         (check-equal?
-           (sort (apply concurrent-filter-map (cons n-workers given)) <)
-           (sort (apply            filter-map                 given ) <)))
+         (let* ([f        (λ (x) (if (even? x) x #f))]
+                [xs       (range 11)]
+                [actual   (sort (concurrent-filter-map 10 f xs) <)]
+                [expected (sort (           filter-map    f xs) <)])
+               (check-equal? actual expected "concurrent-filter-map")))
 
 (define (msg-print out-format odd msg)
   (printf
                                           [rfc3339-record:year   t])])
                  (msg ts_epoch ts_rfc3339 nick uri text))))))
 
+(module+ test
+         (let* ([ts       "2020-11-18T22:22:09-0500"]
+                [tab      "    "]
+                [text     "Lorem ipsum"]
+                [nick     "foo"]
+                [uri      "bar"]
+                [actual   (str->msg nick uri (string-join (list ts text) tab))]
+                [expected (msg 1605756129 ts nick uri text)])
+               (check-equal?
+                 (msg-ts_epoch actual)
+                 (msg-ts_epoch expected)
+                 "str->msg ts_epoch")
+               (check-equal?
+                 (msg-ts_rfc3339 actual)
+                 (msg-ts_rfc3339 expected)
+                 "str->msg ts_rfc3339")
+               (check-equal?
+                 (msg-nick actual)
+                 (msg-nick expected)
+                 "str->msg nick")
+               (check-equal?
+                 (msg-uri actual)
+                 (msg-uri expected)
+                 "str->msg uri")
+               (check-equal?
+                 (msg-text actual)
+                 (msg-text expected)
+                 "str->msg text")))
+
 (define (str->lines str)
   (string-split str (regexp "[\r\n]+")))
 
+(module+ test
+  (check-equal? (str->lines "abc\ndef\n\nghi") '("abc" "def" "ghi")))
+
 (define (str->msgs nick uri str)
   (filter-map (λ (line) (str->msg nick uri line)) (str->lines str)))
 
This page took 0.037131 seconds and 4 git commands to generate.