gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri Oct 8 22:27:03 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/0bce6a1d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3ff5bd82 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f4941a5b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e5027f91 (commit)
	from  https://github.com/Gnucash/gnucash/commit/7692027b (commit)



commit 0bce6a1d56857436af6060da8555e8696fed7796
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Oct 6 09:19:14 2021 +0800

    [core-utils] introduce gnc:format
    
    (gnc:format str [binding value]...)
    
    str will contain ${binding} which will be replaced to value.

diff --git a/bindings/guile/core-utils.scm b/bindings/guile/core-utils.scm
index 7b360cb81..d1bc46af6 100644
--- a/bindings/guile/core-utils.scm
+++ b/bindings/guile/core-utils.scm
@@ -32,6 +32,7 @@
 (use-modules (srfi srfi-26))
 (use-modules (ice-9 match))
 (use-modules (ice-9 i18n))
+(use-modules (ice-9 regex))
 
 (export N_)
 (export G_)
@@ -41,6 +42,7 @@
 (export gnc:string-locale<?)
 (export gnc:string-locale>?)
 (export gnc:version)
+(export gnc:format)
 
 ;; loads modules and re-exports all its public interface into the
 ;; current module
@@ -107,3 +109,16 @@
     (_ (default-printer))))
 
 (set-exception-printer! 'unbound-variable print-unbound-variable-error)
+
+;; format.
+(define %regex (make-regexp "[$][{]([[:alnum:]]+)[}]"))
+(define (gnc:format str . bindings)
+  (define hash (make-hash-table))
+  (define (substitute m)
+    (or (hashq-ref hash (string->symbol (match:substring m 1)))
+        (warn "invalid identifier" (match:substring m 0))))
+  (let lp ((bindings bindings))
+    (match bindings
+      (() (regexp-substitute/global #f %regex str 'pre substitute 'post))
+      (((? symbol? k) v . rest) (hashq-set! hash k (format #f "~a" v)) (lp rest))
+      (_ (error "gnc:format syntax error")))))
diff --git a/bindings/guile/test/test-core-utils.scm b/bindings/guile/test/test-core-utils.scm
index 2d0b0cfae..c36734c18 100644
--- a/bindings/guile/test/test-core-utils.scm
+++ b/bindings/guile/test/test-core-utils.scm
@@ -13,8 +13,37 @@
     "foobar"
     (N_ "foobar")))
 
+(define (gnc-format-tests)
+  (test-equal "null"
+    ""
+    (gnc:format ""))
+
+  (test-equal "basic"
+    "basic"
+    (gnc:format "basic"))
+
+  (test-equal "basic with unused symbols"
+    "basic"
+    (gnc:format "basic" 'task "testing"))
+
+  (test-equal "one substitution"
+    "basic test"
+    (gnc:format "basic ${job}" 'job "test"))
+
+  (test-equal "two substitutions out of order"
+    "basic test"
+    (gnc:format "${difficulty} ${job}" 'job "test" 'difficulty "basic"))
+
+  (test-equal "trying to reference invalid symbol"
+    "${symbol} does not exist"
+    (gnc:format "${symbol} does not exist" 'existence "none"))
+
+  (test-error "gnc:format syntax error"
+    (gnc:format "${symbol} does not exist" 'existence)))
+
 (define (run-test)
   (test-runner-factory gnc:test-runner)
   (test-begin "test-core-utils")
   (N_-tests)
+  (gnc-format-tests)
   (test-end "test-core-utils"))

commit 3ff5bd824618aabfcfdbb0fdaafbe5aad1b578ad
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Oct 7 09:37:24 2021 +0800

    [test-core-utils] uses srfi-64

diff --git a/bindings/guile/test/CMakeLists.txt b/bindings/guile/test/CMakeLists.txt
index 904f9baca..ee48e6f49 100644
--- a/bindings/guile/test/CMakeLists.txt
+++ b/bindings/guile/test/CMakeLists.txt
@@ -25,7 +25,6 @@ gnc_add_test_with_guile(test-scm-query test-scm-query.cpp ENGINE_TEST_INCLUDE_DI
 
 
 set(bindings_test_SCHEME
-    test-core-utils.scm
     test-create-account.scm
 )
 
@@ -59,6 +58,7 @@ add_dependencies(check scm-test-engine)
 gnc_add_scheme_tests("${engine_test_SCHEME}")
 
 set (scm_tests_with_srfi64_SOURCES
+  test-core-utils.scm
   test-business-core.scm
   test-scm-engine.scm
   )
diff --git a/bindings/guile/test/test-core-utils.scm b/bindings/guile/test/test-core-utils.scm
index 5de9dd0ff..2d0b0cfae 100644
--- a/bindings/guile/test/test-core-utils.scm
+++ b/bindings/guile/test/test-core-utils.scm
@@ -1,17 +1,20 @@
-(define exit-code 0)
 (setenv "GNC_UNINSTALLED" "1")
+
+(use-modules (srfi srfi-64))
+(use-modules (tests srfi64-extras))
 (use-modules (gnucash core-utils))
 
-(if (procedure? (module-ref (current-module) 'N_))
-    (display "N_ defined\n")
-    (begin
-      (display "Failed - N_ not defined\n")
-      (set! exit-code -1)))
+(define (N_-tests)
+
+  (test-assert "N_ defined"
+    (module-ref (current-module) 'N_))
 
-(if (string=? (N_ "foobar") "foobar")
-    (display "N_ works properly\n")
-    (begin
-      (display "Failed - N_ doesn't work\n")
-      (set! exit-code -1)))
+  (test-equal "N_ works properly"
+    "foobar"
+    (N_ "foobar")))
 
-(exit exit-code)
+(define (run-test)
+  (test-runner-factory gnc:test-runner)
+  (test-begin "test-core-utils")
+  (N_-tests)
+  (test-end "test-core-utils"))

commit f4941a5b01939aad152a36dc8deb6ef0a031ad9e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 9 10:24:45 2021 +0800

    use g_list_free_full

diff --git a/bindings/guile/gnc-engine-guile.c b/bindings/guile/gnc-engine-guile.c
index 45a69ec24..3873e0ea3 100644
--- a/bindings/guile/gnc-engine-guile.c
+++ b/bindings/guile/gnc-engine-guile.c
@@ -331,15 +331,10 @@ gnc_scm2guid_glist (SCM guids_scm)
     return g_list_reverse (guids);
 }
 
-static void
+static inline void
 gnc_guid_glist_free (GList *guids)
 {
-    GList *node;
-
-    for (node = guids; node; node = node->next)
-        guid_free (node->data);
-
-    g_list_free (guids);
+    g_list_free_full (guids, guid_free);
 }
 
 static SCM
diff --git a/gnucash/gnome/dialog-tax-info.c b/gnucash/gnome/dialog-tax-info.c
index fcd0a3dc7..6b342adf9 100644
--- a/gnucash/gnome/dialog-tax-info.c
+++ b/gnucash/gnome/dialog-tax-info.c
@@ -168,7 +168,7 @@ initialize_getters (void)
 }
 
 static void
-destroy_tax_type_info (gpointer data, gpointer user_data)
+destroy_tax_type_info (gpointer data)
 {
     TaxTypeInfo *tax_type = data;
 
@@ -187,15 +187,14 @@ destroy_tax_type_info (gpointer data, gpointer user_data)
     g_free (tax_type);
 }
 
-static void
+static inline void
 destroy_tax_type_infos (GList *types)
 {
-    g_list_foreach (types, destroy_tax_type_info, NULL);
-    g_list_free (types);
+    g_list_free_full (types, destroy_tax_type_info);
 }
 
 static void
-destroy_txf_info (gpointer data, gpointer user_data)
+destroy_txf_info (gpointer data)
 {
     TXFInfo *txf_info = data;
 
@@ -217,11 +216,10 @@ destroy_txf_info (gpointer data, gpointer user_data)
     g_free (txf_info);
 }
 
-static void
+static inline void
 destroy_txf_infos (GList *infos)
 {
-    g_list_foreach (infos, destroy_txf_info, NULL);
-    g_list_free (infos);
+    g_list_free_full (infos, destroy_txf_info);
 }
 
 static void

commit e5027f91cbf2c0fa6edb5f20e2cbf4d2fa480162
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Oct 8 22:48:42 2021 +0800

    [test-transaction] option has been renamed

diff --git a/gnucash/report/reports/standard/test/test-transaction.scm b/gnucash/report/reports/standard/test/test-transaction.scm
index 5ea03413e..bb7df2156 100644
--- a/gnucash/report/reports/standard/test/test-transaction.scm
+++ b/gnucash/report/reports/standard/test/test-transaction.scm
@@ -378,19 +378,19 @@
       (set! options (default-testing-options))
       (set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 01 01 1969)))
       (set-option! options "General" "End Date" (cons 'absolute (gnc-dmy2time64 31 12 1970)))      
-      (set-option! options "Filter" "Reconcile Status" 'unreconciled)
+      (set-option! options "Filter" "Reconciled Status" 'unreconciled)
       (let ((sxml (options->sxml options "unreconciled")))
         (test-equal "filter unreconciled only, sum = -$20.00"
           '("-$20.00")
           (get-row-col sxml -1 -1)))
 
-      (set-option! options "Filter" "Reconcile Status" 'cleared)
+      (set-option! options "Filter" "Reconciled Status" 'cleared)
       (let ((sxml (options->sxml options "cleared")))
         (test-equal "filter cleared only, sum = $29.00"
           '("$29.00")
           (get-row-col sxml -1 -1)))
 
-      (set-option! options "Filter" "Reconcile Status" 'reconciled)
+      (set-option! options "Filter" "Reconciled Status" 'reconciled)
       (let ((sxml (options->sxml options "reconciled")))
         (test-equal "filter reconciled only, sum = -$8.00"
           '("-$8.00")



Summary of changes:
 bindings/guile/core-utils.scm                      | 15 ++++++
 bindings/guile/gnc-engine-guile.c                  |  9 +---
 bindings/guile/test/CMakeLists.txt                 |  2 +-
 bindings/guile/test/test-core-utils.scm            | 56 +++++++++++++++++-----
 gnucash/gnome/dialog-tax-info.c                    | 14 +++---
 .../reports/standard/test/test-transaction.scm     |  6 +--
 6 files changed, 71 insertions(+), 31 deletions(-)



More information about the gnucash-changes mailing list