Don't fail when creating a rdf:langString literal without a language tag
This commit is contained in:
parent
2fab865779
commit
e80488d601
5 changed files with 21 additions and 10 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -5,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
[Keep a CHANGELOG](http://keepachangelog.com).
|
||||
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- `Literal.new/2` can create `rdf:langString` literals without failing, they are
|
||||
simply invalid
|
||||
|
||||
|
||||
[Compare v0.4.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.4.0...HEAD)
|
||||
|
||||
|
||||
|
||||
## 0.4.0 - 2018-03-10
|
||||
|
||||
### Changed
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.4.0
|
||||
0.4.1-dev
|
||||
|
|
|
@ -10,8 +10,8 @@ defmodule RDF.LangString do
|
|||
%Literal{super(value, lexical, opts) | language: String.downcase(language)}
|
||||
end
|
||||
|
||||
def build_literal(_, _, _) do
|
||||
raise ArgumentError, "datatype of rdf:langString requires a language"
|
||||
def build_literal(value, lexical, opts) do
|
||||
super(value, lexical, opts)
|
||||
end
|
||||
|
||||
|
||||
|
@ -21,5 +21,4 @@ defmodule RDF.LangString do
|
|||
def valid?(%Literal{language: nil}), do: false
|
||||
def valid?(literal), do: super(literal)
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -42,9 +42,10 @@ defmodule RDF.LangStringTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "without a language it raises an error" do
|
||||
test "without a language it warns and produces an invalid literal" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert_raise ArgumentError, fn -> LangString.new(input) end
|
||||
assert %Literal{} = literal = LangString.new(input)
|
||||
refute Literal.valid?(literal)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,10 +86,9 @@ defmodule RDF.LiteralTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "construction of a rdf:langString typed literal without language fails" do
|
||||
assert_raise ArgumentError, fn ->
|
||||
Literal.new("Eule", datatype: RDF.langString)
|
||||
end
|
||||
test "construction of a rdf:langString works, but results in an invalid literal" do
|
||||
assert %Literal{value: "Eule"} = literal = Literal.new("Eule", datatype: RDF.langString)
|
||||
refute Literal.valid?(literal)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue