1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

App: Release v4.5.15.1709

This commit is contained in:
gnosygnu
2017-09-17 22:39:30 -04:00
parent 4ca98f7333
commit ea3f0ffbcc
896 changed files with 69373 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
/*
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.xtns.assessments; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Assessment_func__tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test__parse__tmpl_to_html("{{#assessment:Name|A|Hi}}", "");
}
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.categoryList; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xtn_categoryList_nde_tst {
// private final Xop_fxt fxt = new Xop_fxt(); String raw_src;
@Test public void Basic() {
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.categorytrees; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Categorytree_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test__parse__tmpl_to_html("{{#categorytree:A B}}", "<a href='/wiki/Category:A_B'>Category:A B</a>");
}
}

View File

@@ -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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Ref_itm_mgr_cfg_tst {
@Before public void init() {fxt.Clear();} private Ref_itm_mgr_cfg_fxt fxt = new Ref_itm_mgr_cfg_fxt();
@Test public void Ref_backlabels_xby_bry() {
fxt.Test_Ref_backlabels_xby_bry("a b c" , "a", "b", "c"); // basic
fxt.Test_Ref_backlabels_xby_bry(" a b c" , "a", "b", "c"); // leading ws
fxt.Test_Ref_backlabels_xby_bry("a b c " , "a", "b", "c"); // trailing ws
fxt.Test_Ref_backlabels_xby_bry("a b c" , "a", "b", "c"); // redundant ws
}
}
class Ref_itm_mgr_cfg_fxt {
public void Clear() {}
public void Test_Ref_backlabels_xby_bry(String raw, String... expd) {
byte[][] actl = Ref_html_wtr_cfg.Ref_backlabels_xby_bry(Bry_.new_u8(raw));
Tfds.Eq_ary_str(expd, String_.Ary(actl));
}
}

View File

@@ -0,0 +1,81 @@
/*
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.tests.*;
public class Ref_itm_mgr_tst {
Ref_itm_mgr_fxt fxt = new Ref_itm_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {fxt.run_Add("key_1", "key_2").tst(fxt.itm_("key_1", 0, 0), fxt.itm_("key_2", 1, 1));}
@Test public void Repeat() {fxt.run_Add("key_1", "key_2", "key_1").tst(fxt.itm_("key_1", 0).Related_(fxt.itm_uid_(2)), fxt.itm_("key_2", 1, 1));}
@Test public void Group() {fxt.run_Add_grp("grp_1", "key_1").run_Add("key_1").tst_grp("grp_1", fxt.itm_("key_1", 0, 0)).tst(fxt.itm_("key_1", 0, 1));}
@Test public void Follow() {fxt.run_Add("key_1").run_Add_follow("key_1").tst(fxt.itm_("key_1", 0, 0).Related_(fxt.itm_uid_(1).Idx_minor_follow_()));}
}
class Ref_itm_mgr_fxt {
private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
private Tst_mgr tst_mgr = new Tst_mgr();
public Xtn_ref_nde_chkr itm_uid_(int uid) {return itm_(null, -1, uid);}
public Xtn_ref_nde_chkr itm_(String key, int idx) {return itm_(key, idx, -1);}
public Xtn_ref_nde_chkr itm_(String key, int idx, int uid) {return new Xtn_ref_nde_chkr().Key_(key).Idx_major_(idx).Uid_(uid);}
public Ref_itm_mgr_fxt run_Add_follow(String follow) {return run_Add_grp(Bry_.Empty, Bry_.new_u8(follow), Bry_.Ary(Bry_.Empty));}
public Ref_itm_mgr_fxt run_Add(String... name_ary) {return run_Add_grp(Bry_.Empty, Bry_.Empty, Bry_.Ary(name_ary));}
public Ref_itm_mgr_fxt run_Add_grp(String grp, String... name_ary) {return run_Add_grp(Bry_.new_u8(grp), Bry_.Empty, Bry_.Ary(name_ary));}
public void Clear() {ref_mgr.Grps_clear();}
Ref_itm_mgr_fxt run_Add_grp(byte[] grp_name, byte[] follow, byte[]... name_ary) {
for (int i = 0; i < name_ary.length; i++) {
byte[] name = name_ary[i];
Ref_nde itm = new Ref_nde().Name_(name);
ref_mgr.Grps_add(grp_name, name, follow, itm);
}
return this;
}
public Ref_itm_mgr_fxt tst(Xtn_ref_nde_chkr... chkr_ary) {return tst_grp(ref_mgr.Lst_get(Bry_.Empty, 0), chkr_ary);}
public Ref_itm_mgr_fxt tst_grp(String grp_name, Xtn_ref_nde_chkr... chkr_ary) {return tst_grp(ref_mgr.Lst_get(Bry_.new_a7(grp_name), 0), chkr_ary);}
public Ref_itm_mgr_fxt tst_grp(Ref_itm_lst lst, Xtn_ref_nde_chkr... chkr_ary) {
int itms_len = lst.Itms_len();
Ref_nde[] actl = new Ref_nde[itms_len];
for (int i = 0; i < itms_len; i++)
actl[i] = lst.Itms_get_at(i);
tst_mgr.Tst_ary("", chkr_ary, actl);
return this;
} List_adp actl_list = List_adp_.New();
}
class Xtn_ref_nde_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Ref_nde.class;}
public String Key() {return key;} public Xtn_ref_nde_chkr Key_(String v) {key = v; return this;} private String key;
public int Idx_major() {return idx_major;} public Xtn_ref_nde_chkr Idx_major_(int v) {idx_major = v; return this;} private int idx_major = -1;
public int Idx_minor() {return idx_minor;} public Xtn_ref_nde_chkr Idx_minor_(int v) {idx_minor = v; return this;} private int idx_minor = -1;
public Xtn_ref_nde_chkr Idx_minor_follow_() {idx_minor = Ref_nde.Idx_minor_follow; return this;}
public int Uid() {return uid;} public Xtn_ref_nde_chkr Uid_(int v) {uid = v; return this;} private int uid = -1;
public Xtn_ref_nde_chkr[] Related() {return related;} public Xtn_ref_nde_chkr Related_(Xtn_ref_nde_chkr... v) {related = v; return this;} Xtn_ref_nde_chkr[] related;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Ref_nde actl = (Ref_nde)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Name()));
rv += mgr.Tst_val(idx_major == -1, path, "idx_major", idx_major, actl.Idx_major());
rv += mgr.Tst_val(idx_minor == -1, path, "idx_minor", idx_minor, actl.Idx_minor());
rv += mgr.Tst_val(uid == -1, path, "uid", uid, actl.Uid());
if (related != null)
rv += mgr.Tst_sub_ary(related, Xto_bry(actl), "related", rv);
return rv;
}
Ref_nde[] Xto_bry(Ref_nde itm) {
int len = itm.Related_len();
Ref_nde[] rv = new Ref_nde[len];
for (int i = 0; i < len; i++)
rv[i] = itm.Related_get(i);
return rv;
}
}

View File

@@ -0,0 +1,200 @@
/*
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_basic_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, "<ref>y</ref>"
, "<ref>z</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[3]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
, "</ol>"
, ""
));
}
@Test public void Name_dif() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name='r_x'>x</ref>"
, "<ref name='r_y'>y</ref>"
, "<ref name='r_z'>z</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-r_y_1-0\" class=\"reference\"><a href=\"#cite_note-r_y-1\">[2]</a></sup>"
, "<sup id=\"cite_ref-r_z_2-0\" class=\"reference\"><a href=\"#cite_note-r_z-2\">[3]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_x_0-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-r_y-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_y_1-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "<li id=\"cite_note-r_z-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_z_2-0\">^</a></span> <span class=\"reference-text\">z</span></li>"
, "</ol>"
, ""
));
}
@Test public void Name_same() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name='r_x'>x</ref>"
, "<ref name='r_y'>y</ref>"
, "<ref name='r_x'>z</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-r_y_1-0\" class=\"reference\"><a href=\"#cite_note-r_y-1\">[2]</a></sup>"
, "<sup id=\"cite_ref-r_x_0-1\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-r_x_0-0\">a</a></sup> <sup><a href=\"#cite_ref-r_x_0-1\">b</a></sup></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-r_y-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_y_1-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, ""
));
}
@Test public void Name_same_text_in_last_ref() { // WP:Hundred Years' War
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name='ref_a'></ref>"
, "<ref name='ref_a'></ref>"
, "<ref name='ref_a'>x</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-ref_a_0-0\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-ref_a_0-1\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-ref_a_0-2\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-ref_a-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_a_0-0\">a</a></sup> <sup><a href=\"#cite_ref-ref_a_0-1\">b</a></sup> <sup><a href=\"#cite_ref-ref_a_0-2\">c</a></sup></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, ""
));
}
@Test public void List_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>*x</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">*x</span></li>"
, "</ol>"
, ""
));
}
@Test public void Name_mixed_case() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref NAME=A>x</ref>"
, "<ref Name=A>y</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-A_0-0\" class=\"reference\"><a href=\"#cite_note-A-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-A_0-1\" class=\"reference\"><a href=\"#cite_note-A-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-A-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-A_0-0\">a</a></sup> <sup><a href=\"#cite_ref-A_0-1\">b</a></sup></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, ""
));
}
@Test public void Name2() { // PURPOSE: make sure inline tag matches open tag
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "a<ref name=name_0>b</ref>"
, "b<ref name=name_0/>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "a<sup id=\"cite_ref-name_0_0-0\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[1]</a></sup>"
, "b<sup id=\"cite_ref-name_0_0-1\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-name_0-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-name_0_0-0\">a</a></sup> <sup><a href=\"#cite_ref-name_0_0-1\">b</a></sup></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void References_refs() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "a<ref group=group_0 name=name_0/>"
, "<references group=group_0>"
, " <ref name=name_0>b</ref>"
, "</references>"
), String_.Concat_lines_nl_skip_last
( "a<sup id=\"cite_ref-name_0_0-0\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[group_0 1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-name_0-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-name_0_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void Nested() { // PURPOSE: nested ref was creating 3rd [1]
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "a<ref name=r_x/>"
, "b<ref name=r_x/>"
, "<references>"
, "<ref name=r_x>c</ref>"
, "</references>"
), String_.Concat_lines_nl_skip_last
( "a<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
, "b<sup id=\"cite_ref-r_x_0-1\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-r_x_0-0\">a</a></sup> <sup><a href=\"#cite_ref-r_x_0-1\">b</a></sup></span> <span class=\"reference-text\">c</span></li>"
, "</ol>"
, ""
));
}
@Test public void Key_ignore_nl_tab() { // PURPOSE: \n in ref_name should be escaped to \s; PAGE:en.w:Self-Transcendence 3100 Mile Race
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name=\"name\na\">b</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-name_a_0-0\" class=\"reference\"><a href=\"#cite_note-name_a-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-name_a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-name_a_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void Empty_group_before_ref() { // PURPOSE: empty grp before itm should not throw error; DATE:2013-02-18; EX: w:Help:External links and references; Johnstown,_Colorado
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
( "<references/><references/>a<ref>test</ref>"
, "<references/>"
), String_.Concat_lines_nl
( "a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">test</span></li>"
, "</ol>"
, ""
));
}
@Test public void Follow() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name='ref_a'>x</ref>"
, "<ref>y</ref>"
, "<ref follow='ref_a'>z</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-ref_a_0-0\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-ref_a-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_a_0-0\">a</a></sup></span> <span class=\"reference-text\">x z</span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, ""
));
}
}

View File

@@ -0,0 +1,120 @@
/*
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_group_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Basic() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, "<ref group='group_a'>y</ref>"
, "<ref>z</ref>"
, "<references group='group_a'/>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[group_a 1]</a></sup>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
, "</ol>"
, ""
));
}
@Test public void Lower_alpha_is_ignored() {
String expd =
String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>" // note:do not show lower-alpha; DATE:2014-07-21
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "</ol>"
, ""
);
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='lower-alpha'>x</ref>"
, "<ref>y</ref>"
, "<references group='lower-alpha'/>"
, "<references group=''/>"
), expd);
}
@Test public void Empty() { // PURPOSE: <references group=""/> is same as <references/>; DATE:2013-02-06
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>b</ref>"
, "<references group=\"\"/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
@Test public void Val_less_defaults_to_key() { // PURPOSE: similar to above, except "group" is same as "group=group"; DATE:2014-07-03
String expd = String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[group 1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, "");
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref group='group'>b</ref>"
, "<references group/>"
), expd
);
fxt.Clear_ref_mgr();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last // PURPOSE.FIX: similar to above, except "group />" was not same as "group/>"; SEE:xatr_parser and " a " test; DATE:2014-07-03
( "<ref group='group'>b</ref>"
, "<references group />"
), expd
);
}
@Test public void Empty_group() { // PURPOSE: group without items should be blank; should not throw error; DATE:2013-02-12
fxt.Test_parse_page_wiki_str("<references name='group_a'/>", "");
}
@Test public void Multiple_same_name_groups() { // PURPOSE: multiple groups with same name "clears" out references; DATE:2013-02-11
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>a</ref>"
, "<references/>"
, "<ref>b</ref>"
, "<references/>"
, "<ref>c</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c</span></li>"
, "</ol>"
, ""
));
}
}

View File

@@ -0,0 +1,65 @@
/*
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_pre_tst {
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Pre_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref> x</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"> x</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_2() { // PURPOSE: <ref> creates <li> which will effectively disable all pre; PAGE:en.w:Robert_Browning
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x"
, " y"
, "</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x"
, " y"
, "</span></li>"
, "</ol>"
, ""
));
}
@Test public void Pre_ignored_3() { // PURPOSE: " <references>" should not create pre; fr.w:Heidi_(roman); DATE:2014-02-17
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>x</ref>"
, ""
, " <references/>"
), String_.Concat_lines_nl_skip_last
( "<p><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "</p>"
, " <ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
, "</ol>"
, ""
));
fxt.Init_para_n_();
}
}

View File

@@ -0,0 +1,106 @@
/*
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class References_nde_rare_tst {
@Before public void init() {fxt.Clear_ref_mgr(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Recursive() { // PURPOSE: handle recursive situations; EX: ja.w:Kソリューション ; ja.w:Template:cite web。; DATE:2014-03-05
fxt.Init_page_create("Template:Recursive", "<ref>{{Recursive}}</ref>");
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref>{{Recursive}}</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"></span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\"><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></li>"
, "</ol>"
, ""
));
}
@Test public void Backlabel_out_of_range() { // PURPOSE: handle more backlabels than expected; PAGE:en.w:List_of_Russula_species; DATE:2014-06-07
Ref_html_wtr_cfg cfg = fxt.Wiki().Html_mgr().Html_wtr().Ref_wtr().Cfg();
byte[][] old = cfg.Backlabels();
cfg.Backlabels_(Bry_.Ary("a"));
fxt.Wiki().Msg_mgr().Get_or_make(Ref_html_wtr_cfg.Msg_backlabels_err).Atrs_set(Bry_.new_a7("Ran out of custom link labels for group ~{0}."), true, false);
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ref name='ref_1'>a</ref><ref name='ref_1'>b</ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-ref_1_0-0\" class=\"reference\"><a href=\"#cite_note-ref_1-0\">[1]</a></sup><sup id=\"cite_ref-ref_1_0-1\" class=\"reference\"><a href=\"#cite_note-ref_1-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-ref_1-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_1_0-0\">a</a></sup> <sup><a href=\"#cite_ref-ref_1_0-1\">Ran out of custom link labels for group 1.</a></sup></span> <span class=\"reference-text\">a</span></li>"
, "</ol>"
, ""
));
cfg.Backlabels_(old);
}
@Test public void Tag() { // PURPOSE: #tag can create nested refs; PAGE:en.w:Battle_of_Midway DATE:2014-06-27
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "{{#tag:ref|x<ref>y</ref>}}" //"<ref>x<ref>y</ref></ref>"
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">x<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></li>"
, "</ol>"
, ""
));
}
@Test public void Tag_2() { // PURPOSE: more involved nested refs; PAGE:en.w:Battle_of_Midway DATE:2014-06-27
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a<ref name='itm_0'/> b {{#tag:ref|c<ref name='itm_0'>d</ref>}}" // <ref>c<ref name='itm_0'>d</ref></ref>
, "<references/>"
), String_.Concat_lines_nl_skip_last
( "a<sup id=\"cite_ref-itm_0_0-0\" class=\"reference\"><a href=\"#cite_note-itm_0-0\">[1]</a></sup> b <sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-itm_0-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-itm_0_0-0\">a</a></sup> <sup><a href=\"#cite_ref-itm_0_0-1\">b</a></sup></span> <span class=\"reference-text\">d</span></li>"
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c<sup id=\"cite_ref-itm_0_0-1\" class=\"reference\"><a href=\"#cite_note-itm_0-0\">[1]</a></sup></span></li>"
, "</ol>"
, ""
));
}
@Test public void Dangling_references__nested() { // PURPOSE: handle nested <references/>; PAGE:en.w:Hwair; DATE:2014-06-27
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<ref>a</ref>"
, "<references>"
, " <references/>" // must be ignored, else it will become owner for <ref>
, "</references>"
), String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, "<ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
, "</ol>"
, ""
));
}
@Test public void Dangling_ref_and_stack_overflow() { // PURPOSE: handle dangling <ref> with nested <references/>; PAGE:cs.s:Page:Hejčl,_Jan_-_Pentateuch.pdf/128 DATE:2016-09-01
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a<ref name='ref_0'>b</ref>c"
, "<references><ref name='ref_1'>d"
, "<references/>" // must be ignored, else it will be same as outer <references>
, "</references>"
), String_.Concat_lines_nl_skip_last
( "a<sup id=\"cite_ref-ref_0_0-0\" class=\"reference\"><a href=\"#cite_note-ref_0-0\">[1]</a></sup>c"
, "<ol class=\"references\">"
, "<li id=\"cite_note-ref_0-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-ref_0_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
, ""
));
}
}

View File

@@ -0,0 +1,361 @@
/*
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.xtns.dynamicPageList; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.strings.*; import gplx.xowa.apps.cfgs.*; import gplx.xowa.wikis.nss.*; import gplx.langs.htmls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
public class Dpl_xnde_tst {
private final Dpl_xnde_fxt fxt = new Dpl_xnde_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Ctg() {
fxt.Init__create_ctg("Ctg_0", "B", "A");
fxt.Exec__parse("<DynamicPageList>category=Ctg_0</DynamicPageList>");
fxt.Test__html(fxt.Make__html__itms__null("B", "A"));
}
@Test public void Ctg_multiple() {
fxt.Init__create_ctg_pages("Ctg_0", Dpl_page_mok.new_(101, "A"), Dpl_page_mok.new_(102, "B"));
fxt.Init__create_ctg_pages("Ctg_1", Dpl_page_mok.new_(101, "A"));
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "category=Ctg_1"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A"));
}
@Test public void Ctg_multiple_none() { // PURPOSE: page must be in both categories
fxt.Init__create_ctg("Ctg_0", "A");
fxt.Init__create_ctg("Ctg_1", "B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "category=Ctg_1"
, "</DynamicPageList>"
);
fxt.Test__html("No pages meet these criteria.");
}
@Test public void Ctg_multiple_ignore_invalid() { // PURPOSE: ignore invalid category titles; PAGE:en.n:Category:Egypt DATE:2016-10-18
fxt.Init__create_ctg_pages("Ctg_0", Dpl_page_mok.new_(101, "A"));
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "category={{{2}}}" // ignore invalid titles
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A")); // should not return nothing
}
@Test public void Notcategory() {
fxt.Init__create_ctg_pages("Ctg_0", Dpl_page_mok.new_(101, "A"), Dpl_page_mok.new_(102, "B"));
fxt.Init__create_ctg_pages("Ctg_1", Dpl_page_mok.new_(101, "A"));
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "notcategory=Ctg_1"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("B"));
}
@Test public void Ctg_ascending() {
fxt.Init__create_ctg("Ctg_0", "B", "A");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "order=ascending"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A", "B"));
}
@Test public void Ctg_ws() {
fxt.Init__create_ctg("Ctg_0", "B", "A");
fxt.Exec__parse
( "<DynamicPageList>"
, " category = Ctg_0 "
, " order = ascending "
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A", "B"));
}
@Test public void Ctg_descending() {
fxt.Init__create_ctg("Ctg_0", "A", "B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "order=descending"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("B", "A"));
}
@Test public void Nofollow() {
fxt.Init__create_ctg("Ctg_0", "A", "B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "nofollow=true"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html(" rel=\"nofollow\"", "A", "B"));
}
@Test public void Invalid_key() {
fxt.Init__create_ctg("Ctg_0", "A", "B");
fxt.Init__warns("dynamic_page_list:unknown_key: page=Test page key=invalid_key");
fxt.Exec__parse
( "<DynamicPageList>"
, "invalid_key=invalid_val"
, "category=Ctg_0"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A", "B"));
}
@Test public void No_results() {
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "</DynamicPageList>"
);
fxt.Test__html("No pages meet these criteria.");
}
@Test public void Suppress_errors() {
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "suppresserrors=true"
, "</DynamicPageList>"
);
fxt.Test__html("");
}
@Test public void Count() {
fxt.Init__create_ctg("Ctg_0", "A", "B", "C");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "count=2"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A", "B"));
}
@Test public void Offset() {
fxt.Init__create_ctg("Ctg_0", "A", "B", "C");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "offset=2"
, "count=2"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("C"));
}
@Test public void Ns() {
fxt.Init__create_ctg("Ctg_0", "Talk:A B", "B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "namespace=Talk"
, "</DynamicPageList>"
);
fxt.Test__html(Gfh_utl.Replace_apos_concat_lines
( "<ul>"
, " <li><a href='/wiki/Talk:A_B' title='Talk:A B'>A B</a></li>"
, "</ul>"
));
}
@Test public void Show_ns() {
fxt.Init__create_ctg("Ctg_0", "Talk:A");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "shownamespace=true"
, "</DynamicPageList>"
);
fxt.Test__html(Gfh_utl.Replace_apos_concat_lines
( "<ul>"
, " <li><a href='/wiki/Talk:A' title='Talk:A'>Talk:A</a></li>"
, "</ul>"
));
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "shownamespace=false"
, "</DynamicPageList>"
);
fxt.Test__html(Gfh_utl.Replace_apos_concat_lines
( "<ul>"
, " <li><a href='/wiki/Talk:A' title='Talk:A'>A</a></li>"
, "</ul>"
));
}
@Test public void Comment() { // PURPOSE: comment should be ignored; en.n:Portal:Federally_Administered_Tribal_Areas; DATE:2014-01-18
fxt.Init__create_ctg("Ctg_0", "B", "A");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "<!--category=Ctg_0-->"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("B", "A"));
}
@Test public void Error_skip_line() { // PURPOSE: error should skip rest of line; was failing with array out of bounds; en.n:Portal:Austria/Wikipedia; DATE:2014-01-18
fxt.Init__warns("dynamic_page_list:unknown_key: page=Test page key=Ctg_0 order"); // ignore warning message
fxt.Exec__parse("<DynamicPageList> category=Ctg_0 order=descending</DynamicPageList>");
fxt.Test__html("No pages meet these criteria.");
}
@Test public void Atr_has_template() { // PURPOSE: attribute also has template; DATE:2014-01-31
fxt.Init__create_ctg("Test_page", "B", "A");
fxt.Exec__parse
( "<DynamicPageList>"
, "category={{PAGENAME}}"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("B", "A"));
}
@Test public void Err_page_ns_doesnt_exist() {// PURPOSE: check that <dpl> is not enabled if wiki does not have Page / Index ns; PAGE:fr.w:Wikipedia:Le_Bistro/novembre_2006 DATE:2014-11-28
// reset categories to (a) remove ns for Page / Index; (b) add back Category (else null error)
fxt.Wiki().Ns_mgr().Clear();
fxt.Wiki().Ns_mgr().Add_new(14, "Category").Init();
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached valid ns_page from previous tests
fxt.Fxt().Test_parse_page_wiki_str("<dynamicpagelist>category=a</dynamicpagelist>", "No pages meet these criteria.");
fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached invalid ns_page for next tests
// reset categories for rest of tests
fxt.Wiki().Ns_mgr().Add_new(0, "").Init(); // call .Clear() to remove ns for Page / Index
}
@Test public void Ordermethod__invalid() { // PURPOSE: do not fail if ordermethod is invalid; PAGE:sr.d:Викиречник:Википројекат_1001_арапска_реч/Списак_уноса; DATE:2015-10-16
fxt.Init__create_ctg("Ctg_0", "A", "B", "C");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "ordermethod=ascending" // should not throw error
, "ordermethod=sortkey"
, "</DynamicPageList>"
);
fxt.Test__html(fxt.Make__html__itms__null("A", "B", "C"));
}
@Test public void Encode_spaces() {// PURPOSE:encode spaces in href; PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19
fxt.Init__create_ctg("Ctg_0", "A B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "nofollow=true"
, "</DynamicPageList>"
);
fxt.Test__html(Gfh_utl.Replace_apos_concat_lines
( "<ul>"
, " <li><a href='/wiki/A_B' title='A B' rel='nofollow'>A B</a></li>" // "/wiki/A_B" not "/wiki/A B"
, "</ul>"
));
}
@Test public void Encode_quotes() {// PURPOSE:encode quotes; PAGE:en.b:Wikibooks:Alphabetical_classification/All_Books; DATE:2016-01-21
fxt.Init__create_ctg("Ctg_0", "A\"B");
fxt.Exec__parse
( "<DynamicPageList>"
, "category=Ctg_0"
, "nofollow=true"
, "</DynamicPageList>"
);
fxt.Test__html(Gfh_utl.Replace_apos_concat_lines
( "<ul>"
, " <li><a href='/wiki/A%22B' title='A&quot;B' rel='nofollow'>A&quot;B</a></li>" // "/wiki/A_B" not "/wiki/A B"
, "</ul>"
));
}
@Test public void Err__bad_key_causes_out_of_bound() { // PURPOSE: bad key causes out of bounds error; PAGE:de.n:Portal:Brandenburg DATE:2016-04-21
fxt.Exec__parse
( "<DynamicPageList>"
, "<DynamicPageList>category=A</DynamicPageList>a=b c=d"
, "<DynamicPageList>category=B</DynamicPageList>"
);
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "&lt;DynamicPageList&gt;"
, "No pages meet these criteria.a=b c=d"
, "No pages meet these criteria."
));
}
}
class Dpl_page_mok {
public Dpl_page_mok(int id, String ttl) {this.id = id; this.ttl = ttl;}
public int Id() {return id;} private int id;
public String Ttl() {return ttl;} private String ttl;
public static Dpl_page_mok new_(int id, String ttl) {return new Dpl_page_mok(id, ttl);}
}
class Dpl_xnde_fxt {
private final Xop_fxt fxt = new Xop_fxt();
private final Bry_bfr bfr = Bry_bfr_.New();
private String exec__raw;
private int next_id;
public void Clear() {
next_id = 100;
fxt.Reset();
this.exec__raw = String_.Empty;
this.expd_warns = String_.Ary_empty;
fxt.App().Usr_dlg().Gui_wkr().Clear();
fxt.Wiki().Hive_mgr().Clear();
fxt.Wiki().Db_mgr().Save_mgr().Clear(); // NOTE: must clear to reset next_id to 0; Init__create_ctg assumes clean slate from 0
fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_y_();
fxt.Wiki().Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
fxt.Wiki().Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
Io_mgr.Instance.InitEngine_mem();
}
public Xowe_wiki Wiki() {return fxt.Wiki();}
public Xop_fxt Fxt() {return fxt;}
public void Init__warns(String... v) {expd_warns = v;} private String[] expd_warns;
public void Init__create_ctg(String ctg, String... ttls) {
int len = ttls.length;
Dpl_page_mok[] ary = new Dpl_page_mok[len];
for (int i = 0; i < len; i++)
ary[i] = Dpl_page_mok.new_(++next_id, ttls[i]);
Init__create_ctg_pages(ctg, ary);
}
public void Init__create_ctg_pages(String ctg_ttl, Dpl_page_mok... pages) {
Xoctg_catpage_ctg ctg = new Xoctg_catpage_ctg(1, Bry_.new_u8(ctg_ttl));
int pages_len = pages.length;
Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp();
for (int i = 0; i < pages_len; i++) {
Dpl_page_mok page = pages[i];
int id = page.Id();
String ttl_str = page.Ttl();
Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ttl_str));
Xoae_page page_obj = fxt.Wiki().Data_mgr().Load_page_by_ttl(ttl);
if (page_obj.Db().Page().Exists_n()) {
fxt.Init_page_create(ttl_str, ttl_str);
fxt.Init_id_create (id, 0, 0, false, 5, Xow_ns_.Tid__main, ttl_str);
}
byte tid = gplx.xowa.addons.wikis.ctgs.Xoa_ctg_mgr.Tid__page;
Xoctg_catpage_itm catpage_itm = Xoctg_catpage_itm.New_by_ttl(tid, page.Id(), ttl);
tmp.Add(catpage_itm);
}
tmp.Make_by_ctg(ctg);
Xoctg_catpage_mgr catpage_mgr = fxt.Wiki().Ctg__catpage_mgr();
catpage_mgr.Cache__add(Bry_.new_u8("Category:" + ctg_ttl), ctg);
}
public String Make__html__itms__null(String... pages) {return this.Make__html(null, pages);}
public String Make__html(String itm_html, String... pages) {
bfr.Add_str_a7("<ul>").Add_byte_nl();
int pages_len = pages.length;
for (int i = 0; i < pages_len; i++) {
String page = pages[i];
bfr.Add_str_a7(" <li><a href=\"/wiki/").Add_str_a7(page).Add_str_a7("\" title=\"").Add_str_a7(page).Add_str_a7("\"");
if (itm_html != null) bfr.Add_str_a7(itm_html);
bfr.Add_str_a7(">").Add_str_a7(page).Add_str_a7("</a></li>").Add_byte_nl();
}
bfr.Add_str_a7("</ul>").Add_byte_nl();
return bfr.To_str_and_clear();
}
public void Exec__parse(String... raw_lines) {this.exec__raw = String_.Concat_lines_nl_skip_last(raw_lines);}
public void Test__html(String expd) {
fxt.Test_parse_page_wiki_str(exec__raw, expd);
fxt.tst_Warn(expd_warns);
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.wikis.pages.skins.*;
public class Pages_using_pending_changes_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_html_full_str("{{PAGESUSINGPENDINGCHANGES}}", "0");
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.wikis.pages.skins.*;
public class Pending_change_level_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_html_full_str("{{PENDINGCHANGELEVEL}}", "");
}
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.flaggedRevs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.flaggedRevs.*;
import org.junit.*;
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
public class Flagged_revs_lib_tst {
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Flagged_revs_lib lib;
@Before public void init() {
fxt.Clear();
lib = new Flagged_revs_lib();
lib.Init();
lib.Core_(fxt.Core());
}
@Test public void GetStabilitySettings() {
fxt.Test__proc__objs__nest(lib, Flagged_revs_lib.Invk_getStabilitySettings, Object_.Ary("Page1"), String_.Concat_lines_nl_skip_last
( "1="
, " over"+"ride=0"
, " autoreview="
, " expiry=infinity"
));
}
}

View File

@@ -0,0 +1,185 @@
/*
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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
import gplx.xowa.htmls.*; import gplx.xowa.files.fsdb.*;
public class Gallery_mgr_base__basic__tst {
private Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {
fxt.Test_html_str(String_.Concat_lines_nl_skip_last
( "<gallery widths=200px heights=300px>"
, "A.png|''a1''"
, "B.png|''b1''"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>a1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width:235px;\">"
, " <div style=\"width:235px;\">"
, " <div class=\"thumb\" style=\"width:230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>b1</i>"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
));
fxt.Test_html_modules_js(String_.Concat_lines_nl_skip_last
( ""
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/mediawiki.page/mediawiki.page.gallery.css\" type='text/css'>"
));
}
@Test public void Tmpl() {
fxt.Fxt().Init_defn_add("test_tmpl", "b");
fxt.Test_html_frag("<gallery>File:A.png|a{{test_tmpl}}c</gallery>", "<div class=\"gallerytext\"><p>abc\n</p>");
}
@Test public void Itm_defaults_to_120() {
fxt.Test_html_frag("<gallery>File:A.png|a</gallery>", "<img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />");
}
@Test public void Height_fix() {
fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "y");
fxt.Test_html_frag("<gallery heights=250>File:A.png|a<br/>c</gallery>", " width=\"120\" height=\"250\"");
fxt.Test_html_frag("<div style=\"margin:15px auto;\">");
fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "n");
}
@Test public void Alt() {
fxt.Test_html_frag("<gallery>File:A.png|b|alt=c</gallery>"
, "<img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
, "<div class=\"gallerytext\"><p>b\n</p>"
);
}
@Test public void Link() {
fxt.Test_html_frag("<gallery>File:A.png|b|link=c</gallery>", "<a href=\"/wiki/C\" class=\"image\"");
}
@Test public void Page() { // PURPOSE: page was not being set; PAGE:pt.s:Portal:Diccionario_geographico_do_Brazil; DATE:2015-04-16
fxt.Test_html_frag
( "<gallery>File:A.pdf|b|page=8</gallery>"
, "A.pdf/120px-8.jpg" // make sure page 8 shows up
);
}
@Test public void Alt_caption_multiple() {
fxt.Test_html_frag("<gallery>File:A.png|alt=b|c[[d|e]]f</gallery>", "<div class=\"gallerytext\"><p>c<a href=\"/wiki/D\">ef</a>\n</p>");
}
@Test public void Alt_escape_quote() {
fxt.Test_html_frag("<gallery>File:A.png|b|alt=c\"d'e</gallery>", "alt=\"c&quot;d'e\"");
}
@Test public void Caption_null() { // PURPOSE: null caption causes page to fail; EX: de.w:Lewis Caroll; <gallery>Datei:A.png</gallery>; DATE:2013-10-09
fxt.Test_html_frag("<gallery>File:A.png</gallery>", "<div class=\"gallerytext\">\n");
}
@Test public void Ttl_has_no_ns() { // PURPOSE: MW allows ttl to not have ns; DATE: 2013-11-18
fxt.Test_html_frag("<gallery>A.png|b</gallery>", "<img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"); // make sure image is generated
}
@Test public void Ref() { // PURPOSE: <ref> inside <gallery> was not showing up in <references>; DATE:2013-10-09
fxt.Test_html_frag("<gallery>File:A.png|<ref name='a'>b</ref></gallery><references/>"
, "<div class=\"gallerytext\"><p><sup id=\"cite_ref-a_0-0\" class=\"reference\"><a href=\"#cite_note-a-0\">[1]</a></sup>\n</p>"
, String_.Concat_lines_nl
( "</ul><ol class=\"references\">"
, "<li id=\"cite_note-a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-a_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
, "</ol>"
)
);
}
@Test public void Packed() {
fxt.Test_html_frag("<gallery mode=packed heights=300px>File:A.png|a</gallery>", "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-packed\">");
fxt.Test_html_modules_js(String_.Concat_lines_nl_skip_last
( ""
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/mediawiki.page/mediawiki.page.gallery.css\" type='text/css'>"
, " <script type='text/javascript'>"
, " var xowa_global_values = {"
, " 'gallery-packed-enabled' : true,"
, " }"
, " </script>"
));
}
@Test public void Missing() {
fxt.Init_files_missing_y_();
fxt.Test_html_frag("<gallery>File:A.png|b</gallery>", "<div class=\"thumb\" style=\"height:150px;\">A.png</div>");
}
@Test public void Multiple() { // PURPOSE.bug: multiple galleries should not use same gallery super; DATE:2014-04-13
fxt.Test_html_frag("<gallery>File:A.png|a</gallery><gallery widths=180px>File:B.png|b</gallery>"
, "src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />" // should not be 180px from gallery #2
);
}
@Test public void Link_is_empty() { // PURPOSE: "link=" causes null pointer exception; DATE:2014-06-15
fxt.Test_html_frag("<gallery>File:A.png|link=</gallery>", String_.Concat_lines_nl_skip_last
( "<div style=\"margin:15px auto;\">"
, " <img id=\"xoimg_0\" alt=\"A.png\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
));
}
@Test public void Dangling_autcloses() { // PURPOSE: dangling gallery should auto-close, not escape; PAGE:en.w:Wikipedia:Featured_pictures_thumbs_43 DATE:2014-08-23
fxt.Test_html_frag("<gallery>File:A.png|b", "&lt;gallery&gt;File:A.png|b");
}
@Test public void Nested() { // PURPOSE: handle gallery nested inside ref; PAGE: es.w:Arquitectura_medieval DATE:2015-07-10
fxt.Test_html_frag(String_.Concat_lines_nl_skip_last
( "<gallery>"
, "File:A.jpg|A1"
, "File:B.jpg|B1 <ref>B2 <gallery>File:B11.jpg|B123./gallery></ref>" // NOTE: nested gallery
, "File:C.jpg|C1"
, "</gallery>"
), "C1" // make sure that image after nested gallery appears
);
}
@Test public void Alt__quotes() { // PURPOSE: file name with quotes will cause broken alt; PAGE:en.w:en.w:Alexandria,_Romania; DATE:2015-12-27
fxt.Test_html_frag("<gallery>File:A\"b.png</gallery>", "alt=\"A&quot;b.png\""); // NOTE: not 'alt="A"b.png"'
}
@Test public void Invalid() { // PURPOSE: ignore invalid file names; DATE:2016-01-12
fxt.Test_html_str("<gallery>File:#A.png|a</gallery>"
, String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, "</ul>"
));
}
@Test public void Hdump__div_1_w() {// PURPOSE: handle hdump and div_1_width == 115 instead of 15; PAGE:en.w:National_Gallery_of_Art; DATE:2016-06-19
fxt.Fxt().Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump);
fxt.Fxt().Wiki().File__fsdb_mode().Tid__v2__bld__y_(); // NOTE: must set to v2 mode; dflt will call old v1 img code which "guesses" at html_h;
fxt.Test_html_frag("<gallery widths=200px heights=200px perrow=5>File:A.png|a</gallery>", "<div style=\"margin:15px auto;\">");
}
}
class Gallery_mgr_base_fxt {
public void Reset() {
fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());
Gallery_mgr_wtr.File_found_mode = Bool_.Y_byte;
}
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Init_files_missing_y_() {
Gallery_mgr_wtr.File_found_mode = Bool_.N_byte;
}
public void Test_html_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
public void Test_html_frag(String raw, String... expd_frags) {fxt.Test_html_full_frag(raw, expd_frags);} // TODO_OLD: change to wiki_str; currently uids do not get reset if wiki
public void Test_html_frag_n(String raw, String... expd_frags) {fxt.Test_html_full_frag_n(raw, expd_frags);}
public void Test_html_modules_js(String expd) {
fxt.Page().Html_data().Head_mgr().Itm__globals().Enabled_n_();
fxt.Test_html_modules_js(expd);
}
}

View File

@@ -0,0 +1,63 @@
/*
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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
import gplx.xowa.htmls.*;
public class Gallery_mgr_base__xatrs__tst {
@Before public void init() {fxt.Reset();} private final Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt();
@Test public void Atr_misc() {// PURPOSE: add other atrs to end of ul
fxt.Test_html_frag
( "<gallery id=a>File:A.png</gallery>"
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" id=\"a\">"
);
}
@Test public void Atr_style() { // PURPOSE: combine style with itms_per_row
fxt.Test_html_frag
( "<gallery perrow=2 style='color:blue;'>File:A.png</gallery>"
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" style=\"max-width:326px; _width:326px; color:blue;\">"
);
}
@Test public void Atr_whitelist() { // PURPOSE: ignore atrs not in whitelist
fxt.Test_html_frag
( "<gallery onmouseover='alert();'>A.png</gallery>"
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
);
}
@Test public void Mgr_caption() { // PURPOSE: caption atr adds new element
fxt.Test_html_frag
( "<gallery caption=B>File:A.png</gallery>"
, "<li class=\"gallerycaption\">B</li>"
);
}
@Test public void Mgr_caption_ignore() { // PURPOSE: blank caption should not create caption element; PAGE:fr.w:Chronologie_du_si<73>ge_de_Paris_(1870) DATE:2014-08-15
fxt.Test_html_frag_n
( "<gallery caption=>File:A.png</gallery>"
, "<li class=\"gallerycaption\">"
);
}
@Test public void Show_filename() { // PURPOSE: show filename
fxt.Test_html_frag
( "<gallery showfilename=true>A.png</gallery>"
, "<div class=\"gallerytext\"><a href=\"/wiki/File:A.png\">File:A.png</a>"
);
}
//@Test public void Ttl_caption() { // PURPOSE: category entries get rendered with name only (no ns)
// fxt.Test_html_frag
// ( "<gallery>Category:A</gallery>"
// , "<li class='gallerycaption'>B</li>"
// );
//}
}

View File

@@ -0,0 +1,112 @@
/*
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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
public class Gallery_parser_tst {
@Before public void init() {fxt.Init();} private Gallery_parser_fxt fxt = new Gallery_parser_fxt();
@Test public void All() {fxt.Test_parse("File:A.png|a|alt=b|link=c" , fxt.Expd("File:A.png", "a" , "b" , "c"));}
@Test public void Ttl_only() {fxt.Test_parse("File:A.png" , fxt.Expd("File:A.png", null, null, null));}
@Test public void Ttl_url_encoded() {fxt.Test_parse("File:A%28b%29.png" , fxt.Expd("File:A(b).png"));} // PURPOSE: handle url-encoded sequences; DATE:2014-01-01
@Test public void Caption_only() {fxt.Test_parse("File:A.png|a" , fxt.Expd("File:A.png", "a" , null, null));}
@Test public void Caption_many() {fxt.Test_parse("File:A.png|a|b" , fxt.Expd("File:A.png", "b"));} // NOTE: keep last pipe
@Test public void Caption_many_lnki1(){fxt.Test_parse("File:A.png|a|[[b|c]]" , fxt.Expd("File:A.png", "[[b|c]]"));} // NOTE: ignore pipe in lnki
@Test public void Caption_many_lnki2(){fxt.Test_parse("File:A.png|[[b|c]]|d" , fxt.Expd("File:A.png", "d"));} // NOTE: ignore pipe in lnki
@Test public void Alt_only() {fxt.Test_parse("File:A.png|alt=a" , fxt.Expd("File:A.png", null, "a" , null));}
@Test public void Link_only() {fxt.Test_parse("File:A.png|link=a" , fxt.Expd("File:A.png", null, null, "a"));}
@Test public void Caption_alt() {fxt.Test_parse("File:A.png|a|alt=b" , fxt.Expd("File:A.png", "a" , "b"));}
@Test public void Alt_caption() {fxt.Test_parse("File:A.png|alt=a|b" , fxt.Expd("File:A.png", "b" , "a"));}
@Test public void Alt_blank() {fxt.Test_parse("File:A.png|alt=|b" , fxt.Expd("File:A.png", "b" , ""));}
@Test public void Alt_invalid() {fxt.Test_parse("File:A.png|alta=b" , fxt.Expd("File:A.png", "alta=b"));} // NOTE: invalid alt becomes caption
@Test public void Ws() {fxt.Test_parse("File:A.png| alt = b | c" , fxt.Expd("File:A.png", "c" , "b"));}
@Test public void Ws_caption_many() {fxt.Test_parse("File:A.png| a | b | c " , fxt.Expd("File:A.png", "c"));}
@Test public void Page_pdf() {fxt.Test_parse("File:A.pdf|page=1 " , fxt.Expd("File:A.pdf", null, null, null, 1));} // pdf parses page=1
@Test public void Page_png() {fxt.Test_parse("File:A.png|page=1 " , fxt.Expd("File:A.png", "page=1", null, null));} // non-pdf treats page=1 as caption
@Test public void Page_invalid() {fxt.Test_parse("|page=1");} // check that null title doesn't fail; DATE:2014-03-21
@Test public void Skip_blank() {fxt.Test_parse("");}
@Test public void Skip_empty() {fxt.Test_parse("|File:A.png");}
@Test public void Skip_ws() {fxt.Test_parse(" |File:A.png");}
@Test public void Skip_anchor() {fxt.Test_parse("#a");} // PURPOSE: anchor-like ttl should not render; ar.d:جَبَّارَة; DATE:2014-03-18
@Test public void Many() {
fxt.Test_parse("File:A.png\nFile:B.png" , fxt.Expd("File:A.png"), fxt.Expd("File:B.png"));
}
@Test public void Many_nl() {
fxt.Test_parse("File:A.png\n\n\nFile:B.png" , fxt.Expd("File:A.png"), fxt.Expd("File:B.png"));
}
@Test public void Many_nl_w_tab() {
fxt.Test_parse("File:A.png\n \t \nFile:B.png" , fxt.Expd("File:A.png"), fxt.Expd("File:B.png"));
}
@Test public void Many_invalid() {
fxt.Test_parse("File:A.png\n<invalid>\nFile:B.png" , fxt.Expd("File:A.png"), fxt.Expd("File:B.png"));
}
@Test public void Caption_complicated() {
fxt.Test_parse("File:A.png|alt=a|b[[c|d]]e ", fxt.Expd("File:A.png", "b[[c|d]]e", "a"));
}
@Test public void Link_null() { // PURPOSE: null link causes page to fail; EX: ru.w:Гянджа; <gallery>Datei:A.png|link= |</gallery>; DATE:2014-04-11
fxt.Test_parse("File:A.png|link = |b", fxt.Expd("File:A.png", "b", null, null));
}
@Test public void Caption_empty() { // PURPOSE: check that empty ws doesn't break caption (based on Link_null); DATE:2014-04-11
fxt.Test_parse("File:A.png| | | ", fxt.Expd("File:A.png", null, null, null));
}
@Test public void Alt__magic_word_has_arg() { // PURPOSE: img_alt magic_word is of form "alt=$1"; make sure =$1 is stripped for purpose of parser; DATE:2013-09-12
fxt.Init_kwd_set(Xol_kwd_grp_.Id_img_alt, "alt=$1");
fxt.Test_parse("File:A.png|alt=a|b", fxt.Expd("File:A.png", "b", "a"));
}
}
class Gallery_parser_fxt {
private Xoae_app app; private Xowe_wiki wiki;
private Gallery_parser parser;
public Gallery_parser_fxt Init() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
parser = new Gallery_parser();
parser.Init_by_wiki(wiki);
return this;
}
public String[] Expd(String ttl) {return new String[] {ttl, null, null, null, null};}
public String[] Expd(String ttl, String caption) {return new String[] {ttl, caption, null, null, null};}
public String[] Expd(String ttl, String caption, String alt) {return new String[] {ttl, caption, alt, null, null};}
public String[] Expd(String ttl, String caption, String alt, String link) {return new String[] {ttl, caption, alt, link, null};}
public String[] Expd(String ttl, String caption, String alt, String link, int page) {return new String[] {ttl, caption, alt, link, Int_.To_str(page)};}
public void Init_kwd_set(int kwd_id, String kwd_val) {
wiki.Lang().Kwd_mgr().Get_or_new(kwd_id).Itms()[0].Val_(Bry_.new_a7(kwd_val));
parser.Init_by_wiki(wiki);
}
public void Test_parse(String raw, String[]... expd) {
List_adp actl = List_adp_.New();
byte[] src = Bry_.new_a7(raw);
parser.Parse_all(actl, Gallery_mgr_base_.New(Gallery_mgr_base_.Tid__traditional), new Gallery_xnde(), src, 0, src.length);
Tfds.Eq_ary(String_.Ary_flatten(expd), String_.Ary_flatten(Xto_str_ary(src, actl)));
}
private String[][] Xto_str_ary(byte[] src, List_adp list) {
int len = list.Count();
String[][] rv = new String[len][];
for (int i = 0; i < len; i++) {
Gallery_itm itm = (Gallery_itm)list.Get_at(i);
String[] ary = new String[5];
rv[i] = ary;
ary[0] = String_.new_u8(itm.Ttl().Full_txt_w_ttl_case());
ary[2] = Xto_str_ary_itm(src, itm.Alt_bgn(), itm.Alt_end());
ary[3] = Xto_str_ary_itm(src, itm.Link_bgn(), itm.Link_end());
ary[4] = Xto_str_ary_itm(src, itm.Page_bgn(), itm.Page_end());
byte[] caption = itm.Caption_bry();
ary[1] = caption == null ? null : String_.new_u8(caption);
}
return rv;
}
private String Xto_str_ary_itm(byte[] src, int bgn, int end) {
return bgn == Bry_find_.Not_found && end == Bry_find_.Not_found ? null : String_.new_u8(src, bgn, end);
}
}

View File

@@ -0,0 +1,180 @@
/*
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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.wikis.ttls.*;
public class Gallery_xnde_tst {
private final Xop_fxt fxt = new Xop_fxt(); String raw_src;
@Before public void init() {fxt.Reset(); fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());}
@Test public void Lnki_no_caption() {
fxt.Test_parse_page_wiki("<gallery>File:A.png</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
));
}
@Test public void Lnki_1() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|b</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
));
}
@Test public void Lnki_3() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|a\nFile:B.png|b\nFile:C.png|c</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
, new_chkr_gallery_itm().Expd_lnki_("File:B.png")
, new_chkr_gallery_itm().Expd_lnki_("File:C.png")
)
));
}
@Test public void Ignore_newLines() {
fxt.Test_parse_page_wiki("<gallery>\n\n\nFile:A.png|a\n\n\nFile:B.png|b\n\n\n</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
, new_chkr_gallery_itm().Expd_lnki_("File:B.png")
)
));
}
@Test public void Only_first_pipe() {
fxt.Test_parse_page_wiki("<gallery>File:A.png|File:B.png|cc</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png")
)
));
}
@Test public void Invalid_lnki() {
fxt.Test_parse_page_wiki("<gallery>A.png|cc</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png") // NOTE: MW converts "A.png" to "File:A.png"
)
));
}
@Test public void File_only_trailing_nl() {
fxt.Test_parse_page_wiki("<gallery>File:A.png\n</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(null)
)
));
}
@Test public void Invalid_curly() {
raw_src = "a\n";
fxt.Test_parse_page_wiki("<gallery>File:A.png|" + raw_src + "}}</gallery>" // NOTE: }} is ignored since it is not a valid title
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_("a")
)
));
}
@Test public void Caption() {
raw_src = "a<br/>c";
fxt.Test_parse_page_wiki("<gallery>File:A.png|" + raw_src + "</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(raw_src)
)
));
}
@Test public void Xnde_atr() {
raw_src = "<center>a<br/>b</center>";
fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last
( "<gallery perrow=3>"
, "File:A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.jpg").Expd_caption_(raw_src)
)
));
}
@Test public void Err_pre() { // PURPOSE: leading ws was failing; PAGE:en.w:Vlaardingen; "\nA.jpg| <center>Visbank</center>\n"
raw_src = " <center>a</center>";
fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last
( "<gallery>"
, "File:A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.jpg").Expd_caption_("<center>a</center>")
)
));
}
@Test public void Err_comment() { // PURPOSE: comment was being rendered; PAGE:en.w:Perpetual motion; <!-- removed A.jpg|bcde -->
raw_src = "b";
fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last
( "<gallery>"
, "<!-- deleted A.jpg|" + raw_src
, "</gallery>"
) , fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_()
)
);
}
@Test public void Misc_atr() { // make sure misc attribute doesn't fail
raw_src = "b";
fxt.Test_parse_page_wiki("<gallery id=a>File:A.png|" + raw_src + "</gallery>"
, fxt.tkn_xnde_().Xnde_tagId_(Xop_xnde_tag_.Tid__gallery).Xnde_xtn_
( new_chkr_gallery_mgr().Expd_subs_
( new_chkr_gallery_itm().Expd_lnki_("File:A.png").Expd_caption_(raw_src)
)
));
}
private Gallery_mgr_data_chkr new_chkr_gallery_mgr() {return new Gallery_mgr_data_chkr();}
private Gallery_itm_chkr new_chkr_gallery_itm() {return new Gallery_itm_chkr();}
}
class Gallery_mgr_data_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Gallery_xnde.class;}
public Gallery_itm_chkr[] Expd_subs() {return expd_subs;} public Gallery_mgr_data_chkr Expd_subs_(Gallery_itm_chkr... v) {expd_subs = v; return this;} Gallery_itm_chkr[] expd_subs = null;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Gallery_xnde actl = (Gallery_xnde)actl_obj;
int rv = 0;
rv += Chk_basic(mgr, path, actl, rv);
rv += Chk_subs(mgr, path, actl, rv);
return rv;
}
public int Chk_basic(Tst_mgr mgr, String path, Gallery_xnde actl, int err) {
return err;
}
public int Chk_subs(Tst_mgr mgr, String path, Gallery_xnde actl, int err) {
if (expd_subs != null) {
int actl_subs_len = actl.Itms_len();
Gallery_itm[] actl_subs = new Gallery_itm[actl_subs_len];
for (int i = 0; i < actl_subs_len; i++)
actl_subs[i] = actl.Itms_get_at(i);
return mgr.Tst_sub_ary(expd_subs, actl_subs, path, err);
}
return err;
}
}
class Gallery_itm_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Gallery_itm.class;}
public Gallery_itm_chkr Expd_lnki_(String v) {expd_lnki = Xoa_ttl_chkr.new_(v); return this;} private Xoa_ttl_chkr expd_lnki;
public Gallery_itm_chkr Expd_caption_(String v) {expd_caption = v; return this;} private String expd_caption;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Gallery_itm actl = (Gallery_itm)actl_obj;
int err = 0;
err += mgr.Tst_sub_obj(expd_lnki, actl.Ttl(), path, err);
err += mgr.Tst_val(expd_caption == null, "", "caption", expd_caption, String_.new_u8(actl.Caption_bry()));
return err;
}
}

View File

@@ -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.xtns.geoCrumbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Geoc_isin_func_tst {
@Before public void init() {fxt.Reset();} private Geoc_isin_func_fxt fxt = new Geoc_isin_func_fxt();
@Test public void Basic() {
fxt.Test_parse("{{#isin:A}}", "<a href=\"/wiki/A\">A</a>");
}
}
class Geoc_isin_func_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
}
public void Test_parse(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}" , "");
Tfds.Eq(expd, String_.new_u8(fxt.Page().Html_data().Content_sub()));
}
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.geodata; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Geo_coordinates_func_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {fxt.Test_parse_tmpl_str_test("{{#coordinates:1|2}}" , "{{test}}" , "");}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Hiero_html_mgr_fxt {
private Hiero_xtn_mgr xtn_mgr;
public Hiero_html_mgr_fxt(Xop_fxt fxt) {this.fxt = fxt;}
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
public void Reset() {
fxt.Reset();
xtn_mgr = new Hiero_xtn_mgr();
xtn_mgr.Xtn_init_by_app(fxt.App());
xtn_mgr.Clear();
}
public Hiero_html_mgr_fxt Init_hiero_A1_B1() {
this.Init_file("A1", 29, 38);
this.Init_file("B1", 23, 38);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_cartouche() {
this.Init_phoneme("<", "Ca1");
this.Init_phoneme(">", "Ca2");
return this;
}
public Hiero_html_mgr_fxt Init_hiero_p_t() {
this.Init_phoneme("p", "Q3");
this.Init_phoneme("t", "X1");
this.Init_file("Q3", 12, 15);
this.Init_file("X1", 20, 11);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_a_A1() {
this.Init_prefab("a&A1");
this.Init_file("a&A1", 37, 38);
return this;
}
public Hiero_html_mgr_fxt Init_prefab(String prefab) {xtn_mgr.Prefab_mgr().Add(Bry_.new_u8(prefab)); return this;}
public Hiero_html_mgr_fxt Init_file(String s, int w, int h) {xtn_mgr.File_mgr().Add(Bry_.new_u8(s), w, h); return this;}
public Hiero_html_mgr_fxt Init_phoneme(String phoneme, String code) {xtn_mgr.Phoneme_mgr().Add(Bry_.new_u8(phoneme), Bry_.new_u8(code)); return this;}
public void Test_html_full_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
public void Test_html_full_frag(String raw, String expd) {fxt.Test_html_full_frag(raw, expd);}
}

View File

@@ -0,0 +1,387 @@
/*
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.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Hiero_html_mgr_tst {
@Before public void init() {fxt.Reset();} private Hiero_html_mgr_fxt fxt = new Hiero_html_mgr_fxt(new Xop_fxt());
@Test public void Empty() {
fxt.Test_html_full_str
( "<hiero></hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, ""
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Glyph_1() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str
( "<hiero>A1</hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Mirrored() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str
( "<hiero>A1\\</hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img class=\"mw-mirrored\" style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Glyph_2() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str("<hiero>A1-B1</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Void_half() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str
( "<hiero>A1 . B1</hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " <td>"
, " <table class=\"mw-hiero-table\" style=\"width: 22px;\">"
, " <tr>"
, " <td>&#160;"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Void_full() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str
( "<hiero>A1 .. B1</hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " <td>"
, " <table class=\"mw-hiero-table\" style=\"width: 44px;\">"
, " <tr>"
, " <td>&#160;"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void New_line() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str
( "<hiero>A1 ! B1</hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Cartouche() {
fxt.Init_hiero_A1_B1().Init_hiero_cartouche();
fxt.Test_html_full_str
( "<hiero>< A1 ></hiero>"
, String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Ca1.png' height='44' title='&lt;' alt='&lt;' />"
, " </td>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td class='mw-hiero-box' style='height: 2px;'>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td class='mw-hiero-box' style='height: 2px;'>"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " <td>"
, " <img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Ca2.png' height='44' title='&gt;' alt='&gt;' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Superposition_regular() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str("<hiero>A1:B1</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 20px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
, " <br/>"
, " <img style='margin: 1px; height: 20px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Superposition_phoneme() {
fxt.Init_hiero_p_t();
fxt.Test_html_full_str("<hiero>t:p</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 11px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t' />"
, " <br/>"
, " <img style='margin: 1px; height: 15px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Q3.png' title='Q3 [p]' alt='p' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Superposition_prefab() {
fxt.Init_hiero_a_A1();
fxt.Test_html_full_str("<hiero>a:A1</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&amp;A1.png' title='a&amp;A1' alt='a&amp;A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Juxtaposition_regular() {
fxt.Init_hiero_A1_B1();
fxt.Test_html_full_str("<hiero>A1*B1</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' /> "
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Juxtaposition_phoneme() {
fxt.Init_hiero_p_t();
fxt.Test_html_full_str("<hiero>t*p</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 11px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t' /> "
, " <img style='margin: 1px; height: 15px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Q3.png' title='Q3 [p]' alt='p' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Juxtaposition_prefab() {
fxt.Init_hiero_a_A1();
fxt.Test_html_full_str("<hiero>a*A1</hiero>", String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, " <table class=\"mw-hiero-table\">"
, " <tr>"
, " <td>"
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&amp;A1.png' title='a&amp;A1' alt='a&amp;A1' />"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Para_if_text() {// PURPOSE: check that paras are handled correctly; EX: w:Hieroglyphics; DATE:2014-04-23
fxt.Fxt().Init_para_y_();
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "a" // should always be in <p>
, ""
, "<hiero></hiero> b" // <hiero> should not be in <p> but "b" should be;
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, ""
, " </td>"
, " </tr>"
, "</table>"
, ""
, "<p> b" // NOTE: space seems wrong, but is "harmless"
, "</p>"
));
fxt.Fxt().Init_para_n_();
}
@Test public void Para_skip_if_list() {// PURPOSE: do not add para if in list; EX:de.d:Damascus; DATE:2014-06-06
fxt.Fxt().Init_para_y_();
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( ":<hiero></hiero> a" // a should not be in para
, ":b"
), String_.Concat_lines_nl_skip_last
( "<dl>"
, " <dd><table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, ""
, " </td>"
, " </tr>"
, "</table>"
, " a"
, " </dd>"
, " <dd>b"
, " </dd>"
, "</dl>"
));
fxt.Fxt().Init_para_n_();
}
}

View File

@@ -0,0 +1,73 @@
/*
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.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
import gplx.core.intls.*;
public class Hiero_mw_tables_parser_tst {
@Before public void init() {fxt.Reset();} private Hiero_mw_tables_parser_fxt fxt = new Hiero_mw_tables_parser_fxt();
@Test public void Basic() {// DATE:2014-04-19
fxt.Test_bld_all
( String_.Concat_lines_nl_skip_last
( "$wh_prefabs = array("
, " \"a&A1\","
, " \"Z6&A1\","
, ");"
, ""
, "$wh_files = array("
, " \"a&A1\" => array( 37, 38 ),"
, " \"Z98A\" => array( 5, 15 ),"
, ");"
, ""
, "$wh_phonemes = array("
, " \"mSa\" => \"A12\","
, " \"\\\"]\" => \"\","
, ");"
)
, String_.Concat_lines_nl_skip_last
( "prefabs.srl.load_by_str('"
, "a&A1"
, "Z6&A1"
, "');"
, ""
, "files.srl.load_by_str('"
, "a&A1|37|38"
, "Z98A|5|15"
, "');"
, ""
, "phonemes.srl.load_by_str("
, "<:['"
, "mSa|A12"
, "\"]|"
, "']:>"
, ");"
)
);
}
}
class Hiero_mw_tables_parser_fxt {
private Hiero_mw_tables_parser parser = new Hiero_mw_tables_parser();
public void Reset() {}
public void Test_bld_all(String raw, String expd) {
Io_url load_url = Io_url_.mem_fil_("mem/hiero/load.php");
Io_url save_url = Io_url_.mem_fil_("mem/hiero/save.php");
Io_mgr.Instance.SaveFilStr(load_url, raw);
parser.Bld_all(load_url, save_url);
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(save_url));
}
public void Exec_bld_all(String load, String save) {
parser.Bld_all(Io_url_.new_fil_(load), Io_url_.new_fil_(save));
}
}

View File

@@ -0,0 +1,57 @@
/*
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.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Hiero_parser_tst {
@Before public void init() {fxt.Reset();} private Hiero_parser_fxt fxt = new Hiero_parser_fxt();
@Test public void Separator() {
String[][] expd = new String[][] {fxt.block_("A1"), fxt.block_("B1")};
fxt.Test_parse("A1 B1" , expd); // space
fxt.Test_parse("A1-B1" , expd); // dash
fxt.Test_parse("A1\tB1" , expd); // tab
fxt.Test_parse("A1\nB1" , expd); // nl
fxt.Test_parse("A1\rB1" , expd); // cr
fxt.Test_parse("A1 B1" , expd); // many: space
fxt.Test_parse("A1 \t\nB1" , expd); // many: mixed
}
}
class Hiero_parser_fxt {
private Hiero_parser parser;
public void Reset() {
parser = new Hiero_parser();
parser.Init();
}
public String[] block_(String... v) {return v;}
public void Test_parse(String raw, String[]... expd) {
byte[] raw_bry = Bry_.new_a7(raw);
Hiero_block[] actl = parser.Parse(raw_bry, 0, raw_bry.length);
Tfds.Eq_ary(String_.Ary_flatten(expd), String_.Ary_flatten(Xto_str(actl)));
}
private String[][] Xto_str(Hiero_block[] ary) {
int len = ary.length;
String[][] rv = new String[len][];
for (int i = 0; i < len; i++) {
Hiero_block itm = ary[i];
int itm_len = itm.Len();
String[] rv_sub = new String[itm_len];
rv[i] = rv_sub;
for (int j = 0; j < itm_len; j++) {
rv_sub[j] = String_.new_u8(itm.Get_at(j));
}
}
return rv;
}
}

View File

@@ -0,0 +1,45 @@
/*
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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.xowa.parsers.*;
import gplx.xowa.xtns.imaps.itms.*;
public class Imap_base_fxt {
protected Xoae_app app; protected Xowe_wiki wiki;
@gplx.Virtual public void Reset() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
wiki.Parser_mgr().Ctx().Para().Enabled_n_();
}
public Imap_part_shape itm_rect_(String link, double... pts_ary) {return itm_shape_(Imap_part_.Tid_shape_rect, link, pts_ary);}
public Imap_part_shape itm_circle_(String link, double... pts_ary) {return itm_shape_(Imap_part_.Tid_shape_circle, link, pts_ary);}
public Imap_part_shape itm_poly_(String link, double... pts_ary) {return itm_shape_(Imap_part_.Tid_shape_poly, link, pts_ary);}
private Imap_part_shape itm_shape_(byte tid, String link, double... pts_ary) {
int pts_len = pts_ary.length;
Double_obj_val[] pts_doubles = new Double_obj_val[pts_len];
for (int i = 0; i < pts_len; ++i)
pts_doubles[i] = Double_obj_val.new_(pts_ary[i]);
byte[] link_bry = Bry_.new_u8(link);
Imap_part_shape rv = new Imap_part_shape(tid, pts_doubles);
Imap_link_owner_.Init(rv, app, wiki, link_bry, Make_link_tkn(link_bry));
return rv;
}
private Xop_tkn_itm Make_link_tkn(byte[] src) {
Xop_root_tkn root_tkn = new Xop_root_tkn();
wiki.Parser_mgr().Main().Parse_text_to_wdom(root_tkn, wiki.Parser_mgr().Ctx(), app.Parser_mgr().Tkn_mkr(), src, Xop_parser_.Doc_bgn_bos);
return root_tkn.Subs_get(0);
}
}

View File

@@ -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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.parsers.*; import gplx.xowa.xtns.imaps.itms.*;
public class Imap_parser_tst {
@Before public void init() {fxt.Reset();} private Imap_parser_fxt fxt = new Imap_parser_fxt();
@Test public void Rect_pass() {fxt.Test_shape("rect 1 2 3 4 [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));}
@Test public void Rect_pass_many() {fxt.Test_shape("rect 1 2 3 4 5 6[[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));} // PURPOSE: MW allows extra points to be passed; PAGE:en.w:Kilauea DATE:2014-07-28
@Test public void Rect_pass_invalid() {fxt.Test_shape("rect 1 2 3 4 a b [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));} // PURPOSE: MW only scans first 4 tokens for numbers; PAGE:de.w:Wilhelm_Angele DATE:2014-10-30
@Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));}
@Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));}
@Test public void Poly_pass_chars() {fxt.Test_shape("poly a b [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:uk.w:Стратосфера; DATE:2014-07-26
@Test public void Poly_pass_chars_2() {fxt.Test_shape("poly 1a 2a [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:ru.w:Системный_блок; DATE:2014-10-22
@Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
@Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12
@Test public void Poly_pass_commas_3() {fxt.Test_shape("poly ,1 2 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2));} // PURPOSE: do not fail if comma is at start of number; PAGE:en.w:Area_codes_281,_346,_713,_and_832; DATE:2015-07-31
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
@Test public void Poly_fail_zero() {fxt.Test_shape_err("poly [[A]]" , "imagemap_missing_coord");}
@Test public void Circle_fail_invalid() {fxt.Test_shape_err("rect 1 2..3 4 [[A]]" , "imagemap_invalid_coord");}
}
class Imap_parser_fxt extends Imap_base_fxt {
private Imap_parser parser;
private Imap_map imap;
@Override public void Reset() {
super.Reset();
byte[] ttl_bry = Bry_.new_a7("Test_1");
Imap_xtn_mgr xtn_mgr = new Imap_xtn_mgr();
Xoae_page page = Xoae_page.New(wiki, wiki.Ttl_parse(ttl_bry));
parser = new Imap_parser(xtn_mgr);
parser.Init(wiki, page, Gfo_usr_dlg_.Noop);
parser.Clear();
imap = new Imap_map(1);
}
public void Test_shape(String raw_str, Imap_part_shape expd) {
raw_str = "File:A.png\n" + raw_str;
byte[] raw = Bry_.new_u8(raw_str);
parser.Parse(imap, raw, 0, raw.length);
Imap_part_shape[] actl_ary = imap.Shapes();
Imap_part_shape actl = actl_ary == null | actl_ary.length != 1 ? null : (Imap_part_shape)actl_ary[0];
if (actl == null && expd == null) {} // noop; test passed
else if (actl == null && expd != null) {Tfds.Fail("actl should not be null", raw);}
else if (actl != null && expd == null) {Tfds.Fail("actl should be null", raw);}
else {
Tfds.Eq(expd.Part_tid(), actl.Part_tid(), "tid");
Tfds.Eq_ary(expd.Shape_pts(), actl.Shape_pts(), "pts");
Tfds.Eq(String_.new_u8(expd.Link_href()), String_.new_u8(actl.Link_href()));
Tfds.Eq(String_.new_u8(expd.Link_text()), String_.new_u8(actl.Link_text()));
}
Tfds.Eq(0, imap.Errs().length, "expd 0 errors");
}
public void Test_shape_err(String raw_str, String expd_err) {
raw_str = "File:A.png\n" + raw_str;
byte[] raw = Bry_.new_u8(raw_str);
parser.Parse(imap, raw, 0, raw.length);
Imap_err[] err_ary = imap.Errs();
Tfds.Eq(1, err_ary.length, "expd 1 err");
Tfds.Eq(expd_err, err_ary[0].Err_msg());
}
}

View File

@@ -0,0 +1,46 @@
/*
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.xtns.imaps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.imaps.*;
import org.junit.*;
import gplx.xowa.htmls.core.htmls.*;
public class Imap_html__hdump__tst {
@Before public void init() {fxt.Reset(); fxt.Fxt().Hctx_(Xoh_wtr_ctx.Hdump);} private final Imap_xnde_html_fxt fxt = new Imap_xnde_html_fxt();
@Test public void Basic() {
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|100x200px|a1"
, "circle 0 0 5 [[B|b1]]"
, "rect 0 0 4 8 [[C|c1]]"
, "desc none"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div class=\"thumbinner\" style=\"width:100px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
, " <div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " <area href=\"/wiki/C\" shape=\"rect\" coords=\"0,0,4,8\" alt=\"c1\" title=\"c1\"/>"
, " </map>"
, " <img data-xowa-title=\"A.png\" data-xoimg=\"1|100|200|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" alt=\"\" usemap=\"#imagemap_1_1\"/>"
, " </div>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
, " </div>"
, " </div>"
, "</div>"
));
}
}

View File

@@ -0,0 +1,206 @@
/*
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.xtns.imaps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.imaps.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Imap_html__hview__tst {
@Before public void init() {fxt.Reset();} private final Imap_xnde_html_fxt fxt = new Imap_xnde_html_fxt();
@Test public void Basic() {
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|123px|a1"
, "circle 0 0 5 [[B|b1]]"
, "rect 0 0 4 8 [[C|c1]]"
, "desc none"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
, " <div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " <area href=\"/wiki/C\" shape=\"rect\" coords=\"0,0,4,8\" alt=\"c1\" title=\"c1\"/>"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " </div>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Caption_xml() { // PURPOSE: xnde in caption was being escaped; PAGE:en.w:Council_of_Europe; DATE:2014-07-25
fxt.Test_html_full_frag("<imagemap>File:A.png|thumb|<b>c</b>\n</imagemap>", "<b>c</b>");
}
@Test public void Default() {
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|123px|a1"
, "default [[B|b1]]"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
, " <div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <a href=\"/wiki/B\" title=\"b1\">"
, " <img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " </a>"
, " </div>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Desc() {
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|123px|a1"
, "desc top-left"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div id=\"imap_div_0\" class=\"noresize\" style=\"height:0px; width: 123px;\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"a1\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " <div style=\"margin-left:0px; margin-top:1px; text-align:left;\">"
, " <a href=\"/wiki/File:A.png\" title=\"click here\">"
, " <img alt=\"click here\" src=\"file:///mem/xowa/bin/any/xowa/xtns/ImageMap/imgs/desc-20.png\" style=\"border: none;\" />"
, " </a>"
, " </div>"
, " </div>"
));
}
@Test public void Lnke() { // PURPOSE: handle shapes with lnke; PAGE:en.w:Cholesterolt DATE:2014-07-25
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|123px|a1"
, "circle 0 0 5 [[http://b.org b1]]"
, "desc none"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
, " <div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"http://b.org\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " </div>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Err_trailing_ws() { // PURPOSE: empty 1st line causes failure
fxt.Test_html_full_frag(String_.Concat_lines_nl_skip_last
( "<imagemap> "
, "File:A.png|thumb|test_caption"
, "</imagemap>"
), "test_caption" // no error if test_caption appears;
);
}
@Test public void Para_omitted() { // PURPOSE: imagemap should not be automatically enclosed in para; PAGE:cs.w:Seznam_clenu_ctrn<72>ct<63>ho_Knesetu; DATE:2014-05-08;
fxt.Fxt().Init_para_y_();
fxt.Test_html_full_str("<imagemap>File:A.png</imagemap> a", fxt.Frag_html_full() + " a"); // NOTE: "a" no longer enclosed in <p>; DATE:2014-07-25
fxt.Fxt().Init_para_n_();
}
@Test public void Xnde_double_pipe() {// PURPOSE: if || is inside table and imagemap, treat as lnki; EX:w:United_States_presidential_election,_1992; DATE:2014-03-29; DATE:2014-05-06
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "| z"
, "<imagemap>"
, "File:A.png||123px|b" // NOTE: "||" should not be tblw; also should not be pipe + text; if it is pipe + text, then caption will be "|123px" and width will be -1; DATE:2014-05-06
, "</imagemap>"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td> z"
, "<div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>" // NOTE: width must be 123, not 0
, " </div>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Template_image() { // PURPOSE: handle templates in caption; PAGE:en.w:Kilauea; DATE:2014-07-27
fxt.Fxt().Init_page_create("Template:Test_template", "xyz");
fxt.Test_html_full_frag("<imagemap>File:A.png|thumb|{{Test_template}}\n</imagemap>", "xyz");
}
@Test public void Template_shape() { // PURPOSE: handle templates in shape; PAGE:fr.w:Arrondissements_de_Lyon DATE:2014-08-12
fxt.Fxt().Init_page_create("Template:B1", "<b>b1</b>"); // note that an xnde is a better example as it will throw ArrayOutOfBounds error
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|123px|a1"
, "circle 0 0 5 [[B|{{b1}}]]"
, "desc none"
, "</imagemap>"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
, " <div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " </div>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
, " </div>"
, " </div>"
, "</div>"
));
}
@Test public void Template_multi_line() { // PURPOSE: handle multiple-line captions; PAGE:en.w:Archaea; DATE:2014-08-22
fxt.Test_html_full_frag(String_.Concat_lines_nl_skip_last
( "<imagemap>"
, "File:A.png|thumb|<ref>text"
, "</ref>"
, "</imagemap>"
), "id=\"cite_ref-0\"");
}
}
class Imap_xnde_html_fxt {
public void Reset() {
fxt.Reset();
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_a7("imagemap_description"));
msg.Atrs_set(Bry_.new_a7("click here"), false, false);
}
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Test_html_full_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
public void Test_html_full_frag(String raw, String expd) {fxt.Test_html_full_frag(raw, expd);}
public String Frag_html_full() {
return String_.Concat_lines_nl_skip_last
( "<div id=\"imap_div_0\" class=\"noresize\">"
, " <map name=\"imageMap_1_1\">"
, " </map>"
, " <img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
, " </div>"
);
}
}

View File

@@ -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.xtns.imaps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.imaps.*;
import org.junit.*; import gplx.xowa.xtns.imaps.itms.*;
public class Imap_shapes_arg_tst {
@Before public void init() {fxt.Reset();} private Imap_shapes_arg_fxt fxt = new Imap_shapes_arg_fxt();
@Test public void Rect() {fxt.Test_shape_html(fxt.itm_rect_("[[A|b]]", 1, 2, 3, 4), "\n <area href=\"/wiki/A\" shape=\"rect\" coords=\"1,2,3,4\" alt=\"b\" title=\"b\"/>");}
@Test public void Circle() {fxt.Test_shape_html(fxt.itm_circle_("[[A|b]]", 1, 2, 3 ), "\n <area href=\"/wiki/A\" shape=\"circle\" coords=\"1,2,3\" alt=\"b\" title=\"b\"/>");}
@Test public void Poly() {fxt.Test_shape_html(fxt.itm_poly_("[[A|b]]", 1, 2, 3, 4), "\n <area href=\"/wiki/A\" shape=\"poly\" coords=\"1,2,3,4\" alt=\"b\" title=\"b\"/>");}
}
class Imap_shapes_arg_fxt extends Imap_base_fxt {
public void Test_shape_html(Imap_part_shape shape, String expd) {
Bry_bfr bfr = Bry_bfr_.New();
Imap_shape_pts_arg pts_fmtr_arg = new Imap_shape_pts_arg(1);
Imap_shapes_arg.Fmt_shape(bfr, Imap_html_fmtrs.Area, pts_fmtr_arg, shape);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,64 @@
/*
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.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.xtns.indicators.*;
public class Indicator_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Indicator_html_bldr_fxt fxt = new Indicator_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_indicator("a", "a1");
fxt.Init_indicator("b", "b1");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( ""
, " <div class='mw-indicators'>"
, " <div id='mw-indicator-b' class='mw-indicator'>b1</div>" // reverse-order
, " <div id='mw-indicator-a' class='mw-indicator'>a1</div>"
, " </div>"
));
}
@Test public void Multiple_ignore() {
fxt.Init_indicator("a", "a1");
fxt.Init_indicator("a", "a2");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( ""
, " <div class='mw-indicators'>"
, " <div id='mw-indicator-a' class='mw-indicator'>a2</div>" // 2nd overwrites 1st
, " </div>"
));
}
}
class Indicator_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Indicator_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
this.xtn_mgr = wiki.Xtn_mgr().Xtn_indicator();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
this.page = wiki.Parser_mgr().Ctx().Page();
}
public void Init_indicator(String name, String html) {
Indicator_xnde xnde = new Indicator_xnde();
xnde.Init_for_test(name, Bry_.new_u8(html));
Indicator_html_bldr indicators = page.Html_data().Indicators();
indicators.Add(xnde);
}
public void Test_bld(String expd) {
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
page.Html_data().Indicators().Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Indicator_xnde_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("<indicator name='a'>test</indicator>", "");
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.inputBox; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xtn_inputbox_nde_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_wiki_str("a<inputbox>b</inputbox>c", "ac");
}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Insider_func_tst {
@Before public void init() {fxt.Reset();} private Insider_func_fxt fxt = new Insider_func_fxt();
@Test public void Basic() {
fxt.Test_parse("{{#insider:A}}x{{#insider:B}}", "x", "A", "B");
}
}
class Insider_func_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
}
public void Test_parse(String raw, String expd, String... insiders) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
Insider_xtn_skin_itm skin_itm = (Insider_xtn_skin_itm)fxt.Page().Html_data().Xtn_skin_mgr().Get_or_null(Insider_xtn_skin_itm.KEY);
List_adp list = skin_itm.Itms();
byte[][] brys = (byte[][])list.To_ary(byte[].class);
Tfds.Eq_ary_str(insiders, String_.Ary(brys));
}
}

View File

@@ -0,0 +1,60 @@
/*
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.xtns.insiders; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Insider_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Insider_html_bldr_fxt fxt = new Insider_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_insider("A_1");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( "<div id='p-insiders' class='portal' role='navigation'>"
, " <h3>Docent</h3>"
, " <div class='body'>"
, " <ul>"
, " <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/User:A_1'>A 1</a></li>"
, " <li class='interwiki-insider'><a class='xowa-hover-off' href='/wiki/Docent_page'>About Docents</a></li>"
, " </ul>"
, " </div>"
, "</div>"
));
}
}
class Insider_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Insider_xtn_mgr xtn_mgr;
private Insider_xtn_skin_itm skin_itm;
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xop_fxt.Init_msg(wiki, "insider-title", "Docent");
Xop_fxt.Init_msg(wiki, "insider-about", "About Docents");
Xop_fxt.Init_msg(wiki, "insider-about-page", "Docent_page");
this.xtn_mgr = wiki.Xtn_mgr().Xtn_insider();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
this.page = wiki.Parser_mgr().Ctx().Page();
skin_itm = new Insider_xtn_skin_itm(xtn_mgr.Html_bldr());
page.Html_data().Xtn_skin_mgr().Add(skin_itm);
}
public void Init_insider(String lnki_ttl) {
skin_itm.Add(Bry_.new_u8(lnki_ttl));
}
public void Test_bld(String expd) {
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
skin_itm.Write(tmp_bfr, page);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.kartographers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Mapframe_xnde__tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<mapframe latitude='42.68' longitude='-114.79' zoom='3'>"
, "{ 'type':'Feature'"
, ", 'geometry': {}"
, "</mapframe>"
), ""
);
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.kartographers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Maplink_xnde__tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
( "<maplink zoom=9 latitude=37.8013 longitude=-122.3988>"
, "{ 'type':'Feature'"
, ", 'geometry': {}"
, "</maplink>"
), ""
);
}
}

View File

@@ -0,0 +1,106 @@
/*
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.xtns.listings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Listing_xnde_basic_tst {
private final Xop_fxt fxt = new Xop_fxt();
private Listing_xtn_mgr listings_xtn_mgr;
@Before public void init() {
fxt.Reset_for_msgs();
Listing_xnde_basic_tst.Add_listing_msgs(fxt.Wiki());
listings_xtn_mgr = (Listing_xtn_mgr)fxt.Wiki().Xtn_mgr().Get_or_fail(Listing_xtn_mgr.Xtn_key_static);
listings_xtn_mgr.Enabled_y_();
listings_xtn_mgr.Xtn_init_by_wiki(fxt.Wiki());
}
@Test public void Url() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' url='http://site.org'/>"
, "<a href=\"http://site.org\" rel=\"nofollow\" class=\"external text\" title=\"name_0\"><strong>name_0</strong></a>. "
);
}
@Test public void Alt() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' alt=\"''alt_0''\"/>"
, "<strong>name_0</strong> (<em><i>alt_0</i></em>). "
);
}
@Test public void Address_directions() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' address='address_0' directions='directions_0'/>"
, "<strong>name_0</strong>, address_0 (<em>directions_0</em>). "
);
}
@Test public void Phone_tollfree() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' phone='phone_0' tollfree='tollfree_0'/>"
, "<strong>name_0</strong>, <abbr title=\"phone\">☎</abbr> phone_0 (toll-free: tollfree_0). "
);
}
@Test public void Fax() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' fax='fax_0'/>"
, "<strong>name_0</strong>, fax: fax_0. "
);
}
@Test public void Email() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' email='email_0'/>"
, "<strong>name_0</strong>, email: <a href=\"mailto:email_0\" class=\"email\">email_0</a>. "
);
}
@Test public void Hours() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' hours='hours_0'/>"
, "<strong>name_0</strong>. hours_0. "
);
}
@Test public void Checkin_checkout() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' checkin='checkin_0' checkout='checkout_0'/>"
, "<strong>name_0</strong>. Check-in: checkin_0, check-out: checkout_0. "
);
}
@Test public void Price() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0' price='price_0'/>"
, "<strong>name_0</strong>. price_0. "
);
}
@Test public void Content() {
fxt.Test_parse_page_all_str
( "<sleep name='name_0'>content_0</sleep>"
, "<strong>name_0</strong>. content_0"
);
}
public static void Add_listing_msgs(Xowe_wiki wiki) {
Xol_msg_mgr msg_mgr = wiki.Lang().Msg_mgr();
msg_mgr.Itm_by_key_or_new("listings-unknown", "Unknown destination");
msg_mgr.Itm_by_key_or_new("listings-desc", "Add tags for listing locations");
msg_mgr.Itm_by_key_or_new("listings-phone", "phone");
msg_mgr.Itm_by_key_or_new("listings-phone-symbol", "");
msg_mgr.Itm_by_key_or_new("listings-fax", "fax");
msg_mgr.Itm_by_key_or_new("listings-fax-symbol", "");
msg_mgr.Itm_by_key_or_new("listings-email", "email");
msg_mgr.Itm_by_key_or_new("listings-email-symbol", "");
msg_mgr.Itm_by_key_or_new("listings-tollfree", "toll-free");
msg_mgr.Itm_by_key_or_new("listings-tollfree-symbol", "");
msg_mgr.Itm_by_key_or_new("listings-checkin", "Check-in: ~{0}", true);
msg_mgr.Itm_by_key_or_new("listings-checkout", "check-out: ~{0}");
msg_mgr.Itm_by_key_or_new("listings-desc", "Add tags for listing locations");
msg_mgr.Itm_by_key_or_new("listings-position", "position: ~{0}");
msg_mgr.Itm_by_key_or_new("listings-position-template", "");
}
}

View File

@@ -0,0 +1,141 @@
/*
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.xtns.listings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Listing_xnde_template_tst {
private final Xop_fxt fxt = new Xop_fxt();
private Listing_xtn_mgr listings_xtn_mgr;
@Before public void init() {
fxt.Reset_for_msgs();
Listing_xnde_basic_tst.Add_listing_msgs(fxt.Wiki());
listings_xtn_mgr = (Listing_xtn_mgr)fxt.Wiki().Xtn_mgr().Get_or_fail(Listing_xtn_mgr.Xtn_key_static);
listings_xtn_mgr.Clear();
listings_xtn_mgr.Enabled_y_();
}
private void Init_xtn_mgr() {listings_xtn_mgr.Xtn_init_by_wiki(fxt.Wiki());}
@Test public void Disabled() {
listings_xtn_mgr.Enabled_n_();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' address='address_0'>content_0</sleep>"
, "&lt;sleep name='name_0' address='address_0'&gt;content_0&lt;/sleep&gt;"
);
}
@Test public void Ignore_empty() {
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' alt='' address='' directions='' phone='' url='' checkin='' checkout='' price='' lat='' long=''> </sleep>"
, "<strong>name_0</strong>. "
);
}
@Test public void Ignore_invalid() { // PURPOSE: invalid atrs were causing null reference exception; PAGE:nl.v:Rome;EX:<sleep phone='' "abc"/> DATE:2014-06-04
fxt.Init_page_create("Template:ListingsSample", "{{{name|nil_name}}};{{{address|nil_address}}};{{{1|nil_content}}}");
fxt.Init_page_create("MediaWiki:listings-template", "ListingsSample");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' 'invalid'></sleep>"
, "name_0;nil_address;"
);
}
@Test public void Template() {
fxt.Init_page_create("Template:ListingsSample", "{{{name|nil_name}}};{{{address|nil_address}}};{{{1|nil_content}}}");
fxt.Init_page_create("MediaWiki:listings-template", "ListingsSample");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' address='address_0'>content_0</sleep>"
, "name_0;address_0;content_0"
);
}
@Test public void Template_lat() { // PURPOSE: lat / long was not being set for listings sample; PAGE:fr.v:Marrakech; DATE:2014-05-21
fxt.Init_page_create("Template:ListingsSample2", "{{{name|nil_name}}};{{{lat|nil_lat}}};{{{long|nil_long}}}");
fxt.Init_page_create("MediaWiki:listings-template", "ListingsSample2");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' lat='12' long=''></sleep>"
, "name_0;12;"
);
}
@Test public void Position_template_as_text() {
fxt.Init_page_create("MediaWiki:listings-position-template" , "position_template|$1|$2");
fxt.Init_page_create("Template:position_template" , "tmpl:lat={{{1}}} long={{{2}}}");
fxt.Init_page_create("MediaWiki:listings-position" , "msg: $1");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' lat='100' long='200'></sleep>"
, "<strong>name_0</strong> (<em>msg: tmpl:lat=100 long=200</em>). "
);
}
@Test public void Phone__text() {
fxt.Init_page_create("MediaWiki:listings-phone" , "phone");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' phone='0'></sleep>"
, "<strong>name_0</strong>, <abbr title=\"phone\">☎</abbr> 0. "
);
}
@Test public void Phone__text_and_symbol() {
fxt.Init_page_create("MediaWiki:listings-phone" , "phone");
fxt.Init_page_create("MediaWiki:listings-phone-symbol" , "P");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' phone='0'></sleep>"
, "<strong>name_0</strong>, <abbr title=\"phone\">P</abbr> 0. "
);
}
@Test public void Tollfree__text_and_symbol() {
fxt.Init_page_create("MediaWiki:listings-tollfree" , "tollfree");
fxt.Init_page_create("MediaWiki:listings-tollfree-symbol" , "tf");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' tollfree='0'></sleep>"
, "<strong>name_0</strong>, <abbr title=\"phone\">☎</abbr> (<abbr title=\"tollfree\">tf</abbr>: 0). "
);
}
@Test public void Fax__text_and_symbol() {
fxt.Init_page_create("MediaWiki:listings-fax" , "fax");
fxt.Init_page_create("MediaWiki:listings-fax-symbol" , "f");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' fax='0'></sleep>"
, "<strong>name_0</strong>, <abbr title=\"fax\">f</abbr>: 0. "
);
}
@Test public void Email__text_and_symbol() {
fxt.Init_page_create("MediaWiki:listings-email" , "email");
fxt.Init_page_create("MediaWiki:listings-email-symbol" , "e");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' email='a@b.org'></sleep>"
, "<strong>name_0</strong>, <abbr title=\"email\">e</abbr>: <a href=\"mailto:a@b.org\" class=\"email\">a@b.org</a>. "
);
}
@Test public void Checkin__template() {
fxt.Init_page_create("MediaWiki:listings-checkin" , "checkin: $1");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' checkin='checkin_0'></sleep>"
, "<strong>name_0</strong>. checkin: checkin_0. "
);
}
@Test public void Checkout__template() {
fxt.Init_page_create("MediaWiki:listings-checkout" , "checkout: $1");
Init_xtn_mgr();
fxt.Test_parse_page_all_str
( "<sleep name='name_0' checkout='checkout_0'></sleep>"
, "<strong>name_0</strong>. checkout: checkout_0. "
);
}
}

View File

@@ -0,0 +1,136 @@
/*
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.xtns.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Lst_pfunc_lst_tst {
@Before public void init() {fxt.Clear();} private Lst_pfunc_lst_fxt fxt = new Lst_pfunc_lst_fxt();
@Test public void Bgn_only() {
fxt.Clear().Page_txt_("a<section begin=key0/>val0<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Multiple() {
fxt.Clear().Page_txt_("a<section begin=key0/>val00<section end=key0/> b<section begin=key0/> val01<section end=key0/> c").Test_lst("{{#lst:section_test|key0}}", "val00 val01");
}
@Test public void Range() {
fxt.Clear().Page_txt_("a<section begin=key0/>val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c<section begin=key2/> val2<section end=key2/> d")
.Test_lst("{{#lst:section_test|key0|key2}}", "val0 b val1 c val2");
}
@Test public void Nest() {
fxt.Clear().Page_txt_("<section begin=key0/>val0<section begin=key00/> val00<section end=key00/><section end=key0/>").Test_lst("{{#lst:section_test|key0}}", "val0 val00");
}
@Test public void Wikitext() { // PURPOSE: assert section is expanded to html
fxt.Clear().Page_txt_("a<section begin=key0/>''val0''<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "<i>val0</i>");
}
@Test public void Refs_ignored() { // PURPOSE: assert that nearby refs are ignored
fxt.Clear().Page_txt_("a<section begin=key0/>val0<ref>ref1</ref><section end=key0/> b <ref>ref2</ref>").Test_lst("{{#lst:section_test|key0}}<references/>", String_.Concat_lines_nl
( "val0<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup><ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">ref1</span></li>"
, "</ol>"
));
}
@Test public void Missing_bgn_end() {
fxt.Page_txt_("a<section bgn=key0/> b<section end=key0/> c");
fxt.Clear().Test_lst("{{#lst:section_test}}", "a b c");
}
@Test public void Missing_bgn() {
fxt.Page_txt_("a<section bgn=key0/> b<section end=key0/> c");
fxt.Clear().Test_lst("{{#lst:section_test||key0}}", "a b");
}
@Test public void Missing_end() {
fxt.Page_txt_("a <section begin=key0/>val0<section end=key1/> b");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0 b"); // end is missing; read to end;
}
@Test public void Missing_end_noinclude() { // EX: de.wikisource.org/wiki/Versuch_einer_mokscha-mordwinischen_Grammatik/Mokscha-Texte; Seite:Ahlqvist_Forschungen_auf_dem_Gebiete_der_ural-altaischen_Sprachen_I.pdf/111
fxt.Page_txt_("a <section begin=key0/>val0<section end=key1/> b<noinclude>c</noinclude>");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0 b"); // end is missing; ignore noinclude
}
@Test public void Missing_bgn_dupe() {
fxt.Page_txt_("a <section begin=key0/>val0<section end=key0/> b<section begin=key1/>val1<section end=key0/>");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Nowiki() { // PURPOSE.fix: <nowiki> was creating incorrect sections; DATE:2013-07-11
fxt.Clear().Page_txt_("a<nowiki>''c''</nowiki><section begin=key0/>val0<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Fullpagename() { // PURPOSE.fix: lst creates its own ctx; make sure ctx has same page_name of calling page (Test page) not default (Main page); DATE:2013-07-11
fxt.Clear().Page_txt_("a <section begin=key0/>{{FULLPAGENAME}}<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "Test page");
}
@Test public void Nested_forbid_recursion() { // PURPOSE: forbid recursive calls; DATE:2014-02-09
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a<section end=key_0 />{{#lst:Sub_0|key_0}}"); // NOTE: recursive call to self
fxt.Fxt().Test_parse_page_all_str("{{#lst:Sub_0|key_0}}", "a");
}
@Test public void Nested_allow() { // PURPOSE: allow nested calls; DATE:2014-02-09
fxt.Fxt().Init_page_create("Template:Sub_1", "<section begin=key_1 />b<section end=key_1 />");
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a{{Sub_1}}<section end=key_0 />");
fxt.Fxt().Test_parse_page_all_str("{{#lst:Sub_0|key_0}}", "ab");
}
@Test public void Nested_recursion() { // PURPOSE: allow nested calls; it.s:Main_Page; DATE:2014-02-09
fxt.Fxt().Init_page_create("Sub_1", "<section begin=key_0 />b<section end=key_0 />");
fxt.Fxt().Init_page_create("Template:Sub_1", "{{#section:Sub_1|key_0}}");
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a{{Sub_1}}<section end=key_0 />");
fxt.Fxt().Test_parse_page_all_str("{{#section:Sub_0|key_0}}", "ab");
}
@Test public void Nested__ref() { // PURPOSE: handle tags; PAGE:it.s:La_Secchia_rapita/Canto_primo DATE:2015-12-02
fxt.Fxt().Init_page_create("Template:TagTemplate", "<ref>xyz</ref>");
fxt.Fxt().Init_page_create("PoemPage", "<poem>A{{TagTemplate}}B</poem>");
fxt.Fxt().Test_parse_page_all_str("{{#section:PoemPage}}<references/>", String_.Replace(String_.Concat_lines_nl_skip_last
( "<div class='poem'>"
, "<p>"
, "A<sup id='cite_ref-0' class='reference'><a href='#cite_note-0'>[1]</a></sup>B"
, "</p>"
, "</div><ol class='references'>"
, "<li id='cite_note-0'><span class='mw-cite-backlink'><a href='#cite_ref-0'>^</a></span> <span class='reference-text'>xyz</span></li>"
, "</ol>"
, ""
), "'", "\""));
}
@Test public void Nested__ref_poem() { // PURPOSE: handle tags; PAGE:it.s:La_Secchia_rapita/Canto_primo DATE:2015-12-02
fxt.Fxt().Init_page_create("Template:TagTemplate", "{{#tag:ref|abc<poem>def</poem>xyz}}");
fxt.Fxt().Init_page_create("PoemPage", String_.Concat_lines_nl_skip_last
( "<poem>A{{TagTemplate}}"
, " B"
, "</poem>"
));
fxt.Fxt().Test_parse_page_all_str("{{#section:PoemPage}}<references/>", String_.Replace(String_.Concat_lines_nl_skip_last
( "<div class='poem'>"
, "<p>"
, "A<sup id='cite_ref-0' class='reference'><a href='#cite_note-0'>[1]</a></sup><br/>"
, "&#160;&#160;&#160;&#160;B"
, "</p>"
, "</div><ol class='references'>"
, "<li id='cite_note-0'><span class='mw-cite-backlink'><a href='#cite_ref-0'>^</a></span> <span class='reference-text'>abc<div class='poem'>"
, "<p>"
, "def"
, "</p>"
, "</div>xyz</span></li>"
, "</ol>"
, ""
), "'", "\""));
}
}
class Lst_pfunc_lst_fxt {
public Lst_pfunc_lst_fxt Clear() {
if (fxt == null) fxt = new Xop_fxt();
fxt.Reset();
fxt.Wiki().Cache_mgr().Free_mem__all();
Io_mgr.Instance.InitEngine_mem();
return this;
}
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
public Lst_pfunc_lst_fxt Page_txt_(String v) {page_txt = v; return this;} private String page_txt;
public void Test_lst(String func, String expd) {
fxt.Init_page_create("section_test", page_txt);
fxt.Test_parse_page_all_str(func, expd);
}
}

View File

@@ -0,0 +1,130 @@
/*
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.xtns.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Lst_pfunc_lsth_tst {
private final Lst_pfunc_lst_fxt fxt = new Lst_pfunc_lst_fxt();
private final String src_str_dflt = String_.Concat_lines_nl_skip_last
( "txt_0"
, "== hdr_1 =="
, "txt_1"
, "== hdr_2 =="
, "txt_2"
, "== hdr_3 =="
, "txt_3"
);
@Before public void init() {fxt.Clear();}
@Test public void Bgn__missing() { // PURPOSE: return ""
fxt.Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_x}}", "");
}
@Test public void End__exists() {
fxt.Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_1|hdr_3}}", String_.Concat_lines_nl_skip_last
( "txt_1"
, ""
, "<h2> hdr_2 </h2>"
, "txt_2"
));
}
@Test public void End__missing() { // PURPOSE: read to end of next section
String expd = String_.Concat_lines_nl_skip_last
( "txt_1"
);
fxt.Clear().Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_1}}" , expd); // argument not given
fxt.Clear().Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_1|hdr_x}}", expd); // argument is wrong
}
@Test public void End__missing_eos() { // PURPOSE: read to EOS if last
String expd = String_.Concat_lines_nl_skip_last
( "txt_3"
);
fxt.Clear().Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_3}}" , expd); // argument not given
fxt.Clear().Page_txt_(src_str_dflt).Test_lst("{{#lsth:section_test|hdr_3|hdr_x}}", expd); // argument is wrong
}
@Test public void End__missing__match__len() { // PURPOSE:match next hdr with same length; PAGE:en.w:10s_BC; DATE:2016-08-13
String src_str = String_.Concat_lines_nl_skip_last
( "txt_0"
, "== hdr_1 =="
, "txt_1"
, "=== hdr_1a ==="
, "txt_1a"
, "== hdr_2 =="
, "txt_2"
);
fxt.Page_txt_(src_str).Test_lst("{{#lsth::section_test|hdr_1}}", String_.Concat_lines_nl_skip_last
( "txt_1"
, ""
, "<h3> hdr_1a </h3>"
, "txt_1a"
));
}
@Test public void Extra_nl() { // PURPOSE: hdr.Src_end() includes trailing nl; PAGE:en.w:10s_BC; DATE:2016-08-13
String src_str = String_.Concat_lines_nl_skip_last
( "txt_0"
, "== hdr_1 =="
, ""
, "txt_1"
, "== hdr_2 =="
, "txt_2"
);
fxt.Clear().Page_txt_(src_str).Test_lst("{{#lsth:section_test|hdr_1}}" , "txt_1");
}
@Test public void Only_include() { // PAGE:en.w:10s_BC; DATE:2016-08-13
String src_str = String_.Concat_lines_nl_skip_last
( "txt_0"
, "== hdr_1 =="
, "<onlyinclude>txt_1</onlyinclude>"
, "== hdr_2 =="
, "txt_2"
, "== hdr_3 =="
, "txt_3"
);
fxt.Page_txt_(src_str).Test_lst("{{#lsth::section_test|hdr_1}}", "txt_1");
}
@Test public void Bos() { // PURPOSE.defensive:handle == at BOS; DATE:2016-08-13
String src_str = String_.Concat_lines_nl_skip_last
( "==hdr_1 =="
, "txt_1"
, "== hdr_2 =="
, "txt_2"
);
fxt.Clear().Page_txt_(src_str).Test_lst("{{#lsth:section_test|hdr_1}}", "txt_1");
}
@Test public void Nested__lst() { // PURPOSE:lst inside lsth will add its toc_mgr to lsth; PAGE:en.w:Germany_national_football_team; DATE:2016-08-13
fxt.Fxt().Init_page_create("Nested_lst", String_.Concat_lines_nl_skip_last
( "test"
, "==hdr_1=="
, "txt_1"
));
String src_str = String_.Concat_lines_nl_skip_last
( "{{#lst:Nested_lst}}"
, "==hdr_2=="
, "txt_2"
, "==hdr_3=="
, "txt_3"
);
fxt.Page_txt_(src_str).Test_lst("{{#lsth::section_test|hdr_1}}", "txt_1"); // will fail with idx_out_of_bounds b/c hdr_1.Src_bgn / hdr_1.Src_end will be for Nested_lst's src
}
@Test public void Tmpl_w_nowiki() { // ISSUE:nowiki inside template can cause wrong offsets; PAGE:en.w:Germany_national_football_team; DATE:2016-08-13
fxt.Fxt().Init_page_create("Template:Nested_nowiki", "<nowiki>test</nowiki>");
String src_str = String_.Concat_lines_nl_skip_last
( "{{Nested_nowiki}}"
, "==hdr_2=="
, "txt_2"
, "==hdr_3=="
, "txt_3"
);
fxt.Page_txt_(src_str).Test_lst("{{#lsth::section_test|hdr_2}}", "txt_2"); // will fail with "" b/c <nowiki> requires a 2nd "sub_src = root.Data_mid()"
}
}

View File

@@ -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.xtns.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Lst_pfunc_lstx_tst {
private Lst_pfunc_lst_fxt fxt = new Lst_pfunc_lst_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|key0}}", "a b val1 c");
}
@Test public void Replace() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|key0|val3}}", "aval3 b val1 c");
}
@Test public void Section_is_empty() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|}}", "a val0 b val1 c");
}
@Test public void Missing_bgn_end() {
fxt.Page_txt_("a<section begin=key0/> b<section end=key0/> c").Test_lst("{{#lstx:section_test}}", "a b c");
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Lst_section_nde_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("a<section name=\"b\">c</section>d", "ad");
}
@Test public void German() { // PURPOSE: non-english tags for section DATE:2014-07-18
fxt.Lang_by_id_(Xol_lang_stub_.Id_de);
fxt.Test_parse_page_all_str("a<abschnitt name=\"b\">c</abschnitt>d" , "ad"); // check that German works
fxt.Test_parse_page_all_str("a<section name=\"b\">c</section>d" , "ad"); // check that English still works
fxt.Test_parse_page_all_str("a<trecho name=\"b\">c</trecho>d" , "a&lt;trecho name=&quot;b&quot;&gt;c&lt;/trecho&gt;d"); // check that Portuguese does not work
}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.mapSources; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Map_dd2dms_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Example() {fxt.Test_parse_tmpl_str_test("{{#dd2dms: 14.58|precision=4}}" , "{{test}}" , "14° 34' 48&quot;");}
@Test public void Plus() {fxt.Test_parse_tmpl_str_test("{{#dd2dms: 14.58|precision=4|plus=pos}}" , "{{test}}" , "14° 34' 48&quot; pos");}
@Test public void Ws() {fxt.Test_parse_tmpl_str_test("{{#dd2dms: 14.58| precision = 4 | plus = pos }}" , "{{test}}" , "14° 34' 48&quot; pos");}
@Test public void Nested_pfunc() {fxt.Test_parse_tmpl_str_test("{{#dd2dms: 14.58|{{#if:2|precision=2}}}}" , "{{test|3}}" , "14° 34'");} // handle "{{#if:2|precision=2}}" -> "precision=2"
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.mapSources; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Map_deg2dd_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Prec_basic() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 1.2345|2}}" , "{{test}}" , "1.23");}
@Test public void Prec_round() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 1.2345|3}}" , "{{test}}" , "1.235");}
@Test public void Example() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 14° 23' 45'' S|precision=3}}" , "{{test}}" , "-14.396");}
@Test public void Example_N() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 14° 23' 45'' N|precision=3}}" , "{{test}}" , "14.396");}
@Test public void Apos() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 42°3949N |precision=2}}" , "{{test}}" , "42.66");} // PURPOSE: handle to "; PAGE:it.v:Morro_d'Oro DATE:2015-12-06
}

View File

@@ -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.xtns.mapSources; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Map_geolink_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Example() {
fxt.Test_parse_tmpl_str_test
( "{{#geoLink: $1 $2 $3 $4 $5 $6|lat=10.5|long=20.5|plusLat=N|plusLong=E|minusLat=S|minusLong=W|precision=decimal places}}", "{{test}}"
, "10.5_N 20.5_E 10° 30' 0&quot; N 20° 30' 0&quot; E 10.5 20.5")
;
}
@Test public void Error__invalid_dlm() { // PURPOSE: handle invalid dlm; EX:20°1317'; PAGE:pl.v:Rezerwat_przyrody_Ciosny DATE:2014-08-14
Xop_fxt.Init_msg(fxt.Wiki(), "mapsources-math-incorrect-input", "incorrect input");
fxt.Test_parse_tmpl_str_test
( "{{#geoLink: $1 $2 $3 $4 $5 $6|lat=51°3137″|long=20°1317'}}", "{{test}}"
, "51.5269_N 0_E 51° 31' 37&quot; N incorrect input 51.5269 0")
;
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.massMessage; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Message_target_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("{{#target:A}}", "<a href=\"/wiki/A\">A</a>");
}
}

View File

@@ -0,0 +1,51 @@
/*
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.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xomath_core__tst {
private final Xop_fxt fxt = Xop_fxt.New_app_html();
@Test public void Basic__latex() {
Renderer_(false);
fxt.Test__parse_to_html_mgr("<math>x + y</math>", "<img id='xowa_math_img_0' src='' width='' height=''/><span id='xowa_math_txt_0'>x + y</span>"); // latex has img
}
@Test public void Basic__mathjax() {
Renderer_(true);
fxt.Test__parse_to_html_mgr("<math>x + y</math>", "<span id='xowa_math_txt_0'>x + y</span>"); // mathjax has no img
}
@Test public void Escape__mathjax() { // PURPOSE: escape <>&"; EX:de.w:Vergleich_(Zahlen); DATE:2014-05-10; PAGE:s.w:Matrix_(mathematics) DATE:2014-07-19
Renderer_(true);
fxt.Test__parse_to_html_mgr("<math>a<>b</math>", "<span id='xowa_math_txt_0'>a&lt;&gt;b</span>");
}
@Test public void Escape__latex() {
Renderer_(false);
fxt.Test__parse_to_html_mgr("<math>a<>b</math>", "<img id='xowa_math_img_0' src='' width='' height=''/><span id='xowa_math_txt_0'>a<>b</span>");
}
@Test public void Amp() { // PURPOSE: assert that amp is not escaped; DATE:2014-07-20
Renderer_(true);
fxt.Test__parse_to_html_mgr("<math>a&b</math>", "<span id='xowa_math_txt_0'>a&b</span>");
}
@Test public void Quote() { // PURPOSE: assert that quote is not escaped; DATE:2014-07-20
Renderer_(true);
fxt.Test__parse_to_html_mgr("<math>a\"b</math>", "<span id='xowa_math_txt_0'>a\"b</span>");
}
@Test public void Script() {
Renderer_(false);
fxt.Test__parse_to_html_mgr("<math><script>alert('fail');</script></math>", "<img id='xowa_math_img_0' src='' width='' height=''/><span id='xowa_math_txt_0'>&lt;script>alert('fail');</script></span>");
}
private void Renderer_(boolean mathjax) {
fxt.Wiki().Parser_mgr().Math__core().Renderer_is_mathjax_(mathjax);
}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Xomath_subst_mgr__tst {
private final Xomath_subst_mgr subst_regy = new Xomath_subst_mgr();
@Test public void Basic() {tst("a\\plusmn b" , "a\\pm b");}
@Test public void Match_fails() {tst("a\\plusmna b" , "a\\plusmna b");}
@Test public void Part() {tst("a\\part_t b" , "a\\partial_t b");} // PAGE:en.w:Faraday's law of induction
@Test public void Partial() {tst("a\\partial_{x_i}" , "a\\partial_{x_i}");} // DEFECT: partial -> partialial
private void tst(String src, String expd) {Tfds.Eq(expd, String_.new_u8(subst_regy.Subst(Bry_.new_u8(src))));}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.math.texvcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
import org.junit.*; import gplx.xowa.xtns.math.texvcs.tkns.*; import gplx.xowa.xtns.math.texvcs.funcs.*;
public class Texvc_checker_tst {
private final Texvc_checker_fxt fxt = new Texvc_checker_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Mathrm_tkns() {
fxt.Test_check("\\mathrm\\frac{a}{b}"
, fxt.Mkr().func(0, 7, Texvc_func_itm_.Id__mathrm
, fxt.Mkr().func(7, 12, Texvc_func_itm_.Id__frac
, fxt.Mkr().curly(12, 15
, fxt.Mkr().text(13, 14)
)
, fxt.Mkr().curly(15, 18
, fxt.Mkr().text(16, 17)
)
)
)
);
}
@Test public void Mathrm() {
fxt.Test_check("\\mathrm\\frac{a}{b}" , "\\mathrm{\\frac{a}{b}}");
fxt.Test_check("\\mathrm{\\frac{a}{b}}" , "\\mathrm{\\frac{a}{b}}");
fxt.Test_check("\\frac a b" , "\\frac a b");
}
}
class Texvc_checker_fxt extends Texvc_parser_fxt { private final Texvc_checker checker = new Texvc_checker();
public void Test_check(String src_str, Texvc_tkn... expd_tkns) {
byte[] src_bry = Bry_.new_u8(src_str);
Texvc_root actl_root = this.Exec_parse(src_bry);
checker.Check(src_bry, actl_root);
Tfds.Eq_str_lines(Texvc_tkn_.Print_dbg_str(tmp_bfr, expd_tkns), actl_root.Print_dbg_str(tmp_bfr), src_str);
}
public void Test_check(String src_str, String expd) {
byte[] src_bry = Bry_.new_u8(src_str);
Texvc_root actl_root = this.Exec_parse(src_bry);
checker.Check(src_bry, actl_root);
Tfds.Eq_str_lines(expd, actl_root.Print_tex_str(tmp_bfr));
}
}

View File

@@ -0,0 +1,139 @@
/*
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.xtns.math.texvcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
import org.junit.*; import gplx.xowa.xtns.math.texvcs.tkns.*; import gplx.xowa.xtns.math.texvcs.funcs.*;
public class Texvc_parser_tst {
private final Texvc_parser_fxt fxt = new Texvc_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Text() {
fxt.Test_parse("abc"
, fxt.Mkr().text(0, 3)
);
}
@Test public void Ws() {
fxt.Test_parse(" "
, fxt.Mkr().ws(0, 3)
);
}
@Test public void Mix() {
fxt.Test_parse("a b c"
, fxt.Mkr().text(0, 1)
, fxt.Mkr().ws (1, 2)
, fxt.Mkr().text(2, 3)
, fxt.Mkr().ws (3, 4)
, fxt.Mkr().text(4, 5)
);
}
@Test public void Curly() {
fxt.Test_parse("{a}"
, fxt.Mkr().curly(0, 3
, fxt.Mkr().text(1, 2)
)
);
}
@Test public void Curly_2() {
fxt.Test_parse("{a{b}c}"
, fxt.Mkr().curly(0, 7
, fxt.Mkr().text (1, 2)
, fxt.Mkr().curly (2, 5
, fxt.Mkr().text (3, 4)
)
, fxt.Mkr().text (5, 6)
)
);
}
@Test public void Func() {
fxt.Test_parse("\\abc \\def"
, fxt.Mkr().func(0, 4, Texvc_func_itm_.Id__xowa_unknown)
, fxt.Mkr().ws (4, 5)
, fxt.Mkr().func(5, 9, Texvc_func_itm_.Id__xowa_unknown)
);
}
@Test public void Mathrm() {
fxt.Test_parse("\\mathrm\\frac{a}{b}"
, fxt.Mkr().func ( 0, 7, Texvc_func_itm_.Id__mathrm)
, fxt.Mkr().func ( 7, 12, Texvc_func_itm_.Id__frac)
, fxt.Mkr().curly (12, 15
, fxt.Mkr().text (13, 14)
)
, fxt.Mkr().curly (15, 18
, fxt.Mkr().text (16, 17)
)
);
}
}
class Texvc_tkn_mkr_fxt {
private final Texvc_ctx ctx;
private final Texvc_root root;
public Texvc_tkn_mkr_fxt(Texvc_ctx ctx) {
this.ctx = ctx;
this.root = new Texvc_root();
}
public void Clear() {
root.Init_as_root(ctx.Tkn_mkr(), Bry_.Empty, 0, 8);
}
private Texvc_tkn leaf(int tid, int bgn, int end) {
int uid = root.Regy__add(tid, tid, bgn, end, null);
return new Texvc_tkn__leaf_raw().Init(root, tid, uid, bgn, end);
}
public Texvc_tkn text (int bgn, int end) {return leaf(Texvc_tkn_.Tid__text , bgn, end);}
public Texvc_tkn ws (int bgn, int end) {return leaf(Texvc_tkn_.Tid__ws , bgn, end);}
public Texvc_tkn func (int bgn, int end, int func_tid, Texvc_tkn... subs) {
Texvc_func_itm itm = ctx.Func_regy().Get_at(func_tid);
Texvc_tkn tkn = itm.Tkn(); if (tkn == null) tkn = new Texvc_tkn__func(Texvc_func_itm_.Itm__unknown);
node(Texvc_tkn_.Tid__func, itm.Singleton_id(), tkn, bgn, end, subs);
return tkn;
}
public Texvc_tkn curly(int bgn, int end, Texvc_tkn... subs) {
int tid = Texvc_tkn_.Tid__curly;
Texvc_tkn tkn = new Texvc_tkn__func(Texvc_func_itm_.Itm__arg);
node(tid, Texvc_tkn_mkr.Singleton_id__null, tkn, bgn, end, subs);
return tkn;
}
private void node(int tid, int singleton_id, Texvc_tkn tkn, int bgn, int end, Texvc_tkn... subs) {
root.Regy__add(tid, singleton_id, bgn, end, tkn);
int len = subs.length;
for (int i = 0; i < len; ++i) {
Texvc_tkn sub = subs[i];
root.Regy__move(sub.Uid(), tkn.Uid());
}
}
}
class Texvc_parser_fxt {
protected final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private final Texvc_parser parser = new Texvc_parser();
private final Texvc_root actl_root;
private final Texvc_ctx ctx;
public Texvc_parser_fxt() {
this.actl_root = new Texvc_root();
this.ctx = new Texvc_ctx();
this.mkr_fxt = new Texvc_tkn_mkr_fxt(ctx);
}
public Texvc_tkn_mkr_fxt Mkr() {return mkr_fxt;} private final Texvc_tkn_mkr_fxt mkr_fxt;
public void Clear() {
mkr_fxt.Clear();
actl_root.Init_as_root(ctx.Tkn_mkr(), Bry_.Empty, 0, 8);
}
public Texvc_root Exec_parse(byte[] src_bry) {
parser.Parse(ctx, actl_root, src_bry);
return actl_root;
}
public void Test_parse(String src_str, Texvc_tkn... expd_tkns) {
byte[] src_bry = Bry_.new_u8(src_str);
Exec_parse(src_bry);
Tfds.Eq_str_lines(Texvc_tkn_.Print_dbg_str(tmp_bfr, expd_tkns), actl_root.Print_dbg_str(tmp_bfr), src_str);
}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.new_window_links; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
public class New_window_link_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Lnki__none() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:A}}" , "<a href='/wiki/A'>A</a>");}
@Test public void Lnki__caption() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:A|B}}" , "<a href='/wiki/A'>B</a>");}
@Test public void Lnke__none() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:https://a.org}}" , "<a href='https://a.org' rel='nofollow' class='external free'>https://a.org</a>");}
@Test public void Lnke__caption() {fxt.Test__parse__tmpl_to_html("{{#NewWindowLink:https://a.org|A}}" , "<a href='https://a.org' rel='nofollow' class='external text'>A</a>");}
}

View File

@@ -0,0 +1,84 @@
/*
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.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
import gplx.xowa.htmls.core.htmls.*;
public class Pgbnr_func_tst {
private final Pgbnr_func_fxt fxt = new Pgbnr_func_fxt();
@Test public void Basic() {
fxt.Test__parse(Bool_.N, "{{PAGEBANNER:A.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " <h1 class='wpb-name'>Test page</h1>"
, " <a href='' class='image' title='Test page' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/wiki/repo/trg/orig/7/0/A.png' width='0' height='0' class='wpb-banner-image ' alt='' srcset='' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <div class='wpb-iconbox'>"
, " <a href='/wiki/Star_article'><span aria-disabled='false' title='Star article' class='oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-star oo-ui-iconElement oo-ui-iconWidget'></span></a>"
, " </div>"
, " </div>"
, " <div class='wpb-topbanner-toc'><div class='wpb-banner-toc'><div>"
, " <div id=\"toctitle\" class=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, "</div>"
, "</div></div>"
, "</div>"
));
}
@Test public void Hdump__basic() {
fxt.Test__parse(Bool_.Y, "{{PAGEBANNER:A.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " <h1 class='wpb-name'>Test page</h1>"
, " <a href='/wiki/File:A.png' class='image' title='Test page' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg=\"1|-1|-1|-1|-1|-1\" src='' width='0' height='0' class='wpb-banner-image ' alt='' srcset='' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <div class='wpb-iconbox'>"
, " <a href='/wiki/Star_article'><span aria-disabled='false' title='Star article' class='oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-star oo-ui-iconElement oo-ui-iconWidget'></span></a>"
, " </div>"
, " </div>"
, " <div class='wpb-topbanner-toc'><div class='wpb-banner-toc'><div class=\"xo-toc\" data-toc-mode=\"1\"></div></div></div>"
, "</div>"
));
}
@Test public void Hdump__quote() { // PAGE:en.v:Europe; DATE:2016-07-12
fxt.Test__parse(Bool_.Y, "{{PAGEBANNER:A\"b.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " <h1 class='wpb-name'>Test page</h1>"
, " <a href='/wiki/File:A%22b.png' class='image' title='Test page' xowa_title='A%22b.png'><img data-xowa-title=\"A%22b.png\" data-xoimg=\"1|-1|-1|-1|-1|-1\" src='' width='0' height='0' class='wpb-banner-image ' alt='' srcset='' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <div class='wpb-iconbox'>"
, " <a href='/wiki/Star_article'><span aria-disabled='false' title='Star article' class='oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-star oo-ui-iconElement oo-ui-iconWidget'></span></a>"
, " </div>"
, " </div>"
, " <div class='wpb-topbanner-toc'><div class='wpb-banner-toc'><div class=\"xo-toc\" data-toc-mode=\"1\"></div></div></div>"
, "</div>"
));
}
}
class Pgbnr_func_fxt {
private final Xop_fxt fxt;
public Pgbnr_func_fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "en.wikivoyage.org");
fxt = new Xop_fxt(app, wiki);
}
public void Test__parse(boolean hdump, String raw, String expd) {
fxt.Exec_parse_page_all_as_str(raw);
Xoh_wtr_ctx hctx = hdump ? Xoh_wtr_ctx.Hdump : Xoh_wtr_ctx.Basic;
Bfr_arg arg = fxt.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(fxt.Page(), fxt.Ctx(), hctx);
Bry_bfr bfr = Bry_bfr_.New();
arg.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,114 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_expr_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Null() {fxt.Test_parse_tmpl_str_test("{{#expr:}}" , "{{test}}" , "");}
@Test public void Num_len1() {fxt.Test_parse_tmpl_str_test("{{#expr:1}}" , "{{test}}" , "1");}
@Test public void Num_len3() {fxt.Test_parse_tmpl_str_test("{{#expr:123}}" , "{{test}}" , "123");}
@Test public void Num_decimal() {fxt.Test_parse_tmpl_str_test("{{#expr:1.2}}" , "{{test}}" , "1.2");}
@Test public void Num_decimal_lead() {fxt.Test_parse_tmpl_str_test("{{#expr:.12}}" , "{{test}}" , "0.12");}
@Test public void Num_decimal_lax() {fxt.Test_parse_tmpl_str_test("{{#expr:1.2.3}}" , "{{test}}" , "1.2");} // PURPOSE: PHP allows 1.2.3 to be 1.2
@Test public void Num_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:-1}}" , "{{test}}" , "-1");}
@Test public void Num_neg_double() {fxt.Test_parse_tmpl_str_test("{{#expr:--1}}" , "{{test}}" , "1");}
@Test public void Ws() {fxt.Test_parse_tmpl_str_test("{{#expr: 123\t\n }}" , "{{test}}" , "123");}
@Test public void Plus_op() {fxt.Test_parse_tmpl_str_test("{{#expr:1 + 2}}" , "{{test}}" , "3");}
@Test public void Minus_op() {fxt.Test_parse_tmpl_str_test("{{#expr:3 - 2}}" , "{{test}}" , "1");}
@Test public void Mult() {fxt.Test_parse_tmpl_str_test("{{#expr:3 * 2}}" , "{{test}}" , "6");}
@Test public void Div_sym() {fxt.Test_parse_tmpl_str_test("{{#expr:6 / 3}}" , "{{test}}" , "2");}
@Test public void Div_word() {fxt.Test_parse_tmpl_str_test("{{#expr:6 div 3}}" , "{{test}}" , "2");}
@Test public void Plus_sign() {fxt.Test_parse_tmpl_str_test("{{#expr:1 + + 2}}" , "{{test}}" , "3");}
@Test public void Minus_sign() {fxt.Test_parse_tmpl_str_test("{{#expr:3 + - 2}}" , "{{test}}" , "1");}
@Test public void Paren_1() {fxt.Test_parse_tmpl_str_test("{{#expr:(1 + 2) * 3}}" , "{{test}}" , "9");}
@Test public void Paren_2() {fxt.Test_parse_tmpl_str_test("{{#expr:((1 + 2) * 3) * 4}}" , "{{test}}" , "36");}
@Test public void Pow() {fxt.Test_parse_tmpl_str_test("{{#expr:2 ^ 4}}" , "{{test}}" , "16");}
@Test public void Eq_y() {fxt.Test_parse_tmpl_str_test("{{#expr:2 = 2}}" , "{{test}}" , "1");}
@Test public void Eq_n() {fxt.Test_parse_tmpl_str_test("{{#expr:2 = 3}}" , "{{test}}" , "0");}
@Test public void Neq_1() {fxt.Test_parse_tmpl_str_test("{{#expr:2 != 3}}" , "{{test}}" , "1");}
@Test public void Neq_2() {fxt.Test_parse_tmpl_str_test("{{#expr:2 <> 3}}" , "{{test}}" , "1");}
@Test public void Gt() {fxt.Test_parse_tmpl_str_test("{{#expr:3 > 2}}" , "{{test}}" , "1");}
@Test public void Lt() {fxt.Test_parse_tmpl_str_test("{{#expr:2 < 3}}" , "{{test}}" , "1");}
@Test public void Gte() {fxt.Test_parse_tmpl_str_test("{{#expr:2 >= 2}}" , "{{test}}" , "1");}
@Test public void Lte() {fxt.Test_parse_tmpl_str_test("{{#expr:2 <= 2}}" , "{{test}}" , "1");}
@Test public void Mod() {fxt.Test_parse_tmpl_str_test("{{#expr:3 mod 2}}" , "{{test}}" , "1");}
@Test public void And_1() {fxt.Test_parse_tmpl_str_test("{{#expr:1 and -1}}" , "{{test}}" , "1");}
@Test public void And_0() {fxt.Test_parse_tmpl_str_test("{{#expr:1 and 0}}" , "{{test}}" , "0");}
@Test public void Or_0() {fxt.Test_parse_tmpl_str_test("{{#expr:1 or 0}}" , "{{test}}" , "1");}
@Test public void Not_y() {fxt.Test_parse_tmpl_str_test("{{#expr:not 0}}" , "{{test}}" , "1");}
@Test public void Not_n() {fxt.Test_parse_tmpl_str_test("{{#expr:not 1}}" , "{{test}}" , "0");}
@Test public void Minus_op_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:2 - 3}}" , "{{test}}" , "-1");}
@Test public void E_num() {fxt.Test_parse_tmpl_str_test("{{#expr:e}}" , "{{test}}" , "2.71828182845904");}
@Test public void Pi_num() {fxt.Test_parse_tmpl_str_test("{{#expr:pi}}" , "{{test}}" , "3.14159265358979");}
@Test public void Pi_mult() {fxt.Test_parse_tmpl_str_test("{{#expr:pi*1}}" , "{{test}}" , "3.14159265358979");}
@Test public void E_op_pos() {fxt.Test_parse_tmpl_str_test("{{#expr:1.2 e 2}}" , "{{test}}" , "120");}
@Test public void E_op_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:1.2 e -2}}" , "{{test}}" , "0.012");}
@Test public void E_op_inf() {fxt.Test_parse_tmpl_str_test("{{#expr:1.2 e 309}}" , "{{test}}" , "INF");} // PURPOSE:constrain to PHP double (e308); PAGE:en.w:Factorial; en.w:Astatine; DATE:2015-04-09
@Test public void E_op_inf_2() {fxt.Test_parse_tmpl_str_test("{{#expr:1.8 e 308}}" , "{{test}}" , "INF");} // PURPOSE:constrain to PHP double (1.8 e308); PAGE:en.w:Mathematics_of_Sudoku DATE:2015-04-21
@Test public void E_op_large() {fxt.Test_parse_tmpl_str_test("{{#expr:1E28}}" , "{{test}}" , "1E+28");} // PURPOSE:number should print in exponent notation (1E307), not full literal String (10000000...); DATE:2015-04-09;
@Test public void Ceil_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:ceil(-1.2)}}" , "{{test}}" , "-1");}
@Test public void Trunc_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:trunc(-1.2)}}" , "{{test}}" , "-1");}
@Test public void Floor_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:floor(-1.2)}}" , "{{test}}" , "-2");}
@Test public void Ceil_pos() {fxt.Test_parse_tmpl_str_test("{{#expr:ceil(1.2)}}" , "{{test}}" , "2");}
@Test public void Trunc_pos() {fxt.Test_parse_tmpl_str_test("{{#expr:trunc(1.2)}}" , "{{test}}" , "1");}
@Test public void Floor_pos() {fxt.Test_parse_tmpl_str_test("{{#expr:floor(1.2)}}" , "{{test}}" , "1");}
@Test public void Abs_pos() {fxt.Test_parse_tmpl_str_test("{{#expr:abs(1)}}" , "{{test}}" , "1");}
@Test public void Abs_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:abs(-1)}}" , "{{test}}" , "1");}
@Test public void Exp() {fxt.Test_parse_tmpl_str_test("{{#expr:exp(10)}}" , "{{test}}" , "22026.46579480671789");} // NOTE: MW returns 4807, not 480671789;
@Test public void Ln() {fxt.Test_parse_tmpl_str_test("{{#expr:ln(22026.4657948067)}}" , "{{test}}" , "10");}
@Test public void Ln_mult() {fxt.Test_parse_tmpl_str_test("{{#expr:ln4/ln2}}" , "{{test}}" , "2");} // PAGE:en.w:Fieldbus; DATE:2015-04-09
@Test public void Sin() {fxt.Test_parse_tmpl_str_test("{{#expr:sin(1.5707963267949)}}" , "{{test}}" , "1");}
@Test public void Cos() {fxt.Test_parse_tmpl_str_test("{{#expr:cos(0)}}" , "{{test}}" , "1");}
@Test public void Tan() {fxt.Test_parse_tmpl_str_test("{{#expr:tan(45)}}" , "{{test}}" , "1.61977519054386");}
@Test public void Asin() {fxt.Test_parse_tmpl_str_test("{{#expr:asin(0)}}" , "{{test}}" , "0");}
@Test public void Acos() {fxt.Test_parse_tmpl_str_test("{{#expr:acos(0)}}" , "{{test}}" , "1.57079632679489");} // NOTE: MW (and C#) returns 49, not 489
@Test public void Atan() {fxt.Test_parse_tmpl_str_test("{{#expr:atan(0)}}" , "{{test}}" , "0");}
@Test public void Round() {fxt.Test_parse_tmpl_str_test("{{#expr:1.5 round 0}}" , "{{test}}" , "2");}
@Test public void Round_0() {fxt.Test_parse_tmpl_str_test("{{#expr:0 round 1}}" , "{{test}}" , "0");} // PURPOSE: 0 round 1 should be 0, not 0.0; DATE:2013-11-09
@Test public void Round_ex_1() {fxt.Test_parse_tmpl_str_test("{{#expr:(0.03937007874015)round(3)}}" , "{{test}}" , "0.039");} // PURPOSE: rounding results in excessive decimal places; PAGE:en.w:Milky Way (light year conversions)
@Test public void Mod_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:0.00999999mod10}}" , "{{test}}" , "0");}
@Test public void Mod_large() {fxt.Test_parse_tmpl_str_test("{{#expr:39052000900mod100}}" , "{{test}}" , "0");} // PURPOSE: JAVA was failing in converting to int and converted to Int_.Max_value instead; DATE:2013-01-26
@Test public void Fmod() {fxt.Test_parse_tmpl_str_test("{{#expr:1.25 fmod .5}}" , "{{test}}" , "0.25");}
@Test public void Sqrt() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 4}}" , "{{test}}" , "2");}
@Test public void Sqrt_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 2}}" , "{{test}}" , "1.41421356237309");} // NOTE: MW (and C#) returns 31, not 309
@Test public void Esc_xml_entRef() {fxt.Test_parse_tmpl_str_test("{{#expr:&minus;1 &lt; 5}}" , "{{test}}" , "1");}
@Test public void Ex_1() {fxt.Test_parse_tmpl_str_test("{{#expr:1e2round0}}" , "{{test}}" , "100");} // PURPOSE: used in Convert
@Test public void Floating() {fxt.Test_parse_tmpl_str_test("{{#expr:27.321582}}" , "{{test}}" , "27.321582");}
@Test public void Floating_2() {fxt.Test_parse_tmpl_str_test("{{#expr:0.1*41}}" , "{{test}}" , "4.1");} // PURPOSE: division results in expanded floating-point; PAGE:en.w:Wikipedia
@Test public void Floating_3() {fxt.Test_parse_tmpl_str_test("{{#expr:111/10^(-1)}}" , "{{test}}" , "1110");} // PURPOSE: division by pow; PAGE:en.w:Wikipedia:Featured articles
@Test public void Floating_4() {fxt.Test_parse_tmpl_str_test("{{#expr:abs(-73.9023)}}" , "{{test}}" , "73.9023");} // PURPOSE: Abs;
@Test public void Unicode_8722() {fxt.Test_parse_tmpl_str_test("{{#expr:21}}" , "{{test}}" , "1");} // PURPOSE: handle alternate minus; PAGE:en.w:Australian krill
@Test public void Exp_large_neg() {fxt.Test_parse_tmpl_str_test("{{#expr:418400000000000000000000E-23}}" , "{{test}}" , "4.184");} // PURPOSE: handle large neg; EX: w:Chicxulub_crater; {{convert|100|TtonTNT|J|lk=on}}
@Test public void Exp_large_neg2() {fxt.Test_parse_tmpl_str_test("{{#expr:210000000000000000E-17}}" , "{{test}}" , "2.1");} // PURPOSE: handle large neg2; EX: w:Chicxulub_crater; {{convert|50|MtonTNT|J|lk=on}}
@Test public void Fix_transclusion() {fxt.Test_parse_tmpl_str_test("{{#expr:{{#if:||1}}/.2}}" , "{{test}}" , "5");} // PURPOSE: /. was invoking transclusion; DATE:2013-04-26
@Test public void Exc_unrecognised_word() {fxt.Test_parse_tmpl_str_test("{{#expr:abc}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unrecognised word \"abc\"</strong>");}
@Test public void Exc_division_by_zero() {fxt.Test_parse_tmpl_str_test("{{#expr:1/0}}" , "{{test}}" , "<strong class=\"error\">Division by zero</strong>");}
@Test public void Exc_division_by_zero_mod() {fxt.Test_parse_tmpl_str_test("{{#expr:1 mod 0}}" , "{{test}}" , "<strong class=\"error\">Division by zero</strong>");}
@Test public void Exc_unexpected_number() {fxt.Test_parse_tmpl_str_test("{{#expr:0 1}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unexpected number</strong>");}
@Test public void Exc_unexpected_closing_bracket() {fxt.Test_parse_tmpl_str_test("{{#expr:5 + 1)}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unexpected closing bracket</strong>");}
@Test public void Exc_unclosed_bracket() {fxt.Test_parse_tmpl_str_test("{{#expr:(5 + 1}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unclosed bracket</strong>");}
@Test public void Exc_unexpected_operator_paren_end() {fxt.Test_parse_tmpl_str_test("{{#expr:5 ( 1}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unexpected ( operator</strong>");}
@Test public void Exc_unexpected_number_pi() {fxt.Test_parse_tmpl_str_test("{{#expr:5 pi}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unexpected number</strong>");}
@Test public void Exc_missing_operand() {fxt.Test_parse_tmpl_str_test("{{#expr:5 *}}" , "{{test}}" , "<strong class=\"error\">Expression error: Missing operand for *</strong>");}
@Test public void Exc_invalid_argument_asin() {fxt.Test_parse_tmpl_str_test("{{#expr:asin(2)}}" , "{{test}}" , "<strong class=\"error\">Invalid argument for asin: < -1 or > 1</strong>");}
@Test public void Exc_invalid_argument_acos() {fxt.Test_parse_tmpl_str_test("{{#expr:acos(2)}}" , "{{test}}" , "<strong class=\"error\">Invalid argument for acos: < -1 or > 1</strong>");}
@Test public void Exc_invalid_argument_ln() {fxt.Test_parse_tmpl_str_test("{{#expr:ln(-1)}}" , "{{test}}" , "<strong class=\"error\">Invalid argument for ln: <= 0</strong>");}
@Test public void Exc_pow_nan() {fxt.Test_parse_tmpl_str_test("{{#expr:(-2)^1.2}}" , "{{test}}" , "NaN");} // PURPOSE: handle nan; EX: w:Help:Calculation
@Test public void Exc_unrecognized_word_ornot() {fxt.Test_parse_tmpl_str_test("{{#expr:0ornot0}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unrecognised word \"ornot\"</strong>");} // PURPOSE: handle nan; EX: w:Help:Calculation
@Test public void Exc_unrecognized_word_notnot() {fxt.Test_parse_tmpl_str_test("{{#expr:notnot0}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unrecognised word \"notnot\"</strong>");} // PURPOSE: handle nan; EX: w:Help:Calculation
@Test public void Exc_unrecognized_word_sinln() {fxt.Test_parse_tmpl_str_test("{{#expr:sinln1.1}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unrecognised word \"sinln\"</strong>");} // PURPOSE: handle nan; EX: w:Help:Calculation
}

View File

@@ -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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_if_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void If_y() {fxt.Test_parse_tmpl_str_test("{{#if:1|a|b}}" , "{{test}}" , "a");}
@Test public void If_n() {fxt.Test_parse_tmpl_str_test("{{#if:|a|b}}" , "{{test}}" , "b");}
@Test public void If_n_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b}}" , "{{test}}" , "b");}
@Test public void If_y_ws() {fxt.Test_parse_tmpl_str_test("{{#if: |a|b \n}}" , "{{test}}" , "b");}
@Test public void If_y_ws1() {fxt.Test_parse_tmpl_str_test("{{#if: |a|{{#if: |a|b}}\n}}" , "{{test}}" , "b");}
@Test public void If_prm_n() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test}}" , "b");}
@Test public void If_prm_y() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{{1}}}|b}}" , "{{test|a}}" , "a");}
@Test public void If_prm_n_dflt_ws() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1| }}}|a|b}}" , "{{test}}" , "b");}
@Test public void If_prm_nest_0() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test}}" , "c");}
@Test public void If_prm_nest_1() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1}}" , "b");}
@Test public void If_prm_nest_2() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1|}}}|{{#if:{{{2|}}}|a|b}}|c}}" , "{{test|1|2}}" , "a");}
@Test public void If_ignore_key() {fxt.Test_parse_tmpl_str_test("{{#if:|<i id=1|<i id=2}}" , "{{test}}" , "<i id=2");}
@Test public void If_newline() { // PURPOSE: new_line in comments; WP:[[redirect-distinguish|a|b]]
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{#if:1<!--"
, "-->|a<!--"
, "-->|b<!--"
, "-->}}"
)
, "{{test}}", "a");
}
@Test public void If_rel2abs() {fxt.Test_parse_tmpl_str_test("{{#if:{{{1}}}|y}}" , "{{test|http://a.org/c/}}" , "y");} // PURPOSE.fix: trailing slash should not trigger rel2abs code; DATE:2013-04-06
}

View File

@@ -0,0 +1,46 @@
/*
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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_ifeq_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Ifeq_y() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|1|a|b}}" , "{{test}}" , "a");}
@Test public void Ifeq_n() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|2|a|b}}" , "{{test}}" , "b");}
@Test public void Ifeq_prm_arg() {fxt.Test_parse_tmpl_str_test("{{#ifeq:{{{1}}}|1|a|b}}" , "{{test|1}}" , "a");}
@Test public void Ifeq_prm_arg_n() {fxt.Test_parse_tmpl_str_test("{{#ifeq:{{{1}}}|1|a|b}}" , "{{test|2}}" , "b");}
@Test public void Ifeq_prm_blank_y() {fxt.Test_parse_tmpl_str_test("{{#ifeq:||a|b}}" , "{{test}}" , "a");}
@Test public void Ifeq_prm_blank_n() {fxt.Test_parse_tmpl_str_test("{{#ifeq:|1|a|b}}" , "{{test}}" , "b");}
@Test public void Ifeq_numeric() {fxt.Test_parse_tmpl_str_test("{{#ifeq:003|3.0|y|n}}" , "{{test}}" , "y");}
@Test public void Ifeq_numeric_neg() {fxt.Test_parse_tmpl_str_test("{{#ifeq:-1.0|-1|y|n}}" , "{{test}}" , "y");}
@Test public void Ifeq_prm_arg0() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|{{{1}}}|a|b}}" , "{{test|1}}" , "a");}
@Test public void Ifeq_expr_err() {fxt.Test_parse_tmpl_str_test("{{#ifeq:{{#expr:a}}|0|y|n}}" , "{{test}}" , "n");}
@Test public void Ifeq_blank() {fxt.Test_parse_tmpl_str_test("{{#ifeq:0||y|n}}" , "{{test}}" , "n");}
@Test public void Ifeq_exc_args_0() {fxt.Test_parse_tmpl_str_test("{{#ifeq:}}" , "{{test}}" , "");}
@Test public void Ifeq_exc_args_1() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|1}}" , "{{test}}" , "");}
@Test public void Ifeq_exc_args_2() {fxt.Test_parse_tmpl_str_test("{{#ifeq:1|1|a}}" , "{{test}}" , "a");}
@Test public void Ifeq_exp() {fxt.Test_parse_tmpl_str_test("{{#ifeq:0.006|+6.0E-3|y|n}}" , "{{test}}" , "y");}
@Test public void Ifeq_plus_minus() {fxt.Test_parse_tmpl_str_test("{{#ifeq:+|-|y}}" , "{{test}}" , "");} // PURPOSE: was evaluating to y; PAGE:en.w:Permian-Triassic extinction
@Test public void Tab_ent() { // PURPOSE: hack; tabs are materialized as "&#09;" which causes trimming problems; PAGE:en.w:Template:Cretaceous_graphical_timeline and "|period11= Campanian\s\t"
fxt.Test_parse_page_all_str("{{#ifeq:a|a &#09;|y|n}}", "y"); // note that "|a\s\t" gets trimmed to "a"
}
@Test public void Ifeq_hex() {fxt.Test_parse_tmpl_str_test("{{#ifeq:44|0X002C|y|n}}" , "{{test}}" , "y");} // PURPOSE: hex compares to int; EX:w:Comma
@Test public void Colon_2() { // PURPOSE: 2nd colon causes error b/c of bad whitespace evaluation; PAGE:en.w:de.wiktionary.org/wiki/glitschig; DATE:2013-12-10
fxt.Test_parse_tmpl_str_test("{{#ifeq: :|a|b|c}}" , "{{test}}" , "c");
}
}

View File

@@ -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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_iferror_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic_pass() {fxt.Test_parse_tmpl_str_test("{{#iferror: {{#expr: 1 + 2 }} | error | ok }}" , "{{test}}" , "ok");}
@Test public void Basic_fail() {fxt.Test_parse_tmpl_str_test("{{#iferror: {{#expr: 1 + X }} | error | ok }}" , "{{test}}" , "error");}
@Test public void Basic_omit() {fxt.Test_parse_tmpl_str_test("{{#iferror: ok | error}}" , "{{test}}" , "ok");}
@Test public void NoMatch_0() {fxt.Test_parse_tmpl_str_test("{{#iferror: <strong>error</strong> | error | ok }}" , "{{test}}" , "ok");}
@Test public void NoMatch_1() {fxt.Test_parse_tmpl_str_test("{{#iferror: <strong test=\"error\"></strong> | error | ok }}" , "{{test}}" , "ok");}
@Test public void NoMatch_2() {fxt.Test_parse_tmpl_str_test("{{#iferror: <strong class=\"errora\"></strong> | error | ok }}" , "{{test}}" , "ok");}
//@Test public void NoMatch_3() {fxt.Test_parse_tmpl_str_test("{{#iferror: <strong class=\"error a| error | ok }}" , "{{test}}" , "ok");} // FUTURE: match for ">
}

View File

@@ -0,0 +1,47 @@
/*
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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.wikis.tdbs.metas.*;
public class Pfunc_ifexist_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Wiki().Cache_mgr().Ifexist_cache().Clear();
}
@Test public void Basic_pass() {fxt.Test_parse_tmpl_str_test("{{#ifexist: Abc | exists | doesn't exist }}" , "{{test}}" , "doesn't exist");}
@Test public void Empty() {fxt.Test_parse_tmpl_str_test("{{#ifexist:|y|n}}" , "{{test}}" , "n");} // NOTE: {{autolink}} can pass in ""
@Test public void Db_key() { // PURPOSE: test that (1) & is encoded; (2) " " becomes "_"; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
fxt.Init_page_create("A_&_b", "");
fxt.Test_parse_tmpl_str_test("{{#ifexist:A & b|y|n}}", "{{test}}", "y");
}
@Test public void Media_n() {// DATE:2014-07-04
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "n");
}
@Test public void Media_y_wiki() {// DATE:2014-07-04
fxt.Init_page_create("File:A.png", "");
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
}
@Test public void Media_y_commons() {// DATE:2014-07-04
Xowe_wiki commons_wiki = fxt.App().Wiki_mgr().Get_by_or_make(gplx.xowa.wikis.domains.Xow_domain_itm_.Bry__commons);
fxt.Init_page_create(commons_wiki, "File:A.png", "");
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
}
@Test public void Media_y_file_v1() {// DATE:2014-07-04
Xof_meta_itm meta_itm = fxt.Wiki().File_mgr().Dbmeta_mgr().Get_itm_or_new(Bry_.new_a7("A.png"));
meta_itm.Orig_exists_(Bool_.Y_byte);
fxt.Test_parse_tmpl_str_test("{{#ifexist:Media:A.png|y|n}}", "{{test}}", "y");
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_ifexpr_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic_y() {fxt.Test_parse_tmpl_str_test("{{#ifexpr: 1 > 0 |y|n}}" , "{{test}}" , "y");}
@Test public void Basic_n() {fxt.Test_parse_tmpl_str_test("{{#ifexpr: 1 < 0 |y|n}}" , "{{test}}" , "n");}
@Test public void Blank_n() {fxt.Test_parse_tmpl_str_test("{{#ifexpr: |y|n}}" , "{{test}}" , "n");}
@Test public void Args_0_n() {fxt.Test_parse_tmpl_str_test("{{#ifexpr: 1 > 0}}" , "{{test}}" , "");}
@Test public void Args_0_y() {fxt.Test_parse_tmpl_str_test("{{#ifexpr: 0 > 1}}" , "{{test}}" , "");}
@Test public void Err() {fxt.Test_parse_tmpl_str_test("{{#ifexpr:20abc >1|y|n}}" , "{{test}}" , "<strong class=\"error\">Expression error: Unrecognised word \"abc \"</strong>");} // HACK: shouldn't be "abc "
}
/*
*/

View File

@@ -0,0 +1,89 @@
/*
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.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
public class Pfunc_switch_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic_a() {fxt.Test_parse_tmpl_str_test("{{#switch:a|a=1|b=2|3}}" , "{{test}}" , "1");}
@Test public void Basic_b() {fxt.Test_parse_tmpl_str_test("{{#switch:b|a=1|b=2|3}}" , "{{test}}" , "2");}
@Test public void Basic_dflt() {fxt.Test_parse_tmpl_str_test("{{#switch:z|a=1|b=2|3}}" , "{{test}}" , "3");}
@Test public void FallThru_a() {fxt.Test_parse_tmpl_str_test("{{#switch:a|a|b|c=1|d=2|3}}" , "{{test}}" , "1");}
@Test public void FallThru_b() {fxt.Test_parse_tmpl_str_test("{{#switch:b|a|b|c=1|d=2|3}}" , "{{test}}" , "1");}
@Test public void FallThru_c() {fxt.Test_parse_tmpl_str_test("{{#switch:c|a|b|c=1|d=2|3}}" , "{{test}}" , "1");}
@Test public void FallThru_d() {fxt.Test_parse_tmpl_str_test("{{#switch:d|a|b|c=1|d=2|3}}" , "{{test}}" , "2");}
@Test public void FallThru_dflt() {fxt.Test_parse_tmpl_str_test("{{#switch:z|a|b|c=1|d=2|3}}" , "{{test}}" , "3");}
@Test public void Dflt_named() {fxt.Test_parse_tmpl_str_test("{{#switch:z|b=2|#default=3|a=1}}" , "{{test}}" , "3");}
@Test public void Dflt_last_idx_wins() // even if there is a named default, if last arg is un-keyd, then use it as default
{fxt.Test_parse_tmpl_str_test("{{#switch:z|#default=3|9}}" , "{{test}}" , "9");}
@Test public void Dflt_last_named_wins() // last named default wins
{fxt.Test_parse_tmpl_str_test("{{#switch:z|#default=3|#default=4}}" , "{{test}}" , "4");}
@Test public void Numeric() {fxt.Test_parse_tmpl_str_test("{{#switch:003|3.0=y|n}}" , "{{test}}" , "y");} //{{#switch:{{CURRENTMONTH}}|03=y|n}}
@Test public void NoKeys() {fxt.Test_parse_tmpl_str_test("{{#switch:a|a|b|c|d}}" , "{{test}}" , "d");}// d wins b/c it is default
@Test public void Prm_val() {fxt.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a=1|b=2|3}}" , "{{test|b}}" , "2");}
@Test public void Prm_case1v() {fxt.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a={{{1}}}|b=2|3}}" , "{{test|a}}" , "a");}
@Test public void Prm_case1k() {fxt.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|{{{1}}}=1|b=2|3}}" , "{{test|a}}" , "1");}
@Test public void Null_x() {fxt.Test_parse_tmpl_str_test("{{#switch:|a=1|b=2|3}}" , "{{test|b}}" , "3");}
@Test public void Exc_no_cases() {fxt.Test_parse_tmpl_str_test("{{#switch:a}}" , "{{test}}" , "");}
@Test public void Exc_brace() {fxt.Test_parse_tmpl_str_test("{{#switch:a|{{{1}}}}=y|n}}" , "{{test|a}}" , "n");}// NOTE: deliberate 4th } brace
@Test public void Ex_1() {fxt.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|off=none|def=off|{{{1|off}}}}}", "{{test|b}}" , "b");}
@Test public void Ex_2() {
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{#switch:{{{{{|safesubst:}}}NAMESPACE:Category:Foo}}"
, "|{{ns:0}}"
, "|{{ns:Category}}=yes"
, "|no"
, "}}"
)
, "{{test}}"
, "yes");
}
@Test public void Ws() {
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{#switch: | {{ns:0}}"
, "|{{ns:2}} = yes"
, "|no"
, "}}"
)
, "{{test}}"
, "yes");
}
@Test public void Do_not_call_val_unless_needed() {
fxt.Init_defn_clear();
Xop_xowa_dbg.Argx_list.Clear();
fxt.Init_defn_add("fail", "{{#xowa_dbg:Fail}}");
fxt.Init_defn_add("pass", "{{#xowa_dbg:Pass}}");
fxt.Init_defn_add("dflt", "{{#xowa_dbg:Dflt}}");
fxt.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a={{fail}}|#default={{dflt}}|b={{pass}}}}", "{{test|b}}", "Pass");
Tfds.Eq(1, Xop_xowa_dbg.Argx_list.Count());
}
@Test public void Dflt_empty() { // PURPOSE: empty default should return "" not "#default"; PAGE:de.v:M<>nchen/Sehensw<73>rdigkeiten; DATE:2014-05-29
fxt.Test_parse_tmpl_str_test("{{#switch:z|b=1|#default}}" , "{{test}}" , "");
fxt.Test_parse_tmpl_str_test("{{#switch:z|b=1|#defaultabc}}" , "{{test}}" , "abc"); // chop off "#default"
fxt.Test_parse_tmpl_str_test("{{#switch:a|#default|#default=1}}" , "{{test}}" , "1"); // override "|#default|" with "|#default=2|"
fxt.Test_parse_tmpl_str_test("{{#switch:b|#default|1}}" , "{{test}}" , "1"); // override "|#default|" with "|2|"
fxt.Test_parse_tmpl_str_test("{{#switch:b|#defaultabc=1}}" , "{{test}}" , "1"); // this is also supported by MW
}
@Test public void Multiple() {
fxt.Wiki().Lang().Kwd_mgr().Kwd_default_match_reset();
Xol_kwd_grp kwd_grp = fxt.Wiki().Lang().Kwd_mgr().Get_or_new(Xol_kwd_grp_.Id_xtn_default);
kwd_grp.Srl_load(Bool_.Y, new byte[][] {Bry_.new_a7("#default1"), Bry_.new_a7("#default2")});
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default1=y}}" , "{{test}}" , "y");
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default2=y}}" , "{{test}}" , "y");
fxt.Test_parse_tmpl_str_test("{{#switch:a|n=n|#default=y}}" , "{{test}}" , ""); // #default is just a case
fxt.Test_parse_tmpl_str_test("{{#switch:|n=n|#default=y}}" , "{{test}}" , ""); // make sure empty String doesn't throw out of bounds
fxt.Wiki().Lang().Kwd_mgr().Kwd_default_match_reset();
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Pfunc_gender_tst { // REF.MW:https://translatewiki.net/wiki/Gender
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void No_args() {fxt.Test_parse_template("{{gender:}}" , "");}
@Test public void Username_m() {fxt.Test_parse_template("{{gender:xowa_male|m|f|?}}" , "m");}
@Test public void Username_f() {fxt.Test_parse_template("{{gender:xowa_female|m|f|?}}" , "f");}
@Test public void Username_unknown() {fxt.Test_parse_template("{{gender:wmf_user|m|f|?}}" , "?");} // should look up gender of "wmf_user", but since not avaliable, default to unknown
@Test public void Username_unknown_m() {fxt.Test_parse_template("{{gender:wmf_user|m}}" , "m");} // if only m is provided, use it
@Test public void Username_unknown_f() {fxt.Test_parse_template("{{gender:wmf_user|m|f}}" , "m");} // if only m is provided; same as above, but make sure "f" doesn't change anything
@Test public void Default() {fxt.Test_parse_template("{{gender:.|m|f|?}}" , "?");} // "." means use wiki's default gender; default to unknown
@Test public void Unknown() {fxt.Test_parse_template("{{gender:|m|f|?}}" , "?");} // "" always is unknown
}

View File

@@ -0,0 +1,63 @@
/*
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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Pfunc_grammar_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void English() {// for now, mark unimplemented langs by returning not_found; [[Template:grammar]]; wait for users to report
fxt .Test_parse_tmpl_str_test ("{{grammar:a|b}}" , "{{test}}", "[[:Template:grammar]]");
}
@Test public void Finnish() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_fi);
fxt.Reset().Test_html_full_str("{{grammar:elative|Wikiuutiset}}" , "Wikiuutisista");
fxt.Reset().Test_html_full_str("{{grammar:talo}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|talo}}" , "talon");
fxt.Reset().Test_html_full_str("{{grammar:elative|talo}}" , "talosta");
fxt.Reset().Test_html_full_str("{{grammar:inessive|talo}}" , "talossa");
fxt.Reset().Test_html_full_str("{{grammar:partitive|talo}}" , "taloa");
fxt.Reset().Test_html_full_str("{{grammar:illative|talo}}" , "taloon");
fxt.Reset().Test_html_full_str("{{grammar:genitive|sängy}}" , "sängyn");
fxt.Reset().Test_html_full_str("{{grammar:elative|sängy}}" , "sängystä");
fxt.Reset().Test_html_full_str("{{grammar:inessive|sängy}}" , "sängyssä");
fxt.Reset().Test_html_full_str("{{grammar:partitive|sängy}}" , "sängyä");
fxt.Reset().Test_html_full_str("{{grammar:illative|sängy}}" , "sängyyn");
}
@Test public void Russian() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_ru);
fxt.Reset().Test_html_full_str("{{grammar:unknown}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aвики}}" , "aвики");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aВики}}" , "aВики");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aь}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aия}}" , "aии");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aка}}" , "aки");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aти}}" , "ей");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aды}}" , "ов");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aник}}" , "aника");
fxt.Reset().Test_html_full_str("{{grammar:dative|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:accusative|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:instrumental|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:prepositional|a}}" , "a");
}
@Test public void Hebrew() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_he);
fxt.Reset().Test_html_full_str("{{grammar:unknown|abc}}" , "abc");
fxt.Reset().Test_html_full_str("{{grammar:prefixed|וabc}}" , "ווabc"); // waw: add ו
fxt.Reset().Test_html_full_str("{{grammar:prefixed|ווabc}}" , "ווabc"); // waw: do not add ו if וו
fxt.Reset().Test_html_full_str("{{grammar:prefixed|הabc}}" , "abc"); // he: remove ה
fxt.Reset().Test_html_full_str("{{grammar:prefixed|אabc}}" , "־אabc"); // maqaf: add ־
}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Pfunc_i18n_tst {
@Before public void init() {fxt.Clear();} private Pfunc_i18n_fxt fxt = new Pfunc_i18n_fxt();
@Test public void Casing() {fxt.lang_("de").Ini().Reg_func("fullurl", false, "VOLLSTÄNDIGE_URL").Load().Fxt().Test_parse_tmpl_str_test("{{vollstÄndige_url:a}}", "{{test}}" , "//de.wikipedia.org/wiki/A");}
@Test public void Time() {fxt.lang_("de").Ini().Reg_msg("march", "März").Load().Fxt().Test_parse_tmpl_str_test("{{#time: d F Y|1 Mar 2013}}", "{{test}}" , "01 März 2013");}
}
class Pfunc_i18n_fxt {
public void Clear() {}
public Xop_fxt Fxt() {return fxt;}
public Pfunc_i18n_fxt lang_(String v) {lang_key = v; return this;} private String lang_key;
public Pfunc_i18n_fxt Ini() {
if (app == null) app = Xoa_app_fxt.Make__app__edit();
app.Lang_mgr().Clear(); // else lang values retained from last run
app.Free_mem(false); // else tmpl_result_cache will get reused from last run for {{test}}
lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7(lang_key));
wiki = Xoa_app_fxt.Make__wiki__edit(app, lang_key + ".wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
return this;
} private Xoae_app app; private Xop_fxt fxt; Xol_lang_itm lang; Xowe_wiki wiki;
public Pfunc_i18n_fxt Reg_func(String name, boolean case_match, String word) {
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
String func = "keywords.load_text('" + name + "|" + (case_match ? "1" : "0") + "|" + name + "~" + word + "~');";
Io_mgr.Instance.SaveFilStr(url, func);
return this;
}
public Pfunc_i18n_fxt Reg_msg(String key, String val) {
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
String func = "messages.load_text('" + key + "|" + val + "');";
Io_mgr.Instance.SaveFilStr(url, func);
return this;
}
public Pfunc_i18n_fxt Load() {
lang.Init_by_load();
wiki.Fragment_mgr().Evt_lang_changed(lang);
return this;
}
}

View File

@@ -0,0 +1,114 @@
/*
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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Pfunc_int_tst {
@Before public void init() {fxt.Reset();} private Pf_msg_mgr_fxt fxt = new Pf_msg_mgr_fxt();
@Test public void Basic() {fxt.Test_parse_en("{{int:january}}" , "January");}
@Test public void Upper() {fxt.Test_parse_en("{{int:JANUARY}}" , "January");}
@Test public void Unknown() {fxt.Test_parse_en("{{int:unknown_msg}}" , "<unknown_msg>");}
@Test public void Fmt() {fxt.Test_parse_en("{{int:pfunc_expr_unrecognised_word|1a}}" , "Expression error: Unrecognised word \"1a\"");}
@Test public void Tmpl_txt() {
fxt.Init_msg_gfs("tst_msg", "{{#expr:1}}", false, true);
fxt.Test_parse_en("{{int:tst_msg}}", "1");
}
@Test public void Tmpl_html_entity() { // PURPOSE: check that &nbsp; is swapped out correctly for (194,160); PAGE:fr.s:Main_Page DATE:2014-08-17
fxt.Init_msg_gfs("tst_msg", "A&nbsp;B", false, true);
fxt.Test_parse_en("{{int:tst_msg}}", "A B"); // NOTE: &nbsp;
}
@Test public void Lang_current_defaults_to_en() { // PURPOSE: specifying same language as current returns same; ie: int:january/en -> int:january
fxt.Test_parse_en("{{int:january/en}}", "January");
}
@Test public void Lang_specified_by_page() {
fxt.Test_parse_lang("fr", "{{int:Lang}}", "fr"); // NOTE: "Lang" msg is added by Xol_lang_itm; message_mgr.Itm_by_key_or_new(Bry_.new_a7("Lang")).Atrs_set(key_bry, false, false);
}
@Test public void Lang_missing_msg_return_en() { // PURPOSE: if key does not exist in non-english language, use English; EX: la.w:Fasciculus:HannibalFrescoCapitolinec1510.jpg; DATE:2013-09-10
fxt.Init_msg_gfs("en_only_key", "en_only_val", false, false);
fxt.Test_parse_lang("fr", "{{int:en_only_key}}", "en_only_val");
}
@Test public void Err_fmt_failed() { // PURPOSE: if no args passed to msg, return "$1", not "~{0}"
fxt.Init_msg_gfs("tst_msg", "a~{0}b", true, false);
fxt.Test_parse_en("{{int:tst_msg}}" , "a$1b");
}
@Test public void Mediawiki_overrides_gfs() {
fxt.Init_msg_gfs("mw_overrides", "gfs", false, false);
fxt.Init_msg_db("mw_overrides", "mw");
fxt.Test_parse_en("{{int:mw_overrides}}", "mw");
}
@Test public void Convert_php() {
fxt.Init_msg_db("convert_php", "a\\\\b\\$c$1e");
fxt.Test_parse_en("{{int:convert_php|d}}", "a\\b$cde");
}
@Test public void Convert_php_tilde() { // PURPOSE: tildes should be escaped, else will fail inside ByteAryBfrFmtr; DATE:2013-11-11
fxt.Init_msg_db("convert_php_tilde", "$1~u");
fxt.Test_parse_en("{{int:convert_php_tilde|a}}", "a~u");
}
@Test public void Unknown_val_returns_en() { // PURPOSE: if no "january" in "fr.gfs" and no "january/fr" in mw, use january in "en.gfs"; EX:none
fxt.Test_parse_lang("fr", "{{int:january/fr}}", "January");
}
@Test public void Unknown_lang_returns_en() { // PURPOSE: unknown lang default to english; EX:none; DATE:2014-05-09
fxt.Test_parse_en("{{int:january/unknown}}", "January");
}
@Test public void Transclude_mw_do_not_strip_lang() { // PURPOSE: if /lang matches wiki.lang, do not strip it, else stack overflow; EX:pl.d:Wikislownik:Bar/Archiwum_6; newarticletext/pl; DATE:2014-05-13
fxt.Init_msg_db("january/en", "January_en");
fxt.Test_parse_en("{{MediaWiki:january/en}}", "January_en");
}
@Test public void Transclude_gfs() { // PURPOSE: transclusion of {{MediaWiki}} pages should call {{int}} instead; EX:zh.w:Main_Page; DATE:2014-05-09
fxt.Test_parse_en("{{MediaWiki:january/en}}", "January"); // NOTE: no page exists called "MediaWiki:january/en", but returns "{{int:january/en}}" value
}
@Test public void Create_msg_in_wiki_not_lang() { // PURPOSE: if two wikis share same language and msg is missing from one, do not mark it missing in the other; EX: home/wiki/Main_Page and en.w:Main_Page; DATE:2014-05-13
Xowe_wiki enwiktionary = fxt.Make_wiki("en.wiktionary.org");
fxt.Init_msg_db(enwiktionary, "wiki_only_msg", "enwiktionary_msg");
fxt.Init_msg_gfs("wiki_only_msg", "en_gfs_msg", false, false);
fxt.Test_parse_en("{{int:wiki_only_msg}}", "en_gfs_msg");
fxt.Test_parse_wiki(enwiktionary, "{{int:wiki_only_msg}}", "enwiktionary_msg");
}
}
class Pf_msg_mgr_fxt {
private Xop_fxt fxt;
private Xol_lang_itm en_lang;
private Xowe_wiki en_wiki;
public void Reset() {
fxt = new Xop_fxt(); // new fxt, else transclude tests will fail
en_wiki = fxt.Wiki();
en_lang = en_wiki.Lang();
}
public void Init_msg_gfs(String key, String val, boolean fmt, boolean tmpl) {Init_msg_gfs(en_lang, key, val, fmt, tmpl);}
public void Init_msg_gfs(Xol_lang_itm lang, String key, String val, boolean fmt, boolean tmpl) {
Xol_msg_itm msg_itm = lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_u8(key));
msg_itm.Atrs_set(Bry_.new_u8(val), fmt, tmpl);
}
public void Init_msg_db(String ttl, String val) {Init_msg_db(en_wiki, ttl, val);}
public void Init_msg_db(Xowe_wiki wiki, String ttl, String val) {
fxt.Init_page_create(wiki, "MediaWiki:" + ttl, val);
}
public Xowe_wiki Make_wiki(String domain) {return fxt.App().Wiki_mgr().Get_by_or_make(Bry_.new_u8(domain));}
public void Test_parse_en(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}" , expd);
}
public void Test_parse_wiki(Xowe_wiki alt_wiki, String raw, String expd) {
Xop_fxt alt_fxt = new Xop_fxt(fxt.App(), alt_wiki);
alt_fxt.Test_parse_tmpl_str_test(raw, "{{test}}" , expd);
}
public void Test_parse_lang(String other_lang_id, String raw, String expd) {
Xol_lang_itm other_lang = fxt.App().Lang_mgr().Get_by_or_new(Bry_.new_a7(other_lang_id));
other_lang.Init_by_load();
fxt.Page().Lang_(other_lang);
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
fxt.Page().Lang_(en_lang); // NOTE: must reset back to en_lang, else rest of tests will look up under fr
}
}

View File

@@ -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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_language_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void English() {fxt.Test_parse_tmpl_str_test("{{#language:en}}" , "{{test}}" , "English");}
@Test public void English_case() {fxt.Test_parse_tmpl_str_test("{{#language:eN}}" , "{{test}}" , "English");}
@Test public void Arabic() {fxt.Test_parse_tmpl_str_test("{{#language:ar}}" , "{{test}}" , "العربية");}
@Test public void Unknown() {fxt.Test_parse_tmpl_str_test("{{#language:unknown}}" , "{{test}}" , "unknown");}
@Test public void Foreign() {fxt.Test_parse_tmpl_str_test("{{#language:anp}}" , "{{test}}" , "अङ्गिका");}
@Test public void Foreign_2() {fxt.Test_parse_tmpl_str_test("{{#language:no}}" , "{{test}}" , "Norsk (bokmål)");} // PURPOSE: Names.php have bookend "pipes" (\xE2\x80\xAA)
@Test public void Empty() {fxt.Test_parse_tmpl_str_test("{{#language:}}" , "{{test}}" , "");}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_plural_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Singular() {fxt.Test_parse_tmpl_str_test("{{plural:1|wiki|wikis}}" , "{{test}}" , "wiki");}
@Test public void Plural() {fxt.Test_parse_tmpl_str_test("{{plural:2|wiki|wikis}}" , "{{test}}" , "wikis");}
@Test public void Plural_but_one_arg() {fxt.Test_parse_tmpl_str_test("{{plural:2|wiki}}" , "{{test}}" , "wiki");}
@Test public void Null() {fxt.Test_parse_tmpl_str_test("{{plural:|wiki|wikis}}" , "{{test}}" , "wikis");}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
import gplx.core.intls.*; import gplx.xowa.langs.numbers.*;
public class Pf_formatnum_de_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {
fxt.Reset();
fxt.Init_lang_numbers_separators(".", ",");
}
@After public void term() {
fxt.Init_lang_numbers_separators_en();
}
@Test public void Fmt__plain() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234,56}}" , "{{test}}" , "1.234.56");} // NOTE: double "." looks strange, but matches MW; DATE:2013-10-24
@Test public void Fmt__grp_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1.234,56}}" , "{{test}}" , "1,234.56");}
@Test public void Fmt__dec_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234.56}}" , "{{test}}" , "1.234,56");} // NOTE: "." should be treated as decimal separator, but replaced with ","; DATE:2013-10-21
@Test public void Raw__grp_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1.234,56|R}}" , "{{test}}" , "1234.56");}
@Test public void Raw__plain() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234,56|R}}" , "{{test}}" , "1234.56");}
@Test public void Raw__dec_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:12,34|R}}" , "{{test}}" , "12.34");} // NOTE: dec_dlm is always ".
@Test public void Nosep__plain() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234,56|NOSEP}}" , "{{test}}" , "1234,56");}
@Test public void Nosep__grp_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1.234,56|NOSEP}}" , "{{test}}" , "1.234,56");}
}

View File

@@ -0,0 +1,45 @@
/*
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.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
import gplx.core.intls.*;
public class Pf_formatnum_en_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Len_4() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234}}" , "{{test}}" , "1,234");}
@Test public void Len_7() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234567}}" , "{{test}}" , "1,234,567");}
@Test public void Len_2() {fxt.Test_parse_tmpl_str_test("{{formatnum:12}}" , "{{test}}" , "12");}
@Test public void Len_10() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234567890}}" , "{{test}}" , "1,234,567,890");}
@Test public void Neg() {fxt.Test_parse_tmpl_str_test("{{formatnum:-1234}}" , "{{test}}" , "-1,234");}
@Test public void Decimal() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234.5678}}" , "{{test}}" , "1,234.5678");}
@Test public void Mixed() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234abc5678}}" , "{{test}}" , "1,234abc5,678");}
@Test public void Zeros() {fxt.Test_parse_tmpl_str_test("{{formatnum:0000000}}" , "{{test}}" , "0,000,000");}
@Test public void Raw__grp_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1,234.56|R}}" , "{{test}}" , "1234.56");}
@Test public void Raw__plain() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234.56|R}}" , "{{test}}" , "1234.56");}
@Test public void Nosep__plain() {fxt.Test_parse_tmpl_str_test("{{formatnum:1234.56|NOSEP}}" , "{{test}}" , "1234.56");}
@Test public void Nosep__grp_dlm() {fxt.Test_parse_tmpl_str_test("{{formatnum:1,234.56|NOSEP}}" , "{{test}}" , "1,234.56");}
@Test public void Cs() {fxt.Test_parse_tmpl_str_test("{{FORMATNUM:1234}}" , "{{test}}" , "1,234");}
@Test public void Exc_ws() { // PURPOSE: EX: {{rnd|122835.3|(-3)}}
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{formatnum:"
, " {{#expr:2}}"
, "}}"
)
, "{{test}}"
, "2"
);
}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*;
import gplx.core.intls.*; import gplx.xowa.langs.numbers.*;
public class Pf_formatnum_es_tst {
private Xop_fxt fxt;
@Before public void init() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("es")).Init_by_load_assert();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "es.wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
}
@Test public void Basic() {
fxt.Test_parse_tmpl_str_test("{{formatnum:1234.56}}" , "{{test}}", "1234.56"); // fmt.n;
fxt.Test_parse_tmpl_str_test("{{formatnum:1234}}" , "{{test}}", "1234"); // fmt.n; decimal
fxt.Test_parse_tmpl_str_test("{{formatnum:-1234.56}}" , "{{test}}", "-1234.56"); // fmt.n; neg
fxt.Test_parse_tmpl_str_test("{{formatnum:12345.90}}" , "{{test}}", "12,345.90"); // fmt.y; 5
fxt.Test_parse_tmpl_str_test("{{formatnum:123456.90}}" , "{{test}}", "123,456.90"); // fmt.y; 6
fxt.Test_parse_tmpl_str_test("{{formatnum:1234.}}" , "{{test}}", "1,234."); // stress; decimal at end
fxt.Test_parse_tmpl_str_test("{{formatnum:123456a}}" , "{{test}}", "123,456a"); // stress; letters
}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
import gplx.core.intls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
public class Pf_formatnum_fa_tst {
private Xop_fxt fxt;
@Before public void init() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fa")).Init_by_load_assert();
app.Gfs_mgr().Run_str_for(lang, Persian_numbers_gfs);
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "fa.wikipedia.org", lang);
fxt = new Xop_fxt(app, wiki);
}
@Test public void Basic() {
fxt.Test_parse_tmpl_str_test("{{formatnum:۱۵۰|R}}" , "{{test}}", "150");
}
@Test public void English() { // PURPOSE: make sure regular numbers are still read; DATE:2015-07-18
fxt.Test_parse_tmpl_str_test("{{formatnum:150|R}}" , "{{test}}", "150");
}
public static final String Persian_numbers_gfs = String_.Concat_lines_nl
( "numbers {"
, " digits {"
, " clear;"
, " set('0', '۰');"
, " set('1', '۱');"
, " set('2', '۲');"
, " set('3', '۳');"
, " set('4', '۴');"
, " set('5', '۵');"
, " set('6', '۶');"
, " set('7', '۷');"
, " set('8', '۸');"
, " set('9', '۹');"
, " set('%', '٪');"
, " set('.', '٫');"
, " set(',', '٬');"
, " }"
, "}"
);
}

View File

@@ -0,0 +1,47 @@
/*
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.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_displaytitle_tst {
@Before public void init() {fxt.Reset();} private Pfunc_displaytitle_fxt fxt = new Pfunc_displaytitle_fxt();
@Test public void Basic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:B A}}" , "B A");}
@Test public void Apos_italic() {fxt.Init_restrict(Bool_.N).Test("{{DISPLAYTITLE:''B A''}}" , "<i>B A</i>");}
@Test public void Restrict_skip() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:B A}}" , null);} // PURPOSE: skip if text does not match title; PAGE:de.b:Kochbuch/_Druckversion; DATE:2014-08-18
@Test public void Restrict_keep_ci() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:a B}}" , "a B");} // PURPOSE: keep b/c case-insensitive match; DATE:2014-08-18
@Test public void Restrict_keep_underscore() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:a_b}}" , "a_b");} // PURPOSE: keep b/c underscores should match spaces; PAGE:de.w:Mod_qos DATE:2014-11-06
@Test public void Restrict_keep_tags() {fxt.Init_restrict(Bool_.Y).Test("{{DISPLAYTITLE:<b>a</b> <i>B</i>}}" , "<b>a</b> <i>B</i>");}// PURPOSE: keep b/c text match (tags ignored); DATE:2014-08-18
@Test public void Strip_display() {
String expd_fail = "<span style='/* attempt to bypass $wgRestrictDisplayTitle */'>A b</span>";
fxt.Init_restrict(Bool_.Y);
fxt.Test("{{DISPLAYTITLE:<span style='display:none;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='user-select:n;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style='visibility:n;'>A b</span>}}" , expd_fail);
fxt.Test("{{DISPLAYTITLE:<span style=''>display:none</span>}}" , null);
}
}
class Pfunc_displaytitle_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
fxt.Page_ttl_("A b");
}
public Pfunc_displaytitle_fxt Init_restrict(boolean v) {fxt.Wiki().Cfg_parser().Display_title_restrict_(v); return this;}
public void Test(String raw, String expd) {
fxt.Page().Html_data().Display_ttl_(null); // TEST: always reset; needed for Strip_display which calls multiple times
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", "");
Tfds.Eq(expd, String_.new_u8(fxt.Page().Html_data().Display_ttl()));
}
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_misc_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void CascadingSources() {fxt.Test_parse_page_all_str("{{CASCADINGSOURCES}}", "");} // PURPOSE: noop; DATE:2014-04-09
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.wikis.ttls.*;
public class Pfunc_rev_props_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); fxt.Page().Db().Protection().User_(Bry_.new_a7("user")).Protection_level_(Bry_.new_a7("normal"));}
@Test public void Revision_id() {fxt.Page().Db().Page().Id_(1); fxt.Test_parse_tmpl_str_test("{{REVISIONID}}" , "{{test}}", "1");}
@Test public void Page_id() {fxt.Page().Db().Page().Id_(1); fxt.Test_parse_tmpl_str_test("{{PAGEID}}" , "{{test}}", "1");}
@Test public void Revision_user() {fxt.Test_parse_tmpl_str_test("{{REVISIONUSER}}" , "{{test}}", "user");}
@Test public void Page_size() {fxt.Test_parse_tmpl_str_test("{{PAGESIZE:Test page}}" , "{{test}}", "0");}
@Test public void Revision_size() {fxt.Test_parse_tmpl_str_test("{{REVISIONSIZE}}" , "{{test}}", "8");}
@Test public void Protection_level() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONLEVEL}}" , "{{test}}", "normal");}
@Test public void Protection_expiry() {fxt.Test_parse_tmpl_str_test("{{PROTECTIONEXPIRY}}" , "{{test}}", "infinity");}
@Test public void PageSize_invalid_ttl() {fxt.Test_parse_tmpl_str_test("{{PAGESIZE:{{{100}}}|R}}" , "{{test}}", "0");}
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.pfuncs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
public class Pfunc_scrib_lib_tst {
@Before public void init() {
fxt.Clear_for_lib();
lib = new Pfunc_scrib_lib();
lib.Init();
lib.Core_(fxt.Core());
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Pfunc_scrib_lib lib;
@Test public void Expr__pass() {
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("1 + 2") , "3");
}
@Test public void Expr__int() {
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary(3) , "3"); // int should not cause class cast error; PAGE:en.w:531_BC; DATE:2016-04-29
}
@Test public void Expr__fail() { // PURPOSE: if bad input don't throw error; return error message; PAGE:es.w:Freer_(Texas) DATE:2015-07-28
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("fail") , "<strong class=\"error\">Expression error: Unrecognised word \"fail\"</strong>");
}
}

View File

@@ -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.xtns.pfuncs.strings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Pfunc_case_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Lc() {fxt.Test_parse_tmpl_str_test("{{lc:ABC}}" , "{{test}}", "abc");}
@Test public void Lc_first() {fxt.Test_parse_tmpl_str_test("{{lcfirst:ABC}}" , "{{test}}", "aBC");}
@Test public void Uc() {fxt.Test_parse_tmpl_str_test("{{uc:abc}}" , "{{test}}", "ABC");}
@Test public void Uc_first() {fxt.Test_parse_tmpl_str_test("{{ucfirst:abc}}" , "{{test}}", "Abc");}
@Test public void Multi_byte() {// NOTE: separate test b/c will sometimes fail in suite
fxt.Wiki().Lang().Case_mgr_u8_();
fxt.Test_parse_tmpl_str_test("{{uc:ĉ}}" , "{{test}}", "Ĉ"); // upper all
}
@Test public void Multi_byte_asymmetric() {
fxt.Wiki().Lang().Case_mgr_u8_();
fxt.Test_parse_tmpl_str_test("{{uc:ⱥ}}" , "{{test}}", "Ⱥ"); // handle multi-byte asymmetry (lc is 3 bytes; uc is 2 bytes)
}
@Test public void Multi_byte_first() {
fxt.Wiki().Lang().Case_mgr_u8_();
fxt.Test_parse_tmpl_str_test("{{ucfirst:провинция}}" , "{{test}}", "Провинция"); // upper first; DATE:2014-02-04
}
}

View File

@@ -0,0 +1,32 @@
/*
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.xtns.pfuncs.strings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_pad_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void L_len_3() {fxt.Test_parse_tmpl_str_test("{{padleft: a|4|0}}" , "{{test}}" , "000a");}
@Test public void L_str_ab() {fxt.Test_parse_tmpl_str_test("{{padleft: a|4|01}}" , "{{test}}" , "010a");}
@Test public void L_len_neg1() {fxt.Test_parse_tmpl_str_test("{{padleft: a|-1|01}}" , "{{test}}" , "a");}
@Test public void L_val_null() {fxt.Test_parse_tmpl_str_test("{{padleft: |4|0}}" , "{{test}}" , "0000");}
@Test public void L_word_3() {fxt.Test_parse_tmpl_str_test("{{padleft: abc|4}}" , "{{test}}" , "0abc");}
@Test public void L_word_3_u8() {fxt.Test_parse_tmpl_str_test("{{padleft: niǎo|5}}" , "{{test}}" , "0niǎo");} // PURPOSE:use length of String in chars, not bytes; PAGE:zh.d:不 DATE:2014-08-27
@Test public void L_exc_len_bad1() {fxt.Test_parse_tmpl_str_test("{{padleft:a|bad|01}}" , "{{test}}" , "a");}
@Test public void L_exc_pad_ws() {fxt.Test_parse_tmpl_str_test("{{padleft:a|4|\n \t}}" , "{{test}}" , "a");}
@Test public void R_len_3() {fxt.Test_parse_tmpl_str_test("{{padright:a|4|0}}" , "{{test}}" , "a000");}
@Test public void R_str_ab() {fxt.Test_parse_tmpl_str_test("{{padright:a|4|01}}" , "{{test}}" , "a010");}
@Test public void R_str_intl() {fxt.Test_parse_tmpl_str_test("{{padright:|6|devanā}}" , "{{test}}" , "devanā");}
}

View File

@@ -0,0 +1,56 @@
/*
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.xtns.pfuncs.strings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_tag_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {fxt.Test_html_full_str("{{#tag:pre|a|id=b|style=c}}" , "<pre id=\"b\" style=\"c\">a</pre>");}
@Test public void Atr2_empty() {fxt.Test_html_full_str("{{#tag:pre|a|id=b|}}" , "<pre id=\"b\">a</pre>");} // see {{Reflist|colwidth=30em}} -> <ref group=a>a</ref>{{#tag:references||group=a|}} -> "<references group=a/>"
@Test public void Val_apos() {fxt.Test_html_full_str("{{#tag:pre|a|id='b'}}" , "<pre id=\"b\">a</pre>");}
@Test public void Val_quote() {fxt.Test_html_full_str("{{#tag:pre|a|id=\"b\"}}" , "<pre id=\"b\">a</pre>");}
@Test public void Val_empty() {fxt.Test_html_full_str("{{#tag:pre|a|id=}}" , "<pre>a</pre>");} // PURPOSE: ignore atrs with no val; EX:{{#ref||group=}} PAGE:ru.w:Колчак,_Александр_Васильевич; DATE:2014-07-03
@Test public void Val_quote_w_apos() {fxt.Test_html_full_str("{{#tag:pre|c|id=\"a'b\"}}" , "<pre id=\"a.27b\">c</pre>");} // PURPOSE.fix: tag was not handling apos within quotes; PAGE:en.s:The_formative_period_in_Colby%27s_history DATE:2016-06-23
@Test public void Tmpl() {fxt.Test_html_full_str("{{#tag:pre|a|{{#switch:a|a=id}}=c}}" , "<pre id=\"c\">a</pre>");} // PURPOSE: args must be evaluated
@Test public void Ws_all() {fxt.Test_html_full_str("{{#tag:pre|a| id = b }}" , "<pre id=\"b\">a</pre>");}
@Test public void Ws_quoted() {fxt.Test_html_full_str("{{#tag:pre|a| id = ' b ' }}" , "<pre id=\"_b_\">a</pre>");}
@Test public void Err_bad_key() {fxt.Test_html_full_str("{{#tag:pre|a|id=val|b}}" , "<pre id=\"val\">a</pre>");} // PURPOSE: b was failing b/c id was larger and key_end set to 4 (whereas b was len=1)
@Test public void Html_is_escaped() {fxt.Test_html_full_str("{{#tag:pre|a|id='<br/>'}}" , "<pre id=\".3Cbr.2F.3E\">a</pre>");} // PURPOSE: escape html in atrs; PAGE:fr.v:France; DATE:2017-06-01
// @Test public void Missing_val() {fxt.ini_Msg(Mwl_tag_rsc.Instance.Invalid).Test_parse_tmpl_str_test("{{#tag:pre|a|id=}}" , "{{test}}" , "");} // see {{Reflist|colwidth=30em}} -> <ref group=a>a</ref>{{#tag:references||group=}} -> ""
// @Test public void Err() {
// fxt.Test_parse_tmpl_str_test("{{#tag:ref|George Robertson announced in January 2003 that he would be stepping down in December.<ref> {{cite news|title =NATO Secretary General to Leave His Post in December After 4 Years |first = Craig | last = Smith | work = The New York Times | date = January 23, 2003| url = http://www.nytimes.com/2003/01/23/world/nato-secretary-general-to-leave-his-post-in-december-after-4-years.html?scp=2&sq=lord+robertson&st=nyt|accessdate = 2009-03-29}}</ref> Jaap de Hoop Scheffer was selected as his successor, but could not assume the office until January 2004 because of his commitment in the Dutch Parliament.<ref> {{cite news|title = Jaap de Hoop Scheffer | work = Newsmakers | issue = 1 | publisher = Thomson Gale | date = January 1, 2005}}</ref> Robertson was asked to extend his term until Scheffer was ready, but declined, so Minuto-Rizzo, the Deputy Secretary General, took over in the interim.<ref name =\"ncsd\" /> |group=N|}}"
// , "{{test}}" , "<pre id=\" b \">a</pre>");}
@Test public void Nested_tmpl() { // PURPOSE: nested template must get re-evaluated; EX:de.wikipedia.org/wiki/Freiburg_im_Breisgau; DATE:2013-12-18;
fxt.Init_page_create("Template:!", "|");
fxt.Init_page_create("Template:A", "{{#ifeq:{{{1}}}|expd|pass|fail}}");
fxt.Test_html_full_frag("{{#tag:ref|{{A{{!}}expd}}}}<references/>", "<span class=\"reference-text\">pass</span>");
}
@Test public void Nested_ref__pair() { // PURPOSE: handle refs inside tag; PAGE:en.w:UK; DATE:2015-12-26
fxt.Test_html_full_str("{{#tag:ref|<ref>a</ref>b}}<references/>", String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup><ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\"><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>b</span></li>"
, "</ol>"
));
}
@Test public void Nested_ref__inline() { // PURPOSE: handle refs inside tag; PAGE:en.w:Earth; DATE:2015-12-29
fxt.Test_html_full_str("{{#tag:ref|<ref name='a'/>b}}<references/>", String_.Concat_lines_nl_skip_last
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup><ol class=\"references\">"
, "<li id=\"cite_note-a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-a_0-0\">^</a></span> <span class=\"reference-text\"></span></li>"
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\"><sup id=\"cite_ref-a_0-0\" class=\"reference\"><a href=\"#cite_note-a-0\">[1]</a></sup>b</span></li>"
, "</ol>"
));
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_count_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#count:aaa|a}}" , "3");}
@Test public void Not_found() {fxt.Test_parse_template("{{#count:aaa|b}}" , "0");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#count:a b c}}" , "2");}
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_explode_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Idx_1st() {fxt.Test_parse_template("{{#explode:a,b,c|,|0}}" , "a");}
@Test public void Idx_mid() {fxt.Test_parse_template("{{#explode:a,b,c|,|1}}" , "b");}
@Test public void Idx_nth() {fxt.Test_parse_template("{{#explode:a,b,c|,|2}}" , "c");}
@Test public void Idx_missing() {fxt.Test_parse_template("{{#explode:a,b,c|,|3}}" , "");}
@Test public void Idx_neg() {fxt.Test_parse_template("{{#explode:a,b,c|,|-1}}" , "b");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#explode:a b c||0}}" , "a");}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_len_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#len:abc}}" , "3");}
@Test public void Empty() {fxt.Test_parse_template("{{#len:}}" , "0");}
@Test public void Utf8_2() {fxt.Test_parse_template("{{#len:Ĉ}}" , "1");}
@Test public void Utf8_3() {fxt.Test_parse_template("{{#len:Ⱥ}}" , "1");}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_pos_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#pos:abcabc|b}}" , "1");}
@Test public void Index() {fxt.Test_parse_template("{{#pos:abcabc|b|3}}" , "4");}
@Test public void Missing() {fxt.Test_parse_template("{{#pos:abcabc|z}}" , "");}
@Test public void Find_missing() {fxt.Test_parse_template("{{#pos:abc def}}" , "3");}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_replace_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#replace:abc|b|z}}" , "azc");}
@Test public void Replace_all() {fxt.Test_parse_template("{{#replace:aaa|a|b}}" , "bbb");}
@Test public void Limit() {fxt.Test_parse_template("{{#replace:aaa|a|b|2}}" , "bba");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#replace:a b c||_}}" , "a_b_c");}
@Test public void Not_found() {fxt.Test_parse_template("{{#replace:aaa|b|c}}" , "aaa");}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_rpos_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#rpos:abcabc|b}}" , "4");}
@Test public void Index() {fxt.Test_parse_template("{{#rpos:abcabc|b|3}}" , "1");}
@Test public void Missing() {fxt.Test_parse_template("{{#rpos:abcabc|z}}" , "-1");}
@Test public void Find_missing() {fxt.Test_parse_template("{{#rpos:abc def}}" , "3");}
}

View File

@@ -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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_sub_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#sub:abcde|2|2}}" , "cd");}
@Test public void No_len() {fxt.Test_parse_template("{{#sub:abcde|2}}" , "cde");}
@Test public void Neg_len() {fxt.Test_parse_template("{{#sub:abcde|2|-1}}" , "cd");}
@Test public void Neg_len_too_much() {fxt.Test_parse_template("{{#sub:abcde|2|-9}}" , "");}
@Test public void No_bgn() {fxt.Test_parse_template("{{#sub:abcde}}" , "abcde");}
@Test public void Neg_bgn() {fxt.Test_parse_template("{{#sub:abcde|-2}}" , "de");}
@Test public void Neg_bgn_too_much() {fxt.Test_parse_template("{{#sub:abcde|-9}}" , "");}
}

View File

@@ -0,0 +1,21 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_urldecode_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#urldecode:a%20b}}" , "a b");}
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_date_lcl_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
@After public void teardown() {Datetime_now.Manual_n_();}
@Test public void Lcl_year() {fxt.Test_parse_tmpl_str_test("{{LOCALYEAR}}" , "{{test}}", "2012");}
@Test public void Lcl_month_int() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTH1}}" , "{{test}}", "1");}
@Test public void Lcl_month_int_len2() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTH}}" , "{{test}}", "01");}
@Test public void Lcl_day_int() {fxt.Test_parse_tmpl_str_test("{{LOCALDAY}}" , "{{test}}", "2");}
@Test public void Lcl_day_int_len2() {fxt.Test_parse_tmpl_str_test("{{LOCALDAY2}}" , "{{test}}", "02");}
@Test public void Lcl_day_hour_len2() {fxt.Test_parse_tmpl_str_test("{{LOCALHOUR}}" , "{{test}}", "03");}
@Test public void Lcl_dow_int() {fxt.Test_parse_tmpl_str_test("{{LOCALDOW}}" , "{{test}}", "1");}
@Test public void Lcl_week_int() {fxt.Test_parse_tmpl_str_test("{{LOCALWEEK}}" , "{{test}}", "1");}
@Test public void Lcl_month_name() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTHNAME}}" , "{{test}}", "January");}
@Test public void Lcl_month_gen() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTHNAMEGEN}}" , "{{test}}", "January");}
@Test public void Lcl_day_name() {fxt.Test_parse_tmpl_str_test("{{LOCALDAYNAME}}" , "{{test}}", "Monday");}
@Test public void Lcl_time() {fxt.Test_parse_tmpl_str_test("{{LOCALTIME}}" , "{{test}}", "03:04");}
@Test public void Lcl_timestamp() {fxt.Test_parse_tmpl_str_test("{{LOCALTIMESTAMP}}" , "{{test}}", "20120102030405");}
}

View File

@@ -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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_date_rev_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); fxt.Page().Db().Page().Modified_on_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
@After public void teardown() {}
@Test public void Rev_year() {fxt.Test_parse_tmpl_str_test("{{REVISIONYEAR}}" , "{{test}}", "2012");}
@Test public void Rev_month_int() {fxt.Test_parse_tmpl_str_test("{{REVISIONMONTH1}}" , "{{test}}", "1");}
@Test public void Rev_month_int_len2() {fxt.Test_parse_tmpl_str_test("{{REVISIONMONTH}}" , "{{test}}", "01");}
@Test public void Rev_day_int() {fxt.Test_parse_tmpl_str_test("{{REVISIONDAY}}" , "{{test}}", "2");}
@Test public void Rev_day_int_len2() {fxt.Test_parse_tmpl_str_test("{{REVISIONDAY2}}" , "{{test}}", "02");}
@Test public void Rev_timestamp() {fxt.Test_parse_tmpl_str_test("{{REVISIONTIMESTAMP}}" , "{{test}}", "20120102030405");}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_date_utc_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void setup() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2011, 12, 31, 22, 4, 5, 6));} // ENV:Assumes Eastern Standard Time (-5)
@After public void teardown() {Datetime_now.Manual_n_();}
@Test public void Utc_year() {fxt.Test_parse_tmpl_str_test("{{CURRENTYEAR}}" , "{{test}}", "2012");}
@Test public void Utc_month_int() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTH1}}" , "{{test}}", "1");}
@Test public void Utc_month_int_len2() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTH}}" , "{{test}}", "01");}
@Test public void Utc_day_int() {fxt.Test_parse_tmpl_str_test("{{CURRENTDAY}}" , "{{test}}", "1");}
@Test public void Utc_day_int_len2() {fxt.Test_parse_tmpl_str_test("{{CURRENTDAY2}}" , "{{test}}", "01");}
@Test public void Utc_day_hour_len2() {fxt.Test_parse_tmpl_str_test("{{CURRENTHOUR}}" , "{{test}}", "03");}
@Test public void Utc_dow_int() {fxt.Test_parse_tmpl_str_test("{{CURRENTDOW}}" , "{{test}}", "0");}
@Test public void Utc_week_int() {fxt.Test_parse_tmpl_str_test("{{CURRENTWEEK}}" , "{{test}}", "1");}
@Test public void Utc_month_abrv() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTHABBREV}}" , "{{test}}", "Jan");}
@Test public void Utc_month_name() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTHNAME}}" , "{{test}}", "January");}
@Test public void Utc_month_gen() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTHNAMEGEN}}" , "{{test}}", "January");}
@Test public void Utc_day_name() {fxt.Test_parse_tmpl_str_test("{{CURRENTDAYNAME}}" , "{{test}}", "Sunday");}
@Test public void Utc_time() {fxt.Test_parse_tmpl_str_test("{{CURRENTTIME}}" , "{{test}}", "03:04");}
@Test public void Utc_timestamp() {fxt.Test_parse_tmpl_str_test("{{CURRENTTIMESTAMP}}" , "{{test}}", "20120101030405");}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_formatdate_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Fmt_dmy() {fxt.Test_parse_tmpl_str_test("{{#formatdate:2012-01-02|dmy}}" , "{{test}}" , "2 January 2012");}
@Test public void Fmt_mdy() {fxt.Test_parse_tmpl_str_test("{{#formatdate:2012-01-02|mdy}}" , "{{test}}" , "January 2, 2012");}
@Test public void Fmt_ymd() {fxt.Test_parse_tmpl_str_test("{{#formatdate:2012-01-02|ymd}}" , "{{test}}" , "2012 January 2");}
@Test public void Fmt_ISO_8601() {fxt.Test_parse_tmpl_str_test("{{#formatdate:2012-01-02|ISO 8601}}" , "{{test}}" , "2012-01-02");}
@Test public void Fmt_default() {fxt.Test_parse_tmpl_str_test("{{#formatdate:2012-01-02|default}}" , "{{test}}" , "2012-01-02");} // NOOP?
@Test public void Fmt_none() {fxt.Test_parse_tmpl_str_test("{{#formatdate:10 April 2012}}" , "{{test}}" , "10 April 2012");}
@Test public void Err_multiple_years() {fxt.Test_parse_tmpl_str_test("{{#formatdate:January 2, 1999, 2000|Y}}" , "{{test}}" , "January 2, 1999, 2000");} // PURPOSE: check that multiple years don't fail
@Test public void Unknown() {fxt.Test_parse_tmpl_str_test("{{#formatdate:unknown|dmy}}" , "{{test}}" , "unknown");} // PURPOSE: unknown term should output self, not ""; EX:w:Wikipedia:Wikipedia_Signpost/Newsroom/Opinion_desk/AdminCom; DATE:2014-04-13
}
/*
{{#formatdate:2012-01-02|dmy}}<br/>
{{#formatdate:2012-01-02|mdy}}<br/>
{{#formatdate:2012-01-02|ymd}}<br/>
{{#formatdate:2012-01-02|ISO 8601}}<br/>
{{#formatdate:2012-01-02|default}}<br/>
*/

View File

@@ -0,0 +1,100 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Pft_func_time__basic__tst {
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {Datetime_now.Manual_n_();}
@Test public void Utc_date() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");}
@Test public void Utc_time() {fxt.Test_parse_tmpl_str("{{#time:h:i:s A|2012-01-02 03:04:05}}" , "03:04:05 AM");}
@Test public void Utc_dayOfYear() {fxt.Test_parse_tmpl_str("{{#time:z|2012-01-01 03:04:05}}" , "0");}
@Test public void Utc_escape_basic() {fxt.Test_parse_tmpl_str("{{#time:\\Y Y|2012-01-02 03:04:05}}" , "Y 2012");}
@Test public void Utc_escape_double() {fxt.Test_parse_tmpl_str("{{#time:\\\\ Y|2012-01-02 03:04:05}}" , "\\ 2012");}
@Test public void Utc_escape_eos() {fxt.Test_parse_tmpl_str("{{#time:b\\|2012-01-02 03:04:05}}" , "b\\");}
@Test public void Utc_escape_newLine() {fxt.Test_parse_tmpl_str("{{#time:b\\\nb|2012-01-02 03:04:05}}" , "b\nb");}
@Test public void Utc_quote_basic() {fxt.Test_parse_tmpl_str("{{#time:b \"Y m d\" b|2012-01-02 03:04:05}}" , "b Y m d b");}
@Test public void Utc_quote_double() {fxt.Test_parse_tmpl_str("{{#time:b \"\" b|2012-01-02 03:04:05}}" , "b \" b");}
@Test public void Utc_quote_eos() {fxt.Test_parse_tmpl_str("{{#time:b \"|2012-01-02 03:04:05}}" , "b \"");}
@Test public void Utc_ws() {fxt.Test_parse_tmpl_str("{{#time: Y-m-d |2012-01-02 03:04:05}}" , "2012-01-02");}
@Test public void Lcl_date() {fxt.Test_parse_tmpl_str("{{#timel:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");}
@Test public void Utc_dow_abrv() {fxt.Test_parse_tmpl_str("{{#time:D|20120301}}" , "Thu");}
@Test public void Utc_ymd() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|20120102}}" , "2012-01-02");}
@Test public void Utc_ym() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|201201}}" , "2012-01-02");} // PURPOSE: default to today's date
@Test public void Utc_md() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2-13}}" , "2012-02-13");} // PURPOSE.fix: m-d failed
@Test public void Slashes() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2/13/12}}" , "2012-02-13");} // PURPOSE: assert slashes work
@Test public void Slashes_yyyy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2/13/2012}}" , "2012-02-13");} // PURPOSE: assert slashes work with yyyy; DATE:2017-04-25
@Test public void Utc_day() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|March 27}}" , "2012-03-27");}
@Test public void Parse_day() {fxt.Test_parse_tmpl_str("{{#time:m d|March 27}}" , "03 27");}
@Test public void Month_name() {fxt.Test_parse_tmpl_str("{{#time:M|May 1 2012}}" , "May");}
@Test public void Time_before_date__dmy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|04:50, 17 December 2010}}" , "2010-12-17 04:50");} // PAGE:en.w:Talk:Battle of Fort Washington
@Test public void Time_before_date__mdy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|04:50, December 11, 2010}}" , "2010-12-11 04:50");} // PAGE:en.w:Wikipedia:WikiProject_Maine/members; DATE:2014-06-25
@Test public void Error() {fxt.Test_parse_tmpl_str("{{#time:M|2}}" , "<strong class=\"error\">Invalid year: 2</strong>");}
@Test public void Error2() {fxt.Test_parse_tmpl_str("{{#time:Y|July 28 - August 1, 1975}}" , "<strong class=\"error\">Invalid time</strong>");}
@Test public void Error3() {fxt.Test_parse_tmpl_str("{{#time:Y|106BC-43BC}}" , "<strong class=\"error\">Invalid time</strong>");}
@Test public void Timestamp() {fxt.Test_parse_tmpl_str("{{#time:F j, Y|20060827072854}}" , "August 27, 2006");} // PAGE:en.w:Great Fire of London
@Test public void Unixtime_read() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@0}}" , "1970-01-01 12:00:00 AM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/BLD_Preload
@Test public void Unixtime_read_neg() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@-3600}}" , "1969-12-31 11:00:00 PM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10
@Test public void Unixtime_8_digit() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@20120304}}" , "1970-08-21 08:58:24 PM");} // PURPOSE: make sure yyyy-MM-dd is gobbled by "@" and not evaluated again as date; EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10
@Test public void Unixtime_write() {fxt.Test_parse_tmpl_str("{{#time:U|2012-08-02}}" , "1343865600");} // PAGE:en.w:Opa (programming language)
@Test public void Year_4_digit() {fxt.Test_parse_tmpl_str("{{#time:Y|June 20, 451}}" , "0451");} // PAGE:en.w:Battle of the Catalaunian Plains
@Test public void Year_month() {fxt.Test_parse_tmpl_str("{{#time:F Y|November 2012}}" , "November 2012");} // PAGE:en.w:Project:Current events
@Test public void Day_addition_with_dash(){fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2011-11-13 +1 day}}" , "2011-11-14");} // PURPOSE: +1 day was becoming -1 day b/c it was picking up - at -13; PAGE:en.w:Template:POTD/2012-10-09
@Test public void Hour_zero() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|August 18 2006 00:14}}" , "2006-08-18 00:14");} // PURPOSE: fix; invalid hour; PAGE:en.w:Talk:Martin Luther
@Test public void Iso() {fxt.Test_parse_tmpl_str("{{#time:c|2012-01-02 03:04:05}}" , "2012-01-02T03:04:05-05:00");}
@Test public void Ymdh() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02-99}}" , "2012-01-06");} // PURPOSE: "99" is treated as 99th hour; EX:w:LimeWire; DATE:2014-03-24
@Test public void Ymdh_noop() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02-100}}" , "2012-01-02");} // PURPOSE: "100" is ignored
@Test public void Month_is_0() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-00-01}}" , "2011-12-01");} // PURPOSE: "0" for month is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25
@Test public void Day_is_0() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-12-00}}" , "2012-11-30");} // PURPOSE: "0" for day is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25
@Test public void Day_suffix_y() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|11th Dec 2013}}" , "2013-12-11");} // PURPOSE: ignore suffix days; EX:11th; DATE:2014-03-25
@Test public void Day_suffix_n() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|32nd Dec 2013}}" , "<strong class=\"error\">Invalid day: 32</strong>");}
@Test public void Day_rel_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|today}}" , "2012-01-02");}
@Test public void Day_rel_tomorrow() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|tomorrow}}" , "2012-01-03");}
@Test public void Day_rel_yesterday() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|yesterday}}" , "2012-01-01");}
@Test public void Unit_rel_year_next() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|next year}}" , "2013-01-02");} // DATE:2014-05-02
@Test public void Unit_rel_year_last() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|last year}}" , "2011-01-02");}
@Test public void Unit_rel_year_previous(){fxt.Test_parse_tmpl_str("{{#time:Y-m-d|previous year}}" , "2011-01-02");}
@Test public void Unit_rel_year_this() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|this year}}" , "2012-01-02");}
@Test public void Time_rel_now() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|now}}" , "2012-01-02 03:05:05 AM");} // NOTE: minute is 5, not 4, b/c each call to Datetime_now.Get() automatically increments by 1 minute; DATE:2014-04-13
@Test public void Empty_is_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|}}" , "2012-01-02");} // tested on MW
@Test public void Day_name_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Monday}}" , "2012-01-02");} // 2012-01-02 is Monday, so return Monday; DATE:2014-05-02
@Test public void Day_name_future_1() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Saturday}}" , "2012-01-07");} // return next Sunday; DATE:2014-05-02
@Test public void Day_name_future_2() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Sunday}}" , "2012-01-08");} // return next Saturday; DATE:2014-05-02
@Test public void Day_name_dow() {fxt.Test_parse_tmpl_str("{{#time:w|Monday}}" , "1");}
@Test public void Timezone_offset() {
DateAdp.Timezone_offset_test = -18000;
fxt.Test_parse_tmpl_str("{{#time:Z|}}" , "-18000");
DateAdp.Timezone_offset_test = Int_.Min_value;
} // Z=timezone offset in seconds; http://php.net/manual/en/function.date.php;
@Test public void Timezone_plus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26
@Test public void Timezone_minus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26
@Test public void Timezone_wrap() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-31 22:30:05+01:30}}" , "2012-02-01 00:00:05");} // PURPOSE: handle timezone wrap ; DATE:2014-08-26
@Test public void Rfc5322() {fxt.Test_parse_tmpl_str("{{#time:r|}}" , "Mon, 02 Jan 2012 08:04:05 +0000");}
@Test public void Lang() {
Xol_lang_itm fr_lang = fxt.App().Lang_mgr().Get_by_or_new(Bry_.new_a7("fr"));
Xol_msg_itm msg_itm = fr_lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_a7("January"));
msg_itm.Atrs_set(Bry_.new_a7("Janvier"), false, false);
fxt.Test_parse_tmpl_str("{{#time:F|2012-01|fr}}" , "Janvier");
// fxt.Test_parse_tmpl_str("{{#time:F|2012-01|fr_bad}}" , "January"); // default to english // commented out; fails when running all at once
}
@Test public void Hour_with_dash() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) generates this during {{time ago|November 2, 1991-06-19|min_magnitude=days}}; DATE:2013-06-19
@Test public void Multiple_dates_gt_12() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06-19}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor)
@Test public void Multiple_dates_lt_12() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06-11}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor)
@Test public void Raw_H() {fxt.Test_parse_tmpl_str("{{#time:xnH}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31
@Test public void Raw_h() {fxt.Test_parse_tmpl_str("{{#time:xnh}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31
@Test public void Iso8601_T() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T1:23}}" , "2012-01-02 01:23:00 AM");} // handle "T" flag; PAGE:pl.w:StarCraft_II:_Wings_of_Liberty
@Test public void Iso8601_T_ws() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T 1:23}}" , "2012-01-02 01:23:00 AM");} // handle "T" flag and ws
@Test public void Iso8601_T_fail() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T2012-01-02}}" , "<strong class=\"error\">Invalid hour: T</strong>");} // handle "T" flag and ws
}

