fix: date-only timestamp parsing
This commit is contained in:
parent
e3400352bb
commit
c966b0e022
7 changed files with 435 additions and 450 deletions
|
@ -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))
|
|
||||||
(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")))
|
(let ((tdat (table-from-file "basic.toml")))
|
||||||
(test-equal 2 (toml-count-key-vals tdat))
|
(test "7 Key-Value-Pairs"
|
||||||
(test-equal "TOML" (toml-string tdat "name"))
|
7 (toml-count-key-vals tdat))
|
||||||
(test-equal "Chicken Scheme" (toml-string tdat "language"))
|
(test "Field name is TOML"
|
||||||
(test-equal #t (toml-bool tdat "has-bool"))
|
"TOML" (toml-string tdat "name"))
|
||||||
(test-equal 5 (toml-int tdat "int"))
|
(test "Field language is Chicken Scheme"
|
||||||
(test-equal 10.8 (toml-double tdat "double"))
|
"Chicken Scheme" (toml-string tdat "language"))
|
||||||
(test-equal (rfc3339->string (vector->rfc3339 #(1979 05 27 07 32 00 0 0)))
|
(test "has-bool is #t"
|
||||||
(rfc3339->string (toml-timestamp tdat "timestamp"))))
|
#t (toml-bool tdat "has-bool"))
|
||||||
|
(test "int is 5"
|
||||||
(test-end "Basic")
|
5 (toml-int tdat "int"))
|
||||||
|
(test "double is 10.8"
|
||||||
(test-begin "Table")
|
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")))
|
(let ((tdat (table-from-file "table.toml")))
|
||||||
(test-equal 0 (toml-count-key-vals tdat))
|
(test "No top-level Key-Value-Pairs"
|
||||||
(test-equal 1 (toml-count-tables tdat))
|
0 (toml-count-key-vals tdat))
|
||||||
|
(test "One top-level table"
|
||||||
|
1 (toml-count-tables tdat))
|
||||||
(let ((servertbl (toml-table tdat "server")))
|
(let ((servertbl (toml-table tdat "server")))
|
||||||
(test-equal 1 (toml-count-key-vals servertbl))
|
(test "\"server\" table has 2 Key-Value-Pairs"
|
||||||
(test-equal "www.example.com" (toml-string servertbl "host"))))
|
2 (toml-count-key-vals servertbl))
|
||||||
|
(test "host is www.example.com"
|
||||||
(test-end "Table")
|
"www.example.com" (toml-string servertbl "host"))
|
||||||
|
(test "timestamp parsing"
|
||||||
(test-begin "Array")
|
#(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"))
|
(let* ((tdat (table-from-file "table.toml"))
|
||||||
(tserv (toml-table tdat "server"))
|
(tserv (toml-table tdat "server"))
|
||||||
(tarr (toml-array tserv "port")))
|
(tarr (toml-array tserv "port")))
|
||||||
(test-equal 1 (toml-count-arrays tserv))
|
(test "There is one array"
|
||||||
(test-equal 3 (toml-count-entries tarr))
|
1 (toml-count-arrays tserv))
|
||||||
(test-equal 8080 (toml-int tarr 0))
|
(test "The array has three entries"
|
||||||
(test-equal 8282 (toml-int tarr 2)))
|
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-end "Array")
|
(test-exit)
|
||||||
|
|
|
@ -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