aboutsummaryrefslogtreecommitdiffstats
path: root/strings-test.csc
blob: 4d7a7517c729ed29f77602fe4310623ae1bebd75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(import (scheme base)
        (only (csc testing)
          assert
          assert-equal
          test)
        (csc strings))


(test str-prefix?-good
  (assert-equal #t (str-prefix? "asdf" "asdfjkl;")))


(test str-prefix?-bad
  (assert-equal #f (str-prefix? "asdf" "asdbjkl;")))


(test str-prefix?-too-long
  (assert-equal #f (str-prefix? "asdf" "as")))


(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))
    (assert (str-not-found-error? got-exception))))