Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
sdk_sandbox/checks/src/test/java/dev/zarah/lint/checks/TodoDetectorTest.kt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
207 lines (195 sloc)
6.28 KB
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
package dev.zarah.lint.checks | |
import com.android.tools.lint.checks.infrastructure.TestFiles | |
import com.android.tools.lint.checks.infrastructure.TestLintTask | |
import org.junit.Test | |
@Suppress("UnstableApiUsage") | |
class TodoDetectorTest { | |
@Test | |
fun testJavaFileNormalComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.java( | |
""" | |
package test.pkg; | |
public class TestClass { | |
// In a comment, mentioning "lint" has no effect | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect("No warnings.") | |
} | |
@Test | |
fun testKotlinFileNormalComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.kotlin( | |
""" | |
package test.pkg | |
class TestClass { | |
// In a comment, mentioning "lint" has no effect | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect("No warnings.") | |
} | |
@Test | |
fun testJavaFileValidComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.java( | |
""" | |
package test.pkg; | |
public class TestClass { | |
// TODO-Zarah (20200515): Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect("No warnings.") | |
} | |
@Test | |
fun testKotlinFileValidComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.kotlin( | |
""" | |
package test.pkg | |
class TestClass { | |
// TODO-Zarah (20200515): Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect("No warnings.") | |
} | |
@Test | |
fun testJavaFileInvalidComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.java( | |
""" | |
package test.pkg; | |
public class TestClass { | |
// TODO (20200515): Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect( | |
""" | |
src/test/pkg/TestClass.java:4: Error: Please make sure to assign the TODO, include today's date in YYYYMMDD format, and the comment is properly formatted. [UnassignedTodo] | |
// TODO (20200515): Some comments | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1 errors, 0 warnings | |
""".trimIndent() | |
) | |
} | |
@Test | |
fun testKotlinFileInvalidComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.kotlin( | |
""" | |
package test.pkg | |
class TestClass { | |
// TODO: Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect( | |
""" | |
src/test/pkg/TestClass.kt:4: Error: Please make sure to assign the TODO, include today's date in YYYYMMDD format, and the comment is properly formatted. [UnassignedTodo] | |
// TODO: Some comments | |
~~~~~~~~~~~~~~~~~~~~~~ | |
1 errors, 0 warnings | |
""".trimIndent() | |
) | |
} | |
@Test | |
fun testKotlinFileDateFormat() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.kotlin( | |
""" | |
package test.pkg | |
class TestClass { | |
// TODO-Zarah (30 Sep. 2020): Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect( | |
""" | |
src/test/pkg/TestClass.kt:4: Error: Please make sure to assign the TODO, include today's date in YYYYMMDD format, and the comment is properly formatted. [UnassignedTodo] | |
// TODO-Zarah (30 Sep. 2020): Some comments | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1 errors, 0 warnings | |
""".trimIndent() | |
) | |
} | |
@Test | |
fun testKotlinFileLowercaseComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.kotlin( | |
""" | |
package test.pkg | |
class TestClass { | |
// todo Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect( | |
""" | |
src/test/pkg/TestClass.kt:4: Error: Please make sure to assign the TODO, include today's date in YYYYMMDD format, and the comment is properly formatted. [UnassignedTodo] | |
// todo Some comments | |
~~~~~~~~~~~~~~~~~~~~~ | |
1 errors, 0 warnings | |
""".trimIndent() | |
) | |
} | |
@Test | |
fun testJavaFileLowercaseComment() { | |
TestLintTask.lint() | |
.files( | |
TestFiles.java( | |
""" | |
package test.pkg; | |
public class TestClass { | |
// todo Some comments | |
} | |
""" | |
) | |
) | |
.issues(TodoDetector.ISSUE) | |
.run() | |
.expect( | |
""" | |
src/test/pkg/TestClass.java:5: Error: Please make sure to assign the TODO, include today's date in YYYYMMDD format, and the comment is properly formatted. [UnassignedTodo] | |
// todo Some comments | |
~~~~~~~~~~~~~~~~~~~~~ | |
1 errors, 0 warnings | |
""".trimIndent() | |
) | |
} | |
} |