diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-07-28 19:55:37 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-07-28 19:55:37 -0700 |
| commit | f6cccfb501175ba15a1bd529c7228c22c57152a9 (patch) | |
| tree | e161f8660dcb725aa1f244eb6e2f72eb484aa06c /csc/strings-test.csc | |
| parent | 5857672bf5d5ec5a20caf42c7d15263e1b6cc79e (diff) | |
| download | chromatopelma-f6cccfb501175ba15a1bd529c7228c22c57152a9.tar.zst | |
Improve the strings API.
I'm just copying the go strings library API.
Diffstat (limited to 'csc/strings-test.csc')
| -rw-r--r-- | csc/strings-test.csc | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/csc/strings-test.csc b/csc/strings-test.csc index 60bfb08..1f981ad 100644 --- a/csc/strings-test.csc +++ b/csc/strings-test.csc @@ -8,16 +8,16 @@ (begin - (test prefix?-good - (assert-equal #t (prefix? "asdf" "asdfjkl;"))) + (test has-prefix?-good + (assert-equal #t (has-prefix? "asdfjkl;" "asdf"))) - (test prefix?-bad - (assert-equal #f (prefix? "asdf" "asdbjkl;"))) + (test has-prefix?-bad + (assert-equal #f (has-prefix? "asdbjkl;" "asdf"))) - (test prefix?-too-long - (assert-equal #f (prefix? "asdf" "as"))) + (test has-prefix?-too-long + (assert-equal #f (has-prefix? "as" "asdf"))) (test str-quote-simple @@ -28,46 +28,42 @@ (assert-equal "\"this string \\\" has a quote\"" (str-quote "this string \" has a quote"))) - (test find-ok - (assert-equal 8 (find "abc" "dabsadfdabcdfdfd"))) + (test index-ok + (assert-equal 8 (index "dabsadfdabcdfdfd" "abc"))) - (test find-one-letter - (assert-equal 8 (find "a" "sdfdfdfsasdfe"))) + (test index-one-letter + (assert-equal 8 (index "sdfdfdfsasdfe" "a"))) - (test find-notfound - (let* ((match "a") - (str "def") - (got-exception '())) - (guard (e - ((not-found-error? e) (set! got-exception e))) - (find match str)) - (assert (not-found-error? got-exception)))) + (test index-notfound + (assert-equal + -1 + (index "def" "a"))) (test contains (assert-equal #t - (contains "abc" "b"))) + (contains? "abc" "b"))) (test doesnt-contain (assert-equal #f - (contains "abc" "d"))) + (contains? "abc" "d"))) (test contains-empty (assert-equal #t - (contains "" ""))) + (contains? "" ""))) (test empty-contains (assert-equal #f - (contains "" "a"))) + (contains? "" "a"))) (test join-, @@ -94,4 +90,14 @@ (test split-trailing-empty - (assert-equal '("a" "") (split "a " " "))))) + (assert-equal '("a" "") (split "a " " "))) + + + (test split-n + (assert-equal '("a" "b" "c d e") (split "a b c d e" " " 3))) + + + (test split-none + (assert-equal + '() + (split "a b c d e" " " 0))))) |
