use crate::link::auto_link_url_matcher as url_matcher;
enum Expect {
Text(&'static str),
Url(&'static str),
None,
}
const CASES: [(&str, Expect); 29] = [
("https://google.com", Expect::Text("https://google.com")),
("www.example.com", Expect::Text("www.example.com")),
(
"https://example.com/path?q=1#hash",
Expect::Text("https://example.com/path?q=1#hash"),
),
(
"https://example.com:8080/api",
Expect::Text("https://example.com:8080/api"),
),
(
"https://qabilah.com/posts/عربي",
Expect::Text("https://qabilah.com/posts/عربي"),
),
("https://예시.한국", Expect::Text("https://예시.한국")),
("https://пример.рф", Expect::Text("https://пример.рф")),
(
"https://例子.中国/测试",
Expect::Text("https://例子.中国/测试"),
),
(
"http://예시.한국/경로?키=값#부분",
Expect::Text("http://예시.한국/경로?키=값#부분"),
),
(
"http://مثال.موقع/مسار?مفتاح=قيمة#قسم",
Expect::Text("http://مثال.موقع/مسار?مفتاح=قيمة#قسم"),
),
(
"hello https://google.com world",
Expect::Text("https://google.com"),
),
(
"مرحبا https://qabilah.com/posts/عربي end",
Expect::Text("https://qabilah.com/posts/عربي"),
),
(
"텍스트 https://예시.한국 끝",
Expect::Text("https://예시.한국"),
),
("go www.예시.한국 end", Expect::Text("www.예시.한국")),
(
"see https://google.com, ok",
Expect::Text("https://google.com"),
),
(
"see https://google.com. ok",
Expect::Text("https://google.com"),
),
(
"see https://예시.한국, ok",
Expect::Text("https://예시.한국"),
),
(
"see https://예시.한국. ok",
Expect::Text("https://예시.한국"),
),
("(https://google.com)", Expect::Text("https://google.com")),
("(https://예시.한국)", Expect::Text("https://예시.한국")),
(
"https://en.wikipedia.org/wiki/Fish_(disambiguation)",
Expect::Text("https://en.wikipedia.org/wiki/Fish_(disambiguation)"),
),
(
"https://example.com/a_(b_(c))",
Expect::Text("https://example.com/a_(b_(c))"),
),
("www.example.com", Expect::Url("https://www.example.com")),
("www.예시.한국", Expect::Url("https://www.예시.한국")),
("https://google.com", Expect::Url("https://google.com")),
("http://пример.рф", Expect::Url("http://пример.рф")),
("just text no url", Expect::None),
("http:// alone", Expect::None),
("", Expect::None),
];
#[test]
fn auto_link_url_matcher() {
for (input, expected) in CASES {
let result = url_matcher(input);
match expected {
Expect::Text(text) => assert_eq!(result.expect(input).text, text),
Expect::Url(url) => assert_eq!(result.expect(input).url, url),
Expect::None => assert!(result.is_none(), "{input}"),
}
}
}