Skip to content

Commit

Permalink
test(dsl): for Trim(Leading, Trailing, Both)Dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
waahhh committed Nov 22, 2023
1 parent ee9e9fc commit 787893b
Show file tree
Hide file tree
Showing 4 changed files with 518 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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 TrimBothDslTest : WithAssertions {
private val char1 = 'c'
private val string1 = "string1"

private val charExpression1 = Expressions.value(char1)
private val stringExpression1 = Expressions.value(string1)

@Test
fun `trimBoth() without a char, from() with a string`() {
// when
val expression = queryPart {
trimBoth().from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimBoth() without a char, from() with a string expression`() {
// when
val expression = queryPart {
trimBoth().from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimBoth() with a char, from() with a string`() {
// when
val expression = queryPart {
trimBoth(char1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimBoth() with a char, from() with a string expression`() {
// when
val expression = queryPart {
trimBoth(char1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimBoth() with a char expression, from() with a string`() {
// when
val expression = queryPart {
trimBoth(charExpression1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimBoth() with a char expression, from() with a string expression`() {
// when
val expression = queryPart {
trimBoth(charExpression1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimBoth(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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 TrimDslTest : WithAssertions {
private val char1 = 'c'
private val string1 = "string1"

private val charExpression1 = Expressions.value(char1)
private val stringExpression1 = Expressions.value(string1)

@Test
fun `trim() with a string`() {
// when
val expression = queryPart {
trim(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() with a string expression`() {
// when
val expression = queryPart {
trim(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() without a char, from() with a string`() {
// when
val expression = queryPart {
trim().from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() without a char, from() with a string expression`() {
// when
val expression = queryPart {
trim().from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() with a char, from() with a string`() {
// when
val expression = queryPart {
trim(char1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() with a char, from() with a string expression`() {
// when
val expression = queryPart {
trim(char1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() with a char expression, from() with a string`() {
// when
val expression = queryPart {
trim(charExpression1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trim() with a char expression, from() with a string expression`() {
// when
val expression = queryPart {
trim(charExpression1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trim(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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 TrimLeadingDslTest : WithAssertions {
private val char1 = 'c'
private val string1 = "string1"

private val charExpression1 = Expressions.value(char1)
private val stringExpression1 = Expressions.value(string1)

@Test
fun `trimLeading() without a char, from() with a string`() {
// when
val expression = queryPart {
trimLeading().from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimLeading() without a char, from() with a string expression`() {
// when
val expression = queryPart {
trimLeading().from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimLeading() with a char, from() with a string`() {
// when
val expression = queryPart {
trimLeading(char1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimLeading() with a char, from() with a string expression`() {
// when
val expression = queryPart {
trimLeading(char1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimLeading() with a char expression, from() with a string`() {
// when
val expression = queryPart {
trimLeading(charExpression1).from(string1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}

@Test
fun `trimLeading() with a char expression, from() with a string expression`() {
// when
val expression = queryPart {
trimLeading(charExpression1).from(stringExpression1)
}.toExpression()

val actual: Expression<String> = expression // for type check

// then
val expected = Expressions.trimLeading(
character = charExpression1,
value = stringExpression1,
)

assertThat(actual.toExpression()).isEqualTo(expected)
}
}
Loading

0 comments on commit 787893b

Please sign in to comment.