diff --git a/lib/isn/base.ex b/lib/isn/base.ex index 3c2222e..6bdb63e 100644 --- a/lib/isn/base.ex +++ b/lib/isn/base.ex @@ -13,8 +13,11 @@ defmodule Isn.Base do defdelegate blank?, to: Ecto.Type + def cast(nil), do: :error def cast(isn), do: {:ok, to_string(isn)} + def load(isn), do: {:ok, to_string(isn)} + def dump(isn), do: {:ok, to_string(isn)} end end diff --git a/test/isn/isbn13_test.exs b/test/isn/isbn13_test.exs index 753965a..8d1daf8 100644 --- a/test/isn/isbn13_test.exs +++ b/test/isn/isbn13_test.exs @@ -1,7 +1,18 @@ defmodule Isn.ISBN13Test do - use ExUnit.Case + use ExUnit.Case, async: true - # dump - # cast - # load + @test_isbn "978-1-937785-58-1" + + test "cast" do + assert Isn.ISBN13.cast(@test_isbn) == {:ok, @test_isbn} + assert Isn.ISBN13.cast(nil) == :error + end + + test "load" do + assert Isn.ISBN13.load(@test_isbn) == {:ok, @test_isbn} + end + + test "dump" do + assert Isn.ISBN13.dump(@test_isbn) == {:ok, @test_isbn} + end end