<commit_before>package io.kotlintest.matchers

import org.junit.ComparisonFailure

fun <T> equalityMatcher(expected: T) = object : Matcher<T> {
  override fun test(value: T): Result = Result(expected == value, "$expected should equal $value")
}

fun fail(msg: String): Nothing = throw AssertionError(msg)

infix fun Double.shouldBe(other: Double): Unit = should(ToleranceMatcher(other, 0.0))

infix fun String.shouldBe(other: String) {
  if (this != other) {
    throw ComparisonFailure("", this, other)
  }
}

infix fun BooleanArray.shouldBe(other: BooleanArray): Unit {
  if (this.toList() != other.toList())
    throw AssertionError("Array not equal: $this != $other")
}

infix fun IntArray.shouldBe(other: IntArray): Unit {
  if (this.toList() != other.toList())
    throw AssertionError("Array not equal: $this != $other")
}

infix fun DoubleArray.shouldBe(other: DoubleArray): Unit {
  if (this.toList() != other.toList())
    throw AssertionError("Array not equal: $this != $other")
}

infix fun LongArray.shouldBe(other: LongArray): Unit {
  if (this.toList() != other.toList())
    throw AssertionError("Array not equal: $this != $other")
}

infix fun <T> Array<T>.shouldBe(other: Array<T>): Unit {
  if (this.toList() != other.toList())
    throw AssertionError("Array not equal: $this != $other")
}

infix fun <T> T.shouldHave(matcher: Matcher<T>) = should(matcher)
infix fun <T> T.shouldBe(any: Any?): Unit = shouldEqual(any)
infix fun <T> T.shouldEqual(any: Any?): Unit {
  when (any) {
    is Matcher<*> -> should(any as Matcher<T>)
    else -> {
      if (this == null && any != null)
        throw AssertionError(this.toString() + " did not equal $any")
      if (this != any)
        throw AssertionError(this.toString() + " did not equal $any")
    }
  }
}

infix fun <T> T.should(matcher: (T) -> Unit): Unit = matcher(this)

infix fun <T> T.should(matcher: Matcher<T>): Unit {
  val result = matcher.test(this)
  if (!result.passed)
    throw AssertionError(result.message)
}

infix fun <T> T.shouldNotBe(any: Any?): Unit {
  when (any) {
    is Matcher<*> -> shouldNot(any as Matcher<T>)
    else -> shouldNot(equalityMatcher(any))
  }
}

infix fun <T> T.shouldNot(matcher: Matcher<T>): Unit {
  val result = matcher.test(this)
  if (result.passed)
    throw AssertionError("Test passed which should have failed: " + result.message)
}<commit_msg>Change shouldBe/shouldEqual error text to a format that IntelliJ displays more nicely.<commit_after>package io.kotlintest.matchers

import org.junit.ComparisonFailure

fun <T> equalityMatcher(expected: T) = object : Matcher<T> {
  override fun test(value: T): Result = Result(expected == value, equalsErrorMessage(expected, value))
}

fun fail(msg: String): Nothing = throw AssertionError(msg)

infix fun Double.shouldBe(other: Double): Unit = should(ToleranceMatcher(other, 0.0))

infix fun String.shouldBe(other: String) {
  if (this != other) {
    throw ComparisonFailure("", this, other)
  }
}

infix fun BooleanArray.shouldBe(other: BooleanArray): Unit {
  val expected = other.toList()
  val actual = this.toList()
  if (actual != expected)
    throw equalsError(expected, actual)
}

infix fun IntArray.shouldBe(other: IntArray): Unit {
  val expected = other.toList()
  val actual = this.toList()
  if (actual != expected)
    throw equalsError(expected, actual)
}

infix fun DoubleArray.shouldBe(other: DoubleArray): Unit {
  val expected = other.toList()
  val actual = this.toList()
  if (actual != expected)
    throw equalsError(expected, actual)
}

infix fun LongArray.shouldBe(other: LongArray): Unit {
  val expected = other.toList()
  val actual = this.toList()
  if (actual != expected)
    throw equalsError(expected, actual)
}

infix fun <T> Array<T>.shouldBe(other: Array<T>): Unit {
  val expected = other.toList()
  val actual = this.toList()
  if (actual != expected)
    throw equalsError(expected, actual)
}

infix fun <T> T.shouldHave(matcher: Matcher<T>) = should(matcher)
infix fun <T> T.shouldBe(any: Any?): Unit = shouldEqual(any)
infix fun <T> T.shouldEqual(any: Any?): Unit {
  when (any) {
    is Matcher<*> -> should(any as Matcher<T>)
    else -> {
      if (this == null && any != null)
        throw equalsError(any, this)
      if (this != any)
        throw equalsError(any, this)
    }
  }
}

infix fun <T> T.should(matcher: (T) -> Unit): Unit = matcher(this)

infix fun <T> T.should(matcher: Matcher<T>): Unit {
  val result = matcher.test(this)
  if (!result.passed)
    throw AssertionError(result.message)
}

infix fun <T> T.shouldNotBe(any: Any?): Unit {
  when (any) {
    is Matcher<*> -> shouldNot(any as Matcher<T>)
    else -> shouldNot(equalityMatcher(any))
  }
}

infix fun <T> T.shouldNot(matcher: Matcher<T>): Unit {
  val result = matcher.test(this)
  if (result.passed)
    throw AssertionError("Test passed which should have failed: " + result.message)
}

private fun equalsError(expected: Any?, actual: Any?) = AssertionError(equalsErrorMessage(expected, actual))
private fun equalsErrorMessage(expected: Any?, actual: Any?) = "expected: $expected but was: $actual"
{'fraction_non_alphanumeric': 0.1461689587426326, 'fraction_numerical': 0.0007858546168958742, 'mean_word_length': 4.259297520661157, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6031813', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1696, 'n_words': 473}