diff --git a/test/lexer/combinators_test.exs b/test/lexer/combinators_test.exs index f617cb7..1a03e24 100644 --- a/test/lexer/combinators_test.exs +++ b/test/lexer/combinators_test.exs @@ -6,26 +6,26 @@ defmodule MakeupTest.Lexer.CombinatorsTest do describe "tokens" do test "token with string literal" do assert TokenLexer.lex("chris") == [ - {:phoenix_creator, %{}, "chris"} - ] + {:phoenix_creator, %{}, "chris"} + ] end test "token with string combinator" do assert TokenLexer.lex("grych") == [ - {:drab_creator, %{}, "grych"} - ] + {:drab_creator, %{}, "grych"} + ] end test "token with attrs" do assert TokenLexer.lex("jose") == [ - {:elixir_creator, %{country: "Brazil"}, "jose"} - ] + {:elixir_creator, %{country: "Brazil"}, "jose"} + ] end test "unicode fun" do assert TokenLexer.lex("josé") == [ - {:elixir_creator, %{country: "Poland"}, "josé"} - ] + {:elixir_creator, %{country: "Poland"}, "josé"} + ] end end @@ -62,4 +62,45 @@ defmodule MakeupTest.Lexer.CombinatorsTest do # A previous version had the following wrong output: refute TokenLexer.lex("áò") == [{:character_lexeme, %{}, <<225, 242>>}] end -end \ No newline at end of file + + describe "many_surrounded_by" do + import NimbleParsec + import Makeup.Lexer.Combinators + + defparsecp(:comment_tag, many_surrounded_by(utf8_char([]), "")) + + defparsecp( + :comment_tag_no_eos, + many_surrounded_by(utf8_char([]), "", eos: false, ttype: :custom) + ) + + defparsecp( + :with_combinators, + many_surrounded_by( + utf8_char([]), + choice([string("{"), string("[")]), + choice([string("}"), string("]")]) + ) + ) + + test "includes eos by default" do + assert {:ok, [{:punctuation, %{}, "\"", "", %{}, {1, 0}, 9} = + comment_tag_no_eos(""}], "", + %{}, {1, 0}, + 12} = + comment_tag_no_eos("") + end + + test "left and right can be complex combinators" do + assert {:ok, ["[", 104, 101, 108, 108, 111, "}"], "", %{}, {1, 0}, 7} = + with_combinators("[hello}") + end + end +end