From 3c6bd65e402655aacb9dfd8e2edeb95563f3ccda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 11 Feb 2023 03:27:57 +0100 Subject: Add test for path-append without components. --- tests/test/util.scm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index ab50898a..719afbed 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -254,6 +254,8 @@ (test-equal "root" "/" (path-append "")) +(test-equal "No components" "" (path-append)) + (test-equal '("usr" "lib" "test") (path-split "usr/lib/test")) -- cgit v1.2.3 From 01987c093e2cfbd46115cc58e4ff9f789efb9d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 7 Sep 2023 18:03:40 +0200 Subject: Enable let-env to unset variables. --- tests/test/let-env.scm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test') diff --git a/tests/test/let-env.scm b/tests/test/let-env.scm index e3dc5927..a989776a 100644 --- a/tests/test/let-env.scm +++ b/tests/test/let-env.scm @@ -41,3 +41,8 @@ (getenv "CALP_TEST_ENV")) +(test-group "Unsetting environment" + (setenv "TEST" "A") + (let-env ((TEST #f)) + (test-assert (not (getenv "TEST")))) + (test-equal "A" (getenv "TEST"))) -- cgit v1.2.3 From a2c3802be5301048fb899bc51b8935943daf73fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 7 Sep 2023 18:04:27 +0200 Subject: Add documentation and tests for xdg basedir. --- tests/test/xdg-basedir.scm | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/test/xdg-basedir.scm (limited to 'tests/test') diff --git a/tests/test/xdg-basedir.scm b/tests/test/xdg-basedir.scm new file mode 100644 index 00000000..682c1347 --- /dev/null +++ b/tests/test/xdg-basedir.scm @@ -0,0 +1,58 @@ +(define-module (test xdg-basedir) + :use-module (srfi srfi-64) + :use-module ((xdg basedir) :prefix xdg-) + :use-module (srfi srfi-88) + :use-module ((hnh util env) :select (let-env)) + ) + + +(let-env ((HOME "/home/user") + (XDG_DATA_HOME #f) + (XDG_CONFIG_HOME #f) + (XDG_STATE_HOME #f) + (XDG_DATA_DIRS #f) + (XDG_CONFIG_DIRS #f) + (XDG_CACHE_HOME #f) + (XDG_RUNTIME_DIR #f)) + (test-group "Defaults" + (test-equal "XDG_DATA_HOME" "/home/user/.local/share" + (xdg-data-home)) + (test-equal "XDG_CONFIG_HOME" "/home/user/.config" + (xdg-config-home)) + (test-equal "XDG_STATE_HOME" "/home/user/.local/state" + (xdg-state-home)) + (test-equal "XDG_DATA_DIRS" (xdg-data-dirs) + '("/usr/local/share" "/usr/share")) + (test-equal "XDG_CONFIG_DIRS" '("/etc/xdg") + (xdg-config-dirs)) + (test-equal "XDG_CACHE_HOME" "/home/user/.cache" + (xdg-cache-home)) + (let ((warning + (with-error-to-string + (lambda () + (test-equal "XDG_RUNTIME_DIR" + "/tmp" (xdg-runtime-dir)))))) + (test-assert "The warning actually contains something" + (< 0 (string-length warning))))) + + (test-group "Custom values" + (let-env ((XDG_DATA_HOME "/a")) + (test-equal "XDG_DATA_HOME" "/a" (xdg-data-home))) + (let-env ((XDG_CONFIG_HOME "/b")) + (test-equal "XDG_CONFIG_HOME" "/b" (xdg-config-home))) + (let-env ((XDG_STATE_HOME "/c")) + (test-equal "XDG_STATE_HOME" "/c" (xdg-state-home))) + (let-env ((XDG_DATA_DIRS "/d:/e")) + (test-equal "XDG_DATA_DIRS" '("/d" "/e") (xdg-data-dirs))) + (let-env ((XDG_CONFIG_DIRS "/f:/g")) + (test-equal "XDG_CONFIG_DIRS" '("/f" "/g") (xdg-config-dirs))) + (let-env ((XDG_CACHE_HOME "/h")) + (test-equal "XDG_CACHE_HOME" "/h" (xdg-cache-home))) + (let ((warning + (with-error-to-string + (lambda () + (let-env ((XDG_RUNTIME_DIR "/i")) + (test-equal "XDG_RUNTIME_DIR" "/i" (xdg-runtime-dir))))))) + (test-assert "No error was emitted" + (string-null? warning))))) + -- cgit v1.2.3 From 5672d44892c4010cdfbdc46f5fb29259fa51e076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Sep 2023 17:07:56 +0200 Subject: Add `break` and `continue` support in `for`. --- tests/test/util.scm | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index 719afbed..b25c9add 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -39,15 +39,30 @@ (awhen (memv 0 '(1 2 3 4 5)) (cdr it))) -(test-equal "for simple" - (iota 10) - (for x in (iota 10) - x)) - -(test-equal "for matching" - (iota 12) - (for (x c) in (zip (iota 12) (string->list "Hello, World")) - x)) +(test-group "for" + (test-equal "for simple" + (iota 10) + (for x in (iota 10) + x)) + + (test-equal "for matching" + (iota 12) + (for (x c) in (zip (iota 12) (string->list "Hello, World")) + x)) + + (test-equal "for break" + 'x + (for x in (iota 10) + (break 'x) + (test-assert "This should never happen" #f))) + + (test-equal "for continue" + '(x #f 2) + (for x in (iota 3) + (case x + ((0) (continue 'x)) + ((1) (continue)) + (else x))))) (test-equal "procedure label" 120 -- cgit v1.2.3 From a3b3249bb5162d9b7a040cc05d968c1be9260f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Sep 2023 17:14:09 +0200 Subject: Split test/util.scm into groups. --- tests/test/util.scm | 401 ++++++++++++++++++++++++++-------------------------- 1 file changed, 203 insertions(+), 198 deletions(-) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index b25c9add..81bebdb5 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -17,27 +17,28 @@ relative-to filename-extension))) -(test-equal "when" - 1 (when #t 1)) +(test-group "Conditionals" + (test-equal "when" + 1 (when #t 1)) -(test-equal "'() when #f" - '() (when #f 1)) + (test-equal "'() when #f" + '() (when #f 1)) -(test-equal "unless" - 1 (unless #f 1)) + (test-equal "unless" + 1 (unless #f 1)) -(test-equal "'() unless #t" - '() (unless #t 1)) + (test-equal "'() unless #t" + '() (unless #t 1)) -(test-equal "awhen it" - '(3 4 5) - (awhen (memv 2 '(1 2 3 4 5)) - (cdr it))) + (test-equal "awhen it" + '(3 4 5) + (awhen (memv 2 '(1 2 3 4 5)) + (cdr it))) -(test-equal "awhen not" - '() - (awhen (memv 0 '(1 2 3 4 5)) - (cdr it))) + (test-equal "awhen not" + '() + (awhen (memv 0 '(1 2 3 4 5)) + (cdr it)))) (test-group "for" (test-equal "for simple" @@ -97,49 +98,39 @@ ((unval car+cdr 1) (cons 1 2))) -(test-equal "flatten already flat" - (iota 10) - (flatten (iota 10))) +(test-group "Flatten" + (test-equal "flatten already flat" + (iota 10) + (flatten (iota 10))) -(test-equal "flatten really deep" - '(1) - (flatten '(((((((((((((((1))))))))))))))))) + (test-equal "flatten really deep" + '(1) + (flatten '(((((((((((((((1))))))))))))))))) -(test-equal "flatten mixed" - '(1 2 3 4 5) - (flatten '((((((1(((((2((((3))))))4))))))))5))) + (test-equal "flatten mixed" + '(1 2 3 4 5) + (flatten '((((((1(((((2((((3))))))4))))))))5)))) ;; TODO test let-lazy -(test-equal "map/dotted without dot" - '(1 2 3 4) - (map/dotted 1+ '(0 1 2 3))) +(test-group "map/dotted" + (test-equal "map/dotted without dot" + '(1 2 3 4) + (map/dotted 1+ '(0 1 2 3))) -(test-equal "map/dotted with dot" + (test-equal "map/dotted with dot" '(1 2 3 . 4) - (map/dotted 1+ '(0 1 2 . 3))) - -(test-equal "map/dotted direct value" - 1 (map/dotted 1+ 0)) - -(test-equal "assq merge" - '((k 2 1) (v 2)) - (assq-merge '((k 1) (v 2)) '((k 2)))) + (map/dotted 1+ '(0 1 2 . 3))) -(test-equal "kvlist->assq" - '((a 1) (b 2)) - (kvlist->assq '(a: 1 b: 2))) + (test-equal "map/dotted direct value" + 1 (map/dotted 1+ 0))) -(test-equal "kvlist->assq repeated key" - '((a 1) (b 2) (a 3)) - (kvlist->assq '(a: 1 b: 2 a: 3))) +(test-group "Arrows" -;; TODO assq-limit ? - -(test-equal "->" 9 (-> 1 (+ 2) (* 3))) -(test-equal "-> order dependant" -1 (-> 1 (- 2))) -(test-equal "->> order dependant" 1 (->> 1 (- 2))) + (test-equal "->" 9 (-> 1 (+ 2) (* 3))) + (test-equal "-> order dependant" -1 (-> 1 (- 2))) + (test-equal "->> order dependant" 1 (->> 1 (- 2)))) ;; TODO set and set-> @@ -151,9 +142,25 @@ ;; TODO test failure when grouping isn't possible? -(test-equal "assoc-ref-all" '(1 3) (assoc-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) -(test-equal "assq-ref-all" '(1 3) (assq-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) -(test-equal "assv-ref-all "'(1 3) (assv-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) +(test-group "Associations" + (test-equal "assoc-ref-all" '(1 3) (assoc-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) + (test-equal "assq-ref-all" '(1 3) (assq-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) + (test-equal "assv-ref-all "'(1 3) (assv-ref-all '((a . 1) (b . 2) (a . 3)) 'a)) + + ;; TODO assq-limit ? + + (test-equal "assq merge" + '((k 2 1) (v 2)) + (assq-merge '((k 1) (v 2)) '((k 2)))) + + (test-equal "kvlist->assq" + '((a 1) (b 2)) + (kvlist->assq '(a: 1 b: 2))) + + + (test-equal "kvlist->assq repeated key" + '((a 1) (b 2) (a 3)) + (kvlist->assq '(a: 1 b: 2 a: 3)))) (test-equal "vector-last" 1 (vector-last #(0 2 3 1))) @@ -174,67 +181,70 @@ 'syntax-error (test-read-eval-string "(set/r! x err not)")) -(call-with-values - (lambda () (find-min (iota 10))) - (lambda (extreme rest) - (test-equal "Found correct minimum" 0 extreme) +(test-group "Find extremes" + (call-with-values + (lambda () (find-min (iota 10))) + (lambda (extreme rest) + (test-equal "Found correct minimum" 0 extreme) + (test-equal + "Removed \"something\" from the set" + 9 + (length rest)))) + + (call-with-values + (lambda () + (find-max + '("Hello" "Test" "Something long") + string-length)) + (lambda (extreme rest) + (test-equal + "Found the longest string" + "Something long" + extreme) + (test-equal "Removed the string" 2 (length rest)) + (test-assert + "Other members left 1" + (member "Hello" rest)) + (test-assert + "Other members left 2" + (member "Test" rest)))) + + (test-error 'wrong-type-arg (find-extreme '()))) + +(test-group "Span upto" + (call-with-values + (lambda () + (span-upto + 2 + char-numeric? + (string->list "123456"))) + (lambda (head tail) + (test-equal '(#\1 #\2) head) + (test-equal '(#\3 #\4 #\5 #\6) tail))) + + (call-with-values + (lambda () + (span-upto + 2 + char-numeric? + (string->list "H123456"))) + (lambda (head tail) + (test-equal '() head) + (test-equal '(#\H #\1 #\2 #\3 #\4 #\5 #\6) tail)))) + +(test-group "Begin1" + (let ((value #f)) (test-equal - "Removed \"something\" from the set" - 9 - (length rest)))) - -(call-with-values - (lambda () - (find-max - '("Hello" "Test" "Something long") - string-length)) - (lambda (extreme rest) - (test-equal - "Found the longest string" - "Something long" - extreme) - (test-equal "Removed the string" 2 (length rest)) - (test-assert - "Other members left 1" - (member "Hello" rest)) - (test-assert - "Other members left 2" - (member "Test" rest)))) - -(test-error 'wrong-type-arg (find-extreme '())) - -(call-with-values - (lambda () - (span-upto - 2 - char-numeric? - (string->list "123456"))) - (lambda (head tail) - (test-equal '(#\1 #\2) head) - (test-equal '(#\3 #\4 #\5 #\6) tail))) - -(call-with-values - (lambda () - (span-upto - 2 - char-numeric? - (string->list "H123456"))) - (lambda (head tail) - (test-equal '() head) - (test-equal '(#\H #\1 #\2 #\3 #\4 #\5 #\6) tail))) - -(let ((value #f)) - (test-equal - "begin1 return value" - "Hello" - (begin1 "Hello" (set! value "World"))) - (test-equal "begin1 side effects" "World" value)) + "begin1 return value" + "Hello" + (begin1 "Hello" (set! value "World"))) + (test-equal "begin1 side effects" "World" value)) -(let ((x 1)) - (test-eqv "begin1 set! after return" - 1 (begin1 x (set! x 10))) - (test-eqv "Updates value" - 10 x)) + (let ((x 1)) + (test-eqv "begin1 set! after return" + 1 (begin1 x (set! x 10))) + (test-eqv "Updates value" + 10 x))) (test-equal 0 (iterate 1- zero? 10)) @@ -242,122 +252,117 @@ (test-equal "5" (->string "5")) -(test-equal - "no slashes" - "home/user" - (path-append "home" "user")) - -(test-equal - "no slashes, absolute" - "/home/user" - (path-append "" "home" "user")) +(test-group "Path operations" + (test-equal + "no slashes" + "home/user" + (path-append "home" "user")) -(test-equal - "slashes in one component, absolute" - "/home/user" - (path-append "" "/home/" "user")) + (test-equal + "no slashes, absolute" + "/home/user" + (path-append "" "home" "user")) -(test-equal - "slashes in one component, absolute due to first" - "/home/user" - (path-append "/home/" "user")) + (test-equal + "slashes in one component, absolute" + "/home/user" + (path-append "" "/home/" "user")) -(test-equal - "Slashes in both" - "home/user" - (path-append "home/" "/user")) + (test-equal + "slashes in one component, absolute due to first" + "/home/user" + (path-append "/home/" "user")) -(test-equal "root" "/" (path-append "")) + (test-equal + "Slashes in both" + "home/user" + (path-append "home/" "/user")) -(test-equal "No components" "" (path-append)) + (test-equal "root" "/" (path-append "")) -(test-equal - '("usr" "lib" "test") - (path-split "usr/lib/test")) + (test-equal "No components" "" (path-append)) -(test-equal - '("usr" "lib" "test") - (path-split "usr/lib/test/")) + (test-equal + '("usr" "lib" "test") + (path-split "usr/lib/test")) -(test-equal - '("" "usr" "lib" "test") - (path-split "/usr/lib/test")) + (test-equal + '("usr" "lib" "test") + (path-split "usr/lib/test/")) -(test-equal - '("" "usr" "lib" "test") - (path-split "//usr////lib/test")) + (test-equal + '("" "usr" "lib" "test") + (path-split "/usr/lib/test")) -(test-assert (file-hidden? ".just-filename")) -(test-assert (file-hidden? "/path/to/.hidden")) -(test-assert (not (file-hidden? "/visible/.in/hidden"))) -(test-assert (not (file-hidden? ""))) + (test-equal + '("" "usr" "lib" "test") + (path-split "//usr////lib/test")) -;; TODO test realpath with .. and similar + (test-assert (file-hidden? ".just-filename")) + (test-assert (file-hidden? "/path/to/.hidden")) + (test-assert (not (file-hidden? "/visible/.in/hidden"))) + (test-assert (not (file-hidden? ""))) -(test-equal "Realpath for path fragment" - "/home/hugo" - (with-working-directory - "/home" - (lambda () (realpath "hugo")))) + ;; TODO test realpath with .. and similar -(test-equal "Realpath for already absolute path" - "/home/hugo" - (with-working-directory - "/tmp" - (lambda () (realpath "/home/hugo")))) + (test-equal "Realpath for path fragment" + "/home/hugo" + (with-working-directory + "/home" + (lambda () (realpath "hugo")))) -(test-equal "Realpath for already absolute path" - "/home/hugo" - (with-working-directory - "/tmp" - (lambda () (realpath "/home/hugo")))) + (test-equal "Realpath for already absolute path" + "/home/hugo" + (with-working-directory + "/tmp" + (lambda () (realpath "/home/hugo")))) -(test-group "Relative to" + (test-group "Relative to" - (test-group "With relative child" - (test-equal "/some/path" (relative-to "/some" "path"))) + (test-group "With relative child" + (test-equal "/some/path" (relative-to "/some" "path"))) - ;; Relative parent just adds (getcwd) to start of parent, - ;; but this is "hard" to test. - ;; (test-group "With relative parent") + ;; Relative parent just adds (getcwd) to start of parent, + ;; but this is "hard" to test. + ;; (test-group "With relative parent") - (test-group "With absolute child" - (test-error 'misc-error (relative-to "" "/some/path")) - (test-equal "some/path" (relative-to "/" "/some/path")) - (test-group "Without trailing slashes" - (test-equal "path" (relative-to "/some" "/some/path")) - (test-equal "../path" (relative-to "/some" "/other/path"))) - (test-group "With trailing slashes" - (test-equal "path" (relative-to "/some" "/some/path/")) - (test-equal "../path" (relative-to "/some" "/other/path/")))) + (test-group "With absolute child" + (test-error 'misc-error (relative-to "" "/some/path")) + (test-equal "some/path" (relative-to "/" "/some/path")) + (test-group "Without trailing slashes" + (test-equal "path" (relative-to "/some" "/some/path")) + (test-equal "../path" (relative-to "/some" "/other/path"))) + (test-group "With trailing slashes" + (test-equal "path" (relative-to "/some" "/some/path/")) + (test-equal "../path" (relative-to "/some" "/other/path/")))) - (test-equal "/a/b" (relative-to "/a/b/c" "/a/b")) + (test-equal "/a/b" (relative-to "/a/b/c" "/a/b")) - ) + ) -(test-equal "Extension of simple file" - "txt" (filename-extension "file.txt")) + (test-equal "Extension of simple file" + "txt" (filename-extension "file.txt")) -(test-equal "Extension of file with directory" - "txt" (filename-extension "/direcotry/file.txt")) + (test-equal "Extension of file with directory" + "txt" (filename-extension "/direcotry/file.txt")) -(test-equal "Extension of file with multiple" - "gz" (filename-extension "filename.tar.gz")) + (test-equal "Extension of file with multiple" + "gz" (filename-extension "filename.tar.gz")) -(test-equal "Filename extension when none is present" - "" (filename-extension "filename")) + (test-equal "Filename extension when none is present" + "" (filename-extension "filename")) -(test-equal "Filename extension when none is present, but directory has" - "" (filename-extension "config.d/filename")) + (test-equal "Filename extension when none is present, but directory has" + "" (filename-extension "config.d/filename")) -(test-equal "Filename extension of directory" - "d" (filename-extension "config.d/")) + (test-equal "Filename extension of directory" + "d" (filename-extension "config.d/")) -(test-equal "Extension of hidden file" - "sh" (filename-extension ".bashrc.sh")) + (test-equal "Extension of hidden file" + "sh" (filename-extension ".bashrc.sh")) -(test-equal "Extension of hidden file without extension" - "bashrc" (filename-extension ".bashrc")) + (test-equal "Extension of hidden file without extension" + "bashrc" (filename-extension ".bashrc"))) -- cgit v1.2.3 From 72361e8c3aa8a33e1ea71e2fe081362670940fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Sep 2023 17:16:46 +0200 Subject: Require component for path append. Changed the signature of `path-append` to require at least one argument. The alternative would have been that no components expands into '.'. --- tests/test/util.scm | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index 81bebdb5..75d59801 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -280,8 +280,6 @@ (test-equal "root" "/" (path-append "")) - (test-equal "No components" "" (path-append)) - (test-equal '("usr" "lib" "test") (path-split "usr/lib/test")) -- cgit v1.2.3 From 0c1d9a9856f12641424b7abaeb9f3960c91b9332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 12 Feb 2023 22:44:25 +0100 Subject: Fix seeding of UUIDs. --- tests/test/uuid.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/test') diff --git a/tests/test/uuid.scm b/tests/test/uuid.scm index 6a2bd92a..1cedb59e 100644 --- a/tests/test/uuid.scm +++ b/tests/test/uuid.scm @@ -4,9 +4,8 @@ :use-module (srfi srfi-88) :use-module (hnh util uuid)) -(set! (@@ (hnh util uuid) %seed) - (seed->random-state 0)) (test-equal "UUIDv4 fixed seed" "d19c9347-9a85-4432-a876-5fb9c0d24d2b" - (uuid-v4)) + (parameterize ((seed (seed->random-state 0))) + (uuid-v4))) -- cgit v1.2.3 From c26324e29043423387c3041e86d8cbe5cd4102b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 21 Feb 2023 03:21:43 +0100 Subject: Change `kvlist->assq` and `group-by` to return pairs. Each value in the return of group-by must have exactly two values, so cons pairs (instead of lists) is much better. --- tests/test/util.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index 75d59801..d2fc2d81 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -127,7 +127,6 @@ (test-group "Arrows" - (test-equal "->" 9 (-> 1 (+ 2) (* 3))) (test-equal "-> order dependant" -1 (-> 1 (- 2))) (test-equal "->> order dependant" 1 (->> 1 (- 2)))) @@ -154,12 +153,12 @@ (assq-merge '((k 1) (v 2)) '((k 2)))) (test-equal "kvlist->assq" - '((a 1) (b 2)) + '((a . 1) (b . 2)) (kvlist->assq '(a: 1 b: 2))) (test-equal "kvlist->assq repeated key" - '((a 1) (b 2) (a 3)) + '((a . 1) (b . 2) (a . 3)) (kvlist->assq '(a: 1 b: 2 a: 3)))) (test-equal "vector-last" -- cgit v1.2.3 From 7bdc4a32ff775bca0158533c9e9af250f16cceb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 23 Feb 2023 01:08:16 +0100 Subject: Extend `for'-macro to allow improper list elements. --- tests/test/util.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index d2fc2d81..41dbd7a3 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -51,6 +51,16 @@ (for (x c) in (zip (iota 12) (string->list "Hello, World")) x)) + (test-equal "for with improper list elements" + `(3 7) + (for (a . b) in '((1 . 2) (3 . 4)) + (+ a b))) + + (test-equal "for with longer improper list elements" + '(1 2 4) + (for (a b . c) in '((1 -1 . 1) (2 -2 . 2) (4 -4 . 4)) + (* c (+ 1 a b)))) + (test-equal "for break" 'x (for x in (iota 10) -- cgit v1.2.3 From 634502e7246f8850ad6c649b79ae9f072f45baf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Sep 2023 17:54:35 +0200 Subject: Introduce stream-split-by. This procedure isn't currently used, but as noted is really useful for grouping a character stream into a word stream, which is a later commit will use for it for justifying posibly infinite streams of text. --- tests/test/srfi-41-util.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/test') diff --git a/tests/test/srfi-41-util.scm b/tests/test/srfi-41-util.scm index ff0e3cce..9a753b03 100644 --- a/tests/test/srfi-41-util.scm +++ b/tests/test/srfi-41-util.scm @@ -8,6 +8,7 @@ :use-module (srfi srfi-88) :use-module (srfi srfi-41 util) :use-module (srfi srfi-41) + :use-module ((srfi srfi-1) :select (circular-list)) :use-module ((ice-9 sandbox) :select (call-with-time-limit))) (test-equal "Finite stream" @@ -86,3 +87,22 @@ (test-equal "time limited stream" '(1 2 3) (stream->list strm)))) + + +(test-group "stream-split-by" + (let ((hello-chars-stream (stream-unfold + car + (const #t) + cdr + (apply circular-list + (string->list "Hello "))))) + (test-equal "Check that test list looks as expected" + (string->list "Hello Hell") + (stream->list 10 hello-chars-stream)) + (test-equal "Check that it splits correctly" + '("Hello " "Hello " "Hello ") + (stream->list + 3 + (stream-map list->string + (stream-split-by (lambda (c) (char=? c #\space)) + hello-chars-stream)))))) -- cgit v1.2.3 From d026448edced5b71313629b9feaa9c38134e58e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Sep 2023 22:36:30 +0200 Subject: Fix bug causing for's continue to not work. --- tests/test/util.scm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/test') diff --git a/tests/test/util.scm b/tests/test/util.scm index 41dbd7a3..bdd6e98e 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -71,8 +71,12 @@ '(x #f 2) (for x in (iota 3) (case x - ((0) (continue 'x)) - ((1) (continue)) + ((0) + (continue 'x) + (test-assert "Continue with value failed" #f)) + ((1) + (continue) + (test-assert "Continue without value failed" #f)) (else x))))) (test-equal "procedure label" -- cgit v1.2.3