From 1c8730a3e7ff6992447690d48dd9bca9d781e5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 24 Oct 2023 22:43:10 +0200 Subject: Fix name of text-util test. --- tests/unit/text/text-util.scm | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/unit/text/text-util.scm (limited to 'tests/unit/text/text-util.scm') diff --git a/tests/unit/text/text-util.scm b/tests/unit/text/text-util.scm new file mode 100644 index 00000000..6d721eb1 --- /dev/null +++ b/tests/unit/text/text-util.scm @@ -0,0 +1,50 @@ +(define-module (test text-util) + :use-module (srfi srfi-64) + :use-module (srfi srfi-71) + :use-module (srfi srfi-88) + :use-module (text util)) + +(test-group "words/unwords" + (test-equal '("A" "list" "of" "words") + (words "A list of words")) + + (test-equal "A joined string" + (unwords '("A" "joined" "string")))) + +(test-group "lines/unlines" + (test-equal '("A" "list of" "words") + (lines "A\nlist of\nwords")) + + (test-equal "A joined\nstring" + (unlines '("A joined" "string")))) + +;;; TODO tests for "true" string length procedures +;;; Or better yet, remove them and format text properly. + +(test-group "trim-to-width" + (test-equal "Extending strings" + "An extended string " + (trim-to-width "An extended string" 40)) + (test-equal "Truncating strings" + "This is a…" + (trim-to-width "This is a rather long string" 10)) + (test-equal "Exact width" + "Hello" + (trim-to-width "Hello" 5))) + + +(test-group "Add enumeration punctuation" + (test-equal '("") + (add-enumeration-punctuation '())) + (test-equal '("Single element") + (add-enumeration-punctuation '("Single element"))) + (test-equal "Two elements" + '("Hello" " " "&" " " "World") + (add-enumeration-punctuation '("Hello" "World"))) + (test-equal "Three elements and different end" + '("A" ", " "B" " " "and" " " "C") + (add-enumeration-punctuation '("A" "B" "C") + "and"))) + + +'((text util)) -- cgit v1.2.3