1
0
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:
gnosygnu
2017-09-17 22:39:30 -04:00
parent 4ca98f7333
commit ea3f0ffbcc
896 changed files with 69373 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.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);
}
}

View File

@@ -0,0 +1,78 @@
/*
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;
}
}

View File

@@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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");
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.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]);
}
}
}

View File

@@ -0,0 +1,72 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys; 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"));
}
}

View File

@@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.brys.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);
}
}
}

View File

@@ -0,0 +1,94 @@
/*
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("" , "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);
}
}

View File

@@ -0,0 +1,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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() {}
}

View File

@@ -0,0 +1,121 @@
/*
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;
}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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();
}

View File

@@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.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))
)
));
}
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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;
}
}

View File

@@ -0,0 +1,153 @@
/*
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"
, "]"
, ""
);
}
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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");
}
}

View File

@@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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;
}
}

View File

@@ -0,0 +1,62 @@
/*
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;}
}

View File

@@ -0,0 +1,94 @@
/*
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;
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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")
}
}

View File

@@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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();
}
}

View File

@@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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());
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.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;
*/

View File

@@ -0,0 +1,53 @@
/*
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);
}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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();
}
}

View File

@@ -0,0 +1,126 @@
/*
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");
// }
}

View File

@@ -0,0 +1,93 @@
/*
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());
}
}

View File

@@ -0,0 +1,107 @@
/*
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);
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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");
}
}

View File

@@ -0,0 +1,73 @@
/*
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;
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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");
}
}

View File

@@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.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;
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.metas.*;
public class Db_tbl_copy_tst {
private final Db_tbl_copy_fxt fxt = new Db_tbl_copy_fxt();
@Test public void Basic() {
fxt.Test__bld_sql(fxt.Make_tbl("tbl_1", Dbmeta_fld_itm.new_int("fld_1"), Dbmeta_fld_itm.new_int("fld_2")),
String_.Concat_lines_nl_skip_last
( "INSERT INTO trg"
, "(fld_1, fld_2)"
, "SELECT"
, " fld_1, fld_2"
, "FROM <src_db>src"
));
}
}
class Db_tbl_copy_fxt {
private final Db_tbl_copy mgr = new Db_tbl_copy();
public Dbmeta_tbl_itm Make_tbl(String name, Dbmeta_fld_itm... flds) {return Dbmeta_tbl_itm.New(name, flds);}
public void Test__bld_sql(Dbmeta_tbl_itm tbl, String expd) {
Gftest.Eq__ary__lines(expd, mgr.Bld_sql(tbl, "src", "trg"), "sql");
}
}

View File

@@ -0,0 +1,53 @@
/*
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.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
import org.junit.*; import gplx.dbs.*;
public class Schema_update_mgr_tst {
@Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt();
@Test public void Create() {
fxt.Test_exec_y(new Schema_update_cmd__mock());
}
@Test public void Delete() {
fxt.Init_itm(Dbmeta_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name);
fxt.Test_exec_n(new Schema_update_cmd__mock());
}
}
class Schema_update_mgr_fxt {
private Schema_update_mgr update_mgr; private Schema_db_mgr db_mgr;
public void Clear() {
update_mgr = new Schema_update_mgr();
db_mgr = new Schema_db_mgr();
}
public void Init_itm(int tid, String name) {
db_mgr.Tbl_mgr().Add(Dbmeta_tbl_itm.New(name));
}
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);}
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);}
private void Test_exec(Schema_update_cmd cmd, boolean expd) {
update_mgr.Add(cmd);
update_mgr.Update(db_mgr, Db_conn_.Noop);
Tfds.Eq(expd, cmd.Exec_is_done());
}
}
class Schema_update_cmd__mock implements Schema_update_cmd {
public String Name() {return "xowa.user.cfg_regy.create";}
public boolean Exec_is_done() {return exec_is_done;} private boolean exec_is_done;
public void Exec(Schema_db_mgr mgr, Db_conn conn) {
if (mgr.Tbl_mgr().Has(Tbl_name)) return;
exec_is_done = true;
}
public static final String Tbl_name = "tbl_mock";
}

View File

@@ -0,0 +1,61 @@
/*
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.dbs.percentiles; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class Percentile_rng_tst {
private final Percentile_rng_fxt fxt = new Percentile_rng_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Found__000() {
fxt.Test__rng(999994, 1000001);
fxt.Exec__update( 0).Test__rng(999966, 999994);
fxt.Exec__update( 0).Test__rng(999854, 999966);
}
@Test public void Found__025() {
fxt.Test__rng(999994, 1000001);
fxt.Exec__update( 25).Test__rng(999973, 999994);
fxt.Exec__update( 25).Test__rng(999931, 999973);
fxt.Exec__update( 25).Test__rng(999889, 999931);
fxt.Exec__update( 25).Test__rng(999847, 999889);
}
@Test public void Calc_score_unit() {
fxt.Test__calc_score_unit(50, 16000000, 1000000, 4); // to fill 50 -> 16 pages per point -> read every 4 points to get 64 pages
fxt.Test__calc_score_unit(50, 1000, 1000000, 50000); // to fill 50 -> 1000 points per page -> read every 50k points to get 50 pages
fxt.Test__calc_score_unit(50, 25, 1000000, 1000000); // range bounds check; to fill 50, always read full amount
}
}
class Percentile_rng_fxt {
private final Percentile_rng rng = new Percentile_rng();
public void Clear() {
this.Exec__init_for_wiki(16000000, 1000000);
this.Exec__init_for_search(100, 0);
}
public Percentile_rng_fxt Exec__init_for_wiki (int pages_max, int score_max) {
rng.Init(pages_max, score_max); return this;
}
public Percentile_rng_fxt Exec__init_for_search(int request_count, int score_len_adj) {
rng.Select_init(request_count, Percentile_rng.Score_null, Percentile_rng.Score_null, score_len_adj); return this;
}
public Percentile_rng_fxt Exec__update(int rdr_found) {
rng.Update(rdr_found); return this;
}
public void Test__rng(int expd_bgn, int expd_end) {
Tfds.Eq(expd_end, rng.Score_end(), "rng_end");
Tfds.Eq(expd_bgn, rng.Score_bgn(), "rng_bgn");
}
public void Test__calc_score_unit(int request_count, long pages_max, int score_max, int expd) {
Tfds.Eq(expd, Percentile_rng.Calc_score_unit(request_count, pages_max, score_max));
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
import org.junit.*;
public class Fsd_thm_tbl_tst {
@Before public void init() {fxt.Clear();} private Fsd_thm_tbl_fxt fxt = new Fsd_thm_tbl_fxt();
@Test public void Basic() {
fxt.Init_list(fxt.Make(100), fxt.Make(200), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(400), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(200), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(100), fxt.Make(100));
fxt.Test_match_nearest_itm(fxt.Make(350), fxt.Make(400));
fxt.Test_match_nearest_itm(fxt.Make(150), fxt.Make(200));
fxt.Test_match_nearest_itm(fxt.Make(999), fxt.Make(400));
}
@Test public void Empty() {
fxt.Init_list(); // no items
fxt.Test_match_nearest_itm(fxt.Make(100), Fsd_thm_itm.Null);
}
}
class Fsd_thm_tbl_fxt {
private final List_adp list = List_adp_.New();
public void Clear() {list.Clear();}
public Fsd_thm_itm Make(int w) {
double time = gplx.xowa.files.Xof_lnki_time.Null;
int page = gplx.xowa.files.Xof_lnki_page.Null;
Fsd_thm_itm rv = Fsd_thm_itm.new_();
rv.Init_by_req(w, time, page);
return rv;
}
public void Init_list(Fsd_thm_itm... ary) {list.Add_many((Object[])ary);}
public void Test_match_nearest_itm(Fsd_thm_itm req, Fsd_thm_itm expd) {
Fsd_thm_tbl.Match_nearest(list, req, Bool_.Y);
if (expd == Fsd_thm_itm.Null) {
Tfds.Eq(req.Req_w(), 0);
}
else {
Tfds.Eq(expd.W(), req.W());
Tfds.Eq(expd.Time(), req.Time());
Tfds.Eq(expd.Page(), req.Page());
}
}
}

View File

@@ -0,0 +1,62 @@
/*
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.gfui; import gplx.*;
import org.junit.*;
public class Gfui_bnd_parser_tst {
@Before public void init() {fxt.Clear();} private Gfui_bnd_parser_fxt fxt = new Gfui_bnd_parser_fxt();
@Test public void Norm_one() {
fxt.Test__to_norm("mod.c" , "Ctrl");
fxt.Test__to_norm("key.ctrl" , "Ctrl");
fxt.Test__to_norm("key.a" , "A");
fxt.Test__to_norm("key.left" , "Left");
}
@Test public void Norm_add() {
fxt.Test__to_norm("mod.c+key.a" , "Ctrl + A");
fxt.Test__to_norm("mod.ca+key.a" , "Ctrl + Alt + A");
fxt.Test__to_norm("mod.cas+key.a" , "Ctrl + Alt + Shift + A");
}
@Test public void Norm_chord() {
fxt.Test__to_norm("key.a,key.b" , "A, B");
}
@Test public void Norm_add_and_chord() {
fxt.Test__to_norm("mod.c+key.a,mod.a+key.b" , "Ctrl + A, Alt + B");
}
@Test public void Gfui_add() {
fxt.Test__to_gfui("Ctrl + A" , "mod.c+key.a");
fxt.Test__to_gfui("Ctrl + Shift + A" , "mod.cs+key.a");
fxt.Test__to_gfui("Ctrl + Alt + Shift + A" , "mod.cas+key.a");
}
@Test public void Keypad_enter() {
fxt.Test__to_norm("key.numpad_enter" , "Numpad Enter");
fxt.Test__to_norm("mod.c+key.numpad_enter" , "Ctrl + Numpad Enter");
}
@Test public void None() {
fxt.Test__to_gfui("None" , "key.none");
fxt.Test__to_norm("key.none" , "None");
}
}
class Gfui_bnd_parser_fxt {
private Gfui_bnd_parser parser;
public void Clear() {
parser = Gfui_bnd_parser.new_en_();
}
public void Test__to_norm(String key, String expd) {
Tfds.Eq(expd, parser.Xto_norm(key));
}
public void Test__to_gfui(String key, String expd) {
Tfds.Eq(expd, parser.Xto_gfui(key));
}
}

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Dsv_tbl_parser_int_tst {
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
@Test public void Basic() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|1|3"
, "b|2|4"
)
, fxt.mgr_int_()
, fxt.itm_int_("a", 1, 3)
, fxt.itm_int_("b", 2, 4)
);
}
}
class Mok_int_itm implements To_str_able {
private String fld_0;
private int fld_1, fld_2;
public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;}
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));}
}
class Mok_int_mgr extends Mok_mgr_base {
public void Clear() {itms.Clear();}
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
private String fld_0;
private int fld_1, fld_2;
@Override public Dsv_fld_parser[] Fld_parsers() {
return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance};
}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 0: fld_0 = String_.new_u8(src, bgn, end); return true;
default: return false;
}
}
@Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {
switch (fld_idx) {
case 1: fld_1 = val_int; return true;
case 2: fld_2 = val_int; return true;
default: return false;
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Mok_int_itm itm = new Mok_int_itm(fld_0, fld_1, fld_2);
itms.Add(itm);
}
}

View File

@@ -0,0 +1,107 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Dsv_tbl_parser_str_tst {
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
@Test public void Basic() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|A"
, "b|B"
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a", "A")
, fxt.itm_str_("b", "B")
);
}
@Test public void Blank_lines() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( ""
, "a|A"
, ""
, "b|B"
, ""
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a", "A")
, fxt.itm_str_("b", "B")
);
}
@Test public void Incomplete_row() {
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a"
, "b"
, ""
)
, fxt.mgr_str_(2)
, fxt.itm_str_("a")
, fxt.itm_str_("b")
);
}
@Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells
fxt .Test_load(String_.Concat_lines_nl_skip_last
( "a|")
, fxt.mgr_str_(3)
, fxt.itm_str_("a", "")
);
}
}
abstract class Mok_mgr_base extends Dsv_wkr_base {
public abstract To_str_able[] Itms();
}
class Dsv_mok_fxt {
private Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser();
public Dsv_mok_fxt Clear() {
tbl_parser.Clear();
return this;
}
public Mok_mgr_base mgr_int_() {return new Mok_int_mgr();}
public Mok_mgr_base mgr_str_(int len) {return new Mok_str_mgr(len);}
public Mok_str_itm itm_str_(String... flds) {return new Mok_str_itm(flds);}
public Mok_int_itm itm_int_(String fld_0, int fld_1, int fld_2) {return new Mok_int_itm(fld_0, fld_1, fld_2);}
public void Test_load(String src, Mok_mgr_base mgr, To_str_able... expd) {
mgr.Load_by_bry(Bry_.new_u8(src));
Tfds.Eq_ary_str(expd, mgr.Itms());
}
}
class Mok_str_itm implements To_str_able {
private String[] flds;
public Mok_str_itm(String[] flds) {this.flds = flds;}
public String To_str() {return String_.Concat_with_str("|", flds);}
}
class Mok_str_mgr extends Mok_mgr_base {
private int flds_len;
public Mok_str_mgr(int flds_len) {
this.flds_len = flds_len;
}
public void Clear() {itms.Clear();}
@Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New();
private List_adp flds = List_adp_.New();
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
flds.Add(String_.new_u8(src, bgn, end));
return true;
}
@Override public Dsv_fld_parser[] Fld_parsers() {
Dsv_fld_parser[] rv = new Dsv_fld_parser[flds_len];
for (int i = 0; i < flds_len; i++)
rv[i] = Dsv_fld_parser_.Bry_parser;
return rv;
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Mok_str_itm itm = new Mok_str_itm((String[])flds.To_ary_and_clear(String.class));
itms.Add(itm);
}
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.strings.*;
public class Gfs_msg_bldr_tst {
@Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt();
@Test public void Basic() {
fxt.Test_build("a;", fxt.msg_("a"));
}
@Test public void Dot() {
fxt.Test_build("a.b.c;"
, fxt.msg_("a").Subs_
( fxt.msg_("b").Subs_
( fxt.msg_("c")
)));
}
@Test public void Args() {
fxt.Test_build("a('b', 'c');", fxt.msg_("a", fxt.kv_("", "b"), fxt.kv_("", "c")));
}
@Test public void Args_num() {
fxt.Test_build("a(1);", fxt.msg_("a", fxt.kv_("", "1")));
}
@Test public void Assign() {
fxt.Test_build("a = 'b';", fxt.msg_("a_", fxt.kv_("", "b")));
}
@Test public void Assign_num() {
fxt.Test_build("a = 1;", fxt.msg_("a_", fxt.kv_("", "1")));
}
}
class Gfs_msg_bldr_fxt {
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr.Instance;
public Keyval kv_(String key, String val) {return Keyval_.new_(key, val);}
public GfoMsg msg_(String key, Keyval... args) {
GfoMsg rv = GfoMsg_.new_parse_(key);
int len = args.length;
for (int i = 0; i < len; i++) {
Keyval kv = args[i];
rv.Add(kv.Key(), kv.Val());
}
return rv;
}
public void Test_build(String raw, GfoMsg... expd) {
GfoMsg root = msg_bldr.Bld(raw);
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(To_ary(root)));
}
GfoMsg[] To_ary(GfoMsg msg) {
int len = msg.Subs_count();
GfoMsg[] rv = new GfoMsg[len];
for (int i = 0; i < len; i++)
rv[i] = msg.Subs_getAt(i);
return rv;
}
String Xto_str(GfoMsg[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) sb.Add_char_crlf();
sb.Add(ary[i].To_str());
}
return sb.To_str_and_clear();
}
}

View File

@@ -0,0 +1,194 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfs_parser_tst {
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
@Test public void Semicolon() {
fxt .Test_parse("a;", fxt.nde_("a"));
fxt .Test_parse("a;b;c;", fxt.nde_("a"), fxt.nde_("b"), fxt.nde_("c"));
fxt .Test_parse("a_0;", fxt.nde_("a_0"));
}
@Test public void Dot() {
fxt .Test_parse("a.b;", fxt.nde_("a").Subs_add(fxt.nde_("b")));
fxt .Test_parse("a.b;c.d;", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d")));
}
@Test public void Parens() {
fxt .Test_parse("a();b();", fxt.nde_("a"), fxt.nde_("b"));
fxt .Test_parse("a().b();c().d();", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d")));
}
@Test public void Num() {
fxt .Test_parse("a(1,2);", fxt.nde_("a").Atrs_add_many(fxt.val_("1"), fxt.val_("2")));
}
@Test public void Quote() {
fxt .Test_parse("a('b');", fxt.nde_("a").Atrs_add(fxt.val_("b")));
}
@Test public void Quote_escaped() {
fxt .Test_parse("a('b''c''d');", fxt.nde_("a").Atrs_add(fxt.val_("b'c'd")));
}
@Test public void Quote_escaped_2() {
fxt .Test_parse("a('a''''b');", fxt.nde_("a").Atrs_add(fxt.val_("a''b")));
}
@Test public void Quote_mixed() {
fxt .Test_parse("a('b\"c');", fxt.nde_("a").Atrs_add(fxt.val_("b\"c")));
}
@Test public void Comma() {
fxt .Test_parse("a('b','c','d');", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c"), fxt.val_("d")));
}
@Test public void Ws() {
fxt .Test_parse(" a ( 'b' , 'c' ) ; ", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c")));
}
@Test public void Comment_slash_slash() {
fxt .Test_parse("//z\na;//y\n", fxt.nde_("a"));
}
@Test public void Comment_slash_star() {
fxt .Test_parse("/*z*/a;/*y*/", fxt.nde_("a"));
}
@Test public void Curly() {
fxt .Test_parse("a{b;}", fxt.nde_("a").Subs_add(fxt.nde_("b")));
}
@Test public void Curly_nest() {
fxt .Test_parse("a{b{c{d;}}}"
, fxt.nde_("a").Subs_add
( fxt.nde_("b").Subs_add
( fxt.nde_("c").Subs_add
( fxt.nde_("d")
))));
}
@Test public void Curly_nest_peers() {
fxt .Test_parse(String_.Concat_lines_nl
( "a{"
, " a0{"
, " a00{"
, " a000;"
, " }"
, " a01;"
, " }"
, " a1;"
, "}"
)
, fxt.nde_("a").Subs_add_many
( fxt.nde_("a0").Subs_add_many
( fxt.nde_("a00").Subs_add
( fxt.nde_("a000")
)
, fxt.nde_("a01")
)
, fxt.nde_("a1")
));
}
@Test public void Curly_dot() {
fxt .Test_parse("a{a0.a00;a1.a10;}"
, fxt.nde_("a").Subs_add_many
( fxt.nde_("a0").Subs_add_many(fxt.nde_("a00"))
, fxt.nde_("a1").Subs_add_many(fxt.nde_("a10"))
));
}
@Test public void Eq() {
fxt .Test_parse("a='b';", fxt.nde_("a").Atrs_add(fxt.val_("b")));
fxt .Test_parse("a.b.c='d';"
, fxt.nde_("a").Subs_add
( fxt.nde_("b").Subs_add_many
( fxt.nde_("c").Atrs_add(fxt.val_("d"))
)));
fxt .Test_parse("a.b{c='d'; e='f'}"
, fxt.nde_("a").Subs_add
( fxt.nde_("b").Subs_add_many
( fxt.nde_("c").Atrs_add(fxt.val_("d"))
, fxt.nde_("e").Atrs_add(fxt.val_("f"))
)));
}
@Test public void Curly_nest_peers2() {
fxt .Test_parse(String_.Concat_lines_nl
( "a() {"
, " k1 = 'v1';"
, "}"
)
, fxt.nde_("a").Subs_add_many
( fxt.nde_("k1").Atrs_add(fxt.val_("v1"))
)
);
}
@Test public void Fail() {
fxt .Test_parse_fail("a(.);", Gfs_err_mgr.Fail_msg_invalid_lxr); // (.)
fxt .Test_parse_fail("a..b;", Gfs_err_mgr.Fail_msg_invalid_lxr); // ..
fxt .Test_parse_fail("a.;", Gfs_err_mgr.Fail_msg_invalid_lxr); // .;
fxt .Test_parse_fail("a", Gfs_err_mgr.Fail_msg_eos); // eos
fxt .Test_parse_fail("a;~;", Gfs_err_mgr.Fail_msg_unknown_char); // ~
}
}
class Gfs_parser_fxt {
public void Clear() {}
public Gfs_nde nde_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));}
public Gfs_nde val_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));}
public void Test_parse(String src_str, Gfs_nde... expd) {
byte[] src_bry = Bry_.new_u8(src_str);
Gfs_nde root = parser.Parse(src_bry);
Tfds.Eq_str_lines(To_str(null, expd), To_str(src_bry, root.Subs_to_ary()));
} private Bry_bfr tmp_bfr = Bry_bfr_.New(), path_bfr = Bry_bfr_.New(); Gfs_parser parser = new Gfs_parser();
public void Test_parse_fail(String src_str, String expd_err) {
byte[] src_bry = Bry_.new_u8(src_str);
try {parser.Parse(src_bry);}
catch (Exception e) {
String actl_err = Err_.Message_gplx_full(e);
actl_err = String_.GetStrBefore(actl_err, ":");
boolean match = String_.Has(actl_err, expd_err);
if (!match) Tfds.Fail("expecting '" + expd_err + "' got '" + actl_err + "'");
return;
}
Tfds.Fail("expected to fail with " + expd_err);
}
public String To_str(byte[] src, Gfs_nde[] expd) {
int subs_len = expd.length;
for (int i = 0; i < subs_len; i++) {
path_bfr.Clear().Add_int_variable(i);
To_str(tmp_bfr, path_bfr, src, expd[i]);
}
return tmp_bfr.To_str_and_clear();
}
public void To_str(Bry_bfr bfr, Bry_bfr path, byte[] src, Gfs_nde nde) {
To_str_atr(bfr, path, src, Atr_name, nde.Name(), nde.Name_bgn(), nde.Name_end());
int atrs_len = nde.Atrs_len();
for (int i = 0; i < atrs_len; i++) {
Gfs_nde atr = nde.Atrs_get_at(i);
int path_len_old = path.Len();
path.Add_byte(Byte_ascii.Dot).Add_byte((byte)(Byte_ascii.Ltr_a + i));
int path_len_new = path.Len();
To_str(bfr, path, src, atr);
path.Del_by(path_len_new - path_len_old);
}
int subs_len = nde.Subs_len();
for (int i = 0; i < subs_len; i++) {
Gfs_nde sub = nde.Subs_get_at(i);
int path_len_old = path.Len();
path.Add_byte(Byte_ascii.Dot).Add_int_variable(i);
int path_len_new = path.Len();
To_str(bfr, path, src, sub);
path.Del_by(path_len_new - path_len_old);
}
}
private void To_str_atr(Bry_bfr bfr, Bry_bfr path_bfr, byte[] src, byte[] name, byte[] val, int val_bgn, int val_end) {
if (val == null && val_bgn == -1 && val_end == -1) return;
bfr.Add_bfr_and_preserve(path_bfr).Add_byte(Byte_ascii.Colon);
bfr.Add(name);
if (val == null)
bfr.Add_mid(src, val_bgn, val_end);
else
bfr.Add(val);
bfr.Add_byte_nl();
}
private static final byte[] Atr_name = Bry_.new_a7("name=");
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfh_parser_tst {
@Before public void init() {fxt.Clear();} private Gfh_parser_fxt fxt = new Gfh_parser_fxt();
@Test public void One() {fxt.Test_parse_find_all("<a id='id0'></a>", "id0");}
@Test public void Many() {fxt.Test_parse_find_all("<a id='id0'></a><a id='id1'></a><a id='id2'></a>", "id0", "id1", "id2");}
@Test public void Inline() {fxt.Test_parse_find_all("<a id='id0'/>", "id0");}
@Test public void Mix() {fxt.Test_parse_find_all("012<a id='id0'></a>id=id2<a id='id1'/>345<a id='id2'></a>abc", "id0", "id1", "id2");}
@Test public void Quote_double() {fxt.Test_parse_find_all("<a id='id''0'/>", "id'0");}
@Test public void Quote_escape() {fxt.Test_parse_find_all("<a id='id\\'0'/>", "id'0");}
}
class Gfh_parser_fxt {
public void Clear() {
if (parser == null) {
parser = new Gfh_parser();
}
} private Gfh_parser parser;
public Gfh_parser_fxt Test_parse_find_all(String raw_str, String... expd) {return Test_parse_find(raw_str, Gfh_parser.Wildcard_str, Gfh_parser.Wildcard_str, expd);}
public Gfh_parser_fxt Test_parse_find(String raw_str, String find_key, String find_val, String... expd) {
byte[] raw = Bry_.new_a7(raw_str);
Gfh_nde[] actl_ndes = parser.Parse_as_ary(raw, 0, raw.length, Bry_.new_a7(find_key), Bry_.new_a7(find_val));
String[] actl = Xto_ids(raw, actl_ndes);
Tfds.Eq_ary_str(expd, actl);
return this;
}
private String[] Xto_ids(byte[] src, Gfh_nde[] ary) {
int len = ary.length;
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
Gfh_nde itm = ary[i];
String atr_val = itm.Atrs_val_by_key_str("id");
rv[i] = atr_val;
}
return rv;
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfh_utl__basic__tst {
@Before public void init() {fxt.Clear();} private Gfh_class_fxt fxt = new Gfh_class_fxt();
@Test public void Escape() {
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<b" , "a&lt;b"); // basic
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.N, Bool_.Y, Bool_.Y, "a<&b" , "a&lt;&b"); // fix: & not escaped when <> present
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&\"b" , "a&lt;&gt;&#39;&amp;&quot;b");
}
@Test public void Escape_for_atr_val() {
fxt.Test_escape_for_atr("abc" , Bool_.N, "abc"); // basic
fxt.Test_escape_for_atr("a'\"b" , Bool_.Y, "a&#39;\"b"); // quote is '
fxt.Test_escape_for_atr("a'\"b" , Bool_.N, "a'&quot;b"); // quote is "
}
@Test public void Unescape() {
fxt.Test_unescape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a&lt;&gt;&#39;&amp;&quot;b" , "a<>'&\"b"); // basic
}
}
class Gfh_class_fxt {
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public void Clear() {
tmp_bfr.Clear();
}
public void Test_del_comments(String src, String expd) {
byte[] actl = Gfh_utl.Del_comments(tmp_bfr, Bry_.new_u8(src));
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Test_escape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) {
byte[] actl = Gfh_utl.Escape_html_as_bry(Bry_.new_a7(src), lt, gt, amp, quote, apos);
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Test_escape_for_atr(String src, boolean quote_is_apos, String expd) {
byte[] actl = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? Byte_ascii.Apos : Byte_ascii.Quote, src);
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_unescape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) {
byte[] bry = Bry_.new_u8(src);
byte[] actl = Gfh_utl.Unescape(false, tmp_bfr, bry, 0, bry.length, lt, gt, amp, quote, apos);
Tfds.Eq(expd, String_.new_a7(actl));
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfh_utl__comments__tst {
@Before public void init() {fxt.Clear();} private final Gfh_class_fxt fxt = new Gfh_class_fxt();
@Test public void Basic() {fxt.Test_del_comments("a<!-- b -->c" , "ac");}
@Test public void Bgn_missing() {fxt.Test_del_comments("a b c" , "a b c");}
@Test public void End_missing() {fxt.Test_del_comments("a<!-- b c" , "a");}
@Test public void Multiple() {fxt.Test_del_comments("a<!--b-->c<!--d-->e" , "ace");}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Gfh_class__tst {
private final Gfh_class__fxt fxt = new Gfh_class__fxt();
@Test public void Has() {
fxt.Test__has__y("a b c", "a", "b", "c");
fxt.Test__has__n("a b c", "d");
fxt.Test__has__n("ab", "a");
}
@Test public void Cls__has__hash() {
Hash_adp_bry hash = fxt.Make_hash("x", "y", "z");
fxt.Test__find_1st(hash, 0, "x");
fxt.Test__find_1st(hash, 2, "z");
fxt.Test__find_1st(hash, 0, "a x b");
fxt.Test__find_1st(hash, 0, "a b x");
fxt.Test__find_1st(hash, Byte_.Max_value_127, "a");
fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz");
}
}
class Gfh_class__fxt {
public void Test__has__y(String src, String... ary) {Test__has(Bool_.Y, src, ary);}
public void Test__has__n(String src, String... ary) {Test__has(Bool_.N, src, ary);}
public void Test__has(boolean expd, String src, String... ary) {
byte[] src_bry = Bry_.new_u8(src);
for (String itm : ary) {
byte[] itm_bry = Bry_.new_u8(itm);
Tfds.Eq_bool(expd, Gfh_class_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
}
}
public Hash_adp_bry Make_hash(String... ary) {
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
int len = ary.length;
for (int i = 0; i < len; ++i)
rv.Add_bry_byte(Bry_.new_u8(ary[i]), (byte)i);
return rv;
}
public void Test__find_1st(Hash_adp_bry hash, int expd, String src) {
byte[] src_bry = Bry_.new_u8(src);
Tfds.Eq_byte((byte)expd, Gfh_class_.Find_1st(src_bry, 0, src_bry.length, hash), src);
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Gfh_class_parser__tst {
private final Gfh_class_parser__fxt fxt = new Gfh_class_parser__fxt();
@Test public void Basic() {fxt.Test__parse("v1" , "v1");}
@Test public void Many() {fxt.Test__parse("v1 v2" , "v1", "v2");}
}
class Gfh_class_parser__fxt {
private final Gfh_class_wkr__list wkr = new Gfh_class_wkr__list();
public void Test__parse(String src_str, String... expd) {
byte[] src_bry = Bry_.new_u8(src_str);
String[] actl = wkr.Parse(src_bry, 0, src_bry.length);
Tfds.Eq_ary_str(expd, actl);
}
}
class Gfh_class_wkr__list implements Gfh_class_parser_wkr {
private final List_adp list = List_adp_.New();
public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) {
String s = String_.new_u8(src, val_bgn, val_end);
list.Add(s); //
return true;
}
public String[] Parse(byte[] src, int src_bgn, int src_end) {
Gfh_class_parser_.Parse(src, src_bgn, src_end, this);
return (String[])list.To_ary_and_clear(String.class);
}
}

View File

@@ -0,0 +1,78 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Gfh_tag_rdr_tst {
private final Gfh_tag_rdr_fxt fxt = new Gfh_tag_rdr_fxt();
@Test public void Basic() {
fxt.Init("1<div id='1'>2</div>3<div id='2'>4</div>5<div id='3'>6</div>7");
fxt.Test__move_fwd_head("<div id='1'>"); fxt.Test__pos("2");
fxt.Test__peek_fwd_head("<div id='2'>"); fxt.Test__pos("2");
fxt.Test__move_fwd_head("<div id='2'>"); fxt.Test__pos("4");
fxt.Test__peek_bwd_tail("</div>3") ; fxt.Test__pos("4");
}
@Test public void Comment() {
fxt.Init("1<!--2-->3<!--4-->5<div id='1'>6</div>");
fxt.Test__move_fwd_head(Gfh_tag_.Id__any , "<div id='1'>") ; fxt.Test__pos("6");
}
@Test public void Meta() {
fxt.Init("<!DOCTYPE html>1<div id='1'>2</div>3");
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div id='1'>") ; fxt.Test__pos("2");
}
@Test public void Recursive__same_tags() {
fxt.Init("1<a>2<a>3</a>4</a>5");
fxt.Test__move_fwd_head(Gfh_tag_.Id__a , "<a>") ; fxt.Test__pos("2");
fxt.Test__move_fwd_tail(Gfh_tag_.Id__a , "</a>") ; fxt.Test__pos("5");
}
@Test public void Recursive__diff_tags() {
fxt.Init("1<div>2<a>3<img/>4</a>5</div>6");
fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "<div>") ; fxt.Test__pos("2");
fxt.Test__move_fwd_tail(Gfh_tag_.Id__div , "</div>") ; fxt.Test__pos("6");
}
@Test public void Inline() {
fxt.Init("1<br/>2");
fxt.Test__move_fwd_head(Gfh_tag_.Id__br , "<br/>") ; fxt.Test__pos("2");
}
}
class Gfh_tag_rdr_fxt {
private final Gfh_tag_rdr rdr = Gfh_tag_rdr.New__html();
public void Init(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
rdr.Init(Bry_.Empty, src_bry, 0, src_bry.length);
}
public void Test__move_fwd_head(String expd) {Test__move_fwd_head(Gfh_tag_.Id__any, expd);}
public void Test__move_fwd_head(int match_name_id, String expd) {
Gfh_tag actl_tag = rdr.Tag__move_fwd_head(match_name_id).Chk_name_or_fail(match_name_id);
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
}
public void Test__move_fwd_tail(int match_name_id, String expd) {
Gfh_tag actl_tag = rdr.Tag__move_fwd_tail(match_name_id);
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
}
public void Test__peek_fwd_head(String expd) {
Gfh_tag actl_tag = rdr.Tag__peek_fwd_head();
Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end()));
}
public void Test__peek_bwd_tail(String expd_str) {
byte[] expd_bry = Bry_.new_u8(expd_str);
Gfh_tag actl_tag = rdr.Tag__peek_bwd_tail(-1);
Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_bgn() + expd_bry.length));
}
public void Test__pos(String expd_str) {
byte[] expd_bry = Bry_.new_u8(expd_str);
Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), rdr.Pos(), rdr.Pos() + expd_bry.length));
}
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Gfo_url_encoder_tst {
private final Gfo_url_encoder_fxt fxt = new Gfo_url_encoder_fxt();
@Test public void Id__nums() {fxt.Encoder_id().Test__bicode("0123456789" , "0123456789");}
@Test public void Id__ltrs_lower() {fxt.Encoder_id().Test__bicode("abcdefghijklmnopqrstuvwxyz" , "abcdefghijklmnopqrstuvwxyz");}
@Test public void Id__ltrs_upper() {fxt.Encoder_id().Test__bicode("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , "ABCDEFGHIJKLMNOPQRSTUVWXYZ");}
@Test public void Id__syms() {fxt.Encoder_id().Test__encode("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ".21.22.23.24.25.26.27.28.29.2A.2B.2C-..2F:.3B.3C.3D.3E.3F.40.5B.5C.5D.5E_.60.7B.7C.7D.7E");} // NOTE: not reversible since "." is encode_marker but not encoded
@Test public void Id__foreign() {fxt.Encoder_id().Test__bicode("aéb", "a.C3.A9b");}
@Test public void Id__nbsp() {fxt.Encoder_id().Test__encode("a&nbsp;b", "a.C2.A0b");} // NOTE: not just .A0 (160) but utf8-encoded .C2.A0
@Test public void Id__space() {fxt.Encoder_id().Test__bicode("a b", "a_b");}
@Test public void Id__err() {
byte[] raw = Bry_.new_a7("0%.jpg");
Bry_bfr tmp_bfr = Bry_bfr_.New();
fxt.Encoder_id().Encoder().Decode(tmp_bfr, Bool_.N, raw, 0, raw.length);
Tfds.Eq("0%.jpg", tmp_bfr.To_str_and_clear());
}
@Test public void Ttl__syms__diff() {fxt.Encoder_ttl().Test__encode(" &'=+", "_%26%27%3D%2B");}
@Test public void Ttl__syms__same() {fxt.Encoder_ttl().Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");}
@Test public void Url__syms() {fxt.Encoder_url().Test__bicode("!?^~", "%21%3F%5E%7E");}
@Test public void Url__foreign() {fxt.Encoder_url().Test__bicode("aéb", "a%C3%A9b");}
@Test public void Url__space() {fxt.Encoder_url().Test__bicode("a b", "a+b");}
@Test public void Href__space() {
fxt.Encoder_href().Test__encode("a b", "a_b");
}
@Test public void Href__special_and_anchor() { // PURPOSE: MediaWiki encodes with % for ttls, but . for anchors; REF:Title.php!(before-anchor)getLocalUrl;wfUrlencode (after-anchor)escapeFragmentForURL
fxt.Encoder_href().Test__bicode("^#^", "%5E#.5E");
fxt.Encoder_href().Test__encode("A#", "A#");
}
@Test public void Href__invalid() { // PURPOSE: check that invalid url decodings are rendered literally; DATE:2014-04-10
fxt.Encoder_href().Test__encode("%GC", "%25GC");
}
@Test public void Fsys__wnt() {
fxt.Encoder_fsys_safe().Test__encode("Options/HTML", "Options%2FHTML");
}
}
class Gfo_url_encoder_fxt {
public Gfo_url_encoder Encoder() {return encoder;} private Gfo_url_encoder encoder;
public Gfo_url_encoder_fxt Encoder_id() {encoder = Gfo_url_encoder_.Id; return this;}
public Gfo_url_encoder_fxt Encoder_href() {encoder = Gfo_url_encoder_.Href; return this;}
public Gfo_url_encoder_fxt Encoder_url() {encoder = Gfo_url_encoder_.Http_url; return this;}
public Gfo_url_encoder_fxt Encoder_ttl() {encoder = Gfo_url_encoder_.Mw_ttl; return this;}
public Gfo_url_encoder_fxt Encoder_fsys_safe() {encoder = Gfo_url_encoder_.New__fsys_wnt().Make(); return this;}
public void Test__bicode(String raw, String encoded) {
Test__encode(raw, encoded);
Test__decode(encoded, raw);
}
public void Test__encode(String raw, String expd) {
Tfds.Eq(expd, String_.new_u8(encoder.Encode(Bry_.new_u8(raw))));
}
public void Test__decode(String raw, String expd) {
Tfds.Eq(expd, String_.new_u8(encoder.Decode(Bry_.new_u8(raw))));
}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import org.junit.*;
public class Gfh_style_parser__tst {
private final Gfh_style_parser__fxt fxt = new Gfh_style_parser__fxt();
@Test public void Basic() {
fxt.Test__parse("k_0:v_0" , fxt.Make("k_0", "v_0"));
fxt.Test__parse("k_0:v_0;" , fxt.Make("k_0", "v_0"));
fxt.Test__parse("k_0:v_0;k_1:v_1" , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
}
@Test public void Ws() {
fxt.Test__parse(" k_0 : v_0 ;" , fxt.Make("k_0", "v_0"));
fxt.Test__parse(" k_0 : v_0 ; k_1 : v_1 " , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
fxt.Test__parse(" k_0 : v 0 ;" , fxt.Make("k_0", "v 0"));
}
@Test public void Empty() {
fxt.Test__parse("k_0:v_0;;" , fxt.Make("k_0", "v_0"));
fxt.Test__parse("k_0:v_0; ; " , fxt.Make("k_0", "v_0"));
}
@Test public void Invalid__no_semic() {
fxt.Test__parse("k_0" , fxt.Make("k_0", ""));
}
@Test public void Invalid__dupe_colon() {
fxt.Test__parse("a:b:c:d;" , fxt.Make("a", "b:c:d"));
}
}
class Gfh_style_parser__fxt {
private final Gfh_style_wkr__ary wkr = new Gfh_style_wkr__ary();
public Gfh_style_itm Make(String k, String v) {return new Gfh_style_itm(-1, Bry_.new_u8(k), Bry_.new_u8(v));}
public void Test__parse(String src_str, Gfh_style_itm... expd) {
byte[] src_bry = Bry_.new_u8(src_str);
Gfh_style_itm[] actl = wkr.Parse(src_bry, 0, src_bry.length);
Tfds.Eq_ary_str(expd, actl);
}
}

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_doc_tst {
private final Json_qry_mgr_fxt fxt = new Json_qry_mgr_fxt();
@Test public void Select() {
Json_doc doc = fxt.Make_json
( "{'0':"
, " {'0_0':"
, " {'0_0_0':'000'"
, " },"
, " '0_1':"
, " {'0_1_0':'010'"
, " }"
, " }"
, "}"
);
fxt.Test_get_val_as_str(doc, "0/0_0/0_0_0", "000");
fxt.Test_get_val_as_str(doc, "0/0_1/0_1_0", "010");
fxt.Test_get_val_as_str(doc, "x", null);
}
}
class Json_qry_mgr_fxt {
private final Json_parser json_parser = new Json_parser();
public Json_doc Make_json(String... ary) {return json_parser.Parse_by_apos_ary(ary);}
public void Test_get_val_as_str(Json_doc doc, String qry, String expd){
byte[][] qry_bry = Bry_split_.Split(Bry_.new_u8(qry), Byte_ascii.Slash);
Tfds.Eq(expd, doc.Get_val_as_str_or(qry_bry, null));
}
}

View File

@@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_kv_ary_srl_tst {
@Before public void init() {fxt.Clear();} private Json_kv_ary_srl_fxt fxt = new Json_kv_ary_srl_fxt();
@Test public void Null() {fxt.Test_parse("{'k0':null}" , fxt.ary_(fxt.kv_str_("k0", null)));}
@Test public void Bool_n() {fxt.Test_parse("{'k0':false}" , fxt.ary_(fxt.kv_bool_("k0", false)));}
@Test public void Num() {fxt.Test_parse("{'k0':123}" , fxt.ary_(fxt.kv_int_("k0", 123)));}
@Test public void Str() {fxt.Test_parse("{'k0':'v0'}" , fxt.ary_(fxt.kv_str_("k0", "v0")));}
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.kv_dec_("k0", Decimal_adp_.parse("1.23"))));}
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("1", 1), fxt.kv_int_("2", 2), fxt.kv_int_("3", 3)))));}
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));}
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1,'k01':2}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("k00", 1), fxt.kv_int_("k01", 2)))));}
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));}
}
class Json_kv_ary_srl_fxt {
public void Clear() {
if (parser == null) {
parser = new Json_parser();
}
} private Json_parser parser;
public void Test_parse(String raw_str, Keyval[] expd) {
byte[] raw_bry = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
Json_doc doc = parser.Parse(raw_bry);
Keyval[] actl = Json_kv_ary_srl.Val_by_itm_nde(doc.Root_nde());
Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
}
public Keyval[] ary_(Keyval... ary) {return ary;}
public Keyval kv_obj_(String key, Object val) {return Keyval_.new_(key, val);}
public Keyval kv_str_(String key, String val) {return Keyval_.new_(key, val);}
public Keyval kv_int_(String key, int val) {return Keyval_.new_(key, val);}
public Keyval kv_bool_(String key, boolean val) {return Keyval_.new_(key, Bool_.To_str_lower(val));}
public Keyval kv_dec_(String key, Decimal_adp val) {return Keyval_.new_(key, val.To_str());}
}

