mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Scribunto: Allow int for find
parameter [#802]
This commit is contained in:
parent
59d8a42b22
commit
c801e3a20b
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,12 +13,33 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
package gplx.xowa.xtns.scribunto.libs;
|
||||||
import gplx.objects.strings.unicodes.*;
|
|
||||||
import gplx.core.intls.*; import gplx.langs.regxs.*;
|
import gplx.Bool_;
|
||||||
import gplx.xowa.parsers.*;
|
import gplx.Err_;
|
||||||
import gplx.xowa.xtns.scribunto.procs.*;
|
import gplx.Gfo_usr_dlg_;
|
||||||
import gplx.xowa.xtns.scribunto.libs.patterns.*;
|
import gplx.Io_url;
|
||||||
|
import gplx.Keyval;
|
||||||
|
import gplx.Keyval_;
|
||||||
|
import gplx.List_adp;
|
||||||
|
import gplx.List_adp_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.langs.regxs.Regx_adp;
|
||||||
|
import gplx.langs.regxs.Regx_adp_;
|
||||||
|
import gplx.langs.regxs.Regx_group;
|
||||||
|
import gplx.langs.regxs.Regx_match;
|
||||||
|
import gplx.objects.strings.unicodes.Ustring;
|
||||||
|
import gplx.objects.strings.unicodes.Ustring_;
|
||||||
|
import gplx.xowa.Xoa_page_;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_core;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_kv_utl_;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_lib;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_lua_mod;
|
||||||
|
import gplx.xowa.xtns.scribunto.libs.patterns.Scrib_pattern_matcher;
|
||||||
|
import gplx.xowa.xtns.scribunto.procs.Scrib_proc_args;
|
||||||
|
import gplx.xowa.xtns.scribunto.procs.Scrib_proc_mgr;
|
||||||
|
import gplx.xowa.xtns.scribunto.procs.Scrib_proc_rslt;
|
||||||
|
|
||||||
public class Scrib_lib_ustring implements Scrib_lib {
|
public class Scrib_lib_ustring implements Scrib_lib {
|
||||||
public Scrib_lib_ustring(Scrib_core core) {this.core = core;} private Scrib_core core;
|
public Scrib_lib_ustring(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||||
public String Key() {return "mw.ustring";}
|
public String Key() {return "mw.ustring";}
|
||||||
@ -48,7 +69,7 @@ public class Scrib_lib_ustring implements Scrib_lib {
|
|||||||
}
|
}
|
||||||
private static final int Proc_find = 0, Proc_match = 1, Proc_gmatch_init = 2, Proc_gmatch_callback = 3, Proc_gsub = 4;
|
private static final int Proc_find = 0, Proc_match = 1, Proc_gmatch_init = 2, Proc_gmatch_callback = 3, Proc_gsub = 4;
|
||||||
public static final String Invk_find = "find", Invk_match = "match", Invk_gmatch_init = "gmatch_init", Invk_gmatch_callback = "gmatch_callback", Invk_gsub = "gsub";
|
public static final String Invk_find = "find", Invk_match = "match", Invk_gmatch_init = "gmatch_init", Invk_gmatch_callback = "gmatch_callback", Invk_gsub = "gsub";
|
||||||
private static final String[] Proc_names = String_.Ary(Invk_find, Invk_match, Invk_gmatch_init, Invk_gmatch_callback, Invk_gsub);
|
private static final String[] Proc_names = String_.Ary(Invk_find, Invk_match, Invk_gmatch_init, Invk_gmatch_callback, Invk_gsub);
|
||||||
public boolean Find(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean Find(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
// get args
|
// get args
|
||||||
String text_str = args.Xstr_str_or_null(0);
|
String text_str = args.Xstr_str_or_null(0);
|
||||||
@ -113,7 +134,8 @@ public class Scrib_lib_ustring implements Scrib_lib {
|
|||||||
public boolean Match(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
public boolean Match(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||||
// get args
|
// get args
|
||||||
String text_str = args.Xstr_str_or_null(0); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
String text_str = args.Xstr_str_or_null(0); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
||||||
String find_str = args.Cast_str_or_null(1);
|
// 2019-20-01|ISSUE#:802|passing integer should return NULL, not throw error
|
||||||
|
String find_str = args.Xstr_str_or_null(1);
|
||||||
int bgn_as_codes_base1 = args.Cast_int_or(2, 1);
|
int bgn_as_codes_base1 = args.Cast_int_or(2, 1);
|
||||||
|
|
||||||
// validate / adjust
|
// validate / adjust
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
or alternatively under the terms of the Apache License Version 2.0.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,15 +13,23 @@ The terms of each license can be found in the source code repository:
|
|||||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
package gplx.xowa.xtns.scribunto.libs;
|
||||||
import org.junit.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
|
|
||||||
|
import gplx.Keyval_;
|
||||||
|
import gplx.String_;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_kv_utl_;
|
||||||
|
import gplx.xowa.xtns.scribunto.Scrib_lib;
|
||||||
|
import gplx.xowa.xtns.scribunto.engines.mocks.Mock_scrib_fxt;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Scrib_lib_ustring__match__tst {
|
public class Scrib_lib_ustring__match__tst {
|
||||||
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
|
||||||
@Before public void init() {
|
@Before public void init() {
|
||||||
fxt.Clear();
|
fxt.Clear();
|
||||||
lib = fxt.Core().Lib_ustring().Init();
|
lib = fxt.Core().Lib_ustring().Init();
|
||||||
}
|
}
|
||||||
@Test public void Basic() {
|
@Test public void Basic() {
|
||||||
Exec_match("abcd" , "bc" , 1, "bc"); // basic
|
Exec_match("abcd" , "bc" , 1, "bc"); // basic
|
||||||
Exec_match("abcd" , "x" , 1, String_.Null_mark); // empty
|
Exec_match("abcd" , "x" , 1, String_.Null_mark); // empty
|
||||||
Exec_match("abcd" , "a" , 2, String_.Null_mark); // bgn
|
Exec_match("abcd" , "a" , 2, String_.Null_mark); // bgn
|
||||||
@ -35,24 +43,26 @@ public class Scrib_lib_ustring__match__tst {
|
|||||||
Exec_match(1 , "a" , 1, String_.Null_mark); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
Exec_match(1 , "a" , 1, String_.Null_mark); // Module can pass raw ints; PAGE:en.w:Budget_of_the_European_Union; DATE:2015-01-22
|
||||||
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
|
Exec_match("" , "a?" , 1, ""); // no results with ? should return "" not nil; PAGE:en.d:民; DATE:2015-01-30
|
||||||
}
|
}
|
||||||
@Test public void Args_out_of_order() {
|
@Test public void Args_out_of_order() {
|
||||||
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, Keyval_.Ary(Keyval_.int_(2, "[a]")));
|
fxt.Test__proc__kvps__empty(lib, Scrib_lib_ustring.Invk_match, Keyval_.Ary(Keyval_.int_(2, "[a]")));
|
||||||
}
|
}
|
||||||
@Test public void Balanced__trailing_whitespace() { // PURPOSE: match trailing whitespace; PAGE:en.w:Portal:Constructed_languages/Intro DATE:2018-07-02
|
@Test public void Balanced__trailing_whitespace() { // PURPOSE: match trailing whitespace; PAGE:en.w:Portal:Constructed_languages/Intro DATE:2018-07-02
|
||||||
Exec_match("[[a]] b", "%b[]%s*", 1, "[[a]] ");
|
Exec_match("[[a]] b", "%b[]%s*", 1, "[[a]] ");
|
||||||
}
|
}
|
||||||
@Test public void Balanced__numbered_1() { // PURPOSE: handle mix of balanced and regular capture; PAGE:en.w:Bahamas
|
@Test public void Balanced__numbered_1() { // PURPOSE: handle mix of balanced and regular capture; PAGE:en.w:Bahamas
|
||||||
Exec_match("[[5]]X99Y", "%b[]X(%d)%1Y", 1, "9");
|
Exec_match("[[5]]X99Y", "%b[]X(%d)%1Y", 1, "9");
|
||||||
}
|
}
|
||||||
@Test public void Balanced__numbered_2() {
|
@Test public void Balanced__numbered_2() {
|
||||||
Exec_match("A88B[[5]]X99Y", "A(%d)%1B%b[]X(%d)%2Y", 1, "8;9");
|
Exec_match("A88B[[5]]X99Y", "A(%d)%1B%b[]X(%d)%2Y", 1, "8;9");
|
||||||
}
|
}
|
||||||
@Test public void Unicode_alpha() {// ISSUE#:502; DATE:2019-07-01
|
@Test public void Unicode_alpha() {// ISSUE#:502; DATE:2019-07-01
|
||||||
Exec_match("ä" , "%a", 1, "ä");
|
Exec_match("ä" , "%a", 1, "ä");
|
||||||
}
|
}
|
||||||
|
@Test public void Number() {// 2019-20-01|ISSUE#:802|passing integer should return NULL, not throw error
|
||||||
|
Exec_match_obj("A" , 0, 0, String_.Null_mark);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test public void Match_viwiktionary() {
|
||||||
// @Test public void Match_viwiktionary() {
|
|
||||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||||
// Exec_match("tr" , "()(r)", 1, ";"); // should return all matches
|
// Exec_match("tr" , "()(r)", 1, ";"); // should return all matches
|
||||||
// Exec_match("tr" , "^([b]*).-([c]*)$", 1, ";"); // should return all matches
|
// Exec_match("tr" , "^([b]*).-([c]*)$", 1, ";"); // should return all matches
|
||||||
@ -60,4 +70,7 @@ public class Scrib_lib_ustring__match__tst {
|
|||||||
private void Exec_match(Object text, String regx, int bgn, String expd) {
|
private void Exec_match(Object text, String regx, int bgn, String expd) {
|
||||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn), expd);
|
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn), expd);
|
||||||
}
|
}
|
||||||
|
private void Exec_match_obj(Object text, Object regx, int bgn, String expd) {
|
||||||
|
fxt.Test__proc__kvps__flat(lib, Scrib_lib_ustring.Invk_match, Scrib_kv_utl_.base1_many_(text, regx, bgn), expd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user