gtk and wayland update
[jackhill/guix/guix.git] / tests / glob.scm
CommitLineData
f14c933d
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
371ba7b4 3;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
f14c933d
LC
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (test-glob)
21 #:use-module (guix glob)
22 #:use-module (srfi srfi-64))
23
24\f
25(test-begin "glob")
26
71e08fde 27(define-syntax test-string->sglob
e914b398
LC
28 (syntax-rules (=>)
29 ((_ pattern => result rest ...)
30 (begin
71e08fde 31 (test-equal (format #f "string->sglob, ~s" pattern)
e914b398 32 result
71e08fde
LC
33 (string->sglob pattern))
34 (test-string->sglob rest ...)))
e914b398
LC
35 ((_)
36 #t)))
f14c933d 37
e914b398
LC
38(define-syntax test-glob-match
39 (syntax-rules (matches and not)
40 ((_ (pattern-string matches strings ... (and not others ...)) rest ...)
41 (begin
42 (test-assert (format #f "glob-match? ~s" pattern-string)
71e08fde 43 (let ((pattern (string->compiled-sglob pattern-string)))
e914b398
LC
44 (and (glob-match? pattern strings) ...
45 (not (glob-match? pattern others)) ...)))
46 (test-glob-match rest ...)))
47 ((_)
48 #t)))
f14c933d 49
71e08fde 50(test-string->sglob
e914b398
LC
51 "foo" => "foo"
52 "?foo*" => '(? "foo" *)
53 "foo[1-5]" => '("foo" (range #\1 #\5))
54 "foo[abc]bar" => '("foo" (set #\a #\b #\c) "bar")
55 "foo[a[b]c]bar" => '("foo" (set #\a #\[ #\b #\] #\c) "bar")
56 "[123]x" => '((set #\1 #\2 #\3) "x")
371ba7b4
GL
57 "[a-z]" => '((range #\a #\z))
58 "**/*.scm" => '(**/ * ".scm"))
f14c933d 59
e914b398
LC
60(test-glob-match
61 ("foo" matches "foo" (and not "foobar" "barfoo"))
62 ("foo*" matches "foo" "foobar" (and not "xfoo"))
63 ("foo??bar" matches "fooxxbar" "fooZZbar"
64 (and not "foobar" "fooxxxbar" "fooxxbarzz"))
65 ("foo?" matches "foox" (and not "fooxx"))
66 ("ab[0-9]c" matches "ab0c" "ab7c" "ab9c"
67 (and not "ab-c" "ab00c" "ab3"))
68 ("ab[cdefg]" matches "abc" "abd" "abg"
371ba7b4
GL
69 (and not "abh" "abcd" "ab["))
70 ("foo/**/*.scm" matches "foo/bar/baz.scm" "foo/bar.scm" "foo/bar/baz/zab.scm"
71 (and not "foo/bar/baz.java" "foo/bar.smc")))
f14c933d
LC
72
73(test-end "glob")