gnu: nginx: Update to 1.21.0 [fixes CVE-2021-23017].
[jackhill/guix/guix.git] / tests / glob.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
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
27 (define-syntax test-string->sglob
28 (syntax-rules (=>)
29 ((_ pattern => result rest ...)
30 (begin
31 (test-equal (format #f "string->sglob, ~s" pattern)
32 result
33 (string->sglob pattern))
34 (test-string->sglob rest ...)))
35 ((_)
36 #t)))
37
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)
43 (let ((pattern (string->compiled-sglob pattern-string)))
44 (and (glob-match? pattern strings) ...
45 (not (glob-match? pattern others)) ...)))
46 (test-glob-match rest ...)))
47 ((_)
48 #t)))
49
50 (test-string->sglob
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")
57 "[a-z]" => '((range #\a #\z))
58 "**/*.scm" => '(**/ * ".scm"))
59
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"
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")))
72
73 (test-end "glob")