diff options
author | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-08-02 14:35:06 +0000 |
---|---|---|
committer | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-08-02 14:35:06 +0000 |
commit | 84fddcff2ff32077f0f90620494f68d3f3c0eb8f (patch) | |
tree | 45091405e0d1e0d761e0dad38bc1253b0ae9d221 | |
parent | b259fddba810a4ae2d18f99dfbc414898b426821 (diff) | |
download | ruby-84fddcff2ff32077f0f90620494f68d3f3c0eb8f.tar.gz |
* test/ruby/test_file.rb (test_fnmatch): added more tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | test/ruby/test_file.rb | 104 |
2 files changed, 108 insertions, 0 deletions
@@ -1,3 +1,7 @@ +Mon Aug 2 23:33:48 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> + + * test/ruby/test_file.rb (test_fnmatch): added more tests. + Mon Aug 2 18:04:21 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tk/lib/tk/msgcat.rb (set_translation): bug fix (fail to set 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')) |