Skip to content

Commit dd64436

Browse files
committed
LimeDocRulesValidator: raise error when invalid platform is specified
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
1 parent 72cf8e4 commit dd64436

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

gluecodium/src/main/java/com/here/gluecodium/validator/LimeDocRulesValidator.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ class LimeDocRulesValidator(
4141
private val elementToRules: Map<String, List<LimeDocValidationRule>> = createElementToRulesMapping(docValidationRules)
4242
private val platforms: List<String> = discoverPlatforms(generators)
4343

44+
init {
45+
for (rule in docValidationRules) {
46+
for (platform in rule.platforms) {
47+
if (!ACCEPTED_PLATFORMS.contains(platform)) {
48+
throw OptionReaderException("Unknown platform '$platform' in docs validation rule '${rule.name}'")
49+
}
50+
}
51+
}
52+
}
53+
4454
fun validate(limeModel: LimeModel): Boolean {
4555
val allElements = limeModel.referenceMap.values
4656
val validationResults =
@@ -182,5 +192,7 @@ class LimeDocRulesValidator(
182192
"function",
183193
"property",
184194
)
195+
196+
private val ACCEPTED_PLATFORMS: Set<String> = setOf("Java", "Dart", "Kotlin", "Swift")
185197
}
186198
}

gluecodium/src/test/java/com/here/gluecodium/validator/LimeDocRulesValidatorTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ class LimeDocRulesValidatorTest {
7878
assertTrue(exception.message!!.startsWith("Multiple doc validation rules with the same name = 'SPECIAL_RULE'"))
7979
}
8080

81+
@Test
82+
fun creationFailsForRuleWithUnknownPlatform() {
83+
// Given two a rule with unknown platform.
84+
val docValidationRules: List<LimeDocValidationRule> =
85+
listOf(
86+
LimeDocValidationRule(
87+
name = "SPECIAL_RULE",
88+
limeElements = listOf("class", "struct"),
89+
regex = "It is a special type",
90+
isWarningOnly = false,
91+
platforms = listOf("Python")
92+
)
93+
)
94+
95+
// When constructing validator.
96+
val exception =
97+
assertThrows(OptionReaderException::class.java) {
98+
LimeDocRulesValidator(mockk(relaxed = true), docValidationRules, allGenerators)
99+
}
100+
101+
// Then error is raised.
102+
assertTrue(exception.message!!.startsWith("Unknown platform 'Python' in docs validation rule 'SPECIAL_RULE'"))
103+
}
104+
81105
@Test
82106
fun creationFailsForRuleWithRegexThatDoesNotCompile() {
83107
// Given a validation rule with invalid regex [missing ')']

0 commit comments

Comments
 (0)