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
|
||||
|
||||
- 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
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.4.2-dev
|
||||
0.5.0-dev
|
||||
|
|
|
@ -210,6 +210,8 @@ defmodule RDF.Datatype do
|
|||
convert: 2,
|
||||
valid?: 1,
|
||||
equal_value?: 2,
|
||||
new: 2,
|
||||
new!: 2,
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,14 @@ defmodule RDF.String do
|
|||
|
||||
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
|
||||
build_literal(lexical, nil, opts)
|
||||
|
|
|
@ -20,6 +20,8 @@ defmodule RDF.Datatype.Test.Case do
|
|||
valid = Keyword.get(opts, :valid)
|
||||
invalid = Keyword.get(opts, :invalid)
|
||||
|
||||
allow_language = Keyword.get(opts, :allow_language, false)
|
||||
|
||||
quote do
|
||||
alias RDF.{Literal, Datatype}
|
||||
alias RDF.NS.XSD
|
||||
|
@ -81,9 +83,11 @@ defmodule RDF.Datatype.Test.Case do
|
|||
end
|
||||
end
|
||||
|
||||
test "language option is ignored" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert unquote(datatype).new(input, language: "en") == unquote(datatype).new(input)
|
||||
unless unquote(allow_language) do
|
||||
test "language option is ignored" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert unquote(datatype).new(input, language: "en") == unquote(datatype).new(input)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,21 @@ defmodule RDF.StringTest do
|
|||
true => { "true" , nil , "true" },
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue