File: bad_arguments_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 (33 lines) | stat: -rw-r--r-- 1,141 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
defmodule Acceptance.ErrorHandling.BadArgumentsTest do
  use ExUnit.Case, async: true

  import EarmarkParser, only: [as_ast: 1, as_ast: 2]

  describe "monary as_ast" do
    test "raise Argument error for keyword input" do
      assert_raise(ArgumentError, "line number 1 {:hello, \"world\"} is not a binary", fn -> as_ast(hello: "world") end)
    end

    test "raise ArgumentError for a map" do
      assert_raise(ArgumentError, "%{a: 1} not a binary, nor a list of binaries", fn -> as_ast(%{a: 1}) end)
    end
  end

  describe "binary as_ast" do
    test "raise ArgumentError for keyword input" do
      assert_raise(ArgumentError, "line number 1 {:hello, 42} is not a binary", fn -> as_ast([hello: 42], []) end)
    end

    test "raise ArgumentError for numbers" do
      assert_raise(ArgumentError, "42 not a binary, nor a list of binaries", fn -> as_ast(42, %{}) end)
    end
  end

  describe "bad second argument" do
    test "raise ArgumentError for an integer" do
      assert_raise(ArgumentError, "42 not a legal options map or keyword list", fn -> as_ast([], 42) end)
    end
  end
end

# SPDX-License-Identifier: Apache-2.0