- (begin
- (log-debug "Non-msg line from nick:~a, line:~a" nick str)
- #f)
- (let ([toks (string-split str (regexp "\t+"))])
- (if (not (= 2 (length toks)))
- (begin
- (log-warning "Invalid msg line from nick:~a, msg:~a" nick str)
- #f)
- (let*
- ([ts_rfc3339 (first toks)]
- [text (second toks)]
- [t (string->rfc3339-record ts_rfc3339)]
- ; TODO handle tz offset
- [ts_epoch (find-seconds [rfc3339-record:second t]
- [rfc3339-record:minute t]
- [rfc3339-record:hour t]
- [rfc3339-record:mday t]
- [rfc3339-record:month t]
- [rfc3339-record:year t])])
- (msg ts_epoch ts_rfc3339 nick uri text))))))
+ (begin
+ (log-debug "Non-msg line from nick:~a, line:~a" nick str)
+ #f)
+ (let ([toks (string-split str (regexp "\t+"))])
+ (if (not (= 2 (length toks)))
+ (begin
+ (log-warning "Invalid msg line from nick:~a, msg:~a" nick str)
+ #f)
+ (let*
+ ([ts_rfc3339 (first toks)]
+ [text (second toks)]
+ [t (string->rfc3339-record ts_rfc3339)]
+ ; TODO handle tz offset
+ [ts_epoch (find-seconds [rfc3339-record:second t]
+ [rfc3339-record:minute t]
+ [rfc3339-record:hour t]
+ [rfc3339-record:mday t]
+ [rfc3339-record:month t]
+ [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-append ts tab text))]
+ [expected (msg 1605756129 ts nick uri text)])
+ ; FIXME re-enable after handling tz offset
+ ;(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")))