Skip to content

Commit

Permalink
Improve coverage of datetime structs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Oct 2, 2017
1 parent d9c546d commit a334e89
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,15 @@ defmodule QueryTest do
:ok = query(insert, [1, date0])
:ok = query(insert, [2, date1])

# Strings
assert query("SELECT cast(d AS char) FROM #{table} WHERE id = 1", []) == [["2010-10-17"]]
assert query("SELECT cast(d AS char) FROM #{table} WHERE id = 2", []) == [["0000-01-01"]]

# Date
assert query("SELECT d FROM #{table} WHERE id = 1", []) == [[date0]]
assert query("SELECT d FROM #{table} WHERE id = ?", [1]) == [[date0]]
assert query("SELECT d FROM #{table} WHERE id = ?", [2]) == [[date1]]
assert query("SELECT date('0000-01-01')", []) == [[date1]]
end

test "encode and decode time", context do
Expand All @@ -259,6 +265,10 @@ defmodule QueryTest do
insert = ~s{INSERT INTO #{table} (id, t1, t2) VALUES (?, ?, ?)}
:ok = query(insert, [1, time, time_with_msec])

# Strings
assert query("SELECT cast(t1 as char), cast(t2 as char) FROM #{table} WHERE id = 1", []) ==
[["19:27:30", "10:14:16"]]

# Time
# Only MySQL 5.7 supports microseconds storage, so it will return 0 here
assert query("SELECT t1, t2 FROM #{table} WHERE id = 1", []) == [[~T[19:27:30], ~T[10:14:16]]]
Expand All @@ -277,6 +287,10 @@ defmodule QueryTest do
insert = ~s{INSERT INTO #{table} (id, dt1, dt2) VALUES (?, ?, ?)}
:ok = query(insert, [1, datetime, datetime_with_msec])

# Strings
assert query("SELECT cast(dt1 as char), cast(dt2 as char) FROM #{table} WHERE id = 1", []) ==
[["2010-10-17 10:10:30", "2010-10-17 13:32:15"]]

# Datetime
# Only MySQL 5.7 supports microseconds storage, so it will return 0 here
assert query("SELECT dt1, dt2 FROM #{table} WHERE id = 1", []) == [[~N[2010-10-17 10:10:30], ~N[2010-10-17 13:32:15]]]
Expand All @@ -294,6 +308,10 @@ defmodule QueryTest do
insert = ~s{INSERT INTO #{table} (id, ts1, ts2) VALUES (?, ?, ?)}
:ok = query(insert, [1, timestamp, timestamp_with_msec])

# Strings
assert query("SELECT cast(ts1 as char), cast(ts2 as char) FROM #{table} WHERE id = 1", []) ==
[["2010-10-17 10:10:30", "2010-10-17 13:32:15"]]

# Timestamp
# Only MySQL 5.7 supports microseconds storage, so it will return 0 here
assert query("SELECT ts1, ts2 FROM #{table} WHERE id = 1", []) == [[~N[2010-10-17 10:10:30], ~N[2010-10-17 13:32:15]]]
Expand Down

0 comments on commit a334e89

Please sign in to comment.