Wikibase: Fix script error 'libraryUtil.lua:13 bad argument #1 to message.newRawMessage' on sever dozen military pages

pull/620/head
gnosygnu 6 years ago
parent 10c39e4c76
commit 372cd3958d

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Array__tst {
@Test public void Resize_add() {
tst_Resize_add(ary_(), ary_(1), ary_(1)); // 0 + 1 = 1
tst_Resize_add(ary_(0), ary_(), ary_(0)); // 1 + 0 = 1
tst_Resize_add(ary_(0), ary_(1), ary_(0, 1)); // 1 + 1 = 2
} void tst_Resize_add(int[] source, int[] added, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize_add(source, added));}
@Test public void Resize() {
tst_Resize(ary_(0), 0, ary_()); // 1 -> 0
tst_Resize(ary_(0, 1), 1, ary_(0)); // 2 -> 1
} void tst_Resize(int[] source, int length, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize(source, length));}
@Test public void Insert() {
tst_Insert(ary_obj(0, 1, 4, 5), ary_obj(2, 3), 2, ary_obj(0, 1, 2, 3, 4, 5));
} void tst_Insert(Object[] cur, Object[] add, int addPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Insert(cur, add, addPos));}
@Test public void ReplaceInsert() {
tst_ReplaceInsert(ary_obj(0, 1, 4, 5) , ary_obj(1, 2, 3), 1, 1, ary_obj(0, 1, 2, 3, 4, 5));
tst_ReplaceInsert(ary_obj(0, 1, 2, 4, 5) , ary_obj(1, 2, 3), 1, 2, ary_obj(0, 1, 2, 3, 4, 5));
tst_ReplaceInsert(ary_obj(0, 1, 2, 3, 4, 5) , ary_obj(1, 2, 3), 1, 3, ary_obj(0, 1, 2, 3, 4, 5));
tst_ReplaceInsert(ary_obj(0, 1, 9, 4, 5) , ary_obj(2, 3) , 2, 1, ary_obj(0, 1, 2, 3, 4, 5));
} void tst_ReplaceInsert(Object[] cur, Object[] add, int curReplacePos, int addInsertPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Replace_insert(cur, add, curReplacePos, addInsertPos));}
Object[] ary_obj(Object... ary) {return ary;}
int[] ary_(int... ary) {return ary;}
}

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Bool__tst {
private final Bool__fxt fxt = new Bool__fxt();
@Test public void Compare() {
fxt.Test__compare(Bool_.Y, Bool_.Y, CompareAble_.Same);
fxt.Test__compare(Bool_.N, Bool_.N, CompareAble_.Same);
fxt.Test__compare(Bool_.N, Bool_.Y, CompareAble_.Less);
fxt.Test__compare(Bool_.Y, Bool_.N, CompareAble_.More);
}
}
class Bool__fxt {
public void Test__compare(boolean lhs, boolean rhs, int expd) {Tfds.Eq(expd, Bool_.Compare(lhs, rhs));}
}

@ -0,0 +1,307 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.tests.*;
public class Bry__tst {
private final Bry__fxt fxt = new Bry__fxt();
@Test public void new_ascii_() {
fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_a7("" , Bry_.Empty); // none
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
}
@Test public void new_u8() {
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent
fxt.Test_new_u8("€" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8
}
@Test public void Add__bry_plus_byte() {
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic
fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String
}
@Test public void Add__byte_plus_bry() {
fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic
fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String
}
@Test public void Add_w_dlm() {
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null
}
@Test public void Add_w_dlm_bry() {
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
}
@Test public void MidByPos() {
tst_MidByPos("abcba", 0, 1, "a");
tst_MidByPos("abcba", 0, 2, "ab");
tst_MidByPos("abcba", 1, 4, "bcb");
} void tst_MidByPos(String src, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Mid(Bry_.new_u8(src), bgn, end)));}
@Test public void Replace_one() {
tst_ReplaceOne("a" , "b" , "c" , "a");
tst_ReplaceOne("b" , "b" , "c" , "c");
tst_ReplaceOne("bb" , "b" , "c" , "cb");
tst_ReplaceOne("abcd" , "bc" , "" , "ad");
tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd");
} void tst_ReplaceOne(String src, String find, String repl, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Replace_one(Bry_.new_u8(src), Bry_.new_u8(find), Bry_.new_u8(repl))));}
@Test public void XtoStrBytesByInt() {
tst_XtoStrBytesByInt(0, 0);
tst_XtoStrBytesByInt(9, 9);
tst_XtoStrBytesByInt(10, 1, 0);
tst_XtoStrBytesByInt(321, 3, 2, 1);
tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1);
tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7);
}
void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) {
byte[] expd = new byte[expdAryAsInt.length];
for (int i = 0; i < expd.length; i++) {
int expdInt = expdAryAsInt[i];
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_str(expdAryAsInt[i]);
}
Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val)));
}
@Test public void Has_at_end() {
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many
tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long
tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos
tst_HasAtEnd("abc", "bc", true); // y
tst_HasAtEnd("abc", "bd", false); // n
tst_HasAtEnd("a", "ab", false); // exceeds_len
}
void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));}
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));}
@Test public void Has_at_bgn() {
tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true);
tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true);
tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false);
tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false);
} void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_bgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);}
@Test public void Match() {
tst_Match("abc", 0, "abc", true);
tst_Match("abc", 2, "c", true);
tst_Match("abc", 0, "cde", false);
tst_Match("abc", 2, "abc", false); // bounds check
tst_Match("abc", 0, "abcd", false);
tst_Match("a" , 0, "", false);
tst_Match("" , 0, "a", false);
tst_Match("" , 0, "", true);
tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different
} void tst_Match(String src, int srcPos, String find, boolean expd) {Tfds.Eq(expd, Bry_.Match(Bry_.new_u8(src), srcPos, Bry_.new_u8(find)));}
@Test public void ReadCsvStr() {
tst_ReadCsvStr("a|" , "a");
tst_ReadCsvStr("|a|", 1 , "a");
Int_obj_ref bgn = Int_obj_ref.New_zero(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c");
tst_ReadCsvStr("|", "");
tst_ReadCsvStr_err("a");
tst_ReadCsvStr("'a'|" , "a");
tst_ReadCsvStr("'a''b'|" , "a'b");
tst_ReadCsvStr("'a|b'|" , "a|b");
tst_ReadCsvStr("''|", "");
tst_ReadCsvStr_err("''");
tst_ReadCsvStr_err("'a'b'");
tst_ReadCsvStr_err("'a");
tst_ReadCsvStr_err("'a|");
tst_ReadCsvStr_err("'a'");
}
@Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4
tst_XtoIntBy4Bytes(32, (byte)32); // space
tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // &exist;
tst_XtoIntBy4Bytes(6382179, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
tst_XtoIntBy4Bytes(1633837924, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c, Byte_ascii.Ltr_d);
}
@Test public void XtoInt() {
tst_XtoInt("1", 1);
tst_XtoInt("123", 123);
tst_XtoInt("a", Int_.Min_value, Int_.Min_value);
tst_XtoInt("-1", Int_.Min_value, -1);
tst_XtoInt("-123", Int_.Min_value, -123);
tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value);
tst_XtoInt("+123", Int_.Min_value, 123);
tst_XtoInt("", -1);
}
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");}
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New_zero() , expd);}
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);}
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
int bgn = bgnRef.Val();
boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\'';
String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'");
Tfds.Eq(expd, actl, "rv");
if (rawHasQuotes) {
int quoteAdj = String_.Count(actl, "'");
Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes
}
else
Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len
}
void tst_ReadCsvStr_err(String raw) {
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');}
catch (Exception e) {Err_.Noop(e); return;}
Tfds.Fail_expdError();
}
@Test public void ReadCsvDte() {
tst_ReadCsvDte("20110801 221435.987");
} void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
@Test public void ReadCsvInt() {
tst_ReadCsvInt("1234567890");
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
@Test public void Trim() {
Trim_tst("a b c", 1, 4, "b");
Trim_tst("a c", 1, 3, "");
Trim_tst(" ", 0, 2, "");
} void Trim_tst(String raw, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Trim(Bry_.new_u8(raw), bgn, end)));}
@Test public void Xto_int_lax() {
tst_Xto_int_lax("12a", 12);
tst_Xto_int_lax("1", 1);
tst_Xto_int_lax("123", 123);
tst_Xto_int_lax("a", 0);
tst_Xto_int_lax("-1", -1);
}
private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__lax(Bry_.new_u8(val), 0, String_.Len(val), 0));}
@Test public void To_int_or__trim_ws() {
tst_Xto_int_trim("123 " , 123);
tst_Xto_int_trim(" 123" , 123);
tst_Xto_int_trim(" 123 " , 123);
tst_Xto_int_trim(" 1 3 " , -1);
}
private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__trim_ws(Bry_.new_u8(val), 0, String_.Len(val), -1));}
@Test public void Compare() {
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same);
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less);
tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAble_.More);
tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAble_.Less);
tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAble_.More);
tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAble_.Less);
} void tst_Compare(String lhs, int lhs_bgn, int lhs_end, String rhs, int rhs_bgn, int rhs_end, int expd) {Tfds.Eq(expd, Bry_.Compare(Bry_.new_u8(lhs), lhs_bgn, lhs_end, Bry_.new_u8(rhs), rhs_bgn, rhs_end));}
@Test public void Increment_last() {
tst_IncrementLast(ary_(0), ary_(1));
tst_IncrementLast(ary_(0, 255), ary_(1, 0));
tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102));
}
byte[] ary_(int... ary) {
byte[] rv = new byte[ary.length];
for (int i = 0; i < ary.length; i++)
rv[i] = Byte_.By_int(ary[i]);
return rv;
}
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}
@Test public void Replace_between() {
tst_Replace_between("a[0]b" , "[", "]", "0", "a0b");
tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c");
tst_Replace_between("a[0b" , "[", "]", "0", "a[0b");
} public void tst_Replace_between(String src, String bgn, String end, String repl, String expd) {Tfds.Eq(expd, String_.new_a7(Bry_.Replace_between(Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(end), Bry_.new_a7(repl))));}
@Test public void Replace() {
Bry_bfr tmp_bfr = Bry_bfr_.New();
tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1
tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2
tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1
tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS
tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS
tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match
tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS
}
public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) {
Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl))));
}
@Test public void Split_bry() {
Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c"));
Split_bry_tst("a|" , "|" , String_.Ary("a"));
}
void Split_bry_tst(String src, String dlm, String[] expd) {
String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
Tfds.Eq_ary_str(expd, actl);
}
@Test public void Split_lines() {
Tst_split_lines("a\nb" , "a", "b"); // basic
Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines
Tst_split_lines("a\r\nb" , "a", "b"); // crlf
Tst_split_lines("a\rb" , "a", "b"); // cr only
}
void Tst_split_lines(String src, String... expd) {
Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src))));
}
String[] New_ary(byte[][] lines) {
int len = lines.length;
String[] rv = new String[len];
for (int i = 0; i < len; i++)
rv[i] = String_.new_u8(lines[i]);
return rv;
}
@Test public void Match_bwd_any() {
Tst_match_bwd_any("abc", 2, 0, "c", true);
Tst_match_bwd_any("abc", 2, 0, "b", false);
Tst_match_bwd_any("abc", 2, 0, "bc", true);
Tst_match_bwd_any("abc", 2, 0, "abc", true);
Tst_match_bwd_any("abc", 2, 0, "zabc", false);
Tst_match_bwd_any("abc", 1, 0, "ab", true);
}
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
}
@Test public void Trim_end() {
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none
fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty
}
@Test public void Mid_w_trim() {
fxt.Test_Mid_w_trim("abc", "abc"); // no ws
fxt.Test_Mid_w_trim(" a b c ", "a b c"); // ws at bgn and end
fxt.Test_Mid_w_trim("\r\n\t a\r\n\t b \r\n\t ", "a\r\n\t b"); // space at bgn and end
fxt.Test_Mid_w_trim("", ""); // handle 0 bytes
fxt.Test_Mid_w_trim(" ", ""); // handle all ws
}
@Test public void New_u8_nl_apos() {
fxt.Test__new_u8_nl_apos(String_.Ary("a"), "a");
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b"), "a\nb");
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b'c", "d"), "a\nb\"c\nd");
}
@Test public void Repeat_bry() {
fxt.Test__repeat_bry("abc" , 3, "abcabcabc");
}
@Test public void Xcase__build__all() {
fxt.Test__xcase__build__all(Bool_.N, "abc", "abc");
fxt.Test__xcase__build__all(Bool_.N, "aBc", "abc");
}
}
class Bry__fxt {
private final Bry_bfr tmp = Bry_bfr_.New();
public void Test_trim_end(String raw, byte trim, String expd) {
byte[] raw_bry = Bry_.new_a7(raw);
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
}
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));}
public void Test_add(byte b, String s, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(b, Bry_.new_u8(s))));}
public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));}
public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));}
public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));}
public void Test__new_u8_nl_apos(String[] ary, String expd) {
Tfds.Eq_str_lines(expd, String_.new_u8(Bry_.New_u8_nl_apos(ary)));
}
public void Test__repeat_bry(String s, int count, String expd) {
Gftest.Eq__str(expd, Bry_.Repeat_bry(Bry_.new_u8(s), count));
}
public void Test__xcase__build__all(boolean upper, String src, String expd) {
Gftest.Eq__str(expd, Bry_.Xcase__build__all(tmp, upper, Bry_.new_u8(src)));
}
}

@ -0,0 +1,247 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*;
public class Bry_bfr_tst {
private Bry_bfr bb = Bry_bfr_.New();
@Before public void setup() {bb.Clear();} private ByteAryBfr_fxt fxt = new ByteAryBfr_fxt();
@Test public void AddByte() {
bb = Bry_bfr_.New_w_size(2); // NOTE: make sure auto-expands
tst_AddByte("a", "a", 2);
tst_AddByte("b", "ab", 2);
tst_AddByte("c", "abc", 4);
}
@Test public void AddAry() { // NOTE: make sure auto-expands
bb = Bry_bfr_.New_w_size(2);
tst_AddByte("abcd", "abcd", 12);
}
@Test public void Add_byte_repeat() { // NOTE: make sure auto-expands
bb = Bry_bfr_.New_w_size(2);
tst_Add_byte_repeat(Byte_ascii.Space, 12, String_.Repeat(" ", 12));
} void tst_Add_byte_repeat(byte b, int len, String expd) {Tfds.Eq(expd, bb.Add_byte_repeat(b, len).To_str_and_clear());}
void tst_AddByte(String s, String expdStr, int expdLen) {
if (String_.Len(s) == 1)
bb.Add_byte((byte)String_.CharAt(s, 0));
else
bb.Add(Bry_.new_u8(s));
Tfds.Eq(expdStr, String_.new_u8(bb.To_bry()));
Tfds.Eq(expdLen, bb.Bfr_max());
}
@Test public void Add_dte() {
tst_AddDte("20110801 221435.987");
}
void tst_AddDte(String raw) {
bb.Add_dte(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte));
Tfds.Eq(raw, String_.new_u8(bb.To_bry()));
}
@Test public void Add_int_variable() {
Add_int_variable(-1);
Add_int_variable(-12);
Add_int_variable(-1234);
Add_int_variable(2);
Add_int_variable(12);
Add_int_variable(1234);
Add_int_variable(123456789);
}
@Test public void Add_float() {
tst_Add_float(1 / 3);
tst_Add_float(-1 / 3);
}
void tst_Add_float(float v) {
bb.Add_float(v);
Tfds.Eq(v, Float_.parse(String_.new_u8(bb.To_bry())));
}
void Add_int_variable(int val) {
bb.Clear();
bb.Add_int_variable(val);
Tfds.Eq(val, Int_.Parse(String_.new_u8(bb.To_bry())));
}
@Test public void Add_int_fixed_len3() {tst_Add_int_fixed(123, 3, "123");}
@Test public void Add_int_fixed_pad_1() {tst_Add_int_fixed(2, 1, "2");}
@Test public void Add_int_fixed_pad_2() {tst_Add_int_fixed(2, 2, "02");}
@Test public void Add_int_fixed_pad_16() {tst_Add_int_fixed(2, 16, "0000000000000002");} // test overflows int
@Test public void Add_int_fixed_neg() {tst_Add_int_fixed(-2, 2, "-2");}
@Test public void Add_int_fixed_neg_pad1() {tst_Add_int_fixed(-2, 1, "-");}
@Test public void Add_int_fixed_chop_1() {tst_Add_int_fixed(123, 1, "3");}
@Test public void Add_int_fixed_chop_neg() {tst_Add_int_fixed(-21, 2, "-1");}
void tst_Add_int_fixed(int val, int digits, String expd) {Tfds.Eq(expd, String_.new_u8(bb.Add_int_fixed(val, digits).To_bry()));}
@Test public void Add_long_fixed_len3() {tst_Add_long_fixed(123, 3, "123");}
@Test public void Add_long_fixed_pad_1() {tst_Add_long_fixed(2, 1, "2");}
@Test public void Add_long_fixed_pad_2() {tst_Add_long_fixed(2, 2, "02");}
@Test public void Add_long_fixed_pad_16() {tst_Add_long_fixed(2, 16, "0000000000000002");} // test overflows long
@Test public void Add_long_fixed_neg() {tst_Add_long_fixed(-2, 2, "-2");}
@Test public void Add_long_fixed_neg_pad1() {tst_Add_long_fixed(-2, 1, "-");}
@Test public void Add_long_fixed_chop_1() {tst_Add_long_fixed(123, 1, "3");}
@Test public void Add_long_fixed_chop_neg() {tst_Add_long_fixed(-21, 2, "-1");}
@Test public void Add_long_fixed_large() {tst_Add_long_fixed(123456789012345L, 15, "123456789012345");}
void tst_Add_long_fixed(long val, int digits, String expd) {Tfds.Eq(expd, String_.new_u8(bb.Add_long_fixed(val, digits).To_bry()));}
@Test public void AddDte_short() {
tst_AddDte_short("2010-08-26T22:38:36Z");
}
void tst_AddDte_short(String raw) {
// byte[] ary = String_.XtoByteAryAscii(raw);
// Bry_fmtr_IntBldr ib = new Bry_fmtr_IntBldr();
// int y = 0, m = 0, d = 0, h = 0, n = 0, s = 0, aryLen = ary.length;
// for (int i = 0; i < aryLen; i++) {
// byte b = ary[i];
// switch (i) {
// case 4: y = ib.To_int_and_clear(); break;
// case 7: m = ib.To_int_and_clear(); break;
// case 10: d = ib.To_int_and_clear(); break;
// case 13: h = ib.To_int_and_clear(); break;
// case 16: n = ib.To_int_and_clear(); break;
// case 19: s = ib.To_int_and_clear(); break;
// default: ib.Add(b); break;
// }
// }
// long l = Pow38_to(y, m, d, h, n, s);
//// Base85_.Set_bry(l, bb.
// bb.Add_int(l);
}
// @Test public void InsertAt_str() {
// tst_InsertAt_str("", 0, "c", "c");
// tst_InsertAt_str("ab", 0, "c", "cab");
// tst_InsertAt_str("ab", 0, "cdefghij", "cdefghijab");
// }
// void tst_InsertAt_str(String orig, int insertAt, String insertStr, String expd) {
// bb = Bry_bfr_.New(16);
// bb.Add_str(orig);
// bb.InsertAt_str(insertAt, insertStr);
// String actl = bb.To_str_and_clear();
// Tfds.Eq(expd, actl);
// }
@Test public void To_bry_and_clear_and_trim() {
tst_XtoAryAndClearAndTrim("a" , "a");
tst_XtoAryAndClearAndTrim(" a " , "a");
tst_XtoAryAndClearAndTrim(" a b " , "a b");
tst_XtoAryAndClearAndTrim(" " , "");
}
void tst_XtoAryAndClearAndTrim(String raw, String expd) {
bb.Add_str_u8(raw);
Tfds.Eq(expd, String_.new_u8(bb.To_bry_and_clear_and_trim()));
}
@Test public void XtoInt() {
tst_XtoInt("123", 123);
tst_XtoInt("a", Int_.Min_value);
tst_XtoInt("9999999999", Int_.Min_value);
}
void tst_XtoInt(String raw, int expd) {
bb.Add_str_u8(raw);
Tfds.Eq(expd, bb.To_int_and_clear(Int_.Min_value));
}
static long Pow38_to(int year, int month, int day, int hour, int minute, int second, int frac) {
return ((long)year) << 26
| ((long)month & 0x0f) << 22 // 16
| ((long)day & 0x1f) << 17 // 32
| ((long)hour & 0x1f) << 12 // 32
| ((long)minute & 0x3f) << 6 // 64
| ((long)second & 0x3f) // 64
;
}
static DateAdp Pow38_by(long v) {
int year = (int) (v >> 26);
int month = (int)((v >> 22) & 0x0f);
int day = (int)((v >> 17) & 0x1f);
int hour = (int)((v >> 12) & 0x1f);
int minute = (int)((v >> 6) & 0x3f);
int second = (int)((v ) & 0x3f);
return DateAdp_.new_(year, month, day, hour, minute, second, 0);
}
@Test public void Add_bfr_trimEnd_and_clear() {
tst_Add_bfr_trimEnd_and_clear("a ", "a");
}
void tst_Add_bfr_trimEnd_and_clear(String raw, String expd) {
Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw);
Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, false, true).To_str_and_clear());
}
@Test public void Add_bfr_trimAll_and_clear() {
tst_Add_bfr_trimAll_and_clear(" a ", "a");
tst_Add_bfr_trimAll_and_clear(" a b ", "a b");
tst_Add_bfr_trimAll_and_clear("a", "a");
tst_Add_bfr_trimAll_and_clear("", "");
}
void tst_Add_bfr_trimAll_and_clear(String raw, String expd) {
Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw);
Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, true, true).To_str_and_clear());
}
@Test public void Add_int_pad_bgn() {
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 0, "000");
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1, "001");
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 10, "010");
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 100, "100");
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1000, "1000");
}
@Test public void Add_bry_escape() {
fxt.Test__add_bry_escape("abc" , "abc"); // nothing to escape
fxt.Test__add_bry_escape("a'bc" , "a''bc"); // single escape (code handles first quote differently)
fxt.Test__add_bry_escape("a'b'c" , "a''b''c"); // double escape (code handles subsequent quotes different than first)
fxt.Test__add_bry_escape("abc", 1, 2 , "b"); // nothing to escape
}
@Test public void Add_bry_escape_html() {
fxt.Test__add_bry_escape_html("abc" , "abc"); // escape=none
fxt.Test__add_bry_escape_html("a&\"'<>b" , "a&amp;&quot;&#39;&lt;&gt;b"); // escape=all; code handles first escape differently
fxt.Test__add_bry_escape_html("a&b&c" , "a&amp;b&amp;c"); // staggered; code handles subsequent escapes differently
fxt.Test__add_bry_escape_html("abc", 1, 2 , "b"); // by index; fixes bug in initial implementation
}
@Test public void Insert_at() {
fxt.Test_Insert_at("abcd", 0, "xyz" , "xyzabcd"); // bgn
fxt.Test_Insert_at("abcd", 4, "xyz" , "abcdxyz"); // end
fxt.Test_Insert_at("abcd", 2, "xyz" , "abxyzcd"); // mid
fxt.Test_Insert_at("abcd", 2, "xyz", 1, 2 , "abycd"); // mid
}
@Test public void Delete_rng() {
fxt.Test_Delete_rng("abcd", 0, 2 , "cd"); // bgn
fxt.Test_Delete_rng("abcd", 2, 4 , "ab"); // end
fxt.Test_Delete_rng("abcd", 1, 3 , "ad"); // mid
}
@Test public void Delete_rng_to_bgn() {
fxt.Test_Delete_rng_to_bgn("abcd", 2 , "cd");
}
@Test public void Delete_rng_to_end() {
fxt.Test_Delete_rng_to_end("abcd", 2 , "ab");
}
@Test public void To_bry_ary_and_clear() {
fxt.Test__to_bry_ary_and_clear("" ); // empty
fxt.Test__to_bry_ary_and_clear("a" , "a"); // lines=1
fxt.Test__to_bry_ary_and_clear("a\nb\nc" , "a", "b", "c"); // lines=n
fxt.Test__to_bry_ary_and_clear("a\n" , "a"); // nl at end
}
}
class ByteAryBfr_fxt {
private final Bry_bfr bfr = Bry_bfr_.Reset(16);
public Bry_bfr Bfr() {return bfr;}
public void Clear() {
bfr.ClearAndReset();
}
public void Test_Add_int_pad_bgn(byte pad_byte, int str_len, int val, String expd) {Tfds.Eq(expd, bfr.Add_int_pad_bgn(pad_byte, str_len, val).To_str_and_clear());}
public void Test__add_bry_escape(String src, String expd) {Test__add_bry_escape(src, 0, String_.Len(src), expd);}
public void Test__add_bry_escape(String src, int src_bgn, int src_end, String expd) {
byte[] val_bry = Bry_.new_u8(src);
Tfds.Eq(expd, bfr.Add_bry_escape(Byte_ascii.Apos, Byte_.Ary(Byte_ascii.Apos, Byte_ascii.Apos), val_bry, src_bgn, src_end).To_str_and_clear());
}
public void Test_Insert_at(String init, int pos, String val, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val)).To_str_and_clear());}
public void Test_Insert_at(String init, int pos, String val, int val_bgn, int val_end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val), val_bgn, val_end).To_str_and_clear());}
public void Test_Delete_rng(String init, int bgn, int end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng(bgn, end).To_str_and_clear());}
public void Test_Delete_rng_to_bgn(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_bgn(pos).To_str_and_clear());}
public void Test_Delete_rng_to_end(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_end(pos).To_str_and_clear());}
public void Test__to_bry_ary_and_clear(String bfr_str, String... expd) {
Tfds.Eq_ary(expd, String_.Ary(bfr.Add_str_u8(bfr_str).To_bry_ary_and_clear()));
}
public void Test__add_bry_escape_html(String src, String expd) {Test__add_bry_escape_html(src, 0, String_.Len(src), expd);}
public void Test__add_bry_escape_html(String src, int src_bgn, int src_end, String expd) {
Gftest.Eq__bry(Bry_.new_u8(expd), bfr.Add_bry_escape_html(Bry_.new_u8(src), src_bgn, src_end).To_bry_and_clear());
}
}

@ -0,0 +1,90 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*;
public class Bry_find__tst {
private Bry_find__fxt fxt = new Bry_find__fxt();
@Test public void Find_fwd() {
fxt.Test_Find_fwd("abcba", "b", 0, 1);
fxt.Test_Find_fwd("abcba", "z", 0, -1);
fxt.Test_Find_fwd("abcba", "b", 1, 1);
fxt.Test_Find_fwd("abcba", "b", 2, 3);
fxt.Test_Find_fwd("abcba", "b", 4, -1);
fxt.Test_Find_fwd("abcba", "zb", 4, -1);
fxt.Test_Find_fwd("abcba", "a", 6, -1);
}
@Test public void Find_bwd() {
fxt.Test_Find_bwd("abcba", "b", 4, 3);
fxt.Test_Find_bwd("abcba", "z", 4, -1);
fxt.Test_Find_bwd("abcba", "b", 3, 1);
fxt.Test_Find_bwd("abcba", "b", 2, 1);
fxt.Test_Find_bwd("abcba", "b", 0, -1);
fxt.Test_Find_bwd("abcba", "zb", 4, -1);
fxt.Test_Find_fwd("abcba", "a", -1, -1);
fxt.Test_Find_bwd("abcba", "ab", 4, 0);
}
@Test public void Find_bwd_last_ws() {
fxt.Test_Find_bwd_1st_ws_tst("a b" , 2, 1); // basic
fxt.Test_Find_bwd_1st_ws_tst("a b" , 3, 1); // multiple
fxt.Test_Find_bwd_1st_ws_tst("ab" , 1, Bry_find_.Not_found); // none
}
@Test public void Trim_fwd_space_tab() {
fxt.Test_Trim_fwd_space_tab(" a b" , 1);
fxt.Test_Trim_fwd_space_tab("\ta b" , 1);
fxt.Test_Trim_fwd_space_tab(" \ta b" , 2);
fxt.Test_Trim_fwd_space_tab("a bc" , 0);
fxt.Test_Trim_fwd_space_tab("" , 0);
fxt.Test_Trim_fwd_space_tab(" \t" , 2);
}
@Test public void Trim_bwd_space_tab() {
fxt.Test_Trim_bwd_space_tab("a b " , 3);
fxt.Test_Trim_bwd_space_tab("a b\t" , 3);
fxt.Test_Trim_bwd_space_tab("a b\t " , 3);
fxt.Test_Trim_bwd_space_tab("a bc" , 4);
fxt.Test_Trim_bwd_space_tab("" , 0);
fxt.Test_Trim_bwd_space_tab(" \t" , 0);
}
@Test public void Find_fwd_while_in() {
boolean[] while_ary = fxt.Init__find_fwd_while_in(Byte_ascii.Space, Byte_ascii.Tab, Byte_ascii.Nl);
fxt.Test__find_fwd_while_in(" \t\na", while_ary, 3);
}
}
class Bry_find__fxt {
public void Test_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_fwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
public void Test_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
public void Test_Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd_last_ws(Bry_.new_a7(src), pos));}
public void Test_Trim_bwd_space_tab(String raw_str, int expd) {
byte[] raw_bry = Bry_.new_u8(raw_str);
int actl = Bry_find_.Trim_bwd_space_tab(raw_bry, raw_bry.length, 0);
Tfds.Eq(expd, actl, raw_str);
}
public void Test_Trim_fwd_space_tab(String raw_str, int expd) {
byte[] raw_bry = Bry_.new_u8(raw_str);
int actl = Bry_find_.Trim_fwd_space_tab(raw_bry, 0, raw_bry.length);
Tfds.Eq(expd, actl, raw_str);
}
public boolean[] Init__find_fwd_while_in(byte... ary) {
boolean[] rv = new boolean[256];
int len = ary.length;
for (int i = 0; i < len; i++)
rv[ary[i]] = true;
return rv;
}
public void Test__find_fwd_while_in(String src, boolean[] ary, int expd) {
byte[] src_bry = Bry_.new_u8(src);
Gftest.Eq__int(expd, Bry_find_.Find_fwd_while_in(src_bry, 0, src_bry.length, ary));
}
}

@ -0,0 +1,80 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*;
public class Bry_split__tst {
private final Bry_split__fxt fxt = new Bry_split__fxt();
@Test public void Split() {
fxt.Test_split("a" , Byte_ascii.Pipe, Bool_.N, "a"); // no trim
fxt.Test_split("a|" , Byte_ascii.Pipe, Bool_.N, "a");
fxt.Test_split("|a" , Byte_ascii.Pipe, Bool_.N, "", "a");
fxt.Test_split("|" , Byte_ascii.Pipe, Bool_.N, "");
fxt.Test_split("" , Byte_ascii.Pipe, Bool_.N);
fxt.Test_split("a|b|c" , Byte_ascii.Pipe, Bool_.N, "a", "b", "c");
fxt.Test_split(" a " , Byte_ascii.Pipe, Bool_.Y, "a"); // trim
fxt.Test_split(" a |" , Byte_ascii.Pipe, Bool_.Y, "a");
fxt.Test_split("| a " , Byte_ascii.Pipe, Bool_.Y, "", "a");
fxt.Test_split(" | " , Byte_ascii.Pipe, Bool_.Y, "");
fxt.Test_split(" " , Byte_ascii.Pipe, Bool_.Y);
fxt.Test_split(" a | b | c " , Byte_ascii.Pipe, Bool_.Y, "a", "b", "c");
fxt.Test_split(" a b | c d " , Byte_ascii.Pipe, Bool_.Y, "a b", "c d");
fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.N, " a ", " b "); // ws as dlm
fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.Y, "a", "b"); // ws as dlm; trim
fxt.Test_split("a|extend|b" , Byte_ascii.Pipe, Bool_.Y, "a", "extend|b"); // extend
fxt.Test_split("extend|a" , Byte_ascii.Pipe, Bool_.Y, "extend|a"); // extend
fxt.Test_split("a|cancel|b" , Byte_ascii.Pipe, Bool_.Y, "a"); // cancel
}
@Test public void Split__bry() {
fxt.Test_split("a|b|c|d" , 2, 6, "|", "b", "c");
fxt.Test_split("a|b|c|d" , 2, 4, "|", "b");
}
@Test public void Empty() {
fxt.Test_split("a\n\nb" , Byte_ascii.Nl, Bool_.N, "a", "", "b");
}
@Test public void Split_w_max() {
fxt.Test__split_w_max("a|b|c|d" , Byte_ascii.Pipe, 2, "a", "b"); // max is less
fxt.Test__split_w_max("a" , Byte_ascii.Pipe, 2, "a", null); // max is more
fxt.Test__split_w_max("|" , Byte_ascii.Pipe, 2, "", ""); // empty itms
}
}
class Bry_split__fxt {
private final Bry_split_wkr__example wkr = new Bry_split_wkr__example();
public void Test_split(String raw_str, byte dlm, boolean trim, String... expd) {
byte[] src = Bry_.new_a7(raw_str);
Bry_split_.Split(src, 0, src.length, dlm, trim, wkr);
byte[][] actl_ary = wkr.To_ary();
Tfds.Eq_ary_str(expd, String_.Ary(actl_ary));
}
public void Test_split(String src, int src_bgn, int src_end, String dlm, String... expd) {
Tfds.Eq_ary_str(Bry_.Ary(expd), Bry_split_.Split(Bry_.new_u8(src), src_bgn, src_end, Bry_.new_u8(dlm)));
}
public void Test__split_w_max(String src, byte dlm, int max, String... expd) {
Gftest.Eq__ary(expd, String_.Ary(Bry_split_.Split_w_max(Bry_.new_u8(src), dlm, max)));
}
}
class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr {
private final List_adp list = List_adp_.New();
public int Split(byte[] src, int itm_bgn, int itm_end) {
byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end);
if (Bry_.Eq(bry, Bry_.new_a7("extend"))) return Bry_split_.Rv__extend;
else if (Bry_.Eq(bry, Bry_.new_a7("cancel"))) return Bry_split_.Rv__cancel;
list.Add(bry);
return Bry_split_.Rv__ok;
}
public byte[][] To_ary() {
return (byte[][])list.To_ary_and_clear(byte[].class);
}
}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Byte__tst {
@Test public void int_() {
tst_int_( 0, 0);
tst_int_( 127, 127);
tst_int_( 128, 128); // NOTE: JAVA defines byte as -128 -> 127
tst_int_( 255, 255);
tst_int_( 256, 0); // NOTE: 256 will cast to 1; (byte)256 works same in both JAVA/.NET
} void tst_int_(int v, int expd) {Tfds.Eq((byte)expd, Byte_.By_int(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints
@Test public void To_int() {
tst_XtoInt( 0, 0);
tst_XtoInt( 127, 127);
tst_XtoInt( 128, 128);
tst_XtoInt( 255, 255);
tst_XtoInt( 256, 0);
} void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.To_int((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
}

@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*;
public class DateAdp__tst {
private final DateAdp__fxt fxt = new DateAdp__fxt();
@Test public void Parse_gplx() {
fxt.Test__parse_gplx("99991231_235959.999" , "99991231_235959.999");
fxt.Test__parse_gplx("20090430_213200.123" , "20090430_213200.123");
fxt.Test__parse_gplx("20090430_213200" , "20090430_213200.000");
fxt.Test__parse_gplx("20090430" , "20090430_000000.000");
}
@Test public void Parse_separators() {
fxt.Test__parse_gplx("2009-04-30 21:32:00.123" , "20090430_213200.123");
fxt.Test__parse_gplx("2009-04-30 21:32:00" , "20090430_213200.000");
fxt.Test__parse_gplx("2009-04-30" , "20090430_000000.000");
}
@Test public void Parse_utc() {
fxt.Test__parse_gplx("2015-12-26T10:03:53Z" , "20151226_100353.000");
}
@Test public void DayOfWeek() {
fxt.Test__day_of_week("2012-01-18", 3); //3=Wed
}
@Test public void WeekOfYear() {
fxt.Test__week_of_year("2006-02-01", 5); // 1-1:Sun;2-1:Wed
fxt.Test__week_of_year("2007-02-01", 5); // 1-1:Mon;2-1:Thu
fxt.Test__week_of_year("2008-02-01", 5); // 1-1:Tue;2-1:Fri
fxt.Test__week_of_year("2009-02-01", 6); // 1-1:Thu;2-1:Sun
fxt.Test__week_of_year("2010-02-01", 6); // 1-1:Fri;2-1:Mon
fxt.Test__week_of_year("2011-02-01", 6); // 1-1:Sat;2-1:Tue
}
@Test public void DayOfYear() {
fxt.Test__day_of_year("2012-01-01", 1);
fxt.Test__day_of_year("2012-02-29", 60);
fxt.Test__day_of_year("2012-12-31", 366);
}
@Test public void Timestamp_unix() {
fxt.Test__timestamp_unix("1970-01-01 00:00:00", 0);
fxt.Test__timestamp_unix("2012-01-01 00:00:00", 1325376000);
}
@Test public void DaysInMonth() {
fxt.Test__days_in_month("2012-01-01", 31);
fxt.Test__days_in_month("2012-02-01", 29);
fxt.Test__days_in_month("2012-04-01", 30);
fxt.Test__days_in_month("2011-02-01", 28);
}
@Test public void XtoUtc() {
fxt.Test__to_utc("2012-01-01 00:00", "2012-01-01 05:00"); //4=Wed
}
}
class DateAdp__fxt {
public void Test__parse_gplx(String raw, String expd) {
Gftest.Eq__str(expd, DateAdp_.parse_gplx(raw).XtoStr_gplx());
}
public void Test__day_of_week(String raw, int expd) {
Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).DayOfWeek());
}
public void Test__week_of_year(String raw, int expd) {
Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).WeekOfYear());
}
public void Test__day_of_year(String raw, int expd) {
Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).DayOfYear());
}
public void Test__days_in_month(String raw, int expd) {
Gftest.Eq__int(expd, DateAdp_.DaysInMonth(DateAdp_.parse_gplx(raw)));
}
public void Test__timestamp_unix(String raw, long expd) {
Gftest.Eq__long(expd, DateAdp_.parse_gplx(raw).Timestamp_unix());
}
public void Test__to_utc(String raw, String expd) {
Tfds.Eq(expd, DateAdp_.parse_gplx(raw).XtoUtc().XtoStr_fmt_yyyy_MM_dd_HH_mm());
}
}

@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Decimal_adp__tst {
private final Decimal_adp__fxt fxt = new Decimal_adp__fxt();
@Test public void divide_() {
fxt.Test_divide(1, 1000, "0.001");
fxt.Test_divide(1, 3, "0.33333333333333");
fxt.Test_divide(1, 7, "0.14285714285714");
}
@Test public void base1000_() {
fxt.Test_base_1000(1000, "1");
fxt.Test_base_1000(1234, "1.234");
fxt.Test_base_1000(123, "0.123");
}
@Test public void parts_() {
fxt.Test_parts(1, 0, "1");
fxt.Test_parts(1, 2, "1.2");
fxt.Test_parts(1, 23, "1.23");
fxt.Test_parts(123, 4567, "123.4567");
}
@Test public void parse() {
fxt.Test_parse("1", "1");
fxt.Test_parse("1.2", "1.2");
fxt.Test_parse("0.1", "0.1");
}
@Test public void Truncate_decimal() {
fxt.Test_truncate_decimal("1", "1");
fxt.Test_truncate_decimal("1.1", "1");
fxt.Test_truncate_decimal("1.9", "1");
}
@Test public void Fraction1000() {
fxt.Test_frac_1000(1, 1000, 1); // 0.001
fxt.Test_frac_1000(1, 3, 333); // 0.33333333
fxt.Test_frac_1000(1234, 1000, 234); // 1.234
fxt.Test_frac_1000(12345, 10000, 234); // 1.2345
}
@Test public void Lt() {
fxt.Test_comp_lt(1,123, 2, true);
fxt.Test_comp_lt(1,99999999, 2, true);
}
@Test public void To_str_fmt() {
fxt.Test_to_str_fmt(1, 2, "0.0", "0.5");
fxt.Test_to_str_fmt(1, 3, "0.0", "0.3");
fxt.Test_to_str_fmt(10000, 7, "0,000.000", "1,428.571");
fxt.Test_to_str_fmt(1, 2, "00.00", "00.50");
}
@Test public void Round() {
fxt.Test_round("123.456", 3, "123.456");
fxt.Test_round("123.456", 2, "123.46");
fxt.Test_round("123.456", 1, "123.5");
fxt.Test_round("123.456", 0, "123");
fxt.Test_round("123.456", -1, "120");
fxt.Test_round("123.456", -2, "100");
fxt.Test_round("123.456", -3, "0");
fxt.Test_round("6", -1, "10");
fxt.Test_round("5", -1, "10");
fxt.Test_round("6", -2, "0");
}
}
class Decimal_adp__fxt {
public void Test_divide(int lhs, int rhs, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).To_str());}
public void Test_base_1000(int val, String expd) {Tfds.Eq(expd, Decimal_adp_.base1000_(val).To_str());}
public void Test_parts(int num, int fracs, String expd) {Tfds.Eq(expd, Decimal_adp_.parts_(num, fracs).To_str());}
public void Test_parse(String raw, String expd) {Tfds.Eq(expd, Decimal_adp_.parse(raw).To_str());}
public void Test_truncate_decimal(String raw, String expd) {Tfds.Eq(Decimal_adp_.parse(expd).To_str(), Decimal_adp_.parse(raw).Truncate().To_str());}
public void Test_frac_1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).Frac_1000());}
public void Test_comp_lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, Decimal_adp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));}
public void Test_to_str_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(l, r).To_str(fmt));}
public void Test_round(String raw, int places, String expd) {Tfds.Eq_str(expd, Decimal_adp_.parse(raw).Round(places).To_str(), "round");}
}

@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Double__tst {
private Double__fxt fxt = new Double__fxt();
@Test public void Xto_str_loose() {
fxt.Test_Xto_str_loose(2449.6000000d , "2449.6");
fxt.Test_Xto_str_loose(623.700d , "623.7");
}
}
class Double__fxt {
public void Test_Xto_str_loose(double v, String expd) {Tfds.Eq(expd, Double_.To_str_loose(v));}
}

@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Err_tst {
private final Err_fxt fxt = new Err_fxt();
@Test public void Trace_to_str__gplx() {
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 0, String_.Concat_lines_nl_skip_last
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
, "gplx.String_.Len(String_.java:2)"
), String_.Concat_lines_nl_skip_last
( ""
, " gplx.String_.Len(String_.java:2)"
));
}
@Test public void Trace_to_str__gplx_ignore() {
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 1, String_.Concat_lines_nl_skip_last
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
, "gplx.String_.Fail(String_.java:2)" // ignore this line also
, "gplx.String_.Len(String_.java:3)"
), String_.Concat_lines_nl_skip_last
( ""
, " gplx.String_.Len(String_.java:3)"
));
}
}
class Err_fxt {
public void Test_Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace, String expd) {
String actl = Err.Trace_to_str(is_gplx, called_by_log, ignore_lines, trace);
Tfds.Eq_str_lines(expd, actl);
}
}

@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.langs.gfs.*;
public class GfoMsg_tst {
@Before public void setup() {
GfsCore.Instance.AddObj(new Mok(), "Mok");
}
@Test public void Write1() {
GfoMsg m = GfoMsg_.root_leafArgs_(String_.Ary("a", "b"), Keyval_.new_("int0", 1));
tst_Msg(m, "a.b:int0='1';");
}
@Test public void Write() {
Mok mok = new Mok();
tst_Msg(Gfo_invk_to_str.WriteMsg(mok, Mok.Invk_Cmd0, true, 1, "a"), "Mok.Cmd0:bool0='y' int0='1' str0='a';");
mok.Int0 = 2;
mok.Bool0 = true;
mok.Str0 = "b";
tst_Msg(Gfo_invk_to_str.ReadMsg(mok, Mok.Invk_Cmd0), "Mok.Cmd0:bool0='y' int0='2' str0='b';");
}
void tst_Msg(GfoMsg m, String expd) {Tfds.Eq(expd, m.To_str());}
class Mok implements Gfo_invk {
public boolean Bool0;
public int Int0;
public String Str0;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Cmd0)) {
Bool0 = m.ReadBoolOr("bool0", Bool0);
Int0 = m.ReadIntOr("int0", Int0);
Str0 = m.ReadStrOr("str0", Str0);
if (ctx.Deny()) return this;
}
return this;
} public static final String Invk_Cmd0 = "Cmd0";
}
}

@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Gfo_evt_mgr_tst {
@Before public void setup() {
pub = make_(); sub = make_();
} MockEvObj pub, sub;
@Test public void Basic() {
Gfo_evt_mgr_.Sub_same(pub, "ev1", sub);
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
sub.tst_Handled("val1");
}
@Test public void None() {// make sure no subscribers does not cause exception
Gfo_evt_mgr_.Sub_same(pub, "ev1", sub);
Gfo_evt_mgr_.Pub_val(pub, "ev2", "val1"); //ev2 does not exist
sub.tst_Handled();
}
@Test public void Lnk() {
MockEvObj mid = make_();
mid.Evt_mgr().Lnk(pub);
Gfo_evt_mgr_.Sub_same(mid, "ev1", sub);
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
sub.tst_Handled("val1");
}
@Test public void RlsSub() {
this.Basic();
Gfo_evt_mgr_.Rls_sub(sub);
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
sub.tst_Handled();
}
@Test public void RlsPub() {
this.Basic();
Gfo_evt_mgr_.Rls_sub(pub);
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
sub.tst_Handled();
}
MockEvObj make_() {return new MockEvObj();}
}
class MockEvObj implements Gfo_evt_itm {
public Gfo_evt_mgr Evt_mgr() {return eventMgr;} Gfo_evt_mgr eventMgr;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
handled.Add(m.ReadStr("v"));
return this;
}
List_adp handled = List_adp_.New();
public void tst_Handled(String... expd) {
Tfds.Eq_ary_str(expd, handled.To_str_ary());
handled.Clear();
}
public MockEvObj(){eventMgr = new Gfo_evt_mgr(this);}
}

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Guid_adp__tst {
@Test public void parse() {
tst_parse_("467ffb41-cdfe-402f-b22b-be855425784b");
}
void tst_parse_(String s) {
Guid_adp uuid = Guid_adp_.Parse(s);
Tfds.Eq(uuid.To_str(), s);
}
}

@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Hash_adp_bry_tst {
@Before public void setup() {fxt.Clear();} private Hash_adp_bry_fxt fxt = new Hash_adp_bry_fxt();
@Test public void Add_bry() {
fxt .New_cs()
.Add("a0").Add("b0").Add("c0")
.Get_bry_tst("a0").Get_bry_tst("b0").Get_bry_tst("c0").Get_bry_tst("A0", null)
;
}
@Test public void Get_mid() {
fxt .New_cs()
.Add("a0").Add("b0").Add("c0")
.Get_mid_tst("xyza0xyz", 3, 5, "a0")
.Get_mid_tst("xyza0xyz", 3, 4, null)
;
}
@Test public void Case_insensitive() {
fxt .New_ci()
.Add("a0").Add("B0").Add("c0")
.Get_bry_tst("a0", "a0")
.Get_bry_tst("A0", "a0")
.Get_bry_tst("b0", "B0")
.Get_bry_tst("B0", "B0")
.Get_mid_tst("xyza0xyz", 3, 5, "a0")
.Get_mid_tst("xyzA0xyz", 3, 5, "a0")
.Count_tst(3)
;
}
}
class Hash_adp_bry_fxt {
Hash_adp_bry hash;
public void Clear() {}
public Hash_adp_bry_fxt New_cs() {hash = Hash_adp_bry.cs(); return this;}
public Hash_adp_bry_fxt New_ci() {hash = Hash_adp_bry.ci_a7(); return this;}
public Hash_adp_bry_fxt Add(String key) {byte[] key_bry = Bry_.new_u8(key); hash.Add(key_bry, key_bry); return this;}
public Hash_adp_bry_fxt Count_tst(int expd) {Tfds.Eq(expd, hash.Count()); return this;}
public Hash_adp_bry_fxt Get_bry_tst(String key) {return Get_bry_tst(key, key);}
public Hash_adp_bry_fxt Get_bry_tst(String key, String expd) {
byte[] key_bry = Bry_.new_u8(key);
byte[] actl_bry = (byte[])hash.Get_by_bry(key_bry);
Tfds.Eq(expd, String_.new_u8(actl_bry));
return this;
}
public Hash_adp_bry_fxt Get_mid_tst(String key, int bgn, int end, String expd) {
byte[] key_bry = Bry_.new_u8(key);
byte[] actl_bry = (byte[])hash.Get_by_mid(key_bry, bgn, end);
Tfds.Eq(expd, String_.new_u8(actl_bry));
return this;
}
}

@ -0,0 +1,97 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Int__tst {
@Test public void XtoStr_PadBgn() {
tst_XtoStr_PadLeft_Zeroes(1 , 3, "001"); // pad
tst_XtoStr_PadLeft_Zeroes(123 , 3, "123"); // no pad
tst_XtoStr_PadLeft_Zeroes(1234 , 3, "1234"); // val exceeds pad; confirm noop
tst_XtoStr_PadLeft_Zeroes(-1 , 3, "-01"); // negative
tst_XtoStr_PadLeft_Zeroes(-12 , 3, "-12"); // negative
tst_XtoStr_PadLeft_Zeroes(-123 , 3, "-123"); // negative
tst_XtoStr_PadLeft_Zeroes(-1234 , 3, "-1234"); // negative
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.To_str_pad_bgn_zero(val, zeros));}
@Test public void parseOr_() {
tst_ParseOr("", -1); // empty
tst_ParseOr("123", 123); // single
tst_ParseOr("1a", -1); // fail
} void tst_ParseOr(String raw, int expd) {Tfds.Eq(expd, Int_.Parse_or(raw, -1));}
@Test public void Between() {
tst_Between(1, 0, 2, true); // simple true
tst_Between(3, 0, 2, false); // simple false
tst_Between(0, 0, 2, true); // bgn true
tst_Between(2, 0, 2, true); // end true
} void tst_Between(int val, int lhs, int rhs, boolean expd) {Tfds.Eq(expd, Int_.Between(val, lhs, rhs));}
@Test public void Xto_fmt() {
tst_XtoStr_fmt(1, "1");
tst_XtoStr_fmt(1000, "1,000");
} void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.To_str_fmt(v, "#,###"));}
@Test public void Log10_pos() {
tst_Log10(0, 0);
tst_Log10(1, 0);
tst_Log10(9, 0);
tst_Log10(10, 1);
tst_Log10(100, 2);
tst_Log10(1000000, 6);
tst_Log10(1000000000, 9);
tst_Log10(Int_.Max_value, 9);
}
@Test public void Log10_neg() {
tst_Log10(-1, 0);
tst_Log10(-10, -1);
tst_Log10(-100, -2);
tst_Log10(-1000000, -6);
tst_Log10(-1000000000, -9);
tst_Log10(Int_.Min_value, -9);
tst_Log10(Int_.Min_value + 1, -9);
}
void tst_Log10(int val, int expd) {Tfds.Eq(expd, Int_.Log10(val));}
@Test public void DigitCount() {
tst_DigitCount(0, 1);
tst_DigitCount(9, 1);
tst_DigitCount(100, 3);
tst_DigitCount(-1, 2);
tst_DigitCount(-100, 4);
} void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.To_str(val));}
@Test public void Log10() {
tst_Log10( 0, 0);
tst_Log10( 1, 0);
tst_Log10( 2, 0);
tst_Log10( 10, 1);
tst_Log10( 12, 1);
tst_Log10( 100, 2);
tst_Log10( 123, 2);
tst_Log10( 1000, 3);
tst_Log10( 1234, 3);
tst_Log10( 10000, 4);
tst_Log10( 12345, 4);
tst_Log10( 100000, 5);
tst_Log10( 123456, 5);
tst_Log10( 1000000, 6);
tst_Log10( 1234567, 6);
tst_Log10( 10000000, 7);
tst_Log10( 12345678, 7);
tst_Log10( 100000000, 8);
tst_Log10( 123456789, 8);
tst_Log10( 1000000000, 9);
tst_Log10( 1234567890, 9);
tst_Log10(Int_.Max_value, 9);
}
@Test public void Xto_int_hex_tst() {
Xto_int_hex("007C", 124);
} void Xto_int_hex(String raw, int expd) {Tfds.Eq(expd, Int_.By_hex_bry(Bry_.new_a7(raw)));}
}

@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*;
public class Int_ary__tst {
private Int_ary__fxt fxt = new Int_ary__fxt();
@Test public void Parse() {
fxt.Test__Parse("1,2,3" , 3, Int_ary_.Empty, 1, 2, 3);
fxt.Test__Parse("123,321,213" , 3, Int_ary_.Empty, 123, 321, 213);
fxt.Test__Parse(" 1, 2,3" , 3, Int_ary_.Empty, 1, 2, 3);
fxt.Test__Parse("-1,+2,-3" , 3, Int_ary_.Empty, -1, 2, -3);
fxt.Test__Parse(Int_.To_str(Int_.Min_value) , 1, Int_ary_.Empty, Int_.Min_value);
fxt.Test__Parse(Int_.To_str(Int_.Max_value) , 1, Int_ary_.Empty, Int_.Max_value);
fxt.Test__Parse("1,2" , 1, Int_ary_.Empty);
fxt.Test__Parse("1" , 2, Int_ary_.Empty);
fxt.Test__Parse("a" , 1, Int_ary_.Empty);
fxt.Test__Parse("1-2," , 1, Int_ary_.Empty);
}
@Test public void Parse_list_or_() {
fxt.Test__Parse_or("1", 1);
fxt.Test__Parse_or("123", 123);
fxt.Test__Parse_or("1,2,123", 1, 2, 123);
fxt.Test__Parse_or("1,2,12,123", 1, 2, 12, 123);
fxt.Test__Parse_or("1-5", 1, 2, 3, 4, 5);
fxt.Test__Parse_or("1-1", 1);
fxt.Test__Parse_or("1-3,7,11-13,21", 1, 2, 3, 7, 11, 12, 13, 21);
fxt.Test__Parse_or__empty("1 2"); // NOTE: MW would gen 12; treat as invalid
fxt.Test__Parse_or__empty("1,"); // eos
fxt.Test__Parse_or__empty("1,,2"); // empty comma
fxt.Test__Parse_or__empty("1-"); // eos
fxt.Test__Parse_or__empty("3-1"); // bgn > end
fxt.Test__Parse_or__empty("1,a,2");
fxt.Test__Parse_or__empty("a-1,2");
fxt.Test__Parse_or__empty("-1"); // no rng bgn
}
}
class Int_ary__fxt {
public void Test__Parse_or__empty(String raw) {Tfds.Eq_ary(Int_ary_.Empty, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));}
public void Test__Parse_or(String raw, int... expd) {Tfds.Eq_ary(expd, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));}
public void Test__Parse(String raw, int reqd_len, int[] or, int... expd) {Gftest.Eq__ary(expd, Int_ary_.Parse(raw, reqd_len, or), "failed to parse: {0}", raw);}
}

@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Io_mgr__tst {
@Before public void init() {fxt.Clear();} private final Io_mgr__fxt fxt = new Io_mgr__fxt();
@Test public void Dir_delete_empty__basic() {
fxt.Exec_itm_create("mem/dir/");
fxt.Exec_dir_delete_empty("mem/dir/");
fxt.Test_itm_exists_n("mem/dir/");
}
@Test public void Dir_delete_empty__no_delete() {
fxt.Exec_itm_create
( "mem/dir/"
, "mem/dir/fil.txt"
);
fxt.Exec_dir_delete_empty("mem/dir/");
fxt.Test_itm_exists_y("mem/dir/");
}
@Test public void Dir_delete_empty__nested_simple() {
fxt.Exec_itm_create
( "mem/dir/"
, "mem/dir/1/"
, "mem/dir/1/11/"
);
fxt.Exec_dir_delete_empty("mem/dir/");
fxt.Test_itm_exists_n("mem/dir/");
}
@Test public void Dir_delete_empty__nested_many() {
fxt.Exec_itm_create
( "mem/dir/"
, "mem/dir/1/"
, "mem/dir/1/11/"
, "mem/dir/2/22/"
, "mem/dir/2/22/222a/"
, "mem/dir/2/22/222b/"
);
fxt.Exec_dir_delete_empty("mem/dir/");
fxt.Test_itm_exists_n("mem/dir/");
}
@Test public void Dir_delete_empty__nested_some() {
fxt.Exec_itm_create
( "mem/dir/"
, "mem/dir/1/"
, "mem/dir/1/11/"
, "mem/dir/2/22/"
, "mem/dir/2/22/a.txt"
, "mem/dir/2/22/222a/"
, "mem/dir/2/22/222b/"
);
fxt.Exec_dir_delete_empty("mem/dir/");
fxt.Test_itm_exists_n
( "mem/dir/1/"
, "mem/dir/1/11/"
, "mem/dir/2/22/222a/"
, "mem/dir/2/22/222b/"
);
fxt.Test_itm_exists_y
( "mem/dir/"
, "mem/dir/2/22/"
);
}
}
class Io_mgr__fxt {
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
public void Exec_itm_create(String... ary) {
for (String itm : ary) {
Io_url url = Io_url_.new_any_(itm);
if (url.Type_dir())
Io_mgr.Instance.CreateDir(url);
else
Io_mgr.Instance.SaveFilStr(url, url.NameAndExt());
}
}
public void Exec_dir_delete_empty(String url) {Io_mgr.Instance.Delete_dir_empty(Io_url_.mem_dir_(url));}
public void Test_itm_exists_n(String... ary) {Test_itm_exists(Bool_.N, ary);}
public void Test_itm_exists_y(String... ary) {Test_itm_exists(Bool_.Y, ary);}
public void Test_itm_exists(boolean expd, String... ary) {
for (String itm : ary) {
Io_url url = Io_url_.new_any_(itm);
boolean actl = url.Type_dir() ? Io_mgr.Instance.ExistsDir(url) : Io_mgr.Instance.ExistsFil(url);
Tfds.Eq(expd, actl, itm);
}
}
}

@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
public class Io_url__tst {
@Before public void init() {fxt.Clear();} private final Io_url__fxt fxt = new Io_url__fxt();
@Test public void Basic__lnx() {fxt.Test__New__http_or_null(Bool_.N, "file:///C:/a.txt", "C:/a.txt");}
@Test public void Basic__wnt() {fxt.Test__New__http_or_null(Bool_.Y, "file:///C:/a.txt", "C:\\a.txt");}
@Test public void Null() {fxt.Test__New__http_or_null(Bool_.N, "C:/a.txt", null);}
}
class Io_url__fxt {
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
public void Test__New__http_or_null(boolean os_is_wnt, String raw, String expd) {
Op_sys.Cur_(os_is_wnt ? Op_sys.Tid_wnt : Op_sys.Tid_lnx);
Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw));
}
}

@ -0,0 +1,220 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class List_adp_tst {
@Before public void setup() {
list = List_adp_.New();
listBase = (List_adp_base)list;
} List_adp list; List_adp_base listBase;
@Test public void Add() {
Tfds.Eq(0, list.Count());
list.Add("0");
Tfds.Eq(1, list.Count());
}
@Test public void Add_changeCapacity() {
int capacity = 8;
for (int i = 0; i < capacity; i++)
list.Add("0");
Tfds.Eq(capacity, list.Count());
Tfds.Eq(capacity, listBase.Capacity());
list.Add(capacity); // forces resize
Tfds.Eq(capacity + 1, list.Count());
Tfds.Eq(capacity * 2, listBase.Capacity());
}
@Test public void Get_at() {
list.Add("0");
Tfds.Eq("0", list.Get_at(0));
}
@Test public void Fetch_many() {
list_AddMany("0", "1");
Tfds.Eq("0", list.Get_at(0));
Tfds.Eq("1", list.Get_at(1));
}
@Test public void FetchAt_fail() {
try {list.Get_at(0);}
catch (Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail("Get_at should fail for out of bound index");
}
@Test public void Del_at() {
list.Add("0");
Tfds.Eq(1, list.Count());
list.Del_at(0);
Tfds.Eq(0, list.Count());
}
@Test public void DelAt_shiftDown() {
list_AddMany("0", "1");
Tfds.Eq(list.Count(), 2);
list.Del_at(0);
Tfds.Eq(1, list.Count());
Tfds.Eq("1", list.Get_at(0));
}
@Test public void DelAt_fail() {
try {list.Del_at(0);}
catch (Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail("Del_at should fail for out of bound index");
}
@Test public void Del() {
list.Add("0");
Tfds.Eq(1, list.Count());
list.Del("0");
Tfds.Eq(0, list.Count());
}
@Test public void Del_matchMember() {
list_AddMany("0", "1");
Tfds.Eq(2, list.Count());
list.Del("1");
Tfds.Eq(1, list.Count());
Tfds.Eq("0", list.Get_at(0));
}
@Test public void Del_matchFirst() {
list_AddMany("0", "1", "0");
Tfds.Eq(3, list.Count());
list.Del("0");
tst_Enumerator("1", "0");
}
@Test public void Enumerator() {
list_AddMany("0", "1", "2");
tst_Enumerator("0", "1", "2");
}
@Test public void Enumerator_stateLess() { // run 2x, to confirm no state is being cached
list_AddMany("0", "1", "2");
tst_Enumerator("0", "1", "2");
tst_Enumerator("0", "1", "2");
}
@Test public void Enumerator_recursive() { // confirm separate enumerator objects are used
int pos = 0;
list_AddMany("0", "1", "2");
for (Object valObj : list) {
String val = (String)valObj;
Tfds.Eq(Int_.To_str(pos++), val);
tst_Enumerator("0", "1", "2");
}
}
@Test public void Clear() {
int capacity = 8;
for (int i = 0; i < capacity + 1; i++)
list.Add("0");
Tfds.Eq(capacity * 2, listBase.Capacity());
list.Clear();
Tfds.Eq(0, list.Count());
Tfds.Eq(16, listBase.Capacity()); // check that capacity has increased
}
@Test public void Clear_empty() { // confirm no failure
list.Clear();
Tfds.Eq(0, list.Count());
}
@Test public void Reverse() {
list_AddMany("0", "1", "2");
list.Reverse();
tst_Enumerator("2", "1", "0");
}
@Test public void Reverse_empty() {list.Reverse();}
@Test public void Sort() {
list_AddMany("2", "0", "1");
list.Sort();
tst_Enumerator("0", "1", "2");
}
@Test public void Sort_empty() {list.Sort();}
@Test public void Xto_bry() {
list_AddMany("0", "1");
String[] ary = (String[])list.To_ary(String.class);
Tfds.Eq_nullNot(ary);
Tfds.Eq(2, Array_.Len(ary));
}
@Test public void XtoAry_empty() {
String[] ary = (String[])list.To_ary(String.class);
Tfds.Eq_nullNot(ary);
Tfds.Eq(0, Array_.Len(ary));
}
@Test public void Shuffle() {
for (int i = 0; i < 25; i++)
list.Add(i);
list.Shuffle();
int hasMovedCount = 0;
for (int i = 0; i < list.Count(); i++) {
int val = Int_.Cast(list.Get_at(i));
if (val != i) hasMovedCount++;
}
Tfds.Eq_true(hasMovedCount > 0, "all documents have the same index"); // NOTE: may still fail occasionally (1%)
int count = list.Count();
for (int i = 0; i < count; i++)
list.Del(i);
Tfds.Eq(0, list.Count(), "shuffled list does not have the same contents as original list");
}
@Test public void Shuffle_empty() {list.Shuffle();}
@Test public void Move_to() {
run_ClearAndAdd("0", "1", "2").run_MoveTo(0, 1).tst_Order("1", "0", "2");
run_ClearAndAdd("0", "1", "2").run_MoveTo(0, 2).tst_Order("1", "2", "0");
run_ClearAndAdd("0", "1", "2").run_MoveTo(2, 1).tst_Order("0", "2", "1");
run_ClearAndAdd("0", "1", "2").run_MoveTo(2, 0).tst_Order("2", "0", "1");
}
@Test public void Del_range() {
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 2, "3");
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 3);
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(1, 2, "0", "3");
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(1, 3, "0");
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 3);
run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 0, "1", "2", "3");
}
void tst_DelRange(int bgn, int end, String... expd) {
list.Del_range(bgn, end);
Tfds.Eq_ary_str(expd, list.To_str_ary());
}
List_adp_tst run_ClearAndAdd(String... ary) {
list.Clear();
for (int i = 0; i < Array_.Len(ary); i++) {
String val = ary[i];
list.Add(val);
}
return this;
}
List_adp_tst run_MoveTo(int elemPos, int newPos) {list.Move_to(elemPos, newPos); return this;}
List_adp_tst tst_Order(String... expd) {
String[] actl = (String[])list.To_ary(String.class);
Tfds.Eq_ary(expd, actl);
return this;
}
void list_AddMany(String... ary) {
for (int i = 0; i < Array_.Len(ary); i++) {
String val = ary[i];
list.Add(val);
}
}
void tst_Enumerator(String... expd) {
int pos = 0;
int expdLength = Array_.Len(expd);
for (int i = 0; i < expdLength; i++) {
String val = expd[i];
Tfds.Eq(expd[pos++], val);
}
Tfds.Eq(pos, expdLength);
}
}

@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Long__tst {
@Test public void DigitCount() {
tst_DigitCount(0, 1);
tst_DigitCount(1, 1);
tst_DigitCount(9, 1);
tst_DigitCount(10, 2);
tst_DigitCount(100, 3);
tst_DigitCount(10000, 5);
tst_DigitCount(100000, 6);
tst_DigitCount(1000000, 7);
tst_DigitCount(1000000000, 10);
tst_DigitCount(10000000000L, 11);
tst_DigitCount(100000000000L, 12);
tst_DigitCount(10000000000000000L, 17);
tst_DigitCount(-1, 2);
} void tst_DigitCount(long val, int expd) {Tfds.Eq(expd, Long_.DigitCount(val));}
@Test public void Int_merge() {
tst_Int_merge(123, 456, 528280977864L);
tst_Int_merge(123, 457, 528280977865L);
}
void tst_Int_merge(int hi, int lo, long expd) {
Tfds.Eq(expd, Long_.Int_merge(hi, lo));
Tfds.Eq(hi, Long_.Int_split_hi(expd));
Tfds.Eq(lo, Long_.Int_split_lo(expd));
}
@Test public void parse_or() {
parse_or_tst("10000000000", 10000000000L);
}
void parse_or_tst(String raw, long expd) {Tfds.Eq(expd, Long_.parse_or(raw, -1));}
}

