Created
October 19, 2021 14:57
-
-
Save aglassman/aaf3bb118f3e130a4be17bbeb9355df5 to your computer and use it in GitHub Desktop.
Elvis Test
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
defmodule ElvisTest do | |
use ExUnit.Case | |
def a ~> b, do: elvis(a, b) | |
def elvis(nil, fun), do: nil | |
def elvis({nil, default_val}, fun), do: elvis(default_val, fun) | |
def elvis(val, fun), do: fun.(val) | |
test "example" do | |
tag = fn inner, tag -> "<#{tag}>#{inner}</#{tag}>" end | |
params = %{title: "Movie Title", description: "Great Movie A+"} | |
result_1 = | |
params[:description] | |
~> fn a -> tag.(a, "h1") end | |
~> fn a -> tag.(a, "div") end | |
assert "<div><h1>Great Movie A+</h1></div>" == result_1 | |
result_2 = | |
params[:sub_title] | |
~> fn a -> tag.(a, "h1") end | |
~> fn a -> tag.(a, "div") end | |
refute result_2 | |
result_2 = | |
{params[:sub_title], "No Subtitle"} | |
~> fn a -> tag.(a, "h1") end | |
~> fn a -> tag.(a, "div") end | |
assert "<div><h1>No Subtitle</div>" == result_1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment