1
0
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:
gnosygnu
2021-12-19 16:19:19 -05:00
parent 48559edffe
commit 0e80d7ef6d
7999 changed files with 1375876 additions and 1365947 deletions

View File

@@ -1,6 +1,6 @@
package gplx.langs.javascripts;
import gplx.core.tests.Gftest;
import gplx.frameworks.tests.GfoTstr;
import org.junit.Test;
public class JsString_Test {
@@ -19,9 +19,9 @@ public class JsString_Test {
}
class JsString_Tstr {
public void Test_slice(String note, String expd, String src, int bgn) {
Gftest.Eq__str(expd, JsString_.slice(src, bgn), note);
GfoTstr.Eq(expd, JsString_.slice(src, bgn), note);
}
public void Test_slice(String note, String expd, String src, int bgn, int end) {
Gftest.Eq__str(expd, JsString_.slice(src, bgn, end), note);
GfoTstr.Eq(expd, JsString_.slice(src, bgn, end), note);
}
}

View File

@@ -1,47 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.core.tests.Gftest;
import org.junit.Test;
public class JsonDocBldrTest {
private JsonDocBldrTestUtil util = new JsonDocBldrTestUtil();
@Test public void Basic() {
JsonDocBldr bldr = JsonDocBldr.NewRootNde();
bldr.NdeBgn("nde")
.KvBool("bool", true)
.KvInt("int", 123)
.KvStr("str", "abc")
.NdeEnd();
util.Test(bldr
, "{ 'nde':"
, " { 'bool':true"
, " , 'int':123"
, " , 'str':'abc'"
, " }"
, "}");
}
}
class JsonDocBldrTestUtil {
public void Test(JsonDocBldr bldr, String... ary) {
Bry_bfr bfr = Bry_bfr_.New();
bldr.ToDoc().Root_grp().Print_as_json(bfr, 0);
Gftest.Eq__ary__lines(Json_doc.Make_str_by_apos(ary), bfr.To_str_and_clear());
}
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.frameworks.tests.GfoTstr;
import org.junit.Test;
public class JsonDocBldrTest {
private JsonDocBldrTestUtil util = new JsonDocBldrTestUtil();
@Test public void Basic() {
JsonDocBldr bldr = JsonDocBldr.NewRootNde();
bldr.NdeBgn("nde")
.KvBool("bool", true)
.KvInt("int", 123)
.KvStr("str", "abc")
.NdeEnd();
util.Test(bldr
, "{ 'nde':"
, " { 'bool':true"
, " , 'int':123"
, " , 'str':'abc'"
, " }"
, "}");
}
}
class JsonDocBldrTestUtil {
public void Test(JsonDocBldr bldr, String... ary) {
BryWtr bfr = BryWtr.New();
bldr.ToDoc().Root_grp().Print_as_json(bfr, 0);
GfoTstr.EqLines(Json_doc.Make_str_by_apos(ary), bfr.ToStrAndClear());
}
}

View File

@@ -1,71 +1,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.mustaches;
import gplx.Bry_;
import gplx.Bry_bfr_;
import gplx.core.tests.Gftest;
import gplx.langs.jsons.Json_doc;
import gplx.langs.jsons.Json_parser;
import org.junit.Test;
public class JsonMustacheNdeTest {
private JsonMustacheNdeTestUtil util = new JsonMustacheNdeTestUtil();
@Test public void Str() {
util.TestWrite("[{{key}}]", "{'key':'abc'}", "[abc]");
}
@Test public void Bool() {
String mustache = "[{{#key}}y{{/key}}]";
util.TestWrite(mustache, "{'key':true}", "[y]");
util.TestWrite(mustache, "{'key':false}", "[]");
}
@Test public void Ary() {
String mustache = "[{{#group}}{{key}} {{/group}}]";
util.TestWrite(mustache, "{'group':[{'key':'a'}, {'key':'b'}, {'key':'c'}]}", "[a b c ]");
}
@Test public void SectionPropWithDot() {
String mustache = "[{{#key}}{{.}}{{/key}}]";
util.TestWrite(mustache, "{'key':'test'}", "[test]");
util.TestWrite(mustache, "{'key1':'test'}", "[]");
}
@Test public void SectionPropWithoutDot() {
String mustache = "[{{#prop}}{{propx}}{{/prop}}]";
util.TestWrite(mustache, "{'prop':'test'}", "[]");
util.TestWrite(mustache, "{'propx':'test'}", "[]");
}
@Test public void Dot() {// NOTE: online demo gives `([object Object])`; https://mustache.github.io/#demo
String mustache = "({{.}})";
util.TestWrite(mustache, "{'key':'test'}", "()");
}
}
class JsonMustacheNdeTestUtil {
public void TestWrite(String mustache, String json, String expd) {
// parse JSON to mustache itm
Json_doc jdoc = Json_parser.ParseToJdoc(Json_doc.Make_str_by_apos(json));
JsonMustacheNde nde = new JsonMustacheNde(jdoc.Root_nde());
// parse template
Mustache_tkn_itm actl_itm = new Mustache_tkn_parser().Parse(Bry_.new_u8(mustache));
// render
Mustache_bfr bfr = new Mustache_bfr(Bry_bfr_.New());
actl_itm.Render(bfr, new Mustache_render_ctx().Init(nde));
// test
Gftest.Eq__ary__lines(expd, bfr.To_str_and_clear());
}
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.mustaches;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.langs.jsons.Json_doc;
import gplx.langs.jsons.Json_parser;
import org.junit.Test;
public class JsonMustacheNdeTest {
private JsonMustacheNdeTestUtil util = new JsonMustacheNdeTestUtil();
@Test public void Str() {
util.TestWrite("[{{key}}]", "{'key':'abc'}", "[abc]");
}
@Test public void Bool() {
String mustache = "[{{#key}}y{{/key}}]";
util.TestWrite(mustache, "{'key':true}", "[y]");
util.TestWrite(mustache, "{'key':false}", "[]");
}
@Test public void Ary() {
String mustache = "[{{#group}}{{key}} {{/group}}]";
util.TestWrite(mustache, "{'group':[{'key':'a'}, {'key':'b'}, {'key':'c'}]}", "[a b c ]");
}
@Test public void SectionPropWithDot() {
String mustache = "[{{#key}}{{.}}{{/key}}]";
util.TestWrite(mustache, "{'key':'test'}", "[test]");
util.TestWrite(mustache, "{'key1':'test'}", "[]");
}
@Test public void SectionPropWithoutDot() {
String mustache = "[{{#prop}}{{propx}}{{/prop}}]";
util.TestWrite(mustache, "{'prop':'test'}", "[]");
util.TestWrite(mustache, "{'propx':'test'}", "[]");
}
@Test public void Dot() {// NOTE: online demo gives `([object Object])`; https://mustache.github.io/#demo
String mustache = "({{.}})";
util.TestWrite(mustache, "{'key':'test'}", "()");
}
}
class JsonMustacheNdeTestUtil {
public void TestWrite(String mustache, String json, String expd) {
// parse JSON to mustache itm
Json_doc jdoc = Json_parser.ParseToJdoc(Json_doc.Make_str_by_apos(json));
JsonMustacheNde nde = new JsonMustacheNde(jdoc.Root_nde());
// parse template
Mustache_tkn_itm actl_itm = new Mustache_tkn_parser().Parse(BryUtl.NewU8(mustache));
// render
Mustache_bfr bfr = new Mustache_bfr(BryWtr.New());
actl_itm.Render(bfr, new Mustache_render_ctx().Init(nde));
// test
GfoTstr.EqLines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,25 @@
package gplx.types.basics.encoders;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BoolUtl;
import gplx.types.basics.utls.IntUtl;
import org.junit.Test;
public class XoHexUtlTest {
private final XoHexUtlTstr tstr = new XoHexUtlTstr();
@Test public void Write_bfr() {
tstr.TestWriteBfr(BoolUtl.Y, 0, "0");
tstr.TestWriteBfr(BoolUtl.Y, 15, "f");
tstr.TestWriteBfr(BoolUtl.Y, 16, "10");
tstr.TestWriteBfr(BoolUtl.Y, 32, "20");
tstr.TestWriteBfr(BoolUtl.Y, 255, "ff");
tstr.TestWriteBfr(BoolUtl.Y, 256, "100");
tstr.TestWriteBfr(BoolUtl.Y, IntUtl.MaxValue, "7fffffff");
}
}
class XoHexUtlTstr {
public void TestWriteBfr(boolean lcase, int val, String expd) {
BryWtr bfr = BryWtr.New();
XoHexUtl.WriteBfr(bfr, lcase, val);
GfoTstr.Eq(expd, bfr.ToStrAndClear());
}
}

View File

@@ -15,14 +15,13 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.pages.randoms.specials;
import gplx.Bry_;
import gplx.String_;
import gplx.core.tests.Gftest;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.utls.StringUtl;
import gplx.dbs.wkrs.randoms.TestRandomWkr;
import gplx.xowa.Xoa_app_fxt;
import gplx.xowa.Xoa_test_;
import gplx.xowa.Xoa_ttl;
import gplx.xowa.Xoa_url;
import gplx.xowa.Xoae_app;
import gplx.xowa.Xoae_page;
import gplx.xowa.Xop_fxt;
@@ -64,8 +63,8 @@ class RandomRootTstr {
parserTstr.Init_page_create(page, page);
// add ttl.Root to the testRandomWkr
Xoa_ttl pageTtl = wiki.Ttl_parse(Bry_.new_u8(page));
testRandomWkr.AddRow(String_.new_u8(pageTtl.Root_txt()));
Xoa_ttl pageTtl = wiki.Ttl_parse(BryUtl.NewU8(page));
testRandomWkr.AddRow(StringUtl.NewU8(pageTtl.Root_txt()));
}
}
public void Test(String special_url, int expd_ns, String expd) {
@@ -74,13 +73,13 @@ class RandomRootTstr {
Xoae_page page = Test_special_open(wiki, special_page, special_url);
// test sql
Gftest.Eq__str("page_title", testRandomWkr.SelectRandomRowSelect());
Gftest.Eq__str("page p", testRandomWkr.SelectRandomRowFrom());
Gftest.Eq__str("p.page_namespace = " + expd_ns + " AND p.page_redirect_id = -1 AND p.page_title NOT LIKE '%/%'", testRandomWkr.SelectRandomRowWhere());
GfoTstr.Eq("page_title", testRandomWkr.SelectRandomRowSelect());
GfoTstr.Eq("page p", testRandomWkr.SelectRandomRowFrom());
GfoTstr.Eq("p.page_namespace = " + expd_ns + " AND p.page_redirect_id = -1 AND p.page_title NOT LIKE '%/%'", testRandomWkr.SelectRandomRowWhere());
// test page
Gftest.Eq__str(expd, page.Url().Page_bry());
Gftest.Eq__str("", page.Db().Text().Text_bry()); // ISSUE#:719:redirect should not load page else redirect info will get lost; EX:"Redirected from trg_ttl" instead of "Redirected from src_ttl"; PAGE:en.s; DATE:2020-05-13
GfoTstr.Eq(expd, page.Url().Page_bry());
GfoTstr.Eq("", page.Db().Text().Text_bry()); // ISSUE#:719:redirect should not load page else redirect info will get lost; EX:"Redirected from trg_ttl" instead of "Redirected from src_ttl"; PAGE:en.s; DATE:2020-05-13
}
public static Xoae_page Test_special_open(Xowe_wiki wiki, Xow_special_page special_page, String special_url) {
Xoae_page page = Init_page(wiki, special_url);
@@ -89,7 +88,7 @@ class RandomRootTstr {
}
private static Xoae_page Init_page(Xowe_wiki wiki, String url_str) {
// basic boot-strapping to make sure ctx.Page has .Url and .Ttl
byte[] url_bry = Bry_.new_u8(url_str);
byte[] url_bry = BryUtl.NewU8(url_str);
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
page.Url_(wiki.Utl__url_parser().Parse(url_bry));
page.Ttl_(Xoa_ttl.Parse(wiki, url_bry));

View File

@@ -15,9 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.minifys;
import gplx.core.tests.Gftest;
import gplx.core.tooling.dataCollectors.GfoDataCollectorMgr;
import gplx.core.tooling.asserts.TestAssert;
import gplx.frameworks.tests.GfoTstr;
import org.junit.Test;
public class XoCssMinTest {
@@ -123,6 +123,6 @@ class XoCssMinTstr {
if (expdRules != null) {
TestAssert.Test(note, dataCollectorMgr, expdRules);
}
Gftest.Eq__str(expd, actl, note);
GfoTstr.Eq(expd, actl, note);
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}
}

View File

@@ -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) {

View File

@@ -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 ->

View File

@@ -16,8 +16,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.parsers.tmpls;
import gplx.Bry_;
import gplx.core.tests.Gftest;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.xowa.Xop_fxt;
import gplx.xowa.Xowe_wiki;
import gplx.xowa.parsers.Xop_ctx;
@@ -57,13 +57,13 @@ class Xot_defn_tmpl__fxt {
public void Test_CopyNew_FrameTtl(int frameNs, String frameTtlStr, String expdFrameTtl) {
Xowe_wiki wiki = fxt.Wiki();
Xop_ctx ctx = Xop_ctx.New__top(wiki);
byte[] frameTtlBry = Bry_.new_u8(frameTtlStr);
byte[] frameTtlBry = BryUtl.NewU8(frameTtlStr);
Xot_defn_tmpl orig_defn = new Xot_defn_tmpl();
Xot_invk orig = Xot_invk_temp.New_root(Bry_.new_u8("orig"));
Xot_invk caller = Xot_invk_temp.New_root(Bry_.new_u8("caller"));
byte[] src = Bry_.Empty;
Xot_invk orig = Xot_invk_temp.New_root(BryUtl.NewU8("orig"));
Xot_invk caller = Xot_invk_temp.New_root(BryUtl.NewU8("caller"));
byte[] src = BryUtl.Empty;
Xot_invk tmpl = Xot_defn_tmpl_.CopyNew(ctx, orig_defn, orig, caller, src, frameNs, frameTtlBry);
Gftest.Eq__bry(Bry_.new_u8(expdFrameTtl), tmpl.Frame_ttl());
GfoTstr.Eq(BryUtl.NewU8(expdFrameTtl), tmpl.Frame_ttl());
}
}

View File

@@ -15,10 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.wikis.pages;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.custom.brys.wtrs.BryWtr;
import gplx.frameworks.tests.GfoTstr;
import gplx.xowa.Xop_fxt;
import gplx.xowa.Xowe_wiki;
import gplx.xowa.wikis.pages.htmls.Xopg_html_data;
@@ -40,9 +39,9 @@ class Xopg_page_headingTstr {
}
public void Test(String expd, String ttlDb, String ttlTxt, String lang) {
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);
GfoTstr.EqStr(expd, bfr.To_str_and_clear());
heading.Init(wiki, true, new Xopg_html_data(), BryUtl.NewU8(ttlDb), BryUtl.NewU8(ttlTxt), BryUtl.NewU8(lang));
BryWtr bfr = BryWtr.New();
heading.AddToBfr(bfr);
GfoTstr.Eq(expd, bfr.ToStrAndClear());
}
}

View File

@@ -1,10 +1,10 @@
package gplx.xowa.xtns.indicators;
import gplx.Bry_;
import gplx.Ordered_hash;
import gplx.Ordered_hash_;
import gplx.String_;
import gplx.core.tests.Gftest;
import gplx.frameworks.tests.GfoTstr;
import gplx.types.basics.utls.BryUtl;
import gplx.types.basics.lists.Ordered_hash;
import gplx.types.basics.lists.Ordered_hash_;
import gplx.types.basics.utls.StringUtl;
import org.junit.Test;
public class IndicatorSerialCoreTest {
@@ -12,7 +12,7 @@ public class IndicatorSerialCoreTest {
@Test
public void Save() {
tstr.TestBoth(String_.Concat_lines_nl
tstr.TestBoth(StringUtl.ConcatLinesNl
( "AA"
, "2"
, "5|name0"
@@ -26,23 +26,23 @@ class IndicatorSerialCoreTstr {
public Indicator_xnde NewXnde(String name, String html) {
Indicator_xnde xnde = new Indicator_xnde();
xnde.Name_(name);
xnde.Html_(Bry_.new_u8(html));
xnde.Html_(BryUtl.NewU8(html));
return xnde;
}
public void TestBoth(String data, Indicator_xnde... xndes) {
byte[] save = TestSave(data, xndes);
TestLoad(String_.new_u8(save), xndes);
TestLoad(StringUtl.NewU8(save), xndes);
}
public byte[] TestSave(String expd, Indicator_xnde... xndes) {
byte[] actl = IndicatorSerialCore.Save(ToList(xndes));
Gftest.Eq__str(expd, actl);
GfoTstr.Eq(expd, actl);
return actl;
}
public Ordered_hash TestLoad(String data, Indicator_xnde... expd) {
Ordered_hash list = IndicatorSerialCore.Load(Bry_.new_u8(data));
Ordered_hash list = IndicatorSerialCore.Load(BryUtl.NewU8(data));
Gftest.Eq__bry(IndicatorSerialCore.Save(ToList(expd)), IndicatorSerialCore.Save(list)); // should probably compare items, but easier to compare seiarlization
GfoTstr.Eq(IndicatorSerialCore.Save(ToList(expd)), IndicatorSerialCore.Save(list)); // should probably compare items, but easier to compare seiarlization
return list;
}

View File

@@ -1,87 +1,87 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.template_styles;
import gplx.core.tests.Gftest;
import org.junit.Test;
public class XoCssTransformerTest {
private final XoCssTranformerTstr tstr = new XoCssTranformerTstr();
@Test
public void Minify() {
tstr.Test_Minify("basic" ,"rgb (128,128,128)", "#808080");
}
@Test
public void PrependBasic() {
tstr.Test_Prepend(".x {}", ".a", ".a .x{}");
}
@Test
public void PrependManyClasses() {
tstr.Test_Prepend("x,y,z {}", ".a", ".a x,.a y,.a z{}");
}
@Test
public void PrependManyNodes() {
tstr.Test_Prepend("x {} y {} z {}", ".a", ".a x{}.a y{}.a z{}");
}
@Test
public void PrependEmpty() {
tstr.Test_Prepend("x {}{}", ".a", ".a x{}{}");
}
@Test
public void PrependMediaAtBos() {
tstr.Test_Prepend("@media {} x {}", ".a", "@media {}.a x{}");
}
@Test
public void PrependMediaAtMid() {
tstr.Test_Prepend("x {} @media {} y {}", ".a", ".a x{} @media {}.a y{}");
}
@Test
public void PrependIgnoreBody() {
tstr.Test_Prepend("body {}", ".a", "body{}");
}
@Test
public void Url() {
tstr.Test_Url("match.y" , "url(//site/a.png)", "site", "prepend/site", "url(//prepend/site/a.png)");
tstr.Test_Url("match.y.any", "//site/abc" , "site", "prepend/site", "//prepend/site/abc"); // NOTE: matches any "//"
tstr.Test_Url("match.n" , "url(/-site/a.png)", "site", "prepend/site", "url(/-site/a.png)");
}
}
class XoCssTranformerTstr {
public void Test_Url(String note, String css, String src, String trg, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Url(src, trg).ToStr();
Gftest.Eq__str(expd, actl, note);
}
public void Test_Prepend(String css, String selector, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Prepend(selector).ToStr();
Gftest.Eq__str(expd, actl);
}
public void Test_Minify(String note, String css, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Minify().ToStr();
Gftest.Eq__str(expd, actl, note);
}
}
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.template_styles;
import gplx.frameworks.tests.GfoTstr;
import org.junit.Test;
public class XoCssTransformerTest {
private final XoCssTranformerTstr tstr = new XoCssTranformerTstr();
@Test
public void Minify() {
tstr.Test_Minify("basic" ,"rgb (128,128,128)", "#808080");
}
@Test
public void PrependBasic() {
tstr.Test_Prepend(".x {}", ".a", ".a .x{}");
}
@Test
public void PrependManyClasses() {
tstr.Test_Prepend("x,y,z {}", ".a", ".a x,.a y,.a z{}");
}
@Test
public void PrependManyNodes() {
tstr.Test_Prepend("x {} y {} z {}", ".a", ".a x{}.a y{}.a z{}");
}
@Test
public void PrependEmpty() {
tstr.Test_Prepend("x {}{}", ".a", ".a x{}{}");
}
@Test
public void PrependMediaAtBos() {
tstr.Test_Prepend("@media {} x {}", ".a", "@media {}.a x{}");
}
@Test
public void PrependMediaAtMid() {
tstr.Test_Prepend("x {} @media {} y {}", ".a", ".a x{} @media {}.a y{}");
}
@Test
public void PrependIgnoreBody() {
tstr.Test_Prepend("body {}", ".a", "body{}");
}
@Test
public void Url() {
tstr.Test_Url("match.y" , "url(//site/a.png)", "site", "prepend/site", "url(//prepend/site/a.png)");
tstr.Test_Url("match.y.any", "//site/abc" , "site", "prepend/site", "//prepend/site/abc"); // NOTE: matches any "//"
tstr.Test_Url("match.n" , "url(/-site/a.png)", "site", "prepend/site", "url(/-site/a.png)");
}
}
class XoCssTranformerTstr {
public void Test_Url(String note, String css, String src, String trg, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Url(src, trg).ToStr();
GfoTstr.Eq(expd, actl, note);
}
public void Test_Prepend(String css, String selector, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Prepend(selector).ToStr();
GfoTstr.Eq(expd, actl);
}
public void Test_Minify(String note, String css, String expd) {
XoCssTransformer transformer = new XoCssTransformer(css);
String actl = transformer.Minify().ToStr();
GfoTstr.Eq(expd, actl, note);
}
}