@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Math__tst {
@Test public void Abs() {
tst_Abs(1, 1);
tst_Abs(-1, 1);
tst_Abs(0, 0);
} void tst_Abs(int val, int expd) {Tfds.Eq(expd, Math_.Abs(val));}
@Test public void Log10() {
tst_Log10(0, Int_.Min_value);
tst_Log10(9, 0);
tst_Log10(10, 1);
tst_Log10(99, 1);
tst_Log10(100, 2);
} void tst_Log10(int val, int expd) {Tfds.Eq(expd, Math_.Log10(val));}
@Test public void Min() {
tst_Min(0, 1, 0);
tst_Min(1, 0, 0);
tst_Min(0, 0, 0);
} void tst_Min(int val0, int val1, int expd) {Tfds.Eq(expd, Math_.Min(val0, val1));}
@Test public void Pow() {
tst_Pow(2, 0, 1);
tst_Pow(2, 1, 2);
tst_Pow(2, 2, 4);
} void tst_Pow(int val, int exponent, double expd) {Tfds.Eq(expd, Math_.Pow(val, exponent));}
@Test public void Mult() {
tst_Mult(100, .01f, 1);
} void tst_Mult(int val, float multiplier, int expd) {Tfds.Eq(expd, Int_.Mult(val, multiplier));}
@Test public void Base2Ary() {
tst_Base2Ary( 1, 256, 1);
tst_Base2Ary( 2, 256, 2);
tst_Base2Ary( 3, 256, 1, 2);
tst_Base2Ary( 4, 256, 4);
tst_Base2Ary( 5, 256, 1, 4);
tst_Base2Ary( 6, 256, 2, 4);
tst_Base2Ary(511, 256, 1, 2, 4, 8, 16, 32, 64, 128, 256);
} void tst_Base2Ary(int v, int max, int... expd) {Tfds.Eq_ary(expd, Math_.Base2Ary(v, max));}
@Test public void Round() {
tst_Round(1.5 , 0, 2);
tst_Round(2.5 , 0, 3);
tst_Round(2.123 , 2, 2.12);
tst_Round(21.1 , -1, 20);
} void tst_Round(double v, int places, double expd) {Tfds.Eq(expd, Math_.Round(v, places));}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Object__tst {
@Before public void init() {} private Object__fxt fxt = new Object__fxt();
@Test public void Eq() {
fxt.Test_eq(null, null, true); // both null
fxt.Test_eq(5, 5, true); // both non-null
fxt.Test_eq(5, null, false); // rhs non-null
fxt.Test_eq(null, 5, false); // lhs non-null
}
@Test public void Xto_str_loose_or_null() {
fxt.Test_xto_str_loose_or_null(null, null);
fxt.Test_xto_str_loose_or_null(2449.6000000000004d, "2449.6");
}
}
class Object__fxt {
public void Test_eq(Object lhs, Object rhs, boolean expd) {Tfds.Eq(expd, Object_.Eq(lhs, rhs));}
public void Test_xto_str_loose_or_null(Object v, String expd) {Tfds.Eq(expd, Object_.Xto_str_loose_or(v, null));}
}

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class Ordered_hash_tst {
@Before public void setup() {
hash = Ordered_hash_.New();
}
@Test public void Get_at() {
hash.Add("key1", "val1");
Tfds.Eq("val1", hash.Get_at(0));
}
@Test public void iterator() {
hash.Add("key2", "val2");
hash.Add("key1", "val1");
List_adp list = List_adp_.New();
for (Object val : hash)
list.Add(val);
Tfds.Eq("val2", list.Get_at(0));
Tfds.Eq("val1", list.Get_at(1));
}
Ordered_hash hash;
}

@ -0,0 +1,182 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class String__tst {
@Test public void Len() {
tst_Len("", 0);
tst_Len("abc", 3);
} void tst_Len(String v, int expd) {Tfds.Eq(expd, String_.Len(v), "Len");}
@Test public void LimitToFirst() {
tst_LimitToFirst("abc", 0, "");
tst_LimitToFirst("abc", 1, "a");
tst_LimitToFirst("abc", 2, "ab");
tst_LimitToFirst("abc", 3, "abc");
tst_LimitToFirst("abc", 4, "abc");
err_LimitToFirst("abc", -1);
}
void tst_LimitToFirst(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToFirst(s, v));}
void err_LimitToFirst(String s, int v) {try {String_.LimitToFirst(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void LimitToLast() {
tst_LimitToLast("abc", 0, "");
tst_LimitToLast("abc", 1, "c");
tst_LimitToLast("abc", 2, "bc");
tst_LimitToLast("abc", 3, "abc");
tst_LimitToLast("abc", 4, "abc");
err_LimitToLast("abc", -1);
}
void tst_LimitToLast(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToLast(s, v));}
void err_LimitToLast(String s, int v) {try {String_.LimitToLast(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelBgn() {
tst_DelBgn("abc", 0, "abc");
tst_DelBgn("abc", 1, "bc");
tst_DelBgn("abc", 2, "c");
tst_DelBgn("abc", 3, "");
err_DelBgn(null, 0);
err_DelBgn("abc", 4);
}
void tst_DelBgn(String s, int v, String expd) {Tfds.Eq(expd, String_.DelBgn(s, v));}
void err_DelBgn(String s, int v) {try {String_.DelBgn(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelBgnIf() {
tst_DelBgnIf("abc", "", "abc");
tst_DelBgnIf("abc", "a", "bc");
tst_DelBgnIf("abc", "ab", "c");
tst_DelBgnIf("abc", "abc", "");
tst_DelBgnIf("abc", "abcd", "abc");
tst_DelBgnIf("abc", "bcd", "abc");
err_DelBgnIf(null, "abc");
err_DelBgnIf("abc", null);
}
void tst_DelBgnIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelBgnIf(s, v));}
void err_DelBgnIf(String s, String v) {try {String_.DelBgnIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelEnd() {
tst_DelEnd("abc", 0, "abc");
tst_DelEnd("abc", 1, "ab");
tst_DelEnd("abc", 2, "a");
tst_DelEnd("abc", 3, "");
err_DelEnd(null, 0);
err_DelEnd("abc", 4);
}
void tst_DelEnd(String s, int v, String expd) {Tfds.Eq(expd, String_.DelEnd(s, v));}
void err_DelEnd(String s, int v) {try {String_.DelEnd(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void DelEndIf() {
tst_DelEndIf("abc", "", "abc");
tst_DelEndIf("abc", "c", "ab");
tst_DelEndIf("abc", "bc", "a");
tst_DelEndIf("abc", "abc", "");
tst_DelEndIf("abc", "abcd", "abc");
tst_DelEndIf("abc", "ab", "abc");
err_DelEndIf(null, "");
err_DelEndIf("", null);
}
void tst_DelEndIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelEndIf(s, v));}
void err_DelEndIf(String s, String v) {try {String_.DelEndIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();}
@Test public void MidByPos() {
tst_MidByPos("abc", 0, 0, "");
tst_MidByPos("abc", 0, 1, "a");
tst_MidByPos("abc", 0, 2, "ab");
tst_MidByPos("abc", 0, 3, "abc");
tst_MidByPos("abc", 2, 3, "c");
err_MidByPos("abc", 1, 5);
// err_MidByPos("abc", 0, 4);
}
void tst_MidByPos(String s, int bgn, int end, String expd) {Tfds.Eq(expd, String_.Mid(s, bgn, end));}
void err_MidByPos(String s, int bgn, int end) {try {String_.Mid(s, bgn, end);} catch (Exception e) {Tfds.Err_classMatch(e, Err.class); return;} Tfds.Fail_expdError();}
@Test public void TrimEnd() {
tst_TrimEnd("a", "a");
tst_TrimEnd("a ", "a");
tst_TrimEnd("a\t", "a");
tst_TrimEnd("a\n", "a");
tst_TrimEnd("a\r", "a");
tst_TrimEnd("a\r\n \t", "a");
tst_TrimEnd(" a", " a");
tst_TrimEnd(null, null);
}
void tst_TrimEnd(String s, String expd) {Tfds.Eq(expd, String_.TrimEnd(s));}
@Test public void Count() {
String text = "0 0 0";
Tfds.Eq(3, String_.Count(text, "0"));
}
@Test public void Has() {
String text = "find word";
Tfds.Eq_true(String_.Has(text, "word"));
Tfds.Eq_false(String_.Has(text, "nothing"));
}
@Test public void Repeat() {
Tfds.Eq("333", String_.Repeat("3", 3));
}
@Test public void Format() {
tst_Format("", ""); // empty
tst_Format("no args", "no args"); // no args
tst_Format("0", "{0}", 0); // one
tst_Format("0 and 1", "{0} and {1}", 0, 1); // many
tst_Format("{", "{{", 0); // escape bracketBgn
tst_Format("}", "}}", 0); // escape bracketEnd
tst_Format("{a0c}", "{a{0}c}", 0); // nested;
tst_Format("{a{b}c}", "{a{b}c}", 0); // invalid invalid
tst_Format("{1}", "{1}", 1); // invalid array index
tst_Format("{a} {b}", "{a} {b}", 0); // invalid many
tst_Format("{a}0{b}1", "{a}{0}{b}{1}", 0, 1); // invalid and valid
tst_Format("{0", "{0", 0); // invalid dangling
} void tst_Format(String expd, String fmt, Object... ary) {Tfds.Eq(expd, String_.Format(fmt, ary));}
@Test public void Split() {
tst_Split("ab", " ", "ab"); // no match -> return array with original input
tst_Split("ab cd", " ", "ab", "cd"); // separator.length = 1
tst_Split("ab+!cd", "+!", "ab", "cd"); // separator.length = 2
tst_Split("ab+!cd+!ef", "+!", "ab", "cd", "ef"); // terms = 3
tst_Split("ab+!cd+!", "+!", "ab", "cd", ""); // closing separator
tst_Split("+!ab", "+!", "", "ab"); // opening separator
tst_Split("ab+cd+!ef", "+!", "ab+cd", "ef"); // ignore partial matches
tst_Split("ab+!cd+", "+!", "ab", "cd+"); // ignore partial matches; end of String
// boundary
tst_Split("ab", "", "ab"); // separator.length = 0 -> return array with input as only member
tst_Split("", " ", ""); // empty input -> return array with empty input
// acceptance
tst_Split("this\r\nis\na\rtest\r\n.", "\r\n", "this", "is\na\rtest", ".");
} void tst_Split(String text, String separator, String... expd) {Tfds.Eq_ary(expd, String_.Split(text, separator));}
@Test public void Concat_with_obj() {
tst_ConcatWith_any("a|b", "|", "a", "b"); // do not append final delimiter
tst_ConcatWith_any("a||c", "|", "a", null, "c"); // null
tst_ConcatWith_any("a|b", "|", Object_.Ary("a", "b")); // pass array as arg
} void tst_ConcatWith_any(String expd, String delimiter, Object... array) {Tfds.Eq(expd, String_.Concat_with_obj(delimiter, array));}
@Test public void Compare_byteAry() {
tst_Compare_byteAry("a", "a", CompareAble_.Same);
tst_Compare_byteAry("a", "b", CompareAble_.Less);
tst_Compare_byteAry("b", "a", CompareAble_.More);
tst_Compare_byteAry("ab", "ac", CompareAble_.Less);
tst_Compare_byteAry("ac", "ab", CompareAble_.More);
tst_Compare_byteAry("a", "ab", CompareAble_.Less);
tst_Compare_byteAry("ab", "a", CompareAble_.More);
tst_Compare_byteAry("101", "1-0-1", CompareAble_.More); // NOTE: regular String_.Compare_as_ordinals returns Less in .NET, More in Java
tst_Compare_byteAry("1-0-1", "101 (album)", CompareAble_.Less);
} void tst_Compare_byteAry(String lhs, String rhs, int expd) {Tfds.Eq(expd, String_.Compare_byteAry(lhs, rhs));}
@Test public void FindBwd() { // WORKAROUND.CS:String.LastIndexOf returns -1 for multi-chars;
tst_FindRev("abc", "a", 0, 0);
tst_FindRev("abc", "ab", 0, 0); // 2 chars
tst_FindRev("abc", "abc", 0, 0); // 3 chars
tst_FindRev("ab", "abc", 0, -1); // out of index error
tst_FindRev("ababab", "ab", 2, 2); // make sure cs implementation doesn't pick up next
} void tst_FindRev(String s, String find, int pos, int expd) {Tfds.Eq(expd, String_.FindBwd(s, find, pos));}
@Test public void Extract_after_bwd() {
Extract_after_bwd_tst("a/b", "/", "b");
Extract_after_bwd_tst("a/", "/", "");
Extract_after_bwd_tst("a", "/", "");
} void Extract_after_bwd_tst(String src, String dlm, String expd) {Tfds.Eq(expd, String_.Extract_after_bwd(src, dlm));}
}

@ -0,0 +1,97 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import gplx.core.strings.*;
import gplx.core.lists.*;
public class TfdsTstr_fxt {
public TfdsTstr_fxt Eq_str(Object expd, Object actl, String name) {
int nameLen = String_.Len(name); if (nameLen > nameLenMax) nameLenMax = nameLen;
TfdsTstrItm itm = TfdsTstrItm.new_().Expd_(expd).Actl_(actl).Name_(name);
list.Add(itm);
return this;
}
public void SubName_push(String s) {
stack.Push(s);
TfdsTstrItm itm = TfdsTstrItm.new_();
itm.SubName_make(stack);
itm.TypeOf = 1;
list.Add(itm);
} StackAdp stack = StackAdp_.new_();
public void Fail() {
manualFail = true;
}boolean manualFail = false;
public int List_Max(List_adp expd, List_adp actl) {return Math_.Max(expd.Count(), actl.Count());}
public int List_Max(String[] expd, String[] actl) {return Math_.Max(expd.length, actl.length);}
public Object List_FetchAtOrNull(List_adp l, int i) {return (i >= l.Count()) ? null : l.Get_at(i);}
public void SubName_pop() {stack.Pop();}
int nameLenMax = 0;
public void tst_Equal(String hdr) {
boolean pass = true;
for (int i = 0; i < list.Count(); i++) {
TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i);
if (!itm.Compare()) pass = false; // don't break early; Compare all vals
}
if (pass && !manualFail) return;
String_bldr sb = String_bldr_.new_();
sb.Add_char_crlf();
sb.Add_str_w_crlf(hdr);
for (int i = 0; i < list.Count(); i++) {
TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i);
if (itm.TypeOf == 1) {
sb.Add_fmt_line(" /{0}", itm.SubName());
continue;
}
boolean hasError = itm.CompareResult() != TfdsTstrItm.CompareResult_eq;
String errorKey = hasError ? "*" : " ";
sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd(itm.Name(), nameLenMax, " "), itm.Expd());
if (hasError)
sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd("", nameLenMax, " "), itm.Actl());
}
sb.Add(String_.Repeat("_", 80));
throw Err_.new_wo_type(sb.To_str());
}
List_adp list = List_adp_.New();
public static TfdsTstr_fxt new_() {return new TfdsTstr_fxt();} TfdsTstr_fxt() {}
}
class TfdsTstrItm {
public String Name() {return name;} public TfdsTstrItm Name_(String val) {name = val; return this;} private String name;
public Object Expd() {return expd;} public TfdsTstrItm Expd_(Object val) {expd = val; return this;} Object expd;
public Object Actl() {return actl;} public TfdsTstrItm Actl_(Object val) {actl = val; return this;} Object actl;
public String SubName() {return subName;} private String subName = "";
public int TypeOf;
public void SubName_make(StackAdp stack) {
if (stack.Count() == 0) return;
List_adp list = stack.XtoList();
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < list.Count(); i++) {
if (i != 0) sb.Add(".");
sb.Add((String)list.Get_at(i));
}
subName = sb.To_str();
}
public int CompareResult() {return compareResult;} public TfdsTstrItm CompareResult_(int val) {compareResult = val; return this;} int compareResult;
public boolean Compare() {
boolean eq = Object_.Eq(expd, actl);
compareResult = eq ? 1 : 0;
return eq;
}
public String CompareSym() {
return compareResult == 1 ? "==" : "!=";
}
public static TfdsTstrItm new_() {return new TfdsTstrItm();} TfdsTstrItm() {}
public static final int CompareResult_none = 0, CompareResult_eq = 1, CompareResult_eqn = 2;
}

@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Bry_bfr_mkr_tst {
private final Bry_bfr_mkr_fxt fxt = new Bry_bfr_mkr_fxt();
@Before public void setup() {fxt.Clear();}
@Test public void Get_1() {fxt.Clear().Get().Test__used(0);}
@Test public void Get_2() {fxt.Clear().Get().Get().Test__used(0, 1);}
@Test public void Get_3() {fxt.Clear().Get().Get().Get().Test__used(0, 1, 2);}
@Test public void Rls() {fxt.Clear().Get().Rls(0).Test__used();}
@Test public void Rls_skip_1() {
fxt.Clear().Get().Get().Rls(0).Test__used(-1, 1);
fxt.Get().Test__used(0, 1);
}
@Test public void Rls_skip_2_1() {
fxt.Clear().Get().Get().Get().Rls(1).Rls(0).Test__used(-1, -1, 2);
fxt.Get().Test__used(0, -1, 2);
fxt.Get().Test__used(0, 1, 2);
fxt.Get().Test__used(0, 1, 2, 3);
}
@Test public void Get_rls_get() { // PURPOSE: defect in which last rls failed b/c was not doing ++ if rv existed
fxt.Clear().Get().Rls(0).Get().Get().Rls(1).Rls(0).Test__used();
}
}
class Bry_bfr_mkr_fxt {
private final Bry_bfr_mkr_mgr mkr = new Bry_bfr_mkr_mgr(Byte_.Zero, 32);
public Bry_bfr_mkr_fxt Clear() {mkr.Clear(); return this;}
public Bry_bfr_mkr_fxt Get() {mkr.Get(); return this;}
public Bry_bfr_mkr_fxt Rls(int i) {mkr.Used()[i].Mkr_rls(); return this;}
public Bry_bfr_mkr_fxt Test__used(int... expd) {
int actl_len = mkr.Used_len();
int[] actl = new int[actl_len];
for (int i = 0; i < actl_len; i++) {
Bry_bfr bfr = mkr.Used()[i];
int actl_val = bfr == null ? -2 : bfr.Mkr_idx();
actl[i] = actl_val;
}
Tfds.Eq_ary(expd, actl);
return this;
}
}

@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Bry_rdr_tst {
@Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt();
@Test public void Int() {
fxt.Init_src("12|3456|789");
fxt.Test_read_int(12);
fxt.Test_read_int(3456);
fxt.Test_read_int(789);
fxt.Test_read_int(Int_.Min_value);
}
@Test public void Int_negative() {
fxt.Init_src("-1|-2");
fxt.Test_read_int(-1);
fxt.Test_read_int(-2);
}
@Test public void Bry() {
fxt.Init_src("abc|d||ef");
fxt.Test_read_bry("abc");
fxt.Test_read_bry("d");
fxt.Test_read_bry("");
fxt.Test_read_bry("ef");
fxt.Test_read_bry(null);
}
}
class Bry_rdr_fxt {
private Bry_rdr_old rdr;
public void Clear() {rdr = new Bry_rdr_old();}
public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;}
public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;}
public void Test_read_int(int expd_val) {
Tfds.Eq(expd_val, rdr.Read_int_to_pipe());
}
public void Test_read_bry(String expd_str) {
byte[] actl_bry = rdr.Read_bry_to_pipe();
String actl_str = actl_bry == null ? null : String_.new_u8(actl_bry);
Tfds.Eq(expd_str, actl_str);
}
}

@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bfr_arg__time_tst {
@Test public void Basic() {
Time_fmtr_arg_fxt fxt = new Time_fmtr_arg_fxt().Clear();
fxt.XferAry( 1, "01s"); // seconds
fxt.XferAry( 62, "01m 02s"); // minutes
fxt.XferAry( 3723, "01h 02m 03s"); // hours
fxt.XferAry( 93784, "01d 02h 03m 04s"); // days
fxt.XferAry( 0, "00s"); // handle 0 seconds
fxt.XferAry( 3601, "01h 00m 01s"); // handle 0 in middle unit
}
}
class Time_fmtr_arg_fxt {
public Time_fmtr_arg_fxt Clear() {
if (arg == null) arg = new Bfr_arg__time();
return this;
} Bfr_arg__time arg;
public void XferAry(int seconds, String expd) {
Bry_bfr bfr = Bry_bfr_.Reset(255);
arg.Seconds_(seconds);
arg.Bfr_arg__add(bfr);
Tfds.Eq(expd, bfr.To_str());
}
}

@ -0,0 +1,72 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bry_fmtr_tst {
private final Bry_fmtr_fxt fxt = new Bry_fmtr_fxt();
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
@Test public void Idx__1() {fxt.Clear().Fmt("~{0}").Args("a").Test("a");}
@Test public void Idx__3() {fxt.Clear().Fmt("~{0}~{1}~{2}").Args("a", "b", "c").Test("abc");}
@Test public void Idx__mix() {fxt.Clear().Fmt("a~{0}c~{1}e").Args("b", "d").Test("abcde");}
@Test public void Idx__missing() {fxt.Clear().Fmt("~{0}").Test("~{0}");}
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Keys("key").Args("a").Test("a");}
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Keys("key1").Args("a").Test("aa");}
@Test public void Mix() {fxt.Clear().Fmt("~{key1}~{1}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Simple() {
fxt.Clear().Fmt("0~{key1}1~{key2}2").Keys("key1", "key2").Args(".", ",").Test("0.1,2");
}
@Test public void Cmd() {
Bry_fmtr_tst_mok mok = new Bry_fmtr_tst_mok();
Bry_fmtr fmtr = Bry_fmtr.new_("0~{key1}2~{<>3<>}4", "key1").Eval_mgr_(mok);
Tfds.Eq("012~{<>3<>}4", fmtr.Bld_str_many("1"));
mok.Enabled_(true);
Tfds.Eq("01234", fmtr.Bld_str_many("1"));
}
@Test public void Bld_bfr_many_and_set_fmt() {
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
}
@Test public void Escape_tilde() {
Tfds.Eq("~~~~~~", Bry_fmtr.Escape_tilde("~~~"));
}
}
class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
public byte[] Eval(byte[] cmd) {
return enabled ? cmd : null;
}
}
class Bry_fmtr_fxt {
private final Bry_fmtr fmtr = Bry_fmtr.new_();
private final Bry_bfr bfr = Bry_bfr_.New();
private Object[] args;
public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;}
public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;}
public Bry_fmtr_fxt Keys(String... args) {fmtr.Keys_(args); return this;}
public Bry_fmtr_fxt Args(Object... args) {this.args = args; return this;}
public void Test(String expd) {
fmtr.Bld_bfr_many(bfr, args);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
public void Bld_bfr_many_and_set_fmt(String fmt, Object[] args, String expd) {
fmtr.Fmt_(fmt);
fmtr.Bld_bfr_many_and_set_fmt(args);
Tfds.Eq(expd, String_.new_a7(fmtr.Fmt()));
}
}

@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bry_fmt_tst {
private final Bry_fmt_fxt fxt = new Bry_fmt_fxt();
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Vals("a").Test("a");}
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Vals("a", "b").Test("ab");}
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Vals("a").Test("aa");}
@Test public void Key__missing() {fxt.Clear().Fmt("~{key}").Test("~{key}");}
@Test public void Tilde() {fxt.Clear().Fmt("~~~~").Test("~~");}
@Test public void Simple() {fxt.Clear().Fmt("0~{key1}1~{key2}2").Vals(".", ",").Test("0.1,2");}
@Test public void Arg() {fxt.Clear().Fmt("~{custom}").Args("custom", new Bfr_fmt_arg_mok(123)).Test("123");}
@Test public void Keys() {fxt.Clear().Fmt("~{b}~{c}~{a}").Keys("a", "b", "c").Vals("a", "b", "c").Test("bca");}
}
class Bfr_fmt_arg_mok implements Bfr_arg {
private int num;
public Bfr_fmt_arg_mok(int num) {this.num = num;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_int_variable(num);
}
}
class Bry_fmt_fxt {
private final Bry_fmt fmt = new Bry_fmt(Bry_.Empty, Bry_.Ary_empty, Bfr_fmt_arg.Ary_empty);
private final Bry_bfr bfr = Bry_bfr_.New();
private Object[] vals;
public Bry_fmt_fxt Clear() {vals = Object_.Ary_empty; return this;}
public Bry_fmt_fxt Fmt(String s) {fmt.Fmt_(s); return this;}
public Bry_fmt_fxt Vals(Object... vals) {this.vals = vals; return this;}
public Bry_fmt_fxt Args(String key, Bfr_arg arg) {fmt.Args_(new Bfr_fmt_arg(Bry_.new_u8(key), arg)); return this;}
public Bry_fmt_fxt Keys(String... keys) {fmt.Keys_(Bry_.Ary(keys)); return this;}
public void Test(String expd) {
fmt.Bld_many(bfr, vals);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import org.junit.*;
public class Bry_keys_parser_tst {
private final Bry_keys_parser_fxt fxt = new Bry_keys_parser_fxt();
@Test public void None() {fxt.Test("a");}
@Test public void One() {fxt.Test("~{a}" , "a");}
@Test public void Many() {fxt.Test("~{a}b~{c}d~{e}" , "a", "c", "e");}
@Test public void Dupe() {fxt.Test("~{a}b~{a}" , "a");}
@Test public void Bug__space() {fxt.Test("~{a}~{b} ~{c}" , "a", "b", "c");} // DATE:2016-08-02
}
class Bry_keys_parser_fxt {
public void Test(String fmt, String... expd) {
Tfds.Eq_ary(expd, String_.Ary(Bry_fmt_parser_.Parse_keys(Bry_.new_u8(fmt))));
}
}

@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_bwd_mgr_tst {
@Before public void init() {} private Btrie_bwd_mgr trie;
private void ini_setup1() {
trie = new Btrie_bwd_mgr(false);
run_Add("c" , 1);
run_Add("abc" , 123);
}
@Test public void Get_by() {
ini_setup1();
tst_MatchAtCur("c" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("bc" , 1);
tst_MatchAtCur("yzabc" , 123);
tst_MatchAtCur("ab" , null);
}
@Test public void Fetch_intl() {
trie = new Btrie_bwd_mgr(false);
run_Add("a<>", 1);
tst_MatchAtCur("a<>" , 1);
tst_MatchAtCur("<22>" , null);
}
@Test public void Eos() {
ini_setup1();
tst_Match("ab", Byte_ascii.Ltr_c, 2, 123);
}
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("c", 1);
tst_MatchAtCurExact("bc", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = new Btrie_bwd_mgr(false);
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_bwd_mgr.ci_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
private void run_Add(String k, int val) {trie.Add(Bry_.new_u8(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match(b, src, bgn_pos, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match(src[src.length - 1], src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_u8(srcStr);
Object actl = trie.Match_exact(src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
}

@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_fast_mgr_tst {
private Btrie_fast_mgr_fxt fxt = new Btrie_fast_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Get_by() {
fxt.Test_matchAtCur("a" , 1);
fxt.Test_matchAtCur("abc" , 123);
fxt.Test_matchAtCur("ab" , 1);
fxt.Test_matchAtCur("abcde" , 123);
fxt.Test_matchAtCur(" a" , null);
}
@Test public void Bos() {
fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
fxt.Test_matchAtCurExact("a", 1);
fxt.Test_matchAtCurExact("ab", null);
fxt.Test_matchAtCurExact("abc", 123);
}
@Test public void Del_noop__no_match() {
fxt.Exec_del("d");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_noop__partial_match() {
fxt.Exec_del("ab");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_match__long() {
fxt.Exec_del("abc");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , null);
}
@Test public void Del_match__short() {
fxt.Exec_del("a");
fxt.Test_matchAtCurExact("a" , null);
fxt.Test_matchAtCurExact("abc" , 123);
}
}
class Btrie_fast_mgr_fxt {
private Btrie_fast_mgr trie;
public void Clear() {
trie = Btrie_fast_mgr.cs();
Init_add( 1 , Byte_ascii.Ltr_a);
Init_add(123 , Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
}
public void Init_add(int val, byte... ary) {trie.Add(ary, val);}
public void Test_match(String src_str, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCur(String src_str, Object expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_bgn(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCurExact(String src_str, Object expd) {
byte[] src = Bry_.new_a7(src_str);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Exec_del(String src_str) {
trie.Del(Bry_.new_u8(src_str));
}
}

@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_slim_itm_tst {
private Btrie_slim_itm itm = new Btrie_slim_itm(Byte_.Zero, null, false);
@Before public void init() {itm.Clear();}
@Test public void Find_nil() {
tst_Find(Byte_ascii.Ltr_a, null);
}
@Test public void Add_one() {
run_Add(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Add_many() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Del() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
run_Del(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, null);
tst_Find(Byte_ascii.Num_0, "0");
tst_Find(Byte_ascii.Ltr_B, "B");
}
private void tst_Find(byte b, String expd) {
Btrie_slim_itm actl_itm = itm.Ary_find(b);
Object actl = actl_itm == null ? null : actl_itm.Val();
Tfds.Eq(expd, actl);
}
private void run_Add(byte... ary) {for (byte b : ary) itm.Ary_add(b, Char_.To_str((char)b));}
private void run_Del(byte... ary) {for (byte b : ary) itm.Ary_del(b);}
}

@ -0,0 +1,109 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
public class Btrie_slim_mgr_tst {
@Before public void init() {
} private Btrie_slim_mgr trie;
private void ini_setup1() {
trie = Btrie_slim_mgr.cs();
run_Add("a" , 1);
run_Add("abc" , 123);
}
@Test public void Get_by() {
ini_setup1();
tst_MatchAtCur("a" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("ab" , 1);
tst_MatchAtCur("abcde" , 123);
tst_MatchAtCur(" a" , null);
}
@Test public void Bos() {
ini_setup1();
tst_Match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("a", 1);
tst_MatchAtCurExact("ab", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = Btrie_slim_mgr.cs();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:test
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
@Test public void Del() {
ini_setup1();
trie.Del(Bry_.new_a7("a")); // delete "a"; "abc" still remains;
tst_MatchAtCur("a" , null);
tst_MatchAtCur("abc" , 123);
trie.Del(Bry_.new_a7("abc"));
tst_MatchAtCur("abc" , null);
}
@Test public void Match_none() {
Btrie_slim_mgr_fxt fxt = new Btrie_slim_mgr_fxt();
fxt.Init__add("k1", "v1");
fxt.Exec__match("ak1", 1, 3, "v1", 3); // 3 to position after match
fxt.Exec__match("ak2", 1, 1, null, 1); // 1 to position at current pos; used to be 0; de.w:Butter; DATE:2018-04-12
}
private void run_Add(String k, int val) {trie.Add_obj(Bry_.new_a7(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_a7(srcStr);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
}
class Btrie_slim_mgr_fxt {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
public Btrie_slim_mgr_fxt Init__add(String key, String val) {
trie.Add_str_str(key, val);
return this;
}
public void Exec__match(String src, int bgn_pos, int end_pos, Object expd_val, int expd_pos) {
Btrie_rv trv = new Btrie_rv();
Object actl_val = trie.Match_at(trv, Bry_.new_u8(src), bgn_pos, end_pos);
Gftest.Eq__obj_or_null(expd_val, actl_val);
Gftest.Eq__int(expd_pos, trv.Pos());
}
}

@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.criterias; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.core.ios.*;
public class Criteria_ioItm_tst {
IoItmFil fil; Criteria crt; IoItm_fxt fx = IoItm_fxt.new_();
@Test public void IoType() {
crt = crt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil));
tst_Match(true, crt, fx.fil_wnt_("C:\\fil.txt"));
tst_Match(false, crt, fx.dir_wnt_("C:\\dir"));
}
@Test public void Ext() {
crt = crt_(IoItm_base_.Prop_Ext, Criteria_.eq_(".txt"));
tst_Match(true, crt, fx.fil_wnt_("C:\\fil.txt"));
tst_Match(false, crt, fx.fil_wnt_("C:\\fil.xml"), fx.fil_wnt_("C:\\fil.txt1"), fx.fil_wnt_("C:\\fil1.txt.xml"), fx.dir_wnt_("C:\\.txt"));
}
@Test public void Modified() {
fil = fx.fil_wnt_("C:\\fil.txt");
crt = crt_(IoItmFil_.Prop_Modified, Criteria_.mte_(DateAdp_.parse_gplx("2001-01-01")));
tst_Match(true, crt, fil.ModifiedTime_(DateAdp_.parse_gplx("2001-01-02")), fil.ModifiedTime_(DateAdp_.parse_gplx("2001-01-01")));
tst_Match(false, crt, fil.ModifiedTime_(DateAdp_.parse_gplx("2000-12-31")));
}
@Test public void IoMatch() {
Criteria crt = Criteria_ioMatch.parse(true, "*.txt", false);
CriteriaFxt fx_crt = new CriteriaFxt();
fx_crt.tst_Matches(crt, Io_url_.new_any_("file.txt"));
fx_crt.tst_MatchesNot(crt, Io_url_.new_any_("file.xml"));
}
Criteria crt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);}
void tst_Match(boolean expt, Criteria fieldCrt, IoItm_base... ary) {
for (IoItm_base itm : ary)
Tfds.Eq(expt, fieldCrt.Matches(itm));
}
}

@ -0,0 +1,90 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.criterias; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Criteria_tst {
@Test public void Equal() {
Criteria crt = Criteria_.eq_(true);
fx.tst_Matches(crt, true);
fx.tst_MatchesNot(crt, false);
fx.tst_MatchesFail(crt, "true");
fx.tst_Matches(Criteria_.eq_(1), 1);
fx.tst_Matches(Criteria_.eq_("equal"), "equal");
fx.tst_Matches(Criteria_.eq_(date), date);
}
@Test public void Not() {
Criteria crt = Criteria_.eqn_(true);
fx.tst_Matches(crt, false);
fx.tst_MatchesNot(crt, true);
fx.tst_MatchesFail(crt, "false");
fx.tst_Matches(Criteria_.eqn_(1), -1);
fx.tst_Matches(Criteria_.eqn_("equal"), "not equal");
fx.tst_Matches(Criteria_.eqn_(date), date.Add_minute(1));
}
@Test public void MoreThan() {
Criteria crt = Criteria_.mt_(0);
fx.tst_Matches(crt, 1, 2);
fx.tst_MatchesNot(crt, 0, -1);
fx.tst_MatchesFail(crt, "1");
fx.tst_Matches(Criteria_.mt_(0), 1);
fx.tst_Matches(Criteria_.mt_("a"), "b");
fx.tst_Matches(Criteria_.mt_(date), date.Add_minute(1));
fx.tst_Matches(Criteria_.mt_(false), true); // MISC: thus truth is greater than falsehood
}
@Test public void MoreThanEq() {
Criteria crt = Criteria_.mte_(0);
fx.tst_Matches(crt, 0);
}
@Test public void Less() {
Criteria crt = Criteria_.lt_(0);
fx.tst_Matches(crt, -1, -2);
fx.tst_MatchesNot(crt, 0, 1);
fx.tst_MatchesFail(crt, "-1");
}
@Test public void LessEq() {
Criteria crt = Criteria_.lte_(0);
fx.tst_Matches(crt, 0);
}
@Test public void Between() {
Criteria crt = Criteria_.between_(-1, 1);
fx.tst_Matches(crt, 0, 1, -1);
fx.tst_MatchesNot(crt, -2, 2);
fx.tst_MatchesFail(crt, "0");
fx.tst_Matches(Criteria_.between_(1, -1), 0); // reverse range
fx.tst_Matches(Criteria_.between_("a", "c"), "b");
}
@Test public void In() {
Criteria crt = Criteria_.in_(0, 1, 2);
fx.tst_Matches(crt, 0, 1, 2);
fx.tst_MatchesNot(crt, 3, -1);
fx.tst_MatchesFail(crt, "0");
}
CriteriaFxt fx = new CriteriaFxt();
DateAdp date = DateAdp_.parse_gplx("2001-01-01");
}
class CriteriaFxt {
public void tst_Matches(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(true, crt.Matches(val));}
public void tst_MatchesNot(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(false, crt.Matches(val));}
public void tst_MatchesFail(Criteria crt, Object val) {
try {crt.Matches(val);}
catch(Exception exc) {Err_.Noop(exc); return;}
Tfds.Fail_expdError();
}
}

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.encoders; import gplx.*; import gplx.core.*;
import org.junit.*;
public class B85_fp__tst {
private final B85_fp__fxt fxt = new B85_fp__fxt();
@Test public void Double_to_str() {
fxt.Test__to_str(.1d, "/\"");
}
}
class B85_fp__fxt {
public void Test__to_str(double val, String expd) {
byte[] actl = B85_fp_.To_bry(val);
Tfds.Eq_str(expd, String_.new_a7(actl));
}
}

@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.encoders; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Base85__tst {
private final Base85__fxt fxt = new Base85__fxt();
@Test public void Log() {
fxt.Test_log( 0, 1);
fxt.Test_log( 84, 1);
fxt.Test_log( 85, 2);
fxt.Test_log( 7224, 2);
fxt.Test_log( 7225, 3);
fxt.Test_log( 614124, 3);
fxt.Test_log( 614125, 4);
fxt.Test_log( 52200624, 4);
fxt.Test_log( 52200625, 5);
fxt.Test_log(Int_.Max_value, 5);
}
@Test public void To_str() {
fxt.Test_to_str( 0, "!");
fxt.Test_to_str( 84, "u");
fxt.Test_to_str( 85, "\"!");
fxt.Test_to_str( 7224, "uu");
fxt.Test_to_str( 7225, "\"!!");
fxt.Test_to_str( 614124, "uuu");
fxt.Test_to_str( 614125, "\"!!!");
fxt.Test_to_str( 52200624, "uuuu");
fxt.Test_to_str( 52200625, "\"!!!!");
}
@Test public void XtoStrAry() {
byte[] ary = new byte[9];
fxt.Exec_to_str(ary, 0, 2); // !!#
fxt.Exec_to_str(ary, 3, 173); // !#$
fxt.Exec_to_str(ary, 6, 14709); // #$%
Tfds.Eq("!!#!#$#$%", String_.new_u8(ary));
}
}
class Base85__fxt {
public void Test_log(int val, int expd) {Tfds.Eq(expd, Base85_.Bry_len(val));}
public void Test_to_str(int val, String expd) {
String actl = Base85_.To_str(val, 0);
Tfds.Eq(expd, actl);
Tfds.Eq(val, Base85_.To_int_by_str(expd));
}
public void Exec_to_str(byte[] ary, int aryPos, int val) {Base85_.Set_bry(val, ary, aryPos, 3);}
}

@ -0,0 +1,89 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.encoders; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.tests.*;
public class Hex_utl__tst {
private final Hex_utl__fxt fxt = new Hex_utl__fxt();
@Test public void To_int() {
fxt.Test__to_int("0" , 0);
fxt.Test__to_int("F" , 15);
fxt.Test__to_int("0F" , 15);
fxt.Test__to_int("10" , 16);
fxt.Test__to_int("20" , 32);
fxt.Test__to_int("FF" , 255);
fxt.Test__to_int("100" , 256);
fxt.Test__to_int("0a" , 10);
fxt.Test__to_int("7FFFFFFF" , Int_.Max_value);
fxt.Test__to_int_bry("100" , 256);
}
@Test public void To_str() {
fxt.Test__to_str(0 , "0");
fxt.Test__to_str(15 , "F");
fxt.Test__to_str(16 , "10");
fxt.Test__to_str(32 , "20");
fxt.Test__to_str(255 , "FF");
fxt.Test__to_str(Int_.Max_value, "7FFFFFFF");
fxt.Test__to_str(15, 2 , "0F");
fxt.Test__to_str(15, 3 , "00F");
}
@Test public void Write() {
fxt.Test__write("[00000000]", 1, 9, 15, "[0000000F]");
fxt.Test__write("[00000000]", 1, 9, 255, "[000000FF]");
}
@Test public void Write_bfr() {
fxt.Test__write_bfr(Bool_.Y, 0, "0");
fxt.Test__write_bfr(Bool_.Y, 15, "f");
fxt.Test__write_bfr(Bool_.Y, 16, "10");
fxt.Test__write_bfr(Bool_.Y, 32, "20");
fxt.Test__write_bfr(Bool_.Y, 255, "ff");
fxt.Test__write_bfr(Bool_.Y, 256, "100");
fxt.Test__write_bfr(Bool_.Y, Int_.Max_value, "7fffffff");
}
@Test public void Encode() {
fxt.Test__parse_hex_to_bry("E2A7BC", 226, 167, 188);
}
}
class Hex_utl__fxt {
public void Test__write(String s, int bgn, int end, int val, String expd) {
byte[] bry = Bry_.new_a7(s);
Hex_utl_.Write(bry, bgn, end, val);
Tfds.Eq(expd, String_.new_a7(bry));
}
public void Test__to_int(String raw, int expd) {
int actl = Hex_utl_.Parse(raw);
Tfds.Eq(expd, actl);
}
public void Test__to_int_bry(String raw, int expd) {Tfds.Eq(expd, Hex_utl_.Parse_or(Bry_.new_a7(raw), -1));}
public void Test__to_str(int val, String expd) {Test__to_str(val, 0, expd);}
public void Test__to_str(int val, int pad, String expd) {
String actl = Hex_utl_.To_str(val, pad);
Tfds.Eq(expd, actl);
}
private final Bry_bfr bfr = Bry_bfr_.New();
public void Test__write_bfr(boolean lcase, int val, String expd) {
Hex_utl_.Write_bfr(bfr, lcase, val);
Gftest.Eq__str(expd, bfr.To_str_and_clear());
}
public void Test__encode_bry(String val, int... expd) {
byte[] actl = Hex_utl_.Encode_bry(Bry_.new_u8(val));
Gftest.Eq__ary(Byte_.Ary_by_ints(expd), actl, "encode");
}
public void Test__parse_hex_to_bry(String val, int... expd) {
byte[] actl = Hex_utl_.Parse_hex_to_bry(Bry_.new_u8(val));
Gftest.Eq__ary(Byte_.Ary_by_ints(expd), actl, "encode");
}
}

@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.envs; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Process_adp_tst {
private Process_adp_fxt fxt = new Process_adp_fxt();
@Test public void Escape_ampersands_if_process_is_cmd() {
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c^&d=e\"");
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd1", "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.N, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
}
}
class Process_adp_fxt {
public void Test_Escape_ampersands_if_process_is_cmd(boolean os_is_wnt, String exe_url, String exe_args, String expd) {
Tfds.Eq(expd, Process_adp.Escape_ampersands_if_process_is_cmd(os_is_wnt, exe_url, exe_args));
}
}

@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.gfo_regys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class GfoRegy_RegDir_tst {
@Before public void setup() {
regy = GfoRegy.new_();
Io_mgr.Instance.InitEngine_mem();
root = Io_url_.mem_dir_("mem/root");
} GfoRegy regy; Io_url root;
@Test public void Basic() {
ini_fil("101_tsta.txt");
ini_fil("102_tstb.txt");
ini_fil("103_tstc.png");
ini_fil("dir1", "104_tstd.txt");
regy.RegDir(root, "*.txt", false, "_", ".");
tst_Count(2);
tst_Exists("tsta");
tst_Exists("tstb");
}
@Test public void Err_dupe() {
ini_fil("101_tsta.txt");
ini_fil("102_tsta.txt");
try {regy.RegDir(root, "*.txt", false, "_", ".");}
catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_Dupe); return;}
Tfds.Fail_expdError();
}
@Test public void Err_chopBgn() {
ini_fil("123_");
try {regy.RegDir(root, "*", false, "_", ".");}
catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_ChopBgn); return;}
Tfds.Fail_expdError();
}
@Test public void Err_chopEnd() {
ini_fil(".txt");
try {regy.RegDir(root, "*.txt", false, "_", ".");}
catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_ChopEnd); return;}
Tfds.Fail_expdError();
}
void tst_Count(int expd) {Tfds.Eq(expd, regy.Count());}
void tst_Exists(String expd) {
GfoRegyItm itm = regy.FetchOrNull(expd);
Tfds.Eq_nullNot(itm);
}
void ini_fil(String... nest) {Io_mgr.Instance.SaveFilStr(root.GenSubFil_nest(nest), "");}
}

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.gfo_regys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class GfoRegy_basic_tst {
@Before public void setup() {
regy = GfoRegy.new_();
} GfoRegy regy;
@Test public void RegObjByType() {
regy.Parsers().Add("Io_url", Io_url_.Parser);
Io_url expd = Io_url_.new_any_("C:\\fil.txt");
regy.RegObjByType("test", expd.Xto_api(), "Io_url");
Io_url actl = (Io_url)regy.FetchValOr("test", Io_url_.Empty);
Tfds.Eq(expd.Xto_api(), actl.Xto_api());
}
}

@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.interfaces; import gplx.*; import gplx.core.*;
import org.junit.*;
public class SrlAble__tst {
@Test public void Basic() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1)
, "itm:key='a' val='1';"
);
}
@Test public void Depth1_1() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{itm:key='aa' val='11';}"
)
);
}
@Test public void Depth1_2() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11)
, GfoMsg_.new_cast_("itm").Add("key", "ab").Add("val", 12)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{"
, " itm:key='aa' val='11';"
, " itm:key='ab' val='12';"
, "}"
)
);
}
@Test public void Depth1_1_2() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11).Subs_(
GfoMsg_.new_cast_("itm").Add("key", "aab").Add("val", 112)
)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{itm:key='aa' val='11'{itm:key='aab' val='112';}}"
)
);
}
void tst_Srl_(GfoMsg m, String expd) {Tfds.Eq(expd, SrlAble_.To_str(m));}
}
//class SrlAble__tst

@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.intls; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.primitives.*;
public class Utf16__tst {
private Utf16__fxt fxt = new Utf16__fxt();
@Test public void Encode_decode() {
// fxt.Test_encode_decode(162, 194, 162); // cent
// fxt.Test_encode_decode(8364, 226, 130, 172); // euro
fxt.Test_encode_decode(150370, 240, 164, 173, 162); // example from [[UTF-8]]; should be encoded as two bytes
fxt.Test_encode_decode(143489, 240, 163, 130, 129); // EX: 駣𣂁脁 DATE:2017-04-22
}
@Test public void Encode_as_bry_by_hex() {
fxt.Test_Encode_hex_to_bry("00", 0);
fxt.Test_Encode_hex_to_bry("41", 65);
fxt.Test_Encode_hex_to_bry("0041", 65);
fxt.Test_Encode_hex_to_bry("00C0", 195, 128);
}
@Test public void Surrogate() {
fxt.Test_surrogate(0x64321, 0xD950, 0xDF21); // example from w:UTF-16
fxt.Test_surrogate(66643, 55297, 56403); // example from d:Boomerang
}
}
class Utf16__fxt {
private Int_obj_ref hi_ref = Int_obj_ref.New_neg1(), lo_ref = Int_obj_ref.New_neg1();
public void Test_encode_decode(int expd_c_int, int... expd_int) {
byte[] expd = Bry_.New_by_ints(expd_int);
byte[] bfr = new byte[10];
int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0);
byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len);
Tfds.Eq_ary(expd, actl);
int actl_c_int = Utf16_.Decode_to_int(bfr, 0);
Tfds.Eq(expd_c_int, actl_c_int);
}
public void Test_surrogate(int v, int hi, int lo) {
Tfds.Eq(v, Utf16_.Surrogate_merge((char)hi, (char)lo));
Utf16_.Surrogate_split(v, hi_ref, lo_ref);
Tfds.Eq(hi, hi_ref.Val());
Tfds.Eq(lo, lo_ref.Val());
}
public void Test_Encode_hex_to_bry(String raw, int... expd) {
byte[] actl = Utf16_.Encode_hex_to_bry(raw);
Tfds.Eq_ary(Byte_.Ary_by_ints(expd), actl);
}
}

@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.intls; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Utf8__tst {
private Utf8__fxt fxt = new Utf8__fxt();
@Test public void Get_prv_char_pos0() {
fxt.Test__Get_prv_char_pos0("abcd", 3); // len=1; (note that bry.len = 4)
fxt.Test__Get_prv_char_pos0("a", 0); // len=1; short-String
fxt.Test__Get_prv_char_pos0("abc¢", 3); // len=2; (note that bry.len = 5)
fxt.Test__Get_prv_char_pos0("abc€", 3); // len=3; (note that bry.len = 6)
fxt.Test__Get_prv_char_pos0("abc" + String_.new_u8(Byte_.Ary_by_ints(240, 164, 173, 162)), 3); // len=4; (note that bry.len = 7)
}
@Test public void Increment_char_at_last_pos() {
fxt.Test_Increment_char_at_last_pos("a", "b");
fxt.Test_Increment_char_at_last_pos("abc", "abd");
fxt.Test_Increment_char_at_last_pos("É", "Ê"); // len=2
fxt.Test_Increment_char_at_last_pos("€", "₭"); // len=3
}
// @Test public void Increment_char_at_last_pos_exhaustive_check() { // check all values; commented for perf
// Bry_bfr bfr = Bry_bfr_.New();
// int bgn = 32;
// while (true) {
// byte[] bgn_bry = Utf16_.Encode_int_to_bry(bgn);
// int end = Utf8_.Increment_char(bgn);
// if (end == Utf8_.Codepoint_max) break;
//// if (bgn > 1024 * 1024) break;
// byte[] end_by_codepoint_next = Utf16_.Encode_int_to_bry(end);
// byte[] end_by_increment_char = Utf8_.Increment_char_at_last_pos(bgn_bry);
// if (!Bry_.Eq(end_by_codepoint_next, end_by_increment_char)) {
// Tfds.Write(bgn);
// }
//// bfr .Add_int_variable(bgn).Add_byte(Byte_ascii.Tab)
//// .Add(bgn_bry).Add_byte(Byte_ascii.Tab)
//// .Add(end_by_codepoint_next).Add_byte(Byte_ascii.Tab)
//// .Add(end_by_increment_char).Add_byte(Byte_ascii.Tab)
//// .Add_byte_nl()
//// ;
// bgn = end;
// bgn_bry = end_by_codepoint_next;
// }
// Tfds.WriteText(bfr.To_str_and_clear());
// }
}
class Utf8__fxt {
public void Test__Get_prv_char_pos0(String src_str, int expd) {
byte[] src_bry = Bry_.new_u8(src_str);
Tfds.Eq(expd, Utf8_.Get_prv_char_pos0 (src_bry, src_bry.length));
Tfds.Eq(expd, Utf8_.Get_prv_char_pos0_old(src_bry, src_bry.length - 1));
}
public void Test_Increment_char_at_last_pos(String str, String expd) {
Tfds.Eq(expd, String_.new_u8(Utf8_.Increment_char_at_last_pos(Bry_.new_u8(str))));
}
}

@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
public class IoItm_fxt {
public IoItmFil fil_wnt_(String s) {return fil_(Io_url_.wnt_fil_(s));}
public IoItmFil fil_(Io_url url) {return IoItmFil_.new_(url, 1, DateAdp_.parse_gplx("2001-01-01"), DateAdp_.parse_gplx("2001-01-01"));}
public IoItmDir dir_wnt_(String s) {return dir_(Io_url_.wnt_dir_(s));}
public IoItmDir dir_(Io_url url, IoItm_base... ary) {
IoItmDir rv = IoItmDir_.top_(url);
for (IoItm_base itm : ary) {
if (itm.Type_dir())
rv.SubDirs().Add(itm);
else
rv.SubFils().Add(itm);
}
return rv;
}
public static IoItm_fxt new_() {return new IoItm_fxt();} IoItm_fxt() {}
}

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoZipWkr_tst {
@Test public void Basic() {
wkr = IoZipWkr.new_(Io_url_.Empty, "e \"{0}\" -o\"{1}\" -y");
tst_Expand_genCmdString(Io_url_.wnt_fil_("C:\\fil1.zip"), Io_url_.wnt_dir_("D:\\out\\"), "e \"C:\\fil1.zip\" -o\"D:\\out\" -y"); // NOTE: not "D:\out\" because .Xto_api
} IoZipWkr wkr;
void tst_Expand_genCmdString(Io_url srcUrl, Io_url trgUrl, String expd) {
Tfds.Eq(expd, wkr.Expand_genCmdString(srcUrl, trgUrl));
}
}

@ -0,0 +1,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.envs.*;
public class Io_download_fmt_tst {
Io_download_fmt_fxt fxt = new Io_download_fmt_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Fmt() {
fxt.Clear().Ini("downloading ~{src_name}: ~{prog_left} left (@ ~{prog_rate}); ~{prog_done} of ~{src_len} (~{prog_pct}%)", "http://a.org/b.png", Io_mgr.Len_kb * 10);
fxt.Now_add_f(1000).Prog_done_(1 * Io_mgr.Len_kb).Prog_pct_(1 * 1000).Prog_rate_(Io_mgr.Len_kb).Prog_left_(9 * 1000)
.Prog_msg_("downloading b.png: 09s left (@ 1.000 KBps); 1.000 KB of 10.000 KB (10.00%)")
.Download_(Io_mgr.Len_kb);
fxt.Now_add_f(1000).Prog_done_(2 * Io_mgr.Len_kb).Prog_pct_(2 * 1000).Prog_rate_(Io_mgr.Len_kb).Prog_left_(8 * 1000)
.Prog_msg_("downloading b.png: 08s left (@ 1.000 KBps); 2.000 KB of 10.000 KB (20.00%)")
.Download_(Io_mgr.Len_kb)
;
fxt.Now_add_f(2000).Prog_done_(3 * Io_mgr.Len_kb).Prog_pct_(3 * 1000).Prog_rate_(768).Prog_left_(9333)
.Prog_msg_("downloading b.png: 09s left (@ 768.000 Bps); 3.000 KB of 10.000 KB (30.00%)")
.Download_(Io_mgr.Len_kb)
;
}
@Test public void Tilde() {
fxt.Clear().Ini("a~b", "http://a.org/b.png", Io_mgr.Len_kb * 10);
}
}
class Io_download_fmt_fxt {
public Io_download_fmt_fxt Clear() {
if (fmt == null) {
fmt = new Io_download_fmt();
}
System_.Ticks__test_set(0);
prog_done = prog_rate = prog_pct = prog_left = -1;
prog_msg = null;
return this;
} Io_download_fmt fmt;
public Io_download_fmt_fxt Now_add_f(int v) {System_.Ticks__test_add(v); return this;}
public Io_download_fmt_fxt Prog_done_(int v) {prog_done = v; return this;} long prog_done = -1;
public Io_download_fmt_fxt Prog_pct_ (int v) {prog_pct = v; return this;} long prog_pct = -1;
public Io_download_fmt_fxt Prog_rate_(int v) {prog_rate = v; return this;} long prog_rate = -1;
public Io_download_fmt_fxt Prog_left_(int v) {prog_left = v; return this;} long prog_left = -1;
public Io_download_fmt_fxt Prog_msg_(String v) {
prog_msg = v; return this;
} String prog_msg;
public Io_download_fmt_fxt Download_(int v) {
fmt.Prog(v);
if (prog_done != -1) Tfds.Eq(prog_done, fmt.Prog_done(), "prog_done");
if (prog_pct != -1) Tfds.Eq(prog_pct , fmt.Prog_pct(), "prog_pct");
if (prog_rate != -1) Tfds.Eq(prog_rate, fmt.Prog_rate(), "prog_rate");
if (prog_left != -1) Tfds.Eq(prog_left, fmt.Prog_left(), "prog_left");
if (prog_msg != null) Tfds.Eq(prog_msg, fmt.Prog_msg(), "prog_msg");
return this;
}
public Io_download_fmt_fxt Ini(String prog_msg_hdr, String src_url, int src_len) {
fmt.Download_init(src_url, prog_msg_hdr);
fmt.Bgn(src_len);
return this;
}
}

@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Io_size__tst {
private Io_size__fxt fxt = new Io_size__fxt();
@Test public void XtoLong() {
fxt.Test_XtoLong("1", 1);
fxt.Test_XtoLong("1 KB", 1024);
fxt.Test_XtoLong("1 MB", 1024 * 1024);
fxt.Test_XtoLong("1 GB", 1024 * 1024 * 1024);
fxt.Test_XtoLong("12 kb", 12 * 1024);
fxt.Test_XtoLong("1.5 kb", 1024 + 512); // 1536
fxt.Test_XtoLong("1.5 mb", (long)(1024 * 1024 * 1.5));
fxt.Test_XtoLong("-1", -1); // NOTE: negative bytes allowed
fxt.Test_XtoLongFail("1 kilobite");
fxt.Test_XtoLongFail("1 BB");
// fxt.Test_XtoLongFail("1.1"); // DELETED:do not check for fractional bytes; EX: 10.7 GB DATE:2015-01-06
// fxt.Test_XtoLongFail("1.51 kb");
}
@Test public void To_str() {
fxt.Test_XtoStr(1, "1.000 B");
fxt.Test_XtoStr(1024, "1.000 KB");
fxt.Test_XtoStr(1536, "1.500 KB");
fxt.Test_XtoStr(1024 * 1024, "1.000 MB");
fxt.Test_XtoStr(1016, "1,016.000 B"); // NOTE: 1016 is not 1.016 KB
}
@Test public void Xto_str_full() {
fxt.Test_Xto_str( 500, 1, "#,###", " ", Bool_.Y, "1 KB");
fxt.Test_Xto_str( 1000, 1, "#,###", " ", Bool_.Y, "1 KB");
fxt.Test_Xto_str( 2000, 1, "#,###", " ", Bool_.Y, "2 KB");
fxt.Test_Xto_str( 1234567, 1, "#,###", " ", Bool_.Y, "1,206 KB");
fxt.Test_Xto_str(1234567890, 1, "#,###", " ", Bool_.Y, "1,205,633 KB");
}
@Test public void EqualsTest() {
fxt.Test_Equals("1", "1");
fxt.Test_Equals("1 kb", "1 kb");
fxt.Test_Equals("1024", "1 kb");
fxt.Test_Equals("1048576", "1 mb");
fxt.Test_Equals("1024 kb", "1 mb");
fxt.Test_Equals("1.5 kb", "1536 b");
}
@Test public void To_str_new___b___0() {fxt.Test__to_str_new( 0, 2, "0 B");}
@Test public void To_str_new___b___1() {fxt.Test__to_str_new( 1, 2, "1 B");}
@Test public void To_str_new__kb___1_501__1() {fxt.Test__to_str_new( 1538, 1, "1.5 KB");}
@Test public void To_str_new__kb___1_501__2() {fxt.Test__to_str_new( 1538, 2, "1.50 KB");}
@Test public void To_str_new__kb___1_501__3() {fxt.Test__to_str_new( 1538, 3, "1.501 KB");}
@Test public void To_str_new__kb___1_512__1() {fxt.Test__to_str_new( 1549, 1, "1.5 KB");}
@Test public void To_str_new__kb___1_512__2() {fxt.Test__to_str_new( 1549, 2, "1.51 KB");}
@Test public void To_str_new__kb___1_512__3() {fxt.Test__to_str_new( 1549, 3, "1.512 KB");}
@Test public void To_str_new__mb___1_512__1() {fxt.Test__to_str_new((1024 * 1024) + 536871, 1, "1.5 MB");}
@Test public void To_str_new__mb___1_512__2() {fxt.Test__to_str_new((1024 * 1024) + 536871, 2, "1.51 MB");}
@Test public void To_str_new__mb___1_512__3() {fxt.Test__to_str_new((1024 * 1024) + 536871, 3, "1.512 MB");}
@Test public void To_str_new__gb___1() {fxt.Test__to_str_new(1819264175, 2, "1.69 GB");}
}
class Io_size__fxt {
public void Test_XtoLong(String raw, long expd) {Tfds.Eq(expd, Io_size_.parse_or(raw, Long_.Min_value));}
public void Test_XtoLongFail(String raw) {
long val = Io_size_.parse_or(raw, Long_.Min_value);
if (val != Long_.Min_value) Tfds.Fail("expd parse failure; raw=" + raw);
}
public void Test_Equals(String lhs, String rhs) {Tfds.Eq(Io_size_.parse_or(lhs, Long_.Min_value), Io_size_.parse_or(rhs, Long_.Min_value));}
public void Test_XtoStr(long val, String expd) {Tfds.Eq(expd, Io_size_.To_str(val));}
public void Test_Xto_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1, String expd) {Tfds.Eq(expd, Io_size_.To_str(val, exp_1024, val_fmt, unit_pad, round_0_to_1));}
public void Test__to_str_new(long val, int decimal_places, String expd) {
Bry_bfr bfr = Bry_bfr_.New();
Tfds.Eq_str(expd, Io_size_.To_str_new(bfr, val, decimal_places));
}
}

@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
import org.junit.*; //using System.IO; /*Stream*/
public class IoStream_mem_tst {
@Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer
IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0);
byte[] data = Bry_.New_by_ints(1);
stream.Write(data, 0, Array_.Len(data));
Tfds.Eq(1L , stream.Len());
Tfds.Eq((byte)1 , stream.Buffer()[0]);
stream.Rls();
}
}

@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
import org.junit.*;
public class IoStream_mock_tst {
@Before public void init() {fxt.Clear();} IoStream_mock_fxt fxt = new IoStream_mock_fxt();
@Test public void Basic() {
fxt.Init_src_str_("abcde").Init_trg_len_(5).Init_rdr_limit_(2).Init_read_len_(2);
fxt.Test_read("ab").Test_read("cd").Test_read("e");
}
@Test public void Read_limit() {
fxt.Init_src_str_("abcde").Init_trg_len_(5).Init_rdr_limit_(2).Init_read_len_(4);
fxt.Test_read("ab").Test_read("cd").Test_read("e");
}
}
class IoStream_mock_fxt {
public void Clear() {
if (rdr == null)
rdr = new IoStream_mock();
rdr.Reset();
trg_bgn = 0;
} IoStream_mock rdr; byte[] trg_bry;
public IoStream_mock_fxt Init_src_str_(String v) {rdr.Data_bry_(Bry_.new_a7(v)); return this;}
public IoStream_mock_fxt Init_trg_len_(int v) {trg_bry = new byte[v]; return this;}
public IoStream_mock_fxt Init_read_len_(int v) {read_len = v; return this;} int read_len;
public IoStream_mock_fxt Init_rdr_limit_(int v) {rdr.Read_limit_(v); return this;}
public IoStream_mock_fxt Test_read(String expd) {
int bytes_read = rdr.Read(trg_bry, trg_bgn, read_len);
Tfds.Eq(expd, String_.new_a7(trg_bry, trg_bgn, trg_bgn + bytes_read));
trg_bgn += bytes_read;
return this;
} int trg_bgn;
}

@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
import org.junit.*;
public class Io_stream_rdr__tst {
@Before public void init() {fxt.Clear();} private Io_stream_rdr__fxt fxt = new Io_stream_rdr__fxt();
@After public void term() {fxt.Rls();}
@Test public void Bz2_read() {
fxt .Init_stream("abcd") // read everything at once
.Expd_bytes_read(4).Test_read(0, 4, "abcd");
fxt .Init_stream("abcd") // read in steps
.Expd_bytes_read(1).Test_read(0, 1, "a")
.Expd_bytes_read(2).Test_read(1, 2, "bc")
.Expd_bytes_read(1).Test_read(3, 1, "d")
;
}
}
class Io_stream_rdr__fxt {
private java.io.InputStream stream;
private int stream_bry_len;
public void Clear() {
expd_bytes_read = Int_.Min_value;
}
public Io_stream_rdr__fxt Expd_bytes_read(int v) {expd_bytes_read = v; return this;} private int expd_bytes_read = Int_.Min_value;
public Io_stream_rdr__fxt Init_stream(String v) {
byte[] stream_bry = Bry_.new_a7(v);
stream_bry_len = stream_bry.length;
stream = Io_stream_rdr_.New__mem_as_stream(stream_bry);
return this;
}
public Io_stream_rdr__fxt Test_read(int bgn, int len, String expd_str) {
byte[] bfr = new byte[stream_bry_len]; // allocate whole stream; may not use it all
int actl_bytes_read = Io_stream_rdr_.Read_by_parts(stream, 8, bfr, bgn, len);
Tfds.Eq(expd_bytes_read, actl_bytes_read, "bytes_read");
Tfds.Eq(expd_str, String_.new_u8(bfr, bgn, bgn + actl_bytes_read), "str");
return this;
}
public void Rls() {
Io_stream_rdr_.Close(stream);
}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
public class Io_zip_mgr_mok implements Io_zip_mgr {
public void Zip_fil(Io_url src_fil, Io_url trg_fil) {
byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil);
byte[] zip_bry = Zip_bry(src_bry, 0, src_bry.length);
Io_mgr.Instance.SaveFilBry(trg_fil, zip_bry);
}
public void Zip_dir(Io_url src_dir, Io_url trg_fil) {}
public byte[] Zip_bry(byte[] src, int bgn, int len) {return Bry_.Add(Bry_zipped, Bry_.Mid(src, bgn, len));}
public byte[] Unzip_bry(byte[] src, int bgn, int len) {
if (src == Bry_.Empty) return src;
byte[] section = Bry_.Mid(src, bgn, bgn + len);
if (!Bry_.Has_at_bgn(section, Bry_zipped, 0, section.length)) throw Err_.new_wo_type("src not zipped", "section", String_.new_u8(section));
return Bry_.Mid(section, Bry_zipped.length, section.length);
}
public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {}
private static final byte[] Bry_zipped = Bry_.new_a7("zipped:");
public static final Io_zip_mgr_mok Instance = new Io_zip_mgr_mok(); Io_zip_mgr_mok() {}
}

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
import org.junit.*;
public class Io_zip_mgr_tst {
@Test public void Zip_unzip() {
Zip_unzip_tst("abcdefghijklmnopqrstuvwxyz");
}
private void Zip_unzip_tst(String s) {
Io_zip_mgr zip_mgr = Io_zip_mgr_base.Instance;
byte[] src = Bry_.new_a7(s);
byte[] zip = zip_mgr.Zip_bry(src, 0, src.length);
byte[] unz = zip_mgr.Unzip_bry(zip, 0, zip.length);
Tfds.Eq_ary(src, unz);
}
}

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.js; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Js_wtr_tst {
@Before public void Init() {fxt.Clear();} private Js_wtr_fxt fxt = new Js_wtr_fxt();
@Test public void Basic() {
fxt.Test_write_val_html("abc" , "'abc'");
fxt.Test_write_val_html("a'b" , "'a\\'b'");
fxt.Test_write_val_html("a\"b" , "'a\\\"b'");
fxt.Test_write_val_html("a\nb" , "'a\\nb'");
fxt.Test_write_val_html("a\rb" , "'ab'");
fxt.Test_write_val_html("a\\&b" , "'a\\\\&b'"); // PURPOSE: backslashes need to be escaped; need for MathJax and "\&"; PAGE:Electromagnetic_field_tensor; DATE:2014-06-24
}
}
class Js_wtr_fxt {
private Js_wtr wtr = new Js_wtr();
public void Clear() {
wtr.Clear();
wtr.Quote_char_(Byte_ascii.Apos);
}
public void Test_write_val_html(String raw, String expd) {
wtr.Write_val(Bry_.new_u8(raw));
Tfds.Eq(expd, wtr.To_str_and_clear());
}
}

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.lists; import gplx.*; import gplx.core.*;
import org.junit.*;
public class List_adp_sorter_tst {
@Test public void Basic() {
Object[] src = new Object[] {0,8,1,7,2,6,3,5,4};
List_adp_sorter.new_().Sort(src, src.length);
Tfds.Eq_ary(src, Sequential(0, 8));
}
@Test public void Basic2() {
Object[] src = new Object[] {"0","8","1","7","2","6","3","5","4"};
List_adp_sorter.new_().Sort(src, src.length);
Tfds.Eq_ary(src, new Object[] {"0","1","2","3","4","5","6","7","8"});
}
Object[] Sequential(int bgn, int end) {
Object[] rv = new Object[end - bgn + 1];
for (int i = 0; i < Array_.Len(rv); i++)
rv[i] = i + bgn;
return rv;
}
}

@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.lists; import gplx.*; import gplx.core.*;
import org.junit.*;
public class StackAdp_tst {
@Test public void XtoList() {
tst_XtoList(1, 2, 3);
}
void tst_XtoList(int... ary) {
StackAdp stack = StackAdp_.new_();
for (int i : ary)
stack.Push(i);
List_adp list = stack.XtoList();
int[] actl = (int[])list.To_ary(int.class);
for (int i = 0; i < ary.length; i++)
Tfds.Eq(ary[i], actl[i]);
}
}

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.lists.rings; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
import org.junit.*; import gplx.core.tests.*;
public class Ring__long__tst {
private final Ring__long__fxt fxt = new Ring__long__fxt();
@Test public void Basic__1() {fxt.Clear().Add(1) .Test__to_ary(1);}
@Test public void Basic__2() {fxt.Clear().Add(1, 2) .Test__to_ary(1, 2);}
@Test public void Basic__3() {fxt.Clear().Add(1, 2, 3) .Test__to_ary(1, 2, 3);}
@Test public void Wrap__1() {fxt.Clear().Add(1, 2, 3, 4) .Test__to_ary(2, 3, 4);}
@Test public void Wrap__2() {fxt.Clear().Add(1, 2, 3, 4, 5) .Test__to_ary(3, 4, 5);}
@Test public void Wrap__3() {fxt.Clear().Add(1, 2, 3, 4, 5, 6) .Test__to_ary(4, 5, 6);}
}
class Ring__long__fxt {
private Ring__long ring = new Ring__long(3);
public Ring__long__fxt Clear() {ring.Clear(); return this;}
public Ring__long__fxt Add(long... ary) {
for (long itm : ary)
ring.Add(itm);
return this;
}
public Ring__long__fxt Test__to_ary(long... expd) {
Gftest.Eq__ary(expd, ring.To_ary(), "to_ary");
return this;
}
}

@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.lists.rings; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
import org.junit.*;
public class Ring__string__tst {
private final Ring__string__fxt fxt = new Ring__string__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Clear().Max_(3).Push_many("a") .Expd("a");
fxt.Clear().Max_(3).Push_many("a", "b") .Expd("a", "b");
fxt.Clear().Max_(3).Push_many("a", "b", "c") .Expd("a", "b", "c");
fxt.Clear().Max_(3).Push_many("a", "b", "c", "d") .Expd("b", "c", "d");
fxt.Clear().Max_(3).Push_many("a", "b", "c", "d", "e") .Expd("c", "d", "e");
fxt.Clear().Max_(3).Push_many("a", "b", "c", "d", "e", "f") .Expd("d", "e", "f");
}
}
class Ring__string__fxt {
Ring__string ring = new Ring__string();
public Ring__string__fxt Clear() {ring.Clear(); return this;}
public Ring__string__fxt Max_(int v) {ring.Max_(v); return this;}
public Ring__string__fxt Push_many(String... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++)
ring.Push(ary[i]);
return this;
}
public Ring__string__fxt Expd(String... expd) {
Tfds.Eq_ary_str(expd, ring.Xto_str_ary());
return this;
}
}

@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.log_msgs; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Gfo_msg_root_tst {
Gfo_msg_root_fxt fxt = new Gfo_msg_root_fxt();
@Before public void setup() {fxt.Reset();}
@Test public void Str() {
fxt.Clear().Expd_data_str_("failed a0 b0").Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0");
fxt.Clear().Expd_data_str_("failed a1 b1").Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a1", "b1");
}
// @Test public void Item() { // DISABLED: no longer registering items with owner;
// fxt.Clear().Expd_item_uid_(0).Expd_item_fmtr_arg_exists_(Bool_.Y).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0");
// fxt.Clear().Expd_item_uid_(1).Expd_item_fmtr_arg_exists_(Bool_.N).Tst_data_new_many("proj.cls.proc", "err_1", "failed");
// fxt.Clear().Expd_item_uid_(0).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0"); // make sure item_uid stays the same
// }
@Test public void Cache() {
fxt.Mgr().Data_ary_len_(2);
fxt.Clear().Expd_data_uid_(0).Tst_data_new_many("x", "err_0", "a");
fxt.Clear().Expd_data_uid_(1).Tst_data_new_many("x", "err_0", "b");
fxt.Clear().Expd_data_uid_(2).Tst_data_new_many("x", "err_0", "a");
fxt.Mgr().Data_ary_clear();
fxt.Clear().Expd_data_uid_(0).Tst_data_new_many("x", "err_0", "a");
}
}
class Gfo_msg_root_fxt {
Gfo_msg_root root = new Gfo_msg_root("tst");
public Gfo_msg_root_fxt Reset() {root.Reset(); this.Clear(); return this;}
public Gfo_msg_root_fxt Clear() {
expd_item_uid = -1;
expd_item_fmtr_arg_exists = Bool_.__byte;
expd_data_uid = -1;
expd_data_str = null;
return this;
}
public Gfo_msg_root Mgr() {return root;}
public Gfo_msg_root_fxt Expd_data_uid_(int v) {this.expd_data_uid = v; return this;} int expd_data_uid;
public Gfo_msg_root_fxt Expd_data_str_(String v) {this.expd_data_str = v; return this;} private String expd_data_str;
public Gfo_msg_root_fxt Expd_item_uid_(int v) {this.expd_item_uid = v; return this;} int expd_item_uid;
public Gfo_msg_root_fxt Expd_item_fmtr_arg_exists_(boolean v) {this.expd_item_fmtr_arg_exists = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_item_fmtr_arg_exists;
public void Tst_data_new_many(String path, String key, String fmt, Object... vals) {
Gfo_msg_data data = root.Data_new_many(Gfo_msg_itm_.Cmd_note, path, key, fmt, vals);
if (expd_item_uid != -1) Tfds.Eq(expd_item_uid, data.Item().Uid());;
if (expd_item_fmtr_arg_exists != Bool_.__byte) Tfds.Eq(Bool_.By_int(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist());
if (expd_data_str != null) Tfds.Eq(expd_data_str, data.Item().Gen_str_many(data.Vals()));
}
}

@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.primitives; import gplx.*; import gplx.core.*;
import org.junit.*;
public class EnmParser_tst {
@Before public void setup() {
parser = EnmMgr.new_();
}
@Test public void Basic() { // 1,2,4,8
parser.BitRngEnd_(8);
run_Reg(0, "zero");
run_Reg(1, "one");
run_Reg(2, "two");
run_Reg(4, "four");
run_Reg(8, "eight");
tst_Convert("zero", 0);
tst_Convert("one", 1);
tst_Convert("eight", 8);
tst_Convert("one+eight", 9);
}
@Test public void Keys() {
parser.BitRngBgn_(65536).BitRngEnd_(262144);
run_Reg( 65, "a");
run_Reg( 65536, "shift");
run_Reg(131072, "ctrl");
run_Reg(262144, "alt");
tst_Convert("a", 65);
tst_Convert("shift+a", 65 + 65536);
tst_Convert("ctrl+a", 65 + 131072);
tst_Convert("shift+ctrl+a", 65 + 65536 + 131072);
}
@Test public void Prefix() {
parser.Prefix_("key.").BitRngBgn_(128).BitRngEnd_(128);
run_Reg(65, "a");
tst_Convert("key.a", 65);
}
void run_Reg(int i, String s) {parser.RegObj(i, s, "NULL");}
void tst_Convert(String raw, int val) {
int actlVal = parser.GetVal(raw);
Tfds.Eq(val, actlVal);
Tfds.Eq(raw, parser.GetStr(val));
}
EnmMgr parser;
}

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5());
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
@Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");}
@Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");}
@Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
//@Test
public void Num__x_8() {fxt.Test__hash("57edf4a22be3c955ac49da2e2107b67a", String_.Repeat("1234567890", 8));}
//@Test
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
}
class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw)));
Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw)));
}
}

@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1());
@Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");}
@Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");}
@Test public void abc() {fxt.Test__hash("a9993e364706816aba3e25717850c26c9cd0d89d", "abc");}
@Test public void message_digest() {fxt.Test__hash("c12252ceda8be8994d5fa0290a47231c1d16aae3", "message digest");}
@Test public void a_z() {fxt.Test__hash("32d10c7b8cf96570ca04ce37f2a19d84240d3a89", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("84983e441c3bd26ebaae4aa1f95129e5e54670f1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("761c457bf73b14d27e9e9265c46f4b4dda11f940", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
// @Test
public void Num() {fxt.Test__hash("50abf5706a150990a08b2c5ea40fa0e585554732", String_.Repeat("1234567890", 8));}
//@Test
public void A_1Million() {fxt.Test__hash("34aa973cd4c4daa4f61eeb2bdbad27316534016f", String_.Repeat("a", 1000000));}
}

@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256());
@Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");}
@Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");}
@Test public void abc() {fxt.Test__hash("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");}
@Test public void message_digest() {fxt.Test__hash("f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650", "message digest");}
@Test public void a_z() {fxt.Test__hash("71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73", "abcdefghijklmnopqrstuvwxyz");}
@Test public void a_q__mixed() {fxt.Test__hash("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
// @Test
public void Num() {fxt.Test__hash("f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e", String_.Repeat("1234567890", 8));}
//@Test
public void A_1Million() {fxt.Test__hash("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0", String_.Repeat("a", 1000000));}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());
@Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");}
@Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");}
@Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");}
@Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");}
@Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");}
@Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");}
@Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");}
// @Test
public void a__x_1024() {fxt.Test__hash("L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA", String_.Repeat("A", 1024));}
// @Test
public void a__x_1025() {fxt.Test__hash("PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY", String_.Repeat("A", 1025));}
// @Test
public void A__Pow27() {fxt.Test__hash("QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ", String_.Repeat("A", (int)Math_.Pow(2, 27)));
}
}

@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Hash_algo__tth_192_tree_tst {
@Test public void CalcRecursiveHalves() {
tst_CalcRecursiveHalves(129, 128);
tst_CalcRecursiveHalves(128, 127);
tst_CalcRecursiveHalves(100, 99);
tst_CalcRecursiveHalves(20, 19);
tst_CalcRecursiveHalves(6, 5);
tst_CalcRecursiveHalves(5, 4);
tst_CalcRecursiveHalves(4, 3);
tst_CalcRecursiveHalves(3, 2);
tst_CalcRecursiveHalves(2, 1);
tst_CalcRecursiveHalves(1, 0);
tst_CalcRecursiveHalves(0, 0);
}
@Test public void CalcWorkUnits() {
tst_CalcWorkUnits(101, 21); // leafs; 10 full, 1 part (+11) -> reduce 11 to 5+1 (+5) -> reduce 6 to 3 (+3) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1)
tst_CalcWorkUnits(100, 19); // leafs; 10 full (+10) -> reduce 10 to 5 (+5) -> reduce 5 to 2+1 (+2) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1)
tst_CalcWorkUnits(30, 5); // leafs; 3 full (+3) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1)
tst_CalcWorkUnits(11, 3); // leafs: 1 full, 1 part (+2) -> reduce 2 to 1 (+1)
tst_CalcWorkUnits(10, 1);
tst_CalcWorkUnits(9, 1);
tst_CalcWorkUnits(1, 1);
tst_CalcWorkUnits(0, 1);
}
void tst_CalcWorkUnits(int length, int expd) {
Hash_algo__tth_192 algo = new Hash_algo__tth_192(); algo.BlockSize_set(10);
int actl = algo.CalcWorkUnits(length);
Tfds.Eq(expd, actl);
}
void tst_CalcRecursiveHalves(int val, int expd) {
int actl = CalcRecursiveHalvesMock(val);
Tfds.Eq(expd, actl);
}
int CalcRecursiveHalvesMock(int val) {
if (val <= 1) return 0;
int rv = 0;
while (true) {
int multiple = val / 2;
int remainder = val % 2;
rv += multiple;
val = multiple + remainder;
if (val == 1)
return remainder == 0 ? rv : ++rv;
}
}
}

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
public class Hash_console_wtr_tst {
@Before public void setup() {
Hash_algo__tth_192 algo = new Hash_algo__tth_192();
algo.BlockSize_set(10);
calc = algo;
}
@Test public void Basic() {
tst_Status(10, stringAry_(" - hash: 100%"));
tst_Status(11, stringAry_(" - hash: 66%"));
tst_Status(30, stringAry_(" - hash: 40%", " - hash: 60%", " - hash: 100%"));
}
void tst_Status(int count, String[] expdWritten) {
Console_adp__mem dialog = Console_adp_.Dev();
String data = String_.Repeat("A", count);
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data);
calc.Hash_stream_as_str(dialog, stream);
String[] actlWritten = dialog.Written().To_str_ary();
Tfds.Eq_ary(actlWritten, expdWritten);
}
String[] stringAry_(String... ary) {return ary;}
Hash_algo calc;
}

@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*; import gplx.core.envs.*;
public class PerfLogMgr_fxt {
public void Init(Io_url url, String text) {
this.url = url;
entries.Resize_bounds(1000);
entries.Add(new PerfLogItm(0, text + "|" + Datetime_now.Get().XtoStr_gplx()));
tmr.Bgn();
}
public void Write(String text) {
long milliseconds = tmr.ElapsedMilliseconds();
entries.Add(new PerfLogItm(milliseconds, text));
tmr.Bgn();
}
public void WriteFormat(String fmt, Object... ary) {
long milliseconds = tmr.ElapsedMilliseconds();
String text = String_.Format(fmt, ary);
entries.Add(new PerfLogItm(milliseconds, text));
tmr.Bgn();
}
public void Flush() {
String_bldr sb = String_bldr_.new_();
for (Object itmObj : entries) {
PerfLogItm itm = (PerfLogItm)itmObj;
sb.Add(itm.To_str()).Add_char_crlf();
}
Io_mgr.Instance.AppendFilStr(url, sb.To_str());
entries.Clear();
}
List_adp entries = List_adp_.New(); PerfLogTmr tmr = PerfLogTmr.new_(); Io_url url = Io_url_.Empty;
public static final PerfLogMgr_fxt Instance = new PerfLogMgr_fxt(); PerfLogMgr_fxt() {}
class PerfLogItm {
public String To_str() {
String secondsStr = Time_span_.To_str(milliseconds, Time_span_.Fmt_Default);
secondsStr = String_.PadBgn(secondsStr, 7, "0"); // 7=000.000; left-aligns all times
return String_.Concat(secondsStr, "|", text);
}
long milliseconds; String text;
@gplx.Internal protected PerfLogItm(long milliseconds, String text) {
this.milliseconds = milliseconds; this.text = text;
}
}
}
class PerfLogTmr {
public void Bgn() {bgn = System_.Ticks();} long bgn;
public long ElapsedMilliseconds() {return System_.Ticks() - bgn; }
public static PerfLogTmr new_() {return new PerfLogTmr();} PerfLogTmr() {}
}

@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*;
public class BaseXXConverter_tst {
@Test public void Base32() {
tst_Base32("", "");
tst_Base32("f", "MY");
tst_Base32("fo", "MZXQ");
tst_Base32("foo", "MZXW6");
tst_Base32("foob", "MZXW6YQ");
tst_Base32("fooba", "MZXW6YTB");
tst_Base32("foobar", "MZXW6YTBOI");
tst_Base32("A", "IE");
tst_Base32("a", "ME");
tst_Base32("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLIZDGNBVGY3Q");
}
@Test public void Base64() {
tst_Base64("", "");
tst_Base64("f", "Zg==");
tst_Base64("fo", "Zm8=");
tst_Base64("foo", "Zm9v");
tst_Base64("foob", "Zm9vYg==");
tst_Base64("fooba", "Zm9vYmE=");
tst_Base64("foobar", "Zm9vYmFy");
// tst_Base64("A", "IE");
// tst_Base64("a", "ME");
// tst_Base64("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLIZDGNBVGY3Q");
}
void tst_Base32(String orig, String expd) {
String actl = Base32Converter.EncodeString(orig);
Tfds.Eq(expd, actl);
String decode = Base32Converter.DecodeString(actl);
Tfds.Eq(orig, decode);
}
void tst_Base64(String orig, String expd) {
String actl = Base64Converter.EncodeString(orig);
Tfds.Eq(expd, actl);
String decode = Base64Converter.DecodeString(actl);
Tfds.Eq(orig, decode);
}
}
//http://tools.ietf.org/html/rfc4648: test vectors for "foobar"

@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*;
public class CharStream_tst {
@Before public void setup() {
stream = CharStream.pos0_("abcdefgh");
}
@Test public void To_str() {
Tfds.Eq(stream.To_str(), "abcdefgh");
}
@Test public void CurrentText() {
stream.MoveNextBy(1);
Tfds.Eq(stream.XtoStrAtCur(2), "bc");
Tfds.Eq(stream.To_str(), "abcdefgh");
}
@Test public void CurrentText_outOfBounds() {
stream.MoveNextBy(7);
Tfds.Eq(stream.XtoStrAtCur(2), "h");
}
@Test public void Match() {
stream.MoveNextBy(6);
tst_Match(true, "g");
tst_Match(false, "z");
tst_Match(true, "gh");
tst_Match(false, "gz");
tst_Match(false, "ghi");
}
@Test public void AtBounds() {
stream.Move_to(-1);
tst_AtBounds(true, false, false);
stream.Move_to(0);
tst_AtBounds(false, true, false);
stream.Move_to(stream.Len());
tst_AtBounds(false, false, true);
}
void tst_Match(boolean expd, String text) {Tfds.Eq(expd, stream.Match(text));}
void tst_AtBounds(boolean atBgn, boolean atMid, boolean atEnd) {
Tfds.Eq(atBgn, stream.AtBgn());
Tfds.Eq(atMid, stream.AtMid());
Tfds.Eq(atEnd, stream.AtEnd());
}
CharStream stream;
}

@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*;
public class RegxPatn_cls_ioMatch_tst {
@Test public void SimpleMatches() {
tst_Matches("file.cs", "file.cs", true); // basic
tst_Matches("file.cs", "file.cs.exe", false); // fail: must match name precisely
tst_Matches("file.cs", "tst_file.cs", false); // fail: must match name precisely
}
@Test public void Wildcard() {
tst_Matches("*.cs", "file.cs", true); // pass: before
tst_Matches("file*", "file_valid.cs", true); // pass: after
tst_Matches("*.exe", "file.cs", false); // fail: before
tst_Matches("file*", "invalid_file.cs", false); // fail: after
}
@Test public void DoubleWildcard() {
tst_Matches("*cs*", "file.cs", true); // pass: after
tst_Matches("*cs*", "csFile.exe", true); // pass: before
tst_Matches("*cs*", "file.cs.exe", true); // pass: middle
tst_Matches("*cs*", "file.exe", false); // fail
}
@Test public void Compound() {
tst_Matches("*.cs|*.exe", "file.cs", true); // pass: match first
tst_Matches("*.cs|*.exe", "file.exe", true); // pass: match second
tst_Matches("*.cs|*.exe", "file.dll", false); // fail: match neither
tst_Matches("*.cs|*.exe", "file.cs.exe.dll", false); // fail: match neither (though both are embedded)
}
@Test public void Backslash() {
tst_Matches("*\\bin\\*", "C:\\project\\bin\\", true); // pass: dir
tst_Matches("*\\bin\\*", "C:\\project\\bin\\file.dll", true); // pass: fil
tst_Matches("*\\bin\\*", "C:\\project\\binFiles\\", false); // fail
}
@Test public void MixedCase() {
tst_Matches("file.cs", "file.cs", true); // pass: same case
tst_Matches("file.cs", "File.cS", true); // pass: diff case
}
void tst_Matches(String regx, String raw, boolean expd) {
RegxPatn_cls_ioMatch pattern = RegxPatn_cls_ioMatch_.parse(regx, false);
boolean actl = pattern.Matches(raw);
Tfds.Eq(expd, actl);
}
}

