From 908e7042604599caa19c3d7e607a72b60f686ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 28 Oct 2023 23:37:44 +0200 Subject: Add tests for '(hnh test util)'. --- module/hnh/test/util.scm | 3 ++- tests/unit/util/test-util.scm | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/unit/util/test-util.scm diff --git a/module/hnh/test/util.scm b/module/hnh/test/util.scm index b0f3342a..ba0f8bfb 100644 --- a/module/hnh/test/util.scm +++ b/module/hnh/test/util.scm @@ -38,7 +38,8 @@ (define (string-replace-head s1 s2) (string-replace s1 s2 - 0 (string-length s2))) + 0 (min (string-length s1) + (string-length s2)))) (define diff-cmd diff --git a/tests/unit/util/test-util.scm b/tests/unit/util/test-util.scm new file mode 100644 index 00000000..d5853c95 --- /dev/null +++ b/tests/unit/util/test-util.scm @@ -0,0 +1,45 @@ +(define-module (test test-util) + :use-module (srfi srfi-64) + :use-module (srfi srfi-64 test-error) + :use-module (srfi srfi-88) + :use-module (hnh test util)) + +(test-equal "µs" #e2e6 (µs 2)) + +(test-equal "transform-time-of-day" + 1698494486139313 + (transform-time-of-day + ;; As returned by (gettimeofday) + '(1698494486 . 139313))) + +;; green +;; red +;; yellow +;; bold +;; make-indent + +(test-equal "Indent" + " " + (make-indent 4)) + +(test-equal "" (string-replace-head "" "")) +(test-equal "H" (string-replace-head "" "H")) +(test-equal "TAIL" (string-replace-head "TAIL" "")) +(test-equal "HAIL" (string-replace-head "TAIL" "H")) + + +;;; This is far from perfect +(test-assert "Is some form of diff produced" + (string? + (diff + "This is the +first +string. +" + "This is the +second +string. +"))) + + +'((hnh test util)) -- cgit v1.2.3