Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert end source locations #5116

Merged
merged 3 commits into from Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,7 +34,7 @@ class IndentationSpec {
@Test
fun `places finding location to the indentation`() {
subject.lint(code).assert()
.hasSourceLocation(2, 1)
.hasStartSourceLocation(2, 1)
.hasTextLocations(13 to 14)
}
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ class WrappingSpec {

subject.lint(code).assert()
.hasSize(1)
.hasSourceLocation(1, 12)
.hasStartSourceLocation(1, 12)
.hasTextLocations(11 to 12)
}
}
Expand Up @@ -129,15 +129,15 @@ class ComplexMethodSpec {
)
val subject = ComplexMethod(config)

assertThat(subject.lint(path)).hasSourceLocations(SourceLocation(43, 5))
assertThat(subject.lint(path)).hasStartSourceLocations(SourceLocation(43, 5))
}

@Test
fun `reports all complex methods`() {
val config = TestConfig(mapOf("threshold" to "4"))
val subject = ComplexMethod(config)

assertThat(subject.lint(path)).hasSourceLocations(
assertThat(subject.lint(path)).hasStartSourceLocations(
SourceLocation(6, 5),
SourceLocation(15, 5),
SourceLocation(25, 5),
Expand Down Expand Up @@ -235,7 +235,7 @@ class ComplexMethodSpec {
private fun assertExpectedComplexityValue(code: String, config: TestConfig, expectedValue: Int) {
val findings = ComplexMethod(config).lint(code)

assertThat(findings).hasSourceLocations(SourceLocation(1, 5))
assertThat(findings).hasStartSourceLocations(SourceLocation(1, 5))

assertThat(findings.first())
.isThresholded()
Expand Down
Expand Up @@ -16,7 +16,7 @@ class LargeClassSpec {
fun `should detect only the nested large class which exceeds threshold 70`() {
val findings = subject(threshold = 70).lint(resourceAsPath("NestedClasses.kt"))
assertThat(findings).hasSize(1)
assertThat(findings).hasSourceLocations(SourceLocation(12, 15))
assertThat(findings).hasStartSourceLocations(SourceLocation(12, 15))
}

@Test
Expand Down
Expand Up @@ -116,7 +116,7 @@ class NestedScopeFunctionsSpec(private val env: KotlinCoreEnvironment) {
}

private fun expectSourceLocation(location: Pair<Int, Int>) {
assertThat(actual).hasSourceLocation(location.first, location.second)
assertThat(actual).hasStartSourceLocation(location.first, location.second)
}

private fun expectFunctionInMsg(scopeFunction: String) {
Expand Down
Expand Up @@ -21,7 +21,7 @@ class EmptyFunctionBlockSpec {
protected fun stuff() {}
}
"""
assertThat(subject.compileAndLint(code)).hasSourceLocation(2, 27)
assertThat(subject.compileAndLint(code)).hasStartSourceLocation(2, 27)
}

@Test
Expand Down Expand Up @@ -51,7 +51,7 @@ class EmptyFunctionBlockSpec {
fun b() {}
}
"""
assertThat(subject.compileAndLint(code)).hasSourceLocation(2, 13)
assertThat(subject.compileAndLint(code)).hasStartSourceLocation(2, 13)
}

@Nested
Expand Down Expand Up @@ -89,7 +89,7 @@ class EmptyFunctionBlockSpec {
@Test
fun `should not flag overridden functions`() {
val config = TestConfig(mapOf(IGNORE_OVERRIDDEN_FUNCTIONS to "true"))
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).hasSourceLocation(1, 13)
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).hasStartSourceLocation(1, 13)
}
}

Expand All @@ -115,7 +115,7 @@ class EmptyFunctionBlockSpec {

@Test
fun `should not flag overridden functions with commented body`() {
assertThat(subject.compileAndLint(code)).hasSourceLocation(12, 31)
assertThat(subject.compileAndLint(code)).hasStartSourceLocation(12, 31)
}

@Test
Expand Down
Expand Up @@ -16,7 +16,7 @@ class CastToNullableTypeSpec {
"""
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(1)
assertThat(findings).hasSourceLocation(2, 22)
assertThat(findings).hasStartSourceLocation(2, 22)
assertThat(findings[0]).hasMessage("Use the safe cast ('as? String') instead of 'as String?'.")
}

Expand Down