1 package net.pterodactylus.sone.template
3 import org.hamcrest.MatcherAssert.assertThat
4 import org.hamcrest.Matchers.equalTo
8 * Unit test for [SubstringFilter].
10 class SubstringFilterTest {
12 private val filter = SubstringFilter()
13 private val string = "abcdefghijklmnopqrstuvwxyz"
15 private fun filterText(vararg parameters: Pair<String, Int>) = filter.format(null, string, mapOf(*parameters))
18 fun `filter returns the input string when no parameters are given`() {
19 assertThat(filterText(), equalTo<Any>(string))
23 fun `filter returns "abc" if start is omitted and length is three`() {
24 assertThat(filterText("length" to 3), equalTo<Any>("abc"))
28 fun `filter returns complete string if length is larger than length of string`() {
29 assertThat(filterText("length" to 3000), equalTo<Any>(string))
33 fun `filter returns part of the string if start is set to index within string`() {
34 assertThat(filterText("start" to 13), equalTo<Any>("nopqrstuvwxyz"))
38 fun `filter returns last three characters if start is set to minus three`() {
39 assertThat(filterText("start" to -3), equalTo<Any>("xyz"))
43 fun `filter returns center part of string with start and length set`() {
44 assertThat(filterText("start" to 13, "length" to 3), equalTo<Any>("nop"))
48 fun `filter returns end part of string with start and too-large length set`() {
49 assertThat(filterText("start" to 23, "length" to 30), equalTo<Any>("xyz"))
53 fun `filter returns end part of string with negative start and too-large length set`() {
54 assertThat(filterText("start" to -3, "length" to 30), equalTo<Any>("xyz"))
58 fun `filter returns part of end of string with negative start and small length set`() {
59 assertThat(filterText("start" to -6, "length" to 3), equalTo<Any>("uvw"))