Fix RDF.LangString to produce invalid literals when invalid languages given
This commit is contained in:
parent
d29f729563
commit
978ed89164
3 changed files with 31 additions and 2 deletions
|
@ -30,6 +30,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
|
||||
- `RDF.DateTime`: '24:00:00' is a valid time in a xsd:dateTime; the dateTime
|
||||
value so represented is the first instant of the following day
|
||||
- `RDF.LangString`: non-strings or the empty string as language produce invalid
|
||||
literals
|
||||
|
||||
|
||||
[Compare v0.4.1...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.4.1...HEAD)
|
||||
|
|
|
@ -6,7 +6,8 @@ defmodule RDF.LangString do
|
|||
use RDF.Datatype, id: RDF.uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")
|
||||
|
||||
|
||||
def build_literal(value, lexical, %{language: language} = opts) do
|
||||
def build_literal(value, lexical, %{language: language} = opts)
|
||||
when is_binary(language) and language != "" do
|
||||
%Literal{super(value, lexical, opts) | language: String.downcase(language)}
|
||||
end
|
||||
|
||||
|
|
|
@ -42,12 +42,26 @@ defmodule RDF.LangStringTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "without a language it warns and produces an invalid literal" do
|
||||
test "without a language it produces an invalid literal" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert %Literal{} = literal = LangString.new(input)
|
||||
refute Literal.valid?(literal)
|
||||
end
|
||||
end
|
||||
|
||||
test "with nil as a language it produces an invalid literal" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert %Literal{} = literal = LangString.new(input, language: nil)
|
||||
refute Literal.valid?(literal)
|
||||
end
|
||||
end
|
||||
|
||||
test "with the empty string as a language it produces an invalid literal" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert %Literal{} = literal = LangString.new(input, language: "")
|
||||
refute Literal.valid?(literal)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -68,6 +82,18 @@ defmodule RDF.LangStringTest do
|
|||
assert_raise ArgumentError, fn -> LangString.new!(input) end
|
||||
end
|
||||
end
|
||||
|
||||
test "with nil as a language it raises an error" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert_raise ArgumentError, fn -> LangString.new!(input, language: nil) end
|
||||
end
|
||||
end
|
||||
|
||||
test "with the empty string as a language it raises an error" do
|
||||
Enum.each @valid, fn {input, _} ->
|
||||
assert_raise ArgumentError, fn -> LangString.new!(input, language: "") end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue