gnu: jsoncpp: Update to 1.9.1.
[guix.git] / tests / glob.scm
blob313406978996023e31f749c8da4d3fbfb4ff67c5
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/>.
19 (define-module (test-glob)
20   #:use-module (guix glob)
21   #:use-module (srfi srfi-64))
24 (test-begin "glob")
26 (define-syntax test-string->sglob
27   (syntax-rules (=>)
28     ((_ pattern => result rest ...)
29      (begin
30        (test-equal (format #f "string->sglob, ~s" pattern)
31          result
32          (string->sglob pattern))
33        (test-string->sglob rest ...)))
34     ((_)
35      #t)))
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)
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 ...)))
46     ((_)
47      #t)))
49 (test-string->sglob
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)))
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[")))
69 (test-end "glob")