typeid-elixir/test/spec_test.exs

33 lines
974 B
Elixir
Raw Normal View History

2023-07-02 08:13:02 -04:00
defmodule TypeID.SpecTest do
use ExUnit.Case
2023-07-02 08:19:23 -04:00
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")
2023-07-02 08:13:02 -04:00
|> 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
2023-07-02 08:19:23 -04:00
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
2023-07-02 08:13:02 -04:00
end