Skip to content

Commit 07e54cf

Browse files
authored
Fix formatter test (#154)
Previously the test was written for a version of the formatter that sent back the full code text. Adjust test to expect only the changes to the file. Also change the source text to be generally formatted.
1 parent e8d6774 commit 07e54cf

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

apps/language_server/test/server_test.exs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,53 +126,50 @@ defmodule ElixirLS.LanguageServer.ServerTest do
126126
assert %{received_shutdown?: true} = :sys.get_state(server)
127127
end
128128

129-
# TODO: Fix this test for the incremental formatter
130-
@tag :pending
131-
test "formatter", %{server: server} do
129+
test "incremental formatter", %{server: server} do
132130
in_fixture(__DIR__, "formatter", fn ->
133131
uri = Path.join([root_uri(), "file.ex"])
134-
code = ~S(
132+
133+
code = """
135134
defmodule MyModule do
136-
def my_fn do
137-
foo "This should be split into two lines if reading options from .formatter.exs"
135+
def my_fn do
136+
foo("This should be split into two lines if reading options from .formatter.exs")
137+
end
138138
end
139-
end
140-
)
139+
"""
141140

142141
initialize(server)
143142
Server.receive_packet(server, did_open(uri, "elixir", 1, code))
144-
Server.receive_packet(server, formatting_req(1, uri, %{}))
143+
Server.receive_packet(server, formatting_req(2, uri, %{}))
145144

146145
resp = assert_receive(%{"id" => 2}, 1000)
147146

148-
assert response(1, [
147+
assert response(2, [
148+
%{
149+
"newText" => "\n ",
150+
"range" => %{
151+
"end" => %{"character" => 84, "line" => 2},
152+
"start" => %{"character" => 84, "line" => 2}
153+
}
154+
},
149155
%{
150-
"newText" =>
151-
"defmodule MyModule do\n def my_fn do\n foo(\n \"This should be split into two lines if reading options from .formatter.exs\"\n )\n end\nend\n",
156+
"newText" => "\n ",
152157
"range" => %{
153-
"end" => %{"character" => 6, "line" => 6},
154-
"start" => %{"character" => 0, "line" => 0}
158+
"end" => %{"character" => 8, "line" => 2},
159+
"start" => %{"character" => 8, "line" => 2}
155160
}
156161
}
157-
]) = resp
162+
]) == resp
158163

159-
# Now try it in a subdirectory with its own .formatter.exs file.
164+
# Now try it in a subdirectory with its own .formatter.exs file that does not define a max line length.
160165
subdir_uri = Path.join([root_uri(), "lib/file.ex"])
161166
Server.receive_packet(server, did_open(subdir_uri, "elixir", 1, code))
162-
Server.receive_packet(server, formatting_req(2, subdir_uri, %{}))
167+
Server.receive_packet(server, formatting_req(3, subdir_uri, %{}))
163168

164-
resp = assert_receive(%{"id" => 2}, 1000)
169+
resp = assert_receive(%{"id" => 3}, 1000)
165170

166-
assert response(2, [
167-
%{
168-
"newText" =>
169-
"defmodule MyModule do\n def my_fn do\n foo \"This should be split into two lines if reading options from .formatter.exs\"\n end\nend\n",
170-
"range" => %{
171-
"end" => %{"character" => 6, "line" => 6},
172-
"start" => %{"character" => 0, "line" => 0}
173-
}
174-
}
175-
]) = resp
171+
# File is already formatted
172+
assert response(3, []) == resp
176173
end)
177174
end
178175

0 commit comments

Comments
 (0)