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

Command-line: Fix curid argument not working 2

This commit is contained in:
gnosygnu
2017-02-22 08:44:14 -05:00
parent 0e85cc90ff
commit 5bd3371802
896 changed files with 1 additions and 69011 deletions

View File

@@ -1,311 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.*; import gplx.core.intls.ucas.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr__basic__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
@Test public void Page_itm() {
fxt .Init_itms__pages("A1")
.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>");
}
@Test public void Page_itm_missing() {
fxt.Init_itms__pages("A1");
Xoctg_catpage_itm itm = fxt.Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0);
itm.Page_ttl_(Xoa_ttl.Null);
itm.Sortkey_handle_make(Bry_bfr_.New(), Bry_.Empty);
fxt.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">missing page (0)</li>");
}
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
byte[] page_bry = Bry_.new_a7("A 1");
Xoa_url url = Xoa_url.New(Bry_.new_a7("en.wikipedia.org"), page_bry);
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry);
fxt.Wiki().Appe().Usere().History_mgr().Add(fxt.Wiki().App(), url, ttl, page_bry);
fxt .Init_itms__pages("A_1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A_1\" class=\"xowa-visited\" title=\"A 1\">A 1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all() {
fxt .Init_itms__pages("A1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void File_all() {
fxt .Init_itms__files("File:A1.png")
.Test__html__all(Xoa_ctg_mgr.Tid__file, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-category-media\">"
, " <h2>Media in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following file.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/File:A1.png\" title=\"File:A1.png\">File:A1.png</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Subc_all() {
fxt .Init_itms__subcs("Category:Subc_1")
.Test__html__all(Xoa_ctg_mgr.Tid__subc, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-subcategories\">"
, " <h2>Subcategories</h2>"
, " <p>This category has only the following subcategory.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>S</h3>"
, " <ul>"
, " <li>"
, " <div class=\"CategoryTreeSection\">"
, " <div class=\"CategoryTreeItem\">"
, " <span class=\"CategoryTreeBullet\">"
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"Subc_1\" title=\"Subc 1\" data-ct-state=\"collapsed\">"
, " </span> "
, " </span>"
, " <a href=\"/wiki/Category:Subc_1\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">Subc 1"
, " </a>"
, " <span title=\"contains 0 subcategories, 0 pages, and 0 files\" dir=\"ltr\">"
, " </span>"
, " </div>"
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
, " </div>"
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all_cols() {
fxt.Init_itms__pages("A1", "A2", "A3", "B1", "C1");
fxt.Init__grp_max_(6);
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>The following 5 pages are in this category, out of 5 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " <li><a href=\"/wiki/A2\" title=\"A2\">A2</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>A cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A3\" title=\"A3\">A3</a></li>"
, " </ul>"
, " <h3>B</h3>"
, " <ul>"
, " <li><a href=\"/wiki/B1\" title=\"B1\">B1</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>C</h3>"
, " <ul>"
, " <li><a href=\"/wiki/C1\" title=\"C1\">C1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page__numeric() { // PURPOSE: check numeric sorting; 0, 9, 10; not 0, 10, 9; DATE:2016-10-09
fxt.Init_itms__pages("0", "9", "10");
fxt.Init__grp_max_(6);
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>The following 3 pages are in this category, out of 3 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>0-9</h3>"
, " <ul>"
, " <li><a href=\"/wiki/0\" title=\"0\">0</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/9\" title=\"9\">9</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/10\" title=\"10\">10</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28
fxt .Init_itms__pages("A\"1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A%221\" title=\"A&quot;1\">A&quot;1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Calc_col_len() {
fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items
fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items
fxt.Test__calc_col_len(10, 2, 3); // for 10 items, col 2 has 3 items
fxt.Test__calc_col_len(11, 0, 4);
fxt.Test__calc_col_len(11, 1, 4);
fxt.Test__calc_col_len(11, 2, 3);
fxt.Test__calc_col_len(12, 0, 4);
fxt.Test__calc_col_len(12, 1, 4);
fxt.Test__calc_col_len(12, 2, 4);
}
}
class Xoctg_catpage_mgr_fxt {
private int grp_max;
private Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true);
public Xoctg_catpage_mgr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
ctg_html = wiki.Ctg__catpage_mgr();
}
ctg = new Xoctg_catpage_ctg(1, Bry_.new_a7("Ctg_1"));
grp_max = 3; // default to 3 paer page
return this;
} private Xoae_app app; private Xoctg_catpage_mgr ctg_html;
public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg;
public void Init__grp_max_(int v) {this.grp_max = v;}
public void Init__prev_hide_y_(byte tid) {ctg.Grp_by_tid(tid).Prev_disable_(true);}
public void Init__next_sortkey_(byte tid, String v) {ctg.Grp_by_tid(tid).Next_sortkey_(Bry_.new_u8(v));}
public void Test__navlink(boolean next, String ctg_str, String expd) {
byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid__page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid__page), grp_max);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public Xoctg_catpage_mgr_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__page, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__file, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__subc, titles);}
private Xoctg_catpage_mgr_fxt Init_itms(byte tid, String[] ttls) {
int len = ttls.length;
Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp();
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
grp.Count_all_(len);
for (int i = 0; i < len; ++i) {
byte[] page_ttl_bry = Bry_.new_u8(ttls[i]);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page_ttl_bry);
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl);
tmp.Add(itm);
}
tmp.Make_by_grp(grp);
return this;
}
public void Test__html__page(byte tid, byte grp_char_0, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_itm_base itm_fmt = list_mgr.Itm_fmt();
Xoctg_catpage_grp list = ctg.Grp_by_tid(tid);
itm_fmt.Init_from_ltr(wiki, list, ltr_extractor);
itm_fmt.Set_ltr_and_bgn(new byte[] {grp_char_0}, 0);
itm_fmt.Col_end_(0, 0);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
itm_fmt.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test__html_grp(byte tid, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_ltr fmtr_grp = new Xoctg_fmt_ltr(list_mgr.Itm_fmt());
fmtr_grp.Init_from_grp(wiki, ctg.Grp_by_tid(tid), ltr_extractor);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
fmtr_grp.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test__html__all(byte tid, String expd) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ltr_extractor, ctg, grp_max);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
}

View File

@@ -1,57 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr__navlink__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
@Test public void Navlink__basic() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
fxt.Init_itms__pages("A\" 2", "A\" 3", "A\" 4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A\" 5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2%0AA%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__bos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__prev_hide_y_(Xoa_ctg_mgr.Tid__page);
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(previous 3)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__eos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(next 3)"
));
}
}

View File

@@ -1,37 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
public class Xoctg_catlink_loader__tst {
private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt();
@Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record
fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'"
}
@Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed
fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'"
}
}
class Xoctg_catlink_loader__fxt {
public void Test__build_sortkey_sql(int version, String sortkey, String expd) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation
Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki);
Bry_bfr bfr = Bry_bfr_.New();
Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey)));
}
}

View File

@@ -1,39 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoctg_collation_wkr___tst {
private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt();
@Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");}
@Test public void Identity() {fxt.Test__make("identity" , "identity");}
@Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");}
@Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);}
@Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);}
@Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);}
@Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);}
@Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);}
}
class Xoctg_collation_wkr___fxt {
public void Test__make(String wm_name, String expd_type) {
Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_type, actl.Type_name());
}
public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) {
Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_locale, actl.Icu_locale());
Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting());
}
}

View File

@@ -1,45 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
public class Xoctg_catpage_url__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url__fxt fxt = new Xoctg_catpage_url__fxt();
@Test public void Specific() {
fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void General() {
fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void Url_encoded() {
fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
}
}
class Xoctg_catpage_url__fxt {
private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url;
public void Clear() {
Xoa_app app = Xoa_app_fxt.Make__app__edit();
this.xo_url_parser = app.User().Wikii().Utl__url_parser();
}
public Xoctg_catpage_url__fxt Exec__parse(String url_str) {
Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str));
this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url);
return this;
}
public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;}
public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;}
}

View File

