toml/tests/run.scm

53 lines
1.7 KiB
Scheme

(import (r7rs)
(test)
(rfc3339)
(toml))
(test-group "Basic"
(let ((tdat (table-from-file "basic.toml")))
(test "7 Key-Value-Pairs"
7 (toml-count-key-vals tdat))
(test "Field name is TOML"
"TOML" (toml-string tdat "name"))
(test "Field language is Chicken Scheme"
"Chicken Scheme" (toml-string tdat "language"))
(test "has-bool is #t"
#t (toml-bool tdat "has-bool"))
(test "int is 5"
5 (toml-int tdat "int"))
(test "double is 10.8"
10.8 (toml-double tdat "double"))
(test "timestamp parsing"
#(1979 05 27 07 32 00 0.0 0)
(rfc3339->vector (toml-timestamp tdat "timestamp")))))
(test-group "Table"
(let ((tdat (table-from-file "table.toml")))
(test "No top-level Key-Value-Pairs"
0 (toml-count-key-vals tdat))
(test "One top-level table"
1 (toml-count-tables tdat))
(let ((servertbl (toml-table tdat "server")))
(test "\"server\" table has 2 Key-Value-Pairs"
2 (toml-count-key-vals servertbl))
(test "host is www.example.com"
"www.example.com" (toml-string servertbl "host"))
(test "timestamp parsing"
#(2022 09 09 0 0 0 0.0 0)
(rfc3339->vector (toml-timestamp servertbl "timestamp"))))))
(test-group "Array"
(let* ((tdat (table-from-file "table.toml"))
(tserv (toml-table tdat "server"))
(tarr (toml-array tserv "port")))
(test "There is one array"
1 (toml-count-arrays tserv))
(test "The array has three entries"
3 (toml-count-entries tarr))
(test "Element 0 is 8080"
8080 (toml-int tarr 0))
(test "Element 2 is 8282"
8282 (toml-int tarr 2))))
(test-exit)