-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse/1 accepts anything that implements the String.Chars protocol
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Test.Etc.TestNode do | ||
@moduledoc """ | ||
A struct that implements `String.Chars`, for use in `XmlQueryTest`. | ||
This needs to be in its own `.ex` file rather than defined inside a test, | ||
because `defimpl` doesn't work in `.exs` files (see https://hexdocs.pm/elixir/Protocol.html#module-consolidation) | ||
""" | ||
defstruct [:contents] | ||
|
||
defimpl String.Chars do | ||
def to_string(test_node), do: "<test-node>#{test_node.contents}</test-node>" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters