toml/tests/run.scm

68 lines
2.0 KiB
Scheme

(import (r7rs)
(scheme base)
(scheme write)
(srfi 64)
(srfi 152)
(rfc3339)
(toml))
(define (tap-test-runner)
(let ((runner (test-runner-null))
(testcounter 0))
(display "TAP version 13\n")
(test-runner-on-test-end! runner
(lambda (runner)
(set! testcounter (+ testcounter 1))
(display
(string-append
(if (test-passed? runner) "ok " "not ok ")
(number->string testcounter) " - "
(string-join (test-runner-group-path runner) " - ")
" - " (test-runner-test-name runner)
(if (eq? 'skip (test-result-kind runner)) "# SKIP" "")
"\n"))))
(test-runner-on-final! runner
(lambda (runner)
(display (string-append "1.." (number->string testcounter) "\n"))))
runner))
(test-runner-factory
(lambda () (tap-test-runner)))
(test-begin "Basic")
(let ((tdat (table-from-file "basic.toml")))
(test-equal 2 (toml-count-key-vals tdat))
(test-equal "TOML" (toml-string tdat "name"))
(test-equal "Chicken Scheme" (toml-string tdat "language"))
(test-equal #t (toml-bool tdat "has-bool"))
(test-equal 5 (toml-int tdat "int"))
(test-equal 10.8 (toml-double tdat "double"))
(test-equal (rfc3339->string (vector->rfc3339 #(1979 05 27 07 32 00 0 0)))
(rfc3339->string (toml-timestamp tdat "timestamp"))))
(test-end "Basic")
(test-begin "Table")
(let ((tdat (table-from-file "table.toml")))
(test-equal 0 (toml-count-key-vals tdat))
(test-equal 1 (toml-count-tables tdat))
(let ((servertbl (toml-table tdat "server")))
(test-equal 1 (toml-count-key-vals servertbl))
(test-equal "www.example.com" (toml-string servertbl "host"))))
(test-end "Table")
(test-begin "Array")
(let* ((tdat (table-from-file "table.toml"))
(tserv (toml-table tdat "server"))
(tarr (toml-array tserv "port")))
(test-equal 1 (toml-count-arrays tserv))
(test-equal 3 (toml-count-entries tarr))
(test-equal 8080 (toml-int tarr 0))
(test-equal 8282 (toml-int tarr 2)))
(test-end "Array")