add empty parentheses to bareword function calls for Elixir 1.4
This commit is contained in:
parent
7c4218176b
commit
7304037d47
5 changed files with 45 additions and 45 deletions
|
@ -83,12 +83,12 @@ defmodule RDF do
|
|||
|
||||
|
||||
@doc """
|
||||
Generator function for `RDF.BlankNodes`.
|
||||
Generator function for `RDF.BlankNode`s.
|
||||
"""
|
||||
def bnode, do: BlankNode.new
|
||||
|
||||
@doc """
|
||||
Generator function for `RDF.BlankNodes` with a user-defined identity.
|
||||
Generator function for `RDF.BlankNode`s with a user-defined identity.
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ defmodule RDF.Vocabulary do # or RDF.URI.Namespace?
|
|||
# TODO: the URI should be built at compile-time
|
||||
# uri = RDF.Vocabulary.term_to_uri(@base_uri, unquote(term))
|
||||
def unquote(term)() do
|
||||
URI.parse(__base_uri__ <> to_string(unquote(term)))
|
||||
URI.parse(__base_uri__() <> to_string(unquote(term)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
4
mix.exs
4
mix.exs
|
@ -15,8 +15,8 @@ defmodule RDF.Core.Mixfile do
|
|||
elixir: "~> 1.3",
|
||||
build_embedded: Mix.env == :prod,
|
||||
start_permanent: Mix.env == :prod,
|
||||
package: package,
|
||||
deps: deps
|
||||
package: package(),
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule RDF.DescriptionTest do
|
|||
|
||||
|
||||
def description, do: Description.new(EX.Subject)
|
||||
def description(content), do: Description.add(description, content)
|
||||
def description(content), do: Description.add(description(), content)
|
||||
def description_of_subject(%Description{subject: subject}, subject), do: true
|
||||
def description_of_subject(_, _), do: false
|
||||
def empty_description(%Description{predications: predications}) do
|
||||
|
@ -83,56 +83,56 @@ defmodule RDF.DescriptionTest do
|
|||
|
||||
describe "add" do
|
||||
test "a predicate-object-pair of proper RDF terms" do
|
||||
assert Description.add(description, EX.predicate, uri(EX.Object))
|
||||
assert Description.add(description(), EX.predicate, uri(EX.Object))
|
||||
|> description_includes_predication({EX.predicate, uri(EX.Object)})
|
||||
assert Description.add(description, {EX.predicate, uri(EX.Object)})
|
||||
assert Description.add(description(), {EX.predicate, uri(EX.Object)})
|
||||
|> description_includes_predication({EX.predicate, uri(EX.Object)})
|
||||
end
|
||||
|
||||
test "a predicate-object-pair of convertible RDF terms" do
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
"http://example.com/description/predicate", uri(EX.Object))
|
||||
|> description_includes_predication({EX.predicate, uri(EX.Object)})
|
||||
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
{"http://example.com/description/predicate", 42})
|
||||
|> description_includes_predication({EX.predicate, literal(42)})
|
||||
|
||||
# TODO: Test a url-string as object ...
|
||||
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
{"http://example.com/description/predicate", bnode(:foo)})
|
||||
|> description_includes_predication({EX.predicate, bnode(:foo)})
|
||||
end
|
||||
|
||||
test "a proper triple" do
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
{uri(EX.Subject), EX.predicate, uri(EX.Object)})
|
||||
|> description_includes_predication({EX.predicate, uri(EX.Object)})
|
||||
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
{uri(EX.Subject), EX.predicate, literal(42)})
|
||||
|> description_includes_predication({EX.predicate, literal(42)})
|
||||
|
||||
assert Description.add(description,
|
||||
assert Description.add(description(),
|
||||
{uri(EX.Subject), EX.predicate, bnode(:foo)})
|
||||
|> description_includes_predication({EX.predicate, bnode(:foo)})
|
||||
end
|
||||
|
||||
test "add ignores triples not about the subject of the Description struct" do
|
||||
assert empty_description(
|
||||
Description.add(description, {EX.Other, EX.predicate, uri(EX.Object)}))
|
||||
Description.add(description(), {EX.Other, EX.predicate, uri(EX.Object)}))
|
||||
end
|
||||
|
||||
test "a list of predicate-object-pairs" do
|
||||
desc = Description.add(description,
|
||||
desc = Description.add(description(),
|
||||
[{EX.predicate, EX.Object1}, {EX.predicate, EX.Object2}])
|
||||
assert description_includes_predication(desc, {EX.predicate, uri(EX.Object1)})
|
||||
assert description_includes_predication(desc, {EX.predicate, uri(EX.Object2)})
|
||||
end
|
||||
|
||||
test "a list of triples" do
|
||||
desc = Description.add(description, [
|
||||
desc = Description.add(description(), [
|
||||
{EX.Subject, EX.predicate1, EX.Object1},
|
||||
{EX.Subject, EX.predicate2, EX.Object2}
|
||||
])
|
||||
|
@ -141,7 +141,7 @@ defmodule RDF.DescriptionTest do
|
|||
end
|
||||
|
||||
test "a list of mixed triples and predicate-object-pairs" do
|
||||
desc = Description.add(description, [
|
||||
desc = Description.add(description(), [
|
||||
{EX.predicate, EX.Object1},
|
||||
{EX.Subject, EX.predicate, EX.Object2},
|
||||
{EX.Other, EX.predicate, EX.Object3}
|
||||
|
@ -191,30 +191,30 @@ defmodule RDF.DescriptionTest do
|
|||
|
||||
test "a map of predications with inconvertible RDF terms" do
|
||||
assert_raise RDF.InvalidURIError, fn ->
|
||||
Description.add(description, %{"not a URI" => uri(EX.Object)})
|
||||
Description.add(description(), %{"not a URI" => uri(EX.Object)})
|
||||
end
|
||||
|
||||
assert_raise RDF.InvalidLiteralError, fn ->
|
||||
Description.add(description, %{EX.prop => self})
|
||||
Description.add(description(), %{EX.prop => self()})
|
||||
end
|
||||
end
|
||||
|
||||
test "duplicates are ignored" do
|
||||
desc = Description.add(description, {EX.predicate, EX.Object})
|
||||
desc = Description.add(description(), {EX.predicate, EX.Object})
|
||||
assert Description.add(desc, {EX.predicate, EX.Object}) == desc
|
||||
assert Description.add(desc, {EX.Subject, EX.predicate, EX.Object}) == desc
|
||||
|
||||
desc = Description.add(description, {EX.predicate, 42})
|
||||
desc = Description.add(description(), {EX.predicate, 42})
|
||||
assert Description.add(desc, {EX.predicate, literal(42)}) == desc
|
||||
end
|
||||
|
||||
test "non-convertible Triple elements are causing an error" do
|
||||
assert_raise RDF.InvalidURIError, fn ->
|
||||
Description.add(description, {"not a URI", uri(EX.Object)})
|
||||
Description.add(description(), {"not a URI", uri(EX.Object)})
|
||||
end
|
||||
|
||||
assert_raise RDF.InvalidLiteralError, fn ->
|
||||
Description.add(description, {EX.prop, self})
|
||||
Description.add(description(), {EX.prop, self()})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -265,7 +265,7 @@ defmodule RDF.DescriptionTest do
|
|||
{EX.Subject, EX.predicate1, EX.Object1},
|
||||
{EX.Subject, EX.predicate2, EX.Object2},
|
||||
{EX.predicate2, EX.Object3}])
|
||||
assert desc == Enum.reduce(desc, description,
|
||||
assert desc == Enum.reduce(desc, description(),
|
||||
fn(triple, acc) -> acc |> Description.add(triple) end)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ defmodule RDF.GraphTest do
|
|||
import RDF, only: [uri: 1, bnode: 1]
|
||||
|
||||
|
||||
def graph, do: unnamed_graph
|
||||
def graph, do: unnamed_graph()
|
||||
def unnamed_graph, do: Graph.new
|
||||
def named_graph(name \\ EX.GraphName), do: Graph.new(name)
|
||||
def unnamed_graph?(%Graph{name: nil}), do: true
|
||||
|
@ -28,12 +28,12 @@ defmodule RDF.GraphTest do
|
|||
|
||||
describe "construction" do
|
||||
test "creating an empty unnamed graph" do
|
||||
assert unnamed_graph?(unnamed_graph)
|
||||
assert unnamed_graph?(unnamed_graph())
|
||||
end
|
||||
|
||||
test "creating an empty graph with a proper graph name" do
|
||||
refute unnamed_graph?(named_graph)
|
||||
assert named_graph?(named_graph)
|
||||
refute unnamed_graph?(named_graph())
|
||||
assert named_graph?(named_graph())
|
||||
end
|
||||
|
||||
test "creating an empty graph with a convertible graph name" do
|
||||
|
@ -103,29 +103,29 @@ defmodule RDF.GraphTest do
|
|||
|
||||
describe "adding triples" do
|
||||
test "a proper triple" do
|
||||
assert Graph.add(graph, uri(EX.Subject), EX.predicate, uri(EX.Object))
|
||||
assert Graph.add(graph(), uri(EX.Subject), EX.predicate, uri(EX.Object))
|
||||
|> graph_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
||||
assert Graph.add(graph, {uri(EX.Subject), EX.predicate, uri(EX.Object)})
|
||||
assert Graph.add(graph(), {uri(EX.Subject), EX.predicate, uri(EX.Object)})
|
||||
|> graph_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
||||
end
|
||||
|
||||
test "a convertible triple" do
|
||||
assert Graph.add(graph,
|
||||
assert Graph.add(graph(),
|
||||
"http://example.com/graph/Subject", EX.predicate, EX.Object)
|
||||
|> graph_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
||||
assert Graph.add(graph,
|
||||
assert Graph.add(graph(),
|
||||
{"http://example.com/graph/Subject", EX.predicate, EX.Object})
|
||||
|> graph_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
||||
end
|
||||
|
||||
test "a triple with multiple objects" do
|
||||
g = Graph.add(graph, EX.Subject1, EX.predicate1, [EX.Object1, EX.Object2])
|
||||
g = Graph.add(graph(), EX.Subject1, EX.predicate1, [EX.Object1, EX.Object2])
|
||||
assert graph_includes_statement?(g, {EX.Subject1, EX.predicate1, EX.Object1})
|
||||
assert graph_includes_statement?(g, {EX.Subject1, EX.predicate1, EX.Object2})
|
||||
end
|
||||
|
||||
test "a list of triples" do
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
{EX.Subject1, EX.predicate1, EX.Object1},
|
||||
{EX.Subject1, EX.predicate2, EX.Object2},
|
||||
{EX.Subject3, EX.predicate3, EX.Object3}
|
||||
|
@ -136,7 +136,7 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "a Description" do
|
||||
g = Graph.add(graph, Description.new(EX.Subject1, [
|
||||
g = Graph.add(graph(), Description.new(EX.Subject1, [
|
||||
{EX.predicate1, EX.Object1},
|
||||
{EX.predicate2, EX.Object2},
|
||||
]))
|
||||
|
@ -150,7 +150,7 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "a list of Descriptions" do
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
Description.new({EX.Subject1, EX.predicate1, EX.Object1}),
|
||||
Description.new({EX.Subject2, EX.predicate2, EX.Object2}),
|
||||
Description.new({EX.Subject1, EX.predicate3, EX.Object3})
|
||||
|
@ -161,16 +161,16 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "duplicates are ignored" do
|
||||
g = Graph.add(graph, {EX.Subject, EX.predicate, EX.Object})
|
||||
g = Graph.add(graph(), {EX.Subject, EX.predicate, EX.Object})
|
||||
assert Graph.add(g, {EX.Subject, EX.predicate, EX.Object}) == g
|
||||
end
|
||||
|
||||
test "non-convertible Triple elements are causing an error" do
|
||||
assert_raise RDF.InvalidURIError, fn ->
|
||||
Graph.add(graph, {"not a URI", EX.predicate, uri(EX.Object)})
|
||||
Graph.add(graph(), {"not a URI", EX.predicate, uri(EX.Object)})
|
||||
end
|
||||
assert_raise RDF.InvalidLiteralError, fn ->
|
||||
Graph.add(graph, {EX.Subject, EX.prop, self})
|
||||
Graph.add(graph(), {EX.Subject, EX.prop, self()})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -218,7 +218,7 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "subject_count" do
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
{EX.Subject1, EX.predicate1, EX.Object1},
|
||||
{EX.Subject1, EX.predicate2, EX.Object2},
|
||||
{EX.Subject3, EX.predicate3, EX.Object3}
|
||||
|
@ -252,7 +252,7 @@ defmodule RDF.GraphTest do
|
|||
assert Enum.count(Graph.new {EX.S, EX.p, EX.O}) == 1
|
||||
assert Enum.count(Graph.new [{EX.S, EX.p, EX.O1}, {EX.S, EX.p, EX.O2}]) == 2
|
||||
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
{EX.Subject1, EX.predicate1, EX.Object1},
|
||||
{EX.Subject1, EX.predicate2, EX.Object2},
|
||||
{EX.Subject3, EX.predicate3, EX.Object3}
|
||||
|
@ -264,7 +264,7 @@ defmodule RDF.GraphTest do
|
|||
refute Enum.member?(Graph.new, {uri(EX.S), EX.p, uri(EX.O)})
|
||||
assert Enum.member?(Graph.new({EX.S, EX.p, EX.O}), {EX.S, EX.p, EX.O})
|
||||
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
{EX.Subject1, EX.predicate1, EX.Object1},
|
||||
{EX.Subject1, EX.predicate2, EX.Object2},
|
||||
{EX.Subject3, EX.predicate3, EX.Object3}
|
||||
|
@ -275,13 +275,13 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "Enum.reduce" do
|
||||
g = Graph.add(graph, [
|
||||
g = Graph.add(graph(), [
|
||||
{EX.Subject1, EX.predicate1, EX.Object1},
|
||||
{EX.Subject1, EX.predicate2, EX.Object2},
|
||||
{EX.Subject3, EX.predicate3, EX.Object3}
|
||||
])
|
||||
|
||||
assert g == Enum.reduce(g, graph,
|
||||
assert g == Enum.reduce(g, graph(),
|
||||
fn(triple, acc) -> acc |> Graph.add(triple) end)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue