1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-glob)
20 #:use-module (guix glob)
21 #:use-module (srfi srfi-64))
26 (define-syntax test-string->sglob
28 ((_ pattern => result rest ...)
30 (test-equal (format #f "string->sglob, ~s" pattern)
32 (string->sglob pattern))
33 (test-string->sglob rest ...)))
37 (define-syntax test-glob-match
38 (syntax-rules (matches and not)
39 ((_ (pattern-string matches strings ... (and not others ...)) rest ...)
41 (test-assert (format #f "glob-match? ~s" pattern-string)
42 (let ((pattern (string->compiled-sglob pattern-string)))
43 (and (glob-match? pattern strings) ...
44 (not (glob-match? pattern others)) ...)))
45 (test-glob-match rest ...)))
51 "?foo*" => '(? "foo" *)
52 "foo[1-5]" => '("foo" (range #\1 #\5))
53 "foo[abc]bar" => '("foo" (set #\a #\b #\c) "bar")
54 "foo[a[b]c]bar" => '("foo" (set #\a #\[ #\b #\] #\c) "bar")
55 "[123]x" => '((set #\1 #\2 #\3) "x")
56 "[a-z]" => '((range #\a #\z)))
59 ("foo" matches "foo" (and not "foobar" "barfoo"))
60 ("foo*" matches "foo" "foobar" (and not "xfoo"))
61 ("foo??bar" matches "fooxxbar" "fooZZbar"
62 (and not "foobar" "fooxxxbar" "fooxxbarzz"))
63 ("foo?" matches "foox" (and not "fooxx"))
64 ("ab[0-9]c" matches "ab0c" "ab7c" "ab9c"
65 (and not "ab-c" "ab00c" "ab3"))
66 ("ab[cdefg]" matches "abc" "abd" "abg"
67 (and not "abh" "abcd" "ab[")))