2023-07-02 08:13:02 -04:00
|
|
|
defmodule TypeID.SpecTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
|
2023-07-02 08:20:19 -04:00
|
|
|
specs_path =
|
|
|
|
:code.priv_dir(:typeid_elixir)
|
|
|
|
|> Path.join("/spec")
|
2023-07-02 08:19:23 -04:00
|
|
|
|
|
|
|
@valid_specs specs_path
|
|
|
|
|> Path.join("/valid.yml")
|
|
|
|
|> YamlElixir.read_from_file!()
|
|
|
|
|
|
|
|
@invalid_specs specs_path
|
2023-07-02 08:20:19 -04:00
|
|
|
|> Path.join("/invalid.yml")
|
|
|
|
|> YamlElixir.read_from_file!()
|
2023-07-02 08:13:02 -04:00
|
|
|
|
|
|
|
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
|
2023-07-02 08:20:19 -04:00
|
|
|
for %{"name" => name, "typeid" => typeid, "description" => desc} <- @invalid_specs do
|
2023-07-02 08:19:23 -04:00
|
|
|
test "#{name}: #{desc}" do
|
|
|
|
assert :error = TypeID.from_string(unquote(typeid))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-07-02 08:13:02 -04:00
|
|
|
end
|