From 84b71d2b5029d56191eba7b88c329f80abb255f8 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sat, 6 Mar 2021 02:38:20 +0100 Subject: [PATCH] Fix failing CI on Elixir 1.9 --- lib/rdf/dataset.ex | 10 +++++++--- lib/rdf/description.ex | 10 +++++++--- lib/rdf/graph.ex | 10 +++++++--- test/unit/dataset_test.exs | 5 +++++ test/unit/description_test.exs | 5 +++++ test/unit/graph_test.exs | 5 +++++ test/unit/prefix_map_test.exs | 4 ++++ test/unit/property_map_test.exs | 4 ++++ 8 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/rdf/dataset.ex b/lib/rdf/dataset.ex index bcf086c..9172e2f 100644 --- a/lib/rdf/dataset.ex +++ b/lib/rdf/dataset.ex @@ -880,9 +880,13 @@ defmodule RDF.Dataset do def member?(dataset, statement), do: {:ok, Dataset.include?(dataset, statement)} def count(dataset), do: {:ok, Dataset.statement_count(dataset)} - def slice(dataset) do - size = Dataset.statement_count(dataset) - {:ok, size, &Enumerable.List.slice(Dataset.statements(dataset), &1, &2, size)} + if Version.match?(System.version(), "~> 1.10") do + def slice(dataset) do + size = Dataset.statement_count(dataset) + {:ok, size, &Enumerable.List.slice(Dataset.statements(dataset), &1, &2, size)} + end + else + def slice(_), do: {:error, __MODULE__} end def reduce(dataset, acc, fun) do diff --git a/lib/rdf/description.ex b/lib/rdf/description.ex index d2c2dbc..679d6af 100644 --- a/lib/rdf/description.ex +++ b/lib/rdf/description.ex @@ -828,9 +828,13 @@ defmodule RDF.Description do def count(desc), do: {:ok, Description.statement_count(desc)} - def slice(desc) do - size = Description.statement_count(desc) - {:ok, size, &Enumerable.List.slice(Description.triples(desc), &1, &2, size)} + if Version.match?(System.version(), "~> 1.10") do + def slice(desc) do + size = Description.statement_count(desc) + {:ok, size, &Enumerable.List.slice(Description.triples(desc), &1, &2, size)} + end + else + def slice(_), do: {:error, __MODULE__} end def reduce(desc, acc, fun) do diff --git a/lib/rdf/graph.ex b/lib/rdf/graph.ex index ee66806..d942b9f 100644 --- a/lib/rdf/graph.ex +++ b/lib/rdf/graph.ex @@ -1093,9 +1093,13 @@ defmodule RDF.Graph do def member?(graph, triple), do: {:ok, Graph.include?(graph, triple)} def count(graph), do: {:ok, Graph.statement_count(graph)} - def slice(graph) do - size = Graph.statement_count(graph) - {:ok, size, &Enumerable.List.slice(Graph.triples(graph), &1, &2, size)} + if Version.match?(System.version(), "~> 1.10") do + def slice(graph) do + size = Graph.statement_count(graph) + {:ok, size, &Enumerable.List.slice(Graph.triples(graph), &1, &2, size)} + end + else + def slice(_), do: {:error, __MODULE__} end def reduce(graph, acc, fun) do diff --git a/test/unit/dataset_test.exs b/test/unit/dataset_test.exs index cb41f5a..48bdfe8 100644 --- a/test/unit/dataset_test.exs +++ b/test/unit/dataset_test.exs @@ -1829,6 +1829,11 @@ defmodule RDF.DatasetTest do assert ds == Enum.reduce(ds, dataset(), fn statement, acc -> acc |> Dataset.add(statement) end) end + + test "Enum.at (for Enumerable.slice/1)" do + assert Dataset.new({EX.S, EX.p(), EX.O, EX.Graph}) + |> Enum.at(0) == {RDF.iri(EX.S), EX.p(), RDF.iri(EX.O), RDF.iri(EX.Graph)} + end end describe "Collectable protocol" do diff --git a/test/unit/description_test.exs b/test/unit/description_test.exs index ca49c98..2540cbe 100644 --- a/test/unit/description_test.exs +++ b/test/unit/description_test.exs @@ -953,6 +953,11 @@ defmodule RDF.DescriptionTest do acc |> Description.add(triple) end) end + + test "Enum.at (for Enumerable.slice/1)" do + assert Description.new(EX.S, init: {EX.S, EX.p(), EX.O}) + |> Enum.at(0) == {RDF.iri(EX.S), EX.p(), RDF.iri(EX.O)} + end end describe "Collectable protocol" do diff --git a/test/unit/graph_test.exs b/test/unit/graph_test.exs index 3a8236f..5661a6c 100644 --- a/test/unit/graph_test.exs +++ b/test/unit/graph_test.exs @@ -1504,6 +1504,11 @@ defmodule RDF.GraphTest do assert g == Enum.reduce(g, graph(), fn triple, acc -> acc |> Graph.add(triple) end) end + + test "Enum.at (for Enumerable.slice/1)" do + assert Graph.new({EX.S, EX.p(), EX.O}) + |> Enum.at(0) == {RDF.iri(EX.S), EX.p(), RDF.iri(EX.O)} + end end describe "Collectable protocol" do diff --git a/test/unit/prefix_map_test.exs b/test/unit/prefix_map_test.exs index 70400df..8cf00af 100644 --- a/test/unit/prefix_map_test.exs +++ b/test/unit/prefix_map_test.exs @@ -395,5 +395,9 @@ defmodule RDF.PrefixMapTest do assert Enum.reduce(@example2, [], fn mapping, acc -> [mapping | acc] end) == [{:ex2, @ex_ns2}, {:ex1, @ex_ns1}] end + + test "Enum.at (for Enumerable.slice/1)" do + assert Enum.at(@example2, 0) == {:ex1, @ex_ns1} + end end end diff --git a/test/unit/property_map_test.exs b/test/unit/property_map_test.exs index da273d4..386424b 100644 --- a/test/unit/property_map_test.exs +++ b/test/unit/property_map_test.exs @@ -315,5 +315,9 @@ defmodule RDF.PropertyMapTest do {:Baz, RDF.iri(EX.Baz)} ] end + + test "Enum.at (for Enumerable.slice/1)" do + assert Enum.at(@example_property_map, 0) == {:Baz, RDF.iri(EX.Baz)} + end end end