Change RDF.String.new/2 to produce language strings when language given
This commit is contained in:
parent
978ed89164
commit
4cea91e52f
6 changed files with 36 additions and 5 deletions
|
@ -24,6 +24,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Elixir 1.4 is no longer supported
|
- Elixir 1.4 is no longer supported
|
||||||
|
- `RDF.String.new/2` and `RDF.String.new!/2` produce a `rdf:langString` when
|
||||||
|
given a language tag
|
||||||
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.4.2-dev
|
0.5.0-dev
|
||||||
|
|
|
@ -210,6 +210,8 @@ defmodule RDF.Datatype do
|
||||||
convert: 2,
|
convert: 2,
|
||||||
valid?: 1,
|
valid?: 1,
|
||||||
equal_value?: 2,
|
equal_value?: 2,
|
||||||
|
new: 2,
|
||||||
|
new!: 2,
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,14 @@ defmodule RDF.String do
|
||||||
|
|
||||||
use RDF.Datatype, id: RDF.Datatype.NS.XSD.string
|
use RDF.Datatype, id: RDF.Datatype.NS.XSD.string
|
||||||
|
|
||||||
|
def new(value, opts) when is_list(opts), do: new(value, Map.new(opts))
|
||||||
|
def new(value, %{language: _} = opts), do: RDF.LangString.new!(value, opts)
|
||||||
|
def new(value, opts), do: super(value, opts)
|
||||||
|
|
||||||
|
def new!(value, opts) when is_list(opts), do: new!(value, Map.new(opts))
|
||||||
|
def new!(value, %{language: _} = opts), do: RDF.LangString.new!(value, opts)
|
||||||
|
def new!(value, opts), do: super(value, opts)
|
||||||
|
|
||||||
|
|
||||||
def build_literal_by_lexical(lexical, opts) do
|
def build_literal_by_lexical(lexical, opts) do
|
||||||
build_literal(lexical, nil, opts)
|
build_literal(lexical, nil, opts)
|
||||||
|
|
|
@ -20,6 +20,8 @@ defmodule RDF.Datatype.Test.Case do
|
||||||
valid = Keyword.get(opts, :valid)
|
valid = Keyword.get(opts, :valid)
|
||||||
invalid = Keyword.get(opts, :invalid)
|
invalid = Keyword.get(opts, :invalid)
|
||||||
|
|
||||||
|
allow_language = Keyword.get(opts, :allow_language, false)
|
||||||
|
|
||||||
quote do
|
quote do
|
||||||
alias RDF.{Literal, Datatype}
|
alias RDF.{Literal, Datatype}
|
||||||
alias RDF.NS.XSD
|
alias RDF.NS.XSD
|
||||||
|
@ -81,9 +83,11 @@ defmodule RDF.Datatype.Test.Case do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "language option is ignored" do
|
unless unquote(allow_language) do
|
||||||
Enum.each @valid, fn {input, _} ->
|
test "language option is ignored" do
|
||||||
assert unquote(datatype).new(input, language: "en") == unquote(datatype).new(input)
|
Enum.each @valid, fn {input, _} ->
|
||||||
|
assert unquote(datatype).new(input, language: "en") == unquote(datatype).new(input)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,21 @@ defmodule RDF.StringTest do
|
||||||
true => { "true" , nil , "true" },
|
true => { "true" , nil , "true" },
|
||||||
false => { "false" , nil , "false" },
|
false => { "false" , nil , "false" },
|
||||||
},
|
},
|
||||||
invalid: []
|
invalid: [],
|
||||||
|
allow_language: true
|
||||||
|
|
||||||
|
describe "new" do
|
||||||
|
test "when given a language tag it produces a rdf:langString" do
|
||||||
|
assert RDF.String.new("foo", language: "en") ==
|
||||||
|
RDF.LangString.new("foo", language: "en")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "new!" do
|
||||||
|
test "when given a language tag it produces a rdf:langString" do
|
||||||
|
assert RDF.String.new!("foo", language: "en") ==
|
||||||
|
RDF.LangString.new!("foo", language: "en")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue