Skip to content

Commit

Permalink
Add testsfor multi-line annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
cable729 committed Oct 26, 2018
1 parent ca731f1 commit 272fa08
Showing 1 changed file with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class MemberOrTypeAnnotationRuleTest {

@Test
fun `format single annotation may be placed on line before annotated construct`() {
val code =
"""
val code = """
@FunctionalInterface class A {
@JvmField
var x: String
Expand All @@ -51,8 +50,7 @@ class MemberOrTypeAnnotationRuleTest {

@Test
fun `format single annotation may be placed on same line as annotated construct`() {
val code =
"""
val code = """
@FunctionalInterface class A {
@JvmField var x: String
Expand Down Expand Up @@ -249,12 +247,73 @@ class MemberOrTypeAnnotationRuleTest {

@Test
fun `format annotation after keyword`() {
val code =
"""
val code = """
class A {
private @Test fun myTest() {}
}
""".trimIndent()
assertThat(MemberOrTypeAnnotationRule().format(code)).isEqualTo(code)
}

@Test
fun `lint multi-line annotation`() {
assertThat(
MemberOrTypeAnnotationRule().lint(
"""
class A {
@JvmField @Volatile @Annotation(
enabled = true,
groups = [
"a",
"b",
"c"
]
) val a: Any
}
""".trimIndent()
)
).containsExactly(
LintError(
2, 5, "member-or-type-annotation",
MemberOrTypeAnnotationRule.multipleAnnotationsOnSameLineAsAnnotatedConstructErrorMessage
),
LintError(
2, 5, "member-or-type-annotation",
MemberOrTypeAnnotationRule.annotationsWithParametersAreNotOnSeparateLinesErrorMessage
)
)
}

@Test
fun `format multi-line annotation`() {
val code = """
class A {
@JvmField @Volatile @Annotation(
enabled = true,
groups = [
"a",
"b",
"c"
]
) val a: Any
}
""".trimIndent()
assertThat(MemberOrTypeAnnotationRule().format(code)).isEqualTo(
"""
class A {
@JvmField
@Volatile
@Annotation(
enabled = true,
groups = [
"a",
"b",
"c"
]
)
val a: Any
}
""".trimIndent()
)
}
}

0 comments on commit 272fa08

Please sign in to comment.