1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Scribunto: Return null if integer key is not found

This commit is contained in:
gnosygnu 2017-09-16 21:36:50 -04:00
parent 5e7263ec5c
commit 131c2f696c
3 changed files with 8 additions and 7 deletions

View File

@ -31,7 +31,7 @@ public class Xoa_app_ {
}
public static final String Name = "xowa";
public static final int Version_id = 537;
public static final String Version = "4.5.14.1708";
public static final String Version = "4.5.15.1709";
public static String Build_date = "2012-12-30 00:00:00";
public static String Build_date_fmt = "yyyy-MM-dd HH:mm:ss";
public static String Op_sys_str;

View File

@ -115,13 +115,13 @@ public class Scrib_lib_mw implements Scrib_lib {
if (idx_int != Int_.Min_value) { // idx is integer
Arg_nde_tkn nde = Get_arg(frame, idx_int, frame_arg_adj);
//frame.Args_eval_by_idx(core.Ctx().Src(), idx_int); // NOTE: arg[0] is always MW function name; EX: {{#invoke:Mod_0|Func_0|Arg_1}}; arg_x = "Mod_0"; args[0] = "Func_0"; args[1] = "Arg_1"
if (nde == null) return rslt.Init_ary_empty();
if (nde == null) return rslt.Init_obj(null); // idx_str does not exist; [null] not []; PAGE:en.w:Sainte-Catherine,_Quebec DATE:2017-09-16
nde.Val_tkn().Tmpl_evaluate(ctx, src, core.Frame_parent(), tmp_bfr);
return rslt.Init_obj(tmp_bfr.To_str_and_clear());
}
else {
Arg_nde_tkn nde = frame.Args_get_by_key(src, Bry_.new_u8(idx_str));
if (nde == null) return rslt.Init_ary_empty(); // idx_str does not exist;
if (nde == null) return rslt.Init_obj(null); // idx_str does not exist; [null] not []; PAGE:en.w:Sainte-Catherine,_Quebec DATE:2017-09-16
nde.Val_tkn().Tmpl_evaluate(ctx, src, core.Frame_parent(), tmp_bfr);
return rslt.Init_obj(tmp_bfr.To_str_and_clear_and_trim()); // NOTE: must trim if key_exists; DUPE:TRIM_IF_KEY
}
@ -139,7 +139,7 @@ public class Scrib_lib_mw implements Scrib_lib {
if (idx == cur) return nde;
else ++cur;
}
return invk.Args_get_by_key(src, Bry_.To_a7_bry(idx + 1, 1));
return null; // return null since index does not exist; EX: args[2] when {{#invoke:mod|test|3=abc}} PAGE:en.w:Sainte-Catherine,_Quebec DATE:2017-09-16
}
private static boolean Verify_arg_key(byte[] src, int idx, Arg_nde_tkn nde) {
int key_int = Bry_find_.Not_found;

View File

@ -47,9 +47,9 @@ public class Scrib_lib_mw__lib_tst {
fxt.Init_frame_current(Keyval_.int_(1, "val_1"), Keyval_.new_("key_2", "val_2"), Keyval_.int_(3, "val_3"));
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "1") , "val_1"); // get 1st by idx
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "2") , "val_3"); // get 2nd by idx (which is "3", not "key_2)
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3")); // get 3rd by idx (which is n/a, not "val_3")
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "3") , null); // get 3rd as null
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_2") , "val_2"); // get key_2
fxt.Test_scrib_proc_empty (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3")); // key_3 n/a
fxt.Test_scrib_proc_str (lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("current", "key_3") , null); // key_3 n/a
}
@Test public void GetExpandedArgument_parent() {
fxt.Init_frame_parent ("test", Keyval_.new_("1", "a1"), Keyval_.new_("2", "a2"));
@ -63,11 +63,12 @@ public class Scrib_lib_mw__lib_tst {
@Test public void GetExpandedArgument_numeric_key_2() { // PURPOSE.FIX: same as above, but for parent context; DATE:2013-09-23
fxt.Init_frame_parent ("test", Keyval_.new_("2", "a1"));
fxt.Init_frame_current(Keyval_.new_("2", "a2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "1"), null); // PAGE:en.w:Sainte-Catherine,_Quebec; DATE:2017-09-16
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2"), "a1"); // get 1st by idx, even though idx is String
}
@Test public void GetExpandedArgument_out_of_bounds() {
fxt.Init_frame_parent ("test");
fxt.Test_scrib_proc_empty(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2"));
fxt.Test_scrib_proc_str(lib, Scrib_lib_mw.Invk_getExpandedArgument, Object_.Ary("parent", "2"), null);
}
@Test public void IsSubsting() {
fxt.Test_scrib_proc_bool(lib, Scrib_lib_mw.Invk_isSubsting, Object_.Ary_empty, false);