summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_file.rb104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index a0cd5e2c24..637dced6a6 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -73,6 +73,33 @@ class TestFile < Test::Unit::TestCase
assert(File.fnmatch('ca[a-or-z]', 'can'))
assert(!File.fnmatch('ca[a-or-z]', 'cap'))
assert(File.fnmatch('ca[a-or-z]', 'cat'))
+ s = "[bd-gikl-mosv-x]"
+ assert(!File.fnmatch(s, 'a'))
+ assert(File.fnmatch(s, 'b'))
+ assert(!File.fnmatch(s, 'c'))
+ assert(File.fnmatch(s, 'd'))
+ assert(File.fnmatch(s, 'e'))
+ assert(File.fnmatch(s, 'f'))
+ assert(File.fnmatch(s, 'g'))
+ assert(!File.fnmatch(s, 'h'))
+ assert(File.fnmatch(s, 'i'))
+ assert(!File.fnmatch(s, 'j'))
+ assert(File.fnmatch(s, 'k'))
+ assert(File.fnmatch(s, 'l'))
+ assert(File.fnmatch(s, 'm'))
+ assert(!File.fnmatch(s, 'n'))
+ assert(File.fnmatch(s, 'o'))
+ assert(!File.fnmatch(s, 'p'))
+ assert(!File.fnmatch(s, 'q'))
+ assert(!File.fnmatch(s, 'r'))
+ assert(File.fnmatch(s, 's'))
+ assert(!File.fnmatch(s, 't'))
+ assert(!File.fnmatch(s, 'u'))
+ assert(File.fnmatch(s, 'v'))
+ assert(File.fnmatch(s, 'w'))
+ assert(File.fnmatch(s, 'x'))
+ assert(!File.fnmatch(s, 'y'))
+ assert(!File.fnmatch(s, 'z'))
# matches any character except those listed between bracket
assert(File.fnmatch('ca[!pt]', 'can'))
assert(!File.fnmatch('ca[!pt]', 'cap'))
@@ -86,20 +113,97 @@ class TestFile < Test::Unit::TestCase
assert(!File.fnmatch('ca[^a-or-z]', 'can'))
assert(File.fnmatch('ca[^a-or-z]', 'cap'))
assert(!File.fnmatch('ca[^a-or-z]', 'cat'))
+ s = "[^bd-gikl-mosv-x]"
+ assert(File.fnmatch(s, 'a'))
+ assert(!File.fnmatch(s, 'b'))
+ assert(File.fnmatch(s, 'c'))
+ assert(!File.fnmatch(s, 'd'))
+ assert(!File.fnmatch(s, 'e'))
+ assert(!File.fnmatch(s, 'f'))
+ assert(!File.fnmatch(s, 'g'))
+ assert(File.fnmatch(s, 'h'))
+ assert(!File.fnmatch(s, 'i'))
+ assert(File.fnmatch(s, 'j'))
+ assert(!File.fnmatch(s, 'k'))
+ assert(!File.fnmatch(s, 'l'))
+ assert(!File.fnmatch(s, 'm'))
+ assert(File.fnmatch(s, 'n'))
+ assert(!File.fnmatch(s, 'o'))
+ assert(File.fnmatch(s, 'p'))
+ assert(File.fnmatch(s, 'q'))
+ assert(File.fnmatch(s, 'r'))
+ assert(!File.fnmatch(s, 's'))
+ assert(File.fnmatch(s, 't'))
+ assert(File.fnmatch(s, 'u'))
+ assert(!File.fnmatch(s, 'v'))
+ assert(!File.fnmatch(s, 'w'))
+ assert(!File.fnmatch(s, 'x'))
+ assert(File.fnmatch(s, 'y'))
+ assert(File.fnmatch(s, 'z'))
+ s = "[!bd-gikl-mosv-x]"
+ assert(File.fnmatch(s, 'a'))
+ assert(!File.fnmatch(s, 'b'))
+ assert(File.fnmatch(s, 'c'))
+ assert(!File.fnmatch(s, 'd'))
+ assert(!File.fnmatch(s, 'e'))
+ assert(!File.fnmatch(s, 'f'))
+ assert(!File.fnmatch(s, 'g'))
+ assert(File.fnmatch(s, 'h'))
+ assert(!File.fnmatch(s, 'i'))
+ assert(File.fnmatch(s, 'j'))
+ assert(!File.fnmatch(s, 'k'))
+ assert(!File.fnmatch(s, 'l'))
+ assert(!File.fnmatch(s, 'm'))
+ assert(File.fnmatch(s, 'n'))
+ assert(!File.fnmatch(s, 'o'))
+ assert(File.fnmatch(s, 'p'))
+ assert(File.fnmatch(s, 'q'))
+ assert(File.fnmatch(s, 'r'))
+ assert(!File.fnmatch(s, 's'))
+ assert(File.fnmatch(s, 't'))
+ assert(File.fnmatch(s, 'u'))
+ assert(!File.fnmatch(s, 'v'))
+ assert(!File.fnmatch(s, 'w'))
+ assert(!File.fnmatch(s, 'x'))
+ assert(File.fnmatch(s, 'y'))
+ assert(File.fnmatch(s, 'z'))
# escaping character
assert(File.fnmatch('\?', '?'))
+ assert(!File.fnmatch('\?', '\?'))
assert(!File.fnmatch('\?', 'a'))
+ assert(!File.fnmatch('\?', '\a'))
assert(File.fnmatch('\*', '*'))
+ assert(!File.fnmatch('\*', '\*'))
assert(!File.fnmatch('\*', 'cats'))
+ assert(!File.fnmatch('\*', '\cats'))
assert(File.fnmatch('\a', 'a'))
+ assert(!File.fnmatch('\a', '\a'))
assert(File.fnmatch('[a\-c]', 'a'))
assert(File.fnmatch('[a\-c]', '-'))
assert(File.fnmatch('[a\-c]', 'c'))
assert(!File.fnmatch('[a\-c]', 'b'))
assert(!File.fnmatch('[a\-c]', '\\'))
+ # escaping character loses its meaning if FNM_NOESCAPE is set
+ assert(!File.fnmatch('\?', '?', File::FNM_NOESCAPE))
+ assert(File.fnmatch('\?', '\?', File::FNM_NOESCAPE))
+ assert(!File.fnmatch('\?', 'a', File::FNM_NOESCAPE))
+ assert(File.fnmatch('\?', '\a', File::FNM_NOESCAPE))
+ assert(!File.fnmatch('\*', '*', File::FNM_NOESCAPE))
+ assert(File.fnmatch('\*', '\*', File::FNM_NOESCAPE))
+ assert(!File.fnmatch('\*', 'cats', File::FNM_NOESCAPE))
+ assert(File.fnmatch('\*', '\cats', File::FNM_NOESCAPE))
+ assert(!File.fnmatch('\a', 'a', File::FNM_NOESCAPE))
+ assert(File.fnmatch('\a', '\a', File::FNM_NOESCAPE))
+ assert(File.fnmatch('[a\-c]', 'a', File::FNM_NOESCAPE))
+ assert(!File.fnmatch('[a\-c]', '-', File::FNM_NOESCAPE))
+ assert(File.fnmatch('[a\-c]', 'c', File::FNM_NOESCAPE))
+ assert(File.fnmatch('[a\-c]', 'b', File::FNM_NOESCAPE)) # '\\' < 'b' < 'c'
+ assert(File.fnmatch('[a\-c]', '\\', File::FNM_NOESCAPE))
# case is ignored if FNM_CASEFOLD is set
assert(!File.fnmatch('cat', 'CAT'))
assert(File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD))
+ assert(!File.fnmatch('[a-z]', 'D'))
+ assert(File.fnmatch('[a-z]', 'D', File::FNM_CASEFOLD))
# wildcard doesn't match '/' if FNM_PATHNAME is set
assert(File.fnmatch('foo?boo', 'foo/boo'))
assert(File.fnmatch('foo*', 'foo/boo'))