-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add :include_comments option to Ast.from/2
Use Sourceror.parse_string/1 when include_comments: true.
- Loading branch information
1 parent
4b120fc
commit 60b5803
Showing
2 changed files
with
97 additions
and
5 deletions.
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
86 changes: 86 additions & 0 deletions
86
apps/language_server/test/experimental/code_mod/ast_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,86 @@ | ||
defmodule ElixirLS.LanguageServer.Experimental.CodeMod.AstTest do | ||
alias ElixirLS.LanguageServer.Experimental.CodeMod.Ast | ||
|
||
use ExUnit.Case | ||
|
||
describe "ast" do | ||
test "from\2 / to_string\1" do | ||
string = """ | ||
defmodule Bar do | ||
def foo(baz) do | ||
# TODO | ||
end | ||
end | ||
""" | ||
|
||
{:ok, ast} = Ast.from(string, include_comments: true) | ||
assert string == Ast.to_string(ast) <> "\n" | ||
|
||
{:ok, ast_missing_comments} = Ast.from(string) | ||
|
||
assert """ | ||
defmodule Bar do | ||
def foo(baz) do | ||
end | ||
end | ||
""" == Ast.to_string(ast_missing_comments) <> "\n" | ||
end | ||
|
||
test "from\1" do | ||
assert {:ok, | ||
{:def, [do: [line: 1, column: 16], end: [line: 3, column: 3], line: 1, column: 3], | ||
[ | ||
{:foo, [closing: [line: 1, column: 14], line: 1, column: 7], | ||
[{:baz, [line: 1, column: 11], nil}]}, | ||
[do: {:__block__, [], []}] | ||
]}} = | ||
Ast.from(""" | ||
def foo(baz) do | ||
# TODO | ||
end | ||
""") | ||
end | ||
|
||
test "from\2" do | ||
assert {:ok, | ||
{:def, | ||
[ | ||
trailing_comments: [ | ||
%{column: 5, line: 2, next_eol_count: 1, previous_eol_count: 1, text: "# TODO"} | ||
], | ||
leading_comments: [], | ||
do: [line: 1, column: 16], | ||
end: [line: 3, column: 3], | ||
line: 1, | ||
column: 3 | ||
], | ||
[ | ||
{:foo, | ||
[ | ||
trailing_comments: [], | ||
leading_comments: [], | ||
closing: [line: 1, column: 14], | ||
line: 1, | ||
column: 7 | ||
], | ||
[ | ||
{:baz, [trailing_comments: [], leading_comments: [], line: 1, column: 11], | ||
nil} | ||
]}, | ||
[ | ||
{{:__block__, | ||
[trailing_comments: [], leading_comments: [], line: 1, column: 16], [:do]}, | ||
{:__block__, [trailing_comments: [], leading_comments: []], []}} | ||
] | ||
]}} = | ||
Ast.from( | ||
""" | ||
def foo(baz) do | ||
# TODO | ||
end | ||
""", | ||
include_comments: true | ||
) | ||
end | ||
end | ||
end |