Commit | Line | Data |
---|---|---|
f14c933d LC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
19 | (define-module (test-glob) | |
20 | #:use-module (guix glob) | |
21 | #:use-module (srfi srfi-64)) | |
22 | ||
23 | \f | |
24 | (test-begin "glob") | |
25 | ||
71e08fde | 26 | (define-syntax test-string->sglob |
e914b398 LC |
27 | (syntax-rules (=>) |
28 | ((_ pattern => result rest ...) | |
29 | (begin | |
71e08fde | 30 | (test-equal (format #f "string->sglob, ~s" pattern) |
e914b398 | 31 | result |
71e08fde LC |
32 | (string->sglob pattern)) |
33 | (test-string->sglob rest ...))) | |
e914b398 LC |
34 | ((_) |
35 | #t))) | |
f14c933d | 36 | |
e914b398 LC |
37 | (define-syntax test-glob-match |
38 | (syntax-rules (matches and not) | |
39 | ((_ (pattern-string matches strings ... (and not others ...)) rest ...) | |
40 | (begin | |
41 | (test-assert (format #f "glob-match? ~s" pattern-string) | |
71e08fde | 42 | (let ((pattern (string->compiled-sglob pattern-string))) |
e914b398 LC |
43 | (and (glob-match? pattern strings) ... |
44 | (not (glob-match? pattern others)) ...))) | |
45 | (test-glob-match rest ...))) | |
46 | ((_) | |
47 | #t))) | |
f14c933d | 48 | |
71e08fde | 49 | (test-string->sglob |
e914b398 LC |
50 | "foo" => "foo" |
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))) | |
f14c933d | 57 | |
e914b398 LC |
58 | (test-glob-match |
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["))) | |
f14c933d LC |
68 | |
69 | (test-end "glob") |