Migrates to AGP 9

This commit is contained in:
Vitor Pamplona
2026-02-08 16:33:39 -05:00
parent f8a232385d
commit 6125394354
72 changed files with 48 additions and 117 deletions
@@ -0,0 +1,130 @@
/**
* 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.compose
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TextFieldValueExtensionTest {
@Test
fun testInsertTwoCharsStart() {
val current = TextFieldValue("ab", selection = TextRange(0, 0))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("http://a.b ab", next.text)
assertEquals(TextRange(10, 10), next.selection)
}
@Test
fun testInsertTwoCharsMiddle() {
val current = TextFieldValue("ab", selection = TextRange(1, 1))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsEnd() {
val current = TextFieldValue("ab", selection = TextRange(2, 2))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("ab http://a.b", next.text)
assertEquals(TextRange(13, 13), next.selection)
}
@Test
fun testInsertOneCharStart() {
val current = TextFieldValue("a", selection = TextRange(0, 0))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("http://a.b a", next.text)
assertEquals(TextRange(10, 10), next.selection)
}
@Test
fun testInsertOneCharEnd() {
val current = TextFieldValue("a", selection = TextRange(1, 1))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsWithSpaceStart() {
val current = TextFieldValue("a b", selection = TextRange(1, 1))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsWithSpaceEnd() {
val current = TextFieldValue("a b", selection = TextRange(2, 2))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsWithThreeSpaceStart() {
val current = TextFieldValue("a b", selection = TextRange(1, 1))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsWithThreeSpaceMiddle() {
val current = TextFieldValue("a b", selection = TextRange(2, 2))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(12, 12), next.selection)
}
@Test
fun testInsertTwoCharsWithThreeSpaceEnd() {
val current = TextFieldValue("a b", selection = TextRange(3, 3))
val next = current.insertUrlAtCursor("http://a.b")
assertEquals("a http://a.b b", next.text)
assertEquals(TextRange(13, 13), next.selection)
}
@Test
fun testInsertAfterNewLine() {
val current = TextFieldValue("ab\n\n", selection = TextRange(4, 4))
val next = current.insertUrlAtCursor("https://i.nostr.build/zdMW4.jpg")
assertEquals("ab\n\nhttps://i.nostr.build/zdMW4.jpg", next.text)
assertEquals(TextRange(35, 35), next.selection)
}
}
@@ -0,0 +1,106 @@
/**
* 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.preview
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.amethyst.commons.blurhash.BlurHashDecoder
import com.vitorpamplona.amethyst.commons.blurhash.BlurHashDecoderOld
import com.vitorpamplona.amethyst.commons.blurhash.toBlurhash
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.math.roundToInt
@RunWith(AndroidJUnit4::class)
class BlurhashTest {
val warmHex = "[45#Y7_2^-xt%OSb%4S0-qt0xbotaRInV|M{RlD~M{M_IVIUNHM{M{M{M{RjNGRkoyj]o[t8tPt8"
val testHex = "|NHL-]~pabocs+jDM{j?of4T9ZR+WBWZbdR-WCog04ITn\$t6t6t6t6oJoLZ}?bIUWBs:M{WCogRjs:s+o#R+WBoft7axWBx]IV%LogM{t5xaWBay%KRjxus.WCNGWWt7j[j]s+R-S5ofjYV@j[ofD%t8RPoJt7t7R*WCof"
@Test
fun testAspectRatioWarm() {
Assert.assertEquals(0.44444445f, BlurHashDecoder.aspectRatio(warmHex)!!, 0.001f)
}
@Test
fun testDecoderWarm() {
val aspectRatio = BlurHashDecoder.aspectRatio(warmHex) ?: 1.0f
val bmp1 = BlurHashDecoderOld.decode(warmHex, 100, (100 * (1 / aspectRatio)).roundToInt())
val bmp2 = BlurHashDecoder.decodeKeepAspectRatio(warmHex, 100)
assertTrue(bmp1!!.sameAs(bmp2!!.bitmap))
}
@Test
fun testDecoderWarm25Pixels() {
val aspectRatio = BlurHashDecoder.aspectRatio(warmHex) ?: 1.0f
val bmp1 = BlurHashDecoderOld.decode(warmHex, 25, (25 * (1 / aspectRatio)).roundToInt())
val bmp2 = BlurHashDecoder.decodeKeepAspectRatio(warmHex, 25)
assertTrue(bmp1!!.sameAs(bmp2!!.bitmap))
}
@Test
fun testAspectRatioTest() {
Assert.assertEquals(1.0f, BlurHashDecoder.aspectRatio(testHex)!!)
}
@Test
fun testDecoderTest() {
val aspectRatio = BlurHashDecoder.aspectRatio(testHex) ?: 1.0f
val bmp1 = BlurHashDecoderOld.decode(testHex, 100, (100 * (1 / aspectRatio)).roundToInt())
val bmp2 = BlurHashDecoder.decodeKeepAspectRatio(testHex, 100)
assertTrue(bmp1!!.sameAs(bmp2!!.bitmap))
}
@Test
fun testBlack() {
assertEquals("U00000fQfQfQfQfQfQfQfQfQfQfQfQfQfQfQ", load("/black.png").toBlurhash())
}
@Test
fun test1x1() {
assertEquals("U~TSUA~q~q~q~q~q~q~q~q~q~q~q~q~q~q~q", load("/1x1.png").toBlurhash())
}
@Test
fun testWhite() {
assertEquals("U2TSUA~qfQ~q~qj[fQj[fQfQfQfQ~qj[fQj[", load("/white.png").toBlurhash())
}
@Test
fun testLorikeet() {
val blurhash = load("/lorikeet.jpg").toBlurhash()
assertEquals("rFDcT@_LNs#:-pyBnhRRE2Z~MyX5VuV@WUo{xta\$9]RQw[OXS}rrWFXSw|OsxaxWNHSwn~M}NGaK%0RkM}w{xto|jGs+Sh-Tj]W?wJnjXSxGs.NI", blurhash)
}
private fun load(filename: String): Bitmap =
javaClass.getResourceAsStream(filename).use { inputStream ->
BitmapFactory.decodeStream(inputStream)
}
}
@@ -0,0 +1,106 @@
/**
* 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.preview
import org.junit.Assert.assertEquals
import org.junit.Test
class MetaTagsParserTest {
@Test
fun testParse() {
val input =
"""<html>
| <head>
| <meta charset="utf-8">
| <meta http-equiv="content-type" content="text/html; charset=utf-8">
| <meta property="og:title" content=title>
| <meta property="og:description" content='description'>
| <meta property="og:image" content="https://example.com/img/foo.png">
| <!-- edge cases -->
| <meta
| name="newline"
| content="newline"
| >
| <meta name="space before gt" >
| <meta name ="space before =">
| <meta name= "space after =">
| <META NAME="CAPITAL">
| <meta name="character reference" content="&lt;meta&gt;">
| <meta name="attr value with end of head doesn't harm" content="<head>bang!</head>">
| <meta name="ignore tags with duplicated attr" name="dup">
| </head>
| <body>
| <meta name="ignore meta tags in body">
| </body>
|</html>
""".trimMargin()
val exp =
listOf(
listOf("charset" to "utf-8"),
listOf("http-equiv" to "content-type", "content" to "text/html; charset=utf-8"),
listOf("property" to "og:title", "content" to "title"),
listOf("property" to "og:description", "content" to "description"),
listOf("property" to "og:image", "content" to "https://example.com/img/foo.png"),
listOf("name" to "newline", "content" to "newline"),
listOf("name" to "space before gt"),
listOf("name" to "space before ="),
listOf("name" to "space after ="),
listOf("name" to "CAPITAL"),
listOf("name" to "character reference", "content" to "<meta>"),
listOf("name" to "attr value with end of head doesn't harm", "content" to "<head>bang!</head>"),
)
val metaTags = MetaTagsParser.parse(input).toList()
println(metaTags)
assertEquals(exp.size, metaTags.size)
metaTags.zip(exp).forEach { (meta, expAttrs) ->
expAttrs.forEach { (name, expValue) ->
assertEquals(expValue, meta.attr(name))
}
}
}
@Test
fun testParseWithAdditionalTags() {
val input =
"""<html>
| <head>
| <meta data-preact-helmet property="og:title" content="Uma conversa com Antonio Vargas">
| </head>
|</html>
""".trimMargin()
val exp =
listOf(
listOf("property" to "og:title", "content" to "Uma conversa com Antonio Vargas"),
)
val metaTags = MetaTagsParser.parse(input).toList()
println(metaTags)
assertEquals(exp.size, metaTags.size)
metaTags.zip(exp).forEach { (meta, expAttrs) ->
expAttrs.forEach { (name, expValue) ->
assertEquals(expValue, meta.attr(name))
}
}
}
}
@@ -0,0 +1,59 @@
/**
* 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 androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ExpandableTextCutOffCalculatorTest {
val shortPost: String =
"Goldman Sachs Predicts Modest Gains for S&P 500 in 2024 ( #409962b2 , v0.09)"
val longPost: String =
"Goldman Sachs Predicts Modest Gains for S&P 500 in 2024 ( #409962b2 , v0.09)\n" +
"\n" +
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIiA/Pgo8c3ZnIHdpZHRoPSIzMjAiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCAzMjAgNjUiIGZpbGw9ImJsYWNrIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aAogICAgZmlsbC1ydWxlPSJldmVub2RkIgogICAgY2xpcC1ydWxlPSJldmVub2RkIgogICAgZD0iTTguNTk4MjggNDIuMTU1OEM3LjgxMjgxIDQ5LjA1OTkgNS45ODMyNCA0OC44Njg4IDMuNzYzMDYgNDkuNDMzOUMxLjc1MjU1IDQ5Ljk0MzggMi41MTk5MyA1MS4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kuNTcxMyAyMS4xNzgzIDQ5LjY5NTlDMTAuNzg2MiA0OS44MTE0IDExLjQ4NDQgNDcuNzUxMiAxMS40ODQ0IDQyLjU1NzlWMjYuMDc4NlpNMTEuNDg3NyA3Ljk0NUMxMS40ODc3IDMuNzYxMyAxMS4xMjM3IDIuNjI1OTUgMTUuNzMzMyAyLjUzMzk4QzI0LjU0OTEgMi4zNTkyMyAzMC43NzU0IDcuMDg0NTUgMzAuNTk1NSAxNC44NzA1QzMwLjQ5NTUgMTkuMTAxMiAyNy41ODg4IDIyLjc3NiAxNy45NDcxIDIyLjYyODhDMTEuMzYyMSAyMi41MjY2IDExLjQ4NzcgMjIuMTUyNiAxMS40ODc3IDE5Ljg0MjFWNy45NDVaIgogICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCA1LjQxNzk3KSIKICAvPgo8L3N2Zz4K\n" +
"Goldman Sachs analysts predict that the S&P 500 will have a 4.2% price gain and end at 4,700 by the end of 2024, representing a modest increase from recent levels. They believe that the U.S. economy will continue to expand at a modest pace and that earnings will rise by 5%. The forecast includes an equity market valuation at an 18 times multiple. Goldman Sachs also predicts that the 'Magnificent 7' bundle of mega-caps, including Nvidia, Microsoft, Alphabet, Apple, Amazon.com, Meta Platforms, and Tesla, will outperform the rest of the S&P 500 in 2024. They suggest that there are more attractive investment opportunities in quality stocks, growth stocks with high ROIC, and beaten-down cyclicals. According to Lombard Odier, the US economy is expected to experience a mild slowdown in 2024, leading to two interest rate cuts from the Federal Reserve. Despite slower but still positive nominal growth, corporate earnings growth is expected to remain positive into 2024, allowing room for US stocks to advance. The S&P 500's stock index has seen a rebound, supported by strong US consumer spending and cost cuts in the corporate sector. However, corporate profits in the US have already experienced a recession, recording three quarters of year-on-year declines. The article discusses the factors contributing to the apparent 'divergence' between corporate profits and the broader economy. The author expects the S&P 500 to finish 2024 around 4,800 points. The article also mentions the potential risks to the outlook for equities, including a classic economic recession in the US and the possibility of a more bullish environment with a faster recovery in US manufacturing. The article briefly touches on the relative performance of European and emerging markets. \n" +
"\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))
}
}
@@ -0,0 +1,225 @@
/**
* 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 androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.amethyst.commons.model.EmptyTagList
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
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)
Assert.assertEquals(3, state.paragraphs.size)
// First paragraph is text
Assert.assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[0].words.size)
// Second paragraph is image (rendered individually, not as gallery)
Assert.assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[1].words.size)
Assert.assertTrue(state.paragraphs[1].words[0] is ImageSegment)
Assert.assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[1].words[0].segmentText)
// Third paragraph is video (rendered individually)
Assert.assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[2].words.size)
Assert.assertTrue(state.paragraphs[2].words[0] is VideoSegment)
Assert.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)
Assert.assertEquals(6, state.paragraphs.size)
// First set: text, image, video
Assert.assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[0].words.size)
Assert.assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[1].words[0] is ImageSegment)
Assert.assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[1].words[0].segmentText)
Assert.assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[2].words[0] is VideoSegment)
Assert.assertEquals("https://archive.org/download/cinema-horror-sci-fi/Renfield.2023.ia.mp4", state.paragraphs[2].words[0].segmentText)
// Second set: text, image, video
Assert.assertTrue(state.paragraphs[3] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[3].words.size)
Assert.assertTrue(state.paragraphs[4] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[4].words[0] is ImageSegment)
Assert.assertEquals("https://image.tmdb.org/t/p/original/ekfIcBvqfqKbI6m227NFipBNh7O.jpg", state.paragraphs[4].words[0].segmentText)
Assert.assertTrue(state.paragraphs[5] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[5].words[0] is VideoSegment)
Assert.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)
Assert.assertEquals(2, state.paragraphs.size)
// Should render as gallery (1 gallery with 2 images)
Assert.assertTrue("Should render 1 gallery", state.paragraphs[1] is ImageGalleryParagraph)
Assert.assertEquals("Gallery should contain 2 images", 2, state.paragraphs[1].words.size)
Assert.assertEquals("https://example.com/image1.jpg", state.paragraphs[1].words[0].segmentText)
Assert.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)
Assert.assertEquals(2, state.paragraphs.size)
// Should render as gallery (1 gallery with 2 images)
Assert.assertTrue("Should render 1 gallery", state.paragraphs[1] is ImageGalleryParagraph)
Assert.assertEquals("Gallery should contain 2 images", 2, state.paragraphs[1].words.size)
Assert.assertEquals("https://example.com/image1.jpg", state.paragraphs[1].words[0].segmentText)
Assert.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)
Assert.assertTrue("Should render 1 individual image", state.paragraphs[1] !is ImageGalleryParagraph)
Assert.assertTrue("Should not render as gallery", state.paragraphs[0] !is ImageGalleryParagraph)
Assert.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)
Assert.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)
Assert.assertTrue("Should render as gallery", state.paragraphs[1] is ImageGalleryParagraph)
Assert.assertEquals("https://relay.dergigi.com/d6a3e33b101fe219ef251ac6261c10392c2af9918c3c252d4c202016b0b4ec83.jpg", state.paragraphs[1].words[0].segmentText)
Assert.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)
Assert.assertEquals(4, state.paragraphs.size)
// First paragraph is text
Assert.assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
// Second paragraph is image (rendered individually, not as gallery)
Assert.assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[1].words[0] is ImageSegment)
Assert.assertEquals("https://image.tmdb.org/t/p/original/1r7iOhXSbbuUTORNEUOvCUkQ86K.jpg", state.paragraphs[1].words[0].segmentText)
// Third paragraph is video (rendered individually)
Assert.assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
Assert.assertTrue(state.paragraphs[2].words[0] is VideoSegment)
Assert.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
Assert.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)
Assert.assertEquals(4, state.paragraphs.size)
// First paragraph is text
Assert.assertTrue(state.paragraphs[0] !is ImageGalleryParagraph)
Assert.assertEquals("Desperado (1995)", state.paragraphs[0].words[0].segmentText)
// Second paragraph is image (rendered individually, not as gallery)
Assert.assertTrue(state.paragraphs[1] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[1].words.size)
Assert.assertTrue(state.paragraphs[1].words[0] is ImageSegment)
Assert.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)
Assert.assertTrue(state.paragraphs[2] !is ImageGalleryParagraph)
Assert.assertEquals(1, state.paragraphs[2].words.size)
Assert.assertTrue(state.paragraphs[2].words[0] is VideoSegment)
Assert.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
Assert.assertTrue(state.paragraphs[3] !is ImageGalleryParagraph)
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B