forked from elixir-editors/emacs-elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* do not insert end after do: Fixes elixir-editors#424 * Add a couple more tests Co-authored-by: Jason Axelson <[email protected]>
- Loading branch information
1 parent
f08f5ab
commit 63d10b3
Showing
2 changed files
with
61 additions
and
1 deletion.
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
60 changes: 60 additions & 0 deletions
60
apps/language_server/test/providers/on_type_formatting_test.exs
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
defmodule ElixirLS.LanguageServer.Providers.OnTypeFormattingTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ElixirLS.LanguageServer.Providers.OnTypeFormatting | ||
alias ElixirLS.LanguageServer.SourceFile | ||
|
||
test "insert `end` after `do`" do | ||
text = """ | ||
for a <- b do | ||
""" | ||
|
||
assert {:ok, | ||
[ | ||
%{ | ||
"newText" => "\nend", | ||
"range" => %{ | ||
"start" => %{"character" => 0, "line" => 1}, | ||
"end" => %{"character" => 0, "line" => 1} | ||
} | ||
} | ||
]} = OnTypeFormatting.format(%SourceFile{text: text}, 1, 0, "\n", []) | ||
end | ||
|
||
test "insert `end` after def `do`" do | ||
text = """ | ||
defmodule TestA do | ||
def myfun(a) do | ||
end | ||
""" | ||
|
||
assert {:ok, | ||
[ | ||
%{ | ||
"newText" => "\n end", | ||
"range" => %{ | ||
"start" => %{"character" => 0, "line" => 2}, | ||
"end" => %{"character" => 0, "line" => 2} | ||
} | ||
} | ||
]} = OnTypeFormatting.format(%SourceFile{text: text}, 2, 0, "\n", []) | ||
end | ||
|
||
test "don't insert `end` after `do:`" do | ||
text = """ | ||
for a <- b, do: | ||
""" | ||
|
||
assert {:ok, nil} = OnTypeFormatting.format(%SourceFile{text: text}, 1, 0, "\n", []) | ||
end | ||
|
||
test "don't insert `end` after def `do: a`" do | ||
text = """ | ||
defmodule TestA do | ||
def myfun(a), do: a | ||
end | ||
""" | ||
|
||
assert {:ok, nil} = OnTypeFormatting.format(%SourceFile{text: text}, 2, 0, "\n", []) | ||
end | ||
end |