@@ -1,83 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
import org.junit.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xoctg_double_box__tst {
@Before public void init() {fxt.Clear();} private Xoctg_double_box__fxt fxt = new Xoctg_double_box__fxt();
@Test public void Basic() {
fxt.Init_ctg_hidden("Category:A", "Category:B", "Category:C");
fxt.Init_ctg_normal("Category:D", "Category:E", "Category:F");
fxt.Test_print_hidden(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "<a href=\"/wiki/Special:Categories\" title=\"Special:Categories\">Categories</a>:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:D\" title=\"Category:D\">D</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:E\" title=\"Category:E\">E</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:F\" title=\"Category:F\">F</a>"
, "</li>"
, "</ul>"
, "</div>"
, "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">Hidden categories:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" title=\"Category:A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" title=\"Category:B\">B</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:C\" title=\"Category:C\">C</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoctg_double_box__fxt {
private Xop_fxt fxt; private Xoctg_double_box hidden_wtr;
private final List_adp init_ctgs = List_adp_.New();
public void Clear() {
fxt = new Xop_fxt();
hidden_wtr = new Xoctg_double_box();
hidden_wtr.Init_by_wiki(fxt.Wiki());
init_ctgs.Clear();
}
public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);}
public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);}
public void Init_ctg(boolean hidden, String[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ary[i]));
Xoctg_pagebox_itm itm = Xoctg_pagebox_itm.New_by_ttl(ttl);
itm.Load_by_cat_core(hidden, 0, 0, 0);
init_ctgs.Add_many(itm);
}
}
public void Test_print_hidden(String expd) {
Bry_bfr bfr = Bry_bfr_.New();
Xoctg_pagebox_itm[] ary = (Xoctg_pagebox_itm[])init_ctgs.To_ary_and_clear(Xoctg_pagebox_itm.class);
hidden_wtr.Write_pagebox(bfr, ary);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -1,60 +0,0 @@
/*
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.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
import org.junit.*;
import gplx.xowa.htmls.core.htmls.*;
public class Xoctg_single_box__tst {
@Before public void init() {fxt.Clear();} private final Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt();
@Test public void Basic() {
fxt.Init__ctgs("Category:A", "Category:B").Test_html(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "Categories"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoh_ctg_mgr_fxt {
private Xoctg_single_box ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr_.New();
private Xoae_page page;
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
page = wiki.Parser_mgr().Ctx().Page();
ctg_grp_mgr = new Xoctg_single_box();
ctg_grp_mgr.Init_by_wiki(wiki);
}
public Xoh_ctg_mgr_fxt Init__ctgs(String... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
page.Wtxt().Ctgs__add(wiki.Ttl_parse(Bry_.new_u8(ary[i])));
}
return this;
}
public void Test_html(String expd) {
ctg_grp_mgr.Write_pagebox(tmp_bfr, Xoctg_pagebox_itm.New_ary(page));
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -1,70 +0,0 @@
/*
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.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
import gplx.xowa.wikis.data.*;
public class Xowdir_wiki_props_mgr__tst {
private final Xowdir_wiki_props_mgr__fxt fxt = new Xowdir_wiki_props_mgr__fxt();
@Test public void Import__wiki__missing_all() {
// handle all imported .xowa wikis pre v4.3
fxt.Init__wiki_props(null, null, null);
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__missing_domain() {
// handle personal wikis from v4.2
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__wmf_domain() {
// handle wmf wikis with a core-file of "test-core.xowa"
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test-core.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__clean() {
// handle clean wiki
fxt.Init__wiki_props("test", "test", "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.N, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Open__wiki__missing_name() {
// handle missing name
fxt.Init__user_json("test", "my test", "Main_Page");
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.N, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "my test", "Main_Page"));
}
}
class Xowdir_wiki_props_mgr__fxt {
private final Xowdir_wiki_props_mgr mgr = new Xowdir_wiki_props_mgr__mock();
public Xowdir_wiki_props Make__json(String domain, String name, String main_page) {
return new Xowdir_wiki_props(domain, name, main_page);
}
public void Init__user_json(String domain, String name, String main_page) {
Xowdir_wiki_json wiki_json = new Xowdir_wiki_json(name, main_page);
mgr.User_reg__upsert(domain, wiki_json.To_str(new Json_wtr()));
}
public void Init__wiki_props(String domain, String name, String main_page) {
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__domain, domain);
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__name, name);
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__init__main_page, main_page);
}
public void Test__verify(boolean mode_is_import, String url, boolean expd_dirty, Xowdir_wiki_props expd) {
Xowdir_wiki_props actl = mgr.Verify(mode_is_import, "", Io_url_.new_any_(url));
Gftest.Eq__ary__lines(expd.To_str(), actl.To_str(), "expd");
Gftest.Eq__bool(expd_dirty, actl.Dirty(), "dirty");
}
}

View File

@@ -1,118 +0,0 @@
/*
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.addons.wikis.htmls.css.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.htmls.*; import gplx.xowa.addons.wikis.htmls.css.*;
import org.junit.*; import gplx.core.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.htmls.css.dbs.*;
public class Xowd_css_core_mgr_tst {
@Before public void init() {fxt.Clear();} private Xowd_css_core_mgr_fxt fxt = new Xowd_css_core_mgr_fxt();
@Test public void Basic() {
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050200")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
Io_url trg_dir = Io_url_.mem_dir_("mem/trg/");
fxt.Exec_get(trg_dir, "desktop");
fxt.Test_fs(trg_dir, file_ary);
}
@Test public void Update() { // update css files; keep same skin_id; insert new files
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050500")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a1.css", "a1_data")
, fxt.Make_file_itm(1, "b/b1.png", "b/b1_data")
);
Io_mgr.Instance.DeleteDirDeep(src_dir);
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
}
}
class Xowd_css_core_mgr_fxt {
private final Bry_bfr bfr = Bry_bfr_.Reset(32);
private Xowd_css_core_tbl core_tbl; private Xowd_css_file_tbl file_tbl;
public void Clear() {
Datetime_now.Manual_y_();
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/css.sqlite3"));
this.core_tbl = new Xowd_css_core_tbl(conn);
this.file_tbl = new Xowd_css_file_tbl(conn);
core_tbl.Create_tbl();
file_tbl.Create_tbl();
}
public Xowd_css_core_itm Make_skin_itm(int id, String key, String updated_on) {return new Xowd_css_core_itm(id, key, DateAdp_.parse_gplx(updated_on));}
public Xowd_css_file_itm Make_file_itm(int skin_id, String path, String data) {return new Xowd_css_file_itm(skin_id, path, Bry_.new_u8(data));}
public Xowd_css_file_itm[] Make_file_ary(Xowd_css_file_itm... ary) {return ary;}
public Xowd_css_core_itm[] Make_skin_ary(Xowd_css_core_itm... ary) {return ary;}
public void Init_fs(Io_url css_dir, Xowd_css_file_itm[] file_ary) {
for (Xowd_css_file_itm itm : file_ary)
Io_mgr.Instance.SaveFilBry(css_dir.GenSubFil(itm.Path()), itm.Data());
}
public void Exec_set(Io_url css_dir, String key) {Xowd_css_core_mgr.Set(core_tbl, file_tbl, css_dir, key);}
public void Exec_get(Io_url css_dir, String key) {Xowd_css_core_mgr.Get(core_tbl, file_tbl, css_dir, key);}
public void Test_skin_tbl(Xowd_css_core_itm[] expd) {
Xowd_css_core_itm[] actl = core_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_file_tbl(Xowd_css_file_itm[] expd) {
Xowd_css_file_itm[] actl = file_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_fs(Io_url css_dir, Xowd_css_file_itm[] expd) {
Io_url[] actl = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
int len = expd.length;
Tfds.Eq(len, actl.length);
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm expd_itm = expd[i];
Tfds.Eq_bry(expd_itm.Data(), Io_mgr.Instance.LoadFilBry(actl[i]));
}
}
private String To_str(Xowd_css_file_itm[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm itm = ary[i];
bfr.Add_int_variable(itm.Css_id()).Add_byte_pipe().Add_str_u8(itm.Path()).Add_byte_pipe().Add(itm.Data()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
private String To_str(Xowd_css_core_itm[] ary) {
Bry_bfr bfr = Bry_bfr_.New();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_core_itm itm = ary[i];
bfr.Add_int_variable(itm.Id()).Add_byte_pipe().Add_str_u8(itm.Key()).Add_byte_pipe().Add_str_u8(itm.Updated_on().XtoStr_fmt_yyyyMMdd_HHmmss()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
}

View File

@@ -1,54 +0,0 @@
/*
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.addons.wikis.pages.randoms.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.randoms.*;
import org.junit.*; import gplx.xowa.specials.*;
public class Rndm_root_special_tst {
@Before public void init() {fxt.Clear();} private Rndm_root_special_fxt fxt = new Rndm_root_special_fxt();
@Test public void Ns_main() {
fxt.Init_create_page("A");
fxt.Init_create_page("A/B/C");
fxt.Test_open("Special:RandomRootPage/Main", "A"); // NOTE: result will always be "A"; "A" -> "A"; "A/B/C" -> "A"
}
@Test public void Ns_help() {
fxt.Init_create_page("Help:A");
fxt.Init_create_page("Help:A/B/C");
fxt.Test_open("Special:RandomRootPage/Help", "Help:A");
}
}
class Rndm_root_special_fxt {
private Xop_fxt parser_fxt; private Rndm_root_special special_page; private Xowe_wiki wiki;
public void Clear() {
parser_fxt = new Xop_fxt();
parser_fxt.Reset();
wiki = parser_fxt.Wiki();
special_page = new gplx.xowa.addons.wikis.pages.randoms.specials.Rndm_root_special();
}
public void Init_create_page(String page) {parser_fxt.Init_page_create(page, page);}
public void Test_open(String special_url, String expd) {
Xoae_page page = Test_special_open(wiki, special_page, special_url);
Tfds.Eq(expd, String_.new_a7(page.Url().Page_bry()));
Tfds.Eq(expd, String_.new_a7(page.Db().Text().Text_bry()));
}
public static Xoae_page Test_special_open(Xowe_wiki wiki, Xow_special_page special_page, String special_url) {
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(special_url));
page.Url_(url);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(special_url));
page.Ttl_(ttl);
special_page.Special__gen(wiki, page, url, ttl);
return page;
}
}

View File

@@ -1,50 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import gplx.core.tests.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import gplx.xowa.addons.wikis.pages.syncs.core.parsers.*;
public class Xosync_page_loader__fxt {
private final Xosync_page_loader mgr = new Xosync_page_loader();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final Xoh_page hpg = new Xoh_page();
private Xowe_wiki wiki;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
hpg.Clear();
}
public Xosync_page_loader__fxt Exec__parse(String raw) {
mgr.Parse(wiki, hpg, Bry_.new_u8(raw));
return this;
}
public Xosync_page_loader__fxt Test__html(String expd) {
Gftest.Eq__ary__lines(expd, hpg.Db().Html().Html_bry(), "converted html");
return this;
}
public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, String orig_ext_str, int file_w, double file_time, int file_page) {
Xof_fsdb_itm itm = new Xof_fsdb_itm();
Xof_ext orig_ext = Xof_ext_.new_by_ext_(Bry_.new_u8(orig_ext_str));
itm.Init_by_wm_parse(wiki.Domain_itm().Abrv_xo(), repo_is_commons, file_is_orig, Bry_.new_u8(file_ttl), orig_ext, file_w, file_time, file_page);
return itm;
}
public Xosync_page_loader__fxt Test__fsdb(Xof_fsdb_itm expd) {
Xof_fsdb_itm actl = (Xof_fsdb_itm)hpg.Img_mgr().Get_at(0);
Gftest.Eq__str(Xosync_hdoc_parser__fxt.To_str(tmp_bfr, expd), Xosync_hdoc_parser__fxt.To_str(tmp_bfr, actl));
return this;
}
}

View File

@@ -1,39 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import org.junit.*;
import gplx.langs.htmls.*;
public class Xosync_page_loader__tst {
@Before public void init() {fxt.Clear();} private final Xosync_page_loader__fxt fxt = new Xosync_page_loader__fxt();
@Test public void File() {
fxt.Exec__parse(Gfh_utl.Replace_apos("a<img src='xowa:/file/commons.wikimedia.org/thumb/4/a/6/9/Commons-logo.svg/12px.png' width='12' height='20'>b"))
.Test__html(Gfh_utl.Replace_apos("a<img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/4/a/6/9/Commons-logo.svg/12px.png' width='12' height='20'>b"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "Commons-logo.svg", "svg", 12, -1, -1))
;
}
@Test public void Math() {
fxt.Exec__parse(Gfh_utl.Replace_apos("a<img src='xowa:/math/596f8baf206a81478afd4194b44138715dc1a05c' width='12' height='20'>b"))
.Test__html(Gfh_utl.Replace_apos("a<img id='xoimg_0' src='file:///mem/xowa/file/math/596f8baf206a81478afd4194b44138715dc1a05c' width='12' height='20'>b"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.Y, "596f8baf206a81478afd4194b44138715dc1a05c", "svg", -1, -1, -1))
;
}
@Test public void Ogg() {
fxt.Exec__parse(Gfh_utl.Replace_apos("a<img src='xowa:/file/commons.wikimedia.org/thumb/4/2/7/e/A.ogg/320px.jpg'>b"))
.Test__html(Gfh_utl.Replace_apos("a<img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/4/2/7/e/A.ogg/320px.jpg'>b"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, -1, -1))
;
}
}

View File

@@ -1,45 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import org.junit.*;
import gplx.langs.htmls.*;
public class Xosync_hdoc_parser__err__tst {
@Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt();
@Test public void Url_does_not_start_with_upload_wikimedia_org() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//fail/wikipedia/commons/thumb/7/70/A.png/220px-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<!--wm.parse:img src does not start with known sequence--><img src='//fail/wikipedia/commons/thumb/7/70/A.png/220px-A.png'>"));
}
@Test public void Unknown_repo() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wiktionary/fr/thumb/7/70/A.png/220px-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<!--wm.parse:unknown repo--><img src='//upload.wikimedia.org/wiktionary/fr/thumb/7/70/A.png/220px-A.png'>"));
}
@Test public void Bad_md5() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/fail/A.png/220px-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<!--wm.parse:invalid md5--><img src='//upload.wikimedia.org/wikipedia/commons/thumb/fail/A.png/220px-A.png'>"));
}
@Test public void Missing_px() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<!--wm.parse:missing px--><img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220-A.png'>"));
}
@Test public void Bad_file_w() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220_fail_px-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<!--wm.parse:invalid file_w--><img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220_fail_px-A.png'>"));
}
@Test public void Comment() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<i>a<!-- - --></i><b>b</b><i>c</i>"))
.Test__html(Gfh_utl.Replace_apos("<i>a</i><b>b</b><i>c</i>"));
}
}

View File

@@ -1,56 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import org.junit.*;
import gplx.langs.htmls.*;
public class Xosync_hdoc_parser__file__tst {
@Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt();
@Test public void Commons__thumb() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/320px-A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/7/0/1/c/A.png/320px.png'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.png", 320, -1, -1));
}
@Test public void Url_encoded() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/9/91/A%2CB.png/320px-A%2CB.png'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/9/1/0/8/A%2CB.png/320px.png'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A,B.png", 320, -1, -1));
}
@Test public void Local__orig() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/en/7/70/A.png'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/en.wikipedia.org/orig/7/0/1/c/A.png'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.N, Bool_.Y, "A.png", -1, -1, -1));
}
@Test public void Svg() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/75/A.svg/12px-A.svg.png'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/7/5/9/a/A.svg/12px.png'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.svg", 12, -1, -1));
}
@Test public void Ogg() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/4/42/A.ogg/320px--A.ogg.jpg'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/4/2/7/e/A.ogg/320px.jpg'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, -1, -1));
}
@Test public void Ogg__time() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/4/42/A.ogg/320px-seek%3D1.2-A.ogg.jpg'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/4/2/7/e/A.ogg/320px-1.2.jpg'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, 1.2, -1));
}
@Test public void Pdf__page() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='//upload.wikimedia.org/wikipedia/commons/thumb/7/76/A.djvu/page1-320px-A.djvu.jpg'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/file/commons.wikimedia.org/thumb/7/6/9/a/A.djvu/320px-1.jpg'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.djvu", 320, -1, 1));
}
}

View File

@@ -1,69 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import gplx.core.tests.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
public class Xosync_hdoc_parser__fxt {
private final Xosync_update_mgr mgr = new Xosync_update_mgr();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final Xoh_page hpg = new Xoh_page();
private Xowe_wiki wiki;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
Xoa_app_fxt.repo2_(app, wiki);
mgr.Init_by_app(app);
mgr.Init_by_page(wiki, hpg);
}
public Xosync_hdoc_parser__fxt Exec__parse(String raw) {
mgr.Parse(hpg, wiki, Bry_.Empty, Bry_.new_u8(raw));
return this;
}
public Xosync_hdoc_parser__fxt Test__html(String expd) {
Gftest.Eq__ary__lines(expd, hpg.Db().Html().Html_bry(), "converted html");
return this;
}
public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, int file_w, double file_time, int file_page) {
return Make__fsdb(repo_is_commons, file_is_orig, file_ttl, Xof_ext_.new_by_ttl_(Bry_.new_u8(file_ttl)), file_w, file_time, file_page);
}
public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, String file_ext, int file_w, double file_time, int file_page) {
return Make__fsdb(repo_is_commons, file_is_orig, file_ttl, Xof_ext_.new_by_ext_(Bry_.new_u8(file_ext)), file_w, file_time, file_page);
}
public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, Xof_ext file_ext, int file_w, double file_time, int file_page) {
Xof_fsdb_itm itm = new Xof_fsdb_itm();
itm.Init_by_wm_parse(wiki.Domain_itm().Abrv_xo(), repo_is_commons, file_is_orig, Bry_.new_u8(file_ttl), file_ext, file_w, file_time, file_page);
return itm;
}
public Xosync_hdoc_parser__fxt Test__fsdb(Xof_fsdb_itm expd) {
Xof_fsdb_itm actl = (Xof_fsdb_itm)hpg.Hdump_mgr().Imgs().Get_at(0);
Gftest.Eq__str(To_str(tmp_bfr, expd), To_str(tmp_bfr, actl));
return this;
}
public static String To_str(Bry_bfr tmp_bfr, Xof_fsdb_itm itm) {
To_bfr(tmp_bfr, itm);
return tmp_bfr.To_str_and_clear();
}
private static void To_bfr(Bry_bfr bfr, Xof_fsdb_itm itm) {
bfr.Add_str_a7(itm.Orig_repo_id() == Xof_repo_tid_.Tid__remote ? "remote" : "local").Add_byte_pipe();
bfr.Add_str_a7(itm.File_is_orig() ? "orig" : "thumb").Add_byte_pipe();
bfr.Add(itm.Orig_ttl()).Add_byte_pipe();
bfr.Add(itm.Orig_ext().Ext()).Add_byte_pipe();
bfr.Add_int_variable(itm.File_w()).Add_byte_pipe();
bfr.Add_double(itm.Lnki_time()).Add_byte_pipe();
bfr.Add_int_variable(itm.Lnki_page()).Add_byte_pipe();
}
}

View File

@@ -1,26 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import org.junit.*;
import gplx.langs.htmls.*;
public class Xosync_hdoc_parser__misc__tst {
@Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt();
@Test public void Math() {
fxt.Exec__parse(Gfh_utl.Replace_apos("<img src='https://wikimedia.org/api/rest_v1/media/math/render/svg/596f8baf206a81478afd4194b44138715dc1a05c' class='mwe-math-fallback-image-inline' aria-hidden='true' style='vertical-align: -2.005ex; width:16.822ex; height:6.176ex;' alt='R_{H}=a\\left({\\frac {m}{3M}}\\right)^{\\frac {1}{3}}'>"))
.Test__html(Gfh_utl.Replace_apos("<img src='xowa:/math/596f8baf206a81478afd4194b44138715dc1a05c.svg' class='mwe-math-fallback-image-inline' aria-hidden='true' style='vertical-align: -2.005ex; width:16.822ex; height:6.176ex;' alt='R_{H}=a\\left({\\frac {m}{3M}}\\right)^{\\frac {1}{3}}'>"))
.Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.Y, "596f8baf206a81478afd4194b44138715dc1a05c.svg", -1, -1, -1));
}
}

View File

@@ -1,39 +0,0 @@
/*
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.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import org.junit.*;
import gplx.langs.htmls.*;
public class Xosync_hdoc_parser__tst {
@Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt();
@Test public void Remove_edit() {
fxt.Exec__parse(Gfh_utl.Replace_apos_concat_lines
( "<h2><span class='mw-headline' id='Section_1'>Section_1</span>"
, "<span class='mw-editsection'>"
, "<span class='mw-editsection-bracket'>[</span><a href='/w/index.php?title=Page_1&amp;action=edit&amp;section=1' title='Edit section: Section_1'>edit</a>"
, "<span class='mw-editsection-bracket'>]</span>"
, "</span>"
, "</h2>"
)).Test__html(Gfh_utl.Replace_apos_concat_lines
( "<h2><span class='mw-headline' id='Section_1'>Section_1</span>"
, ""
, "</h2>"
));
}
// @Test public void Smoke() {
// fxt.Exec__parse(Io_mgr.Instance.LoadFilStr("C:\\xowa\\dev\\wm.updater.src.html"));
// Io_mgr.Instance.SaveFilBry("C:\\xowa\\dev\\wm.updater.trg.html", fxt.Hdoc().Converted());
// }
}

View File

@@ -1,45 +0,0 @@
/*
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.addons.wikis.searchs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*;
import org.junit.*; import gplx.xowa.langs.cases.*;
public class Srch_highlight_mgr_tst {
private final Srch_highlight_mgr_tstr tstr = new Srch_highlight_mgr_tstr();
@Test public void Full__one() {tstr.Test("a" , "A" , "<strong>A</strong>");}
@Test public void Full__many() {tstr.Test("a b" , "A B" , "<strong>A</strong> <strong>B</strong>");}
@Test public void Part__one() {tstr.Test("a" , "A1" , "<strong>A</strong>1");}
@Test public void Part__many() {tstr.Test("a b" , "A1 B1" , "<strong>A</strong>1 <strong>B</strong>1");}
@Test public void Unordered() {tstr.Test("b a" , "A1 B1" , "<strong>A</strong>1 <strong>B</strong>1");}
@Test public void Repeat__part() {tstr.Test("a ab" , "Ab A" , "<strong>Ab</strong> <strong>A</strong>");}
@Test public void Repeat__full() {tstr.Test("a" , "A A" , "<strong>A</strong> <strong>A</strong>");}
@Test public void Close() {tstr.Test("a" , "Ba Aa" , "Ba <strong>A</strong>a");}
@Test public void Comma() {tstr.Test("a" , "A, b" , "<strong>A</strong>, b");}
@Test public void Dash() {tstr.Test("b" , "A-B c" , "A-<strong>B</strong> c");}
@Test public void Parens() {tstr.Test("a" , "(A)" , "(<strong>A</strong>)");}
@Test public void Strong() {tstr.Test("strong" , "strong strong" , "<strong>strong</strong> <strong>strong</strong>");}
@Test public void Dash_w_mixed_cases() {tstr.Test("b" , "A-a B" , "A-a <strong>B</strong>");} // search_parser treats A-a separately from a-a
@Test public void Acronymn() {tstr.Test("ab" , "A.B." , "A.B.");}
// @Test public void Slash() {tstr.Test("b" , "A/B/C" , "A/<strong>B</strong>/C");}
}
class Srch_highlight_mgr_tstr {
private final Srch_highlight_mgr mgr;
private final Xol_case_mgr case_mgr = Xol_case_mgr_.A7();
public Srch_highlight_mgr_tstr() {
mgr = new Srch_highlight_mgr(case_mgr);
}
public void Test(String search, String title, String expd) {
Tfds.Eq(expd, String_.new_u8(mgr.Search_(Bry_.new_u8(search)).Highlight(Bry_.new_u8(title))));
}
}

View File

@@ -1,145 +0,0 @@
/*
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.addons.wikis.searchs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*;
import org.junit.*; import gplx.xowa.langs.cases.*;
public class Srch_text_parser_tst {
private final Srch_text_parser_fxt fxt = new Srch_text_parser_fxt();
@Before public void init() {fxt.Init();}
@Test public void Word__one() {fxt.Clear().Test__split("abcd" , "abcd");}
@Test public void Word__many() {fxt.Clear().Test__split("abc d ef" , "abc", "d", "ef");}
@Test public void Ws__many() {fxt.Clear().Test__split("a b" , "a", "b");}
@Test public void Ws__bgn() {fxt.Clear().Test__split(" a" , "a");}
@Test public void Ws__end() {fxt.Clear().Test__split("a " , "a");}
@Test public void Under() {fxt.Clear().Test__split("a_b" , "a", "b");} // NOTE: same as space
@Test public void Lowercase() {fxt.Clear().Test__split("A B C" , "a", "b", "c");}
@Test public void Dupe() {fxt.Clear().Test__split("a a a" , fxt.Make_word("a", 3));}
@Test public void Dupe__lowercase() {fxt.Clear().Test__split("a A" , fxt.Make_word("a", 2));}
@Test public void Comma__end() {fxt.Clear().Test__split("a, b" , "a", "b");} // EX: "Henry VI, Part 3"; "Bergen County, New Jersey"
@Test public void Comma__mid() {fxt.Clear().Test__split("a,b" , "a,b");} // EX: "20,000 Leagues Under the Sea"
@Test public void Comma__bgn() {fxt.Clear().Test__split(",a b" , "a", "b");} // EX: skip bad usages; EX: "Little Harbour,Pictou ,Nova Scotia"; "The Hindu Succession Act ,1956"
@Test public void Colon__end() {fxt.Clear().Test__split("a: b" , "a", "b");}
@Test public void Colon__mid() {fxt.Clear().Test__split("a:b" , "a:b");} // EX: "3:10 to Yuma (2007 film)"; "6:02 AM EST"; "24:7 Theatre Festival"; "Library of Congress Classification:Class P -- Language and Literature"
@Test public void Colon__bgn() {fxt.Clear().Test__split(":a b" , "a", "b");}
@Test public void Semic__end() {fxt.Clear().Test__split("a; b" , "a", "b");}
@Test public void Semic__mid() {fxt.Clear().Test__split("a;b" , "a;b");}
@Test public void Semic__bgn() {fxt.Clear().Test__split(";a b" , "a", "b");}
@Test public void Bang__end() {fxt.Clear().Test__split("a! b" , "a", "b");}
@Test public void Bang__mid() {fxt.Clear().Test__split("a!b" , "a!b");}
@Test public void Bang__bgn() {fxt.Clear().Test__split("!a b" , "a", "b");}
@Test public void Question__end() {fxt.Clear().Test__split("a? b" , "a", "b");}
@Test public void Question__mid() {fxt.Clear().Test__split("a?b" , "a?b");}
@Test public void Question__bgn() {fxt.Clear().Test__split("?a b" , "a", "b");}
@Test public void Question__sentence() {fxt.Clear().Test__split("a?" , "a");}
@Test public void Multiple__1() {fxt.Clear().Test__split("a?!" , "a");}
@Test public void Multiple__2() {fxt.Clear().Test__split("a!?" , "a");}
@Test public void Dot__word() {fxt.Clear().Test__split("a.org" , "a.org");} // EX: "en.wikipedia.org"; "Earth.png"; "IEEE_802.15"
@Test public void Dot__abrv() {fxt.Clear().Test__split("a vs. b" , "a", "vs.", "vs", "b");} // EX: "vs.", "no.", "dr.", "st.", "inc."
@Test public void Dot__initials() {fxt.Clear().Test__split("a. b. cde" , "a.", "a", "b.", "b", "cde");} // EX: "H. G. Wells"
@Test public void Dot__acronym() {fxt.Clear().Test__split("abc D.E.F. ghi" , "abc", "d.e.f.", "def", "ghi");} // EX: "History of U.S.A. Science", "G.I. Bill", "Washington, D.C."; "Barcelona F.C."; "The Office (U.S.)"; "Agents of S.H.I.E.L.D."; "Gunfight at the O.K. Corral"; "H.M.S. Pinafore"; "R.E.M. discography"
@Test public void Dot__bgn() {fxt.Clear().Test__split("a .bcd e" , "a", ".bcd", "bcd", "e");} // EX: "Colt .45", "List of organizations with .int domain names"
@Test public void Dot__bgn__end() {fxt.Clear().Test__split("a .b. c" , "a", ".b.", "c");}
@Test public void Dot__ellipsis_like() {fxt.Clear().Test__split("a . . . b" , "a", "b");} // EX: "Did you know . . ."
@Test public void Ellipsis__len_3() {fxt.Clear().Test__split("a... bc d" , "a", "...", "bc", "d");} // EX: "Nights into Dreams..."
@Test public void Ellipsis__len_3__bgn() {fxt.Clear().Test__split("a ...b" , "a", "...", "b"); ;} // NOTE: make sure "dot_bgn" code doesn't break this
@Test public void Ellipsis__len_2() {fxt.Clear().Test__split("a.. b" , "a", "..", "b");} // EX: "3.. 6.. 9 Seconds of Light"
@Test public void Ellipsis__bgn() {fxt.Clear().Test__split("...a" , "...", "a");}
@Test public void Ellipsis__end() {fxt.Clear().Test__split("a..." , "a", "...");}
@Test public void Ellipsis__no_ws() {fxt.Clear().Test__split("a...b" , "a", "...", "b");}
@Test public void Ellipsis__term() {fxt.Clear().Test__split("a...?!" , "a", "...");} // EX: "Wetten, dass..?"
@Test public void Apos__merge__end__eos() {fxt.Clear().Test__split("ab's" , "ab's", "abs");} // EX: "A Midsummer Night's Dream"; "Director's cut"
@Test public void Apos__merge__end__word() {fxt.Clear().Test__split("ab's c" , "ab's", "abs", "c");} // EX: "Director's cut"; "Cap'n Crunch";
@Test public void Apos__merge__bgn() {fxt.Clear().Test__split("a o'bc" , "a", "o'bc", "obc");} // EX: "Twelve O'Clock High"; "Shaqille O'Neal"; "Banca d'Italia"
@Test public void Apos__merge__mid() {fxt.Clear().Test__split("i'm" , "i'm", "im");}
@Test public void Apos__bgn__long() {fxt.Clear().Test__split("a 'tis b" , "a", "'tis", "tis", "b");} // EX: "My Country, 'Tis of Thee"; "Omaha hold 'em"; "Slash'EM"; "Expo '92"
@Test public void Apos__end__eos() {fxt.Clear().Test__split("a'" , "a");}
@Test public void Apos__end__short() {fxt.Clear().Test__split("a' b" , "a", "b");} // EX: "Will-o'-the-wisp"; "Portuguese man o' war";
@Test public void Apos__end__long() {fxt.Clear().Test__split("ab' c" , "ab", "c");} // EX: "Dunkin' Donuts"; "'Allo 'Allo!"; "Catherine de' Medici"
@Test public void Apos__both__n() {fxt.Clear().Test__split("a 'n' b" , "a", "'n'", "n", "b");} // EX: "Rock 'n' Roll"; "Town 'n' Country, Florida"; "Hill 'n Dale, Florida"; "Chip 'n Dale Rescue Rangers"
@Test public void Apos__multiple() {fxt.Clear().Test__split("ab''cd" , "ab''cd");}
@Test public void Apos__lone() {fxt.Clear().Test__split("' a" , "'", "a");} // EX: "' (disambiguation)"
@Test public void Dash__one() {fxt.Clear().Test__split("a-b" , "a", "b", "a-b");} // EX: "The Amazing Spider-Man"; "On-super percentage"; "Basic Role-Playing"; "Context-sensitive"; "Cross-country skiing"; "Double-barreled shotgun"; "Dot-com bubble"; "Many-worlds interpretation"; "Faster-than-light"; "Gram-positive bacteria"; "Half-life", "Jean-Paul Sartre"; "Austria-Hungary"
@Test public void Dash__many() {fxt.Clear().Test__split("a-b-c" , "a", "b", "c", "a-b-c");}
@Test public void Dash__ws() {fxt.Clear().Test__split("a - b" , "a", "-", "b");}
@Test public void Dash__eos() {fxt.Clear().Test__split("a-" , "a", "a-");}
@Test public void Dash__bos() {fxt.Clear().Test__split("-a" , "a", "-a");}
@Test public void Dash__mult__2() {fxt.Clear().Test__split("--" , "--");}
@Test public void Dash__mult__3() {fxt.Clear().Test__split("---" , "---");}
@Test public void Dash__mult__2__words() {fxt.Clear().Test__split("a--b" , "a", "b", "a--b");}
@Test public void Dash__w_comma() {fxt.Clear().Test__split("a-, b" , "a", "a-", "b");}
@Test public void Slash__one() {fxt.Clear().Test__split("a/b" , "a", "b");} // EX: "Good cop/bad cop"; "Snooker world rankings 2004/2005"; "Debian GNU/Hurd"; "HIV/AIDS in the United States"; "List of minor planets/1<>100"
@Test public void Slash__many() {fxt.Clear().Test__split("a/b/c" , "a", "b", "c");} // EX: "Age/sex/location";
@Test public void Slash__ws() {fxt.Clear().Test__split("a / b" , "a", "b");}
@Test public void Dash__slash() {fxt.Clear().Test__split("a-b/c-d-e/f-g" , "a", "b", "a-b", "c", "d", "e", "c-d-e", "f", "g", "f-g");}
@Test public void Paren__both__one() {fxt.Clear().Test__split("a (b) c" , "a", "b", "c");} // EX: "A (letter)"
@Test public void Paren__both__many() {fxt.Clear().Test__split("a (b c) d" , "a", "b", "c", "d");} // EX: "A (2016 film)"
@Test public void Paren__bgn__multiple() {fxt.Clear().Test__split("a (((b)))" , "a", "b");}
@Test public void Paren__unmatched() {fxt.Clear().Test__split("a(b" , "a(b");}
@Test public void Paren__unmatched__bgn() {fxt.Clear().Test__split("a (b" , "a", "b");}
@Test public void Paren__mid() {fxt.Clear().Test__split("a(b)c" , "a(b)c");} // EX: "Chloro(pyridine)cobaloxime"; "Exi(s)t"
@Test public void Paren__end() {fxt.Clear().Test__split("a(b)" , "a(b)", "a");} // EX: "Come What(ever) May"; "501(c) organization"; "Reindeer(s) Are Better Than People"; "(Miss)understood"; "Chromium(III) picolinate"
@Test public void Paren__bgn() {fxt.Clear().Test__split("(a)b" , "(a)b", "b");} // EX: "International Student Congress of (bio)Medical Sciences"
@Test public void Paren__end__dash() {fxt.Clear().Test__split("a(b-c) d" , "a(b-c)", "a", "d");} // EX: "Bis(2-ethylhexyl) phthalate"
@Test public void Paren__end__comma() {fxt.Clear().Test__split("a(b,c) d" , "a(b,c)", "a", "d");} // EX: "Iron(II,III) oxide"
@Test public void Paren__comma() {fxt.Clear().Test__split("a (b), c" , "a", "b", "c");} // EX: "Corning (city), New York"
@Test public void Paren__multiple() {fxt.Clear().Test__split("(a) (b)" , "a", "b");}
@Test public void Quote__both() {fxt.Clear().Test__split("a \"b\" c" , "a", "b", "c");}
@Test public void Word_bgn__at() {fxt.Clear().Test__split("@a" , "@a", "a");}
@Test public void Word_bgn__tilde() {fxt.Clear().Test__split("~a~" , "a");} // EX: "Phantom ~Requiem for the Phantom~"
}
class Srch_text_parser_fxt {
private final Srch_text_parser word_parser = new Srch_text_parser();
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
private Xol_case_mgr case_mgr;
public void Init() {
case_mgr = Xol_case_mgr_.A7();
word_parser.Init_for_ttl(case_mgr);
}
public Srch_text_parser_fxt Clear() {
word_parser.word_hash.Clear();
return this;
}
public Srch_word_itm Make_word(String raw, int count) {return new Srch_word_itm(Bry_.new_u8(raw)).Count_(count);}
public void Test__split(String src, String... expd_words) {
int len = expd_words.length;
Srch_word_itm[] ary = new Srch_word_itm[len];
for (int i = 0; i < len; ++i) {
ary[i] = Make_word(expd_words[i], 1);
}
Test__split(src, ary);
}
public void Test__split(String src, Srch_word_itm... expd_words) {
byte[] src_bry = Bry_.new_u8(src);
word_parser.Parse(Bool_.Y, src_bry, 0, src_bry.length);
Tfds.Eq_str_lines(To_str(expd_words), To_str(word_parser.word_hash));
}
private String To_str(Srch_word_itm[] word_ary) {
int len = word_ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) tmp_bfr.Add_byte_nl();
Srch_word_itm word = word_ary[i];
tmp_bfr.Add(word.Word).Add_byte_pipe();
tmp_bfr.Add_int_variable(word.Count());
}
return tmp_bfr.To_str_and_clear();
}
private String To_str(Srch_word_hash word_mgr) {
int len = word_mgr.Len();
Srch_word_itm[] ary = new Srch_word_itm[len];
for (int i = 0; i < len; ++i)
ary[i] = word_mgr.Get_at(i);
return To_str(ary);
}
}

View File

@@ -1,46 +0,0 @@
/*
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.addons.wikis.searchs.searchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*;
import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*;
public class Srch_search_phrase_tst {
private final Srch_search_phrase_fxt fxt = new Srch_search_phrase_fxt();
@Test public void Word() {fxt.Test__auto_wildcard("a" , "a*");}
@Test public void Paren_end() {fxt.Test__auto_wildcard("(a)" , "(a*)");}
@Test public void Quoted() {fxt.Test__auto_wildcard("\"a\"" , "\"a\"");}
@Test public void Space() {fxt.Test__auto_wildcard(" " , " ");}
@Test public void Not() {fxt.Test__auto_wildcard("-" , "-");}
@Test public void And() {fxt.Test__auto_wildcard("+" , "+");}
@Test public void Or() {fxt.Test__auto_wildcard("," , ",");}
@Test public void Paren_bgn() {fxt.Test__auto_wildcard("(" , "(");}
@Test public void Star() {fxt.Test__auto_wildcard("*" , "*");}
@Test public void Wildcard__exists__y() {fxt.Test__auto_wildcard("a*b" , "a*b");}
@Test public void Wildcard__exists__escaped() {fxt.Test__auto_wildcard("a\\*b" , "a\\*b*");}
@Test public void Wildcard__exists__n() {fxt.Test__auto_wildcard("a* bc" , "a* bc*");}
@Test public void Escape() {fxt.Test__auto_wildcard("\\*" , "\\**");}
@Test public void Escape__incomplete() {fxt.Test__auto_wildcard("a\\" , "a\\");}
@Test public void Escape__escaped() {fxt.Test__auto_wildcard("a\\\\" , "a\\\\*");}
@Test public void Auto_wildcard_n() {fxt.Init__auto_wildcard_n_().Test__auto_wildcard("a", "a");}
}
class Srch_search_phrase_fxt {
private final Srch_crt_scanner_syms syms = Srch_crt_scanner_syms.Dflt;
private boolean auto_wildcard = true;
public Srch_search_phrase_fxt Init__auto_wildcard_n_() {this.auto_wildcard = false; return this;}
public void Test__auto_wildcard(String src_str, String expd) {
byte[] src_raw = Bry_.new_u8(src_str);
byte[] actl = Srch_search_phrase.Auto_wildcard(src_raw, auto_wildcard, syms);
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View File

@@ -1,66 +0,0 @@
/*
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.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*;
public class Srch_crt_parser_tst {
private final Srch_crt_parser_fxt fxt = new Srch_crt_parser_fxt();
@Test public void Word__one() {fxt.Test__parse("a" , "a");}
@Test public void And__one() {fxt.Test__parse("a + b" , "(a AND b)");}
@Test public void And__many() {fxt.Test__parse("a + b + c" , "(a AND b AND c)");}
@Test public void And__dangling() {fxt.Test__parse("a +" , "a");}
@Test public void And__dupe() {fxt.Test__parse("a + + b" , "(a AND b)");}
@Test public void Quote() {fxt.Test__parse("\"a b\"" , "\"a b\"");}
@Test public void Auto__word() {fxt.Test__parse("a b" , "(a AND b)");}
@Test public void Auto__quote() {fxt.Test__parse("a \"b\"" , "(a AND \"b\")");}
@Test public void Auto__parens() {fxt.Test__parse("a (b , c)" , "(a AND (b OR c))");}
@Test public void Or__one() {fxt.Test__parse("a , b" , "(a OR b)");}
@Test public void Or__many() {fxt.Test__parse("a , b , c" , "(a OR b OR c)");}
@Test public void Mixed__3() {fxt.Test__parse("a + b , c" , "((a AND b) OR c)");}
@Test public void Mixed__5() {fxt.Test__parse("a + b , c + d , e" , "((((a AND b) OR c) AND d) OR e)");}
@Test public void Parens__basic() {fxt.Test__parse("a + (b , c)" , "(a AND (b OR c))");}
@Test public void Parens__nest() {fxt.Test__parse("a + (b , (c + d))" , "(a AND (b OR (c AND d)))");}
@Test public void Parens__mid() {fxt.Test__parse("a + (b , c) + d)" , "(a AND (b OR c) AND d)");}
@Test public void Parens__mixed() {fxt.Test__parse("a + (b , c) , d)" , "((a AND (b OR c)) OR d)");}
@Test public void Parens__dupe() {fxt.Test__parse("((a))" , "a");}
@Test public void Parens__dangling__lhs() {fxt.Test__parse("(a" , "a");}
@Test public void Parens__dangling__rhs() {fxt.Test__parse("a)" , "a");}
@Test public void Parens__empty__bos() {fxt.Test__parse("()" , "");}
@Test public void Parens__empty__mid() {fxt.Test__parse("a () b" , "(a AND b)");}
@Test public void Not__bos() {fxt.Test__parse("-abc" , "NOT abc");}
@Test public void Not__mid() {fxt.Test__parse("a -b" , "(a AND NOT b)");}
@Test public void Not__2() {fxt.Test__parse("a -b -c" , "(a AND NOT b AND NOT c)");}
@Test public void Not__dangling__eos() {fxt.Test__parse("a -" , "a");}
@Test public void Not__dangling__mid() {fxt.Test__parse("a -- b" , "(a AND b)");} // NOTE: scanner will remove spaces and convert to "a", "--", "b"
@Test public void Not__dupe__2() {fxt.Test__parse("a --b" , "(a AND b)");}
@Test public void Not__dupe__3() {fxt.Test__parse("a ---b" , "(a AND NOT b)");}
@Test public void Not__parens() {fxt.Test__parse("a -(b + c)" , "(a AND NOT (b AND c))");}
@Test public void Escape__eos() {fxt.Test__parse("\\" , "");}
@Test public void Escape__escaped() {fxt.Test__parse("\\\\*" , "\\*");} // '\\' -> '\*'
}
class Srch_crt_parser_fxt {
private final Srch_crt_parser crt_parser;
private final Srch_crt_visitor__print visitor__to_str = new Srch_crt_visitor__print();
public Srch_crt_parser_fxt() {
crt_parser = new Srch_crt_parser(Srch_crt_scanner_syms.Dflt);
Srch_text_parser text_parser = new Srch_text_parser();
text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
}
public void Test__parse(String src_str, String expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Srch_crt_mgr crt_mgr = crt_parser.Parse_or_invalid(src_bry, Bool_.N);
Tfds.Eq(expd, String_.new_u8(visitor__to_str.Print(crt_mgr.Root)));
}
}

View File

@@ -1,83 +0,0 @@
/*
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.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*;
public class Srch_crt_scanner_tst {
private final Srch_crt_scanner_fxt fxt = new Srch_crt_scanner_fxt();
@Test public void Word() {fxt.Test__scan("abc" , "abc");}
@Test public void Word__many() {fxt.Test__scan("abc d ef" , "abc", "d", "ef");}
@Test public void Word__symbol() {fxt.Test__scan("a; b" , "a;", "b");}
@Test public void And() {fxt.Test__scan("a + b" , "a", "+", "b");}
@Test public void And__parens() {fxt.Test__scan("a +(b)" , "a", "+", "(", "b", ")");} // check that ( causes and to be treated as separate word
@Test public void Or() {fxt.Test__scan("a , b" , "a", ",", "b");}
@Test public void Or__no_space() {fxt.Test__scan("a, b" , "a", ",", "b");}
@Test public void Not() {fxt.Test__scan("-abc" , "-", "abc");}
@Test public void Not__mid__1() {fxt.Test__scan("a-b" , "a-b");} // fails if "a", "-", "b"
@Test public void Not__mid__2() {fxt.Test__scan("a b-c" , "a", "b-c");} // ignore - if in middle of word
@Test public void Not__and() {fxt.Test__scan("a -bc" , "a", "-", "bc");} // auto-add AND for -
@Test public void Not__dangling() {fxt.Test__scan("a -" , "a", "-");}
@Test public void Space() {fxt.Test__scan(" a b " , "a", "b");} // spaces should not generate tkns
@Test public void Quote() {fxt.Test__scan("\"a b\"" , "a b");}
@Test public void Quote__mid() {fxt.Test__scan("a\"b" , "a", "b");}
@Test public void Quote__double() {fxt.Test__scan("\"a\"\"b\"" , "a\"b");}
@Test public void Quote__missing__one() {fxt.Test__scan("\"abc" , "abc");}
@Test public void Quote__missing__many() {fxt.Test__scan("\"abc a" , "abc", "a");}
@Test public void Escape__bgn() {fxt.Test__scan("\\-a" , "-a");} // fails if "-", "a"
@Test public void Escape__and__bgn() {fxt.Test__scan("\\+" , "+");} // fails if "a", "&", "b"
@Test public void Escape__and__mid() {fxt.Test__scan("a\\+b" , "a+b");} // fails if "a", "&", "b"
@Test public void Escape__eos__1() {fxt.Test__scan("\\" , String_.Ary_empty);}
@Test public void Escape__eos__2() {fxt.Test__scan("a \\" , "a");}
@Test public void Escape__eos__3() {fxt.Test__scan("a\\" , "a");}
@Test public void Escape__many() {fxt.Test__scan("c\\+\\+" , "c++");}
@Test public void Escape__end() {fxt.Test__scan("a\\\\" , "a\\");}
@Test public void Complicated() {fxt.Test__scan("(a + \"b\") , -c", "(", "a", "+", "b", ")", ",", "-", "c");}
}
class Srch_crt_scanner_fxt {
private final Srch_crt_scanner scanner;
public Srch_crt_scanner_fxt() {
this.scanner = new Srch_crt_scanner(Srch_crt_scanner_syms.Dflt);
Srch_text_parser text_parser = new Srch_text_parser();
text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
}
public void Test__scan(String src_str, String... expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Srch_crt_tkn[] actl_itms = scanner.Scan(src_bry);
Tfds.Eq_ary(expd, To_vals(src_bry, actl_itms));
}
public void Test__scan_tids(String src_str, byte... expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Srch_crt_tkn[] actl_itms = scanner.Scan(src_bry);
Tfds.Eq_ary(expd, To_tids(actl_itms));
}
private String[] To_vals(byte[] src, Srch_crt_tkn[] ary) {
int len = ary.length;
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
Srch_crt_tkn tkn = ary[i];
rv[i] = String_.new_a7(tkn.Val);
}
return rv;
}
private byte[] To_tids(Srch_crt_tkn[] ary) {
int len = ary.length;
byte[] rv = new byte[len];
for (int i = 0; i < len; i++) {
Srch_crt_tkn tkn = ary[i];
rv[i] = tkn.Tid;
}
return rv;
}
}

View File

@@ -1,38 +0,0 @@
/*
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.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
import org.junit.*;
public class Srch_crt_sql_tst {
private final Srch_crt_sql_fxt fxt = new Srch_crt_sql_fxt();
@Test public void Eq() {fxt.Exec__new_or_null("a").Test__tid(Srch_crt_sql.Tid__eq).Test__eq("a");}
@Test public void Rng() {fxt.Exec__new_or_null("a*").Test__tid(Srch_crt_sql.Tid__rng).Test__rng_bgn("a").Test__rng_end("b").Test__pattern("a*");}
@Test public void Like() {fxt.Exec__new_or_null("a*b").Test__tid(Srch_crt_sql.Tid__like).Test__like("a%b").Test__pattern("a*b");}
@Test public void Like__escape() {fxt.Exec__new_or_null("a|\\*b").Test__tid(Srch_crt_sql.Tid__like).Test__like("a|\\%b").Test__pattern("a\\*b");} // "a\*b"
@Test public void Quote() {fxt.Exec__new_or_null("\"a b\"").Test__tid(Srch_crt_sql.Tid__eq).Test__eq("\"a b\"");}
}
class Srch_crt_sql_fxt {
private Srch_crt_sql actl;
public Srch_crt_sql_fxt Exec__new_or_null(String src_str) {
this.actl = Srch_crt_sql.New_or_null(Bry_.new_u8(src_str), Srch_search_addon.Wildcard__star);
return this;
}
public Srch_crt_sql_fxt Test__tid(int expd) {Tfds.Eq(expd, actl.Tid); return this;}
public Srch_crt_sql_fxt Test__eq(String expd) {Tfds.Eq(expd, actl.Eq); return this;}
public Srch_crt_sql_fxt Test__rng_bgn(String expd) {Tfds.Eq(expd, actl.Rng_bgn); return this;}
public Srch_crt_sql_fxt Test__rng_end(String expd) {Tfds.Eq(expd, actl.Rng_end); return this;}
public Srch_crt_sql_fxt Test__like(String expd) {Tfds.Eq(expd, actl.Like); return this;}
public Srch_crt_sql_fxt Test__pattern(String expd) {Tfds.Eq(expd, String_.new_u8(actl.Pattern.Raw()), "pattern"); return this;}
}

View File

@@ -1,37 +0,0 @@
/*
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.addons.wikis.searchs.searchers.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*;
public class Srch_link_wkr_sql_tst {
private final Srch_link_wkr_sql_fxt fxt = new Srch_link_wkr_sql_fxt();
@Test public void Rng() {
fxt.Run__search("a").Test__eq
( "select"
);
}
}
class Srch_link_wkr_sql_fxt {
private final Srch_link_wkr_sql link_wkr = new Srch_link_wkr_sql();
public Srch_link_wkr_sql_fxt Run__search(String search) {
// attach_mgr.Init(cur_link_tbl.conn, new Db_attach_itm("page_db", ctx.Db__core.Conn()), new Db_attach_itm("word_db", ctx.Tbl__word.conn));
// link_wkr.Init(ctx, attach_mgr);
// this.actl_sql = link_wkr.Write(ctx, attach_mgr);
link_wkr.Clear();
return this;
}
public void Test__eq(String... v) {
}
}

View File

@@ -1,45 +0,0 @@
/*
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.addons.wikis.searchs.searchers.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;
import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*;
public class Srch_page_tbl_wkr_tst {
private final Srch_page_tbl_wkr_fxt fxt = new Srch_page_tbl_wkr_fxt();
@Test public void Word__one() {fxt.Test__to_bry_or_null("a" , "a");}
@Test public void Word__many() {fxt.Test__to_bry_or_null("a b c" , "a b c");}
@Test public void Wild__end() {fxt.Test__to_bry_or_null("a*" , "a");}
@Test public void Wild__both() {fxt.Test__to_bry_or_null("a*b*" , null);}
@Test public void Quote() {fxt.Test__to_bry_or_null("\"a b\"" , "a b");}
@Test public void Quote__mixed() {fxt.Test__to_bry_or_null("a \"b \"\" c\" d" , "a b \" c d");}
@Test public void Escape() {fxt.Test__to_bry_or_null("a\\+" , "a+");}
@Test public void Not() {fxt.Test__to_bry_or_null("a -b" , null);}
@Test public void And() {fxt.Test__to_bry_or_null("a + b" , null);}
@Test public void Or() {fxt.Test__to_bry_or_null("a , b" , null);}
@Test public void Parens() {fxt.Test__to_bry_or_null("(a)" , null);}
}
class Srch_page_tbl_wkr_fxt {
private final Srch_crt_parser crt_parser;
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public Srch_page_tbl_wkr_fxt() {
crt_parser = new Srch_crt_parser(Srch_crt_scanner_syms.Dflt);
Srch_text_parser text_parser = new Srch_text_parser();
text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
}
public void Test__to_bry_or_null(String src_str, String expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Srch_crt_mgr crt_mgr = crt_parser.Parse_or_invalid(src_bry, Bool_.N);
Tfds.Eq(expd, String_.new_u8(Srch_page_tbl_wkr.To_bry_or_null(tmp_bfr, Srch_search_addon.Wildcard__star, crt_mgr)));
}
}

View File

@@ -1,221 +0,0 @@
/*
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
*/
//namespace gplx.xowa.addons.wikis.searchs.v1s {
// import org.junit.*; using gplx.xowa.wikis.tdbs; using gplx.xowa.wikis.data.tbls;
// public class Xosrh_core_tst {
// @Before public void Init() {fxt.Clear();} private Xos_search_mgr_fxt fxt = new Xos_search_mgr_fxt();
// @Test public void Basic() {
// fxt.Init_basic();
// fxt.Test_search_exact("b2", "B2_22", "B2_12", "B2__2");
// fxt.Test_search_exact("a" , "A___0");
// fxt.Test_search_exact("b1a"); // missing: mid
// fxt.Test_search_exact("d"); // missing: end
// fxt.Test_search_exact("$"); // missing: bgn
// fxt.Test_search_match_bgn("b*", "B3_23", "B2_22", "B1_21", "B3_13", "B2_12", "B1_11", "B3__3", "B2__2", "B1__1");
// }
// @Test public void Page_size() {
// fxt.Init_basic();
// fxt.Search_mgr().Page_mgr().Itms_per_page_(1);
// fxt.Test_search("b*", 0, "B3_23");
// fxt.Test_search("b*", 1, "B2_22");
// fxt.Test_search("b*", 2, "B1_21");
// fxt.Test_search("b*", 3, "B3_13");
// }
// @Test public void Url() {
// Xoa_url url = Xow_url_parser_old.Parse_url(fxt.App(), fxt.Wiki(), "Special:Search/Abc?fulltext=y&xowa_sort=len_desc");
// fxt.Search_mgr().Args_mgr().Clear().Parse(url.Args());
// Tfds.Eq(Srch_rslt_row_sorter.Tid_len_dsc, fxt.Search_mgr().Args_mgr().Sort_tid());
// }
// @Test public void Url_arg_title() {// http://en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes&title=Mars
// fxt.Test_url_search_bry("Special:Search?fulltext=y&search=Abc" , "Abc"); // query arg
//// fxt.Test_url_search_bry("Special:Search/Abc?fulltext=y" , "Abc"); // leaf
// fxt.Test_url_search_bry("Special:Search/Abc?fulltext=y&search=Def" , "Def"); // leaf overrides query arg
// }
// @Test public void Url_ns() {
// fxt.Test_url__ns("Special:Search?search=Abc&ns0=1&ns1=1", "0|1");
// fxt.Test_url__ns("Special:Search?search=Abc&ns*=1", "*");
// fxt.Test_url__ns("Special:Search?search=Abc", "0");
// }
// @Test public void Html() {
// fxt.Init_basic();
// fxt.Test_html_by_url("B1", "", String_.Concat_lines_nl
// ( "Result '''1''' of '''3''' for '''B1'''<br/>"
// , "{|"
// , "|-"
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=0|&lt;]]"
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|&gt;]]"
// , "|-"
// , "| [[Special:Search/B1?fulltext=y&xowa_sort=len_desc|length]]"
// , "| [[Special:Search/B1?fulltext=y&xowa_sort=title_asc|title]]"
// , "|-"
// , "| 42 || [[B1 21]]"
// , "|-"
// , "| 22 || [[B1 11]]"
// , "|-"
// , "| 2 || [[B1 1]]"
// , "|-"
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=0|&lt;]]"
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|&gt;]]"
// , "|}"
// ));
// }
//// @Test public void Page_next() {
//// fxt.Init_basic();
//// fxt.Search_mgr().Page_size_(1);
//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 0, "B1 1");
//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 1, "B1 11");
//// }
//// @Test public void Misc_url() {
//// fxt.Init_basic();
//// fxt.Search_mgr().Page_size_(1);
//// fxt.Expd_address_page_("Special:Search/B1");
//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 0, "B1 1");
//// }
// @Test public void Sort_defaults_to_len_desc() {
// fxt.Init_basic();
// fxt.Search_mgr().Page_mgr().Itms_per_page_(3);
// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b" , 0, Srch_rslt_row_sorter.Tid_ttl_asc , "B1_11", "B1_21", "B1__1"); // sort by name; note that _ sorts after alphabet
// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b" , 1, Srch_rslt_row_sorter.Tid_none , "B2_12", "B2_22", "B2__2"); // sort by name still; next page should not reset
// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b2" , 0, Srch_rslt_row_sorter.Tid_none , "B2_22", "B2_12", "B2__2"); // sort by len desc; new search should reset
// }
// }
// class Xos_search_mgr_fxt {
// Xoae_app app; Xowe_wiki wiki; Bry_bfr bfr = Bry_bfr_.Reset(500); Srch_special_page search_mgr;
// public Xoae_app App() {return app;}
// public Xowe_wiki Wiki() {return wiki;}
// public Xobl_regy_itm regy_itm_(int id, String bgn, String end, int count) {return new Xobl_regy_itm(id, Bry_.new_u8(bgn), Bry_.new_u8(end), count);}
// public Xowd_page_itm data_ttl_(int id, String ttl) {return data_ttl_(id, 0, 0, false, 0, ttl);}
// public Xowd_page_itm data_ttl_(int id, int fil, int row, boolean redirect, int len, String ttl) {return new Xowd_page_itm().Init(id, Bry_.new_u8(ttl), redirect, len, fil, row);}
// public Xowd_page_itm data_id_(int id, String ttl) {return data_id_(id, Xow_ns_.Tid__main, ttl);}
// public Xowd_page_itm data_id_(int id, int ns, String ttl) {return new Xowd_page_itm().Id_(id).Ns_id_(ns).Ttl_page_db_(Bry_.new_u8(ttl)).Text_db_id_(0).Text_len_(0);}
// public Xobl_search_ttl data_sttl_(String word, params int[] ids) {return new Xobl_search_ttl(Bry_.new_u8(word), data_ttl_word_page_ary_(ids));}
// public Xobl_search_ttl_page[] data_ttl_word_page_ary_(params int[] ids) {
// int ids_len = ids.length;
// Xobl_search_ttl_page[] rv = new Xobl_search_ttl_page[ids_len];
// for (int i = 0; i < ids_len; i++) {
// int id = ids[i];
// rv[i] = new Xobl_search_ttl_page(id, id * 2);
// }
// return rv;
// }
// public void Init_regy_site(byte dir_info, params Xobl_regy_itm[] ary) {Init_regy(wiki.Tdb_fsys_mgr().Url_site_reg(dir_info), ary);}
// public void Init_regy_ns (String ns_num, byte tid, params Xobl_regy_itm[] ary) {Init_regy(wiki.Tdb_fsys_mgr().Url_ns_reg(ns_num, tid), ary);}
// public void Init_regy(Io_url url, Xobl_regy_itm[] ary) {
// int ary_len = ary.length;
// for (int i = 0; i < ary_len; i++) {
// Xobl_regy_itm itm = ary[i];
// itm.Srl_save(tmp_bfr);
// }
// Io_mgr.Instance.SaveFilBfr(url, tmp_bfr);
// } private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
// public void Init_data(Io_url fil, params Xobl_data_itm[] ary) {
// Xob_xdat_file xdat_file = new Xob_xdat_file();
// int ary_len = ary.length;
// for (int i = 0; i < ary_len; i++) {
// Xobl_data_itm itm = ary[i];
// itm.Srl_save(tmp_bfr);
// xdat_file.Insert(bfr, tmp_bfr.To_bry_and_clear());
// }
// xdat_file.Save(fil);
// }
// public void Init_basic() {
// this.Init_regy_ns(wiki.Ns_mgr().Ns_main().Num_str(), Xotdb_dir_info_.Tid_search_ttl, this.regy_itm_(0, "A", "C", 5));
// this.Init_data(wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, Xow_ns_.Tid__main, 0)
// , this.data_sttl_("a" , 0)
// , this.data_sttl_("b1" , 1, 11, 21)
// , this.data_sttl_("b2" , 2, 12, 22)
// , this.data_sttl_("b3" , 3, 13, 23)
// , this.data_sttl_("c" , 4)
// );
// this.Init_regy_site(Xotdb_dir_info_.Tid_id, this.regy_itm_(0, "A", "C", 11));
// this.Init_data(wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_id, 0)
// , this.data_id_( 0, "A___0")
// , this.data_id_( 1, "B1__1")
// , this.data_id_( 2, "B2__2")
// , this.data_id_( 3, "B3__3")
// , this.data_id_( 4, "C___4")
// , this.data_id_(11, "B1_11")
// , this.data_id_(12, "B2_12")
// , this.data_id_(13, "B3_13")
// , this.data_id_(21, "B1_21")
// , this.data_id_(22, "B2_22")
// , this.data_id_(23, "B3_23")
// );
// search_mgr.Page_mgr().Ns_mgr().Add_all(); // WORKAROUND: xdat fmt does not store ns with search data; pages will be retrieved with ns_id = null; force ns_all (instead of allowing ns_main default);
// }
// public void Clear() {
// Io_mgr.Instance.InitEngine_mem();
// app = Xoa_app_fxt.Make__app__edit();
// wiki = Xoa_app_fxt.Make__wiki__edit(app);
// search_mgr = wiki.Special_mgr().Page_search();
// wiki.Appe().Gui_mgr().Search_suggest_mgr().Args_default_str_("ns*=1"); // WORKAROUND: xdat fmt does not store ns with search data; pages will be retrieved with ns_id = null; force ns_all (instead of allowing ns_main default);
// }
// public Srch_special_page Search_mgr() {return search_mgr;}
// public void Test_url_search_bry(String url_str, String expd) {
// Xoa_url url = Xow_url_parser_old.Parse_url(app, wiki, url_str);
// search_mgr.Args_mgr().Clear().Parse(url.Args());
// Tfds.Eq(expd, String_.new_u8(search_mgr.Args_mgr().Search_bry()));
// }
// public void Test_url__ns(String url_str, String expd) {
// Xoa_url url = Xow_url_parser_old.Parse_url(app, wiki, url_str);
// search_mgr.Args_mgr().Clear().Parse(url.Args());
// Tfds.Eq(expd, String_.new_a7(search_mgr.Args_mgr().Ns_mgr().Xto_hash_key()));
// }
// public void Test_search_exact(String ttl_str, params String[] expd_ary) {Test_search(ttl_str, 0, expd_ary);}
// public void Test_search_match_bgn(String ttl_str, params String[] expd_ary) {Test_search(ttl_str, 0, expd_ary);}
// public void Test_search(String ttl_str, int page_idx, params String[] expd_ary) {
// byte[] ttl_bry = Bry_.new_a7(ttl_str);
// Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
// Xosrh_rslt_grp page = search_mgr.Page_mgr().Search(bfr, wiki, ttl_bry, page_idx, search_mgr.Page_mgr());
// bfr.Mkr_rls();
// Tfds.Eq_ary(expd_ary, Search_itms_to_int_ary(page));
// }
// public void Test_html_by_url(String ttl_str, String args_str, String expd_html) {
// wiki.Init_needed_(false);
// byte[] ttl_bry = Bry_.new_a7(ttl_str);
// Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
// Xoae_page page = Xoae_page.New_test(wiki, ttl);
// byte[] url_bry = Bry_.new_a7("http://en.wikipedia.org/wiki/Special:Search/" + ttl_str + args_str);
// Xoa_url url = wiki.Appe().Url_parser().Parse(url_bry);
// search_mgr.Special__gen(url, page, wiki, ttl);
// Tfds.Eq_str_lines(expd_html, String_.new_u8(page.Root().Data_htm()));
// }
// public void Test_search2(byte match_tid, String ttl_str, int page_idx, byte sort_tid, params String[] expd_ary) {
// Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
// Xow_url_parser_old url_parser = new Xow_url_parser_old();
// byte[] url_raw = Bry_.new_a7("Special:Search/" + ttl_str + ((match_tid == Srch_special_page.Match_tid_all) ? "" : "*") + "?fulltext=y" + Srch_rslt_row_sorter.Xto_url_arg(sort_tid) + "&xowa_page_size=1&xowa_page_index=" + page_idx);
// Xoa_url url = url_parser.Parse(url_raw);
// Xoa_ttl ttl = Xoa_ttl.Parse(wiki, url_raw);
// Xoae_page page = wiki.Ctx().Page();
// search_mgr.Special__gen(url, page, wiki, ttl);
// Xosrh_rslt_grp cur_grp = search_mgr.Cur_grp();
// bfr.Mkr_rls();
// Tfds.Eq_ary(expd_ary, Search_itms_to_int_ary(cur_grp));
// }
// String[] Search_itms_to_int_ary(Xosrh_rslt_grp page) {
// int itms_len = page.Itms_len();
// String[] rv = new String[itms_len];
// for (int i = 0; i < itms_len; i++) {
// Xowd_page_itm itm = page.Itms_get_at(i);
// rv[i] = String_.new_u8(itm.Ttl_page_db());
// }
// return rv;
// }
// }
// interface Xobl_data_itm {
// void Srl_save(Bry_bfr bfr);
// }
//}

