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:
62
400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java
Normal file
62
400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java
Normal 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.xowa.langs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.intls.*;
|
||||
public class Xob_i18n_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_i18n_parser_fxt fxt = new Xob_i18n_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_xto_gfs(String_.Concat_lines_nl_skip_last
|
||||
( "{"
|
||||
, " \"@metadata\": {"
|
||||
, " \"authors\": []"
|
||||
, " },"
|
||||
, "\"key_1\": \"val_1\","
|
||||
, "\"key_2\": \"val_2\","
|
||||
, "\"key_3\": \"val $1\","
|
||||
, "}"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "this.messages.load_text("
|
||||
, "<:['"
|
||||
, "key_1|val_1"
|
||||
, "key_2|val_2"
|
||||
, "key_3|val ~{0}"
|
||||
, "']:>"
|
||||
, ");"
|
||||
));
|
||||
}
|
||||
// @Test public void Load_msgs_validate() {
|
||||
// fxt.Test_load_msgs_dir("C:\\xowa\\bin\\any\\xowa\\xtns\\Insider\\i18n\\");
|
||||
// }
|
||||
}
|
||||
class Xob_i18n_parser_fxt {
|
||||
public void Clear() {
|
||||
}
|
||||
public void Test_xto_gfs(String raw, String expd) {
|
||||
byte[] actl = Xob_i18n_parser.Xto_gfs(Bry_.new_u8(raw));
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_load_msgs_dir(String dir_str) {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
Io_url dir_url = Io_url_.new_dir_(dir_str);
|
||||
Io_url[] fil_urls = Io_mgr.Instance.QueryDir_fils(dir_url);
|
||||
int len = fil_urls.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xob_i18n_parser.Load_msgs(false, wiki.Lang(), fil_urls[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
178
400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java
Normal file
178
400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
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.langs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xobc_utl_make_lang_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xobc_utl_make_lang_fxt fxt = new Xobc_utl_make_lang_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Parse_rows(String_.Concat_lines_nl
|
||||
( ""
|
||||
, "if|#if~#si~"
|
||||
, ""
|
||||
, "ifeq|#ifeq~#sieq"
|
||||
, ""
|
||||
, "expr|"
|
||||
)
|
||||
, fxt.row_("if", "#if", "#si")
|
||||
, fxt.row_("ifeq", "#ifeq", "#sieq")
|
||||
, fxt.row_("expr")
|
||||
);
|
||||
}
|
||||
@Test public void Trailing_colon() {
|
||||
fxt.Kwd_mgr().Parse_keep_trailing_colon(Bry_.new_a7("fr"), Bry_.new_u8(String_.Concat_lines_nl
|
||||
( "if|if:~si:~"
|
||||
, "ifeq|"
|
||||
)));
|
||||
fxt.Ini_file_mw_core("fr", String_.Concat_lines_nl
|
||||
( "$magicWords = array("
|
||||
, " 'expr' => array(0, 'expr:'),"
|
||||
, " 'if' => array(0, 'if:', 'si:', 'if_unchanged:'),"
|
||||
, " 'ifeq' => array(0, 'ifeq:', 'sieq:'),"
|
||||
, ");"
|
||||
)
|
||||
);
|
||||
fxt.Mgr().Bld_all();
|
||||
fxt.Tst_file_xo("fr", String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "expr|0|expr~"
|
||||
, "if|0|if:~si:~if_unchanged~"
|
||||
, "ifeq|0|ifeq:~sieq:~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Prepend_hash() {
|
||||
fxt.Kwd_mgr().Parse_prepend_hash(Bry_.new_a7("fr"), Bry_.new_u8(String_.Concat_lines_nl
|
||||
( "if|if:~si:~"
|
||||
, "ifeq|"
|
||||
, "tag|tag~"
|
||||
)));
|
||||
fxt.Ini_file_mw_core("fr", String_.Concat_lines_nl
|
||||
( "$magicWords = array("
|
||||
, " 'tag' => array( '0', 'etiqueta', 'ETIQUETA', 'tag' ),"
|
||||
, " 'expr' => array(0, 'expr:'),"
|
||||
, " 'if' => array(0, 'if:', 'si:', 'if_unchanged:'),"
|
||||
, " 'ifeq' => array(0, 'ifeq:', 'sieq:'),"
|
||||
, ");"
|
||||
)
|
||||
);
|
||||
fxt.Mgr().Bld_all();
|
||||
fxt.Tst_file_xo("fr", String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "tag|0|etiqueta~ETIQUETA~#tag~"
|
||||
, "expr|0|expr~"
|
||||
, "if|0|#if~#si~if_unchanged~"
|
||||
, "ifeq|0|#ifeq~#sieq~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Add_words_hash() {
|
||||
fxt.Kwd_mgr().Parse_add_words(Bry_.new_a7("fr"), Bry_.new_u8(String_.Concat_lines_nl
|
||||
( "if|if_new:~if~"
|
||||
, "ifeq|"
|
||||
)));
|
||||
fxt.Ini_file_mw_core("fr", String_.Concat_lines_nl
|
||||
( "$magicWords = array("
|
||||
, " 'if' => array(0, 'if:', 'si:'),"
|
||||
, " 'ifeq' => array(0, 'sieq:'),"
|
||||
, ");"
|
||||
)
|
||||
);
|
||||
fxt.Mgr().Bld_all();
|
||||
fxt.Tst_file_xo("fr", String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "if|0|if~si~if_new:~"
|
||||
, "ifeq|0|sieq~ifeq~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Manual_text() {
|
||||
fxt.Mgr().Parse_manual_text(Bry_.new_a7("fr"), Bry_.new_u8(String_.Concat_lines_nl
|
||||
( "app;"
|
||||
))
|
||||
, fxt.Mgr().Manual_text_end_hash());
|
||||
fxt.Ini_file_mw_core("fr", String_.Concat_lines_nl
|
||||
( "$magicWords = array("
|
||||
, " 'if' => array(0, 'if:', 'si:'),"
|
||||
, ");"
|
||||
)
|
||||
);
|
||||
fxt.Mgr().Bld_all();
|
||||
fxt.Tst_file_xo("fr", String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "if|0|if~si~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
, "app;"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xobc_utl_make_lang_fxt {
|
||||
public Xobc_utl_make_lang Mgr() {return mgr;} private Xobc_utl_make_lang mgr;
|
||||
public Xobc_utl_make_lang_kwds Kwd_mgr() {return mgr.Kwd_mgr();}
|
||||
public Xobc_utl_make_lang_fxt Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
mgr = new Xobc_utl_make_lang(app.Lang_mgr(), app.Fsys_mgr(), app.Msg_log());
|
||||
return this;
|
||||
} private String_bldr sb = String_bldr_.new_(); private Xoae_app app;
|
||||
public Xobcl_kwd_row row_(String key, String... itms) {return new Xobcl_kwd_row(Bry_.new_a7(key), Bry_.Ary(itms));}
|
||||
public void Parse_rows(String raw, Xobcl_kwd_row... expd) {Tfds.Eq_str_lines(Xto_str(expd), Xto_str(Xobc_utl_make_lang_kwds.Parse(Bry_.new_a7(raw))));}
|
||||
public void Ini_file_mw_core(String lang, String raw) {
|
||||
Io_url fil = app.Fsys_mgr().Cfg_lang_core_dir().OwnerDir().GenSubFil_nest("mediawiki", "core_php", "Messages" + String_.UpperFirst(lang) + ".php");
|
||||
Io_mgr.Instance.SaveFilStr(fil, raw);
|
||||
}
|
||||
public void Tst_file_xo(String lang, String expd) {
|
||||
Io_url fil = Xol_lang_itm_.xo_lang_fil_(app.Fsys_mgr(), lang);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(fil));
|
||||
}
|
||||
private String Xto_str(Xobcl_kwd_row[] expd) {
|
||||
int len = expd.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xobcl_kwd_row row = expd[i];
|
||||
sb.Add(row.Key());
|
||||
byte[][] itms = row.Itms();
|
||||
int itms_len = itms.length;
|
||||
if (itms_len > 0) {
|
||||
sb.Add_char_pipe();
|
||||
for (int j = 0; j < itms_len; j++) {
|
||||
byte[] itm = itms[j];
|
||||
sb.Add(itm).Add_char_pipe();
|
||||
}
|
||||
}
|
||||
sb.Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
315
400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java
Normal file
315
400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
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.langs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.intls.*; import gplx.core.log_msgs.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.specials.*;
|
||||
public class Xol_mw_lang_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_mw_lang_parser_fxt fxt = new Xol_mw_lang_parser_fxt();
|
||||
@Test public void Core_keywords() {
|
||||
fxt.Parse_core("$magicWords = array('toc' => array(0, 'a1', 'a2', 'a3'), 'notoc' => array(1, 'b1', 'b2', 'b3'));")
|
||||
.Tst_keyword(Xol_kwd_grp_.Id_toc, false, "a1", "a2", "a3")
|
||||
.Tst_keyword(Xol_kwd_grp_.Id_notoc, true, "b1", "b2", "b3")
|
||||
;
|
||||
}
|
||||
@Test public void Core_keywords_img_thumb() {
|
||||
fxt.Parse_core("$magicWords = array('img_thumbnail' => array(1, 'thumb', 'thmb'));")
|
||||
.Tst_keyword_img("thumb", Xop_lnki_arg_parser.Tid_thumb)
|
||||
.Tst_keyword_img("thmb" , Xop_lnki_arg_parser.Tid_thumb)
|
||||
.Tst_keyword_img("thum" , Xop_lnki_arg_parser.Tid_caption)
|
||||
;
|
||||
}
|
||||
@Test public void Core_keywords_img_upright() {
|
||||
fxt.Parse_core("$magicWords = array('img_upright' => array(1, 'upright', 'upright=$1', 'upright $1'));")
|
||||
.Tst_keyword_img("upright" , Xop_lnki_arg_parser.Tid_upright)
|
||||
.Tst_keyword_img("upright " , Xop_lnki_arg_parser.Tid_upright)
|
||||
;
|
||||
}
|
||||
@Test public void Core_keywords_func_currentmonth() {
|
||||
Datetime_now.Manual_y_();
|
||||
fxt.Parse_core("$magicWords = array('currentmonth' => array(0, 'MOISACTUEL'));")
|
||||
.Tst_parse("{{MOISACTUEL}}", "01")
|
||||
;
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
@Test public void Core_keywords_func_ns() {
|
||||
fxt.Parse_core("$magicWords = array('ns' => array(0, 'ESPACEN'));")
|
||||
.Tst_parse("{{ESPACEN:6}}", "File")
|
||||
;
|
||||
}
|
||||
@Test public void Keywords_img_dim() {
|
||||
fxt.Parse_core("$magicWords = array('img_width' => array(1, '$1pxl'));")
|
||||
.Tst_keyword_img("50pxl", Xop_lnki_arg_parser.Tid_dim)
|
||||
.Tst_keyword_img("50pxlpxl", Xop_lnki_arg_parser.Tid_dim)
|
||||
.Tst_keyword_img("50xl", Xop_lnki_arg_parser.Tid_caption)
|
||||
;
|
||||
}
|
||||
@Test public void Core_namespaces_names() {
|
||||
fxt.Parse_core("$namespaceNames = array(NS_FILE => 'Fichier');")
|
||||
.Sync_ns()
|
||||
.Tst_ns_lkp("Fichier", Xow_ns_.Tid__file)
|
||||
.Tst_ns_lkp("File" , Xow_ns_.Tid__null)
|
||||
;
|
||||
}
|
||||
@Test public void Core_namespaces_aliases() {
|
||||
fxt.Parse_core("$namespaceAliases = array('Discussion_Fichier' => NS_FILE_TALK);")
|
||||
.Sync_ns()
|
||||
.Tst_ns_lkp("Discussion Fichier", Xow_ns_.Tid__file_talk)
|
||||
.Tst_ns_lkp("Discussion Fichierx", Xow_ns_.Tid__null)
|
||||
;
|
||||
}
|
||||
@Test public void Core_specialPageAliases() {
|
||||
fxt.Parse_core("$specialPageAliases = array('Randompage' => array('PageAuHasard', 'Page_au_hasard'));")
|
||||
.Test_specialPageAliases("Randompage", "PageAuHasard", "Page_au_hasard")
|
||||
;
|
||||
}
|
||||
@Test public void Xtn_keywords_fr() {fxt.Parse_xtn("$magicWords['fr'] = array('if' => array(0, 'si' ));").Tst_parse("{{si:|y|n}}", "n");}
|
||||
@Test public void Xtn_keywords_de() {fxt.Parse_xtn("$magicWords['de'] = array('if' => array(0, 'si' ));").Tst_parse("{{si:|y|n}}", "<a href=\"/wiki/Template:Si:\">Template:Si:</a>");} // should be "Si", not "si"; ALSO, should probably be "{{si:|y|n}}" not "[[:Template:si:]]" DATE:2014-07-04
|
||||
@Test public void Core_messages() {
|
||||
fxt.Parse_core("$messages = array('sunday' => 'dimanche');")
|
||||
.Tst_message("sunday", 0, "dimanche", false)
|
||||
;
|
||||
}
|
||||
@Test public void Fallback() {
|
||||
fxt.Parse_core("$fallback = 'zh-hans';");
|
||||
Tfds.Eq("zh-hans", String_.new_u8(fxt.Lang().Fallback_bry()));
|
||||
}
|
||||
@Test public void Separator_transform_table() {
|
||||
fxt.Parse_core("$separatorTransformTable = array( ',' => '.', '.' => ',' );");
|
||||
fxt.Num_fmt_tst("1234,56", "1.234.56"); // NOTE: dot is repeated; confirmed with dewiki and {{formatnum:1234,56}}
|
||||
}
|
||||
@Test public void Separator_transform_table_fr() {
|
||||
fxt.Parse_core("$separatorTransformTable = array( ',' => '\\xc2\\xa0', '.' => ',' );");
|
||||
fxt.Num_fmt_tst("1234,56", "1 234 56"); // NOTE: nbsp here; also, nbsp is repeated. see dewiki and {{formatnum:1234,56}}
|
||||
}
|
||||
@Test public void Digit_transform_table() {
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
|
||||
, "$digitTransformTable = array("
|
||||
, " '0' => 'nulla',"
|
||||
, " '1' => 'I',"
|
||||
, " '2' => 'II',"
|
||||
, " '3' => 'III',"
|
||||
, " '4' => 'IV',"
|
||||
, " '5' => 'V',"
|
||||
, " '6' => 'VI',"
|
||||
, " '7' => 'VII',"
|
||||
, " '8' => 'VIII',"
|
||||
, " '9' => 'IX',"
|
||||
, ");"
|
||||
);
|
||||
fxt.Run_bld_all();
|
||||
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
|
||||
( "numbers {"
|
||||
, " digits {"
|
||||
, " clear;"
|
||||
, " set('0', 'nulla');"
|
||||
, " set('1', 'I');"
|
||||
, " set('2', 'II');"
|
||||
, " set('3', 'III');"
|
||||
, " set('4', 'IV');"
|
||||
, " set('5', 'V');"
|
||||
, " set('6', 'VI');"
|
||||
, " set('7', 'VII');"
|
||||
, " set('8', 'VIII');"
|
||||
, " set('9', 'IX');"
|
||||
, " }"
|
||||
, "}"
|
||||
, "this"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Digit_grouping_pattern() {
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
|
||||
, "$digitGroupingPattern = '##,##,###'"
|
||||
, ");"
|
||||
);
|
||||
fxt.Run_bld_all();
|
||||
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
|
||||
( "numbers {"
|
||||
, " digit_grouping_pattern = '##,##,###';"
|
||||
, "}"
|
||||
, "this"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Bld() {
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_php/MessagesFr.php"
|
||||
, "$fallback = 'zh-hans';"
|
||||
, "$rtl = true;"
|
||||
, "$namespaceNames = array(NS_FILE => 'Filex');"
|
||||
, "$namespaceAliases = array('File Discussion' => NS_FILE_TALK);"
|
||||
, "$magicWords = array('currentmonth' => array(0, 'CUR_MONTH'));"
|
||||
, "$messages = array('sunday' => 'sunday');"
|
||||
);
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/xtns_php/Test.il8n.php"
|
||||
, "$magicWords['fr'] = array('currentyear' => array(0, 'CUR_YEAR'));"
|
||||
, "$messages['fr'] = array('monday' => 'monday');"
|
||||
);
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/core_json/Messages/fr.json"
|
||||
, "{"
|
||||
, " \"@metadata\": {"
|
||||
, " \"authors\": []"
|
||||
, " },"
|
||||
, "\"key_1\": \"val_1\","
|
||||
, "\"key_2\": \"val $1\","
|
||||
, "}"
|
||||
);
|
||||
fxt.Save_file("mem/xowa/bin/any/xowa/cfg/lang/mediawiki/xtns_json/Test2/fr.json"
|
||||
, "{"
|
||||
, " \"@metadata\": {"
|
||||
, " \"authors\": []"
|
||||
, " },"
|
||||
, "\"key_3\": \"val_3\","
|
||||
, "\"key_4\": \"val $1\","
|
||||
, "}"
|
||||
);
|
||||
fxt.Run_bld_all();
|
||||
fxt.Tst_file("mem/xowa/bin/any/xowa/cfg/lang/core/fr.gfs", String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".fallback_load('zh-hans')"
|
||||
, ".dir_rtl_('y')"
|
||||
, ".ns_names"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "6|Filex"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".ns_aliases"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "7|File Discussion"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "currentmonth|0|CUR_MONTH~"
|
||||
, "currentyear|0|CUR_YEAR~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".messages"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "sunday|sunday"
|
||||
, "monday|monday"
|
||||
, "key_1|val_1"
|
||||
, "key_2|val ~{0}"
|
||||
, "key_3|val_3"
|
||||
, "key_4|val ~{0}"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
));
|
||||
}
|
||||
@Test public void Dir_ltr() {
|
||||
fxt.Parse_core("$rtl = 'true';");
|
||||
Tfds.Eq(false, fxt.Lang().Dir_ltr());
|
||||
}
|
||||
@Test public void Core_keywords__only_1() { // PURPOSE: some magic words don't specify case-match; EX: Disambiguator.php; DATE:2013-12-24
|
||||
fxt.Parse_core("$magicWords = array('toc' => array('a1'));")
|
||||
.Tst_keyword(Xol_kwd_grp_.Id_toc, false, "a1")
|
||||
;
|
||||
}
|
||||
@Test public void Core_keywords__skip_case_match__1() { // PURPOSE: some magic words don't specify case-match; EX: Disambiguator.php; DATE:2013-12-24
|
||||
fxt.Parse_core("$magicWords = array('toc' => array('a1'));")
|
||||
.Tst_keyword(Xol_kwd_grp_.Id_toc, false, "a1")
|
||||
;
|
||||
}
|
||||
@Test public void Core_keywords__skip_case_match__2() { // PURPOSE: some magic words don't specify case-match; EX: Disambiguator.php; DATE:2013-12-24
|
||||
fxt.Parse_core("$magicWords = array('toc' => array('a1', 'a2'));")
|
||||
.Tst_keyword(Xol_kwd_grp_.Id_toc, false, "a1", "a2")
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xol_mw_lang_parser_fxt {
|
||||
Xoae_app app; Xowe_wiki wiki; private Xop_fxt fxt;
|
||||
Xol_mw_lang_parser parser = new Xol_mw_lang_parser(Gfo_msg_log.Test()); Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
}
|
||||
app.Lang_mgr().Clear();// NOTE: always clear the lang
|
||||
lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7("fr"));
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app, "en.wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
lang.Kwd_mgr().Clear(); lang.Msg_mgr().Clear(); // NOTE: clear kwds and msgs else they will be printed to file; this line must go last b/c various xtns will fill in kwds dynamically
|
||||
}
|
||||
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
|
||||
public void Num_fmt_tst(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(lang.Num_mgr().Format_num(Bry_.new_u8(raw))));}
|
||||
public void Run_bld_all() {parser.Bld_all(app.Lang_mgr(), app.Fsys_mgr());}
|
||||
public void Save_file(String path, String... lines) {
|
||||
Io_mgr.Instance.SaveFilStr(Io_url_.mem_fil_(path), String_.Concat_lines_nl(lines));
|
||||
}
|
||||
public void Tst_file(String path, String expd) {
|
||||
Io_url url = Io_url_.mem_fil_(path);
|
||||
String actl = Io_mgr.Instance.LoadFilStr(url);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Parse_core(String raw) {parser.Parse_core(raw, lang, tmp_bfr, Xol_lang_transform_null.Instance); return this;}
|
||||
public Xol_mw_lang_parser_fxt Parse_xtn (String raw) {parser.Parse_xtn(raw, Io_url_.Empty, app.Lang_mgr(), tmp_bfr, false, Xol_lang_transform_null.Instance); lang.Evt_lang_changed(); return this;}
|
||||
public Xol_mw_lang_parser_fxt Tst_keyword(int id, boolean case_sensitive, String... words) {
|
||||
Xol_kwd_grp lst = lang.Kwd_mgr().Get_at(id); if (lst == null) throw Err_.new_wo_type("list should not be null");
|
||||
Tfds.Eq(case_sensitive, lst.Case_match());
|
||||
int actl_len = lst.Itms().length;
|
||||
String[] actl = new String[actl_len];
|
||||
for (int i = 0; i < actl_len; i++)
|
||||
actl[i] = String_.new_u8(lst.Itms()[i].Val());
|
||||
Tfds.Eq_ary_str(words, actl);
|
||||
return this;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Tst_keyword_img(String key_str, byte tid) {
|
||||
byte[] key = Bry_.new_u8(key_str);
|
||||
Tfds.Eq(tid, lang.Lnki_arg_parser().Identify_tid(key, 0, key.length));
|
||||
return this;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Tst_parse(String raw, String expd) {
|
||||
fxt.Reset();
|
||||
fxt.Test_parse_page_all_str(raw, expd);
|
||||
return this;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Tst_ns_lkp(String key_str, int id) {
|
||||
byte[] key = Bry_.new_u8(key_str);
|
||||
Xow_ns ns = (Xow_ns)wiki.Ns_mgr().Names_get_or_null(key, 0, key.length);
|
||||
int actl = ns == null ? Xow_ns_.Tid__null : ns.Id();
|
||||
Tfds.Eq(id, actl);
|
||||
return this;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Test_specialPageAliases(String special, String... expd_aliases) {
|
||||
Xol_specials_itm actl_aliases = lang.Specials_mgr().Get_by_key(Bry_.new_u8(special));
|
||||
Tfds.Eq_ary_str(expd_aliases, To_str_ary(actl_aliases));
|
||||
return this;
|
||||
}
|
||||
private String[] To_str_ary(Xol_specials_itm itm) {
|
||||
int len = itm.Aliases().length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = String_.new_u8((byte[])itm.Aliases()[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Sync_ns() {
|
||||
Xow_ns_mgr_.rebuild_(lang, wiki.Ns_mgr());
|
||||
return this;
|
||||
}
|
||||
public Xol_mw_lang_parser_fxt Tst_message(String key, int id, String val, boolean fmt) {
|
||||
Xol_msg_itm itm = lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_a7(key));
|
||||
Tfds.Eq(id, itm.Id());
|
||||
Tfds.Eq(val, String_.new_u8(itm.Val()));
|
||||
Tfds.Eq(fmt, itm.Has_fmt_arg());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
156
400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java
Normal file
156
400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
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.langs.cases; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
public class Xol_case_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_case_mgr_fxt fxt = new Xol_case_mgr_fxt();
|
||||
@Test public void Mw_parse() {
|
||||
fxt.parse_mw__tst(fxt.itm_both_("A", "a"), fxt.itm_both_("B", "b"));
|
||||
}
|
||||
@Test public void Xo_parse() {
|
||||
fxt.parse_xo__tst(fxt.Init_ltrs_raw(), fxt.itm_both_("a", "A"), fxt.itm_upper_("b", "B"), fxt.itm_lower_("C", "c"));
|
||||
}
|
||||
@Test public void Upper_a() {fxt.Init_ltrs().Upper("aAaz", "AAAz");}
|
||||
@Test public void Upper_ab() {fxt.Init_ltrs().Upper("abac", "ABAc");}
|
||||
@Test public void Lower_a() {fxt.Init_ltrs().Lower("aAaZ", "aaaZ");}
|
||||
@Test public void Lower_ac() {fxt.Init_ltrs().Lower("ABAC", "aBac");}
|
||||
@Test public void Upper_1st() {
|
||||
fxt.Init_ltrs_universal();
|
||||
fxt.Test_reuse_1st_upper("a", "A");
|
||||
fxt.Test_reuse_1st_upper("abc", "Abc");
|
||||
fxt.Test_reuse_1st_upper("");
|
||||
fxt.Test_reuse_1st_upper("Abc");
|
||||
fxt.Test_reuse_1st_upper("é", "É");
|
||||
fxt.Test_reuse_1st_upper("É");
|
||||
fxt.Lower("Ι", "ι"); // PURPOSE:test reversal; PAGE:en.d:ἀρχιερεύς DATE:2014-09-02
|
||||
}
|
||||
@Test public void Turkish_redirect() { // PURPOSE: lowercase redirect should match uppercase for asymmetric brys; PAGE:tr.w:Zvishavane DATE:2015-09-07
|
||||
Hash_adp_bry hash = Hash_adp_bry.c__u8(Bool_.N, Xol_case_mgr_.U8());
|
||||
byte[] upper = Bry_.new_u8("YÖNLENDİRME");
|
||||
byte[] lower = Bry_.new_u8("yönlendirme");
|
||||
hash.Add(upper, upper); // add upper to hash
|
||||
Tfds.Eq_bry(upper, (byte[])hash.Get_by_bry(lower)); // get upper by using lower
|
||||
}
|
||||
// @Test public void Hack() {
|
||||
// Xol_case_itm[] ary = Xol_case_mgr_.Utf_8;
|
||||
// Bry_bfr bfr = Bry_bfr_.New();
|
||||
// for (int i = 0; i < ary.length; i++) {
|
||||
// Xol_case_itm itm = ary[i];
|
||||
// bfr.Add_str_a7("xo|");
|
||||
// bfr.Add_bry_comma(itm.Src_ary()).Add_byte_pipe();
|
||||
// bfr.Add_bry_comma(itm.Trg_ary()).Add_byte_nl();
|
||||
// }
|
||||
// Io_mgr.Instance.SaveFilStr("C:\\test1.txt", bfr.To_str_and_clear());
|
||||
// }
|
||||
}
|
||||
class Xol_case_mgr_fxt {
|
||||
private Xol_case_mgr case_mgr = Xol_case_mgr_.new_(); private String_bldr sb = String_bldr_.new_();
|
||||
public void Clear() {case_mgr.Clear();}
|
||||
public Xol_case_itm_bry itm_both_(String src, String trg) {return new Xol_case_itm_bry(Xol_case_itm_.Tid_both , Bry_.new_u8(src), Bry_.new_u8(trg));}
|
||||
public Xol_case_itm_bry itm_upper_(String src, String trg) {return new Xol_case_itm_bry(Xol_case_itm_.Tid_upper, Bry_.new_u8(src), Bry_.new_u8(trg));}
|
||||
public Xol_case_itm_bry itm_lower_(String src, String trg) {return new Xol_case_itm_bry(Xol_case_itm_.Tid_lower, Bry_.new_u8(src), Bry_.new_u8(trg));}
|
||||
public String Init_ltrs_raw() {
|
||||
return String_.Concat_lines_nl
|
||||
( "0|a|A"
|
||||
, "1|b|B"
|
||||
, "2|C|c"
|
||||
);
|
||||
}
|
||||
public Xol_case_mgr_fxt Init_ltrs() {
|
||||
case_mgr = Xol_case_mgr_.new_();
|
||||
case_mgr.Add_bulk(Bry_.new_u8(Init_ltrs_raw()));
|
||||
return this;
|
||||
}
|
||||
public Xol_case_mgr_fxt Init_ltrs_universal() {
|
||||
case_mgr = Xol_case_mgr_.U8();
|
||||
return this;
|
||||
}
|
||||
public Xol_case_mgr_fxt Upper(String raw_str, String expd) {return Case_build(Bool_.Y, raw_str, expd);}
|
||||
public Xol_case_mgr_fxt Lower(String raw_str, String expd) {return Case_build(Bool_.N, raw_str, expd);}
|
||||
public Xol_case_mgr_fxt Case_build(boolean upper, String raw_str, String expd) {
|
||||
byte[] raw = Bry_.new_u8(raw_str);
|
||||
byte[] actl = case_mgr.Case_build(upper, raw, 0, raw.length);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
return this;
|
||||
}
|
||||
public void parse_xo__tst(String raw, Xol_case_itm_bry... expd) {
|
||||
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(Xol_case_itm_.parse_xo_(Bry_.new_u8(raw))));
|
||||
}
|
||||
public void parse_mw__tst(Xol_case_itm_bry... expd) {
|
||||
String raw = raw_(expd);
|
||||
Xol_case_itm[] actl = Xol_case_itm_.parse_mw_(Bry_.new_u8(raw));
|
||||
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(actl));
|
||||
}
|
||||
public String Xto_str(Xol_case_itm[] ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Xol_case_itm itm = ary[i];
|
||||
sb.Add(Byte_.To_str(itm.Tid())).Add_char_pipe().Add(String_.new_u8(itm.Src_ary())).Add_char_pipe().Add(String_.new_u8(itm.Trg_ary())).Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
public String raw_(Xol_case_itm_bry[] itms) {
|
||||
int itms_len = itms.length;
|
||||
uppers_list.Clear(); lowers_list.Clear();
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xol_case_itm_bry itm = itms[i];
|
||||
String src = String_.new_u8(itm.Src_ary());
|
||||
String trg = String_.new_u8(itm.Trg_ary());
|
||||
switch (itm.Tid()) {
|
||||
case Xol_case_itm_.Tid_both:
|
||||
uppers_list.Add(trg); uppers_list.Add(src);
|
||||
lowers_list.Add(src); lowers_list.Add(trg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return raw_str_(uppers_list.To_str_ary(), lowers_list.To_str_ary());
|
||||
} List_adp uppers_list = List_adp_.New(), lowers_list = List_adp_.New();
|
||||
String raw_str_(String[] uppers, String[] lowers) {
|
||||
sb.Add("a:2:{s:14:\"wikiUpperChars\";a:1046:{");
|
||||
raw_ary(sb, uppers);
|
||||
sb.Add("}");
|
||||
sb.Add("s:14:\"wikiLowerChars\";a:1038:{");
|
||||
raw_ary(sb, lowers);
|
||||
sb.Add("}}");
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
private void raw_ary(String_bldr sb, String[] ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String itm = ary[i];
|
||||
int itm_len = String_.Len(itm);
|
||||
sb.Add_fmt("s:{0}:\"{1}\";", itm_len, itm);
|
||||
}
|
||||
}
|
||||
public void Test_reuse_1st_upper(String raw) {Test_reuse_1st_upper(raw, null, Bool_.Y);}
|
||||
public void Test_reuse_1st_upper(String raw, String expd) {Test_reuse_1st_upper(raw, expd, Bool_.N);}
|
||||
private void Test_reuse_1st_upper(String raw, String expd, boolean expd_is_same) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
byte[] actl_bry = case_mgr.Case_reuse_1st_upper(raw_bry);
|
||||
String actl_str = String_.new_u8(actl_bry);
|
||||
boolean actl_is_same = Object_.Eq(raw_bry, actl_bry); // pointers will be same if no change
|
||||
if (expd_is_same) {
|
||||
Tfds.Eq_true(actl_is_same, "expd should be same: " + actl_str);
|
||||
}
|
||||
else {
|
||||
Tfds.Eq_true(!actl_is_same, "expd should not be same: " + actl_str);
|
||||
Tfds.Eq(expd, actl_str, expd);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
a:2:{s:14:"wikiUpperChars";a:1046:{s:1:"a";s:1:"A";s:1:"b";}s:14:"wikiLowerChars";a:1038:{s:1:"A";s:1:"a";s:1:"B";}}
|
||||
*/
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.langs.kwds; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*; import gplx.core.primitives.*;
|
||||
public class Xol_kwd_parse_data_tst {
|
||||
@Before public void init() {Clear();}
|
||||
@Test public void Basic() {Key_("upright" ).Tst_strip("upright");}
|
||||
@Test public void Eq_arg() {Key_("upright" ).Tst_strip("upright=$1");}
|
||||
@Test public void Space() {Key_("upright ").Tst_strip("upright $1");}
|
||||
@Test public void Px() {Key_("px").Tst_strip("$1px");}
|
||||
|
||||
private void Clear() {
|
||||
key = null;
|
||||
}
|
||||
Xol_kwd_parse_data_tst Key_(String v) {this.key = v; return this;} private String key;
|
||||
Xol_kwd_parse_data_tst Tst_strip(String v) {
|
||||
Bry_bfr tmp = Bry_bfr_.New();
|
||||
Byte_obj_ref rslt = Byte_obj_ref.zero_();
|
||||
byte[] actl = Xol_kwd_parse_data.Strip(tmp, Bry_.new_a7(v), rslt);
|
||||
Tfds.Eq(key, String_.new_a7(actl));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -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.langs.lnki_trails; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_lnki_trail_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_lnki_trail_mgr_fxt fxt = new Xol_lnki_trail_mgr_fxt();
|
||||
@Test public void Add_bulk() {
|
||||
fxt.Test_add_bulk("äöüß", "ä", "ö", "ü", "ß");
|
||||
}
|
||||
}
|
||||
class Xol_lnki_trail_mgr_fxt {
|
||||
Xol_lang_itm lang; Xol_lnki_trail_mgr lnki_trail_mgr;
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fr"));
|
||||
lnki_trail_mgr = lang.Lnki_trail_mgr();
|
||||
}
|
||||
public void Test_add_bulk(String raw, String... expd_ary) {
|
||||
lnki_trail_mgr.Add_bulk(Bry_.new_u8(raw));
|
||||
int expd_len = expd_ary.length;
|
||||
Tfds.Eq(expd_len, lang.Lnki_trail_mgr().Count());
|
||||
for (int i = 0; i < expd_len; i++) {
|
||||
byte[] expd_bry = Bry_.new_u8(expd_ary[i]);
|
||||
byte[] actl_bry = (byte[])lnki_trail_mgr.Trie().Match_bgn(expd_bry, 0, expd_bry.length);
|
||||
Tfds.Eq_bry(expd_bry, actl_bry);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java
Normal file
37
400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java
Normal 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.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_msg_itm_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xol_msg_itm_fxt fxt = new Xol_msg_itm_fxt();
|
||||
@Test public void New_plain() {fxt.Test_new("a" , Bool_.N, Bool_.N);}
|
||||
@Test public void New_fmt() {fxt.Test_new("a~{0}b" , Bool_.Y, Bool_.N);}
|
||||
@Test public void New_tmpl() {fxt.Test_new("a{{b}}c" , Bool_.N, Bool_.Y);}
|
||||
@Test public void New_fmt_tmpl() {fxt.Test_new("a{{b}}c~{0}d" , Bool_.Y, Bool_.Y);}
|
||||
@Test public void New_space() {fxt.Test_val("a b" , "a b");}
|
||||
}
|
||||
class Xol_msg_itm_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_new(String val, boolean has_fmt_arg, boolean has_tmpl_txt) {
|
||||
Xol_msg_itm itm = Xol_msg_itm_.new_(0, "test", val);
|
||||
Tfds.Eq(has_fmt_arg, itm.Has_fmt_arg(), "has_fmt_arg");
|
||||
Tfds.Eq(has_tmpl_txt, itm.Has_tmpl_txt(), "has_tmpl_txt");
|
||||
}
|
||||
public void Test_val(String val, String expd) {
|
||||
Xol_msg_itm itm = Xol_msg_itm_.new_(0, "test", val);
|
||||
Tfds.Eq(expd, String_.new_u8(itm.Val()), "has_fmt_arg");
|
||||
}
|
||||
}
|
||||
68
400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java
Normal file
68
400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_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.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xol_msg_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xol_msg_mgr_fxt fxt = new Xol_msg_mgr_fxt();
|
||||
@Test public void Template_msg() {fxt.Test_val_by_key("About {{SITENAME}}", "About Wikipedia");} // PURPOSE.fix: {{Template}} not working inside label tags; EX:de.wikisource.org; DATE:2013-02-10
|
||||
@Test public void Template_mediawiki() { // PURPOSE.fix: {{Template}} not working inside MediaWiki template
|
||||
fxt.Test_mediaWiki_msg("About {{SITENAME}}", "About Wikipedia");
|
||||
}
|
||||
@Test public void Val_html_accesskey_and_title() {
|
||||
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , "a" , " accesskey=\"a\" title=\"test_title [a]\"");
|
||||
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , null , " title=\"test_title\""); // accesskey is missing
|
||||
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , "" , " title=\"test_title\""); // accesskey is ""
|
||||
fxt.Clear().Test_val_html_accesskey_and_title(null , "a" , " title=\"\""); // no title; leave blank
|
||||
}
|
||||
@Test public void Missing() {
|
||||
fxt.Test__get_msg_val("missing", "<missing>"); // check that key is enclosed in <>
|
||||
fxt.Test__get_msg_val("Missing", "<Missing>"); // check that val matches key; used to match 1st case-insensitive variant; EX: "<missing>" b/c "<missing>" was returned above; DATE:2016-08-01
|
||||
}
|
||||
}
|
||||
class Xol_msg_mgr_fxt {
|
||||
public Xol_msg_mgr_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
mgr = wiki.Msg_mgr();
|
||||
}
|
||||
mgr.Clear();
|
||||
wiki.Lang().Msg_mgr().Clear();
|
||||
return this;
|
||||
} private Xoae_app app; Xowe_wiki wiki; Xow_msg_mgr mgr;
|
||||
public void Test_val_by_key(String val, String expd) {
|
||||
Xol_msg_itm itm = wiki.Lang().Msg_mgr().Itm_by_key_or_new(Bry_.new_a7("test"));
|
||||
itm.Atrs_set(Bry_.new_a7(val), false, true);
|
||||
Tfds.Eq(expd, String_.new_u8(wiki.Msg_mgr().Val_by_key_obj(Bry_.new_a7("test"))), "has_tmpl_txt");
|
||||
}
|
||||
public void Test_mediaWiki_msg(String raw, String expd) {
|
||||
byte[] msg_ttl = Bry_.new_a7("MediaWiki:msg_ttl");
|
||||
wiki.Db_mgr().Save_mgr().Data_create(Xoa_ttl.Parse(wiki, msg_ttl), Bry_.new_a7(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(wiki.Msg_mgr().Val_by_key_obj(Bry_.new_a7("msg_ttl"))));
|
||||
}
|
||||
public void Test_val_html_accesskey_and_title(String init_title, String init_accesskey, String expd) {
|
||||
if (init_title != null) new_msg_itm_("tooltip-test" , init_title);
|
||||
if (init_accesskey != null) new_msg_itm_("accesskey-test" , init_accesskey);
|
||||
Tfds.Eq(expd, String_.new_a7(wiki.Msg_mgr().Val_html_accesskey_and_title(Bry_.new_a7("test"))));
|
||||
}
|
||||
public void Test__get_msg_val(String key, String expd) {
|
||||
Gftest.Eq__str(expd, Xol_msg_mgr_.Get_msg_val(wiki, wiki.Lang(), Bry_.new_a7(key), Bry_.Ary_empty));
|
||||
}
|
||||
private void new_msg_itm_(String key, String val) {
|
||||
Xol_msg_itm itm = wiki.Lang().Msg_mgr().Itm_by_key_or_new(Bry_.new_a7(key));
|
||||
itm.Atrs_set(Bry_.new_a7(val), false, true);
|
||||
}
|
||||
}
|
||||
@@ -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.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xow_mainpage_finder_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xow_mainpage_finder_fxt fxt = new Xow_mainpage_finder_fxt();
|
||||
@Test public void Mediawiki() {
|
||||
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
|
||||
fxt.Test_mainpage("Mainpage_by_mediawiki");
|
||||
}
|
||||
@Test public void Lang() {
|
||||
fxt.Init_lang("Mainpage_by_lang");
|
||||
fxt.Test_mainpage("Mainpage_by_lang");
|
||||
}
|
||||
@Test public void Siteinfo() {
|
||||
fxt.Init_siteinfo("Mainpage_by_siteinfo");
|
||||
fxt.Test_mainpage("Mainpage_by_siteinfo");
|
||||
}
|
||||
@Test public void Lang_and_siteinfo() {
|
||||
fxt.Init_lang("Mainpage_by_lang");
|
||||
fxt.Init_siteinfo("Mainpage_by_siteinfo");
|
||||
fxt.Test_mainpage("Mainpage_by_lang");
|
||||
}
|
||||
@Test public void Mediawiki_and_siteinfo() {
|
||||
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
|
||||
fxt.Init_siteinfo("Mainpage_by_siteinfo");
|
||||
fxt.Test_mainpage("Mainpage_by_mediawiki");
|
||||
}
|
||||
@Test public void Mediawiki_and_lang_and_siteinfo() {
|
||||
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
|
||||
fxt.Init_lang("Mainpage_by_lang");
|
||||
fxt.Init_siteinfo("Mainpage_by_siteinfo");
|
||||
fxt.Test_mainpage("Mainpage_by_mediawiki");
|
||||
}
|
||||
@Test public void Mediawiki_tmpl() { // PURPOSE: de.wiktionary.org has "{{ns:project}}:Hauptseite"; DATE:2013-07-07
|
||||
fxt.Init_mediawiki_page("{{ns:project}}:Hauptseite");
|
||||
fxt.Test_mainpage("Wikipedia:Hauptseite");
|
||||
}
|
||||
}
|
||||
class Xow_mainpage_finder_fxt {
|
||||
public void Clear() {
|
||||
fxt.Reset_for_msgs();
|
||||
} private final Xop_fxt fxt = new Xop_fxt();
|
||||
public void Init_siteinfo(String mainpage_val) {
|
||||
fxt.Wiki().Props().Main_page_(Bry_.new_a7(mainpage_val));
|
||||
}
|
||||
public void Init_mediawiki_page(String mainpage_val) {
|
||||
fxt.Init_page_create(String_.new_a7(Ttl_mainpage), mainpage_val);
|
||||
} private static final byte[] Ttl_mainpage = Bry_.new_a7("MediaWiki:Mainpage"); // TEST:
|
||||
public void Init_lang(String mainpage_val) {
|
||||
Xol_msg_itm msg_itm = fxt.Wiki().Lang().Msg_mgr().Itm_by_key_or_new(Xow_mainpage_finder.Msg_mainpage);
|
||||
msg_itm.Atrs_set(Bry_.new_a7(mainpage_val), false, false);
|
||||
}
|
||||
public void Test_mainpage(String expd) {
|
||||
byte[] actl = Xow_mainpage_finder.Find_or(fxt.Wiki(), fxt.Wiki().Props().Main_page());
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
}
|
||||
116
400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java
Normal file
116
400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_num_fmtr_base_tst {
|
||||
Xol_num_fmtr_base mgr = new Xol_num_fmtr_base();
|
||||
@Before public void init() {mgr.Clear();}
|
||||
@Test public void Outliers() {
|
||||
ini_(".", dat_(",", 3));
|
||||
tst_Fmt("1234a1234" , "1,234a1,234");
|
||||
tst_Fmt("1234abc1234" , "1,234abc1,234");
|
||||
tst_Fmt("1234,1234" , "1,234,1,234");
|
||||
tst_Fmt("1234.1234" , "1,234.1234");
|
||||
tst_Fmt("1234." , "1,234.");
|
||||
tst_Fmt("1234.1234.1234.1234" , "1,234.1234.1234.1234");
|
||||
tst_Fmt("-1234567" , "-1,234,567");
|
||||
tst_Fmt("1,234,567" , "1,234,567");
|
||||
}
|
||||
@Test public void English() {
|
||||
ini_(".", dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "12,345,678");
|
||||
tst_Fmt("12345678901234567890" , "12,345,678,901,234,567,890");
|
||||
tst_Raw("1,234.12" , "1234.12");
|
||||
}
|
||||
@Test public void French() {
|
||||
ini_(",", dat_(" ", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1 234");
|
||||
tst_Fmt("12345678" , "12 345 678");
|
||||
tst_Fmt("12345678901234567890" , "12 345 678 901 234 567 890");
|
||||
tst_Fmt("1234,5678" , "1 234 5 678"); // NOTE: nbsp here; also, nbsp is repeated. see dewiki and {{formatnum:1234,56}}
|
||||
}
|
||||
@Test public void Croatia() {
|
||||
ini_(",", dat_(".", 3), dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1.234");
|
||||
tst_Fmt("12345678" , "12,345.678");
|
||||
tst_Fmt("12345678901234567890" , "12,345.678,901.234,567.890");
|
||||
}
|
||||
@Test public void Mexico() {
|
||||
ini_(".", dat_(",", 3, false), dat_("'", 3, false), dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "12'345,678");
|
||||
tst_Fmt("12345678901234567890" , "12,345,678,901,234'567,890");
|
||||
tst_Raw("12'345,678.90" , "12345678.90");
|
||||
}
|
||||
@Test public void China() {
|
||||
ini_(".", dat_(",", 4));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1234");
|
||||
tst_Fmt("12345678" , "1234,5678");
|
||||
tst_Fmt("12345678901234567890" , "1234,5678,9012,3456,7890");
|
||||
}
|
||||
@Test public void Hindi() {
|
||||
ini_(".", dat_(",", 3, false), dat_(",", 2));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "1,23,45,678");
|
||||
tst_Fmt("12345678901234567890" , "1,23,45,67,89,01,23,45,67,890");
|
||||
}
|
||||
@Test public void India() {
|
||||
ini_(".", dat_(",", 3), dat_(",", 2), dat_(",", 2));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "1,23,45,678");
|
||||
tst_Fmt("12345678901234567890" , "1,23,456,78,90,123,45,67,890");
|
||||
}
|
||||
@Test public void MiddleDot() {
|
||||
ini_("·", dat_("·", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1·234");
|
||||
tst_Fmt("12345678" , "12·345·678");
|
||||
tst_Fmt("12345678901234567890" , "12·345·678·901·234·567·890");
|
||||
tst_Fmt("1234·5678" , "1·234·5·678");// NOTE: middle-dot is repeated. see dewiki and {{formatnum:1234,5678}}
|
||||
tst_Raw("1234·5678" , "1234.5678");
|
||||
}
|
||||
Xol_num_grp dat_(String dlm, int digits) {return new Xol_num_grp(Bry_.new_u8(dlm), digits, true);}
|
||||
Xol_num_grp dat_(String dlm, int digits, boolean repeat) {return new Xol_num_grp(Bry_.new_u8(dlm), digits, repeat);}
|
||||
private void tst_Fmt(String val, String expd) {Tfds.Eq(expd, String_.new_u8(mgr.Fmt(Bry_.new_u8(val))));}
|
||||
private void tst_Raw(String val, String expd) {Tfds.Eq(expd, String_.new_u8(mgr.Raw(Xol_num_fmtr_base.Tid_raw, Bry_.new_u8(val))));}
|
||||
private void ini_(String dec_dlm, Xol_num_grp... ary) {
|
||||
mgr.Dec_dlm_(Bry_.new_u8(dec_dlm));
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
mgr.Grps_add(ary[i]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
'france' ' 3#' ',0%' // 1 234 567,89
|
||||
'spain' '.3#' "'0%" // 1.234.567'89
|
||||
'germany' '.3#' ",0%" // 1.234.567,89
|
||||
'italy' ''3#' ",0%" // 1'234'567,89
|
||||
'en-us' ',3#' '.0%' // 1,234,567.89
|
||||
'en-sa' ',3#' '\u00120%' // 1,234,567·89
|
||||
'croatia' ',3#*' '.3#*' ',0%' // 1,234.567,890.123,45
|
||||
'china' ',4$' // 123,4567.89
|
||||
'mexico' ',3#*' "'3#" ',3#' // 1'234,567.89
|
||||
'hindi' ",2#*" ',3#' // 1,23,45,678.9
|
||||
'india' ',2#*' ',2#*' ',3#*' // 1,245,67,89,012
|
||||
*/
|
||||
@@ -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.xowa.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_num_grp_fmtr_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xol_num_grp_fmtr_fxt fxt = new Xol_num_grp_fmtr_fxt();
|
||||
@Test public void Num() {
|
||||
fxt.Test_fmt_regx("" , "");
|
||||
fxt.Test_fmt_regx("1" , "1");
|
||||
fxt.Test_fmt_regx("12" , "12");
|
||||
fxt.Test_fmt_regx("123" , "123");
|
||||
fxt.Test_fmt_regx("1234" , "1,234");
|
||||
fxt.Test_fmt_regx("12345" , "12,345");
|
||||
fxt.Test_fmt_regx("123456" , "123,456");
|
||||
fxt.Test_fmt_regx("1234567" , "1,234,567");
|
||||
fxt.Test_fmt_regx("1234567890" , "1,234,567,890");
|
||||
}
|
||||
@Test public void Dec() {
|
||||
fxt.Test_fmt_regx("1.9876" , "1.9876");
|
||||
fxt.Test_fmt_regx("1234.9876" , "1,234.9876");
|
||||
}
|
||||
@Test public void Neg() {
|
||||
fxt.Test_fmt_regx("-1234.5678" , "-1,234.5678");
|
||||
}
|
||||
@Test public void Char() {
|
||||
fxt.Test_fmt_regx("1,234" , "1,234");
|
||||
fxt.Test_fmt_regx("1a2345" , "1a2,345");
|
||||
fxt.Test_fmt_regx("1234a5678b2345c.3456d7890e3210.f5432", "1,234a5,678b2,345c.3456d7,890e3,210.f5,432");
|
||||
}
|
||||
}
|
||||
class Xol_num_grp_fmtr_fxt {
|
||||
private Xol_num_grp_fmtr grouper = new Xol_num_grp_fmtr();
|
||||
private Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Reset() {}
|
||||
public void Test_fmt_regx(String raw, String expd) {
|
||||
byte[] actl = grouper.Fmt_regx(bfr, Bry_.new_a7(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java
Normal file
39
400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java
Normal 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.langs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_csv_parser_tst {
|
||||
Xol_csv_parser_fxt fxt = new Xol_csv_parser_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Save() {fxt.Tst_save("a\r\n\t|d", "a\\r\\n\\t\\u007Cd");}
|
||||
@Test public void Load() {fxt.Tst_load("a\r\n\t|d", "a\\r\\n\\t\\u007Cd");}
|
||||
@Test public void Save_backslash() {fxt.Tst_save("a\\\\n", "a\\\\\\\\n");}
|
||||
@Test public void Load_backslash() {fxt.Tst_load("a\\\\n", "a\\\\\\\\n");}
|
||||
@Test public void Utf() {fxt.Tst_load(" ", "\\u00c2\\u00a0");} // NOTE: 1st String is nbsp;
|
||||
}
|
||||
class Xol_csv_parser_fxt {
|
||||
Xol_csv_parser parser = Xol_csv_parser.Instance; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public void Clear() {}
|
||||
public void Tst_save(String raw, String expd) {
|
||||
parser.Save(tmp_bfr, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
public void Tst_load(String expd, String raw_str) {
|
||||
byte[] raw = Bry_.new_u8(raw_str);
|
||||
parser.Load(tmp_bfr, raw, 0, raw.length);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
346
400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java
Normal file
346
400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java
Normal file
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
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.langs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import gplx.core.intls.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.specials.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xol_lang_srl_tst {
|
||||
private Xol_lang_srl_fxt fxt = new Xol_lang_srl_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Ns_names() {
|
||||
String raw = String_.Concat_lines_nl
|
||||
( "ns_names"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "6|Filex"
|
||||
, "10|Templatex"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_ns_grp grp = fxt.Lang().Ns_names();
|
||||
fxt.Tst_ns_grp(grp, fxt.ns_(6, "Filex"), fxt.ns_(10, "Templatex"));
|
||||
fxt.Run_save_ns_grp(grp, Xol_lang_itm.Invk_ns_names, raw);
|
||||
}
|
||||
@Test public void Ns_aliases() {
|
||||
String raw = String_.Concat_lines_nl
|
||||
( "ns_aliases"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "6|Filex"
|
||||
, "10|Templatex"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_ns_grp grp = fxt.Lang().Ns_aliases();
|
||||
fxt.Tst_ns_grp(grp, fxt.ns_(6, "Filex"), fxt.ns_(10, "Templatex"));
|
||||
fxt.Run_save_ns_grp(grp, Xol_lang_itm.Invk_ns_aliases, raw);
|
||||
}
|
||||
@Test public void Kwds() {
|
||||
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
|
||||
( "keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "notoc|1|no_table_of_contents~toc_n~"
|
||||
, "toc|0|table_of_contents~toc_y~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
|
||||
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("notoc", true, "no_table_of_contents", "toc_n"), fxt.kwd_("toc", false, "table_of_contents", "toc_y"));
|
||||
fxt.Run_save_kwd_mgr(kwd_mgr, Xol_lang_itm.Invk_keywords, raw);
|
||||
}
|
||||
@Test public void Specials() {
|
||||
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
|
||||
( "specials"
|
||||
, " .clear"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "Randompage|PageAuHasard~Page_au_hasard"
|
||||
, "Search|Recherche~Rechercher"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_specials_mgr specials_mgr = fxt.Lang().Specials_mgr();
|
||||
fxt.Tst_specials(specials_mgr, fxt.special_("Randompage", "PageAuHasard", "Page_au_hasard"), fxt.special_("Search", "Recherche", "Rechercher"));
|
||||
fxt.Run_save_specials_mgr(specials_mgr, Xol_lang_itm.Invk_specials, raw);
|
||||
}
|
||||
@Test public void Kwds_blank_line() { // PURPOSE.fix: extra blank line negates entire entry
|
||||
String raw = String_.Concat_lines_nl
|
||||
( "keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "toc|0|table_of_contents~toc_y~"
|
||||
, ""
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
|
||||
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("toc", false, "table_of_contents", "toc_y")); // make sure 2 items (and not 0)
|
||||
}
|
||||
@Test public void Msgs() {
|
||||
String raw = String_.Concat_lines_nl
|
||||
( "messages"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "sunday|dimanche"
|
||||
, "monday|lundi"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_msg_mgr msg_mgr = fxt.Lang().Msg_mgr();
|
||||
fxt.Tst_messages(msg_mgr, fxt.msg_("sunday", "dimanche"), fxt.msg_("monday", "lundi"));
|
||||
fxt.Run_save_msg_mgr(msg_mgr, Xol_lang_itm.Invk_messages, raw);
|
||||
}
|
||||
@Test public void Fallback() {
|
||||
Io_mgr.Instance.SaveFilStr(Xol_lang_itm_.xo_lang_fil_(fxt.App().Fsys_mgr(), "zh-hans"), String_.Concat_lines_nl
|
||||
( "this"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "toc|0|table_of_contents~toc_y~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".ns_names"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "6|FileA"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".messages"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "sunday|sunday1"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ";"
|
||||
));
|
||||
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
|
||||
( "fallback_load('zh-hans')"
|
||||
, ".keywords"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "notoc|1|no_table_of_contents~toc_n~"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".ns_names"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "6|FileB"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
, ".messages"
|
||||
, " .load_text("
|
||||
, "<:['"
|
||||
, "monday|monday1"
|
||||
, "']:>"
|
||||
, ").lang"
|
||||
);
|
||||
fxt.Invk(raw);
|
||||
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
|
||||
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("notoc", true, "no_table_of_contents", "toc_n"), fxt.kwd_("toc", false, "table_of_contents", "toc_y"));
|
||||
fxt.Tst_ns_grp(fxt.Lang().Ns_names(), fxt.ns_(6, "FileA"), fxt.ns_(6, "FileB"));
|
||||
fxt.Tst_messages(fxt.Lang().Msg_mgr(), fxt.msg_("sunday", "sunday1"), fxt.msg_("monday", "monday1"));
|
||||
}
|
||||
@Test public void Fallback_circular() { // PURPOSE: pt and pt-br cite each other as fallback in Messages*.php; DATE:2013-02-18
|
||||
Io_mgr.Instance.SaveFilStr(Xol_lang_itm_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt") , "fallback_load('pt-br');");
|
||||
Io_mgr.Instance.SaveFilStr(Xol_lang_itm_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt-br") , "fallback_load('pt');");
|
||||
Xol_lang_itm lang = new Xol_lang_itm(fxt.App().Lang_mgr(), Bry_.new_a7("pt"));
|
||||
lang.Init_by_load();
|
||||
}
|
||||
@Test public void Num_fmt() {
|
||||
String raw = String_.Concat_lines_nl
|
||||
( "numbers {"
|
||||
, " separators {"
|
||||
, " clear;"
|
||||
, " set(',', '.');"
|
||||
, " set('.', ',');"
|
||||
, " }"
|
||||
, "}"
|
||||
);
|
||||
fxt.Invk_no_semic(raw);
|
||||
fxt.Tst_num_fmt("1234,56", "1.234.56"); // NOTE: dot is repeated; confirmed with dewiki and {{formatnum:1234,56}}
|
||||
fxt.Run_save_num_mgr(fxt.Lang().Num_mgr(), raw);
|
||||
}
|
||||
@Test public void Num_fmt_apos() { // PURPOSE:de.ch has apos which breaks gfs
|
||||
fxt .Init_clear()
|
||||
.Init_separators(",", "'")
|
||||
.Init_separators(".", ",")
|
||||
;
|
||||
fxt.Run_save_num_mgr(fxt.Lang().Num_mgr(), String_.Concat_lines_nl
|
||||
( "numbers {"
|
||||
, " separators {"
|
||||
, " clear;"
|
||||
, " set(',', '''');"
|
||||
, " set('.', ',');"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xol_lang_srl_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fr"));
|
||||
Xoa_gfs_mgr.Msg_parser_init(); // required by fallback_load
|
||||
} GfsCtx ctx = GfsCtx.new_(); Xoa_gfs_bldr bldr = new Xoa_gfs_bldr(); //Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
|
||||
public Xow_ns ns_(int id, String s) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_u8(s), false);}
|
||||
public Xol_specials_itm special_(String key, String... words) {return new Xol_specials_itm(Bry_.new_u8(key), Bry_.Ary(words));}
|
||||
public Xol_kwd_grp kwd_(String key, boolean case_match, String... words) {
|
||||
Xol_kwd_grp rv = new Xol_kwd_grp(Bry_.new_u8(key));
|
||||
rv.Srl_load(case_match, Bry_.Ary(words));
|
||||
return rv;
|
||||
}
|
||||
public Xol_msg_itm msg_(String key, String val) {
|
||||
Xol_msg_itm rv = lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_u8(key));
|
||||
rv.Atrs_set(Bry_.new_u8(val), false, false);
|
||||
return rv;
|
||||
}
|
||||
public Xol_lang_srl_fxt Init_clear() {
|
||||
lang.Num_mgr().Clear();
|
||||
return this;
|
||||
}
|
||||
public Xol_lang_srl_fxt Init_separators(String k, String v) {
|
||||
lang.Num_mgr().Separators_mgr().Set(Bry_.new_u8(k), Bry_.new_u8(v));
|
||||
return this;
|
||||
}
|
||||
public void Invk(String raw) {
|
||||
app.Gfs_mgr().Run_str_for(lang, raw + ";");
|
||||
}
|
||||
public void Invk_no_semic(String raw) {
|
||||
app.Gfs_mgr().Run_str_for(lang, raw);
|
||||
}
|
||||
public void Tst_ns_grp(Xol_ns_grp grp, Xow_ns... expd_ns) {
|
||||
Tfds.Eq_str_lines(Xto_str(expd_ns), Xto_str(To_ary(grp)));
|
||||
}
|
||||
public void Run_save_ns_grp(Xol_ns_grp grp, String invk, String raw) {
|
||||
Xol_lang_srl.Save_ns_grps(bldr, grp, invk);
|
||||
Tfds.Eq_str_lines("." + raw, bldr.Bfr().To_str_and_clear());
|
||||
}
|
||||
public void Run_save_kwd_mgr(Xol_kwd_mgr kwd_mgr, String invk, String raw) {
|
||||
Xol_lang_srl.Save_keywords(bldr, kwd_mgr);
|
||||
Tfds.Eq_str_lines("." + raw, bldr.Bfr().To_str_and_clear());
|
||||
}
|
||||
public void Run_save_msg_mgr(Xol_msg_mgr msg_mgr, String invk, String raw) {
|
||||
Xol_lang_srl.Save_messages(bldr, msg_mgr, true);
|
||||
Tfds.Eq_str_lines("." + raw, bldr.Bfr().To_str_and_clear());
|
||||
}
|
||||
public void Run_save_num_mgr(Xol_num_mgr num_mgr, String raw) {
|
||||
Xol_lang_srl.Save_num_mgr(bldr, num_mgr);
|
||||
Tfds.Eq_str_lines(raw, bldr.Bfr().To_str_and_clear());
|
||||
}
|
||||
public void Run_save_specials_mgr(Xol_specials_mgr specials_mgr, String invk, String raw) {
|
||||
Xol_lang_srl.Save_specials(bldr, specials_mgr);
|
||||
Tfds.Eq_str_lines("." + raw, bldr.Bfr().To_str_and_clear());
|
||||
}
|
||||
public void Tst_num_fmt(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(lang.Num_mgr().Format_num(Bry_.new_u8(raw))));}
|
||||
public void Tst_keywords(Xol_kwd_mgr kwd_mgr, Xol_kwd_grp... ary) {
|
||||
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(To_ary(kwd_mgr)));
|
||||
}
|
||||
public void Tst_messages(Xol_msg_mgr msg_mgr, Xol_msg_itm... ary) {
|
||||
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(To_ary(msg_mgr)));
|
||||
}
|
||||
public void Tst_specials(Xol_specials_mgr specials_mgr, Xol_specials_itm... expd) {
|
||||
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(To_ary(specials_mgr)));
|
||||
}
|
||||
private String Xto_str(Xol_specials_itm[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_specials_itm itm = ary[i];
|
||||
sb.Add(itm.Special()).Add("|");
|
||||
int aliases_len = itm.Aliases().length;
|
||||
for (int j = 0; j < aliases_len; j++) {
|
||||
if (j != 0) sb.Add("~");
|
||||
sb.Add(itm.Aliases()[j]).Add_char_nl();
|
||||
}
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
private Xol_specials_itm[] To_ary(Xol_specials_mgr specials_mgr) {
|
||||
int len = specials_mgr.Len();
|
||||
Xol_specials_itm[] rv = new Xol_specials_itm[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = specials_mgr.Get_at(i);
|
||||
return rv;
|
||||
}
|
||||
String Xto_str(Xow_ns[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ary[i];
|
||||
sb.Add(ns.Id()).Add("|").Add(ns.Name_db_str()).Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
Xow_ns[] To_ary(Xol_ns_grp ary) {
|
||||
int len = ary.Len();
|
||||
Xow_ns[] rv = new Xow_ns[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = ary.Get_at(i);
|
||||
return rv;
|
||||
}
|
||||
Xol_kwd_grp[] To_ary(Xol_kwd_mgr kwd_mgr) {
|
||||
int len = kwd_mgr.Len();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_kwd_grp kwd_grp = kwd_mgr.Get_at(i);
|
||||
if (kwd_grp == null) continue;
|
||||
rv.Add(kwd_grp);
|
||||
}
|
||||
return (Xol_kwd_grp[])rv.To_ary(Xol_kwd_grp.class);
|
||||
}
|
||||
String Xto_str(Xol_kwd_grp[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_kwd_grp grp = ary[i];
|
||||
sb.Add(grp.Key()).Add("|").Add(grp.Case_match() ? "1" : "0").Add("|");
|
||||
Xol_kwd_itm[] itms = grp.Itms();
|
||||
int itms_len = itms.length;
|
||||
for (int j = 0; j < itms_len; j++) {
|
||||
sb.Add(itms[i].Val()).Add(";");
|
||||
}
|
||||
sb.Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
Xol_msg_itm[] To_ary(Xol_msg_mgr msg_mgr) {
|
||||
int len = msg_mgr.Itms_max();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(i);
|
||||
if (itm == null || !itm.Dirty()) continue;
|
||||
rv.Add(itm);
|
||||
}
|
||||
return (Xol_msg_itm[])rv.To_ary(Xol_msg_itm.class);
|
||||
}
|
||||
String Xto_str(Xol_msg_itm[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xol_msg_itm itm = ary[i];
|
||||
sb.Add(itm.Key()).Add("|").Add(itm.Val()).Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
}
|
||||
private static String_bldr sb = String_bldr_.new_();
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java
Normal file
33
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_plural_ru_tst {
|
||||
@Test public void Plural() {
|
||||
Tst(1, String_.Ary_empty, null); // 0 forms
|
||||
Tst(1, String_.Ary("a", "b"), "a"); // 2 forms; singluar
|
||||
Tst(2, String_.Ary("a", "b"), "b"); // 2 forms; plural
|
||||
Tst(111, String_.Ary("a", "b", "c"), "c"); // 3 forms; (count % 100) / 10 == 0; should not return "a"
|
||||
Tst(1, String_.Ary("a", "b", "c"), "a"); // 3 forms; count % 10 == 1
|
||||
Tst(2, String_.Ary("a", "b", "c"), "b"); // 3 forms; count % 10 == (2, 3, 4)
|
||||
Tst(5, String_.Ary("a", "b", "c"), "c"); // 3 forms; count % 10 != (1, 2, 3, 4)
|
||||
Tst(5, String_.Ary("a"), "a"); // 1 form; count % 10 != (1, 2, 3, 4); but only 1 element, so take 1st
|
||||
}
|
||||
private void Tst(int count, String[] forms, String expd) {
|
||||
byte[] actl = Xol_plural_ru.Instance.Plural_eval(null, count, Bry_.Ary(forms));
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd), actl);
|
||||
}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java
Normal file
60
400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java
Normal 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import gplx.xowa.parsers.vnts.*;
|
||||
public class Xol_vnt_regy_fxt {
|
||||
private final Xol_vnt_regy mgr = new_chinese();
|
||||
public String[] Make_lang_chain_cn() {return String_.Ary("zh-cn", "zh-hans", "zh-hant", "zh");}
|
||||
public void Test_match_any(boolean expd, String[] lang_chain, String[]... vnt_chain_ary) {
|
||||
int len = vnt_chain_ary.length;
|
||||
int lang_flag = mgr.Mask__calc(Bry_.Ary(lang_chain));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String[] vnt_chain = vnt_chain_ary[i]; // EX: -{zh;zh-hans;zh-hant}-
|
||||
int vnt_flag = mgr.Mask__calc(Bry_.Ary(vnt_chain));
|
||||
Tfds.Eq(expd, mgr.Mask__match_any(vnt_flag, lang_flag), String_.Concat_with_str(";", vnt_chain) + "<>" + String_.Concat_with_str(";", lang_chain));
|
||||
}
|
||||
}
|
||||
public void Test_calc(String[] ary, int expd) {
|
||||
Tfds.Eq(expd, mgr.Mask__calc(Bry_.Ary(ary)));
|
||||
}
|
||||
public static void Init__vnt_mgr(Xol_vnt_mgr vnt_mgr, int cur_idx, String[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xol_vnt_itm itm = vnt_mgr.Regy__get_or_new(Bry_.new_a7(ary[i]));
|
||||
vnt_mgr.Lang().Lang_mgr().Get_by_or_load(itm.Key()).Fallback_bry_(Bry_.new_a7("zh-hans,zh-hant"));
|
||||
}
|
||||
vnt_mgr.Init_end();
|
||||
vnt_mgr.Cur_itm_(Bry_.new_a7(ary[cur_idx]));
|
||||
}
|
||||
public static Xol_vnt_regy new_chinese() { // REF.MW:/languages/classes/LanguageZh.php|LanguageZh|__construct
|
||||
Xol_vnt_regy rv = new Xol_vnt_regy();
|
||||
new_chinese_vnt(rv, "zh" , Xol_vnt_dir_.Tid__none, "zh-hans", "zh-hant", "zh-cn", "zh-tw", "zh-hk", "zh-sg", "zh-mo", "zh-my");
|
||||
new_chinese_vnt(rv, "zh-hans" , Xol_vnt_dir_.Tid__uni , "zh-cn", "zh-sg", "zh-my");
|
||||
new_chinese_vnt(rv, "zh-hant" , Xol_vnt_dir_.Tid__uni , "zh-tw", "zh-hk", "zh-mo");
|
||||
new_chinese_vnt(rv, "zh-cn" , Xol_vnt_dir_.Tid__bi , "zh-hans", "zh-sg", "zh-my");
|
||||
new_chinese_vnt(rv, "zh-hk" , Xol_vnt_dir_.Tid__bi , "zh-hant", "zh-mo", "zh-tw");
|
||||
new_chinese_vnt(rv, "zh-my" , Xol_vnt_dir_.Tid__bi , "zh-hans", "zh-sg", "zh-cn");
|
||||
new_chinese_vnt(rv, "zh-mo" , Xol_vnt_dir_.Tid__bi , "zh-hant", "zh-hk", "zh-tw");
|
||||
new_chinese_vnt(rv, "zh-sg" , Xol_vnt_dir_.Tid__bi , "zh-hans", "zh-cn", "zh-my");
|
||||
new_chinese_vnt(rv, "zh-tw" , Xol_vnt_dir_.Tid__bi , "zh-hant", "zh-hk", "zh-mo");
|
||||
return rv;
|
||||
}
|
||||
private static void new_chinese_vnt(Xol_vnt_regy regy, String key, int dir, String... fallbacks) {
|
||||
byte[] key_bry = Bry_.new_u8(key);
|
||||
Xol_vnt_itm itm = regy.Add(key_bry, Bry_.Ucase__all(key_bry));
|
||||
itm.Init(dir, Bry_.Ary(fallbacks));
|
||||
}
|
||||
}
|
||||
47
400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java
Normal file
47
400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_vnt_regy_tst {
|
||||
private final Xol_vnt_regy_fxt fxt = new Xol_vnt_regy_fxt();
|
||||
@Test public void Calc() {
|
||||
fxt.Test_calc(String_.Ary("zh") , 1);
|
||||
fxt.Test_calc(String_.Ary("zh", "zh-hans") , 3);
|
||||
fxt.Test_calc(String_.Ary("zh", "bad") , 1);
|
||||
}
|
||||
@Test public void Match() {
|
||||
String[] lang_chain = fxt.Make_lang_chain_cn(); // zh;zh-hans;zh-hant;zh-cn
|
||||
fxt.Test_match_any(Bool_.Y, lang_chain
|
||||
, String_.Ary("zh")
|
||||
, String_.Ary("zh-hans")
|
||||
, String_.Ary("zh-hant")
|
||||
, String_.Ary("zh-cn")
|
||||
, String_.Ary("zh", "zh-hans")
|
||||
, String_.Ary("zh-cn", "zh-hk")
|
||||
);
|
||||
fxt.Test_match_any(Bool_.N, lang_chain
|
||||
, String_.Ary_empty
|
||||
, String_.Ary("bad")
|
||||
, String_.Ary("zh-hk")
|
||||
, String_.Ary("zh-hk", "zh-sg")
|
||||
);
|
||||
}
|
||||
@Test public void Match_2() {
|
||||
fxt.Test_match_any(Bool_.Y, String_.Ary("zh-hans")
|
||||
, String_.Ary("zh", "zh-hant", "zh-hans")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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.xowa.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.drds.*;
|
||||
public class Xol_convert_regy_tst {
|
||||
private final Xol_convert_regy_fxt fxt = new Xol_convert_regy_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
// fxt.Parser_fxt().Init_page_create("Template:Test_x1", "val");
|
||||
fxt.Init_page("Template:Test_x1", "val");
|
||||
fxt.Parser_fxt().Test_parse_tmpl_str_test("{{Test_x0}}", "{{test}}", "val");
|
||||
}
|
||||
@Test public void Upper_1st() { // PURPOSE: convert should call Xoa_ttl.Parse(), which will upper 1st letter; EX:{{jez-eng|sense}} -> Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
|
||||
fxt.Init_page("Template:X1", "val");
|
||||
fxt.Parser_fxt().Test_parse_tmpl_str_test("{{x0}}", "{{test}}", "val");
|
||||
}
|
||||
@Test public void Redlink() { // PURPOSE: check redlink's Convert_ttl(Xowe_wiki wiki, Xoa_ttl ttl); DATE:2014-07-06
|
||||
fxt.Init_page("Template:Test_x1", "val");
|
||||
fxt.Test_convert_by_ttl("zh", "Template:Test_x0", Bool_.Y); // Template:Test_xo should not be parsed to Template:Template:Test_x0; EX:Шаблон:Šablon:Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
|
||||
fxt.Test_convert_by_ttl("zh", "Template:Test_x1", Bool_.N); // note that convert of trg should not find title;
|
||||
fxt.Test_convert_by_ttl("zh", "Template:Test_x2", Bool_.N); // test that non-convert characters return false
|
||||
}
|
||||
@Test public void Pfunc() {
|
||||
fxt.Parser_fxt().Init_defn_clear();
|
||||
fxt.Init_page("Test_x1", "");
|
||||
fxt.Test_parse("{{#ifexist:Test_x0|y|n}}", "y");
|
||||
}
|
||||
}
|
||||
class Xol_convert_regy_fxt {
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xop_fxt Parser_fxt() {return parser_fxt;} private Xop_fxt parser_fxt;
|
||||
public Xowd_data_tstr Data_mgr() {return data_mgr;} private final Xowd_data_tstr data_mgr = new Xowd_data_tstr();
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7("zh"));
|
||||
Xol_lang_itm_.Lang_init(lang);
|
||||
Init_cnv(app, "zh", "zh-hant", Keyval_.new_("x0", "x1"));
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app, "zh.wikipedia.org", lang);
|
||||
Xoa_test_.Init__db__edit(wiki);
|
||||
data_mgr.Wiki_(wiki);
|
||||
gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(wiki.Lang().Vnt_mgr(), 1, String_.Ary("zh", "zh-hans", "zh-hant"));
|
||||
parser_fxt = new Xop_fxt(app, wiki);
|
||||
}
|
||||
public void Init_page(String ttl, String wtxt) {Xow_data_fxt.Create(wiki, data_mgr, ttl, wtxt);}
|
||||
public static void Init_cnv(Xoae_app app, String lang_key, String vnt_key, Keyval... ary) {
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7(lang_key));
|
||||
Xol_convert_grp grp = lang.Vnt_mgr().Convert_mgr().Converter_regy().Get_or_make(Bry_.new_a7(vnt_key));
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Keyval itm = ary[i];
|
||||
grp.Add(Bry_.new_u8(itm.Key()), Bry_.new_u8(itm.Val_to_str_or_empty()));
|
||||
}
|
||||
Xol_vnt_itm vnt_itm = lang.Vnt_mgr().Regy__get_or_new(Bry_.new_a7(vnt_key));
|
||||
vnt_itm.Convert_ary_(Bry_.Ary(vnt_key));
|
||||
vnt_itm.Convert_wkr().Init(lang.Vnt_mgr().Convert_mgr().Converter_regy(), vnt_itm.Convert_ary());
|
||||
}
|
||||
public void Test_parse(String raw, String expd) {
|
||||
parser_fxt.Test_parse_page_all_str(raw, expd);
|
||||
}
|
||||
public void Test_convert_by_ttl(String lang_key, String raw, boolean expd) {
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7(lang_key));
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(raw));
|
||||
Xowd_page_itm page = lang.Vnt_mgr().Convert_mgr().Convert_ttl(wiki, ttl);
|
||||
if (expd)
|
||||
Tfds.Eq_true(page.Exists());
|
||||
else
|
||||
Tfds.Eq_null(page);
|
||||
}
|
||||
}
|
||||
class Xow_data_fxt {
|
||||
public static void Create(Xow_wiki wiki, Xowd_data_tstr tstr, String ttl_str, String wtxt) {
|
||||
tstr.Page__insert(1, ttl_str, "2015-10-19 00:01:02");
|
||||
tstr.Text__insert(1, wtxt);
|
||||
}
|
||||
}
|
||||
141
400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java
Normal file
141
400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
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.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
|
||||
import org.junit.*; import gplx.core.log_msgs.*; import gplx.langs.phps.*;
|
||||
public class Xol_mw_parse_tst {
|
||||
private final Xol_mw_parse_fxt fxt = new Xol_mw_parse_fxt();
|
||||
// @Test public void Basic() {
|
||||
// fxt.Test_convert("$zh2Hant = array('a' => 'A', 'b' => 'B',);", String_.Concat_lines_nl
|
||||
// ( "// zh_zh-hant"
|
||||
// , "app.langs.get('zh').converts.get('zh-hant').add_bulk("
|
||||
// , "<:['"
|
||||
// , "a|A"
|
||||
// , "b|B"
|
||||
// , "']:>"
|
||||
// , ");"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Run() {
|
||||
// Io_url src_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\cfg\\lang\\mediawiki\\converts\\");
|
||||
// Io_url trg_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\cfg\\lang\\");
|
||||
// fxt.Test_run(src_dir, trg_dir);
|
||||
// }
|
||||
@Test public void Ignore() {
|
||||
fxt.toString();
|
||||
}
|
||||
}
|
||||
class Xol_mw_parse_grp {
|
||||
public byte[] Lng() {return lng;} public Xol_mw_parse_grp Lng_(byte[] v) {lng = v; return this;} private byte[] lng;
|
||||
public byte[] Vnt() {return vnt;} public Xol_mw_parse_grp Vnt_(byte[] v) {vnt = v; return this;} private byte[] vnt;
|
||||
public Xol_mw_parse_itm[] Itms() {return itms;} public Xol_mw_parse_grp Itms_(Xol_mw_parse_itm[] v) {itms = v; return this;} private Xol_mw_parse_itm[] itms;
|
||||
public void Write_as_gfs(Bry_bfr bfr) {
|
||||
int itms_len = itms.length;
|
||||
Write_bgn(bfr);
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xol_mw_parse_itm itm = (Xol_mw_parse_itm)itms[i];
|
||||
Write_itm(bfr, itm);
|
||||
}
|
||||
Write_end(bfr);
|
||||
}
|
||||
private void Write_bgn(Bry_bfr bfr) {
|
||||
bfr.Add_str_a7("// ").Add(lng).Add_str_a7("_").Add(vnt).Add_byte_nl();
|
||||
bfr.Add_str_a7("app.langs.get('");
|
||||
bfr.Add(lng);
|
||||
bfr.Add_str_a7("').converts.get('");
|
||||
bfr.Add(vnt);
|
||||
bfr.Add_str_a7("').add_bulk(");
|
||||
bfr.Add_byte_nl().Add_str_a7("<:['").Add_byte_nl();
|
||||
}
|
||||
private void Write_itm(Bry_bfr bfr, Xol_mw_parse_itm itm) {
|
||||
bfr.Add(itm.Src());
|
||||
bfr.Add_byte_pipe();
|
||||
bfr.Add(itm.Trg());
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
private void Write_end(Bry_bfr bfr) {
|
||||
bfr.Add_str_a7("']:>").Add_byte_nl();
|
||||
bfr.Add_str_a7(");").Add_byte_nl();
|
||||
}
|
||||
}
|
||||
class Xol_mw_parse_itm {
|
||||
public Xol_mw_parse_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg;}
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public byte[] Trg() {return trg;} private byte[] trg;
|
||||
}
|
||||
class Xol_mw_parse_fxt {
|
||||
public void Test_convert(String mw, String expd) {
|
||||
Xol_mw_parse_grp[] actl_ary = Parse(Bry_.new_u8(mw));
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
actl_ary[0].Write_as_gfs(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str());
|
||||
}
|
||||
public void Test_run(Io_url src_dir, Io_url trg_dir) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(src_dir);
|
||||
int fils_len = fils.length;
|
||||
for (int i = 0; i < fils_len; i++) {
|
||||
Io_url fil = fils[i];
|
||||
byte[] src = Io_mgr.Instance.LoadFilBry(fil);
|
||||
Xol_mw_parse_grp[] itms = Parse(src);
|
||||
int itms_len = itms.length;
|
||||
String lang_name = String_.Lower(String_.Mid(fil.NameOnly(), 0, 2)); // ZhConversion.php -> Zh
|
||||
for (int j = 0; j < itms_len; j++) {
|
||||
Xol_mw_parse_grp itm = itms[j];
|
||||
itm.Write_as_gfs(bfr);
|
||||
}
|
||||
Io_url trg_fil = Xol_convert_regy.Bld_url(trg_dir, lang_name);
|
||||
Io_mgr.Instance.SaveFilBry(trg_fil, bfr.To_bry_and_clear());
|
||||
}
|
||||
}
|
||||
public Xol_mw_parse_grp[] Parse(byte[] src) {
|
||||
List_adp list = List_adp_.New();
|
||||
Php_parser parser = new Php_parser();
|
||||
Gfo_msg_log msg_log = new Gfo_msg_log("xowa");
|
||||
Php_evaluator evaluator = new Php_evaluator(msg_log);
|
||||
parser.Parse_tkns(src, evaluator);
|
||||
Php_line[] lines = (Php_line[])evaluator.List().To_ary(Php_line.class);
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
Php_line_assign line = (Php_line_assign)lines[i];
|
||||
Xol_mw_parse_grp grp = Parse_grp(line);
|
||||
list.Add(grp);
|
||||
}
|
||||
return (Xol_mw_parse_grp[])list.To_ary(Xol_mw_parse_grp.class);
|
||||
}
|
||||
private List_adp tmp_itm_list = List_adp_.New();
|
||||
private Xol_mw_parse_grp Parse_grp(Php_line_assign line) {
|
||||
Xol_mw_parse_grp grp = new Xol_mw_parse_grp();
|
||||
byte[] key = line.Key().Val_obj_bry(); // EX: "zh2Hant"
|
||||
key = Bry_.Lcase__all(key); // EX: "zh2hant"
|
||||
byte[][] parts = Bry_split_.Split(key, Byte_ascii.Num_2); // EX: "zh", "hant"
|
||||
byte[] src = parts[0];
|
||||
byte[] trg = Bry_.Add(parts[0], new byte[] {Byte_ascii.Dash}, parts[1]);
|
||||
grp.Lng_(src).Vnt_(trg);
|
||||
Parse_itms(line, grp);
|
||||
return grp;
|
||||
}
|
||||
private void Parse_itms(Php_line_assign line, Xol_mw_parse_grp grp) {
|
||||
Php_itm_ary ary = (Php_itm_ary)line.Val();
|
||||
tmp_itm_list.Clear();
|
||||
int subs_len = ary.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Php_itm_kv kv = (Php_itm_kv)ary.Subs_get(i);
|
||||
Xol_mw_parse_itm itm = new Xol_mw_parse_itm(kv.Key().Val_obj_bry(), kv.Val().Val_obj_bry());
|
||||
tmp_itm_list.Add(itm);
|
||||
}
|
||||
grp.Itms_((Xol_mw_parse_itm[])tmp_itm_list.To_ary(Xol_mw_parse_itm.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user