View File

@@ -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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time__hebrew__tst {
@Before public void init() {fxt.Clear();} private Pft_func_time_foreign_fxt fxt = new Pft_func_time_foreign_fxt();
@After public void term() {fxt.Term();}
@Test public void Year_num() {fxt.Test_parse("{{#time:xjY|2012-01-02}}" , "5772");}
@Test public void Month_num() {fxt.Test_parse("{{#time:xjn|2012-01-02}}" , "4");}
@Test public void Day_num() {fxt.Test_parse("{{#time:xjj|2012-01-02}}" , "7");}
@Test public void Month_days_count() {fxt.Test_parse("{{#time:xjt|2012-01-02}}" , "29");}
@Test public void Month_name_full() {fxt.Init_msg("hebrew-calendar-m4" , "Tevet").Test_parse("{{#time:xjF|2012-01-02}}" , "Tevet");}
@Test public void Month_name_gen() {fxt.Init_msg("hebrew-calendar-m4-gen" , "Tevet").Test_parse("{{#time:xjx|2012-01-02}}" , "Tevet");}
@Test public void Numeral__empty() {fxt.Test_parse("{{#time:xh}}" , "");}
@Test public void Numeral_many() {fxt.Test_parse("{{#time:xhxjj xjx xhxjY|28-08-1608 + 341 days}}" , "ד' ה'שס\"ט");}
@Test public void Numeral__year() {
String s = String_.new_u8(Bry_.New_by_ints(215, 148, 39, 215, 170, 215, 169, 215, 153, 34, 215, 152)); // ה'תש"ך
fxt.Test_parse("{{#time:xhxjY|1959}}", s); // NOTE: 1959 chosen b/c it will choose the first char from the end_trie; .Add_str_str("כ", "ך")
}
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time__int__tst {
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Time_before_date__dmy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.4.2005}}" , "2005-04-03 01:02");} // PAGE:sk.w:Dr._House; DATE:2014-09-23
@Test public void Time_before_date__mdy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.14.2005}}" , "<strong class=\"error\">Invalid month: 14</strong>");} // mdy is invalid; DATE:2014-09-23
}

