forked from termux/termux-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTermuxActivityTest.java
More file actions
63 lines (45 loc) · 2.18 KB
/
TermuxActivityTest.java
File metadata and controls
63 lines (45 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.termux.app;
import com.termux.shared.termux.data.TermuxUrlUtils;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
import java.util.LinkedHashSet;
public class TermuxActivityTest {
private void assertUrlsAre(String text, String... urls) {
LinkedHashSet<String> expected = new LinkedHashSet<>();
Collections.addAll(expected, urls);
Assert.assertEquals(expected, TermuxUrlUtils.extractUrls(text));
}
@Test
public void testExtractUrls() {
// Basic single URL
assertUrlsAre("hello http://example.com world", "http://example.com");
// Multiple URLs separated by newlines
assertUrlsAre("http://example.com\nhttp://another.com",
"http://example.com", "http://another.com");
// Multiple mixed protocols
assertUrlsAre("hello http://example.com and https://secure.com",
"http://example.com", "https://secure.com");
// URLs with fragments
assertUrlsAre("https://example.com/#bar https://example.com/foo#bar",
"https://example.com/#bar", "https://example.com/foo#bar");
// FTP and mailto links
assertUrlsAre("Check ftp://server.com/file.txt and mailto:user@example.com",
"ftp://server.com/file.txt", "mailto:user@example.com");
// Encoded characters in URL
assertUrlsAre("Search: https://example.com/search?q=test%20query",
"https://example.com/search?q=test%20query");
// URL starting with www (if supported)
assertUrlsAre("Visit www.example.com for info", "www.example.com");
// URL inside parentheses
assertUrlsAre("Click (http://example.com)", "http://example.com");
// URL inside quotes
assertUrlsAre("\"https://secure.example.com\"", "https://secure.example.com");
// Plain text without links
assertUrlsAre("This is a plain text with no links at all");
// Duplicate URLs
assertUrlsAre("http://example.com and again http://example.com", "http://example.com");
// Internationalized domain name
assertUrlsAre("Check this: https://مثال.إختبار", "https://مثال.إختبار");
}
}