mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
App: Release v4.5.15.1709
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
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 Bit__tst {
|
||||
@Before public void init() {fxt.Clear();} private Bit__fxt fxt = new Bit__fxt();
|
||||
@Test public void XtoBitStr() {
|
||||
tst_XtoBitStr( 0, "00000000");
|
||||
tst_XtoBitStr( 1, "00000001");
|
||||
tst_XtoBitStr( 2, "00000010");
|
||||
tst_XtoBitStr( 3, "00000011");
|
||||
tst_XtoBitStr(255, "11111111");
|
||||
} void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.ToBitStr(val));}
|
||||
@Test public void Shift_lhs() {// simple: shift 1 bit
|
||||
fxt.Test_shift_lhs(1, 1, 2);
|
||||
fxt.Test_shift_lhs(2, 1, 4);
|
||||
fxt.Test_shift_lhs(3, 1, 6);
|
||||
fxt.Test_shift_lhs(4, 1, 8);
|
||||
}
|
||||
@Test public void Shift_rhs() {
|
||||
fxt.Test_shift_rhs(2, 1, 1);
|
||||
fxt.Test_shift_rhs(4, 1, 2);
|
||||
fxt.Test_shift_rhs(6, 1, 3);
|
||||
fxt.Test_shift_rhs(8, 1, 4);
|
||||
}
|
||||
@Test public void Shift_lhs_to_int() {
|
||||
int[] shift_ary = Int_.Ary(0, 3, 5);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 0, 0), 0);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(7, 0, 0), 7); // 1st 3 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 3, 0), 24); // 2nd 2 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 0, 1), 32); // 3rd 1 bit
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(7, 3, 1), 63); // many bits
|
||||
}
|
||||
@Test public void Shift_rhs_to_ary() {
|
||||
int[] shift_ary = Int_.Ary(0, 3, 5);
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 0, Int_.Ary(0, 0, 0));
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 7, Int_.Ary(7, 0, 0)); // 1st 3 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 24, Int_.Ary(0, 3, 0)); // 2nd 2 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 32, Int_.Ary(0, 0, 1)); // 3rd 1 bit
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 63, Int_.Ary(7, 3, 1)); // many bits
|
||||
}
|
||||
}
|
||||
class Bit__fxt {
|
||||
public void Clear() {}
|
||||
public void Test_shift_lhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs(val, shift));}
|
||||
public void Test_shift_rhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_rhs(val, shift));}
|
||||
public void Test_shift_lhs_to_int(int[] shift_ary, int[] val_ary, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs_to_int(shift_ary, val_ary));}
|
||||
public void Test_shift_rhs_to_ary(int[] shift_ary, int val, int[] expd_ary) {
|
||||
int[] actl_ary = Int_.Ary(0, 0, 0);
|
||||
Bit_.Shift_rhs_to_ary(actl_ary, shift_ary, val);
|
||||
Tfds.Eq_ary(expd_ary, actl_ary);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
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 Bit_heap_rdr_tst {
|
||||
private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt();
|
||||
@Test public void Get_bool() {
|
||||
fxt.Load(255);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur(127, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 63, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 31, 3, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 15, 4, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 7, 5, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 3, 6, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 7, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 0, 1);
|
||||
fxt.Load(0);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0);
|
||||
fxt.Load(6);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 3, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 3, 0);
|
||||
}
|
||||
@Test public void Get_byte() {
|
||||
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
|
||||
fxt.Load(255, 3);
|
||||
fxt.Test__get_byte(7, 127);
|
||||
fxt.Test__get_byte(3, 7);
|
||||
fxt.Load(10);
|
||||
fxt.Test__get_bool(false);
|
||||
fxt.Test__get_byte(3, 5);
|
||||
}
|
||||
@Test public void Get_int_hzip() {
|
||||
fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1);
|
||||
fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3);
|
||||
fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2);
|
||||
fxt.Load(250, 3, 88, 0).Test__get_bool(Bool_.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3);
|
||||
}
|
||||
}
|
||||
class Bit_heap_rdr_fxt {
|
||||
private final Bit_heap_rdr heap = new Bit_heap_rdr();
|
||||
public Bit_heap_rdr_fxt Load(int... src) {
|
||||
byte[] bry = Bry_.New_by_ints(src);
|
||||
heap.Load(bry, 0, bry.length);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_bool(boolean expd) {
|
||||
Tfds.Eq_bool(expd, heap.Get_bool());
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) {
|
||||
Tfds.Eq_byte((byte)expd, heap.Get_byte(bits));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) {
|
||||
Tfds.Eq_int(expd, heap.Get_int_hzip(reqd));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) {
|
||||
Tfds.Eq_int(cur_val, heap.Cur_val(), "val");
|
||||
Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits");
|
||||
Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
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 Bit_heap_wtr_tst {
|
||||
private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt();
|
||||
@Test public void Add_bool() {
|
||||
fxt.Clear().Add_bool(Bool_.Y).Test__vals(1, 1);
|
||||
fxt.Clear().Add_bool(Bool_.N).Test__vals(1, 0);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Test__vals(4, 15);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.N, Bool_.N, Bool_.Y).Test__vals(4, 9);
|
||||
fxt.Clear().Add_bool(8, Bool_.Y).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_byte() {
|
||||
fxt.Clear().Add_byte(255).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_bool_byte() {
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_byte(255).Test__vals(1, 127, 254);
|
||||
fxt.Clear().Add_bool(Bool_.Y).Add_byte(255).Test__vals(1, 127, 255);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Add_byte(255).Test__vals(4, 15, 255);
|
||||
}
|
||||
@Test public void Add_byte_digits() {
|
||||
fxt.Clear().Add_byte(4, 15).Test__vals(4, 15);
|
||||
fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255);
|
||||
fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63);
|
||||
fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255);
|
||||
fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54);
|
||||
}
|
||||
@Test public void Add_int_hzip() {
|
||||
fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100);
|
||||
fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44);
|
||||
fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100);
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88);
|
||||
}
|
||||
}
|
||||
class Bit_heap_wtr_fxt {
|
||||
private final Bit_heap_wtr heap = new Bit_heap_wtr();
|
||||
public Bit_heap_wtr_fxt Clear() {heap.Clear(); return this;}
|
||||
public Bit_heap_wtr_fxt Add_bool(int len, boolean v) {
|
||||
boolean[] ary = new boolean[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = v;
|
||||
Add_bool(ary);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_bool(boolean... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_bool(v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_byte((byte)v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int bits, int val) {
|
||||
heap.Add_byte(bits, (byte)val);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_int_hzip(int reqd, int val) {
|
||||
heap.Add_int_hzip(reqd, val);
|
||||
return this;
|
||||
}
|
||||
public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) {
|
||||
Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits");
|
||||
Tfds.Eq_int (expd_cur , heap.Cur() , "cur");
|
||||
Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap");
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
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_diff_tst {
|
||||
@Before public void init() {} private final Bry_diff_fxt fxt = new Bry_diff_fxt();
|
||||
@Test public void Diff_1st() {
|
||||
fxt.Test__diff_1st("a|b|c" , "a|b|c" , null , null);
|
||||
fxt.Test__diff_1st("a|b|c" , "a|b1|c" , "b" , "b1");
|
||||
fxt.Test__diff_1st("a|b|" , "a|b|c" , "<<EOS>>" , "c");
|
||||
fxt.Test__diff_1st("a|b|c" , "a|b|" , "c" , "<<EOS>>");
|
||||
}
|
||||
@Test public void Diff_1st_show() {
|
||||
fxt.Test__diff_1st("a|b<c>d|e" , "a|b<c>e|e" , "<c>d", "<c>e");
|
||||
}
|
||||
}
|
||||
class Bry_diff_fxt {
|
||||
public void Test__diff_1st(String lhs, String rhs, String expd_lhs, String expd_rhs) {
|
||||
byte[] lhs_src = Bry_.new_u8(lhs);
|
||||
byte[] rhs_src = Bry_.new_u8(rhs);
|
||||
byte[][] actl = Bry_diff_.Diff_1st(lhs_src, 0, lhs_src.length, rhs_src, 0, rhs_src.length, Byte_ascii.Pipe_bry, Byte_ascii.Angle_bgn_bry, 255);
|
||||
if (expd_lhs == null && expd_rhs == null)
|
||||
Tfds.Eq_true(actl == null, "actl not null");
|
||||
else {
|
||||
Tfds.Eq_bry(Bry_.new_u8(expd_lhs), actl[0]);
|
||||
Tfds.Eq_bry(Bry_.new_u8(expd_rhs), actl[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
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 Int_flag_bldr__tst {
|
||||
private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt();
|
||||
@Test public void Bld_pow_ary() {
|
||||
fxt.Test__bld_pow_ary(fxt.Make__ary(1, 1, 1, 1), fxt.Make__ary(8, 4, 2, 1));
|
||||
fxt.Test__bld_pow_ary(fxt.Make__ary(3, 2) , fxt.Make__ary(4, 1));
|
||||
}
|
||||
@Test public void To_int__1_1_1() {
|
||||
int[] seg_ary = fxt.Make__ary(1, 1, 1);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 0, 0), 0);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 1), 7);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 0, 0), 4);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 0), 6);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 1, 1), 3);
|
||||
}
|
||||
@Test public void To_int__2_3() {
|
||||
fxt.Test__to_int(fxt.Make__ary(2, 3) , fxt.Make__ary(3, 7) , 31);
|
||||
fxt.Test__to_int(fxt.Make__ary(1, 2, 3) , fxt.Make__ary(1, 3, 7) , 63);
|
||||
}
|
||||
@Test public void To_int__11_4_5_5_6() {
|
||||
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 17), 2110135761);
|
||||
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 18), 2110135762);
|
||||
}
|
||||
@Test public void To_int_ary() {
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(1, 1, 1, 1) , 15, fxt.Make__ary(1, 1, 1, 1));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(3, 2) , 31, fxt.Make__ary(7, 3));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(3, 2, 1) , 63, fxt.Make__ary(7, 3, 1));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135761, fxt.Make__ary(2012, 6, 3, 23, 17));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135762, fxt.Make__ary(2012, 6, 3, 23, 18));
|
||||
}
|
||||
@Test public void To_int_date_short() {
|
||||
fxt.Test__to_int_date_short("20120604 2359", 117843451);
|
||||
fxt.Test__to_int_date_short("20120604 2358", 117843450);
|
||||
fxt.Test__to_int_date_short("20120605 0000", 117843968);
|
||||
}
|
||||
}
|
||||
class Int_flag_bldr__fxt {
|
||||
public int[] Make__ary(int... v) {return v;}
|
||||
public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));}
|
||||
public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) {
|
||||
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
|
||||
Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary));
|
||||
int[] actl_val_ary = Int_flag_bldr_.To_int_ary(pow_ary, expd);
|
||||
Tfds.Eq_ary(val_ary, actl_val_ary);
|
||||
}
|
||||
public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) {
|
||||
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
|
||||
Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val));
|
||||
}
|
||||
public void Test__to_int_date_short(String date_str, int expd) {
|
||||
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
|
||||
int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry());
|
||||
Tfds.Eq(expd, date_int);
|
||||
Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
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.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Bry_eval_mgr__tst {
|
||||
private final Bry_eval_mgr__fxt fxt = new Bry_eval_mgr__fxt();
|
||||
@Test public void Text() {fxt.Test__eval("abc" , "abc");}
|
||||
@Test public void Args_0() {fxt.Test__eval("abc~{test}xyz" , "abctestxyz");}
|
||||
@Test public void Args_n() {fxt.Test__eval("abc~{concat|d|e|f}xyz" , "abcdefxyz");}
|
||||
@Test public void Recur_1() {fxt.Test__eval("abc~{~{test}}xyz" , "abctestxyz");}
|
||||
@Test public void Recur_2() {fxt.Test__eval("abc~{t~{concat|e|s}t}xyz" , "abctestxyz");}
|
||||
@Test public void Grp_end() {fxt.Test__eval("a}b" , "a}b");}
|
||||
@Test public void Escape() {fxt.Test__eval("a~~b" , "a~b");}
|
||||
// @Test public void Eos() {fxt.Test__eval("a~" , "a~");}
|
||||
}
|
||||
class Bry_eval_mgr__fxt {
|
||||
private final Bry_eval_mgr mgr = Bry_eval_mgr.Dflt().Add_many(new Bry_eval_wkr__test(), new Bry_eval_wkr__concat());
|
||||
public Bry_eval_mgr__fxt Test__eval(String raw, String expd) {
|
||||
Gftest.Eq__bry(Bry_.new_u8(expd), mgr.Eval(Bry_.new_u8(raw)));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Bry_eval_wkr__test implements Bry_eval_wkr {
|
||||
public String Key() {return "test";}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) {
|
||||
rv.Add_str_a7("test");
|
||||
}
|
||||
}
|
||||
class Bry_eval_wkr__concat implements Bry_eval_wkr {
|
||||
public String Key() {return "concat";}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) {
|
||||
byte[][] ary = Bry_split_.Split(src, src_bgn, src_end, Byte_ascii.Pipe, false);
|
||||
for (byte[] itm : ary) {
|
||||
rv.Add(itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
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.xowa.langs.cases.*;
|
||||
public class Btrie_u8_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Btrie_u8_mgr_fxt fxt = new Btrie_u8_mgr_fxt();
|
||||
@Test public void Ascii() {
|
||||
fxt.Init_add(Bry_.new_a7("a") , "1");
|
||||
fxt.Init_add(Bry_.new_a7("abc") , "123");
|
||||
fxt.Test_match("a" , "1"); // single.exact
|
||||
fxt.Test_match("abc" , "123"); // many.exact
|
||||
fxt.Test_match("ab" , "1"); // single.more
|
||||
fxt.Test_match("abcde" , "123"); // many.more
|
||||
fxt.Test_match(" a" , null); // no_match
|
||||
fxt.Test_match("aBC" , "123"); // upper
|
||||
}
|
||||
@Test public void Uft8() {
|
||||
fxt.Init_add(Bry_.new_u8("aéi") , "1");
|
||||
fxt.Test_match("aéi" , "1"); // exact
|
||||
fxt.Test_match("aÉi" , "1"); // upper.utf8
|
||||
fxt.Test_match("AÉI" , "1"); // upper.all
|
||||
fxt.Test_match("AÉIo" , "1"); // trailing-char
|
||||
fxt.Test_match("aei" , null); // no_match
|
||||
}
|
||||
@Test public void Uft8_match_pos() {
|
||||
fxt.Init_add(Bry_.new_u8("aéi") , "1");
|
||||
fxt.Test_match_pos("aAÉI" , 1, "1"); // match at 1
|
||||
fxt.Test_match_pos("aAÉI" , 0, null); // no_match at 0
|
||||
}
|
||||
@Test public void Uft8_asymmetric() {
|
||||
fxt.Init_add(Bry_.new_u8("İ") , "1");
|
||||
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176)
|
||||
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105)
|
||||
fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
|
||||
|
||||
fxt.Clear();
|
||||
fxt.Init_add(Bry_.new_u8("i") , "1");
|
||||
fxt.Test_match("i" , "1"); // exact=y
|
||||
fxt.Test_match("I" , "1"); // upper=y
|
||||
fxt.Test_match("İ" , "1"); // utf_8=y; note that "i" matches "İ" b/c hash is case-insensitive and "İ" lower-cases to "i"; DATE:2015-09-07
|
||||
}
|
||||
@Test public void Utf8_asymmetric_multiple() { // PURPOSE: problems in original implementation of Hash_adp_bry and uneven source / target counts;
|
||||
fxt.Init_add(Bry_.new_u8("İİ") , "1");
|
||||
fxt.Test_match("İİ" , "1"); // exact
|
||||
fxt.Test_match("ii" , "1"); // lower
|
||||
fxt.Test_match("İi" , "1"); // mixed
|
||||
fxt.Test_match("iİ" , "1"); // mixed
|
||||
}
|
||||
@Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_u8_itm and called_by_match
|
||||
fxt.Init_add(Bry_.new_u8("İ") , "1");
|
||||
fxt.Init_add(Bry_.new_u8("I") , "1");
|
||||
fxt.Test_match("İ" , "1"); // exact
|
||||
fxt.Test_match("I" , "1"); // exact
|
||||
fxt.Test_match("i" , "1"); // lower
|
||||
}
|
||||
@Test public void Utf8_asymmetric_symbols() { // PURPOSE: test Hash_adp_bry and multi-byte syms (chars that will never be cased)
|
||||
fxt.Init_add(Bry_.new_u8("a_b") , "1");
|
||||
fxt.Test_match("a_b" , "1"); // exact: len=3
|
||||
fxt.Test_match("a†b" , null); // diff : len=3
|
||||
fxt.Test_match("a±b" , null); // diff : len=2
|
||||
fxt.Test_match("a_b" , null); // diff : len=1
|
||||
}
|
||||
}
|
||||
class Btrie_u8_mgr_fxt {
|
||||
private Btrie_u8_mgr trie;
|
||||
public void Clear() {
|
||||
trie = Btrie_u8_mgr.new_(Xol_case_mgr_.U8());
|
||||
}
|
||||
public void Init_add(byte[] key, Object val) {trie.Add_obj(key, val);}
|
||||
public void Test_match_pos(String src_str, int bgn_pos, String expd) {
|
||||
byte[] src = Bry_.new_u8(src_str);
|
||||
Object actl = trie.Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, src.length);
|
||||
Tfds.Eq(expd, actl, src_str);
|
||||
}
|
||||
public void Test_match(String src_str, String expd) {
|
||||
byte[] src = Bry_.new_u8(src_str);
|
||||
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
|
||||
Tfds.Eq(expd, actl, src_str);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
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.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Gfo_cache_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfo_cache_mgr_fxt fxt = new Gfo_cache_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__add("a");
|
||||
fxt.Test__cur_size(1);
|
||||
fxt.Test__itms("a");
|
||||
}
|
||||
@Test public void Reduce() {
|
||||
fxt.Exec__add("a", "b", "c", "d", "e");
|
||||
fxt.Test__cur_size(2);
|
||||
fxt.Test__itms("a", "b");
|
||||
}
|
||||
@Test public void Reduce_after_get() {
|
||||
fxt.Exec__add("a", "b", "c", "d");
|
||||
fxt.Exec__get("a", "c");
|
||||
fxt.Exec__add("e");
|
||||
fxt.Test__itms("a", "c");
|
||||
}
|
||||
}
|
||||
class Gfo_cache_mgr_fxt {
|
||||
private final Gfo_cache_mgr mgr = new Gfo_cache_mgr().Max_size_(4).Reduce_by_(2);
|
||||
public void Clear() {mgr.Clear();}
|
||||
public Gfo_cache_mgr_fxt Exec__add(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
byte[] key = Bry_.new_u8(itm);
|
||||
mgr.Add(key, new Gfo_cache_itm_mock(itm), key.length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Gfo_cache_mgr_fxt Exec__get(String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
mgr.Get_by_key(Bry_.new_u8(itm));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Gfo_cache_mgr_fxt Test__cur_size(int expd) {Gftest.Eq__int(expd, mgr.Cur_size(), "cur_size"); return this;}
|
||||
public Gfo_cache_mgr_fxt Test__itms(String... expd) {
|
||||
int len = mgr.Test__len();
|
||||
String[] actl = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
actl[i] = ((Gfo_cache_itm_mock)mgr.Test__get_at(i)).Val();
|
||||
Gftest.Eq__ary(expd, actl, "itms");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Gfo_cache_itm_mock implements Rls_able {
|
||||
public Gfo_cache_itm_mock(String val) {this.val = val;}
|
||||
public String Val() {return val;} private String val;
|
||||
public void Rls() {}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
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.consoles; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Gfo_cmd_arg_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfo_cmd_arg_mgr_fxt fxt = new Gfo_cmd_arg_mgr_fxt();
|
||||
@Test public void Val__many() {
|
||||
fxt.Init_args(fxt.Make_arg("a"), fxt.Make_arg("b"));
|
||||
fxt.Exec_process("--a", "0", "--b", "1");
|
||||
fxt.Test_errs_none();
|
||||
fxt.Test_actl(fxt.Make_chkr("a", "0"), fxt.Make_chkr("b", "1"));
|
||||
}
|
||||
@Test public void Val__yn() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn), fxt.Make_arg("b", Gfo_cmd_arg_itm_.Val_tid_yn));
|
||||
fxt.Exec_process("--a", "y", "--b", "n");
|
||||
fxt.Test_errs_none();
|
||||
fxt.Test_actl(fxt.Make_chkr("a", Bool_.Y), fxt.Make_chkr("b", Bool_.N));
|
||||
}
|
||||
@Test public void Dflt() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn).Dflt_(Bool_.Y));
|
||||
fxt.Exec_process("--a", "n").Test_actl(fxt.Make_chkr("a", Bool_.N)); // if val, use it
|
||||
fxt.Exec_process() .Test_actl(fxt.Make_chkr("a", Bool_.Y)); // if no val, use default
|
||||
}
|
||||
@Test public void Err__key__unknown() {
|
||||
fxt.Init_args(fxt.Make_arg("a"));
|
||||
fxt.Exec_process("--b");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__unknown);
|
||||
}
|
||||
@Test public void Err__key__missing() {
|
||||
fxt.Init_args(fxt.Make_arg("a"));
|
||||
fxt.Exec_process("a");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__missing);
|
||||
}
|
||||
@Test public void Err__key__dupe() {
|
||||
fxt.Init_args(fxt.Make_arg("a"));
|
||||
fxt.Exec_process("--a", "0", "--a", "0");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__duplicate);
|
||||
}
|
||||
@Test public void Err__val__reqd() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Bool_.Y), fxt.Make_arg("b", Bool_.N));
|
||||
fxt.Exec_process("--b", "1");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__required);
|
||||
}
|
||||
@Test public void Err__val__parse__yn() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn));
|
||||
fxt.Exec_process("--a", "x");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__invalid__yn);
|
||||
}
|
||||
@Test public void Val_as_url_rel_dir_or() { // PURPOSE: "/xowa" -> "/xowa/"
|
||||
String root_dir = Op_sys.Cur().Tid_is_wnt() ? "C:\\" : "/", dir_spr = Op_sys.Cur().Fsys_dir_spr_str();
|
||||
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" , root_dir + "sub" + dir_spr); // /sub -> /sub/
|
||||
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" + dir_spr , root_dir + "sub" + dir_spr); // /sub/ -> /sub/
|
||||
fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, "sub" , root_dir + "dir" + dir_spr + "sub" + dir_spr); // sub -> /dir/sub/
|
||||
}
|
||||
}
|
||||
class Gfo_cmd_arg_mgr_fxt {
|
||||
private final Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg;
|
||||
public Gfo_cmd_arg_mgr Mgr() {return mgr;} private final Gfo_cmd_arg_mgr mgr = new Gfo_cmd_arg_mgr();
|
||||
public Gfo_cmd_arg_mgr_fxt Clear() {
|
||||
if (usr_dlg == null)
|
||||
usr_dlg = Gfo_usr_dlg_.Test();
|
||||
mgr.Reset();
|
||||
usr_dlg.Gui_wkr().Clear();
|
||||
return this;
|
||||
}
|
||||
public Gfo_cmd_arg_itm Make_arg(String key) {return Make_arg(key, false);}
|
||||
public Gfo_cmd_arg_itm Make_arg(String key, int tid) {return Make_arg(key, false, tid);}
|
||||
public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd) {return Gfo_cmd_arg_itm_.new_(key, reqd, Gfo_cmd_arg_itm_.Val_tid_string);}
|
||||
public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd, int tid) {return Gfo_cmd_arg_itm_.new_(key, reqd, tid);}
|
||||
public Gfo_cmd_itm_chkr Make_chkr(String key, Object val) {return new Gfo_cmd_itm_chkr(key, val);}
|
||||
public Gfo_cmd_arg_mgr_fxt Init_args(Gfo_cmd_arg_itm... v) {mgr.Reg_many(v); return this;}
|
||||
public Gfo_cmd_arg_mgr_fxt Exec_process(String... v) {mgr.Parse(v); return this;}
|
||||
public Gfo_cmd_arg_mgr_fxt Test_actl(Gfo_cmd_itm_chkr... expd) {
|
||||
Gfo_cmd_arg_itm[] actl = mgr.To_ary();
|
||||
tst_mgr.Tst_ary("", expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Gfo_cmd_arg_mgr_fxt Test_errs_none() {return Test_errs(String_.Ary_empty);}
|
||||
public Gfo_cmd_arg_mgr_fxt Test_errs(String... expd) {
|
||||
String[] actl = mgr.Errs__to_str_ary();
|
||||
int len = actl.length;
|
||||
for (int i = 0; i < len; ++i) { // extract key part; EX: "unknown key: abc" -> unknown key
|
||||
actl[i] = String_.GetStrBefore(actl[i], ":");
|
||||
}
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) {
|
||||
Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Msgs().To_str_ary_and_clear());
|
||||
return this;
|
||||
}
|
||||
public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {
|
||||
Io_url actl = Make_arg("key").Val_(val).Val_as_url__rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null);
|
||||
Tfds.Eq(expd, actl.Raw());
|
||||
}
|
||||
}
|
||||
class Gfo_cmd_itm_chkr implements Tst_chkr {
|
||||
public Gfo_cmd_itm_chkr(String key, Object val) {this.key = key; this.val = val;} private String key; Object val;
|
||||
public Class<?> TypeOf() {return Gfo_cmd_arg_itm.class;}
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Gfo_cmd_arg_itm actl = (Gfo_cmd_arg_itm)actl_obj;
|
||||
int err = 0;
|
||||
err += mgr.Tst_val(false, path, "key", key, actl.Key());
|
||||
err += mgr.Tst_val(false, path, "val", val, actl.Val());
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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.flds; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*;
|
||||
public class Gfo_fld_rdr_tst {
|
||||
Gfo_fld_rdr_fxt fxt = new Gfo_fld_rdr_fxt();
|
||||
@Test public void Read_int() {fxt.ini_xdat().Raw_("123|") .tst_Read_int(123);}
|
||||
@Test public void Read_double() {fxt.ini_xdat().Raw_("1.23|") .tst_Read_double(1.23);}
|
||||
@Test public void Read_str_simple() {fxt.ini_xdat().Raw_("ab|") .tst_Read_str_simple("ab");}
|
||||
@Test public void Read_str_escape_pipe() {fxt.ini_xdat().Raw_("a~pb|") .tst_Read_str_escape("a|b");}
|
||||
@Test public void Read_str_escape_tilde() {fxt.ini_xdat().Raw_("a~~b|") .tst_Read_str_escape("a~b");}
|
||||
@Test public void Read_str_escape_nl() {fxt.ini_xdat().Raw_("a~nb|") .tst_Read_str_escape("a\nb");}
|
||||
@Test public void Read_str_escape_tab() {fxt.ini_xdat().Raw_("a~tb|") .tst_Read_str_escape("a\tb");}
|
||||
@Test public void Write_str_escape_pipe() {fxt.ini_xdat().tst_Write_str_escape("a|b", "a~pb|");}
|
||||
@Test public void Read_str_quoted_comma() {fxt.ini_sql ().Raw_("'a,b',") .tst_Read_str_escape("a,b");}
|
||||
@Test public void Read_str_quoted_apos() {fxt.ini_sql ().Raw_("'a\\'b',") .tst_Read_str_escape("a'b");}
|
||||
@Test public void Read_multiple() {
|
||||
fxt.ini_xdat().Raw_("ab|1|.9|\n")
|
||||
.tst_Read_str_escape("ab").tst_Read_int(1).tst_Read_double(.9)
|
||||
;
|
||||
}
|
||||
@Test public void Read_dlm_nl() {fxt.ini_xdat().Raw_("123\n") .tst_Read_int(123);}
|
||||
}
|
||||
class Gfo_fld_rdr_fxt {
|
||||
Gfo_fld_rdr rdr = new Gfo_fld_rdr(); Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_();
|
||||
public Gfo_fld_rdr_fxt Raw_(String v) {rdr.Data_(Bry_.new_u8(v)); return this;}
|
||||
public Gfo_fld_rdr_fxt ini_xdat() {rdr.Ctor_xdat(); return this;}
|
||||
public Gfo_fld_rdr_fxt ini_sql() {rdr.Ctor_sql(); return this;}
|
||||
public Gfo_fld_rdr_fxt tst_Read_int(int expd) {Tfds.Eq(expd, rdr.Read_int()); return this;}
|
||||
public Gfo_fld_rdr_fxt tst_Read_double(double expd) {Tfds.Eq(expd, rdr.Read_double()); return this;}
|
||||
public Gfo_fld_rdr_fxt tst_Read_str_simple(String expd) {Tfds.Eq(expd, rdr.Read_str_simple()); return this;}
|
||||
public Gfo_fld_rdr_fxt tst_Read_str_escape(String expd) {Tfds.Eq(expd, rdr.Read_str_escape()); return this;}
|
||||
public Gfo_fld_rdr_fxt tst_Write_str_escape(String val, String expd) {
|
||||
byte[] bry = Bry_.new_u8(val);
|
||||
wtr.Bfr_(bfr);
|
||||
wtr.Write_bry_escape_fld(bry);
|
||||
Tfds.Eq(expd, bfr.To_str());
|
||||
return this;
|
||||
} private Bry_bfr bfr = Bry_bfr_.New();
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
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.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Gfobj_rdr__json_tst {
|
||||
private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt();
|
||||
@Test public void Type() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'k1':true"
|
||||
, ", 'k2':123"
|
||||
, ", 'k3':9876543210"
|
||||
, ", 'k4':1.23"
|
||||
, ", 'k5':null"
|
||||
, ", 'k6':'abc'"
|
||||
, "}"
|
||||
)
|
||||
, fxt.Make__nde
|
||||
( fxt.Make__fld_bool ("k1", true)
|
||||
, fxt.Make__fld_int ("k2", 123)
|
||||
, fxt.Make__fld_long ("k3", 9876543210L)
|
||||
, fxt.Make__fld_double ("k4", 1.23)
|
||||
, fxt.Make__fld_str ("k5", null)
|
||||
, fxt.Make__fld_str ("k6", "abc")
|
||||
));
|
||||
}
|
||||
@Test public void Nested() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "{ 'a1':'1a'"
|
||||
, ", 'a2':"
|
||||
, " { 'b1':'1b'"
|
||||
, " , 'b2':"
|
||||
, " { 'c1':'1c'"
|
||||
, " }"
|
||||
, " }"
|
||||
, ", 'a3':[1, 2, 3]"
|
||||
, "}"
|
||||
)
|
||||
, fxt.Make__nde
|
||||
( fxt.Make__fld_str ("a1", "1a")
|
||||
, fxt.Make__fld_nde ("a2"
|
||||
, fxt.Make__fld_str("b1", "1b")
|
||||
, fxt.Make__fld_nde("b2"
|
||||
, fxt.Make__fld_str("c1", "1c"))
|
||||
)
|
||||
, fxt.Make__fld_ary ("a3", 1, 2, 3)
|
||||
));
|
||||
}
|
||||
@Test public void Array() {
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "["
|
||||
, " [1, 2, 3]"
|
||||
, ", ['a', 'b', 'c']"
|
||||
, ", [true, false]"
|
||||
, ", [9876543210, 9876543211, 9876543212]"
|
||||
//, ", [1.23, 1.24, 1.25]"
|
||||
, ", [{'a':1}, {'b':2}, {'c':3}]"
|
||||
, "]"
|
||||
)
|
||||
, fxt.Make__ary
|
||||
( fxt.Make__ary (1, 2, 3)
|
||||
, fxt.Make__ary ("a", "b", "c")
|
||||
, fxt.Make__ary (true, false)
|
||||
, fxt.Make__ary (9876543210L, 9876543211L, 9876543212L)
|
||||
// , fxt.Make__ary (1.23, 1.24, 1.25)
|
||||
, fxt.Make__ary
|
||||
( fxt.Make__nde(fxt.Make__fld_int("a", 1))
|
||||
, fxt.Make__nde(fxt.Make__fld_int("b", 2))
|
||||
, fxt.Make__nde(fxt.Make__fld_int("c", 3))
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
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.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.tests.*; import gplx.langs.jsons.*;
|
||||
public class Gfobj_wtr__json_fxt {
|
||||
protected final Gfobj_wtr__json mgr = new Gfobj_wtr__json();
|
||||
public Gfobj_nde Make__nde(Gfobj_fld... ary) {return Make__nde(Gfobj_nde.New(), ary);}
|
||||
private Gfobj_nde Make__nde(Gfobj_nde nde, Gfobj_fld[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfobj_fld fld = (Gfobj_fld)ary[i];
|
||||
nde.Add_fld(fld);
|
||||
}
|
||||
return nde;
|
||||
}
|
||||
public Gfobj_fld Make__fld_bool (String key, boolean val) {return new Gfobj_fld_bool(key, val);}
|
||||
public Gfobj_fld Make__fld_str (String key, String val) {return new Gfobj_fld_str(key, val);}
|
||||
public Gfobj_fld Make__fld_int (String key, int val) {return new Gfobj_fld_int(key, val);}
|
||||
public Gfobj_fld Make__fld_long (String key, long val) {return new Gfobj_fld_long(key, val);}
|
||||
public Gfobj_fld Make__fld_double (String key, double val) {return new Gfobj_fld_double(key, val);}
|
||||
public Gfobj_fld Make__fld_nde(String key, Gfobj_fld... ary) {
|
||||
Gfobj_nde nde = Make__nde(Gfobj_nde.New(), ary);
|
||||
Gfobj_fld_nde rv = new Gfobj_fld_nde(key, nde);
|
||||
return rv;
|
||||
}
|
||||
public Gfobj_fld Make__fld_ary (String key, Object... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary(ary));}
|
||||
public Gfobj_ary Make__ary (Object... ary) {return new Gfobj_ary(ary);}
|
||||
public Gfobj_wtr__json_fxt Test__write(Gfobj_grp root, String... lines) {
|
||||
String[] expd = Json_doc.Make_str_ary_by_apos(lines);
|
||||
Gftest.Eq__ary(expd, Bry_.Ary(String_.SplitLines_nl(mgr.Write(root).To_str())), "json_write");
|
||||
return this;
|
||||
}
|
||||
public Gfobj_wtr__json_fxt Test__parse(String src, Gfobj_grp expd) {
|
||||
Gfobj_rdr__json rdr = new Gfobj_rdr__json();
|
||||
Gfobj_grp actl = rdr.Parse(Bry_.new_u8(Json_doc.Make_str_by_apos(src)));
|
||||
Gftest.Eq__ary(Bry_.Ary(String_.SplitLines_nl(mgr.Write(expd).To_str())), Bry_.Ary(String_.SplitLines_nl(mgr.Write(actl).To_str())), "json_write");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
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.gfobjs; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Gfobj_wtr__json_tst {
|
||||
private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt();
|
||||
@Test public void Flds() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_long ("k2", 2)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':2"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Sub_ndes() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_nde ("k2"
|
||||
, fxt.Make__fld_str ("k2a", "v2a")
|
||||
, fxt.Make__fld_int ("k2b", 2)
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " { 'k2a':'v2a'"
|
||||
, " , 'k2b':2"
|
||||
, " }"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_str() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary ("k2", "a1", "a2", "a3")
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " [ 'a1'"
|
||||
, " , 'a2'"
|
||||
, " , 'a3'"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_int() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary ("k2", 1, 2, 3)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_nde() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary ("k2"
|
||||
, fxt.Make__nde (fxt.Make__fld_str("k21", "v21"))
|
||||
, fxt.Make__nde (fxt.Make__fld_str("k22", "v22"))
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " ["
|
||||
, " { 'k21':'v21'"
|
||||
, " }"
|
||||
, " ,"
|
||||
, " { 'k22':'v22'"
|
||||
, " }"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Ary_ary() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__nde
|
||||
( fxt.Make__fld_str ("k1", "v1")
|
||||
, fxt.Make__fld_ary ("k2"
|
||||
, fxt.Make__ary (1, 2, 3)
|
||||
, fxt.Make__ary (4, 5, 6)
|
||||
)
|
||||
, fxt.Make__fld_int ("k3", 3)
|
||||
)
|
||||
, "{ 'k1':'v1'"
|
||||
, ", 'k2':"
|
||||
, " ["
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, " ,"
|
||||
, " [ 4"
|
||||
, " , 5"
|
||||
, " , 6"
|
||||
, " ]"
|
||||
, " ]"
|
||||
, ", 'k3':3"
|
||||
, "}"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Root_ary() {
|
||||
fxt.Test__write
|
||||
( fxt.Make__ary(1, 2, 3)
|
||||
, "[ 1"
|
||||
, ", 2"
|
||||
, ", 3"
|
||||
, "]"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
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 String_surrogate_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private String_surrogate_utl_fxt fxt = new String_surrogate_utl_fxt();
|
||||
@Test public void Char_idx() {
|
||||
String test_str = "aé𡼾bî𡼾";
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 0, 1, 0, 1); // a
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 0, 2, 0, 3); // aé
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 0, 3, 1, 7); // aé𡼾
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 7, 1, 0, 8); // b
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 7, 2, 0, 10); // bî
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 7, 3, 1, 14); // bî𡼾
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 0, 6, 2, 14); // aé𡼾bî𡼾
|
||||
fxt.Test_count_surrogates__char_idx (test_str, 14, 7, 0, 14); // PURPOSE: test out of bounds; DATE:2014-09-02
|
||||
}
|
||||
@Test public void Codepoint_idx() {
|
||||
String test_str = "aé𡼾bî𡼾";
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 1, 0, 1); // a
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 2, 0, 3); // aé
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 4, 1, 7); // aé𡼾
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 1, 0, 8); // b
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 2, 0, 10); // bî
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 4, 1, 14); // bî𡼾
|
||||
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 8, 2, 14); // aé𡼾bî𡼾
|
||||
}
|
||||
}
|
||||
class String_surrogate_utl_fxt {
|
||||
private String_surrogate_utl codepoint_utl = new String_surrogate_utl();
|
||||
public void Clear() {}
|
||||
public void Test_count_surrogates__char_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str); int src_len = src_bry.length;
|
||||
Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__char_idx(src_bry, src_len, bgn_byte, char_idx));
|
||||
Tfds.Eq(expd_pos , codepoint_utl.Byte_pos());
|
||||
}
|
||||
public void Test_count_surrogates__codepoint_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str); int src_len = src_bry.length;
|
||||
Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__codepoint_idx1(src_bry, src_len, bgn_byte, char_idx), "count");
|
||||
Tfds.Eq(expd_pos , codepoint_utl.Byte_pos(), "pos");
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
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 BinaryHeap_Io_line_rdr_tst {
|
||||
BinaryHeap_Io_line_rdr_fxt fxt = new BinaryHeap_Io_line_rdr_fxt();
|
||||
@Test public void Add() {
|
||||
fxt.Add("c", "a", "b").tst("a", "b", "c");
|
||||
fxt.Add("b", "a", "a").tst("a", "a", "b");
|
||||
fxt.Add("f", "b", "d", "c", "e", "a").tst("a", "b", "c", "d", "e", "f");
|
||||
}
|
||||
}
|
||||
class BinaryHeap_Io_line_rdr_fxt {
|
||||
BinaryHeap_Io_line_rdr heap = new BinaryHeap_Io_line_rdr(Io_sort_split_itm_sorter.Instance); int file_total;
|
||||
public BinaryHeap_Io_line_rdr_fxt Add(String... ary) {
|
||||
file_total = ary.length;
|
||||
for (int i = 0; i < file_total; i++) {
|
||||
Io_url url = Io_url_.mem_fil_("mem/fil_" + ary[i] + ".txt");
|
||||
Io_mgr.Instance.SaveFilStr(url, ary[i]);
|
||||
Io_line_rdr stream = new Io_line_rdr(Gfo_usr_dlg_.Test(), url);
|
||||
stream.Read_next();
|
||||
heap.Add(stream);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public BinaryHeap_Io_line_rdr_fxt tst(String... expd) {
|
||||
String[] actl = new String[file_total];
|
||||
for (int i = 0; i < actl.length; i++) {
|
||||
Io_line_rdr bfr = heap.Pop();
|
||||
actl[i] = String_.new_u8(bfr.Bfr(), 0, bfr.Bfr_len());
|
||||
}
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
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.ios.*; import gplx.core.ios.streams.*;
|
||||
public class Io_buffer_rdr_tst {
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
fil = Io_url_.mem_fil_("mem/byteStreamRdr.txt");
|
||||
ini_Write("0123456789");
|
||||
rdr = Io_buffer_rdr.new_(Io_stream_rdr_.New__raw(fil), 4);
|
||||
} Io_buffer_rdr rdr; Io_url fil;
|
||||
@After public void teardown() {rdr.Rls();}
|
||||
@Test public void Bfr_load_all() {
|
||||
tst_Bfr("0", "1", "2", "3").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_all();
|
||||
tst_Bfr("4", "5", "6", "7").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_all();
|
||||
tst_Bfr("8", "9");
|
||||
rdr.Bfr_load_all(); // NOTE: change to zip_rdrs make eof detection difficult; force another load to ensure that file_pos goes past file_len
|
||||
tst_ReadDone(true); // NOTE: bfr truncated from 4 to 2
|
||||
}
|
||||
@Test public void Bfr_load_from() {
|
||||
tst_Bfr("0", "1", "2", "3").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_from(3); // read from pos 3
|
||||
tst_Bfr("3", "4", "5", "6").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_from(1); // read from pos 1
|
||||
tst_Bfr("4", "5", "6", "7").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_from(1);
|
||||
tst_Bfr("5", "6", "7", "8").tst_ReadDone(false);
|
||||
|
||||
rdr.Bfr_load_from(3);
|
||||
rdr.Bfr_load_all(); // NOTE: change to zip_rdrs make eof detection difficult; force another load to ensure that file_pos goes past file_len
|
||||
tst_Bfr("8", "9").tst_ReadDone(true);
|
||||
}
|
||||
private void ini_Write(String s) {Io_mgr.Instance.SaveFilStr(fil, s);}
|
||||
Io_buffer_rdr_tst tst_Bfr(String... expdAry) {
|
||||
String[] actlAry = new String[rdr.Bfr_len()];
|
||||
for (int i = 0; i < actlAry.length; i++)
|
||||
actlAry[i] = String_.new_u8(rdr.Bfr(), i, i + 1);
|
||||
Tfds.Eq_ary(expdAry, actlAry);
|
||||
return this;
|
||||
}
|
||||
Io_buffer_rdr_tst tst_ReadDone(boolean expd) {Tfds.Eq(expd, rdr.Fil_eof()); return this;}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
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_line_rdr_tst {
|
||||
Io_line_rdr_fxt fxt;
|
||||
@Before public void init() {
|
||||
fxt = new Io_line_rdr_fxt(Io_url_.new_fil_("mem/test.txt"));
|
||||
fxt.Clear();
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.File_lines_(3).tst_Read_til_lines(3, "00", "01", "02");
|
||||
fxt.tst_Read_til_lines(1); // make sure nothing more is read
|
||||
}
|
||||
@Test public void Load_3x() {
|
||||
fxt.File_lines_(9).Load_len_lines_(3).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08");
|
||||
}
|
||||
@Test public void Load_irregular() {
|
||||
fxt.File_lines_(9).Load_len_(4).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08");
|
||||
}
|
||||
@Test public void Load_multiple_files() {
|
||||
fxt = new Io_line_rdr_fxt(Io_url_.new_fil_("mem/test0.txt"), Io_url_.new_fil_("mem/test1.txt"), Io_url_.new_fil_("mem/test2.txt"));
|
||||
fxt.File_lines_(0, 0, 3).File_lines_(1, 3, 5).File_lines_(2, 5, 9).Load_len_(4).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08");
|
||||
}
|
||||
@Test public void Match() {
|
||||
fxt.File_lines_pipe_(9).Load_len_(6);
|
||||
fxt.tst_Match("00", "00");
|
||||
fxt.tst_Match("01", "01");
|
||||
fxt.tst_Match("03", "03");
|
||||
fxt.tst_Match("08", "08");
|
||||
fxt.tst_Match("12", "");
|
||||
}
|
||||
}
|
||||
class Io_line_rdr_fxt {
|
||||
Io_line_rdr rdr;
|
||||
List_adp lines = List_adp_.New(); Bry_bfr tmp = Bry_bfr_.New();
|
||||
public Io_line_rdr_fxt(Io_url... urls) {rdr = new Io_line_rdr(Gfo_usr_dlg_.Test(), urls);}
|
||||
public Io_line_rdr_fxt Load_len_lines_(int v) {return Load_len_(v * 3);} // 3: 2=##, 1=\n
|
||||
public Io_line_rdr_fxt Load_len_(int v) {rdr.Load_len_(v); return this;}
|
||||
public Io_line_rdr_fxt File_lines_(int count) {
|
||||
for (int i = 0; i < count; i++)
|
||||
tmp.Add_int_fixed(i, 2).Add_byte_nl();
|
||||
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
|
||||
return this;
|
||||
}
|
||||
// public Io_url[] Src_fils() {return src_fils;} public Io_line_rdr_fxt Src_fils_(Io_url[] v) {src_fils = v; return this;} Io_url[] src_fils;
|
||||
public Io_line_rdr_fxt tst_Match(String match, String expd) {
|
||||
rdr.Key_gen_(Io_line_rdr_key_gen_.first_pipe);
|
||||
boolean match_v = rdr.Match(Bry_.new_u8(match));
|
||||
String actl = match_v ? String_.new_u8(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end()) : "";
|
||||
Tfds.Eq(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Io_line_rdr_fxt File_lines_pipe_(int count) {
|
||||
for (int i = 0; i < count; i++)
|
||||
tmp.Add_int_fixed(i, 2).Add_byte(Byte_ascii.Pipe).Add_byte_nl();
|
||||
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Io_line_rdr_fxt File_lines_(int fil_idx, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++)
|
||||
tmp.Add_int_fixed(i, 2).Add_byte_nl();
|
||||
Io_mgr.Instance.SaveFilBry(rdr.Urls()[fil_idx], tmp.To_bry_and_clear());
|
||||
return this;
|
||||
}
|
||||
public Io_line_rdr_fxt Clear() {rdr.Clear(); return this;}
|
||||
public Io_line_rdr_fxt tst_Read_til_lines(int count, String... expd) {
|
||||
lines.Clear();
|
||||
for (int i = 0; i < expd.length; i++)
|
||||
expd[i] = expd[i] + Op_sys.Lnx.Nl_str();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (rdr.Read_next())
|
||||
lines.Add(String_.new_u8(rdr.Bfr(), rdr.Itm_pos_bgn(), rdr.Itm_pos_end()));
|
||||
else
|
||||
break;
|
||||
}
|
||||
Tfds.Eq_ary_str(expd, lines.To_str_ary());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
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_sort_misc_tst {
|
||||
@Before public void init() {
|
||||
}
|
||||
@Test public void Io_url_gen_dir() {
|
||||
tst_Io_url_gen_dir("mem/dir/", "{0}.xdat", 4, 3, "0000.xdat", "0001.xdat", "0002.xdat");
|
||||
}
|
||||
private void tst_Io_url_gen_dir(String dir_str, String fmt, int digits, int calls, String... expd) {
|
||||
Io_url dir = Io_url_.mem_dir_(dir_str);
|
||||
List_adp actl_list = List_adp_.New();
|
||||
Io_url_gen wkr = Io_url_gen_.dir_(dir, fmt, digits);
|
||||
for (int i = 0; i < calls; i++)
|
||||
actl_list.Add(wkr.Nxt_url().Raw());
|
||||
String[] actl = actl_list.To_str_ary();
|
||||
for (int i = 0; i < expd.length; i++)
|
||||
expd[i] = dir_str + expd[i];
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
@Test public void Io_line_rdr_comparer_all() {
|
||||
tst_Io_line_rdr_fld_comparer(-1, "a", "b");
|
||||
tst_Io_line_rdr_fld_comparer( 0, "a", "a");
|
||||
tst_Io_line_rdr_fld_comparer( 1, "b", "a");
|
||||
tst_Io_line_rdr_fld_comparer(-1, "a", "ab");
|
||||
tst_Io_line_rdr_fld_comparer( 1, "ab", "a");
|
||||
}
|
||||
private void tst_Io_line_rdr_fld_comparer(int expd, String lhs_str, String rhs_str) {
|
||||
byte[] lhs = Bry_.new_u8(lhs_str), rhs = Bry_.new_u8(rhs_str);
|
||||
Tfds.Eq(expd, Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length));
|
||||
}
|
||||
Io_line_rdr new_Io_line_rdr(String url_str, String text) {
|
||||
Io_url url = Io_url_.mem_fil_(url_str);
|
||||
Io_mgr.Instance.SaveFilStr(url, text);
|
||||
Io_line_rdr rv = new Io_line_rdr(Gfo_usr_dlg_.Test(), url);
|
||||
rv.Read_next();
|
||||
return rv;
|
||||
}
|
||||
@Test public void ExternalSort() {
|
||||
// fxt("c", "a", "b")
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
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.strings.*;
|
||||
public class Io_sort_tst {
|
||||
Io_sort_fxt fxt = new Io_sort_fxt();
|
||||
@Test public void ExternalSort() {
|
||||
fxt.Clear().Memory_max_(12).Src_(fxt.GenRandom(6, 4)).Sorted_(fxt.GenOrdered(6, 4)).tst();
|
||||
fxt.Clear().Memory_max_(64).Src_(fxt.GenRandom(50, 4)).Sorted_(fxt.GenOrdered(50, 4)).tst();
|
||||
}
|
||||
}
|
||||
class Io_sort_fxt {
|
||||
Io_sort externalSort = new Io_sort().Memory_max_(Io_mgr.Len_kb);
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
public Io_sort_fxt Clear() {Io_mgr.Instance.InitEngine_mem(); return this;}
|
||||
public Io_sort_fxt Memory_max_(int v) {externalSort.Memory_max_(v); return this;}
|
||||
public Io_sort_fxt Src_(String v) {src = v; return this;} private String src;
|
||||
public Io_sort_fxt Sorted_(String v) {sorted = v; return this;} private String sorted;
|
||||
public void tst() {
|
||||
Io_url src_url = Io_url_.mem_fil_("mem/src.txt");
|
||||
Io_url trg_url = Io_url_.mem_fil_("mem/trg.txt");
|
||||
Io_mgr.Instance.DeleteFil(src_url); Io_mgr.Instance.DeleteFil(trg_url);
|
||||
|
||||
Io_mgr.Instance.SaveFilStr(src_url, src);
|
||||
|
||||
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
|
||||
Io_url_gen src_fil_gen = Io_url_gen_.fil_(src_url);
|
||||
Io_url[] tmp_url_ary = externalSort.Split(usr_dlg, src_fil_gen, Io_url_gen_.dir_(src_url.OwnerDir()), Io_line_rdr_key_gen_.first_pipe);
|
||||
Io_sort_fil_basic cmd = new Io_sort_fil_basic(usr_dlg, Io_url_gen_.fil_(trg_url), Io_mgr.Len_kb);
|
||||
externalSort.Merge(usr_dlg, tmp_url_ary, Io_sort_split_itm_sorter.Instance, Io_line_rdr_key_gen_.first_pipe, cmd);
|
||||
|
||||
String actl = Io_mgr.Instance.LoadFilStr(trg_url);
|
||||
Tfds.Eq_ary_str(String_.SplitLines_nl(sorted), String_.SplitLines_nl(actl));
|
||||
}
|
||||
public String GenRandom(int rows, int pad) {
|
||||
List_adp list = List_adp_.New();
|
||||
for (int i = 0; i < rows; i++)
|
||||
list.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|");
|
||||
list.Shuffle();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
String itm = (String)list.Get_at(i);
|
||||
sb.Add(itm).Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
public String GenOrdered(int rows, int pad) {
|
||||
for (int i = 0; i < rows; i++)
|
||||
sb.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|" + "\n");
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
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.*; import gplx.core.tests.*;
|
||||
public class Queue_adp_tst {
|
||||
private final Queue_adp_fxt fxt = new Queue_adp_fxt();
|
||||
@Test public void Empty() {
|
||||
boolean pass = true;
|
||||
try {
|
||||
fxt.Test__dequeue(null, -1);
|
||||
pass = false;
|
||||
} catch (Exception e) {
|
||||
Err_.Noop(e);
|
||||
return;
|
||||
}
|
||||
if (pass) throw Err_.new_wo_type("empty should have failed");
|
||||
}
|
||||
@Test public void Add_1() {
|
||||
fxt.Exec__enqueue("a");
|
||||
fxt.Test__dequeue("a", 0);
|
||||
}
|
||||
@Test public void Add_n() {
|
||||
fxt.Exec__enqueue("a");
|
||||
fxt.Exec__enqueue("b");
|
||||
fxt.Exec__enqueue("c");
|
||||
fxt.Test__dequeue("a", 2);
|
||||
fxt.Test__dequeue("b", 1);
|
||||
fxt.Test__dequeue("c", 0);
|
||||
}
|
||||
@Test public void Mix() {
|
||||
fxt.Exec__enqueue("a");
|
||||
fxt.Exec__enqueue("b");
|
||||
fxt.Test__dequeue("a", 1);
|
||||
fxt.Exec__enqueue("c");
|
||||
fxt.Test__dequeue("b", 1);
|
||||
fxt.Test__dequeue("c", 0);
|
||||
}
|
||||
}
|
||||
class Queue_adp_fxt {
|
||||
private final Queue_adp queue = new Queue_adp();
|
||||
public void Exec__enqueue(String s) {queue.Enqueue(s);}
|
||||
public void Test__dequeue(String expd_data, int expd_len) {
|
||||
Gftest.Eq__str(expd_data, (String)queue.Dequeue());
|
||||
Gftest.Eq__int(expd_len , queue.Count());
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
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 StatRng_tst {
|
||||
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance;
|
||||
StatRng_fxt fx = new StatRng_fxt();
|
||||
@Test public void Empty() {
|
||||
fx.ini_(1, 1, 5);
|
||||
fx.Count_(7).Lo_(2).Hi_(8).Avg_(5)
|
||||
.Lo_ary_(2)
|
||||
.Hi_ary_(8)
|
||||
.Slots_(3, 4);
|
||||
fx.tst_(5,7,2,8,3,4,6);
|
||||
}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a=1|b=2|3}}", "{{test|a}}", "1");}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|b=2|#default=3|a=1}}", "{{test|a}}", "1");}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a|b|c=1|d=2}}", "{{test|a}}", "1");}
|
||||
}
|
||||
/*
|
||||
public class Pf_func_switch_tst {
|
||||
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance;
|
||||
|
||||
*/
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
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.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
import org.junit.*; import gplx.core.primitives.*;
|
||||
public class Binary_search__tst {
|
||||
private final Binary_search__fxt fxt = new Binary_search__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__ary("", "e", "j", "o", "t", "y");
|
||||
fxt.Test__binary_search("a", 0);
|
||||
fxt.Test__binary_search("f", 1);
|
||||
fxt.Test__binary_search("k", 2);
|
||||
fxt.Test__binary_search("p", 3);
|
||||
fxt.Test__binary_search("u", 4);
|
||||
fxt.Test__binary_search("z", 5);
|
||||
}
|
||||
@Test public void One() {
|
||||
fxt.Init__ary("");
|
||||
fxt.Test__binary_search("a", 0);
|
||||
}
|
||||
@Test public void Catpage() {
|
||||
String[] ary = new String[25];
|
||||
for (int i = 0; i < 25; ++i)
|
||||
ary[i] = Int_.To_str_pad_bgn_zero(i, 2);
|
||||
fxt.Init__ary(ary);
|
||||
fxt.Test__binary_search("10", 10); // was 9
|
||||
}
|
||||
}
|
||||
class Binary_search__fxt {
|
||||
private String_obj_val[] ary;
|
||||
public void Init__ary(String... v) {
|
||||
int ary_len = v.length;
|
||||
ary = new String_obj_val[ary_len];
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
ary[i] = String_obj_val.new_(v[i]);
|
||||
}
|
||||
public void Test__binary_search(String val, int expd) {
|
||||
int actl = Binary_search_.Search(ary, String_obj_val.new_(val));
|
||||
Tfds.Eq(expd, actl, val);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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.net; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.net.qargs.*;
|
||||
class Gfo_url_parser_fxt {
|
||||
private final Gfo_url_parser parser = new Gfo_url_parser();
|
||||
private Gfo_url actl;
|
||||
public Gfo_url_parser_fxt Test__protocol_tid(byte v) {Tfds.Eq_byte(v, actl.Protocol_tid(), "protocol_tid"); return this;}
|
||||
public Gfo_url_parser_fxt Test__protocol_bry(String v) {Tfds.Eq_str(v, actl.Protocol_bry(), "protocol_bry"); return this;}
|
||||
public Gfo_url_parser_fxt Test__site(String v) {Tfds.Eq_str(v, actl.Segs__get_at_1st(), "site"); return this;}
|
||||
public Gfo_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl.Segs__get_at_nth(), "page"); return this;}
|
||||
public Gfo_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl.Anch(), "anch"); return this;}
|
||||
public Gfo_url_parser_fxt Test__segs(String... ary) {
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl(ary), String_.Concat_lines_nl(String_.Ary(actl.Segs())), "segs");
|
||||
Tfds.Eq_int(ary.length, actl.Segs().length, "segs_len");
|
||||
return this;
|
||||
}
|
||||
public Gfo_url_parser_fxt Test__qargs(String... ary) {Tfds.Eq_str_lines(String_.To_str__as_kv_ary(ary), Qargs__To_str(actl.Qargs()), "qargs"); return this;}
|
||||
public Gfo_url_parser_fxt Exec__parse(String v) {
|
||||
this.actl = parser.Parse(Bry_.new_u8(v), 0, String_.Len(v));
|
||||
return this;
|
||||
}
|
||||
public void Test_Parse_site_fast(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
parser.Parse_site_fast(site_data, raw_bry, 0, raw_bry.length);
|
||||
String actl = String_.new_u8(raw_bry, site_data.Site_bgn(), site_data.Site_end());
|
||||
Tfds.Eq(expd, actl);
|
||||
} private final Gfo_url_site_data site_data = new Gfo_url_site_data();
|
||||
private static String Qargs__To_str(Gfo_qarg_itm[] ary) {
|
||||
int len = ary.length;
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_qarg_itm itm = ary[i];
|
||||
bfr.Add(itm.Key_bry()).Add_byte_eq();
|
||||
if (itm.Val_bry() != null)
|
||||
bfr.Add(itm.Val_bry());
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
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.net; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Gfo_url_parser_tst {
|
||||
private final Gfo_url_parser_fxt tstr = new Gfo_url_parser_fxt();
|
||||
@Test public void Protocol__relative() {
|
||||
tstr.Exec__parse("//en.wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_relative_1).Test__protocol_bry("//").Test__site("en.wikipedia.org");
|
||||
}
|
||||
@Test public void Protocol__none() {
|
||||
tstr.Exec__parse("en.wikipedia.org/wiki/A").Test__protocol_tid(Gfo_protocol_itm.Tid_unknown).Test__segs("en.wikipedia.org", "wiki", "A");
|
||||
}
|
||||
@Test public void Site__parts__3() {
|
||||
tstr.Exec__parse("https://en.wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__protocol_bry("https://").Test__segs("en.wikipedia.org");
|
||||
}
|
||||
@Test public void Site__parts__2() {
|
||||
tstr.Exec__parse("https://wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__segs("wikipedia.org");
|
||||
}
|
||||
@Test public void Site__parts__1() {
|
||||
tstr.Exec__parse("https://wikipedia").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__segs("wikipedia");
|
||||
}
|
||||
@Test public void Site__slash__none() {
|
||||
tstr.Exec__parse("https:site").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("site");
|
||||
}
|
||||
@Test public void Site__slash__eos() {
|
||||
tstr.Exec__parse("https://en.wikipedia.org/").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("en.wikipedia.org");
|
||||
}
|
||||
@Test public void Paths__1() {
|
||||
tstr.Exec__parse("https://site/A").Test__segs("site", "A");
|
||||
}
|
||||
@Test public void Paths__2() {
|
||||
tstr.Exec__parse("https://site/wiki/A").Test__segs("site", "wiki", "A");
|
||||
}
|
||||
@Test public void Paths__n() {
|
||||
tstr.Exec__parse("https://site/wiki/A/B/C/D").Test__segs("site", "wiki", "A", "B", "C", "D");
|
||||
}
|
||||
@Test public void Qargs__1() {
|
||||
tstr.Exec__parse("https://site/A?B=C").Test__page("A").Test__qargs("B", "C");
|
||||
}
|
||||
@Test public void Qargs__2() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D=E").Test__page("A").Test__qargs("B", "C", "D", "E");
|
||||
}
|
||||
@Test public void Qargs__3() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D=E&F=G").Test__page("A").Test__qargs("B", "C", "D", "E", "F", "G");
|
||||
}
|
||||
@Test public void Qargs__ques__dupe__ques() {
|
||||
tstr.Exec__parse("https://site/A?B?Y=Z").Test__page("A?B").Test__qargs("Y", "Z");
|
||||
}
|
||||
@Test public void Qargs__ques__dupe__amp() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D?Y=Z").Test__page("A?B=C&D").Test__qargs("Y", "Z");
|
||||
}
|
||||
@Test public void Qargs__ques__dupe__eq() {
|
||||
tstr.Exec__parse("https://site/A?B=C?Y=Z").Test__page("A?B=C").Test__qargs("Y", "Z");
|
||||
}
|
||||
@Test public void Qargs__amp__dupe__ques() {
|
||||
tstr.Exec__parse("https://site/A?B&Y=Z").Test__page("A").Test__qargs("B", null, "Y", "Z");
|
||||
}
|
||||
@Test public void Qargs__amp__dupe__amp() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D&Y=Z").Test__page("A").Test__qargs("B", "C", "D", null, "Y", "Z");
|
||||
}
|
||||
@Test public void Qargs__missing_val__0() {
|
||||
tstr.Exec__parse("https://site/A?").Test__page("A?").Test__qargs();
|
||||
}
|
||||
@Test public void Qargs__missing_val__2() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D&F=G").Test__page("A").Test__qargs("B", "C", "D", null, "F", "G");
|
||||
}
|
||||
@Test public void Qargs__missing_val__n() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D=E&F").Test__page("A").Test__qargs("B", "C", "D", "E", "F", null);
|
||||
}
|
||||
@Test public void Qargs__site_less__missing__0() {
|
||||
tstr.Exec__parse("A?B").Test__segs("A?B").Test__qargs();
|
||||
}
|
||||
@Test public void Qargs__site_less() {
|
||||
tstr.Exec__parse("A?B=C&D=E").Test__site("A").Test__qargs("B", "C", "D", "E");
|
||||
}
|
||||
@Test public void Anch__basic() {
|
||||
tstr.Exec__parse("https://site/A#B").Test__page("A").Test__anch("B");
|
||||
}
|
||||
@Test public void Anch__repeat__2() {
|
||||
tstr.Exec__parse("https://site/A#B#C").Test__page("A").Test__anch("B#C");
|
||||
}
|
||||
@Test public void Anch__repeat__3() {
|
||||
tstr.Exec__parse("https://site/A#B#C#D").Test__page("A").Test__anch("B#C#D");
|
||||
}
|
||||
@Test public void Anch__missing() {
|
||||
tstr.Exec__parse("https://site/A#").Test__page("A#").Test__anch(null);
|
||||
}
|
||||
@Test public void Anch__missing__eos() {
|
||||
tstr.Exec__parse("https://site/A#B#").Test__page("A").Test__anch("B#");
|
||||
}
|
||||
@Test public void Anch__qargs__basic() {
|
||||
tstr.Exec__parse("https://site/A?B=C&D=E#F").Test__page("A").Test__qargs("B", "C", "D", "E").Test__anch("F");
|
||||
}
|
||||
@Test public void Anch__site_less() {
|
||||
tstr.Exec__parse("A#B").Test__site("A").Test__anch("B");
|
||||
}
|
||||
@Test public void Encode__page() {
|
||||
tstr.Exec__parse("http://site/A%27s").Test__site("site").Test__page("A's");
|
||||
}
|
||||
@Test public void Protocol_less__qargs() {
|
||||
tstr.Exec__parse("Special:Search/Earth?fulltext=yes").Test__segs("Special:Search", "Earth").Test__page("Earth").Test__qargs("fulltext", "yes");
|
||||
}
|
||||
@Test public void Parse_site_fast() {
|
||||
tstr.Test_Parse_site_fast("http://a.org/B" , "a.org");
|
||||
tstr.Test_Parse_site_fast("http://a.org" , "a.org");
|
||||
tstr.Test_Parse_site_fast("//a.org/B" , "a.org");
|
||||
tstr.Test_Parse_site_fast("//a.org/B:C" , "a.org");
|
||||
}
|
||||
// DELETED: logic isn't right; anch is first # not last; EX: https://en.wikipedia.org/w/index.php?title=Category:2001_albums&pagefrom=Beautiful+#View#mw-pages; DATE:2016-10-10
|
||||
// @Test public void Anch__qargs__repeat() {
|
||||
// tstr.Exec__parse("https://site/A?B=C#&D=E#F").Test__page("A").Test__qargs("B", "C#", "D", "E").Test__anch("F");
|
||||
// }
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
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.net; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Http_request_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Http_request_parser_fxt fxt = new Http_request_parser_fxt();
|
||||
@Test public void Type_post() {
|
||||
fxt.Test_type_post("POST /url HTTP/1.1", Http_request_itm.Type_post, "/url", "HTTP/1.1");
|
||||
}
|
||||
@Test public void Type_content_type() {
|
||||
fxt.Test_content_type("Content-Type: multipart/form-data; boundary=---------------------------72432484930026", "multipart/form-data", "-----------------------------72432484930026");
|
||||
}
|
||||
@Test public void Type_content_type__x_www_form_url_encoded() { // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04
|
||||
fxt.Test_content_type("Content-Type: application/x-www-form-urlencoded", null, null);
|
||||
}
|
||||
@Test public void Type_form_data() {
|
||||
fxt.Test_form_data(String_.Ary
|
||||
( "POST /url HTTP/1.1"
|
||||
, "Content-Type: multipart/form-data; boundary=---------------------------12345678901234"
|
||||
, ""
|
||||
, "-----------------------------12345678901234"
|
||||
, "Content-Disposition: form-data; name=\"key0\""
|
||||
, ""
|
||||
, "val0"
|
||||
, "-----------------------------12345678901234"
|
||||
, "Content-Disposition: form-data; name=\"key1\""
|
||||
, ""
|
||||
, "val1"
|
||||
, "-----------------------------12345678901234--"
|
||||
)
|
||||
, fxt.Make_post_data_itm("key0", "val0")
|
||||
, fxt.Make_post_data_itm("key1", "val1")
|
||||
);
|
||||
}
|
||||
@Test public void Type_accept_charset() {
|
||||
fxt.Test_ignore("Accept-Charset: ISO-8859-1,utf-8;q=0.7");
|
||||
}
|
||||
}
|
||||
class Http_request_parser_fxt {
|
||||
private final Http_request_parser parser;
|
||||
private final Http_client_rdr client_rdr = Http_client_rdr_.new_mem();
|
||||
private final Http_server_wtr__mock server_wtr = new Http_server_wtr__mock();
|
||||
public Http_request_parser_fxt() {
|
||||
this.parser = new Http_request_parser(server_wtr, false);
|
||||
}
|
||||
public void Clear() {
|
||||
parser.Clear();
|
||||
server_wtr.Clear();
|
||||
}
|
||||
public Http_post_data_itm Make_post_data_itm(String key, String val) {return new Http_post_data_itm(Bry_.new_u8(key), Bry_.new_u8(val));}
|
||||
public void Test_type_post(String line, int expd_type, String expd_url, String expd_protocol) {
|
||||
client_rdr.Stream_(String_.Ary(line));
|
||||
Http_request_itm req = parser.Parse(client_rdr);
|
||||
Tfds.Eq(expd_type , req.Type());
|
||||
Tfds.Eq(expd_url , String_.new_u8(req.Url()));
|
||||
Tfds.Eq(expd_protocol , String_.new_u8(req.Protocol()));
|
||||
}
|
||||
public void Test_content_type(String line, String expd_content_type, String expd_content_boundary) {
|
||||
client_rdr.Stream_(String_.Ary(line));
|
||||
Http_request_itm req = parser.Parse(client_rdr);
|
||||
Tfds.Eq(expd_content_type , String_.new_u8(req.Content_type()));
|
||||
Tfds.Eq(expd_content_boundary , String_.new_u8(req.Content_type_boundary()));
|
||||
}
|
||||
public void Test_form_data(String[] ary, Http_post_data_itm... expd) {
|
||||
client_rdr.Stream_(ary);
|
||||
Http_request_itm req = parser.Parse(client_rdr);
|
||||
Http_post_data_hash hash = req.Post_data_hash();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Http_post_data_itm itm = hash.Get_at(i);
|
||||
Tfds.Eq_bry(itm.Key(), expd[i].Key());
|
||||
Tfds.Eq_bry(itm.Val(), expd[i].Val());
|
||||
}
|
||||
}
|
||||
public void Test_ignore(String line) {
|
||||
client_rdr.Stream_(String_.Ary(line));
|
||||
parser.Parse(client_rdr);
|
||||
Gftest.Eq__str(null, server_wtr.Data());
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
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 Gfo_number_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfo_number_parser_fxt fxt = new Gfo_number_parser_fxt();
|
||||
@Test public void Integer() {
|
||||
fxt.Test_int("1", 1);
|
||||
fxt.Test_int("1234", 1234);
|
||||
fxt.Test_int("1234567890", 1234567890);
|
||||
fxt.Test_int("-1234", -1234);
|
||||
fxt.Test_int("+1", 1);
|
||||
fxt.Test_int("00001", 1);
|
||||
}
|
||||
@Test public void Long() {
|
||||
fxt.Test_long("9876543210", 9876543210L);
|
||||
}
|
||||
@Test public void Decimal() {
|
||||
fxt.Test_dec("1.23", Decimal_adp_.parse("1.23"));
|
||||
fxt.Test_dec("1.023", Decimal_adp_.parse("1.023"));
|
||||
fxt.Test_dec("-1.23", Decimal_adp_.parse("-1.23"));
|
||||
}
|
||||
@Test public void Double_long() {
|
||||
fxt.Test_dec(".42190046219457", Decimal_adp_.parse(".42190046219457"));
|
||||
}
|
||||
@Test public void Exponent() {
|
||||
fxt.Test_int("1E2", 100);
|
||||
fxt.Test_dec("1.234E2", Decimal_adp_.parse("123.4"));
|
||||
fxt.Test_dec("1.234E-2", Decimal_adp_.parse(".01234"));
|
||||
fxt.Test_dec("123.4E-2", Decimal_adp_.parse("1.234"));
|
||||
fxt.Test_dec("+6.0E-3", Decimal_adp_.parse(".006"));
|
||||
}
|
||||
@Test public void Err() {
|
||||
fxt.Test_err("+", true);
|
||||
fxt.Test_err("-", true);
|
||||
fxt.Test_err("a", true);
|
||||
fxt.Test_err("1-2", false);
|
||||
fxt.Test_err("1..1", true);
|
||||
fxt.Test_err("1,,1", true);
|
||||
fxt.Test_err("1", false);
|
||||
}
|
||||
@Test public void Hex() {
|
||||
fxt.Test_hex("0x1" , 1);
|
||||
fxt.Test_hex("0xF" , 15);
|
||||
fxt.Test_hex("0x20" , 32);
|
||||
fxt.Test_hex("x20" , 0, false);
|
||||
fxt.Test_hex("d" , 0, false); // PURPOSE: d was being converted to 13; no.w:Hovedbanen; DATE:2014-04-13
|
||||
}
|
||||
@Test public void Ignore() {
|
||||
fxt.Init_ignore("\n\t");
|
||||
fxt.Test_int("1" , 1);
|
||||
fxt.Test_int("1\n" , 1);
|
||||
fxt.Test_int("1\t" , 1);
|
||||
fxt.Test_int("1\n2" , 12);
|
||||
fxt.Test_err("1\r" , true);
|
||||
}
|
||||
}
|
||||
class Gfo_number_parser_fxt {
|
||||
private final Gfo_number_parser parser = new Gfo_number_parser();
|
||||
public void Clear() {parser.Clear();}
|
||||
public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));}
|
||||
public void Test_int(String raw, int expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
|
||||
Tfds.Eq(expd, actl, raw);
|
||||
}
|
||||
public void Test_long(String raw, long expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Tfds.Eq(expd, parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_long(), raw);
|
||||
}
|
||||
public void Test_dec(String raw, Decimal_adp expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec();
|
||||
Tfds.Eq(expd.To_double(), actl.To_double(), raw);
|
||||
}
|
||||
public void Test_err(String raw, boolean expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
boolean actl = parser.Parse(raw_bry, 0, raw_bry.length).Has_err();
|
||||
Tfds.Eq(expd, actl, raw);
|
||||
}
|
||||
public void Test_hex(String raw, int expd_val) {Test_hex(raw, expd_val, true);}
|
||||
public void Test_hex(String raw, int expd_val, boolean expd_pass) {
|
||||
parser.Hex_enabled_(true);
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
|
||||
if (expd_pass) {
|
||||
Tfds.Eq(expd_val, actl, raw);
|
||||
Tfds.Eq(true, !parser.Has_err());
|
||||
}
|
||||
else
|
||||
Tfds.Eq(false, !parser.Has_err());
|
||||
parser.Hex_enabled_(false);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
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.*; import gplx.core.tests.*;
|
||||
public class Int_ary_parser_tst {
|
||||
private final Int_ary_parser_fxt fxt = new Int_ary_parser_fxt();
|
||||
@Test public void Many() {fxt.Test__Parse_ary("1,2,3,4,5" , 0, 9, Int_.Ary(1, 2, 3, 4, 5));}
|
||||
@Test public void One() {fxt.Test__Parse_ary("1" , 0, 1, Int_.Ary(1));}
|
||||
@Test public void None() {fxt.Test__Parse_ary("" , 0, 0, Int_.Ary());}
|
||||
}
|
||||
class Int_ary_parser_fxt {
|
||||
public void Test__Parse_ary(String raw, int bgn, int end, int[] expd) {
|
||||
Gftest.Eq__ary(expd, new Int_ary_parser().Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma), "parse_ary failed");
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
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 Int_pool_tst {
|
||||
private final Int_pool_tstr tstr = new Int_pool_tstr();
|
||||
@Before public void init() {tstr.Clear();}
|
||||
@Test public void Get__one() {
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
@Test public void Get__many() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
}
|
||||
@Test public void Del__one() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Exec_del(0);
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
@Test public void Del__sequential() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
tstr.Exec_del(2).Test_get(2);
|
||||
tstr.Exec_del(2);
|
||||
tstr.Exec_del(1);
|
||||
tstr.Exec_del(0).Test_get(0);
|
||||
}
|
||||
@Test public void Del__out_of_order() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
tstr.Exec_del(0).Test_get(0);
|
||||
tstr.Exec_del(0);
|
||||
tstr.Exec_del(1);
|
||||
tstr.Exec_del(2);
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
@Test public void Del__out_of_order_2() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
tstr.Exec_del(1);
|
||||
tstr.Exec_del(2);
|
||||
tstr.Exec_del(0);
|
||||
}
|
||||
}
|
||||
class Int_pool_tstr {
|
||||
private final Int_pool pool = new Int_pool();
|
||||
public void Clear() {pool.Clear();}
|
||||
public Int_pool_tstr Test_get(int expd) {
|
||||
Tfds.Eq(expd, pool.Get_next());
|
||||
return this;
|
||||
}
|
||||
public Int_pool_tstr Exec_del(int val) {
|
||||
pool.Del(val);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
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.progs.rates; import gplx.*; import gplx.core.*; import gplx.core.progs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Gfo_rate_list_tst {
|
||||
private final Gfo_rate_list_fxt fxt = new Gfo_rate_list_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Add__1() {fxt.Add(100, 20).Test(5, 5);}
|
||||
@Test public void Add__2() {fxt.Add(100, 20).Add(100, 30).Test(4, .20d);}
|
||||
@Test public void Add__3() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Test(3, .25d);}
|
||||
@Test public void Add__4() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Add(600, 0).Test(9, 2);}
|
||||
}
|
||||
class Gfo_rate_list_fxt {
|
||||
private final Gfo_rate_list list = new Gfo_rate_list(6);
|
||||
public void Clear() {list.Clear();}
|
||||
public Gfo_rate_list_fxt Add(long data, long time) {list.Add(data, time); return this;}
|
||||
public void Test(double expd_rate, double expd_delta) {
|
||||
Gftest.Eq__double(expd_rate , list.Cur_rate() , "cur_rate");
|
||||
Gftest.Eq__double(expd_delta, list.Cur_delta() , "cur_delta");
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Cksum_list_tst {
|
||||
private final Cksum_list_fxt fxt = new Cksum_list_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__file("a.txt").Init__file("ab.txt");
|
||||
fxt.Test__parse(String_.Concat_lines_nl_skip_last
|
||||
( "a5e54d1fd7bb69a228ef0dcd2431367e *a.txt"
|
||||
, "90f15b7ca11bd4c70d9047cd29a80040 *ab.txt"
|
||||
), 11
|
||||
, fxt.Make__itm("a5e54d1fd7bb69a228ef0dcd2431367e", "a.txt", 5)
|
||||
, fxt.Make__itm("90f15b7ca11bd4c70d9047cd29a80040", "ab.txt", 6)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Cksum_list_fxt {
|
||||
private final Io_url dir = Io_url_.mem_dir_("mem/dir/");
|
||||
public Cksum_list_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
}
|
||||
public Cksum_list_fxt Init__file(String fil_name) {
|
||||
Io_url fil_url = dir.GenSubFil(fil_name);
|
||||
Io_mgr.Instance.SaveFilStr(fil_url, fil_name);
|
||||
return this;
|
||||
}
|
||||
public Cksum_itm Make__itm(String hash, String file_name, long size) {return new Cksum_itm(Bry_.new_u8(hash), dir.GenSubFil(file_name), size);}
|
||||
public Cksum_list_fxt Test__parse(String raw, long expd_size, Cksum_itm... expd_itms) {
|
||||
Cksum_list actl_list = Cksum_list.Parse(gplx.core.security.Hash_algo_.Tid__md5, dir, Bry_.new_u8(raw));
|
||||
Gftest.Eq__long(expd_size, actl_list.Itms_size);
|
||||
Gftest.Eq__ary(expd_itms, actl_list.Itms);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user