@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.langs.regxs.*;
public class RegxPatn_cls_like_tst {
@Test public void Basic() {
tst_Match("abcd", "abcd", true); // basic; pass
tst_Match("abcd", "zbcd", false); // basic; fail
tst_Match("abcd", "abc", false); // no wildcard; must be exact match
tst_Match("a cd", "a cd", true); // check space works
}
@Test public void Wildcard() {
tst_Match("abcd", "a%", true); // bgn; pass
tst_Match("abcd", "b%", false); // bgn; fail
tst_Match("abcd", "%d", true); // end; pass
tst_Match("abcd", "%c", false); // end; fail
tst_Match("abcd", "%b%", true); // flank; pass
tst_Match("abcd", "%e%", false); // flank; fail
tst_Match("abcd", "%a%", true); // flank; bgn; pass
tst_Match("abcd", "%d%", true); // flank; end; pass
}
@Test public void Any() {
tst_Match("abcd", "a_cd", true); // basic; pass
tst_Match("abcd", "z_cd", false); // basic; fail
tst_Match("abcd", "a_c", false); // fail; check no wildcard
}
@Test public void CharSet() {
tst_Match("abcd", "a[b]cd", true); // pass
tst_Match("abcd", "a[x]cd", false); // fail
tst_Match("abcd", "a[bcde]cd", true); // multiple; pass
tst_Match("abcd", "a[xyz]cd", false); // multiple; fail
tst_Match("abcd", "a[^z]cd", true); // not; pass
tst_Match("abcd", "a[^b]cd", false); // not; fail
}
@Test public void Escape() {
tst_Match("a%b", "a|%b", true); // escape wildcard; pass
tst_Match("a%bc", "a|%b", false); // escape wildcard; fail
tst_Match("a|b", "a|b", false); // escape char; fail
tst_Match("a|b", "a||b", true); // escape char; pass
}
@Test public void Escape_diffChar() {
tst_Match("a%b", "a~%b", '~', true); // escape wildcard; pass
tst_Match("a%bc", "a~%b", '~', false); // escape wildcard; fail
tst_Match("a|b", "a|b", '~', true); // no escape needed
tst_Match("a~b", "a~b", '~', false); // escape char; fail
tst_Match("a~b", "a~~b", '~', true); // escape char; pass
}
@Test public void Chars() { // Escape Regx_bldr; ex: LIKE 'a{' -> a\{
tst_EscapeRegxChar(Regx_bldr.Tkn_Escape); // \
tst_EscapeRegxChar(Regx_bldr.Tkn_GroupBegin); // [
tst_EscapeRegxChar(Regx_bldr.Tkn_GroupEnd); // ]
tst_EscapeRegxChar(Regx_bldr.Tkn_LineBegin); // ^
tst_EscapeRegxChar(Regx_bldr.Tkn_LineEnd); // $
tst_EscapeRegxChar(Regx_bldr.Tkn_RepBegin); // {
tst_EscapeRegxChar(Regx_bldr.Tkn_RepEnd); // }
tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_0or1); // ?
tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_0Plus); // *
tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_1Plus); // +
}
void tst_Match(String raw, String regx, boolean expd) {tst_Match(raw, regx, RegxPatn_cls_like.EscapeDefault, expd);}
void tst_Match(String raw, String regx, char escape, boolean expd) {
RegxPatn_cls_like like = RegxPatn_cls_like_.parse(regx, escape);
boolean actl = like.Matches(raw);
Tfds.Eq(expd, actl, "raw={0} regx={1} expd={2}", raw, regx, expd);
}
void tst_EscapeRegxChar(char regexChar) {
RegxPatn_cls_like like = RegxPatn_cls_like_.parse(Object_.Xto_str_strict_or_empty(regexChar), '|');
Tfds.Eq(true, like.Matches(Object_.Xto_str_strict_or_empty(regexChar)));
Tfds.Eq(false, like.Matches("a")); // catches errors for improper escaping of wildcard
}
}

@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.texts; import gplx.*; import gplx.core.*;
import org.junit.*;
public class StringTableBldr_tst {
@Before public void setup() {
bldr = StringTableBldr.new_();
} StringTableBldr bldr;
@Test public void TwoCols() {
bldr.Add("a", "aa")
.Add("bb", "b");
tst_XtoStr
( "a aa"
, "bb b "
, ""
);
}
@Test public void RightAlign() {
bldr.Add("a", "aa")
.Add("bb", "b");
bldr.FetchAtOrNew(0).Halign_(StringTableColAlign.Right);
bldr.FetchAtOrNew(1).Halign_(StringTableColAlign.Right);
tst_XtoStr
( " a aa"
, "bb b"
, ""
);
}
@Test public void CenterAlign() {
bldr.Add("aaaa", "a")
.Add("b", "bbbb");
bldr.FetchAtOrNew(0).Halign_(StringTableColAlign.Mid);
bldr.FetchAtOrNew(1).Halign_(StringTableColAlign.Mid);
tst_XtoStr
( "aaaa a "
, " b bbbb"
, ""
);
}
void tst_XtoStr(String... expdLines) {
String expd = String_.Concat_with_obj(String_.CrLf, (Object[])expdLines);
Tfds.Eq(expd, bldr.To_str());
}
}

@ -0,0 +1,81 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.threads.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
import org.junit.*;
public class Gfo_poolable_mgr_tst {
private final Gfo_poolable_mgr_tstr tstr = new Gfo_poolable_mgr_tstr();
@Before public void init() {tstr.Clear();}
@Test public void Get__one() {
tstr.Test__get(0);
tstr.Test__free__len(0);
tstr.Test__pool__len(2);
}
@Test public void Get__many__expand() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Test__free__len(0);
tstr.Test__pool__len(4);
}
@Test public void Rls__lifo() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Exec__rls(2);
tstr.Exec__rls(1);
tstr.Exec__rls(0);
tstr.Test__pool__nxt(0);
tstr.Test__free__len(0);
}
@Test public void Rls__fifo() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Exec__rls(0);
tstr.Exec__rls(1);
tstr.Test__pool__nxt(3);
tstr.Test__free__len(2); // 2 items in free_ary
tstr.Test__free__ary(0, 1, 0, 0);
tstr.Test__get(1);
tstr.Exec__rls(1);
tstr.Exec__rls(2);
tstr.Test__free__len(0); // 0 items in free_ary
tstr.Test__free__ary(0, 0, 0, 0);
}
}
class Gfo_poolable_mgr_tstr {
private final Gfo_poolable_mgr mgr = new Gfo_poolable_mgr(new Sample_poolable_itm(null, -1, Object_.Ary_empty), Object_.Ary("make"), 2, 8);
public void Clear() {mgr.Clear_fast();}
public void Test__get(int expd_idx) {
Sample_poolable_itm actl_itm = (Sample_poolable_itm)mgr.Get_fast();
Tfds.Eq(expd_idx, actl_itm.Pool__idx(), "pool_idx");
}
public void Test__free__ary(int... expd) {Tfds.Eq_ary(expd, mgr.Free_ary(), "mgr.Free_ary()");}
public void Test__free__len(int expd) {Tfds.Eq(expd, mgr.Free_len(), "mgr.Free_len()");}
public void Test__pool__len(int expd) {Tfds.Eq(expd, mgr.Pool_len(), "mgr.Pool_len()");}
public void Test__pool__nxt(int expd) {Tfds.Eq(expd, mgr.Pool_nxt(), "mgr.Pool_nxt()");}
public void Exec__rls(int idx) {mgr.Rls_fast(idx);}
}
class Sample_poolable_itm implements Gfo_poolable_itm {
private Gfo_poolable_mgr pool_mgr;
public Sample_poolable_itm(Gfo_poolable_mgr pool_mgr, int pool_idx, Object[] make_args) {this.pool_mgr = pool_mgr; this.pool_idx = pool_idx; this.pool__make_args = make_args;}
public int Pool__idx() {return pool_idx;} private final int pool_idx;
public Object[] Pool__make_args() {return pool__make_args;} private final Object[] pool__make_args;
public void Pool__rls() {pool_mgr.Rls_safe(pool_idx);}
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {return new Sample_poolable_itm(pool_mgr, idx, args);}
}

@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class DateAdp_parser_tst {
@Before public void init() {} DateAdp_parser_fxt fxt = new DateAdp_parser_fxt();
@Test public void Parse_gplx() {
fxt.Test_Parse_iso8651_like("2000-01-02T03:04:05.006-05:00" , 2000, 1, 2, 3, 4, 5, 6);
fxt.Test_Parse_iso8651_like("2000-01-02" , 2000, 1, 2, 0, 0, 0, 0);
}
}
class DateAdp_parser_fxt {
DateAdp_parser parser = DateAdp_parser.new_(); int[] actl = new int[7];
public void Test_Parse_iso8651_like(String s, int... expd) {
byte[] bry = Bry_.new_a7(s);
parser.Parse_iso8651_like(actl, bry, 0, bry.length);
Tfds.Eq_ary(expd, actl, s);
}
}

@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Time_span__basic_tst {
@Test public void seconds_() {
Time_span expd = Time_span_.fracs_(123987);
Time_span actl = Time_span_.seconds_(123.987);
Tfds.Eq(expd, actl);
}
@Test public void TotalSecs() {
Time_span val = Time_span_.fracs_(1987);
Tfds.Eq_decimal(Decimal_adp_.parts_(1, 987), val.Total_secs());
}
@Test public void Units() {
tst_Units("01:02:03.987", 1, 2, 3, 987);
tst_Units("01:00:03", 1, 0, 3, 0);
tst_Units("01:00:00.987", 1, 0, 0, 987);
tst_Units("02:00.987", 0, 2, 0, 987);
}
@Test public void Add() {
Time_span val = Time_span_.fracs_(3);
Time_span arg = Time_span_.fracs_(2);
Time_span expd = Time_span_.fracs_(5);
Time_span actl = val.Add(arg);
Tfds.Eq(expd, actl);
}
@Test public void Subtract() {
Time_span val = Time_span_.fracs_(3);
Time_span arg = Time_span_.fracs_(2);
Time_span expd = Time_span_.fracs_(1);
Time_span actl = val.Subtract(arg);
Tfds.Eq(expd, actl);
}
@Test public void Add_unit_identity() {
tst_AddUnit("00:00:01.000", 0, 0, "00:00:01.000");
}
@Test public void Add_unit_basic() {
tst_AddUnit("01:59:58.987", 0, 1013, "02:00:00.000");
tst_AddUnit("01:59:58.987", 1, 2, "02:00:00.987");
tst_AddUnit("01:59:58.987", 2, 1, "02:00:58.987");
tst_AddUnit("01:59:58.987", 3, 1, "02:59:58.987");
}
@Test public void Add_unit_negative() {
tst_AddUnit("01:00:00.00", 0, -1, "00:59:59.999");
tst_AddUnit("01:00:00.00", 1, -1, "00:59:59.000");
tst_AddUnit("01:00:00.00", 2, -1, "00:59:00.000");
tst_AddUnit("01:00:00.00", 3, -1, "00:00:00.000");
}
@Test public void XtoStrUiAbbrv() {
tst_XtoStrUiAbbrv("01:02:03.004", "1h 2m 3s 4f");
tst_XtoStrUiAbbrv("00:00:03.004", "3s 4f");
tst_XtoStrUiAbbrv("00:00:03.000", "3s 0f");
tst_XtoStrUiAbbrv("11:22:33.444", "11h 22m 33s 444f");
tst_XtoStrUiAbbrv("00:00:00.000", "0f");
} void tst_XtoStrUiAbbrv(String raw, String expd) {Tfds.Eq(expd, Time_span_.parse(raw).XtoStrUiAbbrv());}
void tst_AddUnit(String valRaw, int unitIdx, int delta, String expdRaw) {
Time_span val = Time_span_.parse(valRaw);
Time_span actl = val.Add_unit(unitIdx, delta);
Tfds.Eq(Time_span_.parse(expdRaw), actl);
}
void tst_Units(String text, int... expd) {
Time_span val = Time_span_.parse(text);
int hour = 0, min = 0, sec = 0, frac = 0;
int[] ary = val.Units();
hour = ary[Time_span_.Idx_Hour]; min = ary[Time_span_.Idx_Min]; sec = ary[Time_span_.Idx_Sec]; frac = ary[Time_span_.Idx_Frac];
Tfds.Eq(expd[0], hour);
Tfds.Eq(expd[1], min);
Tfds.Eq(expd[2], sec);
Tfds.Eq(expd[3], frac);
}
}

@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Time_span__parse_tst {
@Test public void Zero() {
tst_Parse("0", 0);
}
@Test public void Milliseconds() {
tst_Parse("0.987", 987);
tst_Parse("0.00199", 1); // do not parse as 199
tst_Parse("0.1", 100); // do not parse as 1
}
@Test public void Seconds() {
tst_Parse("1.987", 1987);
}
@Test public void Minutes() {
tst_Parse("1:02.987", 62987);
}
@Test public void MinuteSecondOnly() {
tst_Parse("1:02", 62000);
}
@Test public void Hour() {
tst_Parse("1:02:03.987", 3723987);
}
@Test public void Negative() {
tst_Parse("-1:02:03.987", -3723987);
}
@Test public void Loopholes() {
tst_Parse("001:02", 62000); // multiple leading zeroes
tst_Parse("1.2.3.4", 1200); // ignore all decimals except first
tst_Parse("60:60.9999", 3660999); // value does not need to be bounded to limits (except fracs, which is always < 1000)
tst_Parse(" 01 : 02 : 03 . 987", 3723987); // whitespace
}
void tst_Parse(String text, long expd) {
Time_span val = Time_span_.parse(text);
Tfds.Eq(expd, val.Fracs());
}
}

@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Time_span__to_str_tst {
@Test public void Zero() {
tst_Default(0, "0");
}
@Test public void MinuteSeconds() {
tst_Default(77000, "1:17");
}
@Test public void ZeroSuppression() {
tst_Default(660000, "11:00"); //fractional 0 and leading 0s are suppressed; i.e.: not 00:11:00.000
}
@Test public void HourTest() {
tst_Default(3723987, "1:02:03.987");
}
@Test public void NegSeconds() {
tst_Default(-2000, "-2");
}
@Test public void NegMins() {
tst_Default(-60000, "-1:00");
}
@Test public void NegHours() {
tst_Default(-3723981, "-1:02:03.981");
}
@Test public void ZeroPadding() {
tst_ZeroPadding("0", "00:00:00.000");
tst_ZeroPadding("1:02:03.123", "01:02:03.123");
tst_ZeroPadding("1", "00:00:01.000");
tst_ZeroPadding(".987", "00:00:00.987");
tst_ZeroPadding("2:01.456", "00:02:01.456");
}
void tst_Default(long fractionals, String expd) {
Time_span ts = Time_span_.fracs_(fractionals);
String actl = ts.To_str(Time_span_.Fmt_Default);
Tfds.Eq(expd, actl);
}
void tst_ZeroPadding(String val, String expd) {
Time_span timeSpan = Time_span_.parse(val);
String actl = timeSpan.To_str(Time_span_.Fmt_PadZeros);
Tfds.Eq(expd, actl);
}
}

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.type_xtns; import gplx.*; import gplx.core.*;
import org.junit.*;
public class DateAdpClassXtn_tst {
@Test public void XtoDb() {
tst_XtoDb("20091115 220102.999", "2009-11-15 22:01:02.999");
}
void tst_XtoDb(String val, String expdRaw) {
String actlRaw = (String)DateAdpClassXtn.Instance.XtoDb(DateAdp_.parse_gplx(val));
Tfds.Eq(expdRaw, actlRaw);
}
}

@ -0,0 +1,214 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.strings.*; import gplx.core.gfo_ndes.*;
public class DsvDataRdr_csv_dat_tst {
@Before public void setup() {
fx.Parser_(DsvParser.csv_(false, GfoFldList_.Null));
fx.Clear();
} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
@Test public void Empty() {
fx.run_parse_("");
fx.tst_DatNull();
}
@Test public void Fld_0() {
fx.run_parse_("a");
fx.tst_DatCsv(fx.ary_("a"));
}
@Test public void Fld_N() {
fx.run_parse_("a,b,c");
fx.tst_FldListCsv("fld0", "fld1", "fld2");
fx.tst_DatCsv(fx.ary_("a", "b", "c"));
}
@Test public void Row_N() {
fx.run_parse_
( "a,b,c", String_.CrLf
, "1,2,3"
);
fx.tst_DatCsv
( fx.ary_("a", "b", "c")
, fx.ary_("1", "2", "3")
);
}
@Test public void Escape_WhiteSpace() {
fx.run_parse_("a,\" \t\",c");
fx.tst_DatCsv(fx.ary_("a", " \t", "c"));
}
@Test public void Escape_FldSep() {
fx.run_parse_("a,\",\",c");
fx.tst_DatCsv(fx.ary_("a", ",", "c"));
}
@Test public void Escape_RowSep() {
fx.run_parse_("a,\"" + String_.CrLf + "\",c");
fx.tst_DatCsv(fx.ary_("a", String_.CrLf, "c"));
}
@Test public void Escape_Quote() {
fx.run_parse_("a,\"\"\"\",c");
fx.tst_DatCsv(fx.ary_("a", "\"", "c"));
}
@Test public void Blank_Null() {
fx.run_parse_("a,,c");
fx.tst_DatCsv(fx.ary_("a", null, "c"));
}
@Test public void Blank_EmptyString() {
fx.run_parse_("a,\"\",c");
fx.tst_DatCsv(fx.ary_("a", "", "c"));
}
@Test public void Blank_Null_Multiple() {
fx.run_parse_(",,");
fx.tst_DatCsv(fx.ary_(null, null, null));
}
@Test public void TrailingNull() {
fx.run_parse_("a,");
fx.tst_DatCsv(fx.ary_("a", null));
}
@Test public void TrailingEmpty() {
fx.run_parse_("a,\"\"");
fx.tst_DatCsv(fx.ary_("a", ""));
}
@Test public void Quote_Error() {
try {
fx.run_parse_("a,\"\" ,c");
Tfds.Fail_expdError();
}
catch (Err e) {
Tfds.Eq_true(String_.Has(Err_.Message_lang(e), "invalid quote in quoted field"));
}
}
@Test public void Misc_AllowValsLessThanFields() {
// assume null when vals.Count < fields.Count; PURPOSE: MsExcel will not save trailing commas for csvExport; ex: a, -> a
fx.run_parse_
( "a0,a1", String_.CrLf
, "b0"
);
fx.tst_DatCsv
( fx.ary_("a0", "a1")
, fx.ary_("b0", null)
);
}
@Test public void Misc_NewLineValidForSingleColumnTables() {
fx.run_parse_
( "a", String_.CrLf
, String_.CrLf
, "c" , String_.CrLf
, String_.CrLf
);
fx.tst_DatCsv
( fx.ary_("a")
, fx.ary_null_()
, fx.ary_("c")
, fx.ary_null_()
);
}
@Test public void Misc_NewLineValidForSingleColumnTables_FirstLine() {
fx.run_parse_
( String_.CrLf
, "b", String_.CrLf
, "c"
);
fx.tst_DatCsv
( fx.ary_null_()
, fx.ary_("b")
, fx.ary_("c")
);
}
@Test public void Hdr_Basic() {
fx.Parser_(DsvParser.csv_(true, GfoFldList_.Null));
fx.run_parse_
( "id,name", String_.CrLf
, "0,me"
);
fx.tst_FldListCsv("id", "name");
fx.tst_DatCsv(fx.ary_("0", "me"));
}
// @Test public void Hdr_Manual() {
// fx.Parser_(DsvParser.csv_(false, GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), true));
// fx.run_parse_("0,me");
// fx.tst_DatCsv(fx.ary_(0, "me")); // NOTE: testing auto-parsing of id to int b/c id fld is IntClassXtn.Instance;
// }
}
class DsvDataRdr_fxt {
public Object[] ary_(Object... ary) {return ary;}
public Object[] ary_null_() {return new Object[] {null};}
public void Clear() {parser.Init(); root = null;}
public DsvParser Parser() {return parser;} public DsvDataRdr_fxt Parser_(DsvParser val) {parser = val; return this;} DsvParser parser = DsvParser.dsv_();
public GfoNde Root() {return root;} GfoNde root;
public void run_parse_(String... ary) {root = parser.ParseAsNde(String_.Concat(ary));}
public void run_parse_lines_(String... ary) {root = parser.ParseAsNde(String_.Concat_lines_crlf(ary));}
public DsvDataRdr_fxt tst_FldListCsv(String... names) {return tst_Flds(TblIdx0, GfoFldList_.str_(names));}
public DsvDataRdr_fxt tst_Flds(int tblIdx, GfoFldList expdFlds) {
GfoNde tbl = root.Subs().FetchAt_asGfoNde(tblIdx);
List_adp expdList = List_adp_.New(), actlList = List_adp_.New();
String_bldr sb = String_bldr_.new_();
GfoFldList_BldDbgList(expdFlds, expdList, sb);
GfoFldList_BldDbgList(tbl.SubFlds(), actlList, sb);
Tfds.Eq_list(expdList, actlList);
return this;
}
void GfoFldList_BldDbgList(GfoFldList flds, List_adp list, String_bldr sb) {
for (int i = 0; i < flds.Count(); i++) {
GfoFld fld = flds.Get_at(i);
sb.Add(fld.Key()).Add(",").Add(fld.Type().Key());
list.Add(sb.To_str_and_clear());
}
}
public DsvDataRdr_fxt tst_Tbls(String... expdNames) {
List_adp actlList = List_adp_.New();
for (int i = 0; i < root.Subs().Count(); i++) {
GfoNde tbl = root.Subs().FetchAt_asGfoNde(i);
actlList.Add(tbl.Name());
}
Tfds.Eq_ary(expdNames, actlList.To_str_ary());
return this;
}
public DsvDataRdr_fxt tst_DatNull() {
Tfds.Eq(0, root.Subs().Count());
return this;
}
public DsvDataRdr_fxt tst_DatCsv(Object[]... expdRows) {return tst_Dat(0, expdRows);}
public DsvDataRdr_fxt tst_Dat(int tblIdx, Object[]... expdRows) {
GfoNde tbl = root.Subs().FetchAt_asGfoNde(tblIdx);
if (expdRows.length == 0) {
Tfds.Eq(0, tbl.Subs().Count());
return this;
}
List_adp expdList = List_adp_.New(), actlList = List_adp_.New();
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < tbl.Subs().Count(); i++) {
GfoNde row = tbl.Subs().FetchAt_asGfoNde(i);
for (int j = 0; j < row.Flds().Count(); j++) {
if (j != 0) sb.Add("~");
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(row.ReadAt(j)));
}
expdList.Add(sb.To_str_and_clear());
}
for (Object[] expdRow : expdRows) {
if (expdRow == null) {
actlList.Add("");
continue;
}
for (int j = 0; j < expdRow.length; j++) {
if (j != 0) sb.Add("~");
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(expdRow[j]));
}
actlList.Add(sb.To_str_and_clear());
}
Tfds.Eq_list(expdList, actlList);
return this;
}
public static DsvDataRdr_fxt new_() {return new DsvDataRdr_fxt();}
static final int TblIdx0 = 0;
}

@ -0,0 +1,68 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class DsvDataRdr_dsv_dat_tst {
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
@Test public void NameOnly() {
fx.run_parse_("tableName, ,\" \",#");
fx.tst_Tbls("tableName");
fx.tst_Dat(0);
}
@Test public void Rows_N() {
fx.run_parse_lines_
( "numbers, ,\" \",#"
, "1,2,3"
, "4,5,6"
);
fx.tst_Tbls("numbers");
fx.tst_Dat(0
, fx.ary_("1", "2", "3")
, fx.ary_("4", "5", "6")
);
}
@Test public void Tbls_N() {
fx.run_parse_lines_
( "letters, ,\" \",#"
, "a,b,c"
, "numbers, ,\" \",#"
, "1,2,3"
, "4,5,6"
);
fx.tst_Tbls("letters", "numbers");
fx.tst_Dat(0, fx.ary_("a", "b", "c"));
fx.tst_Dat(1, fx.ary_("1", "2", "3"), fx.ary_("4", "5", "6"));
}
@Test public void IgnoreTrailingBlankRow() {
fx.run_parse_lines_
( "letters, ,\" \",#"
, "a,b,c"
, "" // ignored
);
fx.tst_Tbls("letters");
fx.tst_Dat(0, fx.ary_("a", "b", "c"));
}
@Test public void AllowCommentsDuringData() {
fx.run_parse_lines_
( "letters, ,\" \",#"
, "a,b,c"
, "// letters omitted, ,\" \",//" // these comments are not preserved
, "x,y,z"
);
fx.tst_Tbls("letters");
fx.tst_Dat(0, fx.ary_("a", "b", "c"), fx.ary_("x", "y", "z"));
}
}

@ -0,0 +1,80 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
public class DsvDataRdr_dsv_hdr_tst {
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
@Test public void Names() {
fx.run_parse_lines_
( "id,name, ,\" \",@"
, "0,me"
, "1,you"
);
fx.tst_Flds(0, GfoFldList_.str_("id", "name"));
fx.tst_Tbls(DsvTblBldr.NullTblName);
fx.tst_Dat(0
, fx.ary_("0", "me")
, fx.ary_("1", "you")
);
}
@Test public void Types() {
fx.run_parse_lines_
( "int," + StringClassXtn.Key_const + ", ,\" \",$"
, "0,me"
, "1,you"
);
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", IntClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
fx.tst_Dat(0
, fx.ary_(0, "me")
, fx.ary_(1, "you")
);
}
@Test public void NamesAndTypes() {
fx.run_parse_lines_
( "id,name, ,\" \",@"
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
, "0,me"
, "1,you"
);
fx.tst_Flds(0, GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance));
fx.tst_Dat(0
, fx.ary_(0, "me")
, fx.ary_(1, "you")
);
}
@Test public void MultipleTables_NoData() {
fx.run_parse_lines_
( "persons, ,\" \",#"
, "id,name, ,\" \",@"
, "things, ,\" \",#"
, "id,data, ,\" \",@"
);
fx.tst_Tbls("persons", "things");
fx.tst_Flds(0, GfoFldList_.str_("id", "name"));
fx.tst_Flds(1, GfoFldList_.str_("id", "data"));
fx.tst_Dat(0);
fx.tst_Dat(1);
}
@Test public void Comment() {
fx.run_parse_lines_
( "--------------------, ,\" \",//"
, "tbl0, ,\" \",#"
, "a0,a1"
);
fx.tst_Tbls("tbl0");
fx.tst_Dat(0, fx.ary_("a0", "a1"));
}
}

