aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/kotestStringMatchers.kt
blob: 58bbe768cf2be9a14a45e6d4909d309a7ac9205b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.jetbrains.dokka.dokkatoo.utils

import io.kotest.assertions.print.print
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.neverNullMatcher
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot


infix fun String?.shouldContainAll(substrings: Iterable<String>): String? {
  this should containAll(substrings)
  return this
}

infix fun String?.shouldNotContainAll(substrings: Iterable<String>): String? {
  this shouldNot containAll(substrings)
  return this
}

fun String?.shouldContainAll(vararg substrings: String): String? {
  this should containAll(substrings.asList())
  return this
}

fun String?.shouldNotContainAll(vararg substrings: String): String? {
  this shouldNot containAll(substrings.asList())
  return this
}

private fun containAll(substrings: Iterable<String>) =
  neverNullMatcher<String> { value ->
    MatcherResult(
      substrings.all { it in value },
      { "${value.print().value} should include substrings ${substrings.print().value}" },
      { "${value.print().value} should not include substrings ${substrings.print().value}" })
  }


infix fun String?.shouldContainAnyOf(substrings: Iterable<String>): String? {
  this should containAnyOf(substrings)
  return this
}

infix fun String?.shouldNotContainAnyOf(substrings: Iterable<String>): String? {
  this shouldNot containAnyOf(substrings)
  return this
}

fun String?.shouldContainAnyOf(vararg substrings: String): String? {
  this should containAnyOf(substrings.asList())
  return this
}

fun String?.shouldNotContainAnyOf(vararg substrings: String): String? {
  this shouldNot containAnyOf(substrings.asList())
  return this
}

private fun containAnyOf(substrings: Iterable<String>) =
  neverNullMatcher<String> { value ->
    MatcherResult(
      substrings.any { it in value },
      { "${value.print().value} should include any of these substrings ${substrings.print().value}" },
      { "${value.print().value} should not include any of these substrings ${substrings.print().value}" })
  }