|
1 | 1 | package net.primal.android.core.utils
|
2 | 2 |
|
| 3 | +import io.kotest.matchers.collections.shouldContainExactly |
3 | 4 | import io.kotest.matchers.ints.shouldBeExactly
|
4 | 5 | import io.kotest.matchers.nulls.shouldNotBeNull
|
5 | 6 | import io.kotest.matchers.shouldBe
|
@@ -37,6 +38,63 @@ class UriUtilsTest {
|
37 | 38 | expectedUrls.size shouldBeExactly 1
|
38 | 39 | }
|
39 | 40 |
|
| 41 | + @Test |
| 42 | + fun `parseUrls should recognize various url formats`() { |
| 43 | + val content = """ |
| 44 | + Some random links about bitcoin: |
| 45 | + https://en.m.wikipedia.org/wiki/Bit_(money) |
| 46 | + Check out primal.net for more info! |
| 47 | + Visit us at www.primal.net or at https://primal.net |
| 48 | + Here's a link to a secure site: https://www.example.com/path/to/resource |
| 49 | + And a simple link: example.com |
| 50 | + Don't forget the test with brackets: https://example.com/page?(query)=1&sort=desc |
| 51 | + """.trimIndent() |
| 52 | + |
| 53 | + val expectedUrls = content.parseUris() |
| 54 | + |
| 55 | + expectedUrls shouldBe listOf( |
| 56 | + "primal.net", |
| 57 | + "www.primal.net", |
| 58 | + "https://primal.net", |
| 59 | + "https://www.example.com/path/to/resource", |
| 60 | + "example.com", |
| 61 | + "https://en.m.wikipedia.org/wiki/Bit_(money)", |
| 62 | + "https://example.com/page?(query)=1&sort=desc", |
| 63 | + ) |
| 64 | + expectedUrls.size shouldBeExactly 7 |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + fun `parseUrls should recognize urls with port numbers`() { |
| 69 | + val content = """ |
| 70 | + A link with a port number: |
| 71 | + https://www.example.com:443/resource |
| 72 | + """.trimIndent() |
| 73 | + |
| 74 | + val expectedUrls = content.parseUris() |
| 75 | + |
| 76 | + expectedUrls.shouldNotBeNull() |
| 77 | + expectedUrls shouldContainExactly listOf( |
| 78 | + "https://www.example.com:443/resource" |
| 79 | + ) |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + fun `parseUrls should return empty for invalid urls`() { |
| 84 | + val content = """ |
| 85 | + Some random links: |
| 86 | + thisisnotalink |
| 87 | + http:// |
| 88 | + www. |
| 89 | + example@com |
| 90 | + """.trimIndent() |
| 91 | + |
| 92 | + val expectedUrls = content.parseUris() |
| 93 | + |
| 94 | + expectedUrls.shouldNotBeNull() |
| 95 | + expectedUrls.size shouldBe 0 |
| 96 | + } |
| 97 | + |
40 | 98 | @Test
|
41 | 99 | fun `parseUrls should not return urls with brackets`() {
|
42 | 100 | val hugeContent = javaClass.getResource("/core/release_notes.txt")?.readText()
|
|
0 commit comments