brixen / rubyspec
- Source
- Commits
- Network (2)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
799fd9d
commit 799fd9dc4e9b6d731d4d789687ee46d2949c3270
tree 25f0118d5379423ad270cda2f7bad41f53ff0fa3
parent 68b51a512dcca1e853a98f648957775b8ee7c060
tree 25f0118d5379423ad270cda2f7bad41f53ff0fa3
parent 68b51a512dcca1e853a98f648957775b8ee7c060
| 6c1c34a6 » | brixen | 2008-05-09 | 1 | shared :dir_glob do |cmd| | |
| 2 | describe "Dir.#{cmd}" do | ||||
| 3 | before(:all) do | ||||
| 4 | @cwd = Dir.pwd | ||||
| 5 | Dir.chdir DirSpecs.mock_dir | ||||
| 6 | end | ||||
| 7 | |||||
| 8 | it "matches non-dotfiles with '*'" do | ||||
| 9 | expected = %w[ | ||||
| 10 | deeply | ||||
| 11 | dir | ||||
| 799fd9dc » | nicksieger | 2008-05-14 | 12 | dir_filename_ordering | |
| 13 | file_one.ext | ||||
| 6c1c34a6 » | brixen | 2008-05-09 | 14 | file_two.ext | |
| 15 | nondotfile | ||||
| 16 | special | ||||
| 17 | subdir_one | ||||
| 18 | subdir_two | ||||
| 19 | ] | ||||
| 20 | |||||
| 21 | Dir.send(cmd,'*').sort.should == expected | ||||
| 22 | end | ||||
| 23 | |||||
| 24 | it "returns empty array when empty pattern provided" do | ||||
| 25 | Dir.send(cmd, '').should == [] | ||||
| 26 | end | ||||
| 27 | |||||
| 28 | it "matches regexp special +" do | ||||
| 29 | Dir.send(cmd, 'special/+').should == ['special/+'] | ||||
| 30 | end | ||||
| 31 | |||||
| 32 | platform_is_not :windows do | ||||
| 33 | it "matches regexp special *" do | ||||
| 34 | Dir.send(cmd, 'special/\*').should == ['special/*'] | ||||
| 35 | end | ||||
| 36 | |||||
| 37 | it "matches regexp special ?" do | ||||
| 38 | Dir.send(cmd, 'special/\?').should == ['special/?'] | ||||
| 39 | end | ||||
| 40 | |||||
| 41 | it "matches regexp special |" do | ||||
| 42 | Dir.send(cmd, 'special/|').should == ['special/|'] | ||||
| 43 | end | ||||
| 44 | end | ||||
| 45 | |||||
| 46 | it "matches regexp special ^" do | ||||
| 47 | Dir.send(cmd, 'special/^').should == ['special/^'] | ||||
| 48 | end | ||||
| 49 | |||||
| 50 | it "matches regexp special $" do | ||||
| 51 | Dir.send(cmd, 'special/$').should == ['special/$'] | ||||
| 52 | end | ||||
| 53 | |||||
| 54 | it "matches regexp special (" do | ||||
| 55 | Dir.send(cmd, 'special/(').should == ['special/('] | ||||
| 56 | end | ||||
| 57 | |||||
| 58 | it "matches regexp special )" do | ||||
| 59 | Dir.send(cmd, 'special/)').should == ['special/)'] | ||||
| 60 | end | ||||
| 61 | |||||
| 62 | it "matches regexp special [" do | ||||
| 63 | Dir.send(cmd, 'special/\[').should == ['special/['] | ||||
| 64 | end | ||||
| 65 | |||||
| 66 | it "matches regexp special ]" do | ||||
| 67 | Dir.send(cmd, 'special/]').should == ['special/]'] | ||||
| 68 | end | ||||
| 69 | |||||
| 70 | it "matches regexp special {" do | ||||
| 71 | Dir.send(cmd, 'special/\{').should == ['special/{'] | ||||
| 72 | end | ||||
| 73 | |||||
| 74 | it "matches regexp special }" do | ||||
| 75 | Dir.send(cmd, 'special/\}').should == ['special/}'] | ||||
| 76 | end | ||||
| 77 | |||||
| 78 | it "matches dotfiles with '.*'" do | ||||
| 79 | Dir.send(cmd, '.*').sort.should == %w|. .. .dotfile .dotsubdir|.sort | ||||
| 80 | end | ||||
| 81 | |||||
| 82 | it "matches non-dotfiles with '*<non-special characters>'" do | ||||
| 83 | Dir.send(cmd, '*file').sort.should == %w|nondotfile|.sort | ||||
| 84 | end | ||||
| 85 | |||||
| 86 | it "matches dotfiles with '.*<non-special characters>'" do | ||||
| 87 | Dir.send(cmd, '.*file').sort.should == %w|.dotfile|.sort | ||||
| 88 | end | ||||
| 89 | |||||
| 90 | it "matches files with any ending with '<non-special characters>*'" do | ||||
| 91 | Dir.send(cmd, 'file*').sort.should == %w|file_one.ext file_two.ext|.sort | ||||
| 92 | end | ||||
| 93 | |||||
| 94 | it "matches files with any middle with '<non-special characters>*<non-special characters>'" do | ||||
| 95 | Dir.send(cmd, 'sub*_one').sort.should == %w|subdir_one|.sort | ||||
| 96 | end | ||||
| 97 | |||||
| 98 | it "matches files with multiple '*' special characters" do | ||||
| 99 | Dir.send(cmd, '*fi*e*').sort.should == %w|dir_filename_ordering nondotfile file_one.ext file_two.ext|.sort | ||||
| 799fd9dc » | nicksieger | 2008-05-14 | 100 | end | |
| 6c1c34a6 » | brixen | 2008-05-09 | 101 | ||
| 102 | it "matches non-dotfiles in the current directory with '**'" do | ||||
| 103 | expected = %w[ | ||||
| 104 | deeply | ||||
| 105 | dir | ||||
| 799fd9dc » | nicksieger | 2008-05-14 | 106 | dir_filename_ordering | |
| 107 | file_one.ext | ||||
| 6c1c34a6 » | brixen | 2008-05-09 | 108 | file_two.ext | |
| 109 | nondotfile | ||||
| 110 | special | ||||
| 111 | subdir_one | ||||
| 112 | subdir_two | ||||
| 113 | ] | ||||
| 114 | |||||
| 115 | Dir.send(cmd, '**').sort.should == expected | ||||
| 116 | end | ||||
| 117 | |||||
| 118 | it "matches dotfiles in the current directory with '.**'" do | ||||
| 119 | Dir.send(cmd, '.**').sort.should == %w|. .. .dotsubdir .dotfile|.sort | ||||
| 120 | end | ||||
| 121 | |||||
| 122 | it "recursively matches any nondot subdirectories with '**/'" do | ||||
| 123 | expected = %w[ | ||||
| 124 | deeply/ | ||||
| 125 | deeply/nested/ | ||||
| 126 | deeply/nested/directory/ | ||||
| 127 | deeply/nested/directory/structure/ | ||||
| 128 | dir/ | ||||
| 799fd9dc » | nicksieger | 2008-05-14 | 129 | special/ | |
| 6c1c34a6 » | brixen | 2008-05-09 | 130 | subdir_one/ | |
| 131 | subdir_two/ | ||||
| 132 | ] | ||||
| 133 | |||||
| 134 | Dir.send(cmd, '**/').sort.should == expected | ||||
| 135 | end | ||||
| 136 | |||||
| 137 | it "recursively matches any subdirectories including ./ and ../ with '.**/'" do | ||||
| 138 | Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do | ||||
| 139 | Dir.send(cmd, '.**/').sort.should == %w|./ ../|.sort | ||||
| 140 | end | ||||
| 141 | end | ||||
| 142 | |||||
| 143 | it "matches a single character except leading '.' with '?'" do | ||||
| 144 | Dir.send(cmd, '?ubdir_one').sort.should == %w|subdir_one|.sort | ||||
| 145 | end | ||||
| 146 | |||||
| 147 | it "accepts multiple '?' characters in a pattern" do | ||||
| 148 | Dir.send(cmd, 'subdir_???').sort.should == %w|subdir_one subdir_two|.sort | ||||
| 149 | end | ||||
| 150 | |||||
| 151 | it "matches any characters in a set with '[<characters>]'" do | ||||
| 152 | Dir.send(cmd, '[stfu]ubdir_one').sort.should == %w|subdir_one|.sort | ||||
| 153 | end | ||||
| 154 | |||||
| 155 | it "matches any characters in a range with '[<character>-<character>]'" do | ||||
| 156 | Dir.send(cmd, '[a-zA-Z]ubdir_one').sort.should == %w|subdir_one|.sort | ||||
| 157 | end | ||||
| 158 | |||||
| 159 | it "matches any characters except those in a set with '[^<characters>]'" do | ||||
| 160 | Dir.send(cmd, '[^wtf]ubdir_one').sort.should == %w|subdir_one|.sort | ||||
| 161 | end | ||||
| 162 | |||||
| 163 | it "matches any characters except those in a range with '[^<character>-<character]'" do | ||||
| 164 | Dir.send(cmd, '[^0-9]ubdir_one').sort.should == %w|subdir_one|.sort | ||||
| 165 | end | ||||
| 166 | |||||
| 167 | it "matches any one of the strings in a set with '{<string>,<other>,...}'" do | ||||
| 168 | Dir.send(cmd, 'subdir_{one,two,three}').sort.should == %w|subdir_one subdir_two|.sort | ||||
| 169 | end | ||||
| 170 | |||||
| 171 | it "accepts string sets with empty strings with {<string>,,<other>}" do | ||||
| 172 | a = Dir.send(cmd, 'deeply/nested/directory/structure/file_one{.ext,}').sort | ||||
| 173 | a.should == %w|deeply/nested/directory/structure/file_one.ext | ||||
| 174 | deeply/nested/directory/structure/file_one|.sort | ||||
| 175 | end | ||||
| 176 | |||||
| 177 | it "matches dot or non-dotfiles with '{,.}*'" do | ||||
| 178 | Dir.send(cmd, '{,.}*').sort.should == DirSpecs.expected_paths | ||||
| 179 | end | ||||
| 180 | |||||
| 181 | it "matches special characters by escaping with a backslash with '\\<character>'" do | ||||
| 182 | Dir.mkdir 'foo*bar' | ||||
| 183 | |||||
| 184 | begin | ||||
| 185 | Dir.glob('foo?bar').should == %w|foo*bar| | ||||
| 186 | Dir.glob('foo\?bar').should == [] | ||||
| 187 | Dir.glob('nond\otfile').should == %w|nondotfile| | ||||
| 188 | ensure | ||||
| 189 | Dir.rmdir 'foo*bar' | ||||
| 190 | end | ||||
| 191 | end | ||||
| 192 | |||||
| 193 | it "recursively matches directories with '**/<characters>'" do | ||||
| 194 | %w|glob []|.each {|cmd| | ||||
| 195 | Dir.send(cmd, '**/*fil?{,.}*').sort.should == %w|deeply/nested/directory/structure/file_one | ||||
| 799fd9dc » | nicksieger | 2008-05-14 | 196 | deeply/nested/directory/structure/file_one.ext | |
| 197 | deeply/nondotfile | ||||
| 198 | dir/filename_ordering | ||||
| 199 | dir_filename_ordering | ||||
| 200 | file_one.ext file_two.ext | ||||
| 201 | nondotfile subdir_one/nondotfile | ||||
| 202 | subdir_two/nondotfile | ||||
| 203 | subdir_two/nondotfile.ext | ||||
| 204 | subdir_two/nondotfile.ext| | ||||
| 6c1c34a6 » | brixen | 2008-05-09 | 205 | } | |
| 206 | end | ||||
| 207 | |||||
| 799fd9dc » | nicksieger | 2008-05-14 | 208 | it "orders directory-based entries before files when a glob matches both" do | |
| 209 | expected = %w[dir/filename_ordering dir_filename_ordering] | ||||
| 210 | %w|glob []|.each do |cmd| | ||||
| 211 | Dir.send(cmd, '**/*filename_ordering').should == expected | ||||
| 212 | end | ||||
| 213 | end | ||||
| 214 | |||||
| 215 | after(:all) do | ||||
| 6c1c34a6 » | brixen | 2008-05-09 | 216 | Dir.chdir @cwd | |
| 217 | end | ||||
| 218 | end | ||||
| 219 | end | ||||
| 220 | |||||
