All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonTest.com.bkahlert.kommons.test.MatchesGlobKtTest.kt Maven / Gradle / Ivy

There is a newer version: 2.8.0
Show newest version
@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()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy