File: inline_ial_test.exs

package info (click to toggle)
elixir-earmark-parser 1.4.44-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: makefile: 9
file content (52 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Test.Acceptance.Ast.InlineIalTest do
  use ExUnit.Case

  describe "inline IAL enabled →" do
    data = [
      {"# A Header{:.classy}", [{"h1", [{"class", "classy"}], ["A Header"], %{}}]},
      {"###### Another Header{:.classy}", [{"h6", [{"class", "classy"}], ["Another Header"], %{}}]},
      {"> # Bq Header{:.classy-again}",
       [{"blockquote", [], [{"h1", [{"class", "classy-again"}], ["Bq Header"], %{}}], %{}}]},
      {"- # Bq in a list{:.class42 title=xxx}",
       [{"ul", [], [{"li", [], [{"h1", [{"class", "class42"}, {"title", "xxx"}], ["Bq in a list"], %{}}], %{}}], %{}}]},
      {"`42|>inspect()`{:.elixir}",
       [{"p", [], [{"code", [{"class", "inline elixir"}], ["42|>inspect()"], %{line: 1}}], %{}}]}
    ]

    data
    |> Enum.with_index()
    |> Enum.each(fn {{markdown, expected}, nb} ->
      tag = "inline_ial_#{nb}" |> String.to_atom()
      name = "for #{inspect(markdown)} (#{nb})"
      {:ok, ast, []} = EarmarkParser.as_ast(markdown)

      @tag tag
      test name do
        assert unquote(Macro.escape(ast)) == unquote(Macro.escape(expected))
      end
    end)
  end

  describe "inline IAL disabled →" do
    data = [
      {"######## Not Yet Another Header{:.classy}", [{"p", [], ["######## Not Yet Another Header{:.classy}"], %{}}]},
      {["> code {:.not-classy}", "> still code"],
       [{"blockquote", [], [{"p", [], ["code {:.not-classy}\nstill code"], %{}}], %{}}]},
      {"-- {:.hello}", [{"p", [], ["-- {:.hello}"], %{}}]},
      {"--- {:.hello}", [{"p", [], ["--- {:.hello}"], %{}}]}
    ]

    data
    |> Enum.with_index()
    |> Enum.each(fn {{markdown, expected}, nb} ->
      tag = "not_inline_ial_#{nb}" |> String.to_atom()
      name = "for #{inspect(markdown)} (#{nb})"
      {:ok, ast, []} = EarmarkParser.as_ast(markdown)

      @tag tag
      test name do
        assert unquote(Macro.escape(ast)) == unquote(Macro.escape(expected))
      end
    end)
  end
end