mirror of https://github.com/gnosygnu/xowa
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
5.4 KiB
87 lines
5.4 KiB
/*
|
|
XOWA: the XOWA Offline Wiki Application
|
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
|
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
or alternatively under the terms of the Apache License Version 2.0.
|
|
|
|
You may use XOWA according to either of these licenses as is most appropriate
|
|
for your project on a case-by-case basis.
|
|
|
|
The terms of each license can be found in the source code repository:
|
|
|
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
*/
|
|
package gplx.xowa.mediawiki.includes.parsers.magiclinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
|
import org.junit.*;
|
|
public class Xomw_magiclinks_wkr__tst {
|
|
private final Xomw_magiclinks_wkr__fxt fxt = new Xomw_magiclinks_wkr__fxt();
|
|
@Test public void Basic() {fxt.Test__parse("a https://b.org z", "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a> z");}
|
|
@Test public void Invalid() {fxt.Test__parse("a _https://b.org z", "a _https://b.org z");}
|
|
@Test public void Tag__anch() {fxt.Test__parse("a <a title=\"https://b.org\">b</a> z", "a <a title=\"https://b.org\">b</a> z");}
|
|
@Test public void Tag__misc() {fxt.Test__parse("a <div title=\"https://b.org\">b</div> z", "a <div title=\"https://b.org\">b</div> z");}
|
|
@Test public void Interrupt() {
|
|
// ent
|
|
fxt.Test__parse("a https://b.org<z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a><z");
|
|
// hex
|
|
fxt.Test__parse("a https://b.org<z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a><z");
|
|
// dec
|
|
fxt.Test__parse("a https://b.org<z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a><z");
|
|
// num_post_proto rule
|
|
fxt.Test__parse("a https://< z" , "a https://< z");
|
|
}
|
|
@Test public void Interrupt__hex_dec() {// implementation specific test for mixed hex / dec
|
|
// dec-hex
|
|
fxt.Test__parse("a https://b.orgc;z" , "a <a rel='nofollow' class='external free' href='https://b.org&#3c;z'>https://b.org&#3c;z</a>");
|
|
}
|
|
@Test public void Separator() {
|
|
// basic; ,;.:!?
|
|
fxt.Test__parse("a https://b.org,;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a>,;.:!? z");
|
|
// ")" excluded
|
|
fxt.Test__parse("a https://b.org).:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a>).:!? z");
|
|
// ")" included b/c "(" exists
|
|
fxt.Test__parse("a https://b.org().:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org()'>https://b.org()</a>.:!? z");
|
|
// ";" excluded
|
|
fxt.Test__parse("a https://b.org;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org'>https://b.org</a>;.:!? z");
|
|
// ";" included b/c of ent
|
|
fxt.Test__parse("a https://b.org&abc;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org&abc;'>https://b.org&abc;</a>.:!? z");
|
|
// ";" included b/c of hex; note that Clean_url changes "±" to "±"
|
|
fxt.Test__parse("a https://b.org±.:!? z", "a <a rel='nofollow' class='external free' href='https://b.org±'>https://b.org±</a>.:!? z");
|
|
// ";" included b/c of dec; note that Clean_url changes "{" to "{"
|
|
fxt.Test__parse("a https://b.org{.:!? z", "a <a rel='nofollow' class='external free' href='https://b.org{'>https://b.org{</a>.:!? z");
|
|
// ";" excluded b/c of invalid.ent
|
|
fxt.Test__parse("a https://b.org&a1b;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org&a1b'>https://b.org&a1b</a>;.:!? z");
|
|
// ";" excluded b/c of invalid.hex
|
|
fxt.Test__parse("a https://b.org&#x;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org&#x'>https://b.org&#x</a>;.:!? z");
|
|
// ";" excluded b/c of invalid.dec
|
|
fxt.Test__parse("a https://b.org&#a;.:!? z" , "a <a rel='nofollow' class='external free' href='https://b.org&#a'>https://b.org&#a</a>;.:!? z");
|
|
// num_post_proto rule
|
|
fxt.Test__parse("a https://.:!? z" , "a https://.:!? z");
|
|
}
|
|
@Test public void Clean_url() {
|
|
// basic
|
|
fxt.Test__parse("http://a᠆b.org/c᠆d" , "<a rel='nofollow' class='external free' href='http://ab.org/c᠆d'>http://ab.org/c᠆d</a>");
|
|
}
|
|
}
|
|
class Xomw_magiclinks_wkr__fxt {
|
|
private final Xomw_magiclinks_wkr wkr;
|
|
private final XomwParserCtx pctx = new XomwParserCtx();
|
|
private final XomwParserBfr pbfr = new XomwParserBfr();
|
|
public Xomw_magiclinks_wkr__fxt() {
|
|
Xomw_regex_space regex_space = new Xomw_regex_space();
|
|
XomwParser parser = new XomwParser(XomwEnv_fxt.NewTest());
|
|
pctx.Init_by_page(XomwTitleOld.newFromText(parser.Env(), Bry_.new_a7("Page_1")));
|
|
this.wkr = new Xomw_magiclinks_wkr(parser, parser.Sanitizer(), parser.Linker(), new Xomw_regex_boundary(regex_space), new Xomw_regex_url(regex_space));
|
|
wkr.Init_by_wiki();
|
|
}
|
|
public void Test__parse(String src_str, String expd) {Test__parse(Bool_.Y, src_str, expd);}
|
|
public void Test__parse(boolean apos, String src_str, String expd) {
|
|
byte[] src_bry = Bry_.new_u8(src_str);
|
|
pbfr.Init(src_bry);
|
|
wkr.doMagicLinks(pctx, pbfr);
|
|
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
|
Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
|
}
|
|
}
|