Skip to content

Commit

Permalink
Add tests for list and binary comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi authored and josevalim committed Jan 28, 2025
1 parent e770cd4 commit 0ac0b7d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/makeup/lexers/erlang_lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ defmodule Makeup.Lexers.ErlangLexer do
tuple = many_surrounded_by(parsec(:root_element), "{", "}")

syntax_operators =
word_from_list(~W[+ - +? ++ = == -- * / < > /= =:= =/= =< >= ==? <- ! ? ?!], :operator)
word_from_list(
~W[+ - +? ++ = == -- * / < > /= =:= =/= =< >= ==? <- <= ! ? ?!],
:operator
)

record =
token(string("#"), :operator)
Expand Down
52 changes: 52 additions & 0 deletions test/makeup/erlang_lexer/erlang_lexer_tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,57 @@ defmodule ErlangLexerTokenizer do
end
end

describe "comprehensions" do
test "list" do
assert lex("[A||A<-B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<-"},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]

assert lex("[A||A<-B,true]") ==
[
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<-"},
{:name, %{}, "B"},
{:punctuation, %{}, ","},
{:string_symbol, %{}, "true"},
{:punctuation, %{group_id: "group-1"}, "]"}
]
end

test "binary" do
assert lex("[A||A<=B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<="},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]

assert lex("<<A||A<=B,true>>") == [
{:punctuation, %{group_id: "group-1"}, "<<"},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<="},
{:name, %{}, "B"},
{:punctuation, %{}, ","},
{:string_symbol, %{}, "true"},
{:punctuation, %{group_id: "group-1"}, ">>"}
]
end
end

describe "atoms" do
test "are tokenized as such" do
assert lex("atom") == [{:string_symbol, %{}, "atom"}]
Expand Down Expand Up @@ -312,6 +363,7 @@ defmodule ErlangLexerTokenizer do
assert lex("=") == [{:operator, %{}, "="}]
assert lex("!") == [{:operator, %{}, "!"}]
assert lex("<-") == [{:operator, %{}, "<-"}]
assert lex("<=") == [{:operator, %{}, "<="}]
end

test "word operators are tokenized as operator" do
Expand Down

0 comments on commit 0ac0b7d

Please sign in to comment.