summaryrefslogtreecommitdiff
path: root/lib/iex/test/iex/autocomplete_test.exs
diff options
context:
space:
mode:
authorAleksei Magusev <lexmag@me.com>2016-12-19 18:18:08 +0100
committerAleksei Magusev <lexmag@me.com>2016-12-20 11:02:45 +0100
commit8cbf79ff69c26db540b22f452580187e72c01501 (patch)
tree902b814563592e7e53bd33a81794e1f817120169 /lib/iex/test/iex/autocomplete_test.exs
parente417ab8283d5f0ec05ca5d23f6cb1dd698d11707 (diff)
downloadelixir-8cbf79ff69c26db540b22f452580187e72c01501.tar.gz
Replace :previous_line tagging with eval/1 in IEx.AutocompleteTest
Diffstat (limited to 'lib/iex/test/iex/autocomplete_test.exs')
-rw-r--r--lib/iex/test/iex/autocomplete_test.exs50
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/iex/test/iex/autocomplete_test.exs b/lib/iex/test/iex/autocomplete_test.exs
index 2214fedea..03c756e84 100644
--- a/lib/iex/test/iex/autocomplete_test.exs
+++ b/lib/iex/test/iex/autocomplete_test.exs
@@ -3,18 +3,9 @@ Code.require_file "../test_helper.exs", __DIR__
defmodule IEx.AutocompleteTest do
use ExUnit.Case, async: true
- setup context do
- ExUnit.CaptureIO.capture_io(fn ->
- evaluator = IEx.Server.start_evaluator([])
- Process.put(:evaluator, evaluator)
-
- previous_line = context[:previous_line]
- if previous_line do
- send evaluator, {:eval, self(), previous_line <> "\n", %IEx.State{}}
- assert_receive {:evaled, _, _}
- end
- end)
-
+ setup do
+ evaluator = IEx.Server.start_evaluator([])
+ Process.put(:evaluator, evaluator)
:ok
end
@@ -24,6 +15,15 @@ defmodule IEx.AutocompleteTest do
end
end
+ defp eval(line) do
+ ExUnit.CaptureIO.capture_io(fn ->
+ evaluator = MyServer.evaluator
+ Process.group_leader(evaluator, Process.group_leader)
+ send evaluator, {:eval, self(), line <> "\n", %IEx.State{}}
+ assert_receive {:evaled, _, _}
+ end)
+ end
+
defp expand(expr) do
IEx.Autocomplete.expand(Enum.reverse(expr), MyServer)
end
@@ -114,13 +114,13 @@ defmodule IEx.AutocompleteTest do
assert expand('String.printable?/') == {:yes, '', ['printable?/1']}
end
- @tag previous_line: "mod = String"
test "function completion using a variable bound to a module" do
+ eval("mod = String")
assert expand('mod.print') == {:yes, 'able?', []}
end
- @tag previous_line: "map = %{foo: 1, bar_1: 23, bar_2: 14}"
test "map atom key completion is supported" do
+ eval("map = %{foo: 1, bar_1: 23, bar_2: 14}")
assert expand('map.f') == {:yes, 'oo', []}
assert expand('map.b') == {:yes, 'ar_', []}
assert expand('map.bar_') == {:yes, '', ['bar_1', 'bar_2']}
@@ -129,8 +129,8 @@ defmodule IEx.AutocompleteTest do
assert expand('map.foo') == {:no, '', []}
end
- @tag previous_line: "map = %{nested: %{deeply: %{foo: 1, bar_1: 23, bar_2: 14, mod: String, num: 1}}}"
test "nested map atom key completion is supported" do
+ eval("map = %{nested: %{deeply: %{foo: 1, bar_1: 23, bar_2: 14, mod: String, num: 1}}}")
assert expand('map.nested.deeply.f') == {:yes, 'oo', []}
assert expand('map.nested.deeply.b') == {:yes, 'ar_', []}
assert expand('map.nested.deeply.bar_') == {:yes, '', ['bar_1', 'bar_2']}
@@ -145,27 +145,27 @@ defmodule IEx.AutocompleteTest do
assert expand('map.a.b.c.f') == {:no, '', []}
end
- @tag previous_line: ~s(map = %{"foo" => 1})
test "map string key completion is not supported" do
+ eval(~S(map = %{"foo" => 1}))
assert expand('map.f') == {:no, '', []}
end
- @tag previous_line: "num = 5; map = %{nested: %{num: 23}}"
test "autocompletion off a bound variable only works for modules and maps" do
+ eval("num = 5; map = %{nested: %{num: 23}}")
assert expand('num.print') == {:no, '', []}
assert expand('map.nested.num.f') == {:no, '', []}
assert expand('map.nested.num.key.f') == {:no, '', []}
end
- @tag previous_line: "map = %{nested: %{deeply: %{num: 23}}}"
test "autocompletion using access syntax does is not supported" do
+ eval("map = %{nested: %{deeply: %{num: 23}}}")
assert expand('map[:nested][:deeply].n') == {:no, '', []}
assert expand('map[:nested].deeply.n') == {:no, '', []}
assert expand('map.nested.[:deeply].n') == {:no, '', []}
end
- @tag previous_line: "num = 5"
test "autocompletion off of unbound variables is not supported" do
+ eval("num = 5")
assert expand('other_var.f') == {:no, '', []}
assert expand('a.b.c.d') == {:no, '', []}
end
@@ -188,15 +188,15 @@ defmodule IEx.AutocompleteTest do
assert expand('put_') == {:yes, '', ['put_elem/3', 'put_in/2', 'put_in/3']}
end
- @tag previous_line: "numeral = 3; number = 3; nothing = nil"
test "variable name completion" do
+ eval("numeral = 3; number = 3; nothing = nil")
assert expand('numb') == {:yes, 'er', []}
assert expand('num') == {:yes, '', ['number', 'numeral']}
assert expand('no') == {:yes, '', ['nothing', 'node/0', 'node/1', 'not/1']}
end
- @tag previous_line: "import Enum; import Supervisor, only: [count_children: 1]; import Protocol"
test "completion of manually imported functions and macros" do
+ eval("import Enum; import Supervisor, only: [count_children: 1]; import Protocol")
assert expand('take') == {:yes, '', ['take/2', 'take_every/2', 'take_random/2', 'take_while/2']}
assert expand('count') == {:yes, '', ['count/1', 'count/2', 'count_children/1']}
assert expand('der') == {:yes, 'ive', []}
@@ -206,8 +206,8 @@ defmodule IEx.AutocompleteTest do
quote do: var!(my_var_1, Elixir) = 1
end
- @tag previous_line: "require #{__MODULE__}; #{__MODULE__}.define_var(); my_var_2 = 2"
test "ignores quoted variables when performing variable completion" do
+ eval("require #{__MODULE__}; #{__MODULE__}.define_var(); my_var_2 = 2")
assert expand('my_var') == {:yes, '_2', []}
end
@@ -236,15 +236,15 @@ defmodule IEx.AutocompleteTest do
assert expand('IEx.AutocompleteTest.SublevelTest.') == {:yes, 'LevelA', []}
end
- @tag previous_line: "alias List, as: MyList"
test "complete aliases of Elixir modules" do
+ eval("alias List, as: MyList")
assert expand('MyL') == {:yes, 'ist', []}
assert expand('MyList') == {:yes, '.', []}
assert expand('MyList.to_integer') == {:yes, [], ['to_integer/1', 'to_integer/2']}
end
- @tag previous_line: "alias :lists, as: EList"
test "complete aliases of Erlang modules" do
+ eval("alias :lists, as: EList")
assert expand('EL') == {:yes, 'ist', []}
assert expand('EList') == {:yes, '.', []}
assert expand('EList.map') == {:yes, [], ['map/2', 'mapfoldl/3', 'mapfoldr/3']}
@@ -280,8 +280,8 @@ defmodule IEx.AutocompleteTest do
assert expand('%IEx.AutocompleteTest.MyStr') == {:yes, 'uct', []}
end
- @tag previous_line: "struct = %IEx.AutocompleteTest.MyStruct{}"
test "completion for struct keys" do
+ eval("struct = %IEx.AutocompleteTest.MyStruct{}")
assert expand('struct.my') == {:yes, '_val', []}
end
end