View File

@@ -0,0 +1,51 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time__other__tst {
@Before public void init() {fxt.Clear();} private Pft_func_time_foreign_fxt fxt = new Pft_func_time_foreign_fxt();
@After public void term() {fxt.Term();}
@Test public void Thai() {fxt.Test_parse("{{#time:xkY|2012}}" , "2555");}
@Test public void Minguo() {fxt.Test_parse("{{#time:xoY|2012}}" , "101");}
@Test public void Iranian__year_idx() {fxt.Test_parse("{{#time:xiY|2012-01-02}}" , "1390");}
@Test public void Iranian__month_idx() {fxt.Test_parse("{{#time:xin|2012-01-02}}" , "10");}
@Test public void Iranian__day_idx() {fxt.Test_parse("{{#time:xij|2012-01-02}}" , "12");}
@Test public void Iranian__month_name() {fxt.Init_msg("iranian-calendar-m10" , "Dey"); fxt.Test_parse("{{#time:xiF|2012-01-02}}" , "Dey");}
@Test public void Hijiri__year_idx() {fxt.Test_parse("{{#time:xmY|2012-01-02}}" , "1433");}
@Test public void Hijiri__month_idx() {fxt.Test_parse("{{#time:xmn|2012-01-02}}" , "2");}
@Test public void Hijiri__day_idx() {fxt.Test_parse("{{#time:xmj|2012-01-02}}" , "7");}
@Test public void Hijiri__month_name() {fxt.Init_msg("hijiri-calendar-m2" , "Safar"); fxt.Test_parse("{{#time:xmF|2012-01-02}}" , "Safar");}
@Test public void Roman__year() {fxt.Test_parse("{{#time:xrY|2012}}" , "MMXII");}
@Test public void Roman__various() {
fxt.Test_Roman( 1, "I");
fxt.Test_Roman( 2, "II");
fxt.Test_Roman( 3, "III");
fxt.Test_Roman( 4, "IV");
fxt.Test_Roman( 5, "V");
fxt.Test_Roman( 6, "VI");
fxt.Test_Roman( 7, "VII");
fxt.Test_Roman( 8, "VIII");
fxt.Test_Roman( 9, "IX");
fxt.Test_Roman( 10, "X");
fxt.Test_Roman( 11, "XI");
fxt.Test_Roman( 100, "C");
fxt.Test_Roman( 101, "CI");
fxt.Test_Roman( 111, "CXI");
fxt.Test_Roman(1000, "M");
fxt.Test_Roman(1001, "MI");
fxt.Test_Roman(4000, "4000");
}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time__uncommon__tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
@After public void term() {Datetime_now.Manual_n_();}
@Test public void Year__5_digits() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|00123-4-5}}" , "{{test}}" , "2003-04-05");} // PURPOSE: emulate PHP's incorrect date parsing; EX:ca.w:Nicolau_de_Mira; DATE:2014-04-17
@Test public void Year__multiple() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|12 November 2016 2008}}" , "{{test}}" , "2016-11-12");} // PURPOSE: multiple years should take 1st, not last; EX:en.w:Antipas,_Cotabato; DATE:2017-04-01
@Test public void Day__multiple() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2 12 November 2016}}" , "{{test}}" , "<strong class=\"error\">Invalid month: 12</strong>");} // PURPOSE: multiple days should generate error, not create a real date; EX:en.w:Antipas,_Cotabato; DATE:2017-04-01
}

