-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...-quality/src/test/kotlin/cc/unitmesh/quality/comment/rule/MissingParameterDescRuleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cc.unitmesh.quality.comment.rule; | ||
|
||
import chapi.domain.core.CodeFunction | ||
import chapi.domain.core.CodeProperty | ||
import org.archguard.rule.core.IssueEmit | ||
import org.archguard.rule.core.IssuePosition | ||
import org.archguard.rule.core.Rule | ||
import org.archguard.rule.core.RuleContext | ||
import org.junit.jupiter.api.Test; | ||
|
||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class MissingParameterDescRuleTest { | ||
|
||
@Test | ||
fun shouldNotEmitIssueWhenDocumentationIsComplete() { | ||
// Given | ||
val rule = MissingParameterDescRule() | ||
val function = CodeFunction() | ||
function.Parameters = listOf(CodeProperty(TypeType = "int", TypeValue = "a"), CodeProperty(TypeType = "int", TypeValue = "b")) | ||
val comment = """ | ||
/** | ||
* Sum a and b, and return the result. | ||
* @param a the first number | ||
* @param b the second number | ||
* @return the result of a + b | ||
*/ | ||
""".trimIndent() | ||
val context = RuleContext() | ||
val callback = IssueEmitCallback() | ||
|
||
// When | ||
rule.visitFunction(function, comment, context, callback) | ||
|
||
// Then | ||
assertFalse(callback.hasIssue()) | ||
} | ||
|
||
@Test | ||
fun shouldEmitIssueWhenParameterDescriptionIsMissing() { | ||
// Given | ||
val rule = MissingParameterDescRule() | ||
val function = CodeFunction() | ||
function.Parameters = listOf(CodeProperty(TypeType = "int", TypeValue = "a"), CodeProperty(TypeType = "int", TypeValue = "b")) | ||
val comment = """ | ||
/** | ||
* Sum a and b, and return the result. | ||
* @param a the first number | ||
* @return the result of a + b | ||
*/ | ||
""".trimIndent() | ||
val context = RuleContext() | ||
val callback = IssueEmitCallback() | ||
|
||
// When | ||
rule.visitFunction(function, comment, context, callback) | ||
|
||
// Then | ||
assertTrue(callback.hasIssue()) | ||
} | ||
|
||
@Test | ||
fun shouldEmitIssueWhenParameterNamesDoNotMatch() { | ||
// Given | ||
val rule = MissingParameterDescRule() | ||
val function = CodeFunction() | ||
function.Parameters = listOf(CodeProperty(TypeType = "int", TypeValue = "a"), CodeProperty(TypeType = "int", TypeValue = "b")) | ||
val comment = """ | ||
/** | ||
* Sum a and b, and return the result. | ||
* @param x the first number | ||
* @param y the second number | ||
* @return the result of a + b | ||
*/ | ||
""".trimIndent() | ||
val context = RuleContext() | ||
val callback = IssueEmitCallback() | ||
|
||
// When | ||
rule.visitFunction(function, comment, context, callback) | ||
|
||
// Then | ||
assertTrue(callback.hasIssue()) | ||
} | ||
} | ||
|
||
class IssueEmitCallback : IssueEmit { | ||
private var hasIssue = false | ||
|
||
fun hasIssue(): Boolean { | ||
return hasIssue | ||
} | ||
|
||
override fun invoke(rule: Rule, position: IssuePosition) { | ||
hasIssue = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.