Skip to content

Commit

Permalink
fix: EXPOSED-158 insert space before WHEN
Browse files Browse the repository at this point in the history
added the test code
and removed unnecessary code for this problem
  • Loading branch information
ymotchi committed Aug 29, 2023
1 parent ee1e65c commit dcf2355
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.h2Mode
import org.junit.Test
import java.time.*
import java.time.temporal.ChronoUnit
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
Expand Down Expand Up @@ -401,7 +400,7 @@ class DefaultsTest : DatabaseTestsBase() {
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone(ZoneOffset.UTC))
assertEquals("UTC", ZoneId.systemDefault().id)

val nowWithTimeZone = OffsetDateTime.now().truncatedTo(ChronoUnit.MICROS)
val nowWithTimeZone = OffsetDateTime.now()
val timestampWithTimeZoneLiteral = timestampWithTimeZoneLiteral(nowWithTimeZone)

val testTable = object : IntIdTable("t") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,30 @@ class ConditionsTests : DatabaseTestsBase() {
}
}
}

@Test
fun testChainedAndNestedCaseWhenElseSyntax() {
withCitiesAndUsers { cities, _, _ ->
val nestedCondition = Case()
.When(Op.build { cities.id eq 1 }, intLiteral(1))
.Else(intLiteral(-1))
val chainedCondition = Case()
.When(Op.build { cities.name like "M%" }, intLiteral(0))
.When(Op.build { cities.name like "St. %" }, nestedCondition)
.When(Op.build { cities.name like "P%" }, intLiteral(2))
.Else(intLiteral(-1))

val results = cities.slice(cities.name, chainedCondition).selectAll()
results.forEach {
val cityName = it[cities.name]
val expectedNumber = when {
cityName.startsWith("M") -> 0
cityName.startsWith("St. ") -> 1
cityName.startsWith("P") -> 2
else -> -1
}
assertEquals(expectedNumber, it[chainedCondition])
}
}
}
}

0 comments on commit dcf2355

Please sign in to comment.