Applies new UrlDetector to the RichTextViewer

This commit is contained in:
Vitor Pamplona
2026-03-07 16:38:25 -05:00
parent 030921c963
commit e3f99051db
12 changed files with 178 additions and 73 deletions
@@ -70,7 +70,7 @@ class RichTextParserMultibyteTest {
.parseText(text, EmptyTagList, null)
assertEquals(
"Vitor, você http://test.com? \uD83E\uDD7A",
"Vitor, você http://test.com ? \uD83E\uDD7A",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@@ -157,9 +157,9 @@ class RichTextParserMultibyteTest {
val state = RichTextParser().parseText(text, EmptyTagList, null)
val allSegments = state.paragraphs.flatMap { it.words }
val urlSegments = allSegments.filterIsInstance<LinkSegment>()
val urlSegments = allSegments.filterIsInstance<SchemelessUrlSegment>()
assertTrue("Should have SchemelessUrlSegment", urlSegments.isNotEmpty())
assertTrue("URL should be example.com", urlSegments.any { it.segmentText == "https://example.com" })
assertTrue("URL should be example.com", urlSegments.any { it.segmentText == "example.com" })
val textSegments = allSegments.filterIsInstance<RegularTextSegment>()
assertTrue("Should have prefix ああ", textSegments.any { it.segmentText == "ああ" })
@@ -172,9 +172,9 @@ class RichTextParserMultibyteTest {
val state = RichTextParser().parseText(text, EmptyTagList, null)
val allSegments = state.paragraphs.flatMap { it.words }
val urlSegments = allSegments.filterIsInstance<LinkSegment>()
val urlSegments = allSegments.filterIsInstance<SchemelessUrlSegment>()
assertTrue("Should have SchemelessUrlSegment", urlSegments.isNotEmpty())
assertTrue("URL should be example.com", urlSegments.any { it.segmentText == "https://example.com" })
assertTrue("URL should be example.com", urlSegments.any { it.segmentText == "example.com" })
val textSegments = allSegments.filterIsInstance<RegularTextSegment>()
assertTrue("Should have suffix ああ", textSegments.any { it.segmentText == "ああ" })
@@ -749,52 +749,52 @@ class RichTextParserTest {
"RegularText(Events (%) Relay)",
"RegularText(33.4K)",
"RegularText((4.6%))",
"Link(https://relay.shitforce.one)",
"SchemelessUrl(relay.shitforce.one)",
"RegularText(32.9K)",
"RegularText((4.6%))",
"Link(https://relayable.org)",
"SchemelessUrl(relayable.org)",
"RegularText(26.6K)",
"RegularText((3.7%))",
"Link(https://universe.nostrich.land)",
"SchemelessUrl(universe.nostrich.land)",
"RegularText(22.8K)",
"RegularText((3.2%))",
"Link(https://nos.lol)",
"SchemelessUrl(nos.lol)",
"RegularText(22.7K)",
"RegularText((3.1%))",
"Link(https://universe.nostrich.land?lang=zh)",
"SchemelessUrl(universe.nostrich.land?lang=zh)",
"RegularText(22.5K)",
"RegularText((3.1%))",
"Link(https://universe.nostrich.land?lang=en)",
"SchemelessUrl(universe.nostrich.land?lang=en)",
"RegularText(21.2K)",
"RegularText((2.9%))",
"Link(https://relay.damus.io)",
"SchemelessUrl(relay.damus.io)",
"RegularText(20.6K)",
"RegularText((2.9%))",
"Link(https://relay.nostr.wirednet.jp)",
"SchemelessUrl(relay.nostr.wirednet.jp)",
"RegularText(20.1K)",
"RegularText((2.8%))",
"Link(https://offchain.pub)",
"SchemelessUrl(offchain.pub)",
"RegularText(19.9K)",
"RegularText((2.8%))",
"Link(https://nostr.rocks)",
"SchemelessUrl(nostr.rocks)",
"RegularText(19.5K)",
"RegularText((2.7%))",
"Link(https://relay.wellorder.net)",
"SchemelessUrl(relay.wellorder.net)",
"RegularText(19.4K)",
"RegularText((2.7%))",
"Link(https://nostr.oxtr.dev)",
"SchemelessUrl(nostr.oxtr.dev)",
"RegularText(19K)",
"RegularText((2.6%))",
"Link(https://universe.nostrich.land?lang=ja)",
"SchemelessUrl(universe.nostrich.land?lang=ja)",
"RegularText(18.4K)",
"RegularText((2.6%))",
"Link(https://relay.mostr.pub)",
"SchemelessUrl(relay.mostr.pub)",
"RegularText(17.5K)",
"RegularText((2.4%))",
"Link(https://universe.nostrich.land?lang=zh)",
"SchemelessUrl(universe.nostrich.land?lang=zh)",
"RegularText(16.3K)",
"RegularText((2.3%))",
"Link(https://nostr.bitcoiner.social)",
"SchemelessUrl(nostr.bitcoiner.social)",
"RegularText()",
"RegularText(30 day global new events)",
"RegularText()",
@@ -1633,7 +1633,7 @@ class RichTextParserTest {
"RegularText(eb3b94533dafeb8ebd58a4947a3dce11d83a9931c622bdf30a4257d3347ee1bf)",
"HashTag(#109)",
"RegularText(3%)",
"Link(https://Nostr-Check.com)",
"SchemelessUrl(Nostr-Check.com)",
"RegularText(,)",
"Email(freeverification@Nostr-Check.com)",
"RegularText(-)",
@@ -1910,7 +1910,7 @@ class RichTextParserTest {
"RegularText(d162a53c3b0bfb5c3ebd787d7b08feab206b112362eca25aa291251cd70fe225)",
"HashTag(#154)",
"RegularText(3%)",
"Link(https://MR.Rabbit)",
"SchemelessUrl(MR.Rabbit)",
"RegularText(,)",
"Email(Mr.Rabbit@BitcoinNostr.com)",
"RegularText(-)",
@@ -2087,7 +2087,7 @@ class RichTextParserTest {
"RegularText(39ed0aea2338477103e0b5a820532ded27dbfe4f203e7270392d55f63e60271a)",
"HashTag(#183)",
"RegularText(2%)",
"Link(https://Ancap.su)",
"SchemelessUrl(Ancap.su)",
"RegularText(,)",
"Email(ancapsu@getalby.com)",
"RegularText(-)",
@@ -2488,7 +2488,7 @@ class RichTextParserTest {
"HashTag(#249)",
"RegularText(2%)",
"RegularText(micmad,)",
"Link(https://miceliomad@miceliomad.github.io/nostr/)",
"SchemelessUrl(miceliomad@miceliomad.github.io/nostr/)",
"RegularText(-)",
"RegularText(cd806edcf8ff40ea94fa574ea9cd97da16e5beb2b85aac6e1d648b8388504343)",
"HashTag(#250)",
@@ -2667,7 +2667,7 @@ class RichTextParserTest {
"HashTag(#278)",
"RegularText(2%)",
"RegularText(𝕬𝖓𝖔𝖓𝖞𝖒𝖔𝖚𝖘,)",
"Link(https://zapper.lol)",
"SchemelessUrl(zapper.lol)",
"RegularText(-)",
"RegularText(96aceca84aa381eeda084167dd317e1bf7a45d874cd14147f0a9e0df86fb44c2)",
"HashTag(#279)",
@@ -3125,7 +3125,7 @@ class RichTextParserTest {
"RegularText(c4a9caef93e93f484274c04cd981d1de1424902451aca2f5602bd0835fe4393d)",
"HashTag(#354)",
"RegularText(2%)",
"Link(https://smies.me)",
"SchemelessUrl(smies.me)",
"RegularText(,)",
"Email(jacksmies@iris.to)",
"RegularText(-)",
@@ -4006,7 +4006,7 @@ class RichTextParserTest {
"RegularText(21a7014db2ba17acc8bbb9496645084866b46e1ba0062a80513afda405450183)",
"HashTag(#499)",
"RegularText(1%)",
"Link(https://baller.hodl)",
"SchemelessUrl(baller.hodl)",
"RegularText(,)",
"RegularText()",
"RegularText(-)",
@@ -4287,7 +4287,8 @@ class RichTextParserTest {
listOf<String>(
"RegularText(Thats)",
"RegularText(it!)",
"Link(http://vitorpamplona.com/.)",
"Link(http://vitorpamplona.com/)",
"RegularText(.)",
"RegularText(Thats)",
"RegularText(the)",
"RegularText(note)",
@@ -166,7 +166,7 @@ class UrlParserTest {
fun testNostrUrls() =
test(
"nostr:npub1aabbcc",
Urls(withScheme = setOf("nostr:npub1aabbcc")),
Urls(bech32s = setOf("nostr:npub1aabbcc")),
)
@Test
@@ -261,14 +261,14 @@ class UrlParserTest {
fun testRelayUrl() =
test(
"wss://test.com",
Urls(withScheme = setOf("wss://test.com")),
Urls(relayUrls = setOf("wss://test.com")),
)
@Test
fun testBech12() =
test(
"nostr:npub1aabbcc",
Urls(withScheme = setOf("nostr:npub1aabbcc")),
Urls(bech32s = setOf("nostr:npub1aabbcc")),
)
@Test