-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open lemmy-verse links in Jerboa (#692)
* Implement !community@instance and @user@instance links They merely pop up a toast saying it's unimplemented, but the links are being created and handled. * Open community and user urls if they match regex --------- Co-authored-by: Tyler Little <[email protected]>
- Loading branch information
1 parent
dcaf991
commit 7fdc045
Showing
7 changed files
with
212 additions
and
14 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
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
70 changes: 70 additions & 0 deletions
70
app/src/test/java/com/jerboa/ui/components/common/LemmyLinkPluginTest.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,70 @@ | ||
package com.jerboa.ui.components.common | ||
|
||
import junitparams.JUnitParamsRunner | ||
import junitparams.Parameters | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(JUnitParamsRunner::class) | ||
class LemmyLinkPluginTest { | ||
@Test | ||
@Parameters(method = "communitySuccessCases") | ||
fun testCommunityValid(pattern: String, community: String, instance: String?) { | ||
val matcher = lemmyCommunityPattern.matcher(pattern) | ||
|
||
assertTrue(matcher.find()) | ||
assertEquals(community, matcher.group(1)) | ||
assertEquals(instance, matcher.group(2)) | ||
} | ||
|
||
@Test | ||
@Parameters( | ||
value = [ | ||
"a!community", | ||
"[email protected]", | ||
"!co", | ||
], | ||
) | ||
fun testCommunityInvalid(pattern: String) { | ||
assertFalse(lemmyCommunityPattern.matcher(pattern).find()) | ||
} | ||
|
||
@Test | ||
@Parameters(method = "userSuccessCases") | ||
fun testUserValid(pattern: String, user: String, instance: String?) { | ||
val matcher = lemmyUserPattern.matcher(pattern) | ||
|
||
assertTrue(matcher.find()) | ||
assertEquals(user, matcher.group(1)) | ||
assertEquals(instance, matcher.group(2)) | ||
} | ||
|
||
@Test | ||
@Parameters( | ||
value = [ | ||
"a@user", | ||
"!@[email protected]", | ||
"@co", | ||
], | ||
) | ||
fun testUserInvalid(pattern: String) { | ||
assertFalse(lemmyUserPattern.matcher(pattern).find()) | ||
} | ||
|
||
fun communitySuccessCases() = listOf( | ||
listOf("!community", "community", null), | ||
listOf(" !community.", "community", null), | ||
listOf("[email protected]", "community", "instance.ml"), | ||
listOf("[email protected]!", "community", "instance.ml"), | ||
) | ||
|
||
fun userSuccessCases() = listOf( | ||
listOf("@user", "user", null), | ||
listOf(" @user.", "user", null), | ||
listOf("@[email protected]", "user", "instance.ml"), | ||
listOf("@[email protected]!", "user", "instance.ml"), | ||
) | ||
} |