View File

@@ -1,83 +0,0 @@
/*
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.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.wikis.tdbs.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.wikis.searchs.searchers.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
public class Srch_html_page_bldr_tst {
@Before public void init() {fxt.Clear();} private Srch_html_page_bldr_fxt fxt = new Srch_html_page_bldr_fxt();
@Test public void Paging() {
fxt.Test_paging(Bool_.Y, 1, "<a href='/site/en.wikipedia.org/wiki/Special:Search/A?fulltext=y&xowa_page_index=2' title='Next'>Next<img src='file:///mem/xowa/bin/any/xowa/file/app.general/go_fwd.png' width='16' height='16'/></a>");
fxt.Test_paging(Bool_.N, 1, "<a href='/site/en.wikipedia.org/wiki/Special:Search/A?fulltext=y&xowa_page_index=0' title='Previous'><img src='file:///mem/xowa/bin/any/xowa/file/app.general/go_bwd.png' width='16' height='16'/>Previous</a>");
fxt.Test_paging(Bool_.Y, 2, "<a href='/site/en.wikipedia.org/wiki/Special:Search/A?fulltext=y&xowa_page_index=3' title='Next'>Next<img src='file:///mem/xowa/bin/any/xowa/file/app.general/go_fwd.png' width='16' height='16'/></a>");
fxt.Test_paging(Bool_.N, 0, "&#160;");
}
@Test public void Rows() {
fxt.Test_rows(new Srch_rslt_row[] {fxt.Make_row(10, "A"), fxt.Make_row(20, "B")}, String_.Concat_lines_nl_skip_last
( ""
, " <tr id='w.7C1'>"
, " <td style='padding-right:5px; vertical-align:top; text-align:right;'>10"
, " </td>"
, " <td style='padding-left:5px; vertical-align:top;'><a href='/site/w/wiki/A' title='A'>A</a>"
, " </td>"
, " </tr>"
, " <tr id='w.7C2'>"
, " <td style='padding-right:5px; vertical-align:top; text-align:right;'>20"
, " </td>"
, " <td style='padding-left:5px; vertical-align:top;'><a href='/site/w/wiki/B' title='B'>B</a>"
, " </td>"
, " </tr>"
));
}
}
class Srch_html_page_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Srch_html_page_bldr html_mgr; private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
private int page_id;
public Srch_html_page_bldr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
html_mgr = new Srch_html_page_bldr();
}
page_id = 0;
return this;
}
public void Test_paging(boolean fwd, int slab_idx, String expd) {
byte[] search_orig = Bry_.new_a7("A");
Srch_search_qry qry = Srch_search_qry.New__search_page(Xow_domain_itm_.Ary_empty, wiki, app.Addon_mgr().Itms__search__special().Ns_mgr(), Bool_.N, search_orig, slab_idx, 100);
html_mgr.Init_by_wiki(wiki, wiki.Lang().Num_mgr(), qry);
byte[] paging_link = html_mgr.Bld_paging_link(fwd);
Tfds.Eq(expd, String_.new_a7(paging_link));
}
public void Test_rows(Srch_rslt_row[] rows, String expd) {
Srch_rslt_list rslts = new Srch_rslt_list();
Srch_html_row_bldr row_bldr = new Srch_html_row_bldr(wiki.Html__lnki_bldr());
row_bldr.Init(rslts, 0, rows.length);
for (int i = 0; i < rows.length; ++i)
rslts.Add(rows[i]);
row_bldr.Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
public Srch_rslt_row Make_row(int len, String ttl_str) {
byte[] wiki_bry = Bry_.new_a7("w");
byte[] ttl_bry = Bry_.new_u8(ttl_str);
++page_id;
Srch_rslt_row rv = new Srch_rslt_row(Srch_rslt_row.Bld_key(wiki_bry, page_id), wiki_bry, wiki.Ttl_parse(ttl_bry), gplx.xowa.wikis.nss.Xow_ns_.Tid__main, ttl_bry, page_id, len, len, Srch_rslt_row.Page_redirect_id_null);
rv.Page_ttl_highlight = rv.Page_ttl.Full_txt_w_ttl_case();
return rv;
}
}

View File

@@ -1,64 +0,0 @@
/*
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.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.guis.cbks.js.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
public class Srch_rslt_cbk_tst {
@Before public void init() {fxt.Clear();} private Srch_rslt_cbk_fxt fxt = new Srch_rslt_cbk_fxt();
@Test public void Basic() {
fxt.Test_add(fxt.Make_rslt(50, "L"), fxt.Make_args_append("xowa_insert_w" , "w.7CL")); // insert new
fxt.Test_add(fxt.Make_rslt(30, "N"), fxt.Make_args_append("xowa_insert_w" , "w.7CN")); // insert below last
fxt.Test_add(fxt.Make_rslt(70, "J"), fxt.Make_args_append("w.7CL" , "w.7CJ")); // insert above first
fxt.Test_add(fxt.Make_rslt(60, "K"), fxt.Make_args_append("w.7CL" , "w.7CK")); // insert above mid
fxt.Test_add(fxt.Make_rslt(40, "M"), fxt.Make_args_append("w.7CN" , "w.7CM")); // insert below mid
fxt.Test_add(fxt.Make_rslt(10, "P")); // insert noop
fxt.Test_add(fxt.Make_rslt(80, "I"), fxt.Make_args_append("w.7CJ" , "w.7CI") , fxt.Make_args_replace("w.7CN")); // insert displace all
fxt.Test_add(fxt.Make_rslt(61, "K1"), fxt.Make_args_append("w.7CK" , "w.7CK1"), fxt.Make_args_replace("w.7CM")); // insert displace mid
}
}
class Srch_rslt_cbk_fxt {
private Srch_html_row_bldr html_row; private static final byte[] Bry_enwiki = Bry_.new_a7("w");
private Srch_html_row_wkr async;
private Xog_js_wkr__log js_wkr = new Xog_js_wkr__log();
private Xowe_wiki wiki;
private int page_id;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app, "w");
html_row = new Srch_html_row_bldr(wiki.Html__lnki_bldr());
html_row.Fmtr().Fmt_("~{page_key}");
async = new Srch_html_row_wkr(html_row, js_wkr, 5, Bry_enwiki);
page_id = 0;
}
public Srch_rslt_row Make_rslt(int len, String ttl) {
byte[] ttl_bry = Bry_.new_a7(ttl);
++page_id;
byte[] key = Bry_.Add(Bry_enwiki, Byte_ascii.Pipe_bry, ttl_bry); // NOTE: deliberately changing key to use ttl instead of id to make tests more readable
return new Srch_rslt_row(key, Bry_enwiki, wiki.Ttl_parse(ttl_bry), gplx.xowa.wikis.nss.Xow_ns_.Tid__main, ttl_bry, page_id, len, len, Srch_rslt_row.Page_redirect_id_null);
}
public Object[] Make_args_append(String uid, String html) {return Object_.Ary(Xog_js_wkr__log.Proc_append_above, uid, html);}
public Object[] Make_args_replace(String uid) {return Object_.Ary(Xog_js_wkr__log.Proc_replace_html, uid, "");}
public void Test_add(Srch_rslt_row row, Object[]... expd) {
async.On_rslt_found(row);
int expd_len = expd.length;
Tfds.Eq(expd_len, js_wkr.Log__len());
for (int i = 0; i < expd_len; ++i) {
String expd_str = String_.Concat_with_obj("\n", expd[i]);
String actl_str = String_.Concat_with_obj("\n", js_wkr.Log__get_at(i));
Tfds.Eq_str_lines(expd_str, actl_str);
}
js_wkr.Log__clear();
}
}