String.Chars impl

This commit is contained in:
Sloane Perrault 2023-07-07 12:56:25 -04:00
parent c4c4437508
commit 2c0a468ce2
No known key found for this signature in database
3 changed files with 21 additions and 0 deletions

View file

@ -2,6 +2,10 @@
## main
- Implements `String.Chars` protocol
## 0.3.0
- **BREAKING:** `type/1` has been renamed to `prefix/1`
- `Ecto.ParameterizedType` implementation
- `new/2` now accepts an optional keyword list to specify the UUID `time:` in unix milliseconds

View file

@ -336,3 +336,7 @@ defimpl Inspect, for: TypeID do
concat(["#TypeID<\"", TypeID.to_string(tid), "\">"])
end
end
defimpl String.Chars, for: TypeID do
defdelegate to_string(tid), to: TypeID
end

View file

@ -0,0 +1,13 @@
defmodule TypeID.StringCharTest do
use ExUnit.Case
test "implicit cast to string" do
assert {:ok, tid} = TypeID.from_string("test_01h4rm6n03esc96rwqtnq2fr5a")
assert "cast? test_01h4rm6n03esc96rwqtnq2fr5a" == "cast? #{tid}"
end
test "Kernel.to_string/1" do
assert {:ok, tid} = TypeID.from_string("test_01h4rm6n03esc96rwqtnq2fr5a")
assert "test_01h4rm6n03esc96rwqtnq2fr5a" == to_string(tid)
end
end