utils.lisp (1489B)
1 (uiop:define-package #:aoc-test/utils 2 (:use #:cl) 3 (:mix #:lisp-unit2 #:aoc/utils)) 4 (in-package #:aoc-test/utils) 5 6 (define-test test-read-input 7 () 8 (with-input-from-string (stream "hello 9 world") 10 (assert-equalp '("hello" "world") 11 (read-input stream))) 12 (with-input-from-string (stream "1 13 2 14 3 15 16 3 17 2 18 1") 19 (assert-equalp '(1 2 3 nil 3 2 1) 20 (read-input stream :type 'integer))) 21 (with-input-from-string (stream "this 22 does 23 not 24 matter") 25 (assert-equalp '(1 1 1 1) 26 (read-input stream :type (lambda (line) 27 (declare (ignore line)) 28 1))))) 29 30 (define-test test-read-input-fields 31 () 32 (with-input-from-string (stream "A 1 33 B 2 34 C 3 35 D 36 E 5 37 38 G 7") 39 (assert-equalp '(("A" 1) 40 ("B" 2) 41 ("C" 3) 42 ("D" nil) 43 ("E" 5) 44 (nil nil) 45 ("G" 7)) 46 (read-input-fields stream '(string integer))))) 47 48 (define-test test-read-input-match 49 () 50 (with-input-from-string (stream "x: 1, y: 2 51 x: 3, y: 4 52 x: 2, y: 5") 53 (assert-equalp '(("x" 1 "y" 2) 54 ("x" 3 "y" 4) 55 ("x" 2 "y" 5)) 56 (read-input-match stream 57 "(\\w+): (\\d+), (\\w+): (\\d+)" 58 :types '(string integer string integer)))))