mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55: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-notes lot)
|
||||||
(gnc-lot-get-balance lot)
|
(gnc-lot-get-balance lot)
|
||||||
(gnc-lot-count-splits 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)
|
(define (try proc)
|
||||||
;; Try proc with d as a parameter, catching exceptions to return
|
;; Try proc with d as a parameter, catching exceptions to return
|
||||||
;; #f to the (or) evaluator below.
|
;; #f to the (or) evaluator below.
|
||||||
@ -1294,13 +1306,8 @@ flawed. see report-utilities.scm. please update reports.")
|
|||||||
(try owner->str)
|
(try owner->str)
|
||||||
(try invoice->str)
|
(try invoice->str)
|
||||||
(try lot->str)
|
(try lot->str)
|
||||||
(and (record? d)
|
(try hash-table->str)
|
||||||
(let ((rtd (record-type-descriptor d)))
|
(try record->str)
|
||||||
(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)) ", "))))
|
|
||||||
(object->string d)))
|
(object->string d)))
|
||||||
|
|
||||||
(define (pair->num pair)
|
(define (pair->num pair)
|
||||||
|
@ -152,6 +152,16 @@
|
|||||||
(test-equal "gnc:strify <val-coll 10>"
|
(test-equal "gnc:strify <val-coll 10>"
|
||||||
"coll<10>"
|
"coll<10>"
|
||||||
(gnc:strify coll)))
|
(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"))
|
(test-end "debugging tools"))
|
||||||
|
|
||||||
(define (test-commodity-collector)
|
(define (test-commodity-collector)
|
||||||
|
Loading…
Reference in New Issue
Block a user