Skip to content

Commit

Permalink
fix: EXPOSED-16 Failed tests in KotlinTimeTests
Browse files Browse the repository at this point in the history
The same tests pass for SQLite in JavaTimeTests because the comparison is done differently for Java. A Temporal comparison function is used for Java, but not for Kotlin. This commit changes the Kotlin tests to match those for Java.
  • Loading branch information
joc-a committed Apr 18, 2023
1 parent c8fa037 commit b4cbe97
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
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)
}
}

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

0 comments on commit b4cbe97

Please sign in to comment.