typeid-elixir/test/spec_test.exs
Sloane Perrault 5bf8b50e2d
0.1.0
2023-07-02 08:23:44 -04:00

33 lines
970 B
Elixir

defmodule TypeID.SpecTest do
use ExUnit.Case
specs_path =
:code.priv_dir(:typeid_elixir)
|> Path.join("/spec")
@valid_specs specs_path
|> Path.join("/valid.yml")
|> YamlElixir.read_from_file!()
@invalid_specs specs_path
|> Path.join("/invalid.yml")
|> YamlElixir.read_from_file!()
describe "valid" do
for %{"name" => name, "typeid" => typeid, "prefix" => prefix, "uuid" => uuid} <- @valid_specs do
test "#{name}" do
assert {:ok, tid} = TypeID.from_uuid(unquote(prefix), unquote(uuid))
assert unquote(typeid) == TypeID.to_string(tid)
assert {:ok, ^tid} = TypeID.from_string(unquote(typeid))
end
end
end
describe "invalid" do
for %{"name" => name, "typeid" => typeid, "description" => desc} <- @invalid_specs do
test "#{name}: #{desc}" do
assert :error = TypeID.from_string(unquote(typeid))
end
end
end
end