Skip to content

Commit

Permalink
Remove double .cr extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Aug 16, 2023
1 parent 606ad5c commit ed8a8b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions spec/compiler/crystal_path/crystal_path_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe Crystal::CrystalPath do
it "foo.cr" do
assert_iterates_yielding [
"x/foo.cr",
"x/foo.cr/foo.cr.cr",
"x/foo.cr/src/foo.cr.cr",
"x/foo.cr/foo.cr",
"x/foo.cr/src/foo.cr",
], path.each_file_expansion("foo.cr", "x")
end

Expand All @@ -130,11 +130,11 @@ describe Crystal::CrystalPath do
it "foo.cr/bar.cr" do
assert_iterates_yielding [
"x/foo.cr/bar.cr",
"x/foo.cr/src/bar.cr.cr",
"x/foo.cr/src/foo.cr/bar.cr.cr",
"x/foo.cr/bar.cr/bar.cr.cr",
"x/foo.cr/src/bar.cr/bar.cr.cr",
"x/foo.cr/src/foo.cr/bar.cr/bar.cr.cr",
"x/foo.cr/src/bar.cr",
"x/foo.cr/src/foo.cr/bar.cr",
"x/foo.cr/bar.cr/bar.cr",
"x/foo.cr/src/bar.cr/bar.cr",
"x/foo.cr/src/foo.cr/bar.cr/bar.cr",
], path.each_file_expansion("foo.cr/bar.cr", "x")
end

Expand All @@ -156,7 +156,7 @@ describe Crystal::CrystalPath do
it "./foo.cr" do
assert_iterates_yielding [
"x/./foo.cr",
"x/./foo.cr/foo.cr.cr",
"x/./foo.cr/foo.cr",
], path.each_file_expansion("./foo.cr", "x")
end

Expand Down
13 changes: 7 additions & 6 deletions src/compiler/crystal/crystal_path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,28 @@ module Crystal

if !filename_is_relative && shard_path
shard_src = "#{relative_to}/#{shard_name}/src"
shard_path_stem = shard_path.rchop(".cr")

# If it's "foo/bar/baz", check if "foo/src/bar/baz.cr" exists (for a shard, non-namespaced structure)
yield "#{shard_src}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_path_stem}.cr"

# Then check if "foo/src/foo/bar/baz.cr" exists (for a shard, namespaced structure)
yield "#{shard_src}/#{shard_name}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_name}/#{shard_path_stem}.cr"

# If it's "foo/bar/baz", check if "foo/bar/baz/baz.cr" exists (std, nested)
basename = File.basename(relative_filename)
basename = File.basename(relative_filename, ".cr")
yield "#{relative_filename}/#{basename}.cr"

# If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, non-namespaced, nested)
yield "#{shard_src}/#{shard_path}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_path}/#{shard_path_stem}.cr"

# If it's "foo/bar/baz", check if "foo/src/foo/bar/baz/baz.cr" exists (shard, namespaced, nested)
yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path}.cr"
yield "#{shard_src}/#{shard_name}/#{shard_path}/#{shard_path_stem}.cr"

return nil
end

basename = File.basename(relative_filename)
basename = File.basename(relative_filename, ".cr")

# If it's "foo", check if "foo/foo.cr" exists (for the std, nested)
yield "#{relative_filename}/#{basename}.cr"
Expand Down

0 comments on commit ed8a8b2

Please sign in to comment.