diff options
Diffstat (limited to 'strings-test.csc')
| -rw-r--r-- | strings-test.csc | 113 |
1 files changed, 27 insertions, 86 deletions
diff --git a/strings-test.csc b/strings-test.csc index f7c8e53..4d7a751 100644 --- a/strings-test.csc +++ b/strings-test.csc @@ -1,103 +1,44 @@ (import (scheme base) (only (csc testing) - define-test - errorf - subtest) + assert + assert-equal + test) (csc strings)) -(define-test (test-str-prefix? t) - (define-record-type <test-case> - (test-case name prefix str want) - test-case? - (name name) - (prefix prefix) - (str str) - (want want)) - (let ((tests (list - (test-case - "good" - "asdf" - "asdfjkl;" - #t) - (test-case - "bad" - "asdf" - "asdbjkl;" - #f) - (test-case - "too long" - "asdf" - "as" - #f)))) - (for-each - (lambda (tc) - (subtest t (name tc) - (let ((got (str-prefix? (prefix tc) (str tc)))) - (unless (eq? got (want tc)) - (errorf t "(str-prefix? {} {}) = {}, want {}" (str-quote (prefix tc)) (str-quote (str tc)) got (want tc)))))) - tests))) +(test str-prefix?-good + (assert-equal #t (str-prefix? "asdf" "asdfjkl;"))) -(define-test (test-str-quote t) - (define-record-type <test-case> - (test-case name str want) - test-case? - (name name) - (str str) - (want want)) - (let ((tests (list - (test-case - "simple" - "hello" - "\"hello\"") - (test-case - "escape" - "this string \" has a quote" - "\"this string \\\" has a quote\"")))) - (for-each - (lambda (tc) - (subtest t (name tc) - (let ((got (str-quote (str tc)))) - (unless (equal? got (want tc)) - (errorf t "(str-quote {}) = {}, want {}" (str tc) (got tc) (want tc)))))) - tests))) +(test str-prefix?-bad + (assert-equal #f (str-prefix? "asdf" "asdbjkl;"))) -(define-test (test-str-find t) - (define-record-type <test-case> - (test-case name match str want) - test-case? - (name name) - (match match) - (str str) - (want want)) - (let ((tests (list - (test-case - "ok" - "abc" - "dabsadfdabcdfdfd" - 8) - (test-case - "one letter" - "a" - "sdfdfdfsasdfe" - 8)))) - (for-each - (lambda (tc) - (subtest t (name tc) - (let ((got (str-find (match tc) (str tc)))) - (unless (= got (want tc)) - (errorf t "(str-find {} {}) = {}, want {}" (str-quote (match tc)) (str-quote (str tc)) got (want tc)))))) - tests))) +(test str-prefix?-too-long + (assert-equal #f (str-prefix? "asdf" "as"))) -(define-test (test-str-find-notfound t) +(test str-quote-simple + (assert-equal "\"hello\"" (str-quote "hello"))) + + +(test str-quote-escape + (assert-equal "\"this string \\\" has a quote\"" (str-quote "this string \" has a quote"))) + + +(test str-find-ok + (assert-equal 8 (str-find "abc" "dabsadfdabcdfdfd"))) + + +(test str-find-one-letter + (assert-equal 8 (str-find "a" "sdfdfdfsasdfe"))) + + +(test test-str-find-notfound (let* ((match "a") (str "def") (got-exception '())) (guard (e ((str-not-found-error? e) (set! got-exception e))) (str-find match str)) - (unless (str-not-found-error? got-exception) - (errorf t "str-find succeeded, wanted <str-not-found-error>")))) + (assert (str-not-found-error? got-exception)))) |
