mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
@@ -270,19 +270,19 @@ public class XophpArrayStaticTest {
|
||||
XophpArray array;
|
||||
// Example #1
|
||||
array = XophpArray.New("Mac", "NT", "Irix", "Linux");
|
||||
Gftest.Eq__bool(Bool_.Y, XophpArray.in_array("Irix", array));
|
||||
Gftest.Eq__bool(Bool_.N, XophpArray.in_array("mac" , array));
|
||||
Gftest.Eq__bool(BoolUtl.Y, XophpArray.in_array("Irix", array));
|
||||
Gftest.Eq__bool(BoolUtl.N, XophpArray.in_array("mac" , array));
|
||||
|
||||
// Example #2
|
||||
array = XophpArray.New(12.4d, 1.13d);
|
||||
Gftest.Eq__bool(Bool_.N, XophpArray.in_array("12.4", array, true));
|
||||
Gftest.Eq__bool(Bool_.Y, XophpArray.in_array( 1.13d, array, true));
|
||||
Gftest.Eq__bool(BoolUtl.N, XophpArray.in_array("12.4", array, true));
|
||||
Gftest.Eq__bool(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(Bool_.Y, XophpArray.in_array(XophpArray.New('p', 'h'), array));
|
||||
Gftest.Eq__bool(Bool_.N, XophpArray.in_array(XophpArray.New('f', 'i'), array));
|
||||
Gftest.Eq__bool(Bool_.Y, XophpArray.in_array('o', array));
|
||||
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));
|
||||
}
|
||||
@Test public void array_shift() {
|
||||
XophpArray array;
|
||||
|
||||
@@ -1,118 +1,112 @@
|
||||
package gplx.xowa.mediawiki.includes.libs.services;
|
||||
|
||||
import gplx.Err_;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.tests.Gftest_fxt;
|
||||
import gplx.xowa.mediawiki.XophpArray;
|
||||
import gplx.xowa.mediawiki.XophpCallback;
|
||||
import gplx.xowa.mediawiki.XophpCallbackOwner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class XomwServiceContainerTest {
|
||||
private XomwServiceContainer container = new XomwServiceContainer();
|
||||
private XomwServiceContainerExample wiring = new XomwServiceContainerExample();
|
||||
private XomwServiceManipulatorExample manipulator = new XomwServiceManipulatorExample();
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
XophpArray<String> extraInstantiatorArg = XophpArray.<String>New("a", "b");
|
||||
XomwServiceContainer container = new XomwServiceContainer(extraInstantiatorArg);
|
||||
|
||||
// applyWiring -> adds servicesInstantator by calling defineService
|
||||
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"));
|
||||
|
||||
// getServiceNames -> gets list of instantiators
|
||||
Gftest.Eq__str(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());
|
||||
|
||||
// getService again -> retrieves service
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(0, service.InstanceNumber());
|
||||
|
||||
// resetService + getService -> recreates service
|
||||
container.resetService("test1");
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns service if created
|
||||
service = (XomwServiceExample)container.peekService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns null if not created
|
||||
Gftest.Eq__obj_or_null(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"));
|
||||
|
||||
// resetService -> also reenables service
|
||||
container.resetService("test1");
|
||||
Gftest.Eq__bool_n(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());
|
||||
|
||||
// addServiceManipulator -> adds extra callback
|
||||
container.resetService("test2");
|
||||
container.addServiceManipulator("test2", manipulator.NewCallback("manip1"));
|
||||
service = (XomwServiceExample)container.getService("test2");
|
||||
Gftest.Eq__str("manip1", service.Name());
|
||||
|
||||
// destroy ->
|
||||
|
||||
// loadWiringFiles ->
|
||||
|
||||
// importWiring ->
|
||||
}
|
||||
|
||||
static class XomwServiceExample {
|
||||
private static int instanceNumberCounter = 0;
|
||||
public XomwServiceExample(String name, Object extraInstantiatorArg) {
|
||||
this.name = name;
|
||||
this.extraInstantiatorArg = extraInstantiatorArg;
|
||||
this.instanceNumber = instanceNumberCounter++;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Object ExtraInstantiatorArg() {return extraInstantiatorArg;} private final Object extraInstantiatorArg;
|
||||
public int InstanceNumber() {return instanceNumber;} private final int instanceNumber;
|
||||
}
|
||||
class XomwServiceContainerExample implements XophpCallbackOwner {
|
||||
private XophpArray<XophpCallback> wirings;
|
||||
@Override
|
||||
public Object Call(String method, Object... args) {
|
||||
XomwServiceContainer mediaWikiServices = (XomwServiceContainer)args[0];
|
||||
return new XomwServiceExample(method, args[1]);
|
||||
}
|
||||
public XophpArray<XophpCallback> NewWirings(String... names) {
|
||||
wirings = new XophpArray();
|
||||
for (String name : names) {
|
||||
wirings.Add(name, this.NewCallback(name));
|
||||
}
|
||||
return wirings;
|
||||
}
|
||||
}
|
||||
class XomwServiceManipulatorExample implements XophpCallbackOwner {
|
||||
@Override
|
||||
public Object Call(String method, Object... args) {
|
||||
XophpArray manipulatorArgs = (XophpArray)args[0];
|
||||
return new XomwServiceExample(method, manipulatorArgs);
|
||||
}
|
||||
}
|
||||
package gplx.xowa.mediawiki.includes.libs.services;
|
||||
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.xowa.mediawiki.XophpArray;
|
||||
import gplx.xowa.mediawiki.XophpCallback;
|
||||
import gplx.xowa.mediawiki.XophpCallbackOwner;
|
||||
import org.junit.Test;
|
||||
public class XomwServiceContainerTest {
|
||||
private XomwServiceContainer container = new XomwServiceContainer();
|
||||
private XomwServiceContainerExample wiring = new XomwServiceContainerExample();
|
||||
private XomwServiceManipulatorExample manipulator = new XomwServiceManipulatorExample();
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
XophpArray<String> extraInstantiatorArg = XophpArray.<String>New("a", "b");
|
||||
XomwServiceContainer container = new XomwServiceContainer(extraInstantiatorArg);
|
||||
|
||||
// applyWiring -> adds servicesInstantator by calling defineService
|
||||
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"));
|
||||
|
||||
// getServiceNames -> gets list of instantiators
|
||||
Gftest.Eq__str(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());
|
||||
|
||||
// getService again -> retrieves service
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(0, service.InstanceNumber());
|
||||
|
||||
// resetService + getService -> recreates service
|
||||
container.resetService("test1");
|
||||
service = (XomwServiceExample)container.getService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns service if created
|
||||
service = (XomwServiceExample)container.peekService("test1");
|
||||
Gftest.Eq__int(1, service.InstanceNumber());
|
||||
|
||||
// peekService -> returns null if not created
|
||||
Gftest.Eq__obj_or_null(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"));
|
||||
|
||||
// resetService -> also reenables service
|
||||
container.resetService("test1");
|
||||
Gftest.Eq__bool_n(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());
|
||||
|
||||
// addServiceManipulator -> adds extra callback
|
||||
container.resetService("test2");
|
||||
container.addServiceManipulator("test2", manipulator.NewCallback("manip1"));
|
||||
service = (XomwServiceExample)container.getService("test2");
|
||||
Gftest.Eq__str("manip1", service.Name());
|
||||
|
||||
// destroy ->
|
||||
|
||||
// loadWiringFiles ->
|
||||
|
||||
// importWiring ->
|
||||
}
|
||||
|
||||
static class XomwServiceExample {
|
||||
private static int instanceNumberCounter = 0;
|
||||
public XomwServiceExample(String name, Object extraInstantiatorArg) {
|
||||
this.name = name;
|
||||
this.extraInstantiatorArg = extraInstantiatorArg;
|
||||
this.instanceNumber = instanceNumberCounter++;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Object ExtraInstantiatorArg() {return extraInstantiatorArg;} private final Object extraInstantiatorArg;
|
||||
public int InstanceNumber() {return instanceNumber;} private final int instanceNumber;
|
||||
}
|
||||
class XomwServiceContainerExample implements XophpCallbackOwner {
|
||||
private XophpArray<XophpCallback> wirings;
|
||||
@Override
|
||||
public Object Call(String method, Object... args) {
|
||||
XomwServiceContainer mediaWikiServices = (XomwServiceContainer)args[0];
|
||||
return new XomwServiceExample(method, args[1]);
|
||||
}
|
||||
public XophpArray<XophpCallback> NewWirings(String... names) {
|
||||
wirings = new XophpArray();
|
||||
for (String name : names) {
|
||||
wirings.Add(name, this.NewCallback(name));
|
||||
}
|
||||
return wirings;
|
||||
}
|
||||
}
|
||||
class XomwServiceManipulatorExample implements XophpCallbackOwner {
|
||||
@Override
|
||||
public Object Call(String method, Object... args) {
|
||||
XophpArray manipulatorArgs = (XophpArray)args[0];
|
||||
return new XomwServiceExample(method, manipulatorArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package gplx.xowa.wikis.pages;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.tests.Gftest_fxt;
|
||||
import gplx.tests.GfoTstr;
|
||||
import gplx.xowa.Xop_fxt;
|
||||
import gplx.xowa.Xowe_wiki;
|
||||
import gplx.xowa.wikis.pages.htmls.Xopg_html_data;
|
||||
@@ -43,6 +43,6 @@ class Xopg_page_headingTstr {
|
||||
heading.Init(wiki, true, new Xopg_html_data(), Bry_.new_u8(ttlDb), Bry_.new_u8(ttlTxt), Bry_.new_u8(lang));
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
heading.Bfr_arg__add(bfr);
|
||||
Gftest_fxt.Eq__str(expd, bfr.To_str_and_clear());
|
||||
GfoTstr.EqStr(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user