@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
public class DsvDataRdr_dsv_misc_tst {
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
@Test public void CmdDlm_NearMatches() {
fx.run_parse_("a, ,b");
fx.tst_DatCsv(fx.ary_("a", " ", "b"));
fx.Clear();
fx.run_parse_("a,\" \",b");
fx.tst_DatCsv(fx.ary_("a", " ", "b"));
fx.Clear();
fx.run_parse_("a, ,b,\" \",c");
fx.tst_DatCsv(fx.ary_("a", " ", "b", " ", "c"));
fx.Clear();
}
@Test public void CmdDlm_DoNotSpanLines() {
fx.run_parse_lines_
( "a, "
, "\" \",b"
);
fx.tst_DatCsv
( fx.ary_("a", " ")
, fx.ary_(" ", "b")
);
}
@Test public void CmdDlm_SecondFldMustBeQuoted() {
fx.run_parse_lines_("a, , ,b"); // will fail with "invalid command: b", if second , , is interpreted as command delimiter
fx.tst_DatCsv(fx.ary_("a", " ", " ", "b"));
}
@Test public void Null_Int() {
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
( "int," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
, ",val1"
);
fx.tst_Tbls(DsvTblBldr.NullTblName);
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", IntClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
fx.tst_Dat(0, fx.ary_(null, "val1"));
}
@Test public void Null_String() {
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
( StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
, ",val1"
);
fx.tst_Tbls(DsvTblBldr.NullTblName);
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", StringClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
fx.tst_Dat(0, fx.ary_(null, "val1"));
}
@Test public void EmptyString() {
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
( StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
, "\"\",val1"
);
fx.tst_Tbls(DsvTblBldr.NullTblName);
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", StringClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
fx.tst_Dat(0, fx.ary_("", "val1"));
}
}

@ -0,0 +1,129 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
public class DsvDataRdr_layout_tst {
@Test public void TableName() {
run_parse_lines("table0, ,\" \",#");
tst_Layout(0, DsvHeaderItm.Id_TableName);
}
@Test public void Comment() {
run_parse_lines("-------------, ,\" \",//", "data"); // need dataLine or parser will throw away standalone header
tst_Layout(0, DsvHeaderItm.Id_Comment);
}
@Test public void BlankLine() {
run_parse_lines("", "data"); // need dataLine or parser will throw away standalone header
tst_Layout(0, DsvHeaderItm.Id_BlankLine);
}
@Test public void LeafNames() {
run_parse_lines("id,name, ,\" \",@");
tst_Layout(0, DsvHeaderItm.Id_LeafNames);
}
@Test public void LeafTypes() {
run_parse_lines("int," + StringClassXtn.Key_const + ", ,\" \",$");
tst_Layout(0, DsvHeaderItm.Id_LeafTypes);
}
@Test public void Combined() {
run_parse_lines
( ""
, "-------------, ,\" \",//"
, "table0, ,\" \",#"
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
, "id,name, ,\" \",@"
, "-------------, ,\" \",//"
, "0,me"
);
tst_Layout(0
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_TableName
, DsvHeaderItm.Id_LeafTypes
, DsvHeaderItm.Id_LeafNames
, DsvHeaderItm.Id_Comment
);
}
@Test public void Tbl_N() {
run_parse_lines
( ""
, "*************, ,\" \",//"
, "table0, ,\" \",#"
, "-------------, ,\" \",//"
, "0,me"
, ""
, "*************, ,\" \",//"
, "table1, ,\" \",#"
, " extended data, ,\" \",//"
, "-------------, ,\" \",//"
, "1,you,more"
);
tst_Layout(0
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_TableName
, DsvHeaderItm.Id_Comment
);
tst_Layout(1
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_TableName
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_Comment
);
}
@Test public void Tbl_N_FirstIsEmpty() {
run_parse_lines
( ""
, "*************, ,\" \",//"
, "table0, ,\" \",#"
, "-------------, ,\" \",//"
, ""
, ""
, "*************, ,\" \",//"
, "table1, ,\" \",#"
, " extended data, ,\" \",//"
, "-------------, ,\" \",//"
, "1,you,more"
);
tst_Layout(0
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_TableName
, DsvHeaderItm.Id_Comment
);
tst_Layout(1
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_BlankLine
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_TableName
, DsvHeaderItm.Id_Comment
, DsvHeaderItm.Id_Comment
);
}
void run_parse_lines(String... ary) {
String raw = String_.Concat_lines_crlf(ary);
DsvParser parser = DsvParser.dsv_();
root = parser.ParseAsNde(raw);
}
void tst_Layout(int subIdx, int... expd) {
GfoNde tbl = root.Subs().FetchAt_asGfoNde(subIdx);
DsvStoreLayout layout = (DsvStoreLayout)tbl.EnvVars().Get_by(DsvStoreLayout.Key_const);
int[] actl = new int[layout.HeaderList().Count()];
for (int i = 0; i < actl.length; i++)
actl[i] = layout.HeaderList().Get_at(i).Id();
Tfds.Eq_ary(expd, actl);
}
GfoNde root;
}

@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
public class DsvDataWtr_csv_tst {
@Test public void Dat_Val_0() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root);
expd = String_.Concat_lines_crlf("");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Val_1() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a");
expd = String_.Concat_lines_crlf("a");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Val_N() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "b", "c");
expd = String_.Concat_lines_crlf("a,b,c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Row_N() {
root = fx_nde.csv_dat_();
this.AddCsvRow(root, "a", "b", "c");
this.AddCsvRow(root, "d", "e", "f");
expd = String_.Concat_lines_crlf
( "a,b,c"
, "d,e,f"
);
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Escape_FldSpr() { // ,
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", ",", "c");
expd = String_.Concat_lines_crlf("a,\",\",c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Escape_RcdSpr() { // NewLine
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", String_.CrLf, "c");
expd = String_.Concat_lines_crlf("a,\"" + String_.CrLf + "\",c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Escape_Quote() { // " -> ""
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "\"", "c");
expd = String_.Concat_lines_crlf("a,\"\"\"\",c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Whitespace() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", " b\t", "c");
expd = String_.Concat_lines_crlf("a, b\t,c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_Null() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", null, "c");
expd = String_.Concat_lines_crlf("a,,c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Dat_EmptyString() {
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "", "c");
expd = String_.Concat_lines_crlf("a,\"\",c");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Hdr_Flds() {
wtr = DsvDataWtr_.csv_hdr_();
GfoFldList flds = GfoFldList_.new_().Add("id", StringClassXtn.Instance).Add("name", StringClassXtn.Instance);
root = fx_nde.csv_hdr_(flds); this.AddCsvRow(root, "0", "me");
expd = String_.Concat_lines_crlf
( "id,name"
, "0,me"
);
fx.tst_XtoStr(wtr, root, expd);
}
void AddCsvRow(GfoNde root, String... ary) {
GfoNde sub = GfoNde_.vals_(root.SubFlds(), ary);
root.Subs().Add(sub);
}
GfoNde root; String expd; DsvDataWtr wtr = DsvDataWtr_.csv_dat_(); DsvDataWtr_fxt fx = DsvDataWtr_fxt.new_(); GfoNdeFxt fx_nde = GfoNdeFxt.new_();
}
class DsvDataWtr_fxt {
public void tst_XtoStr(DsvDataWtr wtr, GfoNde root, String expd) {
wtr.Clear();
root.XtoStr_wtr(wtr);
String actl = wtr.To_str();
Tfds.Eq(expd, actl);
}
public static DsvDataWtr_fxt new_() {return new DsvDataWtr_fxt();} DsvDataWtr_fxt() {}
}

@ -0,0 +1,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.gfo_ndes.*;
public class DsvDataWtr_tbls_tst {
@Before public void setup() {
DsvStoreLayout layout = DsvStoreLayout.dsv_brief_();
layout.HeaderList().Add_TableName();
wtr.InitWtr(DsvStoreLayout.Key_const, layout);
}
@Test public void Rows_0() {
root = fx_nde.tbl_("tbl0");
expd = String_.Concat_lines_crlf( "tbl0, ,\" \",#");
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Rows_N() {
root = fx_nde.tbl_
( "numbers"
, fx_nde.row_vals_(1, 2, 3)
, fx_nde.row_vals_(4, 5, 6)
);
expd = String_.Concat_lines_crlf
( "numbers, ,\" \",#"
, "1,2,3"
, "4,5,6"
);
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Tbls_N_Empty() {
root = fx_nde.root_
( fx_nde.tbl_("tbl0")
, fx_nde.tbl_("tbl1")
);
expd = String_.Concat_lines_crlf
( "tbl0, ,\" \",#"
, "tbl1, ,\" \",#"
);
fx.tst_XtoStr(wtr, root, expd);
}
@Test public void Tbls_N() {
root = fx_nde.root_
( fx_nde.tbl_("letters"
, fx_nde.row_vals_("a", "b", "c"))
, fx_nde.tbl_("numbers"
, fx_nde.row_vals_(1, 2, 3)
, fx_nde.row_vals_(4, 5, 6)
));
expd = String_.Concat_lines_crlf
( "letters, ,\" \",#"
, "a,b,c"
, "numbers, ,\" \",#"
, "1,2,3"
, "4,5,6"
);
fx.tst_XtoStr(wtr, root, expd);
}
GfoNde root; String expd; DsvDataWtr wtr = DsvDataWtr_.csv_dat_(); DsvDataWtr_fxt fx = DsvDataWtr_fxt.new_(); GfoNdeFxt fx_nde = GfoNdeFxt.new_();
}

@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfs_Date_tst {
@Before public void setup() {
fx = new GfsCoreFxt();
fx.AddObj(DateAdp_.Gfs, "Date_");
Datetime_now.Manual_y_();
} GfsCoreFxt fx;
@Test public void Now() {
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now")), DateAdp_.parse_gplx("2001-01-01 00:00:00.000"));
}
@Test public void Add_day() {
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now", "Add_day"), Keyval_.new_("days", 1)), DateAdp_.parse_gplx("2001-01-02 00:00:00.000"));
}
}
class GfsCoreFxt {
public GfsCore Core() {return core;} GfsCore core = GfsCore.new_();
public GfoMsg msg_(String[] ary, Keyval... kvAry) {return GfoMsg_.root_leafArgs_(ary, kvAry);}
public void AddObj(Gfo_invk invk, String s) {core.AddObj(invk, s);}
public void tst_MsgStr(GfoMsg msg, Object expd) {
GfsCtx ctx = GfsCtx.new_();
Object actl = core.ExecOne(ctx, msg);
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl));
}
}

@ -0,0 +1,91 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.regxs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.tests.*;
public class Regx_adp__tst implements TfdsEqListItmStr {
@Test public void Match() {
tst_Match("a", "a", true); // basic
tst_Match("a", "b", false); // matchNot
tst_Match("a", "ab", true); // matchPart
tst_Match("a\\+b", "a+b", true); // matchEscape
tst_Match("[^a]", "b", true); // charSet_negate
} void tst_Match(String find, String input, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(input, find));}
@Test public void Match_all() {
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 1); // handle match = true but len = 0; DATE:2013-04-11
tst_Match_all("a", "$", 1); // $ should match once, not zero; DATE:2014-09-02
} void tst_Match_all(String input, String regx, int expd) {Tfds.Eq(expd, Regx_adp_.new_(regx).Match_all(input, 0).length);}
@Test public void Replace() {
tst_Replace("ab", "a", "b", "bb"); // basic
tst_Replace("ab", "c", "b", "ab"); // replaceNot
tst_Replace("aba", "a", "b", "bbb"); // replaceMultiple
} void tst_Replace(String input, String find, String replace, String expd) {Tfds.Eq(expd, Regx_adp_.Replace(input, find, replace));}
@Test public void Match_WholeWord() {
tst_WholeWord("a", "ab a", true); // pass a
tst_WholeWord("a", "ab c", false); // fail ab
tst_WholeWord("a", "a_", false); // fail a_
tst_WholeWord("[a]", "a [a] c", true); // pass [a]
tst_WholeWord("[a]", "a[a]c", false); // fail a[a]c
} void tst_WholeWord(String regx, String text, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(text, Regx_bldr.WholeWord(regx)));}
@Test public void Match_As() {
tst_Regx("public static [A-Za-z0-9_]+ as_\\(Object obj\\)", "public static Obj1 as_(Object obj) {return obj instanceof Obj1 ? (Obj1)obj : null;}", true);
tst_Regx("public static [A-Za-z0-9_]+ as_\\(Object obj\\)", "public static boolean Asterisk(Object obj) {}", false);
} void tst_Regx(String regx, String text, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(text, regx));}
@Test public void Find() {
tst_Matches("b", "a b c b a", match_(2, 1), match_(6, 1));
tst_Matches("d", "a b c b a");
tst_Matches("b", "a b c b a b b", matches_(2, 6, 10, 12)); // BUGFIX: multiple entries did not work b/c of += instead of +
}
@Test public void Groups() {
tst_Groups("abc def ghi dz", "(d\\p{L}+)", "def", "dz");
}
Regx_match[] matches_(int... bgnAry) {
int aryLen = Array_.Len(bgnAry);
Regx_match[] rv = new Regx_match[aryLen];
for (int i = 0; i < aryLen; i++)
rv[i] = match_(bgnAry[i]);
return rv;
}
Regx_match match_(int bgn) {return match_(bgn, Int_.Min_value);}
Regx_match match_(int bgn, int len) {return new Regx_match(true, bgn, bgn + len, Regx_group.Ary_empty);}
void tst_Matches(String find, String input, Regx_match... expd) {
List_adp expdList = Array_.To_list(expd);
List_adp actlList = Regx_adp_.Find_all(input, find);
Tfds.Eq_list(expdList, actlList, this);
}
void tst_Groups(String text, String regx, String... expd) {
Regx_adp regx_mgr = Regx_adp_.new_(regx);
Regx_match[] rslts = regx_mgr.Match_all(text, 0);
Tfds.Eq_ary_str(expd, To_ary(rslts));
}
String[] To_ary(Regx_match[] ary) {
List_adp rv = List_adp_.New();
int len = ary.length;
for (int i = 0; i < len; i++) {
Regx_match itm = ary[i];
int cap_len = itm.Groups().length;
for (int j = 0; j < cap_len; j++) {
rv.Add(itm.Groups()[j].Val());
}
}
return rv.To_str_ary();
}
public String To_str(Object curObj, Object expdObj) {
Regx_match cur = (Regx_match)curObj, expd = (Regx_match)expdObj;
String rv = "bgn=" + cur.Find_bgn();
if (expd != null && expd.Find_len() != Int_.Min_value) rv += " len=" + cur.Find_len();
return rv;
}
}

@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.xmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
import gplx.core.ios.*; import gplx.core.texts.*;
public class HierStrBldr_tst {
@Before public void setup() {bldr = new HierStrBldr();} HierStrBldr bldr;
@Test public void Hier0() {
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000");
tst_MakeName( 0, "/root/idx_000.csv");
tst_MakeName( 1, "/root/idx_001.csv");
tst_MakeName(10, "/root/idx_010.csv");
}
@Test public void Hier1() {
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000", 10);
tst_MakeName( 0, "/root/dir_000/idx_000.csv");
tst_MakeName( 1, "/root/dir_000/idx_001.csv");
tst_MakeName(10, "/root/dir_010/idx_010.csv");
}
@Test public void Hier2() {
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000", 5, 10);
tst_MakeName( 0, "/root/dir_000/dir_000/idx_000.csv");
tst_MakeName( 1, "/root/dir_000/dir_000/idx_001.csv");
tst_MakeName( 10, "/root/dir_000/dir_010/idx_010.csv");
tst_MakeName( 49, "/root/dir_000/dir_040/idx_049.csv");
tst_MakeName( 50, "/root/dir_050/dir_050/idx_050.csv");
tst_MakeName( 99, "/root/dir_050/dir_090/idx_099.csv");
tst_MakeName(100, "/root/dir_100/dir_100/idx_100.csv");
tst_MakeName(110, "/root/dir_100/dir_110/idx_110.csv");
}
void tst_MakeName(int val, String expd) {Tfds.Eq(expd, bldr.GenStrIdxOnly(val));}
}

@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.xmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class XmlDoc_tst {
String xml; XmlDoc xdoc; XmlNde xnde;
@Test public void parse() {
xml = String_.Concat("<root/>");
xdoc = XmlDoc_.parse(xml);
Tfds.Eq("root", xdoc.Root().Name());
Tfds.Eq(true, xdoc.Root().NdeType_element());
}
@Test public void Xml_outer() {
xml = String_.Concat
( "<root>"
, "<a>"
, "<b/>"
, "<b/>"
, "</a>"
, "</root>"
);
xdoc = XmlDoc_.parse(xml);
xnde = xdoc.Root().SubNdes().Get_at(0);
Tfds.Eq("a", xnde.Name());
Tfds.Eq("<a><b/><b/></a>", xnde.Xml_outer());
}
@Test public void Text_inner() {
xml = String_.Concat
( "<root>"
, "<a>"
, "test me"
, "</a>"
, "</root>"
);
xdoc = XmlDoc_.parse(xml);
xnde = xdoc.Root().SubNdes().Get_at(0);
Tfds.Eq("a", xnde.Name());
Tfds.Eq("test me", xnde.Text_inner());
}
@Test public void Atrs() {
xml = String_.Concat
( "<root atr0=\"0\" atr1=\"1\">"
, "</root>"
);
xdoc = XmlDoc_.parse(xml);
XmlAtrList atrs = xdoc.Root().Atrs();
XmlAtr atr = atrs.Get_at(1);
tst_Atr(atr, "atr1", "1");
atr = atrs.Get_at(1);
tst_Atr(atr, "atr1", "1");
}
void tst_Atr(XmlAtr atr, String expdName, String expdVal) {
Tfds.Eq(expdName, atr.Name());
Tfds.Eq(expdVal, atr.Value());
}
}

@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.xmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
import gplx.core.ios.*; import gplx.core.texts.*;
public class XmlFileSplitter_tst {
@Before public void setup() {
splitter = new XmlFileSplitter();
Io_mgr.Instance.InitEngine_mem();
} XmlFileSplitter splitter;
@Test public void FindMatchPos() {
tst_FindMatchPos("abcde", "a", 0);
tst_FindMatchPos("abcde", "b", 1);
tst_FindMatchPos("abcde", "cd", 2);
tst_FindMatchPos("abcde", "f", -1);
tst_FindMatchPos("abcde", "fg", -1);
} void tst_FindMatchPos(String src, String find, int expd) {Tfds.Eq(expd, splitter.FindMatchPos(byte_(src), byteAry_(find)));}
@Test public void FindMatchPosRev() {
tst_FindMatchPosRev("abcde", "a", 0);
tst_FindMatchPosRev("abcde", "b", 1);
tst_FindMatchPosRev("abcde", "cd", 2);
tst_FindMatchPosRev("abcde", "f", -1);
tst_FindMatchPosRev("abcde", "ef", -1);
tst_FindMatchPosRev("abcde", "za", -1);
tst_FindMatchPosRev("dbcde", "d", 3);
} void tst_FindMatchPosRev(String src, String find, int expd) {Tfds.Eq(expd, splitter.FindMatchPosRev(byte_(src), byteAry_(find)));}
@Test public void ExtractHdr() {
tst_ExtractHdr("<a><b>", "<b", "<a>", "<b>");
}
@Test public void Split() {
splitter.Opts().FileSizeMax_(30).XmlNames_("<a").XmlEnd_("</root>");
tst_Split
( "<root><a id='1'/><a id='2'/><a id='3'/><a id='4'/><a id='5'/></root>"
, "<root><a id='1'/><a id='2'/></root>"
, "<root><a id='3'/><a id='4'/></root>"
, "<root><a id='5'/></root>"
);
tst_Split
( "<root><a id='1' name='long_text_that_will_force_next_read'/><a id='2'/></root>"
, "<root><a id='1' name='long_text_that_will_force_next_read'/></root>"
, "<root><a id='2'/></root>"
);
}
void tst_Split(String txt, String... expd) {
Io_url xmlFil = Io_url_.mem_fil_("mem/800_misc/txt.xml");
Io_url tmpDir = xmlFil.OwnerDir().GenSubDir("temp_xml");
Io_mgr.Instance.DeleteDirDeep(tmpDir);
splitter.Opts().StatusFmt_(null).PartDir_(tmpDir);
splitter.Opts().Namer().Ctor_io(tmpDir, "", "fil_{0}.xml", "000");
Io_mgr.Instance.SaveFilStr(xmlFil, txt);
splitter.Split(xmlFil);
Io_url[] tmpFilAry = Io_mgr.Instance.QueryDir_fils(tmpDir);
Tfds.Eq(expd.length, tmpFilAry.length);
for (int i = 0; i < tmpFilAry.length; i++) {
Io_url tmpFil = tmpFilAry[i];
Tfds.Eq(expd[i], Io_mgr.Instance.LoadFilStr(tmpFil));
}
}
byte[] byte_(String s) {return Bry_.new_u8(s);}
byte[][] byteAry_(String s) {
byte[][] rv = new byte[1][];
rv[0] = Bry_.new_u8(s);
return rv;
}
void tst_ExtractHdr(String src, String find, String expdHdr, String expdSrc) {
splitter.Clear();
byte[] srcAry = byte_(src);
int findPos = splitter.FindMatchPos(srcAry, byteAry_(find));
srcAry = splitter.SplitHdr(srcAry, findPos);
Tfds.Eq(String_.new_u8(splitter.Hdr()), expdHdr);
Tfds.Eq(String_.new_u8(srcAry), expdSrc);
}
}

@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.xmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Xpath__tst {
@Test public void Select_all() {
String xml = String_.Concat
( "<root>"
, "<a>"
, "</a>"
, "<b>"
, "<c/>"
, "<c/>"
, "<c/>"
, "</b>"
, "<a>"
, "</a>"
, "</root>"
);
tst_SelectAll(xml, "a", 2);
tst_SelectAll(xml, "b", 1);
tst_SelectAll(xml, "b/c", 3);
}
void tst_SelectAll(String raw, String xpath, int expdCount) {
XmlDoc xdoc = XmlDoc_.parse(raw);
XmlNdeList xndeList = Xpath_.SelectAll(xdoc.Root(), xpath);
Tfds.Eq(expdCount, xndeList.Count());
}
}

@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
import org.junit.*;
public class GfoMsg_rdr_tst {
@Before public void setup() {
msg = msg_().Add("a", "1").Add("b", "2").Add("c", "3");
ctx.Match("init", "init");
} GfoMsg msg; GfsCtx ctx = GfsCtx.new_();
@Test public void Key() {
tst_Msg(msg, "a", "1");
tst_Msg(msg, "b", "2");
tst_Msg(msg, "c", "3");
tst_Msg(msg, "d", null);
}
@Test public void Pos() {
msg = msg_().Add("", "1").Add("", "2").Add("", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
tst_Msg(msg, "", "3");
tst_Msg(msg, "", null);
}
@Test public void OutOfOrder() {
tst_Msg(msg, "c", "3");
tst_Msg(msg, "b", "2");
tst_Msg(msg, "a", "1");
}
@Test public void Key3_Pos1_Pos2() {
msg = msg_().Add("", "1").Add("", "2").Add("c", "3");
tst_Msg(msg, "c", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
}
@Test public void MultipleEmpty() {
msg = msg_().Add("", "1").Add("", "2").Add("", "3");
tst_Msg(msg, "", "1");
tst_Msg(msg, "", "2");
tst_Msg(msg, "", "3");
}
GfoMsg msg_() {return GfoMsg_.new_parse_("test");}
void tst_Msg(GfoMsg m, String k, String expd) {Tfds.Eq(expd, m.ReadStrOr(k, null));}
}

@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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;
public class GfoTreeBldr_fxt {
public List_adp Atrs() {return atrs;} List_adp atrs = List_adp_.New();
public List_adp Subs() {return subs;} List_adp subs = List_adp_.New();
public GfoTreeBldr_fxt atr_(Object key, Object val) {
atrs.Add(new Object[] {key, val});
return this;
}
public GfoTreeBldr_fxt sub_(GfoTreeBldr_fxt... ary) {
for (GfoTreeBldr_fxt sub : ary)
subs.Add(sub);
return this;
}
public static GfoTreeBldr_fxt new_() {return new GfoTreeBldr_fxt();} GfoTreeBldr_fxt() {}
}

@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoEngine_dir_basic_memory_tst extends IoEngine_dir_basic_base {
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem");
} @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
}

@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoEngine_dir_basic_system_tst extends IoEngine_dir_basic_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_system.new_();}
@Test @Override public void ScanDir() {
super.ScanDir();
}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoEngine_dir_deep_memory_tst extends IoEngine_dir_deep_base {
@Override protected void setup_hook() {
root = Io_url_.mem_dir_("mem/root");
} @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();}
@Test @Override public void SearchDir() {
super.SearchDir();
}
@Test @Override public void MoveDirDeep() {
super.MoveDirDeep();
}
@Test @Override public void CopyDir() {
super.CopyDir();
}
@Test @Override public void DeleteDir() {
super.DeleteDir();
}
}

@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class IoEngine_dir_deep_system_tst extends IoEngine_dir_deep_base {
@Override protected void setup_hook() {
root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp");
IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec();
} @Override protected IoEngine engine_() {return IoEngine_.Sys;}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save