mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
[report-utilities] strify hash-table to Hash(kvp-list)
Hash tables are strified to "Hash()" "Hash(key=value,...)"
This commit is contained in:
parent
2333b6db27
commit
ab20071d82
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user