-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.scm
97 lines (73 loc) · 3.17 KB
/
test.scm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(import (scheme base)
(scheme write)
(scheme char)
(cyclone test)
(cyclone string))
(define (digit-value ch)
(case ch
((#\0) 0) ((#\1) 1) ((#\2) 2) ((#\3) 3) ((#\4) 4)
((#\5) 5) ((#\6) 6) ((#\7) 7) ((#\8) 8) ((#\9) 9) (else #f)))
(define (string-find/index str pred)
(string-cursor->index str (string-find str pred)))
(define (string-find-right/index str pred)
(string-cursor->index str (string-find-right str pred)))
(define (string-skip/index str pred)
(string-cursor->index str (string-skip str pred)))
(define (string-skip-right/index str pred)
(string-cursor->index str (string-skip-right str pred)))
(define (run-tests)
(test-begin "strings")
(test #t (string-null? ""))
(test #f (string-null? " "))
(test #t (string-every char-alphabetic? "abc"))
(test #f (string-every char-alphabetic? "abc0"))
(test #f (string-every char-alphabetic? " abc"))
(test #f (string-every char-alphabetic? "a.c"))
(test 3 (string-any digit-value "a3c"))
(test #f (string-any digit-value "abc"))
(test 0 (string-find/index "abc" char-alphabetic?))
(test 3 (string-find/index "abc0" char-numeric?))
(test 3 (string-find/index "abc" char-numeric?))
(test 3 (string-find-right/index "abc" char-alphabetic?))
(test 4 (string-find-right/index "abc0" char-numeric?))
(test 0 (string-find-right/index "abc" char-numeric?))
(test 0 (string-skip/index "abc" char-numeric?))
(test 3 (string-skip/index "abc0" char-alphabetic?))
(test 3 (string-skip/index "abc" char-alphabetic?))
(test 3 (string-skip-right/index "abc" char-numeric?))
(test 4 (string-skip-right/index "abc0" char-alphabetic?))
(test 0 (string-skip-right/index "abc" char-alphabetic?))
(test "foobarbaz" (string-join '("foo" "bar" "baz")))
(test "foo bar baz" (string-join '("foo" "bar" "baz") " "))
(test '() (string-split ""))
(test '("" "") (string-split " "))
(test '("foo" "bar" "baz") (string-split "foo bar baz"))
(test '("foo" "bar" "baz" "") (string-split "foo bar baz "))
(test '("foo" "bar" "baz") (string-split "foo:bar:baz" #\:))
(test '("" "foo" "bar" "baz") (string-split ":foo:bar:baz" #\:))
(test '("foo" "bar" "baz" "") (string-split "foo:bar:baz:" #\:))
(test '("foo" "bar:baz") (string-split "foo:bar:baz" #\: 2))
(test "abc" (string-trim-left " abc"))
(test "abc " (string-trim-left "abc "))
(test "abc " (string-trim-left " abc "))
(test " abc" (string-trim-right " abc"))
(test "abc" (string-trim-right "abc "))
(test " abc" (string-trim-right " abc "))
(test "abc" (string-trim " abc"))
(test "abc" (string-trim "abc "))
(test "abc" (string-trim " abc "))
(test "" (string-trim ""))
(test "" (string-trim " "))
(test "" (string-trim " "))
(test #t (string-prefix? "abc" "abc"))
(test #t (string-prefix? "abc" "abcde"))
(test #f (string-prefix? "abcde" "abc"))
(test #t (string-suffix? "abc" "abc"))
(test #f (string-suffix? "abc" "abcde"))
(test #f (string-suffix? "abcde" "abc"))
(test #f (string-suffix? "abcde" "cde"))
(test #t (string-suffix? "cde" "abcde"))
(test 3 (string-count "!a0 bc /.," char-alphabetic?))
(test "ABC" (string-map char-upcase "abc"))
(test-end))
(run-tests)