Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-16 Failed tests in KotlinTimeTests #1724

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ abstract class FunctionProvider {
* SQL function that casts an expression to a specific type.
*
* @param expr Expression to cast.
* @param type Type to cast hte expression to.
* @param type Type to cast the expression to.
* @param builder Query builder to append the SQL function to.
*/
open fun cast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,33 @@ open class KotlinTimeBaseTest : DatabaseTestsBase() {
}
}

fun assertEqualDateTime(d1: LocalDateTime?, d2: LocalDateTime?) {
fun <T> assertEqualDateTime(d1: T?, d2: T?) {
when {
d1 == null && d2 == null -> return
d1 == null -> error("d1 is null while d2 is not on ${currentDialectTest.name}")
d2 == null -> error("d1 is not null while d2 is null on ${currentDialectTest.name}")
else -> {
assertEquals(d1.toJavaLocalDateTime().toEpochSecond(ZoneOffset.UTC), d2.toJavaLocalDateTime().toEpochSecond(ZoneOffset.UTC), "Failed on epoch seconds ${currentDialectTest.name}")
d1 is LocalTime && d2 is LocalTime -> {
assertEquals(d1.toSecondOfDay(), d2.toSecondOfDay(), "Failed on seconds ${currentDialectTest.name}")
if (d2.nanosecond != 0) {
assertEqualFractionalPart(d1.nanosecond, d2.nanosecond)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add a message hrere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@e5l As a parameter to assertEqualFractionalPart function you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@e5l Every case (for every DB dialect) within that function already has its own message. What other message would we add?

}
}

d1 is LocalDateTime && d2 is LocalDateTime -> {
assertEquals(
d1.toJavaLocalDateTime().toEpochSecond(ZoneOffset.UTC),
d2.toJavaLocalDateTime().toEpochSecond(ZoneOffset.UTC),
"Failed on epoch seconds ${currentDialectTest.name}"
)
assertEqualFractionalPart(d1.nanosecond, d2.nanosecond)
}

d1 is Instant && d2 is Instant -> {
assertEquals(d1.epochSeconds, d2.epochSeconds, "Failed on epoch seconds ${currentDialectTest.name}")
assertEqualFractionalPart(d1.nanosecondsOfSecond, d2.nanosecondsOfSecond)
}

else -> assertEquals(d1, d2, "Failed on ${currentDialectTest.name}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,10 @@ fun Misc.checkRowDates(
assertEquals(dn, row[this.dn])
assertLocalTime(t, row[this.t])
assertLocalTime(tn, row[this.tn])
assertEquals(dt, row[this.dt])
assertEquals(dtn, row[this.dtn])
assertEquals(ts, row[this.ts])
assertEquals(tsn, row[this.tsn])
assertEqualDateTime(dt, row[this.dt])
assertEqualDateTime(dtn, row[this.dtn])
assertEqualDateTime(ts, row[this.ts])
assertEqualDateTime(tsn, row[this.tsn])
assertEquals(dr, row[this.dr])
assertEquals(drn, row[this.drn])
}
Expand Down