A fully functional Android app built entirely with Kotlin and Jetpack Compose
Update regex to match expected format
Simon Marquis473224944339
diff --git a/lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetector.kt b/lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetector.ktindex c7989542e..bcb75ffd5 100644--- a/lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetector.kt+++ b/lint/src/main/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetector.kt@@ -83,7 +83,7 @@ class TestMethodDetector : Detector(), SourceCodeScanner {usageInfo: AnnotationUsageInfo,) {if (!context.isAndroidTest()) return- if ("""^[^\W_]+_[^\W_]+_[^\W_]+$""".toRegex().matches(name)) return+ if ("""[^\W_]+(_[^\W_]+){1,2}""".toRegex().matches(name)) returncontext.report(issue = FORMAT,scope = usageInfo.usage,@@ -153,8 +153,8 @@ class TestMethodDetector : Detector(), SourceCodeScanner {@JvmFieldval FORMAT: Issue = issue(id = "TestMethodFormat",- briefDescription = "Test method does not follow the `given_when_then` format",- explanation = "Test method should follow the `given_when_then` format.",+ briefDescription = "Test method does not follow the `given_when_then` or `when_then` format",+ explanation = "Test method should follow the `given_when_then` or `when_then` format.",)}}diff --git a/lint/src/test/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetectorTest.kt b/lint/src/test/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetectorTest.ktindex ed24b5ccc..592b4f8fb 100644--- a/lint/src/test/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetectorTest.kt+++ b/lint/src/test/kotlin/com/google/samples/apps/nowinandroid/lint/TestMethodDetectorTest.kt@@ -81,10 +81,17 @@ class TestMethodDetectorTest {"""import org.junit.Testclass Test {+ @Test+ fun when_then() = Unit@Testfun given_when_then() = Unit++ @Test+ fun foo() = Unit+ @Test+ fun foo_bar_baz_qux() = Unit@Test- fun given_foo_when_bar_then_baz() = Unit+ fun `foo bar baz`() = Unit}""",).indented(),@@ -92,10 +99,16 @@ class TestMethodDetectorTest {.run().expect("""- src/androidTest/com/example/Test.kt:6: Warning: Test method does not follow the given_when_then format [TestMethodFormat]- fun given_foo_when_bar_then_baz() = Unit- ~~~~~~~~~~~~~~~~~~~~~~~~~~~- 0 errors, 1 warnings+ src/androidTest/com/example/Test.kt:9: Warning: Test method does not follow the given_when_then or when_then format [TestMethodFormat]+ fun foo() = Unit+ ~~~+ src/androidTest/com/example/Test.kt:11: Warning: Test method does not follow the given_when_then or when_then format [TestMethodFormat]+ fun foo_bar_baz_qux() = Unit+ ~~~~~~~~~~~~~~~+ src/androidTest/com/example/Test.kt:13: Warning: Test method does not follow the given_when_then or when_then format [TestMethodFormat]+ fun `foo bar baz`() = Unit+ ~~~~~~~~~~~~~+ 0 errors, 3 warnings""".trimIndent(),)}