package com.suno.android.extensions import android.util.Log import androidx.compose.ui.graphics.Color import io.mockk.every import io.mockk.mockkStatic import io.mockk.unmockkAll import org.junit.After import org.junit.Assert import org.junit.Before import org.junit.Test class StringExtensionsTest { @Before fun setUp() { mockkStatic(Log::class) every { Log.e(any(), any()) } returns 0 every { Log.e(any(), any(), any()) } returns 0 } @After fun tearDown() { unmockkAll() } @Test fun `given 6-digit hex without hash when xAsColor then returns correct color`() { val result = "FF5733".xAsColor() Assert.assertEquals(Color(0xFFFF5733), result) } @Test fun `given 6-digit hex with hash when xAsColor then returns correct color`() { val result = "#FF5733".xAsColor() Assert.assertEquals(Color(0xFFFF5733), result) } @Test fun `given 6-digit lowercase hex when xAsColor then returns correct color`() { val result = "ff5733".xAsColor() Assert.assertEquals(Color(0xFFFF5733), result) } @Test fun `given 6-digit hex with whitespace when xAsColor then returns correct color`() { val result = " FF5733 ".xAsColor() Assert.assertEquals(Color(0xFFFF5733), result) } @Test fun `given 8-digit hex with alpha without hash when xAsColor then repositions alpha correctly`() { // Backend format: RRGGBBAA (RGB + Alpha at end) // Expected Android format: #AARRGGBB (Alpha at start) val result = "FF5733AA".xAsColor() Assert.assertEquals(Color(0xAAFF5733), result) } @Test fun `given 8-digit hex with alpha with hash when xAsColor then repositions alpha correctly`() { val result = "#FF5733AA".xAsColor() Assert.assertEquals(Color(0xAAFF5733), result) } @Test fun `given 8-digit lowercase hex with alpha when xAsColor then returns correct color`() { val result = "ff573380".xAsColor() Assert.assertEquals(Color(0x80FF5733), result) } @Test fun `given fully opaque 8-digit hex when xAsColor then returns correct color`() { val result = "FF5733FF".xAsColor() Assert.assertEquals(Color(0xFFFF5733), result) } @Test fun `given fully transparent 8-digit hex when xAsColor then returns correct color`() { val result = "FF573300".xAsColor() Assert.assertEquals(Color(0x00FF5733), result) } @Test fun `given 3-digit hex shorthand without hash when xAsColor then expands correctly`() { val result = "F73".xAsColor() // F73 should expand to FF7733 Assert.assertEquals(Color(0xFFFF7733), result) } @Test fun `given 3-digit hex shorthand with hash when xAsColor then expands correctly`() { val result = "#ABC".xAsColor() // ABC should expand to AABBCC Assert.assertEquals(Color(0xFFAABBCC), result) } @Test fun `given 3-digit hex FFF when xAsColor then returns white`() { val result = "FFF".xAsColor() Assert.assertEquals(Color.Companion.White, result) } @Test fun `given 3-digit hex 000 when xAsColor then returns black`() { val result = "000".xAsColor() Assert.assertEquals(Color.Companion.Black, result) } @Test fun `given transparent keyword lowercase when xAsColor then returns transparent color`() { val result = "transparent".xAsColor() Assert.assertEquals(Color.Companion.Transparent, result) } @Test fun `given transparent keyword uppercase when xAsColor then returns transparent color`() { val result = "TRANSPARENT".xAsColor() Assert.assertNull(result) } @Test fun `given transparent keyword mixed case when xAsColor then returns transparent color`() { val result = "TrAnSpArEnT".xAsColor() Assert.assertNull(result) } @Test fun `given empty string when xAsColor then returns null`() { val result = "".xAsColor() Assert.assertNull(result) } @Test fun `given whitespace only when xAsColor then returns null`() { val result = " ".xAsColor() Assert.assertNull(result) } @Test fun `given invalid hex characters when xAsColor then returns null`() { val result = "GGHHII".xAsColor() Assert.assertNull(result) } @Test fun `given 4-digit hex when xAsColor then returns null`() { val result = "FFAA".xAsColor() Assert.assertNull(result) } @Test fun `given 5-digit hex when xAsColor then returns null`() { val result = "FFAAB".xAsColor() Assert.assertNull(result) } @Test fun `given 7-digit hex when xAsColor then returns null`() { val result = "FFAABBC".xAsColor() Assert.assertNull(result) } @Test fun `given 9-digit hex when xAsColor then returns null`() { val result = "FFAABBCCD".xAsColor() Assert.assertNull(result) } @Test fun `given invalid keyword when xAsColor then returns null`() { val result = "blue".xAsColor() Assert.assertNull(result) } @Test fun `given special characters when xAsColor then returns null`() { val result = "@#$%^&".xAsColor() Assert.assertNull(result) } @Test fun `given black color 000000 when xAsColor then returns black`() { val result = "000000".xAsColor() Assert.assertEquals(Color.Companion.Black, result) } @Test fun `given white color FFFFFF when xAsColor then returns white`() { val result = "FFFFFF".xAsColor() Assert.assertEquals(Color.Companion.White, result) } @Test fun `given red color FF0000 when xAsColor then returns red`() { val result = "FF0000".xAsColor() Assert.assertEquals(Color.Companion.Red, result) } @Test fun `given green color 00FF00 when xAsColor then returns green`() { val result = "00FF00".xAsColor() Assert.assertEquals(Color.Companion.Green, result) } @Test fun `given blue color 0000FF when xAsColor then returns blue`() { val result = "0000FF".xAsColor() Assert.assertEquals(Color.Companion.Blue, result) } }