git.fiddlerwoaroof.com
Browse code

Add some unit tests

Fernando Borretti authored on 26/09/2013 02:29:19
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+(defsystem cl-yaml-test
2
+  :author "Fernando Borretti"
3
+  :license "MIT"
4
+  :depends-on (:cl-yaml
5
+               :fiveam)
6
+  :components ((:module "t"
7
+                :components
8
+                ((:file "cl-yaml"))))
9
+  :perform (load-op :after (op c) (asdf:clear-system c)))
0 10
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+(defpackage cl-yaml-test
2
+  (:use :cl
3
+        :fiveam
4
+        :cffi
5
+        :yaml))
6
+(in-package :cl-yaml-test)
7
+
8
+(def-suite basic
9
+  :description "firing up a parser, setting input to something, etc.")
10
+
11
+(test (string-input nil basic)
12
+  (is (yaml::with-string-input "derp" 4)))
13
+
14
+(def-suite list
15
+  :description "Parsing lists")
16
+
17
+(test (flat-int nil list)
18
+  (is (equal (yaml:parse "[1,2,3]") (list 1 2 3))))
19
+
20
+(test (flat-str nil list)
21
+  (is (equal (yaml:parse "[\"foo\",\"bar\"]") (list "foo" "bar"))))
22
+
23
+(test (nested nil list)
24
+  (is (equal (yaml:parse "[[a,1],[b,2],[c,3]]") (list (list "a" 1)
25
+						      (list "b" 2)
26
+						      (list "c" 3)))))
27
+
28
+(def-suite map
29
+  :description "Parsing maps")
30
+
31
+(test (flat-map nil map)
32
+  (is (equal (yaml:parse "{a : 1, b : 2, c : 3}")
33
+	     (let ((hash (make-hash-table :test #'equalp)))
34
+	       (setf (gethash "a" hash) 1
35
+		     (gethash "b" hash) 2
36
+		     (gethash "c" hash) 3)
37
+	       hash))))
38
+
39
+(run!)