Url-regexp: Remove redundant escapes and add test

This commit is contained in:
Fredrik Fornwall
2015-11-29 01:08:18 +01:00
parent 1b36c684d6
commit d982c71efe
2 changed files with 31 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
package com.termux.app;
import junit.framework.TestCase;
import java.util.LinkedHashSet;
public class TermuxActivityTest extends TestCase {
private void assertUrlsAre(String text, String... urls) {
LinkedHashSet<String> expected = new LinkedHashSet<>();
for (String url : urls) expected.add(url);
assertEquals(expected, TermuxActivity.extractUrls(text));
}
public void testExtractUrls() {
assertUrlsAre("hello http://example.com world", "http://example.com");
assertUrlsAre("http://example.com\nhttp://another.com", "http://example.com", "http://another.com");
assertUrlsAre("hello http://example.com world and http://more.example.com with secure https://more.example.com",
"http://example.com", "http://more.example.com", "https://more.example.com");
}
}