mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_html_utl__expand_attributes__tst {
|
||||
private final Xomw_html_utl__expand_attributes__fxt fxt = new Xomw_html_utl__expand_attributes__fxt();
|
||||
@Test public void Basic() {fxt.Test__expand_attributes(" a=\"b\"", "a", "b");}
|
||||
}
|
||||
class Xomw_html_utl__expand_attributes__fxt {
|
||||
private final XomwHtml utl = new XomwHtml();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Test__expand_attributes(String expd, String... kvs) {
|
||||
Xomw_atr_mgr atrs = new Xomw_atr_mgr();
|
||||
int kvs_len = kvs.length;
|
||||
for (int i = 0; i < kvs_len; i += 2) {
|
||||
byte[] key = Bry_.new_a7(kvs[i]);
|
||||
byte[] val = Bry_.new_a7(kvs[i + 1]);
|
||||
Xomw_atr_itm itm = new Xomw_atr_itm(-1, key, val);
|
||||
atrs.Add(itm);
|
||||
}
|
||||
utl.Expand_attributes(bfr, atrs);
|
||||
Gftest.Eq__str(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_string_utils__tst {
|
||||
private final Xomw_string_utils__fxt fxt = new Xomw_string_utils__fxt();
|
||||
@Test public void Delimiter_explode() {
|
||||
// basic
|
||||
fxt.Test__delimiter_explode("a|b|c" , "a", "b", "c");
|
||||
// empty
|
||||
fxt.Test__delimiter_explode("|a||c|" , "", "a", "", "c", "");
|
||||
// nest_1
|
||||
fxt.Test__delimiter_explode("a|-{b|c}-|d" , "a", "-{b|c}-", "d");
|
||||
// nest_many
|
||||
fxt.Test__delimiter_explode("a|-{b-{c|d}-e}-|f" , "a", "-{b-{c|d}-e}-", "f");
|
||||
}
|
||||
@Test public void Replace_markup() {
|
||||
// basic
|
||||
fxt.Test__replace_markup("a!!b" , "!!", "||", "a||b");
|
||||
// missing
|
||||
fxt.Test__replace_markup("abcd" , "!!", "||", "abcd");
|
||||
// eos
|
||||
fxt.Test__replace_markup("a!!" , "!!", "||", "a||");
|
||||
// ignore
|
||||
fxt.Test__replace_markup("a!!b<!!>!!c" , "!!", "||", "a||b<!!>||c");
|
||||
// ignore asym_lhs
|
||||
fxt.Test__replace_markup("a!!b<!!<!!>!!c" , "!!", "||", "a||b<!!<!!>||c");
|
||||
// ignore asym_lhs
|
||||
fxt.Test__replace_markup("a!!b<!!>!!>!!c" , "!!", "||", "a||b<!!>||>||c"); // NOTE: should probably be "!!>!!>", but unmatched ">" are escaped to ">"
|
||||
}
|
||||
}
|
||||
class Xomw_string_utils__fxt {
|
||||
public void Test__delimiter_explode(String src_str, String... expd) {
|
||||
List_adp tmp = List_adp_.New();
|
||||
gplx.core.btries.Btrie_rv trv = new gplx.core.btries.Btrie_rv();
|
||||
|
||||
byte[][] actl = Xomw_string_utils.Delimiter_explode(tmp, trv, Bry_.new_u8(src_str));
|
||||
Gftest.Eq__ary(expd, actl, "src=~{0}", src_str);
|
||||
}
|
||||
public void Test__replace_markup(String src_str, String find, String repl, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Xomw_string_utils.Replace_markup(src_bry, 0, src_bry.length, Bry_.new_a7(find), Bry_.new_a7(repl));
|
||||
Gftest.Eq__str(expd, src_bry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.linkers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// import org.junit.*;
|
||||
// public class Xomw_link_renderer__tst {
|
||||
// private final Xomw_link_renderer__fxt fxt = new Xomw_link_renderer__fxt();
|
||||
/*
|
||||
Make_broken_link
|
||||
target.Has_fragment()
|
||||
*/
|
||||
// }
|
||||
// class Xomw_link_renderer__fxt {
|
||||
// private final Xomw_link_renderer wkr = new Xomw_link_renderer(new Xomw_parser());
|
||||
// public void Test__parse(String src_str, String expd) {
|
||||
// byte[] src_bry = Bry_.new_u8(src_str);
|
||||
// wkr.Replace_external_links(new Xomw_parser_ctx(), pbfr.Init(src_bry));
|
||||
// if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
// Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.mediawiki.includes.linkers.*;
|
||||
public class Xomw_block_level_pass__tst {
|
||||
private final Xomw_block_level_pass__fxt fxt = new Xomw_block_level_pass__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__do_block_levels(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xomw_block_level_pass__fxt {
|
||||
private final Xomw_block_level_pass block_level_pass = new Xomw_block_level_pass();
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private boolean apos = true;
|
||||
public void Test__do_block_levels(String src, String expd) {
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
block_level_pass.Do_block_levels(pctx, pbfr.Init(Bry_.new_u8(src)), true);
|
||||
Gftest.Eq__str(expd, pbfr.Rslt().To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*;
|
||||
public class Xomw_parser__tst {
|
||||
private final Xomw_parser__fxt fxt = new Xomw_parser__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "== heading_1 =="
|
||||
, "para_1"
|
||||
, "== heading_2 =="
|
||||
, "para_2"
|
||||
, "-----"
|
||||
, "{|"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|}"
|
||||
, "''italics''"
|
||||
, "__TOC__"
|
||||
, "[https://a.org b]"
|
||||
, "[[A|abc]]"
|
||||
, "https://c.org"
|
||||
, "a »b«  !important c"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2> heading_1 </h2>"
|
||||
, "<p>para_1"
|
||||
, "</p>"
|
||||
, "<h2> heading_2 </h2>"
|
||||
, "<p>para_2"
|
||||
, "</p>"
|
||||
, "<hr />"
|
||||
, "<table>"
|
||||
, ""
|
||||
, "<tr>"
|
||||
, "<td>a"
|
||||
, "</td></tr></table>"
|
||||
, "<p><i>italics</i>"
|
||||
, "<!--MWTOC-->"
|
||||
, "<a rel=\"nofollow\" class=\"external text\" href=\"https://a.org\">b</a>"
|
||||
, "<a href=\"/wiki/A\" title=\"A\">abc</a>"
|
||||
, "<a rel=\"nofollow\" class=\"external free\" href=\"https://c.org\">https://c.org</a>"
|
||||
, "a »b«  !important c"
|
||||
, "</p>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xomw_parser__fxt {
|
||||
private final Xomw_parser mgr = new Xomw_parser();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
public Xomw_parser__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
mgr.Init_by_wiki(wiki);
|
||||
mgr.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1")));
|
||||
}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
mgr.Internal_parse(pbfr, src_bry);
|
||||
mgr.Internal_parse_half_parsed(pbfr, true, true);
|
||||
Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_regex_parser__tst {
|
||||
private final Xomw_regex_parser__fxt fxt = new Xomw_regex_parser__fxt();
|
||||
@Test public void Ary__space() {
|
||||
fxt.Test__parse_ary(String_.Ary("\\s"), String_.Ary(" "));
|
||||
}
|
||||
@Test public void Ary__utf8() {
|
||||
fxt.Test__parse_ary(String_.Ary("\\xc2\\xa7", "\\xe0\\xb9\\x90"), String_.Ary("§", "๐"));
|
||||
}
|
||||
@Test public void Rng__ascii() {
|
||||
fxt.Test__parse_rng("a", "c", String_.Ary("a", "b", "c"));
|
||||
}
|
||||
}
|
||||
class Xomw_regex_parser__fxt {
|
||||
private final Xomw_regex_parser parser = new Xomw_regex_parser();
|
||||
public void Test__parse_ary(String[] ary, String[] expd) {
|
||||
parser.Add_ary(ary);
|
||||
Gftest.Eq__ary(expd, String_.Ary(parser.Rslt()));
|
||||
}
|
||||
public void Test__parse_rng(String bgn, String end, String[] expd) {
|
||||
parser.Add_rng("a", "c");
|
||||
Gftest.Eq__ary(expd, String_.Ary(parser.Rslt()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_strip_state__tst {
|
||||
private final Xomw_strip_state__fxt fxt = new Xomw_strip_state__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__add (Xomw_strip_state.Tid__general, "\u007f'\"`UNIQ-key-1-QINU`\"'\u007f", "val-1");
|
||||
fxt.Test__nostrip(Xomw_strip_state.Tid__nowiki , "a \u007f'\"`UNIQ-key-1-QINU`\"'\u007f b");
|
||||
fxt.Test__unstrip(Xomw_strip_state.Tid__general, "a \u007f'\"`UNIQ-key-1-QINU`\"'\u007f b", "a val-1 b");
|
||||
fxt.Test__unstrip(Xomw_strip_state.Tid__both , "a \u007f'\"`UNIQ-key-1-QINU`\"'\u007f b", "a val-1 b");
|
||||
}
|
||||
@Test public void Recurse() {
|
||||
fxt.Init__add (Xomw_strip_state.Tid__general, "\u007f'\"`UNIQ-key-1-QINU`\"'\u007f", "val-1");
|
||||
fxt.Init__add (Xomw_strip_state.Tid__general, "\u007f'\"`UNIQ-key-2-QINU`\"'\u007f", "\u007f'\"`UNIQ-key-1-QINU`\"'\u007f");
|
||||
fxt.Test__unstrip(Xomw_strip_state.Tid__general, "a \u007f'\"`UNIQ-key-2-QINU`\"'\u007f b", "a val-1 b");
|
||||
}
|
||||
}
|
||||
class Xomw_strip_state__fxt {
|
||||
private final Xomw_strip_state strip_state = new Xomw_strip_state();
|
||||
public void Init__add(byte tid, String marker, String val) {
|
||||
strip_state.Add_item(tid, Bry_.new_u8(marker), Bry_.new_u8(val));
|
||||
}
|
||||
public void Test__nostrip(byte tid, String src) {Test__unstrip(tid, src, src);}
|
||||
public void Test__unstrip(byte tid, String src, String expd) {
|
||||
byte[] actl = strip_state.Unstrip(tid, Bry_.new_u8(src));
|
||||
Gftest.Eq__str(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.doubleunders; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_doubleunder_wkr__tst {
|
||||
private final Xomw_doubleunder_wkr__fxt fxt = new Xomw_doubleunder_wkr__fxt();
|
||||
@Test public void No_match() {fxt.Test__parse("a b c" , "a b c");}
|
||||
@Test public void Force_toc() {fxt.Test__parse("a __FORCETOC__ b" , "a b").Test__prop_y(fxt.data.force_toc);}
|
||||
@Test public void Toc() {fxt.Test__parse("a __TOC__ b __TOC__ c" , "a <!--MWTOC--> b c").Test__prop_y(fxt.data.toc, fxt.data.show_toc, fxt.data.force_toc_position);}
|
||||
@Test public void Notoc_only() {fxt.Test__parse("a __NOTOC__ b" , "a b").Test__prop_y(fxt.data.no_toc).Test__prop_n(fxt.data.show_toc);} // show_toc is false
|
||||
@Test public void Notoc_w_toc() {fxt.Test__parse("a __TOC__ b __NOTOC__ c" , "a <!--MWTOC--> b c").Test__prop_y(fxt.data.toc, fxt.data.show_toc, fxt.data.force_toc_position);} // show_toc is true
|
||||
@Test public void Case_match() {fxt.Test__parse("a __index__ b" , "a __index__ b");}
|
||||
}
|
||||
class Xomw_doubleunder_wkr__fxt {
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private final Xomw_doubleunder_wkr wkr = new Xomw_doubleunder_wkr();
|
||||
public Xomw_doubleunder_data data = new Xomw_doubleunder_data();
|
||||
public Xomw_doubleunder_wkr__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
wkr.Init_by_wiki(data, wiki.Lang());
|
||||
}
|
||||
public Xomw_doubleunder_wkr__fxt Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Do_double_underscore(pctx, pbfr.Init(src_bry));
|
||||
Gftest.Eq__str(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
return this;
|
||||
}
|
||||
public Xomw_doubleunder_wkr__fxt Test__prop_y(boolean... ary) {return Test__prop(Bool_.Y, ary);}
|
||||
public Xomw_doubleunder_wkr__fxt Test__prop_n(boolean... ary) {return Test__prop(Bool_.N, ary);}
|
||||
private Xomw_doubleunder_wkr__fxt Test__prop(boolean expd, boolean... ary) {
|
||||
for (boolean v : ary)
|
||||
Gftest.Eq__bool(expd, v);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.headings; 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_heading_wkr__tst {
|
||||
private final Xomw_heading_wkr__fxt fxt = new Xomw_heading_wkr__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse("==A==" , "<h2>A</h2>");
|
||||
fxt.Test__parse("abc\n==A==\ndef" , "abc\n<h2>A</h2>\ndef");
|
||||
|
||||
fxt.Test__parse("abc" , "abc");
|
||||
fxt.Test__parse("abc\ndef" , "abc\ndef");
|
||||
fxt.Test__parse("abc\n==" , "abc\n<h1></h1>");
|
||||
}
|
||||
}
|
||||
class Xomw_heading_wkr__fxt {
|
||||
private final Xomw_heading_wkr wkr = new Xomw_heading_wkr();
|
||||
private final Xomw_heading_cbk__html cbk = new Xomw_heading_cbk__html().Bfr_(Bry_bfr_.New());
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Parse(pctx, src_bry, -1, src_bry.length, cbk);
|
||||
Tfds.Eq_str_lines(expd, cbk.Bfr().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.hrs; 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_hr_wkr__tst {
|
||||
private final Xomw_hr_wkr__fxt fxt = new Xomw_hr_wkr__fxt();
|
||||
@Test public void Basic() {fxt.Test__parse("a\n-----b" , "a\n<hr />b");}
|
||||
@Test public void Extend() {fxt.Test__parse("a\n------b" , "a\n<hr />b");}
|
||||
@Test public void Not_found() {fxt.Test__parse("a\n----b" , "a\n----b");}
|
||||
@Test public void Bos() {fxt.Test__parse("-----a" , "<hr />a");}
|
||||
@Test public void Bos_and_mid() {fxt.Test__parse("-----a\n-----b" , "<hr />a\n<hr />b");}
|
||||
}
|
||||
class Xomw_hr_wkr__fxt {
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private final Xomw_hr_wkr wkr = new Xomw_hr_wkr();
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Replace_hrs(new Xomw_parser_ctx(), pbfr.Init(src_bry));
|
||||
Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.lnkes; 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_lnke_wkr__tst {
|
||||
private final Xomw_lnke_wkr__fxt fxt = new Xomw_lnke_wkr__fxt();
|
||||
@Test public void Basic() {fxt.Test__parse("[https://a.org b]" , "<a rel='nofollow' class='external text' href='https://a.org'>b</a>");}
|
||||
@Test public void Invaild__protocol() {fxt.Test__parse("[httpz:a.org]" , "[httpz:a.org]");}
|
||||
@Test public void Invaild__protocol_slash() {fxt.Test__parse("[https:a.org]" , "[https:a.org]");}
|
||||
@Test public void Invaild__urlchars__0() {fxt.Test__parse("[https://]" , "[https://]");}
|
||||
@Test public void Invaild__urlchars__bad() {fxt.Test__parse("[https://\"]" , "[https://\"]");}
|
||||
@Test public void Many() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_apos_skip_last
|
||||
( "a"
|
||||
, "[https://b.org c]"
|
||||
, "d"
|
||||
, "[https://e.org f]"
|
||||
, "g"
|
||||
), String_.Concat_lines_nl_apos_skip_last
|
||||
( "a"
|
||||
, "<a rel='nofollow' class='external text' href='https://b.org'>c</a>"
|
||||
, "d"
|
||||
, "<a rel='nofollow' class='external text' href='https://e.org'>f</a>"
|
||||
, "g"
|
||||
));
|
||||
}
|
||||
@Test public void Protocol_rel() {
|
||||
fxt.Test__parse("[//a.org b]" , "<a rel='nofollow' class='external text' href='//a.org'>b</a>");
|
||||
}
|
||||
@Test public void Url_should_not_has_angle_entities() {
|
||||
fxt.Test__parse("[https://a.org/b<c z]" , "<a rel='nofollow' class='external text' href='https://a.org/b'><c z</a>");
|
||||
fxt.Test__parse("[https://a.org/b>c z]" , "<a rel='nofollow' class='external text' href='https://a.org/b'>>c z</a>");
|
||||
}
|
||||
@Test public void Link_trail() {// checks for noop via "Have link text"
|
||||
fxt.Test__parse("[https://a.org b]xyz" , "<a rel='nofollow' class='external text' href='https://a.org'>b</a>xyz");
|
||||
fxt.Test__parse("[https://a.org b]x!z" , "<a rel='nofollow' class='external text' href='https://a.org'>b</a>x!z");
|
||||
}
|
||||
@Test public void Clean_url() {
|
||||
fxt.Test__parse("[https://a"b c]" , "<a rel='nofollow' class='external text' href='https://a%22b'>c</a>");
|
||||
}
|
||||
}
|
||||
class Xomw_lnke_wkr__fxt {
|
||||
private final Xomw_lnke_wkr wkr = new Xomw_lnke_wkr(new Xomw_parser());
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private boolean apos = true;
|
||||
public Xomw_lnke_wkr__fxt() {
|
||||
Xomw_regex_space regex_space = new Xomw_regex_space();
|
||||
wkr.Init_by_wiki(Xomw_parser.Protocols__dflt(), new Xomw_regex_url(regex_space), regex_space);
|
||||
}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Replace_external_links(new Xomw_parser_ctx(), pbfr.Init(src_bry));
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.mediawiki.includes.filerepo.*; import gplx.xowa.mediawiki.includes.filerepo.file.*;
|
||||
import gplx.xowa.mediawiki.includes.media.*;
|
||||
public class Xomw_lnki_wkr__file__tst {
|
||||
private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt();
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init__file("File:A.png", 300, 200);
|
||||
}
|
||||
@Test public void Plain() {
|
||||
fxt.Test__to_html("[[File:A.png]]", "<a href='/wiki/File:A.png' class='image'><img alt='A.png' src='/orig/7/70/A.png' width='300' height='200' /></a>");
|
||||
}
|
||||
@Test public void Thumb() {
|
||||
fxt.Test__to_html("[[File:A.png|thumb]]", "<div class='thumb tright'><div class='thumbinner' style='width:222px;'><a href='/wiki/File:A.png' class='image'><img alt='A.png' src='/thumb/7/70/A.png/220px-A.png' width='220' height='146' class='thumbimage' /></a> <div class='thumbcaption'><div class='magnify'><a href='/wiki/File:A.png' class='internal' title='enlarge'></a></div></div></div></div>");
|
||||
}
|
||||
@Test public void Size() {
|
||||
fxt.Test__to_html("[[File:A.png|123x456px]]", "<a href='/wiki/File:A.png' class='image'><img alt='A.png' src='/thumb/7/70/A.png/123px-A.png' width='123' height='82' /></a>");
|
||||
}
|
||||
@Test public void fitBoxWidth() {
|
||||
// COMMENT:"Height is the relative smaller dimension, so scale width accordingly"
|
||||
// consider file of 200,100 (2:1)
|
||||
// EX_1: view is 120,40 (3:1)
|
||||
// - dimensions are either (a) 120,80 or (b) 80,40
|
||||
// - use (b) 80,40
|
||||
// EX_2: view is 120,80 (1.5:1)
|
||||
// - dimensions are either (a) 120,60 or (b) 160,80
|
||||
// - use (a) 120,60
|
||||
fxt.Init__file("File:A.png", 200, 100);
|
||||
fxt.Test__to_html__has("[[File:A.png|120x40px]]", "/80px-A.png");
|
||||
fxt.Test__to_html__has("[[File:A.png|120x80px]]", "/120px-A.png");
|
||||
}
|
||||
|
||||
@Test public void Test__parseWidthParam() {
|
||||
int[] img_size = new int[2];
|
||||
// WxHpx
|
||||
fxt.Test__parseWidthParam(img_size, "12x34px" , 12, 34);
|
||||
// WxH
|
||||
fxt.Test__parseWidthParam(img_size, "12x34" , 12, 34);
|
||||
// Wpx
|
||||
fxt.Test__parseWidthParam(img_size, "12px" , 12, 0);
|
||||
// W
|
||||
fxt.Test__parseWidthParam(img_size, "12" , 12, 0);
|
||||
// 12x
|
||||
fxt.Test__parseWidthParam(img_size, "12x" , 12, 0);
|
||||
// x34
|
||||
fxt.Test__parseWidthParam(img_size, "x34" , 0, 34);
|
||||
}
|
||||
}
|
||||
class Xomw_lnki_wkr__fxt {
|
||||
private final Xomw_lnki_wkr wkr;
|
||||
private final Xomw_parser_ctx pctx;
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private final XomwFileFinderMock file_finder;
|
||||
private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb"));
|
||||
private boolean apos = true;
|
||||
public Xomw_lnki_wkr__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
Xomw_parser parser = new Xomw_parser();
|
||||
wkr = parser.Lnki_wkr();
|
||||
|
||||
// env
|
||||
file_finder = new XomwFileFinderMock(parser.Env());
|
||||
parser.Env().File_finder_(file_finder);
|
||||
parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_thumbnail"), Bool_.Y, Bry_.Ary("thumb"));
|
||||
parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_width"), Bool_.Y, Bry_.Ary("$1px"));
|
||||
parser.Env().Message_mgr().Add("thumbnail-more", "enlarge");
|
||||
parser.Init_by_wiki(wiki);
|
||||
|
||||
// ctx
|
||||
pctx = new Xomw_parser_ctx();
|
||||
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1")));
|
||||
}
|
||||
public void Clear() {
|
||||
wkr.Clear_state();
|
||||
}
|
||||
public void Init__file(String title, int w, int h) {
|
||||
file_finder.Add(title, repo, w, h, XomwMediaHandlerFactory.Mime__image__png);
|
||||
}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Replace_internal_links(pctx, pbfr.Init(src_bry));
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
Gftest.Eq__ary__lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
public void Test__to_html(String src_str, String expd) {
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
Gftest.Eq__ary__lines(expd, Exec__to_html(src_str), src_str);
|
||||
}
|
||||
public void Test__to_html__has(String src_str, String expd) {
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
Gftest.Eq__bool_y(String_.Has(Exec__to_html(src_str), expd));
|
||||
}
|
||||
private String Exec__to_html(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Replace_internal_links(pctx, pbfr.Init(src_bry));
|
||||
wkr.replaceLinkHolders(pbfr);
|
||||
return pbfr.Rslt().To_str_and_clear();
|
||||
}
|
||||
public void Test__parseWidthParam(int[] img_size, String src_str, int expd_w, int expd_h) {
|
||||
wkr.parseWidthParam(img_size, Bry_.new_u8(src_str));
|
||||
Gftest.Eq__int(expd_w, img_size[0], "w");
|
||||
Gftest.Eq__int(expd_h, img_size[1], "h");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
import org.junit.*; import gplx.xowa.mediawiki.includes.filerepo.*; import gplx.xowa.mediawiki.includes.filerepo.file.*;
|
||||
public class Xomw_lnki_wkr__text__tst {
|
||||
private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <!--LINK 0--> z");}
|
||||
@Test public void Capt() {fxt.Test__parse("a [[A|a]] z" , "a <!--LINK 0--> z");}
|
||||
@Test public void Invalid__char() {fxt.Test__parse("a [[<A>]] z" , "a [[<A>]] z");}
|
||||
@Test public void Html__self() {fxt.Test__to_html("[[Page_1]]" , "<strong class='selflink'>Page_1</strong>");}
|
||||
@Test public void Html__text() {fxt.Test__to_html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");}
|
||||
@Test public void Html__capt() {fxt.Test__to_html("[[A|a]]" , "<a href='/wiki/A' title='A'>a</a>");}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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 Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
public Xomw_magiclinks_wkr__fxt() {
|
||||
Xomw_regex_space regex_space = new Xomw_regex_space();
|
||||
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1")));
|
||||
Xomw_parser parser = new Xomw_parser();
|
||||
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.Do_magic_links(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.nbsps; 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_nbsp_wkr__tst {
|
||||
private final Xomw_nbsp_wkr__fxt fxt = new Xomw_nbsp_wkr__fxt();
|
||||
@Test public void Noop() {fxt.Test__parse("abc" , "abc");}
|
||||
@Test public void Space_lhs__colon() {fxt.Test__parse("a :b c" , "a :b c");}
|
||||
@Test public void Space_lhs__laquo() {fxt.Test__parse("a »b c" , "a »b c");}
|
||||
@Test public void Space_rhs() {fxt.Test__parse("a« b c" , "a« b c");}
|
||||
@Test public void Important() {fxt.Test__parse("a  ! important b" , "a ! important b");}
|
||||
}
|
||||
class Xomw_nbsp_wkr__fxt {
|
||||
private final Xomw_nbsp_wkr wkr = new Xomw_nbsp_wkr();
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private boolean apos = true;
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
pbfr.Init(src_bry);
|
||||
wkr.Do_nbsp(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
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.prepros; 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_prepro_wkr__tst {
|
||||
private final Xomw_prepro_wkr__fxt fxt = new Xomw_prepro_wkr__fxt();
|
||||
@Test public void Text() {
|
||||
fxt.Test__parse("abc", "<root>abc</root>");
|
||||
}
|
||||
@Test public void Brack() {
|
||||
fxt.Test__parse("a[[b]]c", "<root>a[[b]]c</root>");
|
||||
}
|
||||
@Test public void Brack__one() { // COVERS: "Add literal brace(s)"
|
||||
fxt.Test__parse("a[b]c", "<root>a[b]c</root>");
|
||||
}
|
||||
@Test public void Brack__max() { // COVERS: "The specified maximum exists in the callback array, unless the caller"
|
||||
fxt.Test__parse("a[[[[[b]]]]]c", "<root>a[[[[[b]]]]]c</root>");
|
||||
}
|
||||
@Test public void Template() {
|
||||
fxt.Test__parse("a{{b}}c", "<root>a<template><title>b</title></template>c</root>");
|
||||
}
|
||||
@Test public void Template__args__idx() {
|
||||
fxt.Test__parse("a{{b|c|d}}e", "<root>a<template><title>b</title><part><name index=\"1\" /><value>c</value></part><part><name index=\"2\" /><value>d</value></part></template>e</root>");
|
||||
}
|
||||
@Test public void Template__args__key() {
|
||||
fxt.Test__parse("a{{b|c=d}}e", "<root>a<template><title>b</title><part><name>c</name>=<value>d</value></part></template>e</root>");
|
||||
}
|
||||
@Test public void Template__line_start() { // COVERS: "The invocation is at the start of the line if lineStart is set in"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "{{b}}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<template lineStart=\"1\"><title>b</title></template></root>"
|
||||
));
|
||||
}
|
||||
@Test public void Template__max() { // COVERS: "do we still qualify for any callback with remaining count?"
|
||||
fxt.Test__parse("a{{{{{b}}}}}c", "<root>a<template><title><tplarg><title>b</title></tplarg></title></template>c</root>");
|
||||
}
|
||||
@Test public void Tplarg() {
|
||||
fxt.Test__parse("a{{{b}}}c", "<root>a<tplarg><title>b</title></tplarg>c</root>");
|
||||
}
|
||||
@Test public void Tplarg__dflt() {
|
||||
fxt.Test__parse("a{{{b|c}}}d", "<root>a<tplarg><title>b</title><part><name index=\"1\" /><value>c</value></part></tplarg>d</root>");
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test__parse("a<!--b-->c", "<root>a<comment><!--b--></comment>c</root>");
|
||||
}
|
||||
@Test public void Comment__dangling() {// COVERS: "Unclosed comment in input, runs to end"
|
||||
fxt.Test__parse("a<!--b", "<root>a<comment><!--b</comment></root>");
|
||||
}
|
||||
@Test public void Comment__ws() { // COVERS: "Search backwards for leading whitespace"
|
||||
fxt.Test__parse("a <!--b--> c", "<root>a <comment><!--b--></comment> c</root>"); // NOTE: space is outside comment
|
||||
}
|
||||
@Test public void Comment__many__ws() {// COVERS: "Dump all but the last comment to the accumulator"
|
||||
fxt.Test__parse("a <!--1--> <!--2--> z", "<root>a <comment><!--1--></comment> <comment><!--2--></comment> z</root>"); // NOTE: space is outside comment;
|
||||
}
|
||||
@Test public void Comment__nl__ws() { // COVERS: "Eat the line if possible"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, " <!--1--> "
|
||||
, " <!--2--> "
|
||||
, "z"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<comment> <!--1--> " // NOTE: space is inside </comment> if flanked by nl;
|
||||
, "</comment><comment> <!--2--> "
|
||||
, "</comment>z</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Ext() { // COVERS.ALSO: "Note that the attr element contains the whitespace between name and attribute,"
|
||||
fxt.Test__parse("a<pre id=\"1\">b</pre>c", "<root>a<ext><name>pre</name><attr> id="1"</attr><inner>b</inner><close></pre></close></ext>c</root>");
|
||||
}
|
||||
@Test public void Ext__inline() { // COVERS: "if ( $text[$tagEndPos - 1] == '/' ) {"
|
||||
fxt.Test__parse("a<pre/>b" , "<root>a<ext><name>pre</name><attr></attr></ext>b</root>");
|
||||
fxt.Test__parse("a<pre />b" , "<root>a<ext><name>pre</name><attr> </attr></ext>b</root>");
|
||||
}
|
||||
@Test public void Ext__end__pass__space() {// COVERS: "\s*" in `preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",`
|
||||
fxt.Test__parse("a<pre>b</pre >c", "<root>a<ext><name>pre</name><attr></attr><inner>b</inner><close></pre ></close></ext>c</root>");
|
||||
}
|
||||
@Test public void Ext__end__pass__name() { // COVERS: "\s*" in `preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",`
|
||||
fxt.Test__parse("a<pre>b</pro></pre>c", "<root>a<ext><name>pre</name><attr></attr><inner>b</pro></inner><close></pre></close></ext>c</root>");
|
||||
}
|
||||
@Test public void Ext__end__fail__angle() {// COVERS: "\s*" in `preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",`
|
||||
fxt.Test__parse("a<pre>b</pre c", "<root>a<pre>b</pre c</root>");
|
||||
}
|
||||
@Test public void Ext__dangling() { // COVERS: "Let it run out to the end of the text."
|
||||
fxt.Test__parse("a<pre>bc", "<root>a<pre>bc</root>");
|
||||
}
|
||||
@Test public void Ext__dangling__many() { // COVERS: "Cache results, otherwise we have O(N^2) performance for input like <foo><foo><foo>..."
|
||||
fxt.Test__parse("a<pre><pre><pre>bc", "<root>a<pre><pre><pre>bc</root>");
|
||||
}
|
||||
@Test public void Ext__unclosed() { // COVERS: "Infinite backtrack"
|
||||
fxt.Test__parse("a<pre bcd", "<root>a<pre bcd</root>");
|
||||
}
|
||||
@Test public void Ext__noinclude() { // COVERS: "<includeonly> and <noinclude> just become <ignore> tags"
|
||||
fxt.Init__for_inclusion_(Bool_.N);
|
||||
fxt.Test__parse("a<includeonly>b<noinclude>c</noinclude>d</includeonly>e", "<root>a<ignore><includeonly>b<noinclude>c</noinclude>d</includeonly></ignore>e</root>");
|
||||
}
|
||||
@Test public void Heading() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "== b1 =="
|
||||
, "z"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<h level=\"2\" i=\"1\">== b1 ==</h>"
|
||||
, "z</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__eos__no_nl() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "== b1 =="
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<h level=\"2\" i=\"1\">== b1 ==</h></root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__bos__implied_nl() { // COVERS: "Is this the start of a heading?"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "== b1 =="
|
||||
, "z"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root><h level=\"2\" i=\"1\">== b1 ==</h>"
|
||||
, "z</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__dwim__y() { // COVERS: "DWIM: This looks kind of like a name/value separator."
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a{{b|"
|
||||
, "=c="
|
||||
, "}}d"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a<template><title>b</title><part><name>"
|
||||
, "</name>=<value>c="
|
||||
, "</value></part></template>d</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__dwim__n() { // COVERS: "DWIM: This looks kind of like a name/value separator."
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a{{b|"
|
||||
, "==c=="
|
||||
, "}}d"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a<template><title>b</title><part><name index=\"1\" /><value>"
|
||||
, "<h level=\"2\" i=\"1\">==c==</h>"
|
||||
, "</value></part></template>d</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__comment() { // COVERS: "Comment found at line end"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "==b== <!--c-->"
|
||||
, ""
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<h level=\"2\" i=\"1\">==b== <comment><!--c--></comment></h>"
|
||||
, "</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__consecutive__5() { // COVERS: "This is just a single String of equals signs on its own line"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "====="
|
||||
, ""
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "<h level=\"2\" i=\"1\">=====</h>"
|
||||
, "</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__consecutive__1() { // COVERS: "Single equals sign on its own line, count=0"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "="
|
||||
, ""
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "="
|
||||
, "</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Heading__unclosed() { // COVERS: "No match, no <h>, just pass down the inner src"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "===b"
|
||||
, ""
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<root>a"
|
||||
, "===b"
|
||||
, "</root>"
|
||||
));
|
||||
}
|
||||
@Test public void Inclusion__n() {
|
||||
fxt.Init__for_inclusion_(Bool_.N);
|
||||
fxt.Test__parse("a<onlyinclude>b</onlyinclude>c", "<root>a<ignore><onlyinclude></ignore>b<ignore></onlyinclude></ignore>c</root>");
|
||||
}
|
||||
@Test public void Inclusion__y() {
|
||||
fxt.Init__for_inclusion_(Bool_.Y);
|
||||
fxt.Test__parse("a<onlyinclude>b</onlyinclude>c", "<root><ignore>a<onlyinclude></ignore>b<ignore></onlyinclude>c</ignore></root>");
|
||||
}
|
||||
@Test public void Ignored__noinclude() { // COVERS: "Handle ignored tags"
|
||||
fxt.Init__for_inclusion_(Bool_.N);
|
||||
fxt.Test__parse("a<noinclude>b</noinclude>c", "<root>a<ignore><noinclude></ignore>b<ignore></noinclude></ignore>c</root>");
|
||||
}
|
||||
}
|
||||
class Xomw_prepro_wkr__fxt {
|
||||
private final Xomw_prepro_wkr wkr = new Xomw_prepro_wkr();
|
||||
private boolean for_inclusion = false;
|
||||
public Xomw_prepro_wkr__fxt() {
|
||||
wkr.Init_by_wiki("pre");
|
||||
}
|
||||
public void Init__for_inclusion_(boolean v) {for_inclusion = v;}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
byte[] actl = wkr.Preprocess_to_xml(src_bry, for_inclusion);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.quotes; 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_quote_wkr__tst {
|
||||
private final Xomw_quote_wkr__fxt fxt = new Xomw_quote_wkr__fxt();
|
||||
@Test public void Apos__0() {fxt.Test__parse("abc" , "abc");}
|
||||
@Test public void Apos__1() {fxt.Test__parse("a'b'c" , "a'b'c");}
|
||||
@Test public void Apos__2() {fxt.Test__parse("a''b''c" , "a<i>b</i>c");}
|
||||
@Test public void Apos__3() {fxt.Test__parse("a'''b'''c" , "a<b>b</b>c");}
|
||||
@Test public void Apos__4() {fxt.Test__parse("a''''b''''c" , "a'<b>b'</b>c");} // COVERS: "If there are ever four apostrophes"
|
||||
@Test public void Apos__5() {fxt.Test__parse("a'''''b'''''c" , "a<i><b>b</b></i>c");}
|
||||
@Test public void Apos__7() {fxt.Test__parse("a'''''''b'''''''c" , "a''<i><b>b''</b></i>c");} // COVERS: "If there are more than 5 apostrophes in a row"
|
||||
@Test public void Mix__single() {fxt.Test__parse("''a ''' ''b b''' ''cc'''" , "<i>a <b> </b></i><b>b b'<i> </i>cc</b>");} // COVERS: "If there is a single-letter word, use it!"
|
||||
@Test public void Mix__multi() {fxt.Test__parse("''a ''' ''b ''' ''cc'''" , "<i>a <b> </b></i><b>b </b> <i>cc'</i>");} // COVERS: "If not, but there's a multi-letter word, use that one."
|
||||
@Test public void Mix__space() {fxt.Test__parse("''a ''' ''b ''' ''c '''" , "<i>a '</i> <i>b <b> </b></i><b>c </b>");} // COVERS: "... otherwise use the first one that has neither."
|
||||
@Test public void Dangling__b() {fxt.Test__parse("a'''b" , "a<b>b</b>");} // COVERS: "if (state == State__b || state == State__ib)"
|
||||
@Test public void Dangling__i() {fxt.Test__parse("a''b" , "a<i>b</i>");} // COVERS: "if (state == State__i || state == State__bi || state == State__ib)"
|
||||
@Test public void Dangling__lone(){fxt.Test__parse("a'''''b" , "a<b><i>b</i></b>");} // COVERS: "There might be lonely ''''', so make sure we have a buffer"
|
||||
@Test public void Nl__text() {fxt.Test__parse("a\nb''c''d\n\ne" , "a\nb<i>c</i>d\n\ne");}
|
||||
}
|
||||
class Xomw_quote_wkr__fxt {
|
||||
private final Xomw_quote_wkr wkr = new Xomw_quote_wkr(new Xomw_parser());
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
wkr.Do_all_quotes(new Xomw_parser_ctx(), pbfr.Init(src_bry));
|
||||
Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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.tables; 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_table_wkr__tst {
|
||||
private final Xomw_table_wkr__fxt fxt = new Xomw_table_wkr__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, ""
|
||||
, "<tr>"
|
||||
, "<td>a"
|
||||
, "</td></tr></table>"
|
||||
));
|
||||
}
|
||||
@Test public void Tb__atrs() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|id='1'"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table id=\"1\">"
|
||||
, ""
|
||||
, "<tr>"
|
||||
, "<td>a"
|
||||
, "</td></tr></table>"
|
||||
));
|
||||
}
|
||||
@Test public void Tc__atrs() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|+id='1'|a"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, "<caption id=\"1\">a"
|
||||
, "</caption><tr><td></td></tr></table>"
|
||||
));
|
||||
}
|
||||
@Test public void Th__double() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "!a!!b"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, "<tr>"
|
||||
, "<th>a</th>"
|
||||
, "<th>b"
|
||||
, "</th></tr></table>"
|
||||
));
|
||||
}
|
||||
@Test public void Blank() { // COVERS: "empty line, go to next line"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( " "
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( " "
|
||||
));
|
||||
}
|
||||
@Test public void Tb__indent() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "::{|"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<dl><dd><dl><dd><table>"
|
||||
, ""
|
||||
, "<tr>"
|
||||
, "<td>a"
|
||||
, "</td></tr></table></dd></dl></dd></dl>"
|
||||
));
|
||||
}
|
||||
@Test public void Tb__empty() { // COVERS: "if (has_opened_tr.Len() == 0) {"
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, "<tr><td></td></tr></table>"
|
||||
));
|
||||
}
|
||||
@Test public void Td__empty() { // PURPOSE: handles (a) failure due to "first_2" array not handling "\n|\n"; (b) missing <tr><td></td></tr>
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, ""
|
||||
, "<tr>"
|
||||
, "<td>"
|
||||
, "</td></tr></table>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xomw_table_wkr__fxt {
|
||||
private final Xomw_parser_bfr parser_bfr = new Xomw_parser_bfr();
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_table_wkr wkr = new Xomw_table_wkr(new Xomw_parser());
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
parser_bfr.Init(src_bry);
|
||||
wkr.Do_table_stuff(pctx, parser_bfr);
|
||||
Tfds.Eq_str_lines(expd, parser_bfr.Rslt().To_str_and_clear(), src_str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Php_preg___tst {
|
||||
private final Php_preg___fxt fxt = new Php_preg___fxt();
|
||||
@Test public void Basic() {fxt.Test__split("a''b''c" , "''", Bool_.Y, "a", "''", "b", "''", "c");}
|
||||
@Test public void Extend() {fxt.Test__split("a'''b'''c" , "''", Bool_.Y, "a", "'''", "b", "'''", "c");}
|
||||
@Test public void Eos() {fxt.Test__split("a''" , "''", Bool_.Y, "a", "''");}
|
||||
}
|
||||
class Php_preg___fxt {
|
||||
private final gplx.core.primitives.Int_list rv = new gplx.core.primitives.Int_list();
|
||||
public void Test__split(String src, String dlm, boolean extend, String... expd) {Test__split(src, 0, String_.Len(src), dlm, extend, expd);}
|
||||
public void Test__split(String src, int src_bgn, int src_end, String dlm, boolean extend, String... expd) {
|
||||
byte[][] actl = Php_preg_.Split(rv, Bry_.new_u8(src), src_bgn, src_end, Bry_.new_u8(dlm), extend);
|
||||
Gftest.Eq__ary(expd, String_.Ary(actl), "find_failed");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.btries.*;
|
||||
public class Php_str___tst {
|
||||
private final Php_str___fxt fxt = new Php_str___fxt();
|
||||
@Test public void Strspn_fwd__byte() {
|
||||
fxt.Test__strspn_fwd__byte("aaaaab", Byte_ascii.Ltr_a, 0, -1, 5); // basic
|
||||
fxt.Test__strspn_fwd__byte("aaaaab", Byte_ascii.Ltr_a, 1, -1, 4); // bgn
|
||||
fxt.Test__strspn_fwd__byte("aaaaab", Byte_ascii.Ltr_a, 1, 2, 2); // max
|
||||
}
|
||||
@Test public void Strspn_fwd__space_or_tab() {
|
||||
fxt.Test__strspn_fwd__space_or_tab(" a", 0, -1, 5); // basic
|
||||
fxt.Test__strspn_fwd__space_or_tab(" a", 1, -1, 4); // bgn
|
||||
fxt.Test__strspn_fwd__space_or_tab(" a", 1, 2, 2); // max
|
||||
}
|
||||
@Test public void Strspn_bwd__byte() {
|
||||
fxt.Test__strspn_bwd__byte("aaaaab", Byte_ascii.Ltr_a, 5, -1, 5); // basic
|
||||
fxt.Test__strspn_bwd__byte("aaaaab", Byte_ascii.Ltr_a, 4, -1, 4); // bgn
|
||||
fxt.Test__strspn_bwd__byte("aaaaab", Byte_ascii.Ltr_a, 4, 2, 2); // max
|
||||
}
|
||||
@Test public void Strspn_bwd__space_or_tab() {
|
||||
fxt.Test__strspn_bwd__space_or_tab(" a", 5, -1, 5); // basic
|
||||
fxt.Test__strspn_bwd__space_or_tab(" a", 4, -1, 4); // bgn
|
||||
fxt.Test__strspn_bwd__space_or_tab(" a", 4, 2, 2); // max
|
||||
}
|
||||
@Test public void Substr__bgn_is_neg() {
|
||||
fxt.Test__substr("abcde" , -1, "e");
|
||||
fxt.Test__substr("abcde" , -3, -1, "cd");
|
||||
}
|
||||
@Test public void Strtr() {
|
||||
fxt.Init__strtr_by_trie("01", "89", "02", "79");
|
||||
fxt.Test__strtr_by_trie("abc" , "abc"); // found=none
|
||||
fxt.Test__strtr_by_trie("ab_01_cd" , "ab_89_cd"); // found=one
|
||||
fxt.Test__strtr_by_trie("ab_01_cd_02_ef", "ab_89_cd_79_ef"); // found=many
|
||||
fxt.Test__strtr_by_trie("01_ab" , "89_ab"); // BOS
|
||||
fxt.Test__strtr_by_trie("ab_01" , "ab_89"); // EOS
|
||||
}
|
||||
}
|
||||
class Php_str___fxt {
|
||||
public void Test__strspn_fwd__byte(String src_str, byte find, int bgn, int max, int expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Gftest.Eq__int(expd, Php_str_.Strspn_fwd__byte(src_bry, find, bgn, max, src_bry.length));
|
||||
}
|
||||
public void Test__strspn_fwd__space_or_tab(String src_str, int bgn, int max, int expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Gftest.Eq__int(expd, Php_str_.Strspn_fwd__space_or_tab(src_bry, bgn, max, src_bry.length));
|
||||
}
|
||||
public void Test__strspn_bwd__byte(String src_str, byte find, int bgn, int max, int expd) {
|
||||
Gftest.Eq__int(expd, Php_str_.Strspn_bwd__byte(Bry_.new_u8(src_str), find, bgn, max));
|
||||
}
|
||||
public void Test__strspn_bwd__space_or_tab(String src_str, int bgn, int max, int expd) {
|
||||
Gftest.Eq__int(expd, Php_str_.Strspn_bwd__space_or_tab(Bry_.new_u8(src_str), bgn, max));
|
||||
}
|
||||
public void Test__substr(String src_str, int bgn, String expd) {Test__substr(src_str, bgn, String_.Len(src_str), expd);}
|
||||
public void Test__substr(String src_str, int bgn, int len, String expd) {
|
||||
Gftest.Eq__str(expd, Php_str_.Substr(Bry_.new_u8(src_str), bgn, len));
|
||||
}
|
||||
private Btrie_slim_mgr strtr_trie;
|
||||
public void Init__strtr_by_trie(String... kvs) {
|
||||
if (strtr_trie == null) strtr_trie = Btrie_slim_mgr.cs();
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
strtr_trie.Add_str_str(kvs[i], kvs[i + 1]);
|
||||
}
|
||||
}
|
||||
public void Test__strtr_by_trie(String src, String expd) {
|
||||
Bry_bfr tmp = Bry_bfr_.New();
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
Gftest.Eq__str(expd, Php_str_.Strtr(Bry_.new_u8(src), strtr_trie, tmp, trv));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xomw_ttl_utl__tst {
|
||||
private final Xomw_ttl_utl__fxt fxt = new Xomw_ttl_utl__fxt();
|
||||
@Test public void Alphanum() {fxt.Test__find_fwd_while_title("0aB" , 3);}
|
||||
@Test public void Angle() {fxt.Test__find_fwd_while_title("0a<" , 2);}
|
||||
}
|
||||
class Xomw_ttl_utl__fxt {
|
||||
public void Test__find_fwd_while_title(String src_str, int expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Gftest.Eq__int(expd, Xomw_ttl_utl.Find_fwd_while_title(src_bry, 0, src_bry.length, Xomw_ttl_utl.Title_chars_valid()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user