]> gitweb.factorcode.org Git - factor.git/blob - basis/globs/globs-tests.factor
Fixes #2966
[factor.git] / basis / globs / globs-tests.factor
1 USING: globs globs.private io.directories io.pathnames sorting
2 tools.test ;
3
4 { f } [ "abd" "fdf" glob-matches? ] unit-test
5 { f } [ "fdsafas" "?" glob-matches? ] unit-test
6 { t } [ "fdsafas" "*as" glob-matches? ] unit-test
7 { t } [ "fdsafas" "*a*" glob-matches? ] unit-test
8 { t } [ "fdsafas" "*a?" glob-matches? ] unit-test
9 { t } [ "fdsafas" "*?" glob-matches? ] unit-test
10 { f } [ "fdsafas" "*s?" glob-matches? ] unit-test
11 { t } [ "a" "[abc]" glob-matches? ] unit-test
12 { f } [ "a" "[^abc]" glob-matches? ] unit-test
13 { t } [ "d" "[^abc]" glob-matches? ] unit-test
14 { f } [ "foo.java" "*.{xml,txt}" glob-matches? ] unit-test
15 { t } [ "foo.txt" "*.{xml,txt}" glob-matches? ] unit-test
16 { t } [ "foo.xml" "*.{xml,txt}" glob-matches? ] unit-test
17 { f } [ "foo." "*.{xml,txt}" glob-matches? ] unit-test
18 { t } [ "foo." "*.{,xml,txt}" glob-matches? ] unit-test
19 { t } [ "foo.{" "*.{" glob-matches? ] unit-test
20 { t } [ "foo" "[a-z]oo" glob-matches? ] unit-test
21 { f } [ "foo" "[g-z]oo" glob-matches? ] unit-test
22
23 { f } [ "foo" "bar" append-path "*" glob-matches? ] unit-test
24 { t } [ "foo" "bar" append-path "*" "*" append-path glob-matches? ] unit-test
25 { t } [ "foo" "bar" append-path "**/bar" glob-matches? ] unit-test
26 { t } [ "foo" "bar" append-path "**/b*" glob-matches? ] unit-test
27 { f } [ "foo" "bar" append-path "foo?bar" glob-matches? ] unit-test
28 { t } [ "foo" "bar" append-path "fo?" "bar" append-path glob-matches? ] unit-test
29
30 { f } [ "foo" glob-pattern? ] unit-test
31 { t } [ "fo?" glob-pattern? ] unit-test
32 { t } [ "fo*" glob-pattern? ] unit-test
33 { t } [ "fo[mno]" glob-pattern? ] unit-test
34 { t } [ "fo\\*" glob-pattern? ] unit-test
35 { t } [ "fo{o,bro}" glob-pattern? ] unit-test
36
37 { "a/b/c" { } } [ "a/b/c" split-glob ] unit-test
38 { "a/b" { "c*" } } [ "a/b/c*" split-glob ] unit-test
39 { "a/b" { "c*" "" } } [ "a/b/c*/" split-glob ] unit-test
40 { "/path/to" { "a?" } } [ "/path/to/a?" split-glob ] unit-test
41
42 {
43     { "a" }
44     { "a" "a/b" "a/b/c" "a/b/c/d" "a/b/h" "a/e" "a/e/g" }
45     {
46         "a" "a/b" "a/b/c" "a/b/c/d" "a/b/c/d/e" "a/b/c/f"
47         "a/b/g" "a/b/h" "a/b/h/e" "a/e" "a/e/f" "a/e/g"
48         "a/e/g/e"
49     }
50     {
51         "a" "a/b" "a/b/c" "a/b/c/d" "a/b/c/d/e" "a/b/c/f"
52         "a/b/g" "a/b/h" "a/b/h/e" "a/e" "a/e/f" "a/e/g"
53         "a/e/g/e"
54     }
55     { "a/b" }
56     { "a/b/c/d/e" "a/b/h/e" "a/e" "a/e/g/e" }
57     ! { "a/b/c/d/e" "a/b/h/e" "a/e" "a/e/g/e" }
58     ! { "a/b/c/d/e" "a/b/h/e" "a/e" "a/e/g/e" }
59     { "a/e/f" "a/e/g" }
60     { "a/b" "a/e" }
61     { "a" }
62     { "a/b" }
63 } [
64
65     [
66         "a" make-directory
67         "a/b" make-directory
68         "a/b/c" make-directory
69         "a/b/c/d" make-directory
70         "a/b/c/d/e" touch-file
71         "a/b/c/f" touch-file
72         "a/b/g" touch-file
73         "a/b/h" make-directory
74         "a/b/h/e" touch-file
75         "a/e" make-directory
76         "a/e/f" touch-file
77         "a/e/g" make-directory
78         "a/e/g/e" touch-file
79
80         "**" glob natural-sort
81         "**/" glob natural-sort
82         "**/*" glob natural-sort
83         "**/**" glob natural-sort
84         "**/b" glob natural-sort
85         "**/e" glob natural-sort
86         ! "**//e" glob natural-sort
87         ! "**/**/e" glob natural-sort
88         "**/e/**" glob natural-sort
89         "a/**" glob natural-sort
90         "a" glob natural-sort
91         "a/b" glob natural-sort
92     ] with-test-directory
93 ] unit-test