From dcf23550374c10ef53467ea5e1795442cfb6ee90 Mon Sep 17 00:00:00 2001 From: ymotchi Date: Tue, 29 Aug 2023 23:44:32 +0900 Subject: [PATCH] fix: EXPOSED-158 insert space before WHEN added the test code and removed unnecessary code for this problem --- .../org/jetbrains/exposed/DefaultsTest.kt | 3 +-- .../sql/tests/shared/dml/ConditionsTests.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt index b4379951b7..0c9f1906d9 100644 --- a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt +++ b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt @@ -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 @@ -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") { diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ConditionsTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ConditionsTests.kt index 5e5e90f815..47e2ed3fb8 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ConditionsTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ConditionsTests.kt @@ -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]) + } + } + } }