mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
chore(tests): finalize and implement missing tests
This commit is contained in:
parent
e4a65e301b
commit
c3e456f0ef
5 changed files with 61 additions and 18 deletions
|
@ -148,7 +148,17 @@ impl<'lua> FromLua<'lua> for DateTime {
|
|||
}
|
||||
}
|
||||
|
||||
impl LuaUserData for DateTimeBuilder {}
|
||||
impl LuaUserData for DateTimeBuilder {
|
||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||
fields.add_field_method_get("year", |_, this| Ok(this.year));
|
||||
fields.add_field_method_get("month", |_, this| Ok(this.month));
|
||||
fields.add_field_method_get("day", |_, this| Ok(this.day));
|
||||
fields.add_field_method_get("hour", |_, this| Ok(this.hour));
|
||||
fields.add_field_method_get("minute", |_, this| Ok(this.minute));
|
||||
fields.add_field_method_get("second", |_, this| Ok(this.second));
|
||||
fields.add_field_method_get("millisecond", |_, this| Ok(this.millisecond));
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua> FromLua<'lua> for DateTimeBuilder {
|
||||
fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<Self> {
|
||||
|
@ -176,6 +186,7 @@ impl<'lua> FromLua<'lua> for DateTimeBuilder {
|
|||
.with_hour(t.get("hour")?)
|
||||
.with_minute(t.get("minute")?)
|
||||
.with_second(t.get("second")?)
|
||||
.with_millisecond(t.get("millisecond")?)
|
||||
// TODO: millisecond support
|
||||
.build()),
|
||||
_ => Err(LuaError::external(
|
||||
|
|
|
@ -15,7 +15,7 @@ assert(
|
|||
["second"] = 28,
|
||||
["millisecond"] = 0,
|
||||
})["unixTimestamp"] == 1693049188,
|
||||
"expected DateTime.fromLocalTime() to return DateTime with timestamp to return 1693049188s"
|
||||
"expected DateTime.fromLocalTime() with DateTimeValues arg to return 1693049188s"
|
||||
)
|
||||
|
||||
assert(
|
||||
|
@ -27,6 +27,6 @@ assert(
|
|||
["minute"] = 56,
|
||||
["second"] = 28,
|
||||
["millisecond"] = 892,
|
||||
})["unixTimestampMillis"] == 1693049188000,
|
||||
"expected DateTime.fromLocalTime() with float millis arg timestamp to return 1693049188000ms"
|
||||
})["unixTimestampMillis"] == 1693049188892,
|
||||
"expected DateTime.fromLocalTime() with DateTimeValues arg with millis to return 1693049188892ms"
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ local DateTime = require("@lune/datetime")
|
|||
|
||||
assert(
|
||||
DateTime.fromUniversalTime()["unixTimestamp"] == os.time(),
|
||||
"expected DateTime.fromLocalTime() with no args to return DateTime at current moment"
|
||||
"expected DateTime.fromLocalTime() with no args to return DateTime at the current moment"
|
||||
)
|
||||
|
||||
assert(
|
||||
|
@ -15,7 +15,7 @@ assert(
|
|||
["second"] = 28,
|
||||
["millisecond"] = 0,
|
||||
})["unixTimestamp"] == 1693068988,
|
||||
"expected DateTime.fromLocalTime() to return DateTime with timestamp to return 1693068988s"
|
||||
"expected DateTime.fromUniversalTime() with DateTimeValues arg to return 1693068988s"
|
||||
)
|
||||
|
||||
assert(
|
||||
|
@ -27,6 +27,6 @@ assert(
|
|||
["minute"] = 56,
|
||||
["second"] = 28,
|
||||
["millisecond"] = 892,
|
||||
})["unixTimestampMillis"] == 1693068988000,
|
||||
"expected DateTime.fromLocalTime() with float millis arg timestamp to return 1693068988000ms"
|
||||
})["unixTimestampMillis"] == 1693068988892,
|
||||
"expected DateTime.fromUniversalTime() with DateTimeValues arg with millis to return 1693068988892ms"
|
||||
)
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
local DateTime = require("@lune/datetime")
|
||||
|
||||
local TIME = "2023-08-27T05:54:19Z"
|
||||
local dateTime = DateTime.fromIsoDate(TIME):toLocalTime()
|
||||
local expectedDateTimeValues =
|
||||
table.pack(string.match(TIME, "(%d%d%d%d)-?(%d?%d?)-?(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)Z$"))
|
||||
local dateTime = (DateTime.fromIsoDate("2023-08-27T05:54:19Z") :: DateTime.DateTime):toLocalTime()
|
||||
|
||||
-- TODO: Implement the test
|
||||
local expectedDateTimeValues = table.pack(
|
||||
string.match(
|
||||
"2023-08-27T11:24:19Z",
|
||||
"(%d%d%d%d)-?(%d?%d?)-?(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)Z$"
|
||||
)
|
||||
)
|
||||
|
||||
local expectedYear = tonumber(expectedDateTimeValues[1])
|
||||
local expectedMonth = tonumber(expectedDateTimeValues[2])
|
||||
local expectedDay = tonumber(expectedDateTimeValues[3])
|
||||
local expectedHour = tonumber(expectedDateTimeValues[4])
|
||||
local expectedMinute = tonumber(expectedDateTimeValues[5])
|
||||
local expectedSecond = tonumber(expectedDateTimeValues[6])
|
||||
|
||||
assert(dateTime.year == expectedYear, `expected {dateTime.year} == {expectedYear}`)
|
||||
assert(dateTime.month == expectedMonth, `expected {dateTime.month} == {expectedMonth}`)
|
||||
assert(dateTime.day == expectedDay, `expected {dateTime.day} == {expectedDay}`)
|
||||
assert(dateTime.hour == expectedHour, `expected {dateTime.hour} == {expectedHour}`)
|
||||
assert(dateTime.minute == expectedMinute, `expected {dateTime.minute} == {expectedMinute}`)
|
||||
assert(dateTime.second == expectedSecond, `expected {dateTime.second} == {expectedSecond}`)
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
local DateTime = require("@lune/datetime")
|
||||
|
||||
local TIME = "2023-08-27T05:54:19Z"
|
||||
local dateTime = DateTime.fromIsoDate(TIME):toLocalTime()
|
||||
local expectedDateTimeValues =
|
||||
table.pack(string.match(TIME, "(%d%d%d%d)-?(%d?%d?)-?(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)Z$"))
|
||||
local dateTime = (DateTime.fromIsoDate("2023-08-27T05:54:19Z") :: DateTime.DateTime):toLocalTime()
|
||||
|
||||
-- TODO: Implement the test
|
||||
local expectedDateTimeValues = table.pack(
|
||||
string.match(
|
||||
"2023-08-27T11:24:19Z",
|
||||
"(%d%d%d%d)-?(%d?%d?)-?(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)Z$"
|
||||
)
|
||||
)
|
||||
|
||||
local expectedYear = tonumber(expectedDateTimeValues[1])
|
||||
local expectedMonth = tonumber(expectedDateTimeValues[2])
|
||||
local expectedDay = tonumber(expectedDateTimeValues[3])
|
||||
local expectedHour = tonumber(expectedDateTimeValues[4])
|
||||
local expectedMinute = tonumber(expectedDateTimeValues[5])
|
||||
local expectedSecond = tonumber(expectedDateTimeValues[6])
|
||||
|
||||
assert(dateTime.year == expectedYear, `expected {dateTime.year} == {expectedYear}`)
|
||||
assert(dateTime.month == expectedMonth, `expected {dateTime.month} == {expectedMonth}`)
|
||||
assert(dateTime.day == expectedDay, `expected {dateTime.day} == {expectedDay}`)
|
||||
assert(dateTime.hour == expectedHour, `expected {dateTime.hour} == {expectedHour}`)
|
||||
assert(dateTime.minute == expectedMinute, `expected {dateTime.minute} == {expectedMinute}`)
|
||||
assert(dateTime.second == expectedSecond, `expected {dateTime.second} == {expectedSecond}`)
|
||||
|
|
Loading…
Add table
Reference in a new issue