true and false with capital letters are no longer valid RDF.Booleans
This commit is contained in:
parent
5b10ccd58b
commit
34eaacdf37
5 changed files with 13 additions and 15 deletions
|
@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
- language literals were not properly unescaped during Turtle parsing
|
||||
- `RDF.Literal.new/1` can take decimals and infers the datatype `xsd:decimal`
|
||||
correctly
|
||||
- `true` and `false` with capital letters are no longer valid `RDF.Boolean`s
|
||||
following the XSD specification; the same applies for booleans in Turtle
|
||||
|
||||
|
||||
[Compare v0.6.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.6.0...HEAD)
|
||||
|
|
|
@ -14,10 +14,10 @@ defmodule RDF.Boolean do
|
|||
def convert(value, _) when is_boolean(value), do: value
|
||||
|
||||
def convert(value, opts) when is_binary(value) do
|
||||
with normalized_value = String.downcase(value) do
|
||||
with value do
|
||||
cond do
|
||||
normalized_value in ~W[true 1] -> true
|
||||
normalized_value in ~W[false 0] -> false
|
||||
value in ~W[true 1] -> true
|
||||
value in ~W[false 0] -> false
|
||||
true ->
|
||||
super(value, opts)
|
||||
end
|
||||
|
|
|
@ -8,12 +8,10 @@ defmodule RDF.BooleanTest do
|
|||
1 => { true , nil , "true" },
|
||||
"true" => { true , nil , "true" },
|
||||
"false" => { false , nil , "false" },
|
||||
"tRuE" => { true , "tRuE" , "true" },
|
||||
"FaLsE" => { false , "FaLsE" , "false" },
|
||||
"0" => { false , "0" , "false" },
|
||||
"1" => { true , "1" , "true" },
|
||||
},
|
||||
invalid: ~w(foo 10) ++ [42, 3.14, "true false", "true foo"]
|
||||
invalid: ~w(foo 10) ++ [42, 3.14, "tRuE", "FaLsE", "true false", "true foo"]
|
||||
|
||||
import RDF.Sigils
|
||||
|
||||
|
@ -53,11 +51,9 @@ defmodule RDF.BooleanTest do
|
|||
|
||||
test "casting a string with a value from the lexical value space of xsd:boolean" do
|
||||
assert RDF.string("true") |> RDF.Boolean.cast() == RDF.true
|
||||
assert RDF.string("tRuE") |> RDF.Boolean.cast() == RDF.true
|
||||
assert RDF.string("1") |> RDF.Boolean.cast() == RDF.true
|
||||
|
||||
assert RDF.string("false") |> RDF.Boolean.cast() == RDF.false
|
||||
assert RDF.string("FaLsE") |> RDF.Boolean.cast() == RDF.false
|
||||
assert RDF.string("0") |> RDF.Boolean.cast() == RDF.false
|
||||
end
|
||||
|
||||
|
|
|
@ -109,13 +109,13 @@ defmodule RDF.EqualityTest do
|
|||
{RDF.boolean("foo"), RDF.boolean("bar")},
|
||||
]
|
||||
@value_equal_booleans [
|
||||
{RDF.true, RDF.boolean("TRUE")},
|
||||
{RDF.boolean(1), RDF.true},
|
||||
{RDF.true, RDF.boolean("1")},
|
||||
{RDF.boolean(0), RDF.false},
|
||||
# invalid literals
|
||||
{RDF.boolean("foo"), RDF.boolean("foo")},
|
||||
]
|
||||
@value_unequal_booleans [
|
||||
{RDF.true, RDF.boolean("FALSE")},
|
||||
{RDF.true, RDF.boolean("false")},
|
||||
{RDF.boolean(0), RDF.true},
|
||||
# invalid literals
|
||||
{RDF.boolean("foo"), RDF.boolean("bar")},
|
||||
|
|
|
@ -534,11 +534,9 @@ defmodule RDF.Turtle.EncoderTest do
|
|||
[
|
||||
{true, "true ."},
|
||||
{"true", "true ."},
|
||||
{"TrUe", "true ."},
|
||||
{"1", "true ."},
|
||||
{false, "false ."},
|
||||
{"false", "false ."},
|
||||
{"FaLsE", "false ."},
|
||||
{"0", "false ."},
|
||||
]
|
||||
|> Enum.each(fn {value, output} ->
|
||||
|
@ -550,7 +548,9 @@ defmodule RDF.Turtle.EncoderTest do
|
|||
test "invalid booleans" do
|
||||
[
|
||||
{"string", ~s{"string"^^<http://www.w3.org/2001/XMLSchema#boolean>}},
|
||||
{"42", ~s{"42"^^<http://www.w3.org/2001/XMLSchema#boolean>}}
|
||||
{"42", ~s{"42"^^<http://www.w3.org/2001/XMLSchema#boolean>}},
|
||||
{"TrUe", ~s{"TrUe"^^<http://www.w3.org/2001/XMLSchema#boolean>}},
|
||||
{"FaLsE", ~s{"FaLsE"^^<http://www.w3.org/2001/XMLSchema#boolean>}},
|
||||
]
|
||||
|> Enum.each(fn {value, output} ->
|
||||
Graph.new({EX.S, EX.p, RDF.Boolean.new(value)})
|
||||
|
|
Loading…
Reference in a new issue