Add search terms parser + tests

This commit is contained in:
2020-08-19 18:19:34 +02:00
parent 12619f6550
commit 315a01ea18
7 changed files with 122 additions and 16 deletions
@@ -0,0 +1,39 @@
package be.simplenotes.app.utils
import be.simplenotes.search.SearchTerms
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
internal class SearchTermsParserKtTest {
private fun createResult(
input: String,
title: String? = null,
tag: String? = null,
content: String? = null,
): Pair<String, SearchTerms> = input to SearchTerms(title, tag, content)
@Suppress("Unused")
private fun results() = Stream.of(
createResult("title:'example'", title = "example"),
createResult("title:'example with words'", title = "example with words"),
createResult("title:'example with words'", title = "example with words"),
createResult("""title:"double quotes"""", title = "double quotes"),
createResult("title:'example' something else", title = "example", content = "something else"),
createResult("tag:'example'", tag = "example"),
createResult("tag:'example' title:'other'", title = "other", tag = "example"),
createResult("blah blah tag:'example' title:'other'", title = "other", tag = "example", content = "blah blah"),
createResult("tag:'example' middle title:'other'", title = "other", tag = "example", content = "middle"),
createResult("tag:'example' title:'other' end", title = "other", tag = "example", content = "end"),
createResult("tag:'example abc' title:'other with words' this is the end ", title = "other with words", tag = "example abc", content = "this is the end"),
)
@ParameterizedTest
@MethodSource("results")
fun `valid search parser`(case: Pair<String, SearchTerms>) {
assertThat(parseSearchTerms(case.first)).isEqualTo(case.second)
}
}