mirror of
https://github.com/sloanelybutsurely/typeid-elixir.git
synced 2025-05-21 04:22:54 -04:00
String.Chars
impl
This commit is contained in:
parent
c4c4437508
commit
2c0a468ce2
3 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
13
test/type_id/string_char_test.exs
Normal file
13
test/type_id/string_char_test.exs
Normal 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
|
Loading…
Reference in a new issue