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

Improve processing CgNotNullAssertion in deepEquals #582

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1004,18 +1004,17 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
} else {
// array of objects, have to use deep equals

if (expected is CgLiteral) {
// Literal can only be Primitive or String, can use equals here
testFrameworkManager.assertEquals(expected, actual)
return
}

require(resultModel is UtArrayModel) {
"Result model have to be UtArrayModel to generate arrays assertion " +
"but `${resultModel::class}` found"
when (expected) {
is CgLiteral -> testFrameworkManager.assertEquals(expected, actual)
is CgNotNullAssertion -> generateForNotNullAssertion(expected, actual)
else -> {
require(resultModel is UtArrayModel) {
"Result model have to be UtArrayModel to generate arrays assertion " +
"but `${resultModel::class}` found"
}
generateDeepEqualsOrNullAssertion(expected, actual)
}
}

generateDeepEqualsOrNullAssertion(expected, actual)
}
}
}
Expand Down Expand Up @@ -1046,23 +1045,22 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
}
else -> {
when (expected) {
is CgLiteral -> {
// Literal can only be Primitive or String, can use equals here
testFrameworkManager.assertEquals(expected, actual)
}
is CgNotNullAssertion -> {
require(expected.expression is CgVariable) {
"Only Variable wrapped in CgNotNullAssertion is supported in deep equals"
}
currentBlock = currentBlock.addAll(generateDeepEqualsAssertion(expected.expression, actual))
}
is CgLiteral -> testFrameworkManager.assertEquals(expected, actual)
is CgNotNullAssertion -> generateForNotNullAssertion(expected, actual)
else -> generateDeepEqualsOrNullAssertion(expected, actual)
}
}
}
}
}

private fun generateForNotNullAssertion(expected: CgNotNullAssertion, actual: CgVariable) {
require(expected.expression is CgVariable) {
"Only CgVariable wrapped in CgNotNullAssertion is supported in deepEquals"
}
generateDeepEqualsOrNullAssertion(expected.expression, actual)
}

/**
* We can't use standard deepEquals method in parametrized tests
* because nullable objects require different asserts.
Expand Down