From 34f6a0e28b599cd5f8955203d0773c0110c1e51c Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Fri, 19 May 2017 17:19:06 +0200 Subject: [PATCH] core: blank node sigil --- lib/rdf/sigils.ex | 15 +++++++++++++++ test/unit/sigils_test.exs | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/lib/rdf/sigils.ex b/lib/rdf/sigils.ex index 05f5457..27f9296 100644 --- a/lib/rdf/sigils.ex +++ b/lib/rdf/sigils.ex @@ -16,6 +16,21 @@ defmodule RDF.Sigils do Macro.escape(RDF.uri(iri)) end + @doc ~S""" + Handles the sigil `~B` for blank nodes. + + ## Examples + + iex> import RDF.Sigils + iex> ~B + RDF.bnode("foo") + + """ + defmacro sigil_B({:<<>>, _, [bnode]}, []) when is_binary(bnode) do + Macro.escape(RDF.BlankNode.new(bnode)) + end + + @doc ~S""" Handles the sigil `~L` for plain Literals. diff --git a/test/unit/sigils_test.exs b/test/unit/sigils_test.exs index fedc567..75e6820 100644 --- a/test/unit/sigils_test.exs +++ b/test/unit/sigils_test.exs @@ -11,6 +11,12 @@ defmodule RDF.SigilsTest do end end + describe "Blank node sigil without interpolation" do + test "creating a blank node" do + assert ~B == RDF.bnode("foo") + end + end + describe "Literal sigil without interpolation" do test "creating a plain Literal" do assert ~L"foo" == RDF.literal("foo")