Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arabickit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {

defaultConfig {
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

Expand All @@ -37,4 +38,7 @@ android {

dependencies {
testImplementation("junit:junit:4.13.2")

androidTestImplementation("androidx.test:runner:1.7.0")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.khalid567cpu.arabickit

import android.graphics.Color
import android.text.style.BackgroundColorSpan
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
public class ArabicHighlighterInstrumentedTest {
@Test
public fun highlightBackground_mapsNormalizedMatchesToOriginalArabicText() {
val source = "إِنَّ الــلَّهَ غَفُورٌ، إن الله رحيم ٢٠٢٦"

val highlighted = ArabicHighlighter.highlightBackground(
text = source,
query = "ان الله",
color = Color.YELLOW,
)

val spans = highlighted
.getSpans(0, highlighted.length, BackgroundColorSpan::class.java)
.sortedBy(highlighted::getSpanStart)

assertEquals(2, spans.size)
assertTrue(spans.all { it.backgroundColor == Color.YELLOW })

val highlightedSubstrings = spans.map { span ->
source.substring(
highlighted.getSpanStart(span),
highlighted.getSpanEnd(span),
)
}

assertEquals(
listOf(
"إِنَّ الــلَّهَ",
"إن الله",
),
highlightedSubstrings,
)
}
}
Loading