Skip to content

Add support for likeIgnoreCase #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ fun <T> KProperty1<T, String?>.like(x: String): Specifications<T> = spec { like(
fun <T> KProperty1<T, String?>.like(x: String, escapeChar: Char): Specifications<T> = spec { like(it, x, escapeChar) }
fun <T> KProperty1<T, String?>.notLike(x: String): Specifications<T> = spec { notLike(it, x) }
fun <T> KProperty1<T, String?>.notLike(x: String, escapeChar: Char): Specifications<T> = spec { notLike(it, x, escapeChar) }
fun <T> KProperty1<T, String?>.likeIgnoreCase(x: String): Specifications<T> = spec { like(lower(it), x.toLowerCase()) }
fun <T> KProperty1<T, String?>.likeIgnoreCase(x: String, escapeChar: Char): Specifications<T> = spec { like(lower(it), x.toLowerCase(), escapeChar) }
fun <T> KProperty1<T, String?>.notLikeIgnoreCase(x: String): Specifications<T> = spec { notLike(lower(it), x.toLowerCase()) }
fun <T> KProperty1<T, String?>.notLikeIgnoreCase(x: String, escapeChar: Char): Specifications<T> = spec { notLike(lower(it), x.toLowerCase(), escapeChar) }

// And
infix fun <T> Specifications<T>.and(other: Specification<T>): Specifications<T> = this.and(other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,48 @@ open class JPASpecificationDSLTest {
assertThat(shows, containsInAnyOrder(theWalkingDead))
}

@Test
fun `Get a tv show by name likeIgnoreCase`() {
val shows = tvShowRepo.findAll(TvShow::name.likeIgnoreCase("THE%"))
assertThat(shows, containsInAnyOrder(theWalkingDead))
}

@Test
fun `Get a tv show by synopsis like with escape char`() {
val shows = tvShowRepo.findAll(TvShow::synopsis.like("%them\\?", escapeChar = '\\'))
assertThat(shows, containsInAnyOrder(hemlockGrove))
}

@Test
fun `Get a tv show by synopsis likeIgnoreCase with escape char`() {
val shows = tvShowRepo.findAll(TvShow::synopsis.likeIgnoreCase("%THEM\\?", escapeChar = '\\'))
assertThat(shows, containsInAnyOrder(hemlockGrove))
}

@Test
fun `Get a tv show by name notLike`() {
val shows = tvShowRepo.findAll(TvShow::name.notLike("The %"))
assertThat(shows, containsInAnyOrder(betterCallSaul, hemlockGrove))
}

@Test
fun `Get a tv show by name notLikeIgnoreCase`() {
val shows = tvShowRepo.findAll(TvShow::name.notLikeIgnoreCase("THE %"))
assertThat(shows, containsInAnyOrder(betterCallSaul, hemlockGrove))
}

@Test
fun `Get a tv show by synopsis notLike with escape char`() {
val shows = tvShowRepo.findAll(TvShow::synopsis.notLike("%\\.", escapeChar = '\\'))
assertThat(shows, containsInAnyOrder(hemlockGrove))
}

@Test
fun `Get a tv show by synopsis notLikeIgnoreCase with escape char`() {
val shows = tvShowRepo.findAll(TvShow::synopsis.notLikeIgnoreCase("%MEXICO\\.", escapeChar = '\\'))
assertThat(shows, containsInAnyOrder(hemlockGrove, theWalkingDead))
}

@Test
fun `Find tv shows with and`() {
val shows = tvShowRepo.findAll(TvShow::availableOnNetflix.isFalse() and TvShow::releaseDate.equal("2010"))
Expand Down