diff --git a/lib/solid/matcher.ex b/lib/solid/matcher.ex index 844a883..f1d9d96 100644 --- a/lib/solid/matcher.ex +++ b/lib/solid/matcher.ex @@ -7,7 +7,17 @@ end defimpl Solid.Matcher, for: Any do def match(data, []), do: {:ok, data} - def match(_, _), do: {:error, :not_found} + def match(data, _) do + raise Protocol.UndefinedError, + protocol: @protocol, + value: data + end +end + +defimpl Solid.Matcher, for: Integer do + def match(data, []), do: {:ok, data} + + def match(_data, _), do: {:error, :not_found} end defimpl Solid.Matcher, for: List do diff --git a/test/solid_test.exs b/test/solid_test.exs index 90f3d4b..7431417 100644 --- a/test/solid_test.exs +++ b/test/solid_test.exs @@ -197,6 +197,26 @@ defmodule SolidTest do |> Solid.render!(%{}) |> IO.iodata_to_binary() == "yofoo" end + + test "protcol not implemented for structs" do + template = "{{ var1 }}" + + assert_raise(Protocol.UndefinedError, fn -> + template + |> Solid.parse!() + |> Solid.render!(%{__struct__: MyStruct, var1: "yo"}) + end) + end + + test "protcol not implemented for floats" do + template = "{{ var1 }}" + + assert_raise(Protocol.UndefinedError, fn -> + template + |> Solid.parse!() + |> Solid.render!(3.14) + end) + end end describe "strict_variables" do