Merge upstream/main into feat/desktop-advanced-search

Resolve conflicts:
- RelayStatus.kt: keep both relay URLs
- SearchScreen.kt: keep advanced search implementation
- SinglePaneLayout.kt: add missing Spacer import

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
nrobi144
2026-03-12 13:22:15 +02:00
363 changed files with 17702 additions and 2051 deletions
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.richtext
import kotlin.test.Test
import kotlin.test.assertEquals
class ExpandableTextCutOffCalculatorTest {
val shortPost: String =
"Goldman Sachs Predicts Modest Gains for S&P 500 in 2024 ( #409962b2 , v0.09)"
val image: String =
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIiA/Pgo8c3ZnIHdpZHRoPSIzMjAiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCAzMjAgNjUiIGZpbGw9Im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Mi40MzU4NCAyLjEyNDU1IDYuMjIzNzYgMS44ODY0NSA2LjIyMzc2IDcuMzY3OTdWNDIuODUxOFpNMTEuNDg0NCAyNi4wNzg2QzExLjQ4NDQgMjUuNDI4NiAxMS4xMTgzIDI0LjQxOCAxNi43NTQ5IDI0LjQxOEMzMy41ODkzIDI0LjQxOCAzMy44ODIgMzMuOTc5IDMzLjg4MiAzOC41OTI5QzMzLjg4MiA0Mi45MTg2IDMyLjQxODYgNDkuNTcxMyAyMS4xNzgzIDQ5LjY5NTlDMTAuNzg2MiA0OS44MTE0IDExLjQ4NDQgNDcuNzUxMiAxMS40ODQ0IDQyLjU1NzlWMjYuMDc4NlpNMTEuNDg3NyA3Ljk0NUMxMS40ODc3IDMuNzYxMyAxMS4xMjM3IDIuNjI1OTUgMTUuNzMzMyAyLjUzMzk4QzI0LjU0OTEgMi4zNTkyMyAzMC43NzU0IDcuMDg0NTUgMzAuNTk1NSAxNC44NzA1QzMwLjQ5NTUgMTkuMTAxMiAyNy41ODg4IDIyLjc3NiAxNy45NDcxIDIyLjYyODhDMTEuMzYyMSAyMi41MjY2IDExLjQ4NzcgMjIuMTUyNiAxMS40ODc3IDE5Ljg0MjFWNy45NDVaIgogICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCA1LjQxNzk3KSIKICAvPgo8L3N2Zz4K"
val longPost: String =
"Goldman Sachs Predicts Modest Gains for S&P 500 in 2024 ( #409962b2 , v0.09)\n" +
"\n" + image + "\n" +
"#GoldmanSachs #S&P500 #stockmarket #economy #earnings \n" +
"\n" +
"References:\n" +
"- Barrons: https://www.barrons.com/livecoverage/stock-market-today-111523/card/goldman-sees-4-2-rise-for-s-p-500-through-2024-as-u-s-avoids-recession-OmkU52x3hbSKJGcFBkyj\n" +
"- 8world: https://www.8world.com/finance/gang-says-icbc-paid-ransom-over-hack-2292621\n" +
"\n"
@Test
fun testShortPost() {
assertEquals(76, ExpandableTextCutOffCalculator.indexToCutOff(shortPost))
}
@Test
fun testLostPost() {
assertEquals(77, ExpandableTextCutOffCalculator.indexToCutOff(longPost))
}
@Test
fun testImage() {
assertEquals(350, ExpandableTextCutOffCalculator.indexToCutOff(image))
}
}
@@ -0,0 +1,224 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.richtext
import com.vitorpamplona.amethyst.commons.model.EmptyTagList
import kotlin.test.DefaultAsserter.assertTrue
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class GalleryParserTest {
@Test
fun testMixedImageAndVideoRenderedIndividually() {
// Test that when image + video are in consecutive paragraphs, both should be rendered individually (not as gallery)
val text =
"Renfield (2023)\n" +
"https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg\n" +
"https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 3 paragraphs (text, image, video)
assertEquals(3, state.paragraphs.size)
// First paragraph is text
assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[0].words.size)
// Second paragraph is image (rendered individually, not as gallery)
assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[1].words.size)
assertTrue(state.paragraphs[1].words[0] is ImageSegment)
assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[1].words[0].segmentText)
// Third paragraph is video (rendered individually)
assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[2].words.size)
assertTrue(state.paragraphs[2].words[0] is VideoSegment)
assertEquals("https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4", state.paragraphs[2].words[0].segmentText)
}
@Test
fun testMixedImageAndVideoRenderedIndividuallyDoubled() {
// Test that when image + video are repeated, both should be rendered individually (not as gallery)
val text =
"Renfield (2023)\n" +
"https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg\n" +
"https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4\n" +
"Renfield (2023)\n" +
"https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg\n" +
"https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 6 paragraphs (text, image, video, text, image, video)
assertEquals(6, state.paragraphs.size)
// First set: text, image, video
assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[0].words.size)
assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[1].words[0] is ImageSegment)
assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[1].words[0].segmentText)
assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[2].words[0] is VideoSegment)
assertEquals("https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4", state.paragraphs[2].words[0].segmentText)
// Second set: text, image, video
assertTrue(state.paragraphs[3] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[3].words.size)
assertTrue(state.paragraphs[4] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[4].words[0] is ImageSegment)
assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[4].words[0].segmentText)
assertTrue(state.paragraphs[5] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[5].words[0] is VideoSegment)
assertEquals("https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4", state.paragraphs[5].words[0].segmentText)
}
@Test
fun testMultipleImagesRenderedAsGallery() {
// Test that multiple images (no videos) are correctly grouped as gallery
val text =
"Gallery:\n" +
"https://example.com/image1.jpg\n" +
"https://example.com/image2.png"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 2 image segments (image + video URLs)
assertEquals(2, state.paragraphs.size)
// Should render as gallery (1 gallery with 2 images)
assertTrue("Should render 1 gallery", state.paragraphs[1] is ImageGalleryParagraph)
assertEquals(2, state.paragraphs[1].words.size, "Gallery should contain 2 images")
assertEquals("https://example.com/image1.jpg", state.paragraphs[1].words[0].segmentText)
assertEquals("https://example.com/image2.png", state.paragraphs[1].words[1].segmentText)
}
@Test
fun testMultipleImagesInAParagraphRenderedAsGallery() {
// Test that multiple images (no videos) are correctly grouped as gallery
val text =
"Gallery:\n" +
"https://example.com/image1.jpg https://example.com/image2.png"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 2 image segments (image + video URLs)
assertEquals(2, state.paragraphs.size)
// Should render as gallery (1 gallery with 2 images)
assertTrue("Should render 1 gallery", state.paragraphs[1] is ImageGalleryParagraph)
assertEquals(2, state.paragraphs[1].words.size, "Gallery should contain 2 images")
assertEquals("https://example.com/image1.jpg", state.paragraphs[1].words[0].segmentText)
assertEquals("https://example.com/image2.png", state.paragraphs[1].words[1].segmentText)
}
@Test
fun testSingleImageRenderedIndividually() {
// Test that a single image is rendered individually, not as gallery
val text = "Single image:\nhttps://example.com/image.jpg"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should render individually (not as gallery)
assertTrue("Should render 1 individual image", state.paragraphs[1] !is ImageGalleryParagraph)
assertTrue("Should not render as gallery", state.paragraphs[0] !is ImageGalleryParagraph)
assertEquals("https://example.com/image.jpg", state.paragraphs[1].words[0].segmentText)
}
@Test
fun testGigiMessage() {
val text = "I played The Typing of the Dead a lot when I was younger, and now I just found out that there's a new take on it: The Last Sentence. Tempted! https://relay.dergigi.com/d6a3e33b101fe219ef251ac6261c10392c2af9918c3c252d4c202016b0b4ec83.jpg https://relay.dergigi.com/d60c9c562912573f214c2b1958cc20bf8913cd718d2ed9e020621e3e3120634b.jpg"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should render individually (not as gallery)
assertEquals("I played The Typing of the Dead a lot when I was younger, and now I just found out that there's a new take on it: The Last Sentence. Tempted!", state.paragraphs[0].words[0].segmentText)
assertTrue("Should render as gallery", state.paragraphs[1] is ImageGalleryParagraph)
assertEquals("https://relay.dergigi.com/d6a3e33b101fe219ef251ac6261c10392c2af9918c3c252d4c202016b0b4ec83.jpg", state.paragraphs[1].words[0].segmentText)
assertEquals("https://relay.dergigi.com/d60c9c562912573f214c2b1958cc20bf8913cd718d2ed9e020621e3e3120634b.jpg", state.paragraphs[1].words[1].segmentText)
}
@Test
fun testMixedImageAndVideoInSameParagraph() {
// Test the user's specific example: mixed image and video in same paragraph should render individually
val text =
"The Crow (1994)\n" +
"https://image.tmdb.org/t/p/original/1r7iOhXSbbuUTORNEUOvCUkQ86K.jpg\n" +
"https://archive.org/download/the-crow-1994_20231024/The%20Crow%201994.rar/The%20Crow%201994.1080p.BluRay.x264%20.%20NVEE%2FThe%20Crow%201994.1080p.BluRay.x264%20.%20NVEE.mp4\n" +
"#fantasy #action #thriller #film #movies #kinostr"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 4 paragraphs (text, image, video, hashtags)
assertEquals(4, state.paragraphs.size)
// First paragraph is text
assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
// Second paragraph is image (rendered individually, not as gallery)
assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[1].words[0] is ImageSegment)
assertEquals("https://image.tmdb.org/t/p/original/1r7iOhXSbbuUTORNEUOvCUkQ86K.jpg", state.paragraphs[1].words[0].segmentText)
// Third paragraph is video (rendered individually)
assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
assertTrue(state.paragraphs[2].words[0] is VideoSegment)
assertEquals("https://archive.org/download/the-crow-1994_20231024/The%20Crow%201994.rar/The%20Crow%201994.1080p.BluRay.x264%20.%20NVEE%2FThe%20Crow%201994.1080p.BluRay.x264%20.%20NVEE.mp4", state.paragraphs[2].words[0].segmentText)
// Fourth paragraph is hashtags
assertTrue(state.paragraphs[3] !is ImageGalleryParagraph)
}
@Test
fun testDesperadoExample() {
// Test the exact example provided by the user
val text =
"Desperado (1995)\n" +
"https://media.themoviedb.org/t/p/w440_and_h660_face/e3gwpBeXpvGZsxUya9zNym5QXrw.jpg\n" +
"https://archive.org/download/desperado.-1995.1080p.-blu-ray.x-264.-yify/Desperado.1995.1080p.BluRay.x264.YIFY.mp4\n" +
"#action #crime #film #movies #kinostr"
val state = RichTextParser().parseText(text, EmptyTagList, null)
// Should have 4 paragraphs (text, image, video, hashtags)
assertEquals(4, state.paragraphs.size)
// First paragraph is text
assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
assertEquals("Desperado (1995)", state.paragraphs[0].words[0].segmentText)
// Second paragraph is image (rendered individually, not as gallery)
assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[1].words.size)
assertTrue(state.paragraphs[1].words[0] is ImageSegment)
assertEquals("https://media.themoviedb.org/t/p/w440_and_h660_face/e3gwpBeXpvGZsxUya9zNym5QXrw.jpg", state.paragraphs[1].words[0].segmentText)
// Third paragraph is video (rendered individually)
assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
assertEquals(1, state.paragraphs[2].words.size)
assertTrue(state.paragraphs[2].words[0] is VideoSegment)
assertEquals("https://archive.org/download/desperado.-1995.1080p.-blu-ray.x-264.-yify/Desperado.1995.1080p.BluRay.x264.YIFY.mp4", state.paragraphs[2].words[0].segmentText)
// Fourth paragraph is hashtags
assertTrue(state.paragraphs[3] !is ImageGalleryParagraph)
}
}
@@ -55,7 +55,55 @@ class RichTextParserMultibyteTest {
// user@example.com should not be in urlSet
assertTrue(
"user@example.com should not be in urlSet",
!state.urlSet.contains("user@example.com"),
!state.urlSet.withScheme.contains("user@example.com") && !state.urlSet.withoutScheme.contains("user@example.com"),
)
}
@Test
fun testHttpWithoutSpaces() {
// Multibyte characters around an email address should not produce URL/Link segments
val text =
"Vitor, vocêhttp://test.com? \uD83E\uDD7A"
val state =
RichTextParser()
.parseText(text, EmptyTagList, null)
assertEquals(
"Vitor, você http://test.com ? \uD83E\uDD7A",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@Test
fun testHttpWithoutSpacesJapan() {
// Multibyte characters around an email address should not produce URL/Link segments
val text =
"Vitor, vocêhttp://test.comほげほげ"
val state =
RichTextParser()
.parseText(text, EmptyTagList, null)
assertEquals(
"Vitor, você http://test.com ほげほげ",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@Test
fun testHttpWithoutSpacesJapan2() {
// Multibyte characters around an email address should not produce URL/Link segments
val text =
"Vitor, vocêhttp://test.com。ほげほげ"
val state =
RichTextParser()
.parseText(text, EmptyTagList, null)
assertEquals(
"Vitor, você http://test.com 。ほげほげ",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@@ -65,11 +113,29 @@ class RichTextParserMultibyteTest {
val text =
"Vitor, você tem como colocar alguma forma de aviso se o link vai carregar uma imagem ou um vídeo? \uD83E\uDD7A"
val regex = Regex("(?<=[\\u0000-\\u00FF])(?=[\\u0100-\\uFFFF])|(?<=[\\u0100-\\uFFFF])(?=[\\u0000-\\u00FF])| +")
val state =
RichTextParser()
.parseText(text, EmptyTagList, null)
assertEquals(
"Vitor,-você-tem-como-colocar-alguma-forma-de-aviso-se-o-link-vai-carregar-uma-imagem-ou-um-vídeo?-\uD83E\uDD7A",
text.split(regex).joinToString("-"),
"Vitor, você tem como colocar alguma forma de aviso se o link vai carregar uma imagem ou um vídeo? \uD83E\uDD7A",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@Test
fun testFullTextWithMultibyteAndQuotes() {
// Multibyte characters around an email address should not produce URL/Link segments
val text =
"Ive been thinking lately about how I believe there will more than likely be models unattainable by most. Think Bloomberg Terminal. Where their cost of tokens is too high for the average lay person, but their level of “cognition” is unmatched by anything else. Im sure there will even be many closed models that are invite only. Crazy times ahead."
val state =
RichTextParser()
.parseText(text, EmptyTagList, null)
assertEquals(
"Ive been thinking lately about how I believe there will more than likely be models unattainable by most. Think Bloomberg Terminal. Where their cost of tokens is too high for the average lay person, but their level of “cognition” is unmatched by anything else. Im sure there will even be many closed models that are invite only. Crazy times ahead.",
state.paragraphs.joinToString("\n") { it.words.joinToString(" ") { it.segmentText } },
)
}
@@ -93,7 +159,7 @@ class RichTextParserMultibyteTest {
val urlSegments = allSegments.filterIsInstance<SchemelessUrlSegment>()
assertTrue("Should have SchemelessUrlSegment", urlSegments.isNotEmpty())
assertTrue("URL should be example.com", urlSegments.any { it.url == "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 == "ああ" })
@@ -108,7 +174,7 @@ class RichTextParserMultibyteTest {
val urlSegments = allSegments.filterIsInstance<SchemelessUrlSegment>()
assertTrue("Should have SchemelessUrlSegment", urlSegments.isNotEmpty())
assertTrue("URL should be example.com", urlSegments.any { it.url == "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 == "ああ" })
File diff suppressed because one or more lines are too long
@@ -0,0 +1,294 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.richtext
import kotlin.test.Test
import kotlin.test.assertEquals
class UrlParserTest {
val parser = UrlParser()
fun test(
text: String,
expected: Urls,
) {
val urlSet = parser.parseValidUrls(text)
assertEquals(expected.withScheme, urlSet.withScheme)
assertEquals(expected.withoutScheme, urlSet.withoutScheme)
assertEquals(expected.emails, urlSet.emails)
}
@Test
fun testSimpleText() =
test(
"test. com",
Urls(),
)
@Test
fun testBasicUrl() =
test(
"http://test.com",
Urls(withScheme = setOf("http://test.com")),
)
@Test
fun testNoSchemaUrl() =
test(
"test.com",
Urls(withoutScheme = setOf("test.com")),
)
@Test
fun testNoSchemaUrlPrefixMultibyte() =
test(
"ほtest.com",
Urls(withoutScheme = setOf("test.com")),
)
@Test
fun testNoSchemaUrlSuffixMultibyte() =
test(
"test.comほ",
Urls(withoutScheme = setOf("test.com")),
)
@Test
fun testNoSchemaUrlWithParams() =
test(
"test.com/some/me/hey?param=value#some=value",
Urls(withoutScheme = setOf("test.com/some/me/hey?param=value#some=value")),
)
@Test
fun testNoSchemaUrlWithParamsWithOtherWords() =
test(
"Hi there, check my website test.com/some/me/hey?param=value#some=value .",
Urls(withoutScheme = setOf("test.com/some/me/hey?param=value#some=value")),
)
@Test
fun testBasicUrlWithoutSpaceBefore() =
test(
"ahttp://test.com",
Urls(withScheme = setOf("http://test.com")),
)
@Test
fun testBasicUrlWithoutSpaceBeforeMultiByte() =
test(
"ほhttp://test.com",
Urls(withScheme = setOf("http://test.com")),
)
@Test
fun testBasicUrlWithoutSpaceAfter() =
test(
"http://test.comほ",
Urls(withScheme = setOf("http://test.com")),
)
@Test
fun testBasicUrlWithMultibytePath() =
test(
"http://test.com/ほ",
Urls(withScheme = setOf("http://test.com/ほ")),
)
@Test
fun testBasicUrls() =
test(
"http://test.com http://test2.com",
Urls(withScheme = setOf("http://test.com", "http://test2.com")),
)
@Test
fun testEmail() =
test(
"vitor@vitorpamplona.com",
Urls(emails = setOf("vitor@vitorpamplona.com")),
)
@Test
fun testEmailWithMultibytePrefix() =
test(
"ほvitor@vitorpamplona.com",
Urls(emails = setOf("vitor@vitorpamplona.com")),
)
@Test
fun testEmailWithMultibyteSuffix() =
test(
"vitor@vitorpamplona.comほ",
Urls(emails = setOf("vitor@vitorpamplona.com")),
)
@Test
fun testEmailWithMultibyteBoth() =
test(
"ほvitor@vitorpamplona.comほ",
Urls(emails = setOf("vitor@vitorpamplona.com")),
)
@Test
fun testUrlWithUserAndMultibyteSuffix() =
test(
"http://vitor@vitorpamplona.comほ",
Urls(withScheme = setOf("http://vitor@vitorpamplona.com")),
)
@Test
fun testUrlWithUserAndMultibytePrefix() =
test(
"ほhttp://vitor@vitorpamplona.com",
Urls(withScheme = setOf("http://vitor@vitorpamplona.com")),
)
@Test
fun testNostrUrls() =
test(
"nostr:npub142gywvjkq0dv6nupggyn2euhx4nduwc7yz5f24ah9rpmunr2s39se3xrj0",
Urls(bech32s = setOf("nostr:npub142gywvjkq0dv6nupggyn2euhx4nduwc7yz5f24ah9rpmunr2s39se3xrj0")),
)
@Test
fun testUrlsWithUsernameAndPath() =
test(
"miceliomad@miceliomad.github.io/nostr/",
Urls(withoutScheme = setOf("miceliomad@miceliomad.github.io/nostr/")),
)
@Test
fun testUrlsWithQuery() =
test(
" universe.nostrich.land?lang=zh ",
Urls(withoutScheme = setOf("universe.nostrich.land?lang=zh")),
)
@Test
fun testUrlsWithSchemaPathAndQuery() =
test(
"https://miceliomad.github.io/nostr/test?me=you",
Urls(withScheme = setOf("https://miceliomad.github.io/nostr/test?me=you")),
)
@Test
fun testUrlsWithPathAndQuery() =
test(
"miceliomad.github.io/nostr/test?me=you",
Urls(withoutScheme = setOf("miceliomad.github.io/nostr/test?me=you")),
)
@Test
fun testAvifFileNameComplete() =
test(
"https://bae.st/media/66b08dde784287ed8f92c455bc62076a04671ccb44097550626a532185a5d3ed.avif?name=81ca16-b665-4f57-80cb-11a58461fb61.avif",
Urls(withScheme = setOf("https://bae.st/media/66b08dde784287ed8f92c455bc62076a04671ccb44097550626a532185a5d3ed.avif?name=81ca16-b665-4f57-80cb-11a58461fb61.avif")),
)
@Test
fun testAvifFileName() =
test(
"81ca16-b665-4f57-80cb-11a58461fb61.avif",
Urls(withoutScheme = setOf("81ca16-b665-4f57-80cb-11a58461fb61.avif")),
)
@Test
fun testMultiLine() =
test(
"""
22.8K (3.2%) nos.lol
22.7K (3.1%) universe.nostrich.land?lang=zh
22.5K (3.1%) universe.nostrich.land?lang=en
""".trimIndent(),
Urls(withoutScheme = setOf("nos.lol", "universe.nostrich.land?lang=zh", "universe.nostrich.land?lang=en")),
)
@Test
fun testEmailWithDashes() =
test(
"freeverification@Nostr-Check.com",
Urls(emails = setOf("freeverification@Nostr-Check.com")),
)
@Test
fun testEmailWithManyDashes() =
test(
"free-veri-fica-tion@No-str-Ch-eck.com",
Urls(emails = setOf("free-veri-fica-tion@No-str-Ch-eck.com")),
)
@Test
fun testEmailWithUnderscore() =
test(
"vi_t_or@vitorpamplona.com",
Urls(emails = setOf("vi_t_or@vitorpamplona.com")),
)
@Test
fun testEmailsWithPeriod() =
test(
"john.smith@gmail.com",
Urls(emails = setOf("john.smith@gmail.com")),
)
@Test
fun testStrangeError() =
test(
"neomobius_at_mstdn.jp@mostr.pub",
Urls(emails = setOf("neomobius_at_mstdn.jp@mostr.pub")),
)
@Test
fun testRelayUrl() =
test(
"wss://test.com",
Urls(relayUrls = setOf("wss://test.com")),
)
@Test
fun testBech12() =
test(
"nostr:npub142gywvjkq0dv6nupggyn2euhx4nduwc7yz5f24ah9rpmunr2s39se3xrj0",
Urls(bech32s = setOf("nostr:npub142gywvjkq0dv6nupggyn2euhx4nduwc7yz5f24ah9rpmunr2s39se3xrj0")),
)
@Test
fun testJapaneseUrls() =
test(
"我进入你的主页很卡顿,也许是你的关注人数或者其他数据太多了,其他人主页没有这么卡顿。来自amethyst客户端",
Urls(withScheme = emptySet()),
)
@Test
fun testHour() =
test(
"10.00hr,",
Urls(withScheme = emptySet()),
)
@Test
fun testBlossom() =
test(
"blossom:b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553.pdf?xs=cdn.satellite.earth",
Urls(withScheme = setOf("blossom:b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553.pdf?xs=cdn.satellite.earth")),
)
}