]> gitweb.factorcode.org Git - factor.git/blob - extra/combinators/extras/extras-tests.factor
dc9e7fa7c59a37bdc53897d650ee335622a7ddea
[factor.git] / extra / combinators / extras / extras-tests.factor
1 ! Copyright (C) 2013 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.extras io.files kernel math sequences
4 tools.test ;
5 IN: combinators.extras.tests
6
7 { "a b" }
8 [ "a" "b" [ " " glue ] once ] unit-test
9
10 { "a b c" }
11 [ "a" "b" "c" [ " " glue ] twice ] unit-test
12
13 { "a b c d" }
14 [ "a" "b" "c" "d" [ " " glue ] thrice ] unit-test
15
16 { { "negative" 0 "positive" } } [
17     { -1 0 1 } [
18         {
19            { [ 0 > ] [ "positive" ] }
20            { [ 0 < ] [ "negative" ] }
21            [ ]
22         } cond-case
23     ] map
24 ] unit-test
25
26 { { 1 2 3 } } [ 1 { [ ] [ 1 + ] [ 2 + ] } cleave-array ] unit-test
27
28 { 2 15 } [ 1 2 3 4 5 6 [ - - ] [ + + ] 3bi* ] unit-test
29
30 { 2 5 } [ 1 2 3 4 5 6 [ - - ] 3bi@ ] unit-test
31
32 { 3 1 } [ 1 2 [ + ] keepd ] unit-test
33
34 { "1" "123" } [ "1" "123" [ length ] [ > ] swap-when ] unit-test
35 { "123" "1" } [ "1" "123" [ length ] [ < ] swap-when ] unit-test
36
37
38 { t } [ "resource:" [ exists? ] ?1arg >boolean ] unit-test
39 { f } [ f [ exists? ] ?1arg ] unit-test
40 { f } [ "/homeasdfasdf123123" [ exists? ] ?1arg ] unit-test
41
42 { "hi " "there" } [
43     "hi there" {
44         { [ "there" over subseq-start ] [ cut ] }
45         [ f ]
46     } cond*
47 ] unit-test
48
49 { "hi " "there" } [
50     "hi there" {
51         { [ "foo" over subseq-start ] [ head f ] }
52         { [ "there" over subseq-start ] [ cut ] }
53         [ f ]
54     } cond*
55 ] unit-test
56
57 { "hi there" f } [
58     "hi there" {
59         { [ "foo" over subseq-start ] [ head f ] }
60         { [ "bar" over subseq-start ] [ cut ] }
61         [ f ]
62     } cond*
63 ] unit-test