]> gitweb.factorcode.org Git - factor.git/blob - extra/combinators/extras/extras-tests.factor
io.files: exists? -> file-exists? and rename primitive.
[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: assocs combinators.extras io.files kernel math sequences
4 splitting tools.test ;
5
6 { "a b" }
7 [ "a" "b" [ " " glue ] once ] unit-test
8
9 { "a b c" }
10 [ "a" "b" "c" [ " " glue ] twice ] unit-test
11
12 { "a b c d" }
13 [ "a" "b" "c" "d" [ " " glue ] thrice ] unit-test
14
15 { { "negative" 0 "positive" } } [
16     { -1 0 1 } [
17         {
18            { [ 0 > ] [ "positive" ] }
19            { [ 0 < ] [ "negative" ] }
20            [ ]
21         } cond-case
22     ] map
23 ] unit-test
24
25 { { 1 2 3 } } [ 1 { [ ] [ 1 + ] [ 2 + ] } cleave-array ] unit-test
26
27 { 2 15 } [ 1 2 3 4 5 6 [ - - ] [ + + ] 3bi* ] unit-test
28
29 { 2 5 } [ 1 2 3 4 5 6 [ - - ] 3bi@ ] unit-test
30
31 { 3 1 } [ 1 2 [ + ] keepd ] unit-test
32
33 { "1" "123" } [ "1" "123" [ length ] [ > ] swap-when ] unit-test
34 { "123" "1" } [ "1" "123" [ length ] [ < ] swap-when ] unit-test
35
36
37 { t } [ "resource:" [ file-exists? ] ?1arg >boolean ] unit-test
38 { f } [ f [ file-exists? ] ?1arg ] unit-test
39 { f } [ "/homeasdfasdf123123" [ file-exists? ] ?1arg ] unit-test
40
41 { "hi " "there" } [
42     "hi there" {
43         { [ "there" over subseq-start ] [ cut ] }
44         [ f ]
45     } cond*
46 ] unit-test
47
48 { "hi " "there" } [
49     "hi there" {
50         { [ "foo" over subseq-start ] [ head f ] }
51         { [ "there" over subseq-start ] [ cut ] }
52         [ f ]
53     } cond*
54 ] unit-test
55
56 { "hi there" f } [
57     "hi there" {
58         { [ "foo" over subseq-start ] [ head f ] }
59         { [ "bar" over subseq-start ] [ cut ] }
60         [ f ]
61     } cond*
62 ] unit-test
63
64 { f } [ f { } chain ] unit-test
65 { 3 } [ H{ { 1 H{ { 2 3 } } } } { [ 1 of ] [ 2 of ] } chain ] unit-test
66 { f } [ H{ { 1 H{ { 3 4 } } } } { [ 1 of ] [ 2 of ] } chain ] unit-test
67 { f } [ H{ { 2 H{ { 3 4 } } } } { [ 1 of ] [ 2 of ] } chain ] unit-test
68 { 5 } [
69     "hello factor!" { [ words ] [ first ] [ length ] } chain
70 ] unit-test