Generalize url scheme parsing/highlighting (#1008)

* Add support for highlighting dat, ssb, ipfs url schemes. #847

* Generalize scheme parsing for url highlighting. #847

* Migrate LinkHelper to kotlin
This commit is contained in:
Levi Bard 2019-02-05 19:55:28 +01:00 committed by Konrad Pozniak
commit 85610a8311
10 changed files with 317 additions and 279 deletions

View file

@ -10,11 +10,11 @@ import org.junit.runners.Parameterized
class SpanUtilsTest {
@Test
fun matchesMixedSpans() {
val input = "one #one two @two three https://thr.ee/meh?foo=bar&wat=@at#hmm four #four five @five"
val input = "one #one two dat://tw.wo?no=yes three @three four https://fo.ur/meh?foo=bar&wat=@at#hmm five #five ipfs://si.xx/?pick=up#sticks seven @seven "
val inputSpannable = FakeSpannable(input)
highlightSpans(inputSpannable, 0xffffff)
val spans = inputSpannable.spans
Assert.assertEquals(5, spans.size)
Assert.assertEquals(7, spans.size)
}
@Test
@ -38,6 +38,9 @@ class SpanUtilsTest {
return listOf(
"@mention",
"#tag",
"dat://thr.ee/meh?foo=bar&wat=@at#hmm",
"ssb://thr.ee/meh?foo=bar&wat=@at#hmm",
"ipfs://thr.ee/meh?foo=bar&wat=@at#hmm",
"https://thr.ee/meh?foo=bar&wat=@at#hmm",
"http://thr.ee/meh?foo=bar&wat=@at#hmm"
)
@ -64,7 +67,7 @@ class SpanUtilsTest {
@Test
fun doesNotMatchSpanEmbeddedInText() {
val inputSpannable = FakeSpannable("aa${thingToHighlight}aa")
val inputSpannable = FakeSpannable("__${thingToHighlight}__")
highlightSpans(inputSpannable, 0xffffff)
val spans = inputSpannable.spans
Assert.assertTrue(spans.isEmpty())
@ -76,6 +79,7 @@ class SpanUtilsTest {
highlightSpans(inputSpannable, 0xffffff)
val spans = inputSpannable.spans
Assert.assertEquals(1, spans.size)
Assert.assertEquals(0, spans[0].start)
}
@Test