View File

@@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_parser_tst {
private final Json_parser_fxt fxt = new Json_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Null() {fxt.Test_parse_val0("{'k0':null}" , null);}
@Test public void Bool_n() {fxt.Test_parse_val0("{'k0':false}" , false);}
@Test public void Bool_y() {fxt.Test_parse_val0("{'k0':true}" , true);}
@Test public void Num() {fxt.Test_parse_val0("{'k0':123}" , 123);}
@Test public void Num_neg() {fxt.Test_parse_val0("{'k0':-123}" , -123);}
@Test public void Str() {fxt.Test_parse_val0("{'k0':'v0'}" , "v0");}
@Test public void Str_esc_quote() {fxt.Test_parse_val0("{'k0':'a\\\"b'}" , "a\"b");}
@Test public void Str_esc_hex4() {fxt.Test_parse_val0("{'k0':'a\\u0021b'}" , "a!b");}
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1.23")));}
@Test public void Num_exp() {fxt.Test_parse("{'k0':1e+2}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1e+2")));}
@Test public void Num_mix() {fxt.Test_parse("{'k0':-1.23e-1}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "-1.23e-1")));}
@Test public void Str_many() {fxt.Test_parse("{'k0':'v0','k1':'v1','k2':'v2'}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0"), fxt.itm_kv_("k1", "v1"), fxt.itm_kv_("k2", "v2")));}
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0")));}
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));}
@Test public void Ary_str() {fxt.Test_parse("{'k0':['a','b','c']}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_str_("k0", "a", "b", "c")));}
@Test public void Ary_ws() {fxt.Test_parse("{'k0': [ 1 , 2 , 3 ] }", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));}
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));}
@Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_())));}
@Test public void Subs_ws() {fxt.Test_parse("{'k0': { 'k00' : 1 } }", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));}
@Test public void Ws() {fxt.Test_parse(" { 'k0' : 'v0' } ", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0")));}
@Test public void Root_is_ary() {fxt.Test_parse("[ 1 , 2 , 3 ]", fxt.itm_ary_().Add_many(fxt.itm_int_(1), fxt.itm_int_(2), fxt.itm_int_(3)));}
public static String Replace_apos_as_str(String v) {return String_.new_u8(Replace_apos(Bry_.new_u8(v)));}
public static byte[] Replace_apos(byte[] v) {return Bry_.Replace(v, Byte_ascii.Apos, Byte_ascii.Quote);}
}
class Json_parser_fxt {
public void Clear() {
if (parser == null) {
parser = new Json_parser();
factory = parser.Factory();
}
} Json_parser parser; Json_factory factory; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public Json_itm itm_int_(int v) {return Json_itm_tmp.new_int_(v);}
Json_itm itm_str_(String v) {return Json_itm_tmp.new_str_(v);}
public Json_ary itm_ary_() {return factory.Ary(-1, -1);}
public Json_nde itm_nde_() {return factory.Nde(null, -1);}
public Json_kv itm_kv_null_(String k) {return factory.Kv(itm_str_(k), factory.Null());}
public Json_kv itm_kv_(String k, String v) {return factory.Kv(itm_str_(k), itm_str_(v));}
public Json_kv itm_kv_(String k, int v) {return factory.Kv(itm_str_(k), itm_int_(v));}
public Json_kv itm_kv_(String k, boolean v) {return factory.Kv(itm_str_(k), v ? factory.Bool_y() : factory.Bool_n());}
public Json_kv itm_kv_dec_(String k, String v) {return factory.Kv(itm_str_(k), new Json_itm_tmp(Json_itm_.Tid__decimal, v));}
public Json_kv itm_kv_(String k, Json_nde v) {return factory.Kv(itm_str_(k), v);}
public Json_kv itm_kv_ary_int_(String k, int... v) {
Json_ary ary = factory.Ary(-1, -1);
int len = v.length;
for (int i = 0; i < len; i++)
ary.Add(itm_int_(v[i]));
return factory.Kv(itm_str_(k), ary);
}
public Json_kv itm_kv_ary_str_(String k, String... v) {
Json_ary ary = factory.Ary(-1, -1);
int len = v.length;
for (int i = 0; i < len; i++)
ary.Add(itm_str_(v[i]));
return factory.Kv(itm_str_(k), ary);
}
public void Test_parse(String raw_str, Json_itm... expd_ary) {
byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
Json_doc doc = parser.Parse(raw);
doc.Root_grp().Print_as_json(tmp_bfr, 0);
String actl = tmp_bfr.To_str_and_clear();
String expd = Xto_str(raw, doc, expd_ary, 0, expd_ary.length);
Tfds.Eq_str_lines(expd, actl, actl);
}
public void Test_parse_val0(String raw_str, Object expd) {
byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
Json_doc doc = parser.Parse(raw);
Json_kv kv = Json_kv.cast(doc.Root_nde().Get_at(0)); // assume root has kv as first sub; EX: {"a":"b"}
Object actl = kv.Val().Data(); // NOTE: Data_bry is escaped val; EX: a\"b has DataBry of a"b
Tfds.Eq(expd, actl);
}
String Xto_str(byte[] raw, Json_doc doc, Json_itm[] ary, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Json_itm itm = ary[i];
itm.Print_as_json(tmp_bfr, 0);
}
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_printer_tst {
private final Json_printer_fxt fxt = new Json_printer_fxt();
@Test public void Root_nde() {
fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':'v1','k2':'v2'}"), String_.Concat_lines_nl
( "{ 'k1':'v1'"
, ", 'k2':'v2'"
, "}"
));
}
@Test public void Root_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("[1,2,3]"), String_.Concat_lines_nl
( "[ 1"
, ", 2"
, ", 3"
, "]"
));
}
@Test public void Ary_w_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("[[1,2],[3,4]]"), String_.Concat_lines_nl
( "[ "
, " [ 1"
, " , 2"
, " ]"
, ", "
, " [ 3"
, " , 4"
, " ]"
, "]"
));
}
@Test public void Ary_w_nde() {
fxt.Test_print(Json_doc.Make_str_by_apos("[{'k1':'v1','k2':'v2'},{'k3':'v3','k4':'v4'}]"), String_.Concat_lines_nl
( "[ "
, " { 'k1':'v1'"
, " , 'k2':'v2'"
, " }"
, ", "
, " { 'k3':'v3'"
, " , 'k4':'v4'"
, " }"
, "]"
));
}
@Test public void Nde_w_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':[1,2],'k2':[3,4]}"), String_.Concat_lines_nl
( "{ 'k1':"
, " [ 1"
, " , 2"
, " ]"
, ", 'k2':"
, " [ 3"
, " , 4"
, " ]"
, "}"
));
}
// @Test public void Smoke() {
// Json_printer printer = new Json_printer();
// String url = "C:\\temp.json";
// String s = printer.Pretty_print_as_str(Bry_.new_u8(Io_mgr.Instance.LoadFilStr(url)));
// Io_mgr.Instance.SaveFilStr(url, s);
// }
}
class Json_printer_fxt {
private final Json_printer printer = new Json_printer().Opt_quote_byte_(Byte_ascii.Apos);
public void Test_print(String raw, String expd) {
Tfds.Eq_str_lines(expd, printer.Print_by_bry(Bry_.new_u8(raw)).To_str());
}
}

View File

@@ -0,0 +1,132 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_wtr_tst {
@Before public void init() {fxt.Clear();} private final Json_wtr_fxt fxt = new Json_wtr_fxt();
@Test public void Root() {
fxt.Wtr().Doc_nde_bgn().Doc_nde_end();
fxt.Test
( "{"
, "}"
);
}
@Test public void Kv() {
fxt.Wtr()
.Doc_nde_bgn()
.Kv_str("k0", "v0")
.Kv_str("k1", "v1")
.Doc_nde_end();
fxt.Test
( "{ 'k0':'v0'"
, ", 'k1':'v1'"
, "}"
);
}
@Test public void Escaped() {
fxt.Wtr()
.Doc_nde_bgn()
.Kv_str("backslash", "\\")
.Kv_str("quote", "\"")
.Kv_str("apos", "'")
.Kv_str("nl", "\n")
.Kv_str("cr", "\r")
.Kv_str("tab", "\t")
.Doc_nde_end();
fxt.Test
( "{ 'backslash':'\\\\'"
, ", 'quote':'\\\"'"
, ", 'apos':'\''"
, ", 'nl':'\\\\n'"
, ", 'cr':'\\\\r'"
, ", 'tab':'\\\\t'"
, "}"
);
}
@Test public void Nde() {
fxt.Wtr()
.Doc_nde_bgn()
.Nde_bgn("s0")
.Nde_bgn("s00")
.Nde_end()
.Nde_end()
.Nde_bgn("s1")
.Nde_bgn("s10")
.Nde_end()
.Nde_end()
.Doc_nde_end();
fxt.Test
( "{ 's0':"
, " { 's00':"
, " {"
, " }"
, " }"
, ", 's1':"
, " { 's10':"
, " {"
, " }"
, " }"
, "}"
);
}
@Test public void Ary() {
fxt.Wtr()
.Doc_nde_bgn()
.Ary_bgn("a0")
.Ary_itm_str("v0")
.Ary_itm_str("v1")
.Ary_end()
.Doc_nde_end();
fxt.Test
( "{ 'a0':"
, " [ 'v0'"
, " , 'v1'"
, " ]"
, "}"
);
}
@Test public void Nde__nested() {
fxt.Wtr()
.Doc_nde_bgn()
.Ary_bgn("a0")
.Ary_itm_obj(Keyval_.Ary
( Keyval_.new_("k1", "v1")
, Keyval_.new_("k2", "v2")
))
.Ary_end()
.Doc_nde_end();
fxt.Test
( "{ 'a0':"
, " ["
, " { 'k1':'v1'"
, " , 'k2':'v2'"
, " }"
, " ]"
, "}"
);
}
}
class Json_wtr_fxt {
private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos);
public void Clear() {wtr.Clear();}
public Json_wtr Wtr() {return wtr;}
public void Test(String... expd) {
Tfds.Eq_ary_str
( String_.Ary_add(expd, String_.Ary("")) // json_wtr always ends with "}\n"; rather than add "\n" to each test, just add it here
, String_.SplitLines_nl(String_.new_u8(wtr.To_bry_and_clear()))
);
}
}

View File

