mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -15,7 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki;
|
||||
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import org.junit.Test;
|
||||
public class XophpArrayInstanceTest { // REF: http://php.net/manual/en/language.types.array.php
|
||||
private final XophpArrayfxt fxt = new XophpArrayfxt();
|
||||
@Test public void array__kvs() {
|
||||
@@ -132,7 +134,7 @@ public class XophpArrayInstanceTest { // REF: http://php.net/manual/en/language.
|
||||
fxt.Test__Count(ary, 0);
|
||||
fxt.Test__Pop(ary, null);
|
||||
}
|
||||
@Test public void Itm_str_concat_end() {
|
||||
@Test public void Itm_str_concat_end() {
|
||||
XophpArray ary = XophpArray.New();
|
||||
ary.Add(0, "a").Add(1, "b").Add(2, "c");
|
||||
|
||||
@@ -141,13 +143,13 @@ public class XophpArrayInstanceTest { // REF: http://php.net/manual/en/language.
|
||||
fxt.Test__Itm_str_concat_end(ary, "b1", 1, "1");
|
||||
fxt.Test__Itm_str_concat_end(ary, "c2", 2, "2");
|
||||
}
|
||||
@Test public void Clone() {
|
||||
@Test public void Clone() {
|
||||
XophpArray ary = XophpArray.New();
|
||||
ary.Add(0, "a").Add(1, "b").Add(2, "c");
|
||||
|
||||
fxt.Test__Eq(ary, ary.Clone());
|
||||
}
|
||||
@Test public void Get_by() {
|
||||
@Test public void Get_by() {
|
||||
XophpArray ary = XophpArray.New();
|
||||
ary.Add("0", "a").Add("1", "b").Add("2", "c");
|
||||
|
||||
@@ -157,29 +159,29 @@ public class XophpArrayInstanceTest { // REF: http://php.net/manual/en/language.
|
||||
}
|
||||
class XophpArrayfxt {
|
||||
public void Test__Count(XophpArray ary, int expd) {
|
||||
Gftest.Eq__int(expd, ary.Len());
|
||||
GfoTstr.Eq(expd, ary.Len());
|
||||
}
|
||||
public void Test__array(XophpArray ary, XophpArrayItm... expd) {
|
||||
XophpArrayItm[] actl = ary.To_ary();
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
Gftest.EqAry(expd, actl);
|
||||
}
|
||||
public void Test__unset(XophpArray ary, int idx, XophpArrayItm... expd) {
|
||||
XophpArrayItm[] actl = ary.To_ary();
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
Gftest.EqAry(expd, actl);
|
||||
}
|
||||
public void Test__Pop(XophpArray ary, String expd) {
|
||||
String actl = (String)XophpArray.array_pop(ary);
|
||||
Gftest.Eq__str(expd, actl);
|
||||
GfoTstr.Eq(expd, actl);
|
||||
}
|
||||
public void Test__Itm_str_concat_end(XophpArray ary, String expd, int idx, String v) {
|
||||
ary.Itm_str_concat_end(idx, v);
|
||||
String actl = ary.Get_at_str(idx);
|
||||
Gftest.Eq__str(expd, actl);
|
||||
GfoTstr.Eq(expd, actl);
|
||||
}
|
||||
public void Test__Eq(XophpArray lhs, XophpArray rhs) {
|
||||
Gftest.Eq__ary(lhs.To_ary(), rhs.To_ary());
|
||||
Gftest.EqAry(lhs.To_ary(), rhs.To_ary());
|
||||
}
|
||||
public void Test__Get_by(XophpArray ary, String key, Object expd) {
|
||||
Gftest.Eq__obj_or_null(expd, ary.Get_by(key));
|
||||
GfoTstr.EqObjToStr(expd, ary.Get_by(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki;
|
||||
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XophpArrayStaticTest {
|
||||
@@ -260,7 +259,7 @@ public class XophpArrayStaticTest {
|
||||
}
|
||||
@Test public void implode() {
|
||||
XophpArray orig = fxt.Make().Add_many("a", "b", "c");
|
||||
Gftest.Eq__str
|
||||
GfoTstr.Eq
|
||||
( "a b c"
|
||||
, XophpArray.implode(" ", orig)
|
||||
);
|
||||
@@ -270,19 +269,19 @@ public class XophpArrayStaticTest {
|
||||
XophpArray array;
|
||||
// Example #1
|
||||
array = XophpArray.New("Mac", "NT", "Irix", "Linux");
|
||||
Gftest.Eq__bool(BoolUtl.Y, XophpArray.in_array("Irix", array));
|
||||
Gftest.Eq__bool(BoolUtl.N, XophpArray.in_array("mac" , array));
|
||||
GfoTstr.Eq(BoolUtl.Y, XophpArray.in_array("Irix", array));
|
||||
GfoTstr.Eq(BoolUtl.N, XophpArray.in_array("mac" , array));
|
||||
|
||||
// Example #2
|
||||
array = XophpArray.New(12.4d, 1.13d);
|
||||
Gftest.Eq__bool(BoolUtl.N, XophpArray.in_array("12.4", array, true));
|
||||
Gftest.Eq__bool(BoolUtl.Y, XophpArray.in_array( 1.13d, array, true));
|
||||
GfoTstr.Eq(BoolUtl.N, XophpArray.in_array("12.4", array, true));
|
||||
GfoTstr.Eq(BoolUtl.Y, XophpArray.in_array( 1.13d, array, true));
|
||||
|
||||
// Example #3
|
||||
array = XophpArray.New(XophpArray.New('p', 'h'), XophpArray.New('p', 'r'), 'o');
|
||||
Gftest.Eq__bool(BoolUtl.Y, XophpArray.in_array(XophpArray.New('p', 'h'), array));
|
||||
Gftest.Eq__bool(BoolUtl.N, XophpArray.in_array(XophpArray.New('f', 'i'), array));
|
||||
Gftest.Eq__bool(BoolUtl.Y, XophpArray.in_array('o', array));
|
||||
GfoTstr.Eq(BoolUtl.Y, XophpArray.in_array(XophpArray.New('p', 'h'), array));
|
||||
GfoTstr.Eq(BoolUtl.N, XophpArray.in_array(XophpArray.New('f', 'i'), array));
|
||||
GfoTstr.Eq(BoolUtl.Y, XophpArray.in_array('o', array));
|
||||
}
|
||||
@Test public void array_shift() {
|
||||
XophpArray array;
|
||||
@@ -292,7 +291,7 @@ public class XophpArrayStaticTest {
|
||||
array = XophpArray.New("a", "b");
|
||||
shifted = (String)XophpArray.array_shift(array);
|
||||
|
||||
Gftest.Eq__str("a", shifted);
|
||||
GfoTstr.Eq("a", shifted);
|
||||
fxt.Test__eq
|
||||
( XophpArray.New().Add(0, "b")
|
||||
, array
|
||||
@@ -302,7 +301,7 @@ public class XophpArrayStaticTest {
|
||||
array = XophpArray.New().Add("a", "a").Add(2, "b").Add(5, "c");
|
||||
shifted = (String)XophpArray.array_shift(array);
|
||||
|
||||
Gftest.Eq__str("a", shifted);
|
||||
GfoTstr.Eq("a", shifted);
|
||||
fxt.Test__eq
|
||||
( XophpArray.New().Add(0, "b").Add(1, "c")
|
||||
, array
|
||||
@@ -312,7 +311,7 @@ public class XophpArrayStaticTest {
|
||||
array = XophpArray.New();
|
||||
shifted = (String)XophpArray.array_shift(array);
|
||||
|
||||
Gftest.Eq__bool_y(shifted == null);
|
||||
GfoTstr.EqBoolY(shifted == null);
|
||||
fxt.Test__eq
|
||||
( XophpArray.New()
|
||||
, array
|
||||
@@ -322,15 +321,15 @@ public class XophpArrayStaticTest {
|
||||
array = null;
|
||||
shifted = (String)XophpArray.array_shift(array);
|
||||
|
||||
Gftest.Eq__bool_y(shifted == null);
|
||||
Gftest.Eq__bool_y(array == null);
|
||||
GfoTstr.EqBoolY(shifted == null);
|
||||
GfoTstr.EqBoolY(array == null);
|
||||
|
||||
// PHP examples
|
||||
// Example #1
|
||||
array = XophpArray.New("orange", "banana", "apple", "strawberry");
|
||||
shifted = (String)XophpArray.array_shift(array);
|
||||
|
||||
Gftest.Eq__str("orange", shifted);
|
||||
GfoTstr.Eq("orange", shifted);
|
||||
fxt.Test__eq
|
||||
( XophpArray.New().Add(0, "banana").Add(1, "apple").Add(2, "strawberry")
|
||||
, array
|
||||
@@ -378,16 +377,16 @@ public class XophpArrayStaticTest {
|
||||
array = XophpArray.New("step one", "step two", "step three", "step four");
|
||||
|
||||
// by default, the pointer is on the first element
|
||||
Gftest.Eq__str("step one", (String)XophpArray.current(array));
|
||||
GfoTstr.Eq("step one", (String)XophpArray.current(array));
|
||||
|
||||
// skip two steps
|
||||
XophpArray.next(array);
|
||||
XophpArray.next(array);
|
||||
Gftest.Eq__str("step three", (String)XophpArray.current(array));
|
||||
GfoTstr.Eq("step three", (String)XophpArray.current(array));
|
||||
|
||||
// reset pointer, start again on step one
|
||||
XophpArray.reset(array);
|
||||
Gftest.Eq__str("step one", (String)XophpArray.current(array));
|
||||
GfoTstr.Eq("step one", (String)XophpArray.current(array));
|
||||
}
|
||||
@Test public void array_diff() {
|
||||
// test To_str
|
||||
@@ -447,7 +446,7 @@ public class XophpArrayStaticTest {
|
||||
class XophpArray_fxt {
|
||||
public XophpArray Make() {return new XophpArray();}
|
||||
public void Test__eq(XophpArray expd, XophpArray actl) {
|
||||
Gftest.Eq__str(expd.To_str(), actl.To_str());
|
||||
GfoTstr.Eq(expd.To_str(), actl.To_str());
|
||||
}
|
||||
}
|
||||
class XophpArrayTestCallbackOwner implements XophpCallbackOwner {
|
||||
@@ -455,15 +454,15 @@ class XophpArrayTestCallbackOwner implements XophpCallbackOwner {
|
||||
public Object Call(String method, Object... args) {
|
||||
switch (method) {
|
||||
case "array_filter_even":
|
||||
return Int_.Cast(args[0]) % 2 == 0;
|
||||
return IntUtl.Cast(args[0]) % 2 == 0;
|
||||
case "array_filter_odd":
|
||||
return Int_.Cast(args[0]) % 2 == 1;
|
||||
return IntUtl.Cast(args[0]) % 2 == 1;
|
||||
case "array_filter_key":
|
||||
return String_.cast(args[0]).equals("b");
|
||||
return StringUtl.Cast(args[0]).equals("b");
|
||||
case "array_filter_both":
|
||||
return String_.cast(args[0]).equals("b") || Int_.Cast(args[1]) == 4;
|
||||
return StringUtl.Cast(args[0]).equals("b") || IntUtl.Cast(args[1]) == 4;
|
||||
default:
|
||||
throw Err_.new_unhandled_default(method);
|
||||
throw ErrUtl.NewUnhandled(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package gplx.xowa.mediawiki.includes;
|
||||
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.xowa.mediawiki.XophpArray;
|
||||
import gplx.xowa.mediawiki.XophpCallback;
|
||||
import gplx.xowa.mediawiki.XophpCallbackOwner;
|
||||
@@ -18,23 +18,23 @@ public class XomwHooksTest {
|
||||
|
||||
@Test
|
||||
public void isRegistered() {
|
||||
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolN(XomwHooks.isRegistered("test1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void register() {
|
||||
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolN(XomwHooks.isRegistered("test1"));
|
||||
XomwHooks.register("test1", callbackOwner.NewCallback("test1"));
|
||||
Gftest.Eq__bool_y(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolY(XomwHooks.isRegistered("test1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clear() {
|
||||
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolN(XomwHooks.isRegistered("test1"));
|
||||
XomwHooks.register("test1", callbackOwner.NewCallback("test1"));
|
||||
Gftest.Eq__bool_y(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolY(XomwHooks.isRegistered("test1"));
|
||||
XomwHooks.clear("test1");
|
||||
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
|
||||
GfoTstr.EqBoolN(XomwHooks.isRegistered("test1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +43,7 @@ public class XomwHooksTest {
|
||||
XomwHooks.register("test1", callbackOwner.NewCallback("test1b"));
|
||||
XomwHooks.register("test2", callbackOwner.NewCallback("test2"));
|
||||
XophpArray handlers = XomwHooks.getHandlers("test1");
|
||||
Gftest.Eq__ary
|
||||
GfoTstr.EqLines
|
||||
( new String[] {"test1a", "test1b"}
|
||||
, extractKeysFromCallbackAry(handlers)
|
||||
);
|
||||
@@ -55,9 +55,9 @@ public class XomwHooksTest {
|
||||
XomwHooks.register("test1", callbackOwner.NewCallback("test1b"));
|
||||
XomwHooks.register("test2", callbackOwner.NewCallback("test2"));
|
||||
|
||||
Gftest.Eq__bool_y(XomwHooks.run("test1", XophpArray.New(1, 2, 3)));
|
||||
GfoTstr.EqBoolY(XomwHooks.run("test1", XophpArray.New(1, 2, 3)));
|
||||
|
||||
Gftest.Eq__str("test1a:3;test1b:3;", callbackOwner.Result());
|
||||
GfoTstr.Eq("test1a:3;test1b:3;", callbackOwner.Result());
|
||||
}
|
||||
|
||||
private static String[] extractKeysFromCallbackAry(XophpArray callbacks) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package gplx.xowa.mediawiki.includes.libs.services;
|
||||
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.xowa.mediawiki.XophpArray;
|
||||
import gplx.xowa.mediawiki.XophpCallback;
|
||||
import gplx.xowa.mediawiki.XophpCallbackOwner;
|
||||
@@ -19,55 +19,55 @@ public class XomwServiceContainerTest {
|
||||
container.applyWiring(wiring.NewWirings("test1", "test2"));
|
||||
|
||||
// hasService -> checks if instantiator exists
|
||||
Gftest.Eq__bool_y(container.hasService("test1"));
|
||||
Gftest.Eq__bool_n(container.hasService("test9"));
|
||||
GfoTstr.EqBoolY(container.hasService("test1"));
|
||||
GfoTstr.EqBoolN(container.hasService("test9"));
|
||||
|
||||
// getServiceNames -> gets list of instantiators
|
||||
Gftest.Eq__str(XophpArray.<String>New("test1", "test2").To_str(), container.getServiceNames().To_str());
|
||||
GfoTstr.Eq(XophpArray.<String>New("test1", "test2").To_str(), container.getServiceNames().To_str());
|
||||
|
||||
// getService -> creates service
|
||||
XomwServiceExample service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__str("test1", service.Name());
|
||||
Gftest.Eq__int(0, service.InstanceNumber());
|
||||
Gftest.Eq__obj_or_null(extraInstantiatorArg, service.ExtraInstantiatorArg());
|
||||
GfoTstr.Eq("test1", service.Name());
|
||||
GfoTstr.Eq(0, service.InstanceNumber());
|
||||
GfoTstr.EqObjToStr(extraInstantiatorArg, service.ExtraInstantiatorArg());
|
||||
|
||||
// getService again -> retrieves service
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(0, service.InstanceNumber());
|
||||
GfoTstr.Eq(0, service.InstanceNumber());
|
||||
|
||||
// resetService + getService -> recreates service
|
||||
container.resetService("test1");
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
GfoTstr.Eq(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns service if created
|
||||
service = (XomwServiceExample)container.peekService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
GfoTstr.Eq(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns null if not created
|
||||
Gftest.Eq__obj_or_null(null, (XomwServiceExample)container.peekService("test2"));
|
||||
GfoTstr.EqObjToStr(null, (XomwServiceExample)container.peekService("test2"));
|
||||
|
||||
// disableService -> disables service
|
||||
container.disableService("test1");
|
||||
|
||||
// isServiceDisabled -> checks disabled state
|
||||
Gftest.Eq__bool_y(container.isServiceDisabled("test1"));
|
||||
Gftest.Eq__bool_n(container.isServiceDisabled("test2"));
|
||||
GfoTstr.EqBoolY(container.isServiceDisabled("test1"));
|
||||
GfoTstr.EqBoolN(container.isServiceDisabled("test2"));
|
||||
|
||||
// resetService -> also reenables service
|
||||
container.resetService("test1");
|
||||
Gftest.Eq__bool_n(container.isServiceDisabled("test1"));
|
||||
GfoTstr.EqBoolN(container.isServiceDisabled("test1"));
|
||||
|
||||
// redefineService -> redefines instantiator if not called
|
||||
container.redefineService("test2", wiring.NewCallback("test2a"));
|
||||
service = (XomwServiceExample)container.getService("test2");
|
||||
Gftest.Eq__str("test2a", service.Name());
|
||||
GfoTstr.Eq("test2a", service.Name());
|
||||
|
||||
// addServiceManipulator -> adds extra callback
|
||||
container.resetService("test2");
|
||||
container.addServiceManipulator("test2", manipulator.NewCallback("manip1"));
|
||||
service = (XomwServiceExample)container.getService("test2");
|
||||
Gftest.Eq__str("manip1", service.Name());
|
||||
GfoTstr.Eq("manip1", service.Name());
|
||||
|
||||
// destroy ->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user