rdf-ex/test/unit/sigils_test.exs

79 lines
2 KiB
Elixir
Raw Normal View History

2017-04-10 00:38:30 +00:00
defmodule RDF.SigilsTest do
use ExUnit.Case, async: true
import RDF.Sigils
doctest RDF.Sigils
2022-04-09 19:15:34 +00:00
describe "~I sigil" do
test "creates an IRI" do
assert ~I<http://example.com> == RDF.iri("http://example.com")
2017-04-10 00:38:30 +00:00
end
2022-04-09 19:15:34 +00:00
test "escaping" do
assert ~I<http://example.com/f\no> == RDF.iri("http://example.com/f\\no")
end
2022-06-06 18:49:21 +00:00
test "in pattern matches" do
assert (case RDF.iri("http://example.com/foo") do
~I<http://example.com/foo> -> "match"
_ -> :mismatch
end) == "match"
end
2022-04-09 19:15:34 +00:00
end
describe "~i sigil" do
test "without interpolation" do
assert ~i<http://example.com> == RDF.iri("http://example.com")
end
test "with interpolation" do
assert ~i<http://example.com/#{1 + 2}> == RDF.iri("http://example.com/3")
assert ~i<http://example.com/#{:foo}> == RDF.iri("http://example.com/foo")
assert ~i<http://example.com/#{"foo"}> == RDF.iri("http://example.com/foo")
end
test "escaping" do
assert ~i<http://example.com/f\no> == RDF.iri("http://example.com/f\\no")
end
2017-04-18 01:27:28 +00:00
end
2017-04-10 00:38:30 +00:00
2022-04-09 19:15:34 +00:00
describe "~B sigil" do
test "creates a blank node" do
2017-05-19 15:19:06 +00:00
assert ~B<foo> == RDF.bnode("foo")
end
end
2022-04-09 19:15:34 +00:00
describe "~b sigil" do
test "without interpolation" do
assert ~b<foo> == RDF.bnode("foo")
end
test "with interpolation" do
assert ~b<foo#{1 + 2}> == RDF.bnode("foo3")
end
end
describe "~L sigil" do
test "creates a plain Literal" do
2017-04-18 01:27:28 +00:00
assert ~L"foo" == RDF.literal("foo")
end
2022-04-09 19:15:34 +00:00
test "creates a language-tagged Literal" do
2017-04-18 01:27:28 +00:00
assert ~L"foo"en == RDF.literal("foo", language: "en")
end
2017-04-10 00:38:30 +00:00
end
2022-04-09 19:15:34 +00:00
describe "~l sigil" do
test "without interpolation" do
assert ~l"foo" == RDF.literal("foo")
assert ~l"foo"en == RDF.literal("foo", language: "en")
end
test "with interpolation" do
assert ~l"foo#{1 + 2}" == RDF.literal("foo3")
assert ~l"foo#{1 + 2}"en == RDF.literal("foo3", language: "en")
end
end
2017-04-10 00:38:30 +00:00
end