diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-18 12:46:39 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-18 12:49:30 +0200 |
commit | 54bd472298cc05c50428c19cf222e0375e8bcc09 (patch) | |
tree | c68d4e6208adce8914168785f950e482722bf172 /tests/unit | |
parent | Change add-enumeration-punctuation to always return lists. (diff) | |
download | calp-54bd472298cc05c50428c19cf222e0375e8bcc09.tar.gz calp-54bd472298cc05c50428c19cf222e0375e8bcc09.tar.xz |
Add tests for (text util).
The "true string" procedures are still not tested, since they are way to
much work to get right. See comments added in this commit about removing
them entirely.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/coverage-supplement.scm | 5 | ||||
-rw-r--r-- | tests/unit/text/test-util.scm | 50 |
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/unit/coverage-supplement.scm b/tests/unit/coverage-supplement.scm index 130a4e84..9242a3c1 100644 --- a/tests/unit/coverage-supplement.scm +++ b/tests/unit/coverage-supplement.scm @@ -31,4 +31,9 @@ 23 29 ; internal lookup table, used by everything so tested implicitly 53 ; internal helper function, tested implictly ) + ("module/text/util.scm" + "271a5f7740aa6e378e7fda2da4725171dc50a2e4a790e9529fceed19a747e775" + 5 ; (Module declaration + 52 ; else "keyword" apparently missed + ) ) diff --git a/tests/unit/text/test-util.scm b/tests/unit/text/test-util.scm new file mode 100644 index 00000000..6d721eb1 --- /dev/null +++ b/tests/unit/text/test-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)) |