140faf4741
* Improve RemoteDocTest * Add unit tests for remote context * Add unit tests for default document loader
24 lines
600 B
Elixir
24 lines
600 B
Elixir
defmodule JSON.LD.DocumentLoader.Test do
|
|
@behaviour JSON.LD.DocumentLoader
|
|
|
|
alias JSON.LD.DocumentLoader.RemoteDocument
|
|
|
|
def load(url, _options) do
|
|
with {:ok, data} <- load_context(url) do
|
|
{:ok, %RemoteDocument{document: data, document_url: url}}
|
|
end
|
|
end
|
|
|
|
defp load_context("http://example.com/test-context") do
|
|
{:ok,
|
|
%{
|
|
"@context" => %{
|
|
"homepage" => %{"@id" => "http://xmlns.com/foaf/0.1/homepage", "@type" => "@id"},
|
|
"name" => "http://xmlns.com/foaf/0.1/name"
|
|
}
|
|
}}
|
|
end
|
|
|
|
defp load_context(_), do: {:error, :invalid_url}
|
|
end
|