commonTest.com.bkahlert.kommons.test.MatchesGlobKtTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommons-test Show documentation
Show all versions of kommons-test Show documentation
Kommons Test is a Kotlin Multiplatform Library to ease testing.
@file:Suppress("SpellCheckingInspection")
package com.bkahlert.kommons.test
import com.bkahlert.kommons.text.LineSeparators
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import kotlin.test.Test
class MatchesGlobKtTest {
@Test fun should_match_glob() {
shouldNotThrowAny {
multilineGlobMatchInput shouldMatchGlob """
foo
.**()
""".trimIndent()
}
}
@Test fun should_match_glob__failure() {
shouldThrow {
multilineGlobMatchInput shouldMatchGlob """
foo
.*()
""".trimIndent()
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should match the following glob pattern (wildcard: *, multiline wildcard: **, line separators: CRLF (\r\n), LF (\n), CR (\r)):
""${'"'}
foo
.*()
""${'"'}
""".trimIndent()
}
@Test fun should_not_match_glob() {
shouldNotThrowAny {
multilineGlobMatchInput shouldNotMatchGlob """
foo
.*()
""".trimIndent()
}
}
@Test fun should_not_match_glob__failure() {
shouldThrow {
multilineGlobMatchInput shouldNotMatchGlob """
foo
.**()
""".trimIndent()
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should not match the following glob pattern (wildcard: *, multiline wildcard: **, line separators: CRLF (\r\n), LF (\n), CR (\r)):
""${'"'}
foo
.**()
""${'"'}
""".trimIndent()
}
@Test fun match_glob() {
shouldNotThrowAny {
multilineGlobMatchInput should matchGlob(
"""
foo
{}.{{}}()
""".trimIndent(),
wildcard = "{}",
multilineWildcard = "{{}}",
*LineSeparators.Unicode, "🫠",
)
}
}
@Test fun match_glob__failure() {
@Suppress("LongLine")
shouldThrow {
multilineGlobMatchInput should matchGlob(
"""
foo
{}.{}()
""".trimIndent(),
wildcard = "{}",
multilineWildcard = "{{}}",
*LineSeparators.Unicode, "🫠",
)
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should match the following glob pattern (wildcard: {}, multiline wildcard: {{}}, line separators: CRLF (\r\n), LF (\n), CR (\r), NEL (\u0085), PS (\u2029), LS (\u2028), Unknown (0xf09faba0)):
""${'"'}
foo
{}.{}()
""${'"'}
""".trimIndent()
}
@Test fun match_glob__singleLine_failure() {
@Suppress("LongLine")
shouldThrow {
"foo.bar()" should matchGlob("bar.{}")
}.message shouldBe """
"foo.bar()"
should match the following glob pattern (wildcard: *, multiline wildcard: **, line separators: CRLF (\r\n), LF (\n), CR (\r)):
"bar.{}"
""".trimIndent()
}
@Test fun should_match_curly() {
shouldNotThrowAny {
multilineGlobMatchInput shouldMatchCurly """
foo
.{{}}()
""".trimIndent()
}
}
@Test fun should_match_curly__failure() {
shouldThrow {
multilineGlobMatchInput shouldMatchCurly """
foo
.{}()
""".trimIndent()
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should match the following curly pattern (line separators: CRLF (\r\n), LF (\n), CR (\r)):
""${'"'}
foo
.{}()
""${'"'}
""".trimIndent()
}
@Test fun should_not_match_curly() {
shouldNotThrowAny {
multilineGlobMatchInput shouldNotMatchCurly """
foo
.{}()
""".trimIndent()
}
}
@Test fun should_not_match_curly__failure() {
shouldThrow {
multilineGlobMatchInput shouldNotMatchCurly """
foo
.{{}}()
""".trimIndent()
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should not match the following curly pattern (line separators: CRLF (\r\n), LF (\n), CR (\r)):
""${'"'}
foo
.{{}}()
""${'"'}
""".trimIndent()
}
@Test fun match_curly() {
shouldNotThrowAny {
multilineGlobMatchInput should matchCurly(
"""
foo
{}.{{}}()
""".trimIndent(),
*LineSeparators.Unicode, "🫠",
)
}
}
@Test fun match_curly__failure() {
@Suppress("LongLine")
shouldThrow {
multilineGlobMatchInput should matchCurly(
"""
foo
{}.{}()
""".trimIndent(),
*LineSeparators.Unicode, "🫠",
)
}.message shouldBe """
""${'"'}
foo
.bar()
.baz()
""${'"'}
should match the following curly pattern (line separators: CRLF (\r\n), LF (\n), CR (\r), NEL (\u0085), PS (\u2029), LS (\u2028), Unknown (0xf09faba0)):
""${'"'}
foo
{}.{}()
""${'"'}
""".trimIndent()
}
@Test fun match_curly__singleLine_failure() {
@Suppress("LongLine")
shouldThrow {
"foo.bar()" should matchCurly("bar.{}")
}.message shouldBe """
"foo.bar()"
should match the following curly pattern (line separators: CRLF (\r\n), LF (\n), CR (\r)):
"bar.{}"
""".trimIndent()
}
}
internal val multilineGlobMatchInput = """
foo
.bar()
.baz()
""".trimIndent()