From b3b5152fc42190bec8d760732abe07c63c2d23d2 Mon Sep 17 00:00:00 2001 From: waahhh Date: Mon, 20 Nov 2023 22:01:35 +0900 Subject: [PATCH] test(dsl): for TrimDsl --- .../dsl/jpql/expression/TrimDslTest.kt | 362 ++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/TrimDslTest.kt diff --git a/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/TrimDslTest.kt b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/TrimDslTest.kt new file mode 100644 index 000000000..b69c0a860 --- /dev/null +++ b/dsl/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/expression/TrimDslTest.kt @@ -0,0 +1,362 @@ +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 com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl.JpqlTrim +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) + + private val leadingSpecification = JpqlTrim.Specification.LEADING + private val trailingSpecification = JpqlTrim.Specification.TRAILING + private val bothSpecification = JpqlTrim.Specification.BOTH + + @Test + fun `trim() with a string, without a specification and a character`() { + // when + val expression = queryPart { + trim(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trim() with a string expression, without a specification and a character`() { + // when + val expression = queryPart { + trim(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = null, + stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trim(), from() with a string, without a specification and a character`() { + // when + val expression = queryPart { + trim().from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trim(), from() with a string expression, without a specification and a character`() { + // when + val expression = queryPart { + trim().from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimLeading(), from() with a string, without a character`() { + // when + val expression = queryPart { + trimLeading().from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = leadingSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimLeading(), from() with a string expression, without a character`() { + // when + val expression = queryPart { + trimLeading().from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = leadingSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimTrailing(), from() with a string, without a character`() { + // when + val expression = queryPart { + trimTrailing().from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = trailingSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimTrailing(), from() with a string expression, without a character`() { + // when + val expression = queryPart { + trimTrailing().from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = trailingSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimBoth(), from() with a string, without a character`() { + // when + val expression = queryPart { + trimBoth().from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = bothSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimBoth(), from() with a string expression, without a character`() { + // when + val expression = queryPart { + trimBoth().from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = bothSpecification, + character = null, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trim() with a character, from() with a string, without a specification`() { + // when + val expression = queryPart { + trim(char1).from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trim() with a character, from() with a string expression, without a specification`() { + // when + val expression = queryPart { + trim(char1).from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = null, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimLeading() with a character, from() with a string`() { + // when + val expression = queryPart { + trimLeading(char1).from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = leadingSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimLeading() with a character, from() with a string expression`() { + // when + val expression = queryPart { + trimLeading(char1).from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = leadingSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimTrailing() with a character, from() with a string`() { + // when + val expression = queryPart { + trimTrailing(char1).from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = trailingSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimTrailing() with a character, from() with a string expression`() { + // when + val expression = queryPart { + trimTrailing(char1).from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = trailingSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimBoth() with a character, from() with a string`() { + // when + val expression = queryPart { + trimBoth(char1).from(string1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = bothSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } + + @Test + fun `trimBoth() with a character, from() with a string expression`() { + // when + val expression = queryPart { + trimBoth(char1).from(stringExpression1) + }.toExpression() + + val actual: Expression = expression // for type check + + // then + val expected = Expressions.trim( + specification = bothSpecification, + character = charExpression1, + value = stringExpression1, + ) + + assertThat(actual.toExpression()).isEqualTo(expected) + } +}