View File

@@ -0,0 +1,41 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
class Pft_func_time_foreign_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));
}
public void Term() {
Datetime_now.Manual_n_();
}
public Pft_func_time_foreign_fxt Init_msg(String key, String val) {
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_u8(key));
msg.Atrs_set(Bry_.new_u8(val), false, false);
return this;
}
public void Test_parse(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
}
public void Test_Roman(int v, String expd) {
Bry_bfr bfr = Bry_bfr_.New_w_size(16);
Pfxtp_roman.ToRoman(v, bfr);
String actl = bfr.To_str_and_clear();
Tfds.Eq(expd, actl);
}
}

View File

@@ -0,0 +1,94 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pxd_parser_tst {
Bry_bfr bfr = Bry_bfr_.New_w_size(16); Pxd_parser parser = new Pxd_parser();
@Before public void init() {Datetime_now.Manual_y_(); Datetime_now.Manual_(test_date);} DateAdp test_date = DateAdp_.parse_fmt("2012-02-27", "yyyy-MM-dd");
@After public void teardown() {Datetime_now.Manual_n_();}
@Test public void Month_name_0__day__year() {tst_date_("Mar 2 2001" , "2001-03-02");} // y:Mar-02-2001;Mar.02.2001;Mar 02, 2001 n:Mar/02/2001;Feb,05,2011
@Test public void Month_name_0__day__year__bad_day() {tst_date_("Mar 32 2001" , "Invalid day: 32");}
@Test public void Month_name_0__day__year__bad_year() {tst_date_("Mar 3 999" , "0999-03-03");}
@Test public void Month_name_0__day__year__bad_day_year() {tst_date_("Mar 32 999" , "Invalid day: 32");}
@Test public void Month_name_0__year() {tst_date_("Mar 2001" , "2001-03-27");}
@Test public void Month_name_0__day() {tst_date_("Mar 02" , "2012-03-02");}
@Test public void Month_name_0__day_fail() {tst_date_("Mar 32" , "Invalid day: 32");}
@Test public void Month_name_0() {tst_date_("Mar" , "2012-03-27");} // y: ,.,.. Feb; n: / Feb, - Feb
@Test public void Month_name_1__day__year() {tst_date_("2 Mar 2001" , "2001-03-02");} // y: 3-Feb-2012; 3 Feb 2012;
@Test public void Month_name_1__year__day() {tst_date_("2001 Mar 02" , "2001-03-02");} // y: 2012-Feb-3 n:2012.Feb.3;2012 Feb 3; 2012,Feb,3;2012/Feb/3
@Test public void Month_name_1__day__year__guess() {tst_date_("02 Mar 01" , "2001-03-02");}
@Test public void Month_name_1__day() {tst_date_("02 Mar" , "2012-03-02");}
@Test public void Month_name_1__year() {tst_date_("2003 Mar" , "2003-03-27");}
@Test public void Month_name_2__day__year() {tst_date_("2001.02.Mar" , "2001-03-02");} // y: 2012.5.Feb; 2012 5 Feb n: 2012-5-Feb; 2012/5/Feb
@Test public void Year_0__month__day() {tst_date_("2001-03-31" , "2001-03-31");}
@Test public void Year_0__day__month__fail() {tst_date_("2001-31-03" , "Invalid month: 31");} // n:2012.31.03; 2012/31/03
@Test public void Year_0__month() {tst_date_("2001-03" , "2001-03-27");}
@Test public void Year_0() {tst_date_("2001" , "2001-02-27");}
@Test public void Year_1() {tst_date_("31-2001" , "Invalid date: 4 digit year must be either yyyy-##-## or ##-##-yyyy");} // n:31-2012; 31.2012; 31/2012; 03-2012; 03.2012; 03/2012
@Test public void Year_2__month__day() {tst_date_("03/31/2001" , "2001-03-31");} // n: 03.31.2012;03-31-2012
@Test public void Year_2__day__month() {tst_date_("31-03-2001" , "2001-03-31");} // y: 31.03.2012; n:31/03/2012
@Test public void Day_0__month__day() {tst_date_("31-03-02" , "2031-03-02");}
@Test public void Day_0__month__day_dot() {tst_date_("22.05.70" , "1970-05-22");} // PURPOSE: dmy when delimiter is dot
@Test public void Day_1__month__year() {tst_date_("03-31-02" , "2002-03-31");}
@Test public void Day_2__month__day() {tst_date_("03-02-31" , "2031-03-02");}
@Test public void Dmy_is_default() {tst_date_("03-04-05" , "2005-04-03");}
@Test public void Dmy_is_default_y4() {tst_date_("2-5-2000" , "2000-05-02");}
@Test public void Colon_hour_min() {tst_time_("01:02" , "01:02:00.000");}
@Test public void Colon_hour_min_second() {tst_time_("01:02:03" , "01:02:03.000");}
@Test public void Time_all() {tst_both_("04-03-05 06:07:08" , "2005-03-04 06:07:08.000");}
@Test public void Unit_day_pos() {tst_date_("+ 3 days" , "2012-03-01");}
@Test public void Unit_day_neg() {tst_date_("- 3 days" , "2012-02-24");}
@Test public void Unit_day_neg_w_day() {tst_date_("30 May 2012 -1 days" , "2012-05-29");} // PAGE:en.w:Main Page
@Test public void Unit_week() {tst_date_("- 1 week" , "2012-02-26");} // PURPOSE.FIX: "week" was not being handled; error on main Page; EX:da.wikipedia.org/Main_Page
@Test public void Time_len_6() {tst_time_("041526" , "04:15:26.000");}
@Test public void Time_len_12() {tst_both_("201601020304" , "2016-01-02 03:04:00.000");} // PURPOSE: handle 12 digit datetime; PAGE:en.w:Boron; DATE:2015-07-29
@Test public void Err_one_num() {tst_time_("2" , "Invalid year: 2");} // occurs on some templates; PAGE:en.w:Voyager 1 and {{date}}
@Test public void Dmy_at_y_dot() {tst_date_("1.2.70" , "1970-02-27");} // PURPOSE: dmy when delimiter is dot
@Test public void Mdy_at_y_slash() {tst_date_("1/2/70" , "1970-01-02");} // PURPOSE: mdy when delimiter is slash
@Test public void Ago() {tst_date_("1 month ago" , "2012-01-27");}
private void tst_date_(String raw, String expd) {
byte[] raw_ary = Bry_.new_u8(raw);
DateAdp date = parser.Parse(raw_ary, bfr);
if (date == DateAdp_.MinValue)
Tfds.Eq(expd, bfr.To_str_and_clear(), raw);
else
Tfds.Eq(expd, date.XtoStr_fmt_yyyy_MM_dd());
}
private void tst_time_(String raw, String expd) {
byte[] raw_ary = Bry_.new_u8(raw);
DateAdp date = parser.Parse(raw_ary, bfr);
if (date == DateAdp_.MinValue)
Tfds.Eq(expd, bfr.To_str_and_clear(), raw);
else
Tfds.Eq(expd, date.XtoStr_fmt("HH:mm:ss.fff"));
}
private void tst_both_(String raw, String expd) {
byte[] raw_ary = Bry_.new_u8(raw);
DateAdp date = parser.Parse(raw_ary, bfr);
if (date == DateAdp_.MinValue)
Tfds.Eq(expd, bfr.To_str_and_clear(), raw);
else
Tfds.Eq(expd, date.XtoStr_fmt("yyyy-MM-dd HH:mm:ss.fff"));
}
}
/*
12:12 2012 5 Feb: pass
2012 5 Feb 12:12: fail
2012-Feb-5 12:12: pass (but 2012-02-01)
2012-Feb-05 12:12: pass (and 2012-02-05)
{{#time:Y-m-d H:i:s A|.....2012.-.-.Feb-09....}}
*/

View File

@@ -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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_anchorencode_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Lnke() {fxt.Test_parse_tmpl_str_test("{{anchorencode:[irc://a b c]}}" , "{{test}}" , "b_c");}
@Test public void Apos_bold() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a ''b'' c}}" , "{{test}}" , "a_b_c");}
@Test public void Apos_1() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a 'b c}}" , "{{test}}" , "a_.27b_c");}
@Test public void Lnki_trg() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b]] c}}" , "{{test}}" , "a_b_c");}
@Test public void Lnki_caption() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[b|c]] c}}" , "{{test}}" , "a_c_c");}
@Test public void Lnki_file() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a [[Image:b|thumb|c]] d}}" , "{{test}}" , "a_thumb.7Cc_d");}
@Test public void Xnde() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a <i>b</i> c}}" , "{{test}}" , "a_b_c");}
@Test public void Html_ncr() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a &#34; b}}" , "{{test}}" , "a_.22_b");}
@Test public void Html_ref() {fxt.Test_parse_tmpl_str_test("{{anchorencode:a &quot; b}}" , "{{test}}" , "a_.22_b");}
@Test public void Tmpl_missing_basic() {fxt.Test_parse_tmpl_str_test("{{anchorencode:{{a}}}}" , "{{test}}" , "Template:a");}
@Test public void Tmpl_missing_colon() {fxt.Test_parse_tmpl_str_test("{{anchorencode:{{:a}}}}" , "{{test}}" , "a");} // NOTE: changed from "Template:A" to "a"; DATE:2016-06-24
@Test public void Lnki_literal() {fxt.Test_parse_tmpl_str_test("{{anchorencode:[[:a]]}}" , "{{test}}" , "a");}
}

View File

@@ -0,0 +1,64 @@
/*
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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.dbs.*;
import gplx.xowa.wikis.tdbs.*;
import gplx.xowa.files.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.repos.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
public class Pfunc_filepath_tst {
private final Xop_fxt fxt = new Xop_fxt();
private final Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock();
private Xowe_wiki en_wiki, commons_wiki;
@Before public void init() {
fxt.Reset();
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Xoae_app app = fxt.App();
en_wiki = fxt.Wiki();
// Init_orig_mgr(en_wiki);
commons_wiki = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__commons);
mock_wkr.Clear_commons(); // assume all files are in repo 0
en_wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
commons_wiki.Db_mgr().Load_mgr().Clear();
en_wiki.Db_mgr().Load_mgr().Clear();
app.Wiki_mgr().Add(commons_wiki);
app.File_mgr().Repo_mgr().Set("src_commons", "mem/xowa/file/commons/src/", commons_wiki.Domain_str());
app.File_mgr().Repo_mgr().Set("trg_commons", "mem/xowa/file/commons/trg/", commons_wiki.Domain_str());
en_wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src_commons"), Bry_.new_a7("trg_commons"));
Io_mgr.Instance.CreateDir(Io_url_.new_dir_("mem/xowa/wiki/commons.wikimedia.org/ns/000/page/")); // HACK: create page_dir so Scan_dirs_zip will not identify commons as zipped; FIX: remove; WHEN: after redoing commons.css download logic
}
@Test public void Wiki_is_local() {
fxt.Init_page_create(en_wiki, "File:A.png", "");
mock_wkr.Redirect_("A.png", "A.png").Repo_idx_(0);
fxt.Test_parse_tmpl_str_test("{{filepath:A.png}}", "{{test}}", "file:///mem/wiki/repo/trg/orig/7/0/A.png");
}
@Test public void Wiki_is_commons() {
fxt.Init_page_create(commons_wiki, "File:A.png", "");
commons_wiki.Tdb_fsys_mgr().Tdb_dir_regy()[Xotdb_dir_info_.Tid_page].Ext_tid_(gplx.core.ios.streams.Io_stream_tid_.Tid__raw);
mock_wkr.Redirect_("A.png", "A.png").Repo_idx_(1);
fxt.Test_parse_tmpl_str_test("{{filepath:A.png}}", "{{test}}", "file:///mem/xowa/file/commons/trg/orig/7/0/1/c/A.png");
}
@Test public void Not_found() {
fxt.Test_parse_tmpl_str_test("{{filepath:B.png}}", "{{test}}", "");
}
@Test public void Invalid() { // PURPOSE: handle invalid ttls; EX:w:Germicidin
fxt.Test_parse_tmpl_str_test("{{filepath:{{{ImageFile}}}}}", "{{test}}", "");
}
// private static void Init_orig_mgr(Xow_wiki wiki) {
// Xof_orig_tbl orig_tbl = null;
// wiki.File__orig_mgr().Init_by_wiki(wiki, Xof_fsdb_mode.New__v2__gui(), new Xof_orig_tbl[] {orig_tbl}, Xof_url_bldr.new_v2());
// }
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_ns_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Ns_0() {fxt.Test_parse_tmpl_str_test("{{ns:0}}" , "{{test}}", "");}
@Test public void Ns_10() {fxt.Test_parse_tmpl_str_test("{{ns:10}}" , "{{test}}", "Template");}
@Test public void Ns_11() {fxt.Test_parse_tmpl_str_test("{{ns:11}}" , "{{test}}", "Template talk");}
@Test public void Ns_11_ws() {fxt.Test_parse_tmpl_str_test("{{ns: 11 }}" , "{{test}}", "Template talk");}
@Test public void Ns_Template() {fxt.Test_parse_tmpl_str_test("{{ns:Template}}" , "{{test}}", "Template");}
@Test public void Ns_invalid() {fxt.Test_parse_tmpl_str_test("{{ns:252}}" , "{{test}}", "");}
@Test public void Nse_10() {fxt.Test_parse_tmpl_str_test("{{nse:10}}" , "{{test}}", "Template");}
@Test public void Nse_11() {fxt.Test_parse_tmpl_str_test("{{nse:11}}" , "{{test}}", "Template_talk");}
@Test public void Ns_Image() {fxt.Test_parse_tmpl_str_test("{{ns:Image}}" , "{{test}}", "File");}
@Test public void Ns_Templatex() {fxt.Test_parse_tmpl_str_test("{{ns:Templatex}}" , "{{test}}", "");}
@Test public void Ns_Talk() { // PURPOSE: non-English wikis may have parameterized Project Talk ($1 talk); swap out with ns:4; REF.MW: Language.php!fixVariableInNamespace
fxt.Wiki().Ns_mgr().Clear().Add_new(4, "wiki").Add_new(5, "$1 talk").Add_new(10, "Template").Init();
fxt.Test_parse_tmpl_str_test("{{ns:5}}" , "{{test}}", "wiki talk");
}
@Test public void Ns_neg1() {fxt.Test_parse_tmpl_str_test("{{ns:-1}}" , "{{test}}", "Special");} // PURPOSE.FIX:handle special; DATE:2015-05-18
}

View File

@@ -0,0 +1,66 @@
/*
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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_rel2abs_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Slash_lvl3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/d|a/b/c}}" , "{{test}}" , "a/b/c/d");}
@Test public void Cur_lvl1() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:./d|a}}" , "{{test}}" , "a/d");}
@Test public void Cur_lvl2() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:./d|a/b}}" , "{{test}}" , "a/b/d");}
@Test public void Cur_lvl3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:./d|a/b/c}}" , "{{test}}" , "a/b/c/d");}
@Test public void Owner_lvl3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:../d|a/b/c}}" , "{{test}}" , "a/b/d");}
@Test public void Owner_cur_lvl3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:../.|a/b/c}}" , "{{test}}" , "a/b");}
@Test public void Text_lvl3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:d|a/b/c}}" , "{{test}}" , "d");}
@Test public void Slash_mult() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/d//e|a/b/c}}" , "{{test}}" , "a/b/c/d/e");}
@Test public void Slash_cur_mult() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/d/./e|a/b/c}}" , "{{test}}" , "a/b/c/d/e");}
@Test public void Qry_ends_w_slash() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/d/|a/b/c}}" , "{{test}}" , "a/b/c/d");}
@Test public void Qry_is_empty() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:|a/b/c}}" , "{{test}}" , "a/b/c");}
@Test public void Qry_is_dot() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:.|a/b/c}}" , "{{test}}" , "a/b/c");}
@Test public void DotDot_mult2() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/../..|a/b/c}}" , "{{test}}" , "a");}
@Test public void DotDot_mult3() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/../../..|a/b/c}}" , "{{test}}" , "");}
@Test public void Src_is_empty() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/d|}}" , "{{test}}" , "Test page/d");}
@Test public void Err_owner() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:..}}" , "{{test}}" , "");} // PURPOSE.fix: should not fail
@Test public void Err_owner_2() {fxt.Test_parse_tmpl_str_test("{{#rel2abs:/../../b|a}}" , "{{test}}" , "");} // PURPOSE.fix: should not fail
@Test public void Ns_should_be_included_for_cur_page() {// PURPOSE.fix: current title was not returning ns; EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung#Funktion_rel2abs
fxt.Page_ttl_("Help:A"); // set page to title with Srch_rslt_cbk
fxt.Test_parse_tmpl_str_test("{{#rel2abs:.}}" , "{{test}}" , "Help:A");
}
@Test public void Owner_lvl0() {// PURPOSE.fix: old rel2abs was producing "/c"; EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung#Funktion_rel2abs
fxt.Test_parse_tmpl_str_test("{{#rel2abs:../c|a}}" , "{{test}}" , "c");
}
@Test public void Rel2abs_slash() {
fxt.Page_ttl_("Page_1");
fxt.Init_defn_clear();
fxt.Init_defn_add("test" , "{{/B}}");
fxt.Init_page_create("Page_1/B" , "Page_1/B text");
fxt.Test_parse_tmpl_str("{{test}}" , "Page_1/B text");
fxt.Init_defn_clear();
}
@Test public void Rel2abs_dot() {
fxt.Page_ttl_("Page_1/A");
fxt.Init_defn_clear();
fxt.Init_defn_add("test" , "{{../C}}");
fxt.Init_page_create("Page_1/C" , "Page_1/C text");
fxt.Test_parse_tmpl_str("{{test}}" , "Page_1/C text");
fxt.Init_defn_clear();
}
@Test public void Rel2abs_ttl() {
Tst_rel2abs_ttl("a../b", true);
Tst_rel2abs_ttl("a../[b", false);
}
private void Tst_rel2abs_ttl(String raw, boolean expd) {Tfds.Eq(expd, Pfunc_rel2abs.Rel2abs_ttl(Bry_.new_a7(raw), 0, String_.Len(raw)));}
}

View File

@@ -0,0 +1,79 @@
/*
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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_titleparts_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Len1() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|1}}" , "{{test}}", "A");}
@Test public void Len2() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|2}}" , "{{test}}", "A/b");}
@Test public void Len2_Bgn2() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|2|2}}" , "{{test}}", "b/c");}
@Test public void LenNeg1() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|-1}}" , "{{test}}", "A/b/c");}
@Test public void LenNeg1Bgn2() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|-1|2}}" , "{{test}}", "b/c");}
@Test public void Exc_len0() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|0}}" , "{{test}}", "A/b/c/d");}
@Test public void Exc_lenNeg4() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|-4}}" , "{{test}}", "");}
@Test public void Exc_lenNeg5() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|-5}}" , "{{test}}", "");}
@Test public void Exc_no_dlm() {fxt.Test_parse_tmpl_str_test("{{#titleparts:abcd|1}}" , "{{test}}", "Abcd");}
@Test public void Exc_parts0() {fxt.Test_parse_tmpl_str_test("{{#titleparts:abcd|0}}" , "{{test}}", "Abcd");}
@Test public void Exc_many_segs() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b|1|4}}" , "{{test}}", "");} // PURPOSE: bgn=4, len=1 requested; only bgn=1,2 available
@Test public void Exc_bad_len() {fxt.Init_log_(Pfunc_titleparts_log.Len_is_invalid).Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|bad}}" , "{{test}}", "A/b/c/d");}
@Test public void Exc_bad_bgn() {fxt.Init_log_(Pfunc_titleparts_log.Bgn_is_invalid).Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d|1|bad}}" , "{{test}}", "A");}
@Test public void Exc_1() {fxt.Test_parse_tmpl_str_test("{{#titleparts:50|1|1}}" , "{{test}}", "50");}
@Test public void Exc_2() {fxt.Test_parse_tmpl_str_test("{{#titleparts:50|1|2}}" , "{{test}}", "");}
@Test public void Lnki() {fxt.Test_parse_tmpl_str_test("{{#titleparts:[[a|b]]|1}}" , "{{test}}", "[[a|b]]");} // PURPOSE: invalid title was not being rendered
@Test public void Invalid_table() {// PURPOSE: Template:Taxobox/showtaxon calls #titleparts on table fragments; do not remove new lines; PAGE:en.w:Owl
fxt.Init_defn_clear();
fxt.Init_defn_add("!", "|");
fxt.Init_defn_add("!!", "||");
fxt.Test_parse_tmpl_str_test
( String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "{{#titleparts:"
, "{{!}} Order: {{!!}} '''Strigiformes'''"
, "{{!}}-|1}}"
, "|}"
)
, "{{test}}"
, String_.Concat_lines_nl_skip_last
( "" // NOTE: don't know why this new line is necessary, but hopefully it is benign
, "{|"
, "|-"
, "| Order: || '''Strigiformes'''"
, "|-"
, "|}"
)
);
}
@Test public void Invalid_xml() {// PURPOSE: handle calls like {{#titleparts:a<span id='b'>c</span>d|1}}; PAGE:en.w:Triceratops
fxt.Test_parse_tmpl_str_test
( "{{#titleparts:a<span id='b'>c</span>d/e|1}}"
, "{{test}}"
, "a<span id='b'>c</span>d/e"
);
}
@Test public void Bgn_neg_1() {fxt.Test_parse_tmpl_str_test("{{#titleparts:a/b/c/d||-1}}" , "{{test}}", "d");}
@Test public void Bgn_neg_2() { // PURPOSE: EX: Wikisource:Requests for comment/Annotations and derivative works; DATE:2013-12-19
fxt.Test_parse_tmpl_str_test
( "{{#titleparts:a/b|-1|-2}}"
, "{{test}}"
, "A"
);
}
}

View File

@@ -0,0 +1,49 @@
/*
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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_ttl_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Ttl_page_txt() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAME}}" , "{{test}}", "A b");}
@Test public void Ttl_page_txt_empty() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAME:}}" , "{{test}}", "");}
@Test public void Ttl_page_txt_empty_2() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAME:{{{a|}}}}}" , "{{test}}", "");} // PURPOSE.fix: {{PAGENAME:{{{nom|}}}}} should return ""; pt.wikipedia.org/wiki/Nicholas Kratzer; DATE:2013-02-20
@Test public void Ttl_page_txt_arg() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAME:c d}}" , "{{test}}", "C d");}
@Test public void Ttl_page_txt_amp() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAME:c & d}}" , "{{test}}", "C & d");}
@Test public void Ttl_page_url() {fxt.Page_ttl_("a b"); fxt.Test_parse_tmpl_str_test("{{PAGENAMEE}}" , "{{test}}", "A_b");}
@Test public void Ttl_full_txt() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{FULLPAGENAME}}" , "{{test}}", "Help:A b");}
@Test public void Ttl_full_url() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{FULLPAGENAMEE}}" , "{{test}}", "Help:A_b");}
@Test public void Ttl_leaf_txt() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{SUBPAGENAME}}" , "{{test}}", "d e");}
@Test public void Ttl_leaf_url() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{SUBPAGENAMEE}}" , "{{test}}", "d_e");}
@Test public void Ttl_base_txt() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{BASEPAGENAME}}" , "{{test}}", "A b/c");}
@Test public void Ttl_base_url() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{BASEPAGENAMEE}}" , "{{test}}", "A_b/c");}
@Test public void Rootpagename() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{ROOTPAGENAME}}" , "{{test}}", "A b");}
@Test public void Rootpagenamee() {fxt.Page_ttl_("a b/c/d e"); fxt.Test_parse_tmpl_str_test("{{ROOTPAGENAMEE}}" , "{{test}}", "A_b");}
@Test public void Ttl_subj_txt() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{SUBJECTPAGENAME}}" , "{{test}}", "Help:A b");}
@Test public void Ttl_subj_url() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{SUBJECTPAGENAMEE}}" , "{{test}}", "Help:A_b");}
@Test public void Ttl_talk_txt() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{TALKPAGENAME}}" , "{{test}}", "Help talk:A b");}
@Test public void Ttl_talk_url() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{TALKPAGENAMEE}}" , "{{test}}", "Help_talk:A_b");}
@Test public void Ns_num() {fxt.Page_ttl_("Help:A"); fxt.Test_parse_tmpl_str_test("{{NAMESPACENUMBER}}" , "{{test}}", "12");}
@Test public void Ns_txt() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{NAMESPACE}}" , "{{test}}", "Help talk");}
@Test public void Ns_url() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{NAMESPACEE}}" , "{{test}}", "Help_talk");}
@Test public void Ns_subj_txt() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{SUBJECTSPACE}}" , "{{test}}", "Help");}
@Test public void Ns_subj_url() {fxt.Page_ttl_("Help talk:a b"); fxt.Test_parse_tmpl_str_test("{{SUBJECTSPACEE}}" , "{{test}}", "Help");}
@Test public void Ns_talk_txt() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{TALKSPACE}}" , "{{test}}", "Help talk");}
@Test public void Ns_talk_url() {fxt.Page_ttl_("Help:a b"); fxt.Test_parse_tmpl_str_test("{{TALKSPACEE}}" , "{{test}}", "Help_talk");}
@Test public void Ns_safesubst() {fxt.Page_ttl_("Help:a"); fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}NAMESPACE}}" , "{{test}}", "Help");} // PURPOSE: "safesubst:NAMESPACE" was being interpreted as "NAMESPACE:" due to false colon detection; DATE:2013-11-11
@Test public void Ns_safesubst2() {fxt.Page_ttl_("Help:a"); fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}NAMESPACE:}}" , "{{test}}", "");} //PURPOSE: makes sure "safesubst:NAMESPACE:" still returns ""
@Test public void Exc_empty2() {fxt.Page_ttl_("Test"); fxt.Test_parse_tmpl_str_test("{{NAMESPACE:<noinclude>x</noinclude>}}" , "{{test}}", "");} // {{NMS:<ni>x</ni>}} -> {{NMS:}}
}

Some files were not shown because too many files have changed in this diff Show More