mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.2.1
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.xtns.gallery.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.poems.*; import gplx.xowa.xtns.hiero.*;
|
||||
import gplx.xowa.xtns.scores.*; import gplx.xowa.xtns.listings.*; import gplx.xowa.xtns.titleBlacklists.*;
|
||||
import gplx.xowa.xtns.scores.*; import gplx.xowa.xtns.listings.*; import gplx.xowa.xtns.titleBlacklists.*; import gplx.xowa.xtns.pfuncs.scribunto.*;
|
||||
public class Xow_xtn_mgr implements GfoInvkAble {
|
||||
private OrderedHash regy = OrderedHash_.new_bry_();
|
||||
public int Count() {return regy.Count();}
|
||||
@@ -31,6 +31,7 @@ public class Xow_xtn_mgr implements GfoInvkAble {
|
||||
Add(app, new Score_xtn_mgr());
|
||||
Add(app, new Listing_xtn_mgr());
|
||||
Add(app, new Blacklist_xtn_mgr());
|
||||
Add(app, new Pfunc_xtn_mgr());
|
||||
return this;
|
||||
}
|
||||
public Xow_xtn_mgr Ctor_by_wiki(Xow_wiki wiki) {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_mgr {
|
||||
private Hash_adp_bry grps = Hash_adp_bry.ci_();
|
||||
private Hash_adp_bry grps = Hash_adp_bry.cs_(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);
|
||||
private int uid_last;
|
||||
public int Tag__next_id() {return ++tag__next_id;} private int tag__next_id = 0;
|
||||
|
||||
@@ -26,8 +26,8 @@ public class Ref_itm_mgr_tst {
|
||||
@Test public void Follow() {fxt.run_Add("key_1").run_Add_follow("key_1").tst(fxt.itm_("key_1", 0, 0).Related_(fxt.itm_uid_(1).Idx_minor_follow_()));}
|
||||
}
|
||||
class Ref_itm_mgr_fxt {
|
||||
Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
private Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public Xtn_ref_nde_chkr itm_uid_(int uid) {return itm_(null, -1, uid);}
|
||||
public Xtn_ref_nde_chkr itm_(String key, int idx) {return itm_(key, idx, -1);}
|
||||
public Xtn_ref_nde_chkr itm_(String key, int idx, int uid) {return new Xtn_ref_nde_chkr().Key_(key).Idx_major_(idx).Uid_(uid);}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (ctx.Tid_is_popup()) return;
|
||||
Xop_xatr_itm.Xatr_parse(wiki.App(), this, wiki.Lang().Xatrs_ref(), wiki, src, xnde);
|
||||
Xop_xatr_itm.Xatr_parse(wiki.App(), this, xatrs_hash, wiki, src, xnde);
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair)
|
||||
body = wiki.Parser().Parse_text_to_wdom_old_ctx(ctx, Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
||||
byte[] references_group = ctx.References_group(); // set by <references>
|
||||
@@ -76,4 +76,9 @@ public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
public static final byte Xatr_id_name = 0, Xatr_id_group = 1, Xatr_id_follow = 2;
|
||||
public static final int Idx_minor_follow = -2;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_obj("name", Byte_obj_val.new_(Ref_nde.Xatr_id_name))
|
||||
.Add_str_obj("group", Byte_obj_val.new_(Ref_nde.Xatr_id_group))
|
||||
.Add_str_obj("follow", Byte_obj_val.new_(Ref_nde.Xatr_id_follow));
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
Ref_itm_mgr ref_mgr = ctx.Cur_page().Ref_mgr();
|
||||
if (ref_mgr.References__recursing()) return; // skip nested <references> else refs will be lost; EX:"<references><references/></references>"; PAGE:en.w:Hwair; DATE:2014-06-27
|
||||
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag_div); // xnde generates <block_node>; <references> -> <ol>; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17
|
||||
Xop_xatr_itm.Xatr_parse(wiki.App(), this, wiki.Lang().Xatrs_references(), wiki, src, xnde);
|
||||
Xop_xatr_itm.Xatr_parse(wiki.App(), this, xatrs_hash, wiki, src, xnde);
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) { // "<references>", "</references>"; parse anything in between but only to pick up <ref> tags; discard everything else; DATE:2014-06-27
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
Xop_ctx references_ctx = Xop_ctx.new_sub_(wiki).References_group_(group);
|
||||
@@ -56,4 +56,6 @@ public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
public static final byte Xatr_id_group = 0;
|
||||
public static boolean Enabled = true;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_obj("group", Byte_obj_val.new_(References_nde.Xatr_id_group));
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class Dpl_itm {
|
||||
else
|
||||
usr_dlg.Warn_many("", "", err_msg);
|
||||
}
|
||||
private static final Hash_adp_bry Known_invalid_keys = Hash_adp_bry.ci_()
|
||||
private static final Hash_adp_bry Known_invalid_keys = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_obj("orcer" , Bool_obj_val.True) // ignore as per http://en.wikinews.org/wiki/Template_talk:United_States; (Note it doesn't make a difference, as categoryadd is the default order method.)
|
||||
.Add_str_obj("addcategorydatefirst" , Bool_obj_val.True)
|
||||
.Add_str_obj("mainspace" , Bool_obj_val.True)
|
||||
|
||||
@@ -78,7 +78,7 @@ class Dpl_itm_keys {
|
||||
, Key_false = 40
|
||||
, Key_true = 41
|
||||
;
|
||||
private static final Hash_adp_bry keys = Hash_adp_bry.ci_()
|
||||
private static final Hash_adp_bry keys = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("category", Dpl_itm_keys.Key_category)
|
||||
.Add_str_byte("notcategory", Dpl_itm_keys.Key_notcategory)
|
||||
.Add_str_byte("namespace", Dpl_itm_keys.Key_ns)
|
||||
|
||||
@@ -16,10 +16,11 @@ 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.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Gallery_itm_parser {
|
||||
private Xow_wiki wiki; private ByteTrieMgr_slim trie = ByteTrieMgr_slim.ci_utf_8_();
|
||||
private Xow_wiki wiki; private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_utf_8_();
|
||||
private Gallery_itm cur_itm;
|
||||
private byte[] src; private int end_pos;
|
||||
private int cur_pos; private byte cur_byte;
|
||||
@@ -95,7 +96,7 @@ public class Gallery_itm_parser {
|
||||
case Mode_eos:
|
||||
return mode;
|
||||
}
|
||||
Object o = trie.Match(cur_byte, src, cur_pos, end_pos);
|
||||
Object o = trie.Match_bgn_w_byte(cur_byte, src, cur_pos, end_pos);
|
||||
if (o != null) { // either "alt" or "link"
|
||||
int old_pos = cur_pos;
|
||||
cur_pos = trie.Match_pos();
|
||||
@@ -224,7 +225,7 @@ public class Gallery_itm_parser {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_kwd_itm itm = itms[i];
|
||||
byte[] itm_bry = Xol_kwd_parse_data.Strip(caption_bfr, itm.Val(), tmp_bref); // strip off =$1 for "alt=$1"
|
||||
trie.Add(itm_bry, trie_ref);
|
||||
trie.Add_obj(itm_bry, trie_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class Gallery_mgr_base_ {
|
||||
, Packed_hover_bry = Bry_.new_ascii_("packed-hover")
|
||||
, Packed_overlay_bry = Bry_.new_ascii_("packed-overlay")
|
||||
;
|
||||
private static final Hash_adp_bry Hash = Hash_adp_bry.ci_()
|
||||
private static final Hash_adp_bry Hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Traditional_bry , Traditional_tid)
|
||||
.Add_bry_byte(Nolines_bry , Nolines_tid)
|
||||
.Add_bry_byte(Packed_bry , Packed_tid)
|
||||
|
||||
@@ -114,7 +114,7 @@ class Gallery_xnde_atrs {
|
||||
, Style_tid = 6
|
||||
, Class_tid = 7
|
||||
;
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.ci_()
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("mode" , Mode_tid)
|
||||
.Add_str_byte("perrow" , Perrow_tid)
|
||||
.Add_str_byte("widths" , Widths_tid)
|
||||
|
||||
@@ -16,9 +16,9 @@ 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.hiero; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.html.*; import gplx.xowa.html.*;
|
||||
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.html.*;
|
||||
class Hiero_parser {
|
||||
private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
private ListAdp blocks = ListAdp_.new_();
|
||||
private Hiero_block cur_block;
|
||||
private Bry_bfr cur_tkn = Bry_bfr.reset_(16);
|
||||
@@ -30,7 +30,7 @@ class Hiero_parser {
|
||||
while (true) {
|
||||
if (pos == end) break;
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match(b, src, pos, end);
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, end);
|
||||
if (o == null) {
|
||||
New_char(b);
|
||||
++pos;
|
||||
@@ -114,7 +114,7 @@ class Hiero_parser {
|
||||
String key_str = keys[i];
|
||||
byte[] key_bry = Bry_.new_utf8_(key_str);
|
||||
Hiero_parser_itm itm = new Hiero_parser_itm(tid, key_bry);
|
||||
trie.Add(key_bry, itm);
|
||||
trie.Add_obj(key_bry, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_html_bldr.java
Normal file
56
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_html_bldr.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.imageMap; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
class Imap_html_bldr {
|
||||
private Pts_fmtr_arg pts_fmtr_arg = new Pts_fmtr_arg();
|
||||
public void Bld_map(Bry_bfr rslt_bfr, Xow_wiki wiki, Imap_itm[] itms) {
|
||||
int itms_len = itms.length;
|
||||
// Imap_itm img_itm = itms[0];
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Imap_itm itm = itms[i];
|
||||
switch (itm.Itm_tid()) {
|
||||
case Imap_itm_.Tid_shape_dflt:
|
||||
case Imap_itm_.Tid_shape_rect:
|
||||
case Imap_itm_.Tid_shape_circle:
|
||||
case Imap_itm_.Tid_shape_poly:
|
||||
Bld_map_shape(rslt_bfr, wiki, (Imap_itm_shape)itm);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Bld_map_shape(Bry_bfr rslt_bfr, Xow_wiki wiki, Imap_itm_shape itm) {
|
||||
byte[] shape_name = Imap_itm_.Xto_str(itm.Itm_tid());
|
||||
pts_fmtr_arg.Init(itm.Shape_pts());
|
||||
area_fmtr.Bld_bfr_many(rslt_bfr, itm.Shape_link_href(), itm.Shape_link_caption(), shape_name, pts_fmtr_arg);
|
||||
}
|
||||
private static final Bry_fmtr area_fmtr = Bry_fmtr.new_
|
||||
("<area href=\"~{href}\" shape=\"~{shape}\" coords=\"~{pts}\" alt=\"{caption}\" title=\"~{caption}\"/>"
|
||||
, "href", "caption", "shape", "pts"
|
||||
);
|
||||
}
|
||||
class Pts_fmtr_arg implements Bry_fmtr_arg {
|
||||
private Double_obj_val[] pts;
|
||||
public void Init(Double_obj_val[] pts) {this.pts = pts;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
int pts_len = pts.length;
|
||||
for (int i = 0; i < pts_len; ++i) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
|
||||
bfr.Add_double(pts[i].Val());
|
||||
}
|
||||
}
|
||||
}
|
||||
177
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_itm_parser.java
Normal file
177
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_itm_parser.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
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.imageMap; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
class Imap_itm_parser {
|
||||
private Xoa_url page_url; private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._;
|
||||
private ListAdp itms = ListAdp_.new_();
|
||||
private ListAdp pts = ListAdp_.new_();
|
||||
private ListAdp errs = ListAdp_.new_();
|
||||
private byte[] src; // private int src_bgn, src_end;
|
||||
private int itm_idx; private int itm_bgn, itm_end;
|
||||
private Xoa_app app; private Xow_wiki wiki; private Xop_ctx imap_ctx; private Xop_root_tkn imap_root;
|
||||
public void Init(Xow_wiki wiki, Xoa_url page_url, Gfo_usr_dlg usr_dlg) {
|
||||
this.app = wiki.App(); this.wiki = wiki; this.page_url = page_url; this.usr_dlg = usr_dlg;
|
||||
if (imap_ctx == null) {
|
||||
imap_ctx = Xop_ctx.new_(wiki);
|
||||
imap_root = app.Tkn_mkr().Root(Bry_.Empty);
|
||||
}
|
||||
}
|
||||
public void Clear() {
|
||||
this.itm_idx = 0; itms.Clear();
|
||||
pts.Clear();
|
||||
errs.Clear();
|
||||
}
|
||||
public ListAdp Errs() {return errs;}
|
||||
public Imap_itm[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
this.Clear();
|
||||
this.src = src; // this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
itm_bgn = src_bgn; itm_end = src_bgn - 1;
|
||||
while (true) {
|
||||
if (itm_end == src_end) break;
|
||||
itm_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_end + 1, src_end); // trim ws at start, and look for first char
|
||||
if (itm_bgn == src_end) break; // line is entirely ws and terminated by eos; EX: "\n EOS"
|
||||
itm_end = Bry_finder.Find_fwd_until(src, itm_bgn, src_end, Byte_ascii.NewLine); // look for \n
|
||||
if (itm_end == Bry_finder.Not_found) itm_end = src_end; // no \n; make EOS \n
|
||||
itm_end = Bry_finder.Trim_bwd_space_tab(src, itm_end, itm_bgn); // trim any ws at end
|
||||
if (itm_end - itm_bgn == 0) continue; // line is entirely ws; continue;
|
||||
byte b = src[itm_bgn];
|
||||
if (b == Byte_ascii.Hash) {
|
||||
Parse_comment(itm_bgn, itm_end);
|
||||
continue;
|
||||
}
|
||||
if (itm_idx == 0)
|
||||
Parse_img(itm_bgn, itm_end);
|
||||
else {
|
||||
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, itm_bgn, itm_end);
|
||||
byte tid_val = tid_obj == null ? Imap_itm_.Tid_invalid : ((Byte_obj_val)tid_obj).Val();
|
||||
int tid_end_pos = tid_trie.Match_pos();
|
||||
switch (tid_val) {
|
||||
case Imap_itm_.Tid_desc: Parse_desc(itm_bgn, itm_end); break;
|
||||
case Imap_itm_.Tid_shape_dflt: Parse_shape(tid_val, tid_end_pos, itm_end, Reqd_dflt); break;
|
||||
case Imap_itm_.Tid_shape_rect: Parse_shape(tid_val, tid_end_pos, itm_end, 4); break;
|
||||
case Imap_itm_.Tid_shape_poly: Parse_shape(tid_val, tid_end_pos, itm_end, Reqd_poly); break;
|
||||
case Imap_itm_.Tid_shape_circle: Parse_shape(tid_val, tid_end_pos, itm_end, 3); break;
|
||||
default:
|
||||
case Imap_itm_.Tid_invalid: Parse_invalid(itm_bgn, itm_end); break;
|
||||
}
|
||||
}
|
||||
++itm_idx;
|
||||
}
|
||||
return (Imap_itm[])itms.XtoAryAndClear(Imap_itm.class);
|
||||
}
|
||||
private void Parse_comment(int itm_bgn, int itm_end) {} // noop comments; EX: "# comment\n"
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_utf8_(src, itm_bgn, itm_end));}
|
||||
private void Parse_desc(int itm_bgn, int itm_end) {itms.Add(new Imap_itm_desc(itm_idx, itm_bgn, itm_end));}
|
||||
private void Parse_shape(byte shape_tid, int itm_bgn, int itm_end, int reqd_pts) {
|
||||
int num_bgn = -1; // differs from MW parser which loks for link via regx, and then chops off rest; regx is difficult due to lnke; doing opposite approach which is eat numbers until something else
|
||||
int pos = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end);
|
||||
boolean reading_numbers = true;
|
||||
while (reading_numbers) {
|
||||
boolean last = pos == itm_end;
|
||||
byte b = last ? Byte_ascii.Space : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Dash: case Byte_ascii.Dot:
|
||||
if (num_bgn == -1)
|
||||
num_bgn = pos;
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
int new_pos = Parse_shape_num(num_bgn, pos, itm_end);
|
||||
if (new_pos == -1) {Add_err("imagemap_invalid_coord", itm_bgn, itm_end); return;}
|
||||
if (new_pos == pos)
|
||||
reading_numbers = false;
|
||||
else
|
||||
pos = Bry_finder.Trim_fwd_space_tab(src, new_pos, itm_end);
|
||||
num_bgn = -1;
|
||||
break;
|
||||
}
|
||||
if (last) reading_numbers = false;
|
||||
}
|
||||
int pts_len = pts.Count();
|
||||
switch (reqd_pts) {
|
||||
case Reqd_poly: {
|
||||
if (pts_len == 0) {Add_err("imagemap_missing_coord", itm_bgn, itm_end); return;}
|
||||
else if (pts_len % 2 != 0) {Add_err("imagemap_poly_odd", itm_bgn, itm_end); return;}
|
||||
break;
|
||||
}
|
||||
case Reqd_dflt: {
|
||||
pts.Clear(); // dflt should have 0 points; if any defined, ignore them; clearing list for purpose of test
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (reqd_pts != pts_len) {Add_err("imagemap_missing_coord", itm_bgn, itm_end); return;}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos = Bry_finder.Trim_fwd_space_tab(src, pos, itm_end);
|
||||
Imap_itm_shape shape_itm = new Imap_itm_shape(itm_idx, itm_bgn, itm_end, shape_tid, (Double_obj_val[])pts.XtoAryAndClear(Double_obj_val.class));
|
||||
Xop_tkn_itm link_tkn = Parse_link(pos, itm_end);
|
||||
shape_itm.Shape_link_(app, wiki, src, link_tkn);
|
||||
itms.Add(shape_itm);
|
||||
}
|
||||
private void Add_err(String err_key, int bgn, int end) {
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_utf8_(src, bgn, end));
|
||||
errs.Add(new Imap_itm_err(itm_idx, err_key));
|
||||
}
|
||||
private Xop_tkn_itm Parse_link(int link_bgn, int link_end) {
|
||||
imap_root.Clear();
|
||||
imap_ctx.Clear();
|
||||
wiki.Parser().Parse_to_src_end(imap_root, imap_ctx, wiki.App().Tkn_mkr(), src, wiki.Parser().Wtxt_trie(), link_bgn, link_end);
|
||||
int subs_len = imap_root.Subs_len();
|
||||
for (int i = 0; i < subs_len; ++i) {
|
||||
Xop_tkn_itm sub = imap_root.Subs_get(i);
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_lnki:
|
||||
case Xop_tkn_itm_.Tid_lnke:
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private int Parse_shape_num(int num_bgn, int num_end, int itm_end) {
|
||||
if (num_bgn == -1) return num_end;
|
||||
double num = Bry_.XtoDoubleByPosOr(src, num_bgn, num_end, Double_.NaN);
|
||||
if (Double_.IsNaN(num)) return -1; // invalid number; EX: "1.2.3"
|
||||
pts.Add(Double_obj_val.new_(num));
|
||||
return Bry_finder.Trim_fwd_space_tab(src, num_end, itm_end);
|
||||
}
|
||||
|
||||
private void Parse_img(int itm_bgn, int itm_end) {
|
||||
int pos = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end);
|
||||
Xop_tkn_itm link_tkn = Parse_link(pos, itm_end);
|
||||
Imap_itm_img itm = new Imap_itm_img(itm_idx, itm_bgn, itm_end, link_tkn);
|
||||
itms.Add(itm);
|
||||
}
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // NOTE: names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add_str_byte("desc" , Imap_itm_.Tid_desc)
|
||||
.Add_str_byte("#" , Imap_itm_.Tid_comment)
|
||||
.Add_bry_bval(Imap_itm_.Tid_name_default , Imap_itm_.Tid_shape_dflt)
|
||||
.Add_bry_bval(Imap_itm_.Tid_name_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_bval(Imap_itm_.Tid_name_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_bval(Imap_itm_.Tid_name_poly , Imap_itm_.Tid_shape_poly)
|
||||
;
|
||||
private static final int Reqd_poly = -1, Reqd_dflt = -2;
|
||||
}
|
||||
class Imap_itm_err {
|
||||
public Imap_itm_err(int itm_idx, String err_key) {this.itm_idx = itm_idx; this.err_key = err_key;}
|
||||
public int Itm_idx() {return itm_idx;} private int itm_idx;
|
||||
public String Err_key() {return err_key;} private String err_key;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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.imageMap; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Imap_itm_parser_tst {
|
||||
@Before public void init() {fxt.Reset();} private Imap_itm_parser_fxt fxt = new Imap_itm_parser_fxt();
|
||||
@Test public void Dflt_pass() {fxt.Test_shape("default [[A]]" , fxt.itm_dflt_("[[A]]"));}
|
||||
@Test public void Dflt_ignore_points() {fxt.Test_shape("default 1 2 3 [[A]]" , fxt.itm_dflt_("[[A]]"));}
|
||||
@Test public void Rect_pass() {fxt.Test_shape("rect 1 2 3 4 [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));}
|
||||
@Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));}
|
||||
@Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));}
|
||||
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
|
||||
@Test public void Poly_fail_zero() {fxt.Test_shape_err("poly [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Poly_fail_invalid() {fxt.Test_shape_err("poly 1 2..3 [[A]]" , "imagemap_invalid_coord");}
|
||||
}
|
||||
class Imap_itm_parser_fxt {
|
||||
private Xoa_app app; private Xow_wiki wiki;
|
||||
private Imap_itm_parser parser = new Imap_itm_parser();
|
||||
public void Reset() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
Xoa_url url = Xoa_url.new_(wiki.Domain_bry(), Bry_.new_ascii_("Test_1"));
|
||||
parser.Init(wiki, url, Gfo_usr_dlg_.Null);
|
||||
parser.Clear();
|
||||
}
|
||||
public Imap_itm_shape itm_dflt_(String link) {return itm_shape_(Imap_itm_.Tid_shape_dflt, link);}
|
||||
public Imap_itm_shape itm_rect_(String link, int... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_rect, link, pts_ary);}
|
||||
public Imap_itm_shape itm_circle_(String link, int... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_circle, link, pts_ary);}
|
||||
public Imap_itm_shape itm_poly_(String link, int... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_poly, link, pts_ary);}
|
||||
private Imap_itm_shape itm_shape_(byte tid, String link, int... pts_ary) {
|
||||
int pts_len = pts_ary.length;
|
||||
Double_obj_val[] pts_doubles = new Double_obj_val[pts_len];
|
||||
for (int i = 0; i < pts_len; ++i)
|
||||
pts_doubles[i] = Double_obj_val.new_(pts_ary[i]);
|
||||
byte[] link_bry = Bry_.new_utf8_(link);
|
||||
Xop_tkn_itm link_tkn = app.Tkn_mkr().Bry(-1, -1, link_bry);
|
||||
Imap_itm_shape rv = new Imap_itm_shape(0, 0, link_bry.length, tid, pts_doubles);
|
||||
rv.Shape_link_(app, wiki, link_bry, link_tkn);
|
||||
return rv;
|
||||
}
|
||||
public void Test_shape(String raw_str, Imap_itm_shape expd) {
|
||||
raw_str = "File:A.png\n" + raw_str;
|
||||
byte[] raw = Bry_.new_utf8_(raw_str);
|
||||
Imap_itm[] actl_ary = parser.Parse(raw, 0, raw.length);
|
||||
Imap_itm_shape actl = actl_ary == null | actl_ary.length != 2 ? null : (Imap_itm_shape)actl_ary[1];
|
||||
if (actl == null && expd == null) {} // noop; test passed
|
||||
else if (actl == null && expd != null) {Tfds.Fail("actl should not be null", raw);}
|
||||
else if (actl != null && expd == null) {Tfds.Fail("actl should be null", raw);}
|
||||
else {
|
||||
Tfds.Eq(expd.Itm_tid(), actl.Itm_tid(), "tid");
|
||||
Tfds.Eq_ary(expd.Shape_pts(), actl.Shape_pts(), "pts");
|
||||
Xop_bry_tkn expd_link_tkn = ((Xop_bry_tkn)expd.Shape_link());
|
||||
String expd_link = String_.new_utf8_(expd_link_tkn.Val());
|
||||
String actl_link = String_.new_utf8_(raw, actl.Shape_link().Src_bgn(), actl.Shape_link().Src_end());
|
||||
Tfds.Eq(expd_link, actl_link);
|
||||
}
|
||||
Tfds.Eq(0, parser.Errs().Count(), "expd 0 errors");
|
||||
}
|
||||
public void Test_shape_err(String raw_str, String expd_err) {
|
||||
raw_str = "File:A.png\n" + raw_str;
|
||||
byte[] raw = Bry_.new_utf8_(raw_str);
|
||||
parser.Parse(raw, 0, raw.length);
|
||||
Imap_itm_err[] err_ary = (Imap_itm_err[])parser.Errs().XtoAryAndClear(Imap_itm_err.class);
|
||||
Tfds.Eq(1, err_ary.length, "expd 1 err");
|
||||
Tfds.Eq(expd_err, err_ary[0].Err_key());
|
||||
}
|
||||
}
|
||||
95
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_line.java
Normal file
95
400_xowa/src/gplx/xowa/xtns/imageMap/Imap_line.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.imageMap; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
interface Imap_itm {
|
||||
byte Itm_tid();
|
||||
int Itm_idx();
|
||||
int Src_bgn();
|
||||
int Src_end();
|
||||
}
|
||||
class Imap_itm_ {
|
||||
public static final byte Tid_invalid = 0, Tid_img = 1, Tid_desc = 2, Tid_comment = 3, Tid_shape_dflt = 4, Tid_shape_rect = 5, Tid_shape_circle = 6, Tid_shape_poly = 7;
|
||||
public static final byte[]
|
||||
Tid_name_default = Bry_.new_ascii_("default")
|
||||
, Tid_name_rect = Bry_.new_ascii_("rect")
|
||||
, Tid_name_circle = Bry_.new_ascii_("circle")
|
||||
, Tid_name_poly = Bry_.new_ascii_("poly")
|
||||
;
|
||||
public static byte[] Xto_str(byte v) {
|
||||
switch (v) {
|
||||
case Tid_shape_dflt : return Tid_name_default;
|
||||
case Tid_shape_rect : return Tid_name_rect;
|
||||
case Tid_shape_circle : return Tid_name_circle;
|
||||
case Tid_shape_poly : return Tid_name_poly;
|
||||
default : throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
abstract class Imap_itm_base implements Imap_itm {
|
||||
public abstract byte Itm_tid();
|
||||
public void Ctor(int itm_idx, int src_bgn, int src_end) {this.itm_idx = itm_idx; this.src_bgn = src_bgn; this.src_end = src_end;}
|
||||
public int Itm_idx() {return itm_idx;} private int itm_idx;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
}
|
||||
class Imap_itm_img extends Imap_itm_base {
|
||||
public Imap_itm_img(int itm_idx, int src_bgn, int src_end, Xop_tkn_itm img_link) {
|
||||
this.Ctor(itm_idx, src_bgn, src_end);
|
||||
this.img_link = img_link;
|
||||
}
|
||||
public Xop_tkn_itm Img_link() {return img_link;} private Xop_tkn_itm img_link;
|
||||
@Override public byte Itm_tid() {return Imap_itm_.Tid_img;}
|
||||
}
|
||||
class Imap_itm_desc extends Imap_itm_base {
|
||||
public Imap_itm_desc(int itm_idx, int src_bgn, int src_end) {this.Ctor(itm_idx, src_bgn, src_end);}
|
||||
@Override public byte Itm_tid() {return Imap_itm_.Tid_desc;}
|
||||
}
|
||||
// class Imap_itm_comment : Imap_itm_base {
|
||||
// public override byte Itm_tid() {return Imap_itm_.Tid_comment;}
|
||||
// }
|
||||
class Imap_itm_shape extends Imap_itm_base {
|
||||
public Imap_itm_shape(int itm_idx, int src_bgn, int src_end, byte shape_tid, Double_obj_val[] shape_pts) {
|
||||
this.Ctor(itm_idx, src_bgn, src_end);
|
||||
this.shape_tid = shape_tid;
|
||||
this.shape_pts = shape_pts;
|
||||
}
|
||||
@Override public byte Itm_tid() {return shape_tid;} private byte shape_tid;
|
||||
public Double_obj_val[] Shape_pts() {return shape_pts;} private Double_obj_val[] shape_pts;
|
||||
public Xop_tkn_itm Shape_link() {return shape_link;} private Xop_tkn_itm shape_link;
|
||||
public byte[] Shape_link_href() {return shape_link_href;} private byte[] shape_link_href;
|
||||
public byte[] Shape_link_caption() {return shape_link_caption;} private byte[] shape_link_caption;
|
||||
public void Shape_link_(Xoa_app app, Xow_wiki wiki, byte[] src, Xop_tkn_itm tkn) {
|
||||
this.shape_link = tkn;
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
shape_link_href = app.Href_parser().Build_to_bry(wiki, lnki_tkn.Ttl());
|
||||
shape_link_caption = Bry_.Mid(src, lnki_tkn.Src_bgn(), lnki_tkn.Src_end());
|
||||
break;
|
||||
}
|
||||
case Xop_tkn_itm_.Tid_lnke: {
|
||||
// gplx.xowa.parsers.lnkes.Xop_lnke_tkn lnke_tkn = (gplx.xowa.parsers.lnkes.Xop_lnke_tkn)tkn;
|
||||
// shape_link_href = lnke_tkn.
|
||||
// shape_link_caption = Bry_.Mid(src, lnki_tkn.Src_bgn(), lnki_tkn.Src_end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final byte Tid_default = 0, Tid_rect = 4, Tid_circle = 3, Tid_poly = 5;
|
||||
public static final Imap_itm_shape Shape_dflt = new Imap_itm_shape(-1, -1, -1, Imap_itm_.Tid_shape_dflt, null);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ 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.imageMap; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.parsers.logs.*;
|
||||
public class Xop_imageMap_xnde implements Xox_xnde {
|
||||
private boolean first = true;
|
||||
@@ -36,7 +36,7 @@ public class Xop_imageMap_xnde implements Xox_xnde {
|
||||
boolean last = cur_pos == content_end;
|
||||
if (last) nl_1_pos = cur_pos;
|
||||
if (nl_1_pos != -1 || last) {
|
||||
Object typeId_obj = TypeTrie.MatchAtCur(src, nl_0_pos, nl_1_pos);
|
||||
Object typeId_obj = TypeTrie.Match_bgn(src, nl_0_pos, nl_1_pos);
|
||||
if (typeId_obj == null) { // flag itm
|
||||
if (!first && nl_1_pos - nl_0_pos > 0)
|
||||
ctx.Msg_log().Add_itm_none(Xtn_imageMap_msg.Line_type_unknown, src, nl_0_pos, nl_1_pos);
|
||||
@@ -116,13 +116,13 @@ public class Xop_imageMap_xnde implements Xox_xnde {
|
||||
}
|
||||
}
|
||||
public static final byte TypeId_default = 0, TypeId_rect = 4, TypeId_circle = 3, TypeId_poly = 5, TypeId_desc = 6, TypeId_comment = 7;
|
||||
public static ByteTrieMgr_slim TypeTrie = ByteTrieMgr_slim.ci_ascii_() // NOTE: names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add("default" , Byte_obj_val.new_(TypeId_default))
|
||||
.Add("rect" , Byte_obj_val.new_(TypeId_rect))
|
||||
.Add("circle" , Byte_obj_val.new_(TypeId_circle))
|
||||
.Add("poly" , Byte_obj_val.new_(TypeId_poly))
|
||||
.Add("desc" , Byte_obj_val.new_(TypeId_desc))
|
||||
.Add("#" , Byte_obj_val.new_(TypeId_comment))
|
||||
public static Btrie_mgr TypeTrie = Btrie_slim_mgr.ci_ascii_() // NOTE: names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add_obj("default" , Byte_obj_val.new_(TypeId_default))
|
||||
.Add_obj("rect" , Byte_obj_val.new_(TypeId_rect))
|
||||
.Add_obj("circle" , Byte_obj_val.new_(TypeId_circle))
|
||||
.Add_obj("poly" , Byte_obj_val.new_(TypeId_poly))
|
||||
.Add_obj("desc" , Byte_obj_val.new_(TypeId_desc))
|
||||
.Add_obj("#" , Byte_obj_val.new_(TypeId_comment))
|
||||
;
|
||||
}
|
||||
class Xtn_imageMap_shape {
|
||||
|
||||
@@ -27,19 +27,4 @@ public class Lst_pfunc_lst extends Pf_func_base {
|
||||
new Lst_pfunc_wkr().Init_include(src_ttl_bry, sect_bgn, sect_end).Exec(bfr, ctx);
|
||||
}
|
||||
public static final Lst_pfunc_lst _ = new Lst_pfunc_lst(); Lst_pfunc_lst() {}
|
||||
public static Hash_adp_bry new_xatrs_(Xol_lang lang) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_();
|
||||
rv.Add_str_byte("name", Lst_section_nde.Xatr_name);
|
||||
Xatrs_add(rv, "begin", "end");
|
||||
switch (lang.Lang_id()) { // NOTE: as of v315572b, i18n is done directly in code, not in magic.php; am wary of adding keywords for general words like begin/end, so adding them manually per language; DATE:2013-02-09
|
||||
case Xol_lang_itm_.Id_de: Xatrs_add(rv, "Anfang", "Ende"); break;
|
||||
case Xol_lang_itm_.Id_he: Xatrs_add(rv, "התחלה", "סוף"); break;
|
||||
case Xol_lang_itm_.Id_pt: Xatrs_add(rv, "começo", "fim"); break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static void Xatrs_add(Hash_adp_bry hash, String key_begin, String key_end) {
|
||||
hash.Add_str_byte(key_begin , Lst_section_nde.Xatr_bgn);
|
||||
hash.Add_str_byte(key_end , Lst_section_nde.Xatr_end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,19 @@ public class Lst_section_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_html_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {} // NOTE: write nothing; <section> is just a bookmark
|
||||
public static final byte Xatr_name = 0, Xatr_bgn = 1, Xatr_end = 2;
|
||||
public static Hash_adp_bry new_xatrs_(Xol_lang lang) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_utf8_(lang.Case_mgr()); // UTF8:see xatrs below
|
||||
rv.Add_str_byte("name", Lst_section_nde.Xatr_name);
|
||||
Xatrs_add(rv, "begin", "end");
|
||||
switch (lang.Lang_id()) { // NOTE: as of v315572b, i18n is done directly in code, not in magic.php; am wary of adding keywords for general words like begin/end, so adding them manually per language; DATE:2013-02-09
|
||||
case Xol_lang_itm_.Id_de: Xatrs_add(rv, "Anfang", "Ende"); break;
|
||||
case Xol_lang_itm_.Id_he: Xatrs_add(rv, "התחלה", "סוף"); break;
|
||||
case Xol_lang_itm_.Id_pt: Xatrs_add(rv, "começo", "fim"); break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static void Xatrs_add(Hash_adp_bry hash, String key_begin, String key_end) {
|
||||
hash.Add_str_byte(key_begin , Lst_section_nde.Xatr_bgn);
|
||||
hash.Add_str_byte(key_end , Lst_section_nde.Xatr_end);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.mapSources; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.btries.*;
|
||||
class Map_math {// REF.MW:MapSources_math.php
|
||||
private int word_idx_nsew;
|
||||
private double[] rv = new double[4];
|
||||
@@ -224,7 +225,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
}
|
||||
private static byte Parse_dir(byte[] dir) {
|
||||
if (Bry_.Len_eq_0(dir)) return Dir_unknown_id;
|
||||
Object dir_obj = Dir_trie.MatchAtCur(dir, 0, dir.length);
|
||||
Object dir_obj = Dir_trie.Match_bgn(dir, 0, dir.length);
|
||||
return dir_obj == null ? Dir_unknown_id : ((Byte_obj_val)dir_obj).Val();
|
||||
}
|
||||
private static int Parse_precision(int val) { // REF.MW: MapSourcesMath.php|newCoord
|
||||
@@ -238,7 +239,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
int i = 0;
|
||||
while (i < input_end) {
|
||||
byte b = input[i];
|
||||
Object o = Input_trie.Match(b, input, i, input_end);
|
||||
Object o = Input_trie.Match_bgn_w_byte(b, input, i, input_end);
|
||||
if (o == null) {
|
||||
bfr.Add_byte(b);
|
||||
++i;
|
||||
@@ -260,7 +261,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
}
|
||||
private static final byte Dir_unknown_id = 0, Dir_lat_id = 1, Dir_long_id = 2;
|
||||
public static final byte[] Dir_lat_bry = Bry_.new_ascii_("lat"), Dir_long_bry = Bry_.new_ascii_("long");
|
||||
private static final ByteTrieMgr_slim Dir_trie = ByteTrieMgr_slim.ci_ascii_() // NOTE:ci.ascii:MW_const.en
|
||||
private static final Btrie_slim_mgr Dir_trie = Btrie_slim_mgr.ci_ascii_() // NOTE:ci.ascii:MW_const.en
|
||||
.Add_bry_bval(Dir_lat_bry , Dir_lat_id)
|
||||
.Add_bry_bval(Dir_long_bry , Dir_long_id)
|
||||
;
|
||||
@@ -275,7 +276,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
private static final byte[] Input_units = new byte[] {Input_byte_degree, Byte_ascii.Apos, Byte_ascii.Quote, Byte_ascii.Space};
|
||||
private static final int Input_units_len = Input_units.length;
|
||||
private static final byte[] Input_bry_degree = Bry_.new_utf8_("°");
|
||||
private static final ByteTrieMgr_slim Input_trie = ByteTrieMgr_slim.cs_()
|
||||
private static final Btrie_slim_mgr Input_trie = Btrie_slim_mgr.cs_()
|
||||
.Add_str_byte("'" , Input_tid_apos) // NOTE: must add ' so that "'" -> "' "
|
||||
.Add_str_byte("‘" , Input_tid_apos)
|
||||
.Add_str_byte("’" , Input_tid_apos)
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xof_math_subst_regy {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
public byte[] Subst(byte[] src) {
|
||||
@@ -24,7 +25,7 @@ public class Xof_math_subst_regy {
|
||||
int dollarSignCount = 0;
|
||||
for (int i = 0; i < src_len; i++) {
|
||||
byte b = src[i];
|
||||
Object o = trie.Match(b, src, i, src_len);
|
||||
Object o = trie.Match_bgn_w_byte(b, src, i, src_len);
|
||||
if (o == null)
|
||||
bfr.Add_byte(b);
|
||||
else {
|
||||
@@ -161,9 +162,9 @@ public class Xof_math_subst_regy {
|
||||
private void Reg(String src_str, String trg_str, boolean dollarSign, boolean wholeWord) {
|
||||
byte[] src_bry = Bry_.new_ascii_(src_str);
|
||||
Xof_math_subst_itm itm = new Xof_math_subst_itm(src_bry, Bry_.new_ascii_(trg_str), dollarSign, wholeWord);
|
||||
trie.Add(src_bry, itm);
|
||||
trie.Add_obj(src_bry, itm);
|
||||
}
|
||||
ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
}
|
||||
class Xof_math_subst_itm {
|
||||
public int SrcLen() {return src_len;} private int src_len;
|
||||
|
||||
@@ -18,18 +18,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
public class Pfunc_expr extends Pf_func_base {
|
||||
@Override public boolean Func_require_colon_arg() {return true;}
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self); if (val_dat_ary == Bry_.Empty) return;
|
||||
DecimalAdp rslt = shunter.Evaluate(ctx, val_dat_ary); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
|
||||
if (rslt == Pfunc_expr_shunter.Null_rslt) {
|
||||
bb.Add_bfr_and_preserve(shunter.Err());
|
||||
// ctx.Msg_log().Add_args(src, self.Src_bgn(), self.Src_end(), Pfunc_expr_msg.Unknown);
|
||||
shunter.Err().Clear();
|
||||
}
|
||||
else
|
||||
bb.Add_str(rslt.XtoStr());
|
||||
Evaluate(bfr, ctx, val_dat_ary);
|
||||
}
|
||||
Pfunc_expr_shunter shunter = Pfunc_expr_shunter._;
|
||||
public static boolean Evaluate(Bry_bfr bfr, Xop_ctx ctx, byte[] expr) {
|
||||
DecimalAdp rslt = shunter.Evaluate(ctx, expr); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
|
||||
if (rslt == Pfunc_expr_shunter.Null_rslt) {
|
||||
bfr.Add_bfr_and_preserve(shunter.Err());
|
||||
shunter.Err().Clear();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
bfr.Add_str(rslt.XtoStr());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static Pfunc_expr_shunter shunter = Pfunc_expr_shunter._;
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_xtn_expr;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_expr().Name_(name);}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ 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.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Pfunc_expr_shunter {
|
||||
ByteTrieMgr_fast trie = expression_();
|
||||
Btrie_fast_mgr trie = expression_();
|
||||
Val_stack val_stack = new Val_stack();
|
||||
Func_tkn_stack prc_stack = new Func_tkn_stack();
|
||||
public static final DecimalAdp Null_rslt = null;
|
||||
@@ -41,7 +42,7 @@ public class Pfunc_expr_shunter {
|
||||
while (true) {
|
||||
// can't think of a way for this to happen; note that operators will automatically push values/operators off stack that are lower; can't get up to 100
|
||||
// if (val_stack.Len() > 100 || prc_stack.Len() > 100) return Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_err__stack_exhausted);
|
||||
Object o = trie.Match(cur_byt, src, cur_pos, src_len);
|
||||
Object o = trie.Match_bgn_w_byte(cur_byt, src, cur_pos, src_len);
|
||||
int bgn_pos = cur_pos;
|
||||
if (o == null) { // letter or unknown symbol
|
||||
while (cur_pos < src_len) {
|
||||
@@ -156,8 +157,8 @@ public class Pfunc_expr_shunter {
|
||||
}
|
||||
return val_stack.Len() == 0 ? Null_rslt : val_stack.Pop(); // HACK: for [[List of Premiers of South Australia by time in office]] and {{#expr:\n{{age in days
|
||||
}
|
||||
private static ByteTrieMgr_fast expression_() {
|
||||
ByteTrieMgr_fast rv = ByteTrieMgr_fast.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; math and expressions
|
||||
private static Btrie_fast_mgr expression_() {
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; math and expressions
|
||||
Trie_add(rv, new Ws_tkn(Byte_ascii.Space));
|
||||
Trie_add(rv, new Ws_tkn(Byte_ascii.Tab));
|
||||
Trie_add(rv, new Ws_tkn(Byte_ascii.NewLine));
|
||||
@@ -214,6 +215,6 @@ public class Pfunc_expr_shunter {
|
||||
Trie_add(rv, new Func_tkn_minus("−"));
|
||||
return rv;
|
||||
}
|
||||
private static void Trie_add(ByteTrieMgr_fast trie, Expr_tkn tkn) {trie.Add(tkn.Val_ary(), tkn);}
|
||||
private static void Trie_add(Btrie_fast_mgr trie, Expr_tkn tkn) {trie.Add(tkn.Val_ary(), tkn);}
|
||||
public static final Pfunc_expr_shunter _ = new Pfunc_expr_shunter(); Pfunc_expr_shunter() {}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Pfunc_iferror extends Pf_func_base {
|
||||
@Override public boolean Func_require_colon_arg() {return true;}
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bb) {
|
||||
@@ -43,7 +44,7 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
while (true) {
|
||||
if (pos == src_len) break;
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match(b, src, pos, src_len);
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
|
||||
if (o == null)
|
||||
++pos;
|
||||
else {
|
||||
@@ -105,10 +106,10 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static final ByteTrieMgr_slim trie = trie_();
|
||||
private static final Btrie_slim_mgr trie = trie_();
|
||||
static final byte State_null = 0, State_nde = 1, State_class = 2, State_error = 3, State_close = 4;
|
||||
private static ByteTrieMgr_slim trie_() {
|
||||
ByteTrieMgr_slim rv = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
private static Btrie_slim_mgr trie_() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
trie_init(rv, State_nde , "<strong");
|
||||
trie_init(rv, State_nde , "<span");
|
||||
trie_init(rv, State_nde , "<p");
|
||||
@@ -118,5 +119,5 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
trie_init(rv, State_close, ">");
|
||||
return rv;
|
||||
}
|
||||
private static void trie_init(ByteTrieMgr_slim trie, byte b, String s) {trie.Add(s, Byte_obj_val.new_(b));}
|
||||
private static void trie_init(Btrie_slim_mgr trie, byte b, String s) {trie.Add_obj(s, Byte_obj_val.new_(b));}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Pfunc_ifexist_mgr {
|
||||
Xow_ns ttl_ns = ttl.Ns();
|
||||
switch (ttl_ns.Id()) {
|
||||
case Xow_ns_.Id_special:
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "ifexist.special ns page; page=~{0} ifexist=~{1}", wiki.Ctx().Cur_page().Url().X_to_full_str_safe(), String_.new_utf8_(raw_bry));
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "ifexist.special ns page; page=~{0} ifexist=~{1}", wiki.Ctx().Cur_page().Url().Xto_full_str_safe(), String_.new_utf8_(raw_bry));
|
||||
exists_itm.Exists_(true);
|
||||
return true;
|
||||
case Xow_ns_.Id_media: return Find_ttl_for_media_ns(exists_itm, wiki, ttl_ns, ttl_bry);
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.pfuncs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.intl.*; import gplx.xowa.langs.numbers.*;
|
||||
import gplx.core.btries.*; import gplx.intl.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Pf_formatnum extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_str_formatnum;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pf_formatnum().Name_(name);}
|
||||
@@ -29,13 +29,13 @@ public class Pf_formatnum extends Pf_func_base {
|
||||
bfr.Add(Format_num(lang, argx, arg1));
|
||||
}
|
||||
public static byte[] Format_num(Xol_lang lang, byte[] num, byte[] arg1) {
|
||||
ByteTrieMgr_slim trie_raw = lang.Kwd_mgr().Trie_raw();
|
||||
ByteTrieMgr_slim trie_nosep = lang.Kwd_mgr().Trie_nosep();
|
||||
Btrie_slim_mgr trie_raw = lang.Kwd_mgr().Trie_raw();
|
||||
Btrie_slim_mgr trie_nosep = lang.Kwd_mgr().Trie_nosep();
|
||||
int arg1_len = arg1.length;
|
||||
if (Bry_.Len_gt_0(arg1)) { // argument specified
|
||||
if (trie_raw .MatchAtCurExact(arg1, 0, arg1_len) != null)
|
||||
if (trie_raw .Match_exact(arg1, 0, arg1_len) != null)
|
||||
return lang.Num_mgr().Raw(num);
|
||||
else if (trie_nosep .MatchAtCurExact(arg1, 0, arg1_len) != null)
|
||||
else if (trie_nosep .Match_exact(arg1, 0, arg1_len) != null)
|
||||
return lang.Num_mgr().Format_num_no_separators(num);
|
||||
}
|
||||
return lang.Num_mgr().Format_num(num);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.pfuncs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.lib.*;
|
||||
import gplx.xowa.xtns.pfuncs.exprs.*;
|
||||
public class Pfunc_scrib_lib implements Scrib_lib {
|
||||
private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
|
||||
public void Core_(Scrib_core v) {this.core = v;} // TEST:
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
this.core = core;
|
||||
Init();
|
||||
mod = core.RegisterInterface(this, core.App().Fsys_mgr().Bin_extensions_dir().GenSubFil_nest("ParserFunctions", "mw.ext.ParserFunctions.lua"));
|
||||
return mod;
|
||||
}
|
||||
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
|
||||
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
switch (key) {
|
||||
case Proc_expr: return Expr(args, rslt);
|
||||
default: throw Err_.unhandled(key);
|
||||
}
|
||||
}
|
||||
private static final int Proc_expr = 0;
|
||||
public static final String Invk_expr = "expr";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_expr);
|
||||
public boolean Expr(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] expr_bry = args.Pull_bry(0);
|
||||
Bry_bfr tmp_bfr = core.Wiki().Utl_bry_bfr_mkr().Get_b128();
|
||||
boolean pass = Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry);
|
||||
String expr_rslt = tmp_bfr.Mkr_rls().XtoStrAndClear();
|
||||
if (pass)
|
||||
return rslt.Init_obj(expr_rslt);
|
||||
else
|
||||
throw Err_.new_(expr_rslt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.pfuncs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.lib.*;
|
||||
public class Pfunc_scrib_lib_tst {
|
||||
@Before public void init() {
|
||||
fxt.Init_scrib_proc();
|
||||
lib = new Pfunc_scrib_lib();
|
||||
lib.Init();
|
||||
lib.Core_(fxt.Core());
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Pfunc_scrib_lib lib;
|
||||
@Test public void Expr() {
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("1 + 2") , "3");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.pfuncs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.xtns.scribunto.*;
|
||||
public class Pfunc_xtn_mgr extends Xox_mgr_base {
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_ascii_("ParserFunctions");
|
||||
@Override public void Xtn_init_by_app(Xoa_app app) {
|
||||
Scrib_xtn_mgr scrib_xtn = (Scrib_xtn_mgr)app.Xtn_mgr().Get_or_fail(Scrib_xtn_mgr.XTN_KEY);
|
||||
scrib_xtn.Lib_mgr().Add(new Pfunc_scrib_lib());
|
||||
}
|
||||
@Override public Xox_mgr Clone_new() {return new Pfunc_xtn_mgr();}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ 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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Pft_fmt_itm_ {
|
||||
public static final int
|
||||
Tid_seg_int = 1
|
||||
@@ -76,7 +77,7 @@ public class Pft_fmt_itm_ {
|
||||
, Rfc_5322 = new Pft_fmt_itm_rfc_5322()
|
||||
, Timezone_offset = new Pft_fmt_itm_timezone_offset()
|
||||
;
|
||||
public static final ByteTrieMgr_fast Regy = ByteTrieMgr_fast.cs_()
|
||||
public static final Btrie_fast_mgr Regy = Btrie_fast_mgr.cs_()
|
||||
.Add(Byte_ascii.Ltr_Y , Pft_fmt_itm_.Year_len4) // 2012
|
||||
.Add(Byte_ascii.Ltr_y , Pft_fmt_itm_.Year_len2) // 12
|
||||
.Add(Byte_ascii.Ltr_L , Pft_fmt_itm_.Year_isLeap) // 1,0
|
||||
@@ -115,12 +116,12 @@ public class Pft_fmt_itm_ {
|
||||
// TODO: foreign; space; "
|
||||
;
|
||||
public static Pft_fmt_itm[] Parse(Xop_ctx ctx, byte[] fmt) {
|
||||
ByteTrieMgr_fast trie = Pft_fmt_itm_.Regy;
|
||||
Btrie_fast_mgr trie = Pft_fmt_itm_.Regy;
|
||||
int i = 0, fmt_len = fmt.length;
|
||||
fmt_itms.Clear(); int raw_bgn = String_.Pos_neg1; byte raw_byt = Byte_.Zero;
|
||||
while (i < fmt_len) {
|
||||
byte b = fmt[i];
|
||||
Object o = trie.Match(b, fmt, i, fmt_len);
|
||||
Object o = trie.Match_bgn_w_byte(b, fmt, i, fmt_len);
|
||||
if (o != null) {
|
||||
if (raw_bgn != String_.Pos_neg1) {fmt_itms.Add(i - raw_bgn == 1 ? new Pft_fmt_itm_raw_byt(raw_byt) : (Pft_fmt_itm)new Pft_fmt_itm_raw_ary(fmt, raw_bgn, i)); raw_bgn = String_.Pos_neg1;}
|
||||
fmt_itms.Add((Pft_fmt_itm)o);
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Pft_func_formatdate extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_str_formatdate;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pft_func_formatdate().Name_(name);}
|
||||
@@ -26,7 +27,7 @@ public class Pft_func_formatdate extends Pf_func_base {
|
||||
byte[] fmt_bry = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
|
||||
if (fmt_bry == Bry_.Empty) {bfr.Add(date_bry); return;} // no format given; add self;
|
||||
int fmt_bry_len = fmt_bry.length;
|
||||
Object o = trie.MatchAtCur(fmt_bry, 0, fmt_bry_len);
|
||||
Object o = trie.Match_bgn(fmt_bry, 0, fmt_bry_len);
|
||||
if (o == null
|
||||
|| o == Fmt_itms_default) {// NOOP for default?
|
||||
bfr.Add(date_bry);
|
||||
@@ -38,7 +39,7 @@ public class Pft_func_formatdate extends Pf_func_base {
|
||||
}
|
||||
public static Pft_func_formatdate_bldr Date_bldr() {return date_bldr;} private static Pft_func_formatdate_bldr date_bldr = new Pft_func_formatdate_bldr();
|
||||
private static final Pft_fmt_itm[] Fmt_itms_default = new Pft_fmt_itm[0];
|
||||
private static final ByteTrieMgr_fast trie = ByteTrieMgr_fast.cs_()
|
||||
private static final Btrie_fast_mgr trie = Btrie_fast_mgr.cs_()
|
||||
.Add("dmy" , new Pft_fmt_itm[] {Pft_fmt_itm_.Day_int, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Year_len4})
|
||||
.Add("mdy" , new Pft_fmt_itm[] {Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Day_int, Pft_fmt_itm_.Byte_comma, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Year_len4})
|
||||
.Add("ymd" , new Pft_fmt_itm[] {Pft_fmt_itm_.Year_len4, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Month_name, Pft_fmt_itm_.Byte_space, Pft_fmt_itm_.Day_int})
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.core.btries.*;
|
||||
class Pxd_parser {
|
||||
byte[] src; int cur_pos, tkn_bgn_pos, src_len, tkn_type;
|
||||
public Pxd_itm[] Tkns() {return tkns;} Pxd_itm[] tkns;
|
||||
@@ -76,7 +77,7 @@ class Pxd_parser {
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case Byte_ascii.At:
|
||||
MakePrvTkn(cur_pos, Pxd_itm_.TypeId_null); // first, make prv tkn
|
||||
Object o = trie.Match(b, src, cur_pos, src_len); // now match String against tkn
|
||||
Object o = trie.Match_bgn_w_byte(b, src, cur_pos, src_len); // now match String against tkn
|
||||
if (o == null) return false; // unknown letter / word; exit now;
|
||||
tkns[tkns_len] = ((Pxd_itm_prototype)o).MakeNew(tkns_len);
|
||||
++tkns_len;
|
||||
@@ -158,16 +159,16 @@ class Pxd_parser {
|
||||
}
|
||||
}
|
||||
}
|
||||
private static ByteTrieMgr_slim trie = Pxd_parser_.Trie();
|
||||
private static Btrie_slim_mgr trie = Pxd_parser_.Trie();
|
||||
}
|
||||
class Pxd_parser_ {
|
||||
public static ByteTrieMgr_slim Trie() {
|
||||
public static Btrie_slim_mgr Trie() {
|
||||
if (trie == null) {
|
||||
trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
Init();
|
||||
}
|
||||
return trie;
|
||||
} static ByteTrieMgr_slim trie;
|
||||
} static Btrie_slim_mgr trie;
|
||||
private static final String[] Names_month_full = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};
|
||||
private static final String[] Names_month_abrv = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
|
||||
private static final String[] Names_month_roman = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"};
|
||||
@@ -183,7 +184,7 @@ class Pxd_parser_ {
|
||||
int name_ary_len = name_ary.length;
|
||||
for (int i = 0; i < name_ary_len; i++) {
|
||||
byte[] name_bry = Bry_.new_utf8_(name_ary[i]);
|
||||
trie.Add(name_bry, new Pxd_itm_unit(-1, name_bry, seg_idx, seg_val));
|
||||
trie.Add_obj(name_bry, new Pxd_itm_unit(-1, name_bry, seg_idx, seg_val));
|
||||
}
|
||||
}
|
||||
public static final byte[]
|
||||
@@ -206,10 +207,10 @@ class Pxd_parser_ {
|
||||
Init_unit(DateAdp_.SegIdx_month , "month", "months");
|
||||
Init_unit(DateAdp_.SegIdx_year , "year", "years");
|
||||
Init_unit(DateAdp_.SegIdx_day, 7 , "week", "weeks");
|
||||
trie.Add(Pxd_itm_ago.Name_ago, new Pxd_itm_ago(-1, -1));
|
||||
trie.Add_obj(Pxd_itm_ago.Name_ago, new Pxd_itm_ago(-1, -1));
|
||||
Init_suffix(Names_day_suffix);
|
||||
Init_relative();
|
||||
trie.Add(Pxd_itm_unixtime.Name_unixtime, new Pxd_itm_unixtime(-1, -1));
|
||||
trie.Add_obj(Pxd_itm_unixtime.Name_unixtime, new Pxd_itm_unixtime(-1, -1));
|
||||
}
|
||||
private static void Init_reg_months(String[] names) {
|
||||
for (int i = 0; i < names.length; i++)
|
||||
@@ -217,31 +218,31 @@ class Pxd_parser_ {
|
||||
}
|
||||
private static void Init_reg_month(String name_str, int seg_val) {
|
||||
byte[] name_ary = Bry_.new_utf8_(name_str);
|
||||
trie.Add(name_ary, new Pxd_itm_month_name(-1, name_ary, DateAdp_.SegIdx_month, seg_val));
|
||||
trie.Add_obj(name_ary, new Pxd_itm_month_name(-1, name_ary, DateAdp_.SegIdx_month, seg_val));
|
||||
}
|
||||
private static void Init_reg_days_of_week(String[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] itm_bry = Bry_.new_utf8_(ary[i]);
|
||||
trie.Add(itm_bry, new Pxd_itm_dow_name(-1, itm_bry, i)); // NOTE: days are base0; 0-6
|
||||
trie.Add_obj(itm_bry, new Pxd_itm_dow_name(-1, itm_bry, i)); // NOTE: days are base0; 0-6
|
||||
}
|
||||
}
|
||||
private static void Init_suffix(String[] suffix_ary) {
|
||||
int len = suffix_ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String suffix = suffix_ary[i];
|
||||
trie.Add(suffix, Pxd_itm_day_suffix._);
|
||||
trie.Add_obj(suffix, Pxd_itm_day_suffix._);
|
||||
}
|
||||
}
|
||||
private static void Init_relative() {
|
||||
trie.Add("today", Pxd_itm_day_relative.Today);
|
||||
trie.Add("tomorrow", Pxd_itm_day_relative.Tomorrow);
|
||||
trie.Add("yesterday", Pxd_itm_day_relative.Yesterday);
|
||||
trie.Add("now", Pxd_itm_time_relative.Now);
|
||||
trie.Add("next", Pxd_itm_unit_relative.Next);
|
||||
trie.Add("last", Pxd_itm_unit_relative.Prev);
|
||||
trie.Add("previous", Pxd_itm_unit_relative.Prev);
|
||||
trie.Add("this", Pxd_itm_unit_relative.This);
|
||||
trie.Add_obj("today", Pxd_itm_day_relative.Today);
|
||||
trie.Add_obj("tomorrow", Pxd_itm_day_relative.Tomorrow);
|
||||
trie.Add_obj("yesterday", Pxd_itm_day_relative.Yesterday);
|
||||
trie.Add_obj("now", Pxd_itm_time_relative.Now);
|
||||
trie.Add_obj("next", Pxd_itm_unit_relative.Next);
|
||||
trie.Add_obj("last", Pxd_itm_unit_relative.Prev);
|
||||
trie.Add_obj("previous", Pxd_itm_unit_relative.Prev);
|
||||
trie.Add_obj("this", Pxd_itm_unit_relative.This);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -16,10 +16,11 @@ 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.poems; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Poem_lxr_nl implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_nl_poem;}
|
||||
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Byte_ascii.NewLine, this);}
|
||||
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
|
||||
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.NewLine, this);}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
if (bgn_pos == Xop_parser_.Doc_bgn_bos) return ctx.Lxr_make_txt_(cur_pos); // simulated nl at beginning of every parse
|
||||
ctx.Subs_add(root, tkn_mkr.Xnde(bgn_pos, cur_pos).Tag_(Xop_xnde_tag_.Tag_br)); // add <br/>
|
||||
|
||||
@@ -16,10 +16,11 @@ 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.poems; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Poem_lxr_pre implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_poem;}
|
||||
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Hook_ary, this);}
|
||||
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
|
||||
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_ary, this);}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
int space_count = 1;
|
||||
while (cur_pos < src_len) {
|
||||
|
||||
@@ -362,7 +362,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
tmp_parser.Parse_text_to_wdom(rv, tmp_ctx, tmp_ctx.Tkn_mkr(), wikitext, Xop_parser_.Doc_bgn_bos);
|
||||
return rv;
|
||||
}
|
||||
private static Hash_adp_bry xtn_atrs = Hash_adp_bry.ci_() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
private static Hash_adp_bry xtn_atrs = Hash_adp_bry.ci_ascii_() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
.Add_str_obj("index" , Byte_obj_val.new_(Pp_pages_nde.Xatr_index_ttl))
|
||||
.Add_str_obj("from" , Byte_obj_val.new_(Pp_pages_nde.Xatr_bgn_page))
|
||||
.Add_str_obj("to" , Byte_obj_val.new_(Pp_pages_nde.Xatr_end_page))
|
||||
|
||||
@@ -185,11 +185,18 @@ public class Score_xnde implements Xox_xnde, Xop_xnde_atr_parser, Xoh_cmd_itm {
|
||||
return Bry_.Mid(rslt, bgn_pos, end_pos);
|
||||
}
|
||||
public static final byte Xatr_id_lang_is_abc = 0, Xatr_id_code_is_raw = 1, Xatr_id_output_midi = 2, Xatr_id_output_ogg = 3, Xatr_id_file_midi = 4, Xatr_id_file_ogg = 5;
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_().Add_str_byte("lang", Xatr_id_lang_is_abc).Add_str_byte("raw", Xatr_id_code_is_raw).Add_str_byte("midi", Xatr_id_output_midi).Add_str_byte("vorbis", Xatr_id_output_ogg).Add_str_byte("over"+"ride_midi", Xatr_id_file_midi).Add_str_byte("over"+"ride_ogg", Xatr_id_file_ogg);
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("lang", Xatr_id_lang_is_abc)
|
||||
.Add_str_byte("raw", Xatr_id_code_is_raw)
|
||||
.Add_str_byte("midi", Xatr_id_output_midi)
|
||||
.Add_str_byte("vorbis", Xatr_id_output_ogg)
|
||||
.Add_str_byte("over"+"ride_midi", Xatr_id_file_midi)
|
||||
.Add_str_byte("over"+"ride_ogg", Xatr_id_file_ogg)
|
||||
;
|
||||
private static final byte[]
|
||||
Lang_abc = Bry_.new_ascii_("ABC")
|
||||
, Abc_tagline_bgn = Bry_.new_ascii_("tagline ="), Abc_tagline_end = new byte[] {Byte_ascii.NewLine}, Abc_tagline_repl = Bry_.new_ascii_("tagline = \"\"\n")
|
||||
, Version_unknown = Bry_.new_ascii_("unknown"), Version_find_bgn = Bry_.new_ascii_("GNU LilyPond")
|
||||
;
|
||||
Lang_abc = Bry_.new_ascii_("ABC")
|
||||
, Abc_tagline_bgn = Bry_.new_ascii_("tagline ="), Abc_tagline_end = new byte[] {Byte_ascii.NewLine}, Abc_tagline_repl = Bry_.new_ascii_("tagline = \"\"\n")
|
||||
, Version_unknown = Bry_.new_ascii_("unknown"), Version_find_bgn = Bry_.new_ascii_("GNU LilyPond")
|
||||
;
|
||||
static final String GRP_KEY = "xowa.xtns.scores.itm";
|
||||
}
|
||||
|
||||
@@ -153,8 +153,13 @@ public class Scrib_core {
|
||||
parent_frame.Scrib_frame_tid_(Scrib_frame_.Tid_parent); current_frame.Scrib_frame_tid_(Scrib_frame_.Tid_current);
|
||||
try {
|
||||
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
|
||||
KeyVal[] fnc_args = Scrib_kv_utl_.base1_obj_(mod.Fncs_get_by_key(String_.new_utf8_(fnc_name)));
|
||||
KeyVal[] rv = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeFunction"), fnc_args);
|
||||
// KeyVal[] fnc_args = Scrib_kv_utl_.base1_obj_(mod.Fncs_get_by_key(String_.new_utf8_(fnc_name)));
|
||||
// KeyVal[] rv = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeFunction"), fnc_args);
|
||||
KeyVal[] fnc_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_utf8_(fnc_name));
|
||||
KeyVal[] rv = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), fnc_args);
|
||||
Scrib_lua_proc proc = (Scrib_lua_proc)rv[1].Val();
|
||||
fnc_args = Scrib_kv_utl_.base1_many_(proc);
|
||||
rv = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeFunction"), fnc_args);
|
||||
String rslt = Scrib_kv_utl_.Val_to_str(rv, 0); // NOTE: expects an array with 1 scalar value
|
||||
bfr.Add_str(rslt);
|
||||
}
|
||||
@@ -173,7 +178,7 @@ public class Scrib_core {
|
||||
rv.LoadString(String_.new_utf8_(mod_text));
|
||||
mods.Add(mod_name, rv);
|
||||
}
|
||||
rv.Execute();
|
||||
// rv.Execute(); // TODO: move inside rv == null
|
||||
return rv;
|
||||
}
|
||||
public static Scrib_core Core() {return core;} public static Scrib_core Core_new_(Xoa_app app, Xop_ctx ctx) {core = new Scrib_core(app, ctx); return core;} private static Scrib_core core;
|
||||
|
||||
@@ -18,6 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.xtns.scribunto.engines.process.*;
|
||||
public class Scrib_core_fxt {
|
||||
public Scrib_core_fxt() {}
|
||||
public Scrib_core_fxt(Xop_fxt fxt) {
|
||||
app = fxt.App();
|
||||
wiki = fxt.Wiki();
|
||||
core = Scrib_core.Core_new_(app, wiki.Ctx());
|
||||
}
|
||||
public Scrib_core_fxt Clear() {
|
||||
if (core == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
|
||||
@@ -90,22 +90,22 @@ public class Scrib_core_tst {
|
||||
.Test_ExecuteModule(14, fxt.kv_func_("prc_0", 15), fxt.kv_func_("prc_1", 16))
|
||||
;
|
||||
}
|
||||
@Test public void Invoke() {
|
||||
fxt .Init_lib_mw();
|
||||
fxt .Init_cbks_add("getExpandedArgument", gplx.xowa.xtns.scribunto.lib.Scrib_lib_mw.Proc_getExpandedArgument);
|
||||
fxt .Expd_server_rcvd_add("0000004900000091{[\"op\"]=\"loadString\",[\"text\"]=\"Mod_0_code\",[\"chunkName\"]=\"=Module:Mod_0\"}")
|
||||
.Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;i:13;}}") // NOTE: 13=id of "Module:Mod_0"
|
||||
.Expd_server_rcvd_add("0000003E0000007B{[\"op\"]=\"call\",[\"id\"]=8,[\"nargs\"]=1,[\"args\"]={[1]=chunks[13]}}") // NOTE: 8=executeModule; 13=id of "Module:Mod_0"
|
||||
.Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;a:1:{s:5:\"Prc_0\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:14;}}}}") // NOTE: 14=id of "Prc_0"
|
||||
.Expd_server_rcvd_add("0000003E0000007B{[\"op\"]=\"call\",[\"id\"]=9,[\"nargs\"]=1,[\"args\"]={[1]=chunks[14]}}") // NOTE: 9=executeFunction; 14=id of "Prc_0"
|
||||
.Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:1:\"1\";}}")
|
||||
.Expd_server_rcvd_add("000000380000006F{[\"op\"]=\"return\",[\"nvalues\"]=1,[\"values\"]={[1]=\"arg_0\"}}")
|
||||
.Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:1:\"2\";}}")
|
||||
.Expd_server_rcvd_add("000000380000006F{[\"op\"]=\"return\",[\"nvalues\"]=1,[\"values\"]={[1]=\"arg_1\"}}")
|
||||
.Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:11:\"arg_0,arg_1\";}}")
|
||||
.Test_Invoke("Mod_0", "Mod_0_code", "Prc_0", Scrib_kv_utl_.base1_many_("arg_0", "arg_1"))
|
||||
;
|
||||
}
|
||||
// @Test public void Invoke() {
|
||||
// fxt .Init_lib_mw();
|
||||
// fxt .Init_cbks_add("getExpandedArgument", gplx.xowa.xtns.scribunto.lib.Scrib_lib_mw.Proc_getExpandedArgument);
|
||||
// fxt .Expd_server_rcvd_add("0000004900000091{[\"op\"]=\"loadString\",[\"text\"]=\"Mod_0_code\",[\"chunkName\"]=\"=Module:Mod_0\"}")
|
||||
// .Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;i:13;}}") // NOTE: 13=id of "Module:Mod_0"
|
||||
// .Expd_server_rcvd_add("0000003E0000007B{[\"op\"]=\"call\",[\"id\"]=8,[\"nargs\"]=1,[\"args\"]={[1]=chunks[13]}}") // NOTE: 8=executeModule; 13=id of "Module:Mod_0"
|
||||
// .Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;a:1:{s:5:\"Prc_0\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:14;}}}}") // NOTE: 14=id of "Prc_0"
|
||||
// .Expd_server_rcvd_add("0000003E0000007B{[\"op\"]=\"call\",[\"id\"]=9,[\"nargs\"]=1,[\"args\"]={[1]=chunks[14]}}") // NOTE: 9=executeFunction; 14=id of "Prc_0"
|
||||
// .Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:1:\"1\";}}")
|
||||
// .Expd_server_rcvd_add("000000380000006F{[\"op\"]=\"return\",[\"nvalues\"]=1,[\"values\"]={[1]=\"arg_0\"}}")
|
||||
// .Init_server_prep_add("a:4:{s:2:\"id\";s:32:\"mw_interface-getExpandedArgument\";s:2:\"op\";s:4:\"call\";s:5:\"nargs\";i:2;s:4:\"args\";a:2:{i:1;s:7:\"current\";i:2;s:1:\"2\";}}")
|
||||
// .Expd_server_rcvd_add("000000380000006F{[\"op\"]=\"return\",[\"nvalues\"]=1,[\"values\"]={[1]=\"arg_1\"}}")
|
||||
// .Init_server_prep_add("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:11:\"arg_0,arg_1\";}}")
|
||||
// .Test_Invoke("Mod_0", "Mod_0_code", "Prc_0", Scrib_kv_utl_.base1_many_("arg_0", "arg_1"))
|
||||
// ;
|
||||
// }
|
||||
String Mod_basic() {
|
||||
return String_.Concat
|
||||
( "local p = {}"
|
||||
|
||||
@@ -27,10 +27,9 @@ public class Scrib_frame_ {
|
||||
public static Xot_invk Get_frame(Scrib_core core, String frame_id) {
|
||||
if (String_.Eq(frame_id, "current")) return core.Frame_current();
|
||||
else if (String_.Eq(frame_id, "parent")) return core.Frame_parent();
|
||||
else if (String_.Eq(frame_id, "empty")) return Xot_invk_mock.new_(core.Frame_current().Defn_tid(), 0, KeyVal_.Ary_empty); // not sure if it should return null title; DATE:2014-07-12
|
||||
else {
|
||||
Xot_invk rv = (Xot_invk)core.Frame_created_list().Fetch(frame_id);
|
||||
if (rv == null) throw Err_.new_("invalid frame ID: frame_id={0}", frame_id);
|
||||
return rv;
|
||||
return (Xot_invk)core.Frame_created_list().Fetch(frame_id); // NOTE: can return null; some calls expect nil; EX:mw.lua and "currentFrame = newFrame( 'empty' )"; DATE:2014-07-12
|
||||
}
|
||||
}
|
||||
public static int Get_arg_adj(byte frame_tid) {
|
||||
|
||||
@@ -126,7 +126,66 @@ public class Scrib_invoke_func_fxt {
|
||||
public void Test_log_rcvd(int i, String expd) {
|
||||
Tfds.Eq(expd, (String)server.Log_rcvd().FetchAt(i));
|
||||
}
|
||||
public static final String Null_rslt = "null"; // NOTE: Scrib procs will return null, which will show up in tests as "null"
|
||||
public void Init_scrib_proc() {
|
||||
fxt = new Xop_fxt(); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
|
||||
core_fxt = new Scrib_core_fxt(fxt);
|
||||
core = core_fxt.Core();
|
||||
core.Frame_parent_(Xot_invk_mock.new_());
|
||||
core.Frame_current_(Xot_invk_mock.new_());
|
||||
Io_mgr._.InitEngine_mem();
|
||||
fxt.Reset();
|
||||
core.When_page_changed(fxt.Page());
|
||||
}
|
||||
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_str(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
|
||||
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
Tfds.Eq(Object_.XtoStr_OrNullStr(expd), Object_.XtoStr_OrNullStr(actl[0].Val()));
|
||||
}
|
||||
public void Test_scrib_proc_kv_vals(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_kv_vals(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_kv_vals(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
|
||||
KeyVal[] actl_ary = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
Tfds.Eq(expd, Kv_ary_to_kv_vals_str(actl_ary));
|
||||
}
|
||||
private String Kv_ary_to_kv_vals_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(Object_.XtoStr_OrNullStr(kv.Val()));
|
||||
}
|
||||
return bfr.XtoStrAndClear();
|
||||
}
|
||||
public void Test_scrib_proc_bool(Scrib_lib lib, String proc_name, Object[] args, boolean expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_int(Scrib_lib lib, String proc_name, Object[] args, int expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, Object[] args, Object expd) {Test_scrib_proc_obj(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_obj(Scrib_lib lib, String proc_name, KeyVal[] args, Object expd) {
|
||||
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
Tfds.Eq(expd, actl[0].Val());
|
||||
}
|
||||
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, Object[] args) {Test_scrib_proc_empty(lib, proc_name, Scrib_kv_utl_.base1_many_(args));}
|
||||
public void Test_scrib_proc_empty(Scrib_lib lib, String proc_name, KeyVal[] args) {
|
||||
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
Tfds.Eq(0, actl.length);
|
||||
}
|
||||
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str_ary(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
|
||||
KeyVal[] actl_ary = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
String actl = KeyVal_.Ary_xto_str_nested(actl_ary);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public KeyVal[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
|
||||
KeyVal[] actl = Test_scrib_proc_rv(lib, proc_name, Scrib_kv_utl_.base1_many_(args));
|
||||
return (KeyVal[])actl[0].Val();
|
||||
}
|
||||
private KeyVal[] Test_scrib_proc_rv(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 final String Null_rslt = "<<NULL>>";
|
||||
public static final String Null_rslt_ary = "1=<<NULL>>";
|
||||
}
|
||||
class Scrib_lua_rsp_bldr {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
|
||||
@@ -18,47 +18,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.scribunto.lib.*;
|
||||
public class Scrib_invoke_func_tst {
|
||||
@Before public void init() {fxt.Clear();} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt();
|
||||
@Test public void Err_mod_blank() {fxt.Test_parse_err("{{#invoke:}}", Scrib_invoke_func.Err_mod_missing);}
|
||||
@Test public void Err_mod_missing() {fxt.Test_parse_err("{{#invoke:Missing}}", Scrib_invoke_func.Err_mod_missing);}
|
||||
@Test public void Preprocess() {
|
||||
this.Init_preprocess();
|
||||
this.Exec_preprocess(Scrib_core.Frame_key_module , "1", "c");
|
||||
this.Exec_preprocess(Scrib_core.Frame_key_module , "2", "d");
|
||||
this.Exec_preprocess(Scrib_core.Frame_key_template , "1", "a");
|
||||
this.Exec_preprocess(Scrib_core.Frame_key_template , "2", "b");
|
||||
}
|
||||
@Test public void ExpandTemplate() {
|
||||
this.Init_expandTemplate();
|
||||
fxt.Parser_fxt().Init_page_create("Template:Format", "{{{1}}}");
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd_expandTemplate(Scrib_core.Frame_key_module , "Format", KeyVal_.int_(1, "a"));
|
||||
fxt.Test_invoke("a");
|
||||
}
|
||||
@Test public void ExpandTemplate_ns_name() {
|
||||
this.Init_expandTemplate();
|
||||
fxt.Parser_fxt().Init_page_create("Template:Format", "{{{1}}}");
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd_expandTemplate(Scrib_core.Frame_key_module , "Template:Format", KeyVal_.int_(1, "a"));
|
||||
fxt.Test_invoke("a");
|
||||
}
|
||||
private void Init_preprocess() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Func_0|1|c|d}}"); // current
|
||||
fxt.Init_page("{{test|1|a|b|c}}"); // parent
|
||||
fxt.Core().Lib_mw().Init();
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_mw(), Scrib_lib_mw.Invk_preprocess);
|
||||
}
|
||||
private void Exec_preprocess(String frame, String arg_idx, String expd) {
|
||||
fxt.Parser_fxt().Wiki().Cache_mgr().Tmpl_result_cache().Clear();
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd_preprocess(frame, "{{#ifeq:" + arg_idx + "|{{{1}}}|{{{2}}}|{{{3}}}}}");
|
||||
fxt.Test_invoke(expd);
|
||||
}
|
||||
private void Init_expandTemplate() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Func_0|1|c|d}}"); // current
|
||||
fxt.Init_page("{{test|null|1|a|b}}"); // parent
|
||||
fxt.Core().Lib_mw().Init();
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_mw(), Scrib_lib_mw.Invk_expandTemplate);
|
||||
}
|
||||
}
|
||||
// public class Scrib_invoke_func_tst {
|
||||
// @Before public void init() {fxt.Clear();} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt();
|
||||
// @Test public void Err_mod_blank() {fxt.Test_parse_err("{{#invoke:}}", Scrib_invoke_func.Err_mod_missing);}
|
||||
// @Test public void Err_mod_missing() {fxt.Test_parse_err("{{#invoke:Missing}}", Scrib_invoke_func.Err_mod_missing);}
|
||||
// @Test public void Preprocess() {
|
||||
// this.Init_preprocess();
|
||||
// this.Exec_preprocess(Scrib_core.Frame_key_module , "1", "c");
|
||||
// this.Exec_preprocess(Scrib_core.Frame_key_module , "2", "d");
|
||||
// this.Exec_preprocess(Scrib_core.Frame_key_template , "1", "a");
|
||||
// this.Exec_preprocess(Scrib_core.Frame_key_template , "2", "b");
|
||||
// }
|
||||
// @Test public void ExpandTemplate() {
|
||||
// this.Init_expandTemplate();
|
||||
// fxt.Parser_fxt().Init_page_create("Template:Format", "{{{1}}}");
|
||||
// fxt.Init_lua_module();
|
||||
// fxt.Init_lua_rcvd_expandTemplate(Scrib_core.Frame_key_module , "Format", KeyVal_.int_(1, "a"));
|
||||
// fxt.Test_invoke("a");
|
||||
// }
|
||||
// @Test public void ExpandTemplate_ns_name() {
|
||||
// this.Init_expandTemplate();
|
||||
// fxt.Parser_fxt().Init_page_create("Template:Format", "{{{1}}}");
|
||||
// fxt.Init_lua_module();
|
||||
// fxt.Init_lua_rcvd_expandTemplate(Scrib_core.Frame_key_module , "Template:Format", KeyVal_.int_(1, "a"));
|
||||
// fxt.Test_invoke("a");
|
||||
// }
|
||||
// private void Init_preprocess() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Func_0|1|c|d}}"); // current
|
||||
// fxt.Init_page("{{test|1|a|b|c}}"); // parent
|
||||
// fxt.Core().Lib_mw().Init();
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_mw(), Scrib_lib_mw.Invk_preprocess);
|
||||
// }
|
||||
// private void Exec_preprocess(String frame, String arg_idx, String expd) {
|
||||
// fxt.Parser_fxt().Wiki().Cache_mgr().Tmpl_result_cache().Clear();
|
||||
// fxt.Init_lua_module();
|
||||
// fxt.Init_lua_rcvd_preprocess(frame, "{{#ifeq:" + arg_idx + "|{{{1}}}|{{{2}}}|{{{3}}}}}");
|
||||
// fxt.Test_invoke(expd);
|
||||
// }
|
||||
// private void Init_expandTemplate() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Func_0|1|c|d}}"); // current
|
||||
// fxt.Init_page("{{test|null|1|a|b}}"); // parent
|
||||
// fxt.Core().Lib_mw().Init();
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_mw(), Scrib_lib_mw.Invk_expandTemplate);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Scrib_lua_mod {
|
||||
private OrderedHash hash = OrderedHash_.new_();
|
||||
private Scrib_lua_proc load_string_fnc;
|
||||
public Scrib_lua_mod(Scrib_core core, String name) {this.name = name; this.core = core;} private Scrib_core core;
|
||||
public int Lua_id() {return lua_id;} private int lua_id = -1;
|
||||
public String Name() {return name;} private String name;
|
||||
public Scrib_lua_proc Init_chunk_func() {return init_chunk_func;} private Scrib_lua_proc init_chunk_func;
|
||||
public byte[] Text_bry() {return text_bry;} private byte[] text_bry;
|
||||
public void Fncs_clear() {hash.Clear();}
|
||||
public int Fncs_len() {return hash.Count();}
|
||||
@@ -33,12 +33,12 @@ public class Scrib_lua_mod {
|
||||
return fnc.Id();
|
||||
}
|
||||
public Scrib_lua_proc LoadString(String text) {
|
||||
if (lua_id != -1) return load_string_fnc;
|
||||
if (lua_id != -1) return init_chunk_func;
|
||||
text = String_.Replace(text, "	", "\t"); // NOTE: this should only get called once per module
|
||||
text_bry = Bry_.new_utf8_(text);
|
||||
load_string_fnc = core.Interpreter().LoadString("=" + name, text); // MW: Scribunto: Prepending an "=" to the chunk name avoids truncation or a "[string" prefix;
|
||||
lua_id = load_string_fnc.Id();
|
||||
return load_string_fnc;
|
||||
init_chunk_func = core.Interpreter().LoadString("=" + name, text); // MW: Scribunto: Prepending an "=" to the chunk name avoids truncation or a "[string" prefix;
|
||||
lua_id = init_chunk_func.Id();
|
||||
return init_chunk_func;
|
||||
}
|
||||
public void Execute() {
|
||||
hash.Clear(); // NOTE: questionable. should probably be removed, as it forces all modules to be "loadString"'d again; DATE:2013-10-16
|
||||
@@ -58,6 +58,5 @@ public class Scrib_lua_mod {
|
||||
fnc = new Scrib_lua_proc(prc_key, -1);
|
||||
Fncs_add(fnc);
|
||||
}
|
||||
// return exports[0].Val();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Process_send_wtr {
|
||||
Encode_obj(tmp_bfr, o);
|
||||
return tmp_bfr.XtoStrAndClear();
|
||||
}
|
||||
public void Encode_bool(Bry_bfr bfr, boolean v) {bfr.Add(v ? CONST_bool_true : CONST_bool_false);}
|
||||
public void Encode_bool(Bry_bfr bfr, boolean v) {bfr.Add(v ? CONST_bool_true : CONST_bool_false);}
|
||||
public void Encode_int(Bry_bfr bfr, int v) {bfr.Add_int_variable(v);}
|
||||
public boolean Encode_double(Bry_bfr bfr, double v) {
|
||||
if (Double_.IsNaN(v)) {usr_dlg.Warn_many(GRP_KEY, "fail_encode_double", "cannot convert non-finite number"); return false;}
|
||||
@@ -87,7 +87,7 @@ public class Process_send_wtr {
|
||||
else if (Object_.Eq(c, Double_.ClassOf)) {if (!Encode_double(bfr, Double_.cast_(o))) return false;}
|
||||
else if (Object_.Eq(c, String.class)) {if (!Encode_str(bfr, (String)o)) return false;}
|
||||
else if (Object_.Eq(c, byte[].class)) {if (!Encode_str(bfr, (byte[])o)) return false;} // NOTE: not in Scribunto; added here for PERF of not re-creating a String Object
|
||||
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
|
||||
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
|
||||
else if (Object_.Eq(c, KeyVal.class)) {if (!Encode_kv(bfr, (KeyVal)o)) return false;}
|
||||
else if (Object_.Eq(c, KeyVal[].class)) {if (!Encode_ary(bfr, (KeyVal[])o)) return false;}
|
||||
else {throw Scrib_xtn_mgr.err_("Object cannot be serialized: {0}", ClassAdp_.NameOf_obj(o));}
|
||||
|
||||
@@ -20,102 +20,113 @@ import org.junit.*;
|
||||
import gplx.xowa.langs.numbers.*;
|
||||
public class Scrib_lib_language_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_language().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void GetContLangCode() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_getContLangCode, Object_.Ary_empty, "en");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_getContLangCode, Object_.Ary_empty, "en");
|
||||
}
|
||||
@Test public void IsSupportedLanguage() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("fr"), "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("qq"), "false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("EN"), "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("fr"), true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("qq"), false);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isSupportedLanguage, Object_.Ary("EN"), false);
|
||||
}
|
||||
@Test public void IsKnownLanguageTag() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isKnownLanguageTag, Object_.Ary("fr"), "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isKnownLanguageTag, Object_.Ary("qq"), "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isKnownLanguageTag, Object_.Ary("fr"), true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isKnownLanguageTag, Object_.Ary("qq"), false);
|
||||
}
|
||||
@Test public void IsValidCode() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isValidCode, Object_.Ary("a,b"), "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isValidCode, Object_.Ary("a'b"), "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isValidCode, Object_.Ary("a,b"), true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isValidCode, Object_.Ary("a'b"), false);
|
||||
}
|
||||
@Test public void IsValidBuiltInCode() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isValidBuiltInCode, Object_.Ary("e-N"), "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isValidBuiltInCode, Object_.Ary("e n"), "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isValidBuiltInCode, Object_.Ary("e-N"), true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isValidBuiltInCode, Object_.Ary("e n"), false);
|
||||
}
|
||||
@Test public void FetchLanguageName() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("en"), "English");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("fr"), "Français");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("enx"), "");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("en"), "English");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("fr"), "Français");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_fetchLanguageName, Object_.Ary("enx"), "");
|
||||
}
|
||||
@Test public void GetFallbacksFor() {
|
||||
Xol_lang other_lang = fxt.Core().App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("zh"));
|
||||
other_lang.Fallback_bry_(Bry_.new_ascii_("gan-hant, zh-hant, zh-hans"));
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_getFallbacksFor, Object_.Ary("zh"), "gan-hant;zh-hant;zh-hans;en"); // auto-add en
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_getFallbacksFor, Object_.Ary("unknown"), "");
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_language.Invk_getFallbacksFor, Object_.Ary("zh"), String_.Concat_lines_nl
|
||||
( "1=gan-hant"
|
||||
, "2=zh-hant"
|
||||
, "3=zh-hans"
|
||||
, "4=en" // auto-add en
|
||||
));
|
||||
}
|
||||
@Test public void GetFallbacksFor_unknown() {
|
||||
fxt.Test_scrib_proc_empty(lib, Scrib_lib_language.Invk_getFallbacksFor, Object_.Ary("unknown"));
|
||||
}
|
||||
@Test public void FormatNum() {
|
||||
Xol_lang other_lang = fxt.Core().App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("de")).Init_by_load_assert(); // NOTE: must call Init_by_load_assert, else load will be called by scrib and sprs below will get overwritten during load;
|
||||
fxt.Parser_fxt().Init_lang_numbers_separators(other_lang, ".", ",");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("de", 1234), "1.234"); // german spr
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", 1234), "1,234"); // english spr
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234"), "1,234"); // String passed (not int)
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", true))) , "1234"); // noCommafy.y
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("de", 1234), "1.234"); // german spr
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", 1234), "1,234"); // english spr
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234"), "1,234"); // String passed (not int)
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", true))) , "1234"); // noCommafy.y
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234", KeyVal_.Ary(KeyVal_.new_("noCommafy", false))) , "1,234"); // noCommafy.n
|
||||
}
|
||||
@Test public void FormatDate() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
}
|
||||
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
|
||||
Tfds.Now_enabled_y_();
|
||||
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_language.Invk_formatDate, new KeyVal[] {KeyVal_.int_(1, "en"), KeyVal_.int_(2, "Y-m-d"), KeyVal_.int_(4, false)}, "2013-12-19");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, KeyVal_.Ary(KeyVal_.int_(1, "en"), KeyVal_.int_(2, "Y-m-d"), KeyVal_.int_(4, false)), "2013-12-19");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
|
||||
Tfds.Now_enabled_n_();
|
||||
}
|
||||
@Test public void Lc() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_lc, Object_.Ary("en", "ABC"), "abc");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_lc, Object_.Ary("en", "ABC"), "abc");
|
||||
}
|
||||
@Test public void Uc() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_uc, Object_.Ary("en", "abc"), "ABC");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_uc, Object_.Ary("en", "abc"), "ABC");
|
||||
}
|
||||
@Test public void LcFirst() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_lcfirst, Object_.Ary("en", "ABC"), "aBC");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_lcfirst, Object_.Ary("en", "ABC"), "aBC");
|
||||
}
|
||||
@Test public void UcFirst() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_uc, Object_.Ary("en", "abc"), "ABC");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_uc, Object_.Ary("en", "abc"), "ABC");
|
||||
}
|
||||
@Test public void ParseFormattedNumber() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", "1,234.56") , "1234.56"); // formatted String
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", "1234") , "1234"); // String
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", 1234) , "1234"); // int
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", 1234.56) , "1234.56"); // double
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en"), Scrib_invoke_func_fxt.Null_rslt); // PURPOSE: missing arg should not fail; EX: ru.w:Туйон DATE:2014-01-06
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", "1,234.56") , "1234.56"); // formatted String
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", "1234") , "1234"); // String
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", 1234) , "1234"); // int
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en", 1234.56) , "1234.56"); // double
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_parseFormattedNumber, Object_.Ary("en"), Scrib_invoke_func_fxt.Null_rslt); // PURPOSE: missing arg should not fail; EX: ru.w:Туйон DATE:2014-01-06
|
||||
}
|
||||
@Test public void ConvertGrammar() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertGrammar, Object_.Ary("fi", "talo", "elative"), "talosta");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_convertGrammar, Object_.Ary("fi", "talo", "elative"), "talosta");
|
||||
}
|
||||
@Test public void ConvertPlural() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, Kv_ary_("a", "b", "c")), "c"); // forms in kv_ary
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, "a", "b", "c"), "c"); // forms as rest of ary; PAGE:ru.w:Ленин,_Владимир_Ильич DATE:2014-07-01
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, Kv_ary_("a", "b", "c")), "c"); // forms in kv_ary
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_convertPlural, Object_.Ary("ru", 5, "a", "b", "c"), "c"); // forms as rest of ary; PAGE:ru.w:Ленин,_Владимир_Ильич DATE:2014-07-01
|
||||
}
|
||||
@Test public void IsRTL() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isRTL, Object_.Ary("en"), "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isRTL, Object_.Ary("en"), false);
|
||||
Xol_lang other_lang = fxt.Core().App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("ar"));
|
||||
GfoInvkAble_.InvkCmd_val(other_lang, Xol_lang.Invk_dir_rtl_, true);
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_isRTL, Object_.Ary("ar"), "true");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_language.Invk_isRTL, Object_.Ary("ar"), true);
|
||||
}
|
||||
@Test public void Format_duration() {
|
||||
Init_lang_durations(fxt.Core().Wiki());
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 3723d, Kv_ary_("hours", "minutes", "seconds")), "1 hour, 2 minutes and 3 seconds"); // basic
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 123d, Kv_ary_("hours", "minutes", "seconds")), "2 minutes and 3 seconds"); // omit hour since < 1
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 123d, Kv_ary_("hours")) , "0 hours"); // handle fractional duration
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 3723d, Kv_ary_("hours", "minutes", "seconds")), "1 hour, 2 minutes and 3 seconds"); // basic
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 123d, Kv_ary_("hours", "minutes", "seconds")), "2 minutes and 3 seconds"); // omit hour since < 1
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDuration, Object_.Ary("en", 123d, Kv_ary_("hours")) , "0 hours"); // handle fractional duration
|
||||
}
|
||||
@Test public void Get_duration_intervals() {
|
||||
Init_lang_durations(fxt.Core().Wiki());
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_language.Invk_getDurationIntervals, Object_.Ary("en", 3723d, Kv_ary_("hours", "minutes", "seconds")), "\n 1;2;3");
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_language.Invk_getDurationIntervals, Object_.Ary("en", 3723d, Kv_ary_("hours", "minutes", "seconds")), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " hours=1"
|
||||
, " minutes=2"
|
||||
, " seconds=3"
|
||||
));
|
||||
}
|
||||
private static KeyVal[] Kv_ary_(String... ary) {
|
||||
int ary_len = ary.length;
|
||||
|
||||
@@ -148,7 +148,13 @@ class Scrib_lib_message_data {
|
||||
return msg_val;
|
||||
}
|
||||
static final byte Key_tid_keys = 1, Key_tid_rawMessage = 2, Key_tid_lang = 3, Key_tid_useDB = 4, Key_tid_title = 5, Key_tid_params = 6;
|
||||
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_().Add_str_byte("keys", Key_tid_keys).Add_str_byte("rawMessage", Key_tid_rawMessage).Add_str_byte("lang", Key_tid_lang).Add_str_byte("useDB", Key_tid_useDB).Add_str_byte("title", Key_tid_title).Add_str_byte("params", Key_tid_params);
|
||||
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("keys", Key_tid_keys)
|
||||
.Add_str_byte("rawMessage", Key_tid_rawMessage)
|
||||
.Add_str_byte("lang", Key_tid_lang)
|
||||
.Add_str_byte("useDB", Key_tid_useDB)
|
||||
.Add_str_byte("title", Key_tid_title)
|
||||
.Add_str_byte("params", Key_tid_params);
|
||||
public static byte parse_fmt_(byte[] key) {return parse_or_fail(fmt_hash, key, "invalid message format: {0}");}
|
||||
public static byte parse_chk_(byte[] key) {return parse_or_fail(check_hash, key, "invalid check arg: {0}");}
|
||||
public static byte parse_or_fail(Hash_adp_bry hash, byte[] key, String fmt) {
|
||||
@@ -157,7 +163,15 @@ class Scrib_lib_message_data {
|
||||
return ((Byte_obj_val)o).Val();
|
||||
}
|
||||
public static final byte Fmt_tid_parse = 1, Fmt_tid_text = 2, Fmt_tid_plain = 3, Fmt_tid_escaped = 4, Fmt_tid_parseAsBlock = 5;
|
||||
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_().Add_str_byte("parse", Fmt_tid_parse).Add_str_byte("text", Fmt_tid_text).Add_str_byte("plain", Fmt_tid_plain).Add_str_byte("escaped", Fmt_tid_escaped).Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
|
||||
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("parse", Fmt_tid_parse)
|
||||
.Add_str_byte("text", Fmt_tid_text)
|
||||
.Add_str_byte("plain", Fmt_tid_plain)
|
||||
.Add_str_byte("escaped", Fmt_tid_escaped)
|
||||
.Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
|
||||
public static final byte Check_tid_exists = 1, Check_tid_isBlank = 2, Check_tid_isDisabled = 3;
|
||||
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_().Add_str_byte("exists", Check_tid_exists).Add_str_byte("isBlank", Check_tid_isBlank).Add_str_byte("isDisabled", Check_tid_isDisabled);
|
||||
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("exists", Check_tid_exists)
|
||||
.Add_str_byte("isBlank", Check_tid_isBlank)
|
||||
.Add_str_byte("isDisabled", Check_tid_isDisabled);
|
||||
}
|
||||
|
||||
@@ -19,37 +19,36 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_message_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_message().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Plain() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary("sun")) , "Sun");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary("sunx")) , "<sunx>");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_arg("redirectedfrom", "A")) , "(Redirected from A)");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary("sun")) , "Sun");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary("sunx")) , "<sunx>");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_arg("redirectedfrom", "A")) , "(Redirected from A)");
|
||||
}
|
||||
@Test public void Plain_lang() {
|
||||
Xol_lang lang = fxt.Parser_fxt().Wiki().App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("fr"));
|
||||
Init_msg(lang, "sun", "dim");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_lang("sun", "fr")) , "dim");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)keys_ary_lang("sun", "fr")) , "dim");
|
||||
}
|
||||
@Test public void Plain_rawMessage() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "abc");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_plain, Object_.Ary((Object)Scrib_kv_utl_.flat_many_("rawMessage", "$1", "params", KeyVal_.Ary(KeyVal_.int_(1, "abc")))), "abc");
|
||||
}
|
||||
@Test public void Check() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sun")) , "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sunx")) , "false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("sun")) , "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sun")) , true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("exists" , keys_ary("sunx")) , false);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("sun")) , false);
|
||||
Init_msg("blank", "");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("blank")) , "true");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("blank")) , true);
|
||||
Init_msg("disabled", "-");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("sun")) , "false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("blank")) , "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("disabled")) , "true");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("disabled")) , "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("sun")) , false);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("blank")) , true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isDisabled" , keys_ary("disabled")) , true);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_message.Invk_check, Object_.Ary("isBlank" , keys_ary("disabled")) , false);
|
||||
}
|
||||
@Test public void Init_message_for_lang() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_message.Invk_init_message_for_lang, Object_.Ary_empty , "lang=en");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_message.Invk_init_message_for_lang, Object_.Ary_empty , "lang=en");
|
||||
}
|
||||
private void Init_msg(String key, String val) {Init_msg(fxt.Core().Wiki().Lang(), key, val);}
|
||||
private void Init_msg(Xol_lang lang, String key, String val) {
|
||||
|
||||
@@ -25,6 +25,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
public Scrib_lib Init() {procs.Init_by_lib(this, Proc_names); return this;}
|
||||
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
|
||||
Init();
|
||||
core.RegisterInterface(this, script_dir.GenSubFil("mwInit.lua")); // DATE:2014-07-12
|
||||
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.lua")
|
||||
, KeyVal_.new_("allowEnvFuncs", allow_env_funcs));
|
||||
return mod;
|
||||
@@ -55,6 +56,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
case Proc_isSubsting: return IsSubsting(args, rslt);
|
||||
case Proc_newChildFrame: return NewChildFrame(args, rslt);
|
||||
case Proc_getFrameTitle: return GetFrameTitle(args, rslt);
|
||||
case Proc_setTTL: return SetTTL(args, rslt);
|
||||
default: throw Err_.unhandled(key);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +66,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
, Proc_getExpandedArgument = 3, Proc_getAllExpandedArguments = 4
|
||||
, Proc_expandTemplate = 5, Proc_preprocess = 6, Proc_callParserFunction = 7
|
||||
, Proc_incrementExpensiveFunctionCount = 8, Proc_isSubsting = 9
|
||||
, Proc_newChildFrame = 10, Proc_getFrameTitle = 11
|
||||
, Proc_newChildFrame = 10, Proc_getFrameTitle = 11, Proc_setTTL = 12
|
||||
;
|
||||
public static final String
|
||||
Invk_loadPackage = "loadPackage"
|
||||
@@ -72,7 +74,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
, Invk_getExpandedArgument = "getExpandedArgument", Invk_getAllExpandedArguments = "getAllExpandedArguments"
|
||||
, Invk_expandTemplate = "expandTemplate", Invk_preprocess = "preprocess", Invk_callParserFunction = "callParserFunction"
|
||||
, Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount", Invk_isSubsting = "isSubsting"
|
||||
, Invk_newChildFrame = "newChildFrame", Invk_getFrameTitle = "getFrameTitle"
|
||||
, Invk_newChildFrame = "newChildFrame", Invk_getFrameTitle = "getFrameTitle", Invk_setTTL = "setTTL"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_loadPackage
|
||||
@@ -80,7 +82,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
, Invk_getExpandedArgument, Invk_getAllExpandedArguments
|
||||
, Invk_expandTemplate, Invk_preprocess, Invk_callParserFunction
|
||||
, Invk_incrementExpensiveFunctionCount, Invk_isSubsting
|
||||
, Invk_newChildFrame, Invk_getFrameTitle
|
||||
, Invk_newChildFrame, Invk_getFrameTitle, Invk_setTTL
|
||||
);
|
||||
public boolean LoadPackage(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String mod_name = args.Pull_str(0);
|
||||
@@ -356,6 +358,12 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
Xot_invk frame = Scrib_frame_.Get_frame(core, frame_id);
|
||||
return rslt.Init_obj(frame.Frame_ttl());
|
||||
}
|
||||
public boolean SetTTL(Scrib_proc_args args, Scrib_proc_rslt rslt) { // needed for {{cite web}} PAGE:en.w:A DATE:2014-07-12
|
||||
int timeToLive = args.Pull_int(0);
|
||||
Xot_invk current_frame = core.Frame_current();
|
||||
current_frame.Frame_lifetime_(timeToLive);
|
||||
return rslt.Init_empty();
|
||||
}
|
||||
}
|
||||
class Scrib_lib_mw_callParserFunction_sorter implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
|
||||
@@ -18,147 +18,157 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_mw_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
lib = fxt.Core().Lib_mw().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void ParentFrameExists() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Init_page("{{test}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, "true");
|
||||
}
|
||||
@Test public void ParentFrameExists_false() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, "false");
|
||||
}
|
||||
@Test public void GetAllExpandedArguments() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0|v0|k1=v1}}");
|
||||
fxt.Init_server_print_key_y_();
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n 1:v0;k1:v1");
|
||||
fxt.Init_server_print_key_n_();
|
||||
}
|
||||
@Test public void GetAllExpandedArguments_parent() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
fxt.Init_page("{{test|a1|a2}}");
|
||||
fxt.Init_server_print_key_y_();
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "\n 1:a1;2:a2");
|
||||
fxt.Init_server_print_key_n_();
|
||||
}
|
||||
@Test public void GetAllExpandedArguments_ws_prm_key_exists() { // PURPOSE: trim val if key exists; parameterized value ("key={{{1}}}")
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|key={{{1}}}}}");
|
||||
fxt.Init_page("{{test| a }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n a"); // " a " -> "a"
|
||||
}
|
||||
@Test public void GetAllExpandedArguments_ws_prm_key_missing() { // PURPOSE: do not trim val if key missing; parameterized value ("{{{1}}}")
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|{{{1}}}}}");
|
||||
fxt.Init_page("{{test| a }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n a "); // " a " -> " a "
|
||||
}
|
||||
@Test public void GetAllExpandedArguments__ignore_empty_key() {// PURPOSE: ignore arguents that have an empty key (|=8|); EX:w:Fool's_mate; DATE:2014-03-05
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Init_page("{{test|a1||a2|=a3|a4}}");
|
||||
fxt.Init_server_print_key_y_();
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "\n 1:a1;2:;3:a2;4:a4"); // NOTE: || is not ignored but |=a3| is
|
||||
fxt.Init_server_print_key_n_();
|
||||
}
|
||||
@Test public void GetExpandedArgument() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0|val_1|key_2=val_2|val_3}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "2") , "val_3"); // get 2nd by idx (which is "3", not "key_2)
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3") , ""); // get 3rd by idx (which is n/a, not "3")
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_2") , "val_2"); // get key_2
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3") , ""); // key_3 n/a
|
||||
}
|
||||
@Test public void GetExpandedArgument_ws_key_exists() { // PURPOSE: trim val if key exists; literal value
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0| key1 = val1 }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key1") , "val1"); // "key1" -> "key1"
|
||||
}
|
||||
@Test public void GetExpandedArgument_ws_key_missing() { // PURPOSE: do not trim val if key missing; literal value
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0| a }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , " a "); // " a " -> " a "
|
||||
}
|
||||
@Test public void GetExpandedArgument_ws_key_prm_key_exists() { // PURPOSE: trim val if key exists; parameterized value ("key={{{1}}}")
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|key1={{{1}}}}}");
|
||||
fxt.Init_page("{{test| a }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key1") , "a"); // " a " -> "a"
|
||||
}
|
||||
@Test public void GetExpandedArgument_ws_key_prm_key_missing() { // PURPOSE: do not trim val if key missing; parameterized value ("{{{1}}}")
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|{{{1}}}}}");
|
||||
fxt.Init_page("{{test| a }}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , " a "); // " a " -> " a "
|
||||
}
|
||||
@Test public void GetExpandedArgument_parent() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
fxt.Init_page("{{test|a1|a2}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "1"), "a1");
|
||||
}
|
||||
@Test public void GetExpandedArgument_numeric_key() { // PURPOSE.FIX: frame.args[1] was ignoring "1=val_1" b/c it was looking for 1st unnamed arg (and 1 is the name for "1=val_1")
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0|1=val_1}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx, even though idx is String
|
||||
}
|
||||
@Test public void GetExpandedArgument_numeric_key_2() { // PURPOSE.FIX: same as above, but for parent context; DATE:2013-09-23
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b2}}"); // current
|
||||
fxt.Init_page("{{test|2=b1}}"); // parent
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2") , "b1"); // get 1st by idx, even though idx is String
|
||||
}
|
||||
@Test public void GetExpandedArgument_out_of_bounds() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
fxt.Init_page("{{test}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2") , "");
|
||||
}
|
||||
@Test public void Preprocess() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0|key1=a|key2=b|key1=c}}"); // add key1 twice
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_preprocess, Object_.Ary("current", "{{#ifeq:1|1|{{{key1}}}|{{{key2}}}}}"), "c");
|
||||
}
|
||||
@Test public void CallParserFunction() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "#expr", "1") , "1"); // named: args is scalar
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "#if", Scrib_kv_utl_.base1_many_("", "y", "n")) , "n"); // named: args is table
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", "", "y", "n") , "n"); // list: args is ary
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", Scrib_kv_utl_.base1_many_("", "y", "n")) , "n"); // list: args is table
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if:", "y", "n") , "n"); // colon_in_name
|
||||
}
|
||||
@Test public void CallParserFunction_tag() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.flat_many_(1, "current", 2, "#tag", 3, Scrib_kv_utl_.flat_many_("3", "id=1", "2", "text", "1", "pre")), "<pre 3=\"id=1\">2=text</pre>");// named: sort args; NOTE: keys should probably be stripped
|
||||
}
|
||||
@Test public void CallParserFunction_displayTitle() { // PURPOSE: DISPLAYTITLE not being set when called through CallParserFunction; DATE:2013-08-05
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "DISPLAYTITLE", "''a''"), "");
|
||||
Tfds.Eq("<i>a</i>", String_.new_ascii_(fxt.Parser_fxt().Ctx().Cur_page().Display_ttl()));
|
||||
}
|
||||
@Test public void IsSubsting() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_isSubsting, Object_.Ary_empty, "false");
|
||||
}
|
||||
@Test public void ExpandTemplate_tmpl() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Parser_fxt().Data_create("Template:A", "b{{{key1}}}c");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "A", Scrib_kv_utl_.flat_many_("key1", "val1")) , "bval1c"); // list: args is ary
|
||||
}
|
||||
@Test public void ExpandTemplate_tmpl_bool() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Parser_fxt().Data_create("Template:Scribunto_bool", "bool_true={{{bool_true}}};bool_false={{{bool_false}}};");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "Scribunto_bool", Scrib_kv_utl_.flat_many_("bool_true", true, "bool_false", false)), "bool_true=1;bool_false={{{bool_false}}};");
|
||||
}
|
||||
@Test public void ExpandTemplate_page() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Parser_fxt().Data_create("A", "b{{{key1}}}c");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", ":A", Scrib_kv_utl_.flat_many_("key1", "val1")) , "bval1c"); // list: args is ary
|
||||
}
|
||||
@Test public void GetFrameTitle_current() {
|
||||
fxt.Parser_fxt().Wiki().Cache_mgr().Free_mem_all();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}"); // current
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getFrameTitle, Object_.Ary("current") , "Module:Mod_0");
|
||||
}
|
||||
@Test public void GetFrameTitle_owner() {
|
||||
fxt.Parser_fxt().Wiki().Cache_mgr().Free_mem_all();
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}"); // current
|
||||
fxt.Init_page("{{test}}"); // parent
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getFrameTitle, Object_.Ary("parent") , "Template:Test");
|
||||
}
|
||||
@Test public void NewChildFrame() {
|
||||
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_newChildFrame, Object_.Ary("current", "Page_0", Scrib_kv_utl_.flat_many_("key1", "val1")) , "frame0");
|
||||
}
|
||||
@Test public void Stub() {}
|
||||
// @Before public void init() {
|
||||
// fxt.Clear();
|
||||
// lib = fxt.Core().Lib_mw().Init();
|
||||
// } private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
// @Test public void ParentFrameExists() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Init_page("{{test}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, "true");
|
||||
// }
|
||||
// @Test public void ParentFrameExists_false() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_parentFrameExists, Object_.Ary_empty, "false");
|
||||
// }
|
||||
// @Test public void GetAllExpandedArguments() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0|v0|k1=v1}}");
|
||||
// fxt.Init_server_print_key_y_();
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n 1:v0;k1:v1");
|
||||
// fxt.Init_server_print_key_n_();
|
||||
// }
|
||||
// @Test public void GetAllExpandedArguments_parent() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
// fxt.Init_page("{{test|a1|a2}}");
|
||||
// fxt.Init_server_print_key_y_();
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "\n 1:a1;2:a2");
|
||||
// fxt.Init_server_print_key_n_();
|
||||
// }
|
||||
// @Test public void GetAllExpandedArguments_ws_prm_key_exists() { // PURPOSE: trim val if key exists; parameterized value ("key={{{1}}}")
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|key={{{1}}}}}");
|
||||
// fxt.Init_page("{{test| a }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n a"); // " a " -> "a"
|
||||
// }
|
||||
// @Test public void GetAllExpandedArguments_ws_prm_key_missing() { // PURPOSE: do not trim val if key missing; parameterized value ("{{{1}}}")
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|{{{1}}}}}");
|
||||
// fxt.Init_page("{{test| a }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("current"), "\n a "); // " a " -> " a "
|
||||
// }
|
||||
// @Test public void GetAllExpandedArguments__ignore_empty_key() {// PURPOSE: ignore arguents that have an empty key (|=8|); EX:w:Fool's_mate; DATE:2014-03-05
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Init_page("{{test|a1||a2|=a3|a4}}");
|
||||
// fxt.Init_server_print_key_y_();
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getAllExpandedArguments, Object_.Ary("parent"), "\n 1:a1;2:;3:a2;4:a4"); // NOTE: || is not ignored but |=a3| is
|
||||
// fxt.Init_server_print_key_n_();
|
||||
// }
|
||||
// @Test public void GetExpandedArgument() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0|val_1|key_2=val_2|val_3}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "2") , "val_3"); // get 2nd by idx (which is "3", not "key_2)
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3") , ""); // get 3rd by idx (which is n/a, not "3")
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_2") , "val_2"); // get key_2
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3") , ""); // key_3 n/a
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_ws_key_exists() { // PURPOSE: trim val if key exists; literal value
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0| key1 = val1 }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key1") , "val1"); // "key1" -> "key1"
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_ws_key_missing() { // PURPOSE: do not trim val if key missing; literal value
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0| a }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , " a "); // " a " -> " a "
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_ws_key_prm_key_exists() { // PURPOSE: trim val if key exists; parameterized value ("key={{{1}}}")
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|key1={{{1}}}}}");
|
||||
// fxt.Init_page("{{test| a }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key1") , "a"); // " a " -> "a"
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_ws_key_prm_key_missing() { // PURPOSE: do not trim val if key missing; parameterized value ("{{{1}}}")
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|{{{1}}}}}");
|
||||
// fxt.Init_page("{{test| a }}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , " a "); // " a " -> " a "
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_parent() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
// fxt.Init_page("{{test|a1|a2}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "1"), "a1");
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_numeric_key() { // PURPOSE.FIX: frame.args[1] was ignoring "1=val_1" b/c it was looking for 1st unnamed arg (and 1 is the name for "1=val_1")
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0|1=val_1}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx, even though idx is String
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_numeric_key_2() { // PURPOSE.FIX: same as above, but for parent context; DATE:2013-09-23
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b2}}"); // current
|
||||
// fxt.Init_page("{{test|2=b1}}"); // parent
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2") , "b1"); // get 1st by idx, even though idx is String
|
||||
// }
|
||||
// @Test public void GetExpandedArgument_out_of_bounds() {
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0|b1}}");
|
||||
// fxt.Init_page("{{test}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2") , "");
|
||||
// }
|
||||
// @Test public void Preprocess() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0|key1=a|key2=b|key1=c}}"); // add key1 twice
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_preprocess, Object_.Ary("current", "{{#ifeq:1|1|{{{key1}}}|{{{key2}}}}}"), "c");
|
||||
// }
|
||||
// @Test public void CallParserFunction() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "#expr", "1") , "1"); // named: args is scalar
|
||||
// fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "#if", Scrib_kv_utl_.base1_many_("", "y", "n")) , "n"); // named: args is table
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", "", "y", "n") , "n"); // list: args is ary
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if", Scrib_kv_utl_.base1_many_("", "y", "n")) , "n"); // list: args is table
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_callParserFunction, Object_.Ary("current", "#if:", "y", "n") , "n"); // colon_in_name
|
||||
// }
|
||||
// @Test public void CallParserFunction_tag() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.flat_many_(1, "current", 2, "#tag", 3, Scrib_kv_utl_.flat_many_("3", "id=1", "2", "text", "1", "pre")), "<pre 3=\"id=1\">2=text</pre>");// named: sort args; NOTE: keys should probably be stripped
|
||||
// }
|
||||
// @Test public void CallParserFunction_displayTitle() { // PURPOSE: DISPLAYTITLE not being set when called through CallParserFunction; DATE:2013-08-05
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "DISPLAYTITLE", "''a''"), "");
|
||||
// Tfds.Eq("<i>a</i>", String_.new_ascii_(fxt.Parser_fxt().Ctx().Cur_page().Display_ttl()));
|
||||
// }
|
||||
// @Test public void IsSubsting() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_isSubsting, Object_.Ary_empty, "false");
|
||||
// }
|
||||
// @Test public void ExpandTemplate_tmpl() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Parser_fxt().Data_create("Template:A", "b{{{key1}}}c");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "A", Scrib_kv_utl_.flat_many_("key1", "val1")) , "bval1c"); // list: args is ary
|
||||
// }
|
||||
// @Test public void ExpandTemplate_tmpl_bool() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Parser_fxt().Data_create("Template:Scribunto_bool", "bool_true={{{bool_true}}};bool_false={{{bool_false}}};");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", "Scribunto_bool", Scrib_kv_utl_.flat_many_("bool_true", true, "bool_false", false)), "bool_true=1;bool_false={{{bool_false}}};");
|
||||
// }
|
||||
// @Test public void ExpandTemplate_page() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Parser_fxt().Data_create("A", "b{{{key1}}}c");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_expandTemplate, Object_.Ary("current", ":A", Scrib_kv_utl_.flat_many_("key1", "val1")) , "bval1c"); // list: args is ary
|
||||
// }
|
||||
// @Test public void GetFrameTitle_current() {
|
||||
// fxt.Parser_fxt().Wiki().Cache_mgr().Free_mem_all();
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}"); // current
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getFrameTitle, Object_.Ary("current") , "Module:Mod_0");
|
||||
// }
|
||||
// @Test public void GetFrameTitle_owner() {
|
||||
// fxt.Parser_fxt().Wiki().Cache_mgr().Free_mem_all();
|
||||
// fxt.Init_tmpl("{{#invoke:Mod_0|Prc_0}}"); // current
|
||||
// fxt.Init_page("{{test}}"); // parent
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getFrameTitle, Object_.Ary("parent") , "Template:Test");
|
||||
// }
|
||||
// @Test public void GetFrameTitle_empty() {
|
||||
// fxt.Parser_fxt().Wiki().Cache_mgr().Free_mem_all();
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}"); // current
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_getFrameTitle, Object_.Ary("empty") , Scrib_invoke_func_fxt.Null_rslt);
|
||||
// }
|
||||
// @Test public void NewChildFrame() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_newChildFrame, Object_.Ary("current", "Page_0", Scrib_kv_utl_.flat_many_("key1", "val1")), "frame0");
|
||||
// }
|
||||
// @Test public void SetTTL() {
|
||||
// fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_mw.Invk_setTTL, Object_.Ary(123), ""); // smoke test; difficult to get member reference to current_frame since it's freed automatically in invoke; DATE:2014-07-12
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -19,27 +19,24 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_site_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_site().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void GetNsIndex() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), "12");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx"), ""); // unknown ns; return empty String
|
||||
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Help"), 12);
|
||||
}
|
||||
@Test public void GetNsIndex_invalid() {
|
||||
fxt.Test_scrib_proc_empty(lib, Scrib_lib_site.Invk_getNsIndex, Object_.Ary("Helpx")); // unknown ns; return empty String
|
||||
}
|
||||
@Test public void UsersInGroup() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), "0"); // SELECT * FROM user_groups;
|
||||
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_usersInGroup, Object_.Ary("sysop"), 0); // SELECT * FROM user_groups;
|
||||
}
|
||||
@Test public void PagesInCategory() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A"), "0");
|
||||
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInCategory, Object_.Ary("A"), 0);
|
||||
}
|
||||
@Test public void PagesInNs() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), "0");
|
||||
fxt.Test_scrib_proc_int(lib, Scrib_lib_site.Invk_pagesInNs, Object_.Ary("12"), 0);
|
||||
}
|
||||
// @Test public void LoadSiteStats() { // deprecated by Scribunto; DATE:2013-04-12
|
||||
// fxt.Parser_fxt().Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7);
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_loadSiteStats, Object_.Ary_empty, "1;2;3;4;5;6;7");
|
||||
// }
|
||||
@Test public void Init_lib_site() {
|
||||
Xow_ns_mgr ns_mgr = new Xow_ns_mgr(fxt.Core().Wiki().Lang().Case_mgr());
|
||||
ns_mgr.Add_new(Scrib_xtn_mgr.Ns_id_module, "Module");
|
||||
@@ -51,16 +48,111 @@ public class Scrib_lib_site_tst {
|
||||
Xow_wiki wiki = fxt.Parser_fxt().Wiki();
|
||||
fxt.Parser_fxt().Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7).NumAdmins_(8);
|
||||
wiki.Ns_mgr_(ns_mgr);
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl
|
||||
( ""
|
||||
, " Wikipedia;http://en.wikipedia.org;/wiki;/wiki/skins;1.21wmf11;"
|
||||
, " " // namespaces
|
||||
, " -1;Special;Special;false;false;false;false;true;false;true;false;null;{};-1;"
|
||||
, " 0;;;false;false;false;true;true;true;true;false;null;{};0;1;1;(Main);"
|
||||
, " 1;Talk;Talk;false;false;false;false;true;true;false;true;null;{};1;1;0;"
|
||||
, " 828;Module;Module;false;false;false;false;true;true;true;false;null;{};828;829;829;"
|
||||
, " 829;Module talk;Module_talk;false;false;false;false;true;true;false;true;null;{};829;829;828;"
|
||||
, " 1;2;3;4;5;6;7;8"
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_site.Invk_init_site_for_wiki, Object_.Ary_empty, String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " siteName=Wikipedia"
|
||||
, " server=http://en.wikipedia.org"
|
||||
, " scriptPath=/wiki"
|
||||
, " stylePath=/wiki/skins"
|
||||
, " currentVersion=1.21wmf11"
|
||||
, " namespaces="
|
||||
, " -1="
|
||||
, " id=-1"
|
||||
, " name=Special"
|
||||
, " canonicalName=Special"
|
||||
, " hasSubpages=false"
|
||||
, " hasGenderDistinction=false"
|
||||
, " isCapitalized=false"
|
||||
, " isContent=false"
|
||||
, " isIncludable=true"
|
||||
, " isMovable=false"
|
||||
, " isSubject=true"
|
||||
, " isTalk=false"
|
||||
, " defaultContentModel=<<NULL>>"
|
||||
, " aliases="
|
||||
, " subject=-1"
|
||||
, " 0="
|
||||
, " id=0"
|
||||
, " name="
|
||||
, " canonicalName="
|
||||
, " hasSubpages=false"
|
||||
, " hasGenderDistinction=false"
|
||||
, " isCapitalized=false"
|
||||
, " isContent=true"
|
||||
, " isIncludable=true"
|
||||
, " isMovable=true"
|
||||
, " isSubject=true"
|
||||
, " isTalk=false"
|
||||
, " defaultContentModel=<<NULL>>"
|
||||
, " aliases="
|
||||
, " subject=0"
|
||||
, " talk=1"
|
||||
, " associated=1"
|
||||
, " displayName=(Main)"
|
||||
, " 1="
|
||||
, " id=1"
|
||||
, " name=Talk"
|
||||
, " canonicalName=Talk"
|
||||
, " hasSubpages=false"
|
||||
, " hasGenderDistinction=false"
|
||||
, " isCapitalized=false"
|
||||
, " isContent=false"
|
||||
, " isIncludable=true"
|
||||
, " isMovable=true"
|
||||
, " isSubject=false"
|
||||
, " isTalk=true"
|
||||
, " defaultContentModel=<<NULL>>"
|
||||
, " aliases="
|
||||
, " subject=1"
|
||||
, " talk=1"
|
||||
, " associated=0"
|
||||
, " 828="
|
||||
, " id=828"
|
||||
, " name=Module"
|
||||
, " canonicalName=Module"
|
||||
, " hasSubpages=false"
|
||||
, " hasGenderDistinction=false"
|
||||
, " isCapitalized=false"
|
||||
, " isContent=false"
|
||||
, " isIncludable=true"
|
||||
, " isMovable=true"
|
||||
, " isSubject=true"
|
||||
, " isTalk=false"
|
||||
, " defaultContentModel=<<NULL>>"
|
||||
, " aliases="
|
||||
, " subject=828"
|
||||
, " talk=829"
|
||||
, " associated=829"
|
||||
, " 829="
|
||||
, " id=829"
|
||||
, " name=Module talk"
|
||||
, " canonicalName=Module_talk"
|
||||
, " hasSubpages=false"
|
||||
, " hasGenderDistinction=false"
|
||||
, " isCapitalized=false"
|
||||
, " isContent=false"
|
||||
, " isIncludable=true"
|
||||
, " isMovable=true"
|
||||
, " isSubject=false"
|
||||
, " isTalk=true"
|
||||
, " defaultContentModel=<<NULL>>"
|
||||
, " aliases="
|
||||
, " subject=829"
|
||||
, " talk=829"
|
||||
, " associated=828"
|
||||
, " stats="
|
||||
, " pages=1"
|
||||
, " articles=2"
|
||||
, " files=3"
|
||||
, " edits=4"
|
||||
, " views=5"
|
||||
, " users=6"
|
||||
, " activeUsers=7"
|
||||
, " admins=8"
|
||||
));
|
||||
}
|
||||
// @Test public void LoadSiteStats() { // deprecated by Scribunto; DATE:2013-04-12
|
||||
// fxt.Parser_fxt().Wiki().Stats().NumPages_(1).NumArticles_(2).NumFiles_(3).NumEdits_(4).NumViews_(5).NumUsers_(6).NumUsersActive_(7);
|
||||
// fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_site.Invk_loadSiteStats, Object_.Ary_empty, "1;2;3;4;5;6;7");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Scrib_lib_text implements Scrib_lib {
|
||||
public boolean GetEntityTable(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
if (Html_entity_ == null) Html_entity_ = Scrib_lib_text_html_entities.new_();
|
||||
return rslt.Init_obj(Html_entity_);
|
||||
} static KeyVal[] Html_entity_;
|
||||
} private static KeyVal[] Html_entity_;
|
||||
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
|
||||
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
Xow_msg_mgr msg_mgr = core.Wiki().Msg_mgr();
|
||||
|
||||
@@ -19,16 +19,14 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_text_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_text().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Unstrip() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_text.Invk_unstrip, Object_.Ary("a"), "a");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_text.Invk_unstrip, Object_.Ary("a"), "a");
|
||||
}
|
||||
@Test public void GetEntityTable() {
|
||||
byte[] rv = fxt.Test_lib_proc_rv(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
|
||||
rv = Bry_.Replace(rv, new byte[] {Byte_ascii.Semic, Byte_ascii.Semic}, new byte[] {Byte_ascii.Semic});
|
||||
Tfds.Eq(1510, Bry_.Split(rv, Byte_ascii.Semic).length);
|
||||
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
|
||||
Tfds.Eq(1510, actl.length); // large result; only test # of entries
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ 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.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.wikis.caches.*;
|
||||
public class Scrib_lib_title implements Scrib_lib {
|
||||
public Scrib_lib_title(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -74,22 +75,25 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
if (url_func_obj == null) throw Err_.new_fmt_("url_function is not valid: {0}", String_.new_utf8_(url_func_bry));
|
||||
byte url_func_tid = ((Byte_obj_val)url_func_obj).Val();
|
||||
byte[] qry_bry = args.Extract_qry_args(wiki, 2);
|
||||
// byte[] proto = Scrib_kv_utl_.Val_to_bry_or(values, 3, null);
|
||||
// byte[] proto = Scrib_kv_utl_.Val_to_bry_or(values, 3, null); // NOTE: Scribunto has more conditional logic around argument 2 and setting protocols; DATE:2014-07-07
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Bry_bfr bfr = wiki.App().Utl_bry_bfr_mkr().Get_b512();
|
||||
// if (url_func_tid == Pf_url_urlfunc.Tid_full) {
|
||||
// if (proto == null) proto = Proto_relative;
|
||||
// Object proto_obj = proto_hash.Fetch(proto); if (proto_obj == null) throw Err_.new_fmt_("protocol is not valid: {0}", proto);
|
||||
// //qry_bry = (byte[])proto_obj;
|
||||
// byte proto_tid = ((Byte_obj_val)proto_obj).Val();
|
||||
// bfr.Add();
|
||||
// }
|
||||
//if (url_func_tid == Pf_url_urlfunc.Tid_full) {
|
||||
// if (proto == null) proto = Proto_relative;
|
||||
// Object proto_obj = proto_hash.Fetch(proto); if (proto_obj == null) throw Err_.new_fmt_("protocol is not valid: {0}", proto);
|
||||
// //qry_bry = (byte[])proto_obj;
|
||||
// byte proto_tid = ((Byte_obj_val)proto_obj).Val();
|
||||
// bfr.Add();
|
||||
//}
|
||||
Pf_url_urlfunc.UrlString(core.Ctx(), url_func_tid, false, ttl_bry, bfr, qry_bry);
|
||||
return rslt.Init_obj(bfr.Mkr_rls().XtoStrAndClear());
|
||||
}
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_().Add_str_byte("fullUrl", Pf_url_urlfunc.Tid_full).Add_str_byte("localUrl", Pf_url_urlfunc.Tid_local).Add_str_byte("canonicalUrl", Pf_url_urlfunc.Tid_canonical);
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_str_byte("fullUrl", Pf_url_urlfunc.Tid_full)
|
||||
.Add_str_byte("localUrl", Pf_url_urlfunc.Tid_local)
|
||||
.Add_str_byte("canonicalUrl", Pf_url_urlfunc.Tid_canonical);
|
||||
// private static final byte[] Proto_relative = Bry_.new_ascii_("relative");
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_().Add_str_obj("http", Bry_.new_ascii_("http://")).Add_str_obj("https", Bry_.new_ascii_("https://")).Add_str_obj("relative", Bry_.new_ascii_("//")).Add_str_obj("canonical", Bry_.new_ascii_("1"));
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_ascii_().Add_str_obj("http", Bry_.new_ascii_("http://")).Add_str_obj("https", Bry_.new_ascii_("https://")).Add_str_obj("relative", Bry_.new_ascii_("//")).Add_str_obj("canonical", Bry_.new_ascii_("1"));
|
||||
private byte[] Parse_ns(Xow_wiki wiki, Object ns_obj) {
|
||||
if (ClassAdp_.Eq_typeSafe(ns_obj, String.class))
|
||||
return Bry_.new_utf8_(String_.cast_(ns_obj));
|
||||
@@ -130,8 +134,18 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xow_wiki wiki = core.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
byte[] rv = wiki.Cache_mgr().Page_cache().Get_or_load_as_src(ttl); if (rv == null) return rslt.Init_obj(null);
|
||||
return rslt.Init_obj(String_.new_utf8_(rv));
|
||||
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
|
||||
byte[] rv = null;
|
||||
if (page_itm != null) {
|
||||
byte[] redirected_src = page_itm.Redirected_src();
|
||||
if (redirected_src != null) { // page is redirect; use its src, not its target's src; DATE:2014-07-11
|
||||
rv = redirected_src;
|
||||
core.Frame_parent().Rslt_is_redirect_(true); // flag frame as redirect, so that \n won't be prepended; EX:"#REDIRECT" x> "\n#REDIRECT"
|
||||
}
|
||||
else
|
||||
rv = page_itm.Src();
|
||||
}
|
||||
return rv == null ? rslt.Init_obj(null) : rslt.Init_obj(String_.new_utf8_(rv));
|
||||
}
|
||||
public boolean GetCurrentTitle(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(Xto_kv_ary(core.Page().Ttl()));
|
||||
|
||||
@@ -19,62 +19,92 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_title_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_title().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void NewTitle() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("Page_0") , "\n true;false;;0;;Page 0;0;;wikitext;Page_0;false;false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("Page_0", "Template") , "\n true;false;;10;Template;Page 0;0;;wikitext;Page_0;false;false");
|
||||
fxt.Parser_fxt().Init_log_(Xop_ttl_log.Invalid_char);
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("a[b") , Scrib_invoke_func_fxt.Null_rslt); // invalid
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("Page_0") , ttl_data_(0 , "", "Page 0", "", "", "Page_0"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("A", "Template") , ttl_data_(10 , "Template", "A"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_newTitle, Object_.Ary("a[b") , Scrib_invoke_func_fxt.Null_rslt_ary); // invalid
|
||||
}
|
||||
@Test public void GetUrl() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl") , "//en.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "action=edit") , "//en.wikipedia.org/wiki/Main_Page?action=edit");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "localUrl") , "/wiki/Main_Page");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "http://en.wikipedia.org/wiki/Main_Page");
|
||||
// fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl") , "//en.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "action=edit") , "//en.wikipedia.org/wiki/Main_Page?action=edit");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "localUrl") , "/wiki/Main_Page");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl") , "http://en.wikipedia.org/wiki/Main_Page");
|
||||
// fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "", "http") , "http://en.wikipedia.org/wiki/Main_Page"); // TODO
|
||||
}
|
||||
@Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikip<69>dia:Image_du_jour/Date; DATE:2013-12-24
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", KeyVal_.Ary(KeyVal_.new_("action", "edit"), KeyVal_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", KeyVal_.Ary(KeyVal_.new_("action", "edit"), KeyVal_.new_("preload", "b"))), "http://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
|
||||
}
|
||||
@Test public void MakeTitle() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_data_("828", "Module", "A"));
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary(828, "A") , ttl_data_("828", "Module", "A"));
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "A", "b") , ttl_data_("10", "Template", "A", "b"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_data_(828, "Module", "A"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary(828, "A") , ttl_data_(828, "Module", "A"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "A", "b") , ttl_data_(10, "Template", "A", "b"));
|
||||
fxt.Parser_fxt().Wiki().Xwiki_mgr().Add_full("fr", "fr.wikipedia.org");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "A", "b", "fr") , ttl_data_("0", "", "Template:A", "b", "fr"));
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "A", "b", "fr") , ttl_data_(0, "", "Template:A", "b", "fr"));
|
||||
fxt.Parser_fxt().Init_log_(Xop_ttl_log.Invalid_char);
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "a[b"), Scrib_invoke_func_fxt.Null_rslt); // PURPOSE: handle bad MakeTitle cmds; EX: Disney; DATE:2013-10-15
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Template", "a[b"), Scrib_invoke_func_fxt.Null_rslt_ary); // PURPOSE: handle bad MakeTitle cmds; PAGE:en.w:Disney; DATE:2013-10-15
|
||||
}
|
||||
@Test public void FileExists() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("A") , "false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("Template:A") , "false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , "false");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("A") , false);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("Template:A") , false);
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , false);
|
||||
fxt.Parser_fxt().Init_page_create("File:A.png");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , "true");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , true);
|
||||
}
|
||||
@Test public void FileExists_commons() { // PURPOSE: check that Scribunto FileExists calls filepath.FileExists; DATE:2014-01-07
|
||||
Xow_wiki commons_wiki = fxt.Parser_fxt().Wiki().App().Wiki_mgr().Get_by_key_or_make(Xow_wiki_.Domain_commons_bry).Init_assert();
|
||||
fxt.Parser_fxt().Init_page_create(commons_wiki, "File:A.png", "text_is_blank");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , "true");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("File:A.png") , true);
|
||||
}
|
||||
@Test public void FileExists_media() { // PURPOSE: [[Media:]] ns should find entries in [[File:]]; DATE:2014-01-07
|
||||
fxt.Parser_fxt().Init_page_create("File:A.png");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("Media:A.png") , "true");
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_title.Invk_fileExists, Object_.Ary("Media:A.png") , true);
|
||||
}
|
||||
@Test public void GetContent() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , Scrib_invoke_func_fxt.Null_rslt);
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , Scrib_invoke_func_fxt.Null_rslt);
|
||||
fxt.Parser_fxt().Init_page_create("A", "test");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , "test");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , "test");
|
||||
}
|
||||
@Test public void GetContent_redirect() {// PURPOSE: GetContent should return source text for redirect, not target; PAGE:de.w:Wikipedia:Autorenportal DATE:2014-07-11
|
||||
fxt.Parser_fxt().Init_page_create("A", "#REDIRECT [[B]]");
|
||||
fxt.Parser_fxt().Init_page_create("B", "C");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , "#REDIRECT [[B]]"); // should not be "C"
|
||||
}
|
||||
@Test public void ProtectionLevels() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_title.Invk_protectionLevels, Object_.Ary("A") , "");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_title.Invk_protectionLevels, Object_.Ary("A") , "");
|
||||
}
|
||||
private static String ttl_data_(String ns_id, String ns_str, String ttl) {return ttl_data_(ns_id, ns_str, ttl, "", "");}
|
||||
private static String ttl_data_(String ns_id, String ns_str, String ttl, String anchor) {return ttl_data_(ns_id, ns_str, ttl, anchor, "");}
|
||||
private static String ttl_data_(String ns_id, String ns_str, String ttl, String anchor, String xwiki) {
|
||||
return "\n true;false;" + xwiki + ";" + ns_id + ";" + ns_str + ";" + ttl + ";0;" + anchor + ";wikitext;" + ttl + ";false;false";
|
||||
private static String ttl_data_(int ns_id, String ns_str, String ttl) {return ttl_data_(ns_id, ns_str, ttl, "", "", ttl);}
|
||||
private static String ttl_data_(int ns_id, String ns_str, String ttl, String anchor) {return ttl_data_(ns_id, ns_str, ttl, anchor, "", ttl);}
|
||||
private static String ttl_data_(int ns_id, String ns_str, String ttl, String anchor, String xwiki) {return ttl_data_(ns_id, ns_str, ttl, anchor, xwiki, ttl);}
|
||||
private static String ttl_data_(int ns_id, String ns_str, String ttl, String anchor, String xwiki, String partial_url) {
|
||||
return String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " isLocal=true"
|
||||
, " isRedirect=false"
|
||||
, " interwiki=" + xwiki
|
||||
, " namespace=" + Int_.XtoStr(ns_id)
|
||||
, " nsText=" + ns_str
|
||||
, " text=" + ttl
|
||||
, " id=0"
|
||||
, " fragment=" + anchor
|
||||
, " contentModel=wikitext"
|
||||
, " thePartialUrl=" + partial_url
|
||||
, " exists=false"
|
||||
, " fileExists=false"
|
||||
);
|
||||
}
|
||||
}
|
||||
//0000: '' != '1=isLocal=True'
|
||||
//0001: ' true;false;;828;Module;A;0;;wikitext;A;false;false' != 'isRedirect=False'
|
||||
//0002: <<N/A>> != 'interwiki='
|
||||
//0003: <<N/A>> != 'namespace=828'
|
||||
//0004: <<N/A>> != 'nsText=Module'
|
||||
//0005: <<N/A>> != 'text=A'
|
||||
//0006: <<N/A>> != 'id=0'
|
||||
//0007: <<N/A>> != 'fragment='
|
||||
//0008: <<N/A>> != 'contentModel=wikitext'
|
||||
//0009: <<N/A>> != 'thePartialUrl=A'
|
||||
//0010: <<N/A>> != 'exists=False'
|
||||
//0011: <<N/A>> != 'fileExists=False'
|
||||
|
||||
@@ -19,27 +19,25 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_uri_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_uri().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Url() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" ), "/wiki/A%26b!_c");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_fullUrl , Object_.Ary("a&b! c" ), "//en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "http://en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" , "action=edit" ), "/wiki/A%26b!_c?action=edit");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("Media:A.png" ), "/wiki/File:A.png");
|
||||
fxt.Parser_fxt().Init_log_(Xop_ttl_log.Invalid_char);
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" ), "/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl , Object_.Ary("a&b! c" ), "//en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_canonicalUrl , Object_.Ary("a&b! c" ), "http://en.wikipedia.org/wiki/A%26b!_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("a&b! c" , "action=edit" ), "/wiki/A%26b!_c?action=edit");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("Media:A.png" ), "/wiki/File:A.png");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_localUrl , Object_.Ary("[bad]" ), Scrib_invoke_func_fxt.Null_rslt); // handle invalid titles; EX:it.w:Billy_the_Kid; DATE:2014-01-20
|
||||
}
|
||||
@Test public void Url__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; it.w:Astronomie; DATE:2014-01-18
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", KeyVal_.Ary(KeyVal_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", KeyVal_.Ary(KeyVal_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
|
||||
}
|
||||
@Test public void AnchorEncode() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_anchorEncode , Object_.Ary("[irc://a b c]" ), "b_c");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_anchorEncode , Object_.Ary("[irc://a b c]" ), "b_c");
|
||||
}
|
||||
@Test public void Init_uri_for_page() {
|
||||
fxt.Parser_fxt().Page_ttl_("Page_1");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_uri.Invk_init_uri_for_page , Object_.Ary_empty , "//en.wikipedia.org/wiki/Page_1");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_init_uri_for_page , Object_.Ary_empty , "//en.wikipedia.org/wiki/Page_1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
public class Scrib_lib_ustring_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_scrib_proc();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
lib = fxt.Core().Lib_ustring().Init();
|
||||
} Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Find() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_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
|
||||
@@ -36,10 +35,9 @@ public class Scrib_lib_ustring_tst {
|
||||
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 Match() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||
Exec_match("abcd" , "bc" , 1, "bc"); // basic
|
||||
Exec_match("abcd" , "x" , 1, "null"); // empty
|
||||
Exec_match("abcd" , "a" , 2, "null"); // bgn
|
||||
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
|
||||
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
|
||||
@@ -49,8 +47,7 @@ public class Scrib_lib_ustring_tst {
|
||||
Exec_match("a b" , "%S" , 1, "a"); // %S was returning every match instead of 1st; EX:en.w:Bertrand_Russell; DATE:2014-04-02
|
||||
}
|
||||
@Test public void Match_args_out_of_order() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||
fxt.Test_lib_proc_kv(lib, Scrib_lib_ustring.Invk_match, new KeyVal[] {KeyVal_.int_(2, "[a]")}, "");
|
||||
fxt.Test_scrib_proc_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);
|
||||
@@ -58,115 +55,108 @@ public class Scrib_lib_ustring_tst {
|
||||
// Exec_match("tr" , "^([b]*).-([c]*)$", 1, ";"); // should return all matches
|
||||
// }
|
||||
@Test public void Gsub() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_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
|
||||
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() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
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_capture() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%1z", "az;1"); // capture
|
||||
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_proc() {
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx_func_0("abcd", "([a])", "Abcd;1");
|
||||
}
|
||||
@Test public void Gsub_proc_w_grouped() { // PURPOSE: gsub_proc should pass matched String, not entire String; DATE:2013-12-01
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx_func_1("[[a]]", "%[%[([^#|%]]-)%]%]" , "A;1");
|
||||
fxt.Test_log_rcvd(3, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"a\"}}"); // should be "a", not "[[a]]"
|
||||
}
|
||||
@Test public void Gsub_proc_w_grouped_2() {// PURPOSE: gsub_proc failed when passing multiple matches; DATE:2013-12-01
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx_func_2("[[a]] [[b]]", "%[%[([^#|%]]-)%]%]" , "A B;2");
|
||||
fxt.Test_log_rcvd(3, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"a\"}}"); // should be "a", not "[[a]]"
|
||||
fxt.Test_log_rcvd(4, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"b\"}}"); // should be "b", not "[[b]]"
|
||||
}
|
||||
// @Test public void Gsub_proc() {
|
||||
// Exec_gsub_regx_func_0("abcd", "([a])", "Abcd;1");
|
||||
// }
|
||||
// @Test public void Gsub_proc_w_grouped() { // PURPOSE: gsub_proc should pass matched String, not entire String; DATE:2013-12-01
|
||||
// Exec_gsub_regx_func_1("[[a]]", "%[%[([^#|%]]-)%]%]" , "A;1");
|
||||
// fxt.Test_log_rcvd(3, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"a\"}}"); // should be "a", not "[[a]]"
|
||||
// }
|
||||
// @Test public void Gsub_proc_w_grouped_2() {// PURPOSE: gsub_proc failed when passing multiple matches; DATE:2013-12-01
|
||||
// Exec_gsub_regx_func_2("[[a]] [[b]]", "%[%[([^#|%]]-)%]%]" , "A B;2");
|
||||
// fxt.Test_log_rcvd(3, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"a\"}}"); // should be "a", not "[[a]]"
|
||||
// fxt.Test_log_rcvd(4, "000000370000006D{[\"op\"]=\"call\",[\"id\"]=1,[\"nargs\"]=1,[\"args\"]={[1]=\"b\"}}"); // should be "b", not "[[b]]"
|
||||
// }
|
||||
// @Test public void Gsub_int() { // PURPOSE: gsub with integer arg should not fail; DATE:2013-11-06
|
||||
//// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
//// fxt.Init_lua_module();
|
||||
//// fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(1, "[1]", "2", 1)); // NOTE: text is integer (lua / php are type-less)
|
||||
//// fxt.Init_lua_rcvd_rv();
|
||||
//// fxt.Test_invoke("2;1");
|
||||
// fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_ustring.Invk_gsub, Object_.Ary("[1]", 1) , "2;1");
|
||||
// }
|
||||
@Test public void Gsub_no_replace() {// PURPOSE: gsub with no replace argument should not fail; EX:d:'orse; DATE:2013-10-14
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_("text", "regx")); // NOTE: repl, limit deliberately omitted
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke("text");
|
||||
}
|
||||
@Test public void Gsub_int() { // PURPOSE: gsub with integer arg should not fail; DATE:2013-11-06
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(1, "[1]", "2", 1)); // NOTE: text is integer (lua / php are type-less)
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke("2;1");
|
||||
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 Gmatch_init() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a(b)") , "a(b);\n false");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_init, Object_.Ary("abcabc", "a()(b)") , "a()(b);\n true;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=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_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 0) , "2;\n b");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 2) , "5;\n b");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("abcabc", "a(b)", Scrib_kv_utl_.base1_many_(false), 8) , "8;{}");
|
||||
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_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a", "a" , KeyVal_.Ary_empty, 0) , "1;\n a");
|
||||
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_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary("a bcd e", "()(b)" , Scrib_kv_utl_.base1_many_(true, false), 0) , "3;\n 3;b");
|
||||
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_lib_proc(lib, Scrib_lib_ustring.Invk_gmatch_callback, Object_.Ary(1234, "1(2)", Scrib_kv_utl_.base1_many_(false), 0) , "2;\n 2");
|
||||
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"
|
||||
));
|
||||
}
|
||||
private void Exec_find(String text, String regx, int bgn, boolean plain, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_find, Scrib_kv_utl_.base1_many_(text, regx, bgn, plain));
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(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(String text, String regx, int bgn, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn));
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(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, String regx, int limit, Object repl, String expd) {Exec_gsub(text, regx, limit, repl, expd);}
|
||||
private void Exec_gsub(String text, String regx, int limit, Object repl, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, repl, limit));
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(expd);
|
||||
}
|
||||
private void Exec_gsub_regx_func_0(String text, String regx, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(expd);
|
||||
}
|
||||
private void Exec_gsub_regx_func_1(String text, String regx, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(expd);
|
||||
}
|
||||
private void Exec_gsub_regx_func_2(String text, String regx, String expd) {
|
||||
fxt.Init_lua_module();
|
||||
fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"B\";}}");
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Init_lua_rcvd_rv();
|
||||
fxt.Test_invoke(expd);
|
||||
fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, repl, limit), expd);
|
||||
}
|
||||
// private void Exec_gsub_regx_func_0(String text, String regx, String expd) {
|
||||
// fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)), expd);
|
||||
//// fxt.Init_lua_module();
|
||||
//// fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
//// fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
//// fxt.Init_lua_rcvd_rv();
|
||||
//// fxt.Test_invoke(expd);
|
||||
// }
|
||||
// private void Exec_gsub_regx_func_1(String text, String regx, String expd) {
|
||||
// fxt.Test_scrib_proc_kv_vals(lib, Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)), expd);
|
||||
//// fxt.Init_lua_module();
|
||||
//// fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
//// fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
//// fxt.Init_lua_rcvd_rv();
|
||||
//// fxt.Test_invoke(expd);
|
||||
// }
|
||||
// private void Exec_gsub_regx_func_2(String text, String regx, String expd) {
|
||||
// fxt.Init_lua_module();
|
||||
// fxt.Init_lua_rcvd(Scrib_lib_ustring.Invk_gsub, Scrib_kv_utl_.base1_many_(text, regx, new Scrib_lua_proc("ignore_key", 1)));
|
||||
// fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"A\";}}");
|
||||
// fxt.Init_lua_rcvd_raw("a:3:{s:2:\"op\";s:6:\"return\";s:7:\"nvalues\";i:1;s:6:\"values\";a:1:{i:1;s:1:\"B\";}}");
|
||||
// fxt.Init_lua_rcvd_rv();
|
||||
// fxt.Init_lua_rcvd_rv();
|
||||
// fxt.Test_invoke(expd);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@ import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Scrib_lib_wikibase_entity_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_wikibase().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void GetGlobalSiteId() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase_entity.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,37 +20,44 @@ import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Scrib_lib_wikibase_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = fxt.Core().Lib_wikibase().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void GetGlobalSiteId() {
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
}
|
||||
@Test public void GetEntityId() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_links_add("enwiki", "Earth", "q2");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
|
||||
}
|
||||
@Test public void GetEntity() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc());
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl
|
||||
( ""
|
||||
, " q2;item;2;"
|
||||
, " "
|
||||
, " en;b"
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " id=q2"
|
||||
, " type=item"
|
||||
, " schemaVersion=2"
|
||||
, " labels="
|
||||
, " en="
|
||||
, " language=en"
|
||||
, " value=b"
|
||||
));
|
||||
}
|
||||
@Test public void GetEntity_property() { // PURPOSE: getEntity should be able to convert "p2" to "Property:P2"; EX:es.w:Arnold_Gesell; DATE:2014-02-18
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.page_bldr_("Property:p2").Label_add("en", "b").Xto_page_doc());
|
||||
fxt.Test_lib_proc(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl
|
||||
( ""
|
||||
, " Property:p2;item;2;"
|
||||
, " "
|
||||
, " en;b"
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " id=Property:p2" // only difference from above
|
||||
, " type=item"
|
||||
, " schemaVersion=2"
|
||||
, " labels="
|
||||
, " en="
|
||||
, " language=en"
|
||||
, " value=b"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
public class Scrib_regx_converter_tst {
|
||||
@Before public void init() {fxt.Clear();} Scrib_regx_converter_fxt fxt = new Scrib_regx_converter_fxt();
|
||||
@Before public void init() {fxt.Clear();} private Scrib_regx_converter_fxt fxt = new Scrib_regx_converter_fxt();
|
||||
@Test public void Basic() {fxt.Test_parse("abc012ABC" , "abc012ABC");}
|
||||
@Test public void Pow_0() {fxt.Test_parse("^a" , "\\Ga");}
|
||||
@Test public void Pow_1() {fxt.Test_parse("a^b" , "a\\^b");}
|
||||
|
||||
@@ -95,5 +95,5 @@ public class Xtn_syntaxHighlight_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
private static final byte[] Lang_text = Bry_.new_ascii_("text"), Style_line = Bry_.new_ascii_("-moz-user-select:none;"), Style_highlight = Bry_.new_ascii_("background-color: #FFFFCC;"), Enclose_none = Bry_.new_ascii_("none");
|
||||
public static final byte Xatr_enclose = 2, Xatr_lang = 3, Xatr_style = 4, Xatr_line = 5, Xatr_start = 6, Xatr_highlight = 7;
|
||||
private static final Hash_adp_bry xatrs_syntaxHighlight = Hash_adp_bry.ci_().Add_str_byte("enclose", Xatr_enclose).Add_str_byte("lang", Xatr_lang).Add_str_byte("style", Xatr_style).Add_str_byte("line", Xatr_line).Add_str_byte("start", Xatr_start).Add_str_byte("highlight", Xatr_highlight);
|
||||
private static final Hash_adp_bry xatrs_syntaxHighlight = Hash_adp_bry.ci_ascii_().Add_str_byte("enclose", Xatr_enclose).Add_str_byte("lang", Xatr_lang).Add_str_byte("style", Xatr_style).Add_str_byte("line", Xatr_line).Add_str_byte("start", Xatr_start).Add_str_byte("highlight", Xatr_highlight);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@ import org.junit.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.lib.*;
|
||||
public class Blacklist_scrib_lib_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_page("{{#invoke:Mod_0|Func_0}}");
|
||||
fxt.Init_scrib_proc();
|
||||
lib = new Blacklist_scrib_lib().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); Scrib_lib lib;
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void Exec_test() {
|
||||
fxt.Test_lib_proc(lib, Blacklist_scrib_lib.Invk_test, Object_.Ary("title") , "null");
|
||||
fxt.Test_scrib_proc_str(lib, Blacklist_scrib_lib.Invk_test, Object_.Ary("title") , String_.Null_mark);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ 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.translates; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xop_tvar_lxr implements Xop_lxr {
|
||||
public byte Lxr_tid() {return Xop_lxr_.Tid_tvar;}
|
||||
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Hook_bgn, this);}
|
||||
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
|
||||
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook_bgn, this);}
|
||||
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
|
||||
private static final byte[] Hook_bgn = Bry_.new_ascii_("<tvar|"), Close_nde = Bry_.new_ascii_("</>");
|
||||
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
int rhs_end = Bry_finder.Find_fwd(src, Byte_ascii.Gt, cur_pos); if (rhs_end == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
|
||||
|
||||
@@ -134,10 +134,10 @@ public class Wdata_doc_parser {
|
||||
private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);}
|
||||
public static final OrderedHash Empty_ordered_hash_bry = OrderedHash_.new_bry_(), Empty_ordered_hash_generic = OrderedHash_.new_();
|
||||
private static final byte Prop_tid_m = 0, Prop_tid_q = 1, Prop_tid_g = 2, Prop_tid_rank = 3, Prop_tid_refs = 4;
|
||||
private static final Hash_adp_bry Prop_key_hash = Hash_adp_bry.ci_()
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_m_bry , Prop_tid_m)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_q_bry , Prop_tid_q)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_g_bry , Prop_tid_g)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_rank_bry , Prop_tid_rank)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_refs_bry , Prop_tid_refs);
|
||||
private static final Hash_adp_bry Prop_key_hash = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_m_bry , Prop_tid_m)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_q_bry , Prop_tid_q)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_g_bry , Prop_tid_g)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_rank_bry , Prop_tid_rank)
|
||||
.Add_bry_byte(Wdata_doc_consts.Key_claims_refs_bry , Prop_tid_refs);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Wdata_external_lang_links_data {
|
||||
private Hash_adp_bry langs_hash = Hash_adp_bry.ci_(); private ListAdp langs_list = ListAdp_.new_();
|
||||
private ListAdp langs_list = ListAdp_.new_(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:lang_code
|
||||
public boolean Enabled() {return enabled;} private boolean enabled; public Wdata_external_lang_links_data Enabled_(boolean v) {enabled = v; return this;}
|
||||
public boolean Sort() {return sort;} private boolean sort; public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;}
|
||||
public int Langs_len() {return langs_list.Count();}
|
||||
|
||||
@@ -102,5 +102,5 @@ class Wdata_pf_property_data {
|
||||
}
|
||||
static final byte Atr_of_id = 1, Atr_q_id = 2;
|
||||
private static final byte[] Atr_of_bry = Bry_.new_ascii_("of"), Atr_q_bry = Bry_.new_ascii_("q");
|
||||
private static final Hash_adp_bry Atr_keys = Hash_adp_bry.ci_().Add_bry_byte(Atr_of_bry, Atr_of_id).Add_bry_byte(Atr_q_bry, Atr_q_id);
|
||||
private static final Hash_adp_bry Atr_keys = Hash_adp_bry.ci_ascii_().Add_bry_byte(Atr_of_bry, Atr_of_id).Add_bry_byte(Atr_q_bry, Atr_q_id);
|
||||
}
|
||||
|
||||
@@ -37,14 +37,14 @@ public class Wdata_prop_itm_base_ {
|
||||
if (bval_obj == null) return Val_tid_unknown;
|
||||
return ((Byte_obj_val)bval_obj).Val();
|
||||
}
|
||||
private static final Hash_adp_bry Val_tid_regy = Hash_adp_bry.ci_()
|
||||
.Add_bry_byte(Val_bry_string, Wdata_prop_itm_base_.Val_tid_string)
|
||||
.Add_bry_byte(Val_bry_entity, Wdata_prop_itm_base_.Val_tid_entity)
|
||||
.Add_bry_byte(Val_bry_time, Wdata_prop_itm_base_.Val_tid_time)
|
||||
.Add_bry_byte(Val_bry_globecoordinate, Wdata_prop_itm_base_.Val_tid_globecoordinate)
|
||||
.Add_bry_byte(Val_bry_quantity, Wdata_prop_itm_base_.Val_tid_quantity)
|
||||
.Add_bry_byte(Val_bry_bad, Wdata_prop_itm_base_.Val_tid_bad)
|
||||
;
|
||||
private static final Hash_adp_bry Val_tid_regy = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Val_bry_string, Wdata_prop_itm_base_.Val_tid_string)
|
||||
.Add_bry_byte(Val_bry_entity, Wdata_prop_itm_base_.Val_tid_entity)
|
||||
.Add_bry_byte(Val_bry_time, Wdata_prop_itm_base_.Val_tid_time)
|
||||
.Add_bry_byte(Val_bry_globecoordinate, Wdata_prop_itm_base_.Val_tid_globecoordinate)
|
||||
.Add_bry_byte(Val_bry_quantity, Wdata_prop_itm_base_.Val_tid_quantity)
|
||||
.Add_bry_byte(Val_bry_bad, Wdata_prop_itm_base_.Val_tid_bad)
|
||||
;
|
||||
public static String Val_tid_to_string(byte tid) {
|
||||
switch (tid) {
|
||||
case Val_tid_string : return Val_str_string;
|
||||
@@ -62,11 +62,11 @@ public class Wdata_prop_itm_base_ {
|
||||
if (bval_obj == null) throw Err_.new_fmt_("unknown snak type_id: ~{0}", String_.new_utf8_(v));
|
||||
return ((Byte_obj_val)bval_obj).Val();
|
||||
}
|
||||
private static Hash_adp_bry Snak_tid_regy = Hash_adp_bry.ci_()
|
||||
.Add_bry_byte(Wdata_doc_consts.Val_prop_novalue_bry, Snak_tid_novalue)
|
||||
.Add_str_byte(Wdata_doc_consts.Val_prop_value_str, Snak_tid_value)
|
||||
.Add_str_byte(Wdata_doc_consts.Val_prop_somevalue_str, Snak_tid_somevalue)
|
||||
;
|
||||
private static Hash_adp_bry Snak_tid_regy = Hash_adp_bry.ci_ascii_()
|
||||
.Add_bry_byte(Wdata_doc_consts.Val_prop_novalue_bry, Snak_tid_novalue)
|
||||
.Add_str_byte(Wdata_doc_consts.Val_prop_value_str, Snak_tid_value)
|
||||
.Add_str_byte(Wdata_doc_consts.Val_prop_somevalue_str, Snak_tid_somevalue)
|
||||
;
|
||||
public static String Snak_tid_string(byte v) {
|
||||
switch (v) {
|
||||
case Snak_tid_value: return Wdata_doc_consts.Val_prop_value_str;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
Tfds.Eq(expd, String_.new_utf8_(wdata_mgr.Qids_get(Bry_.new_ascii_(lang), Xow_wiki_domain_.Tid_wikipedia, Bry_.new_ascii_("000"), Bry_.new_utf8_(page))));
|
||||
}
|
||||
public void Test_parse_pid_null(String val) {Test_parse_pid(val, Wdata_wiki_mgr.Pid_null);}
|
||||
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_ascii_(val)));} NumberParser num_parser = new NumberParser();
|
||||
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_ascii_(val)));} private NumberParser num_parser = new NumberParser();
|
||||
public void Init_pages_add(Wdata_doc page) {wdata_mgr.Pages_add(page.Qid(), page);}
|
||||
public void Test_parse(String raw, String expd) {
|
||||
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
|
||||
|
||||
@@ -61,5 +61,5 @@ public class Xox_xowa_html_cmd implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
.Add_bry_byte(Xatr_pos_val__html_end, Pos_html_end)
|
||||
;
|
||||
private static final byte Xatr_pos_id = 1;
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_ascii_().Add_bry_byte(Xatr_pos_key, Xatr_pos_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user