[report-utilities] strify hash-table to Hash(kvp-list)

Hash tables are strified to "Hash()" "Hash(key=value,...)"
This commit is contained in:
Christopher Lam 2019-12-02 08:26:01 +08:00
parent 2333b6db27
commit ab20071d82
2 changed files with 24 additions and 7 deletions

View File

@ -1259,6 +1259,18 @@ flawed. see report-utilities.scm. please update reports.")
(gnc-lot-get-notes lot)
(gnc-lot-get-balance lot)
(gnc-lot-count-splits lot)))
(define (record->str rec)
(let ((rtd (record-type-descriptor rec)))
(define (fld->str fld)
(format #f "~a=~a" fld (gnc:strify ((record-accessor rtd fld) rec))))
(format #f "Rec:~a{~a}"
(record-type-name rtd)
(string-join (map fld->str (record-type-fields rtd)) ", "))))
(define (hash-table->str hash)
(string-append
"Hash(" (string-join
(hash-map->list (lambda (k v) (format #f "~a=~a" k v)) hash) ",")
")"))
(define (try proc)
;; Try proc with d as a parameter, catching exceptions to return
;; #f to the (or) evaluator below.
@ -1294,13 +1306,8 @@ flawed. see report-utilities.scm. please update reports.")
(try owner->str)
(try invoice->str)
(try lot->str)
(and (record? d)
(let ((rtd (record-type-descriptor d)))
(define (fld->str fld)
(format #f "~a=~a" fld (gnc:strify ((record-accessor rtd fld) d))))
(format #f "Rec:~a{~a}"
(record-type-name rtd)
(string-join (map fld->str (record-type-fields rtd)) ", "))))
(try hash-table->str)
(try record->str)
(object->string d)))
(define (pair->num pair)

View File

@ -152,6 +152,16 @@
(test-equal "gnc:strify <val-coll 10>"
"coll<10>"
(gnc:strify coll)))
(let ((ht (make-hash-table)))
(test-equal "gnc:strify Hash()"
"Hash()"
(gnc:strify ht))
(hash-set! ht 'one "uno")
(test-equal "gnc:strify Hash(one=uno)"
"Hash(one=uno)"
(gnc:strify ht)))
(test-end "debugging tools"))
(define (test-commodity-collector)