Skip to content

Commit fb03792

Browse files
zachallaunjosevalim
authored andcommitted
Fix Code.Fragment.surround_context/2 for submodules of non-aliases (#12890)
1 parent def65ab commit fb03792

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

lib/elixir/lib/code/fragment.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ defmodule Code.Fragment do
677677
{{:alias, acc}, offset} ->
678678
build_surround({:alias, acc}, reversed, line, offset)
679679

680+
{{:alias, parent, acc}, offset} ->
681+
build_surround({:alias, parent, acc}, reversed, line, offset)
682+
680683
{{:struct, acc}, offset} ->
681684
build_surround({:struct, acc}, reversed, line, offset)
682685

lib/elixir/test/elixir/code_fragment_test.exs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,21 @@ defmodule CodeFragmentTest do
755755
end: {1, 11}
756756
}
757757

758-
assert CF.surround_context("__MODULE__.Foo", {1, 12}) == %{
759-
context: {:alias, {:local_or_var, ~c"__MODULE__"}, ~c"Foo"},
760-
begin: {1, 1},
761-
end: {1, 15}
762-
}
758+
for i <- 1..15 do
759+
assert CF.surround_context("__MODULE__.Foo", {1, i}) == %{
760+
context: {:alias, {:local_or_var, ~c"__MODULE__"}, ~c"Foo"},
761+
begin: {1, 1},
762+
end: {1, 15}
763+
}
764+
end
763765

764-
assert CF.surround_context("__MODULE__.Foo.Sub", {1, 16}) == %{
765-
context: {:alias, {:local_or_var, ~c"__MODULE__"}, ~c"Foo.Sub"},
766-
begin: {1, 1},
767-
end: {1, 19}
768-
}
766+
for i <- 1..19 do
767+
assert CF.surround_context("__MODULE__.Foo.Sub", {1, i}) == %{
768+
context: {:alias, {:local_or_var, ~c"__MODULE__"}, ~c"Foo.Sub"},
769+
begin: {1, 1},
770+
end: {1, 19}
771+
}
772+
end
769773

770774
assert CF.surround_context("%__MODULE__{}", {1, 5}) == %{
771775
context: {:struct, {:local_or_var, ~c"__MODULE__"}},
@@ -811,17 +815,21 @@ defmodule CodeFragmentTest do
811815
end
812816

813817
test "attribute submodules" do
814-
assert CF.surround_context("@some.Foo", {1, 8}) == %{
815-
context: {:alias, {:module_attribute, ~c"some"}, ~c"Foo"},
816-
begin: {1, 1},
817-
end: {1, 10}
818-
}
818+
for i <- 1..10 do
819+
assert CF.surround_context("@some.Foo", {1, i}) == %{
820+
context: {:alias, {:module_attribute, ~c"some"}, ~c"Foo"},
821+
begin: {1, 1},
822+
end: {1, 10}
823+
}
824+
end
819825

820-
assert CF.surround_context("@some.Foo.Sub", {1, 12}) == %{
821-
context: {:alias, {:module_attribute, ~c"some"}, ~c"Foo.Sub"},
822-
begin: {1, 1},
823-
end: {1, 14}
824-
}
826+
for i <- 1..14 do
827+
assert CF.surround_context("@some.Foo.Sub", {1, i}) == %{
828+
context: {:alias, {:module_attribute, ~c"some"}, ~c"Foo.Sub"},
829+
begin: {1, 1},
830+
end: {1, 14}
831+
}
832+
end
825833

826834
assert CF.surround_context("%@some{}", {1, 5}) == %{
827835
context: {:struct, {:module_attribute, ~c"some"}},

0 commit comments

Comments
 (0)