@@ -0,0 +1,162 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.primitives.*;
public class Mustache_itm_render_tst {
private final Mustache_itm_render_fxt fxt = new Mustache_itm_render_fxt();
@Test public void Text() {
fxt.Test__parse("a b c", "a b c");
}
@Test public void Variable() {
fxt.Init__root(fxt.Make_mock(0).Add_prop("prop1", "1").Add_prop("prop2", "2"));
fxt.Test__parse("{{prop1}}", "1");
fxt.Test__parse("a{{prop1}}b{{prop2}}c", "a1b2c");
}
@Test public void Escape() {
fxt.Init__root(fxt.Make_mock(0).Add_prop("prop1", "<"));
fxt.Test__parse("{{{prop1}}}", "<");
fxt.Test__parse("{{prop1}}", "&lt;");
}
@Test public void Section_bool() {
fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y").Add_bool_n("bool_n"));
fxt.Test__parse("a{{#bool_y}}b{{/bool_y}}c", "abc");
fxt.Test__parse("a{{#bool_n}}b{{/bool_n}}c", "ac");
fxt.Test__parse("a{{#bool_y}}b{{/bool_y}}c{{#bool_n}}d{{/bool_n}}e", "abce");
}
@Test public void Section_not() {
fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y").Add_bool_n("bool_n"));
fxt.Test__parse("a{{^bool_y}}b{{/bool_y}}c", "ac");
fxt.Test__parse("a{{^bool_n}}b{{/bool_n}}c", "abc");
fxt.Test__parse("a{{^bool_y}}b{{/bool_y}}c{{^bool_n}}d{{/bool_n}}e", "acde");
}
@Test public void Section_ws() {
fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y"));
fxt.Test__parse("a\n {{#bool_y}} \nb\n {{/bool_y}} \nc", "a\nb\nc");
}
@Test public void Section_subs_flat() {
fxt.Init__root(fxt.Make_mock(0).Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "1").Add_subs("subs2")
, fxt.Make_mock(2).Add_prop("prop1", "2").Add_subs("subs2")
));
fxt.Test__parse("a{{#subs1}}({{prop1}}){{/subs1}}d", "a(1)(2)d");
}
@Test public void Section_subs_nest_1() {
fxt.Init__root
( fxt.Make_mock(0).Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2"
, fxt.Make_mock(11).Add_prop("prop2", "1")
, fxt.Make_mock(12).Add_prop("prop2", "2"))
));
fxt.Test__parse
( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{/subs1}}"
, "a12"
);
}
@Test public void Section_subs_nest_2() {
fxt.Init__root
( fxt.Make_mock(0).Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2"
, fxt.Make_mock(11).Add_prop("prop2", "1")
, fxt.Make_mock(12).Add_prop("prop2", "2")
)
, fxt.Make_mock(2).Add_prop("prop1", "b")
)
);
fxt.Test__parse
( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{/subs1}}"
, "a12b"
);
}
@Test public void Section_subs_nest_3() {
fxt.Init__root
( fxt.Make_mock(0).Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2"
, fxt.Make_mock(11).Add_prop("prop2", "1")
, fxt.Make_mock(12).Add_prop("prop2", "2")
)
, fxt.Make_mock(2).Add_prop("prop1", "b").Add_subs("subs2"
, fxt.Make_mock(21).Add_prop("prop2", "3")
, fxt.Make_mock(22).Add_prop("prop2", "4")
)
)
);
fxt.Test__parse
( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{prop1}}{{/subs1}}"
, "a12ab34b"
);
}
@Test public void Section_bool_subs() { // handle prop written after boolean; should not pick up inner prop
fxt.Init__root
( fxt.Make_mock(0).Add_bool_y("bool1").Add_prop("prop2", "2").Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "11")
, fxt.Make_mock(2).Add_prop("prop1", "12")
));
fxt.Test__parse
( "a{{#bool1}}b{{#subs1}}c{{prop1}}d{{/subs1}}e{{/bool1}}f{{prop2}}g"
, "abc11dc12def2g"
);
}
@Test public void Section_owner() {
fxt.Init__root
( fxt.Make_mock(0).Add_subs("subs1"
, fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2"
, fxt.Make_mock(11).Add_prop("prop2", "1")
)
));
fxt.Test__parse
( "{{#subs1}}{{#subs2}}{{prop1}}{{prop2}}{{/subs2}}{{/subs1}}" // prop1 is cited in subs2, but value belongs to subs1
, "a1"
);
}
}
class Mustache_itm_render_fxt {
private final Mustache_tkn_parser parser = new Mustache_tkn_parser();
private final Mustache_render_ctx ctx = new Mustache_render_ctx();
private final Mustache_bfr bfr = Mustache_bfr.New();
private Mustache_doc_itm__mock root;
public Mustache_doc_itm__mock Make_mock(int id) {return new Mustache_doc_itm__mock(id);}
public void Init__root(Mustache_doc_itm__mock v) {this.root = v;}
public void Test__parse(String src_str, String expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Mustache_tkn_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length);
ctx.Init(root);
actl_itm.Render(bfr, ctx);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}
class Mustache_doc_itm__mock implements Mustache_doc_itm {
private final Hash_adp hash_prop = Hash_adp_.New(), hash_bool = Hash_adp_.New(), hash_subs = Hash_adp_.New();
public Mustache_doc_itm__mock(int id) {this.id = id;}
public int id;
public Mustache_doc_itm__mock Add_prop(String key, String val) {hash_prop.Add(key, Bry_.new_u8(val)); return this;}
public Mustache_doc_itm__mock Add_bool_y(String key) {hash_bool.Add(key, Bool_obj_ref.y_()); return this;}
public Mustache_doc_itm__mock Add_bool_n(String key) {hash_bool.Add(key, Bool_obj_ref.n_()); return this;}
public Mustache_doc_itm__mock Add_subs(String key, Mustache_doc_itm__mock... ary) {hash_subs.Add(key, ary); return this;}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
byte[] rv = (byte[])hash_prop.Get_by(key);
if (rv == null) return false;
bfr.Add_bry(rv);
return true;
}
public Mustache_doc_itm[] Mustache__subs(String key) {
Object rv = hash_bool.Get_by(key);
if (rv != null) {
boolean bool_val = ((Bool_obj_ref)rv).Val();
return bool_val ? Mustache_doc_itm_.Ary__bool__y : Mustache_doc_itm_.Ary__bool__n;
}
return (Mustache_doc_itm__mock[])hash_subs.Get_by(key);
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.mustaches; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Mustache_tkn_parser_tst {
private final Mustache_tkn_parser_fxt fxt = new Mustache_tkn_parser_fxt();
@Test public void Basic() {
fxt.Test_parse("a{{b}}c", "ac");
}
@Test public void Comment() {
fxt.Test_parse("a{{!b}}c", "ac");
}
}
class Mustache_tkn_parser_fxt {
private final Mustache_tkn_parser parser = new Mustache_tkn_parser();
private final Mustache_render_ctx ctx = new Mustache_render_ctx();
private final Mustache_bfr bfr = Mustache_bfr.New();
public void Test_parse(String src_str, String expd) {
byte[] src_bry = Bry_.new_a7(src_str);
Mustache_tkn_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length);
actl_itm.Render(bfr, ctx);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,290 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
import gplx.core.tests.*; import gplx.core.log_msgs.*;
class Php_parser_fxt {
Php_tkn_factory tkn_factory = new Php_tkn_factory();
Php_parser parser = new Php_parser();
Php_tkn_wkr_tkn tkn_wkr = new Php_tkn_wkr_tkn();
Php_evaluator line_wkr = new Php_evaluator(new Gfo_msg_log("test"));
Tst_mgr tst_mgr = new Tst_mgr();
Gfo_msg_log_chkr log_mgr_chkr = new Gfo_msg_log_chkr();
public void Clear() {log_mgr_chkr.Clear(); tkn_wkr.Clear(); line_wkr.Clear();}
public Php_tkn_chkr_base tkn_declaration() {return Php_tkn_declaration_chkr.Instance;}
public Php_tkn_chkr_base tkn_txt(int bgn, int end) {return new Php_tkn_txt_chkr(bgn, end);}
public Php_tkn_chkr_base tkn_ws(int bgn, int end) {return new Php_tkn_ws_chkr(bgn, end);}
public Php_tkn_chkr_base tkn_generic(int bgn, int end, byte tid) {return new Php_tkn_generic_chkr(bgn, end, tid);}
public Php_tkn_comment_chkr tkn_comment_mult(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_mult);}
public Php_tkn_comment_chkr tkn_comment_slash(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_slash);}
public Php_tkn_comment_chkr tkn_comment_hash(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_hash);}
public Php_tkn_quote_chkr tkn_quote_apos(int bgn, int end) {return new Php_tkn_quote_chkr(bgn, end).Quote_tid_(Byte_ascii.Apos);}
public Php_tkn_quote_chkr tkn_quote_quote(int bgn, int end) {return new Php_tkn_quote_chkr(bgn, end).Quote_tid_(Byte_ascii.Quote);}
public Php_parser_fxt Msg(Gfo_msg_itm itm, int bgn, int end) {
log_mgr_chkr.Add_itm(itm, bgn, end);
return this;
}
public Php_tkn_var_chkr tkn_var(int bgn, int end, String v) {return new Php_tkn_var_chkr(bgn, end).Var_name_(v);}
public Php_tkn_num_chkr tkn_num(int bgn, int end, int v) {return new Php_tkn_num_chkr(bgn, end).Num_val_int_(v);}
public Php_line_assign_chkr line_assign(String key, Php_itm_chkr_base val) {return new Php_line_assign_chkr().Key_(key).Val_(val);}
public Php_line_assign_chkr line_assign_subs(String key, String[] subs, Php_itm_chkr_base val) {return new Php_line_assign_chkr().Key_(key).Subs_(subs).Val_(val);}
public Php_itm_chkr_base itm_bool_true() {return new Php_itm_generic_chkr(Php_itm_.Tid_bool_true);}
public Php_itm_chkr_base itm_bool_false() {return new Php_itm_generic_chkr(Php_itm_.Tid_bool_false);}
public Php_itm_chkr_base itm_null() {return new Php_itm_generic_chkr(Php_itm_.Tid_null);}
public Php_itm_chkr_base itm_quote(String v) {return new Php_itm_quote_chkr().Val_obj_str_(v);}
public Php_itm_chkr_base itm_int(int v) {return new Php_itm_int_chkr().Val_obj_int_(v);}
public Php_itm_chkr_base itm_txt(String v) {return new Php_itm_txt_chkr().Val_obj_str_(v);}
public Php_itm_ary_chkr itm_ary() {return new Php_itm_ary_chkr();}
public Php_itm_kv_chkr itm_kv_quote(String k, String v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_quote(v));}
public Php_itm_kv_chkr itm_kv_txt(String k, String v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_txt(v));}
public Php_itm_kv_chkr itm_kv_int(String k, int v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_int(v));}
public Php_itm_kv_chkr itm_kv_itm(String k, Php_itm_chkr_base v) {return new Php_itm_kv_chkr().Key_(k).Val_(v);}
public void tst_tkns(String raw, Php_tkn_chkr_base... expd) {
byte[] raw_bry = Bry_.new_u8(raw);
parser.Parse_tkns(raw_bry, tkn_wkr);
Php_tkn[] actl = (Php_tkn[])tkn_wkr.List().To_ary(Php_tkn.class);
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
tst_mgr.Tst_ary("", expd, actl);
log_mgr_chkr.tst(tst_mgr, tkn_wkr.Msg_log());
}
public void tst_lines(String raw, Php_line_assign_chkr... expd) {
byte[] raw_bry = Bry_.new_u8(raw);
parser.Parse_tkns(raw_bry, line_wkr);
Php_line[] actl = (Php_line[])line_wkr.List().To_ary(Php_line.class);
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
tst_mgr.Tst_ary("", expd, actl);
log_mgr_chkr.tst(tst_mgr, line_wkr.Msg_log());
}
}
abstract class Php_tkn_chkr_base implements Tst_chkr {
public abstract byte Tkn_tid();
public abstract Class<?> TypeOf();
public int Src_bgn() {return src_bgn;} private int src_bgn = -1;
public int Src_end() {return src_end;} private int src_end = -1;
public void Src_rng_(int src_bgn, int src_end) {this.src_bgn = src_bgn; this.src_end = src_end;}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Php_tkn actl = (Php_tkn)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "tkn_tid", this.Tkn_tid(), actl.Tkn_tid());
rv += mgr.Tst_val(src_bgn == -1, path, "src_bgn", src_bgn, actl.Src_bgn());
rv += mgr.Tst_val(src_end == -1, path, "src_end", src_end, actl.Src_end());
rv += Chk_tkn(mgr, path, actl);
return rv;
}
@gplx.Virtual public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {return 0;}
}
class Php_tkn_declaration_chkr extends Php_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Php_tkn_declaration.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_declaration;}
public static final Php_tkn_declaration_chkr Instance = new Php_tkn_declaration_chkr();
}
class Php_tkn_txt_chkr extends Php_tkn_chkr_base {
public Php_tkn_txt_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_txt.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_txt;}
}
class Php_tkn_ws_chkr extends Php_tkn_chkr_base {
public Php_tkn_ws_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_ws.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_ws;}
}
class Php_tkn_comment_chkr extends Php_tkn_chkr_base {
public Php_tkn_comment_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_comment.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_comment;}
public Php_tkn_comment_chkr Comment_tid_(byte v) {this.comment_tid = v; return this;} private byte comment_tid = Php_tkn_comment.Tid_null;
@Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {
Php_tkn_comment actl = (Php_tkn_comment)actl_obj;
int rv = 0;
rv += mgr.Tst_val(comment_tid == Php_tkn_comment.Tid_null, path, "comment_tid", comment_tid, actl.Comment_tid());
return rv;
}
}
class Php_tkn_quote_chkr extends Php_tkn_chkr_base {
public Php_tkn_quote_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_quote.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_quote;}
public Php_tkn_quote_chkr Quote_tid_(byte v) {this.quote_tid = v; return this;} private byte quote_tid = Byte_ascii.Null;
@Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {
Php_tkn_quote actl = (Php_tkn_quote)actl_obj;
int rv = 0;
rv += mgr.Tst_val(quote_tid == Byte_ascii.Null, path, "quote_tid", quote_tid, actl.Quote_tid());
return rv;
}
}
class Php_tkn_var_chkr extends Php_tkn_chkr_base {
public Php_tkn_var_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_var.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_var;}
public Php_tkn_var_chkr Var_name_(String v) {this.var_name = v; return this;} private String var_name;
@Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {
Php_tkn_var actl = (Php_tkn_var)actl_obj;
int rv = 0;
byte[] raw_bry = (byte[])mgr.Vars_get_by_key("raw_bry");
rv += mgr.Tst_val(var_name == null, path, "var_name", var_name, String_.new_u8(actl.Var_name(raw_bry)));
return rv;
}
}
class Php_tkn_num_chkr extends Php_tkn_chkr_base {
public Php_tkn_num_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public Class<?> TypeOf() {return Php_tkn_num.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_num;}
public Php_tkn_num_chkr Num_val_int_(int v) {this.num_val_int = v; return this;} private int num_val_int = Int_.Min_value;
@Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {
Php_tkn_num actl = (Php_tkn_num)actl_obj;
int rv = 0;
byte[] raw_bry = (byte[])mgr.Vars_get_by_key("raw_bry");
rv += mgr.Tst_val(num_val_int == Int_.Min_value, path, "num_val_int", num_val_int, actl.Num_val_int(raw_bry));
return rv;
}
}
class Php_tkn_generic_chkr extends Php_tkn_chkr_base {
public Php_tkn_generic_chkr(int src_bgn, int src_end, byte tkn_tid) {this.Src_rng_(src_bgn, src_end); this.tkn_tid = tkn_tid;}
@Override public Class<?> TypeOf() {return Php_tkn.class;}
@Override public byte Tkn_tid() {return tkn_tid;} private byte tkn_tid;
}
class Php_line_assign_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Php_line_assign.class;}
public Php_line_assign_chkr Key_(String v) {key = v; return this;} private String key;
public Php_line_assign_chkr Subs_(String[] v) {
int subs_len = v.length;
subs = new Php_itm_quote_chkr[subs_len];
for (int i = 0; i < subs_len; i++)
subs[i] = new Php_itm_quote_chkr().Val_obj_str_(v[i]);
return this;
} Php_itm_chkr_base[] subs;
public Php_line_assign_chkr Val_(Php_itm_chkr_base v) {val = v; return this;} Php_itm_chkr_base val;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Php_line_assign actl = (Php_line_assign)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key().Val_obj_bry()));
if (subs != null) rv += mgr.Tst_sub_ary(subs, actl.Key_subs(), "subs", rv);
rv += mgr.Tst_sub_obj(val, actl.Val(), "val", rv);
return rv;
}
}
abstract class Php_itm_chkr_base implements Tst_chkr {
public abstract byte Itm_tid();
public abstract Class<?> TypeOf();
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Php_itm actl = (Php_itm)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "tkn_tid", this.Itm_tid(), actl.Itm_tid());
rv += Chk_itm(mgr, path, actl);
return rv;
}
@gplx.Virtual public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {return 0;}
public static final Php_itm_chkr_base[] Ary_empty = new Php_itm_chkr_base[0];
}
class Php_itm_generic_chkr extends Php_itm_chkr_base {
public Php_itm_generic_chkr(byte itm_tid) {this.itm_tid = itm_tid;} private byte itm_tid;
@Override public byte Itm_tid() {return itm_tid;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
}
class Php_itm_int_chkr extends Php_itm_chkr_base {
@Override public byte Itm_tid() {return Php_itm_.Tid_int;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
public Php_itm_int_chkr Val_obj_int_(int v) {this.val_obj_int = v; return this;} private int val_obj_int;
@Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {
Php_itm_int actl = (Php_itm_int)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_int, actl.Val_obj_int());
return rv;
}
}
class Php_itm_txt_chkr extends Php_itm_chkr_base {
@Override public byte Itm_tid() {return Php_itm_.Tid_var;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
public Php_itm_txt_chkr Val_obj_str_(String v) {this.val_obj_str = v; return this;} private String val_obj_str;
@Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {
Php_itm_var actl = (Php_itm_var)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_str, String_.new_u8(actl.Val_obj_bry()));
return rv;
}
}
class Php_itm_quote_chkr extends Php_itm_chkr_base {
@Override public byte Itm_tid() {return Php_itm_.Tid_quote;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
public Php_itm_quote_chkr Val_obj_str_(String v) {this.val_obj_str = v; return this;} private String val_obj_str;
@Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {
Php_itm_quote actl = (Php_itm_quote)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_str, String_.new_u8(actl.Val_obj_bry()));
return rv;
}
}
class Php_itm_ary_chkr extends Php_itm_chkr_base {
@Override public byte Itm_tid() {return Php_itm_.Tid_ary;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
public Php_itm_ary_chkr Subs_(Php_itm_chkr_base... v) {this.itms = v; return this;} Php_itm_chkr_base[] itms = Php_itm_chkr_base.Ary_empty;
@Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {
Php_itm_ary actl = (Php_itm_ary)actl_obj;
int rv = 0;
int actl_subs_len = actl.Subs_len();
Php_itm[] actl_ary = new Php_itm[actl_subs_len];
for (int i = 0; i < actl_subs_len; i++) {
actl_ary[i] = (Php_itm)actl.Subs_get(i);
}
rv += mgr.Tst_sub_ary(itms, actl_ary, "subs", rv);
return rv;
}
}
class Php_itm_kv_chkr extends Php_itm_chkr_base {
@Override public byte Itm_tid() {return Php_itm_.Tid_kv;}
@Override public Class<?> TypeOf() {return Php_itm.class;}
public Php_itm_kv_chkr Key_(String v) {key = v; return this;} private String key;
public Php_itm_kv_chkr Val_(Php_itm_chkr_base v) {val = v; return this;} Php_itm_chkr_base val;
@Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {
Php_itm_kv actl = (Php_itm_kv)actl_obj;
int rv = 0;
rv += mgr.Tst_val(false, path, "key", key, String_.new_u8(actl.Key().Val_obj_bry()));
rv += mgr.Tst_sub_obj(val, actl.Val(), path, rv);
return rv;
}
}
class Gfo_msg_log_chkr implements Tst_chkr {
List_adp itms = List_adp_.New();
public Class<?> TypeOf() {return Gfo_msg_log.class;}
public void Clear() {itms.Clear();}
public void Add_itm(Gfo_msg_itm itm, int bgn, int end) {
Gfo_msg_data_chkr chkr = new Gfo_msg_data_chkr();
chkr.Itm_(itm).Excerpt_bgn_(bgn).Excerpt_end_(end);
itms.Add(chkr);
}
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {return 0;}
public void tst(Tst_mgr mgr, Object actl_obj) {
Gfo_msg_log actl = (Gfo_msg_log)actl_obj;
int actl_itms_len = actl.Ary_len();
Gfo_msg_data[] actl_itms = new Gfo_msg_data[actl_itms_len];
for (int i = 0; i < actl_itms_len; i++)
actl_itms[i] = actl.Ary_get(i);
mgr.Tst_ary("itms", (Gfo_msg_data_chkr[])itms.To_ary(Gfo_msg_data_chkr.class), actl_itms);
}
}
class Gfo_msg_data_chkr implements Tst_chkr {
public Class<?> TypeOf() {return Gfo_msg_data.class;}
public Gfo_msg_data_chkr Itm_(Gfo_msg_itm v) {itm = v; return this;} Gfo_msg_itm itm;
public Gfo_msg_data_chkr Excerpt_bgn_(int v) {excerpt_bgn = v; return this;} private int excerpt_bgn = -1;
public Gfo_msg_data_chkr Excerpt_end_(int v) {excerpt_end = v; return this;} private int excerpt_end = -1;
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Gfo_msg_data actl = (Gfo_msg_data)actl_obj;
int rv = 0;
rv += mgr.Tst_val(itm == null, path, "itm", itm.Path_str(), actl.Item().Path_str());
rv += mgr.Tst_val(excerpt_bgn == -1, path, "excerpt_bgn", excerpt_bgn, actl.Src_bgn());
rv += mgr.Tst_val(excerpt_end == -1, path, "excerpt_end", excerpt_end, actl.Src_end());
return rv;
}
}

View File

@@ -0,0 +1,82 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Php_parser_tst {
@Before public void init() {fxt.Clear();} private final Php_parser_fxt fxt = new Php_parser_fxt();
@Test public void Text() {fxt.tst_tkns("text", fxt.tkn_txt(0, 4)); }
@Test public void Declaration_pass() {fxt.tst_tkns("<?php", fxt.tkn_declaration());}
@Test public void Declaration_fail() {fxt.tst_tkns("<?phpx", fxt.tkn_txt(0, 6));}
@Test public void Ws_basic() {fxt.tst_tkns(" ", fxt.tkn_ws(0, 1));}
@Test public void Ws_mix() {fxt.tst_tkns(" a\n", fxt.tkn_ws(0, 1), fxt.tkn_txt(1, 2), fxt.tkn_ws(2, 3));}
@Test public void Comment_mult() {fxt.tst_tkns("/*a*/", fxt.tkn_comment_mult(0, 5));}
@Test public void Comment_slash() {fxt.tst_tkns("//a\n", fxt.tkn_comment_slash(0, 4));}
@Test public void Comment_hash() {fxt.tst_tkns("#a\n", fxt.tkn_comment_hash(0, 3));}
@Test public void Comment_mult_fail() {fxt.Msg(Php_lxr_comment.Dangling_comment, 0, 2).tst_tkns("/*a", fxt.tkn_comment_mult(0, 3));}
@Test public void Var() {fxt.tst_tkns("$abc", fxt.tkn_var(0, 4, "abc"));}
@Test public void Sym() {fxt.tst_tkns(";==>,()", fxt.tkn_generic(0, 1, Php_tkn_.Tid_semic), fxt.tkn_generic(1, 2, Php_tkn_.Tid_eq), fxt.tkn_generic(2, 4, Php_tkn_.Tid_eq_kv), fxt.tkn_generic(4, 5, Php_tkn_.Tid_comma), fxt.tkn_generic(5, 6, Php_tkn_.Tid_paren_bgn), fxt.tkn_generic(6, 7, Php_tkn_.Tid_paren_end));}
@Test public void Keyword() {fxt.tst_tkns("null=nulla", fxt.tkn_generic(0, 4, Php_tkn_.Tid_null), fxt.tkn_generic(4, 5, Php_tkn_.Tid_eq), fxt.tkn_txt(5, 10));}
@Test public void Num() {fxt.tst_tkns("0=123", fxt.tkn_num(0, 1, 0), fxt.tkn_generic(1, 2, Php_tkn_.Tid_eq), fxt.tkn_num(2, 5, 123));}
@Test public void Quote_apos() {fxt.tst_tkns("'a\"b'", fxt.tkn_quote_apos(0, 5));}
@Test public void Quote_quote() {fxt.tst_tkns("\"a'b\"", fxt.tkn_quote_quote(0, 5));}
@Test public void Quote_escape() {fxt.tst_tkns("'a\\'b'", fxt.tkn_quote_apos(0, 6));}
@Test public void Brack() {fxt.tst_tkns("['a']", fxt.tkn_generic(0, 1, Php_tkn_.Tid_brack_bgn), fxt.tkn_quote_apos(1, 4), fxt.tkn_generic(4, 5, Php_tkn_.Tid_brack_end));}
@Test public void Line_ws() {fxt.tst_lines("\r\n$a = false;", fxt.line_assign("a", fxt.itm_bool_false()));}
@Test public void Line_brack() {fxt.tst_lines("$a['b'] = 'c';", fxt.line_assign_subs("a", String_.Ary("b"), fxt.itm_quote("c")));}
@Test public void Line_assign_false() {fxt.tst_lines("$a = false;", fxt.line_assign("a", fxt.itm_bool_false()));}
@Test public void Line_assign_quote_charcode() {fxt.tst_lines("$a = 'bc';", fxt.line_assign("a", fxt.itm_quote("bc")));}
@Test public void Line_assign_mult() {fxt.tst_lines("$a = 'b';\n$c='d';", fxt.line_assign("a", fxt.itm_quote("b")), fxt.line_assign("c", fxt.itm_quote("d")));}
@Test public void Empty_usr_array() {
fxt.tst_lines("$a = array();\n$b = array();"
, fxt.line_assign("a", fxt.itm_ary())
, fxt.line_assign("b", fxt.itm_ary())
);
}
@Test public void Ary_flat() {fxt.tst_lines("$a = array('b', 'c', 'd');" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_quote("c"), fxt.itm_quote("d"))));}
@Test public void Brack_flat() {fxt.tst_lines("$a = ['b', 'c', 'd'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_quote("c"), fxt.itm_quote("d"))));}
@Test public void Ary_flat_escape() { // PURPOSE.fix: \\' was being interpreted incorrectly; \\ should escape \, but somehow \' was being escaped
fxt.tst_lines("$a = array('b\\\\', 'c');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b\\\\"), fxt.itm_quote("c"))));
}
@Test public void Ary_flat_escape2() { // PURPOSE.fix: \\' was being interpreted incorrectly; \\ should escape \, but somehow \' was being escaped
fxt.tst_lines("$a = array('b\\\\\\'c', 'd');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b\\\\\\'c"), fxt.itm_quote("d"))));
}
@Test public void Ary_kv() {fxt.tst_lines("$a = array(k0 => 'v0', k1 => 'v1', k2 => 'v2');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_quote("k0", "v0"), fxt.itm_kv_quote("k1", "v1"), fxt.itm_kv_quote("k2", "v2"))));}
@Test public void Brack_kv() {fxt.tst_lines("$a = [k0 => 'v0', k1 => 'v1', k2 => 'v2'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_quote("k0", "v0"), fxt.itm_kv_quote("k1", "v1"), fxt.itm_kv_quote("k2", "v2"))));}
@Test public void Ary_kv_num() {fxt.tst_lines("$a = array(k0 => 0, k1 => 1);", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_int("k0", 0), fxt.itm_kv_int("k1", 1))));}
@Test public void Ary_kv_txt() {fxt.tst_lines("$a = array('k0' => a, 'k1' => b);", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_txt("k0", "a"), fxt.itm_kv_txt("k1", "b"))));}
@Test public void Ary_nest() {fxt.tst_lines("$a = array('b', array('c', 'd'), 'e');" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_ary().Subs_(fxt.itm_quote("c"), fxt.itm_quote("d")), fxt.itm_quote("e"))));}
@Test public void Brack_nest() {fxt.tst_lines("$a = ['b', ['c', 'd'], 'e'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_ary().Subs_(fxt.itm_quote("c"), fxt.itm_quote("d")), fxt.itm_quote("e"))));}
@Test public void Ary_nest_kv() {
fxt.tst_lines("$a = array('i00' => array('01', '02'), 'i10' => array('11', '12'), 'i20' => array('21', '22'));"
, fxt.line_assign
( "a"
, fxt.itm_ary().Subs_
( fxt.itm_kv_itm("i00", fxt.itm_ary().Subs_(fxt.itm_quote("01"), fxt.itm_quote("02")))
, fxt.itm_kv_itm("i10", fxt.itm_ary().Subs_(fxt.itm_quote("11"), fxt.itm_quote("12")))
, fxt.itm_kv_itm("i20", fxt.itm_ary().Subs_(fxt.itm_quote("21"), fxt.itm_quote("22")))
)));
}
@Test public void Brack_nest_kv() {
fxt.tst_lines("$a = ['i00' => ['01', '02'], 'i10' => ['11', '12'], 'i20' => ['21', '22']];"
, fxt.line_assign
( "a"
, fxt.itm_ary().Subs_
( fxt.itm_kv_itm("i00", fxt.itm_ary().Subs_(fxt.itm_quote("01"), fxt.itm_quote("02")))
, fxt.itm_kv_itm("i10", fxt.itm_ary().Subs_(fxt.itm_quote("11"), fxt.itm_quote("12")))
, fxt.itm_kv_itm("i20", fxt.itm_ary().Subs_(fxt.itm_quote("21"), fxt.itm_quote("22")))
)));
}
}

View File

@@ -0,0 +1,110 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Php_srl_parser_tst {
Php_srl_parser_fxt fxt = new Php_srl_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Nil() {fxt.Test_parse("N;", fxt.itm_nil_());}
@Test public void Bool_y() {fxt.Test_parse("b:1;", fxt.itm_bool_y_());}
@Test public void Bool_n() {fxt.Test_parse("b:0;", fxt.itm_bool_n_());}
@Test public void Num_int() {fxt.Test_parse("i:123;", fxt.itm_int_(123));}
@Test public void Num_int_neg() {fxt.Test_parse("i:-123;", fxt.itm_int_(-123));}
@Test public void Num_double() {fxt.Test_parse("d:1.23;", fxt.itm_double_(1.23d));}
@Test public void Num_double_inf_pos(){fxt.Test_parse("d:INF;", fxt.itm_double_(Double_.Inf_pos));}
@Test public void Num_double_exp() {fxt.Test_parse("d:1.2e+2;", fxt.itm_double_(120));}
@Test public void Num_double_nan() {fxt.Test_parse("d:NAN;", fxt.itm_double_(Double_.NaN));}
@Test public void Str_len_3() {fxt.Test_parse("s:3:\"abc\";", fxt.itm_str_("abc"));}
@Test public void Str_len_4() {fxt.Test_parse("s:4:\"abcd\";", fxt.itm_str_("abcd"));}
@Test public void Str_len_0() {fxt.Test_parse("s:0:\"\";", fxt.itm_str_(""));}
@Test public void Ary_empty() {fxt.Test_parse("a:0:{}", fxt.itm_ary_());}
@Test public void Ary_flat_one() {fxt.Test_parse("a:1:{i:1;i:9;}", fxt.itm_ary_().Subs_add(fxt.itm_kvi_(1, fxt.itm_int_(9))));}
@Test public void Ary_flat_many() {
fxt.Test_parse(String_.Concat
( "a:3:{"
, "i:1;i:9;"
, "i:2;i:8;"
, "i:3;i:7;"
, "}"), fxt.itm_ary_().Subs_add_many
( fxt.itm_kvi_(1, fxt.itm_int_(9))
, fxt.itm_kvi_(2, fxt.itm_int_(8))
, fxt.itm_kvi_(3, fxt.itm_int_(7))
));
}
@Test public void Ary_nest_one() {
fxt.Test_parse(String_.Concat
( "a:1:{"
, "i:1;"
, "a:2:{"
, "i:1;i:9;"
, "i:2;i:8;"
, "}"
, "}"
)
, fxt.itm_ary_().Subs_add_many
( fxt.itm_kvi_(1, fxt.itm_ary_().Subs_add_many
( fxt.itm_kvi_(1, fxt.itm_int_(9))
, fxt.itm_kvi_(2, fxt.itm_int_(8))
))));
}
@Test public void Ary_key_str() {
fxt.Test_parse(String_.Concat
( "a:1:{"
, "s:3:\"abc\";"
, "i:987;"
, "}"), fxt.itm_ary_().Subs_add_many
( fxt.itm_kvs_("abc", fxt.itm_int_(987))
));
}
@Test public void Func() {
fxt.Test_parse("O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:123;}", fxt.itm_func_(123));
}
@Test public void Smoke() {
// fxt.Test_parse("a:2:{s:6:\"values\";a:1:{i:1;a:9:{s:21:\"makeProt"+"ectedEnvFuncs\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:2;}s:3:\"log\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:3;}s:14:\"clearLogBuffer\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:4;}s:5:\"setup\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:5;}s:5:\"clone\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:6;}s:15:\"getCurrentFrame\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:7;}s:13:\"executeModule\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:8;}s:15:\"executeFunction\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:9;}s:12:\"getLogBuffer\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:10;}}}s:2:\"op\";s:6:\"return\";}");
}
}
class Php_srl_parser_fxt {
public void Clear() {
parser = new Php_srl_parser();
factory = parser.Factory();
} Php_srl_parser parser; Php_srl_factory factory; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public Php_srl_itm itm_nil_() {return factory.Nil();}
public Php_srl_itm itm_bool_n_() {return factory.Bool_n();}
public Php_srl_itm itm_bool_y_() {return factory.Bool_y();}
public Php_srl_itm itm_int_(int v) {return factory.Int(-1, -1, v);}
public Php_srl_itm itm_double_(double v) {return factory.Double(-1, -1, v);}
public Php_srl_itm itm_str_(String v) {return factory.Str(-1, -1, v);}
public Php_srl_itm itm_func_(int v) {return factory.Func(-1, -1, v);}
public Php_srl_itm_ary itm_ary_() {return factory.Ary(-1, -1);}
public Php_srl_itm_kv itm_kvi_(int k, Php_srl_itm v){return factory.Kv().Key_(itm_int_(k)).Val_(v);}
public Php_srl_itm_kv itm_kvs_(String k, Php_srl_itm v){return factory.Kv().Key_(itm_str_(k)).Val_(v);}
public void Test_parse(String raw_str, Php_srl_itm... expd_ary) {
byte[] raw = Bry_.new_u8(raw_str);
Php_srl_itm_ary root = parser.Parse(raw);
Php_srl_itm root_sub = root.Subs_get_at(0).Val();
root_sub.Xto_bfr(tmp_bfr, 0);
String actl = tmp_bfr.To_str_and_clear();
String expd = Xto_str(expd_ary, 0, expd_ary.length);
Tfds.Eq_str_lines(expd, actl, actl);
}
String Xto_str(Php_srl_itm[] ary, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Php_srl_itm itm = ary[i];
itm.Xto_bfr(tmp_bfr, 0);
}
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Php_text_itm_tst {
@Before public void init() {fxt.Clear();} private Php_text_itm_fxt fxt = new Php_text_itm_fxt();
@Test public void Q1_basic() {fxt.Init_q1().Test_parse("abcde" , "abcde");}
@Test public void Q1_apos() {fxt.Init_q1().Test_parse("a\\'b" , "a'b");}
@Test public void Q1_backslash() {fxt.Init_q1().Test_parse("a\\\\b" , "a\\b");}
@Test public void Q1_backslash_eos() {fxt.Init_q1().Test_parse("a\\" , "a\\");} // PURPOSE: allow single trailing backslash; DATE:2014-08-06
@Test public void Q1_noop() {fxt.Init_q1().Test_parse("a\\$\\nb" , "a\\$\\nb");}
@Test public void Q2_basic() {fxt.Init_q2().Test_parse("abcde" , "abcde");}
@Test public void Q2_quote() {fxt.Init_q2().Test_parse("a\\\"b" , "a\"b");}
@Test public void Q2_backslash() {fxt.Init_q2().Test_parse("a\\\\b" , "a\\b");}
@Test public void Q2_noop() {fxt.Init_q2().Test_parse("a\\%\\cb" , "a\\%\\cb");}
@Test public void Q2_ws() {fxt.Init_q2().Test_parse("a\\tb\\nc" , "a\tb\nc");}
@Test public void Q2_fmt() {fxt.Init_q2().Test_parse("a$1b$2c" , "a~{0}b~{1}c");}
@Test public void Q2_utf_pipe() {fxt.Init_q2().Test_parse("a\\u007Cd" , "a|d");}
@Test public void Q2_hex_nbsp() {fxt.Init_q2().Test_parse("a\\xc2\\xa0d" , "a\\u00c2\\u00a0d");}
}
class Php_text_itm_fxt {
private Php_text_itm_parser parser;
public void Clear() {parser = new Php_text_itm_parser();}
public Php_text_itm_fxt Init_q1() {parser.Quote_is_single_(Bool_.Y); return this;}
public Php_text_itm_fxt Init_q2() {parser.Quote_is_single_(Bool_.N); return this;}
public void Test_parse(String raw_str, String expd) {
List_adp list = List_adp_.New();
byte[] raw = Bry_.new_u8(raw_str);
parser.Parse(list, raw);
Bry_bfr bfr = Bry_bfr_.Reset(255);
int list_len = list.Count();
for (int i = 0; i < list_len; i++) {
Php_text_itm itm = (Php_text_itm)list.Get_at(i);
itm.Bld(bfr, raw);
}
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,91 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.strings.*;
public class Gfo_pattern_tst {
@Before public void init() {fxt.Clear();} private Gfo_pattern_itm_fxt fxt = new Gfo_pattern_itm_fxt();
@Test public void Compile() {
fxt.Test_Compile("a" , fxt.itm_text_("a"));
fxt.Test_Compile("*" , fxt.itm_wild_());
fxt.Test_Compile("a*" , fxt.itm_text_("a"), fxt.itm_wild_());
fxt.Test_Compile("*a" , fxt.itm_wild_(), fxt.itm_text_("a"));
fxt.Test_Compile("*ab*" , fxt.itm_wild_(), fxt.itm_text_("ab"), fxt.itm_wild_());
fxt.Test_Compile("" );
}
@Test public void Match() {
Gfo_pattern pattern = fxt.pattern_("abc");
fxt.Test_Match_y(pattern, "abc");
fxt.Test_Match_n(pattern, "ab", "a", "bc", "Abc", "");
}
@Test public void Match_all() {
Gfo_pattern pattern = fxt.pattern_("*");
fxt.Test_Match_y(pattern, "a", "abc", "");
}
@Test public void Match_bgn() {
Gfo_pattern pattern = fxt.pattern_("abc*");
fxt.Test_Match_y(pattern, "abc", "abcdef");
fxt.Test_Match_n(pattern, "abd", "aabc", "");
}
@Test public void Match_end() {
Gfo_pattern pattern = fxt.pattern_("*abc");
fxt.Test_Match_y(pattern, "abc", "xyzabc");
fxt.Test_Match_n(pattern, "abcd", "");
}
@Test public void Match_mid() {
Gfo_pattern pattern = fxt.pattern_("a*c*e");
fxt.Test_Match_y(pattern, "ace", "abcde");
fxt.Test_Match_n(pattern, "abc", "");
}
@Test public void Bug_ctx() { // PURPOSE.fix: cb was true b/c ctx was not reset correctly
Gfo_pattern pattern = fxt.pattern_("b*");
fxt.Test_Match_y(pattern, "bc");
fxt.Test_Match_n(pattern, "cb");
}
}
class Gfo_pattern_itm_fxt {
public void Clear() {}
public Gfo_pattern pattern_(String raw) {return new Gfo_pattern(Bry_.new_u8(raw));}
public void Test_Match_y(Gfo_pattern pattern, String... itms) {Test_Match(pattern, itms, Bool_.Y);}
public void Test_Match_n(Gfo_pattern pattern, String... itms) {Test_Match(pattern, itms, Bool_.N);}
private void Test_Match(Gfo_pattern pattern, String[] itms, boolean expd) {
int len = itms.length;
for (int i = 0; i < len; i++) {
String itm = itms[i];
Tfds.Eq(expd, pattern.Match(Bry_.new_u8(itm)), "pattern={0} itm={1} expd={2}", String_.new_u8(pattern.Raw()), itm, expd);
}
}
public Gfo_pattern_itm_wild itm_wild_() {return Gfo_pattern_itm_wild.Instance;}
public Gfo_pattern_itm_text itm_text_(String raw) {
Gfo_pattern_itm_text rv = new Gfo_pattern_itm_text();
byte[] bry = Bry_.new_u8(raw);
rv.Compile(bry, 0, bry.length);
return rv;
}
public void Test_Compile(String raw, Gfo_pattern_itm... expd) {
Gfo_pattern_itm[] actl = Gfo_pattern_itm_.Compile(Bry_.new_u8(raw));
Tfds.Eq(Ary_xto_str(expd), Ary_xto_str(actl));
}
private static String Ary_xto_str(Gfo_pattern_itm[] ary) {
int len = ary.length;
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < len; i++) {
if (i != 0) sb.Add_char_nl();
Gfo_pattern_itm itm = ary[i];
itm.Xto_str(sb);
}
return sb.To_str_and_clear();
}
}

View File

@@ -0,0 +1,79 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.xmls; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfo_xml_wtr_tst {
private final Gfo_xml_wtr_fxt fxt = new Gfo_xml_wtr_fxt();
@Before public void init() {}
@Test public void Root() {
fxt.Wtr().Nde_lhs("a").Nde_rhs();
fxt.Test_bld("<a>", "</a>");
}
@Test public void Nest() {
fxt.Wtr()
.Nde_lhs("a")
. Nde_lhs("a_a")
. Nde_lhs("a_a_a")
. Nde_rhs()
. Nde_rhs()
.Nde_rhs()
;
fxt.Test_bld
( "<a>"
, " <a_a>"
, " <a_a_a>"
, " </a_a_a>"
, " </a_a>"
, "</a>"
);
}
@Test public void Atrs() {
fxt.Wtr()
.Nde_lhs_bgn_itm("a")
.Atr_kv_str_a7("b", "b1")
.Nde_lhs_end()
.Nde_rhs()
;
fxt.Test_bld("<a b='b1'></a>");
}
@Test public void Atrs_escape() {
fxt.Wtr()
.Nde_lhs_bgn_itm("a")
.Atr_kv_str_a7("b", "'\"<>&")
.Nde_lhs_end()
.Nde_rhs()
;
fxt.Test_bld("<a b='&apos;\"<>&'></a>");
}
@Test public void Nde_txt() {
fxt.Wtr()
.Nde_txt_str("a", "a123")
;
fxt.Test_bld("<a>a123</a>");
}
@Test public void Nde_txt_escape() {
fxt.Wtr()
.Nde_txt_str("a", "'\"<>&x")
;
fxt.Test_bld("<a>'\"&lt;&gt;&amp;x</a>");
}
}
class Gfo_xml_wtr_fxt {
public Gfo_xml_wtr Wtr() {return wtr;} private final Gfo_xml_wtr wtr = new Gfo_xml_wtr();
public void Test_bld(String... lines) {
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(lines), wtr.Bld_str());
}
}

View File

@@ -0,0 +1,105 @@
/*
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.xowa; import gplx.*;
import gplx.core.envs.*;
import gplx.gfui.kits.core.*;
import gplx.langs.gfs.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
import gplx.xowa.apps.*; import gplx.xowa.files.exts.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.guis.tabs.*;
public class Xoa_app_fxt {
public static Xoae_app Make__app__edit() {
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
return Make__app__edit("linux", Io_url_.mem_dir_("mem/xowa/"));
}
public static Xoae_app Make__app__edit(String op_sys, Io_url root_dir) {
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
Xoae_app app = new Xoae_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_cmd, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), op_sys);
GfsCore.Instance.Clear(); // NOTE: must clear
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_app); // NOTE: must add app to GfsCore; app.Gfs_mgr() always adds current app to GfsCore; note this causes old test to leave behind GfsCore for new test
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_xowa); // add alias for app; DATE:2014-06-09
return app;
}
public static Xoav_app Make__app__view() {
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
return Make__app__view("linux", Io_url_.mem_dir_("mem/xowa/"));
}
public static Xoav_app Make__app__view(String op_sys, Io_url root_dir) {
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
Xoav_app rv = new Xoav_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_gui, Xog_tab_mgr_.New_mem(), op_sys, root_dir, root_dir.GenSubDir("file"), root_dir.GenSubDir("css"), root_dir);
rv.Init_by_app(user_dir);
rv.Wiki_mgr().Add(new Xowv_wiki(rv, Xow_domain_itm_.Bry__home, user_dir));
return rv;
}
public static Xowv_wiki Make__wiki__view(Xoa_app app) {return Make__wiki__view(app, "en.wikipedia.org");}
public static Xowv_wiki Make__wiki__view(Xoa_app app, String domain_str) {
byte[] domain_bry = Bry_.new_u8(domain_str);
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_str);
Xowv_wiki rv = new Xowv_wiki((Xoav_app)app, domain_bry, wiki_dir);
((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv);
return rv;
}
public static Xowe_wiki Make__wiki__edit__nonwmf(Xoae_app app, String key) {
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true);
Xol_lang_itm_.Lang_init(lang);
return Make__wiki__edit(app, key, lang);
}
public static Xowe_wiki Make__wiki__edit(Xoae_app app) {return Make__wiki__edit(app, "en.wikipedia.org");}
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key) {return Make__wiki__edit(app, key, app.Lang_mgr().Lang_en());}
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key, Xol_lang_itm lang) {
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key);
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir);
rv.File_mgr().Dbmeta_mgr().Depth_(2); // TEST: written for 2 depth
rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs)
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true);
app.Wiki_mgr().Add(rv);
return rv;
}
public static void repo_(Xoae_app app, Xowe_wiki wiki) {
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
app.File_mgr().Repo_mgr().Set("src:c", "mem/wiki/repo/src/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:c", "mem/wiki/repo/trg/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c"));
}
public static void repo2_(Xoae_app app, Xowe_wiki wiki) {
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm"));
}
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {
app.Gui_mgr().Browser_win().Init_by_kit(Mem_kit.Instance);
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(wiki, Xoae_page.Empty);
}
public static Xob_bldr bldr_(Xoae_app app) {
Xob_bldr rv = new Xob_bldr(app);
rv.Sort_mem_len_(Io_mgr.Len_kb).Dump_fil_len_(Io_mgr.Len_kb).Make_fil_len_(Io_mgr.Len_kb);
return rv;
}
public static final Io_url Root_dir = Op_sys.Cur().Tid_is_lnx() ? Io_url_.new_dir_("/xowa/") : Io_url_.new_dir_("C:\\xowa\\");
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa; import gplx.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoae_page__tst {
private final Xoae_page__fxt fxt = new Xoae_page__fxt();
@Test public void Ttl() {
fxt.Init__page("Abc");
fxt.Exec__ttl("Заглавная_страница");
fxt.Test__url("en.wikipedia.org/wiki/Заглавная_страница"); // fails if "%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"; DATE:2016-11-25
}
}
class Xoae_page__fxt {
private Xoae_page page;
private Xowe_wiki wiki;
public Xoae_page__fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
}
public void Init__page(String ttl) {
page = Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_u8(ttl)));
}
public void Exec__ttl(String raw) {
page.Ttl_(wiki.Ttl_parse(Bry_.new_u8(raw)));
}
public void Test__url(String expd) {
Gftest.Eq__str(expd, page.Url().To_str(), "url");
}
}

View File

@@ -0,0 +1,485 @@
/*
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.xowa; import gplx.*;
import gplx.core.tests.*; import gplx.core.log_msgs.*;
import gplx.xowa.apps.cfgs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.tdbs.hives.*;
import gplx.xowa.wikis.pages.*;
public class Xop_fxt {
public Xop_fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
ctor(app, wiki);
}
public Xop_fxt(Xoae_app app, Xowe_wiki wiki) {
this.ctor(app, wiki);
}
private void ctor(Xoae_app app, Xowe_wiki wiki) {
this.app = app;
this.wiki = wiki;
app.Wiki_mgr().Add(wiki);
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
ctx = wiki.Parser_mgr().Ctx();
mock_wkr.Clear_commons(); // assume all files are in repo 0
wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
parser = wiki.Parser_mgr().Main();
this.tkn_mkr = app.Parser_mgr().Tkn_mkr();
ctx.Para().Enabled_n_();
hdom_wtr = wiki.Html_mgr().Html_wtr();
wiki.Html_mgr().Img_suppress_missing_src_(false);
wiki.Xtn_mgr().Init_by_wiki(wiki);
Page_ttl_(Ttl_str);
Xot_invk_tkn.Cache_enabled = false;// always disable cache for tests; can cause strange behavior when running entire suite and lnki_temp test turns on;
}
private Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock();
public Xoae_app App() {return app;} private Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
public Xop_parser Parser() {return parser;} private Xop_parser parser;
public Xoae_page Page() {return ctx.Page();}
public void Lang_by_id_(int id) {ctx.Page().Lang_(wiki.Appe().Lang_mgr().Get_by_or_new(Xol_lang_stub_.Get_by_id(id).Key()));}
public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr;
public Xop_fxt Reset() {
ctx.Clear_all();
ctx.App().Free_mem(false);
ctx.Page().Clear_all();
wiki.File_mgr().Clear_for_tests();
wiki.Db_mgr().Load_mgr().Clear();
app.Wiki_mgr().Clear();
Io_mgr.Instance.InitEngine_mem(); // clear created pages
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
return this;
}
public Xop_fxt Reset_for_msgs() {
Io_mgr.Instance.InitEngine_mem();
wiki.Lang().Msg_mgr().Clear(); // need to clear out lang
wiki.Msg_mgr().Clear(); // need to clear out wiki.Msgs
this.Reset();
return this;
}
public Xoa_ttl Page_ttl_(String txt) {
Xoa_ttl rv = Xoa_ttl.Parse(wiki, Bry_.new_u8(txt));
ctx.Page().Ttl_(rv);
return rv;
}
public Xop_tkn_chkr_base tkn_bry_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_bry).Src_rng_(bgn, end);}
public Xop_tkn_chkr_base tkn_txt_() {return tkn_txt_(String_.Pos_neg1, String_.Pos_neg1);}
public Xop_tkn_chkr_base tkn_txt_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_txt).Src_rng_(bgn, end);}
public Xop_tkn_chkr_base tkn_space_() {return tkn_space_(String_.Pos_neg1, String_.Pos_neg1);}
public Xop_tkn_chkr_base tkn_space_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_space).Src_rng_(bgn, end);}
public Xop_tkn_chkr_base tkn_eq_(int bgn) {return tkn_eq_(bgn, bgn + 1);}
public Xop_tkn_chkr_base tkn_eq_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_eq).Src_rng_(bgn, end);}
public Xop_tkn_chkr_base tkn_colon_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_colon).Src_rng_(bgn, bgn + 1);}
public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);}
public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);}
public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);}
public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);}
public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);}
public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);}
public Xop_tblw_tb_tkn_chkr tkn_tblw_tb_(int bgn, int end) {return (Xop_tblw_tb_tkn_chkr)new Xop_tblw_tb_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_tc_tkn_chkr tkn_tblw_tc_(int bgn, int end) {return (Xop_tblw_tc_tkn_chkr)new Xop_tblw_tc_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);}
public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid__br);}
public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);}
public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tkn_chkr_base tkn_curly_bgn_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tmpl_curly_bgn).Src_rng_(bgn, bgn + 2);}
public Xop_tkn_chkr_base tkn_para_blank_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_none);}
public Xop_tkn_chkr_base tkn_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_pre);}
public Xop_tkn_chkr_base tkn_para_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_para);}
public Xop_tkn_chkr_base tkn_para_mid_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_para);}
public Xop_tkn_chkr_base tkn_para_end_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_none);}
public Xop_tkn_chkr_base tkn_para_end_pre_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_para);}
public Xop_tkn_chkr_base tkn_para_end_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_pre);}
public Xop_tkn_chkr_base tkn_para_end_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_none);}
public Xop_tkn_chkr_base tkn_para_(int pos, byte end, byte bgn) {return new Xop_para_tkn_chkr().Para_end_(end).Para_bgn_(bgn).Src_rng_(pos, pos);}
public Xop_tkn_chkr_base tkn_nl_char_(int bgn, int end) {return tkn_nl_(bgn, end, Xop_nl_tkn.Tid_char);}
public Xop_tkn_chkr_base tkn_nl_char_len1_(int bgn) {return tkn_nl_(bgn, bgn + 1, Xop_nl_tkn.Tid_char);}
public Xop_tkn_chkr_base tkn_nl_char_len0_(int pos) {return tkn_nl_(pos, pos, Xop_nl_tkn.Tid_char);}
public Xop_tkn_chkr_base tkn_nl_(int bgn, int end, byte tid) {return new Xop_nl_tkn_chkr().Nl_tid_(tid).Src_rng_(bgn, end);}
public Xop_list_tkn_chkr tkn_list_bgn_(int bgn, int end, byte listType) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().List_itmTyp_(listType).Src_rng_(bgn, end);}
public Xop_list_tkn_chkr tkn_list_end_(int pos) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().Src_rng_(pos, pos);}
public Xop_tkn_chkr_lnke tkn_lnke_(int bgn, int end) {return new Xop_tkn_chkr_lnke(bgn, end);}
public Xop_lnki_tkn_chkr tkn_lnki_() {return tkn_lnki_(-1, -1);}
public Xop_lnki_tkn_chkr tkn_lnki_(int bgn, int end) {return (Xop_lnki_tkn_chkr)new Xop_lnki_tkn_chkr().Src_rng_(bgn, end);}
public Xop_arg_itm_tkn_chkr tkn_arg_itm_(Xop_tkn_chkr_base... subs) {return (Xop_arg_itm_tkn_chkr)new Xop_arg_itm_tkn_chkr().Subs_(subs);}
public Xop_arg_nde_tkn_chkr tkn_arg_nde_() {return tkn_arg_nde_(String_.Pos_neg1, String_.Pos_neg1);}
public Xop_arg_nde_tkn_chkr tkn_arg_nde_(int bgn, int end) {return (Xop_arg_nde_tkn_chkr)new Xop_arg_nde_tkn_chkr().Src_rng_(bgn, end);}
public Xop_arg_nde_tkn_chkr tkn_arg_val_(Xop_tkn_chkr_base... subs) {
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
Xop_arg_itm_tkn_chkr val = new Xop_arg_itm_tkn_chkr();
val.Subs_(subs);
rv.Val_tkn_(val);
return rv;
}
public Xop_arg_nde_tkn_chkr tkn_arg_val_txt_(int bgn, int end) {
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
rv.Val_tkn_(itm);
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
return rv;
}
Xop_arg_nde_tkn_chkr tkn_arg_key_txt_(int bgn, int end) {
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
rv.Key_tkn_(itm);
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
return rv;
}
public Xot_invk_tkn_chkr tkn_tmpl_invk_(int bgn, int end) {return (Xot_invk_tkn_chkr)new Xot_invk_tkn_chkr().Src_rng_(bgn, end);}
public Xot_invk_tkn_chkr tkn_tmpl_invk_w_name(int bgn, int end, int name_bgn, int name_end) {
Xot_invk_tkn_chkr rv = new Xot_invk_tkn_chkr();
rv.Src_rng_(bgn, end);
rv.Name_tkn_(tkn_arg_key_txt_(name_bgn, name_end));
return rv;
}
public Xot_prm_chkr tkn_tmpl_prm_find_(Xop_tkn_chkr_base find) {
Xot_prm_chkr rv = new Xot_prm_chkr();
rv.Find_tkn_(tkn_arg_itm_(find));
return rv;
}
public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;}
public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;}
public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.New();
public void Init_defn_add(String name, String text) {Init_defn_add(name, text, Xow_ns_case_.Tid__all);}
public void Init_defn_add(String name, String text, byte case_match) {
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.new_a7(name), Bry_.new_u8(text));
wiki.Cache_mgr().Defn_cache().Add(itm, case_match);
}
public void Init_defn_clear() {wiki.Cache_mgr().Defn_cache().Free_mem_all();}
public Xop_fxt Init_id_create(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Xow_hive_mgr_fxt.Create_id(app, wiki.Hive_mgr(), id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;}
public Xop_fxt Init_page_create(String ttl) {return Init_page_create(wiki, ttl, "");}
public Xop_fxt Init_page_create(String ttl, String txt) {return Init_page_create(wiki, ttl, txt);}
public Xop_fxt Init_page_create(Xowe_wiki wiki, String ttl, String txt) {Init_page_create_static(wiki, ttl, txt);return this;}
public static void Init_page_create_static(Xowe_wiki wiki, String ttl_str, String text_str) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
byte[] text = Bry_.new_u8(text_str);
wiki.Db_mgr().Save_mgr().Data_create(ttl, text);
}
public static void Init_msg(Xowe_wiki wiki, String key, String val) {
wiki.Lang().Msg_mgr().Itm_by_key_or_new(key, val);
}
public Xop_fxt Init_page_update(String ttl, String txt) {return Init_page_update(wiki, ttl, txt);}
public Xop_fxt Init_page_update(Xowe_wiki wiki, String ttl, String txt) {
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl));
byte[] page_raw = Bry_.new_u8(txt);
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_ttl);
wiki.Db_mgr().Save_mgr().Data_update(page, page_raw);
return this;
}
public Xop_fxt Init_xwiki_clear() {
wiki.Xwiki_mgr().Clear();
app.Usere().Wiki().Xwiki_mgr().Clear();
return this;
}
public Xop_fxt Init_xwiki_add_wiki_and_user_(String alias, String domain) {
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
return this;
}
public Xop_fxt Init_xwiki_add_user_(String domain) {return Init_xwiki_add_user_(domain, domain);}
public Xop_fxt Init_xwiki_add_user_(String alias, String domain) {
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(alias, domain);
return this;
}
public void Test_parse_template(String tmpl_raw, String expd) {Test_parse_tmpl_str_test(tmpl_raw, "{{test}}", expd);}
public void Test_parse_tmpl_str_test(String tmpl_raw, String page_raw, String expd) {
Init_defn_add("test", tmpl_raw);
Test_parse_tmpl_str(page_raw, expd);
}
public void Test_parse_tmpl_str(String raw, String expd) {
byte[] actl = Test_parse_tmpl_str_rv(raw);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
tst_Log_check();
}
public byte[] Test_parse_tmpl_str_rv(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
ctx.Page().Root_(root);
ctx.Page().Db().Text().Text_bry_(raw_bry);
return parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
}
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
public void Test_parse_tmpl(String raw, Tst_chkr... expd) {
byte[] raw_bry = Bry_.new_u8(raw);
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.Empty, raw_bry);
Parse_chk(raw_bry, itm.Root(), expd);
}
public void Test_parse_page_tmpl_str(String raw, String expd) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
byte[] actl = parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
Tfds.Eq(expd, String_.new_u8(actl));
tst_Log_check();
}
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
return root;
}
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
Parse_chk(raw_bry, root, expd_ary);
}
public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = Test_parse_page_wiki_root(raw_bry);
Parse_chk(raw_bry, root, expd_ary);
}
public Xop_root_tkn Test_parse_page_wiki_root(String raw) {return Test_parse_page_wiki_root(Bry_.new_u8(raw));}
Xop_root_tkn Test_parse_page_wiki_root(byte[] raw_bry) {
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
return root;
}
public void Test_parse_page_all(String raw, Tst_chkr... expd_ary) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
Parse_chk(raw_bry, root, expd_ary);
}
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));}
public void Test_parse_page_all_str(String raw, String expd) {
String actl = Exec_parse_page_all_as_str(raw);
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
}
public void Test_parse_page_all_str_and_chk(String raw, String expd, Gfo_msg_itm... ary) {
this.Init_log_(ary);
Test_parse_page_all_str(raw, expd);
this.tst_Log_check();
}
public Xop_root_tkn Exec_parse_page_all_as_root(byte[] raw_bry) {
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_page_all_clear(root, ctx, tkn_mkr, raw_bry);
return root;
}
public String Exec_parse_page_all_as_str(String raw) {
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
Bry_bfr actl_bfr = Bry_bfr_.New();
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root);
return actl_bfr.To_str_and_clear();
}
public Xoh_wtr_ctx Hctx() {return hctx;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;}
public String Exec_parse_page_wiki_as_str(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
Bry_bfr actl_bfr = Bry_bfr_.New();
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, raw_bry, root);
return actl_bfr.To_str_and_clear();
}
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
int subs_len = root.Subs_len();
Object[] actl_ary = new Object[subs_len];
for (int i = 0; i < subs_len; i++)
actl_ary[i] = root.Subs_get(i);
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
tst_Log_check();
}
public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));}
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
String actl = Exec_parse_page_wiki_as_str(raw);
Tfds.Eq_str_lines(expd, actl, raw);
return this;
}
public void Log_clear() {ctx.App().Msg_log().Clear();}
public String[] Log_xtoAry() {
Gfo_msg_log msg_log = app.Msg_log();
int len = msg_log.Ary_len();
List_adp actl_list = List_adp_.New();
for (int i = 0; i < len; i++) {
Gfo_msg_data eny = msg_log.Ary_get(i);
if (eny.Item().Cmd() > Gfo_msg_itm_.Cmd_note) {
actl_list.Add(String_.new_u8(eny.Item().Path_bry()));
}
}
String[] actl = actl_list.To_str_ary();
msg_log.Clear();
return actl;
}
public Xop_fxt tst_Log_check() {
int len = log_itms.Count();
String[] expd = new String[len];
for (int i = 0; i < len; i++) {
Gfo_msg_itm itm = (Gfo_msg_itm)log_itms.Get_at(i);
expd[i] = itm.Path_str();
}
log_itms.Clear();
String[] actl = Log_xtoAry();
Tfds.Eq_ary_str(expd, actl);
return this;
}
public void tst_Warn(String... expd) {
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
Gfo_usr_dlg__gui_test ui_wkr = (Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr();
String[] actl = ui_wkr.Warns().To_str_ary();
Tfds.Eq_ary_str(expd, actl);
}
public void Test_parse_page(String ttl, String expd) {
byte[] actl = Load_page(wiki, ttl);
Tfds.Eq(expd, String_.new_u8(actl));
}
public static byte[] Load_page(Xowe_wiki wiki, String ttl_str) {
byte[] ttl_bry = Bry_.new_u8(ttl_str);
Xoa_url page_url = Xoa_url.New(wiki.Domain_bry(), ttl_bry);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
return wiki.Data_mgr().Load_page_and_parse(page_url, ttl).Db().Text().Text_bry();
}
public static void Reg_xwiki_alias(Xowe_wiki wiki, String alias, String domain) {
byte[] domain_bry = Bry_.new_a7(domain);
wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_a7(alias), domain_bry, Bry_.Add(domain_bry, Bry_.new_a7("/wiki/~{0}")));
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain_bry, domain_bry);
}
public static String html_img_none(String trg, String alt, String src, String ttl) {
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xoimg_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
}
private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);}
private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);}
public void Test_html_wiki_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_wiki(raw));}
public void Test_html_full_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_full(raw));}
public void Test_html_wiki_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_wiki(raw), expd_frags);}
public void Test_html_full_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_full(raw), expd_frags);}
public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);}
public void Test__parse__tmpl_to_html(String raw, String expd) {Test_str_full(raw, gplx.langs.htmls.Gfh_utl.Replace_apos(expd), Exec_html_full(raw));}
public void Test__parse__wtxt_to_html(String raw, String expd) {
String actl = Exec_html_wiki(raw);
Tfds.Eq_str_lines(gplx.langs.htmls.Gfh_utl.Replace_apos(expd), actl, raw);
}
public void Test_str_full(String raw, String expd, String actl) {
Tfds.Eq_str_lines(expd, actl, raw);
}
public void Test_str_part_y(String actl, String... expd_parts) {
int expd_parts_len = expd_parts.length;
for (int i = 0; i < expd_parts_len; i++) {
String expd_part = expd_parts[i];
boolean pass = String_.Has(actl, expd_part);
if (!pass)
Tfds.Eq_true(false, expd_part + "\n" + actl);
}
}
private void Test_str_part_n(String actl, String... expd_parts) {
int expd_parts_len = expd_parts.length;
for (int i = 0; i < expd_parts_len; i++) {
String expd_part = expd_parts[i];
boolean has = String_.Has(actl, expd_part);
if (has)
Tfds.Eq_true(false, expd_part + "\n" + actl);
}
}
public void Test_html_modules_js(String expd) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
this.Page().Html_data().Head_mgr().Init(app, wiki, this.Page());
this.Page().Html_data().Head_mgr().Bfr_arg__add(bfr);
bfr.Mkr_rls();
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
private Tst_mgr tst_mgr = new Tst_mgr(); private Xop_tkn_mkr tkn_mkr;
public static final String Ttl_str = "Test page";
public Xop_fxt Init_lang_numbers_separators_en() {return Init_lang_numbers_separators(",", ".");}
public Xop_fxt Init_lang_numbers_separators(String grp_spr, String dec_spr) {return Init_lang_numbers_separators(wiki.Lang(), grp_spr, dec_spr);}
public Xop_fxt Init_lang_numbers_separators(Xol_lang_itm lang, String grp_spr, String dec_spr) {
gplx.xowa.langs.numbers.Xol_transform_mgr separator_mgr = lang.Num_mgr().Separators_mgr();
separator_mgr.Clear();
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_u8(grp_spr));
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__dec, Bry_.new_u8(dec_spr));
return this;
}
public void Init_lang_kwds(int kwd_id, boolean case_match, String... kwds) {Init_lang_kwds(wiki.Lang(), kwd_id, case_match, kwds);}
public void Init_lang_kwds(Xol_lang_itm lang, int kwd_id, boolean case_match, String... kwds) {
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
Xol_kwd_grp kwd_grp = kwd_mgr.Get_or_new(kwd_id);
kwd_grp.Srl_load(case_match, Bry_.Ary(kwds));
}
public void Init_lang_vnts(String... vnts) {
wiki.Lang().Vnt_mgr().Enabled_(true);
gplx.xowa.langs.vnts.Xol_vnt_regy vnt_regy = wiki.Lang().Vnt_mgr().Regy();
for (int i = 0; i < vnts.length; i++) {
byte[] vnt = Bry_.new_u8(vnts[i]);
vnt_regy.Add(vnt, vnt);
if (i == 0) {
wiki.Lang().Vnt_mgr().Cur_itm_(vnt);
}
}
wiki.Lang().Vnt_mgr().Init_end();
}
public void Init_xtn_pages() {
Io_mgr.Instance.InitEngine_mem();
wiki.Xtn_mgr().Xtn_proofread().Enabled_y_();
wiki.Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
wiki.Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
}
public void Clear_ref_mgr() {this.Page().Ref_mgr().Grps_clear();} // clear to reset count
public static Xop_fxt new_nonwmf() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
return new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit__nonwmf(app, "nethackwiki"));
}
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
public String Exec__parse_to_hdump(String src_str) {
byte[] src_bry = Bry_.new_u8(src_str);
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
ctx.Page().Html_data().Redlink_list().Clear();
html_wtr.Write_doc(tmp_bfr, ctx, hctx, src_bry, root);
// Tfds.Dbg(tmp_bfr.To_str());
return tmp_bfr.To_str_and_clear();
}
public void Test__parse_to_html_mgr(String src_str, String expd) {
byte[] src_bry = Bry_.new_u8(src_str);
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
Xoae_page page = this.Page();
page.Root_(root);
byte[] actl = wiki.Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public String Exec__parse_to_html_w_skin(String raw) {
Bry_bfr bfr = Bry_bfr_.New();
Xow_html_mgr html_mgr = wiki.Html_mgr();
this.Wiki().Html__wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = this.Exec_parse_page_all_as_root(raw_bry);
this.Page().Root_(root);
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, this.Page(), this.Ctx(), Xoh_page_html_source_.Wtr);
return bfr.To_str_and_clear();
}
public void Test__parse_to_html_w_skin(String raw, String expd) {
Tfds.Eq_str_lines(expd, Exec__parse_to_html_w_skin(raw));
}
public static Xop_fxt New_app_html() {
Xop_fxt fxt = new Xop_fxt();
fxt.Wiki().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
return fxt;
}
}

View File

@@ -0,0 +1,78 @@
/*
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.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.*;
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.specials.maints.services.*;
public class Xocfg_cache_mgr__tst {
private final Xocfg_cache_mgr__fxt fxt = new Xocfg_cache_mgr__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Get__wiki() {
fxt.Init__db_add("en.w", "key_1", "val_1");
fxt.Test__get("en.w", "key_1", "val_1");
fxt.Test__get("en.d", "key_1", "dflt");
}
@Test public void Get__app() {
String ctx = Xocfg_mgr.Ctx__app;
fxt.Init__db_add(ctx, "key_1", "val_1");
fxt.Test__get(ctx, "key_1", "val_1");
fxt.Test__get("en.w", "key_1", "val_1");
fxt.Test__get("en.d", "key_1", "val_1");
}
@Test public void Set__app() {
String ctx = Xocfg_mgr.Ctx__app;
fxt.Init__db_add(ctx, "key_1", "123");
fxt.Init__sub(ctx, "key_1", "key_1");
fxt.Exec__set(ctx, "key_1", "234");
fxt.Test__get(ctx, "key_1", "234");
fxt.Sub().Test__key_1(234);
}
}
class Xocfg_cache_mgr__fxt {
private Xocfg_cache_mgr mgr = new Xocfg_cache_mgr();
private int id;
public void Clear() {
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
Db_conn conn = Db_conn_bldr.Instance.Get_or_autocreate(true, Io_url_.new_any_("mem/xowa/wiki/en.wikipedia.org/"));
mgr.Init_by_app(conn, conn);
}
public Xocfg_cache_sub_mock Sub() {return sub;} private Xocfg_cache_sub_mock sub = new Xocfg_cache_sub_mock();
public void Init__db_add(String ctx, String key, Object val) {
Xocfg_maint_svc.Create_grp(mgr.Db_app(), "", id++, "test_grp", "", "");
Xocfg_maint_svc.Create_itm(mgr.Db_app(), "test_grp", id++, key, "", "", "wiki", String_.Cls_val_name, "dflt", "", "");
mgr.Db_usr().Set_str(ctx, key, Object_.Xto_str_strict_or_null(val));
}
public void Init__sub(String ctx, String key, String evt) {
mgr.Sub(sub, ctx, key, evt);
}
public void Test__get(String ctx, String key, String expd) {
Gftest.Eq__str(expd, mgr.Get(ctx, key), "ctx={0} key={1}", ctx, key);
}
public void Exec__set(String ctx, String key, String val) {
mgr.Set(ctx, key, val);
}
}
class Xocfg_cache_sub_mock implements Gfo_invk {
private int key_1;
public void Test__key_1(int expd) {
Gftest.Eq__int(expd, key_1);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Evt__key_1)) {key_1 = m.ReadInt("v");}
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Evt__key_1 = "key_1";
}

View File

@@ -0,0 +1,43 @@
/*
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.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
import org.junit.*; import gplx.core.tests.*;
public class Xocfg_maint_parser__tst {
private final Xocfg_maint_parser__fxt fxt = new Xocfg_maint_parser__fxt();
@Test public void Parse_grp() {
fxt.Exec__parse("grp {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'}"
, fxt.Make__grp("owner_1", 123, "key_1", "name_1", "help_1")
);
}
@Test public void Parse_itm() {
fxt.Exec__parse("itm {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'; scope='scope_1'; type='type_1'; dflt='dflt_1'; html_atrs='html_atrs_1'; html_cls='html_cls_1'}"
, fxt.Make__itm("owner_1", 123, "key_1", "name_1", "help_1", "scope_1", "type_1", "dflt_1", "html_atrs_1", "html_cls_1")
);
}
}
class Xocfg_maint_parser__fxt {
private Xocfg_maint_parser parser = new Xocfg_maint_parser();
public void Exec__parse(String raw, Xocfg_maint_nde... expd) {
Xocfg_maint_nde[] actl = parser.Parse(raw);
Gftest.Eq__ary(expd, actl);
}
public Xocfg_maint_grp Make__grp(String owner, int id, String key, String name, String help) {
return new Xocfg_maint_grp(owner, id, key, name, help);
}
public Xocfg_maint_itm Make__itm(String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) {
return new Xocfg_maint_itm(owner, id, key, name, help, scope, type, dflt, html_atrs, html_cls);
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
import org.junit.*; import gplx.core.tests.*;
public class Xocfg_upgrade_mgr__tst {
private final Xocfg_upgrade_mgr__fxt fxt = new Xocfg_upgrade_mgr__fxt();
@Test public void Parse__one() {
fxt.Test__parse("app.cfgs.get('k_1', 'app').val = 'v_1';\n", Keyval_.new_("k_1", "v_1"));
}
@Test public void Parse__apos() {
fxt.Test__parse("app.cfgs.get('k_1(''k_1a'')', 'app').val = 'v_1';\n", Keyval_.new_("k_1('k_1a')", "v_1"));
}
@Test public void Parse__many() {
fxt.Test__parse
( "app.cfgs.get('k_1', 'app').val = 'v_1';\n"
+ "app.cfgs.get('k_2', 'app').val = 'v_2';\n"
, Keyval_.new_("k_1", "v_1"), Keyval_.new_("k_2", "v_2"));
}
@Test public void Parse__multi_line() {
fxt.Test__parse
( "app.cfgs.get('k_1', 'app').val = '''v_1'';\n"
+ "v_2\n"
+ "v_3';\n"
, Keyval_.new_("k_1", "'v_1';\nv_2\nv_3"));
}
@Test public void Parse__io_cmd() {
fxt.Test__parse
( "app.cfgs.get('a.cmd', 'app').val = 'cmd_1';\n"
+ "app.cfgs.get('a.args', 'app').val = 'args_1';\n"
, Keyval_.new_("a.cmd", "cmd_1|args_1"));
}
@Test public void Parse__gui_binding() {
fxt.Test__parse
( "app.cfgs.get('app.cfg.get.gui.bnds.init(''xowa.app.exit-1'').src', 'app').val = 'box=''browser'';ipt=''key.none'';';\n"
, Keyval_.new_("xowa.gui.shortcuts.xowa.app.exit-1", "browser|key.none"));
}
}
class Xocfg_upgrade_mgr__fxt {
public void Test__parse(String raw, Keyval... expd) {
Keyval[] actl = Xocfg_upgrade_mgr.Parse(Bry_.new_u8(raw));
Gftest.Eq__str(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
}
}

View File

@@ -0,0 +1,72 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoscript_doc_head__tst {
private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt();
@Before public void init() {
fxt.Init__sect("head");
fxt.Exec__reg_marker("<!--top-->", "top", Xoscript_doc_head.Pos__default);
fxt.Exec__reg_marker("<!--bot-->", "bot");
fxt.Exec__doc__html("a<!--top-->b<!--bot-->c");
}
@Test public void Add_html() {
fxt.Exec__add_html("top", "<b>add_1</b>");
fxt.Exec__add_html("top", "<b>add_2</b>");
fxt.Test__html("a<b>add_1</b><b>add_2</b><!--top-->b<!--bot-->c");
}
@Test public void Add_html__default() {
fxt.Exec__add_html("<b>add_1</b>");
fxt.Test__html("a<b>add_1</b><!--top-->b<!--bot-->c");
}
@Test public void Add_tag() {
fxt.Exec__add_tag("top", "div", "div_body", "k0", "v0", "k1", "v1");
fxt.Test__html
( "a<div k0=\"v0\" k1=\"v1\">div_body</div>"
, "<!--top-->b<!--bot-->c");
}
@Test public void Add_js_file() {
fxt.Exec__add_js_file("top", "./a.js");
fxt.Test__html
( "a<script src=\"file:///mem/wiki/test_wiki/bin/script/a.js\" type=\"text/javascript\"></script>"
, "<!--top-->b<!--bot-->c");
}
}
class Xoscript_doc_head__fxt {
private final Xoscript_page spg;
private Xoscript_doc_sect_base sect;
public Xoscript_doc_head__fxt() {
Bry_bfr rv = Bry_bfr_.New();
Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
Xoscript_url url = new Xoscript_url("test_wiki", "test_page");
spg = new Xoscript_page(rv, env, url);
}
public void Init__sect(String sect_name) {
if (String_.Eq(sect_name, "head"))
sect = spg.doc().head();
else if (String_.Eq(sect_name, "tail"))
sect = spg.doc().tail();
}
public void Exec__doc__html(String html) {spg.doc().html(html);}
public void Exec__reg_marker(String marker, String... pos_ary) {sect.reg_marker(marker, pos_ary);}
public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);}
public void Exec__add_html(String html) {sect.add_html(html);}
public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);}
public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
public void Test__html(String... expd) {
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html");
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.apps.updates.specials.svcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; import gplx.xowa.addons.apps.updates.specials.*;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
public class Xoa_update_svc__tst {
private final Xoa_update_svc__fxt fxt = new Xoa_update_svc__fxt();
@Test public void Restart_cmd() {
Io_url jar_fil = Io_url_.new_dir_("/home/gnosygnu/xowa/xowa.jar");
fxt.Test__restart_cmd("manual" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "manual");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_linux_64.sh");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_linux.sh");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_macosx_64");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_macosx");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_64, "/home/gnosygnu/xowa/xowa_64.exe");
fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_32, "/home/gnosygnu/xowa/xowa.exe");
}
}
class Xoa_update_svc__fxt {
public void Test__restart_cmd(String current, Io_url app_url, byte op_sys_tid, byte bitness, String expd) {
Gftest.Eq__str(expd, Xoa_update_svc.App__update__restart_cmd(current, app_url, op_sys_tid, bitness), "restart_cmd");
}
}

View File

@@ -0,0 +1,177 @@
/*
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.xowa.addons.bldrs.app_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import org.junit.*; import gplx.core.strings.*;
public class Xob_wiki_cfg_bldr_tst {
Xob_wiki_cfg_bldr_fxt fxt = new Xob_wiki_cfg_bldr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Exec() {
fxt .Init_cmd("en.wikipedia.org", "key0", "en.val0")
.Init_cmd("en.wikipedia.org", "key1", "en.val1")
.Init_cmd("fr.wikipedia.org", "key0", "fr.val0")
.Init_cmd("fr.wikipedia.org", "key1", "fr.val1")
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "en.val0"
, "// key0.end"
, "// key1.bgn"
, "en.val1"
, "// key1.end"
))
.Expd_txt("fr.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "fr.val0"
, "// key0.end"
, "// key1.bgn"
, "fr.val1"
, "// key1.end"
))
.Test()
;
fxt .Clear()
.Init_cmd("en.wikipedia.org", "key2", "en.val2")
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "en.val0"
, "// key0.end"
, "// key1.bgn"
, "en.val1"
, "// key1.end"
, "// key2.bgn"
, "en.val2"
, "// key2.end"
));
}
// @Test public void Lang_names_run() {
// Io_url dir = Io_url_.new_dir_("/var/www/mediawiki/languages/messages/");
// Io_url[] fils = Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry();
// int fils_len = fils.length;
// String_bldr sb = String_bldr_.new_();
// for (int i = 0; i < fils_len; i++) {
// Io_url fil = fils[i];
// String lang_code = String_.Lower(String_.Replace(fil.NameOnly(), "Messages", ""));
// String txt = Io_mgr.Instance.LoadFilStr(fil);
// String[] lines = String_.Split(txt, '\n');
// String line = lines[1];
// line = String_.Replace(line, "/** ", "");
// int pos = String_.FindBwd(line, " (");
// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line
// if ( String_.Has_at_bgn(lang_code, "be_")
// || String_.Has_at_bgn(lang_code, "crh_")
// || String_.Has_at_bgn(lang_code, "kk_")
// || String_.Has_at_bgn(lang_code, "ku_")
// || String_.Has_at_bgn(lang_code, "sr_")
// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no")
// ) {
// int new_pos = String_.FindBwd(line, " (", pos - 1);
// if (new_pos != String_.Find_none)
// pos = new_pos;
// }
// line = Replace_by_pos(line, pos, pos + 2, "|");
// int line_len = String_.Len(line);
// if (line_len > 0)
// line = String_.MidByLen(line, 0, line_len - 1);
// String[] terms = String_.Split(line, '|');
// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n");
// }
// Tfds.Dbg(sb.To_str_and_clear());
// }
@Test public void Ns_aliases() {
Io_mgr.Instance.InitEngine_mem();
Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl
( "<api>"
, "<query>"
, "<namespacealiases>"
, "<ns id=\"4\" xml:space=\"preserve\">WP"
, "</ns>"
, "<ns id=\"5\" xml:space=\"preserve\">WT"
, "</ns>"
, "<ns id=\"6\" xml:space=\"preserve\">Image"
, "</ns>"
, "<ns id=\"7\" xml:space=\"preserve\">Image talk"
, "</ns>"
, "</namespacealiases>"
, "</query>"
, "</api>"
));
String[] wikis = new String[] {"en.wikipedia.org"}; String protocol = "mem/";
Tfds.Eq_str_lines(Query_ns(protocol, gplx.core.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl
( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\""
, "4|WP"
, "5|WT"
, "6|Image"
, "7|Image_talk"
, "\");');"
));
}
String Query_ns(String protocol, String trg_engine_key, String[] wikis) {
String_bldr sb = String_bldr_.new_();
int wikis_len = wikis.length;
for (int i = 0; i < wikis_len; i++) {
String wiki = wikis[i];
if (String_.Len_eq_0(wiki)) continue;
try {
String api = protocol + wiki + "/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases";
String xml = String_.new_u8(Io_mgr.Instance.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api));
if (xml == null) continue; // not found
gplx.langs.xmls.XmlDoc xdoc = gplx.langs.xmls.XmlDoc_.parse(xml);
gplx.langs.xmls.XmlNde xnde = gplx.langs.xmls.Xpath_.SelectFirst(xdoc.Root(), "query/namespacealiases");
sb.Add("app.bldr.wiki_cfg_bldr.get('").Add(wiki).Add("').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"\n");
int xndes_len = xnde.SubNdes().Count();
for (int j = 0; j < xndes_len; j++) {
gplx.langs.xmls.XmlNde ns_nde = xnde.SubNdes().Get_at(j);
if (!String_.Eq(ns_nde.Name(), "ns")) continue;
int id = Int_.parse(ns_nde.Atrs().FetchValOr("id", "-1"));
String name = String_.Replace(String_.Replace(ns_nde.Text_inner(), " ", "_"), "'", "''");
sb.Add(Int_.To_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl();
}
sb.Add("\");');\n");
}
catch(Exception e) {sb.Add("// fail: " + wiki + " " + Err_.Message_gplx_full(e)).Add_char_nl();}
}
return sb.To_str_and_clear();
}
}
class Xob_wiki_cfg_bldr_fxt {
public Xob_wiki_cfg_bldr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki_cfg_bldr = app.Bldr().Wiki_cfg_bldr();
}
wiki_cfg_bldr.Clear();
hash.Clear();
return this;
} private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.New();
public Xob_wiki_cfg_bldr_fxt Init_cmd(String wiki, String key, String text) {
wiki_cfg_bldr.Itms_get_or_new(wiki).Itms_add(key, text);
return this;
}
public Xob_wiki_cfg_bldr_fxt Expd_txt(String wiki, String text) {
hash.Add(wiki, Keyval_.new_(wiki, text));
return this;
}
public void Test() {
wiki_cfg_bldr.Exec();
int len = hash.Count();
for (int i = 0; i < len; i++) {
Keyval kv = (Keyval)hash.Get_at(i);
String wiki = kv.Key();
String expd = (String)kv.Val();
String actl = Io_mgr.Instance.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
Tfds.Eq_str_lines(expd, actl);
}
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
public class Host_eval_wkr__tst {
private final Host_eval_wkr__fxt fxt = new Host_eval_wkr__fxt();
@Test public void En_w() {fxt.Test__resolve_quick("en.wikipedia.org" , "Xowa_enwiki_latest");}
@Test public void Fr_d() {fxt.Test__resolve_quick("fr.wiktionary.org" , "Xowa_frwiki_latest");}
@Test public void Species() {fxt.Test__resolve_quick("species.wikimedia.org" , "Xowa_enwiki_latest");}
}
class Host_eval_wkr__fxt {
public void Test__resolve_quick(String domain_str, String expd) {
Host_eval_itm eval_itm = new Host_eval_itm();
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
Gftest.Eq__bry(Bry_.new_u8(expd), eval_itm.Eval_dir_name(domain_itm));
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import org.junit.*; import gplx.core.tests.*;
public class Time_dhms__tst {
private final Time_dhms__fxt fxt = new Time_dhms__fxt();
@Test public void S__0() {fxt.Test__to_str( 0, 4, "0 s");}
@Test public void S__1() {fxt.Test__to_str( 1, 4, "1 s");}
@Test public void S__2() {fxt.Test__to_str( 30, 4, "30 s");}
@Test public void M__1() {fxt.Test__to_str( 60, 4, "1:00 m");}
@Test public void M__2() {fxt.Test__to_str( 600, 4, "10:00 m");}
@Test public void H__1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");}
@Test public void H__2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");}
@Test public void D__1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");}
@Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");}
}
class Time_dhms__fxt {
private final Bry_bfr bfr = Bry_bfr_.New();
public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) {
Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places));
return this;}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
import org.junit.*; import gplx.core.tests.*;
public class Pack_zip_name_bldr__tst {
private Pack_zip_name_bldr__fxt fxt = new Pack_zip_name_bldr__fxt();
@Test public void Basic() {
fxt.Test__to_wiki_url("mem/wiki/en.wikipedia.org/", "mem/wiki/en.wikipedia.org/tmp/Xowa_enwiki_2016-09_file_deletion_2016.09/", "mem/wiki/en.wikipedia.org/en.wikipedia.org-file-deletion-2016.09.xowa");
}
@Test public void Bld_by_suffix() {
Pack_zip_name_bldr bldr = fxt.Make__bldr("mem/wiki/en.wikipedia.org/tmp/pack/", "en.wikipedia.org", "enwiki", "2017-03", null);
fxt.Test__bld_by_suffix(bldr, "xtn.fulltext_search", 1, "mem/wiki/en.wikipedia.org/tmp/pack/Xowa_enwiki_2017-03_xtn.fulltext_search.002.zip");
}
}
class Pack_zip_name_bldr__fxt {
public void Test__to_wiki_url(String wiki_dir, String zip_fil, String expd) {
Gftest.Eq__str(expd, Pack_zip_name_bldr.To_wiki_url(Io_url_.mem_fil_(wiki_dir), Io_url_.mem_dir_(zip_fil)).Raw(), "wiki_url");
}
public Pack_zip_name_bldr Make__bldr(String wiki_dir, String domain, String wiki_abrv, String wiki_date, String custom_name) {
return new Pack_zip_name_bldr(Io_url_.new_dir_(wiki_dir), domain, wiki_abrv, wiki_date, custom_name);
}
public void Test__bld_by_suffix(Pack_zip_name_bldr bldr, String suffix, int pack_num, String expd) {
Gftest.Eq__str(expd, bldr.Bld_by_suffix(suffix, pack_num).Xto_api());
}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*; import gplx.core.ios.*; import gplx.xowa.files.*;
public class Xobldr__image__create_tst {
private Xobldr__image__create_fxt fxt = new Xobldr__image__create_fxt();
@Test public void Basic() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_png, 220, 110) .Test(Xof_ext_.Id_png);} // A.png -> png
@Test public void Ogg_VIDEO() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 220, 110) .Test(Xof_ext_.Id_ogv);} // A.ogg and VIDEO -> ogv
@Test public void Ogg_VIDEO_null_size() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 0, 0) .Test(Xof_ext_.Id_ogg);} // A.ogg but 0,0 -> ogg (not ogv)
@Test public void Png_is_jpg() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpg);} // A.png and jpg -> jpg
@Test public void Jpeg_is_jpeg() {fxt.Init_("A.jpeg" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpeg);} // A.jpeg and jpg -> jpeg (unchanged)
}
class Xobldr__image__create_fxt {
private byte[] name, media_type, minor_mime; int w, h;
public Xobldr__image__create_fxt Init_png() {Name_("A.png").Media_type_(Xof_media_type.Name_bitmap).Minor_mime_(Xof_ext_.Bry_png).W_(220).H_(110);
return this;
}
public Xobldr__image__create_fxt Init_(String name, String media_type, byte[] minor_mime, int w, int h) {
Name_(name);
Media_type_(media_type);
Minor_mime_(minor_mime);
W_(w);
H_(h);
return this;
}
public Xobldr__image__create_fxt Name_(String v) {name = Bry_.new_a7(v); return this;}
public Xobldr__image__create_fxt Media_type_(String v) {media_type = Bry_.new_a7(v); return this;}
public Xobldr__image__create_fxt Minor_mime_(byte[] v) {minor_mime = v; return this;}
public Xobldr__image__create_fxt Minor_mime_(String v) {return Minor_mime_(Bry_.new_a7(v));}
public Xobldr__image__create_fxt W_(int v) {w = v; return this;}
public Xobldr__image__create_fxt H_(int v) {h = v; return this;}
public Xobldr__image__create_fxt Test(int expd) {
Tfds.Eq(expd, Xobldr__image__create.Calc_ext_id(Gfo_usr_dlg_.Noop, name, media_type, minor_mime, w, h));
return this;
}
}

View File

@@ -0,0 +1,41 @@
/*
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.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*;
public class Xobldr__lnki_temp__create__tst {
private Xobldr__lnki_temp__create__fxt fxt = new Xobldr__lnki_temp__create__fxt();
@Test public void Xto_commons() {
fxt.Init__to_commons(true);
fxt.Test__to_commons("a", "A");
fxt.Test__to_commons("A", null);
fxt.Init__to_commons(false);
fxt.Test__to_commons("a", null);
fxt.Test__to_commons("A", null);
}
}
class Xobldr__lnki_temp__create__fxt {
private boolean wiki_ns_file_is_case_match_all;
private Xowe_wiki commons_wiki;
public Xobldr__lnki_temp__create__fxt Init__to_commons(boolean wiki_ns_file_is_case_match_all) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all;
this.commons_wiki = Xoa_app_fxt.Make__wiki__edit(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st
return this;
}
public void Test__to_commons(String ttl, String expd) {
Tfds.Eq(expd, String_.new_u8(gplx.xowa.addons.bldrs.mass_parses.parses.utls.Xomp_lnki_temp_wkr.To_commons_ttl(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_u8(ttl))));
}
}

View File

@@ -0,0 +1,41 @@
/*
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.xowa.addons.bldrs.files.missing_origs.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.missing_origs.*;
import org.junit.*; import gplx.core.tests.*;
public class Xowmf_imageinfo_item__tst {
private final Xowmf_imageinfo_item__fxt fxt = new Xowmf_imageinfo_item__fxt();
@Test public void Normalize_ttl() {
fxt.Test__Normalize_ttl("File:A b.png", "A_b.png");
}
@Test public void Normalize_minor_mime() {
fxt.Test__Normalize_minor_mime("image/svg+xml", "svg+xml");
}
@Test public void Normalize_timestamp() {
fxt.Test__Normalize_timestamp("2017-03-06T08:09:10Z", "20170306080910");
}
}
class Xowmf_imageinfo_item__fxt {
public void Test__Normalize_ttl(String src, String expd) {
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_ttl(Bry_.new_u8(src)));
}
public void Test__Normalize_timestamp(String src, String expd) {
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_timestamp(Bry_.new_u8(src)));
}
public void Test__Normalize_minor_mime(String src, String expd) {
Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_minor_mime(Bry_.new_u8(src)));
}
}

View File

@@ -0,0 +1,190 @@
/*
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.xowa.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import org.junit.*;
import gplx.core.gfo_ndes.*;
import gplx.core.stores.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
import gplx.xowa.addons.bldrs.files.dbs.*;
public class Xob_xfer_temp_itm_tst {
private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Pass() {fxt.Test_pass().Test_itm_chk_fail_id_none();}
@Test public void Missing_orig() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_page_id_is_null , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_page_id, null));}
@Test public void File_is_audio() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type, Xof_media_type.Name_audio));}
@Test public void File_is_mid() {
fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext, Xof_ext_.Id_mid));
}
@Test public void Redirect_src_is_empty() { // orig_cmd sets all direct files to have "orig_join" == "lnki_ttl"
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "A.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
);
fxt.Test_lnki_redirect_src(""); // confirm redirect_src set to ""
}
@Test public void Redirect_src_has_val() { // orig_cmd sets all redirect files to have "orig_join" = redirect and "lnki_ttl" as orig; EX: A.png redirects to B.png; orig_join will be B.png (the actual image) and redirect_src will be A.png (the original lnki)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
);
fxt.Test_lnki_redirect_src("A.png"); // confirm redirect_src set to ""
}
@Test public void Redirect_should_take_trg_ext() {// if "A.png" redirects to "B.jpg", ext_id should be ".jpg" (the actual file) not ".png (lnki_ext_id)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.jpg")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) // .png b/c B.jpg
);
fxt.Test_lnki_ext_id(Xof_ext_.Id_jpg); // confirm ext changed to .jpg
}
@Test public void Thumbtime_check() {// PURPOSE: one image actually had a thumbtime defined; EX: General_Dynamics_F-16_Fighting_Falcon; [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
);
fxt.Test_lnki_thumbtime(Xof_lnki_time.Null);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
);
fxt.Test_lnki_thumbtime(3);
}
@Test public void Page_check() {
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(Xof_lnki_page.Null);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(3);
fxt.Reset().Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_djvu)
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
);
fxt.Test_lnki_page(3);
}
@Test public void Media_should_be_ignored() {// ignore [[Media:]] for xfer_thumb (needed for xfer_orig)
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
, Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_src_tid , Xop_file_logger_.Tid__media)
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media);
}
@Test public void Orig_width_is_0() {// PURPOSE: ignore files with an orig width of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20
fxt.Test_bgn
( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.ogg")
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) // VIDEO
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_w , 0) // no width defined in image table
, Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_h , 0)
);
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_orig_w_is_0);
}
}
class Xob_xfer_temp_itm_fxt {
private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm();
private Xof_img_size img_size = new Xof_img_size();
private DataRdr_mem rdr;
private GfoNde nde;
public static String[] Flds = new String[]
{ Xob_lnki_regy_tbl.Fld_lnki_ext
, Xob_lnki_regy_tbl.Fld_lnki_id
, Xob_lnki_regy_tbl.Fld_lnki_tier_id
, Xob_orig_regy_tbl.Fld_orig_repo
, Xob_orig_regy_tbl.Fld_orig_file_ttl
, Xob_orig_regy_tbl.Fld_orig_file_ext
, Xob_orig_regy_tbl.Fld_lnki_ttl
, Xob_lnki_regy_tbl.Fld_lnki_type
, Xob_lnki_regy_tbl.Fld_lnki_src_tid
, Xob_lnki_regy_tbl.Fld_lnki_w
, Xob_lnki_regy_tbl.Fld_lnki_h
, Xob_lnki_regy_tbl.Fld_lnki_count
, Xob_lnki_regy_tbl.Fld_lnki_page_id
, Xob_orig_regy_tbl.Fld_orig_w
, Xob_orig_regy_tbl.Fld_orig_h
, Xob_orig_regy_tbl.Fld_orig_page_id
, Xob_lnki_regy_tbl.Fld_lnki_upright
, Xob_lnki_regy_tbl.Fld_lnki_time
, Xob_lnki_regy_tbl.Fld_lnki_page
, Xob_orig_regy_tbl.Fld_orig_media_type
, Xob_orig_regy_tbl.Fld_orig_minor_mime
}
;
public Xob_xfer_temp_itm_fxt Reset() {
itm.Clear();
return this;
}
public Xob_xfer_temp_itm_fxt Init_rdr_image() {
GfoFldList flds = GfoFldList_.str_(Flds);
nde = GfoNde_.vals_(flds, Object_.Ary
( Xof_ext_.Id_png, 1, 1, Xof_repo_tid_.Tid__remote
, "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xop_file_logger_.Tid__file
, 220, 200, 1, 2, 440, 400, 3
, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null
, Xof_media_type.Name_bitmap, "png"
));
GfoNdeList subs = GfoNdeList_.new_();
subs.Add(nde);
GfoNde root = GfoNde_.root_(nde);
rdr = DataRdr_mem.new_(root, flds, subs);
rdr.MoveNextPeer();
return this;
}
public Xob_xfer_temp_itm_fxt Init_rdr(String key, Object val) {
nde.Write(key, val);
return this;
}
public Xob_xfer_temp_itm_fxt Test_pass() {return Test_bgn();}
public Xob_xfer_temp_itm_fxt Test_fail(byte fail_tid, Keyval... kvs) {
Test_bgn(kvs);
this.Test_itm_chk_fail_id(fail_tid);
return this;
}
public Xob_xfer_temp_itm_fxt Test_bgn(Keyval... kvs) {
Init_rdr_image();
int len = kvs.length;
for (int i = 0; i < len; i++) {
Keyval kv = kvs[i];
Init_rdr(kv.Key(), kv.Val());
}
this.Exec_load();
this.Exec_chk();
return this;
}
public Xob_xfer_temp_itm_fxt Test_atr(String key, Object val) {
Tfds.Eq(rdr.Read(key), val);
return this;
}
public Xob_xfer_temp_itm_fxt Exec_load() {
itm.Load(rdr);
return this;
}
public Xob_xfer_temp_itm_fxt Exec_chk() {
itm.Chk(img_size);
return this;
}
public Xob_xfer_temp_itm_fxt Test_lnki_ext_id(int expd) {Tfds.Eq(expd, itm.Lnki_ext()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_thumbtime(double expd) {Tfds.Eq(expd, itm.Lnki_thumbtime()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_page(int expd) {Tfds.Eq(expd, itm.Lnki_page()); return this;}
public Xob_xfer_temp_itm_fxt Test_lnki_redirect_src(String expd) {Tfds.Eq(expd, itm.Redirect_src()); return this;}
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id_none() {return Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_none);}
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id(byte expd) {
Tfds.Eq(expd, itm.Chk_tid());
return this;
}
}

View File

@@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
public class Xobc_info_html__tst {
private final Xobc_info_html__fxt fxt = new Xobc_info_html__fxt();
@Test public void Torrent__en_w() {fxt.Test__torrent_link("en.wikipedia.org" , "https://archive.org/download/Xowa_enwiki_latest_archive.torrent");}
@Test public void Torrent__fr_d() {fxt.Test__torrent_link("fr.wiktionary.org" , "https://archive.org/download/Xowa_frwiki_latest_archive.torrent");}
}
class Xobc_info_html__fxt {
public void Test__torrent_link(String domain_str, String expd) {
Gftest.Eq__str(expd, Xobc_info_html.Make_torrent_fil("https://archive.org/download/", Xow_domain_itm_.parse(Bry_.new_u8(domain_str))));
}
}

View File

@@ -0,0 +1,38 @@
/*
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.xowa.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import org.junit.*; import gplx.core.tests.*;
public class Volume_prep_rdr_tst {
private final Volume_prep_rdr_fxt fxt = new Volume_prep_rdr_fxt();
@Test public void Parse() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last("A", "", "B")
, fxt.Make__itm("A")
, fxt.Make__itm("B")
);
}
}
class Volume_prep_rdr_fxt {
private final Volume_prep_rdr rdr = new Volume_prep_rdr();
public Volume_prep_rdr_fxt Test__parse(String raw, Volume_prep_itm... expd) {
Gftest.Eq__ary(expd, rdr.Parse(Bry_.new_u8(raw)));
return this;
}
public Volume_prep_itm Make__itm(String page_ttl) {
Volume_prep_itm rv = new Volume_prep_itm();
rv.Page_ttl = Bry_.new_u8(page_ttl);
return rv;
}
}

View File

@@ -0,0 +1,235 @@
/*
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.xowa.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Xoh_sidebar_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt();
@Test public void Grp() {
fxt.Init__msg__grp("key", "text", "title");
fxt.Exec__make("* key");
fxt.Test__objs(fxt.Make__grp("text", "title"));
}
@Test public void Grp_missing_msg() {
fxt.Exec__make("* key");
fxt.Test__objs(fxt.Make__grp("key", Null_str));
}
@Test public void Itm() {
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
fxt.Exec__make("** href_key|main_key");
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
}
@Test public void Itm_missing_msg() {
fxt.Exec__make("** href_key|main_key");
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Href_key"));
}
@Test public void Itm_text() { // PURPOSE: only text msg exists; EX: ** Portal:Contents|contents; no href, accesskey, title
fxt.Init__msg__itm("href_key", "main_key", "text", Null_str, Null_str, Null_str); // only define msg for text
fxt.Exec__make("** href_key|main_key");
fxt.Test__objs(fxt.Make__itm("text", Null_str, Null_str, "/wiki/Href_key"));
}
@Test public void Itm_href_absolute() {
fxt.Exec__make("** http://a.org|main_key");
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "http://a.org"));
}
@Test public void Itm_href_manual() {
fxt.Exec__make("** Help:Contents|main_key");
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Help:Contents"));
}
@Test public void Itm_href_xwiki() {
Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), "c", "commons.wikimedia.org");
fxt.Exec__make("** c:Help:Contents|main_key");
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/site/commons.wikimedia.org/wiki/Help:Contents"));
}
@Test public void Itm_err_missing_key() {
fxt.Exec__make("** no_main_key");
fxt.Test__objs();
}
@Test public void Itm_ignore() { // PURPOSE: ignore SEARCH, TOOLBOX, LANGUAGES
fxt.Exec__make
( "** SEARCH"
, "** TOOLBOX"
, "** LANGUAGES"
);
fxt.Test__objs();
}
@Test public void Itm_comment() { // PURPOSE: ignore comment; EX:de.v:MediaWiki:Sidebar; DATE:2014-03-08
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
fxt.Exec__make("** href_key<!--a-->|main_key<!--b-->");
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
}
@Test public void Smoke() {
fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title");
fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href");
fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str);
fxt.Exec__make
( "* navigation"
, "** mainpage|mainpage-description"
, "** Portal:Contents|contents"
, "* SEARCH"
, "* interaction"
, "** helppage|help"
, "* TOOLBOX"
, "** TOOLBOXEND"
, "* LANGUAGES"
);
fxt.Test__objs
( fxt.Make__grp("Grp_0_text", "Grp_0_title").Subs__add
( fxt.Make__itm("Itm_0_text", "Itm_0_title [a]", "a", "/wiki/Itm_0_href")
, fxt.Make__itm("Itm_1_text", Null_str, Null_str, "/wiki/Portal:Contents")
)
, fxt.Make__grp("interaction", Null_str).Subs__add
( fxt.Make__itm("help", Null_str, Null_str, "/wiki/Helppage")
));
fxt.Test__html
( "<div class=\"portal\" id=\"n-navigation\">"
, " <h3>Grp_0_text</h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Itm_0_href\" accesskey=\"a\" title=\"Itm_0_title [a] [a]\">Itm_0_text</a></li>"
, " <li id=\"n-contents\"><a href=\"/wiki/Portal:Contents\" title=\"\">Itm_1_text</a></li>"
, " </ul>"
, " </div>"
, "</div>"
, "<div class=\"portal\" id=\"n-interaction\">"
, " <h3>interaction</h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li id=\"n-help\"><a href=\"/wiki/Helppage\" title=\"\">help</a></li>"
, " </ul>"
, " </div>"
, "</div>"
);
}
@Test public void Itm_template_msg() {
fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random");
fxt.Exec__make("** href|main");
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
}
@Test public void Itm_template_key() {
fxt.Exec__make("** {{ns:Special}}:Random|main");
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
}
@Test public void Popups() {
fxt.Init__popups_enabled(true);
fxt.Exec__make
( "* navigation"
, "** mainpage|mainpage-description"
);
fxt.Test__objs
( fxt.Make__grp("navigation", "").Subs__add
( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage")
));
fxt.Test__html
( "<div class=\"portal\" id=\"n-navigation\">"
, " <h3>navigation</h3>"
, " <div class=\"body\">"
, " <ul>"
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Mainpage\" class='xowa-hover-off' title=\"\">mainpage-description</a></li>"
, " </ul>"
, " </div>"
, "</div>"
);
}
private static final String Null_str = "";
}
class Xoh_sidebar_mgr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoh_sidebar_mgr sidebar_mgr; private Bry_bfr bfr;
public Xoh_sidebar_mgr_fxt Clear() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
sidebar_mgr = wiki.Html_mgr().Portal_mgr().Sidebar_mgr();
bfr = Bry_bfr_.Reset(Io_mgr.Len_kb);
Init__popups_enabled(false);
return this;
}
public Xowe_wiki Wiki() {return wiki;}
public Xoh_sidebar_itm Make__grp(String text, String title, Xoh_sidebar_itm... itms) {
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.N, Bry_.new_a7(text), Bry_.new_a7(text), null);
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), null, null);
return rv;
}
public Xoh_sidebar_itm Make__itm(String text, String title, String accesskey, String href) {
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.Y, Bry_.new_a7(text), Bry_.new_a7(text), Bry_.new_a7(href));
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), Bry_.new_a7(accesskey), null);
return rv;
}
public Xoh_sidebar_mgr_fxt Init__popups_enabled(boolean v) {
wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled_(v);
return this;
}
public Xoh_sidebar_mgr_fxt Init__msg__grp(String key, String text, String title) {
Init_msg(key, text);
Init_msg("tooltip-n-" + key, title);
return this;
}
public Xoh_sidebar_mgr_fxt Init__msg__itm(String href_key, String main_key, String text, String title, String accesskey, String href) {
if (text != null) Init_msg(main_key, text);
if (href != null) Init_msg(href_key, href);
if (title != null) Init_msg("tooltip-n-" + main_key, title);
if (accesskey != null) Init_msg("accesskey-n-" + main_key, accesskey);
return this;
}
public Xoh_sidebar_mgr_fxt Init_msg(String key, String val) {
Xol_msg_mgr msg_mgr = wiki.Lang().Msg_mgr();
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(Bry_.new_a7(key));
msg_itm.Atrs_set(Bry_.new_a7(val), false, String_.Has(val, "{{"));
return this;
}
public void Exec__make(String... raw) {
sidebar_mgr.Make(bfr, Bry_.new_u8(String_.Concat_lines_nl_skip_last(raw)));
}
public void Test__objs(Xoh_sidebar_itm... expd) {
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
}
public void Test__objs(String raw, Xoh_sidebar_itm... expd) {
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
}
public void Test__html(String... expd) {
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), String_.new_u8(sidebar_mgr.Html_bry()));
}
private static String To_str_by_mgr(Xoh_sidebar_mgr mgr) {
List_adp grps = mgr.Grps();
int len = grps.Len();
Xoh_sidebar_itm[] ary = new Xoh_sidebar_itm[len];
for (int i = 0; i < len; i++)
ary[i] = (Xoh_sidebar_itm)grps.Get_at(i);
return To_str_by_itms(ary);
}
private static String To_str_by_itms(Xoh_sidebar_itm[] ary) {
Bry_bfr bfr = Bry_bfr_.New();
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++)
To_str_by_itm(bfr, ary[i]);
return bfr.To_str_and_clear();
}
private static void To_str_by_itm(Bry_bfr bfr, Xoh_sidebar_itm cur) {
boolean tid_is_itm = cur.Tid_is_itm();
bfr.Add_str_a7(tid_is_itm ? "itm|" : "grp|");
bfr.Add(cur.Text()).Add_byte_pipe();
bfr.Add(cur.Title()).Add_byte_pipe();
if (tid_is_itm) {
bfr.Add(cur.Accesskey()).Add_byte_pipe();
bfr.Add(cur.Href()).Add_byte_pipe();
}
bfr.Add_byte_nl();
int len = cur.Subs__len();
for (int i = 0; i< len; ++i)
To_str_by_itm(bfr, cur.Subs__get_at(i));
}
}

View File

@@ -0,0 +1,175 @@
/*
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.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_htmlr__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_htmlr__basic__fxt fxt = new Xoh_toc_htmlr__basic__fxt();
@Test public void D1_S0_S0() {
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_S0_U1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(3, "a_b");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_b\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(2, "b");
fxt.Init__add(3, "b_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#b_a\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1_U2() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D2_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(4, "a_a_a_a");
fxt.Init__add(3, "a_a_a");
fxt.Init__add(4, "a_a_a_b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a_a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a_a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#a_a_a_b\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">a_a_a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void Div() {
fxt.Init__init_page("Table of contents", false);
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_div
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\" class=\"toctitle\">"
, " <h2>Table of contents</h2>"
, " </div>"
, " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
, "</div>"
);
}
}
class Xoh_toc_htmlr__basic__fxt {
private final Xoh_toc_mgr wtr = new Xoh_toc_mgr();
private final Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {wtr.Clear();}
public void Init__add(int hdr_num, String hdr_txt) {wtr.Add(hdr_num, Bry_.new_u8(hdr_txt));}
public void Init__init_page(String toc_title, boolean page_banner) {wtr.Init(gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface_.Noop, Bry_.new_u8(toc_title), Bry_.Empty);}
public void Test__html_itms(String... expd_ary) {
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.Test__to_html())));
}
public void Test__html_div(String... expd_ary) {
wtr.To_html(bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, false);
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(bfr.To_bry_and_clear())));
}
}

View File

@@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__lvl__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__lvl__fxt fxt = new Xoh_toc_wkr__lvl__fxt();
@Test public void D1_S0_S0() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(2, fxt.Make(2, 1, Int_.Ary(2)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(3)));
}
@Test public void D1_D1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
}
@Test public void D1_D1_S0_U1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(3, fxt.Make(3, 2, Int_.Ary(1, 2)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
@Test public void D1_D1_U1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(2)));
fxt.Test__calc(3, fxt.Make(4, 2, Int_.Ary(2, 1)));
}
@Test public void D1_D1_D1_U2() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
}
class Xoh_toc_wkr__lvl__fxt {
private final Xoh_toc_wkr__lvl wkr = new Xoh_toc_wkr__lvl();
private final Xoh_toc_itm actl = new Xoh_toc_itm();
public void Clear() {wkr.Clear();}
public Xoh_toc_itm Make(int uid, int lvl, int[] path) {
Xoh_toc_itm rv = new Xoh_toc_itm();
rv.Set__lvl(uid, lvl, path);
return rv;
}
public void Test__calc(int lvl, Xoh_toc_itm expd) {
wkr.Calc_level(actl, lvl);
Gftest.Eq__int(expd.Uid(), actl.Uid(), "uid");
Gftest.Eq__int(expd.Lvl(), actl.Lvl(), "lvl");
Gftest.Eq__ary(expd.Path(), actl.Path(), "path");
}
}

View File

@@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*; import gplx.langs.htmls.*;
public class Xoh_toc_wkr__txt__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@Test public void Basic() {
fxt.Test__both("a b c", "a_b_c", "a b c");
}
@Test public void Ws() {
fxt.Test__both(" a b ", "a_b", "a b");
}
@Test public void Nl() {
fxt.Test__both("\na b\n", "a_b", "a b");
}
@Test public void Empty() { // PAGE:s.w:Colac,_Victoria DATE:2016-07-17
fxt.Test__both("", "", "");
}
@Test public void Amp__ncr() {
fxt.Test__both("&#91;a&#93;", ".5Ba.5D", "&#91;a&#93;");
}
@Test public void Encode() {
fxt.Test__both("a+b", "a.2Bb", "a+b");
}
@Test public void Comment() {
fxt.Test__text("a<!--b-->c", "ac");
}
@Test public void Remove_comment__one() {
fxt.Test__remove_comment("a<!--b-->c", "ac");
}
@Test public void Remove_comment__many() {
fxt.Test__remove_comment("1<!--2-->3<!--4-->5", "135");
}
@Test public void Remove_comment__dangling() {
fxt.Test__remove_comment("1<!--2-->3<!--4->5", "13");
}
}
class Xoh_toc_wkr__txt__fxt {
private final Xoh_toc_wkr__txt wkr = new Xoh_toc_wkr__txt();
private final Xoh_toc_itm itm = new Xoh_toc_itm();
private final Bry_bfr tmp = Bry_bfr_.New();
private final Xow_tidy_mgr_interface__test tidy_mgr = new Xow_tidy_mgr_interface__test();
public void Clear() {
wkr.Clear();
tidy_mgr.Clear();
wkr.Init(tidy_mgr, Xoa_page_.Main_page_bry);
}
public void Init__tidy(String html, String tidy) {tidy_mgr.Add(Bry_.new_u8(html), Bry_.new_u8(tidy));}
public void Test__anch(String html, String expd_anch) {Test__both(html, expd_anch, null);}
public void Test__text(String html, String expd_text) {Test__both(html, null, expd_text);}
public void Test__both(String html, String expd) {Test__both(html, expd, expd);}
public void Test__both(String html, String expd_anch, String expd_text) {
wkr.Calc_anch_text(itm, Bry_.new_u8(html));
if (expd_anch != null) Gftest.Eq__str(expd_anch, itm.Anch(), "anch");
if (expd_text != null) Gftest.Eq__str(expd_text, itm.Text(), "text");
}
public void Test__remove_comment(String html, String expd) {
byte[] html_bry = Bry_.new_u8(html);
Gftest.Eq__str(expd, Gfh_utl.Del_comments(tmp, html_bry, 0, html_bry.length));
}
}
class Xow_tidy_mgr_interface__test implements gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface {
private final Ordered_hash hash = Ordered_hash_.New_bry();
public void Clear() {hash.Clear();}
public void Add(byte[] html, byte[] tidy) {hash.Add(html, tidy);}
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {
byte[] html = bfr.To_bry_and_clear();
byte[] actl = (byte[])hash.Get_by_or_fail(html);
bfr.Add(actl);
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__dupe__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@Test public void Basic() {
fxt.Test__anch("a" , "a");
fxt.Test__anch("a" , "a_2");
}
@Test public void Case_insensitive() {
fxt.Test__anch("a" , "a");
fxt.Test__anch("A" , "A_2");
}
@Test public void Autonumber_exists() { // PAGE:fr.w:Itanium; EX: Itanium,Itanium_2,Itanium
fxt.Test__anch("a" , "a");
fxt.Test__anch("a_2" , "a_2");
fxt.Test__anch("a" , "a_3");
}
@Test public void Autonumber_exists_2() {
fxt.Test__anch("a_2" , "a_2");
fxt.Test__anch("a" , "a");
fxt.Test__anch("a" , "a_3");
fxt.Test__anch("a" , "a_4");
fxt.Test__anch("a_2" , "a_2_2");
}
}

View File

@@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__xnde__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@Test public void I() {fxt.Test__both("<i>a</i>" , "a", "<i>a</i>");}
@Test public void I__id() {fxt.Test__both("<i id='1'>a</i>" , "a", "<i>a</i>");}
@Test public void B() {fxt.Test__both("<b>a</b>" , "a", "<b>a</b>");}
@Test public void Sup() {fxt.Test__both("<sup>a</sup>" , "a", "<sup>a</sup>");}
@Test public void Sub() {fxt.Test__both("<sub>a</sub>" , "a", "<sub>a</sub>");}
@Test public void Bdi() {fxt.Test__both("<bdi>a</bdi>" , "a", "<bdi>a</bdi>");}
@Test public void Span() {fxt.Test__both("<span>a</span>" , "a", "a");}
@Test public void Span__id() {fxt.Test__both("<span id='1'>a</span>" , "a", "a");}
@Test public void Span__dir() {fxt.Test__both("<span dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Span__dir_id() {fxt.Test__both("<span id='1' dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Small() {fxt.Test__text("<small>a</small>" , "a");}
@Test public void A() {fxt.Test__both("<a href=\"/wiki/A\">b</a>" , "b");}
@Test public void A__nest() {fxt.Test__both("<a href=\"/wiki/A\">b<i>c</i>d</a>" , "bcd", "b<i>c</i>d");}
@Test public void Br() {fxt.Test__both("a<br/>b" , "ab");}
@Test public void Br__dangling() {fxt.Test__both("a<br>b" , "ab");}
@Test public void Wbr__dangling() {fxt.Test__both("a<wbr>b" , "ab");}
@Test public void H2() {fxt.Test__both("a<h2>b</h2>c" , "abc");} // NOTE: not a valid test; MW actually generates "ab" b/c of tidy; see corresponding edit test; DATE:2016-06-28
@Test public void Li() {fxt.Test__text("a<ul><li>b</li></ul>c" , "abc");}
@Test public void Table() {fxt.Test__text("a<table><tr><td>b</td></tr></table>c" , "abc");}
@Test public void Unknown__i() {fxt.Test__both("a<unknown>b<i>c</i>d</unknown>e" , "abcde", "a<unknown>b<i>c</i>d</unknown>e");} // NOTE: technically, anch should be href_encoded a<unknown>b<i>c</i>d</unknown>e b/c <unknown> is not a valid tag; compare with known tags like <li> / <table> which are just stripped
@Test public void Unknown__a() {fxt.Test__both("a<unknown>b<a>c</a>d</unknown>e" , "abcde", "a<unknown>bcd</unknown>e");}
@Test public void Fail() {
String html = "<i><a href='b'>c</i></a>";
fxt.Init__tidy(html, "<i><a href='b'>c</a></i>");
fxt.Test__both(html, "c", "<i>c</i>");
}
}

View File

@@ -0,0 +1,547 @@
/*
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.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.hdrs.*;
public class Xowe_hdr_bldr__tst {
@Before public void init() {fxt.Clear();} private final Xowe_hdr_bldr_fxt fxt = new Xowe_hdr_bldr_fxt();
@Test public void Basic() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "==b=="
, "==c=="
, "==d=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
)
);
}
@Test public void Hier_down() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "===b==="
, "====c===="
, "=====d====="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
, " <ul>"
, " <li class=\"toclevel-4 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.1.1.1</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
));
}
@Test public void Hier_up() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "===b==="
, "===c==="
, "==d=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Down_up() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "===b==="
, "==c=="
, "===d==="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">c</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
));
}
@Test public void D1_D1_D1_U2() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "===b==="
, "====c===="
, "==d=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Err() { // PURPOSE: models strange case wherein jumping down does not work
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "====b===="
, "===c==="
, "====d===="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">c</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
));
}
@Test public void Repeat_name() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
, "==a=="
, "==a=="
, "==a=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#a_2\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#a_3\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#a_4\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Id__encode() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a+b=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.2Bb\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a+b</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Ws() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "== a b =="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a b</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a_b'> a b </span></h2>"
));
}
@Test public void Apos_italic() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==''a''=="
)
, String_.Concat_lines_nl_skip_last
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
, ""
));
}
@Test public void Xnde__italic() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<i>a</i>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"><i>a</i></span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
));
}
@Test public void Xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a</small>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a'><small>a</small></span></h2>"
));
}
@Test public void Xnde__li() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<ul><li>b</li></ul>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='abc'>a<ul><li>b</li></ul>c</span></h2>"
));
}
@Test public void Xnde__table() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<table><tr><td>b</td></tr></table>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='abc'>a<table><tr><td>b</td></tr></table>c</span></h2>"
));
}
// TOMBSTONE: on MW, shows up as 'href="#ab"; <span class="toctext">ab</span>; '; TIDY doing strange things; ignore for now; DATE:2016-06-28
//@Test public void Xnde__h2() {
// fxt.Test_html_all(String_.Concat_lines_nl_skip_last
// ( "__FORCETOC__"
// , "==a<h2>b</h2>c=="
// )
// , String_.Concat_lines_nl
// ( fxt.toc_tbl_nl_n
// ( " <ul>"
// , " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
// , " </li>"
// , " </ul>"
// )
// , "<h2><span class='mw-headline' id='abc'>a<h2>b</h2>c</span></h2>"
// ));
//}
@Test public void Xnde__dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a<small>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a'><small>a<small></small></small></span></h2>"
));
}
@Test public void Nest__xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a <sup>b<small>c</small>d</sup> e=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_bcd_e\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a <sup>bcd</sup> e</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a_bcd_e'>a <sup>b<small>c</small>d</sup> e</span></h2>"
));
}
@Test public void Nest__lnki() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>[[a|b]]</small>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='b'><small><a href=\"/wiki/A\">b</a></small></span></h2>"
));
}
@Test public void Nest__br() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<span id=\"b\">b<br/></span>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ab\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ab</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='ab'>a<span id='b'>b<br/></span></span></h2>"
));
}
@Test public void Lnki_link() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==[[a]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a'><a href=\"/wiki/A\">a</a></span></h2>"
));
}
@Test public void Lnki_caption() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==[[a|b]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/A\">b</a></span></h2>"
));
}
@Test public void Lnki_caption_nest() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==[[a|b<i>c</i>d]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#bcd\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b<i>c</i>d</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='bcd'><a href=\"/wiki/A\">b<i>c</i>d</a></span></h2>"
));
}
@Test public void Html_ncr() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==&#91;a&#93;=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5Ba.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">&#91;a&#93;</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='.5Ba.5D'>&#91;a&#93;</span></h2>"
));
}
@Test public void Fix_large_before_small() { // PURPOSE.fix: "===a===\n===b===\n" followed by "==c==" causes improper formatting; DATE:2013-05-16
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "===a==="
, "===b==="
, "==c=="
, "==d=="
), fxt.toc_tbl_nl_y // NOTE: should all be level 2
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#d\"><span class=\"tocnumber\">4</span> <span class=\"toctext\">d</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Fix_large_before_small_2() { // PURPOSE.fix: similar to above, but has h3 after h2; PAGE:https://en.wikipedia.org/wiki/Wikipedia:Articles_for_creation/2006-08-27 DATE:2014-06-09
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "===a_0==="
, "==b_0=="
, "===b_1==="
, "==c_0=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_0\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a_0</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b_0\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b_0</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#b_1\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_1</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#c_0\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c_0</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Translate_and_comment() { // PURPOSE: <translate> is an xtn and parses its innerText separately; meanwhile, toc_mgr defaults to using the innerText to build toc; EX:Wikidata:Introduction; DATE:2013-07-16
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<translate><!--b-->ac</translate>=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ac\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
, " </li>"
, " </ul>"
));
}
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<ref>b</ref>=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.5B1.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a<sup>[1]</sup></span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a.5B1.5D'>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></h2>"
));
}
@Test public void Category() { // PURPOSE: Category should not show in in TOC; DATE:2013-12-09
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==A[[Category:B]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#A\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">A</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='A'>A</span></h2>"
));
}
@Test public void Category_literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==A[[:Category:B]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ACategory:B\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ACategory:B</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='ACategory:B'>A<a href=\"/wiki/Category:B\">Category:B</a></span></h2>"
));
}
@Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==[[File:A.png]] b=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b</span></h2>"
));
}
@Test public void Lnki_invalid() { // PURPOSE: invalid lnki was causing null ref; DATE:2014-02-07
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==[[]]=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.5B.5B.5D.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">[[]]</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='.5B.5B.5D.5D'>[[]]</span></h2>"
));
}
@Test public void File_in_tbl() { // PURPOSE: two issues (a) don't show file if in tbl; (b) if v2, file inside tbl fails; PAGE:en.w:Holmes County,_Mississippi; DATE:2014-06-22
fxt.Test_html_frag(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a <table><tr><td>[[File:A.png]]b</td></tr></table> c=="
)
, "<span class=\"toctext\">a b c</span>" // note that "b" inside tbl shows
);
}
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xowe_hdr_bldr_fxt {
private final Bry_bfr tmp = Bry_bfr_.New();
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
tmp.Clear();
}
public void Test_html_toc(String raw, String expd) {
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
// HACK: proc only tests TOC; remove <h#><span class="mw-> section; ugly hack, but this is only test code
int span_pos = String_.FindFwd(actl, "<span class=\"mw-");
actl = String_.Mid(actl, 0, span_pos - 5);
Tfds.Eq_str_lines(expd, actl);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public void Test_html_all(String raw, String expd) {
expd = Xoh_consts.Escape_apos(expd);
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
Tfds.Eq_str_lines(expd, actl);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public void Test_html_frag(String raw, String frag) {
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
fxt.Test_str_part_y(actl, frag);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public String toc_tbl_nl_y(String... ary) {return toc_tbl(Bool_.Y, ary);}
public String toc_tbl_nl_n(String... ary) {return toc_tbl(Bool_.N, ary);}
public String toc_tbl(boolean nl, String... ary) {
return String_.Concat_lines_nl_skip_last
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\" class=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, String_.Concat_lines_nl_skip_last(ary)
, "</div>" + (nl ? "\n" : "")
);
}
public static String Bld_page_with_toc(Bry_bfr bfr, Xop_fxt fxt, String raw) {
gplx.xowa.parsers.Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
fxt.Ctx().Page_data().Copy_to(fxt.Page());
fxt.Wiki().Html_mgr().Html_wtr().Write_doc(bfr, fxt.Ctx(), fxt.Hctx(), root.Root_src(), root);
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(bfr, fxt.Page(), Xoh_wtr_ctx.Basic);
return bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.parsers.mediawikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.parsers.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_mediawiki_wkr__tst {
private final Xop_mediawiki_wkr__fxt fxt = new Xop_mediawiki_wkr__fxt();
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void Basic() {
fxt.Init__wkr("en.wikipedia.org", null);
fxt.Test__parse("Page_1", "''{{PAGENAME}}''"
, "<p><i>Page 1</i>"
, "</p>"
);
}
@Test public void Template() {
fxt.Init__wkr("en.wikipedia.org", new Xop_mediawiki_loader__mock());
fxt.Test__parse("Page_1", "{{bold}}"
, "<p><b>bold</b>"
, "</p>"
);
}
}
class Xop_mediawiki_wkr__fxt {
private final Xop_mediawiki_mgr mgr = new Xop_mediawiki_mgr("mem/xowa/wiki/en.wikipedia.org/", false);
private Xop_mediawiki_wkr wkr;
public Xop_mediawiki_wkr__fxt() {
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
}
public void Init__wkr(String wiki, Xop_mediawiki_loader cbk) {
this.wkr = mgr.Make(wiki, cbk);
}
public void Test__parse(String page, String wtxt, String... expd) {
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), wkr.Parse(page, wtxt), "parse failed; wtxt={0}", wtxt);
}
}
class Xop_mediawiki_loader__mock implements Xop_mediawiki_loader {
public String LoadWikitext(String page) {
if (String_.Eq(page, "Template:Bold")) return "'''bold'''";
else return "text";
}
}

View File

@@ -0,0 +1,311 @@
/*
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.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.*; import gplx.core.intls.ucas.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr__basic__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
@Test public void Page_itm() {
fxt .Init_itms__pages("A1")
.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>");
}
@Test public void Page_itm_missing() {
fxt.Init_itms__pages("A1");
Xoctg_catpage_itm itm = fxt.Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0);
itm.Page_ttl_(Xoa_ttl.Null);
itm.Sortkey_handle_make(Bry_bfr_.New(), Bry_.Empty);
fxt.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">missing page (0)</li>");
}
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
byte[] page_bry = Bry_.new_a7("A 1");
Xoa_url url = Xoa_url.New(Bry_.new_a7("en.wikipedia.org"), page_bry);
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry);
fxt.Wiki().Appe().Usere().History_mgr().Add(fxt.Wiki().App(), url, ttl, page_bry);
fxt .Init_itms__pages("A_1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A_1\" class=\"xowa-visited\" title=\"A 1\">A 1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all() {
fxt .Init_itms__pages("A1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void File_all() {
fxt .Init_itms__files("File:A1.png")
.Test__html__all(Xoa_ctg_mgr.Tid__file, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-category-media\">"
, " <h2>Media in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following file.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/File:A1.png\" title=\"File:A1.png\">File:A1.png</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Subc_all() {
fxt .Init_itms__subcs("Category:Subc_1")
.Test__html__all(Xoa_ctg_mgr.Tid__subc, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-subcategories\">"
, " <h2>Subcategories</h2>"
, " <p>This category has only the following subcategory.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>S</h3>"
, " <ul>"
, " <li>"
, " <div class=\"CategoryTreeSection\">"
, " <div class=\"CategoryTreeItem\">"
, " <span class=\"CategoryTreeBullet\">"
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"Subc_1\" title=\"Subc 1\" data-ct-state=\"collapsed\">"
, " </span> "
, " </span>"
, " <a href=\"/wiki/Category:Subc_1\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">Subc 1"
, " </a>"
, " <span title=\"contains 0 subcategories, 0 pages, and 0 files\" dir=\"ltr\">"
, " </span>"
, " </div>"
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
, " </div>"
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all_cols() {
fxt.Init_itms__pages("A1", "A2", "A3", "B1", "C1");
fxt.Init__grp_max_(6);
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>The following 5 pages are in this category, out of 5 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " <li><a href=\"/wiki/A2\" title=\"A2\">A2</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>A cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A3\" title=\"A3\">A3</a></li>"
, " </ul>"
, " <h3>B</h3>"
, " <ul>"
, " <li><a href=\"/wiki/B1\" title=\"B1\">B1</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>C</h3>"
, " <ul>"
, " <li><a href=\"/wiki/C1\" title=\"C1\">C1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page__numeric() { // PURPOSE: check numeric sorting; 0, 9, 10; not 0, 10, 9; DATE:2016-10-09
fxt.Init_itms__pages("0", "9", "10");
fxt.Init__grp_max_(6);
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>The following 3 pages are in this category, out of 3 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>0-9</h3>"
, " <ul>"
, " <li><a href=\"/wiki/0\" title=\"0\">0</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/9\" title=\"9\">9</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/10\" title=\"10\">10</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28
fxt .Init_itms__pages("A\"1")
.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A%221\" title=\"A&quot;1\">A&quot;1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Calc_col_len() {
fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items
fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items
fxt.Test__calc_col_len(10, 2, 3); // for 10 items, col 2 has 3 items
fxt.Test__calc_col_len(11, 0, 4);
fxt.Test__calc_col_len(11, 1, 4);
fxt.Test__calc_col_len(11, 2, 3);
fxt.Test__calc_col_len(12, 0, 4);
fxt.Test__calc_col_len(12, 1, 4);
fxt.Test__calc_col_len(12, 2, 4);
}
}
class Xoctg_catpage_mgr_fxt {
private int grp_max;
private Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true);
public Xoctg_catpage_mgr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
ctg_html = wiki.Ctg__catpage_mgr();
}
ctg = new Xoctg_catpage_ctg(1, Bry_.new_a7("Ctg_1"));
grp_max = 3; // default to 3 paer page
return this;
} private Xoae_app app; private Xoctg_catpage_mgr ctg_html;
public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg;
public void Init__grp_max_(int v) {this.grp_max = v;}
public void Init__prev_hide_y_(byte tid) {ctg.Grp_by_tid(tid).Prev_disable_(true);}
public void Init__next_sortkey_(byte tid, String v) {ctg.Grp_by_tid(tid).Next_sortkey_(Bry_.new_u8(v));}
public void Test__navlink(boolean next, String ctg_str, String expd) {
byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid__page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid__page), grp_max);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public Xoctg_catpage_mgr_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__page, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__file, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__subc, titles);}
private Xoctg_catpage_mgr_fxt Init_itms(byte tid, String[] ttls) {
int len = ttls.length;
Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp();
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
grp.Count_all_(len);
for (int i = 0; i < len; ++i) {
byte[] page_ttl_bry = Bry_.new_u8(ttls[i]);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page_ttl_bry);
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl);
tmp.Add(itm);
}
tmp.Make_by_grp(grp);
return this;
}
public void Test__html__page(byte tid, byte grp_char_0, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_itm_base itm_fmt = list_mgr.Itm_fmt();
Xoctg_catpage_grp list = ctg.Grp_by_tid(tid);
itm_fmt.Init_from_ltr(wiki, list, ltr_extractor);
itm_fmt.Set_ltr_and_bgn(new byte[] {grp_char_0}, 0);
itm_fmt.Col_end_(0, 0);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
itm_fmt.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test__html_grp(byte tid, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_ltr fmtr_grp = new Xoctg_fmt_ltr(list_mgr.Itm_fmt());
fmtr_grp.Init_from_grp(wiki, ctg.Grp_by_tid(tid), ltr_extractor);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
fmtr_grp.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test__html__all(byte tid, String expd) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ltr_extractor, ctg, grp_max);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr__navlink__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
@Test public void Navlink__basic() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
fxt.Init_itms__pages("A\" 2", "A\" 3", "A\" 4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A\" 5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2%0AA%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__bos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__prev_hide_y_(Xoa_ctg_mgr.Tid__page);
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(previous 3)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__eos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(next 3)"
));
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
public class Xoctg_catlink_loader__tst {
private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt();
@Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record
fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'"
}
@Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed
fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'"
}
}
class Xoctg_catlink_loader__fxt {
public void Test__build_sortkey_sql(int version, String sortkey, String expd) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation
Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki);
Bry_bfr bfr = Bry_bfr_.New();
Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey)));
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoctg_collation_wkr___tst {
private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt();
@Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");}
@Test public void Identity() {fxt.Test__make("identity" , "identity");}
@Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");}
@Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);}
@Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);}
@Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);}
@Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);}
@Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);}
}
class Xoctg_collation_wkr___fxt {
public void Test__make(String wm_name, String expd_type) {
Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_type, actl.Type_name());
}
public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) {
Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_locale, actl.Icu_locale());
Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting());
}
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
public class Xoctg_catpage_url__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url__fxt fxt = new Xoctg_catpage_url__fxt();
@Test public void Specific() {
fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void General() {
fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void Url_encoded() {
fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
}
}
class Xoctg_catpage_url__fxt {
private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url;
public void Clear() {
Xoa_app app = Xoa_app_fxt.Make__app__edit();
this.xo_url_parser = app.User().Wikii().Utl__url_parser();
}
public Xoctg_catpage_url__fxt Exec__parse(String url_str) {
Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str));
this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url);
return this;
}
public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;}
public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;}
}

View File

@@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
import org.junit.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xoctg_double_box__tst {
@Before public void init() {fxt.Clear();} private Xoctg_double_box__fxt fxt = new Xoctg_double_box__fxt();
@Test public void Basic() {
fxt.Init_ctg_hidden("Category:A", "Category:B", "Category:C");
fxt.Init_ctg_normal("Category:D", "Category:E", "Category:F");
fxt.Test_print_hidden(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "<a href=\"/wiki/Special:Categories\" title=\"Special:Categories\">Categories</a>:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:D\" title=\"Category:D\">D</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:E\" title=\"Category:E\">E</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:F\" title=\"Category:F\">F</a>"
, "</li>"
, "</ul>"
, "</div>"
, "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">Hidden categories:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" title=\"Category:A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" title=\"Category:B\">B</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:C\" title=\"Category:C\">C</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoctg_double_box__fxt {
private Xop_fxt fxt; private Xoctg_double_box hidden_wtr;
private final List_adp init_ctgs = List_adp_.New();
public void Clear() {
fxt = new Xop_fxt();
hidden_wtr = new Xoctg_double_box();
hidden_wtr.Init_by_wiki(fxt.Wiki());
init_ctgs.Clear();
}
public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);}
public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);}
public void Init_ctg(boolean hidden, String[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ary[i]));
Xoctg_pagebox_itm itm = Xoctg_pagebox_itm.New_by_ttl(ttl);
itm.Load_by_cat_core(hidden, 0, 0, 0);
init_ctgs.Add_many(itm);
}
}
public void Test_print_hidden(String expd) {
Bry_bfr bfr = Bry_bfr_.New();
Xoctg_pagebox_itm[] ary = (Xoctg_pagebox_itm[])init_ctgs.To_ary_and_clear(Xoctg_pagebox_itm.class);
hidden_wtr.Write_pagebox(bfr, ary);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
import org.junit.*;
import gplx.xowa.htmls.core.htmls.*;
public class Xoctg_single_box__tst {
@Before public void init() {fxt.Clear();} private final Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt();
@Test public void Basic() {
fxt.Init__ctgs("Category:A", "Category:B").Test_html(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "Categories:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoh_ctg_mgr_fxt {
private Xoctg_single_box ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr_.New();
private Xoae_page page;
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
page = wiki.Parser_mgr().Ctx().Page();
ctg_grp_mgr = new Xoctg_single_box();
ctg_grp_mgr.Init_by_wiki(wiki);
}
public Xoh_ctg_mgr_fxt Init__ctgs(String... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
page.Wtxt().Ctgs__add(wiki.Ttl_parse(Bry_.new_u8(ary[i])));
}
return this;
}
public void Test_html(String expd) {
ctg_grp_mgr.Write_pagebox(tmp_bfr, Xoctg_pagebox_itm.New_ary(page));
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,70 @@
/*
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.xowa.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*;
import gplx.xowa.wikis.data.*;
public class Xowdir_wiki_props_mgr__tst {
private final Xowdir_wiki_props_mgr__fxt fxt = new Xowdir_wiki_props_mgr__fxt();
@Test public void Import__wiki__missing_all() {
// handle all imported .xowa wikis pre v4.3
fxt.Init__wiki_props(null, null, null);
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__missing_domain() {
// handle personal wikis from v4.2
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__wmf_domain() {
// handle wmf wikis with a core-file of "test-core.xowa"
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test-core.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Import__wiki__clean() {
// handle clean wiki
fxt.Init__wiki_props("test", "test", "Main_Page");
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.N, fxt.Make__json("test", "test", "Main_Page"));
}
@Test public void Open__wiki__missing_name() {
// handle missing name
fxt.Init__user_json("test", "my test", "Main_Page");
fxt.Init__wiki_props(null, null, "Main_Page");
fxt.Test__verify(Bool_.N, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "my test", "Main_Page"));
}
}
class Xowdir_wiki_props_mgr__fxt {
private final Xowdir_wiki_props_mgr mgr = new Xowdir_wiki_props_mgr__mock();
public Xowdir_wiki_props Make__json(String domain, String name, String main_page) {
return new Xowdir_wiki_props(domain, name, main_page);
}
public void Init__user_json(String domain, String name, String main_page) {
Xowdir_wiki_json wiki_json = new Xowdir_wiki_json(name, main_page);
mgr.User_reg__upsert(domain, wiki_json.To_str(new Json_wtr()));
}
public void Init__wiki_props(String domain, String name, String main_page) {
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__domain, domain);
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__name, name);
mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__init__main_page, main_page);
}
public void Test__verify(boolean mode_is_import, String url, boolean expd_dirty, Xowdir_wiki_props expd) {
Xowdir_wiki_props actl = mgr.Verify(mode_is_import, "", Io_url_.new_any_(url));
Gftest.Eq__ary__lines(expd.To_str(), actl.To_str(), "expd");
Gftest.Eq__bool(expd_dirty, actl.Dirty(), "dirty");
}
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.fulltexts.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*;
import org.junit.*; import gplx.core.tests.*;
public class Xofulltext_extractor__tst {
private final Xofulltext_extractor__fxt fxt = new Xofulltext_extractor__fxt();
@Test public void Basic() {
// simple node
fxt.Test__extract("a <i>b</i> c", "a b c");
// node with attributes
fxt.Test__extract("a <a href='b.html' caption='c d e'>f</a> g", "a f g");
// nested nodes
fxt.Test__extract("a <b>b <i>c</i> d</b> e", "a b c d e");
// periods
fxt.Test__extract("a <b>b</b>. c d", "a b. c d");
// parens
fxt.Test__extract("(a <b>b</b>)", "(a b)");
// parens
fxt.Test__extract("<b>a</b> (b)", "a (b)");
}
}
class Xofulltext_extractor__fxt {
private final Xofulltext_extractor extractor = new Xofulltext_extractor();
public void Test__extract(String src, String expd) {
Gftest.Eq__str(expd, extractor.Extract(Bry_.new_u8(src)));
}
}

View File

@@ -0,0 +1,122 @@
/*
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.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.finders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*; import gplx.xowa.addons.wikis.fulltexts.searchers.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.*;
import org.junit.*; import gplx.core.tests.*;
public class Xofulltext_finder_cbk__eval__tst {
private final Xofulltext_finder_cbk__eval__fxt fxt = new Xofulltext_finder_cbk__eval__fxt();
@Test public void Exact() {
fxt.Init__search("a");
// y: basic match
fxt.Test__eval_y("a");
// n: no match
fxt.Test__eval_n("z");
// n: wildcard_bgn not enabled
fxt.Test__eval_n("az");
}
@Test public void Or() {
fxt.Init__search("a, c");
// y: lone char
fxt.Test__eval_y("a" , "c");
// y: one char
fxt.Test__eval_y("a b", "b c");
// y: both chars
fxt.Test__eval_y("a c", "a b c");
// n: no chars
fxt.Test__eval_n("b");
}
@Test public void And() {
fxt.Init__search("a + c");
// y: both chars
fxt.Test__eval_y("a c", "a b c");
// n: one char only
fxt.Test__eval_n("a", "c", "a b", "b c");
}
@Test public void And__shorthand() {
fxt.Init__search("a c");
// y: both chars
fxt.Test__eval_y("a b c");
// n: one char only
fxt.Test__eval_n("a", "c");
}
@Test public void Not() {
fxt.Init__search("-a");
// y: no chars
fxt.Test__eval_y("b");
// n: char exists
fxt.Test__eval_n("a");
}
@Test public void Trim_end() {
fxt.Init__search("a");
// y: single
fxt.Test__eval_y("a!");
// y: many
fxt.Test__eval_y("a!!!");
}
@Test public void Trim_bgn() {
fxt.Init__search("a");
// y: single
fxt.Test__eval_y("!a");
// y: many
fxt.Test__eval_y("!!!a");
}
@Test public void Trim_both() {
fxt.Init__search("a");
// y: single
fxt.Test__eval_y("'a'");
// y: many
fxt.Test__eval_y("'''a'''");
}
@Test public void Slash() {
fxt.Init__search("a");
// y: slash before, after
fxt.Test__eval_y("a/b/c", "b/a/c", "b/c/a");
}
@Test public void Brack() {
fxt.Init__search("a");
// y
fxt.Test__eval_y("[[a]]");
}
// .
// ...
// -
// a'b
// https://site/page
// ()
// []
// <>
}
class Xofulltext_finder_cbk__eval__fxt {
private boolean case_match = false;
private boolean auto_wildcard_bgn = false;
private boolean auto_wildcard_end = false;
private byte wildcard_byte = Byte_ascii.Star;
private byte not_byte = Byte_ascii.Dash;
private final Xofulltext_finder_mgr finder = new Xofulltext_finder_mgr();
private final Xofulltext_finder_cbk__eval cbk = new Xofulltext_finder_cbk__eval();
public void Init__search(String query) {
finder.Init(Bry_.new_u8(query), case_match, auto_wildcard_bgn, auto_wildcard_end, wildcard_byte, not_byte);
}
public void Test__eval_y(String... texts) {Test__eval(Bool_.Y, texts);}
public void Test__eval_n(String... texts) {Test__eval(Bool_.N, texts);}
public void Test__eval(boolean expd, String... texts) {
for (String text : texts) {
byte[] text_bry = Bry_.new_u8(text);
cbk.found = false;
finder.Match(text_bry, 0, text_bry.length, cbk);
Gftest.Eq__bool(expd, cbk.found, "query={0} text={1}", finder.Query(), text);
}
}
}

View File

@@ -0,0 +1,118 @@
/*
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.xowa.addons.wikis.htmls.css.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.htmls.*; import gplx.xowa.addons.wikis.htmls.css.*;
import org.junit.*; import gplx.core.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.htmls.css.dbs.*;
public class Xowd_css_core_mgr_tst {
@Before public void init() {fxt.Clear();} private Xowd_css_core_mgr_fxt fxt = new Xowd_css_core_mgr_fxt();
@Test public void Basic() {
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050200")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
Io_url trg_dir = Io_url_.mem_dir_("mem/trg/");
fxt.Exec_get(trg_dir, "desktop");
fxt.Test_fs(trg_dir, file_ary);
}
@Test public void Update() { // update css files; keep same skin_id; insert new files
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
( fxt.Make_skin_itm(1, "desktop", "20010101_050500")
);
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a.css", "a_data")
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
);
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
file_ary = fxt.Make_file_ary
( fxt.Make_file_itm(1, "a1.css", "a1_data")
, fxt.Make_file_itm(1, "b/b1.png", "b/b1_data")
);
Io_mgr.Instance.DeleteDirDeep(src_dir);
fxt.Init_fs(src_dir, file_ary);
fxt.Exec_set(src_dir, "desktop");
fxt.Test_skin_tbl(skin_ary);
fxt.Test_file_tbl(file_ary);
}
}
class Xowd_css_core_mgr_fxt {
private final Bry_bfr bfr = Bry_bfr_.Reset(32);
private Xowd_css_core_tbl core_tbl; private Xowd_css_file_tbl file_tbl;
public void Clear() {
Datetime_now.Manual_y_();
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/css.sqlite3"));
this.core_tbl = new Xowd_css_core_tbl(conn);
this.file_tbl = new Xowd_css_file_tbl(conn);
core_tbl.Create_tbl();
file_tbl.Create_tbl();
}
public Xowd_css_core_itm Make_skin_itm(int id, String key, String updated_on) {return new Xowd_css_core_itm(id, key, DateAdp_.parse_gplx(updated_on));}
public Xowd_css_file_itm Make_file_itm(int skin_id, String path, String data) {return new Xowd_css_file_itm(skin_id, path, Bry_.new_u8(data));}
public Xowd_css_file_itm[] Make_file_ary(Xowd_css_file_itm... ary) {return ary;}
public Xowd_css_core_itm[] Make_skin_ary(Xowd_css_core_itm... ary) {return ary;}
public void Init_fs(Io_url css_dir, Xowd_css_file_itm[] file_ary) {
for (Xowd_css_file_itm itm : file_ary)
Io_mgr.Instance.SaveFilBry(css_dir.GenSubFil(itm.Path()), itm.Data());
}
public void Exec_set(Io_url css_dir, String key) {Xowd_css_core_mgr.Set(core_tbl, file_tbl, css_dir, key);}
public void Exec_get(Io_url css_dir, String key) {Xowd_css_core_mgr.Get(core_tbl, file_tbl, css_dir, key);}
public void Test_skin_tbl(Xowd_css_core_itm[] expd) {
Xowd_css_core_itm[] actl = core_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_file_tbl(Xowd_css_file_itm[] expd) {
Xowd_css_file_itm[] actl = file_tbl.Select_all();
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
}
public void Test_fs(Io_url css_dir, Xowd_css_file_itm[] expd) {
Io_url[] actl = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
int len = expd.length;
Tfds.Eq(len, actl.length);
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm expd_itm = expd[i];
Tfds.Eq_bry(expd_itm.Data(), Io_mgr.Instance.LoadFilBry(actl[i]));
}
}
private String To_str(Xowd_css_file_itm[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_file_itm itm = ary[i];
bfr.Add_int_variable(itm.Css_id()).Add_byte_pipe().Add_str_u8(itm.Path()).Add_byte_pipe().Add(itm.Data()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
private String To_str(Xowd_css_core_itm[] ary) {
Bry_bfr bfr = Bry_bfr_.New();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_css_core_itm itm = ary[i];
bfr.Add_int_variable(itm.Id()).Add_byte_pipe().Add_str_u8(itm.Key()).Add_byte_pipe().Add_str_u8(itm.Updated_on().XtoStr_fmt_yyyyMMdd_HHmmss()).Add_byte_nl();
}
return bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.pages.randoms.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.randoms.*;
import org.junit.*; import gplx.xowa.specials.*;
public class Rndm_root_special_tst {
@Before public void init() {fxt.Clear();} private Rndm_root_special_fxt fxt = new Rndm_root_special_fxt();
@Test public void Ns_main() {
fxt.Init_create_page("A");
fxt.Init_create_page("A/B/C");
fxt.Test_open("Special:RandomRootPage/Main", "A"); // NOTE: result will always be "A"; "A" -> "A"; "A/B/C" -> "A"
}
@Test public void Ns_help() {
fxt.Init_create_page("Help:A");
fxt.Init_create_page("Help:A/B/C");
fxt.Test_open("Special:RandomRootPage/Help", "Help:A");
}
}
class Rndm_root_special_fxt {
private Xop_fxt parser_fxt; private Rndm_root_special special_page; private Xowe_wiki wiki;
public void Clear() {
parser_fxt = new Xop_fxt();
parser_fxt.Reset();
wiki = parser_fxt.Wiki();
special_page = new gplx.xowa.addons.wikis.pages.randoms.specials.Rndm_root_special();
}
public void Init_create_page(String page) {parser_fxt.Init_page_create(page, page);}
public void Test_open(String special_url, String expd) {
Xoae_page page = Test_special_open(wiki, special_page, special_url);
Tfds.Eq(expd, String_.new_a7(page.Url().Page_bry()));
Tfds.Eq(expd, String_.new_a7(page.Db().Text().Text_bry()));
}
public static Xoae_page Test_special_open(Xowe_wiki wiki, Xow_special_page special_page, String special_url) {
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(special_url));
page.Url_(url);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(special_url));
page.Ttl_(ttl);
special_page.Special__gen(wiki, page, url, ttl);
return page;
}
}

View File

@@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
import gplx.core.tests.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import gplx.xowa.addons.wikis.pages.syncs.core.parsers.*;
public class Xosync_page_loader__fxt {
private final Xosync_page_loader mgr = new Xosync_page_loader();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final Xoh_page hpg = new Xoh_page();
private Xowe_wiki wiki;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
hpg.Clear();
}
public Xosync_page_loader__fxt Exec__parse(String raw) {
mgr.Parse(wiki, hpg, Bry_.new_u8(raw));
return this;
}
public Xosync_page_loader__fxt Test__html(String expd) {
Gftest.Eq__ary__lines(expd, hpg.Db().Html().Html_bry(), "converted html");
return this;
}
public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, String orig_ext_str, int file_w, double file_time, int file_page) {
Xof_fsdb_itm itm = new Xof_fsdb_itm();
Xof_ext orig_ext = Xof_ext_.new_by_ext_(Bry_.new_u8(orig_ext_str));
itm.Init_by_wm_parse(wiki.Domain_itm().Abrv_xo(), repo_is_commons, file_is_orig, Bry_.new_u8(file_ttl), orig_ext, file_w, file_time, file_page);
return itm;
}
public Xosync_page_loader__fxt Test__fsdb(Xof_fsdb_itm expd) {
Xof_fsdb_itm actl = (Xof_fsdb_itm)hpg.Img_mgr().Get_at(0);
Gftest.Eq__str(Xosync_hdoc_parser__fxt.To_str(tmp_bfr, expd), Xosync_hdoc_parser__fxt.To_str(tmp_bfr, actl));
return this;
}
}

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