fix: date-only timestamp parsing
This commit is contained in:
parent
e3400352bb
commit
c966b0e022
7 changed files with 435 additions and 450 deletions
105
tests/run.scm
105
tests/run.scm
|
@ -1,67 +1,52 @@
|
||||||
(import (r7rs)
|
(import (r7rs)
|
||||||
(scheme base)
|
(test)
|
||||||
(scheme write)
|
|
||||||
(srfi 64)
|
|
||||||
(srfi 152)
|
|
||||||
(rfc3339)
|
(rfc3339)
|
||||||
(toml))
|
(toml))
|
||||||
|
|
||||||
(define (tap-test-runner)
|
(test-group "Basic"
|
||||||
(let ((runner (test-runner-null))
|
(let ((tdat (table-from-file "basic.toml")))
|
||||||
(testcounter 0))
|
(test "7 Key-Value-Pairs"
|
||||||
(display "TAP version 13\n")
|
7 (toml-count-key-vals tdat))
|
||||||
(test-runner-on-test-end! runner
|
(test "Field name is TOML"
|
||||||
(lambda (runner)
|
"TOML" (toml-string tdat "name"))
|
||||||
(set! testcounter (+ testcounter 1))
|
(test "Field language is Chicken Scheme"
|
||||||
(display
|
"Chicken Scheme" (toml-string tdat "language"))
|
||||||
(string-append
|
(test "has-bool is #t"
|
||||||
(if (test-passed? runner) "ok " "not ok ")
|
#t (toml-bool tdat "has-bool"))
|
||||||
(number->string testcounter) " - "
|
(test "int is 5"
|
||||||
(string-join (test-runner-group-path runner) " - ")
|
5 (toml-int tdat "int"))
|
||||||
" - " (test-runner-test-name runner)
|
(test "double is 10.8"
|
||||||
(if (eq? 'skip (test-result-kind runner)) "# SKIP" "")
|
10.8 (toml-double tdat "double"))
|
||||||
"\n"))))
|
(test "timestamp parsing"
|
||||||
(test-runner-on-final! runner
|
#(1979 05 27 07 32 00 0.0 0)
|
||||||
(lambda (runner)
|
(rfc3339->vector (toml-timestamp tdat "timestamp")))))
|
||||||
(display (string-append "1.." (number->string testcounter) "\n"))))
|
|
||||||
runner))
|
|
||||||
|
|
||||||
(test-runner-factory
|
(test-group "Table"
|
||||||
(lambda () (tap-test-runner)))
|
(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-begin "Basic")
|
(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))))
|
||||||
|
|
||||||
(let ((tdat (table-from-file "basic.toml")))
|
(test-exit)
|
||||||
(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")
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
[server]
|
[server]
|
||||||
host = "www.example.com"
|
host = "www.example.com"
|
||||||
port = [ 8080, 8181, 8282 ]
|
port = [ 8080, 8181, 8282 ]
|
||||||
|
timestamp = 2022-09-09
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
(int index))
|
(int index))
|
||||||
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
|
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
|
||||||
"toml_timestamp_t* stamp = datum.u.ts;"
|
"toml_timestamp_t* stamp = datum.u.ts;"
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
|
||||||
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
||||||
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
||||||
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
||||||
|
@ -106,11 +106,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define (table-from-file filename)
|
(define (table-from-file filename)
|
||||||
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
|
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
|
||||||
"FILE* fp = fopen(fname, \"r\");"
|
"FILE* fp = fopen(fname, \"r\");"
|
||||||
|
@ -209,7 +204,7 @@
|
||||||
(c-string key))
|
(c-string key))
|
||||||
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
|
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
|
||||||
"toml_timestamp_t* stamp = datum.u.ts;"
|
"toml_timestamp_t* stamp = datum.u.ts;"
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
|
||||||
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
||||||
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
||||||
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
||||||
|
|
2
toml.egg
2
toml.egg
|
@ -5,7 +5,7 @@
|
||||||
(license "MIT")
|
(license "MIT")
|
||||||
(version "0.6")
|
(version "0.6")
|
||||||
(dependencies r7rs rfc3339 coops)
|
(dependencies r7rs rfc3339 coops)
|
||||||
(test-dependencies srfi-64 srfi-152)
|
(test-dependencies test)
|
||||||
|
|
||||||
(components
|
(components
|
||||||
(c-object tomlc99/toml
|
(c-object tomlc99/toml
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
;; -*- Scheme -*-
|
||||||
(repo git "https://gitea.lyrion.ch/zilti/toml.git")
|
(repo git "https://gitea.lyrion.ch/zilti/toml.git")
|
||||||
(uri targz "https://gitea.lyrion.ch/zilti/toml/archive/{egg-release}.tar.gz")
|
(uri targz "https://gitea.lyrion.ch/zilti/toml/archive/{egg-release}.tar.gz")
|
||||||
(release "0.6")
|
(release "0.6")
|
||||||
|
|
|
@ -88,6 +88,9 @@ The repository of the Chicken wrapper can be found at [[https://gitea.lyrion.ch/
|
||||||
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
|
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
|
||||||
|
|
||||||
=== Version History
|
=== Version History
|
||||||
|
|
||||||
|
; 0.7 : fixed an issue with timestamp parsing
|
||||||
|
|
||||||
; 0.6 : first version of the wrapper
|
; 0.6 : first version of the wrapper
|
||||||
|
|
||||||
=== License
|
=== License
|
||||||
|
|
Loading…
Reference in a new issue