aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/base-test-utils/src/main/kotlin/utils/assertHtmlEqualsIgnoringWhitespace.kt
blob: 95dcae4ec281933454800b689aac05a713353131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package utils

import junit.framework.Assert.assertEquals
import org.jsoup.Jsoup
import org.jsoup.nodes.Document

/**
 * Parses it using JSOUP, trims whitespace at the end of the line and asserts if they are equal
 * parsing is required to unify the formatting
 */
fun assertHtmlEqualsIgnoringWhitespace(expected: String, actual: String) {
    val ignoreFormattingSettings = Document.OutputSettings().indentAmount(0).outline(true)
    assertEquals(
        Jsoup.parse(expected).outputSettings(ignoreFormattingSettings).outerHtml().trimSpacesAtTheEndOfLine(),
        Jsoup.parse(actual).outputSettings(ignoreFormattingSettings).outerHtml().trimSpacesAtTheEndOfLine()
    )
}

private fun String.trimSpacesAtTheEndOfLine(): String =
    replace(" \n", "\n")