b378f180 |
(in-package :cl-user)
(defpackage cl-yaml-test.parser
(:use :cl :fiveam)
|
5a0596e0 |
(:import-from :alexandria
:alist-hash-table)
|
bb4f27b9 |
(:export :parser)
(:documentation "Parser tests."))
|
b378f180 |
(in-package :cl-yaml-test.parser)
(def-suite parser
:description "YAML parser tests.")
(in-suite parser)
|
05b24c4d |
(defmacro define-test-cases ((name) &rest pairs)
`(test ,name
,@(loop for (string form) in pairs collecting
|
f7cc02da |
`(is (equal (second (yaml.parser:parse-string ,string))
|
05b24c4d |
,form)))))
(define-test-cases (special-scalars)
("[true, True, TRUE]"
(list t t t))
("[false, False, FALSE]"
(list nil nil nil))
("[null, Null, NULL, ~]"
(list nil nil nil nil)))
(define-test-cases (integers)
("1"
1)
("123456"
123456)
("0001"
1)
("-2"
-2)
("0o31" ;; The old OCT 31 = DEC 25 joke
25))
(define-test-cases (floats)
("6.62606957e-34"
6.62607e-34))
|
3569832d |
(define-test-cases (strings)
("test" "test")
("\"test\"" "test")
("€" "€")
("€1234" "€1234"))
|
05b24c4d |
(define-test-cases (lists)
("[a, b, c]"
(list "a" "b" "c"))
("[1, 2, 3]"
(list 1 2 3)))
(define-test-cases (nested-lists)
;; Right-nested list
("[1, [2, [3]]]"
(list 1 (list 2 (list 3))))
;; Left-nested list
("[[[1], 2], 3]"
(list (list (list 1) 2) 3))
;; Mid-centered list
("[1, [2, [3], 4], 5]"
(list 1 (list 2 (list 3) 4) 5)))
|
44244d05 |
(test top-level-parsing
(let ((data (yaml:parse "[1,2,3]")))
(is
(equal data
(list 1 2 3)))))
|
0d0901cc |
|
56a102e0 |
(test hash-tables
(let ((data (yaml:parse "{ a: 1, b: 2}")))
(is
(equal (hash-table-count data)
2))
(is-false
(set-difference (alexandria:hash-table-keys data)
(list "a" "b")
:test #'equal))
(is-false
(set-difference (alexandria:hash-table-values data)
(list 1 2)))))
|
0d0901cc |
(test parsing-errors
(signals yaml.error:parsing-error
(yaml:parse "[1,2,3")))
|
af1f1446 |
|
56a102e0 |
(test parse-file
|
af1f1446 |
(is
(equal (yaml:parse (asdf:system-relative-pathname :cl-yaml #p"t/test.yaml"))
(list 1 2 3))))
|