diff --git a/src/test/java/io/github/brenoepics/MentionExtractorTest.kt b/src/test/java/io/github/brenoepics/MentionExtractorTest.kt index 920127f..6499d0a 100644 --- a/src/test/java/io/github/brenoepics/MentionExtractorTest.kt +++ b/src/test/java/io/github/brenoepics/MentionExtractorTest.kt @@ -85,4 +85,66 @@ class MentionExtractorTest { assertEquals(setOf("user1", "user2"), mentions) } + + @Test + fun `extract mentions from null text`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = null + val mentions = extractor.fromString(text) + + assertTrue(mentions.isEmpty()) + } + + @Test + fun `extract mentions from empty text`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = "" + val mentions = extractor.fromString(text) + + assertTrue(mentions.isEmpty()) + } + + @Test + fun `check if null text contains mention`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = null + + assertFalse(extractor.containsMention(text)) + } + + @Test + fun `check if empty text contains mention`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = "" + + assertFalse(extractor.containsMention(text)) + } + + @Test + fun `count mentions in null text`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = null + + assertEquals(0, extractor.countMentions(text)) + } + + @Test + fun `count mentions in empty text`() { + val pattern = MentionPattern().defaultPattern() + val extractor = MentionExtractor.Builder().pattern(pattern).build() + + val text = "" + + assertEquals(0, extractor.countMentions(text)) + } } diff --git a/src/test/java/io/github/brenoepics/MentionPatternTest.kt b/src/test/java/io/github/brenoepics/MentionPatternTest.kt index 388f5a6..7d8b8b4 100644 --- a/src/test/java/io/github/brenoepics/MentionPatternTest.kt +++ b/src/test/java/io/github/brenoepics/MentionPatternTest.kt @@ -2,6 +2,7 @@ package io.github.brenoepics import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import kotlin.test.assertFalse class MentionPatternTest { @@ -30,6 +31,16 @@ class MentionPatternTest { assertTrue(pattern.matcher("@user@example.net").matches()) } + @Test + fun `withUnderscores should match mentions with underscores`() { + val pattern = MentionPattern().withUnderscores().build() + assertTrue(pattern.matcher("@user_name").matches()) + assertTrue(pattern.matcher("@username").matches()) + assertTrue(!pattern.matcher("@user-name").matches()) + assertTrue(pattern.matcher("@username123").matches()) + assertTrue(pattern.matcher("@user_name_123").matches()) + } + @Test fun `defaultPattern should match any word character after '@'`() { val pattern = MentionPattern().defaultPattern().build() @@ -49,4 +60,34 @@ class MentionPatternTest { assertTrue(pattern.matcher("@username123").matches()) assertTrue(pattern.matcher("@user_name_123").matches()) } + + @Test + fun `defaultPattern should not match null or empty strings`() { + val pattern = MentionPattern().defaultPattern().build() + assertFalse(pattern.matcher("").matches()) + } + + @Test + fun `withSpecialChars should not match null or empty strings`() { + val pattern = MentionPattern().withSpecialChars().build() + assertFalse(pattern.matcher("").matches()) + } + + @Test + fun `withEmailLike should not match null or empty strings`() { + val pattern = MentionPattern().withEmailLike().build() + assertFalse(pattern.matcher("").matches()) + } + + @Test + fun `withUnderscores should not match null or empty strings`() { + val pattern = MentionPattern().withUnderscores().build() + assertFalse(pattern.matcher("").matches()) + } + + @Test + fun `customPattern should not match null or empty strings`() { + val pattern = MentionPattern().customPattern("@([A-Za-z0-9_]+)").build() + assertFalse(pattern.matcher("").matches()) + } }