|
195 | 195 | expect(directory.to_directory).to be == directory |
196 | 196 | end |
197 | 197 | end |
| 198 | + |
198 | 199 | it "should start with the given path" do |
199 | 200 | path = Utopia::Path["/a/b/c/d/e"] |
200 | 201 |
|
|
263 | 264 |
|
264 | 265 | expect((output + short).simplify).to be == input |
265 | 266 | end |
| 267 | + |
| 268 | + with "#simplify" do |
| 269 | + it "doesn't remove leading .. from relative paths" do |
| 270 | + path = Utopia::Path["../foo/bar"] |
| 271 | + simplified = path.simplify |
| 272 | + |
| 273 | + expect(simplified.components).to be == ["..", "foo", "bar"] |
| 274 | + end |
| 275 | + |
| 276 | + it "removes redundant .. from absolute paths" do |
| 277 | + path = Utopia::Path["/foo/../../bar"] |
| 278 | + simplified = path.simplify |
| 279 | + |
| 280 | + expect(simplified.components).to be == ["", "bar"] |
| 281 | + end |
| 282 | + |
| 283 | + it "preserves excess .. for purely relative paths" do |
| 284 | + # ../../foo cannot be reduced without a base; keep leading .. components |
| 285 | + path = Utopia::Path["../../foo"] |
| 286 | + simplified = path.simplify |
| 287 | + |
| 288 | + expect(simplified.components).to be == ["..", "..", "foo"] |
| 289 | + end |
| 290 | + |
| 291 | + it "reduces relative paths only as far as components allow" do |
| 292 | + # foo/../../bar -> ../bar (pop foo for first .., then keep remaining ..) |
| 293 | + path = Utopia::Path["foo/../../bar"] |
| 294 | + simplified = path.simplify |
| 295 | + |
| 296 | + expect(simplified.components).to be == ["..", "bar"] |
| 297 | + end |
| 298 | + |
| 299 | + it "does not traverse above root for absolute paths" do |
| 300 | + # /a/b/../../../c -> /c (ignore .. beyond root) |
| 301 | + path = Utopia::Path["/a/b/../../../c"] |
| 302 | + simplified = path.simplify |
| 303 | + |
| 304 | + expect(simplified.components).to be == ["", "c"] |
| 305 | + end |
| 306 | + |
| 307 | + it "ignores leading .. at absolute root" do |
| 308 | + # /../../c -> /c |
| 309 | + path = Utopia::Path["/../../c"] |
| 310 | + simplified = path.simplify |
| 311 | + |
| 312 | + expect(simplified.components).to be == ["", "c"] |
| 313 | + end |
| 314 | + |
| 315 | + it "preserves trailing slash for directories after simplify" do |
| 316 | + path = Utopia::Path["/a/./b/../c/"] |
| 317 | + simplified = path.simplify |
| 318 | + |
| 319 | + expect(simplified.components).to be == ["", "a", "c", ""] |
| 320 | + end |
| 321 | + end |
266 | 322 | end |
0 commit comments