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:
214
100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java
Normal file
214
100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataRdr_csv_dat_tst {
|
||||
@Before public void setup() {
|
||||
fx.Parser_(DsvParser.csv_(false, GfoFldList_.Null));
|
||||
fx.Clear();
|
||||
} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void Empty() {
|
||||
fx.run_parse_("");
|
||||
fx.tst_DatNull();
|
||||
}
|
||||
@Test public void Fld_0() {
|
||||
fx.run_parse_("a");
|
||||
fx.tst_DatCsv(fx.ary_("a"));
|
||||
}
|
||||
@Test public void Fld_N() {
|
||||
fx.run_parse_("a,b,c");
|
||||
fx.tst_FldListCsv("fld0", "fld1", "fld2");
|
||||
fx.tst_DatCsv(fx.ary_("a", "b", "c"));
|
||||
}
|
||||
@Test public void Row_N() {
|
||||
fx.run_parse_
|
||||
( "a,b,c", String_.CrLf
|
||||
, "1,2,3"
|
||||
);
|
||||
fx.tst_DatCsv
|
||||
( fx.ary_("a", "b", "c")
|
||||
, fx.ary_("1", "2", "3")
|
||||
);
|
||||
}
|
||||
@Test public void Escape_WhiteSpace() {
|
||||
fx.run_parse_("a,\" \t\",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", " \t", "c"));
|
||||
}
|
||||
@Test public void Escape_FldSep() {
|
||||
fx.run_parse_("a,\",\",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", ",", "c"));
|
||||
}
|
||||
@Test public void Escape_RowSep() {
|
||||
fx.run_parse_("a,\"" + String_.CrLf + "\",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", String_.CrLf, "c"));
|
||||
}
|
||||
@Test public void Escape_Quote() {
|
||||
fx.run_parse_("a,\"\"\"\",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", "\"", "c"));
|
||||
}
|
||||
@Test public void Blank_Null() {
|
||||
fx.run_parse_("a,,c");
|
||||
fx.tst_DatCsv(fx.ary_("a", null, "c"));
|
||||
}
|
||||
@Test public void Blank_EmptyString() {
|
||||
fx.run_parse_("a,\"\",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", "", "c"));
|
||||
}
|
||||
@Test public void Blank_Null_Multiple() {
|
||||
fx.run_parse_(",,");
|
||||
fx.tst_DatCsv(fx.ary_(null, null, null));
|
||||
}
|
||||
@Test public void TrailingNull() {
|
||||
fx.run_parse_("a,");
|
||||
fx.tst_DatCsv(fx.ary_("a", null));
|
||||
}
|
||||
@Test public void TrailingEmpty() {
|
||||
fx.run_parse_("a,\"\"");
|
||||
fx.tst_DatCsv(fx.ary_("a", ""));
|
||||
}
|
||||
@Test public void Quote_Error() {
|
||||
try {
|
||||
fx.run_parse_("a,\"\" ,c");
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
catch (Err e) {
|
||||
Tfds.Eq_true(String_.Has(Err_.Message_lang(e), "invalid quote in quoted field"));
|
||||
}
|
||||
}
|
||||
@Test public void Misc_AllowValsLessThanFields() {
|
||||
// assume null when vals.Count < fields.Count; PURPOSE: MsExcel will not save trailing commas for csvExport; ex: a, -> a
|
||||
fx.run_parse_
|
||||
( "a0,a1", String_.CrLf
|
||||
, "b0"
|
||||
);
|
||||
fx.tst_DatCsv
|
||||
( fx.ary_("a0", "a1")
|
||||
, fx.ary_("b0", null)
|
||||
);
|
||||
}
|
||||
@Test public void Misc_NewLineValidForSingleColumnTables() {
|
||||
fx.run_parse_
|
||||
( "a", String_.CrLf
|
||||
, String_.CrLf
|
||||
, "c" , String_.CrLf
|
||||
, String_.CrLf
|
||||
);
|
||||
fx.tst_DatCsv
|
||||
( fx.ary_("a")
|
||||
, fx.ary_null_()
|
||||
, fx.ary_("c")
|
||||
, fx.ary_null_()
|
||||
);
|
||||
}
|
||||
@Test public void Misc_NewLineValidForSingleColumnTables_FirstLine() {
|
||||
fx.run_parse_
|
||||
( String_.CrLf
|
||||
, "b", String_.CrLf
|
||||
, "c"
|
||||
);
|
||||
fx.tst_DatCsv
|
||||
( fx.ary_null_()
|
||||
, fx.ary_("b")
|
||||
, fx.ary_("c")
|
||||
);
|
||||
}
|
||||
@Test public void Hdr_Basic() {
|
||||
fx.Parser_(DsvParser.csv_(true, GfoFldList_.Null));
|
||||
fx.run_parse_
|
||||
( "id,name", String_.CrLf
|
||||
, "0,me"
|
||||
);
|
||||
fx.tst_FldListCsv("id", "name");
|
||||
fx.tst_DatCsv(fx.ary_("0", "me"));
|
||||
}
|
||||
// @Test public void Hdr_Manual() {
|
||||
// fx.Parser_(DsvParser.csv_(false, GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), true));
|
||||
// fx.run_parse_("0,me");
|
||||
// fx.tst_DatCsv(fx.ary_(0, "me")); // NOTE: testing auto-parsing of id to int b/c id fld is IntClassXtn.Instance;
|
||||
// }
|
||||
}
|
||||
class DsvDataRdr_fxt {
|
||||
public Object[] ary_(Object... ary) {return ary;}
|
||||
public Object[] ary_null_() {return new Object[] {null};}
|
||||
public void Clear() {parser.Init(); root = null;}
|
||||
public DsvParser Parser() {return parser;} public DsvDataRdr_fxt Parser_(DsvParser val) {parser = val; return this;} DsvParser parser = DsvParser.dsv_();
|
||||
public GfoNde Root() {return root;} GfoNde root;
|
||||
public void run_parse_(String... ary) {root = parser.ParseAsNde(String_.Concat(ary));}
|
||||
public void run_parse_lines_(String... ary) {root = parser.ParseAsNde(String_.Concat_lines_crlf(ary));}
|
||||
public DsvDataRdr_fxt tst_FldListCsv(String... names) {return tst_Flds(TblIdx0, GfoFldList_.str_(names));}
|
||||
public DsvDataRdr_fxt tst_Flds(int tblIdx, GfoFldList expdFlds) {
|
||||
GfoNde tbl = root.Subs().FetchAt_asGfoNde(tblIdx);
|
||||
List_adp expdList = List_adp_.New(), actlList = List_adp_.New();
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
GfoFldList_BldDbgList(expdFlds, expdList, sb);
|
||||
GfoFldList_BldDbgList(tbl.SubFlds(), actlList, sb);
|
||||
Tfds.Eq_list(expdList, actlList);
|
||||
return this;
|
||||
}
|
||||
void GfoFldList_BldDbgList(GfoFldList flds, List_adp list, String_bldr sb) {
|
||||
for (int i = 0; i < flds.Count(); i++) {
|
||||
GfoFld fld = flds.Get_at(i);
|
||||
sb.Add(fld.Key()).Add(",").Add(fld.Type().Key());
|
||||
list.Add(sb.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
public DsvDataRdr_fxt tst_Tbls(String... expdNames) {
|
||||
List_adp actlList = List_adp_.New();
|
||||
for (int i = 0; i < root.Subs().Count(); i++) {
|
||||
GfoNde tbl = root.Subs().FetchAt_asGfoNde(i);
|
||||
actlList.Add(tbl.Name());
|
||||
}
|
||||
Tfds.Eq_ary(expdNames, actlList.To_str_ary());
|
||||
return this;
|
||||
}
|
||||
public DsvDataRdr_fxt tst_DatNull() {
|
||||
Tfds.Eq(0, root.Subs().Count());
|
||||
return this;
|
||||
}
|
||||
public DsvDataRdr_fxt tst_DatCsv(Object[]... expdRows) {return tst_Dat(0, expdRows);}
|
||||
public DsvDataRdr_fxt tst_Dat(int tblIdx, Object[]... expdRows) {
|
||||
GfoNde tbl = root.Subs().FetchAt_asGfoNde(tblIdx);
|
||||
if (expdRows.length == 0) {
|
||||
Tfds.Eq(0, tbl.Subs().Count());
|
||||
return this;
|
||||
}
|
||||
List_adp expdList = List_adp_.New(), actlList = List_adp_.New();
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < tbl.Subs().Count(); i++) {
|
||||
GfoNde row = tbl.Subs().FetchAt_asGfoNde(i);
|
||||
for (int j = 0; j < row.Flds().Count(); j++) {
|
||||
if (j != 0) sb.Add("~");
|
||||
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(row.ReadAt(j)));
|
||||
}
|
||||
expdList.Add(sb.To_str_and_clear());
|
||||
}
|
||||
for (Object[] expdRow : expdRows) {
|
||||
if (expdRow == null) {
|
||||
actlList.Add("");
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < expdRow.length; j++) {
|
||||
if (j != 0) sb.Add("~");
|
||||
sb.Add_obj(Object_.Xto_str_strict_or_null_mark(expdRow[j]));
|
||||
}
|
||||
actlList.Add(sb.To_str_and_clear());
|
||||
}
|
||||
Tfds.Eq_list(expdList, actlList);
|
||||
return this;
|
||||
}
|
||||
public static DsvDataRdr_fxt new_() {return new DsvDataRdr_fxt();}
|
||||
static final int TblIdx0 = 0;
|
||||
}
|
||||
68
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java
Normal file
68
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class DsvDataRdr_dsv_dat_tst {
|
||||
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void NameOnly() {
|
||||
fx.run_parse_("tableName, ,\" \",#");
|
||||
fx.tst_Tbls("tableName");
|
||||
fx.tst_Dat(0);
|
||||
}
|
||||
@Test public void Rows_N() {
|
||||
fx.run_parse_lines_
|
||||
( "numbers, ,\" \",#"
|
||||
, "1,2,3"
|
||||
, "4,5,6"
|
||||
);
|
||||
fx.tst_Tbls("numbers");
|
||||
fx.tst_Dat(0
|
||||
, fx.ary_("1", "2", "3")
|
||||
, fx.ary_("4", "5", "6")
|
||||
);
|
||||
}
|
||||
@Test public void Tbls_N() {
|
||||
fx.run_parse_lines_
|
||||
( "letters, ,\" \",#"
|
||||
, "a,b,c"
|
||||
, "numbers, ,\" \",#"
|
||||
, "1,2,3"
|
||||
, "4,5,6"
|
||||
);
|
||||
fx.tst_Tbls("letters", "numbers");
|
||||
fx.tst_Dat(0, fx.ary_("a", "b", "c"));
|
||||
fx.tst_Dat(1, fx.ary_("1", "2", "3"), fx.ary_("4", "5", "6"));
|
||||
}
|
||||
@Test public void IgnoreTrailingBlankRow() {
|
||||
fx.run_parse_lines_
|
||||
( "letters, ,\" \",#"
|
||||
, "a,b,c"
|
||||
, "" // ignored
|
||||
);
|
||||
fx.tst_Tbls("letters");
|
||||
fx.tst_Dat(0, fx.ary_("a", "b", "c"));
|
||||
}
|
||||
@Test public void AllowCommentsDuringData() {
|
||||
fx.run_parse_lines_
|
||||
( "letters, ,\" \",#"
|
||||
, "a,b,c"
|
||||
, "// letters omitted, ,\" \",//" // these comments are not preserved
|
||||
, "x,y,z"
|
||||
);
|
||||
fx.tst_Tbls("letters");
|
||||
fx.tst_Dat(0, fx.ary_("a", "b", "c"), fx.ary_("x", "y", "z"));
|
||||
}
|
||||
}
|
||||
80
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java
Normal file
80
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class DsvDataRdr_dsv_hdr_tst {
|
||||
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void Names() {
|
||||
fx.run_parse_lines_
|
||||
( "id,name, ,\" \",@"
|
||||
, "0,me"
|
||||
, "1,you"
|
||||
);
|
||||
fx.tst_Flds(0, GfoFldList_.str_("id", "name"));
|
||||
fx.tst_Tbls(DsvTblBldr.NullTblName);
|
||||
fx.tst_Dat(0
|
||||
, fx.ary_("0", "me")
|
||||
, fx.ary_("1", "you")
|
||||
);
|
||||
}
|
||||
@Test public void Types() {
|
||||
fx.run_parse_lines_
|
||||
( "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "0,me"
|
||||
, "1,you"
|
||||
);
|
||||
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", IntClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
|
||||
fx.tst_Dat(0
|
||||
, fx.ary_(0, "me")
|
||||
, fx.ary_(1, "you")
|
||||
);
|
||||
}
|
||||
@Test public void NamesAndTypes() {
|
||||
fx.run_parse_lines_
|
||||
( "id,name, ,\" \",@"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "0,me"
|
||||
, "1,you"
|
||||
);
|
||||
fx.tst_Flds(0, GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance));
|
||||
fx.tst_Dat(0
|
||||
, fx.ary_(0, "me")
|
||||
, fx.ary_(1, "you")
|
||||
);
|
||||
}
|
||||
@Test public void MultipleTables_NoData() {
|
||||
fx.run_parse_lines_
|
||||
( "persons, ,\" \",#"
|
||||
, "id,name, ,\" \",@"
|
||||
, "things, ,\" \",#"
|
||||
, "id,data, ,\" \",@"
|
||||
);
|
||||
fx.tst_Tbls("persons", "things");
|
||||
fx.tst_Flds(0, GfoFldList_.str_("id", "name"));
|
||||
fx.tst_Flds(1, GfoFldList_.str_("id", "data"));
|
||||
fx.tst_Dat(0);
|
||||
fx.tst_Dat(1);
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fx.run_parse_lines_
|
||||
( "--------------------, ,\" \",//"
|
||||
, "tbl0, ,\" \",#"
|
||||
, "a0,a1"
|
||||
);
|
||||
fx.tst_Tbls("tbl0");
|
||||
fx.tst_Dat(0, fx.ary_("a0", "a1"));
|
||||
}
|
||||
}
|
||||
74
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java
Normal file
74
100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java
Normal 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.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class DsvDataRdr_dsv_misc_tst {
|
||||
@Before public void setup() {fx.Clear();} DsvDataRdr_fxt fx = DsvDataRdr_fxt.new_();
|
||||
@Test public void CmdDlm_NearMatches() {
|
||||
fx.run_parse_("a, ,b");
|
||||
fx.tst_DatCsv(fx.ary_("a", " ", "b"));
|
||||
fx.Clear();
|
||||
|
||||
fx.run_parse_("a,\" \",b");
|
||||
fx.tst_DatCsv(fx.ary_("a", " ", "b"));
|
||||
fx.Clear();
|
||||
|
||||
fx.run_parse_("a, ,b,\" \",c");
|
||||
fx.tst_DatCsv(fx.ary_("a", " ", "b", " ", "c"));
|
||||
fx.Clear();
|
||||
}
|
||||
@Test public void CmdDlm_DoNotSpanLines() {
|
||||
fx.run_parse_lines_
|
||||
( "a, "
|
||||
, "\" \",b"
|
||||
);
|
||||
fx.tst_DatCsv
|
||||
( fx.ary_("a", " ")
|
||||
, fx.ary_(" ", "b")
|
||||
);
|
||||
}
|
||||
@Test public void CmdDlm_SecondFldMustBeQuoted() {
|
||||
fx.run_parse_lines_("a, , ,b"); // will fail with "invalid command: b", if second , , is interpreted as command delimiter
|
||||
fx.tst_DatCsv(fx.ary_("a", " ", " ", "b"));
|
||||
}
|
||||
@Test public void Null_Int() {
|
||||
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
|
||||
( "int," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
|
||||
, ",val1"
|
||||
);
|
||||
fx.tst_Tbls(DsvTblBldr.NullTblName);
|
||||
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", IntClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
|
||||
fx.tst_Dat(0, fx.ary_(null, "val1"));
|
||||
}
|
||||
@Test public void Null_String() {
|
||||
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
|
||||
( StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
|
||||
, ",val1"
|
||||
);
|
||||
fx.tst_Tbls(DsvTblBldr.NullTblName);
|
||||
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", StringClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
|
||||
fx.tst_Dat(0, fx.ary_(null, "val1"));
|
||||
}
|
||||
@Test public void EmptyString() {
|
||||
fx.run_parse_ // not using run_parse_lines_ b/c (a) will have extra lineBreak; (b) test will look funny;
|
||||
( StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$", String_.CrLf
|
||||
, "\"\",val1"
|
||||
);
|
||||
fx.tst_Tbls(DsvTblBldr.NullTblName);
|
||||
fx.tst_Flds(0, GfoFldList_.new_().Add("fld0", StringClassXtn.Instance).Add("fld1", StringClassXtn.Instance));
|
||||
fx.tst_Dat(0, fx.ary_("", "val1"));
|
||||
}
|
||||
}
|
||||
129
100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java
Normal file
129
100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class DsvDataRdr_layout_tst {
|
||||
@Test public void TableName() {
|
||||
run_parse_lines("table0, ,\" \",#");
|
||||
tst_Layout(0, DsvHeaderItm.Id_TableName);
|
||||
}
|
||||
@Test public void Comment() {
|
||||
run_parse_lines("-------------, ,\" \",//", "data"); // need dataLine or parser will throw away standalone header
|
||||
tst_Layout(0, DsvHeaderItm.Id_Comment);
|
||||
}
|
||||
@Test public void BlankLine() {
|
||||
run_parse_lines("", "data"); // need dataLine or parser will throw away standalone header
|
||||
tst_Layout(0, DsvHeaderItm.Id_BlankLine);
|
||||
}
|
||||
@Test public void LeafNames() {
|
||||
run_parse_lines("id,name, ,\" \",@");
|
||||
tst_Layout(0, DsvHeaderItm.Id_LeafNames);
|
||||
}
|
||||
@Test public void LeafTypes() {
|
||||
run_parse_lines("int," + StringClassXtn.Key_const + ", ,\" \",$");
|
||||
tst_Layout(0, DsvHeaderItm.Id_LeafTypes);
|
||||
}
|
||||
@Test public void Combined() {
|
||||
run_parse_lines
|
||||
( ""
|
||||
, "-------------, ,\" \",//"
|
||||
, "table0, ,\" \",#"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,name, ,\" \",@"
|
||||
, "-------------, ,\" \",//"
|
||||
, "0,me"
|
||||
);
|
||||
tst_Layout(0
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_TableName
|
||||
, DsvHeaderItm.Id_LeafTypes
|
||||
, DsvHeaderItm.Id_LeafNames
|
||||
, DsvHeaderItm.Id_Comment
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_N() {
|
||||
run_parse_lines
|
||||
( ""
|
||||
, "*************, ,\" \",//"
|
||||
, "table0, ,\" \",#"
|
||||
, "-------------, ,\" \",//"
|
||||
, "0,me"
|
||||
, ""
|
||||
, "*************, ,\" \",//"
|
||||
, "table1, ,\" \",#"
|
||||
, " extended data, ,\" \",//"
|
||||
, "-------------, ,\" \",//"
|
||||
, "1,you,more"
|
||||
);
|
||||
tst_Layout(0
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_TableName
|
||||
, DsvHeaderItm.Id_Comment
|
||||
);
|
||||
tst_Layout(1
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_TableName
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_Comment
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_N_FirstIsEmpty() {
|
||||
run_parse_lines
|
||||
( ""
|
||||
, "*************, ,\" \",//"
|
||||
, "table0, ,\" \",#"
|
||||
, "-------------, ,\" \",//"
|
||||
, ""
|
||||
, ""
|
||||
, "*************, ,\" \",//"
|
||||
, "table1, ,\" \",#"
|
||||
, " extended data, ,\" \",//"
|
||||
, "-------------, ,\" \",//"
|
||||
, "1,you,more"
|
||||
);
|
||||
tst_Layout(0
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_TableName
|
||||
, DsvHeaderItm.Id_Comment
|
||||
);
|
||||
tst_Layout(1
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_BlankLine
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_TableName
|
||||
, DsvHeaderItm.Id_Comment
|
||||
, DsvHeaderItm.Id_Comment
|
||||
);
|
||||
}
|
||||
void run_parse_lines(String... ary) {
|
||||
String raw = String_.Concat_lines_crlf(ary);
|
||||
DsvParser parser = DsvParser.dsv_();
|
||||
root = parser.ParseAsNde(raw);
|
||||
}
|
||||
void tst_Layout(int subIdx, int... expd) {
|
||||
GfoNde tbl = root.Subs().FetchAt_asGfoNde(subIdx);
|
||||
DsvStoreLayout layout = (DsvStoreLayout)tbl.EnvVars().Get_by(DsvStoreLayout.Key_const);
|
||||
int[] actl = new int[layout.HeaderList().Count()];
|
||||
for (int i = 0; i < actl.length; i++)
|
||||
actl[i] = layout.HeaderList().Get_at(i).Id();
|
||||
Tfds.Eq_ary(expd, actl);
|
||||
}
|
||||
GfoNde root;
|
||||
}
|
||||
98
100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java
Normal file
98
100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java
Normal 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.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class DsvDataWtr_csv_tst {
|
||||
@Test public void Dat_Val_0() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root);
|
||||
expd = String_.Concat_lines_crlf("");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Val_1() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a");
|
||||
expd = String_.Concat_lines_crlf("a");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Val_N() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "b", "c");
|
||||
expd = String_.Concat_lines_crlf("a,b,c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Row_N() {
|
||||
root = fx_nde.csv_dat_();
|
||||
this.AddCsvRow(root, "a", "b", "c");
|
||||
this.AddCsvRow(root, "d", "e", "f");
|
||||
expd = String_.Concat_lines_crlf
|
||||
( "a,b,c"
|
||||
, "d,e,f"
|
||||
);
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Escape_FldSpr() { // ,
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", ",", "c");
|
||||
expd = String_.Concat_lines_crlf("a,\",\",c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Escape_RcdSpr() { // NewLine
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", String_.CrLf, "c");
|
||||
expd = String_.Concat_lines_crlf("a,\"" + String_.CrLf + "\",c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Escape_Quote() { // " -> ""
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "\"", "c");
|
||||
expd = String_.Concat_lines_crlf("a,\"\"\"\",c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Whitespace() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", " b\t", "c");
|
||||
expd = String_.Concat_lines_crlf("a, b\t,c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_Null() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", null, "c");
|
||||
expd = String_.Concat_lines_crlf("a,,c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Dat_EmptyString() {
|
||||
root = fx_nde.csv_dat_(); this.AddCsvRow(root, "a", "", "c");
|
||||
expd = String_.Concat_lines_crlf("a,\"\",c");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Hdr_Flds() {
|
||||
wtr = DsvDataWtr_.csv_hdr_();
|
||||
GfoFldList flds = GfoFldList_.new_().Add("id", StringClassXtn.Instance).Add("name", StringClassXtn.Instance);
|
||||
root = fx_nde.csv_hdr_(flds); this.AddCsvRow(root, "0", "me");
|
||||
expd = String_.Concat_lines_crlf
|
||||
( "id,name"
|
||||
, "0,me"
|
||||
);
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
void AddCsvRow(GfoNde root, String... ary) {
|
||||
GfoNde sub = GfoNde_.vals_(root.SubFlds(), ary);
|
||||
root.Subs().Add(sub);
|
||||
}
|
||||
GfoNde root; String expd; DsvDataWtr wtr = DsvDataWtr_.csv_dat_(); DsvDataWtr_fxt fx = DsvDataWtr_fxt.new_(); GfoNdeFxt fx_nde = GfoNdeFxt.new_();
|
||||
}
|
||||
class DsvDataWtr_fxt {
|
||||
public void tst_XtoStr(DsvDataWtr wtr, GfoNde root, String expd) {
|
||||
wtr.Clear();
|
||||
root.XtoStr_wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
public static DsvDataWtr_fxt new_() {return new DsvDataWtr_fxt();} DsvDataWtr_fxt() {}
|
||||
}
|
||||
71
100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java
Normal file
71
100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java
Normal 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.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*;
|
||||
public class DsvDataWtr_tbls_tst {
|
||||
@Before public void setup() {
|
||||
DsvStoreLayout layout = DsvStoreLayout.dsv_brief_();
|
||||
layout.HeaderList().Add_TableName();
|
||||
wtr.InitWtr(DsvStoreLayout.Key_const, layout);
|
||||
}
|
||||
@Test public void Rows_0() {
|
||||
root = fx_nde.tbl_("tbl0");
|
||||
expd = String_.Concat_lines_crlf( "tbl0, ,\" \",#");
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Rows_N() {
|
||||
root = fx_nde.tbl_
|
||||
( "numbers"
|
||||
, fx_nde.row_vals_(1, 2, 3)
|
||||
, fx_nde.row_vals_(4, 5, 6)
|
||||
);
|
||||
expd = String_.Concat_lines_crlf
|
||||
( "numbers, ,\" \",#"
|
||||
, "1,2,3"
|
||||
, "4,5,6"
|
||||
);
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Tbls_N_Empty() {
|
||||
root = fx_nde.root_
|
||||
( fx_nde.tbl_("tbl0")
|
||||
, fx_nde.tbl_("tbl1")
|
||||
);
|
||||
expd = String_.Concat_lines_crlf
|
||||
( "tbl0, ,\" \",#"
|
||||
, "tbl1, ,\" \",#"
|
||||
);
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
@Test public void Tbls_N() {
|
||||
root = fx_nde.root_
|
||||
( fx_nde.tbl_("letters"
|
||||
, fx_nde.row_vals_("a", "b", "c"))
|
||||
, fx_nde.tbl_("numbers"
|
||||
, fx_nde.row_vals_(1, 2, 3)
|
||||
, fx_nde.row_vals_(4, 5, 6)
|
||||
));
|
||||
expd = String_.Concat_lines_crlf
|
||||
( "letters, ,\" \",#"
|
||||
, "a,b,c"
|
||||
, "numbers, ,\" \",#"
|
||||
, "1,2,3"
|
||||
, "4,5,6"
|
||||
);
|
||||
fx.tst_XtoStr(wtr, root, expd);
|
||||
}
|
||||
GfoNde root; String expd; DsvDataWtr wtr = DsvDataWtr_.csv_dat_(); DsvDataWtr_fxt fx = DsvDataWtr_fxt.new_(); GfoNdeFxt fx_nde = GfoNdeFxt.new_();
|
||||
}
|
||||
40
100_core/src/gplx/langs/gfs/Gfs_Date_tst.java
Normal file
40
100_core/src/gplx/langs/gfs/Gfs_Date_tst.java
Normal 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.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_Date_tst {
|
||||
@Before public void setup() {
|
||||
fx = new GfsCoreFxt();
|
||||
fx.AddObj(DateAdp_.Gfs, "Date_");
|
||||
Datetime_now.Manual_y_();
|
||||
} GfsCoreFxt fx;
|
||||
@Test public void Now() {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now")), DateAdp_.parse_gplx("2001-01-01 00:00:00.000"));
|
||||
}
|
||||
@Test public void Add_day() {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now", "Add_day"), Keyval_.new_("days", 1)), DateAdp_.parse_gplx("2001-01-02 00:00:00.000"));
|
||||
}
|
||||
}
|
||||
class GfsCoreFxt {
|
||||
public GfsCore Core() {return core;} GfsCore core = GfsCore.new_();
|
||||
public GfoMsg msg_(String[] ary, Keyval... kvAry) {return GfoMsg_.root_leafArgs_(ary, kvAry);}
|
||||
public void AddObj(Gfo_invk invk, String s) {core.AddObj(invk, s);}
|
||||
public void tst_MsgStr(GfoMsg msg, Object expd) {
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
Object actl = core.ExecOne(ctx, msg);
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_null_mark(expd), Object_.Xto_str_strict_or_null_mark(actl));
|
||||
}
|
||||
}
|
||||
91
100_core/src/gplx/langs/regxs/Regx_adp__tst.java
Normal file
91
100_core/src/gplx/langs/regxs/Regx_adp__tst.java
Normal 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.tests.*;
|
||||
public class Regx_adp__tst implements TfdsEqListItmStr {
|
||||
@Test public void Match() {
|
||||
tst_Match("a", "a", true); // basic
|
||||
tst_Match("a", "b", false); // matchNot
|
||||
tst_Match("a", "ab", true); // matchPart
|
||||
tst_Match("a\\+b", "a+b", true); // matchEscape
|
||||
tst_Match("[^a]", "b", true); // charSet_negate
|
||||
} void tst_Match(String find, String input, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(input, find));}
|
||||
@Test public void Match_all() {
|
||||
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 1); // handle match = true but len = 0; DATE:2013-04-11
|
||||
tst_Match_all("a", "$", 1); // $ should match once, not zero; DATE:2014-09-02
|
||||
} void tst_Match_all(String input, String regx, int expd) {Tfds.Eq(expd, Regx_adp_.new_(regx).Match_all(input, 0).length);}
|
||||
@Test public void Replace() {
|
||||
tst_Replace("ab", "a", "b", "bb"); // basic
|
||||
tst_Replace("ab", "c", "b", "ab"); // replaceNot
|
||||
tst_Replace("aba", "a", "b", "bbb"); // replaceMultiple
|
||||
} void tst_Replace(String input, String find, String replace, String expd) {Tfds.Eq(expd, Regx_adp_.Replace(input, find, replace));}
|
||||
@Test public void Match_WholeWord() {
|
||||
tst_WholeWord("a", "ab a", true); // pass a
|
||||
tst_WholeWord("a", "ab c", false); // fail ab
|
||||
tst_WholeWord("a", "a_", false); // fail a_
|
||||
tst_WholeWord("[a]", "a [a] c", true); // pass [a]
|
||||
tst_WholeWord("[a]", "a[a]c", false); // fail a[a]c
|
||||
} void tst_WholeWord(String regx, String text, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(text, Regx_bldr.WholeWord(regx)));}
|
||||
@Test public void Match_As() {
|
||||
tst_Regx("public static [A-Za-z0-9_]+ as_\\(Object obj\\)", "public static Obj1 as_(Object obj) {return obj instanceof Obj1 ? (Obj1)obj : null;}", true);
|
||||
tst_Regx("public static [A-Za-z0-9_]+ as_\\(Object obj\\)", "public static boolean Asterisk(Object obj) {}", false);
|
||||
} void tst_Regx(String regx, String text, boolean expd) {Tfds.Eq(expd, Regx_adp_.Match(text, regx));}
|
||||
@Test public void Find() {
|
||||
tst_Matches("b", "a b c b a", match_(2, 1), match_(6, 1));
|
||||
tst_Matches("d", "a b c b a");
|
||||
tst_Matches("b", "a b c b a b b", matches_(2, 6, 10, 12)); // BUGFIX: multiple entries did not work b/c of += instead of +
|
||||
}
|
||||
@Test public void Groups() {
|
||||
tst_Groups("abc def ghi dz", "(d\\p{L}+)", "def", "dz");
|
||||
}
|
||||
Regx_match[] matches_(int... bgnAry) {
|
||||
int aryLen = Array_.Len(bgnAry);
|
||||
Regx_match[] rv = new Regx_match[aryLen];
|
||||
for (int i = 0; i < aryLen; i++)
|
||||
rv[i] = match_(bgnAry[i]);
|
||||
return rv;
|
||||
}
|
||||
Regx_match match_(int bgn) {return match_(bgn, Int_.Min_value);}
|
||||
Regx_match match_(int bgn, int len) {return new Regx_match(true, bgn, bgn + len, Regx_group.Ary_empty);}
|
||||
void tst_Matches(String find, String input, Regx_match... expd) {
|
||||
List_adp expdList = Array_.To_list(expd);
|
||||
List_adp actlList = Regx_adp_.Find_all(input, find);
|
||||
Tfds.Eq_list(expdList, actlList, this);
|
||||
}
|
||||
void tst_Groups(String text, String regx, String... expd) {
|
||||
Regx_adp regx_mgr = Regx_adp_.new_(regx);
|
||||
Regx_match[] rslts = regx_mgr.Match_all(text, 0);
|
||||
Tfds.Eq_ary_str(expd, To_ary(rslts));
|
||||
}
|
||||
String[] To_ary(Regx_match[] ary) {
|
||||
List_adp rv = List_adp_.New();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Regx_match itm = ary[i];
|
||||
int cap_len = itm.Groups().length;
|
||||
for (int j = 0; j < cap_len; j++) {
|
||||
rv.Add(itm.Groups()[j].Val());
|
||||
}
|
||||
}
|
||||
return rv.To_str_ary();
|
||||
}
|
||||
public String To_str(Object curObj, Object expdObj) {
|
||||
Regx_match cur = (Regx_match)curObj, expd = (Regx_match)expdObj;
|
||||
String rv = "bgn=" + cur.Find_bgn();
|
||||
if (expd != null && expd.Find_len() != Int_.Min_value) rv += " len=" + cur.Find_len();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
45
100_core/src/gplx/langs/xmls/HierStrBldr_tst.java
Normal file
45
100_core/src/gplx/langs/xmls/HierStrBldr_tst.java
Normal 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.langs.xmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; import gplx.core.texts.*;
|
||||
public class HierStrBldr_tst {
|
||||
@Before public void setup() {bldr = new HierStrBldr();} HierStrBldr bldr;
|
||||
@Test public void Hier0() {
|
||||
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000");
|
||||
tst_MakeName( 0, "/root/idx_000.csv");
|
||||
tst_MakeName( 1, "/root/idx_001.csv");
|
||||
tst_MakeName(10, "/root/idx_010.csv");
|
||||
}
|
||||
@Test public void Hier1() {
|
||||
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000", 10);
|
||||
tst_MakeName( 0, "/root/dir_000/idx_000.csv");
|
||||
tst_MakeName( 1, "/root/dir_000/idx_001.csv");
|
||||
tst_MakeName(10, "/root/dir_010/idx_010.csv");
|
||||
}
|
||||
@Test public void Hier2() {
|
||||
bldr.Ctor("/root/", "dir_{0}/", "idx_{0}.csv", "000", 5, 10);
|
||||
tst_MakeName( 0, "/root/dir_000/dir_000/idx_000.csv");
|
||||
tst_MakeName( 1, "/root/dir_000/dir_000/idx_001.csv");
|
||||
tst_MakeName( 10, "/root/dir_000/dir_010/idx_010.csv");
|
||||
tst_MakeName( 49, "/root/dir_000/dir_040/idx_049.csv");
|
||||
tst_MakeName( 50, "/root/dir_050/dir_050/idx_050.csv");
|
||||
tst_MakeName( 99, "/root/dir_050/dir_090/idx_099.csv");
|
||||
tst_MakeName(100, "/root/dir_100/dir_100/idx_100.csv");
|
||||
tst_MakeName(110, "/root/dir_100/dir_110/idx_110.csv");
|
||||
}
|
||||
void tst_MakeName(int val, String expd) {Tfds.Eq(expd, bldr.GenStrIdxOnly(val));}
|
||||
}
|
||||
69
100_core/src/gplx/langs/xmls/XmlDoc_tst.java
Normal file
69
100_core/src/gplx/langs/xmls/XmlDoc_tst.java
Normal 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.xmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class XmlDoc_tst {
|
||||
String xml; XmlDoc xdoc; XmlNde xnde;
|
||||
@Test public void parse() {
|
||||
xml = String_.Concat("<root/>");
|
||||
xdoc = XmlDoc_.parse(xml);
|
||||
Tfds.Eq("root", xdoc.Root().Name());
|
||||
Tfds.Eq(true, xdoc.Root().NdeType_element());
|
||||
}
|
||||
@Test public void Xml_outer() {
|
||||
xml = String_.Concat
|
||||
( "<root>"
|
||||
, "<a>"
|
||||
, "<b/>"
|
||||
, "<b/>"
|
||||
, "</a>"
|
||||
, "</root>"
|
||||
);
|
||||
xdoc = XmlDoc_.parse(xml);
|
||||
xnde = xdoc.Root().SubNdes().Get_at(0);
|
||||
Tfds.Eq("a", xnde.Name());
|
||||
Tfds.Eq("<a><b/><b/></a>", xnde.Xml_outer());
|
||||
}
|
||||
@Test public void Text_inner() {
|
||||
xml = String_.Concat
|
||||
( "<root>"
|
||||
, "<a>"
|
||||
, "test me"
|
||||
, "</a>"
|
||||
, "</root>"
|
||||
);
|
||||
xdoc = XmlDoc_.parse(xml);
|
||||
xnde = xdoc.Root().SubNdes().Get_at(0);
|
||||
Tfds.Eq("a", xnde.Name());
|
||||
Tfds.Eq("test me", xnde.Text_inner());
|
||||
}
|
||||
@Test public void Atrs() {
|
||||
xml = String_.Concat
|
||||
( "<root atr0=\"0\" atr1=\"1\">"
|
||||
, "</root>"
|
||||
);
|
||||
xdoc = XmlDoc_.parse(xml);
|
||||
XmlAtrList atrs = xdoc.Root().Atrs();
|
||||
XmlAtr atr = atrs.Get_at(1);
|
||||
tst_Atr(atr, "atr1", "1");
|
||||
atr = atrs.Get_at(1);
|
||||
tst_Atr(atr, "atr1", "1");
|
||||
}
|
||||
void tst_Atr(XmlAtr atr, String expdName, String expdVal) {
|
||||
Tfds.Eq(expdName, atr.Name());
|
||||
Tfds.Eq(expdVal, atr.Value());
|
||||
}
|
||||
}
|
||||
86
100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java
Normal file
86
100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java
Normal 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.xmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; import gplx.core.texts.*;
|
||||
public class XmlFileSplitter_tst {
|
||||
@Before public void setup() {
|
||||
splitter = new XmlFileSplitter();
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
} XmlFileSplitter splitter;
|
||||
@Test public void FindMatchPos() {
|
||||
tst_FindMatchPos("abcde", "a", 0);
|
||||
tst_FindMatchPos("abcde", "b", 1);
|
||||
tst_FindMatchPos("abcde", "cd", 2);
|
||||
tst_FindMatchPos("abcde", "f", -1);
|
||||
tst_FindMatchPos("abcde", "fg", -1);
|
||||
} void tst_FindMatchPos(String src, String find, int expd) {Tfds.Eq(expd, splitter.FindMatchPos(byte_(src), byteAry_(find)));}
|
||||
@Test public void FindMatchPosRev() {
|
||||
tst_FindMatchPosRev("abcde", "a", 0);
|
||||
tst_FindMatchPosRev("abcde", "b", 1);
|
||||
tst_FindMatchPosRev("abcde", "cd", 2);
|
||||
tst_FindMatchPosRev("abcde", "f", -1);
|
||||
tst_FindMatchPosRev("abcde", "ef", -1);
|
||||
tst_FindMatchPosRev("abcde", "za", -1);
|
||||
tst_FindMatchPosRev("dbcde", "d", 3);
|
||||
} void tst_FindMatchPosRev(String src, String find, int expd) {Tfds.Eq(expd, splitter.FindMatchPosRev(byte_(src), byteAry_(find)));}
|
||||
@Test public void ExtractHdr() {
|
||||
tst_ExtractHdr("<a><b>", "<b", "<a>", "<b>");
|
||||
}
|
||||
@Test public void Split() {
|
||||
splitter.Opts().FileSizeMax_(30).XmlNames_("<a").XmlEnd_("</root>");
|
||||
tst_Split
|
||||
( "<root><a id='1'/><a id='2'/><a id='3'/><a id='4'/><a id='5'/></root>"
|
||||
, "<root><a id='1'/><a id='2'/></root>"
|
||||
, "<root><a id='3'/><a id='4'/></root>"
|
||||
, "<root><a id='5'/></root>"
|
||||
);
|
||||
tst_Split
|
||||
( "<root><a id='1' name='long_text_that_will_force_next_read'/><a id='2'/></root>"
|
||||
, "<root><a id='1' name='long_text_that_will_force_next_read'/></root>"
|
||||
, "<root><a id='2'/></root>"
|
||||
);
|
||||
}
|
||||
void tst_Split(String txt, String... expd) {
|
||||
Io_url xmlFil = Io_url_.mem_fil_("mem/800_misc/txt.xml");
|
||||
Io_url tmpDir = xmlFil.OwnerDir().GenSubDir("temp_xml");
|
||||
Io_mgr.Instance.DeleteDirDeep(tmpDir);
|
||||
splitter.Opts().StatusFmt_(null).PartDir_(tmpDir);
|
||||
splitter.Opts().Namer().Ctor_io(tmpDir, "", "fil_{0}.xml", "000");
|
||||
Io_mgr.Instance.SaveFilStr(xmlFil, txt);
|
||||
splitter.Split(xmlFil);
|
||||
Io_url[] tmpFilAry = Io_mgr.Instance.QueryDir_fils(tmpDir);
|
||||
Tfds.Eq(expd.length, tmpFilAry.length);
|
||||
for (int i = 0; i < tmpFilAry.length; i++) {
|
||||
Io_url tmpFil = tmpFilAry[i];
|
||||
Tfds.Eq(expd[i], Io_mgr.Instance.LoadFilStr(tmpFil));
|
||||
}
|
||||
}
|
||||
byte[] byte_(String s) {return Bry_.new_u8(s);}
|
||||
byte[][] byteAry_(String s) {
|
||||
byte[][] rv = new byte[1][];
|
||||
rv[0] = Bry_.new_u8(s);
|
||||
return rv;
|
||||
}
|
||||
void tst_ExtractHdr(String src, String find, String expdHdr, String expdSrc) {
|
||||
splitter.Clear();
|
||||
byte[] srcAry = byte_(src);
|
||||
int findPos = splitter.FindMatchPos(srcAry, byteAry_(find));
|
||||
srcAry = splitter.SplitHdr(srcAry, findPos);
|
||||
Tfds.Eq(String_.new_u8(splitter.Hdr()), expdHdr);
|
||||
Tfds.Eq(String_.new_u8(srcAry), expdSrc);
|
||||
}
|
||||
}
|
||||
42
100_core/src/gplx/langs/xmls/Xpath__tst.java
Normal file
42
100_core/src/gplx/langs/xmls/Xpath__tst.java
Normal 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.xmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xpath__tst {
|
||||
@Test public void Select_all() {
|
||||
String xml = String_.Concat
|
||||
( "<root>"
|
||||
, "<a>"
|
||||
, "</a>"
|
||||
, "<b>"
|
||||
, "<c/>"
|
||||
, "<c/>"
|
||||
, "<c/>"
|
||||
, "</b>"
|
||||
, "<a>"
|
||||
, "</a>"
|
||||
, "</root>"
|
||||
);
|
||||
tst_SelectAll(xml, "a", 2);
|
||||
tst_SelectAll(xml, "b", 1);
|
||||
tst_SelectAll(xml, "b/c", 3);
|
||||
}
|
||||
void tst_SelectAll(String raw, String xpath, int expdCount) {
|
||||
XmlDoc xdoc = XmlDoc_.parse(raw);
|
||||
XmlNdeList xndeList = Xpath_.SelectAll(xdoc.Root(), xpath);
|
||||
Tfds.Eq(expdCount, xndeList.Count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user