-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the new path search algorithm
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
- 0.22.0
- 0.21.1
- 0.21.0
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
- 0.19.4
Ary Borenszweig
committed
Oct 6, 2016
1 parent
3525bcd
commit fece2f7
Showing
11 changed files
with
113 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,93 @@ | ||
require "../../spec_helper" | ||
|
||
describe Crystal::CrystalPath do | ||
it "finds file with .cr extension" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "test_files/file_one.cr" | ||
matches.should eq(["#{__DIR__}/test_files/file_one.cr"]) | ||
end | ||
|
||
it "finds file without .cr extension" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "test_files/file_one" | ||
matches.should eq(["#{__DIR__}/test_files/file_one.cr"]) | ||
end | ||
|
||
it "finds all files with *" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "test_files/*" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/file_one.cr", | ||
"#{__DIR__}/test_files/file_two.cr", | ||
]) | ||
end | ||
|
||
it "finds all files with **" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "test_files/**" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/file_one.cr", | ||
"#{__DIR__}/test_files/file_two.cr", | ||
"#{__DIR__}/test_files/test_folder/file_three.cr", | ||
"#{__DIR__}/test_files/test_folder/test_folder.cr", | ||
]) | ||
end | ||
|
||
it "finds file in directory with its basename" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "test_files/test_folder" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/test_folder/test_folder.cr", | ||
]) | ||
end | ||
|
||
it "doesn't find file relative to another one if not using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
expect_raises Exception, /can't find file/ do | ||
path.find "file_two.cr", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
end | ||
end | ||
|
||
it "finds file relative to another one if using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "./file_two.cr", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/file_two.cr", | ||
]) | ||
private def assert_finds(search, results, relative_to = nil, path = __DIR__, file = __FILE__, line = __LINE__) | ||
it "finds #{search.inspect}", file, line do | ||
crystal_path = Crystal::CrystalPath.new(path) | ||
relative_to = "#{__DIR__}/#{relative_to}" if relative_to | ||
results = results.map { |result| "#{__DIR__}/#{result}" } | ||
matches = crystal_path.find search, relative_to: relative_to | ||
matches.should eq(results) | ||
end | ||
end | ||
|
||
it "doesn't find file relative to another one with directory if not using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
private def assert_doesnt_find(search, relative_to = nil, path = __DIR__, file = __FILE__, line = __LINE__) | ||
it "doesn't finds #{search.inspect}", file, line do | ||
crystal_path = Crystal::CrystalPath.new(path) | ||
relative_to = "#{__DIR__}/#{relative_to}" if relative_to | ||
expect_raises Exception, /can't find file/ do | ||
path.find "test_folder/file_three.cr", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
crystal_path.find search, relative_to: relative_to | ||
end | ||
end | ||
end | ||
|
||
it "finds file relative to another one with directory if using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "./test_folder/file_three.cr", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/test_folder/file_three.cr", | ||
]) | ||
end | ||
describe Crystal::CrystalPath do | ||
assert_finds "test_files/file_one.cr", ["test_files/file_one.cr"] | ||
assert_finds "test_files/file_one", ["test_files/file_one.cr"] | ||
assert_finds "test_files/*", [ | ||
"test_files/file_one.cr", | ||
"test_files/file_two.cr", | ||
] | ||
assert_finds "test_files/**", [ | ||
"test_files/file_one.cr", | ||
"test_files/file_two.cr", | ||
"test_files/src/file_three.cr", | ||
"test_files/src/test_files.cr", | ||
"test_files/src/test_files/file_four.cr", | ||
"test_files/src/test_files/another/another.cr", | ||
"test_files/src/yet_another/yet_another.cr", | ||
"test_files/test_folder/file_three.cr", | ||
"test_files/test_folder/test_folder.cr", | ||
] | ||
assert_finds "./file_two.cr", relative_to: "test_files/file_one.cr", results: [ | ||
"test_files/file_two.cr", | ||
] | ||
assert_finds "./test_folder/file_three.cr", relative_to: "test_files/file_one.cr", results: [ | ||
"test_files/test_folder/file_three.cr", | ||
] | ||
assert_finds "./test_folder/*", relative_to: "test_files/file_one.cr", results: [ | ||
"test_files/test_folder/file_three.cr", | ||
"test_files/test_folder/test_folder.cr", | ||
] | ||
assert_finds "../**", relative_to: "test_files/test_folder/file_three.cr", results: [ | ||
"test_files/file_one.cr", | ||
"test_files/file_two.cr", | ||
"test_files/src/file_three.cr", | ||
"test_files/src/test_files.cr", | ||
"test_files/src/test_files/file_four.cr", | ||
"test_files/src/test_files/another/another.cr", | ||
"test_files/src/yet_another/yet_another.cr", | ||
"test_files/test_folder/file_three.cr", | ||
"test_files/test_folder/test_folder.cr", | ||
] | ||
assert_finds "../test_folder", relative_to: "test_files/test_folder/file_three.cr", results: [ | ||
"test_files/test_folder/test_folder.cr", | ||
] | ||
|
||
it "doesn't inds files with * relative to another one if not using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
expect_raises Exception, /can't find file/ do | ||
path.find "test_folder/*", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
end | ||
end | ||
# For `require "foo"`: | ||
# 1. foo.cr (to find something in the standard library) | ||
assert_finds "crystal_path_spec", ["crystal_path_spec.cr"] | ||
# 2. foo/src/foo.cr (to find something in a shard) | ||
assert_finds "test_files", ["test_files/src/test_files.cr"] | ||
|
||
it "finds files with * relative to another one if using ./" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "./test_folder/*", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/test_folder/file_three.cr", | ||
"#{__DIR__}/test_files/test_folder/test_folder.cr", | ||
]) | ||
end | ||
# For `require "foo/bar"`: | ||
# 1. foo/bar.cr (to find something in the standard library) | ||
assert_finds "test_files/file_one", ["test_files/file_one.cr"] | ||
# 2. foo/src/bar.cr (to find something in a shard, non-namespaced structure) | ||
assert_finds "test_files/file_three", ["test_files/src/file_three.cr"] | ||
# 3. foo/src/foo/bar.cr (to find something in a shard, namespaced structure) | ||
assert_finds "test_files/file_four", ["test_files/src/test_files/file_four.cr"] | ||
|
||
it "finds files with ** relative to another one" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
matches = path.find "../**", relative_to: "#{__DIR__}/test_files/test_folder/file_three.cr" | ||
matches.should eq([ | ||
"#{__DIR__}/test_files/file_one.cr", | ||
"#{__DIR__}/test_files/file_two.cr", | ||
"#{__DIR__}/test_files/test_folder/file_three.cr", | ||
"#{__DIR__}/test_files/test_folder/test_folder.cr", | ||
]) | ||
end | ||
# Nested searches | ||
# a/1. foo.cr (to find something in the standard library (nested)) | ||
assert_finds "other_test_files", ["other_test_files/other_test_files.cr"] | ||
# b/2. foo/src/bar/bar.cr (to find something in a shard, non-namespaced structure, nested) | ||
assert_finds "test_files/yet_another", ["test_files/src/yet_another/yet_another.cr"] | ||
# b/3. foo/src/foo/bar/bar.cr (to find something in a shard, namespaced structure, nested) | ||
assert_finds "test_files/another", ["test_files/src/test_files/another/another.cr"] | ||
|
||
it "doesn't find file with .cr extension" do | ||
path = Crystal::CrystalPath.new(__DIR__) | ||
expect_raises Exception, /can't find file/ do | ||
path.find "test_files/missing_file.cr" | ||
end | ||
end | ||
|
||
it "ignore an empty directory path" do | ||
path = Crystal::CrystalPath.new(":") | ||
expect_raises Exception, /can't find file/ do | ||
path.find __FILE__[1..-1] | ||
end | ||
end | ||
assert_doesnt_find "file_two.cr" | ||
assert_doesnt_find "test_folder/file_three.cr" | ||
assert_doesnt_find "test_folder/*", relative_to: "#{__DIR__}/test_files/file_one.cr" | ||
assert_doesnt_find "test_files/missing_file.cr" | ||
assert_doesnt_find __FILE__[1..-1], path: ":" | ||
end |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/doc/ | ||
/libs/ | ||
/lib/ | ||
/.crystal/ | ||
/.shards/ | ||
|
||
|