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