core: IRI sigil

This commit is contained in:
Marcel Otto 2017-04-10 02:38:30 +02:00
parent e09714158c
commit b167cd7e8e
2 changed files with 32 additions and 0 deletions

16
lib/rdf/sigils.ex Normal file
View file

@ -0,0 +1,16 @@
defmodule RDF.Sigils do
@doc ~S"""
Handles the sigil `~I` for IRIs.
## Examples
iex> import RDF.Sigils
iex> ~I<http://example.com>
RDF.uri("http://example.com")
"""
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri),
do: Macro.escape(RDF.uri(iri))
end

16
test/unit/sigils_test.exs Normal file
View file

@ -0,0 +1,16 @@
defmodule RDF.SigilsTest do
use ExUnit.Case, async: true
import RDF.Sigils
doctest RDF.Sigils
describe "IRI sigil without interpolation" do
test "it can create a URI struct from a sigil" do
assert ~I<http://example.com> == RDF.uri("http://example.com")
end
end
end