mirror of https://github.com/gnosygnu/xowa
parent
235228976e
commit
686d56fdab
@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs.diffs.tbls; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.*;
|
||||
/*
|
||||
reg:
|
||||
id,name,made_by,made_on,meta
|
||||
0,'Diffs for Simple Wikipedia betwee 2015-11-16 and 2015-12-23',gnosygnu,2015-12-23'dif;simplewiki;20151223;20151116'
|
||||
cmd:
|
||||
owner,id,tid,meta
|
||||
0,0,data_comp_tid,page
|
||||
0,1,data_comp_tid,cat_core
|
||||
0,2,data_comp_tid,cat_link
|
||||
txn:
|
||||
reg_id,txn_id,cmd_id,owner_txn
|
||||
0,0,0,-1,page
|
||||
0,1,-1,-1,cat
|
||||
0,2,-1,1,mid
|
||||
0,3,1,2,cat_core
|
||||
0,4,2,2,cat_link
|
||||
*/
|
||||
class Gdif_txn_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_txn";
|
||||
private String fld_owner, fld_id;
|
||||
private final Dbmeta_fld_list flds = Dbmeta_fld_list.new_();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_txn_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_owner = flds.Add_int("txn_owner"); fld_id = flds.Add_int("txn_id");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary(), Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_owner, fld_id)));}
|
||||
public void Insert(int txn_owner, int txn_id) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_owner , txn_owner)
|
||||
.Val_int(fld_id , txn_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
interface Mustache_doc_itm {
|
||||
byte[] Get_by_key(byte[] key);
|
||||
Mustache_doc_itm Get_owner();
|
||||
void Move_next();
|
||||
void Move_down(byte[] key);
|
||||
void Move_up();
|
||||
}
|
||||
class Mustache_doc_itm_ {
|
||||
public static final byte[] Null_val = null;
|
||||
public static final Mustache_doc_itm Null_itm = null;
|
||||
}
|
||||
class Mustache_doc_itm__json implements Mustache_doc_itm {
|
||||
// private Json_doc jdoc;
|
||||
private final List_adp stack = List_adp_.new_();
|
||||
private Json_nde cur; private int cur_idx = -1;
|
||||
public void Init_by_jdoc(Json_doc jdoc) {
|
||||
// this.jdoc = jdoc;
|
||||
this.cur = jdoc.Root_nde();
|
||||
}
|
||||
public byte[] Get_by_key(byte[] key) {return cur.Get_bry_or_null(key);}
|
||||
public Mustache_doc_itm Get_owner() {return Mustache_doc_itm_.Null_itm;}
|
||||
public void Move_next() {
|
||||
++cur_idx;
|
||||
// cur = cur.Owner().Get_at();
|
||||
}
|
||||
public void Move_down(byte[] key) {
|
||||
stack.Add(cur);
|
||||
cur_idx = 0;
|
||||
cur = (Json_nde)cur.Get_itm(key);
|
||||
}
|
||||
public void Move_up() {
|
||||
if (cur_idx == 0) {}
|
||||
cur = (Json_nde)stack.Get_at_last();
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
class Mustache_itm_parser {
|
||||
private byte[] src; private int src_end;
|
||||
private final Mustache_tkn_def tkn_def = new Mustache_tkn_def();
|
||||
public Mustache_elem_itm Parse(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.src_end = src_end;
|
||||
Mustache_elem_root root = new Mustache_elem_root();
|
||||
Parse_grp(root, src_bgn);
|
||||
return root;
|
||||
}
|
||||
private void Parse_grp(Mustache_elem_itm owner, int src_bgn) {
|
||||
List_adp subs_list = List_adp_.new_();
|
||||
int pos = src_bgn;
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
int tkn_lhs_bgn = Bry_find_.Find_fwd(src, tkn_def.Variable_lhs, pos, src_end); // next "{{"
|
||||
if (tkn_lhs_bgn == Bry_find_.Not_found) { // no "{{"; EOS
|
||||
loop = false;
|
||||
tkn_lhs_bgn = src_end;
|
||||
}
|
||||
subs_list.Add(new Mustache_elem_text(src, pos, tkn_lhs_bgn)); // add everything between last "}}" and cur "{{"
|
||||
if (!loop) break;
|
||||
pos = Parse_itm(subs_list, tkn_lhs_bgn + tkn_def.Variable_lhs_len);
|
||||
}
|
||||
if (subs_list.Count() > 0)
|
||||
owner.Subs_ary_((Mustache_elem_itm[])subs_list.To_ary_and_clear(Mustache_elem_itm.class));
|
||||
}
|
||||
private int Parse_itm(List_adp subs_list, int tkn_lhs_end) {
|
||||
if (tkn_lhs_end >= src_end) throw Fail(tkn_lhs_end, "early eos");
|
||||
byte b = src[tkn_lhs_end];
|
||||
int tkn_rhs_bgn = Bry_find_.Find_fwd(src, tkn_def.Variable_rhs, tkn_lhs_end, src_end);
|
||||
if (tkn_rhs_bgn == Bry_find_.Not_found) throw Fail(tkn_lhs_end, "dangling tkn");
|
||||
byte[] tkn_val = Bry_.Mid(src, tkn_lhs_end, tkn_rhs_bgn);
|
||||
Mustache_elem_itm elem = null;
|
||||
byte rhs_chk_byte = Byte_ascii.Null;
|
||||
switch (b) {
|
||||
default: elem = new Mustache_elem_variable(tkn_val); break;
|
||||
case Mustache_tkn_def.Comment: elem = new Mustache_elem_comment(tkn_val); break;
|
||||
case Mustache_tkn_def.Partial: elem = new Mustache_elem_partial(tkn_val); break;
|
||||
case Mustache_tkn_def.Delimiter_bgn: elem = new Mustache_elem_delimiter(tkn_val); rhs_chk_byte = Mustache_tkn_def.Delimiter_end; break; // TODO: change tkn_def{{=<% %>=}}
|
||||
case Mustache_tkn_def.Escape_bgn: elem = new Mustache_elem_escape(tkn_val); rhs_chk_byte = Mustache_tkn_def.Escape_end; break;
|
||||
case Mustache_tkn_def.Section: elem = new Mustache_elem_section(tkn_val); break;
|
||||
case Mustache_tkn_def.Inverted: elem = new Mustache_elem_inverted(tkn_val); break;
|
||||
case Mustache_tkn_def.Grp_end: break;
|
||||
}
|
||||
subs_list.Add(elem);
|
||||
if (rhs_chk_byte != Byte_ascii.Null) {
|
||||
if (src[tkn_rhs_bgn] != rhs_chk_byte) throw Fail(tkn_lhs_end, "invalid check byte");
|
||||
++tkn_rhs_bgn;
|
||||
}
|
||||
return tkn_rhs_bgn + tkn_def.Variable_rhs_len;
|
||||
}
|
||||
private Err Fail(int pos, String fmt, Object... args) {
|
||||
return Err_.new_("mustache", fmt, "excerpt", Bry_.Mid_by_len_safe(src, pos, 32));
|
||||
}
|
||||
}
|
||||
class Mustache_tkn_def {
|
||||
public byte[] Variable_lhs = Dflt_variable_lhs;
|
||||
public byte[] Variable_rhs = Dflt_variable_rhs;
|
||||
public int Variable_lhs_len;
|
||||
public int Variable_rhs_len;
|
||||
public static final byte[]
|
||||
Dflt_variable_lhs = Bry_.new_a7("{{")
|
||||
, Dflt_variable_rhs = Bry_.new_a7("}}")
|
||||
;
|
||||
public static final byte
|
||||
Escape_bgn = Byte_ascii.Curly_bgn // {{{escape}}}
|
||||
, Escape_end = Byte_ascii.Curly_end // {{{escape}}}
|
||||
, Section = Byte_ascii.Hash // {{#section}}
|
||||
, Grp_end = Byte_ascii.Slash // {{/section}}
|
||||
, Inverted = Byte_ascii.Pow // {{^inverted}}
|
||||
, Comment = Byte_ascii.Bang // {{!comment}}
|
||||
, Partial = Byte_ascii.Angle_bgn // {{>partial}}
|
||||
, Delimiter_bgn = Byte_ascii.Eq // {{=<% %>=}}
|
||||
, Delimiter_end = Byte_ascii.Curly_end // {{=<% %>=}}
|
||||
;
|
||||
public Mustache_tkn_def() {
|
||||
Variable_lhs_len = Variable_lhs.length;
|
||||
Variable_rhs_len = Variable_rhs.length;
|
||||
}
|
||||
}
|
||||
/*
|
||||
root
|
||||
txt
|
||||
key
|
||||
txt
|
||||
section
|
||||
txt
|
||||
key
|
||||
txt
|
||||
txt
|
||||
*/
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Mustache_itm_parser_tst {
|
||||
private final Mustache_itm_parser_fxt fxt = new Mustache_itm_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("a{{b}}c", "ac");
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test_parse("a{{!b}}c", "ac");
|
||||
}
|
||||
}
|
||||
class Mustache_itm_parser_fxt {
|
||||
private final Mustache_itm_parser parser = new Mustache_itm_parser();
|
||||
private final Mustache_render_ctx ctx = new Mustache_render_ctx();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public void Test_parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_a7(src_str);
|
||||
Mustache_elem_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length);
|
||||
actl_itm.Render(tmp_bfr, ctx);
|
||||
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
|
||||
class Mustache_render_ctx {
|
||||
private Mustache_doc_itm doc;
|
||||
public void Init_dom_doc(Mustache_doc_itm doc) {this.doc = doc;}
|
||||
public byte[] Render_variable(byte[] key) {
|
||||
byte[] rv = Mustache_doc_itm_.Null_val;
|
||||
Mustache_doc_itm cur = doc;
|
||||
while (cur != Mustache_doc_itm_.Null_itm) {
|
||||
rv = doc.Get_by_key(key);
|
||||
if (rv != Mustache_doc_itm_.Null_val) break;
|
||||
cur = cur.Get_owner();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
public interface Xod_search_cmd {
|
||||
void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search);
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xod_search_cmd_ {
|
||||
public static final Xod_search_cmd
|
||||
New__page_eq = Xod_search_cmd__page_eq.Instance
|
||||
, New__page_like = Xod_search_cmd__page_like.Instance
|
||||
, New__word_eq = Xod_search_cmd__word_tbl.Instance_eq
|
||||
, New__word_like = Xod_search_cmd__word_tbl.Instance_like
|
||||
;
|
||||
}
|
||||
class Xod_search_cmd__page_eq implements Xod_search_cmd {
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
Xowd_page_itm page_itm = new Xowd_page_itm();
|
||||
if (wiki.Data__core_mgr().Tbl__page().Select_by_ttl(page_itm, wiki.Ns_mgr().Ns_main(), Bry_.Ucase__1st(Bry_.new_u8(search)))) {
|
||||
Xows_db_row search_itm = new Xows_db_row(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
ui_async.Add(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_eq Instance = new Xod_search_cmd__page_eq(); Xod_search_cmd__page_eq() {}
|
||||
}
|
||||
class Xod_search_cmd__page_like implements Xod_search_cmd {// NOTE: slow; takes at least 10+ seconds
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
List_adp tmp_list = List_adp_.new_();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_search(cancelable, tmp_list, Bry_.Ucase__1st(Bry_.new_u8(search + "*")), 50);
|
||||
int len = tmp_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_page_itm page_itm = (Xowd_page_itm)tmp_list.Get_at(i);
|
||||
Xows_db_row search_itm = new Xows_db_row(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
ui_async.Add(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_like Instance = new Xod_search_cmd__page_like(); Xod_search_cmd__page_like() {}
|
||||
}
|
||||
class Xod_search_cmd__word_tbl implements Xod_search_cmd {
|
||||
private final boolean wildcard;
|
||||
private final int results_wanted;
|
||||
private final Xows_db_wkr search_wkr = new Xows_db_wkr();
|
||||
Xod_search_cmd__word_tbl(boolean wildcard, int results_wanted) {this.wildcard = wildcard; this.results_wanted = results_wanted;}
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
search_wkr.Search_by_drd(cancelable, wiki, ui_async, Bry_.new_u8(Standardize_search(search, wildcard)), results_wanted);
|
||||
}
|
||||
public static final Xod_search_cmd__word_tbl Instance_eq = new Xod_search_cmd__word_tbl(Bool_.N, 10), Instance_like = new Xod_search_cmd__word_tbl(Bool_.Y, 50);
|
||||
private static String Standardize_search(String search, boolean wildcard) {
|
||||
String rv = "";
|
||||
String[] words = String_.Split(search, " ");
|
||||
int words_len = words.length;
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
String word = words[i];
|
||||
if (String_.Len(word) < 3) continue;
|
||||
if (String_.Len(rv) != 0) rv += " ";
|
||||
rv += word;
|
||||
if (wildcard) rv += "*";
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
public class Xof_file_wkr__tst {
|
||||
private final Xof_file_wkr___fxt fxt = new Xof_file_wkr___fxt();
|
||||
@Test public void Ttl_standardize() {
|
||||
fxt.Test__ttl_standardize("Abc.png" , "Abc.png"); // basic
|
||||
fxt.Test__ttl_standardize("A b.png" , "A_b.png"); // spaces -> unders
|
||||
fxt.Test__ttl_standardize("A b c.png" , "A_b_c.png"); // spaces -> unders; multiple
|
||||
fxt.Test__ttl_standardize("abc.png" , "Abc.png"); // ucase 1st
|
||||
}
|
||||
}
|
||||
class Xof_file_wkr___fxt {
|
||||
public void Test__ttl_standardize(String src_str, String expd) {
|
||||
Tfds.Eq_bry(Bry_.new_u8(expd), Xof_file_wkr_.Ttl_standardize(Bry_.new_u8(src_str)));
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_lnki_wtr_utl {
|
||||
private final Xoa_app app; private final Xow_wiki wiki; private final Xoh_href_wtr href_wtr; private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
|
||||
public Xoh_lnki_wtr_utl(Xow_wiki wiki, Xoh_href_wtr href_wtr) {
|
||||
this.app = wiki.App();
|
||||
this.wiki = wiki; this.href_wtr = href_wtr;
|
||||
}
|
||||
public byte[] Bld_href(byte[] page) {return Bld_href(wiki.Domain_bry(), wiki.Ttl_parse(page));}
|
||||
public byte[] Bld_href(byte[] domain_bry, Xoa_ttl ttl) {
|
||||
href_wtr.Build_to_bfr(tmp_bfr, app, Xoh_wtr_ctx.Mode_popup, domain_bry, ttl);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Bld_title(byte[] text) {
|
||||
return gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(tmp_bfr, text, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Pb_xnde implements Xox_xnde {
|
||||
// private Pb_xtn xtn;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
// this.xtn = (Pb_xtn)wiki.Xtn_mgr().Get_or_fail(Pb_xtn.Xtn_key_static);
|
||||
// xtn.Xtn_init_assert(wiki);
|
||||
// ctx.Cur_page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
|
||||
// boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_graph, src, xnde);
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
// bfr.Add(Html__div_bgn);
|
||||
// bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
// bfr.Add(Html__div_end);
|
||||
}
|
||||
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
// private static final byte[]
|
||||
// Html__div_bgn = Bry_.new_a7("<div class='mw-wiki-graph'>\n")
|
||||
// , Html__div_end = Bry_.new_a7("</div>\n")
|
||||
// ;
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
class Pgbnr_cfg {
|
||||
public byte[] Default_file() {return null;}
|
||||
public boolean Enabled_in_ns(int ns_id) {return false;}
|
||||
}
|
||||
class Pgbnr_icon {
|
||||
public byte[] Name;
|
||||
public byte[] Title;
|
||||
public byte[] Url;
|
||||
public Pgbnr_icon(byte[] name, byte[] title, byte[] url) {
|
||||
this.Name = name; this.Title = title; this.Url = url;
|
||||
}
|
||||
public static final Pgbnr_icon[] Ary_empty = new Pgbnr_icon[0];
|
||||
}
|
||||
class Pgbnr_itm {
|
||||
public byte[] Name;
|
||||
public byte[] Tooltip;
|
||||
public byte[] Title;
|
||||
public boolean Bottomtoc;
|
||||
public boolean Toc;
|
||||
public Xoa_ttl File_ttl;
|
||||
public Pgbnr_icon[] Icons;
|
||||
public Pgbnr_itm(byte[] name, byte[] tooltip, byte[] title, boolean bottomtoc, boolean toc, Xoa_ttl file_ttl, Pgbnr_icon[] icons) {
|
||||
this.Name = name;
|
||||
this.Tooltip = tooltip; this.Title = title; this.Bottomtoc = bottomtoc; this.Toc = toc; this.File_ttl = file_ttl; this.Icons = icons;
|
||||
}
|
||||
// public static void Do(Bry_bfr bfr, Xop_ctx ctx, Pgbnr_cfg cfg, Pgbnr_itm itm) {
|
||||
// if (itm != null) {
|
||||
// byte[] name = itm.Name;
|
||||
//// if ( isset( $params['icons'] ) ){
|
||||
//// $out->enableOOUI();
|
||||
//// $params['icons'] = self::expandIconTemplateOptions( $params['icons'] );
|
||||
//// }
|
||||
// // $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// }
|
||||
// else {}
|
||||
// }
|
||||
public static void Get_banner_html(Bry_bfr bfr, byte[] banner_name, Pgbnr_itm itm, Pgbnr_cfg cfg) {
|
||||
byte[][] urls = Bry_.Ary(Bry_.Empty); // $urls = static::getStandardSizeUrls( $bannername );
|
||||
if (urls.length == 0) return;
|
||||
}
|
||||
// public static function getBannerHtml( $bannername, $options = array() ) {
|
||||
// // @var int index variable
|
||||
// $i = 0;
|
||||
// foreach ( $urls as $url ) {
|
||||
// $size = $config->get( 'WPBStandardSizes' );
|
||||
// $size = $size[$i];
|
||||
// // add url with width and a comma if not adding the last url
|
||||
// if ( $i < count( $urls ) ) {
|
||||
// $srcset[] = "$url {$size}w";
|
||||
// }
|
||||
// $i++;
|
||||
// }
|
||||
// // create full src set from individual urls, separated by comma
|
||||
// $srcset = implode( ',', $srcset );
|
||||
// // use largest image url as src attribute
|
||||
// $bannerurl = $urls[count( $urls ) - 1];
|
||||
// $bannerfile = Title::newFromText( "File:$bannername" );
|
||||
// $templateParser = new TemplateParser( __DIR__ . '/../templates' );
|
||||
// $options['bannerfile'] = $bannerfile->getLocalUrl();
|
||||
// $options['banner'] = $bannerurl;
|
||||
// $options['srcset'] = $srcset;
|
||||
// $file = wfFindFile( $bannerfile );
|
||||
// $options['maxWidth'] = $file->getWidth();
|
||||
// $options['isHeadingOverrideEnabled'] = $config->get( 'WPBEnableHeadingOverride' );
|
||||
// $banner = $templateParser->processTemplate(
|
||||
// 'banner',
|
||||
// $options
|
||||
// );
|
||||
// }
|
||||
|
||||
// public static function addBanner( OutputPage $out, Skin $skin ) {
|
||||
// $config = WikidataPageBannerFunctions::getWPBConfig();
|
||||
// $title = $out->getTitle();
|
||||
// $isDiff = $out->getRequest()->getVal( 'diff' );
|
||||
// $wpbFunctionsClass = self::$wpbFunctionsClass;
|
||||
//
|
||||
// // if banner-options are set and not a diff page, add banner anyway
|
||||
// if ( $out->getProperty( 'wpb-banner-options' ) !== null && !$isDiff ) {
|
||||
// $params = $out->getProperty( 'wpb-banner-options' );
|
||||
// $bannername = $params['name'];
|
||||
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// // attempt to get WikidataBanner
|
||||
// if ( $banner === null ) {
|
||||
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
|
||||
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
|
||||
// }
|
||||
// // only add banner and styling if valid banner generated
|
||||
// if ( $banner !== null ) {
|
||||
// if ( isset( $params['toc'] ) ) {
|
||||
// $out->addModuleStyles( 'ext.WikidataPageBanner.toc.styles' );
|
||||
// }
|
||||
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
|
||||
//
|
||||
// // FIXME: This is currently only needed to support testing
|
||||
// $out->setProperty( 'articlebanner-name', $bannername );
|
||||
// }
|
||||
// }
|
||||
// // if the page uses no 'PAGEBANNER' invocation and if article page, insert default banner
|
||||
// elseif (
|
||||
// $title->isKnown() &&
|
||||
// $out->isArticle() &&
|
||||
// $config->get( 'WPBEnableDefaultBanner' ) &&
|
||||
// !$isDiff
|
||||
// ) {
|
||||
// $ns = $title->getNamespace();
|
||||
// // banner only on specified namespaces, and not Main Page of wiki
|
||||
// if ( in_array( $ns, $config->get( 'WPBNamespaces' ) )
|
||||
// && !$title->isMainPage() ) {
|
||||
// // first try to obtain bannername from Wikidata
|
||||
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
|
||||
// if ( $bannername === null ) {
|
||||
// // if Wikidata banner not found, set bannername to default banner
|
||||
// $bannername = $config->get( 'WPBImage' );
|
||||
// }
|
||||
// // add title to template parameters
|
||||
// $paramsForBannerTemplate = array( 'title' => $title );
|
||||
// $banner = $wpbFunctionsClass::
|
||||
// getBannerHtml( $bannername, $paramsForBannerTemplate );
|
||||
// // only add banner and styling if valid banner generated
|
||||
// if ( $banner !== null ) {
|
||||
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
|
||||
//
|
||||
// // set articlebanner property on OutputPage
|
||||
// // FIXME: This is currently only needed to support testing
|
||||
// $out->setProperty( 'articlebanner-name', $bannername );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Pgbnr_func extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_pagebanner;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pgbnr_func().Name_(name);}
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { // WikidataPageBanner.hooks.php|addCustomBanner
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
Pgbnr_cfg cfg = new Pgbnr_cfg(); // ctx.Wiki().Xtn_mgr().Xtn_pgbnr();
|
||||
Xoa_ttl ttl = ctx.Cur_page().Ttl();
|
||||
if ( !cfg.Enabled_in_ns(ttl.Ns().Id()) // chk if ns allows banner
|
||||
|| Bry_.Eq(ttl.Page_db(), wiki.Props().Main_page())) // never show on main page
|
||||
return;
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
boolean bottomtoc = false, toc = false;
|
||||
byte[] tooltip = ttl.Page_txt();
|
||||
byte[] title = ttl.Page_txt();
|
||||
int args_len = self.Args_len();
|
||||
List_adp icons_list = null;
|
||||
for (int i = 0; i < args_len; ++i) {
|
||||
Arg_nde_tkn arg = self.Args_get_by_idx(i);
|
||||
byte[] key = Pf_func_.Eval_tkn(tmp_bfr, ctx, src, caller, arg.Key_tkn());
|
||||
byte[] val = Pf_func_.Eval_tkn(tmp_bfr, ctx, src, caller, arg.Val_tkn());
|
||||
int tid = arg_hash.Get_as_int_or(key, -1);
|
||||
if (tid == Arg__pgname)
|
||||
tooltip = title = val;
|
||||
if (tid == Arg__tooltip) // note that this overrides pgname above
|
||||
tooltip = val;
|
||||
if (tid == Arg__bottomtoc && Bry_.Eq(val, Bry__yes))
|
||||
bottomtoc = true;
|
||||
if (tid == Arg__toc && Bry_.Eq(val, Bry__yes))
|
||||
toc = true;
|
||||
if (tid == -1 && Bry_.Has_at_bgn(key, Bry__icon) && Bry_.Len_gt_0(val)) {
|
||||
if (icons_list == null) icons_list = List_adp_.new_();
|
||||
byte[] icon_name = Xop_sanitizer.Escape_cls(val);
|
||||
byte[] icon_title = icon_name;
|
||||
Xoa_ttl icon_url_ttl = wiki.Ttl_parse(val);
|
||||
byte[] icon_url_bry = Bry_.Empty;
|
||||
if (icon_url_ttl == null) icon_url_bry = Bry__url_dflt;
|
||||
else {
|
||||
icon_url_bry = Bry_.Empty;// $iconUrl->getLocalUrl();
|
||||
icon_title = ttl.Page_txt();
|
||||
}
|
||||
icons_list.Add(new Pgbnr_icon(icon_name, icon_title, icon_url_bry));
|
||||
tid = Arg__icon;
|
||||
}
|
||||
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", "page", ctx.Cur_page().Url_bry_safe(), key, val);
|
||||
// WikidataPageBannerFunctions::addFocus( $paramsForBannerTemplate, $argumentsFromParserFunction );
|
||||
}
|
||||
byte[] name = Eval_argx(ctx, src, caller, self);
|
||||
if (Bry_.Len_eq_0(name))
|
||||
name = cfg.Default_file();
|
||||
Xoa_ttl file_ttl = wiki.Ttl_parse(name);
|
||||
Pgbnr_itm itm = new Pgbnr_itm(name, tooltip, title, bottomtoc, toc, file_ttl, icons_list == null ? Pgbnr_icon.Ary_empty : (Pgbnr_icon[])icons_list.To_ary_and_clear(Pgbnr_icon.class));
|
||||
Tfds.Write(itm);
|
||||
}
|
||||
private static final byte[] Bry__yes = Bry_.new_a7("yes"), Bry__icon = Bry_.new_a7("icon-"), Bry__url_dflt = Bry_.new_a7("#");
|
||||
private static final int Arg__pgname = 0, Arg__tooltip = 1, Arg__bottomtoc = 2, Arg__toc = 3, Arg__icon = 4;
|
||||
private static final Hash_adp_bry arg_hash = Hash_adp_bry.cs().Add_str_int("pgname", Arg__pgname)
|
||||
.Add_str_int("tooltip", Arg__tooltip).Add_str_int("bottomtoc", Arg__bottomtoc).Add_str_int("toc", Arg__toc);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.engines.mocks; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.core.primitives.*;
|
||||
public abstract class Mock_proc_fxt {
|
||||
public Mock_proc_fxt(int id, String key) {this.id = id; this.key = key;}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public Scrib_lua_proc To_scrib_lua_proc() {return new Scrib_lua_proc(key, id);}
|
||||
public abstract KeyVal[] Exec_by_scrib(KeyVal[] args);
|
||||
}
|
||||
class Mock_engine implements Scrib_engine {
|
||||
private final Hash_adp hash = Hash_adp_.new_();
|
||||
private final Int_obj_ref tmp_hash_id = Int_obj_ref.neg1_();
|
||||
public boolean Dbg_print() {return false;} public void Dbg_print_(boolean v) {}
|
||||
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {} private final Mock_server server = new Mock_server();
|
||||
public Scrib_lua_proc LoadString(String name, String text) {return null;}
|
||||
public KeyVal[] CallFunction(int id, KeyVal[] args) {
|
||||
Mock_proc_fxt proc = (Mock_proc_fxt)hash.Get_by_or_fail(tmp_hash_id.Val_(id));
|
||||
return proc.Exec_by_scrib(args);
|
||||
}
|
||||
public void RegisterLibrary(KeyVal[] functions_ary) {}
|
||||
public KeyVal[] ExecuteModule(int mod_id) {return null;}
|
||||
public void CleanupChunks(KeyVal[] ids) {}
|
||||
public void Clear() {}
|
||||
public void RegisterLibraryForTest(Mock_proc_fxt proc) {
|
||||
hash.Add(Int_obj_ref.new_(proc.Id()), proc);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.engines.mocks; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Mock_scrib_fxt {
|
||||
private final Mock_engine engine = new Mock_engine();
|
||||
private final Mock_server server = new Mock_server();
|
||||
private Xop_fxt parser_fxt;
|
||||
public Scrib_core Core() {return core;} private Scrib_core core;
|
||||
public void Clear() {Clear("en.wikipedia.org", "en");}
|
||||
public void Clear(String domain, String lang) {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_or_new(Bry_.new_u8(lang)));
|
||||
parser_fxt = new Xop_fxt(app, wiki); // NOTE: always new(); don't try to cache; causes errors in Language_lib
|
||||
core = Scrib_core.Core_new_(app, wiki.Parser_mgr().Ctx());
|
||||
core.Engine_(engine); engine.Clear();
|
||||
core.Interpreter().Server_(server);
|
||||
Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null);
|
||||
Xot_invk current_frame = Xot_invk_mock.test_(Bry_.new_a7("Module:Mod_0"));
|
||||
core.Invoke_init(core.Wiki(), core.Ctx(), Bry_.Empty, parent_frame, current_frame);
|
||||
core.When_page_changed(parser_fxt.Page());
|
||||
}
|
||||
public void Init__cbk(Mock_proc_fxt... ary) {
|
||||
for (Mock_proc_fxt proc : ary)
|
||||
engine.RegisterLibraryForTest(proc);
|
||||
}
|
||||
public void Test__proc__objs__flat(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, Scrib_kv_utl_.base1_many_(args));}
|
||||
public void Test__proc__objs__nest(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, Scrib_kv_utl_.base1_many_(args));}
|
||||
public void Test__proc__kvps__flat(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.Y, args);}
|
||||
public void Test__proc__kvps__nest(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {Test__proc__kvps(lib, proc_name, expd, Bool_.N, args);}
|
||||
private static void Test__proc__kvps(Scrib_lib lib, String proc_name, String expd, boolean flat, KeyVal[] args) {
|
||||
KeyVal[] actl_ary = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
|
||||
if (flat)
|
||||
Tfds.Eq(expd, Mock_scrib_fxt_.Kvp_vals_to_str(actl_ary));
|
||||
else
|
||||
Tfds.Eq_str_lines(expd, KeyVal_.Ary__to_str__nest(actl_ary));
|
||||
}
|
||||
public void Test__proc__objs__empty(Scrib_lib lib, String proc_name, Object[] args) {Test__proc__kvps__empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
|
||||
public void Test__proc__kvps__empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
|
||||
Tfds.Eq(0, Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args).length);
|
||||
}
|
||||
public void Test__proc__kvps__vals(Scrib_lib lib, String proc_name, KeyVal[] args, Object... expd_ary) {
|
||||
KeyVal[] actl_kvs = Mock_scrib_fxt_.Test__lib_proc__core(lib, proc_name, args);
|
||||
Object[] actl_ary = Mock_scrib_fxt_.Kvp_vals_to_objs(actl_kvs);
|
||||
Tfds.Eq_ary(expd_ary, actl_ary);
|
||||
}
|
||||
}
|
||||
class Mock_scrib_fxt_ {
|
||||
public static KeyVal[] Test__lib_proc__core(Scrib_lib lib, String proc_name, KeyVal[] args) {
|
||||
Scrib_proc proc = lib.Procs().Get_by_key(proc_name);
|
||||
Scrib_proc_rslt proc_rslt = new Scrib_proc_rslt();
|
||||
proc.Proc_exec(new Scrib_proc_args(args), proc_rslt);
|
||||
return proc_rslt.Ary();
|
||||
}
|
||||
public static Object[] Kvp_vals_to_objs(KeyVal[] kvps) {
|
||||
int len = kvps.length;
|
||||
Object[] rv = new Object[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = kvps[i].Val();
|
||||
return rv;
|
||||
}
|
||||
public static String Kvp_vals_to_str(KeyVal[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
|
||||
KeyVal kv = ary[i];
|
||||
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(kv.Val()));
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
class Mock_server implements Scrib_server {
|
||||
public void Init(String... process_args) {}
|
||||
public int Server_timeout() {return server_timeout;} public Scrib_server Server_timeout_(int v) {server_timeout = v; return this;} private int server_timeout = 60;
|
||||
public int Server_timeout_polling() {return server_timeout_polling;} public Scrib_server Server_timeout_polling_(int v) {server_timeout_polling = v; return this;} private int server_timeout_polling = 1;
|
||||
public int Server_timeout_busy_wait() {return server_timeout_busy_wait;} public Scrib_server Server_timeout_busy_wait_(int v) {server_timeout_busy_wait = v; return this;} private int server_timeout_busy_wait = 1;
|
||||
public byte[] Server_comm(byte[] cmd, Object[] cmd_objs) {return Bry_.Empty;}
|
||||
public void Server_send(byte[] cmd, Object[] cmd_objs) {}
|
||||
public byte[] Server_recv() {return Bry_.Empty;}
|
||||
public void Term() {}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
|
||||
public class Scrib_lib_ustring__find__tst {
|
||||
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
}
|
||||
@Test public void Basic() {
|
||||
Exec_find("abcd" , "b" , 1, Bool_.N, "2;2"); // basic
|
||||
Exec_find("abac" , "a" , 2, Bool_.N, "3;3"); // bgn
|
||||
Exec_find("()()" , "(" , 2, Bool_.Y, "3;3"); // plain; note that ( would "break" regx
|
||||
Exec_find("a bcd e" , "(b(c)d)" , 2, Bool_.N, "3;5;bcd;c"); // groups
|
||||
Exec_find("a bcd e" , "()(b)" , 2, Bool_.N, "3;3;3;b"); // groups; empty capture
|
||||
Exec_find("abcd" , "x" , 1, Bool_.N, ""); // empty
|
||||
Exec_find("abcd" , "" , 2, Bool_.Y, "2;1"); // empty regx should return values; plain; EX:w:Fool's_mate; DATE:2014-03-04
|
||||
Exec_find("abcd" , "" , 2, Bool_.N, "2;1"); // empty regx should return values; regx; EX:w:Fool's_mate; DATE:2014-03-04
|
||||
Exec_find("abcd" , "^(c)" , 3, Bool_.N, "3;3;c"); // ^ should be converted to \G; regx; EX:cs.n:Category:1._září_2008; DATE:2014-05-07
|
||||
}
|
||||
@Test public void Arg_int() { // PURPOSE: allow int find; PAGE:ro.w:Innsbruck DATE:2015-09-12
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_(123, "2", 1, Bool_.N), "2;2");
|
||||
}
|
||||
@Test public void Return_int() {
|
||||
fxt.Test__proc__kvps__vals(lib, Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_("a", "()", 2, Bool_.N), 2, 1, 2);
|
||||
}
|
||||
@Test public void Surrogate() { // PURPOSE: handle surrogates in Find PAGE:zh.w:南北鐵路_(越南); DATE:2014-08-28
|
||||
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 1, Bool_.N, "4;4"); // 4 b/c \n starts at pos 4 (super 1)
|
||||
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 5, Bool_.N, "8;8"); // 8 b/c \n starts at pos 8 (super 1)
|
||||
}
|
||||
private void Exec_find(String text, String regx, int bgn, boolean plain, String expd) {
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_(text, regx, bgn, plain), expd);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
|
||||
public class Scrib_lib_ustring__gmatch__tst {
|
||||
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
}
|
||||
@Test public void Init__basic() {
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a(b)") , "1=a(b)\n2=\n 1=false");
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a()(b)") , "1=a()(b)\n2=\n 1=true\n 2=false");
|
||||
}
|
||||
@Test public void Callback__basic() {
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 0) , "1=2\n2=\n 1=b");
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 2) , "1=5\n2=\n 1=b");
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 8) , "1=8\n2=");
|
||||
}
|
||||
@Test public void Callback__nomatch() {// PURPOSE.fix: was originally returning "" instead of original String; EX:vi.d:trở_thành; DATE:2014-04-23
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , KeyVal_.Ary_empty, 0) , "1=1\n2=\n 1=a");
|
||||
}
|
||||
@Test public void Callback__anypos() {// PURPOSE.fix: was not handling $capt argument; EX:vi.d:trở_thành; DATE:2014-04-23
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a bcd e", "()(b)" , Scrib_kv_utl_.base1_many_(true, false), 0), String_.Concat_lines_nl_skip_last
|
||||
( "1=3"
|
||||
, "2="
|
||||
, " 1=3"
|
||||
, " 2=b"
|
||||
));
|
||||
}
|
||||
@Test public void Callback__text_as_number() { // PURPOSE: Gmatch_callback must be able to take non String value; DATE:2013-12-20
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary(1234, "1(2)", Scrib_kv_utl_.base1_many_(false), 0), String_.Concat_lines_nl_skip_last
|
||||
( "1=2"
|
||||
, "2="
|
||||
, " 1=2"
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.langs.regxs.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
|
||||
public class Scrib_lib_ustring__gsub__tst {
|
||||
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
}
|
||||
@Test public void Replace__basic() {
|
||||
Exec_gsub("abcd", "[a]" , -1, "A" , "Abcd;1");
|
||||
Exec_gsub("aaaa", "[a]" , 2, "A" , "AAaa;2");
|
||||
Exec_gsub("a" , "(a)" , 1, "%%%1" , "%a;1");
|
||||
Exec_gsub("à{b}c", "{b}" , 1, "b" , "àbc;1"); // utf8
|
||||
Exec_gsub("àbc", "^%s*(.-)%s*$" , 1, "%1" , "àbc;1"); // utf8; regx is for trim line
|
||||
Exec_gsub("a" , "[^]" , 1, "b" , "a;0"); // invalid regx should not fail; should return self; DATE:2013-10-20
|
||||
}
|
||||
@Test public void Replace__none() {// PURPOSE: gsub with no replace argument should not fail; EX:d:'orse; DATE:2013-10-14
|
||||
fxt.Test__proc__objs__flat(lib, Scrib_lib_ustring.Invk_gsub, Object_.Ary("text", "regx") , "text"); // NOTE: repl, limit deliberately omitted
|
||||
}
|
||||
@Test public void Replace__int() { // PURPOSE: do not fail if integer is passed in for @replace; PAGE:en.d:λύω DATE:2014-09-02
|
||||
Exec_gsub("abcd", 1 , -1, 1 , "abcd;0");
|
||||
}
|
||||
@Test public void Replace__table() {
|
||||
Exec_gsub("abcd", "[ac]" , -1, Scrib_kv_utl_.flat_many_("a", "A", "c", "C") , "AbCd;2");
|
||||
Exec_gsub("abc" , "[ab]" , -1, Scrib_kv_utl_.flat_many_("a", "A") , "Abc;2"); // PURPOSE: match not in regex should still print itself; in this case [c] is not in tbl regex; DATE:2014-03-31
|
||||
}
|
||||
@Test public void Replace__table__match() {// PURPOSE: replace using group, not found term; EX:"b" not "%b%" PAGE:en.w:Bannered_routes_of_U.S._Route_60; DATE:2014-08-15
|
||||
Exec_gsub("a%b%c", "%%(%w+)%%" , -1, Scrib_kv_utl_.flat_many_("b", "B") , "aBc;1");
|
||||
}
|
||||
@Test public void Replace__proc__recursive() { // PURPOSE:handle recursive gsub calls; PAGE:en.d:כלב; DATE:2016-01-22
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Mock_proc__recursive proc_lvl2 = new Mock_proc__recursive(fxt, lib, bfr, 2, null);
|
||||
Mock_proc__recursive proc_lvl1 = new Mock_proc__recursive(fxt, lib, bfr, 1, proc_lvl2);
|
||||
Mock_proc__recursive proc_root = new Mock_proc__recursive(fxt, lib, bfr, 0, proc_lvl1);
|
||||
fxt.Init__cbk(proc_root, proc_lvl1, proc_lvl2);
|
||||
Exec_gsub("ab", ".", -1, proc_root.To_scrib_lua_proc(), "ab;2"); // fails if "ab;4"
|
||||
Tfds.Eq_str("0;1;2;0;1;2;", bfr.To_str_and_clear()); // fails if "0;1;1;1"
|
||||
}
|
||||
@Test public void Regx__int() { // PURPOSE: do not fail if integer is passed in for @regx; PAGE:en.d:λύω DATE:2014-09-02
|
||||
Exec_gsub("abcd", 1 , -1, "A" , "abcd;0");
|
||||
}
|
||||
@Test public void Regx__dash() { // PURPOSE: "-" at end of regx should be literal; EX:[A-]; PAGE:en.d:frei DATE:2016-01-23
|
||||
Exec_gsub("abc", "[a-]", -1, "d", "dbc;1");
|
||||
}
|
||||
@Test public void Regx__word_class() { // PURPOSE: handle %w in extended regex; PAGE:en.w:A♯_(musical_note) DATE:2015-06-10
|
||||
Exec_gsub("(a b)", "[^%w%p%s]", -1, "x", "(a b);0"); // was returning "(x x)" b/c ^%w was incorrectly matching "a" and "b"
|
||||
}
|
||||
@Test public void Regx__balanced_group() { // PURPOSE: handle balanced group regex; EX:"%b()"; NOTE:test will fail if run in 1.6 environment; DATE:2013-12-20
|
||||
Exec_gsub("(a)", "%b()", 1, "c", "c;1");
|
||||
}
|
||||
@Test public void Regx__capture() {
|
||||
Exec_gsub("aa" , "(a)%1" , 1, "%0z", "aaz;1"); // capture; handle %0; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub("aa" , "(a)%1" , 1, "%1z", "az;1"); // capture; handle %1+; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub("a\"b'c\"d" , "([\"'])(.-)%1" , 1, "%1z", "a\"zd;1"); // capture; http://www.lua.org/pil/20.3.html; {{#invoke:test|gsub_string|a"b'c"d|(["'])(.-)%1|%1z}}
|
||||
}
|
||||
@Test public void Regx__frontier_pattern() { // PURPOSE: handle frontier pattern; EX:"%f[%a]"; DATE:2015-07-21
|
||||
Exec_gsub("a b c", "%f[%W]", 5, "()", "a() b() c();3");
|
||||
Exec_gsub("abC DEF gHI JKm NOP", "%f[%a]%u+%f[%A]", Int_.Max_value, "()", "abC () gHI JKm ();2"); // based on http://lua-users.org/wiki/FrontierPattern
|
||||
}
|
||||
@Test public void Regx__frontier_pattern_utl() {// PURPOSE: standalone test for \0 logic in frontier pattern; note that verified against PHP: echo(preg_match( "/[\w]/us", "\0" )); DATE:2015-07-21
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "a")); // \0 not matched by a
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "0")); // \0 not matched by numeric 0
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "[\\w]")); // \0 not matched by word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\W]")); // \0 matched by !word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\x]")); // \0 matched by any_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\X]")); // \0 matched by !any_char
|
||||
}
|
||||
private void Exec_gsub(String text, Object regx, int limit, Object repl, String expd) {
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, repl, limit), expd);
|
||||
}
|
||||
}
|
||||
class Mock_proc__recursive extends Mock_proc_fxt { private final Mock_scrib_fxt fxt; private final Scrib_lib lib; private final Mock_proc__recursive inner;
|
||||
private final Bry_bfr bfr;
|
||||
public Mock_proc__recursive(Mock_scrib_fxt fxt, Scrib_lib lib, Bry_bfr bfr, int id, Mock_proc__recursive inner) {super(id, "recur");
|
||||
this.fxt = fxt; this.lib = lib; this.inner = inner;
|
||||
this.bfr = bfr;
|
||||
}
|
||||
@Override public KeyVal[] Exec_by_scrib(KeyVal[] args) {
|
||||
bfr.Add_int_variable(this.Id()).Add_byte_semic();
|
||||
if (inner != null)
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_("a", ".", inner.To_scrib_lua_proc(), -1), "a;1");
|
||||
return args;
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.langs.regxs.*;
|
||||
public class Scrib_lib_ustring__lib_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear_for_lib();
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Find() {
|
||||
Exec_find("abcd" , "b" , 1, Bool_.N, "2;2"); // basic
|
||||
Exec_find("abac" , "a" , 2, Bool_.N, "3;3"); // bgn
|
||||
Exec_find("()()" , "(" , 2, Bool_.Y, "3;3"); // plain; note that ( would "break" regx
|
||||
Exec_find("a bcd e" , "(b(c)d)" , 2, Bool_.N, "3;5;bcd;c"); // groups
|
||||
Exec_find("a bcd e" , "()(b)" , 2, Bool_.N, "3;3;3;b"); // groups; empty capture
|
||||
Exec_find("abcd" , "x" , 1, Bool_.N, ""); // empty
|
||||
Exec_find("abcd" , "" , 2, Bool_.Y, "2;1"); // empty regx should return values; plain; EX:w:Fool's_mate; DATE:2014-03-04
|
||||
Exec_find("abcd" , "" , 2, Bool_.N, "2;1"); // empty regx should return values; regx; EX:w:Fool's_mate; DATE:2014-03-04
|
||||
Exec_find("abcd" , "^(c)" , 3, Bool_.N, "3;3;c"); // ^ should be converted to \G; regx; EX:cs.n:Category:1._září_2008; DATE:2014-05-07
|
||||
}
|
||||
@Test public void Find_int() { // PURPOSE: allow int find; PAGE:ro.w:Innsbruck DATE:2015-09-12
|
||||
fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_(123, "2", 1, Bool_.N), "2;2");
|
||||
}
|
||||
@Test public void Find_surrogate() { // PURPOSE: handle surrogates in Find PAGE:zh.w:南北鐵路_(越南); DATE:2014-08-28
|
||||
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 1, Bool_.N, "4;4"); // 4 b/c \n starts at pos 4 (super 1)
|
||||
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 5, Bool_.N, "8;8"); // 8 b/c \n starts at pos 8 (super 1)
|
||||
}
|
||||
@Test public void Match() {
|
||||
Exec_match("abcd" , "bc" , 1, "bc"); // basic
|
||||
Exec_match("abcd" , "x" , 1, String_.Null_mark); // empty
|
||||
Exec_match("abcd" , "a" , 2, String_.Null_mark); // bgn
|
||||
Exec_match("abcd" , "b(c)" , 1, "c"); // group
|
||||
Exec_match(" a b " , "^%s*(.-)%s*$" , 1, "a b;"); // trim; NOTE: changed from "a b" to "a b;"; DATE:2015-01-30
|
||||
Exec_match("abcd" , "a" , 0, "a"); // handle 0; note that php/lua is super-1, but some modules pass in 0; ru.w:Module:Infocards; DATE:2013-11-08
|
||||
Exec_match("abcd" , "." , -1, "d"); // -1
|
||||
Exec_match("aaa" , "a" , 1, "a"); // should return 1st match not many
|
||||
Exec_match("aaa" , "(a)" , 1, "a;a;a"); // should return all matches
|
||||
Exec_match("a b" , "%S" , 1, "a"); // %S was returning every match instead of 1st; PAGE:en.w:Bertrand_Russell; DATE:2014-04-02
|
||||
Exec_match(1 , "a" , 1, String_.Null_mark); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
||||
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
|
||||
}
|
||||
@Test public void Match_args_out_of_order() {
|
||||
fxt.Test_scrib_proc_empty(lib, Scrib_lib_ustring.Invk_match, KeyVal_.Ary(KeyVal_.int_(2, "[a]")));
|
||||
}
|
||||
@Test public void Gsub() {
|
||||
Exec_gsub_regx("abcd", "[a]" , -1, "A" , "Abcd;1");
|
||||
Exec_gsub_regx("aaaa", "[a]" , 2, "A" , "AAaa;2");
|
||||
Exec_gsub_regx("a" , "(a)" , 1, "%%%1" , "%a;1");
|
||||
Exec_gsub_regx("à{b}c", "{b}" , 1, "b" , "àbc;1"); // utf8
|
||||
Exec_gsub_regx("àbc", "^%s*(.-)%s*$", 1, "%1" , "àbc;1"); // utf8; regx is for trim line
|
||||
Exec_gsub_regx("a" , "[^]" , 1, "b" , "a;0"); // invalid regx should not fail; should return self; DATE:2013-10-20
|
||||
}
|
||||
@Test public void Gsub_table() {
|
||||
Exec_gsub_regx("abcd", "[ac]" , -1, Scrib_kv_utl_.flat_many_("a", "A", "c", "C") , "AbCd;2");
|
||||
Exec_gsub_regx("abc" , "[ab]" , -1, Scrib_kv_utl_.flat_many_("a", "A") , "Abc;2"); // PURPOSE: match not in regex should still print itself; in this case [c] is not in tbl regex; DATE:2014-03-31
|
||||
}
|
||||
@Test public void Gsub_table_match() { // PURPOSE: replace using group, not found term; EX:"b" not "%b%" PAGE:en.w:Bannered_routes_of_U.S._Route_60; DATE:2014-08-15
|
||||
Exec_gsub_regx("a%b%c", "%%(%w+)%%" , -1, Scrib_kv_utl_.flat_many_("b", "B") , "aBc;1");
|
||||
}
|
||||
@Test public void Gsub_capture() {
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%0z", "aaz;1"); // capture; handle %0; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%1z", "az;1"); // capture; handle %1+; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub_regx("a\"b'c\"d" , "([\"'])(.-)%1" , 1, "%1z", "a\"zd;1"); // capture; http://www.lua.org/pil/20.3.html; {{#invoke:test|gsub_string|a"b'c"d|(["'])(.-)%1|%1z}}
|
||||
}
|
||||
@Test public void Gsub_no_replace() {// PURPOSE: gsub with no replace argument should not fail; EX:d:'orse; DATE:2013-10-14
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gsub, Object_.Ary("text", "regx") , "1=text"); // NOTE: repl, limit deliberately omitted
|
||||
}
|
||||
@Test public void Gsub_pattern_is_int() { // PURPOSE: do not fail if integer is passed in for @regx; PAGE:en.d:λύω DATE:2014-09-02
|
||||
Exec_gsub_regx("abcd", 1 , -1, "A" , "abcd;0");
|
||||
}
|
||||
@Test public void Gsub_replace_is_int() { // PURPOSE: do not fail if integer is passed in for @replace; PAGE:en.d:λύω DATE:2014-09-02
|
||||
Exec_gsub_regx("abcd", 1 , -1, 1 , "abcd;0");
|
||||
}
|
||||
@Test public void Gsub_word_class() { // PURPOSE: handle %w in extended regex; PAGE:en.w:A♯_(musical_note) DATE:2015-06-10
|
||||
Exec_gsub_regx("(a b)", "[^%w%p%s]", -1, "x", "(a b);0"); // was returning "(x x)" b/c ^%w was incorrectly matching "a" and "b"
|
||||
}
|
||||
@Test public void Gmatch_init() {
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a(b)") , "1=a(b)\n2=\n 1=false");
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a()(b)") , "1=a()(b)\n2=\n 1=true\n 2=false");
|
||||
}
|
||||
@Test public void Gmatch_callback() {
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 0) , "1=2\n2=\n 1=b");
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 2) , "1=5\n2=\n 1=b");
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 8) , "1=8\n2=");
|
||||
}
|
||||
@Test public void Gmatch_callback_nomatch() {// PURPOSE.fix: was originally returning "" instead of original String; EX:vi.d:trở_thành; DATE:2014-04-23
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , KeyVal_.Ary_empty, 0) , "1=1\n2=\n 1=a");
|
||||
}
|
||||
@Test public void Gmatch_callback_anypos() {// PURPOSE.fix: was not handling $capt argument; EX:vi.d:trở_thành; DATE:2014-04-23
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a bcd e", "()(b)" , Scrib_kv_utl_.base1_many_(true, false), 0), String_.Concat_lines_nl_skip_last
|
||||
( "1=3"
|
||||
, "2="
|
||||
, " 1=3"
|
||||
, " 2=b"
|
||||
));
|
||||
}
|
||||
@Test public void Gsub_balanced_group() { // PURPOSE: handle balanced group regex; EX:"%b()"; NOTE:test will fail if run in 1.6 environment; DATE:2013-12-20
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx("(a)", "%b()", 1, "c", "c;1");
|
||||
}
|
||||
@Test public void Gmatch_callback__text_as_number() { // PURPOSE: Gmatch_callback must be able to take non String value; DATE:2013-12-20
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary(1234, "1(2)", Scrib_kv_utl_.base1_many_(false), 0), String_.Concat_lines_nl_skip_last
|
||||
( "1=2"
|
||||
, "2="
|
||||
, " 1=2"
|
||||
));
|
||||
}
|
||||
@Test public void Gsub_frontier_pattern() { // PURPOSE: handle frontier pattern; EX:"%f[%a]"; DATE:2015-07-21
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx("a b c", "%f[%W]", 5, "()", "a() b() c();3");
|
||||
Exec_gsub_regx("abC DEF gHI JKm NOP", "%f[%a]%u+%f[%A]", Int_.Max_value, "()", "abC () gHI JKm ();2"); // based on http://lua-users.org/wiki/FrontierPattern
|
||||
}
|
||||
@Test public void Gsub_frontier_pattern_utl() {// PURPOSE: standalone test for \0 logic in frontier pattern; note that verified against PHP: echo(preg_match( "/[\w]/us", "\0" )); DATE:2015-07-21
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "a")); // \0 not matched by a
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "0")); // \0 not matched by numeric 0
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "[\\w]")); // \0 not matched by word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\W]")); // \0 matched by !word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\x]")); // \0 matched by any_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\X]")); // \0 matched by !any_char
|
||||
}
|
||||
// @Test public void Match_viwiktionary() {
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||
// Exec_match("tr" , "()(r)", 1, ";"); // should return all matches
|
||||
// Exec_match("tr" , "^([b]*).-([c]*)$", 1, ";"); // should return all matches
|
||||
// }
|
||||
private void Exec_find(String text, String regx, int bgn, boolean plain, String expd) {
|
||||
fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_(text, regx, bgn, plain), expd);
|
||||
}
|
||||
private void Exec_match(Object text, String regx, int bgn, String expd) {
|
||||
fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn), expd);
|
||||
}
|
||||
private void Exec_gsub_regx(String text, Object regx, int limit, Object repl, String expd) {Exec_gsub(text, regx, limit, repl, expd);}
|
||||
private void Exec_gsub(String text, Object regx, int limit, Object repl, String expd) {
|
||||
fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, repl, limit), expd);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
|
||||
public class Scrib_lib_ustring__match__tst {
|
||||
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
}
|
||||
@Test public void Basic() {
|
||||
Exec_match("abcd" , "bc" , 1, "bc"); // basic
|
||||
Exec_match("abcd" , "x" , 1, String_.Null_mark); // empty
|
||||
Exec_match("abcd" , "a" , 2, String_.Null_mark); // bgn
|
||||
Exec_match("abcd" , "b(c)" , 1, "c"); // group
|
||||
Exec_match(" a b " , "^%s*(.-)%s*$" , 1, "a b;"); // trim; NOTE: changed from "a b" to "a b;"; DATE:2015-01-30
|
||||
Exec_match("abcd" , "a" , 0, "a"); // handle 0; note that php/lua is super-1, but some modules pass in 0; ru.w:Module:Infocards; DATE:2013-11-08
|
||||
Exec_match("abcd" , "." , -1, "d"); // -1
|
||||
Exec_match("aaa" , "a" , 1, "a"); // should return 1st match not many
|
||||
Exec_match("aaa" , "(a)" , 1, "a;a;a"); // should return all matches
|
||||
Exec_match("a b" , "%S" , 1, "a"); // %S was returning every match instead of 1st; PAGE:en.w:Bertrand_Russell; DATE:2014-04-02
|
||||
Exec_match(1 , "a" , 1, String_.Null_mark); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
||||
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
|
||||
}
|
||||
@Test public void Args_out_of_order() {
|
||||
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, KeyVal_.Ary(KeyVal_.int_(2, "[a]")));
|
||||
}
|
||||
// @Test public void Match_viwiktionary() {
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||
// Exec_match("tr" , "()(r)", 1, ";"); // should return all matches
|
||||
// Exec_match("tr" , "^([b]*).-([c]*)$", 1, ";"); // should return all matches
|
||||
// }
|
||||
private void Exec_match(Object text, String regx, int bgn, String expd) {
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn), expd);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue