[report-utilities] fix gnc:strify

Try monetary-collector and value-collector printers earlier; output is
fixed and will be "coll<([$200.00])>" for commodity-collectors or
"coll<23>" for value-collectors
This commit is contained in:
Christopher Lam 2019-07-14 21:20:52 +08:00
parent 8adcacbdd2
commit 75d5d8106b
2 changed files with 28 additions and 11 deletions

View File

@ -1098,21 +1098,20 @@ flawed. see report-utilities.scm. please update reports.")
(define (account->str acc)
(format #f "Acc<~a>" (xaccAccountGetName acc)))
(define (monetary-collector->str coll)
(format #f "Mon-coll<~a>"
(format #f "coll<~a>"
(map gnc:strify (coll 'format gnc:make-gnc-monetary #f))))
(define (value-collector->str coll)
(format #f "Val-coll<~a>"
(map gnc:strify (coll 'total gnc:make-gnc-monetary))))
(format #f "coll<~a>" (coll 'total #f)))
(define (procedure->str proc)
(format #f "Proc<~a>"
(or (procedure-name proc) "unk")))
(define (monetary->string mon)
(format #f "Mon<~a>"
(format #f "[~a]"
(gnc:monetary->string mon)))
(define (try proc)
;; Try proc with d as a parameter, catching 'wrong-type-arg
;; exceptions to return #f to the (or) evaluator below.
(catch 'wrong-type-arg
;; Try proc with d as a parameter, catching exceptions to return
;; #f to the (or) evaluator below.
(catch #t
(lambda () (proc d))
(const #f)))
(or (and (boolean? d) (if d "#t" "#f"))
@ -1128,13 +1127,13 @@ flawed. see report-utilities.scm. please update reports.")
(if (eq? (car d) 'absolute)
(qof-print-date (cdr d))
(gnc:strify (cdr d)))))
(try monetary-collector->str)
(try value-collector->str)
(try procedure->str)
(try gnc-commodity-get-mnemonic)
(try account->str)
(try split->str)
(try trans->str)
(try monetary-collector->str)
(try value-collector->str)
(try monetary->string)
(try gnc-budget-get-name)
(object->string d)))

View File

@ -130,8 +130,26 @@
"('a . 2)"
(gnc:strify (cons 'a 2)))
(test-equal "gnc:strify cons"
"Proc<cons>"
(gnc:strify cons))
"Proc<identity>"
(gnc:strify identity))
(let ((coll (gnc:make-commodity-collector)))
(test-equal "gnc:strify <mon-coll>"
"coll<()>"
(gnc:strify coll))
(coll 'add (gnc-commodity-table-lookup
(gnc-commodity-table-get-table
(gnc-get-current-book)) "CURRENCY" "USD") 10)
(test-equal "gnc:strify <mon-coll $10>"
"coll<([$10.00])>"
(gnc:strify coll)))
(let ((coll (gnc:make-value-collector)))
(test-equal "gnc:strify <val-coll 0>"
"coll<0>"
(gnc:strify coll))
(coll 'add 10)
(test-equal "gnc:strify <val-coll 10>"
"coll<10>"
(gnc:strify coll)))
(test-end "debugging tools"))
(define (test-commodity-collector)