| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (test-glob)
|
| 21 | #:use-module (guix glob)
|
| 22 | #:use-module (srfi srfi-64))
|
| 23 |
|
| 24 |
|
| 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")
|