mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Wikibase: Fix script error 'libraryUtil.lua:13 bad argument #1 to message.newRawMessage' on sever dozen military pages
This commit is contained in:
105
400_xowa/src/gplx/xowa/Xoa_app_fxt.java
Normal file
105
400_xowa/src/gplx/xowa/Xoa_app_fxt.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.gfui.kits.core.*;
|
||||
import gplx.langs.gfs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.guis.tabs.*;
|
||||
public class Xoa_app_fxt {
|
||||
public static Xoae_app Make__app__edit() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Make__app__edit("linux", Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public static Xoae_app Make__app__edit(String op_sys, Io_url root_dir) {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoae_app app = new Xoae_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_cmd, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), op_sys);
|
||||
GfsCore.Instance.Clear(); // NOTE: must clear
|
||||
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_app); // NOTE: must add app to GfsCore; app.Gfs_mgr() always adds current app to GfsCore; note this causes old test to leave behind GfsCore for new test
|
||||
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_xowa); // add alias for app; DATE:2014-06-09
|
||||
return app;
|
||||
}
|
||||
public static Xoav_app Make__app__view() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Make__app__view("linux", Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public static Xoav_app Make__app__view(String op_sys, Io_url root_dir) {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoav_app rv = new Xoav_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_gui, Xog_tab_mgr_.New_mem(), op_sys, root_dir, root_dir.GenSubDir("file"), root_dir.GenSubDir("css"), root_dir);
|
||||
rv.Init_by_app(user_dir);
|
||||
rv.Wiki_mgr().Add(new Xowv_wiki(rv, Xow_domain_itm_.Bry__home, user_dir));
|
||||
return rv;
|
||||
}
|
||||
public static Xowv_wiki Make__wiki__view(Xoa_app app) {return Make__wiki__view(app, "en.wikipedia.org");}
|
||||
public static Xowv_wiki Make__wiki__view(Xoa_app app, String domain_str) {
|
||||
byte[] domain_bry = Bry_.new_u8(domain_str);
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_str);
|
||||
Xowv_wiki rv = new Xowv_wiki((Xoav_app)app, domain_bry, wiki_dir);
|
||||
((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public static Xowe_wiki Make__wiki__edit__nonwmf(Xoae_app app, String key) {
|
||||
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true);
|
||||
Xol_lang_itm_.Lang_init(lang);
|
||||
return Make__wiki__edit(app, key, lang);
|
||||
}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app) {return Make__wiki__edit(app, "en.wikipedia.org");}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key) {return Make__wiki__edit(app, key, app.Lang_mgr().Lang_en());}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key, Xol_lang_itm lang) {
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key);
|
||||
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir);
|
||||
rv.File_mgr().Dbmeta_mgr().Depth_(2); // TEST: written for 2 depth
|
||||
rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs)
|
||||
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true);
|
||||
app.Wiki_mgr().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public static void repo_(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
app.File_mgr().Repo_mgr().Set("src:c", "mem/wiki/repo/src/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:c", "mem/wiki/repo/trg/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c"));
|
||||
}
|
||||
public static void repo2_(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm"));
|
||||
}
|
||||
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.Gui_mgr().Browser_win().Init_by_kit(Mem_kit.Instance);
|
||||
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(wiki, Xoae_page.Empty);
|
||||
}
|
||||
public static Xob_bldr bldr_(Xoae_app app) {
|
||||
Xob_bldr rv = new Xob_bldr(app);
|
||||
rv.Sort_mem_len_(Io_mgr.Len_kb).Dump_fil_len_(Io_mgr.Len_kb).Make_fil_len_(Io_mgr.Len_kb);
|
||||
return rv;
|
||||
}
|
||||
public static final Io_url Root_dir = Op_sys.Cur().Tid_is_lnx() ? Io_url_.new_dir_("/xowa/") : Io_url_.new_dir_("C:\\xowa\\");
|
||||
}
|
||||
42
400_xowa/src/gplx/xowa/Xoae_page__tst.java
Normal file
42
400_xowa/src/gplx/xowa/Xoae_page__tst.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoae_page__tst {
|
||||
private final Xoae_page__fxt fxt = new Xoae_page__fxt();
|
||||
@Test public void Ttl() {
|
||||
fxt.Init__page("Abc");
|
||||
fxt.Exec__ttl("Заглавная_страница");
|
||||
fxt.Test__url("en.wikipedia.org/wiki/Заглавная_страница"); // fails if "%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"; DATE:2016-11-25
|
||||
}
|
||||
}
|
||||
class Xoae_page__fxt {
|
||||
private Xoae_page page;
|
||||
private Xowe_wiki wiki;
|
||||
public Xoae_page__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public void Init__page(String ttl) {
|
||||
page = Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_u8(ttl)));
|
||||
}
|
||||
public void Exec__ttl(String raw) {
|
||||
page.Ttl_(wiki.Ttl_parse(Bry_.new_u8(raw)));
|
||||
}
|
||||
public void Test__url(String expd) {
|
||||
Gftest.Eq__str(expd, page.Url().To_str(), "url");
|
||||
}
|
||||
}
|
||||
485
400_xowa/src/gplx/xowa/Xop_fxt.java
Normal file
485
400_xowa/src/gplx/xowa/Xop_fxt.java
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.tests.*; import gplx.core.log_msgs.*;
|
||||
import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.hives.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xop_fxt {
|
||||
public Xop_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
ctor(app, wiki);
|
||||
}
|
||||
public Xop_fxt(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.ctor(app, wiki);
|
||||
}
|
||||
private void ctor(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.app = app;
|
||||
this.wiki = wiki;
|
||||
app.Wiki_mgr().Add(wiki);
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
ctx = wiki.Parser_mgr().Ctx();
|
||||
mock_wkr.Clear_commons(); // assume all files are in repo 0
|
||||
wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
|
||||
parser = wiki.Parser_mgr().Main();
|
||||
this.tkn_mkr = app.Parser_mgr().Tkn_mkr();
|
||||
ctx.Para().Enabled_n_();
|
||||
hdom_wtr = wiki.Html_mgr().Html_wtr();
|
||||
wiki.Html_mgr().Img_suppress_missing_src_(false);
|
||||
wiki.Xtn_mgr().Init_by_wiki(wiki);
|
||||
Page_ttl_(Ttl_str);
|
||||
Xot_invk_tkn.Cache_enabled = false;// always disable cache for tests; can cause strange behavior when running entire suite and lnki_temp test turns on;
|
||||
}
|
||||
private Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock();
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xoae_page Page() {return ctx.Page();}
|
||||
public void Lang_by_id_(int id) {ctx.Page().Lang_(wiki.Appe().Lang_mgr().Get_by_or_new(Xol_lang_stub_.Get_by_id(id).Key()));}
|
||||
public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr;
|
||||
public Xop_fxt Reset() {
|
||||
ctx.Clear_all();
|
||||
ctx.App().Free_mem(false);
|
||||
ctx.Page().Clear_all();
|
||||
wiki.File_mgr().Clear_for_tests();
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr.Instance.InitEngine_mem(); // clear created pages
|
||||
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Reset_for_msgs() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
wiki.Lang().Msg_mgr().Clear(); // need to clear out lang
|
||||
wiki.Msg_mgr().Clear(); // need to clear out wiki.Msgs
|
||||
this.Reset();
|
||||
return this;
|
||||
}
|
||||
public Xoa_ttl Page_ttl_(String txt) {
|
||||
Xoa_ttl rv = Xoa_ttl.Parse(wiki, Bry_.new_u8(txt));
|
||||
ctx.Page().Ttl_(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Xop_tkn_chkr_base tkn_bry_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_bry).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_txt_() {return tkn_txt_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_txt_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_txt).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_space_() {return tkn_space_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_space_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_space).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn) {return tkn_eq_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_eq).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_colon_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_colon).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);}
|
||||
public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);}
|
||||
public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);}
|
||||
public Xop_tblw_tb_tkn_chkr tkn_tblw_tb_(int bgn, int end) {return (Xop_tblw_tb_tkn_chkr)new Xop_tblw_tb_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tc_tkn_chkr tkn_tblw_tc_(int bgn, int end) {return (Xop_tblw_tc_tkn_chkr)new Xop_tblw_tc_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid__br);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_curly_bgn_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tmpl_curly_bgn).Src_rng_(bgn, bgn + 2);}
|
||||
public Xop_tkn_chkr_base tkn_para_blank_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_mid_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_(int pos, byte end, byte bgn) {return new Xop_para_tkn_chkr().Para_end_(end).Para_bgn_(bgn).Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_(int bgn, int end) {return tkn_nl_(bgn, end, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len1_(int bgn) {return tkn_nl_(bgn, bgn + 1, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len0_(int pos) {return tkn_nl_(pos, pos, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_(int bgn, int end, byte tid) {return new Xop_nl_tkn_chkr().Nl_tid_(tid).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_bgn_(int bgn, int end, byte listType) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().List_itmTyp_(listType).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_end_(int pos) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_lnke tkn_lnke_(int bgn, int end) {return new Xop_tkn_chkr_lnke(bgn, end);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_() {return tkn_lnki_(-1, -1);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_(int bgn, int end) {return (Xop_lnki_tkn_chkr)new Xop_lnki_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_itm_tkn_chkr tkn_arg_itm_(Xop_tkn_chkr_base... subs) {return (Xop_arg_itm_tkn_chkr)new Xop_arg_itm_tkn_chkr().Subs_(subs);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_() {return tkn_arg_nde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_(int bgn, int end) {return (Xop_arg_nde_tkn_chkr)new Xop_arg_nde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_(Xop_tkn_chkr_base... subs) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr val = new Xop_arg_itm_tkn_chkr();
|
||||
val.Subs_(subs);
|
||||
rv.Val_tkn_(val);
|
||||
return rv;
|
||||
}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Val_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
Xop_arg_nde_tkn_chkr tkn_arg_key_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Key_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_(int bgn, int end) {return (Xot_invk_tkn_chkr)new Xot_invk_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_w_name(int bgn, int end, int name_bgn, int name_end) {
|
||||
Xot_invk_tkn_chkr rv = new Xot_invk_tkn_chkr();
|
||||
rv.Src_rng_(bgn, end);
|
||||
rv.Name_tkn_(tkn_arg_key_txt_(name_bgn, name_end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_prm_chkr tkn_tmpl_prm_find_(Xop_tkn_chkr_base find) {
|
||||
Xot_prm_chkr rv = new Xot_prm_chkr();
|
||||
rv.Find_tkn_(tkn_arg_itm_(find));
|
||||
return rv;
|
||||
}
|
||||
public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;}
|
||||
public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;}
|
||||
public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.New();
|
||||
public void Init_defn_add(String name, String text) {Init_defn_add(name, text, Xow_ns_case_.Tid__all);}
|
||||
public void Init_defn_add(String name, String text, byte case_match) {
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.new_a7(name), Bry_.new_u8(text));
|
||||
wiki.Cache_mgr().Defn_cache().Add(itm, case_match);
|
||||
}
|
||||
public void Init_defn_clear() {wiki.Cache_mgr().Defn_cache().Free_mem_all();}
|
||||
public Xop_fxt Init_id_create(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Xow_hive_mgr_fxt.Create_id(app, wiki.Hive_mgr(), id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;}
|
||||
public Xop_fxt Init_page_create(String ttl) {return Init_page_create(wiki, ttl, "");}
|
||||
public Xop_fxt Init_page_create(String ttl, String txt) {return Init_page_create(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_create(Xowe_wiki wiki, String ttl, String txt) {Init_page_create_static(wiki, ttl, txt);return this;}
|
||||
public static void Init_page_create_static(Xowe_wiki wiki, String ttl_str, String text_str) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
|
||||
byte[] text = Bry_.new_u8(text_str);
|
||||
wiki.Db_mgr().Save_mgr().Data_create(wiki, ttl, text);
|
||||
}
|
||||
public static void Init_msg(Xowe_wiki wiki, String key, String val) {
|
||||
wiki.Lang().Msg_mgr().Itm_by_key_or_new(key, val);
|
||||
}
|
||||
public Xop_fxt Init_page_update(String ttl, String txt) {return Init_page_update(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_update(Xowe_wiki wiki, String ttl, String txt) {
|
||||
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl));
|
||||
byte[] page_raw = Bry_.new_u8(txt);
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_update(page, page_raw);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_clear() {
|
||||
wiki.Xwiki_mgr().Clear();
|
||||
app.Usere().Wiki().Xwiki_mgr().Clear();
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_wiki_and_user_(String alias, String domain) {
|
||||
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_user_(String domain) {return Init_xwiki_add_user_(domain, domain);}
|
||||
public Xop_fxt Init_xwiki_add_user_(String alias, String domain) {
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_template(String tmpl_raw, String expd) {Test_parse_tmpl_str_test(tmpl_raw, "{{test}}", expd);}
|
||||
public void Test_parse_tmpl_str_test(String tmpl_raw, String page_raw, String expd) {
|
||||
Init_defn_add("test", tmpl_raw);
|
||||
Test_parse_tmpl_str(page_raw, expd);
|
||||
}
|
||||
public void Test_parse_tmpl_str(String raw, String expd) {
|
||||
byte[] actl = Test_parse_tmpl_str_rv(raw);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public byte[] Test_parse_tmpl_str_rv(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
ctx.Page().Root_(root);
|
||||
ctx.Page().Db().Text().Text_bry_(raw_bry);
|
||||
return parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
}
|
||||
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
|
||||
public void Test_parse_tmpl(String raw, Tst_chkr... expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.Empty, raw_bry);
|
||||
Parse_chk(raw_bry, itm.Root(), expd);
|
||||
}
|
||||
public void Test_parse_page_tmpl_str(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
byte[] actl = parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Test_parse_page_wiki_root(raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_wiki_root(String raw) {return Test_parse_page_wiki_root(Bry_.new_u8(raw));}
|
||||
Xop_root_tkn Test_parse_page_wiki_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_all(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
|
||||
public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public void Test_parse_page_all_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_all_as_str(raw);
|
||||
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
|
||||
}
|
||||
public void Test_parse_page_all_str_and_chk(String raw, String expd, Gfo_msg_itm... ary) {
|
||||
this.Init_log_(ary);
|
||||
Test_parse_page_all_str(raw, expd);
|
||||
this.tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Exec_parse_page_all_as_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_page_all_clear(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public String Exec_parse_page_all_as_str(String raw) {
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Bry_bfr actl_bfr = Bry_bfr_.New();
|
||||
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
public Xoh_wtr_ctx Hctx() {return hctx;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
|
||||
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;}
|
||||
public String Exec_parse_page_wiki_as_str(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
Bry_bfr actl_bfr = Bry_bfr_.New();
|
||||
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, raw_bry, root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
|
||||
int subs_len = root.Subs_len();
|
||||
Object[] actl_ary = new Object[subs_len];
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
actl_ary[i] = root.Subs_get(i);
|
||||
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
|
||||
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_wiki_as_str(raw);
|
||||
Tfds.Eq_str_lines(expd, actl, raw);
|
||||
return this;
|
||||
}
|
||||
public void Log_clear() {ctx.App().Msg_log().Clear();}
|
||||
public String[] Log_xtoAry() {
|
||||
Gfo_msg_log msg_log = app.Msg_log();
|
||||
int len = msg_log.Ary_len();
|
||||
List_adp actl_list = List_adp_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_data eny = msg_log.Ary_get(i);
|
||||
if (eny.Item().Cmd() > Gfo_msg_itm_.Cmd_note) {
|
||||
actl_list.Add(String_.new_u8(eny.Item().Path_bry()));
|
||||
}
|
||||
}
|
||||
String[] actl = actl_list.To_str_ary();
|
||||
msg_log.Clear();
|
||||
return actl;
|
||||
}
|
||||
public Xop_fxt tst_Log_check() {
|
||||
int len = log_itms.Count();
|
||||
String[] expd = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_itm itm = (Gfo_msg_itm)log_itms.Get_at(i);
|
||||
expd[i] = itm.Path_str();
|
||||
}
|
||||
log_itms.Clear();
|
||||
String[] actl = Log_xtoAry();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public void tst_Warn(String... expd) {
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
Gfo_usr_dlg__gui_test ui_wkr = (Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr();
|
||||
String[] actl = ui_wkr.Warns().To_str_ary();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
public void Test_parse_page(String ttl, String expd) {
|
||||
byte[] actl = Load_page(wiki, ttl);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public static byte[] Load_page(Xowe_wiki wiki, String ttl_str) {
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
Xoa_url page_url = Xoa_url.New(wiki.Domain_bry(), ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
|
||||
return wiki.Data_mgr().Load_page_and_parse(page_url, ttl).Db().Text().Text_bry();
|
||||
}
|
||||
public static void Reg_xwiki_alias(Xowe_wiki wiki, String alias, String domain) {
|
||||
byte[] domain_bry = Bry_.new_a7(domain);
|
||||
wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_a7(alias), domain_bry, Bry_.Add(domain_bry, Bry_.new_a7("/wiki/~{0}")));
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain_bry, domain_bry);
|
||||
}
|
||||
public static String html_img_none(String trg, String alt, String src, String ttl) {
|
||||
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xoimg_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
|
||||
}
|
||||
private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);}
|
||||
private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);}
|
||||
public void Test_html_wiki_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_wiki(raw));}
|
||||
public void Test_html_full_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_full(raw));}
|
||||
public void Test_html_wiki_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_wiki(raw), expd_frags);}
|
||||
public void Test_html_full_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_full(raw), expd_frags);}
|
||||
public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);}
|
||||
public void Test__parse__tmpl_to_html(String raw, String expd) {Test_str_full(raw, gplx.langs.htmls.Gfh_utl.Replace_apos(expd), Exec_html_full(raw));}
|
||||
public void Test__parse__wtxt_to_html(String raw, String expd) {
|
||||
String actl = Exec_html_wiki(raw);
|
||||
Tfds.Eq_str_lines(gplx.langs.htmls.Gfh_utl.Replace_apos(expd), actl, raw);
|
||||
}
|
||||
|
||||
public void Test_str_full(String raw, String expd, String actl) {
|
||||
Tfds.Eq_str_lines(expd, actl, raw);
|
||||
}
|
||||
public void Test_str_part_y(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean pass = String_.Has(actl, expd_part);
|
||||
if (!pass)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
private void Test_str_part_n(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean has = String_.Has(actl, expd_part);
|
||||
if (has)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
public void Test_html_modules_js(String expd) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
this.Page().Html_data().Head_mgr().Init(app, wiki, this.Page());
|
||||
this.Page().Html_data().Head_mgr().Bfr_arg__add(bfr);
|
||||
bfr.Mkr_rls();
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
|
||||
private Tst_mgr tst_mgr = new Tst_mgr(); private Xop_tkn_mkr tkn_mkr;
|
||||
public static final String Ttl_str = "Test page";
|
||||
public Xop_fxt Init_lang_numbers_separators_en() {return Init_lang_numbers_separators(",", ".");}
|
||||
public Xop_fxt Init_lang_numbers_separators(String grp_spr, String dec_spr) {return Init_lang_numbers_separators(wiki.Lang(), grp_spr, dec_spr);}
|
||||
public Xop_fxt Init_lang_numbers_separators(Xol_lang_itm lang, String grp_spr, String dec_spr) {
|
||||
gplx.xowa.langs.numbers.Xol_transform_mgr separator_mgr = lang.Num_mgr().Separators_mgr();
|
||||
separator_mgr.Clear();
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_u8(grp_spr));
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__dec, Bry_.new_u8(dec_spr));
|
||||
return this;
|
||||
}
|
||||
public void Init_lang_kwds(int kwd_id, boolean case_match, String... kwds) {Init_lang_kwds(wiki.Lang(), kwd_id, case_match, kwds);}
|
||||
public void Init_lang_kwds(Xol_lang_itm lang, int kwd_id, boolean case_match, String... kwds) {
|
||||
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
|
||||
Xol_kwd_grp kwd_grp = kwd_mgr.Get_or_new(kwd_id);
|
||||
kwd_grp.Srl_load(case_match, Bry_.Ary(kwds));
|
||||
}
|
||||
public void Init_lang_vnts(String... vnts) {
|
||||
wiki.Lang().Vnt_mgr().Enabled_(true);
|
||||
gplx.xowa.langs.vnts.Xol_vnt_regy vnt_regy = wiki.Lang().Vnt_mgr().Regy();
|
||||
for (int i = 0; i < vnts.length; i++) {
|
||||
byte[] vnt = Bry_.new_u8(vnts[i]);
|
||||
vnt_regy.Add(vnt, vnt);
|
||||
if (i == 0) {
|
||||
wiki.Lang().Vnt_mgr().Cur_itm_(vnt);
|
||||
}
|
||||
}
|
||||
wiki.Lang().Vnt_mgr().Init_end();
|
||||
}
|
||||
public void Init_xtn_pages() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
wiki.Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
wiki.Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
wiki.Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
}
|
||||
public void Clear_ref_mgr() {this.Page().Ref_mgr().Grps_clear();} // clear to reset count
|
||||
public static Xop_fxt new_nonwmf() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
return new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit__nonwmf(app, "nethackwiki"));
|
||||
}
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
|
||||
public String Exec__parse_to_hdump(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
|
||||
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
|
||||
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
|
||||
ctx.Page().Html_data().Redlink_list().Clear();
|
||||
html_wtr.Write_doc(tmp_bfr, ctx, hctx, src_bry, root);
|
||||
// Tfds.Dbg(tmp_bfr.To_str());
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
public void Test__parse_to_html_mgr(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
|
||||
Xoae_page page = this.Page();
|
||||
page.Root_(root);
|
||||
byte[] actl = wiki.Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public String Exec__parse_to_html_w_skin(String raw) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Xow_html_mgr html_mgr = wiki.Html_mgr();
|
||||
this.Wiki().Html__wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
|
||||
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = this.Exec_parse_page_all_as_root(raw_bry);
|
||||
this.Page().Root_(root);
|
||||
|
||||
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, this.Page(), this.Ctx(), Xoh_page_html_source_.Wtr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public void Test__parse_to_html_w_skin(String raw, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Exec__parse_to_html_w_skin(raw));
|
||||
}
|
||||
public static Xop_fxt New_app_html() {
|
||||
Xop_fxt fxt = new Xop_fxt();
|
||||
fxt.Wiki().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
|
||||
return fxt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.specials.maints.services.*;
|
||||
public class Xocfg_cache_mgr__tst {
|
||||
private final Xocfg_cache_mgr__fxt fxt = new Xocfg_cache_mgr__fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Get__wiki() {
|
||||
fxt.Init__db_add("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.d", "key_1", "dflt");
|
||||
}
|
||||
@Test public void Get__app() {
|
||||
String ctx = Xocfg_mgr.Ctx__app;
|
||||
fxt.Init__db_add(ctx, "key_1", "val_1");
|
||||
fxt.Test__get(ctx, "key_1", "val_1");
|
||||
fxt.Test__get("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.d", "key_1", "val_1");
|
||||
}
|
||||
@Test public void Set__app() {
|
||||
String ctx = Xocfg_mgr.Ctx__app;
|
||||
fxt.Init__db_add(ctx, "key_1", "123");
|
||||
fxt.Init__sub(ctx, "key_1", "key_1");
|
||||
fxt.Exec__set(ctx, "key_1", "234");
|
||||
fxt.Test__get(ctx, "key_1", "234");
|
||||
fxt.Sub().Test__key_1(234);
|
||||
}
|
||||
}
|
||||
class Xocfg_cache_mgr__fxt {
|
||||
private Xocfg_cache_mgr mgr = new Xocfg_cache_mgr();
|
||||
private int id;
|
||||
public void Clear() {
|
||||
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get_or_autocreate(true, Io_url_.new_any_("mem/xowa/wiki/en.wikipedia.org/"));
|
||||
mgr.Init_by_app(conn, conn);
|
||||
}
|
||||
public Xocfg_cache_sub_mock Sub() {return sub;} private Xocfg_cache_sub_mock sub = new Xocfg_cache_sub_mock();
|
||||
public void Init__db_add(String ctx, String key, Object val) {
|
||||
Xocfg_maint_svc.Create_grp(mgr.Db_app(), "", id++, "test_grp", "", "");
|
||||
Xocfg_maint_svc.Create_itm(mgr.Db_app(), "test_grp", id++, key, "", "", "wiki", String_.Cls_val_name, "dflt", "", "");
|
||||
mgr.Db_usr().Set_str(ctx, key, Object_.Xto_str_strict_or_null(val));
|
||||
}
|
||||
public void Init__sub(String ctx, String key, String evt) {
|
||||
mgr.Sub(sub, ctx, key, evt);
|
||||
}
|
||||
public void Test__get(String ctx, String key, String expd) {
|
||||
Gftest.Eq__str(expd, mgr.Get(ctx, key), "ctx={0} key={1}", ctx, key);
|
||||
}
|
||||
public void Exec__set(String ctx, String key, String val) {
|
||||
mgr.Set(ctx, key, val);
|
||||
}
|
||||
}
|
||||
class Xocfg_cache_sub_mock implements Gfo_invk {
|
||||
private int key_1;
|
||||
public void Test__key_1(int expd) {
|
||||
Gftest.Eq__int(expd, key_1);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Evt__key_1)) {key_1 = m.ReadInt("v");}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Evt__key_1 = "key_1";
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xocfg_maint_parser__tst {
|
||||
private final Xocfg_maint_parser__fxt fxt = new Xocfg_maint_parser__fxt();
|
||||
@Test public void Parse_grp() {
|
||||
fxt.Exec__parse("grp {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'}"
|
||||
, fxt.Make__grp("owner_1", 123, "key_1", "name_1", "help_1")
|
||||
);
|
||||
}
|
||||
@Test public void Parse_itm() {
|
||||
fxt.Exec__parse("itm {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'; scope='scope_1'; type='type_1'; dflt='dflt_1'; html_atrs='html_atrs_1'; html_cls='html_cls_1'}"
|
||||
, fxt.Make__itm("owner_1", 123, "key_1", "name_1", "help_1", "scope_1", "type_1", "dflt_1", "html_atrs_1", "html_cls_1")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xocfg_maint_parser__fxt {
|
||||
private Xocfg_maint_parser parser = new Xocfg_maint_parser();
|
||||
public void Exec__parse(String raw, Xocfg_maint_nde... expd) {
|
||||
Xocfg_maint_nde[] actl = parser.Parse(raw);
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
}
|
||||
public Xocfg_maint_grp Make__grp(String owner, int id, String key, String name, String help) {
|
||||
return new Xocfg_maint_grp(owner, id, key, name, help);
|
||||
}
|
||||
public Xocfg_maint_itm Make__itm(String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) {
|
||||
return new Xocfg_maint_itm(owner, id, key, name, help, scope, type, dflt, html_atrs, html_cls);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xocfg_upgrade_mgr__tst {
|
||||
private final Xocfg_upgrade_mgr__fxt fxt = new Xocfg_upgrade_mgr__fxt();
|
||||
@Test public void Parse__one() {
|
||||
fxt.Test__parse("app.cfgs.get('k_1', 'app').val = 'v_1';\n", Keyval_.new_("k_1", "v_1"));
|
||||
}
|
||||
@Test public void Parse__apos() {
|
||||
fxt.Test__parse("app.cfgs.get('k_1(''k_1a'')', 'app').val = 'v_1';\n", Keyval_.new_("k_1('k_1a')", "v_1"));
|
||||
}
|
||||
@Test public void Parse__many() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('k_1', 'app').val = 'v_1';\n"
|
||||
+ "app.cfgs.get('k_2', 'app').val = 'v_2';\n"
|
||||
, Keyval_.new_("k_1", "v_1"), Keyval_.new_("k_2", "v_2"));
|
||||
}
|
||||
@Test public void Parse__multi_line() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('k_1', 'app').val = '''v_1'';\n"
|
||||
+ "v_2\n"
|
||||
+ "v_3';\n"
|
||||
, Keyval_.new_("k_1", "'v_1';\nv_2\nv_3"));
|
||||
}
|
||||
@Test public void Parse__io_cmd() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('a.cmd', 'app').val = 'cmd_1';\n"
|
||||
+ "app.cfgs.get('a.args', 'app').val = 'args_1';\n"
|
||||
, Keyval_.new_("a.cmd", "cmd_1|args_1"));
|
||||
}
|
||||
@Test public void Parse__gui_binding() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('app.cfg.get.gui.bnds.init(''xowa.app.exit-1'').src', 'app').val = 'box=''browser'';ipt=''key.none'';';\n"
|
||||
, Keyval_.new_("xowa.gui.shortcuts.xowa.app.exit-1", "browser|key.none"));
|
||||
}
|
||||
}
|
||||
class Xocfg_upgrade_mgr__fxt {
|
||||
public void Test__parse(String raw, Keyval... expd) {
|
||||
Keyval[] actl = Xocfg_upgrade_mgr.Parse(Bry_.new_u8(raw));
|
||||
Gftest.Eq__str(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoscript_doc_head__tst {
|
||||
private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt();
|
||||
@Before public void init() {
|
||||
fxt.Init__sect("head");
|
||||
fxt.Exec__reg_marker("<!--top-->", "top", Xoscript_doc_head.Pos__default);
|
||||
fxt.Exec__reg_marker("<!--bot-->", "bot");
|
||||
fxt.Exec__doc__html("a<!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_html() {
|
||||
fxt.Exec__add_html("top", "<b>add_1</b>");
|
||||
fxt.Exec__add_html("top", "<b>add_2</b>");
|
||||
fxt.Test__html("a<b>add_1</b><b>add_2</b><!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_html__default() {
|
||||
fxt.Exec__add_html("<b>add_1</b>");
|
||||
fxt.Test__html("a<b>add_1</b><!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_tag() {
|
||||
fxt.Exec__add_tag("top", "div", "div_body", "k0", "v0", "k1", "v1");
|
||||
fxt.Test__html
|
||||
( "a<div k0=\"v0\" k1=\"v1\">div_body</div>"
|
||||
, "<!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_js_file() {
|
||||
fxt.Exec__add_js_file("top", "./a.js");
|
||||
fxt.Test__html
|
||||
( "a<script src=\"file:///mem/wiki/test_wiki/bin/script/a.js\" type=\"text/javascript\"></script>"
|
||||
, "<!--top-->b<!--bot-->c");
|
||||
}
|
||||
}
|
||||
class Xoscript_doc_head__fxt {
|
||||
private final Xoscript_page spg;
|
||||
private Xoscript_doc_sect_base sect;
|
||||
public Xoscript_doc_head__fxt() {
|
||||
Bry_bfr rv = Bry_bfr_.New();
|
||||
Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_url url = new Xoscript_url("test_wiki", "test_page");
|
||||
spg = new Xoscript_page(rv, env, url);
|
||||
}
|
||||
public void Init__sect(String sect_name) {
|
||||
if (String_.Eq(sect_name, "head"))
|
||||
sect = spg.doc().head();
|
||||
else if (String_.Eq(sect_name, "tail"))
|
||||
sect = spg.doc().tail();
|
||||
}
|
||||
public void Exec__doc__html(String html) {spg.doc().html(html);}
|
||||
public void Exec__reg_marker(String marker, String... pos_ary) {sect.reg_marker(marker, pos_ary);}
|
||||
public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);}
|
||||
public void Exec__add_html(String html) {sect.add_html(html);}
|
||||
public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Test__html(String... expd) {
|
||||
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates.specials.svcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; import gplx.xowa.addons.apps.updates.specials.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Xoa_update_svc__tst {
|
||||
private final Xoa_update_svc__fxt fxt = new Xoa_update_svc__fxt();
|
||||
@Test public void Restart_cmd() {
|
||||
Io_url jar_fil = Io_url_.new_dir_("/home/gnosygnu/xowa/xowa.jar");
|
||||
fxt.Test__restart_cmd("manual" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "manual");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_linux_64.sh");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_linux.sh");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_macosx_64");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_macosx");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_64, "/home/gnosygnu/xowa/xowa_64.exe");
|
||||
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_32, "/home/gnosygnu/xowa/xowa.exe");
|
||||
}
|
||||
}
|
||||
class Xoa_update_svc__fxt {
|
||||
public void Test__restart_cmd(String current, Io_url app_url, byte op_sys_tid, byte bitness, String expd) {
|
||||
Gftest.Eq__str(expd, Xoa_update_svc.App__update__restart_cmd(current, app_url, op_sys_tid, bitness), "restart_cmd");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
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.bldrs.app_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
public class Xob_wiki_cfg_bldr_tst {
|
||||
Xob_wiki_cfg_bldr_fxt fxt = new Xob_wiki_cfg_bldr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Exec() {
|
||||
fxt .Init_cmd("en.wikipedia.org", "key0", "en.val0")
|
||||
.Init_cmd("en.wikipedia.org", "key1", "en.val1")
|
||||
.Init_cmd("fr.wikipedia.org", "key0", "fr.val0")
|
||||
.Init_cmd("fr.wikipedia.org", "key1", "fr.val1")
|
||||
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
|
||||
( "// key0.bgn"
|
||||
, "en.val0"
|
||||
, "// key0.end"
|
||||
, "// key1.bgn"
|
||||
, "en.val1"
|
||||
, "// key1.end"
|
||||
))
|
||||
.Expd_txt("fr.wikipedia.org", String_.Concat_lines_nl
|
||||
( "// key0.bgn"
|
||||
, "fr.val0"
|
||||
, "// key0.end"
|
||||
, "// key1.bgn"
|
||||
, "fr.val1"
|
||||
, "// key1.end"
|
||||
))
|
||||
.Test()
|
||||
;
|
||||
fxt .Clear()
|
||||
.Init_cmd("en.wikipedia.org", "key2", "en.val2")
|
||||
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
|
||||
( "// key0.bgn"
|
||||
, "en.val0"
|
||||
, "// key0.end"
|
||||
, "// key1.bgn"
|
||||
, "en.val1"
|
||||
, "// key1.end"
|
||||
, "// key2.bgn"
|
||||
, "en.val2"
|
||||
, "// key2.end"
|
||||
));
|
||||
}
|
||||
// @Test public void Lang_names_run() {
|
||||
// Io_url dir = Io_url_.new_dir_("/var/www/mediawiki/languages/messages/");
|
||||
// Io_url[] fils = Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry();
|
||||
// int fils_len = fils.length;
|
||||
// String_bldr sb = String_bldr_.new_();
|
||||
// for (int i = 0; i < fils_len; i++) {
|
||||
// Io_url fil = fils[i];
|
||||
// String lang_code = String_.Lower(String_.Replace(fil.NameOnly(), "Messages", ""));
|
||||
// String txt = Io_mgr.Instance.LoadFilStr(fil);
|
||||
// String[] lines = String_.Split(txt, '\n');
|
||||
// String line = lines[1];
|
||||
// line = String_.Replace(line, "/** ", "");
|
||||
// int pos = String_.FindBwd(line, " (");
|
||||
// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line
|
||||
// if ( String_.Has_at_bgn(lang_code, "be_")
|
||||
// || String_.Has_at_bgn(lang_code, "crh_")
|
||||
// || String_.Has_at_bgn(lang_code, "kk_")
|
||||
// || String_.Has_at_bgn(lang_code, "ku_")
|
||||
// || String_.Has_at_bgn(lang_code, "sr_")
|
||||
// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no")
|
||||
// ) {
|
||||
// int new_pos = String_.FindBwd(line, " (", pos - 1);
|
||||
// if (new_pos != String_.Find_none)
|
||||
// pos = new_pos;
|
||||
// }
|
||||
// line = Replace_by_pos(line, pos, pos + 2, "|");
|
||||
// int line_len = String_.Len(line);
|
||||
// if (line_len > 0)
|
||||
// line = String_.MidByLen(line, 0, line_len - 1);
|
||||
// String[] terms = String_.Split(line, '|');
|
||||
// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n");
|
||||
// }
|
||||
// Tfds.Dbg(sb.To_str_and_clear());
|
||||
// }
|
||||
@Test public void Ns_aliases() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl
|
||||
( "<api>"
|
||||
, "<query>"
|
||||
, "<namespacealiases>"
|
||||
, "<ns id=\"4\" xml:space=\"preserve\">WP"
|
||||
, "</ns>"
|
||||
, "<ns id=\"5\" xml:space=\"preserve\">WT"
|
||||
, "</ns>"
|
||||
, "<ns id=\"6\" xml:space=\"preserve\">Image"
|
||||
, "</ns>"
|
||||
, "<ns id=\"7\" xml:space=\"preserve\">Image talk"
|
||||
, "</ns>"
|
||||
, "</namespacealiases>"
|
||||
, "</query>"
|
||||
, "</api>"
|
||||
));
|
||||
String[] wikis = new String[] {"en.wikipedia.org"}; String protocol = "mem/";
|
||||
Tfds.Eq_str_lines(Query_ns(protocol, gplx.core.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl
|
||||
( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\""
|
||||
, "4|WP"
|
||||
, "5|WT"
|
||||
, "6|Image"
|
||||
, "7|Image_talk"
|
||||
, "\");');"
|
||||
));
|
||||
}
|
||||
String Query_ns(String protocol, String trg_engine_key, String[] wikis) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int wikis_len = wikis.length;
|
||||
for (int i = 0; i < wikis_len; i++) {
|
||||
String wiki = wikis[i];
|
||||
if (String_.Len_eq_0(wiki)) continue;
|
||||
try {
|
||||
String api = protocol + wiki + "/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases";
|
||||
String xml = String_.new_u8(Io_mgr.Instance.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api));
|
||||
if (xml == null) continue; // not found
|
||||
gplx.langs.xmls.XmlDoc xdoc = gplx.langs.xmls.XmlDoc_.parse(xml);
|
||||
gplx.langs.xmls.XmlNde xnde = gplx.langs.xmls.Xpath_.SelectFirst(xdoc.Root(), "query/namespacealiases");
|
||||
sb.Add("app.bldr.wiki_cfg_bldr.get('").Add(wiki).Add("').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"\n");
|
||||
int xndes_len = xnde.SubNdes().Count();
|
||||
for (int j = 0; j < xndes_len; j++) {
|
||||
gplx.langs.xmls.XmlNde ns_nde = xnde.SubNdes().Get_at(j);
|
||||
if (!String_.Eq(ns_nde.Name(), "ns")) continue;
|
||||
int id = Int_.Parse(ns_nde.Atrs().FetchValOr("id", "-1"));
|
||||
String name = String_.Replace(String_.Replace(ns_nde.Text_inner(), " ", "_"), "'", "''");
|
||||
sb.Add(Int_.To_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl();
|
||||
}
|
||||
sb.Add("\");');\n");
|
||||
}
|
||||
catch(Exception e) {sb.Add("// fail: " + wiki + " " + Err_.Message_gplx_full(e)).Add_char_nl();}
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
class Xob_wiki_cfg_bldr_fxt {
|
||||
public Xob_wiki_cfg_bldr_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki_cfg_bldr = app.Bldr().Wiki_cfg_bldr();
|
||||
}
|
||||
wiki_cfg_bldr.Clear();
|
||||
hash.Clear();
|
||||
return this;
|
||||
} private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xob_wiki_cfg_bldr_fxt Init_cmd(String wiki, String key, String text) {
|
||||
wiki_cfg_bldr.Itms_get_or_new(wiki).Itms_add(key, text);
|
||||
return this;
|
||||
}
|
||||
public Xob_wiki_cfg_bldr_fxt Expd_txt(String wiki, String text) {
|
||||
hash.Add(wiki, Keyval_.new_(wiki, text));
|
||||
return this;
|
||||
}
|
||||
public void Test() {
|
||||
wiki_cfg_bldr.Exec();
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval kv = (Keyval)hash.Get_at(i);
|
||||
String wiki = kv.Key();
|
||||
String expd = (String)kv.Val();
|
||||
String actl = Io_mgr.Instance.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Host_eval_wkr__tst {
|
||||
private final Host_eval_wkr__fxt fxt = new Host_eval_wkr__fxt();
|
||||
@Test public void En_w() {fxt.Test__resolve_quick("en.wikipedia.org" , "Xowa_enwiki_latest");}
|
||||
@Test public void Fr_d() {fxt.Test__resolve_quick("fr.wiktionary.org" , "Xowa_frwiki_latest");}
|
||||
@Test public void Species() {fxt.Test__resolve_quick("species.wikimedia.org" , "Xowa_enwiki_latest");}
|
||||
}
|
||||
class Host_eval_wkr__fxt {
|
||||
public void Test__resolve_quick(String domain_str, String expd) {
|
||||
Host_eval_itm eval_itm = new Host_eval_itm();
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), eval_itm.Eval_dir_name(domain_itm));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Time_dhms__tst {
|
||||
private final Time_dhms__fxt fxt = new Time_dhms__fxt();
|
||||
@Test public void S__0() {fxt.Test__to_str( 0, 4, "0 s");}
|
||||
@Test public void S__1() {fxt.Test__to_str( 1, 4, "1 s");}
|
||||
@Test public void S__2() {fxt.Test__to_str( 30, 4, "30 s");}
|
||||
@Test public void M__1() {fxt.Test__to_str( 60, 4, "1:00 m");}
|
||||
@Test public void M__2() {fxt.Test__to_str( 600, 4, "10:00 m");}
|
||||
@Test public void H__1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");}
|
||||
@Test public void H__2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");}
|
||||
@Test public void D__1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");}
|
||||
@Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");}
|
||||
}
|
||||
class Time_dhms__fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) {
|
||||
Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places));
|
||||
return this;}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Pack_zip_name_bldr__tst {
|
||||
private Pack_zip_name_bldr__fxt fxt = new Pack_zip_name_bldr__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__to_wiki_url("mem/wiki/en.wikipedia.org/", "mem/wiki/en.wikipedia.org/tmp/Xowa_enwiki_2016-09_file_deletion_2016.09/", "mem/wiki/en.wikipedia.org/en.wikipedia.org-file-deletion-2016.09.xowa");
|
||||
}
|
||||
@Test public void Bld_by_suffix() {
|
||||
Pack_zip_name_bldr bldr = fxt.Make__bldr("mem/wiki/en.wikipedia.org/tmp/pack/", "en.wikipedia.org", "enwiki", "2017-03", null);
|
||||
fxt.Test__bld_by_suffix(bldr, "xtn.fulltext_search", 1, "mem/wiki/en.wikipedia.org/tmp/pack/Xowa_enwiki_2017-03_xtn.fulltext_search.002.zip");
|
||||
}
|
||||
}
|
||||
class Pack_zip_name_bldr__fxt {
|
||||
public void Test__to_wiki_url(String wiki_dir, String zip_fil, String expd) {
|
||||
Gftest.Eq__str(expd, Pack_zip_name_bldr.To_wiki_url(Io_url_.mem_fil_(wiki_dir), Io_url_.mem_dir_(zip_fil)).Raw(), "wiki_url");
|
||||
}
|
||||
|
||||
public Pack_zip_name_bldr Make__bldr(String wiki_dir, String domain, String wiki_abrv, String wiki_date, String custom_name) {
|
||||
return new Pack_zip_name_bldr(Io_url_.new_dir_(wiki_dir), domain, wiki_abrv, wiki_date, custom_name);
|
||||
}
|
||||
public void Test__bld_by_suffix(Pack_zip_name_bldr bldr, String suffix, int pack_num, String expd) {
|
||||
Gftest.Eq__str(expd, bldr.Bld_by_suffix(suffix, pack_num).Xto_api());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.files.*;
|
||||
public class Xobldr__image__create_tst {
|
||||
private Xobldr__image__create_fxt fxt = new Xobldr__image__create_fxt();
|
||||
@Test public void Basic() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_png, 220, 110) .Test(Xof_ext_.Id_png);} // A.png -> png
|
||||
@Test public void Ogg_VIDEO() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 220, 110) .Test(Xof_ext_.Id_ogv);} // A.ogg and VIDEO -> ogv
|
||||
@Test public void Ogg_VIDEO_null_size() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 0, 0) .Test(Xof_ext_.Id_ogg);} // A.ogg but 0,0 -> ogg (not ogv)
|
||||
@Test public void Png_is_jpg() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpg);} // A.png and jpg -> jpg
|
||||
@Test public void Jpeg_is_jpeg() {fxt.Init_("A.jpeg" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpeg);} // A.jpeg and jpg -> jpeg (unchanged)
|
||||
}
|
||||
class Xobldr__image__create_fxt {
|
||||
private byte[] name, media_type, minor_mime; int w, h;
|
||||
public Xobldr__image__create_fxt Init_png() {Name_("A.png").Media_type_(Xof_media_type.Name_bitmap).Minor_mime_(Xof_ext_.Bry_png).W_(220).H_(110);
|
||||
return this;
|
||||
}
|
||||
public Xobldr__image__create_fxt Init_(String name, String media_type, byte[] minor_mime, int w, int h) {
|
||||
Name_(name);
|
||||
Media_type_(media_type);
|
||||
Minor_mime_(minor_mime);
|
||||
W_(w);
|
||||
H_(h);
|
||||
return this;
|
||||
}
|
||||
public Xobldr__image__create_fxt Name_(String v) {name = Bry_.new_a7(v); return this;}
|
||||
public Xobldr__image__create_fxt Media_type_(String v) {media_type = Bry_.new_a7(v); return this;}
|
||||
public Xobldr__image__create_fxt Minor_mime_(byte[] v) {minor_mime = v; return this;}
|
||||
public Xobldr__image__create_fxt Minor_mime_(String v) {return Minor_mime_(Bry_.new_a7(v));}
|
||||
public Xobldr__image__create_fxt W_(int v) {w = v; return this;}
|
||||
public Xobldr__image__create_fxt H_(int v) {h = v; return this;}
|
||||
public Xobldr__image__create_fxt Test(int expd) {
|
||||
Tfds.Eq(expd, Xobldr__image__create.Calc_ext_id(Gfo_usr_dlg_.Noop, name, media_type, minor_mime, w, h));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
|
||||
import org.junit.*;
|
||||
public class Xobldr__lnki_temp__create__tst {
|
||||
private Xobldr__lnki_temp__create__fxt fxt = new Xobldr__lnki_temp__create__fxt();
|
||||
@Test public void Xto_commons() {
|
||||
fxt.Init__to_commons(true);
|
||||
fxt.Test__to_commons("a", "A");
|
||||
fxt.Test__to_commons("A", null);
|
||||
fxt.Init__to_commons(false);
|
||||
fxt.Test__to_commons("a", null);
|
||||
fxt.Test__to_commons("A", null);
|
||||
}
|
||||
}
|
||||
class Xobldr__lnki_temp__create__fxt {
|
||||
private boolean wiki_ns_file_is_case_match_all;
|
||||
private Xowe_wiki commons_wiki;
|
||||
public Xobldr__lnki_temp__create__fxt Init__to_commons(boolean wiki_ns_file_is_case_match_all) {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all;
|
||||
this.commons_wiki = Xoa_app_fxt.Make__wiki__edit(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st
|
||||
return this;
|
||||
}
|
||||
public void Test__to_commons(String ttl, String expd) {
|
||||
Tfds.Eq(expd, String_.new_u8(gplx.xowa.addons.bldrs.mass_parses.parses.utls.Xomp_lnki_temp_wkr.To_commons_ttl(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_u8(ttl))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.files.missing_origs.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.missing_origs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xowmf_imageinfo_item__tst {
|
||||
private final Xowmf_imageinfo_item__fxt fxt = new Xowmf_imageinfo_item__fxt();
|
||||
|
||||
@Test public void Normalize_ttl() {
|
||||
fxt.Test__Normalize_ttl("File:A b.png", "A_b.png");
|
||||
}
|
||||
@Test public void Normalize_minor_mime() {
|
||||
fxt.Test__Normalize_minor_mime("image/svg+xml", "svg+xml");
|
||||
}
|
||||
@Test public void Normalize_timestamp() {
|
||||
fxt.Test__Normalize_timestamp("2017-03-06T08:09:10Z", "20170306080910");
|
||||
}
|
||||
}
|
||||
class Xowmf_imageinfo_item__fxt {
|
||||
public void Test__Normalize_ttl(String src, String expd) {
|
||||
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_ttl(Bry_.new_u8(src)));
|
||||
}
|
||||
public void Test__Normalize_timestamp(String src, String expd) {
|
||||
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_timestamp(Bry_.new_u8(src)));
|
||||
}
|
||||
public void Test__Normalize_minor_mime(String src, String expd) {
|
||||
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_minor_mime(Bry_.new_u8(src)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
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.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
import gplx.core.stores.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
|
||||
import gplx.xowa.addons.bldrs.files.dbs.*;
|
||||
public class Xob_xfer_temp_itm_tst {
|
||||
private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Pass() {fxt.Test_pass().Test_itm_chk_fail_id_none();}
|
||||
@Test public void Missing_orig() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_page_id_is_null , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_page_id, null));}
|
||||
@Test public void File_is_audio() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type, Xof_media_type.Name_audio));}
|
||||
@Test public void File_is_mid() {
|
||||
fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext, Xof_ext_.Id_mid));
|
||||
}
|
||||
@Test public void Redirect_src_is_empty() { // orig_cmd sets all direct files to have "orig_join" == "lnki_ttl"
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "A.png")
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
);
|
||||
fxt.Test_lnki_redirect_src(""); // confirm redirect_src set to ""
|
||||
}
|
||||
@Test public void Redirect_src_has_val() { // orig_cmd sets all redirect files to have "orig_join" = redirect and "lnki_ttl" as orig; EX: A.png redirects to B.png; orig_join will be B.png (the actual image) and redirect_src will be A.png (the original lnki)
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.png")
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
);
|
||||
fxt.Test_lnki_redirect_src("A.png"); // confirm redirect_src set to ""
|
||||
}
|
||||
@Test public void Redirect_should_take_trg_ext() {// if "A.png" redirects to "B.jpg", ext_id should be ".jpg" (the actual file) not ".png (lnki_ext_id)
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.jpg")
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) // .png b/c B.jpg
|
||||
);
|
||||
fxt.Test_lnki_ext_id(Xof_ext_.Id_jpg); // confirm ext changed to .jpg
|
||||
}
|
||||
@Test public void Thumbtime_check() {// PURPOSE: one image actually had a thumbtime defined; EX: General_Dynamics_F-16_Fighting_Falcon; [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
|
||||
);
|
||||
fxt.Test_lnki_thumbtime(Xof_lnki_time.Null);
|
||||
fxt.Reset().Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video)
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
|
||||
);
|
||||
fxt.Test_lnki_thumbtime(3);
|
||||
}
|
||||
@Test public void Page_check() {
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(Xof_lnki_page.Null);
|
||||
fxt.Reset().Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf)
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(3);
|
||||
fxt.Reset().Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_djvu)
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(3);
|
||||
}
|
||||
@Test public void Media_should_be_ignored() {// ignore [[Media:]] for xfer_thumb (needed for xfer_orig)
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_src_tid , Xop_file_logger_.Tid__media)
|
||||
);
|
||||
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media);
|
||||
}
|
||||
@Test public void Orig_width_is_0() {// PURPOSE: ignore files with an orig width of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
|
||||
fxt.Test_bgn
|
||||
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.ogg")
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) // VIDEO
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_w , 0) // no width defined in image table
|
||||
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_h , 0)
|
||||
);
|
||||
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_orig_w_is_0);
|
||||
}
|
||||
}
|
||||
class Xob_xfer_temp_itm_fxt {
|
||||
private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm();
|
||||
private Xof_img_size img_size = new Xof_img_size();
|
||||
private DataRdr_mem rdr;
|
||||
private GfoNde nde;
|
||||
public static String[] Flds = new String[]
|
||||
{ Xob_lnki_regy_tbl.Fld_lnki_ext
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_id
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_tier_id
|
||||
, Xob_orig_regy_tbl.Fld_orig_repo
|
||||
, Xob_orig_regy_tbl.Fld_orig_file_ttl
|
||||
, Xob_orig_regy_tbl.Fld_orig_file_ext
|
||||
, Xob_orig_regy_tbl.Fld_lnki_ttl
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_type
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_src_tid
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_w
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_h
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_count
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_page_id
|
||||
, Xob_orig_regy_tbl.Fld_orig_w
|
||||
, Xob_orig_regy_tbl.Fld_orig_h
|
||||
, Xob_orig_regy_tbl.Fld_orig_page_id
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_upright
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_time
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_page
|
||||
, Xob_orig_regy_tbl.Fld_orig_media_type
|
||||
, Xob_orig_regy_tbl.Fld_orig_minor_mime
|
||||
}
|
||||
;
|
||||
public Xob_xfer_temp_itm_fxt Reset() {
|
||||
itm.Clear();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Init_rdr_image() {
|
||||
GfoFldList flds = GfoFldList_.str_(Flds);
|
||||
nde = GfoNde_.vals_(flds, Object_.Ary
|
||||
( Xof_ext_.Id_png, 1, 1, Xof_repo_tid_.Tid__remote
|
||||
, "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xop_file_logger_.Tid__file
|
||||
, 220, 200, 1, 2, 440, 400, 3
|
||||
, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null
|
||||
, Xof_media_type.Name_bitmap, "png"
|
||||
));
|
||||
GfoNdeList subs = GfoNdeList_.new_();
|
||||
subs.Add(nde);
|
||||
GfoNde root = GfoNde_.root_(nde);
|
||||
rdr = DataRdr_mem.new_(root, flds, subs);
|
||||
rdr.MoveNextPeer();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Init_rdr(String key, Object val) {
|
||||
nde.Write(key, val);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_pass() {return Test_bgn();}
|
||||
public Xob_xfer_temp_itm_fxt Test_fail(byte fail_tid, Keyval... kvs) {
|
||||
Test_bgn(kvs);
|
||||
this.Test_itm_chk_fail_id(fail_tid);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_bgn(Keyval... kvs) {
|
||||
Init_rdr_image();
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval kv = kvs[i];
|
||||
Init_rdr(kv.Key(), kv.Val());
|
||||
}
|
||||
this.Exec_load();
|
||||
this.Exec_chk();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_atr(String key, Object val) {
|
||||
Tfds.Eq(rdr.Read(key), val);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Exec_load() {
|
||||
itm.Load(rdr);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Exec_chk() {
|
||||
itm.Chk(img_size);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_ext_id(int expd) {Tfds.Eq(expd, itm.Lnki_ext()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_thumbtime(double expd) {Tfds.Eq(expd, itm.Lnki_thumbtime()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_page(int expd) {Tfds.Eq(expd, itm.Lnki_page()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_redirect_src(String expd) {Tfds.Eq(expd, itm.Redirect_src()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id_none() {return Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_none);}
|
||||
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id(byte expd) {
|
||||
Tfds.Eq(expd, itm.Chk_tid());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xobc_info_html__tst {
|
||||
private final Xobc_info_html__fxt fxt = new Xobc_info_html__fxt();
|
||||
@Test public void Torrent__en_w() {fxt.Test__torrent_link("en.wikipedia.org" , "https://archive.org/download/Xowa_enwiki_latest_archive.torrent");}
|
||||
@Test public void Torrent__fr_d() {fxt.Test__torrent_link("fr.wiktionary.org" , "https://archive.org/download/Xowa_frwiki_latest_archive.torrent");}
|
||||
}
|
||||
class Xobc_info_html__fxt {
|
||||
public void Test__torrent_link(String domain_str, String expd) {
|
||||
Gftest.Eq__str(expd, Xobc_info_html.Make_torrent_fil("https://archive.org/download/", Xow_domain_itm_.parse(Bry_.new_u8(domain_str))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Volume_prep_rdr_tst {
|
||||
private final Volume_prep_rdr_fxt fxt = new Volume_prep_rdr_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last("A", "", "B")
|
||||
, fxt.Make__itm("A")
|
||||
, fxt.Make__itm("B")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Volume_prep_rdr_fxt {
|
||||
private final Volume_prep_rdr rdr = new Volume_prep_rdr();
|
||||
public Volume_prep_rdr_fxt Test__parse(String raw, Volume_prep_itm... expd) {
|
||||
Gftest.Eq__ary(expd, rdr.Parse(Bry_.new_u8(raw)));
|
||||
return this;
|
||||
}
|
||||
public Volume_prep_itm Make__itm(String page_ttl) {
|
||||
Volume_prep_itm rv = new Volume_prep_itm();
|
||||
rv.Page_ttl = Bry_.new_u8(page_ttl);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
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.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xoh_sidebar_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt();
|
||||
@Test public void Grp() {
|
||||
fxt.Init__msg__grp("key", "text", "title");
|
||||
fxt.Exec__make("* key");
|
||||
fxt.Test__objs(fxt.Make__grp("text", "title"));
|
||||
}
|
||||
@Test public void Grp_missing_msg() {
|
||||
fxt.Exec__make("* key");
|
||||
fxt.Test__objs(fxt.Make__grp("key", Null_str));
|
||||
}
|
||||
@Test public void Itm() {
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
||||
}
|
||||
@Test public void Itm_missing_msg() {
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Href_key"));
|
||||
}
|
||||
@Test public void Itm_text() { // PURPOSE: only text msg exists; EX: ** Portal:Contents|contents; no href, accesskey, title
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", Null_str, Null_str, Null_str); // only define msg for text
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("text", Null_str, Null_str, "/wiki/Href_key"));
|
||||
}
|
||||
@Test public void Itm_href_absolute() {
|
||||
fxt.Exec__make("** http://a.org|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "http://a.org"));
|
||||
}
|
||||
@Test public void Itm_href_manual() {
|
||||
fxt.Exec__make("** Help:Contents|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Help:Contents"));
|
||||
}
|
||||
@Test public void Itm_href_xwiki() {
|
||||
Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), "c", "commons.wikimedia.org");
|
||||
fxt.Exec__make("** c:Help:Contents|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/site/commons.wikimedia.org/wiki/Help:Contents"));
|
||||
}
|
||||
@Test public void Itm_err_missing_key() {
|
||||
fxt.Exec__make("** no_main_key");
|
||||
fxt.Test__objs();
|
||||
}
|
||||
@Test public void Itm_ignore() { // PURPOSE: ignore SEARCH, TOOLBOX, LANGUAGES
|
||||
fxt.Exec__make
|
||||
( "** SEARCH"
|
||||
, "** TOOLBOX"
|
||||
, "** LANGUAGES"
|
||||
);
|
||||
fxt.Test__objs();
|
||||
}
|
||||
@Test public void Itm_comment() { // PURPOSE: ignore comment; EX:de.v:MediaWiki:Sidebar; DATE:2014-03-08
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
|
||||
fxt.Exec__make("** href_key<!--a-->|main_key<!--b-->");
|
||||
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
||||
}
|
||||
@Test public void Smoke() {
|
||||
fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title");
|
||||
fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href");
|
||||
fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str);
|
||||
fxt.Exec__make
|
||||
( "* navigation"
|
||||
, "** mainpage|mainpage-description"
|
||||
, "** Portal:Contents|contents"
|
||||
, "* SEARCH"
|
||||
, "* interaction"
|
||||
, "** helppage|help"
|
||||
, "* TOOLBOX"
|
||||
, "** TOOLBOXEND"
|
||||
, "* LANGUAGES"
|
||||
);
|
||||
fxt.Test__objs
|
||||
( fxt.Make__grp("Grp_0_text", "Grp_0_title").Subs__add
|
||||
( fxt.Make__itm("Itm_0_text", "Itm_0_title [a]", "a", "/wiki/Itm_0_href")
|
||||
, fxt.Make__itm("Itm_1_text", Null_str, Null_str, "/wiki/Portal:Contents")
|
||||
)
|
||||
, fxt.Make__grp("interaction", Null_str).Subs__add
|
||||
( fxt.Make__itm("help", Null_str, Null_str, "/wiki/Helppage")
|
||||
));
|
||||
fxt.Test__html
|
||||
( "<div class=\"portal\" id=\"n-navigation\">"
|
||||
, " <h3>Grp_0_text</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Itm_0_href\" accesskey=\"a\" title=\"Itm_0_title [a] [a]\">Itm_0_text</a></li>"
|
||||
, " <li id=\"n-contents\"><a href=\"/wiki/Portal:Contents\" title=\"\">Itm_1_text</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, "<div class=\"portal\" id=\"n-interaction\">"
|
||||
, " <h3>interaction</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-help\"><a href=\"/wiki/Helppage\" title=\"\">help</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
||||
@Test public void Itm_template_msg() {
|
||||
fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random");
|
||||
fxt.Exec__make("** href|main");
|
||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||
}
|
||||
@Test public void Itm_template_key() {
|
||||
fxt.Exec__make("** {{ns:Special}}:Random|main");
|
||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||
}
|
||||
@Test public void Popups() {
|
||||
fxt.Init__popups_enabled(true);
|
||||
fxt.Exec__make
|
||||
( "* navigation"
|
||||
, "** mainpage|mainpage-description"
|
||||
);
|
||||
fxt.Test__objs
|
||||
( fxt.Make__grp("navigation", "").Subs__add
|
||||
( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage")
|
||||
));
|
||||
fxt.Test__html
|
||||
( "<div class=\"portal\" id=\"n-navigation\">"
|
||||
, " <h3>navigation</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Mainpage\" class='xowa-hover-off' title=\"\">mainpage-description</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
||||
private static final String Null_str = "";
|
||||
}
|
||||
class Xoh_sidebar_mgr_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoh_sidebar_mgr sidebar_mgr; private Bry_bfr bfr;
|
||||
public Xoh_sidebar_mgr_fxt Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
sidebar_mgr = wiki.Html_mgr().Portal_mgr().Sidebar_mgr();
|
||||
bfr = Bry_bfr_.Reset(Io_mgr.Len_kb);
|
||||
Init__popups_enabled(false);
|
||||
return this;
|
||||
}
|
||||
public Xowe_wiki Wiki() {return wiki;}
|
||||
public Xoh_sidebar_itm Make__grp(String text, String title, Xoh_sidebar_itm... itms) {
|
||||
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.N, Bry_.new_a7(text), Bry_.new_a7(text), null);
|
||||
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), null, null);
|
||||
return rv;
|
||||
}
|
||||
public Xoh_sidebar_itm Make__itm(String text, String title, String accesskey, String href) {
|
||||
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.Y, Bry_.new_a7(text), Bry_.new_a7(text), Bry_.new_a7(href));
|
||||
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), Bry_.new_a7(accesskey), null);
|
||||
return rv;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init__popups_enabled(boolean v) {
|
||||
wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled_(v);
|
||||
return this;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init__msg__grp(String key, String text, String title) {
|
||||
Init_msg(key, text);
|
||||
Init_msg("tooltip-n-" + key, title);
|
||||
return this;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init__msg__itm(String href_key, String main_key, String text, String title, String accesskey, String href) {
|
||||
if (text != null) Init_msg(main_key, text);
|
||||
if (href != null) Init_msg(href_key, href);
|
||||
if (title != null) Init_msg("tooltip-n-" + main_key, title);
|
||||
if (accesskey != null) Init_msg("accesskey-n-" + main_key, accesskey);
|
||||
return this;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init_msg(String key, String val) {
|
||||
Xol_msg_mgr msg_mgr = wiki.Lang().Msg_mgr();
|
||||
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(Bry_.new_a7(key));
|
||||
msg_itm.Atrs_set(Bry_.new_a7(val), false, String_.Has(val, "{{"));
|
||||
return this;
|
||||
}
|
||||
public void Exec__make(String... raw) {
|
||||
sidebar_mgr.Make(bfr, Bry_.new_u8(String_.Concat_lines_nl_skip_last(raw)));
|
||||
}
|
||||
public void Test__objs(Xoh_sidebar_itm... expd) {
|
||||
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
|
||||
}
|
||||
public void Test__objs(String raw, Xoh_sidebar_itm... expd) {
|
||||
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
|
||||
}
|
||||
public void Test__html(String... expd) {
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), String_.new_u8(sidebar_mgr.Html_bry()));
|
||||
}
|
||||
private static String To_str_by_mgr(Xoh_sidebar_mgr mgr) {
|
||||
List_adp grps = mgr.Grps();
|
||||
int len = grps.Len();
|
||||
Xoh_sidebar_itm[] ary = new Xoh_sidebar_itm[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
ary[i] = (Xoh_sidebar_itm)grps.Get_at(i);
|
||||
return To_str_by_itms(ary);
|
||||
}
|
||||
|
||||
private static String To_str_by_itms(Xoh_sidebar_itm[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
To_str_by_itm(bfr, ary[i]);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private static void To_str_by_itm(Bry_bfr bfr, Xoh_sidebar_itm cur) {
|
||||
boolean tid_is_itm = cur.Tid_is_itm();
|
||||
bfr.Add_str_a7(tid_is_itm ? "itm|" : "grp|");
|
||||
bfr.Add(cur.Text()).Add_byte_pipe();
|
||||
bfr.Add(cur.Title()).Add_byte_pipe();
|
||||
if (tid_is_itm) {
|
||||
bfr.Add(cur.Accesskey()).Add_byte_pipe();
|
||||
bfr.Add(cur.Href()).Add_byte_pipe();
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
|
||||
int len = cur.Subs__len();
|
||||
for (int i = 0; i< len; ++i)
|
||||
To_str_by_itm(bfr, cur.Subs__get_at(i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoh_toc_htmlr__basic__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_toc_htmlr__basic__fxt fxt = new Xoh_toc_htmlr__basic__fxt();
|
||||
@Test public void D1_S0_S0() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(2, "b");
|
||||
fxt.Init__add(2, "c");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void D1_D1_D1() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(3, "a_a");
|
||||
fxt.Init__add(4, "a_a_a");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void D1_D1_S0_U1() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(3, "a_a");
|
||||
fxt.Init__add(3, "a_b");
|
||||
fxt.Init__add(2, "b");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_b\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void D1_D1_U1_D1() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(3, "a_a");
|
||||
fxt.Init__add(2, "b");
|
||||
fxt.Init__add(3, "b_a");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#b_a\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void D1_D1_D1_U2() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(3, "a_a");
|
||||
fxt.Init__add(4, "a_a_a");
|
||||
fxt.Init__add(2, "b");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void D1_D2_U1_D1() {
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(4, "a_a_a_a");
|
||||
fxt.Init__add(3, "a_a_a");
|
||||
fxt.Init__add(4, "a_a_a_b");
|
||||
fxt.Test__html_itms
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a_a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a_a_a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_a_a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#a_a_a_b\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">a_a_a_b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
);
|
||||
}
|
||||
@Test public void Div() {
|
||||
fxt.Init__init_page("Table of contents", false);
|
||||
fxt.Init__add(2, "a");
|
||||
fxt.Init__add(2, "b");
|
||||
fxt.Init__add(2, "c");
|
||||
fxt.Test__html_div
|
||||
( "<div id=\"toc\" class=\"toc\">"
|
||||
, " <div id=\"toctitle\" class=\"toctitle\">"
|
||||
, " <h2>Table of contents</h2>"
|
||||
, " </div>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoh_toc_htmlr__basic__fxt {
|
||||
private final Xoh_toc_mgr wtr = new Xoh_toc_mgr();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Clear() {wtr.Clear();}
|
||||
public void Init__add(int hdr_num, String hdr_txt) {wtr.Add(hdr_num, Bry_.new_u8(hdr_txt));}
|
||||
public void Init__init_page(String toc_title, boolean page_banner) {wtr.Init(gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface_.Noop, Bry_.new_u8(toc_title), Bry_.Empty);}
|
||||
public void Test__html_itms(String... expd_ary) {
|
||||
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.Test__to_html())));
|
||||
}
|
||||
public void Test__html_div(String... expd_ary) {
|
||||
wtr.To_html(bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, false);
|
||||
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(bfr.To_bry_and_clear())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoh_toc_wkr__lvl__basic__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__lvl__fxt fxt = new Xoh_toc_wkr__lvl__fxt();
|
||||
@Test public void D1_S0_S0() {
|
||||
fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1)));
|
||||
fxt.Test__calc(2, fxt.Make(2, 1, Int_ary_.New(2)));
|
||||
fxt.Test__calc(2, fxt.Make(3, 1, Int_ary_.New(3)));
|
||||
}
|
||||
@Test public void D1_D1_D1() {
|
||||
fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1)));
|
||||
fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1)));
|
||||
fxt.Test__calc(4, fxt.Make(3, 3, Int_ary_.New(1, 1, 1)));
|
||||
}
|
||||
@Test public void D1_D1_S0_U1() {
|
||||
fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1)));
|
||||
fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1)));
|
||||
fxt.Test__calc(3, fxt.Make(3, 2, Int_ary_.New(1, 2)));
|
||||
fxt.Test__calc(2, fxt.Make(4, 1, Int_ary_.New(2)));
|
||||
}
|
||||
@Test public void D1_D1_U1_D1() {
|
||||
fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1)));
|
||||
fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1)));
|
||||
fxt.Test__calc(2, fxt.Make(3, 1, Int_ary_.New(2)));
|
||||
fxt.Test__calc(3, fxt.Make(4, 2, Int_ary_.New(2, 1)));
|
||||
}
|
||||
@Test public void D1_D1_D1_U2() {
|
||||
fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1)));
|
||||
fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1)));
|
||||
fxt.Test__calc(4, fxt.Make(3, 3, Int_ary_.New(1, 1, 1)));
|
||||
fxt.Test__calc(2, fxt.Make(4, 1, Int_ary_.New(2)));
|
||||
}
|
||||
}
|
||||
class Xoh_toc_wkr__lvl__fxt {
|
||||
private final Xoh_toc_wkr__lvl wkr = new Xoh_toc_wkr__lvl();
|
||||
private final Xoh_toc_itm actl = new Xoh_toc_itm();
|
||||
public void Clear() {wkr.Clear();}
|
||||
public Xoh_toc_itm Make(int uid, int lvl, int[] path) {
|
||||
Xoh_toc_itm rv = new Xoh_toc_itm();
|
||||
rv.Set__lvl(uid, lvl, path);
|
||||
return rv;
|
||||
}
|
||||
public void Test__calc(int lvl, Xoh_toc_itm expd) {
|
||||
wkr.Calc_level(actl, lvl);
|
||||
Gftest.Eq__int(expd.Uid(), actl.Uid(), "uid");
|
||||
Gftest.Eq__int(expd.Lvl(), actl.Lvl(), "lvl");
|
||||
Gftest.Eq__ary(expd.Path(), actl.Path(), "path");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.langs.htmls.*;
|
||||
public class Xoh_toc_wkr__txt__basic__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__both("a b c", "a_b_c", "a b c");
|
||||
}
|
||||
@Test public void Ws() {
|
||||
fxt.Test__both(" a b ", "a_b", "a b");
|
||||
}
|
||||
@Test public void Nl() {
|
||||
fxt.Test__both("\na b\n", "a_b", "a b");
|
||||
}
|
||||
@Test public void Empty() { // PAGE:s.w:Colac,_Victoria DATE:2016-07-17
|
||||
fxt.Test__both("", "", "");
|
||||
}
|
||||
@Test public void Amp__ncr() {
|
||||
fxt.Test__both("[a]", ".5Ba.5D", "[a]");
|
||||
}
|
||||
@Test public void Encode() {
|
||||
fxt.Test__both("a+b", "a.2Bb", "a+b");
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test__text("a<!--b-->c", "ac");
|
||||
}
|
||||
@Test public void Remove_comment__one() {
|
||||
fxt.Test__remove_comment("a<!--b-->c", "ac");
|
||||
}
|
||||
@Test public void Remove_comment__many() {
|
||||
fxt.Test__remove_comment("1<!--2-->3<!--4-->5", "135");
|
||||
}
|
||||
@Test public void Remove_comment__dangling() {
|
||||
fxt.Test__remove_comment("1<!--2-->3<!--4->5", "13");
|
||||
}
|
||||
}
|
||||
class Xoh_toc_wkr__txt__fxt {
|
||||
private final Xoh_toc_wkr__txt wkr = new Xoh_toc_wkr__txt();
|
||||
private final Xoh_toc_itm itm = new Xoh_toc_itm();
|
||||
private final Bry_bfr tmp = Bry_bfr_.New();
|
||||
private final Xow_tidy_mgr_interface__test tidy_mgr = new Xow_tidy_mgr_interface__test();
|
||||
public void Clear() {
|
||||
wkr.Clear();
|
||||
tidy_mgr.Clear();
|
||||
wkr.Init(tidy_mgr, Xoa_page_.Main_page_bry);
|
||||
}
|
||||
public void Init__tidy(String html, String tidy) {tidy_mgr.Add(Bry_.new_u8(html), Bry_.new_u8(tidy));}
|
||||
public void Test__anch(String html, String expd_anch) {Test__both(html, expd_anch, null);}
|
||||
public void Test__text(String html, String expd_text) {Test__both(html, null, expd_text);}
|
||||
public void Test__both(String html, String expd) {Test__both(html, expd, expd);}
|
||||
public void Test__both(String html, String expd_anch, String expd_text) {
|
||||
wkr.Calc_anch_text(itm, Bry_.new_u8(html));
|
||||
if (expd_anch != null) Gftest.Eq__str(expd_anch, itm.Anch(), "anch");
|
||||
if (expd_text != null) Gftest.Eq__str(expd_text, itm.Text(), "text");
|
||||
}
|
||||
public void Test__remove_comment(String html, String expd) {
|
||||
byte[] html_bry = Bry_.new_u8(html);
|
||||
Gftest.Eq__str(expd, Gfh_utl.Del_comments(tmp, html_bry, 0, html_bry.length));
|
||||
}
|
||||
}
|
||||
class Xow_tidy_mgr_interface__test implements gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(byte[] html, byte[] tidy) {hash.Add(html, tidy);}
|
||||
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {
|
||||
byte[] html = bfr.To_bry_and_clear();
|
||||
byte[] actl = (byte[])hash.Get_by_or_fail(html);
|
||||
bfr.Add(actl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoh_toc_wkr__txt__dupe__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__anch("a" , "a");
|
||||
fxt.Test__anch("a" , "a_2");
|
||||
}
|
||||
@Test public void Case_insensitive() {
|
||||
fxt.Test__anch("a" , "a");
|
||||
fxt.Test__anch("A" , "A_2");
|
||||
}
|
||||
@Test public void Autonumber_exists() { // PAGE:fr.w:Itanium; EX: Itanium,Itanium_2,Itanium
|
||||
fxt.Test__anch("a" , "a");
|
||||
fxt.Test__anch("a_2" , "a_2");
|
||||
fxt.Test__anch("a" , "a_3");
|
||||
}
|
||||
@Test public void Autonumber_exists_2() {
|
||||
fxt.Test__anch("a_2" , "a_2");
|
||||
fxt.Test__anch("a" , "a");
|
||||
fxt.Test__anch("a" , "a_3");
|
||||
fxt.Test__anch("a" , "a_4");
|
||||
fxt.Test__anch("a_2" , "a_2_2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoh_toc_wkr__txt__xnde__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
|
||||
@Test public void I() {fxt.Test__both("<i>a</i>" , "a", "<i>a</i>");}
|
||||
@Test public void I__id() {fxt.Test__both("<i id='1'>a</i>" , "a", "<i>a</i>");}
|
||||
@Test public void B() {fxt.Test__both("<b>a</b>" , "a", "<b>a</b>");}
|
||||
@Test public void Sup() {fxt.Test__both("<sup>a</sup>" , "a", "<sup>a</sup>");}
|
||||
@Test public void Sub() {fxt.Test__both("<sub>a</sub>" , "a", "<sub>a</sub>");}
|
||||
@Test public void Bdi() {fxt.Test__both("<bdi>a</bdi>" , "a", "<bdi>a</bdi>");}
|
||||
@Test public void Span() {fxt.Test__both("<span>a</span>" , "a", "a");}
|
||||
@Test public void Span__id() {fxt.Test__both("<span id='1'>a</span>" , "a", "a");}
|
||||
@Test public void Span__dir() {fxt.Test__both("<span dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
|
||||
@Test public void Span__dir_id() {fxt.Test__both("<span id='1' dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
|
||||
@Test public void Small() {fxt.Test__text("<small>a</small>" , "a");}
|
||||
@Test public void A() {fxt.Test__both("<a href=\"/wiki/A\">b</a>" , "b");}
|
||||
@Test public void A__nest() {fxt.Test__both("<a href=\"/wiki/A\">b<i>c</i>d</a>" , "bcd", "b<i>c</i>d");}
|
||||
@Test public void Br() {fxt.Test__both("a<br/>b" , "ab");}
|
||||
@Test public void Br__dangling() {fxt.Test__both("a<br>b" , "ab");}
|
||||
@Test public void Wbr__dangling() {fxt.Test__both("a<wbr>b" , "ab");}
|
||||
@Test public void H2() {fxt.Test__both("a<h2>b</h2>c" , "abc");} // NOTE: not a valid test; MW actually generates "ab" b/c of tidy; see corresponding edit test; DATE:2016-06-28
|
||||
@Test public void Li() {fxt.Test__text("a<ul><li>b</li></ul>c" , "abc");}
|
||||
@Test public void Table() {fxt.Test__text("a<table><tr><td>b</td></tr></table>c" , "abc");}
|
||||
@Test public void Unknown__i() {fxt.Test__both("a<unknown>b<i>c</i>d</unknown>e" , "abcde", "a<unknown>b<i>c</i>d</unknown>e");} // NOTE: technically, anch should be href_encoded a<unknown>b<i>c</i>d</unknown>e b/c <unknown> is not a valid tag; compare with known tags like <li> / <table> which are just stripped
|
||||
@Test public void Unknown__a() {fxt.Test__both("a<unknown>b<a>c</a>d</unknown>e" , "abcde", "a<unknown>bcd</unknown>e");}
|
||||
@Test public void Fail() {
|
||||
String html = "<i><a href='b'>c</i></a>";
|
||||
fxt.Init__tidy(html, "<i><a href='b'>c</a></i>");
|
||||
fxt.Test__both(html, "c", "<i>c</i>");
|
||||
}
|
||||
}
|
||||
547
400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr__tst.java
Normal file
547
400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr__tst.java
Normal file
@@ -0,0 +1,547 @@
|
||||
/*
|
||||
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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.hdrs.*;
|
||||
public class Xowe_hdr_bldr__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xowe_hdr_bldr_fxt fxt = new Xowe_hdr_bldr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "==b=="
|
||||
, "==c=="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Hier_down() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "====c===="
|
||||
, "=====d====="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-4 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.1.1.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Hier_up() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "===c==="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Down_up() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "==c=="
|
||||
, "===d==="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void D1_D1_D1_U2() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "===b==="
|
||||
, "====c===="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Err() { // PURPOSE: models strange case wherein jumping down does not work
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "====b===="
|
||||
, "===c==="
|
||||
, "====d===="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Repeat_name() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, "==a=="
|
||||
, "==a=="
|
||||
, "==a=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#a_2\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#a_3\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#a_4\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Id__encode() {
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a+b=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.2Bb\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a+b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Ws() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "== a b =="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a_b'> a b </span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Apos_italic() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==''a''=="
|
||||
)
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Xnde__italic() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<i>a</i>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Xnde__small() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>a</small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><small>a</small></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Xnde__li() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<ul><li>b</li></ul>c=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='abc'>a<ul><li>b</li></ul>c</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Xnde__table() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<table><tr><td>b</td></tr></table>c=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='abc'>a<table><tr><td>b</td></tr></table>c</span></h2>"
|
||||
));
|
||||
}
|
||||
// TOMBSTONE: on MW, shows up as 'href="#ab"; <span class="toctext">ab</span>; '; TIDY doing strange things; ignore for now; DATE:2016-06-28
|
||||
//@Test public void Xnde__h2() {
|
||||
// fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
// ( "__FORCETOC__"
|
||||
// , "==a<h2>b</h2>c=="
|
||||
// )
|
||||
// , String_.Concat_lines_nl
|
||||
// ( fxt.toc_tbl_nl_n
|
||||
// ( " <ul>"
|
||||
// , " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
|
||||
// , " </li>"
|
||||
// , " </ul>"
|
||||
// )
|
||||
// , "<h2><span class='mw-headline' id='abc'>a<h2>b</h2>c</span></h2>"
|
||||
// ));
|
||||
//}
|
||||
@Test public void Xnde__dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>a<small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><small>a<small></small></small></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Nest__xnde__small() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a <sup>b<small>c</small>d</sup> e=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_bcd_e\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a <sup>bcd</sup> e</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a_bcd_e'>a <sup>b<small>c</small>d</sup> e</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Nest__lnki() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<small>[[a|b]]</small>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='b'><small><a href=\"/wiki/A\">b</a></small></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Nest__br() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<span id=\"b\">b<br/></span>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ab\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ab</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='ab'>a<span id='b'>b<br/></span></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_link() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a'><a href=\"/wiki/A\">a</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_caption() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a|b]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/A\">b</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_caption_nest() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[a|b<i>c</i>d]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#bcd\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b<i>c</i>d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='bcd'><a href=\"/wiki/A\">b<i>c</i>d</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Html_ncr() {
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[a]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5Ba.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">[a]</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='.5Ba.5D'>[a]</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Fix_large_before_small() { // PURPOSE.fix: "===a===\n===b===\n" followed by "==c==" causes improper formatting; DATE:2013-05-16
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "===a==="
|
||||
, "===b==="
|
||||
, "==c=="
|
||||
, "==d=="
|
||||
), fxt.toc_tbl_nl_y // NOTE: should all be level 2
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Fix_large_before_small_2() { // PURPOSE.fix: similar to above, but has h3 after h2; PAGE:https://en.wikipedia.org/wiki/Wikipedia:Articles_for_creation/2006-08-27 DATE:2014-06-09
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "===a_0==="
|
||||
, "==b_0=="
|
||||
, "===b_1==="
|
||||
, "==c_0=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_0\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a_0</span></a>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b_0\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b_0</span></a>"
|
||||
, " <ul>"
|
||||
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#b_1\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_1</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#c_0\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c_0</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Translate_and_comment() { // PURPOSE: <translate> is an xtn and parses its innerText separately; meanwhile, toc_mgr defaults to using the innerText to build toc; EX:Wikidata:Introduction; DATE:2013-07-16
|
||||
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==<translate><!--b-->ac</translate>=="
|
||||
), fxt.toc_tbl_nl_y
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ac\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
));
|
||||
}
|
||||
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a<ref>b</ref>=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.5B1.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a<sup>[1]</sup></span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='a.5B1.5D'>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Category() { // PURPOSE: Category should not show in in TOC; DATE:2013-12-09
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==A[[Category:B]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#A\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">A</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Category_literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==A[[:Category:B]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ACategory:B\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ACategory:B</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='ACategory:B'>A<a href=\"/wiki/Category:B\">Category:B</a></span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[File:A.png]] b=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnki_invalid() { // PURPOSE: invalid lnki was causing null ref; DATE:2014-02-07
|
||||
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==[[]]=="
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( fxt.toc_tbl_nl_n
|
||||
( " <ul>"
|
||||
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5B.5B.5D.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">[[]]</span></a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
)
|
||||
, "<h2><span class='mw-headline' id='.5B.5B.5D.5D'>[[]]</span></h2>"
|
||||
));
|
||||
}
|
||||
@Test public void File_in_tbl() { // PURPOSE: two issues (a) don't show file if in tbl; (b) if v2, file inside tbl fails; PAGE:en.w:Holmes County,_Mississippi; DATE:2014-06-22
|
||||
fxt.Test_html_frag(String_.Concat_lines_nl_skip_last
|
||||
( "__FORCETOC__"
|
||||
, "==a <table><tr><td>[[File:A.png]]b</td></tr></table> c=="
|
||||
)
|
||||
, "<span class=\"toctext\">a b c</span>" // note that "b" inside tbl shows
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xowe_hdr_bldr_fxt {
|
||||
private final Bry_bfr tmp = Bry_bfr_.New();
|
||||
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
|
||||
public void Clear() {
|
||||
fxt.Reset();
|
||||
tmp.Clear();
|
||||
}
|
||||
public void Test_html_toc(String raw, String expd) {
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
|
||||
String actl = Bld_page_with_toc(tmp, fxt, raw);
|
||||
|
||||
// HACK: proc only tests TOC; remove <h#><span class="mw-> section; ugly hack, but this is only test code
|
||||
int span_pos = String_.FindFwd(actl, "<span class=\"mw-");
|
||||
actl = String_.Mid(actl, 0, span_pos - 5);
|
||||
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.N);
|
||||
}
|
||||
public void Test_html_all(String raw, String expd) {
|
||||
expd = Xoh_consts.Escape_apos(expd);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
|
||||
String actl = Bld_page_with_toc(tmp, fxt, raw);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.N);
|
||||
}
|
||||
public void Test_html_frag(String raw, String frag) {
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
|
||||
String actl = Bld_page_with_toc(tmp, fxt, raw);
|
||||
fxt.Test_str_part_y(actl, frag);
|
||||
fxt.Wtr_cfg().Toc__show_(Bool_.N);
|
||||
}
|
||||
public String toc_tbl_nl_y(String... ary) {return toc_tbl(Bool_.Y, ary);}
|
||||
public String toc_tbl_nl_n(String... ary) {return toc_tbl(Bool_.N, ary);}
|
||||
public String toc_tbl(boolean nl, String... ary) {
|
||||
return String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"toc\" class=\"toc\">"
|
||||
, " <div id=\"toctitle\" class=\"toctitle\">"
|
||||
, " <h2>Contents</h2>"
|
||||
, " </div>"
|
||||
, String_.Concat_lines_nl_skip_last(ary)
|
||||
, "</div>" + (nl ? "\n" : "")
|
||||
);
|
||||
}
|
||||
public static String Bld_page_with_toc(Bry_bfr bfr, Xop_fxt fxt, String raw) {
|
||||
gplx.xowa.parsers.Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
fxt.Ctx().Page_data().Copy_to(fxt.Page());
|
||||
fxt.Wiki().Html_mgr().Html_wtr().Write_doc(bfr, fxt.Ctx(), fxt.Hctx(), root.Root_src(), root);
|
||||
|
||||
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(bfr, fxt.Page(), Xoh_wtr_ctx.Basic);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.parsers.mediawikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.parsers.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xop_mediawiki_wkr__tst {
|
||||
private final Xop_mediawiki_wkr__fxt fxt = new Xop_mediawiki_wkr__fxt();
|
||||
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__wkr("en.wikipedia.org", null);
|
||||
fxt.Test__parse("Page_1", "''{{PAGENAME}}''"
|
||||
, "<p><i>Page 1</i>"
|
||||
, "</p>"
|
||||
);
|
||||
}
|
||||
@Test public void Template() {
|
||||
fxt.Init__wkr("en.wikipedia.org", new Xop_mediawiki_loader__mock());
|
||||
fxt.Test__parse("Page_1", "{{bold}}"
|
||||
, "<p><b>bold</b>"
|
||||
, "</p>"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xop_mediawiki_wkr__fxt {
|
||||
private final Xop_mediawiki_mgr mgr = new Xop_mediawiki_mgr("mem/xowa/wiki/en.wikipedia.org/", false);
|
||||
private Xop_mediawiki_wkr wkr;
|
||||
public Xop_mediawiki_wkr__fxt() {
|
||||
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public void Init__wkr(String wiki, Xop_mediawiki_loader cbk) {
|
||||
this.wkr = mgr.Make(wiki, cbk);
|
||||
}
|
||||
public void Test__parse(String page, String wtxt, String... expd) {
|
||||
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), wkr.Parse(page, wtxt), "parse failed; wtxt={0}", wtxt);
|
||||
}
|
||||
}
|
||||
class Xop_mediawiki_loader__mock implements Xop_mediawiki_loader {
|
||||
public String LoadWikitext(String page) {
|
||||
if (String_.Eq(page, "Template:Bold")) return "'''bold'''";
|
||||
else return "text";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
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"1\">A"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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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)"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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;}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.fulltexts.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xofulltext_extractor__tst {
|
||||
private final Xofulltext_extractor__fxt fxt = new Xofulltext_extractor__fxt();
|
||||
@Test public void Basic() {
|
||||
// simple node
|
||||
fxt.Test__extract("a <i>b</i> c", "a b c");
|
||||
|
||||
// node with attributes
|
||||
fxt.Test__extract("a <a href='b.html' caption='c d e'>f</a> g", "a f g");
|
||||
|
||||
// nested nodes
|
||||
fxt.Test__extract("a <b>b <i>c</i> d</b> e", "a b c d e");
|
||||
|
||||
// periods
|
||||
fxt.Test__extract("a <b>b</b>. c d", "a b. c d");
|
||||
|
||||
// parens
|
||||
fxt.Test__extract("(a <b>b</b>)", "(a b)");
|
||||
|
||||
// parens
|
||||
fxt.Test__extract("<b>a</b> (b)", "a (b)");
|
||||
}
|
||||
}
|
||||
class Xofulltext_extractor__fxt {
|
||||
private final Xofulltext_extractor extractor = new Xofulltext_extractor();
|
||||
public void Test__extract(String src, String expd) {
|
||||
Gftest.Eq__str(expd, extractor.Extract(Bry_.new_u8(src)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
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.fulltexts.searchers.mgrs.brutes.finders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*; import gplx.xowa.addons.wikis.fulltexts.searchers.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xofulltext_finder_cbk__eval__tst {
|
||||
private final Xofulltext_finder_cbk__eval__fxt fxt = new Xofulltext_finder_cbk__eval__fxt();
|
||||
@Test public void Exact() {
|
||||
fxt.Init__search("a");
|
||||
// y: basic match
|
||||
fxt.Test__eval_y("a");
|
||||
// n: no match
|
||||
fxt.Test__eval_n("z");
|
||||
// n: wildcard_bgn not enabled
|
||||
fxt.Test__eval_n("az");
|
||||
}
|
||||
@Test public void Or() {
|
||||
fxt.Init__search("a, c");
|
||||
// y: lone char
|
||||
fxt.Test__eval_y("a" , "c");
|
||||
// y: one char
|
||||
fxt.Test__eval_y("a b", "b c");
|
||||
// y: both chars
|
||||
fxt.Test__eval_y("a c", "a b c");
|
||||
// n: no chars
|
||||
fxt.Test__eval_n("b");
|
||||
}
|
||||
@Test public void And() {
|
||||
fxt.Init__search("a + c");
|
||||
// y: both chars
|
||||
fxt.Test__eval_y("a c", "a b c");
|
||||
// n: one char only
|
||||
fxt.Test__eval_n("a", "c", "a b", "b c");
|
||||
}
|
||||
@Test public void And__shorthand() {
|
||||
fxt.Init__search("a c");
|
||||
// y: both chars
|
||||
fxt.Test__eval_y("a b c");
|
||||
// n: one char only
|
||||
fxt.Test__eval_n("a", "c");
|
||||
}
|
||||
@Test public void Not() {
|
||||
fxt.Init__search("-a");
|
||||
// y: no chars
|
||||
fxt.Test__eval_y("b");
|
||||
// n: char exists
|
||||
fxt.Test__eval_n("a");
|
||||
}
|
||||
@Test public void Trim_end() {
|
||||
fxt.Init__search("a");
|
||||
// y: single
|
||||
fxt.Test__eval_y("a!");
|
||||
// y: many
|
||||
fxt.Test__eval_y("a!!!");
|
||||
}
|
||||
@Test public void Trim_bgn() {
|
||||
fxt.Init__search("a");
|
||||
// y: single
|
||||
fxt.Test__eval_y("!a");
|
||||
// y: many
|
||||
fxt.Test__eval_y("!!!a");
|
||||
}
|
||||
@Test public void Trim_both() {
|
||||
fxt.Init__search("a");
|
||||
// y: single
|
||||
fxt.Test__eval_y("'a'");
|
||||
// y: many
|
||||
fxt.Test__eval_y("'''a'''");
|
||||
}
|
||||
@Test public void Slash() {
|
||||
fxt.Init__search("a");
|
||||
// y: slash before, after
|
||||
fxt.Test__eval_y("a/b/c", "b/a/c", "b/c/a");
|
||||
}
|
||||
@Test public void Brack() {
|
||||
fxt.Init__search("a");
|
||||
// y
|
||||
fxt.Test__eval_y("[[a]]");
|
||||
}
|
||||
// .
|
||||
// ...
|
||||
// -
|
||||
// a'b
|
||||
// https://site/page
|
||||
// ()
|
||||
// []
|
||||
// <>
|
||||
}
|
||||
class Xofulltext_finder_cbk__eval__fxt {
|
||||
private boolean case_match = false;
|
||||
private boolean auto_wildcard_bgn = false;
|
||||
private boolean auto_wildcard_end = false;
|
||||
private byte wildcard_byte = Byte_ascii.Star;
|
||||
private byte not_byte = Byte_ascii.Dash;
|
||||
private final Xofulltext_finder_mgr finder = new Xofulltext_finder_mgr();
|
||||
private final Xofulltext_finder_cbk__eval cbk = new Xofulltext_finder_cbk__eval();
|
||||
public void Init__search(String query) {
|
||||
finder.Init(Bry_.new_u8(query), case_match, auto_wildcard_bgn, auto_wildcard_end, wildcard_byte, not_byte);
|
||||
}
|
||||
public void Test__eval_y(String... texts) {Test__eval(Bool_.Y, texts);}
|
||||
public void Test__eval_n(String... texts) {Test__eval(Bool_.N, texts);}
|
||||
public void Test__eval(boolean expd, String... texts) {
|
||||
for (String text : texts) {
|
||||
byte[] text_bry = Bry_.new_u8(text);
|
||||
cbk.found = false;
|
||||
finder.Match(text_bry, 0, text_bry.length, cbk);
|
||||
Gftest.Eq__bool(expd, cbk.found, "query={0} text={1}", finder.Query(), text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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>"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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&action=edit&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());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
Tfds.Eq(expd, String_.new_u8(visitor__to_str.Print(crt_mgr.Root)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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;}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
Tfds.Eq(expd, String_.new_u8(Srch_page_tbl_wkr.To_bry_or_null(tmp_bfr, Srch_search_addon.Wildcard__star, crt_mgr)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
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|<]]"
|
||||
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|>]]"
|
||||
// , "|-"
|
||||
// , "| [[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|<]]"
|
||||
// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|>]]"
|
||||
// , "|}"
|
||||
// ));
|
||||
// }
|
||||
//// @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);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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, " ");
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.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();
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java
Normal file
40
400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
public class Xoa_app_eval_tst {
|
||||
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]");
|
||||
}
|
||||
}
|
||||
class Xoa_app_eval_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
fmtr = Bry_fmtr.new_();
|
||||
eval = new Xoa_app_eval();
|
||||
fmtr.Eval_mgr_(eval);
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
}
|
||||
} private Xoae_app app; Bry_fmtr fmtr; Xoa_app_eval eval;
|
||||
public void Eval_test(String raw, String expd) {
|
||||
Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd);
|
||||
}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java
Normal file
28
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.xowa.apps.gfs.*;
|
||||
public class Xoa_shell_tst {
|
||||
@Test public void Fetch_page() { // PURPOSE.fix: fetch_page failed with nullRef; DATE:2013-04-12
|
||||
Xop_fxt parser_fxt = new Xop_fxt();
|
||||
Xoae_app app = parser_fxt.App(); Xowe_wiki wiki = parser_fxt.Wiki();
|
||||
parser_fxt.Init_page_create("A", "test"); // need to create page in order for html output to gen
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); // need to set html_capable in order for div_home to load
|
||||
Xoa_gfs_mgr.Msg_parser_init();
|
||||
wiki.Html_mgr().Portal_mgr().Div_home_fmtr().Fmt_("~{<>app.user.msgs.get('mainpage-description');<>}");
|
||||
app.Gfs_mgr().Run_str("app.shell.fetch_page('en.wikipedia.org/wiki/A' 'html');"); // this causes a nullRef error b/c app.user.lang is null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.apps.apis.xowa.addons.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xopg_match_mgr__tst {
|
||||
private final Xopg_match_mgr__fxt fxt = new Xopg_match_mgr__fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Specific() {
|
||||
fxt.Init__set("en.w:A");
|
||||
fxt.Test__match_y("A");
|
||||
fxt.Test__match_n("AB");
|
||||
}
|
||||
@Test public void Other_wiki() {
|
||||
fxt.Init__set("fr.w:A");
|
||||
fxt.Test__match_n("A"); // note that test defaults to "en.w" as primary wiki
|
||||
}
|
||||
@Test public void Wildcard__app() {
|
||||
fxt.Init__set("*");
|
||||
fxt.Test__match_y("A", "B");
|
||||
}
|
||||
@Test public void Wildcard__page() {
|
||||
fxt.Init__set("en.w:*");
|
||||
fxt.Test__match_y("A", "B");
|
||||
}
|
||||
@Test public void Wildcard__page__other() {
|
||||
fxt.Init__set("fr.w:*");
|
||||
fxt.Test__match_n("A", "B");
|
||||
}
|
||||
@Test public void Wildcard__wiki() {
|
||||
fxt.Init__set("*:A");
|
||||
fxt.Test__match_y("A");
|
||||
fxt.Test__match_n("B");
|
||||
}
|
||||
}
|
||||
class Xopg_match_mgr__fxt {
|
||||
private final Xopg_match_mgr match_mgr = new Xopg_match_mgr();
|
||||
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);
|
||||
app.User().Wikii().Xwiki_mgr().Add_by_atrs(wiki.Domain_bry(), wiki.Domain_bry());
|
||||
}
|
||||
public void Init__set(String url) {
|
||||
match_mgr.Set(url);
|
||||
}
|
||||
public void Test__match_y(String... urls) {Test__match(Bool_.Y, urls);}
|
||||
public void Test__match_n(String... urls) {Test__match(Bool_.N, urls);}
|
||||
private void Test__match(boolean expd, String... urls) {
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
String url = urls[i];
|
||||
boolean actl = match_mgr.Match(wiki, Bry_.new_u8(url));
|
||||
Gftest.Eq__bool(expd, actl, "match failed", "expd", expd, "url", url);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java
Normal file
70
400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xowc_xtn_pages_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xowc_xtn_pages_fxt fxt = new Xowc_xtn_pages_fxt();
|
||||
@Test public void Init() {
|
||||
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
|
||||
fxt.Init_names("Foreign_page", "Foreign_page_talk", "Foreign_index", "Foreign_index_talk"); // ns set by .gfs files in /user/wiki/#cfg
|
||||
fxt.Exec_init();
|
||||
fxt.Test_ns_ids(200, 201, 202, 203);
|
||||
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
|
||||
}
|
||||
@Test public void Spaces() { // PURPOSE: ensure underlines, not space; EX:"Mục_lục" not "Mục lục"; PAGE:vi.s:Việt_Nam_sử_lược/Quyển_II DATE:2015-10-27
|
||||
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
|
||||
fxt.Init_names("Foreign page", "Foreign page talk", "Foreign index", "Foreign index talk"); // ns set by .gfs files in /user/wiki/#cfg
|
||||
fxt.Exec_init();
|
||||
fxt.Test_ns_ids(200, 201, 202, 203);
|
||||
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
|
||||
}
|
||||
}
|
||||
class Xowc_xtn_pages_fxt {
|
||||
private Xow_ns_mgr ns_mgr;
|
||||
private Xowc_xtn_pages cfg_pages;
|
||||
public void Clear() {
|
||||
ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
cfg_pages = new Xowc_xtn_pages();
|
||||
}
|
||||
public Xowc_xtn_pages_fxt Init_ns(int id, String name) {
|
||||
ns_mgr.Add_new(id, name);
|
||||
return this;
|
||||
}
|
||||
public void Init_names(String page_name, String page_talk_name, String index_name, String index_talk_name) {
|
||||
cfg_pages.Ns_names_(Bry_.new_a7(page_name), Bry_.new_a7(page_talk_name), Bry_.new_a7(index_name), Bry_.new_a7(index_talk_name));
|
||||
}
|
||||
public void Exec_init() {
|
||||
ns_mgr.Init_w_defaults(); // init ns_msg
|
||||
cfg_pages.Init(ns_mgr); // init cfg
|
||||
}
|
||||
public void Test_ns_ids(int page_id, int page_talk_id, int index_id, int index_talk_id) {
|
||||
Tfds.Eq(page_id , cfg_pages.Ns_page_id());
|
||||
Tfds.Eq(page_talk_id , cfg_pages.Ns_page_talk_id());
|
||||
Tfds.Eq(index_id , cfg_pages.Ns_index_id());
|
||||
Tfds.Eq(index_talk_id , cfg_pages.Ns_index_talk_id());
|
||||
}
|
||||
public void Test_ns_canonical(String page_name, String page_talk_name, String index_name, String index_talk_name) {
|
||||
Test_ns_canonical_itm(page_name , cfg_pages.Ns_page_id());
|
||||
Test_ns_canonical_itm(page_talk_name , cfg_pages.Ns_page_talk_id());
|
||||
Test_ns_canonical_itm(index_name , cfg_pages.Ns_index_id());
|
||||
Test_ns_canonical_itm(index_talk_name , cfg_pages.Ns_index_talk_id());
|
||||
}
|
||||
private void Test_ns_canonical_itm(String name, int expd_ns_id) {
|
||||
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_a7(name));
|
||||
int actl_ns_id = ns == null ? Int_.Min_value : ns.Id();
|
||||
Tfds.Eq(expd_ns_id, actl_ns_id);
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java
Normal file
40
400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.langs.gfs.*;
|
||||
public class Xoa_fmtr_itm_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_fmtr_itm_fxt fxt = new Xoa_fmtr_itm_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init_src("app.wikis;");
|
||||
fxt.Init_fmt("domain=~{<>domain;<>};");
|
||||
fxt.Test_run("domain=en.wikipedia.org;");
|
||||
}
|
||||
}
|
||||
class Xoa_fmtr_itm_fxt {
|
||||
private Xoae_app app; private Xoa_fmtr_itm itm;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
Xoa_app_fxt.Make__wiki__edit(app); // create enwiki
|
||||
itm = new Xoa_fmtr_itm(app);
|
||||
GfsCore.Instance.MsgParser_(gplx.langs.gfs.Gfs_msg_bldr.Instance);
|
||||
}
|
||||
public Xoa_fmtr_itm_fxt Init_src(String v) {itm.Src_(v); return this;}
|
||||
public Xoa_fmtr_itm_fxt Init_fmt(String v) {itm.Fmt_(Bry_.new_a7(v)); return this;}
|
||||
public void Test_run(String expd) {
|
||||
String actl = itm.Run();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
64
400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java
Normal file
64
400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.users.*;
|
||||
public class Xoa_url_finder_tst {
|
||||
private final Xoa_url_finder_fxt fxt = new Xoa_url_finder_fxt();
|
||||
@Test public void Find_by_css_or_null() {
|
||||
// init
|
||||
String wiki = "en.wikipedia.org";
|
||||
String file = "logo_night.png";
|
||||
String[] subs = String_.Ary("bin", "any", "xowa", "html", "css", "nightmode");
|
||||
String expd = null;
|
||||
|
||||
// null case
|
||||
expd = null;
|
||||
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
|
||||
|
||||
// app_bin
|
||||
expd = "mem/xowa/bin/any/xowa/html/css/nightmode/logo_night.png";
|
||||
fxt.Init__Fsys__save(expd);
|
||||
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
|
||||
|
||||
// usr_bin
|
||||
expd = "mem/xowa/user/anonymous/app/overrides/bin/any/xowa/html/css/nightmode/logo_night.png";
|
||||
fxt.Init__Fsys__save(expd);
|
||||
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
|
||||
|
||||
// wiki_css
|
||||
expd = "mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo_night.png";
|
||||
fxt.Init__Fsys__save(expd);
|
||||
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
|
||||
}
|
||||
}
|
||||
class Xoa_url_finder_fxt {
|
||||
private final Xoa_url_finder finder;
|
||||
public Xoa_url_finder_fxt() {
|
||||
Io_url root_dir = Io_url_.mem_dir_("mem/xowa/");
|
||||
Xoa_fsys_mgr app_fsys_mgr = Xoa_fsys_mgr.New_by_plat("lnx", root_dir);
|
||||
Xou_fsys_mgr usr_fsys_mgr = new Xou_fsys_mgr(root_dir.GenSubDir_nest("user", "anonymous"));
|
||||
this.finder = new Xoa_url_finder(app_fsys_mgr);
|
||||
finder.Init_by_user(usr_fsys_mgr);
|
||||
}
|
||||
public void Init__Fsys__save(String url) {
|
||||
Io_mgr.Instance.SaveFilStr(url, "");
|
||||
}
|
||||
public void Test__Find_by_css_or_null(String expd, String wiki, String file, String[] dir_parts) {
|
||||
Io_url actl = finder.Find_by_css_or(wiki, file, dir_parts, false);
|
||||
Gftest.Eq__str(expd, actl == null ? null : actl.Raw());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_php_converter__to_gfs__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
|
||||
@Test public void Escape_sequences() {
|
||||
fxt.Test__to_gfs("a\\\"b" , "a\"b");
|
||||
fxt.Test__to_gfs("a\\'b" , "a'b");
|
||||
fxt.Test__to_gfs("a\\$b" , "a$b");
|
||||
fxt.Test__to_gfs("a\\\\b" , "a\\b");
|
||||
fxt.Test__to_gfs("a\\nb" , "a\nb");
|
||||
fxt.Test__to_gfs("a\\tb" , "a\tb");
|
||||
fxt.Test__to_gfs("a\\rb" , "a\rb");
|
||||
fxt.Test__to_gfs("a\\ b" , "a\\ b"); // "\ " seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
|
||||
fxt.Test__to_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
|
||||
fxt.Test__to_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
|
||||
}
|
||||
@Test public void Tilde() {
|
||||
fxt.Test__to_gfs("a~b" , "a~~b"); // tilde.escape
|
||||
}
|
||||
@Test public void Arguments() {
|
||||
fxt.Test__to_gfs("a$1b" , "a~{0}b"); // dollar
|
||||
fxt.Test__to_gfs("a $ b" , "a $ b"); // noop
|
||||
}
|
||||
}
|
||||
class Gfs_php_converter_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Clear() {}
|
||||
public void Test__to_gfs(String raw, String expd) {
|
||||
byte[] actl = Gfs_php_converter.To_gfs(bfr, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
|
||||
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
|
||||
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
|
||||
byte[] actl = Gfs_php_converter.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_php_converter__to_php__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
|
||||
@Test public void Xto_php() {
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many
|
||||
fxt.Test_Xto_php_escape_y("a~{9}" , "a$10"); // tilde.arg.9 -> 10
|
||||
fxt.Test_Xto_php_escape_y("a~~b" , "a~b"); // tilde.escape
|
||||
fxt.Test_Xto_php_escape_y("a\\b'c\"d$e" , "a\\\\b\\'c\\\"d\\$e"); // backslash.escape_y
|
||||
fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
|
||||
import org.junit.*;
|
||||
public class Http_server_wkr__tst {
|
||||
@Before public void init() {fxt.Clear();} private Http_server_wkr__fxt fxt = new Http_server_wkr__fxt();
|
||||
@Test public void Assert_main_page() {
|
||||
fxt.Init_wiki_main_page("fr.wikiversity.org", "Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/A" , "/fr.wikiversity.org/wiki/A");
|
||||
}
|
||||
}
|
||||
class Http_server_wkr__fxt {
|
||||
private Xoae_app app;
|
||||
public void Clear() {
|
||||
this.app = Xoa_app_fxt.Make__app__edit();
|
||||
}
|
||||
public void Init_wiki_main_page(String domain, String main_page) {
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(Bry_.new_u8(domain));
|
||||
wiki.Props().Main_page_(Bry_.new_u8(main_page));
|
||||
}
|
||||
public void Test_assert_main_page(String url, String expd) {
|
||||
Tfds.Eq(expd, Http_server_wkr_.Assert_main_page(app, url));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Xosrv_msg_rdr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xosrv_msg_rdr_fxt fxt = new Xosrv_msg_rdr_fxt();
|
||||
@Test public void Parse() {
|
||||
String raw = "0|0000000045|0000000091|cmd_0|id_0|sender_0|recipient_0|date_0|text_0";
|
||||
Xosrv_msg msg = fxt.Test_parse_msg(raw, "cmd_0", "id_0", "sender_0", "recipient_0", "date_0", "text_0");
|
||||
fxt.Test_print(msg, raw);
|
||||
}
|
||||
@Test public void Err_header_is_invalid() {fxt.Test_parse_err("abcde", "header is invalid");}
|
||||
@Test public void Err_checksum_failed() {fxt.Test_parse_err("0|0000000000|0000000000|", "checksum failed");}
|
||||
@Test public void Err_cmd_missing() {fxt.Test_parse_err("0|0000000001|0000000003|a", "pipe not found for cmd_name");}
|
||||
}
|
||||
class Xosrv_msg_rdr_fxt {
|
||||
public Xosrv_msg_rdr_fxt Clear() {
|
||||
if (msg_rdr == null) {
|
||||
msg_rdr_stream = new IoStream_mock();
|
||||
msg_rdr = new Xosrv_msg_rdr(Bry_.Empty, msg_rdr_stream);
|
||||
}
|
||||
msg_rdr_stream.Reset();
|
||||
return this;
|
||||
} private Xosrv_msg_rdr msg_rdr; private IoStream_mock msg_rdr_stream;
|
||||
public Xosrv_msg Test_parse_msg(String raw, String expd_cmd, String expd_id, String expd_sender, String expd_recipient, String expd_date, String expd_text) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length);
|
||||
Xosrv_msg msg = msg_rdr.Read();
|
||||
Tfds.Eq(String_.new_a7(msg.Cmd_name()) , expd_cmd);
|
||||
Tfds.Eq(String_.new_a7(msg.Msg_id()) , expd_id);
|
||||
Tfds.Eq(String_.new_a7(msg.Sender()) , expd_sender);
|
||||
Tfds.Eq(String_.new_a7(msg.Recipient()) , expd_recipient);
|
||||
Tfds.Eq(String_.new_a7(msg.Msg_date()) , expd_date);
|
||||
Tfds.Eq(String_.new_a7(msg.Msg_text()) , expd_text);
|
||||
return msg;
|
||||
}
|
||||
public void Test_parse_err(String raw, String expd_err) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length);
|
||||
Xosrv_msg msg = msg_rdr.Read();
|
||||
String msg_text = String_.new_a7(msg.Msg_text());
|
||||
Tfds.Eq_true(String_.Has_at_bgn(msg_text, expd_err), msg_text);
|
||||
}
|
||||
public void Test_print(Xosrv_msg msg, String expd) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
msg.Print(bfr);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*;
|
||||
public class Xosrv_server_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xosrv_server_fxt fxt = new Xosrv_server_fxt();
|
||||
@Test public void Exec_js() {
|
||||
fxt.Test_exec_js("{\"args\":[\"xowa_exec_test\",\"a\",\"b\"]}", "{\"xowa_js_result\":\"xowa_exec_test|a|b\"}");
|
||||
}
|
||||
@Test public void Exec_js_ary() {
|
||||
fxt.Test_exec_js("{\"args\":[\"xowa_exec_test_as_array\",\"a\",\"b\"]}", "{\"xowa_js_result\":[\"xowa_exec_test_as_array\",\"a\",\"b\"]}");
|
||||
}
|
||||
}
|
||||
class Xosrv_server_fxt {
|
||||
public Xosrv_server_fxt Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
Xoa_app_fxt.Init_gui(app, null); // NOTE: null wiki does not matter for test
|
||||
return this;
|
||||
} private Xoae_app app;
|
||||
public void Test_exec_js(String raw, String expd) {
|
||||
String actl = app.Tcp_server().Exec_js(null, Bry_.new_a7(raw));
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java
Normal file
34
400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_setup_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_setup_mgr_fxt fxt = new Xoa_setup_mgr_fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test_delete_old_dir("mem/dir/", "1.8.1.1" , "1.8.2.1", Bool_.Y); // version is earlier than checkpoint; delete
|
||||
fxt.Test_delete_old_dir("mem/dir/", "1.8.2.1" , "1.8.2.1", Bool_.N); // version is not earlier than checkpoint; don't delete
|
||||
fxt.Test_delete_old_dir("mem/dir/", "" , "1.8.2.1", Bool_.Y); // version is empty; delete;
|
||||
}
|
||||
}
|
||||
class Xoa_setup_mgr_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_delete_old_dir(String dir_str, String version_prv, String version_del, boolean expd) {
|
||||
Io_url dir = Io_url_.new_fil_(dir_str);
|
||||
Io_mgr.Instance.CreateDirIfAbsent(dir);
|
||||
Xoa_setup_mgr.Delete_old_dir(Gfo_usr_dlg_.Noop, version_prv, version_del, dir);
|
||||
Tfds.Eq(expd, !Io_mgr.Instance.ExistsDir(dir), version_prv + "|" + version_del);
|
||||
}
|
||||
}
|
||||
178
400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java
Normal file
178
400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
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.apps.site_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.dbs.cfgs.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.bldrs.wms.*;
|
||||
public class Xoa_site_cfg_mgr_tst {
|
||||
private final Xoa_site_cfg_mgr_fxt fxt = new Xoa_site_cfg_mgr_fxt();
|
||||
@Before public void init() {fxt.Init();}
|
||||
@After public void term() {fxt.Term();}
|
||||
@Test public void Extensiontags__cfg() {
|
||||
fxt.Init_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 1, "math", "source"));
|
||||
fxt.Exec_load();
|
||||
fxt.Test_extensiontags_y("math" , "source");
|
||||
fxt.Test_extensiontags_n("ref" , "graph");
|
||||
fxt.Test_extensiontags_y("translate", "languages"); // always whitelist <translate>,<languages> DATE:2015-10-13
|
||||
}
|
||||
@Test public void Extensiontags__fsys() {
|
||||
fxt.Init_fsys(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__null, 1, "math", "source"));
|
||||
fxt.Exec_load();
|
||||
fxt.Test_extensiontags_y("math", "source");
|
||||
fxt.Test_extensiontags_n("ref" , "graph");
|
||||
fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__fsys, 1, "math", "source"));
|
||||
}
|
||||
@Test public void Extensiontags__inet() {
|
||||
fxt.Init_inet(fxt.Make_api(fxt.Make_api_extensiontags("math", "source")));
|
||||
fxt.Exec_load();
|
||||
fxt.Test_extensiontags_y("math", "source");
|
||||
fxt.Test_extensiontags_n("ref" , "graph");
|
||||
fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 1, "math", "source"));
|
||||
}
|
||||
@Test public void Extensiontags__fallback() {
|
||||
fxt.Exec_load();
|
||||
fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__fallback, 1));
|
||||
fxt.Test_extensiontags_y("math", "source", "ref", "graph");
|
||||
}
|
||||
@Test public void Interwikimap__inet() {
|
||||
fxt.Init_inet(fxt.Make_api(fxt.Make_api_interwikimap("w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org")));
|
||||
fxt.Exec_load();
|
||||
fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__interwikimap, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 2, "w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org"));
|
||||
}
|
||||
// @Test public void Print() {
|
||||
// String s = fxt.Make_api(fxt.Make_api_interwikimap("k1", "v1", "k2", "v2"), fxt.Make_api_extensiontags2("k3", "v3", "k4", "v4"));
|
||||
// Tfds.Dbg(s);
|
||||
// }
|
||||
}
|
||||
class Xoa_site_cfg_mgr_fxt {
|
||||
private final Xoae_app app; private final Xowe_wiki wiki;
|
||||
private final Xoa_site_cfg_mgr site_cfg_mgr;
|
||||
private final Db_cfg_tbl cfg_tbl;
|
||||
private final Json_printer printer = new Json_printer();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Xoa_site_cfg_mgr_fxt() {
|
||||
// Xoa_app_.Usr_dlg_(Xoa_app_.New__usr_dlg__console());
|
||||
gplx.core.ios.IoEngine_system.Web_access_enabled = true; // HACK: must manually enable web_access else above tests will fail due to some other test disabling singleton; DATE:2016-12-15
|
||||
Xoa_test_.Inet__init();
|
||||
this.app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
Xoa_test_.Init__db__edit(wiki);
|
||||
this.cfg_tbl = wiki.Data__core_mgr().Tbl__cfg();
|
||||
this.site_cfg_mgr = app.Site_cfg_mgr();
|
||||
}
|
||||
public void Init() {
|
||||
Datetime_now.Manual_y_(); Datetime_now.Autoincrement_n_();
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
cfg_tbl.Delete_grp(Xoa_site_cfg_loader__db.Grp__xowa_wm_api);
|
||||
site_cfg_mgr.Init_loader_bgn(wiki);
|
||||
app.Utl__inet_conn().Clear();
|
||||
}
|
||||
public void Term() {
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
public void Init_db(String key, String data) {
|
||||
cfg_tbl.Assert_bry(Xoa_site_cfg_loader__db.Grp__xowa_wm_api, key, Bry_.new_u8(data));
|
||||
}
|
||||
public void Test_db(String key, String expd) {
|
||||
byte[] actl = cfg_tbl.Select_bry_or(Xoa_site_cfg_loader__db.Grp__xowa_wm_api, key, null);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Init_inet(String data) {
|
||||
String url = Xoa_site_cfg_loader__inet.Bld_url(tmp_bfr, wiki.Domain_str(), site_cfg_mgr.Data_hash(), site_cfg_mgr.Itm_ary());
|
||||
app.Utl__inet_conn().Upload_by_bytes(url, Bry_.new_u8(data));
|
||||
}
|
||||
public void Init_fsys(String key, String data) {
|
||||
Xoa_site_cfg_loader__fsys loader = Xoa_site_cfg_loader__fsys.new_(app);
|
||||
Io_url url = loader.Make_load_url(wiki.Domain_str(), key);
|
||||
Io_mgr.Instance.SaveFilStr(url, data);
|
||||
}
|
||||
public Xoa_site_cfg_mgr_fxt Exec_load() {
|
||||
site_cfg_mgr.Load(wiki);
|
||||
return this;
|
||||
}
|
||||
public void Test_extensiontags_y(String... ary) {Test_extensiontags(Bool_.Y, ary);}
|
||||
public void Test_extensiontags_n(String... ary) {Test_extensiontags(Bool_.N, ary);}
|
||||
public void Test_extensiontags(boolean expd_exists, String... ary) {
|
||||
Btrie_slim_mgr trie = wiki.Mw_parser_mgr().Xnde_tag_regy().Get_trie(Xop_parser_tid_.Tid__defn);
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String str = ary[i];
|
||||
byte[] bry = Bry_.new_u8(str);
|
||||
boolean actl_exists = trie.Match_exact(bry, 0, bry.length) != null;
|
||||
Tfds.Eq_bool(expd_exists, actl_exists, str);
|
||||
}
|
||||
}
|
||||
public void Test_inet_qarg(String expd) {
|
||||
Xoa_site_cfg_loader__inet loader__inet = (Xoa_site_cfg_loader__inet)site_cfg_mgr.Loader_ary()[2];
|
||||
String api_url = loader__inet.Api_url();
|
||||
Tfds.Eq(expd, String_.Mid(api_url, String_.FindBwd(api_url, "=") + 1));
|
||||
}
|
||||
public String Make_api(byte[]... sections) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
bfr.Add_str_a7("{'query':");
|
||||
int len = sections.length;
|
||||
bfr.Add_str_a7("{");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_str_a7(",");
|
||||
bfr.Add(sections[i]);
|
||||
}
|
||||
bfr.Add_str_a7("}");
|
||||
bfr.Add_str_a7("}");
|
||||
return printer.Print_by_bry(Bry_.new_u8(Json_doc.Make_str_by_apos(bfr.To_str_and_rls()))).To_str();
|
||||
}
|
||||
public byte[] Make_api_interwikimap(String... ary) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
bfr.Add_str_a7("'interwikimap':");
|
||||
int len = ary.length;
|
||||
bfr.Add_str_a7("[");
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
if (i != 0) bfr.Add_str_a7(",");
|
||||
bfr.Add_str_a7("{'prefix':'" + ary[i] + "'");
|
||||
bfr.Add_str_a7(",'url':'" + ary[i + 1] + "'");
|
||||
bfr.Add_str_a7("}");
|
||||
}
|
||||
bfr.Add_str_a7("]");
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Make_api_extensiontags(String... ary) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
bfr.Add_str_a7("'extensiontags':");
|
||||
int len = ary.length;
|
||||
bfr.Add_str_a7("[");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_str_a7(",");
|
||||
bfr.Add_str_a7("'<" + ary[i] + ">'");
|
||||
}
|
||||
bfr.Add_str_a7("]");
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public String Make_data(int loader_tid, int flds, String... ary) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
if (loader_tid != Xoa_site_cfg_loader_.Tid__null) // null when constructing data for fsys
|
||||
bfr.Add_str_u8(Xoa_site_cfg_loader__db.Bld_meta(loader_tid)).Add_byte_nl();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i += flds) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
for (int j = 0; j < flds; ++j) {
|
||||
if (j != 0) bfr.Add_byte_pipe();
|
||||
bfr.Add_str_u8(ary[i + j]);
|
||||
}
|
||||
}
|
||||
return bfr.To_str_and_rls();
|
||||
}
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java
Normal file
30
400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_url__basic__tst {
|
||||
private final Xoa_url_fxt fxt = new Xoa_url_fxt();
|
||||
@Test public void Eq_page() {
|
||||
fxt.Test_eq_page(Bool_.Y, "en.wikipedia.org/wiki/A?redirect=yes", "en.wikipedia.org/wiki/A?redirect=yes");
|
||||
fxt.Test_eq_page(Bool_.N, "en.wikipedia.org/wiki/A?redirect=no" , "en.wikipedia.org/wiki/A?redirect=yes");
|
||||
}
|
||||
}
|
||||
class Xoa_url_fxt extends Xow_url_parser_fxt { public void Test_eq_page(boolean expd, String lhs_str, String rhs_str) {
|
||||
Xoa_url lhs_url = parser.Parse(Bry_.new_u8(lhs_str));
|
||||
Xoa_url rhs_url = parser.Parse(Bry_.new_u8(rhs_str));
|
||||
Tfds.Eq_bool(expd, lhs_url.Eq_page(rhs_url), "Eq_page");
|
||||
}
|
||||
}
|
||||
54
400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java
Normal file
54
400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xoa_url__to_str__tst {
|
||||
private final Xoa_url__to_str__fxt fxt = new Xoa_url__to_str__fxt();
|
||||
@Test public void Http() {fxt.Chk_to_str_href(Bool_.N, "http://a.org/b" , "http://a.org/b");}
|
||||
@Test public void File() {fxt.Chk_to_str_href(Bool_.N, "file:///C/xowa/file/a.png" , "file:///C/xowa/file/a.png");}
|
||||
@Test public void Abrv__page() {fxt.Chk_to_str_href(Bool_.N, "/wiki/A" , "A");}
|
||||
@Test public void Abrv__anch() {fxt.Chk_to_str_href(Bool_.N, "#b" , "#b");}
|
||||
@Test public void Full__page() {fxt.Chk_to_str_href(Bool_.Y, "/wiki/A" , "en.wikipedia.org/wiki/A");}
|
||||
@Test public void Full__anch() {fxt.Chk_to_str_href(Bool_.Y, "#b" , "en.wikipedia.org/wiki/Page_1#b");}
|
||||
@Test public void Vnt() {
|
||||
Xowe_wiki zh_wiki = fxt.Prep_create_wiki("zh.wikipedia.org");
|
||||
gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(zh_wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant"));
|
||||
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hans/A" , "zh.wikipedia.org/zh-hans/A");
|
||||
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hant/A" , "zh.wikipedia.org/zh-hant/A");
|
||||
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-cn/A" , "zh.wikipedia.org/wiki/A");
|
||||
fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/wiki/A" , "zh.wikipedia.org/wiki/A");
|
||||
}
|
||||
@Test public void Xwiki() {
|
||||
fxt.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
fxt.Chk_to_str_href(Bool_.N, "/site/fr.wikipedia.org/wiki/Page", "fr.wikipedia.org/wiki/Page");
|
||||
}
|
||||
@Test public void Alias() {
|
||||
fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org");
|
||||
Xow_wiki en_d = fxt.Prep_create_wiki("en.wiktionary.org");
|
||||
en_d.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all);
|
||||
fxt.Chk_to_str_href(Bool_.N, "/wiki/wikt:a" , "en.wiktionary.org/wiki/a");
|
||||
}
|
||||
@Test public void Unknown() {fxt.Chk_to_str_href(Bool_.N, "/wiki/{{{extlink}}}" , "");} // {{{extlink}}} not a valid title; return empty
|
||||
}
|
||||
class Xoa_url__to_str__fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser();
|
||||
public void Chk_to_str_href(boolean full, String raw, String expd) {Chk_to_str_href(cur_wiki, full, raw, expd);}
|
||||
public void Chk_to_str_href(Xowe_wiki wiki, boolean full, String raw, String expd) {
|
||||
href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), wiki, Bry__page);
|
||||
this.Test__to_str(full, expd);
|
||||
}
|
||||
private static final byte[] Bry__page = Bry_.new_a7("Page_1");
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java
Normal file
41
400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoav_url_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoav_url_parser_fxt fxt = new Xoav_url_parser_fxt();
|
||||
@Test public void Page() {
|
||||
fxt.Exec_parse_xo_href("http:/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
|
||||
}
|
||||
@Test public void Site() {
|
||||
fxt.Exec_parse_xo_href("http:/site/en.wikipedia.org/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth");
|
||||
}
|
||||
}
|
||||
class Xoav_url_parser_fxt {
|
||||
private Xoav_url_parser url_parser = new Xoav_url_parser(); private Xoav_url url = new Xoav_url();
|
||||
public void Clear() {
|
||||
cur_wiki = Bry_.new_a7("en.wikipedia.org");
|
||||
url.Clear();
|
||||
}
|
||||
public Xoav_url_parser_fxt Init_cur_wiki(String v) {cur_wiki = Bry_.new_u8(v); return this;} private byte[] cur_wiki;
|
||||
public Xoav_url_parser_fxt Test_wiki(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Wiki_bry()); return this;}
|
||||
public Xoav_url_parser_fxt Test_page(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Page_bry()); return this;}
|
||||
public Xoav_url_parser_fxt Exec_parse_xo_href(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
url_parser.Parse_xo_href(url, src_bry, cur_wiki);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__proto_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Relative() {
|
||||
tstr.Exec__parse("//en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Http__basic() {
|
||||
tstr.Exec__parse("http://en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Upload__basic() {
|
||||
tstr.Prep_add_xwiki_to_user("commons.wikimedia.org"); // NOTE: need to add xwiki to be able to resolve "/commons/"
|
||||
tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg").Test__wiki("commons.wikimedia.org").Test__page("File:C.svg"); // orig
|
||||
tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png").Test__wiki("commons.wikimedia.org").Test__page("File:A.png"); // thum
|
||||
}
|
||||
@Test public void File__basic() {
|
||||
tstr.Exec__parse("file:///C:/a/b/c").Test__tid(Xoa_url_.Tid_file);
|
||||
}
|
||||
@Test public void Ftp__basic() {
|
||||
tstr.Exec__parse("ftp://en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_inet);
|
||||
}
|
||||
@Test public void Extended() {
|
||||
tstr.Exec__parse("http://en.wikipedia.org/w/index.php?A=B").Test__wiki("en.wikipedia.org").Test__page("index.php").Test__qargs("?A=B").Test__anch(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__qarg__tst {
|
||||
private final Xow_url_parser_fxt fxt = new Xow_url_parser_fxt();
|
||||
@Test public void Redirect() {
|
||||
fxt.Exec__parse("A?redirect=no").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?redirect=no");
|
||||
}
|
||||
@Test public void Action_is_edit() {
|
||||
fxt.Exec__parse("A?action=edit").Test__wiki("en.wikipedia.org").Test__page("A").Test__action_is_edit_y();
|
||||
}
|
||||
@Test public void Assert_state_cleared() { // PURPOSE.fix: action_is_edit (et. al.) was not being cleared on parse even though Xoa_url reused; DATE:20121231
|
||||
fxt.Exec__parse("A?action=edit") .Test__action_is_edit_y();
|
||||
fxt.Exec__parse_reuse("B") .Test__action_is_edit_n();
|
||||
}
|
||||
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
|
||||
fxt.Exec__parse("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes").Test__build_str_is_same();
|
||||
}
|
||||
@Test public void Dupe_key() {
|
||||
fxt.Exec__parse("A?B=C1&B=C2").Test__page("A").Test__qargs("?B=C1&B=C2");
|
||||
}
|
||||
@Test public void Question_is_eos() {
|
||||
fxt.Exec__parse("A?").Test__wiki("en.wikipedia.org").Test__page("A?").Test__qargs("");
|
||||
}
|
||||
@Test public void Question_is_page() {
|
||||
fxt.Exec__parse("A?B").Test__wiki("en.wikipedia.org").Test__page("A?B").Test__qargs("");
|
||||
}
|
||||
@Test public void Question_is_anchor() {
|
||||
fxt.Exec__parse("A#b?c").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b.3Fc");
|
||||
}
|
||||
@Test public void Title_remove_w() { // PURPOSE: fix /w/ showing up as seg; DATE:2014-05-30
|
||||
fxt.Exec__parse("http://en.wikipedia.org/w/index.php?title=A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Ctg() {
|
||||
fxt.Exec__parse("Category:A?pagefrom=A#mw-pages").Test__page("Category:A").Test__qargs("?pagefrom=A").Test__anch("mw-pages");
|
||||
}
|
||||
@Test public void Anch() {
|
||||
fxt.Exec__parse("A?k1=v1#anch");
|
||||
fxt.Test__page("A");
|
||||
fxt.Test__anch("anch");
|
||||
fxt.Test__qargs("?k1=v1");
|
||||
fxt.Test__to_str("en.wikipedia.org/wiki/A?k1=v1#anch");
|
||||
}
|
||||
// DELETED: this is wrong as url should not handle html_entities like = instead # should strictly designate anch_href; DATE:2016-10-10
|
||||
// @Test public void Encoded() {
|
||||
// fxt.Exec__parse("en.wikipedia.org/wiki/A?action=edit&preload=B").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?action==edit=&preload=&=").Test__anch("61.3BB"); // NOTE: this is wrong; fix later
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__ttl_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Name() {
|
||||
tstr.Exec__parse("A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Sub_1() {
|
||||
tstr.Exec__parse("A/b").Test__wiki("en.wikipedia.org").Test__page("A/b");
|
||||
}
|
||||
@Test public void Sub_2() {
|
||||
tstr.Exec__parse("A/b/c").Test__wiki("en.wikipedia.org").Test__page("A/b/c");
|
||||
}
|
||||
@Test public void Anch() {
|
||||
tstr.Exec__parse("A#b").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b");
|
||||
}
|
||||
@Test public void Anch_w_slash() { // PURPOSE: A/b#c/d was not parsing correctly; PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29
|
||||
tstr.Exec__parse("A/b#c/d").Test__page("A/b").Test__anch("c.2Fd");
|
||||
}
|
||||
@Test public void Ns_category() {
|
||||
tstr.Exec__parse("Category:A").Test__wiki("en.wikipedia.org").Test__page("Category:A");
|
||||
}
|
||||
@Test public void Main_page__basic() {
|
||||
tstr.Exec__parse("en.wikipedia.org") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
|
||||
tstr.Exec__parse("en.wikipedia.org/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y();
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/A") .Test__wiki("en.wikipedia.org").Test__page_is_main_n();
|
||||
}
|
||||
@Test public void Ns_file__basic() {// PURPOSE: "File:A" should not be mistaken for "file:///" ns
|
||||
tstr.Exec__parse("File:A").Test__wiki("en.wikipedia.org").Test__page("File:A");
|
||||
}
|
||||
@Test public void Ns_file__nested() {// PURPOSE: handle fictitious "File:A/B/C.png"
|
||||
tstr.Exec__parse("File:A/B/C.png").Test__wiki("en.wikipedia.org").Test__page("File:A/B/C.png"); // should not be C.png b/c of Gfo_url_parser_old
|
||||
}
|
||||
@Test public void Anch__basic() {// DATE:2015-07-26
|
||||
tstr.Exec__parse("#A").Test__tid(Xoa_url_.Tid_anch).Test__wiki_is_missing(true).Test__page("").Test__anch("A");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__url_bar_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
tstr.Exec__parse_from_url_bar("Page_1").Test__to_str("en.wikipedia.org/wiki/Page_1"); // basic
|
||||
}
|
||||
@Test public void Lang() {
|
||||
tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org");
|
||||
tstr.Exec__parse_from_url_bar("uk").Test__to_str("en.wikipedia.org/wiki/Uk"); // lang-like page (uk=Ukraine) should not try to open wiki; DATE:2014-02-07
|
||||
}
|
||||
@Test public void Lang_like() {
|
||||
tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org", "http://~{1}.wikipedia.org"); // NOTE: fmt needed for Type_is_lang
|
||||
tstr.Exec__parse_from_url_bar("uk/A").Test__to_str("en.wikipedia.org/wiki/Uk/A"); // uk/A should not try be interpreted as wiki="uk" page="A"; DATE:2014-04-26
|
||||
}
|
||||
@Test public void Macro() {
|
||||
tstr.Prep_add_xwiki_to_user("fr.wikisource.org");
|
||||
tstr.Exec__parse_from_url_bar("fr.s:Auteur:Shakespeare").Test__to_str("fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
|
||||
}
|
||||
@Test public void Main_page__home() {
|
||||
tstr.Exec__parse_from_url_bar("home").Test__to_str("en.wikipedia.org/wiki/Home"); // home should go to current wiki's home; DATE:2014-02-09
|
||||
tstr.Exec__parse_from_url_bar("home/wiki/Main_Page").Test__to_str("home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09
|
||||
}
|
||||
@Test public void Main_page__zhw() {
|
||||
Xowe_wiki zh_wiki = tstr.Prep_create_wiki("zh.wikipedia.org");
|
||||
zh_wiki.Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
tstr.Exec__parse_from_url_bar("zh.w:Main_Page") .Test__page_is_main_n().Test__to_str("zh.wikipedia.org/wiki/Main_Page");
|
||||
tstr.Exec__parse_from_url_bar("zh.w:") .Test__page_is_main_y().Test__to_str("zh.wikipedia.org/wiki/Zh_Main_Page");
|
||||
tstr.Exec__parse_from_url_bar("en.w:") .Test__page_is_main_y().Test__to_str("en.wikipedia.org/wiki/Main_Page"); // old bug: still stuck at zh main page due to reused objects
|
||||
}
|
||||
@Test public void Mobile() { // PURPOSE: handle mobile links; DATE:2014-05-03
|
||||
tstr.Exec__parse_from_url_bar("en.m.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // basic
|
||||
tstr.Exec__parse_from_url_bar("en.M.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // upper
|
||||
tstr.Exec__parse_from_url_bar("A" ).Test__to_str("en.wikipedia.org/wiki/A"); // bounds-check: 0
|
||||
tstr.Exec__parse_from_url_bar("A." ).Test__to_str("en.wikipedia.org/wiki/A."); // bounds-check: 1
|
||||
tstr.Exec__parse_from_url_bar("A.b" ).Test__to_str("en.wikipedia.org/wiki/A.b"); // bounds-check: 2
|
||||
tstr.Exec__parse_from_url_bar("A.b.m." ).Test__to_str("en.wikipedia.org/wiki/A.b.m."); // false-match
|
||||
tstr.Exec__parse_from_url_bar("en.x.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/En.x.wikipedia.org/wiki/A"); // fail
|
||||
}
|
||||
@Test public void Missing_page() {
|
||||
tstr.Exec__parse_from_url_bar("http://a.org").Test__is_null(); // unknown wiki; return null;
|
||||
tstr.Exec__parse_from_url_bar("http://en.wikipedia.org").Test__to_str("en.wikipedia.org/wiki/Main_Page"); // known wiki; return Main_Page
|
||||
}
|
||||
@Test public void Invalid_names() {
|
||||
tstr.Exec__parse_from_url_bar("http://a/b/c").Test__is_null(); // unknown url
|
||||
tstr.Exec__parse_from_url_bar("war").Test__to_str("en.wikipedia.org/wiki/War"); // word looks like lang, but is actually page; default to current
|
||||
}
|
||||
@Test public void Proper_case() {
|
||||
tstr.Exec__parse_from_url_bar("a" ).Test__to_str("en.wikipedia.org/wiki/A"); // "a" -> "A" x> "a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__wiki_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void No_wiki() { // PURPOSE: no "/wiki/"
|
||||
tstr.Exec__parse("en.wikipedia.org/A").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Nested() {
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/A/b").Test__wiki("en.wikipedia.org").Test__page("A/b");
|
||||
}
|
||||
@Test public void Slash() {
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki//A").Test__wiki("en.wikipedia.org").Test__page("/A");
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/A//b").Test__wiki("en.wikipedia.org").Test__page("A//b");
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki///A").Test__wiki("en.wikipedia.org").Test__page("//A");
|
||||
}
|
||||
@Test public void Vnt() {
|
||||
Xowe_wiki wiki = tstr.Wiki();
|
||||
gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant"));
|
||||
tstr.Exec__parse("en.wikipedia.org/zh-hans/A").Test__wiki("en.wikipedia.org").Test__page("A").Test__vnt("zh-hans");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xow_url_parser__xcmd_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
tstr.Exec__parse("xowa-cmd:xowa.app.version").Test__tid(Xoa_url_.Tid_xcmd).Test__page("xowa.app.version");
|
||||
}
|
||||
@Test public void Encoded() {
|
||||
tstr.Exec__parse("xowa-cmd:a%22b*c").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a\"b*c");
|
||||
}
|
||||
@Test public void Ignore_anchor_and_qargs() {
|
||||
tstr.Exec__parse("xowa-cmd:a/b/c?d=e#f").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a/b/c?d=e#f");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xow_url_parser__xwiki_tst {
|
||||
private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt();
|
||||
@Test public void Commons() { // PURPOSE: "C" was being picked up as an xwiki to commons; PAGE:no.b:C/Variabler; DATE:2014-10-14
|
||||
tstr.Prep_add_xwiki_to_user("c", "commons.wikimedia.org"); // add alias of "c"
|
||||
tstr.Exec__parse("C/D").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("C/D"); // should use current wiki (enwiki), not xwiki to commons; also, page should be "C/D", not "D"
|
||||
}
|
||||
@Test public void Parse_lang() {
|
||||
tstr.Prep_add_xwiki_to_wiki("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/~{0}");
|
||||
tstr.Exec__parse("http://en.wikipedia.org/wiki/fr:A").Test__tid(Xoa_url_.Tid_page).Test__wiki("fr.wikipedia.org").Test__page("A");
|
||||
}
|
||||
@Test public void Alias_wiki() {
|
||||
tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
|
||||
tstr.Exec__parse("s:A/b/c").Test__wiki("en.wikisource.org").Test__page("A/b/c");
|
||||
}
|
||||
@Test public void Xwiki_no_segs() { // PURPOSE: handle xwiki without full url; EX: "commons:Commons:Media_of_the_day"; DATE:2014-02-19
|
||||
tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
|
||||
tstr.Exec__parse("s:Project:A").Test__wiki("en.wikisource.org").Test__page("Project:A");
|
||||
}
|
||||
@Test public void Domain_only() {
|
||||
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
tstr.Exec__parse("fr.wikipedia.org").Test__wiki("fr.wikipedia.org").Test__page("");
|
||||
}
|
||||
@Test public void Domain_and_wiki() {
|
||||
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
tstr.Exec__parse("fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page("");
|
||||
}
|
||||
@Test public void Domain_and_wiki_w_http() {
|
||||
tstr.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
tstr.Exec__parse("http://fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page("");
|
||||
}
|
||||
@Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki
|
||||
Xowe_wiki en_s = tstr.Prep_create_wiki("en.wikisource.org");
|
||||
tstr.Exec__parse(en_s, "Category:A").Test__wiki("en.wikisource.org").Test__page("Category:A");
|
||||
}
|
||||
@Test public void Case_sensitive() {
|
||||
// tstr.Exec__parse("en.wikipedia.org/wiki/a").Test__wiki("en.wikipedia.org").Test__page("A");
|
||||
Xowe_wiki en_d = tstr.Prep_create_wiki("en.wiktionary.org");
|
||||
Xow_ns_mgr ns_mgr = en_d.Ns_mgr();
|
||||
|
||||
ns_mgr.Ns_main().Case_match_(Xow_ns_case_.Tid__all);
|
||||
tstr.Exec__parse("en.wiktionary.org/wiki/a").Test__wiki("en.wiktionary.org").Test__page("a");
|
||||
|
||||
ns_mgr.Ns_category().Case_match_(Xow_ns_case_.Tid__all);
|
||||
tstr.Exec__parse("en.wiktionary.org/wiki/Category:a").Test__wiki("en.wiktionary.org").Test__page("Category:a");
|
||||
|
||||
tstr.Exec__parse("en.wiktionary.org/wiki/A/B/C").Test__page("A/B/C");
|
||||
}
|
||||
@Test public void Xwiki__to_enwiki() { // PURPOSE: handle alias of "wikipedia" and sv.wikipedia.org/wiki/Wikipedia:Main_Page; DATE:2015-07-31
|
||||
Xowe_wiki xwiki = tstr.Prep_create_wiki("sv.wikipedia.org");
|
||||
tstr.Prep_xwiki(xwiki, "wikipedia", "en.wikipedia.org", null);
|
||||
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Wikipedia");
|
||||
tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("wikipedia:X");
|
||||
tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/Wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("Wikipedia:X");
|
||||
}
|
||||
@Test public void Xwiki__to_ns() { // PURPOSE: handle alias of "wikipedia" in current, but no "Wikipedia" ns in other wiki; PAGE:pt.w:Wikipedia:P<>gina_de_testes DATE:2015-09-17
|
||||
tstr.Prep_create_wiki("pt.wikipedia.org");
|
||||
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
|
||||
tstr.Prep_xwiki(tstr.Wiki(), "wikipedia", "en.wikipedia.org", null); // add alias of "wikipedia" in current wiki
|
||||
tstr.Exec__parse(tstr.Wiki(), "pt.wikipedia.org/wiki/Wikipedia:X").Test__wiki("pt.wikipedia.org").Test__page("Wikipedia:X"); // should get "pt.wikipedia.org", not "en.wikipedia.org" (through alias)
|
||||
}
|
||||
}
|
||||
81
400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java
Normal file
81
400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xow_url_parser_fxt {
|
||||
protected final Xoae_app app; protected final Xowe_wiki cur_wiki;
|
||||
protected final Xow_url_parser parser;
|
||||
protected Xoa_url actl_url;
|
||||
public Xow_url_parser_fxt() {
|
||||
this.app = Xoa_app_fxt.Make__app__edit();
|
||||
this.cur_wiki = Prep_create_wiki("en.wikipedia.org");
|
||||
this.parser = cur_wiki.Utl__url_parser();
|
||||
this.actl_url = Xoa_url.blank(); // default to blank for subclasses
|
||||
}
|
||||
public Xoae_app App() {return app;}
|
||||
public Xowe_wiki Wiki() {return cur_wiki;}
|
||||
public Xowe_wiki Prep_create_wiki(String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(app, domain);
|
||||
Prep_add_xwiki_to_user(domain);
|
||||
return rv;
|
||||
}
|
||||
public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain) {return Prep_xwiki(cur_wiki, alias, domain, null);}
|
||||
public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain, String fmt) {return Prep_xwiki(cur_wiki, alias, domain, fmt);}
|
||||
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String domain) {return Prep_xwiki(app.Usere().Wiki(), domain, domain, null);}
|
||||
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, null);}
|
||||
public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain, String fmt) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, fmt);}
|
||||
public Xow_url_parser_fxt Prep_xwiki(Xow_wiki wiki, String alias, String domain, String fmt) {
|
||||
wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), Bry_.new_u8_safe(fmt));
|
||||
return this;
|
||||
}
|
||||
public Xow_ns_mgr Prep_get_ns_mgr_from_meta(String wiki) {
|
||||
return app.Dbmeta_mgr().Ns__get_or_load(Bry_.new_u8(wiki));
|
||||
}
|
||||
public Xow_url_parser_fxt Exec__parse(String actl_str) {return Exec__parse(cur_wiki, actl_str);}
|
||||
public Xow_url_parser_fxt Exec__parse(Xow_wiki wiki, String actl_str) {
|
||||
this.actl_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(actl_str));
|
||||
return this;
|
||||
}
|
||||
public Xow_url_parser_fxt Exec__parse_reuse(String actl_str) {
|
||||
this.actl_url = parser.Parse(Bry_.new_u8(actl_str));
|
||||
return this;
|
||||
}
|
||||
public Xow_url_parser_fxt Exec__parse_from_url_bar(String raw) {
|
||||
this.actl_url = parser.Parse_by_urlbar_or_null(raw);
|
||||
return this;
|
||||
}
|
||||
public Xow_url_parser_fxt Test__tid(int v) {Tfds.Eq_int(v, actl_url.Tid() , "tid"); return this;}
|
||||
public Xow_url_parser_fxt Test__is_null() {Tfds.Eq_bool(true, actl_url == null); return this;}
|
||||
public Xow_url_parser_fxt Test__vnt(String v) {Tfds.Eq_str(v, actl_url.Vnt_bry() , "vnt"); return this;}
|
||||
public Xow_url_parser_fxt Test__wiki(String v) {Tfds.Eq_str(v, actl_url.Wiki_bry() , "wiki"); return this;}
|
||||
public Xow_url_parser_fxt Test__wiki_is_missing(boolean v) {Tfds.Eq_bool(v, actl_url.Wiki_is_missing(), "wiki_is_missing"); return this;}
|
||||
public Xow_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl_url.Page_bry() , "page"); return this;}
|
||||
public Xow_url_parser_fxt Test__qargs(String v) {Tfds.Eq_str(v, actl_url.Qargs_mgr().To_bry(), "qargs"); return this;}
|
||||
public Xow_url_parser_fxt Test__page_is_main_y() {return Test__page_is_main(Bool_.Y);}
|
||||
public Xow_url_parser_fxt Test__page_is_main_n() {return Test__page_is_main(Bool_.N);}
|
||||
public Xow_url_parser_fxt Test__page_is_main(boolean v) {Tfds.Eq_bool(v, actl_url.Page_is_main() , "page_is_main"); return this;}
|
||||
public Xow_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl_url.Anch_bry(), "anch"); return this;}
|
||||
public Xow_url_parser_fxt Test__action_is_edit_y() {return Test__action_is_edit_(Bool_.Y);}
|
||||
public Xow_url_parser_fxt Test__action_is_edit_n() {return Test__action_is_edit_(Bool_.N);}
|
||||
private Xow_url_parser_fxt Test__action_is_edit_(boolean v) {Tfds.Eq_bool(v, actl_url.Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit), "action_is_edit"); return this;}
|
||||
public Xow_url_parser_fxt Test__to_str(String v) {return Test__to_str(Bool_.Y, v);}
|
||||
public Xow_url_parser_fxt Test__to_str(boolean full, String v) {Tfds.Eq_str(v, actl_url.To_bry(full, Bool_.Y), "To_bry"); return this;}
|
||||
public Xow_url_parser_fxt Test__build_str_is_same() {
|
||||
Xow_url_parser parser = new Xow_url_parser(cur_wiki);
|
||||
Tfds.Eq_str(actl_url.Raw(), parser.Build_str(actl_url), "build_str");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java
Normal file
29
400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoa_url_encoder__tst {
|
||||
private final Xoa_url_encoder__fxt fxt = new Xoa_url_encoder__fxt();
|
||||
@Test public void Syms__diff() {fxt.Test__encode(" &'=+", "_%26%27%3D%2B");}
|
||||
@Test public void Syms__same() {fxt.Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");}
|
||||
@Test public void Mixed() {fxt.Test__encode("a &'=+b", "a_%26%27%3D%2Bb");} // PURPOSE: make sure dirty flag is set
|
||||
}
|
||||
class Xoa_url_encoder__fxt {
|
||||
private final Xoa_url_encoder encoder = new Xoa_url_encoder();
|
||||
public void Test__encode(String raw, String expd) {
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), encoder.Encode(Bry_.new_u8(raw)));
|
||||
}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
35
400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_version_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less
|
||||
fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more
|
||||
fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same
|
||||
fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less
|
||||
fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less
|
||||
fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more
|
||||
fxt.Test_compare("", "" , CompareAble_.Same); // empty:more
|
||||
}
|
||||
}
|
||||
class Xoa_version_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_compare(String lhs, String rhs, int expd) {
|
||||
Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
|
||||
import org.junit.*;
|
||||
// https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main Page&rvprop=timestamp|content
|
||||
public class Xoapi_orig_base_tst {
|
||||
Xoapi_orig_base_fxt fxt = new Xoapi_orig_base_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Bld_api_url() {
|
||||
fxt.Bld_api_url_tst("A.png" , 220, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220&iiurlheight=110");
|
||||
fxt.Bld_api_url_tst("A.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220");
|
||||
fxt.Bld_api_url_tst("A.png" , 0, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png"); // assert that null width does not write height
|
||||
fxt.Bld_api_url_tst("A b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A_b.png&iiurlwidth=220");
|
||||
fxt.Bld_api_url_tst("A&b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A%26b.png&iiurlwidth=220");
|
||||
}
|
||||
@Test public void Parse_size() {
|
||||
String raw = "<api><query><pages><page ns=\"6\" title=\"File:A.png\" missing=\"\" imagerepository=\"shared\"><imageinfo><ii size=\"1234\" width=\"220\" height=\"110\" /></imageinfo></page></pages></query></api>";
|
||||
fxt.Parse_size_tst(raw, 220, 110);
|
||||
}
|
||||
@Test public void Parse_reg() {
|
||||
String raw = "<api><query><pages><page ns=\"6\" title=\"File:A.png\" missing=\"\" imagerepository=\"shared\"><imageinfo><ii descriptionurl=\"http://commons.wikimedia.org/wiki/File:Berkheyde-Haarlem.png\" /></imageinfo></page></pages></query></api>";
|
||||
fxt.Parse_reg_tst(raw, "commons.wikimedia.org", "Berkheyde-Haarlem.png");
|
||||
}
|
||||
}
|
||||
class Xoapi_orig_base_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoapi_orig_rslts rv = new Xoapi_orig_rslts();
|
||||
public void Clear() {
|
||||
this.app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public void Bld_api_url_tst(String ttl_str, int w, int h, String expd) {
|
||||
String actl = Xoapi_orig_wmf.Bld_api_url(wiki.Domain_bry(), Bry_.new_u8(ttl_str), w, h);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
public void Parse_size_tst(String xml_str, int expd_w, int expd_h) {
|
||||
byte[] xml_bry = Bry_.new_u8(xml_str);
|
||||
Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry);
|
||||
Tfds.Eq(expd_w, rv.Orig_w());
|
||||
Tfds.Eq(expd_h, rv.Orig_h());
|
||||
}
|
||||
public void Parse_reg_tst(String xml_str, String expd_wiki, String expd_page) {
|
||||
byte[] xml_bry = Bry_.new_u8(xml_str);
|
||||
Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry);
|
||||
Tfds.Eq(expd_wiki, String_.new_u8(rv.Orig_wiki()));
|
||||
Tfds.Eq(expd_page, String_.new_u8(rv.Orig_page()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
public class Xoapi_orig_mok extends Xoapi_orig_base {
|
||||
private String wiki_str = "", ttl_str = "", redirect_str = ""; private int orig_w, orig_h; private boolean fail = false;
|
||||
public Xoapi_orig_mok Ini(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h, boolean pass) {
|
||||
this.wiki_str = wiki_str; this.ttl_str = ttl_str; this.redirect_str = redirect_str; this.orig_w = orig_w; this.orig_h = orig_h; this.fail = !pass;
|
||||
return this;
|
||||
}
|
||||
public void Clear() {wiki_str = ttl_str = redirect_str = ""; orig_w = orig_h = 0;}
|
||||
@Override public boolean Api_query_size_exec(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, byte[] ttl, int width, int height, Gfo_usr_dlg usr_dlg, byte[] repo_wiki_key) {
|
||||
if (!Bry_.Eq(ttl, Bry_.new_u8(ttl_str))) return false;
|
||||
if (!String_.Eq(wiki_str, String_.new_a7(repo_wiki_key))) return false;
|
||||
if (fail) return false;
|
||||
byte[] orig_page = String_.Eq(redirect_str, "") ? ttl : Bry_.new_u8(redirect_str);
|
||||
rv.Init_all(repo_wiki_key, orig_page, orig_w, orig_h);
|
||||
return true;
|
||||
}
|
||||
public static final Xoapi_orig_mok Instance = new Xoapi_orig_mok(); Xoapi_orig_mok() {}
|
||||
}
|
||||
92
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
92
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.strings.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.infos.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Db_mgr_fxt {
|
||||
public Db_mgr_fxt Ctor_fsys() {bldr_fxt = new Xob_fxt().Ctor(Xoa_test_.Url_root().GenSubDir("root")); return this;}
|
||||
public Db_mgr_fxt Ctor_mem() {bldr_fxt = new Xob_fxt().Ctor_mem(); return this;} private Xob_fxt bldr_fxt;
|
||||
public Xowd_page_itm page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xowd_page_itm().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Redirected_(type_redirect).Text_len_(text_len);}
|
||||
public Xowe_wiki Wiki() {return bldr_fxt.Wiki();}
|
||||
public Xob_bldr Bldr() {return bldr_fxt.Bldr();}
|
||||
public Db_mgr_fxt doc_ary_(Xowd_page_itm... v) {bldr_fxt.doc_ary_(v); return this;}
|
||||
public Xowd_page_itm doc_(int id, String date, String title, String text) {return bldr_fxt.doc_(id, date, title, text);}
|
||||
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, text);}
|
||||
public Xowd_page_itm doc_ttl_(int id, String title) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, "IGNORE");}
|
||||
public Db_mgr_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Db_mgr_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xob_page_wkr wkr) {bldr_fxt.Run_page_wkrs(wkr); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xob_cmd cmd) {bldr_fxt.Run_cmds(cmd); return this;}
|
||||
public Db_mgr_fxt Exec_run(Xobd_parser_wkr wkr) {bldr_fxt.Run(wkr); return this;}
|
||||
public void Init_page_insert(Int_obj_ref page_id_next, int ns_id, String[] ttls) {
|
||||
Xowe_wiki wiki = this.Wiki();
|
||||
int len = ttls.length;
|
||||
DateAdp modified_on = Datetime_now.Dflt_add_min_(0);
|
||||
Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
|
||||
tbl_page.Insert_bgn();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String ttl = ttls[i];
|
||||
int page_id = page_id_next.Val();
|
||||
tbl_page.Insert_cmd_by_batch(page_id, ns_id, Bry_.new_u8(ttl), false, modified_on, 0, page_id, 0, 0, -1);
|
||||
page_id_next.Val_add(1);
|
||||
}
|
||||
tbl_page.Insert_end();
|
||||
}
|
||||
public void Test_load_ttl(int ns_id, String ttl_str, Xowd_page_itm expd) {
|
||||
Xowe_wiki wiki = bldr_fxt.Wiki();
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
byte[] ttl_bry = Bry_.new_a7(ttl_str);
|
||||
wiki.Db_mgr_as_sql().Load_mgr().Load_by_ttl(actl, ns, ttl_bry);
|
||||
Tfds.Eq(expd.Id(), actl.Id());
|
||||
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on());
|
||||
Tfds.Eq(expd.Redirected(), actl.Redirected());
|
||||
Tfds.Eq(expd.Text_len(), actl.Text_len());
|
||||
} private Xowd_page_itm actl = new Xowd_page_itm();
|
||||
public void Test_load_page(int ns_id, int page_id, String expd) {
|
||||
Xowe_wiki wiki = bldr_fxt.Wiki();
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns);
|
||||
Tfds.Eq(expd, String_.new_a7(actl.Text()));
|
||||
}
|
||||
int[] Xto_int_ary(List_adp rslts) {
|
||||
int len = rslts.Count();
|
||||
int[] rv = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)rslts.Get_at(i);
|
||||
rv[i] = page.Id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_file(String url, String expd) {
|
||||
String actl = Io_mgr.Instance.LoadFilStr(url);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public void Init_db_sqlite() {
|
||||
Xowe_wiki wiki = this.Wiki();
|
||||
Db_conn_pool.Instance.Rls_all();
|
||||
Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
Io_mgr.Instance.DeleteDir_cmd(wiki.Fsys_mgr().Root_dir()).MissingIgnored_().Exec();
|
||||
wiki.Db_mgr_create_as_sql().Core_data_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
|
||||
Io_mgr.Instance.SaveFilStr(wiki.Import_cfg().Src_dir().GenSubFil("a.xml"), "<test/>");
|
||||
}
|
||||
public void Rls() {
|
||||
this.Wiki().Db_mgr_as_sql().Core_data_mgr().Rls();
|
||||
}
|
||||
}
|
||||
77
400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java
Normal file
77
400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_base_fxt {
|
||||
public Xob_base_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
bldr = Xoa_app_fxt.bldr_(app);
|
||||
}
|
||||
this.Init_(bldr, wiki);
|
||||
Clear_hook();
|
||||
return this;
|
||||
}
|
||||
@gplx.Virtual public void Clear_hook() {}
|
||||
public Xob_base_fxt Init_(Xob_bldr bldr, Xowe_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Gfo_invk Bldr_itm() {return bldr_itm;} Gfo_invk bldr_itm;
|
||||
public Xowd_page_itm page_(String ttl) {return page_(ttl, "");}
|
||||
public Xowd_page_itm page_(String ttl, String text) {return new Xowd_page_itm().Ttl_(Bry_.new_u8(ttl), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));}
|
||||
public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);}
|
||||
public void Init_fxts(Xob_bldr bldr, Xowe_wiki wiki, Xob_base_fxt... fxt_ary) {
|
||||
int fxt_ary_len = fxt_ary.length;
|
||||
for (int i = 0; i < fxt_ary_len; i++)
|
||||
fxt_ary[i].Init_(bldr, wiki);
|
||||
}
|
||||
public Xob_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Xob_base_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;}
|
||||
public Xob_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) {
|
||||
Xob_cmd cmd = (Xob_cmd)bldr.Cmd_mgr().Add_cmd(wiki, cmd_key);
|
||||
this.bldr_itm = cmd;
|
||||
int len = msgs.length;
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
GfoMsg msg = msgs[i];
|
||||
cmd.Invk(ctx, GfsCtx.Ikey_null, msg.Key(), msg);
|
||||
}
|
||||
Run_cmd(bldr, cmd);
|
||||
return this;
|
||||
}
|
||||
public Xob_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public Xob_base_fxt Test_fil(Io_url url, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
public static void Run_cmd(Xob_bldr bldr, Xob_cmd cmd) {
|
||||
cmd.Cmd_bgn(bldr);
|
||||
cmd.Cmd_run();
|
||||
cmd.Cmd_end();
|
||||
}
|
||||
public static void Run_wkr(Xob_bldr bldr, Xob_page_wkr wkr, Xowd_page_itm[] page_ary) {
|
||||
wkr.Page_wkr__bgn();
|
||||
int page_ary_len = page_ary.length;
|
||||
for (int i = 0; i < page_ary_len; i++) {
|
||||
Xowd_page_itm page = page_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
}
|
||||
154
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
154
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
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.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.tests.*; import gplx.core.ios.*; import gplx.core.times.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
|
||||
import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_fxt {
|
||||
private final Tst_mgr tst_mgr = new Tst_mgr();
|
||||
private final DateAdp_parser dateParser = DateAdp_parser.new_();
|
||||
public Xob_fxt Ctor_mem() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
return Ctor(Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public Xob_fxt Ctor(Io_url root_dir) {
|
||||
Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
app = Xoa_app_fxt.Make__app__edit("linux", root_dir);
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
bldr = Xoa_app_fxt.bldr_(app);
|
||||
return this;
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xob_fxt Fil_expd(Io_url url, String... expd) {
|
||||
String text = String_.Concat_lines_nl_skip_last(expd); // skipLast b/c if trailing line wanted, easier to pass in extra argument for ""
|
||||
expd_list.Add(new Io_fil_chkr(url, text));
|
||||
return this;
|
||||
} List_adp expd_list = List_adp_.New();
|
||||
public Xob_fxt Fil_skip(Io_url... urls) {
|
||||
for (int i = 0; i < urls.length; i++)
|
||||
skip_list.Add(urls[i]);
|
||||
return this;
|
||||
} List_adp skip_list = List_adp_.New();
|
||||
public Xob_fxt doc_ary_(Xowd_page_itm... v) {doc_ary = v; return this;} private Xowd_page_itm[] doc_ary;
|
||||
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);}
|
||||
public Xowd_page_itm doc_(int id, String date, String title, String text) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_u8(title), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));
|
||||
int[] modified_on = new int[7];
|
||||
dateParser.Parse_iso8651_like(modified_on, date);
|
||||
rv.Modified_on_(DateAdp_.seg_(modified_on));
|
||||
return rv;
|
||||
}
|
||||
public Xob_fxt Run_id() {
|
||||
Xob_make_id_wkr wkr = new Xob_make_id_wkr(bldr, wiki);
|
||||
Run_page_wkrs(wkr);
|
||||
return this;
|
||||
}
|
||||
private void Run_wkr(Xob_page_wkr wkr) {
|
||||
wkr.Page_wkr__bgn();
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xowd_page_itm page = doc_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
private void tst_fils(Io_url[] ary) {
|
||||
Io_fil[] actls = Get_actl(ary);
|
||||
Io_fil_chkr[] expds = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
|
||||
tst_mgr.Tst_ary("all", expds, actls);
|
||||
}
|
||||
Io_fil[] Get_actl(Io_url[] ary) {
|
||||
int len = ary.length;
|
||||
Io_fil[] rv = new Io_fil[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url url = ary[i];
|
||||
String data = Io_mgr.Instance.LoadFilStr(url);
|
||||
rv[i] = new Io_fil(url, data);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xob_fxt Run_tmpl_dump() {
|
||||
Xob_parse_dump_templates_cmd wkr = new Xob_parse_dump_templates_cmd(bldr, wiki);
|
||||
Run_wkr(wkr);
|
||||
tst_fils(wkr.Dump_url_gen().Prv_urls());
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run(Xobd_parser_wkr... wkrs) {
|
||||
Xobd_parser parser_wkr = new Xobd_parser(bldr);
|
||||
int len = wkrs.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
parser_wkr.Wkr_add(wkrs[i]);
|
||||
Run_page_wkrs(parser_wkr);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_page_wkrs(Xob_page_wkr... wkrs) {
|
||||
int doc_ary_len = doc_ary.length;
|
||||
for (int j = 0; j < wkrs.length; j++) {
|
||||
Xob_page_wkr wkr = wkrs[j];
|
||||
wkr.Page_wkr__bgn();
|
||||
for (int i = 0; i < doc_ary_len; i++) {
|
||||
Xowd_page_itm page = doc_ary[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
Test_expd_files();
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_cmds(Xob_cmd... cmds) {
|
||||
for (int j = 0; j < cmds.length; j++) {
|
||||
Xob_cmd cmd = cmds[j];
|
||||
cmd.Cmd_bgn(bldr);
|
||||
cmd.Cmd_run();
|
||||
cmd.Cmd_end();
|
||||
}
|
||||
Test_expd_files();
|
||||
return this;
|
||||
}
|
||||
private void Test_expd_files() {
|
||||
if (expd_list.Count() > 0) {
|
||||
Io_fil_chkr[] expd = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
|
||||
Io_fil[] actl = wiki_();
|
||||
tst_mgr.Tst_ary("all", expd, actl);
|
||||
}
|
||||
}
|
||||
Io_fil[] wiki_() {
|
||||
List_adp rv = List_adp_.New();
|
||||
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Ns_dir());
|
||||
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Site_dir());
|
||||
rv.Sort();
|
||||
return (Io_fil[])rv.To_ary(Io_fil.class);
|
||||
}
|
||||
private void wiki_fil_add(List_adp list, Io_url root_dir) {
|
||||
Io_url[] ary = Io_mgr.Instance.QueryDir_args(root_dir).Recur_().ExecAsUrlAry();
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
Io_url url = ary[i];
|
||||
Io_fil fil = new Io_fil(url, Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec());
|
||||
list.Add(fil);
|
||||
}
|
||||
}
|
||||
|
||||
public void Run_page_wkr(Xob_page_wkr wkr, Xowd_page_itm... pages) {
|
||||
int len = pages.length;
|
||||
wkr.Page_wkr__bgn();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = pages[i];
|
||||
wkr.Page_wkr__run(page);
|
||||
}
|
||||
wkr.Page_wkr__end();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xob_init_base_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_init_base_fxt fxt = new Xob_init_base_fxt();
|
||||
@Test public void Dirty_wiki_itms() {
|
||||
Xoae_app app = fxt.App(); Xowe_wiki wiki = fxt.Wiki();
|
||||
Xoa_available_wikis_mgr wikis_list = fxt.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis();
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // assert
|
||||
Xow_xwiki_itm xwiki_itm = app.Usere().Wiki().Xwiki_mgr().Add_by_atrs("en.wikipedia.org", "en.wikipedia.org");
|
||||
xwiki_itm.Offline_(Bool_.Y); // simulate add via Available_from_fsys; DATE:2014-09-21
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // still empty
|
||||
new Xob_init_tdb(app.Bldr(), wiki).Cmd_end(); // mock "init" task
|
||||
Tfds.Eq("\n <li><a href=\"/site/en.wikipedia.org/\" class='xowa-hover-off'>en.wikipedia.org</a></li>", wikis_list.Itms_as_html()); // no longer empty
|
||||
}
|
||||
}
|
||||
class Xob_init_base_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
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.bldrs.cmds.texts.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_siteinfo_parser__tst {
|
||||
private final Xob_siteinfo_parser__fxt fxt = new Xob_siteinfo_parser__fxt();
|
||||
@Test public void Basic__simplewikt() { // PURPOSE: basic test of siteinfo parse; DATE:2015-11-01
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( " <siteinfo>"
|
||||
, " <sitename>Wiktionary</sitename>"
|
||||
, " <dbname>simplewiktionary</dbname>"
|
||||
, " <super>https://simple.wiktionary.org/wiki/Main_Page</super>"
|
||||
, " <generator>MediaWiki 1.27.0-wmf.3</generator>"
|
||||
, " <case>case-sensitive</case>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key=\"-2\" case=\"case-sensitive\">Media</namespace>"
|
||||
, " <namespace key=\"-1\" case=\"first-letter\">Special</namespace>"
|
||||
, " <namespace key=\"0\" case=\"case-sensitive\" />"
|
||||
, " <namespace key=\"1\" case=\"case-sensitive\">Talk</namespace>"
|
||||
, " <namespace key=\"2\" case=\"first-letter\">User</namespace>"
|
||||
, " <namespace key=\"3\" case=\"first-letter\">User talk</namespace>"
|
||||
, " <namespace key=\"4\" case=\"case-sensitive\">Wiktionary</namespace>"
|
||||
, " <namespace key=\"5\" case=\"case-sensitive\">Wiktionary talk</namespace>"
|
||||
, " <namespace key=\"6\" case=\"case-sensitive\">File</namespace>"
|
||||
, " <namespace key=\"7\" case=\"case-sensitive\">File talk</namespace>"
|
||||
, " <namespace key=\"8\" case=\"first-letter\">MediaWiki</namespace>"
|
||||
, " <namespace key=\"9\" case=\"first-letter\">MediaWiki talk</namespace>"
|
||||
, " <namespace key=\"10\" case=\"case-sensitive\">Template</namespace>"
|
||||
, " <namespace key=\"11\" case=\"case-sensitive\">Template talk</namespace>"
|
||||
, " <namespace key=\"12\" case=\"case-sensitive\">Help</namespace>"
|
||||
, " <namespace key=\"13\" case=\"case-sensitive\">Help talk</namespace>"
|
||||
, " <namespace key=\"14\" case=\"case-sensitive\">Category</namespace>"
|
||||
, " <namespace key=\"15\" case=\"case-sensitive\">Category talk</namespace>"
|
||||
, " <namespace key=\"828\" case=\"case-sensitive\">Module</namespace>"
|
||||
, " <namespace key=\"829\" case=\"case-sensitive\">Module talk</namespace>"
|
||||
, " <namespace key=\"2300\" case=\"case-sensitive\">Gadget</namespace>"
|
||||
, " <namespace key=\"2301\" case=\"case-sensitive\">Gadget talk</namespace>"
|
||||
, " <namespace key=\"2302\" case=\"case-sensitive\">Gadget definition</namespace>"
|
||||
, " <namespace key=\"2303\" case=\"case-sensitive\">Gadget definition talk</namespace>"
|
||||
, " <namespace key=\"2600\" case=\"first-letter\">Topic</namespace>"
|
||||
, " </namespaces>"
|
||||
, " </siteinfo>"
|
||||
), String_.Concat_lines_nl
|
||||
( "Main_Page|case-sensitive|Wiktionary|simplewiktionary|MediaWiki 1.27.0-wmf.3"
|
||||
, "-2|case-sensitive|Media"
|
||||
, "-1|first-letter|Special"
|
||||
, "0|case-sensitive|"
|
||||
, "1|case-sensitive|Talk"
|
||||
, "2|first-letter|User"
|
||||
, "3|first-letter|User talk"
|
||||
, "4|case-sensitive|Wiktionary"
|
||||
, "5|case-sensitive|Wiktionary talk"
|
||||
, "6|case-sensitive|File"
|
||||
, "7|case-sensitive|File talk"
|
||||
, "8|first-letter|MediaWiki"
|
||||
, "9|first-letter|MediaWiki talk"
|
||||
, "10|case-sensitive|Template"
|
||||
, "11|case-sensitive|Template talk"
|
||||
, "12|case-sensitive|Help"
|
||||
, "13|case-sensitive|Help talk"
|
||||
, "14|case-sensitive|Category"
|
||||
, "15|case-sensitive|Category talk"
|
||||
, "828|case-sensitive|Module"
|
||||
, "829|case-sensitive|Module talk"
|
||||
, "2300|case-sensitive|Gadget"
|
||||
, "2301|case-sensitive|Gadget talk"
|
||||
, "2302|case-sensitive|Gadget definition"
|
||||
, "2303|case-sensitive|Gadget definition talk"
|
||||
, "2600|first-letter|Topic"
|
||||
, "2601|first-letter|2601" // NOTE: Topic_talk doesn't exist in <siteinfo>, but added by XOWA b/c every subj ns must have a talk ns
|
||||
));
|
||||
}
|
||||
@Test public void Case_dflt() { // PURPOSE: missing case should use dflt DATE:2015-11-01
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( " <siteinfo>"
|
||||
, " <case>case-sensitive</case>"
|
||||
, " <namespaces>"
|
||||
, " <namespace key=\"-2\">Media</namespace>"
|
||||
, " </namespaces>"
|
||||
, " </siteinfo>"
|
||||
), String_.Concat_lines_nl
|
||||
( "Main_Page|case-sensitive|||"
|
||||
, "-2|case-sensitive|Media"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xob_siteinfo_parser__fxt {
|
||||
private final Xow_ns_mgr ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
Xob_siteinfo_nde nde = Xob_siteinfo_parser_.Parse(src_str, ns_mgr);
|
||||
nde.To_bfr(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.wikis.data.*; import gplx.xowa.files.downloads.*;
|
||||
import gplx.xowa.wikis.data.fetchers.*;
|
||||
public class Xoa_css_extractor_basic_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
|
||||
@Test public void Logo_download() {
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html);
|
||||
fxt.Init_fil("mem/http/wiki.png" , "download");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "download");
|
||||
}
|
||||
@Test public void Logo_download_mw_wiki_logo() {
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , "");
|
||||
fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/a/wiki.png" , "download");
|
||||
fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css" , ".mw-wiki-logo{background-image:url(\"//a/wiki.png\");");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png" , "download");
|
||||
}
|
||||
@Test public void Logo_failover() {
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/logo.png" , "failover");
|
||||
fxt.Exec_logo_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "failover");
|
||||
}
|
||||
@Test public void Css_common_download_failover() {
|
||||
fxt.Css_installer().Opt_download_css_common_(true);
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_common_copy() {
|
||||
fxt.Css_installer().Opt_download_css_common_(false);
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_common_copy_specific_wiki() { // PURPOSE: css for specific wiki
|
||||
fxt.Css_installer().Opt_download_css_common_(false).Wiki_code_(Bry_.new_a7("enwiki"));
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_override/xowa_common_enwiki.css", "failover");
|
||||
fxt.Exec_css_common_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
@Test public void Css_scrape_download() {
|
||||
fxt.Css_installer().Url_encoder_(Gfo_url_encoder_.Http_url);
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html);
|
||||
fxt.Init_fil("mem/http/en.wikipedia.org/common.css" , "download");
|
||||
fxt.Init_fil("mem/http/www/a&0|b,c" , "data=css_0");
|
||||
fxt.Init_fil("mem/http/www/a&1|b,c" , "data=css_1");
|
||||
fxt.Exec_css_mainpage_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:mem/http/www/a&0|b,c*/"
|
||||
, "data=css_0"
|
||||
, ""
|
||||
, "/*XOWA:mem/http/www/a&1|b,c*/"
|
||||
, "data=css_1"
|
||||
));
|
||||
}
|
||||
@Test public void Css_scrape_failover() {
|
||||
fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover");
|
||||
fxt.Exec_css_mainpage_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover");
|
||||
}
|
||||
}
|
||||
71
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java
Normal file
71
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.core.ios.*;
|
||||
import gplx.xowa.wikis.data.fetchers.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
public class Xoa_css_extractor_fxt {
|
||||
public void Clear() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
|
||||
css_installer = new Xoa_css_extractor();
|
||||
css_installer.Download_xrg().Trg_engine_key_(IoEngine_.MemKey);
|
||||
css_installer
|
||||
.Usr_dlg_(usr_dlg)
|
||||
.Wiki_domain_(Bry_.new_a7("en.wikipedia.org"))
|
||||
.Protocol_prefix_("mem/http/")
|
||||
.Mainpage_url_("mem/http/en.wikipedia.org")
|
||||
.Failover_dir_(Io_url_.new_any_("mem/xowa/bin/any/html/xowa/import/")) // "mem/xowa/user/anonymous/wiki/home/html/"
|
||||
.Wiki_html_dir_(Io_url_.new_any_("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/"))
|
||||
;
|
||||
page_fetcher = new Xow_page_fetcher_test();
|
||||
css_installer.Page_fetcher_(page_fetcher);
|
||||
Xoa_css_img_downloader css_img_downloader = new Xoa_css_img_downloader();
|
||||
css_img_downloader.Ctor(usr_dlg, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/"));
|
||||
css_installer.Css_img_downloader_(css_img_downloader);
|
||||
} private Xow_page_fetcher_test page_fetcher;
|
||||
public Xoa_css_extractor Css_installer() {return css_installer;} private Xoa_css_extractor css_installer;
|
||||
public void Init_page(int ns_id, String ttl, String text) {
|
||||
page_fetcher.Add(ns_id, Bry_.new_a7(ttl), Bry_.new_a7(text));
|
||||
}
|
||||
public void Init_fil_empty(String url) {Init_fil(url, "");}
|
||||
public void Init_fil(String url, String text) {Io_mgr.Instance.SaveFilStr(url, text);}
|
||||
public void Test_fil(String url, String expd) {Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(Io_url_.new_any_(url)));}
|
||||
public void Exec_logo_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Logo_setup();
|
||||
}
|
||||
public void Exec_css_common_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Css_common_setup();
|
||||
}
|
||||
public void Exec_css_wiki_setup() {css_installer.Css_wiki_setup();}
|
||||
public void Exec_css_mainpage_setup() {
|
||||
css_installer.Mainpage_download();
|
||||
css_installer.Css_scrape_setup();
|
||||
}
|
||||
public static String Main_page_html = String_.Concat_lines_nl
|
||||
( "<html>"
|
||||
, " <head>"
|
||||
, " <link rel=\"stylesheet\" href=\"www/a&0%7Cb%2Cc\" />"
|
||||
, " <link rel=\"stylesheet\" href=\"www/a&1%7Cb%2Cc\" />"
|
||||
, " </head>"
|
||||
, " <body>"
|
||||
, " <div id=\"p-logo\" role=\"banner\"><a style=\"background-image: url(wiki.png);\""
|
||||
, " </body>"
|
||||
, "</html>"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoa_css_extractor_wiki_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
|
||||
@Test public void Css_wiki_generate() {
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "css_0");
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Vector.css" , "css_1");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
, "css_0"
|
||||
, ""
|
||||
, "/*XOWA:MediaWiki:Vector.css*/"
|
||||
, "css_1"
|
||||
));
|
||||
}
|
||||
@Test public void Css_wiki_missing() {
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", "");
|
||||
}
|
||||
@Test public void Css_wiki_tab() { // PURPOSE: swap out 	 for xdat files
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "a	b");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
, "a\tb"
|
||||
));
|
||||
}
|
||||
}
|
||||
181
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java
Normal file
181
400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.xowa.files.downloads.*;
|
||||
public class Xoa_css_img_downloader_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_img_downloader_fxt fxt = new Xoa_css_img_downloader_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg\")}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"site/b.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
, "site/b.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Unquoted() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(//site/a.jpg)}"
|
||||
, "x {url(\"site/a.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Http() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(http://site/a.jpg)}"
|
||||
, "x {url(\"site/a.jpg\")}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Base64() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Exc_missing_quote() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"//site/b.jpg} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Exc_empty() {
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg\")} y {url(\"\"} z {}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"\"} z {}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
// @Test public void Exc_name_only() { // COMMENTED: not sure how to handle "b.jpg" (automatically add "current" path?); RESTORE: when example found
|
||||
// fxt.Test_css_convert
|
||||
// ( "x {url(\"//site/a.jpg\")} y {url(\"b.jpg\"} z {}"
|
||||
// , "x {url(\"site/a.jpg\")} y {url(\"b.jpg\"} z {}"
|
||||
// , "site/a.jpg"
|
||||
// );
|
||||
// }
|
||||
@Test public void Repeat() {// PURPOSE.fix: exact same item was being added literally
|
||||
fxt.Test_css_convert
|
||||
( "x {url(\"//site/a.jpg?a=b\")} y {url(\"//site/a.jpg?a=b\"}"
|
||||
, "x {url(\"site/a.jpg\")} y {url(\"site/a.jpg\"}"
|
||||
, "site/a.jpg"
|
||||
);
|
||||
}
|
||||
@Test public void Clean_basic() {fxt.Test_clean_img_url("//site/a.jpg" , "site/a.jpg");}
|
||||
@Test public void Clean_query() {fxt.Test_clean_img_url("//site/a.jpg?key=val" , "site/a.jpg");}
|
||||
@Test public void Clean_dir() {fxt.Test_clean_img_url("//site/a/b/c.jpg?key=val" , "site/a/b/c.jpg");}
|
||||
@Test public void Clean_exc_site_only() {fxt.Test_clean_img_url("//site" , null);}
|
||||
@Test public void Clean_exc_site_only_2() {fxt.Test_clean_img_url("//site/" , null);}
|
||||
@Test public void Import_url() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/www/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"mem/www/b.css\") screen; z"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/www/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_make() {
|
||||
fxt.Test_import_url("a.org/b" , "http:a.org/b"); // add "stylesheet_prefix"
|
||||
fxt.Test_import_url("http://a.org" , "http://a.org"); // unless it starts with http
|
||||
fxt.Test_import_url("https://a.org" , "https://a.org"); // unless starts with https EX:: handle @import(https://...); PAGE:tr.n:Main_Page; DATE:2014-06-04
|
||||
}
|
||||
@Test public void Import_url_relative() { // PURPOSE: if directory, add domain; "/a/b.css" -> "//domain/a/b.css"; DATE:2014-02-03
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/www/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"/www/b.css\") screen; z" // starts with "/"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/en.wikipedia.org/www/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_relative_skip() { // PURPOSE: if rel path, skip; "//site/a/b.css"; DATE:2014-02-03
|
||||
fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem//en.wikipedia.org/a/b.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"//en.wikipedia.org/a/b.css\") screen; z" // starts with "//"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA://en.wikipedia.org/a/b.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Import_url_space() { // PURPOSE: some css has spaces; replace with underlines else fails when downloaded; EX: https://it.wikivoyage.org/w/index.php?title=MediaWiki:Container e Infobox.css&action=raw&ctype=text/css; DATE:2015-03-08
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem/www/b_c.css", "imported_css");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"mem/www/b c.css\") screen; z"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA:mem/www/b_c.css*/"
|
||||
, "imported_css"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Wikisource_freedimg() { // PURPOSE: check that "wikimedia" is replaced for FreedImg hack; PAGE:en.s:Page:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species.pdf/3 DATE:2014-09-06
|
||||
fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_mgr.Instance.SaveFilStr("mem//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css", ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {");
|
||||
fxt.Test_css_convert
|
||||
( "x @import url(\"//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css\") screen; z" // starts with "//"
|
||||
, String_.Concat_lines_nl
|
||||
( "x "
|
||||
, "/*XOWA://en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css*/"
|
||||
, ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], /*XOWA:handle file:// paths which will have /commons.wikimedia.org/ but not /wikipedia/ */ .freedImg img[src*=\"wikimedia\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {"
|
||||
, ""
|
||||
, " z"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xoa_css_img_downloader_fxt {
|
||||
public Xoa_css_img_downloader Downloader() {return downloader;} private Xoa_css_img_downloader downloader;
|
||||
public void Clear() {
|
||||
downloader = new Xoa_css_img_downloader();
|
||||
downloader.Ctor(Gfo_usr_dlg_.Test(), new Xof_download_wkr_test(), Bry_.Empty);
|
||||
}
|
||||
public void Test_css_convert(String raw, String expd, String... expd_img_ary) {
|
||||
List_adp actl_img_list = List_adp_.New();
|
||||
byte[] actl_bry = downloader.Convert_to_local_urls(Bry_.new_a7("mem/en.wikipedia.org"), Bry_.new_u8(raw), actl_img_list);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl_bry));
|
||||
Tfds.Eq_ary_str(expd_img_ary, actl_img_list.To_str_ary());
|
||||
}
|
||||
public void Test_clean_img_url(String raw_str, String expd) {
|
||||
byte[] raw = Bry_.new_a7(raw_str);
|
||||
byte[] actl = downloader.Clean_img_url(raw, raw.length);
|
||||
Tfds.Eq(expd, actl == null ? null : String_.new_a7(actl));
|
||||
}
|
||||
public void Test_import_url(String raw, String expd) {
|
||||
byte[] actl = Xoa_css_img_downloader.Import_url_build(Bry_.new_a7("http:"), Bry_.new_a7("//en.wikipedia.org"), Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_css_parser__import_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_css_parser__import_fxt fxt = new Xob_css_parser__import_fxt();
|
||||
@Test public void Basic() {fxt.Test_parse_import (" @import url(//site/a.png)" , " @import url('site/a.png')");}
|
||||
@Test public void Warn_eos() {fxt.Test_parse_warn (" @import" , " @import" , "EOS");}
|
||||
@Test public void Warn_missing() {fxt.Test_parse_warn (" @import ('//site/a.png')" , " @import" , "missing");} // no "url("
|
||||
@Test public void Warn_invalid() {fxt.Test_parse_warn (" @import url('//site')" , " @import url('//site')" , "invalid");} // invalid
|
||||
}
|
||||
class Xob_css_parser__import_fxt extends Xob_css_parser__url_fxt { private Xob_css_parser__import import_parser;
|
||||
@Override public void Clear() {
|
||||
super.Clear();
|
||||
this.import_parser = new Xob_css_parser__import(url_parser);
|
||||
}
|
||||
@Override protected void Exec_parse_hook() {
|
||||
this.cur_frag = import_parser.Parse(src_bry, src_bry.length, 0, 8); // 8=" @import".length
|
||||
}
|
||||
public void Test_parse_import(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_import, expd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_css_parser__url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_css_parser__url_fxt fxt = new Xob_css_parser__url_fxt();
|
||||
@Test public void Quote_none() {fxt.Test_parse_url(" url(//site/A.png) b" , " url('site/A.png')");}
|
||||
@Test public void Quote_apos() {fxt.Test_parse_url(" url('//site/A.png') b" , " url('site/A.png')");}
|
||||
@Test public void Quote_quote() {fxt.Test_parse_url(" url(\"//site/A.png\") b" , " url(\"site/A.png\")");}
|
||||
@Test public void Base64() {fxt.Test_parse_base64(" url('data:image/png;base64,BASE64DATA;ABC=') b", " url('data:image/png;base64,BASE64DATA;ABC=')");}
|
||||
@Test public void Base64_dangling() {fxt.Test_parse_warn(" url('data:image/png;base64,BASE64DATA;ABC=' ", " url('data:image/png;base64,BASE64DATA;ABC='", "base64 dangling");}
|
||||
@Test public void Warn_eos() {fxt.Test_parse_warn(" url(" , " url(" , "EOS");}
|
||||
@Test public void Warn_dangling() {fxt.Test_parse_warn(" url(a" , " url(" , "dangling");}
|
||||
@Test public void Warn_empty() {fxt.Test_parse_warn(" url()" , " url(" , "empty");}
|
||||
@Test public void Warn_site() {fxt.Test_parse_warn(" url('//site')" , " url('//site')" , "invalid");}
|
||||
}
|
||||
class Xob_css_parser__url_fxt {
|
||||
protected Xob_css_parser__url url_parser; private final Bry_bfr bfr = Bry_bfr_.New_w_size(32);
|
||||
protected Xob_css_tkn__base cur_frag; protected byte[] src_bry;
|
||||
@gplx.Virtual public void Clear() {
|
||||
url_parser = new Xob_css_parser__url(Bry_.new_a7("site"));
|
||||
}
|
||||
protected void Exec_parse(String src_str, int expd_tid, String expd_str) {
|
||||
this.src_bry = Bry_.new_u8(src_str);
|
||||
this.Exec_parse_hook();
|
||||
cur_frag.Write(bfr, src_bry);
|
||||
String actl_str = bfr.To_str_and_clear();
|
||||
Tfds.Eq(expd_tid, cur_frag.Tid(), "wrong tid; expd={0}, actl={1}", expd_tid, cur_frag.Tid());
|
||||
Tfds.Eq(expd_str, actl_str);
|
||||
}
|
||||
@gplx.Virtual protected void Exec_parse_hook() {
|
||||
this.cur_frag = url_parser.Parse(src_bry, src_bry.length, 0, 5); // 5=" url(".length
|
||||
}
|
||||
public void Test_parse_url(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_url, expd);
|
||||
}
|
||||
public void Test_parse_base64(String src_str, String expd) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_base64, expd);
|
||||
}
|
||||
public void Test_parse_warn(String src_str, String expd, String warn) {
|
||||
Exec_parse(src_str, Xob_css_tkn__base.Tid_warn, expd);
|
||||
Xob_css_tkn__warn sub_frag = (Xob_css_tkn__warn)cur_frag;
|
||||
Tfds.Eq(true, String_.Has(sub_frag.Fail_msg(), warn));
|
||||
}
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java
Normal file
61
400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.files.downloads.*;
|
||||
public class Xob_mirror_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_mirror_mgr_fxt fxt = new Xob_mirror_mgr_fxt();
|
||||
@Test public void Download_1() {
|
||||
fxt.Fsys().Init_fil("mem/http/enwiki/file/a.png");
|
||||
fxt.Fsys().Init_fil("mem/http/enwiki/wiki/Main_Page", "url('//enwiki/wiki/a.png')");
|
||||
// fxt.Test_css();
|
||||
// fxt.Fsys().Test_fil("url('//enwiki/wiki/a.png')", "url('enwiki/wiki/a.png')"); // remove "//"
|
||||
// fxt.Fsys().Test_fil("mem/fsys/enwiki/file/a.png");
|
||||
}
|
||||
}
|
||||
class Xob_mirror_mgr_fxt {
|
||||
// private Xob_mirror_mgr mirror_mgr;
|
||||
public Io_fsys_fxt Fsys() {return fsys;} private final Io_fsys_fxt fsys = new Io_fsys_fxt();
|
||||
public void Clear() {
|
||||
fsys.Clear();
|
||||
// mirror_mgr = new Xob_mirror_mgr(Gfo_usr_dlg_.Noop, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/enwiki"), Bry_.new_a7("mem/http/enwiki/wiki/Main_Page"), Io_url_.new_dir_("mem/fsys"));
|
||||
}
|
||||
public void Test_css(String raw, String expd) {
|
||||
// byte[] raw_bry = Bry_.new_u8(raw);
|
||||
// mirror_mgr.Exec();
|
||||
}
|
||||
}
|
||||
class Io_fsys_fxt {
|
||||
public void Clear() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public void Init_fil(String url_str) {
|
||||
Io_url url = Io_url_.new_fil_(url_str);
|
||||
Init_fil(url, url.NameAndExt());
|
||||
}
|
||||
public void Init_fil(String url_str, String text) {Init_fil(Io_url_.new_fil_(url_str), text);}
|
||||
public void Init_fil(Io_url url, String text) {
|
||||
Io_mgr.Instance.SaveFilStr(url, text);
|
||||
}
|
||||
public void Test_fil(String url_str) {
|
||||
Io_url url = Io_url_.new_fil_(url_str);
|
||||
Test_fil(url, url.NameAndExt());
|
||||
}
|
||||
public void Test_fil(String url, String expd) {Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public void Test_fil(Io_url url, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java
Normal file
40
400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_url_fixer_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_url_fixer_fxt fxt = new Xob_url_fixer_fxt();
|
||||
@Test public void Slash2() {fxt.Test_fix("//site/a.png" , "site/a.png");}
|
||||
@Test public void Http() {fxt.Test_fix("http://site/a.png" , "site/a.png");}
|
||||
@Test public void Https() {fxt.Test_fix("https://site/a.png" , "site/a.png");}
|
||||
@Test public void Qarg() {fxt.Test_fix("//site/a.png?key=val" , "site/a.png");}
|
||||
@Test public void Qarg_dir() {fxt.Test_fix("//site/a/b/c.png?key=val" , "site/a/b/c.png");}
|
||||
@Test public void Root() {fxt.Test_fix("/a/b.png" , "site/a/b.png");} // EX:/static/images/project-logos/wikivoyage.png; DATE:2015-05-09
|
||||
@Test public void Rel_dot2() {fxt.Test_fix("//site/a/../b/c.png" , "site/b/c.png");} // DATE:2015-05-09
|
||||
@Test public void Rel_dot2_mult() {fxt.Test_fix("//site/a/../b/../c/d.png" , "site/c/d.png");} // DATE:2015-05-09
|
||||
@Test public void Rel_dot1() {fxt.Test_fix("//site/a/./b/c.png" , "site/a/b/c.png");} // DATE:2015-05-09
|
||||
@Test public void Site_only() {fxt.Test_fix("//site" , null);}
|
||||
}
|
||||
class Xob_url_fixer_fxt {
|
||||
public void Site_(String v) {site_bry = Bry_.new_u8(v);} private byte[] site_bry;
|
||||
public void Clear() {
|
||||
this.Site_("site");
|
||||
}
|
||||
public void Test_fix(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Xob_url_fixer.Fix(site_bry, raw_bry, raw_bry.length)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*;
|
||||
public class Xob_ttl_filter_mgr_srl_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_srl_fxt fxt = new Xob_ttl_filter_mgr_srl_fxt();
|
||||
@Test public void One() {fxt.Test_parse("a" , 1, "a");}
|
||||
@Test public void Two() {fxt.Test_parse("a\nb" , 2, "a", "b");}
|
||||
@Test public void Comment() {fxt.Test_parse("|x" , 0);}
|
||||
@Test public void Comment_many() {fxt.Test_parse("|x||" , 0);}
|
||||
@Test public void Blank() {fxt.Test_parse("\n" , 0);}
|
||||
@Test public void Mix() {
|
||||
fxt.Test_parse(String_.Concat_lines_nl_skip_last
|
||||
( "|comment 1"
|
||||
, "a"
|
||||
, ""
|
||||
, "|comment 2"
|
||||
, "b"
|
||||
)
|
||||
, 2, "a", "b")
|
||||
;}
|
||||
}
|
||||
class Xob_ttl_filter_mgr_srl_fxt {
|
||||
private final Xob_ttl_filter_mgr_srl mgr = new Xob_ttl_filter_mgr_srl();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {
|
||||
hash.Clear();
|
||||
}
|
||||
public void Test_parse(String src, int expd_count, String... expd_itms) {
|
||||
mgr.Init(hash);
|
||||
mgr.Load_by_bry(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd_count, hash.Count());
|
||||
int expd_len = expd_itms.length;
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
String expd_itm = expd_itms[i];
|
||||
Tfds.Eq_true(hash.Has(Bry_.new_u8(expd_itm)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*;
|
||||
import org.junit.*;
|
||||
public class Xob_ttl_filter_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_fxt fxt = new Xob_ttl_filter_mgr_fxt();
|
||||
@Test public void One() {
|
||||
fxt.Init_load_exclude("A");
|
||||
fxt.Init_load_include("B");
|
||||
fxt.Test_match_exclude_y("A");
|
||||
fxt.Test_match_exclude_n("B", "C");
|
||||
fxt.Test_match_include_y("B");
|
||||
fxt.Test_match_include_n("A", "C");
|
||||
}
|
||||
}
|
||||
class Xob_ttl_filter_mgr_fxt {
|
||||
private final Xob_ttl_filter_mgr mgr = new Xob_ttl_filter_mgr();
|
||||
public void Clear() {
|
||||
mgr.Clear();
|
||||
}
|
||||
public void Init_load_exclude(String itm) {mgr.Load(Bool_.Y, Bry_.new_u8(itm));}
|
||||
public void Init_load_include(String itm) {mgr.Load(Bool_.N, Bry_.new_u8(itm));}
|
||||
public void Test_match_exclude_y(String... itms) {Test_match(Bool_.Y, Bool_.Y, itms);}
|
||||
public void Test_match_exclude_n(String... itms) {Test_match(Bool_.Y, Bool_.N, itms);}
|
||||
public void Test_match_include_y(String... itms) {Test_match(Bool_.N, Bool_.Y, itms);}
|
||||
public void Test_match_include_n(String... itms) {Test_match(Bool_.N, Bool_.N, itms);}
|
||||
private void Test_match(boolean exclude, boolean expd, String... itms) {
|
||||
for (String itm : itms) {
|
||||
byte[] itm_bry = Bry_.new_u8(itm);
|
||||
if (exclude)
|
||||
Tfds.Eq(expd, mgr.Match_exclude(itm_bry), itm);
|
||||
else
|
||||
Tfds.Eq(expd, mgr.Match_include(itm_bry), itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user