Use getReportLocation in tests
This commit is contained in:
@ -22,7 +22,7 @@ import java.util.*
|
||||
val TextAvailableNode.textStr: String
|
||||
get() = text.toString()
|
||||
|
||||
infix fun TextAvailableNode.textEquals(str:String) {
|
||||
infix fun TextAvailableNode.shouldHaveText(str:String) {
|
||||
this::textStr shouldBe str
|
||||
}
|
||||
|
||||
|
@ -95,8 +95,10 @@ fun assertSuppressed(report: Report, size: Int): List<Report.SuppressedViolation
|
||||
|
||||
/** Checks the coordinates of this node. */
|
||||
fun Node.assertPosition(bline: Int, bcol: Int, eline: Int, ecol: Int) {
|
||||
this::getBeginLine shouldBe bline
|
||||
this::getBeginColumn shouldBe bcol
|
||||
this::getEndLine shouldBe eline
|
||||
this::getEndColumn shouldBe ecol
|
||||
reportLocation.apply {
|
||||
this::getBeginLine shouldBe bline
|
||||
this::getBeginColumn shouldBe bcol
|
||||
this::getEndLine shouldBe eline
|
||||
this::getEndColumn shouldBe ecol
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import io.kotest.matchers.shouldBe
|
||||
import net.sourceforge.pmd.lang.ast.test.matchNode
|
||||
import net.sourceforge.pmd.lang.ast.test.assertPosition
|
||||
import net.sourceforge.pmd.lang.ast.test.shouldBe
|
||||
import net.sourceforge.pmd.lang.ast.test.shouldHaveText
|
||||
import net.sourceforge.pmd.lang.modelica.ModelicaParsingHelper
|
||||
|
||||
class ModelicaCoordsTest : FunSpec({
|
||||
@ -24,7 +25,7 @@ package TestPackage
|
||||
end TestPackage;
|
||||
""".trim().parseModelica() should matchNode<ASTStoredDefinition> {
|
||||
|
||||
it::getText shouldBe """package TestPackage
|
||||
it shouldHaveText """package TestPackage
|
||||
package EmptyPackage
|
||||
end EmptyPackage;
|
||||
end TestPackage;"""
|
||||
@ -32,30 +33,30 @@ end TestPackage;"""
|
||||
it.assertPosition(1, 1, 4, 17)
|
||||
|
||||
child<ASTClassDefinition> {
|
||||
it::getText shouldBe """package TestPackage
|
||||
it shouldHaveText """package TestPackage
|
||||
package EmptyPackage
|
||||
end EmptyPackage;
|
||||
end TestPackage"""
|
||||
it.assertPosition(1, 1, 4, 16)
|
||||
|
||||
child<ASTClassPrefixes> {
|
||||
it::getText shouldBe "package"
|
||||
it shouldHaveText "package"
|
||||
it.assertPosition(1, 1, 1, 8)
|
||||
|
||||
child<ASTPackageClause> {
|
||||
it::getText shouldBe "package"
|
||||
it shouldHaveText "package"
|
||||
it.assertPosition(1, 1, 1, 8)
|
||||
}
|
||||
}
|
||||
child<ASTClassSpecifier> {
|
||||
it::getText shouldBe """TestPackage
|
||||
it shouldHaveText """TestPackage
|
||||
package EmptyPackage
|
||||
end EmptyPackage;
|
||||
end TestPackage"""
|
||||
it.assertPosition(1, 9, 4, 16)
|
||||
|
||||
child<ASTSimpleLongClassSpecifier> {
|
||||
it::getText shouldBe """TestPackage
|
||||
it shouldHaveText """TestPackage
|
||||
package EmptyPackage
|
||||
end EmptyPackage;
|
||||
end TestPackage"""
|
||||
@ -63,64 +64,64 @@ end TestPackage"""
|
||||
it.assertPosition(1, 9, 4, 16)
|
||||
|
||||
child<ASTSimpleName> {
|
||||
it::getText shouldBe "TestPackage"
|
||||
it shouldHaveText "TestPackage"
|
||||
it.assertPosition(1, 9, 1, 20)
|
||||
}
|
||||
child<ASTComposition> {
|
||||
it::getText shouldBe """package EmptyPackage
|
||||
it shouldHaveText """package EmptyPackage
|
||||
end EmptyPackage;"""
|
||||
it.assertPosition(2, 3, 3, 20)
|
||||
|
||||
child<ASTElementList> {
|
||||
it::getText shouldBe """package EmptyPackage
|
||||
it shouldHaveText """package EmptyPackage
|
||||
end EmptyPackage;"""
|
||||
it.assertPosition(2, 3, 3, 20)
|
||||
|
||||
child<ASTRegularElement> {
|
||||
it::getText shouldBe """package EmptyPackage
|
||||
it shouldHaveText """package EmptyPackage
|
||||
end EmptyPackage"""
|
||||
it.assertPosition(2, 3, 3, 19)
|
||||
|
||||
child<ASTClassDefinition> {
|
||||
it::getText shouldBe """package EmptyPackage
|
||||
it shouldHaveText """package EmptyPackage
|
||||
end EmptyPackage"""
|
||||
it.assertPosition(2, 3, 3, 19)
|
||||
it.isPartial shouldBe false
|
||||
|
||||
child<ASTClassPrefixes> {
|
||||
it::getText shouldBe "package"
|
||||
it shouldHaveText "package"
|
||||
it.assertPosition(2, 3, 2, 10)
|
||||
|
||||
child<ASTPackageClause> {
|
||||
it::getText shouldBe "package"
|
||||
it shouldHaveText "package"
|
||||
it.assertPosition(2, 3, 2, 10)
|
||||
}
|
||||
}
|
||||
child<ASTClassSpecifier> {
|
||||
it::getText shouldBe """EmptyPackage
|
||||
it shouldHaveText """EmptyPackage
|
||||
end EmptyPackage"""
|
||||
it.assertPosition(2, 11, 3, 19)
|
||||
|
||||
child<ASTSimpleLongClassSpecifier> {
|
||||
it::getText shouldBe """EmptyPackage
|
||||
it shouldHaveText """EmptyPackage
|
||||
end EmptyPackage"""
|
||||
it.assertPosition(2, 11, 3, 19)
|
||||
it.simpleClassName shouldBe "EmptyPackage"
|
||||
|
||||
child<ASTSimpleName> {
|
||||
it::getText shouldBe "EmptyPackage"
|
||||
it shouldHaveText "EmptyPackage"
|
||||
it.assertPosition(2, 11, 2, 23)
|
||||
|
||||
}
|
||||
child<ASTComposition> {
|
||||
it::getText shouldBe ""
|
||||
it shouldHaveText ""
|
||||
it.firstToken::isImplicit shouldBe true
|
||||
it.lastToken shouldBe it.firstToken
|
||||
|
||||
it.assertPosition(3, 3, 3, 3)
|
||||
|
||||
child<ASTElementList> {
|
||||
it::getText shouldBe ""
|
||||
it shouldHaveText ""
|
||||
it.firstToken::isImplicit shouldBe true
|
||||
it.lastToken shouldBe it.firstToken
|
||||
|
||||
@ -128,7 +129,7 @@ end TestPackage"""
|
||||
}
|
||||
}
|
||||
child<ASTSimpleName> {
|
||||
it::getText shouldBe "EmptyPackage"
|
||||
it shouldHaveText "EmptyPackage"
|
||||
it::getImage shouldBe "EmptyPackage"
|
||||
it.assertPosition(3, 7, 3, 19)
|
||||
}
|
||||
@ -139,7 +140,7 @@ end TestPackage"""
|
||||
}
|
||||
}
|
||||
child<ASTSimpleName> {
|
||||
it::getText shouldBe "TestPackage"
|
||||
it shouldHaveText "TestPackage"
|
||||
it.assertPosition(4, 5, 4, 16)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user