-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/SubstringDslTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.linecorp.kotlinjdsl.dsl.jpql.expression | ||
|
||
import com.linecorp.kotlinjdsl.dsl.jpql.queryPart | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions | ||
import org.assertj.core.api.WithAssertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class SubstringDslTest : WithAssertions { | ||
private val string1 = "string1" | ||
private val int1 = 1 | ||
private val int2 = 2 | ||
|
||
private val stringExpression1 = Expressions.value("string1") | ||
private val intExpression1 = Expressions.value(1) | ||
private val intExpression2 = Expressions.value(2) | ||
|
||
@Test | ||
fun `substring() with a string and an int`() { | ||
// when | ||
val expression = queryPart { | ||
substring(string1, int1) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = Expressions.value(string1), | ||
start = Expressions.value(int1), | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `substring() with a string and ints`() { | ||
// when | ||
val expression = queryPart { | ||
substring(string1, int1, int2) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = Expressions.value(string1), | ||
start = Expressions.value(int1), | ||
length = Expressions.value(int2), | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `substring() with a string expression and an int`() { | ||
// when | ||
val expression = queryPart { | ||
substring(stringExpression1, int1) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = stringExpression1, | ||
start = Expressions.value(int1), | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `substring() with a string expression and ints`() { | ||
// when | ||
val expression = queryPart { | ||
substring(stringExpression1, int1, int2) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = stringExpression1, | ||
start = Expressions.value(int1), | ||
length = Expressions.value(int2), | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `substring() with a string expression and an int expression`() { | ||
// when | ||
val expression = queryPart { | ||
substring(stringExpression1, intExpression1) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = stringExpression1, | ||
start = intExpression1, | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `substring() with a string expression and int expressions`() { | ||
// when | ||
val expression = queryPart { | ||
substring(stringExpression1, intExpression1, intExpression2) | ||
}.toExpression() | ||
|
||
val actual: Expression<String> = expression // for type check | ||
|
||
// then | ||
val expected = Expressions.substring( | ||
value = stringExpression1, | ||
start = intExpression1, | ||
length = intExpression2, | ||
) | ||
|
||
assertThat(actual).isEqualTo(expected) | ||
} | ||
} |