-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENUM_VALUE styles support: snakeCase/pascalCase (#408)
### What's done: * added config parameter for ENUM_VALUE: enumStyle: snakeCase/pascalCase * rule documentation updated with more info * warnings&analysis updated * warning test added
- Loading branch information
1 parent
906fe1c
commit f57a88b
Showing
12 changed files
with
126 additions
and
12 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
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
39 changes: 37 additions & 2 deletions
39
diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/EnumValueCaseTest.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 |
---|---|---|
@@ -1,16 +1,51 @@ | ||
package org.cqfn.diktat.ruleset.chapter1 | ||
|
||
import generated.WarningNames | ||
import org.cqfn.diktat.common.config.rules.RulesConfig | ||
import org.cqfn.diktat.common.config.rules.getRuleConfig | ||
import org.cqfn.diktat.ruleset.constants.Warnings | ||
import org.cqfn.diktat.ruleset.rules.IdentifierNaming | ||
import org.cqfn.diktat.util.FixTestBase | ||
import org.junit.jupiter.api.Tag | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class EnumValueCaseTest : FixTestBase("test/paragraph1/naming", ::IdentifierNaming) { | ||
private val rulesConfigSnakeCaseEnum: List<RulesConfig> = listOf( | ||
RulesConfig(Warnings.ENUM_VALUE.name, true, | ||
mapOf("enumStyle" to "snakeCase")) | ||
) | ||
|
||
private val rulesConfigPascalCaseEnum: List<RulesConfig> = listOf( | ||
RulesConfig(Warnings.ENUM_VALUE.name, true, | ||
mapOf("enumStyle" to "pascalCase")) | ||
) | ||
|
||
private val rulesConfigEnumUnknownStyle: List<RulesConfig> = listOf( | ||
RulesConfig(Warnings.ENUM_VALUE.name, true, | ||
mapOf("enumStyle" to "otherCase")) | ||
) | ||
|
||
@Test | ||
@Tag(WarningNames.ENUM_VALUE) | ||
fun `incorrect enum snake case value fix`() { | ||
fixAndCompare("enum_/EnumValueSnakeCaseExpected.kt", "enum_/EnumValueSnakeCaseTest.kt", rulesConfigSnakeCaseEnum) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.ENUM_VALUE) | ||
fun `incorrect enum pascal case value fix`() { | ||
fixAndCompare("enum_/EnumValuePascalCaseExpected.kt", "enum_/EnumValuePascalCaseTest.kt", rulesConfigPascalCaseEnum) | ||
} | ||
|
||
@Test | ||
@Tag(WarningNames.ENUM_VALUE) | ||
fun `incorrect enum value fix`() { | ||
fixAndCompare("enum_/EnumValueCaseExpected.kt", "enum_/EnumValueCaseTest.kt") | ||
fun `incorrect enum unknown style`() { | ||
assertThrows<IllegalStateException> { | ||
IdentifierNaming.IdentifierNamingConfiguration( | ||
rulesConfigEnumUnknownStyle.getRuleConfig(Warnings.ENUM_VALUE) | ||
?.configuration ?: mapOf() | ||
) | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
diktat-rules/src/test/resources/test/paragraph1/naming/enum_/EnumValuePascalCaseExpected.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,10 @@ | ||
package org.cqfn.diktat.test.resources.test.paragraph1.naming.enum_ | ||
|
||
enum class EnumValuePascalCaseTest { | ||
PaScSalL, | ||
PascAslF, | ||
StartPsaaaDfe, | ||
NameMyaSayR, | ||
NameMyaSayR | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
diktat-rules/src/test/resources/test/paragraph1/naming/enum_/EnumValuePascalCaseTest.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,10 @@ | ||
package org.cqfn.diktat.test.resources.test.paragraph1.naming.enum_ | ||
|
||
enum class EnumValuePascalCaseTest { | ||
paSC_SAl_l, | ||
PascAsl_f, | ||
START_PSaaa_DFE, | ||
_NAme_MYa_sayR, | ||
NAme_MYa_sayR_ | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...ph1/naming/enum_/EnumValueCaseExpected.kt → ...aming/enum_/EnumValueSnakeCaseExpected.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
2 changes: 1 addition & 1 deletion
2
...agraph1/naming/enum_/EnumValueCaseTest.kt → ...h1/naming/enum_/EnumValueSnakeCaseTest.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
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
f57a88b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: