gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Tue Apr 23 06:53:49 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/d9623b0a (commit)
via https://github.com/Gnucash/gnucash/commit/4d8ef9b9 (commit)
from https://github.com/Gnucash/gnucash/commit/3815e17e (commit)
commit d9623b0ad1878e0f11d870cd3c47fa2f2fed12d1
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Apr 23 18:46:48 2019 +0800
[test-utilities] initial commit
Add tests for libgnucash/scm/utilities.scm functions
- tests for list<->vec
- tests for gnc:substring-replace
- tests for gnc:substring-replace-from-to
The latter confirms that the comment before the function definition
is *incorrect* - it describes that substring-replace-from-to will
start from the 2nd substring for the first substitution, and
performs 2 substitutions. However the comment illustrates only 1
substitution. The test suite performs the test according to code
behaviour, rather than the comment. This issue is moot in practice
because the end-after is always called with negative in the code
base.
original comment:
;; gnc:substring-replace-from-to
;; same as gnc:substring-replace extended by:
;; start: from which occurrence onwards the replacement shall start
;; end-after: max. number times the replacement should executed
;;
;; Example: (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 2)
;; returns "foobarfooxyzfoobar".
diff --git a/libgnucash/scm/test/test-utilities.scm b/libgnucash/scm/test/test-utilities.scm
new file mode 100644
index 000000000..8ee2f5975
--- /dev/null
+++ b/libgnucash/scm/test/test-utilities.scm
@@ -0,0 +1,63 @@
+(use-modules (gnucash gnc-module))
+(gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0))
+(use-modules (gnucash utilities))
+(use-modules (srfi srfi-64))
+(use-modules (gnucash engine test srfi64-extras))
+
+(define (run-test)
+ (test-runner-factory gnc:test-runner)
+ (test-begin "test-utilities.scm")
+ (test-traverse-vec)
+ (test-substring-replace)
+ (test-begin "test-utilities.scm"))
+
+(define (test-traverse-vec)
+ (test-begin "traverse-vec")
+ (test-equal "list->vec"
+ (vector 1 (vector 2 3))
+ (traverse-list->vec
+ (list 1 (list 2 3))))
+ (test-equal "vec->list"
+ (list 1 (list 2 3))
+ (traverse-vec->list
+ (vector 1 (vector 2 3))))
+ (test-end "traverse-vec"))
+
+(define (test-substring-replace)
+ (test-begin "substring-replace")
+
+ ;; generic gnc:substring-replace used in qif-guess-map.scm
+ (test-equal "gnc:substring-replace"
+ "fooxyzfooxyz"
+ (gnc:substring-replace "foobarfoobar" "bar" "xyz"))
+
+ ;; note the following 2 tests show the code was not coded according
+ ;; to the example in the comments.
+ (test-equal "gnc:substring-replace-from-to ... ... 2 2"
+ "foobarfooxyzfooxyz"
+ (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 2))
+
+ (test-equal "gnc:substring-replace-from-to ... ... 2 1"
+ "foobarfooxyzfoobar"
+ (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 1))
+
+ ;; comprehensive test suite for gnc:substring-replace-from-to:
+ (test-equal "gnc:substring-replace-from-to ... ... 2 1"
+ "foo xxx foo foo foo foo foo foo"
+ (gnc:substring-replace-from-to
+ "foo foo foo foo foo foo foo foo"
+ "foo" "xxx" 2 1))
+
+ (test-equal "gnc:substring-replace-from-to ... ... 1 1"
+ "xxx foo foo foo foo foo foo foo"
+ (gnc:substring-replace-from-to
+ "foo foo foo foo foo foo foo foo"
+ "foo" "xxx" 1 1))
+
+ (test-equal "gnc:substring-replace-from-to ... ... 4 -1"
+ "foo foo foo xxx xxx xxx xxx xxx"
+ (gnc:substring-replace-from-to
+ "foo foo foo foo foo foo foo foo"
+ "foo" "xxx" 4 -1))
+
+ (test-end "substring-replace"))
commit 4d8ef9b9e461157eaa8f5b19e0198d35e315088f
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Apr 23 06:38:48 2019 +0800
[report] inline args-to-defn
diff --git a/gnucash/report/report-system/report.scm b/gnucash/report/report-system/report.scm
index 5d6f1e874..b48acd828 100644
--- a/gnucash/report/report-system/report.scm
+++ b/gnucash/report/report-system/report.scm
@@ -119,16 +119,14 @@ not found.")))
;; set of options, and generates the report. the renderer must
;; return as its final value an <html-document> object.
- (define (args-to-defn)
- (let loop ((report-rec (make-report-template)) (args args))
- (cond
- ((null? args) report-rec)
- (else
- (let ((modifier (record-modifier <report-template> (car args))))
- (modifier report-rec (cadr args))
- (loop report-rec (cddr args)))))))
-
- (let* ((report-rec (args-to-defn))
+ (let* ((report-rec
+ (let loop ((report-rec (make-report-template)) (args args))
+ (cond
+ ((null? args) report-rec)
+ (else
+ ((record-modifier <report-template> (car args))
+ report-rec (cadr args))
+ (loop report-rec (cddr args))))))
(report-guid (gnc:report-template-report-guid report-rec))
(report-name (gnc:report-template-name report-rec)))
(cond
Summary of changes:
gnucash/report/report-system/report.scm | 18 +++++-----
libgnucash/scm/test/test-utilities.scm | 63 +++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 10 deletions(-)
create mode 100644 libgnucash/scm/test/test-utilities.scm
More information about the gnucash-changes
mailing list