58 lines
3 KiB
Elixir
58 lines
3 KiB
Elixir
defmodule RDF.DateTimeTest do
|
|
import RDF.Datatype.Test.Case, only: [dt: 1]
|
|
|
|
use RDF.Datatype.Test.Case, datatype: RDF.DateTime, id: RDF.NS.XSD.dateTime,
|
|
valid: %{
|
|
# input => { value , lexical , canonicalized }
|
|
dt( "2010-01-01T00:00:00Z") => { dt( "2010-01-01T00:00:00Z") , nil , "2010-01-01T00:00:00Z" },
|
|
~N[2010-01-01T00:00:00] => { dt( "2010-01-01T00:00:00") , nil , "2010-01-01T00:00:00" },
|
|
~N[2010-01-01T00:00:00.0000] => { dt( "2010-01-01T00:00:00") , nil , "2010-01-01T00:00:00" },
|
|
dt("2010-01-01T00:00:00+00:00") => { dt( "2010-01-01T00:00:00Z") , nil , "2010-01-01T00:00:00Z" },
|
|
dt("2010-01-01T01:00:00+01:00") => { dt( "2010-01-01T00:00:00Z") , nil , "2010-01-01T00:00:00Z" },
|
|
dt("2009-12-31T23:00:00-01:00") => { dt( "2010-01-01T00:00:00Z") , nil , "2010-01-01T00:00:00Z" },
|
|
"2010-01-01T00:00:00Z" => { dt( "2010-01-01T00:00:00Z") , nil , "2010-01-01T00:00:00Z" },
|
|
"2010-01-01T00:00:00.0000Z" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T00:00:00.0000Z", "2010-01-01T00:00:00Z" },
|
|
"2010-01-01T00:00:00" => { dt( "2010-01-01T00:00:00") , nil , "2010-01-01T00:00:00" },
|
|
"2010-01-01T00:00:00+00:00" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T00:00:00+00:00", "2010-01-01T00:00:00Z" },
|
|
"2010-01-01T01:00:00+01:00" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T01:00:00+01:00", "2010-01-01T00:00:00Z" },
|
|
"2009-12-31T23:00:00-01:00" => { dt( "2010-01-01T00:00:00Z") , "2009-12-31T23:00:00-01:00", "2010-01-01T00:00:00Z" },
|
|
# TODO: DateTime doesn't support negative years (at least with the iso8601 conversion functions)
|
|
# "-2010-01-01T00:00:00Z" => { dt("-2010-01-01T00:00:00Z") , nil, "-2010-01-01T00:00:00Z" },
|
|
},
|
|
invalid: ~w(
|
|
foo
|
|
+2010-01-01T00:00:00Z
|
|
2010-01-01T00:00:00FOO
|
|
02010-01-01T00:00:00
|
|
2010-01-01
|
|
2010-1-1T00:00:00
|
|
0000-01-01T00:00:00
|
|
2010-07
|
|
2010_
|
|
) ++ [true, false, 2010, 3.14, "2010-01-01T00:00:00Z foo", "foo 2010-01-01T00:00:00Z"]
|
|
|
|
|
|
describe "equality" do
|
|
test "two literals are equal when they have the same datatype and lexical form" do
|
|
[
|
|
{"2010-01-01T00:00:00Z" , dt("2010-01-01T00:00:00Z")},
|
|
{"2010-01-01T00:00:00" , ~N[2010-01-01T00:00:00]},
|
|
]
|
|
|> Enum.each(fn {l, r} ->
|
|
assert DateTime.new(l) == DateTime.new(r)
|
|
end)
|
|
end
|
|
|
|
test "two literals with same value but different lexical form are not equal" do
|
|
[
|
|
{"2010-01-01T00:00:00Z" , "2010-01-01T00:00:00" },
|
|
{"2010-01-01T00:00:00+00:00", "2010-01-01T00:00:00Z"},
|
|
{"2010-01-01T00:00:00.0000Z", "2010-01-01T00:00:00Z"},
|
|
]
|
|
|> Enum.each(fn {l, r} ->
|
|
assert DateTime.new(l) != DateTime.new(r)
|
|
end)
|
|
end
|
|
end
|
|
|
|
end
|