]> gitweb.factorcode.org Git - factor.git/blob - core/strings/strings-tests.factor
Initial import
[factor.git] / core / strings / strings-tests.factor
1 USING: continuations kernel math namespaces strings sbufs
2 tools.test sequences vectors ;
3 IN: temporary
4
5 [ CHAR: b ] [ 1 >bignum "abc" nth ] unit-test
6
7 [ ] [ 10 [ [ -1000000 <sbuf> ] catch drop ] times ] unit-test
8
9 [ "abc" ] [ [ "a" "b" "c" ] [ [ % ] each ] "" make ] unit-test
10
11 [ "abc" ] [ "ab" "c" append ] unit-test
12 [ "abc" ] [ "a" "b" "c" 3append ] unit-test
13
14 [ 3 ] [ "a" "hola" start ] unit-test
15 [ f ] [ "x" "hola" start ] unit-test
16 [ 0 ] [ "" "a" start ] unit-test
17 [ 0 ] [ "" "" start ] unit-test
18 [ 0 ] [ "hola" "hola" start ] unit-test
19 [ 1 ] [ "ol" "hola" start ] unit-test
20 [ f ] [ "amigo" "hola" start ] unit-test
21 [ f ] [ "holaa" "hola" start ] unit-test
22
23 [ "Beginning" ] [ "Beginning and end" 9 head ] unit-test
24
25 [ f ] [ CHAR: I "team" member? ] unit-test
26 [ t ] [ "ea" "team" subseq? ] unit-test
27 [ f ] [ "actore" "Factor" subseq? ] unit-test
28
29 [ "end" ] [ "Beginning and end" 14 tail ] unit-test
30
31 [ t ] [ CHAR: a letter? ] unit-test
32 [ f ] [ CHAR: A letter? ] unit-test
33 [ f ] [ CHAR: a LETTER? ] unit-test
34 [ t ] [ CHAR: A LETTER? ] unit-test
35 [ t ] [ CHAR: 0 digit? ] unit-test
36 [ f ] [ CHAR: x digit? ] unit-test
37
38 [ t ] [ "abc" "abd" <=> 0 < ] unit-test
39 [ t ] [ "z" "abd" <=> 0 > ] unit-test
40
41 [ f ] [ [ 0 10 "hello" subseq ] catch not ] unit-test
42
43 [ 4 ] [
44     0 "There are Four Upper Case characters"
45     [ LETTER? [ 1+ ] when ] each
46 ] unit-test
47
48 [ "Replacing+spaces+with+plus" ]
49 [
50     "Replacing spaces with plus"
51     [ dup CHAR: \s = [ drop CHAR: + ] when ] map
52 ]
53 unit-test
54
55 [ "05" ] [ "5" 2 CHAR: 0 pad-left ] unit-test
56 [ "666" ] [ "666" 2 CHAR: 0 pad-left ] unit-test
57
58 [ 1 "" nth ] unit-test-fails
59 [ -6 "hello" nth ] unit-test-fails
60
61 [ t ] [ "hello world" dup >vector >string = ] unit-test 
62
63 [ "ab" ] [ 2 "abc" resize-string ] unit-test
64 [ "abc\0\0\0" ] [ 6 "abc" resize-string ] unit-test
65
66 ! Random tester found this
67 [ { "kernel-error" 3 12 -7 } ]
68 [ [ 2 -7 resize-string ] catch ] unit-test