-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare Release v1.4.25 need Release NOTES
- Loading branch information
1 parent
484527c
commit 427a55b
Showing
2 changed files
with
60 additions
and
21 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
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,40 @@ | ||
defmodule Test.Acceptance.Transform.MapAstWithFnchangeTest do | ||
use ExUnit.Case | ||
|
||
import Earmark.Transform | ||
import EarmarkAstDsl | ||
|
||
describe "change #elixir" do | ||
@elixir_home {"a", [{"href", "https://elixir-lang.org"}], ["Elixir"], %{}} | ||
@original [ | ||
{"p", [],[ "#elixir"], %{}}, {"bold", [],[ "#elixir"], %{}}, | ||
{"ol", [], [{"li", [],[ "#elixir"], %{}}, {"p", [],[ "elixir"], %{}}, {"p", [], ["#elixir"], %{}}], %{}} | ||
] | ||
@expected [ | ||
{"p", [],[{"a", [{"href", "https://elixir-lang.org"}], ["Elixir"], %{}}], %{}}, {"bold", [],[ "#elixir"], %{}}, | ||
{"ol", [], [{"li", [],[ "#elixir"], %{}}, {"p", [],[ "elixir"], %{}}, {"p", [], [{"a", [{"href", "https://elixir-lang.org"}], ["Elixir"], %{}}], %{}}], %{}} | ||
] | ||
|
||
test "transform with function change" do | ||
result = map_ast(@original, &main_traverser/1) | ||
assert result == @expected | ||
end | ||
|
||
test "small" do | ||
ast = [p("#elixir"), p("hello")] | ||
expected = [p(@elixir_home), p("hello")] | ||
assert map_ast(ast, &main_traverser/1) == expected | ||
end | ||
defp main_traverser(element) | ||
defp main_traverser({"p", _, _, _}=para) do | ||
{&replacer/1, para} | ||
end | ||
defp main_traverser(element), do: element | ||
|
||
defp replacer(element) | ||
defp replacer("#elixir"), do: @elixir_home | ||
defp replacer(element) when is_binary(element), do: element | ||
defp replacer(element), do: {&main_traverser/1, element} | ||
end | ||
end | ||
# SPDX-License-Identifier: Apache-2.0 |