Skip to content

Commit

Permalink
Run all parser tests with new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakoth authored and doomspork committed May 9, 2017
1 parent d9eac96 commit da9dfd1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 2 additions & 4 deletions lib/slime/parser/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Slime.Parser.Transform do
def transform(:tag, {:blank, _}, _index), do: {0, ""}
def transform(:tag, input, _index) do
case input do
[indent, {:eex, content: content, inline: false} = tag] ->
[indent, {:eex, [{:content, content}, {:inline, false} | _]} = tag] ->
indent = indent_size(indent)
# TODO: handle if/unless with else in grammar
if content =~ ~r/^\s*else\s*$/ do
Expand Down Expand Up @@ -175,9 +175,7 @@ defmodule Slime.Parser.Transform do
"-" -> {false, %{}}
[_, _, spaces] -> {true, spaces}
end
opts = [content: code, inline: inline]
opts = if spaces == %{}, do: opts, else: [{:spaces, spaces} | opts]
{:eex, opts}
{:eex, [content: code, inline: inline, spaces: spaces]}
end

def transform(:code_lines, input, _index) do
Expand Down
8 changes: 4 additions & 4 deletions test/parser/multiline_elixir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ParserMultilineElixirTest do
" another_expression \\",
" Final_expression"
]
parsed = Parser.parse_lines(lines)
parsed = Parser.parse(Enum.join(lines, "\n"))
content = lines |> Enum.join("\n") |> String.lstrip(?=) |> String.lstrip

assert parsed == [{0, {:eex, [content: content, inline: true, spaces: %{}]}}]
Expand All @@ -20,7 +20,7 @@ defmodule ParserMultilineElixirTest do
" param2,",
" param3"
]
parsed = Parser.parse_lines(lines)
parsed = Parser.parse(Enum.join(lines, "\n"))
content = lines |> Enum.join("\n") |> String.lstrip(?=) |> String.lstrip

assert parsed == [{0, {:eex, [content: content, inline: true, spaces: %{}]}}]
Expand All @@ -32,7 +32,7 @@ defmodule ParserMultilineElixirTest do
" another_expression \\",
" Final_expression"
]
parsed = Parser.parse_lines(lines)
parsed = Parser.parse(Enum.join(lines, "\n"))
content = lines |> Enum.join("\n") |> String.lstrip(?-) |> String.lstrip

assert parsed == [{0, {:eex, [content: content, inline: false, spaces: %{}]}}]
Expand All @@ -44,7 +44,7 @@ defmodule ParserMultilineElixirTest do
" param2,",
" param3"
]
parsed = Parser.parse_lines(lines)
parsed = Parser.parse(Enum.join(lines, "\n"))
content = lines |> Enum.join("\n") |> String.lstrip(?-) |> String.lstrip

assert parsed == [{0, {:eex, [content: content, inline: false, spaces: %{}]}}]
Expand Down
38 changes: 20 additions & 18 deletions test/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ defmodule ParserTest do
end

test "parses inline nesting" do
parsed = [".row: .col-lg-12: p Hello World"] |> Parser.parse_lines
parsed = Parser.parse(".row: .col-lg-12: p Hello World")
assert parsed == [
{0, {"div",
children: [
{"div",
children: [
{"p",
attributes: [],
children: ["Hello World"],
spaces: %{},
close: false}
],
attributes: [class: "col-lg-12"],
spaces: %{},
close: false}
],
attributes: [class: "row"],
spaces: %{},
close: false}
}
attributes: [{"class", "row"}],
spaces: %{},
children: [
{"div",
attributes: [{"class", "col-lg-12"}],
spaces: %{},
children: [
{"p",
attributes: [],
spaces: %{},
children: ["Hello World"],
close: false
}
],
close: false
}
],
close: false
}}
]
end

Expand Down

0 comments on commit da9dfd1

Please sign in to comment.