From 372cd3958d3c97b9c1a0c5629bd59f5444c7dfd0 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Sun, 1 Jul 2018 07:55:55 -0400 Subject: [PATCH] Wikibase: Fix script error 'libraryUtil.lua:13 bad argument #1 to message.newRawMessage' on sever dozen military pages --- 100_core/src/gplx/Array__tst.java | 39 + 100_core/src/gplx/Bool__tst.java | 29 + 100_core/src/gplx/Bry__tst.java | 307 +++++ 100_core/src/gplx/Bry_bfr_tst.java | 247 ++++ 100_core/src/gplx/Bry_find__tst.java | 90 ++ 100_core/src/gplx/Bry_split__tst.java | 80 ++ 100_core/src/gplx/Byte__tst.java | 33 + 100_core/src/gplx/DateAdp__tst.java | 86 ++ 100_core/src/gplx/Decimal_adp__tst.java | 86 ++ 100_core/src/gplx/Double__tst.java | 27 + 100_core/src/gplx/Err_tst.java | 45 + 100_core/src/gplx/GfoMsg_tst.java | 49 + 100_core/src/gplx/Gfo_evt_mgr_tst.java | 67 ++ 100_core/src/gplx/Guid_adp__tst.java | 26 + 100_core/src/gplx/Hash_adp_bry_tst.java | 66 ++ 100_core/src/gplx/Int__tst.java | 97 ++ 100_core/src/gplx/Int_ary__tst.java | 58 + 100_core/src/gplx/Io_mgr__tst.java | 98 ++ 100_core/src/gplx/Io_url__tst.java | 30 + 100_core/src/gplx/List_adp_tst.java | 220 ++++ 100_core/src/gplx/Long__tst.java | 47 + 100_core/src/gplx/Math__tst.java | 59 + 100_core/src/gplx/Object__tst.java | 34 + 100_core/src/gplx/Ordered_hash_tst.java | 37 + 100_core/src/gplx/String__tst.java | 182 +++ 100_core/src/gplx/TfdsTstr_fxt.java | 97 ++ .../src/gplx/core/brys/Bry_bfr_mkr_tst.java | 55 + 100_core/src/gplx/core/brys/Bry_rdr_tst.java | 54 + .../core/brys/args/Bfr_arg__time_tst.java | 40 + .../gplx/core/brys/fmtrs/Bry_fmtr_tst.java | 72 ++ .../src/gplx/core/brys/fmts/Bry_fmt_tst.java | 50 + .../core/brys/fmts/Bry_keys_parser_tst.java | 30 + .../gplx/core/btries/Btrie_bwd_mgr_tst.java | 85 ++ .../gplx/core/btries/Btrie_fast_mgr_tst.java | 83 ++ .../gplx/core/btries/Btrie_slim_itm_tst.java | 47 + .../gplx/core/btries/Btrie_slim_mgr_tst.java | 109 ++ .../core/criterias/Criteria_ioItm_tst.java | 48 + .../src/gplx/core/criterias/Criteria_tst.java | 90 ++ .../src/gplx/core/encoders/B85_fp__tst.java | 29 + .../src/gplx/core/encoders/Base85__tst.java | 59 + .../src/gplx/core/encoders/Hex_utl__tst.java | 89 ++ .../src/gplx/core/envs/Process_adp_tst.java | 30 + .../core/gfo_regys/GfoRegy_RegDir_tst.java | 59 + .../core/gfo_regys/GfoRegy_basic_tst.java | 29 + .../gplx/core/interfaces/SrlAble__tst.java | 64 + 100_core/src/gplx/core/intls/Utf16__tst.java | 58 + 100_core/src/gplx/core/intls/Utf8__tst.java | 67 ++ 100_core/src/gplx/core/ios/IoItm_fxt.java | 32 + 100_core/src/gplx/core/ios/IoZipWkr_tst.java | 26 + .../gplx/core/ios/Io_download_fmt_tst.java | 71 ++ 100_core/src/gplx/core/ios/Io_size__tst.java | 83 ++ .../core/ios/streams/IoStream_mem_tst.java | 28 + .../core/ios/streams/IoStream_mock_tst.java | 46 + .../core/ios/streams/Io_stream_rdr__tst.java | 54 + .../gplx/core/ios/zips/Io_zip_mgr_mok.java | 34 + .../gplx/core/ios/zips/Io_zip_mgr_tst.java | 29 + 100_core/src/gplx/core/js/Js_wtr_tst.java | 39 + .../gplx/core/lists/List_adp_sorter_tst.java | 35 + .../src/gplx/core/lists/StackAdp_tst.java | 31 + .../core/lists/rings/Ring__long__tst.java | 39 + .../core/lists/rings/Ring__string__tst.java | 44 + .../gplx/core/log_msgs/Gfo_msg_root_tst.java | 60 + .../gplx/core/primitives/EnmParser_tst.java | 58 + .../core/security/Hash_algo__md5__tst.java | 39 + .../core/security/Hash_algo__sha1__tst.java | 31 + .../security/Hash_algo__sha2_256__tst.java | 31 + .../security/Hash_algo__tth_192__tst.java | 34 + .../security/Hash_algo__tth_192_tree_tst.java | 63 + .../core/security/Hash_console_wtr_tst.java | 39 + .../src/gplx/core/tests/PerfLogMgr_fxt.java | 64 + .../gplx/core/texts/BaseXXConverter_tst.java | 56 + .../src/gplx/core/texts/CharStream_tst.java | 59 + .../core/texts/RegxPatn_cls_ioMatch_tst.java | 56 + .../core/texts/RegxPatn_cls_like_tst.java | 84 ++ .../gplx/core/texts/StringTableBldr_tst.java | 57 + .../poolables/Gfo_poolable_mgr_tst.java | 81 ++ .../gplx/core/times/DateAdp_parser_tst.java | 32 + .../gplx/core/times/Time_span__basic_tst.java | 85 ++ .../gplx/core/times/Time_span__parse_tst.java | 52 + .../core/times/Time_span__to_str_tst.java | 57 + .../core/type_xtns/DateAdpClassXtn_tst.java | 26 + .../langs/dsvs/DsvDataRdr_csv_dat_tst.java | 214 ++++ .../langs/dsvs/DsvDataRdr_dsv_dat_tst.java | 68 ++ .../langs/dsvs/DsvDataRdr_dsv_hdr_tst.java | 80 ++ .../langs/dsvs/DsvDataRdr_dsv_misc_tst.java | 74 ++ .../langs/dsvs/DsvDataRdr_layout_tst.java | 129 +++ .../gplx/langs/dsvs/DsvDataWtr_csv_tst.java | 98 ++ .../gplx/langs/dsvs/DsvDataWtr_tbls_tst.java | 71 ++ 100_core/src/gplx/langs/gfs/Gfs_Date_tst.java | 40 + .../src/gplx/langs/regxs/Regx_adp__tst.java | 91 ++ .../src/gplx/langs/xmls/HierStrBldr_tst.java | 45 + 100_core/src/gplx/langs/xmls/XmlDoc_tst.java | 69 ++ .../gplx/langs/xmls/XmlFileSplitter_tst.java | 86 ++ 100_core/src/gplx/langs/xmls/Xpath__tst.java | 42 + 100_core/tst/gplx/GfoMsg_rdr_tst.java | 55 + 100_core/tst/gplx/GfoTreeBldr_fxt.java | 30 + .../ios/IoEngine_dir_basic_memory_tst.java | 22 + .../ios/IoEngine_dir_basic_system_tst.java | 26 + .../ios/IoEngine_dir_deep_memory_tst.java | 34 + .../ios/IoEngine_dir_deep_system_tst.java | 23 + .../ios/IoEngine_fil_basic_memory_tst.java | 55 + .../ios/IoEngine_fil_basic_system_tst.java | 56 + .../ios/IoEngine_fil_xfer_memory_tst.java | 26 + .../ios/IoEngine_fil_xfer_system_tst.java | 26 + .../core/ios/IoEngine_stream_xfer_tst.java | 47 + .../core/ios/IoEngine_xrg_queryDir_tst.java | 63 + .../core/ios/IoEngine_xrg_recycleFil_tst.java | 30 + .../ios/IoItmDir_FetchDeepOrNull_tst.java | 38 + .../gplx/core/ios/IoUrlInfo_alias_tst.java | 56 + 100_core/tst/gplx/core/ios/IoUrl_lnx_tst.java | 53 + 100_core/tst/gplx/core/ios/IoUrl_map_tst.java | 29 + 100_core/tst/gplx/core/ios/IoUrl_wnt_tst.java | 96 ++ .../gplx/core/stores/GfoNdeRdr_read_tst.java | 46 + .../tst/gplx/core/stores/GfoNdeRdr_tst.java | 187 +++ .../gplx/core/stores/xmls/XmlDataRdr_tst.java | 100 ++ .../gplx/core/stores/xmls/XmlDataWtr_tst.java | 93 ++ 110_gfml/tst/gplx/gfml/GfmlDataRdr_tst.java | 118 ++ .../tst/gplx/gfml/yfxts_GfmlParse_fxt.java | 77 ++ .../gplx/gfml/yfxts_GfmlTypeCompiler_fxt.java | 100 ++ .../gplx/gfml/ymoks_GfmlAtr_GfmlNde_mok.java | 180 +++ 110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java | 75 ++ .../gplx/gfml/ymoks_GfmlTyp_GfmlFld_mok.java | 81 ++ 110_gfml/tst/gplx/gfml/ymoks_UsrMsg_mok.java | 34 + .../tst/gplx/gfml/z011_IntObjHash_tst.java | 61 + 110_gfml/tst/gplx/gfml/z012_GfmlTrie_tst.java | 71 ++ .../tst/gplx/gfml/z015_GfmlDocPos_tst.java | 50 + .../tst/gplx/gfml/z016_GfmlScopeList_tst.java | 53 + .../gfml/z017_GfmlStringHighlighter_tst.java | 51 + .../gplx/gfml/z051_GfmlFldPool_keyed_tst.java | 75 ++ .../tst/gplx/gfml/z081_GfmlDataWtr_tst.java | 69 ++ .../gplx/gfml/z082_GfmlDataWtrOpts_tst.java | 52 + .../tst/gplx/gfml/z091_GfmlLxr_basic_tst.java | 66 ++ .../gplx/gfml/z101_core_ndeInline_tst.java | 48 + .../gplx/gfml/z102_core_whitespace_tst.java | 77 ++ .../tst/gplx/gfml/z103_core_elmKey_tst.java | 50 + .../tst/gplx/gfml/z111_core_comment0_tst.java | 49 + .../tst/gplx/gfml/z112_core_comment1_tst.java | 67 ++ .../tst/gplx/gfml/z120_quotes_eval0_tst.java | 39 + .../gplx/gfml/z121_quotes_quotes0_tst.java | 50 + .../gfml/z122_quotes_quote0_eval0_tst.java | 62 + .../gplx/gfml/z123_quotes_quoteBlock_tst.java | 38 + .../gplx/gfml/z124_quotes_quoteFold_tst.java | 59 + .../tst/gplx/gfml/z151_ndeSubs_basic_tst.java | 63 + .../tst/gplx/gfml/z152_ndeSubs_data_tst.java | 66 ++ .../gplx/gfml/z161_ndeHdrs_inline_tst.java | 44 + .../tst/gplx/gfml/z162_ndeHdrs_err_tst.java | 31 + .../tst/gplx/gfml/z163_ndeHdrs_body_tst.java | 50 + .../tst/gplx/gfml/z164_hdeHdrs_data_tst.java | 51 + .../tst/gplx/gfml/z181_ndeDots_basic_tst.java | 63 + .../tst/gplx/gfml/z182_ndeDots_subs_tst.java | 71 ++ .../gplx/gfml/z183_ndeDots_parens_tst.java | 138 +++ .../gplx/gfml/z184_ndeDots_atrSpr_tst.java | 45 + .../gplx/gfml/z191_ndeProps_basic_tst.java | 118 ++ .../tst/gplx/gfml/z192_ndeProps_dots_tst.java | 37 + .../tst/gplx/gfml/z400_GfmlTypeMakr_tst.java | 64 + .../gfml/z401_types_compile_basic_tst.java | 63 + .../gfml/z402_types_compile_implicit_tst.java | 61 + .../gfml/z403_types_compile_default_tst.java | 62 + .../gfml/z411_types_apply_atrs_basic_tst.java | 64 + .../gfml/z421_types_apply_ndes_basic_tst.java | 50 + .../gfml/z422_types_apply_ndes_multi_tst.java | 72 ++ .../gfml/z423_types_apply_ndes_misc_tst.java | 47 + .../gfml/z424_types_apply_ndes_nest_tst.java | 65 ++ .../gplx/gfml/z441_types_parse_basic_tst.java | 51 + .../gfml/z442_types_parse_default_tst.java | 99 ++ .../gplx/gfml/z443_types_parse_keyd_tst.java | 48 + .../gfml/z450_fx_GfmlDefaultItem_fxt.java | 39 + .../tst/gplx/gfml/z451_dflts_compile_tst.java | 44 + .../tst/gplx/gfml/z452_dflts_exec_tst.java | 94 ++ .../tst/gplx/gfml/z455_dflts_scope_tst.java | 47 + .../tst/gplx/gfml/z456_dflts_parse_tst.java | 33 + .../tst/gplx/gfml/z481_vars_compile_tst.java | 33 + .../tst/gplx/gfml/z482_vars_parse_tst.java | 83 ++ .../tst/gplx/gfml/z501_lxr_parse_tst.java | 86 ++ 110_gfml/tst/gplx/gfml/z601_edit_atr_tst.java | 128 ++ 110_gfml/tst/gplx/gfml/z602_edit_nde_tst.java | 22 + .../gplx/gfml/z801_useCase_DataRdr_tst.java | 79 ++ .../gfml/z803_useCase_KbdKeyboard_tst.java | 85 ++ .../gplx/gfml/z811_useCase_GfmlIoSql_tst.java | 48 + 110_gfml/tst/gplx/gfml/z901_perf_tst.java | 115 ++ .../src/gplx/core/stores/DbMaprMgr_tst.java | 138 +++ 140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java | 57 + 140_dbs/src/gplx/dbs/Db_conn_info_tst.java | 46 + 140_dbs/src/gplx/dbs/Db_crt_tst.java | 50 + 140_dbs/src/gplx/dbs/Db_qry_fxt.java | 65 ++ .../dbs/diffs/builds/Gfdb_diff_bldr_tst.java | 105 ++ .../cmds/Gfdb_diff_cmd_sql_bldr_tst.java | 69 ++ .../src/gplx/dbs/engines/mems/Mem_db_fxt.java | 72 ++ .../dbs/engines/mems/Mem_exec_select_tst.java | 128 ++ .../dbs/engines/tdbs/TdbConnectInfo_tst.java | 30 + .../dbs/engines/tdbs/TdbDbLoadMgr_tst.java | 99 ++ .../dbs/engines/tdbs/TdbDbSaveMgr_tst.java | 75 ++ .../gplx/dbs/engines/tdbs/TdbFlush_tst.java | 117 ++ .../metas/parsers/Dbmeta_parser__fld_tst.java | 72 ++ .../metas/parsers/Dbmeta_parser__idx_tst.java | 35 + .../metas/parsers/Dbmeta_parser__tbl_tst.java | 63 + .../dbs/metas/parsers/Sql_bry_rdr_tst.java | 50 + 140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java | 42 + .../src/gplx/dbs/qrys/Db_qry_select_tst.java | 87 ++ 140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java | 46 + .../src/gplx/dbs/qrys/Db_stmt_sql_tst.java | 27 + .../gplx/dbs/sqls/itms/Db_obj_ary_tst.java | 42 + .../gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java | 34 + .../gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java | 31 + .../dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java | 97 ++ .../sqls/wtrs/Sql_qry_wtr__iosql__tst.java | 59 + .../dbs/sqls/wtrs/Sql_schema_wtr_tst.java | 66 ++ .../dbs/sqls/wtrs/Sql_select_wtr_tst.java | 26 + .../gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java | 37 + .../gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java | 53 + 140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java | 32 + .../src/gplx/dbs/utls/Db_cmd_backup_tst.java | 29 + 140_dbs/src/gplx/dbs/utls/PoolIds_tst.java | 54 + 140_dbs/tst/gplx/dbs/Db_conn_fxt.java | 53 + .../tst/gplx/dbs/engines/db_CrudOps_tst.java | 127 ++ .../gplx/dbs/engines/db_DataTypes_tst.java | 77 ++ .../gplx/dbs/groupBys/GroupBys_base_tst.java | 93 ++ .../gplx/dbs/groupBys/GroupBys_mysql_tst.java | 26 + .../gplx/dbs/groupBys/GroupBys_tdb_tst.java | 27 + .../dbs/insertIntos/InsertIntos_base_tst.java | 58 + .../insertIntos/InsertIntos_mysql_tst.java | 22 + .../dbs/insertIntos/InsertIntos_tdb_tst.java | 22 + .../tst/gplx/dbs/joins/Joins_base_tst.java | 42 + 140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java | 29 + .../gplx/dbs/orderBys/OrderBys_base_tst.java | 50 + .../gplx/dbs/orderBys/OrderBys_tdb_tst.java | 36 + .../gplx/gfui/controls/GfuiBorderMgr_tst.java | 51 + .../controls/customs/GfuiMoveElemBtn_tst.java | 33 + .../standards/Gfui_tab_itm_data_tst.java | 30 + .../gplx/gfui/controls/tabs/TabBox_tst.java | 129 +++ .../windows/GfuiFocusOrderer_tst.java | 85 ++ .../src/gplx/gfui/draws/ColorAdp__tst.java | 56 + .../src/gplx/gfui/envs/ClipboardAdp__tst.java | 24 + .../src/gplx/gfui/envs/ScreenAdp_tst.java | 27 + 150_gfui/src/gplx/gfui/imgs/ImageAdp_tst.java | 46 + .../gplx/gfui/ipts/GfuiClickKeyMgr_tst.java | 29 + .../gplx/gfui/ipts/IptArgChainMgr_tst.java | 60 + .../src/gplx/gfui/ipts/IptArg_parser_tst.java | 61 + .../src/gplx/gfui/ipts/IptBndMgr_tst.java | 70 ++ 150_gfui/src/gplx/gfui/ipts/IptCfg_tst.java | 82 ++ .../src/gplx/gfui/ipts/IptEventType_tst.java | 32 + .../src/gplx/gfui/ipts/IptKeyStrMgr_tst.java | 57 + 150_gfui/src/gplx/gfui/ipts/IptKey__tst.java | 37 + .../src/gplx/gfui/layouts/GftBand_tst.java | 110 ++ 400_xowa/src/gplx/core/brys/Bit__tst.java | 66 ++ .../src/gplx/core/brys/Bit_heap_rdr_tst.java | 78 ++ .../src/gplx/core/brys/Bit_heap_wtr_tst.java | 84 ++ 400_xowa/src/gplx/core/brys/Bry_diff_tst.java | 42 + .../gplx/core/brys/Int_flag_bldr__tst.java | 72 ++ .../core/brys/evals/Bry_eval_mgr__tst.java | 50 + .../gplx/core/btries/Btrie_u8_mgr_tst.java | 94 ++ .../gplx/core/caches/Gfo_cache_mgr_tst.java | 71 ++ .../core/consoles/Gfo_cmd_arg_mgr_tst.java | 121 ++ .../src/gplx/core/flds/Gfo_fld_rdr_tst.java | 54 + .../gplx/core/gfobjs/Gfobj_rdr__json_tst.java | 86 ++ .../gplx/core/gfobjs/Gfobj_wtr__json_fxt.java | 52 + .../gplx/core/gfobjs/Gfobj_wtr__json_tst.java | 153 +++ .../core/intls/String_surrogate_utl_tst.java | 55 + .../core/ios/BinaryHeap_Io_line_rdr_tst.java | 48 + .../src/gplx/core/ios/Io_buffer_rdr_tst.java | 62 + .../src/gplx/core/ios/Io_line_rdr_tst.java | 94 ++ .../src/gplx/core/ios/Io_sort_misc_tst.java | 56 + 400_xowa/src/gplx/core/ios/Io_sort_tst.java | 64 + .../src/gplx/core/lists/Queue_adp_tst.java | 59 + 400_xowa/src/gplx/core/lists/StatRng_tst.java | 37 + .../binary_searches/Binary_search__tst.java | 53 + .../src/gplx/core/net/Gfo_url_parser_fxt.java | 54 + .../src/gplx/core/net/Gfo_url_parser_tst.java | 126 ++ .../core/net/Http_request_parser_tst.java | 93 ++ .../primitives/Gfo_number_parser_tst.java | 107 ++ .../core/primitives/Int_ary_parser_tst.java | 28 + .../gplx/core/primitives/Int_pool_tst.java | 73 ++ .../core/progs/rates/Gfo_rate_list_tst.java | 34 + .../core/security/files/Cksum_list_tst.java | 48 + .../src/gplx/dbs/bulks/Db_tbl_copy_tst.java | 37 + .../metas/updates/Schema_update_mgr_tst.java | 53 + .../dbs/percentiles/Percentile_rng_tst.java | 61 + .../src/gplx/fsdb/data/Fsd_thm_tbl_tst.java | 56 + .../src/gplx/gfui/Gfui_bnd_parser_tst.java | 62 + .../langs/dsvs/Dsv_tbl_parser_int_tst.java | 62 + .../langs/dsvs/Dsv_tbl_parser_str_tst.java | 107 ++ .../src/gplx/langs/gfs/Gfs_msg_bldr_tst.java | 74 ++ .../src/gplx/langs/gfs/Gfs_parser_tst.java | 194 ++++ .../src/gplx/langs/htmls/Gfh_parser_tst.java | 51 + .../gplx/langs/htmls/Gfh_utl__basic__tst.java | 56 + .../langs/htmls/Gfh_utl__comments__tst.java | 24 + .../langs/htmls/clses/Gfh_class__tst.java | 56 + .../htmls/clses/Gfh_class_parser__tst.java | 42 + .../langs/htmls/docs/Gfh_tag_rdr_tst.java | 78 ++ .../htmls/encoders/Gfo_url_encoder_tst.java | 69 ++ .../htmls/styles/Gfh_style_parser__tst.java | 49 + .../src/gplx/langs/jsons/Json_doc_tst.java | 44 + .../gplx/langs/jsons/Json_kv_ary_srl_tst.java | 48 + .../src/gplx/langs/jsons/Json_parser_tst.java | 98 ++ .../gplx/langs/jsons/Json_printer_tst.java | 86 ++ .../src/gplx/langs/jsons/Json_wtr_tst.java | 132 +++ .../mustaches/Mustache_itm_render_tst.java | 162 +++ .../mustaches/Mustache_tkn_parser_tst.java | 37 + .../src/gplx/langs/phps/Php_parser_fxt.java | 290 +++++ .../src/gplx/langs/phps/Php_parser_tst.java | 82 ++ .../gplx/langs/phps/Php_srl_parser_tst.java | 110 ++ .../src/gplx/langs/phps/Php_text_itm_tst.java | 51 + .../src/gplx/langs/regxs/Gfo_pattern_tst.java | 91 ++ .../src/gplx/langs/xmls/Gfo_xml_wtr_tst.java | 79 ++ 400_xowa/src/gplx/xowa/Xoa_app_fxt.java | 105 ++ 400_xowa/src/gplx/xowa/Xoae_page__tst.java | 42 + 400_xowa/src/gplx/xowa/Xop_fxt.java | 485 ++++++++ .../mgrs/caches/Xocfg_cache_mgr__tst.java | 78 ++ .../services/Xocfg_maint_parser__tst.java | 43 + .../cfgs/upgrades/Xocfg_upgrade_mgr__tst.java | 56 + .../scripts/apis/Xoscript_doc_head__tst.java | 72 ++ .../specials/svcs/Xoa_update_svc__tst.java | 35 + .../bldrs/app_cfgs/Xob_wiki_cfg_bldr_tst.java | 177 +++ .../centrals/hosts/Host_eval_wkr__tst.java | 30 + .../bldrs/centrals/utils/Time_dhms__tst.java | 35 + .../packs/files/Pack_zip_name_bldr__tst.java | 39 + .../files/cmds/Xobldr__image__create_tst.java | 49 + .../cmds/Xobldr__lnki_temp__create__tst.java | 41 + .../apis/Xowmf_imageinfo_item__tst.java | 41 + .../files/utls/Xob_xfer_temp_itm_tst.java | 190 +++ .../bldrs/infos/Xobc_info_html__tst.java | 27 + .../bldrs/volumes/Volume_prep_rdr_tst.java | 38 + .../htmls/sidebars/Xoh_sidebar_mgr_tst.java | 235 ++++ .../htmls/tocs/Xoh_toc_htmlr__basic__tst.java | 175 +++ .../tocs/Xoh_toc_wkr__lvl__basic__tst.java | 64 + .../tocs/Xoh_toc_wkr__txt__basic__tst.java | 84 ++ .../tocs/Xoh_toc_wkr__txt__dupe__tst.java | 40 + .../tocs/Xoh_toc_wkr__txt__xnde__tst.java | 46 + .../addons/htmls/tocs/Xowe_hdr_bldr__tst.java | 547 +++++++++ .../addons/htmls/tocs/Xowe_hdr_bldr_fxt.java | 69 ++ .../mediawikis/Xop_mediawiki_wkr__tst.java | 54 + .../Xoctg_catpage_mgr__basic__tst.java | 311 +++++ .../Xoctg_catpage_mgr__navlink__tst.java | 57 + .../dbs/Xoctg_catlink_loader__tst.java | 37 + .../langs/Xoctg_collation_wkr___tst.java | 39 + .../catpages/urls/Xoctg_catpage_url__tst.java | 45 + .../doubles/Xoctg_double_box__tst.java | 83 ++ .../singles/Xoctg_single_box__tst.java | 60 + .../dbs/Xowdir_wiki_props_mgr__tst.java | 70 ++ .../core/Xofulltext_extractor__tst.java | 45 + .../Xofulltext_finder_cbk__eval__tst.java | 122 ++ .../htmls/css/mgrs/Xowd_css_core_mgr_tst.java | 118 ++ .../specials/Rndm_root_special_tst.java | 54 + .../core/loaders/Xosync_page_loader__fxt.java | 50 + .../core/loaders/Xosync_page_loader__tst.java | 39 + .../parsers/Xosync_hdoc_parser__err__tst.java | 45 + .../Xosync_hdoc_parser__file__tst.java | 56 + .../core/parsers/Xosync_hdoc_parser__fxt.java | 69 ++ .../Xosync_hdoc_parser__misc__tst.java | 26 + .../core/parsers/Xosync_hdoc_parser__tst.java | 39 + .../parsers/Srch_highlight_mgr_tst.java | 45 + .../searchs/parsers/Srch_text_parser_tst.java | 145 +++ .../searchers/Srch_search_phrase_tst.java | 46 + .../searchers/crts/Srch_crt_parser_tst.java | 66 ++ .../searchers/crts/Srch_crt_scanner_tst.java | 83 ++ .../searchers/crts/Srch_crt_sql_tst.java | 38 + .../searchers/wkrs/Srch_link_wkr_sql_tst.java | 37 + .../searchers/wkrs/Srch_page_tbl_wkr_tst.java | 45 + .../specials/Srch_special_searcher_tst.java | 221 ++++ .../htmls/Srch_html_page_bldr_tst.java | 83 ++ .../specials/htmls/Srch_rslt_cbk_tst.java | 64 + .../src/gplx/xowa/apps/Xoa_app_eval_tst.java | 40 + .../src/gplx/xowa/apps/Xoa_shell_tst.java | 28 + .../addons/bldrs/Xopg_match_mgr__tst.java | 68 ++ .../xowa/apps/cfgs/Xowc_xtn_pages_tst.java | 70 ++ .../xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java | 40 + .../xowa/apps/fsys/Xoa_url_finder_tst.java | 64 + .../gfs/Gfs_php_converter__to_gfs__tst.java | 53 + .../gfs/Gfs_php_converter__to_php__tst.java | 28 + .../servers/http/Http_server_wkr__tst.java | 40 + .../apps/servers/tcp/Xosrv_msg_rdr_tst.java | 63 + .../apps/servers/tcp/Xosrv_server_tst.java | 38 + .../xowa/apps/setups/Xoa_setup_mgr_tst.java | 34 + .../apps/site_cfgs/Xoa_site_cfg_mgr_tst.java | 178 +++ .../xowa/apps/urls/Xoa_url__basic__tst.java | 30 + .../xowa/apps/urls/Xoa_url__to_str__tst.java | 54 + .../xowa/apps/urls/Xoav_url_parser_tst.java | 41 + .../apps/urls/Xow_url_parser__proto_tst.java | 40 + .../apps/urls/Xow_url_parser__qarg__tst.java | 62 + .../apps/urls/Xow_url_parser__ttl_tst.java | 54 + .../urls/Xow_url_parser__url_bar_tst.java | 66 ++ .../apps/urls/Xow_url_parser__wiki_tst.java | 39 + .../apps/urls/Xow_url_parser__xcmd_tst.java | 29 + .../apps/urls/Xow_url_parser__xwiki_tst.java | 78 ++ .../xowa/apps/urls/Xow_url_parser_fxt.java | 81 ++ .../xowa/apps/utls/Xoa_url_encoder__tst.java | 29 + .../xowa/apps/versions/Xoa_version_tst.java | 35 + .../wms/apis/origs/Xoapi_orig_base_tst.java | 60 + .../apps/wms/apis/origs/Xoapi_orig_mok.java | 34 + 400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java | 92 ++ .../src/gplx/xowa/bldrs/Xob_base_fxt.java | 77 ++ 400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java | 154 +++ .../cmds/texts/tdbs/Xob_init_base_tst.java | 41 + .../texts/xmls/Xob_siteinfo_parser__tst.java | 108 ++ .../css/Xoa_css_extractor_basic_tst.java | 77 ++ .../xowa/bldrs/css/Xoa_css_extractor_fxt.java | 71 ++ .../bldrs/css/Xoa_css_extractor_wiki_tst.java | 44 + .../bldrs/css/Xoa_css_img_downloader_tst.java | 181 +++ .../bldrs/css/Xob_css_parser__import_tst.java | 36 + .../bldrs/css/Xob_css_parser__url_tst.java | 58 + .../xowa/bldrs/css/Xob_mirror_mgr_tst.java | 61 + .../xowa/bldrs/css/Xob_url_fixer_tst.java | 40 + .../core/Xob_ttl_filter_mgr_srl_tst.java | 52 + .../filters/core/Xob_ttl_filter_mgr_tst.java | 49 + .../dansguardians/Dg_match_mgr_tst.java | 56 + .../filters/dansguardians/Dg_parser_tst.java | 55 + .../bldrs/installs/Xoi_cmd_dumpfile_tst.java | 74 ++ .../xowa/bldrs/installs/Xoi_cmd_wiki_tst.java | 128 ++ .../bldrs/installs/Xoi_mirror_parser_tst.java | 58 + .../addons/Xoi_firefox_installer_tst.java | 41 + .../maints/Wmf_dump_list_parser_tst.java | 135 +++ .../setups/maints/Wmf_latest_parser_tst.java | 51 + .../setups/upgrades/Xoa_upgrade_mgr_tst.java | 31 + .../sql_dumps/Xosql_dump_parser__tst.java | 88 ++ .../sql_dumps/Xosql_tbl_parser__tst.java | 84 ++ .../wiki_cfgs/Xoi_wiki_props_api_tst.java | 140 +++ .../gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java | 41 + .../Xowmf_wiki_dump_dirs_parser_tst.java | 66 ++ .../bldrs/wms/dumps/Xowm_dump_file_tst.java | 43 + .../bldrs/wms/dumps/Xowm_dump_type__tst.java | 27 + .../wms/revs/Xowm_rev_wkr__meta__wm_tst.java | 81 ++ .../bldrs/wms/sites/Site_json_parser_tst.java | 429 +++++++ .../xowa/bldrs/xmls/Xob_xml_dumper_tst.java | 100 ++ .../xowa/bldrs/xmls/Xob_xml_parser_tst.java | 146 +++ 400_xowa/src/gplx/xowa/drds/Xod_app_tst.java | 71 ++ .../src/gplx/xowa/files/Xof_file_fxt.java | 48 + .../gplx/xowa/files/Xof_file_wkr__tst.java | 31 + .../src/gplx/xowa/files/Xof_fsdb_itm_fxt.java | 79 ++ .../src/gplx/xowa/files/Xof_img_size_tst.java | 105 ++ .../gplx/xowa/files/Xof_url_bldr__tst.java | 65 ++ .../src/gplx/xowa/files/Xof_xfer_itm_tst.java | 63 + .../gplx/xowa/files/Xofv_file_mgr_tst.java | 184 +++ .../bins/Xof_bin_wkr__http_wmf__tst.java | 65 ++ .../xowa/files/caches/Xof_cache_mgr_tst.java | 70 ++ .../xowa/files/caches/Xou_cache_mgr_tst.java | 112 ++ .../xowa/files/caches/Xou_cache_tbl_tst.java | 59 + .../cnvs/Xof_img_wkr_resize_img_mok.java | 30 + .../files/fsdb/fs_roots/Fs_root_wkr_tst.java | 82 ++ .../fsdb/tsts/Xof_file_ext__bmp_tst.java | 31 + .../fsdb/tsts/Xof_file_ext__flac_tst.java | 33 + .../fsdb/tsts/Xof_file_ext__oga_tst.java | 33 + .../fsdb/tsts/Xof_file_ext__ogg_tst.java | 35 + .../fsdb/tsts/Xof_file_ext__ogv_tst.java | 34 + .../fsdb/tsts/Xof_file_ext__pdf_tst.java | 27 + .../fsdb/tsts/Xof_file_ext__png_tst.java | 61 + .../fsdb/tsts/Xof_file_ext__svg_tst.java | 38 + .../fsdb/tsts/Xof_file_ext__unknown_tst.java | 33 + .../fsdb/tsts/Xof_file_ext__wav_tst.java | 34 + .../fsdb/tsts/Xof_file_ext__xcf_tst.java | 33 + .../xowa/files/fsdb/tsts/Xof_file_fxt.java | 190 +++ .../fsdb/tsts/Xof_file_redirect_tst.java | 64 + .../xowa/files/origs/Xof_orig_tbl_tst.java | 74 ++ .../xowa/files/repos/Xof_repo_itm__tst.java | 56 + .../files/xfers/Xof_xfer_queue_base_fxt.java | 113 ++ .../xfers/Xof_xfer_queue_html_basic_tst.java | 132 +++ .../xfers/Xof_xfer_queue_html_cases_tst.java | 288 +++++ .../files/xfers/Xof_xfer_queue_html_fxt.java | 60 + .../Xof_xfer_queue_html_offline_tst.java | 28 + .../Xof_xfer_queue_html_wmf_api_tst.java | 171 +++ .../swts/Gfobj_wtr__json__browser__tst.java | 39 + .../guis/history/Xog_history_stack_tst.java | 83 ++ .../guis/urls/Xog_url_wkr__file__tst.java | 66 ++ .../gplx/xowa/guis/urls/Xog_url_wkr__tst.java | 46 + .../url_macros/Xog_url_macro_mgr_tst.java | 54 + .../url_box_fmts/Xog_urlfmtr_mgr_tst.java | 62 + .../gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java | 45 + .../gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java | 74 ++ .../htmls/bridges/Bridge_msg_bldr_tst.java | 31 + .../dbuis/fmtrs/Dbui_tbl_fmtr_tst.java | 39 + .../htmls/core/htmls/Xoh_html_wtr_tst.java | 348 ++++++ .../core/htmls/tidy/Xoh_tidy_mgr_tst.java | 90 ++ .../htmls/tidy/Xoh_tidy_wkr_jtidy_tst.java | 63 + .../core/hzips/Gfo_decimal_parser_tst.java | 44 + .../htmls/core/hzips/Xoh_hzip_int__tst.java | 46 + .../htmls/core/hzips/Xoh_hzip_int_tst.java | 84 ++ .../htmls/core/makes/tests/Xoh_make_fxt.java | 53 + .../xowa/htmls/core/wkrs/Xoh_hzip_fxt.java | 115 ++ .../htmls/core/wkrs/Xoh_itm_parser_fxt.java | 47 + .../addons/gallerys/Xoh_gallery_hzip_tst.java | 27 + .../addons/medias/Xoh_media_hzip_tst.java | 93 ++ .../timelines/Xoh_timeline_hzip_tst.java | 24 + .../wkrs/escapes/Xoh_escape_hzip_tst.java | 29 + .../wkrs/glys/Xoh_gly_html__dump__tst.java | 104 ++ .../wkrs/glys/Xoh_gly_hzip__basic__tst.java | 179 +++ .../wkrs/glys/Xoh_gly_hzip__caption__tst.java | 122 ++ .../wkrs/glys/Xoh_gly_hzip__style__tst.java | 142 +++ .../core/wkrs/glys/Xoh_gly_itm_wtr_tst.java | 52 + .../core/wkrs/hdrs/Xoh_hdr_html_tst.java | 47 + .../core/wkrs/hdrs/Xoh_hdr_hzip_tst.java | 106 ++ .../core/wkrs/hdrs/Xoh_hdr_make_tst.java | 47 + .../wkrs/imgs/Xoh_img_bare_hzip__tst.java | 47 + .../wkrs/imgs/Xoh_img_html__dump__tst.java | 51 + .../imgs/Xoh_img_hzip__dump__basic__tst.java | 108 ++ .../imgs/Xoh_img_hzip__dump__link__tst.java | 117 ++ .../imgs/Xoh_img_hzip__dump__orig__tst.java | 71 ++ .../imgs/Xoh_img_hzip__dump__pgbnr__tst.java | 33 + .../wkrs/imgs/Xoh_img_hzip__view__tst.java | 34 + .../wkrs/imgs/Xoh_img_make__dump__tst.java | 60 + .../core/wkrs/imgs/atrs/Xoh_img_cls__tst.java | 32 + .../wkrs/imgs/atrs/Xoh_img_src_data_tst.java | 66 ++ .../wkrs/lnkes/Xoh_lnke_html__basic__tst.java | 44 + .../wkrs/lnkes/Xoh_lnke_html__hdump__tst.java | 28 + .../core/wkrs/lnkes/Xoh_lnke_hzip_tst.java | 63 + .../wkrs/lnkis/Xoh_lnki_html__basic__tst.java | 25 + .../wkrs/lnkis/Xoh_lnki_html__hdump__tst.java | 32 + .../wkrs/lnkis/Xoh_lnki_hzip__anch__tst.java | 38 + .../wkrs/lnkis/Xoh_lnki_hzip__diff__tst.java | 35 + .../wkrs/lnkis/Xoh_lnki_hzip__ns__tst.java | 84 ++ .../wkrs/lnkis/Xoh_lnki_hzip__same__tst.java | 52 + .../wkrs/lnkis/Xoh_lnki_hzip__site__tst.java | 82 ++ .../lnkis/anchs/Xoh_anch_capt_itm_tst.java | 50 + .../lnkis/anchs/Xoh_anch_href_data_tst.java | 60 + .../lnkis/htmls/Xoh_file_wtr__audio__tst.java | 102 ++ .../Xoh_file_wtr__image__basic__tst.java | 378 ++++++ .../htmls/Xoh_file_wtr__image__link__tst.java | 53 + .../lnkis/htmls/Xoh_file_wtr__media__tst.java | 61 + .../lnkis/htmls/Xoh_file_wtr__video__tst.java | 130 +++ .../lnkis/htmls/Xoh_lnki_title_bldr_tst.java | 41 + .../core/wkrs/thms/Xoh_thm_html_tst.java | 64 + .../wkrs/thms/Xoh_thm_hzip__avo__tst.java | 64 + .../wkrs/thms/Xoh_thm_hzip__basic__tst.java | 122 ++ .../wkrs/thms/Xoh_thm_hzip__pseudo__tst.java | 141 +++ .../wkrs/thms/Xoh_thm_hzip__tidy__tst.java | 91 ++ .../core/wkrs/tocs/Xoh_toc_hzip_tst.java | 23 + .../wkrs/xndes/Xoh_xnde_hzip_nde__tst.java | 27 + .../wkrs/xndes/dicts/Xoh_xnde_dict__tst.java | 76 ++ .../src/gplx/xowa/htmls/doms/Xoh_dom_tst.java | 43 + .../xowa/htmls/heads/Xoh_head_mgr_tst.java | 146 +++ .../xowa/htmls/heads/Xoh_head_wtr_tst.java | 61 + .../htmls/heads/Xow_fragment_mgr_tst.java | 55 + .../htmls/hrefs/Xoh_href_gui_utl_tst.java | 66 ++ .../hrefs/Xoh_href_parser__basic__tst.java | 94 ++ .../hrefs/Xoh_href_parser__qargs__tst.java | 36 + .../hrefs/Xoh_href_parser__wiki__tst.java | 48 + .../xowa/htmls/hrefs/Xoh_href_wtr_tst.java | 57 + .../gplx/xowa/htmls/js/Xoh_js_cbk_tst.java | 44 + .../htmls/js/Xoh_js_cbk_wdata_labels_tst.java | 61 + .../xowa/htmls/js/Xoh_js_cleaner_tst.java | 40 + .../Xow_popup_anchor_finder__hdr_tst.java | 83 ++ .../Xow_popup_anchor_finder__id_tst.java | 48 + .../modules/popups/Xow_popup_parser_tst.java | 520 +++++++++ .../keeplists/Xop_keeplist_wiki_tst.java | 59 + .../ns_files/Xoh_ns_file_page_mgr_tst.java | 129 +++ .../htmls/portal/Xoh_page_body_cls_tst.java | 52 + .../xowa/htmls/portal/Xoh_rtl_utl_tst.java | 62 + .../htmls/portal/Xoh_subpages_bldr_tst.java | 47 + .../xowa/htmls/portal/Xow_portal_mgr_tst.java | 72 ++ .../portal/vnts/Vnt_mnu_grp_fmtr_tst.java | 65 ++ .../xowa/langs/bldrs/Xob_i18n_parser_tst.java | 62 + .../langs/bldrs/Xobc_utl_make_lang_tst.java | 178 +++ .../langs/bldrs/Xol_mw_lang_parser_tst.java | 315 +++++ .../xowa/langs/cases/Xol_case_mgr_tst.java | 156 +++ .../langs/kwds/Xol_kwd_parse_data_tst.java | 36 + .../lnki_trails/Xol_lnki_trail_mgr_tst.java | 41 + .../gplx/xowa/langs/msgs/Xol_msg_itm_tst.java | 37 + .../gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java | 68 ++ .../langs/msgs/Xow_mainpage_finder_tst.java | 71 ++ .../langs/numbers/Xol_num_fmtr_base_tst.java | 116 ++ .../langs/numbers/Xol_num_grp_fmtr_tst.java | 52 + .../langs/parsers/Xol_csv_parser_tst.java | 39 + .../xowa/langs/parsers/Xol_lang_srl_tst.java | 346 ++++++ .../xowa/langs/plurals/Xol_plural_ru_tst.java | 33 + .../xowa/langs/vnts/Xol_vnt_regy_fxt.java | 60 + .../xowa/langs/vnts/Xol_vnt_regy_tst.java | 47 + .../vnts/converts/Xol_convert_regy_tst.java | 91 ++ .../langs/vnts/converts/Xol_mw_parse_tst.java | 141 +++ .../src/gplx/xowa/parsers/Xop_ctx__tst.java | 31 + .../gplx/xowa/parsers/Xop_parser__tst.java | 56 + .../amps/Xop_amp_mgr__decode__tst.java | 62 + .../amps/Xop_amp_mgr__parse_tkn__tst.java | 25 + .../xowa/parsers/amps/Xop_amp_wkr_tst.java | 35 + .../xowa/parsers/apos/Xop_apos_wkr_tst.java | 151 +++ .../parsers/hdrs/Xop_hdr_wkr__basic_tst.java | 125 ++ .../parsers/hdrs/Xop_hdr_wkr__para_tst.java | 24 + .../Xop_section_list__merge__tst.java | 177 +++ .../Xop_section_list__slice__tst.java | 160 +++ .../xowa/parsers/htmls/Mwh_atr_mgr_tst.java | 37 + .../parsers/htmls/Mwh_atr_parser_fxt.java | 74 ++ .../parsers/htmls/Mwh_atr_parser_tst.java | 76 ++ .../parsers/htmls/Mwh_doc_parser_fxt.java | 73 ++ .../parsers/htmls/Mwh_doc_parser_tst.java | 59 + .../parsers/lists/HierPosAryBldr_tst.java | 63 + .../parsers/lists/Xop_list_wkr_basic_tst.java | 351 ++++++ .../parsers/lists/Xop_list_wkr_para_tst.java | 86 ++ .../lists/Xop_list_wkr_uncommon_tst.java | 407 +++++++ .../parsers/lnkes/Xop_lnke_wkr_brack_tst.java | 92 ++ .../lnkes/Xop_lnke_wkr_dangling_tst.java | 37 + .../lnkes/Xop_lnke_wkr_relative_tst.java | 40 + .../parsers/lnkes/Xop_lnke_wkr_text_tst.java | 97 ++ .../lnkes/Xop_lnke_wkr_uncommon_tst.java | 47 + .../parsers/lnkes/Xop_lnke_wkr_xwiki_tst.java | 61 + .../lnkis/Xop_lnki_wkr__basic_tst.java | 315 +++++ .../parsers/lnkis/Xop_lnki_wkr__ctg_tst.java | 130 +++ .../lnkis/Xop_lnki_wkr__frame_tst.java | 23 + .../lnkis/Xop_lnki_wkr__invalid_tst.java | 95 ++ .../lnkis/Xop_lnki_wkr__link__basic__tst.java | 81 ++ .../lnkis/Xop_lnki_wkr__link__xwiki__tst.java | 102 ++ .../parsers/lnkis/Xop_lnki_wkr__pre_tst.java | 102 ++ .../parsers/lnkis/Xop_lnki_wkr__size_tst.java | 61 + .../lnkis/Xop_lnki_wkr__subpage_tst.java | 66 ++ .../lnkis/Xop_lnki_wkr__uncommon_tst.java | 58 + .../lnkis/Xop_lnki_wkr__video_tst.java | 29 + .../lnkis/Xop_lnki_wkr__xwiki_tst.java | 113 ++ .../xowa/parsers/miscs/Xop_comm_lxr_tst.java | 100 ++ .../parsers/miscs/Xop_hr_lxr_basic_tst.java | 29 + .../parsers/miscs/Xop_hr_lxr_para_tst.java | 52 + .../xowa/parsers/miscs/Xop_space_lxr_tst.java | 30 + .../xowa/parsers/miscs/Xop_under_lxr_tst.java | 226 ++++ .../parsers/paras/Xop_nl_tab_lxr_tst.java | 63 + .../parsers/paras/Xop_para_wkr_basic_tst.java | 1026 +++++++++++++++++ .../parsers/paras/Xop_para_wkr_para_tst.java | 107 ++ .../parsers/paras/Xop_para_wkr_pre_tst.java | 258 +++++ .../parsers/tblws/Xop_tblw_wkr__atrs_tst.java | 210 ++++ .../tblws/Xop_tblw_wkr__basic_tst.java | 814 +++++++++++++ .../tblws/Xop_tblw_wkr__dangling_tst.java | 55 + .../tblws/Xop_tblw_wkr__double_pipe_tst.java | 106 ++ .../parsers/tblws/Xop_tblw_wkr__errs_tst.java | 92 ++ .../tblws/Xop_tblw_wkr__nested_tst.java | 163 +++ .../parsers/tblws/Xop_tblw_wkr__para_tst.java | 175 +++ .../parsers/tblws/Xop_tblw_wkr__tblx_tst.java | 152 +++ .../tblws/Xop_tblw_wkr__uncommon_tst.java | 127 ++ .../xowa/parsers/tmpls/Xop_subst_tst.java | 74 ++ .../xowa/parsers/tmpls/Xop_tkn_print_tst.java | 38 + .../tmpls/Xot_defn_trace_brief_tst.java | 56 + .../parsers/tmpls/Xot_defn_trace_dbg_tst.java | 47 + .../xowa/parsers/tmpls/Xot_examples_tst.java | 129 +++ .../parsers/tmpls/Xot_invk_sandbox_tst.java | 46 + .../tmpls/Xot_invk_wkr__basic__tst.java | 438 +++++++ .../tmpls/Xot_invk_wkr__missing__tst.java | 45 + .../tmpls/Xot_invk_wkr__prepend_nl__tst.java | 119 ++ .../tmpls/Xot_invk_wkr__raw_msg__tst.java | 47 + .../tmpls/Xot_invk_wkr__transclude__tst.java | 54 + .../xowa/parsers/tmpls/Xot_prm_tkn_tst.java | 55 + .../uniqs/Xop_uniq_mgr__parse__tst.java | 26 + .../xowa/parsers/uniqs/Xop_uniq_mgr__tst.java | 79 ++ .../gplx/xowa/parsers/utils/TstObj_tst.java | 231 ++++ .../parsers/utils/Xop_redirect_mgr_tst.java | 84 ++ .../xowa/parsers/utils/Xop_sanitizer_tst.java | 41 + .../vnts/Vnt_convert_lang__html__tst.java | 100 ++ .../vnts/Vnt_convert_lang__syntax__tst.java | 81 ++ .../parsers/vnts/Vnt_convert_lang_fxt.java | 54 + .../parsers/vnts/Vnt_flag_parser_tst.java | 54 + .../vnts/Vnt_rule_parser__bidi_tst.java | 25 + .../vnts/Vnt_rule_parser__undi_tst.java | 22 + .../parsers/vnts/Vnt_rule_parser_fxt.java | 35 + .../xndes/Xop_xatr_whitelist_mgr_tst.java | 73 ++ .../xndes/Xop_xnde_wkr__basic_tst.java | 151 +++ .../xndes/Xop_xnde_wkr__blockquote_tst.java | 58 + .../xndes/Xop_xnde_wkr__err_dangling_tst.java | 204 ++++ .../Xop_xnde_wkr__err_malformed_tst.java | 72 ++ .../xndes/Xop_xnde_wkr__err_misc_tst.java | 194 ++++ .../Xop_xnde_wkr__include_basic_tst.java | 81 ++ .../Xop_xnde_wkr__include_uncommon_tst.java | 192 +++ .../parsers/xndes/Xop_xnde_wkr__li_tst.java | 102 ++ .../xndes/Xop_xnde_wkr__nowiki_tst.java | 142 +++ .../parsers/xndes/Xop_xnde_wkr__tblx_tst.java | 78 ++ .../xndes/Xop_xnde_wkr__text_block_tst.java | 77 ++ .../parsers/xndes/Xop_xnde_wkr__tidy_tst.java | 44 + .../xndes/Xop_xnde_wkr__xatrs_tst.java | 58 + .../allPages/Xows_page_allpages_tst.java | 204 ++++ .../xowa/specials/nearby/Nearby_mgr_tst.java | 75 ++ .../statistics/Xop_statistics_page_tst.java | 53 + .../src/gplx/xowa/users/Xou_user_tst.java | 42 + .../xowa/users/data/Xoud_opt_scope_tst.java | 50 + .../users/history/Xou_history_mgr_tst.java | 98 ++ .../users/wikis/Xofs_url_itm_parser_tst.java | 51 + .../xowa/wikis/data/Xow_data_mgr_tst.java | 162 +++ .../wikis/data/tbls/Xowd_page_itm_tst.java | 40 + .../wikis/data/tbls/Xowd_page_tbl_tst.java | 33 + .../xowa/wikis/domains/Xow_abrv_wm_tst.java | 94 ++ .../xowa/wikis/domains/Xow_abrv_xo__tst.java | 41 + .../wikis/domains/Xow_domain_itm_tst.java | 53 + .../wikis/domains/Xow_domain_uid__tst.java | 35 + .../gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java | 77 ++ .../src/gplx/xowa/wikis/nss/Xow_ns_tst.java | 61 + .../redirects/Xopg_redirect_mgr__tst.java | 51 + .../xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java | 36 + .../wikis/tdbs/hives/Xob_hive_mgr_tst.java | 27 + .../wikis/tdbs/hives/Xow_hive_mgr_fxt.java | 111 ++ .../wikis/tdbs/hives/Xowd_hive_mgr_tst.java | 97 ++ .../wikis/tdbs/hives/Xowd_regy_mgr__tst.java | 35 + .../wikis/tdbs/hives/Xowd_regy_mgr_tst.java | 86 ++ .../wikis/tdbs/metas/Xof_meta_fil_tst.java | 27 + .../wikis/tdbs/metas/Xof_meta_mgr_tst.java | 94 ++ .../tdbs/metas/Xof_meta_thumb_parser_tst.java | 48 + .../wikis/tdbs/utils/Xos_url_gen_tst.java | 30 + .../wikis/tdbs/xdats/Xob_xdat_file_tst.java | 116 ++ .../tdbs/xdats/Xob_xdat_file_wtr_tst.java | 52 + .../xowa/wikis/ttls/Xoa_ttl__err_tst.java | 31 + .../src/gplx/xowa/wikis/ttls/Xoa_ttl_fxt.java | 33 + .../xowa/wikis/ttls/Xow_ttl__anchor_tst.java | 41 + .../xowa/wikis/ttls/Xow_ttl__basic_tst.java | 59 + .../wikis/ttls/Xow_ttl__html_entity_tst.java | 27 + .../xowa/wikis/ttls/Xow_ttl__i18n_tst.java | 52 + .../xowa/wikis/ttls/Xow_ttl__qarg_tst.java | 29 + .../gplx/xowa/wikis/ttls/Xow_ttl__ws_tst.java | 27 + .../xowa/wikis/ttls/Xow_ttl__xwik_tst.java | 40 + .../src/gplx/xowa/wikis/ttls/Xow_ttl_fxt.java | 87 ++ .../xowa/wikis/xwikis/Xow_xwiki_itm_tst.java | 47 + .../xwikis/bldrs/Xow_xwiki_itm_bldr_tst.java | 36 + .../parsers/Xow_xwiki_itm_parser_tst.java | 95 ++ .../xwikis/parsers/Xow_xwiki_mgr_tst.java | 145 +++ .../Xoa_sitelink_mgr_parser_tst.java | 67 ++ .../htmls/Xoa_sitelink_div_wtr_fxt.java | 60 + .../htmls/Xoa_sitelink_div_wtr_tst.java | 98 ++ .../assessments/Assessment_func__tst.java | 23 + .../Xtn_categoryList_nde_tst.java | 22 + .../categorytrees/Categorytree_func_tst.java | 23 + .../xowa/xtns/cites/Ref_itm_mgr_cfg_tst.java | 33 + .../gplx/xowa/xtns/cites/Ref_itm_mgr_tst.java | 81 ++ .../xtns/cites/References_nde_basic_tst.java | 200 ++++ .../xtns/cites/References_nde_group_tst.java | 120 ++ .../xtns/cites/References_nde_pre_tst.java | 65 ++ .../xtns/cites/References_nde_rare_tst.java | 106 ++ .../xtns/dynamicPageList/Dpl_xnde_tst.java | 361 ++++++ .../Pages_using_pending_changes_func_tst.java | 23 + .../Pending_change_level_func_tst.java | 23 + .../scribunto/Flagged_revs_lib_tst.java | 35 + .../gallery/Gallery_mgr_base__basic__tst.java | 185 +++ .../gallery/Gallery_mgr_base__xatrs__tst.java | 63 + .../xowa/xtns/gallery/Gallery_parser_tst.java | 112 ++ .../xowa/xtns/gallery/Gallery_xnde_tst.java | 180 +++ .../xtns/geoCrumbs/Geoc_isin_func_tst.java | 33 + .../geodata/Geo_coordinates_func_tst.java | 22 + .../gplx/xowa/xtns/graphs/Json_fmtr_tst.java | 70 ++ .../xowa/xtns/hieros/Hiero_html_mgr_fxt.java | 54 + .../xowa/xtns/hieros/Hiero_html_mgr_tst.java | 387 +++++++ .../hieros/Hiero_mw_tables_parser_tst.java | 73 ++ .../xowa/xtns/hieros/Hiero_parser_tst.java | 57 + .../gplx/xowa/xtns/imaps/Imap_base_fxt.java | 45 + .../gplx/xowa/xtns/imaps/Imap_parser_tst.java | 75 ++ .../imaps/htmls/Imap_html__hdump__tst.java | 46 + .../imaps/htmls/Imap_html__hview__tst.java | 206 ++++ .../xtns/imaps/htmls/Imap_shapes_arg_tst.java | 31 + .../indicators/Indicator_html_bldr_tst.java | 64 + .../xtns/indicators/Indicator_xnde_tst.java | 23 + .../xtns/inputBox/Xtn_inputbox_nde_tst.java | 23 + .../xowa/xtns/insiders/Insider_func_tst.java | 36 + .../xtns/insiders/Insider_html_bldr_tst.java | 60 + .../scribunto/Jscfg_scrib_lib_tst.java | 173 +++ .../kartographers/Mapframe_xnde__tst.java | 29 + .../xtns/kartographers/Maplink_xnde__tst.java | 29 + .../xtns/listings/Listing_xnde_basic_tst.java | 106 ++ .../listings/Listing_xnde_template_tst.java | 141 +++ .../gplx/xowa/xtns/lst/Lst_pfunc_lst_tst.java | 136 +++ .../xowa/xtns/lst/Lst_pfunc_lsth_tst.java | 130 +++ .../xowa/xtns/lst/Lst_pfunc_lstx_tst.java | 33 + .../xowa/xtns/lst/Lst_section_nde_tst.java | 29 + .../xtns/mapSources/Map_dd2dms_func_tst.java | 24 + .../xtns/mapSources/Map_deg2dd_func_tst.java | 25 + .../xtns/mapSources/Map_geolink_func_tst.java | 33 + .../massMessage/Message_target_func_tst.java | 23 + .../gplx/xowa/xtns/math/Xomath_core__tst.java | 51 + .../xowa/xtns/math/Xomath_subst_mgr__tst.java | 25 + .../xtns/math/texvcs/Texvc_checker_tst.java | 54 + .../xtns/math/texvcs/Texvc_parser_tst.java | 139 +++ .../New_window_link_func_tst.java | 24 + .../xowa/xtns/pagebanners/Pgbnr_func_tst.java | 84 ++ .../xtns/pfuncs/exprs/Pfunc_expr_tst.java | 114 ++ .../xowa/xtns/pfuncs/ifs/Pfunc_if_tst.java | 43 + .../xowa/xtns/pfuncs/ifs/Pfunc_ifeq_tst.java | 46 + .../xtns/pfuncs/ifs/Pfunc_iferror_tst.java | 28 + .../xtns/pfuncs/ifs/Pfunc_ifexist_tst.java | 47 + .../xtns/pfuncs/ifs/Pfunc_ifexpr_tst.java | 29 + .../xtns/pfuncs/ifs/Pfunc_switch_tst.java | 89 ++ .../xtns/pfuncs/langs/Pfunc_gender_tst.java | 29 + .../xtns/pfuncs/langs/Pfunc_grammar_tst.java | 63 + .../xtns/pfuncs/langs/Pfunc_i18n_tst.java | 54 + .../xowa/xtns/pfuncs/langs/Pfunc_int_tst.java | 114 ++ .../xtns/pfuncs/langs/Pfunc_language_tst.java | 28 + .../xtns/pfuncs/langs/Pfunc_plural_tst.java | 25 + .../pfuncs/numbers/Pf_formatnum_de_tst.java | 36 + .../pfuncs/numbers/Pf_formatnum_en_tst.java | 45 + .../pfuncs/numbers/Pf_formatnum_es_tst.java | 36 + .../pfuncs/numbers/Pf_formatnum_fa_tst.java | 54 + .../pfuncs/pages/Pfunc_displaytitle_tst.java | 47 + .../xtns/pfuncs/pages/Pfunc_misc_tst.java | 22 + .../pfuncs/pages/Pfunc_rev_props_tst.java | 29 + .../pfuncs/scribunto/Pfunc_scrib_lib_tst.java | 35 + .../xtns/pfuncs/strings/Pfunc_case_tst.java | 38 + .../xtns/pfuncs/strings/Pfunc_pad_tst.java | 32 + .../xtns/pfuncs/strings/Pfunc_tag_tst.java | 56 + .../pfuncs/stringutils/Pfunc_count_tst.java | 23 + .../pfuncs/stringutils/Pfunc_explode_tst.java | 26 + .../pfuncs/stringutils/Pfunc_len_tst.java | 24 + .../pfuncs/stringutils/Pfunc_pos_tst.java | 24 + .../pfuncs/stringutils/Pfunc_replace_tst.java | 25 + .../pfuncs/stringutils/Pfunc_rpos_tst.java | 24 + .../pfuncs/stringutils/Pfunc_sub_tst.java | 27 + .../stringutils/Pfunc_urldecode_tst.java | 21 + .../pfuncs/times/Pft_func_date_lcl_tst.java | 35 + .../pfuncs/times/Pft_func_date_rev_tst.java | 28 + .../pfuncs/times/Pft_func_date_utc_tst.java | 36 + .../pfuncs/times/Pft_func_formatdate_tst.java | 36 + .../times/Pft_func_time__basic__tst.java | 100 ++ .../times/Pft_func_time__hebrew__tst.java | 33 + .../pfuncs/times/Pft_func_time__int__tst.java | 22 + .../times/Pft_func_time__other__tst.java | 51 + .../times/Pft_func_time__uncommon__tst.java | 25 + .../times/Pft_func_time_foreign_fxt.java | 41 + .../xtns/pfuncs/times/Pxd_parser_tst.java | 103 ++ .../pfuncs/ttls/Pfunc_anchorencode_tst.java | 33 + .../xtns/pfuncs/ttls/Pfunc_filepath_tst.java | 64 + .../xowa/xtns/pfuncs/ttls/Pfunc_ns_tst.java | 35 + .../xtns/pfuncs/ttls/Pfunc_rel2abs_tst.java | 66 ++ .../pfuncs/ttls/Pfunc_titleparts_tst.java | 79 ++ .../xowa/xtns/pfuncs/ttls/Pfunc_ttl_tst.java | 49 + .../xtns/pfuncs/ttls/Pfunc_urlencode_tst.java | 28 + .../xtns/pfuncs/ttls/Pfunc_urlfunc_tst.java | 40 + .../wikis/Pfunc_pagesincategory_tst.java | 64 + .../pfuncs/wikis/Pfunc_wiki_props_tst.java | 37 + .../pfuncs/wikis/Pfunc_wiki_stats_tst.java | 30 + .../gplx/xowa/xtns/poems/Poem_nde_tst.java | 278 +++++ .../proofreadPage/Pp_pagelist_nde_tst.java | 23 + .../proofreadPage/Pp_pagequality_nde_tst.java | 23 + .../proofreadPage/Pp_pages_nde_basic_tst.java | 126 ++ .../proofreadPage/Pp_pages_nde_hdr_tst.java | 155 +++ .../proofreadPage/Pp_pages_nde_index_tst.java | 234 ++++ .../Pp_pages_nde_recursion_tst.java | 40 + .../gplx/xowa/xtns/quiz/Quiz_xnde_tst.java | 23 + .../relatedArticles/Articles_func_tst.java | 48 + .../relatedSites/Sites_html_bldr_tst.java | 67 ++ .../src/gplx/xowa/xtns/rss/Rss_xnde_tst.java | 25 + .../gplx/xowa/xtns/scores/Score_xnde_tst.java | 23 + .../xowa/xtns/scribunto/Scrib_core_fxt.java | 147 +++ .../xowa/xtns/scribunto/Scrib_core_tst.java | 115 ++ .../scribunto/Scrib_err_filter_mgr_tst.java | 48 + .../xtns/scribunto/Scrib_fsys_mgr_tst.java | 60 + .../xtns/scribunto/Scrib_invoke_func_fxt.java | 241 ++++ .../engines/luaj/Luaj_value__tst.java | 63 + .../engines/mocks/Mock_proc_fxt.java | 42 + .../engines/mocks/Mock_scrib_fxt.java | 100 ++ .../engines/process/Process_send_wtr_tst.java | 40 + .../process/Process_stream_rdr_tst.java | 77 ++ .../scribunto/libs/Scrib_lib_language.java | 15 +- .../libs/Scrib_lib_language_tst.java | 161 +++ .../scribunto/libs/Scrib_lib_message_tst.java | 74 ++ .../libs/Scrib_lib_mw__invoke_tst.java | 135 +++ .../scribunto/libs/Scrib_lib_mw__lib_tst.java | 113 ++ .../scribunto/libs/Scrib_lib_site_tst.java | 190 +++ .../libs/Scrib_lib_text__nowiki_util_tst.java | 55 + .../libs/Scrib_lib_text_json_tst.java | 321 ++++++ .../scribunto/libs/Scrib_lib_text_tst.java | 35 + .../scribunto/libs/Scrib_lib_title_tst.java | 166 +++ .../scribunto/libs/Scrib_lib_uri_tst.java | 41 + .../libs/Scrib_lib_ustring__find__tst.java | 52 + .../libs/Scrib_lib_ustring__gmatch__tst.java | 51 + .../libs/Scrib_lib_ustring__gsub__tst.java | 134 +++ .../libs/Scrib_lib_ustring__match__tst.java | 49 + .../Scrib_lib_ustring__shell_cmd__tst.java | 69 ++ .../scribunto/libs/Scrib_lib_wikibase.java | 6 +- .../libs/Scrib_lib_wikibase_entity_tst.java | 44 + .../libs/Scrib_lib_wikibase_srl_tst.java | 486 ++++++++ .../libs/Scrib_lib_wikibase_tst.java | 222 ++++ .../libs/Scrib_regx_converter_tst.java | 67 ++ .../xtns/scribunto/libs/Xow_wiki_tst.java | 39 + .../scribunto/procs/Scrib_proc_args__tst.java | 47 + .../syntax_highlights/Int_rng_mgr_tst.java | 44 + .../syntax_highlights/Synh_xtn_nde_tst.java | 172 +++ .../Xtn_templateData_nde_tst.java | 23 + .../Blacklist_scrib_lib_tst.java | 27 + .../translates/Xop_languages_xnde_tst.java | 72 ++ .../translates/Xop_mylanguage_page_tst.java | 56 + .../translates/Xop_translate_xnde_tst.java | 26 + .../xtns/translates/Xop_tvar_lxr_tst.java | 30 + .../xowa/xtns/wbases/Wdata_wiki_mgr_fxt.java | 178 +++ .../xowa/xtns/wbases/Wdata_wiki_mgr_tst.java | 74 ++ .../xtns/wbases/Wdata_xwiki_link_wtr_tst.java | 138 +++ .../wbases/claims/Wbase_claim_grp_tst.java | 71 ++ .../claims/itms/times/Wbase_date_tst.java | 90 ++ .../xtns/wbases/dbs/Wbase_qid_tbl_tst.java | 46 + .../xtns/wbases/hwtrs/Wdata_hwtr_mgr_tst.java | 326 ++++++ .../hwtrs/Wdata_visitor__html_wtr_tst.java | 101 ++ .../imports/Xob_wdata_pid_base_tst.java | 74 ++ .../wbases/imports/Xob_wdata_pid_sql_tst.java | 91 ++ .../imports/Xob_wdata_qid_base_tst.java | 173 +++ .../client/config/WikibaseClientDefault.java | 47 + ...ikibaseLanguageIndependentLuaBindings.java | 6 +- .../parsers/Wdata_doc_parser_v1_tst.java | 185 +++ .../Wdata_doc_parser_v2__basic__tst.java | 258 +++++ .../Wdata_doc_parser_v2__claims__tst.java | 191 +++ .../Wdata_pf_noExternalLangLinks_tst.java | 62 + .../pfuncs/Wdata_pf_property__basic__tst.java | 141 +++ .../pfuncs/Wdata_pf_property__parse__tst.java | 52 + .../Wdata_pf_statements__basic__tst.java | 31 + .../pfuncs/Wdata_pf_wbreponame_tst.java | 34 + .../specials/Wdata_itemByTitle_page_tst.java | 74 ++ .../wbases/stores/Wbase_doc_mgr__tst.java | 31 + .../wikias/Random_selection_xnde_tst.java | 45 + .../xowa/xtns/wikias/Tabber_xnde_tst.java | 68 ++ .../xowa/xtns/wikias/Tabview_xnde_tst.java | 40 + .../xowa/xtns/xowa_cmds/Xop_xowa_cmd_tst.java | 93 ++ .../xtns/xowa_cmds/Xop_xowa_func_tst.java | 29 + .../xtns/xowa_cmds/Xox_xowa_html_cmd_tst.java | 55 + .../gplx/xowa/mediawiki/Xophp_ary_tst.java | 137 +++ .../JsonConfig/includes/JCSingleton_tst.java | 66 ++ .../parsers/Xomw_regex_parser__tst.java | 40 + .../Xomw_doubleunder_wkr__tst.java | 50 + .../headings/Xomw_heading_wkr__tst.java | 39 + .../parsers/hrs/Xomw_hr_wkr__tst.java | 34 + .../parsers/lnkes/Xomw_lnke_wkr__tst.java | 71 ++ .../lnkis/Xomw_lnki_wkr__file__tst.java | 132 +++ .../lnkis/Xomw_lnki_wkr__text__tst.java | 27 + .../magiclinks/Xomw_magiclinks_wkr__tst.java | 86 ++ .../parsers/nbsps/Xomw_nbsp_wkr__tst.java | 38 + .../parsers/prepros/Xomw_prepro_wkr__tst.java | 233 ++++ .../parsers/quotes/Xomw_quote_wkr__tst.java | 43 + .../parsers/tables/Xomw_table_wkr__tst.java | 132 +++ 908 files changed, 70356 insertions(+), 14 deletions(-) create mode 100644 100_core/src/gplx/Array__tst.java create mode 100644 100_core/src/gplx/Bool__tst.java create mode 100644 100_core/src/gplx/Bry__tst.java create mode 100644 100_core/src/gplx/Bry_bfr_tst.java create mode 100644 100_core/src/gplx/Bry_find__tst.java create mode 100644 100_core/src/gplx/Bry_split__tst.java create mode 100644 100_core/src/gplx/Byte__tst.java create mode 100644 100_core/src/gplx/DateAdp__tst.java create mode 100644 100_core/src/gplx/Decimal_adp__tst.java create mode 100644 100_core/src/gplx/Double__tst.java create mode 100644 100_core/src/gplx/Err_tst.java create mode 100644 100_core/src/gplx/GfoMsg_tst.java create mode 100644 100_core/src/gplx/Gfo_evt_mgr_tst.java create mode 100644 100_core/src/gplx/Guid_adp__tst.java create mode 100644 100_core/src/gplx/Hash_adp_bry_tst.java create mode 100644 100_core/src/gplx/Int__tst.java create mode 100644 100_core/src/gplx/Int_ary__tst.java create mode 100644 100_core/src/gplx/Io_mgr__tst.java create mode 100644 100_core/src/gplx/Io_url__tst.java create mode 100644 100_core/src/gplx/List_adp_tst.java create mode 100644 100_core/src/gplx/Long__tst.java create mode 100644 100_core/src/gplx/Math__tst.java create mode 100644 100_core/src/gplx/Object__tst.java create mode 100644 100_core/src/gplx/Ordered_hash_tst.java create mode 100644 100_core/src/gplx/String__tst.java create mode 100644 100_core/src/gplx/TfdsTstr_fxt.java create mode 100644 100_core/src/gplx/core/brys/Bry_bfr_mkr_tst.java create mode 100644 100_core/src/gplx/core/brys/Bry_rdr_tst.java create mode 100644 100_core/src/gplx/core/brys/args/Bfr_arg__time_tst.java create mode 100644 100_core/src/gplx/core/brys/fmtrs/Bry_fmtr_tst.java create mode 100644 100_core/src/gplx/core/brys/fmts/Bry_fmt_tst.java create mode 100644 100_core/src/gplx/core/brys/fmts/Bry_keys_parser_tst.java create mode 100644 100_core/src/gplx/core/btries/Btrie_bwd_mgr_tst.java create mode 100644 100_core/src/gplx/core/btries/Btrie_fast_mgr_tst.java create mode 100644 100_core/src/gplx/core/btries/Btrie_slim_itm_tst.java create mode 100644 100_core/src/gplx/core/btries/Btrie_slim_mgr_tst.java create mode 100644 100_core/src/gplx/core/criterias/Criteria_ioItm_tst.java create mode 100644 100_core/src/gplx/core/criterias/Criteria_tst.java create mode 100644 100_core/src/gplx/core/encoders/B85_fp__tst.java create mode 100644 100_core/src/gplx/core/encoders/Base85__tst.java create mode 100644 100_core/src/gplx/core/encoders/Hex_utl__tst.java create mode 100644 100_core/src/gplx/core/envs/Process_adp_tst.java create mode 100644 100_core/src/gplx/core/gfo_regys/GfoRegy_RegDir_tst.java create mode 100644 100_core/src/gplx/core/gfo_regys/GfoRegy_basic_tst.java create mode 100644 100_core/src/gplx/core/interfaces/SrlAble__tst.java create mode 100644 100_core/src/gplx/core/intls/Utf16__tst.java create mode 100644 100_core/src/gplx/core/intls/Utf8__tst.java create mode 100644 100_core/src/gplx/core/ios/IoItm_fxt.java create mode 100644 100_core/src/gplx/core/ios/IoZipWkr_tst.java create mode 100644 100_core/src/gplx/core/ios/Io_download_fmt_tst.java create mode 100644 100_core/src/gplx/core/ios/Io_size__tst.java create mode 100644 100_core/src/gplx/core/ios/streams/IoStream_mem_tst.java create mode 100644 100_core/src/gplx/core/ios/streams/IoStream_mock_tst.java create mode 100644 100_core/src/gplx/core/ios/streams/Io_stream_rdr__tst.java create mode 100644 100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java create mode 100644 100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java create mode 100644 100_core/src/gplx/core/js/Js_wtr_tst.java create mode 100644 100_core/src/gplx/core/lists/List_adp_sorter_tst.java create mode 100644 100_core/src/gplx/core/lists/StackAdp_tst.java create mode 100644 100_core/src/gplx/core/lists/rings/Ring__long__tst.java create mode 100644 100_core/src/gplx/core/lists/rings/Ring__string__tst.java create mode 100644 100_core/src/gplx/core/log_msgs/Gfo_msg_root_tst.java create mode 100644 100_core/src/gplx/core/primitives/EnmParser_tst.java create mode 100644 100_core/src/gplx/core/security/Hash_algo__md5__tst.java create mode 100644 100_core/src/gplx/core/security/Hash_algo__sha1__tst.java create mode 100644 100_core/src/gplx/core/security/Hash_algo__sha2_256__tst.java create mode 100644 100_core/src/gplx/core/security/Hash_algo__tth_192__tst.java create mode 100644 100_core/src/gplx/core/security/Hash_algo__tth_192_tree_tst.java create mode 100644 100_core/src/gplx/core/security/Hash_console_wtr_tst.java create mode 100644 100_core/src/gplx/core/tests/PerfLogMgr_fxt.java create mode 100644 100_core/src/gplx/core/texts/BaseXXConverter_tst.java create mode 100644 100_core/src/gplx/core/texts/CharStream_tst.java create mode 100644 100_core/src/gplx/core/texts/RegxPatn_cls_ioMatch_tst.java create mode 100644 100_core/src/gplx/core/texts/RegxPatn_cls_like_tst.java create mode 100644 100_core/src/gplx/core/texts/StringTableBldr_tst.java create mode 100644 100_core/src/gplx/core/threads/poolables/Gfo_poolable_mgr_tst.java create mode 100644 100_core/src/gplx/core/times/DateAdp_parser_tst.java create mode 100644 100_core/src/gplx/core/times/Time_span__basic_tst.java create mode 100644 100_core/src/gplx/core/times/Time_span__parse_tst.java create mode 100644 100_core/src/gplx/core/times/Time_span__to_str_tst.java create mode 100644 100_core/src/gplx/core/type_xtns/DateAdpClassXtn_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java create mode 100644 100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java create mode 100644 100_core/src/gplx/langs/gfs/Gfs_Date_tst.java create mode 100644 100_core/src/gplx/langs/regxs/Regx_adp__tst.java create mode 100644 100_core/src/gplx/langs/xmls/HierStrBldr_tst.java create mode 100644 100_core/src/gplx/langs/xmls/XmlDoc_tst.java create mode 100644 100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java create mode 100644 100_core/src/gplx/langs/xmls/Xpath__tst.java create mode 100644 100_core/tst/gplx/GfoMsg_rdr_tst.java create mode 100644 100_core/tst/gplx/GfoTreeBldr_fxt.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_dir_basic_memory_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_dir_basic_system_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_dir_deep_memory_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_dir_deep_system_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_fil_basic_memory_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_fil_basic_system_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_fil_xfer_memory_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_fil_xfer_system_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_stream_xfer_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_xrg_queryDir_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoEngine_xrg_recycleFil_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoItmDir_FetchDeepOrNull_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoUrlInfo_alias_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoUrl_lnx_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoUrl_map_tst.java create mode 100644 100_core/tst/gplx/core/ios/IoUrl_wnt_tst.java create mode 100644 100_core/tst/gplx/core/stores/GfoNdeRdr_read_tst.java create mode 100644 100_core/tst/gplx/core/stores/GfoNdeRdr_tst.java create mode 100644 100_core/tst/gplx/core/stores/xmls/XmlDataRdr_tst.java create mode 100644 100_core/tst/gplx/core/stores/xmls/XmlDataWtr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/GfmlDataRdr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/yfxts_GfmlParse_fxt.java create mode 100644 110_gfml/tst/gplx/gfml/yfxts_GfmlTypeCompiler_fxt.java create mode 100644 110_gfml/tst/gplx/gfml/ymoks_GfmlAtr_GfmlNde_mok.java create mode 100644 110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java create mode 100644 110_gfml/tst/gplx/gfml/ymoks_GfmlTyp_GfmlFld_mok.java create mode 100644 110_gfml/tst/gplx/gfml/ymoks_UsrMsg_mok.java create mode 100644 110_gfml/tst/gplx/gfml/z011_IntObjHash_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z012_GfmlTrie_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z015_GfmlDocPos_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z016_GfmlScopeList_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z017_GfmlStringHighlighter_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z051_GfmlFldPool_keyed_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z081_GfmlDataWtr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z082_GfmlDataWtrOpts_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z091_GfmlLxr_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z101_core_ndeInline_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z102_core_whitespace_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z103_core_elmKey_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z111_core_comment0_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z112_core_comment1_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z120_quotes_eval0_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z121_quotes_quotes0_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z122_quotes_quote0_eval0_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z123_quotes_quoteBlock_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z124_quotes_quoteFold_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z151_ndeSubs_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z152_ndeSubs_data_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z161_ndeHdrs_inline_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z162_ndeHdrs_err_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z163_ndeHdrs_body_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z164_hdeHdrs_data_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z181_ndeDots_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z182_ndeDots_subs_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z183_ndeDots_parens_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z184_ndeDots_atrSpr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z191_ndeProps_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z192_ndeProps_dots_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z400_GfmlTypeMakr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z401_types_compile_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z402_types_compile_implicit_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z403_types_compile_default_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z411_types_apply_atrs_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z421_types_apply_ndes_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z422_types_apply_ndes_multi_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z423_types_apply_ndes_misc_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z424_types_apply_ndes_nest_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z441_types_parse_basic_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z442_types_parse_default_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z443_types_parse_keyd_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z450_fx_GfmlDefaultItem_fxt.java create mode 100644 110_gfml/tst/gplx/gfml/z451_dflts_compile_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z452_dflts_exec_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z455_dflts_scope_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z456_dflts_parse_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z481_vars_compile_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z482_vars_parse_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z501_lxr_parse_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z601_edit_atr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z602_edit_nde_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z801_useCase_DataRdr_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z803_useCase_KbdKeyboard_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z811_useCase_GfmlIoSql_tst.java create mode 100644 110_gfml/tst/gplx/gfml/z901_perf_tst.java create mode 100644 140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java create mode 100644 140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java create mode 100644 140_dbs/src/gplx/dbs/Db_conn_info_tst.java create mode 100644 140_dbs/src/gplx/dbs/Db_crt_tst.java create mode 100644 140_dbs/src/gplx/dbs/Db_qry_fxt.java create mode 100644 140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java create mode 100644 140_dbs/src/gplx/dbs/diffs/cmds/Gfdb_diff_cmd_sql_bldr_tst.java create mode 100644 140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java create mode 100644 140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java create mode 100644 140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java create mode 100644 140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java create mode 100644 140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java create mode 100644 140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java create mode 100644 140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__fld_tst.java create mode 100644 140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__idx_tst.java create mode 100644 140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__tbl_tst.java create mode 100644 140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java create mode 100644 140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java create mode 100644 140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java create mode 100644 140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java create mode 100644 140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java create mode 100644 140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java create mode 100644 140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java create mode 100644 140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java create mode 100644 140_dbs/src/gplx/dbs/utls/PoolIds_tst.java create mode 100644 140_dbs/tst/gplx/dbs/Db_conn_fxt.java create mode 100644 140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java create mode 100644 140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java create mode 100644 140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java create mode 100644 140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.java create mode 100644 140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java create mode 100644 140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java create mode 100644 140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java create mode 100644 140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java create mode 100644 140_dbs/tst/gplx/dbs/joins/Joins_base_tst.java create mode 100644 140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java create mode 100644 140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.java create mode 100644 140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java create mode 100644 150_gfui/src/gplx/gfui/controls/GfuiBorderMgr_tst.java create mode 100644 150_gfui/src/gplx/gfui/controls/customs/GfuiMoveElemBtn_tst.java create mode 100644 150_gfui/src/gplx/gfui/controls/standards/Gfui_tab_itm_data_tst.java create mode 100644 150_gfui/src/gplx/gfui/controls/tabs/TabBox_tst.java create mode 100644 150_gfui/src/gplx/gfui/controls/windows/GfuiFocusOrderer_tst.java create mode 100644 150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java create mode 100644 150_gfui/src/gplx/gfui/envs/ClipboardAdp__tst.java create mode 100644 150_gfui/src/gplx/gfui/envs/ScreenAdp_tst.java create mode 100644 150_gfui/src/gplx/gfui/imgs/ImageAdp_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/GfuiClickKeyMgr_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptArgChainMgr_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptArg_parser_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptBndMgr_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptCfg_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptEventType_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptKeyStrMgr_tst.java create mode 100644 150_gfui/src/gplx/gfui/ipts/IptKey__tst.java create mode 100644 150_gfui/src/gplx/gfui/layouts/GftBand_tst.java create mode 100644 400_xowa/src/gplx/core/brys/Bit__tst.java create mode 100644 400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java create mode 100644 400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java create mode 100644 400_xowa/src/gplx/core/brys/Bry_diff_tst.java create mode 100644 400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java create mode 100644 400_xowa/src/gplx/core/brys/evals/Bry_eval_mgr__tst.java create mode 100644 400_xowa/src/gplx/core/btries/Btrie_u8_mgr_tst.java create mode 100644 400_xowa/src/gplx/core/caches/Gfo_cache_mgr_tst.java create mode 100644 400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java create mode 100644 400_xowa/src/gplx/core/flds/Gfo_fld_rdr_tst.java create mode 100644 400_xowa/src/gplx/core/gfobjs/Gfobj_rdr__json_tst.java create mode 100644 400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_fxt.java create mode 100644 400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_tst.java create mode 100644 400_xowa/src/gplx/core/intls/String_surrogate_utl_tst.java create mode 100644 400_xowa/src/gplx/core/ios/BinaryHeap_Io_line_rdr_tst.java create mode 100644 400_xowa/src/gplx/core/ios/Io_buffer_rdr_tst.java create mode 100644 400_xowa/src/gplx/core/ios/Io_line_rdr_tst.java create mode 100644 400_xowa/src/gplx/core/ios/Io_sort_misc_tst.java create mode 100644 400_xowa/src/gplx/core/ios/Io_sort_tst.java create mode 100644 400_xowa/src/gplx/core/lists/Queue_adp_tst.java create mode 100644 400_xowa/src/gplx/core/lists/StatRng_tst.java create mode 100644 400_xowa/src/gplx/core/lists/binary_searches/Binary_search__tst.java create mode 100644 400_xowa/src/gplx/core/net/Gfo_url_parser_fxt.java create mode 100644 400_xowa/src/gplx/core/net/Gfo_url_parser_tst.java create mode 100644 400_xowa/src/gplx/core/net/Http_request_parser_tst.java create mode 100644 400_xowa/src/gplx/core/primitives/Gfo_number_parser_tst.java create mode 100644 400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.java create mode 100644 400_xowa/src/gplx/core/primitives/Int_pool_tst.java create mode 100644 400_xowa/src/gplx/core/progs/rates/Gfo_rate_list_tst.java create mode 100644 400_xowa/src/gplx/core/security/files/Cksum_list_tst.java create mode 100644 400_xowa/src/gplx/dbs/bulks/Db_tbl_copy_tst.java create mode 100644 400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr_tst.java create mode 100644 400_xowa/src/gplx/dbs/percentiles/Percentile_rng_tst.java create mode 100644 400_xowa/src/gplx/fsdb/data/Fsd_thm_tbl_tst.java create mode 100644 400_xowa/src/gplx/gfui/Gfui_bnd_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java create mode 100644 400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java create mode 100644 400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java create mode 100644 400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/Gfh_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/Gfh_utl__basic__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/Gfh_utl__comments__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser__tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/encoders/Gfo_url_encoder_tst.java create mode 100644 400_xowa/src/gplx/langs/htmls/styles/Gfh_style_parser__tst.java create mode 100644 400_xowa/src/gplx/langs/jsons/Json_doc_tst.java create mode 100644 400_xowa/src/gplx/langs/jsons/Json_kv_ary_srl_tst.java create mode 100644 400_xowa/src/gplx/langs/jsons/Json_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/jsons/Json_printer_tst.java create mode 100644 400_xowa/src/gplx/langs/jsons/Json_wtr_tst.java create mode 100644 400_xowa/src/gplx/langs/mustaches/Mustache_itm_render_tst.java create mode 100644 400_xowa/src/gplx/langs/mustaches/Mustache_tkn_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/phps/Php_parser_fxt.java create mode 100644 400_xowa/src/gplx/langs/phps/Php_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/phps/Php_srl_parser_tst.java create mode 100644 400_xowa/src/gplx/langs/phps/Php_text_itm_tst.java create mode 100644 400_xowa/src/gplx/langs/regxs/Gfo_pattern_tst.java create mode 100644 400_xowa/src/gplx/langs/xmls/Gfo_xml_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/Xoa_app_fxt.java create mode 100644 400_xowa/src/gplx/xowa/Xoae_page__tst.java create mode 100644 400_xowa/src/gplx/xowa/Xop_fxt.java create mode 100644 400_xowa/src/gplx/xowa/addons/apps/cfgs/mgrs/caches/Xocfg_cache_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/apps/cfgs/specials/maints/services/Xocfg_maint_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/apps/cfgs/upgrades/Xocfg_upgrade_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/apps/scripts/apis/Xoscript_doc_head__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/apps/updates/specials/svcs/Xoa_update_svc__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/app_cfgs/Xob_wiki_cfg_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/centrals/hosts/Host_eval_wkr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/centrals/utils/Time_dhms__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/exports/packs/files/Pack_zip_name_bldr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__image__create_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__lnki_temp__create__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/files/missing_origs/apis/Xowmf_imageinfo_item__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/files/utls/Xob_xfer_temp_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_html__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/bldrs/volumes/Volume_prep_rdr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/sidebars/Xoh_sidebar_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_htmlr__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__lvl__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__dupe__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__xnde__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__navlink__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/dbs/Xoctg_catlink_loader__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/urls/Xoctg_catpage_url__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/doubles/Xoctg_double_box__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/singles/Xoctg_single_box__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/directorys/dbs/Xowdir_wiki_props_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/fulltexts/core/Xofulltext_extractor__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/mgrs/brutes/finders/Xofulltext_finder_cbk__eval__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/htmls/css/mgrs/Xowd_css_core_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/randoms/specials/Rndm_root_special_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__fxt.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__err__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__file__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__fxt.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__misc__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_highlight_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_text_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/Srch_search_phrase_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_scanner_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_sql_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_link_wkr_sql_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_page_tbl_wkr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/Srch_special_searcher_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_html_page_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_rslt_cbk_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/apis/xowa/addons/bldrs/Xopg_match_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_gfs__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_php__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/servers/http/Http_server_wkr__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_msg_rdr_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_server_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__proto_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__qarg__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__ttl_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__url_bar_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__wiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xcmd_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xwiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java create mode 100644 400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_base_tst.java create mode 100644 400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_mok.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/cmds/texts/tdbs/Xob_init_base_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/cmds/texts/xmls/Xob_siteinfo_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_wiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__import_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__url_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_srl_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_match_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/setups/addons/Xoi_firefox_installer_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_list_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_latest_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/setups/upgrades/Xoa_upgrade_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_dump_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_tbl_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wiki_cfgs/Xoi_wiki_props_api_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wms/dump_pages/Xowmf_wiki_dump_dirs_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_file_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_type__tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wms/revs/Xowm_rev_wkr__meta__wm_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java create mode 100644 400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/drds/Xod_app_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_file_fxt.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_file_wkr__tst.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_fsdb_itm_fxt.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_img_size_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_url_bldr__tst.java create mode 100644 400_xowa/src/gplx/xowa/files/Xof_xfer_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/Xofv_file_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/bins/Xof_bin_wkr__http_wmf__tst.java create mode 100644 400_xowa/src/gplx/xowa/files/caches/Xof_cache_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/caches/Xou_cache_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/caches/Xou_cache_tbl_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/cnvs/Xof_img_wkr_resize_img_mok.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/fs_roots/Fs_root_wkr_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__bmp_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__flac_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__oga_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogg_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogv_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__pdf_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__png_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__svg_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__unknown_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__wav_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__xcf_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_fxt.java create mode 100644 400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_redirect_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/origs/Xof_orig_tbl_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/repos/Xof_repo_itm__tst.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_base_fxt.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_cases_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_fxt.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_offline_tst.java create mode 100644 400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_wmf_api_tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/cbks/swts/Gfobj_wtr__json__browser__tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/history/Xog_history_stack_tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__file__tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/urls/url_macros/Xog_url_macro_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/bridges/dbuis/fmtrs/Dbui_tbl_fmtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_html_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_wkr_jtidy_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/hzips/Gfo_decimal_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/makes/tests/Xoh_make_fxt.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_fxt.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser_fxt.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/gallerys/Xoh_gallery_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/medias/Xoh_media_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/timelines/Xoh_timeline_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/escapes/Xoh_escape_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_html__dump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__caption__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__style__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_itm_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_html_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_bare_hzip__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__link__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__orig__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__pgbnr__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_data_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__hdump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__anch__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__diff__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__ns__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__same__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__site__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_capt_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_data_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__audio__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__link__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__media__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__video__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_title_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__avo__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__pseudo__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__tidy__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/tocs/Xoh_toc_hzip_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/Xoh_xnde_hzip_nde__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/dicts/Xoh_xnde_dict__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__qargs__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__wiki__tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_wdata_labels_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cleaner_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__hdr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__id_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/modules/popups/keeplists/Xop_keeplist_wiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/ns_files/Xoh_ns_file_page_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/htmls/portal/vnts/Vnt_mnu_grp_fmtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/kwds/Xol_kwd_parse_data_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/lnki_trails/Xol_lnki_trail_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/msgs/Xow_mainpage_finder_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/numbers/Xol_num_grp_fmtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java create mode 100644 400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_convert_regy_tst.java create mode 100644 400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/Xop_ctx__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/Xop_parser__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__decode__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__parse_tkn__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_wkr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/apos/Xop_apos_wkr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__para_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__merge__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__slice__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_fxt.java create mode 100644 400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_fxt.java create mode 100644 400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_para_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_uncommon_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_brack_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_dangling_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_relative_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_text_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_uncommon_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_xwiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__ctg_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__frame_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__invalid_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__xwiki__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__pre_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__size_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__uncommon_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__video_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__xwiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/miscs/Xop_comm_lxr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_para_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/miscs/Xop_space_lxr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/paras/Xop_nl_tab_lxr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_para_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_pre_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__atrs_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__dangling_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__double_pipe_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__errs_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__nested_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__para_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__tblx_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__uncommon_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xop_subst_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xop_tkn_print_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_brief_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_dbg_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_examples_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_sandbox_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__missing__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__prepend_nl__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__raw_msg__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__transclude__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/tmpls/Xot_prm_tkn_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__parse__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/utils/TstObj_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/utils/Xop_sanitizer_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang__html__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang__syntax__tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang_fxt.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__bidi_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__undi_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser_fxt.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xatr_whitelist_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__blockquote_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_dangling_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_malformed_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_misc_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_uncommon_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__li_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__nowiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tblx_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__text_block_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tidy_tst.java create mode 100644 400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__xatrs_tst.java create mode 100644 400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages_tst.java create mode 100644 400_xowa/src/gplx/xowa/specials/nearby/Nearby_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page_tst.java create mode 100644 400_xowa/src/gplx/xowa/users/Xou_user_tst.java create mode 100644 400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java create mode 100644 400_xowa/src/gplx/xowa/users/history/Xou_history_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/users/wikis/Xofs_url_itm_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_xo__tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_uid__tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/pages/redirects/Xopg_redirect_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xoa_ttl__err_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xoa_ttl_fxt.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__anchor_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__html_entity_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__i18n_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__qarg_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__ws_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl__xwik_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/ttls/Xow_ttl_fxt.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/bldrs/Xow_xwiki_itm_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/parsers/Xow_xwiki_itm_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/parsers/Xow_xwiki_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/sitelinks/Xoa_sitelink_mgr_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/sitelinks/htmls/Xoa_sitelink_div_wtr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/wikis/xwikis/sitelinks/htmls/Xoa_sitelink_div_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/assessments/Assessment_func__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/categoryList/Xtn_categoryList_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/categorytrees/Categorytree_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_cfg_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/References_nde_group_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/References_nde_pre_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/cites/References_nde_rare_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/dynamicPageList/Dpl_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pages_using_pending_changes_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pending_change_level_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/flaggedRevs/scribunto/Flagged_revs_lib_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/gallery/Gallery_mgr_base__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/gallery/Gallery_mgr_base__xatrs__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/gallery/Gallery_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/gallery/Gallery_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/geoCrumbs/Geoc_isin_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/geodata/Geo_coordinates_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/graphs/Json_fmtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/hieros/Hiero_mw_tables_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/hieros/Hiero_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/imaps/Imap_base_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/imaps/Imap_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/imaps/htmls/Imap_html__hdump__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/imaps/htmls/Imap_html__hview__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/imaps/htmls/Imap_shapes_arg_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/indicators/Indicator_html_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/indicators/Indicator_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/inputBox/Xtn_inputbox_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/insiders/Insider_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/insiders/Insider_html_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/jsonConfigs/scribunto/Jscfg_scrib_lib_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/kartographers/Mapframe_xnde__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/kartographers/Maplink_xnde__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/listings/Listing_xnde_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/listings/Listing_xnde_template_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/lst/Lst_pfunc_lst_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/lst/Lst_pfunc_lsth_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/lst/Lst_pfunc_lstx_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/lst/Lst_section_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/mapSources/Map_dd2dms_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/mapSources/Map_deg2dd_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/mapSources/Map_geolink_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/massMessage/Message_target_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/math/Xomath_core__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/math/Xomath_subst_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/math/texvcs/Texvc_checker_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/math/texvcs/Texvc_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/new_window_links/New_window_link_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pagebanners/Pgbnr_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/exprs/Pfunc_expr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_if_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifeq_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_iferror_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexist_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_ifexpr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ifs/Pfunc_switch_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_gender_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_grammar_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_i18n_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_int_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_language_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/langs/Pfunc_plural_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/numbers/Pf_formatnum_de_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/numbers/Pf_formatnum_en_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/numbers/Pf_formatnum_es_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/numbers/Pf_formatnum_fa_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/pages/Pfunc_displaytitle_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/pages/Pfunc_misc_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/pages/Pfunc_rev_props_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/scribunto/Pfunc_scrib_lib_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/strings/Pfunc_case_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/strings/Pfunc_pad_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/strings/Pfunc_tag_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_count_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_explode_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_len_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_pos_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_replace_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_rpos_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_sub_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/stringutils/Pfunc_urldecode_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_date_lcl_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_date_rev_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_date_utc_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_formatdate_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time__hebrew__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time__int__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time__other__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time__uncommon__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_foreign_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_parser_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_anchorencode_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_filepath_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_ns_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_rel2abs_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_titleparts_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_ttl_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlencode_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/ttls/Pfunc_urlfunc_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/wikis/Pfunc_pagesincategory_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/wikis/Pfunc_wiki_props_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/pfuncs/wikis/Pfunc_wiki_stats_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/poems/Poem_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pagelist_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pagequality_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde_basic_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde_hdr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde_index_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/proofreadPage/Pp_pages_nde_recursion_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/quiz/Quiz_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/relatedArticles/Articles_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/relatedSites/Sites_html_bldr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/rss/Rss_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scores/Score_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_err_filter_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_fsys_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/engines/luaj/Luaj_value__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/engines/mocks/Mock_proc_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/engines/mocks/Mock_scrib_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/engines/process/Process_send_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/engines/process/Process_stream_rdr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_language_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_message_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_mw__invoke_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_mw__lib_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_site_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_text__nowiki_util_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_text_json_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_text_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_title_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_uri_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_ustring__find__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_ustring__gmatch__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_ustring__gsub__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_ustring__match__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_ustring__shell_cmd__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_srl_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_regx_converter_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/libs/Xow_wiki_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/scribunto/procs/Scrib_proc_args__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/syntax_highlights/Int_rng_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/syntax_highlights/Synh_xtn_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/templateData/Xtn_templateData_nde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/titleBlacklists/Blacklist_scrib_lib_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/translates/Xop_languages_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/translates/Xop_mylanguage_page_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/translates/Xop_translate_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/translates/Xop_tvar_lxr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/Wdata_wiki_mgr_fxt.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/Wdata_wiki_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/Wdata_xwiki_link_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/claims/Wbase_claim_grp_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/claims/itms/times/Wbase_date_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/dbs/Wbase_qid_tbl_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/hwtrs/Wdata_hwtr_mgr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/hwtrs/Wdata_visitor__html_wtr_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/imports/Xob_wdata_pid_base_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/imports/Xob_wdata_pid_sql_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/imports/Xob_wdata_qid_base_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/mediawiki/client/config/WikibaseClientDefault.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/parsers/Wdata_doc_parser_v1_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/parsers/Wdata_doc_parser_v2__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/parsers/Wdata_doc_parser_v2__claims__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/pfuncs/Wdata_pf_noExternalLangLinks_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/pfuncs/Wdata_pf_property__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/pfuncs/Wdata_pf_property__parse__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/pfuncs/Wdata_pf_statements__basic__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/pfuncs/Wdata_pf_wbreponame_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/specials/Wdata_itemByTitle_page_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wbases/stores/Wbase_doc_mgr__tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wikias/Random_selection_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wikias/Tabber_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/wikias/Tabview_xnde_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_cmd_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xop_xowa_func_tst.java create mode 100644 400_xowa/src/gplx/xowa/xtns/xowa_cmds/Xox_xowa_html_cmd_tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/Xophp_ary_tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/extensions/JsonConfig/includes/JCSingleton_tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/Xomw_regex_parser__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/doubleunders/Xomw_doubleunder_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/headings/Xomw_heading_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/hrs/Xomw_hr_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/lnkes/Xomw_lnke_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/lnkis/Xomw_lnki_wkr__file__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/lnkis/Xomw_lnki_wkr__text__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/magiclinks/Xomw_magiclinks_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/nbsps/Xomw_nbsp_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/prepros/Xomw_prepro_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/quotes/Xomw_quote_wkr__tst.java create mode 100644 gplx.xowa.mediawiki/src/gplx/xowa/mediawiki/includes/parsers/tables/Xomw_table_wkr__tst.java diff --git a/100_core/src/gplx/Array__tst.java b/100_core/src/gplx/Array__tst.java new file mode 100644 index 000000000..f00e89500 --- /dev/null +++ b/100_core/src/gplx/Array__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Array__tst { + @Test public void Resize_add() { + tst_Resize_add(ary_(), ary_(1), ary_(1)); // 0 + 1 = 1 + tst_Resize_add(ary_(0), ary_(), ary_(0)); // 1 + 0 = 1 + tst_Resize_add(ary_(0), ary_(1), ary_(0, 1)); // 1 + 1 = 2 + } void tst_Resize_add(int[] source, int[] added, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize_add(source, added));} + @Test public void Resize() { + tst_Resize(ary_(0), 0, ary_()); // 1 -> 0 + tst_Resize(ary_(0, 1), 1, ary_(0)); // 2 -> 1 + } void tst_Resize(int[] source, int length, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize(source, length));} + @Test public void Insert() { + tst_Insert(ary_obj(0, 1, 4, 5), ary_obj(2, 3), 2, ary_obj(0, 1, 2, 3, 4, 5)); + } void tst_Insert(Object[] cur, Object[] add, int addPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Insert(cur, add, addPos));} + @Test public void ReplaceInsert() { + tst_ReplaceInsert(ary_obj(0, 1, 4, 5) , ary_obj(1, 2, 3), 1, 1, ary_obj(0, 1, 2, 3, 4, 5)); + tst_ReplaceInsert(ary_obj(0, 1, 2, 4, 5) , ary_obj(1, 2, 3), 1, 2, ary_obj(0, 1, 2, 3, 4, 5)); + tst_ReplaceInsert(ary_obj(0, 1, 2, 3, 4, 5) , ary_obj(1, 2, 3), 1, 3, ary_obj(0, 1, 2, 3, 4, 5)); + tst_ReplaceInsert(ary_obj(0, 1, 9, 4, 5) , ary_obj(2, 3) , 2, 1, ary_obj(0, 1, 2, 3, 4, 5)); + } void tst_ReplaceInsert(Object[] cur, Object[] add, int curReplacePos, int addInsertPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Replace_insert(cur, add, curReplacePos, addInsertPos));} + Object[] ary_obj(Object... ary) {return ary;} + int[] ary_(int... ary) {return ary;} +} diff --git a/100_core/src/gplx/Bool__tst.java b/100_core/src/gplx/Bool__tst.java new file mode 100644 index 000000000..f95218094 --- /dev/null +++ b/100_core/src/gplx/Bool__tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Bool__tst { + private final Bool__fxt fxt = new Bool__fxt(); + @Test public void Compare() { + fxt.Test__compare(Bool_.Y, Bool_.Y, CompareAble_.Same); + fxt.Test__compare(Bool_.N, Bool_.N, CompareAble_.Same); + fxt.Test__compare(Bool_.N, Bool_.Y, CompareAble_.Less); + fxt.Test__compare(Bool_.Y, Bool_.N, CompareAble_.More); + } +} +class Bool__fxt { + public void Test__compare(boolean lhs, boolean rhs, int expd) {Tfds.Eq(expd, Bool_.Compare(lhs, rhs));} +} diff --git a/100_core/src/gplx/Bry__tst.java b/100_core/src/gplx/Bry__tst.java new file mode 100644 index 000000000..6e531636d --- /dev/null +++ b/100_core/src/gplx/Bry__tst.java @@ -0,0 +1,307 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.tests.*; +public class Bry__tst { + private final Bry__fxt fxt = new Bry__fxt(); + @Test public void new_ascii_() { + fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one + fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many + fxt.Test_new_a7("" , Bry_.Empty); // none + fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ? + } + @Test public void new_u8() { + fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one + fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many + fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent + fxt.Test_new_u8("€" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro + fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8 + } + @Test public void Add__bry_plus_byte() { + fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic + fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String + } + @Test public void Add__byte_plus_bry() { + fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic + fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String + } + @Test public void Add_w_dlm() { + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null + } + @Test public void Add_w_dlm_bry() { + fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c"); + } + @Test public void MidByPos() { + tst_MidByPos("abcba", 0, 1, "a"); + tst_MidByPos("abcba", 0, 2, "ab"); + tst_MidByPos("abcba", 1, 4, "bcb"); + } void tst_MidByPos(String src, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Mid(Bry_.new_u8(src), bgn, end)));} + @Test public void Replace_one() { + tst_ReplaceOne("a" , "b" , "c" , "a"); + tst_ReplaceOne("b" , "b" , "c" , "c"); + tst_ReplaceOne("bb" , "b" , "c" , "cb"); + tst_ReplaceOne("abcd" , "bc" , "" , "ad"); + tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd"); + } void tst_ReplaceOne(String src, String find, String repl, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Replace_one(Bry_.new_u8(src), Bry_.new_u8(find), Bry_.new_u8(repl))));} + @Test public void XtoStrBytesByInt() { + tst_XtoStrBytesByInt(0, 0); + tst_XtoStrBytesByInt(9, 9); + tst_XtoStrBytesByInt(10, 1, 0); + tst_XtoStrBytesByInt(321, 3, 2, 1); + tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1); + tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7); + } + void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) { + byte[] expd = new byte[expdAryAsInt.length]; + for (int i = 0; i < expd.length; i++) { + int expdInt = expdAryAsInt[i]; + expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_str(expdAryAsInt[i]); + } + Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val))); + } + @Test public void Has_at_end() { + tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic + tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many + tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long + tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos + tst_HasAtEnd("abc", "bc", true); // y + tst_HasAtEnd("abc", "bd", false); // n + tst_HasAtEnd("a", "ab", false); // exceeds_len + } + void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));} + void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));} + @Test public void Has_at_bgn() { + tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true); + tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true); + tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false); + tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false); + } void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_bgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);} + @Test public void Match() { + tst_Match("abc", 0, "abc", true); + tst_Match("abc", 2, "c", true); + tst_Match("abc", 0, "cde", false); + tst_Match("abc", 2, "abc", false); // bounds check + tst_Match("abc", 0, "abcd", false); + tst_Match("a" , 0, "", false); + tst_Match("" , 0, "a", false); + tst_Match("" , 0, "", true); + tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different + } void tst_Match(String src, int srcPos, String find, boolean expd) {Tfds.Eq(expd, Bry_.Match(Bry_.new_u8(src), srcPos, Bry_.new_u8(find)));} + @Test public void ReadCsvStr() { + tst_ReadCsvStr("a|" , "a"); + tst_ReadCsvStr("|a|", 1 , "a"); + Int_obj_ref bgn = Int_obj_ref.New_zero(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c"); + tst_ReadCsvStr("|", ""); + tst_ReadCsvStr_err("a"); + + tst_ReadCsvStr("'a'|" , "a"); + tst_ReadCsvStr("'a''b'|" , "a'b"); + tst_ReadCsvStr("'a|b'|" , "a|b"); + tst_ReadCsvStr("''|", ""); + tst_ReadCsvStr_err("''"); + tst_ReadCsvStr_err("'a'b'"); + tst_ReadCsvStr_err("'a"); + tst_ReadCsvStr_err("'a|"); + tst_ReadCsvStr_err("'a'"); + } + @Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4 + tst_XtoIntBy4Bytes(32, (byte)32); // space + tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // ∃ + tst_XtoIntBy4Bytes(6382179, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c); + tst_XtoIntBy4Bytes(1633837924, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c, Byte_ascii.Ltr_d); + } + @Test public void XtoInt() { + tst_XtoInt("1", 1); + tst_XtoInt("123", 123); + tst_XtoInt("a", Int_.Min_value, Int_.Min_value); + tst_XtoInt("-1", Int_.Min_value, -1); + tst_XtoInt("-123", Int_.Min_value, -123); + tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value); + tst_XtoInt("+123", Int_.Min_value, 123); + tst_XtoInt("", -1); + } + void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);} + void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));} + void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");} + void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New_zero() , expd);} + void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);} + void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) { + int bgn = bgnRef.Val(); + boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\''; + String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'"); + Tfds.Eq(expd, actl, "rv"); + if (rawHasQuotes) { + int quoteAdj = String_.Count(actl, "'"); + Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes + } + else + Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len + } + void tst_ReadCsvStr_err(String raw) { + try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');} + catch (Exception e) {Err_.Noop(e); return;} + Tfds.Fail_expdError(); + } + @Test public void ReadCsvDte() { + tst_ReadCsvDte("20110801 221435.987"); + } void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));} + @Test public void ReadCsvInt() { + tst_ReadCsvInt("1234567890"); + } void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));} + @Test public void Trim() { + Trim_tst("a b c", 1, 4, "b"); + Trim_tst("a c", 1, 3, ""); + Trim_tst(" ", 0, 2, ""); + } void Trim_tst(String raw, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Trim(Bry_.new_u8(raw), bgn, end)));} + @Test public void Xto_int_lax() { + tst_Xto_int_lax("12a", 12); + tst_Xto_int_lax("1", 1); + tst_Xto_int_lax("123", 123); + tst_Xto_int_lax("a", 0); + tst_Xto_int_lax("-1", -1); + } + private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__lax(Bry_.new_u8(val), 0, String_.Len(val), 0));} + @Test public void To_int_or__trim_ws() { + tst_Xto_int_trim("123 " , 123); + tst_Xto_int_trim(" 123" , 123); + tst_Xto_int_trim(" 123 " , 123); + tst_Xto_int_trim(" 1 3 " , -1); + } + private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__trim_ws(Bry_.new_u8(val), 0, String_.Len(val), -1));} + @Test public void Compare() { + tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same); + tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less); + tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAble_.More); + tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAble_.Less); + tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAble_.More); + tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAble_.Less); + } void tst_Compare(String lhs, int lhs_bgn, int lhs_end, String rhs, int rhs_bgn, int rhs_end, int expd) {Tfds.Eq(expd, Bry_.Compare(Bry_.new_u8(lhs), lhs_bgn, lhs_end, Bry_.new_u8(rhs), rhs_bgn, rhs_end));} + @Test public void Increment_last() { + tst_IncrementLast(ary_(0), ary_(1)); + tst_IncrementLast(ary_(0, 255), ary_(1, 0)); + tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102)); + } + byte[] ary_(int... ary) { + byte[] rv = new byte[ary.length]; + for (int i = 0; i < ary.length; i++) + rv[i] = Byte_.By_int(ary[i]); + return rv; + } + void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));} + @Test public void Replace_between() { + tst_Replace_between("a[0]b" , "[", "]", "0", "a0b"); + tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c"); + tst_Replace_between("a[0b" , "[", "]", "0", "a[0b"); + } public void tst_Replace_between(String src, String bgn, String end, String repl, String expd) {Tfds.Eq(expd, String_.new_a7(Bry_.Replace_between(Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(end), Bry_.new_a7(repl))));} + @Test public void Replace() { + Bry_bfr tmp_bfr = Bry_bfr_.New(); + tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1 + tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2 + tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1 + tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS + tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS + tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match + tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS + } + public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) { + Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl)))); + } + @Test public void Split_bry() { + Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c")); + Split_bry_tst("a|" , "|" , String_.Ary("a")); + } + void Split_bry_tst(String src, String dlm, String[] expd) { + String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm))); + Tfds.Eq_ary_str(expd, actl); + } + @Test public void Split_lines() { + Tst_split_lines("a\nb" , "a", "b"); // basic + Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines + Tst_split_lines("a\r\nb" , "a", "b"); // crlf + Tst_split_lines("a\rb" , "a", "b"); // cr only + } + void Tst_split_lines(String src, String... expd) { + Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src)))); + } + String[] New_ary(byte[][] lines) { + int len = lines.length; + String[] rv = new String[len]; + for (int i = 0; i < len; i++) + rv[i] = String_.new_u8(lines[i]); + return rv; + } + @Test public void Match_bwd_any() { + Tst_match_bwd_any("abc", 2, 0, "c", true); + Tst_match_bwd_any("abc", 2, 0, "b", false); + Tst_match_bwd_any("abc", 2, 0, "bc", true); + Tst_match_bwd_any("abc", 2, 0, "abc", true); + Tst_match_bwd_any("abc", 2, 0, "zabc", false); + Tst_match_bwd_any("abc", 1, 0, "ab", true); + } + void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) { + Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find))); + } + @Test public void Trim_end() { + fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one + fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many + fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none + fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty + } + @Test public void Mid_w_trim() { + fxt.Test_Mid_w_trim("abc", "abc"); // no ws + fxt.Test_Mid_w_trim(" a b c ", "a b c"); // ws at bgn and end + fxt.Test_Mid_w_trim("\r\n\t a\r\n\t b \r\n\t ", "a\r\n\t b"); // space at bgn and end + fxt.Test_Mid_w_trim("", ""); // handle 0 bytes + fxt.Test_Mid_w_trim(" ", ""); // handle all ws + } + @Test public void New_u8_nl_apos() { + fxt.Test__new_u8_nl_apos(String_.Ary("a"), "a"); + fxt.Test__new_u8_nl_apos(String_.Ary("a", "b"), "a\nb"); + fxt.Test__new_u8_nl_apos(String_.Ary("a", "b'c", "d"), "a\nb\"c\nd"); + } + @Test public void Repeat_bry() { + fxt.Test__repeat_bry("abc" , 3, "abcabcabc"); + } + @Test public void Xcase__build__all() { + fxt.Test__xcase__build__all(Bool_.N, "abc", "abc"); + fxt.Test__xcase__build__all(Bool_.N, "aBc", "abc"); + } +} +class Bry__fxt { + private final Bry_bfr tmp = Bry_bfr_.New(); + public void Test_trim_end(String raw, byte trim, String expd) { + byte[] raw_bry = Bry_.new_a7(raw); + Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length))); + } + public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));} + public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));} + public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));} + public void Test_add(byte b, String s, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(b, Bry_.new_u8(s))));} + public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));} + public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));} + public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));} + public void Test__new_u8_nl_apos(String[] ary, String expd) { + Tfds.Eq_str_lines(expd, String_.new_u8(Bry_.New_u8_nl_apos(ary))); + } + public void Test__repeat_bry(String s, int count, String expd) { + Gftest.Eq__str(expd, Bry_.Repeat_bry(Bry_.new_u8(s), count)); + } + public void Test__xcase__build__all(boolean upper, String src, String expd) { + Gftest.Eq__str(expd, Bry_.Xcase__build__all(tmp, upper, Bry_.new_u8(src))); + } +} diff --git a/100_core/src/gplx/Bry_bfr_tst.java b/100_core/src/gplx/Bry_bfr_tst.java new file mode 100644 index 000000000..dcaee5c64 --- /dev/null +++ b/100_core/src/gplx/Bry_bfr_tst.java @@ -0,0 +1,247 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; +public class Bry_bfr_tst { + private Bry_bfr bb = Bry_bfr_.New(); + @Before public void setup() {bb.Clear();} private ByteAryBfr_fxt fxt = new ByteAryBfr_fxt(); + @Test public void AddByte() { + bb = Bry_bfr_.New_w_size(2); // NOTE: make sure auto-expands + tst_AddByte("a", "a", 2); + tst_AddByte("b", "ab", 2); + tst_AddByte("c", "abc", 4); + } + @Test public void AddAry() { // NOTE: make sure auto-expands + bb = Bry_bfr_.New_w_size(2); + tst_AddByte("abcd", "abcd", 12); + } + @Test public void Add_byte_repeat() { // NOTE: make sure auto-expands + bb = Bry_bfr_.New_w_size(2); + tst_Add_byte_repeat(Byte_ascii.Space, 12, String_.Repeat(" ", 12)); + } void tst_Add_byte_repeat(byte b, int len, String expd) {Tfds.Eq(expd, bb.Add_byte_repeat(b, len).To_str_and_clear());} + void tst_AddByte(String s, String expdStr, int expdLen) { + if (String_.Len(s) == 1) + bb.Add_byte((byte)String_.CharAt(s, 0)); + else + bb.Add(Bry_.new_u8(s)); + Tfds.Eq(expdStr, String_.new_u8(bb.To_bry())); + Tfds.Eq(expdLen, bb.Bfr_max()); + } + @Test public void Add_dte() { + tst_AddDte("20110801 221435.987"); + } + void tst_AddDte(String raw) { + bb.Add_dte(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte)); + Tfds.Eq(raw, String_.new_u8(bb.To_bry())); + } + @Test public void Add_int_variable() { + Add_int_variable(-1); + Add_int_variable(-12); + Add_int_variable(-1234); + Add_int_variable(2); + Add_int_variable(12); + Add_int_variable(1234); + Add_int_variable(123456789); + } + @Test public void Add_float() { + tst_Add_float(1 / 3); + tst_Add_float(-1 / 3); + } + void tst_Add_float(float v) { + bb.Add_float(v); + Tfds.Eq(v, Float_.parse(String_.new_u8(bb.To_bry()))); + } + void Add_int_variable(int val) { + bb.Clear(); + bb.Add_int_variable(val); + Tfds.Eq(val, Int_.Parse(String_.new_u8(bb.To_bry()))); + } + @Test public void Add_int_fixed_len3() {tst_Add_int_fixed(123, 3, "123");} + @Test public void Add_int_fixed_pad_1() {tst_Add_int_fixed(2, 1, "2");} + @Test public void Add_int_fixed_pad_2() {tst_Add_int_fixed(2, 2, "02");} + @Test public void Add_int_fixed_pad_16() {tst_Add_int_fixed(2, 16, "0000000000000002");} // test overflows int + @Test public void Add_int_fixed_neg() {tst_Add_int_fixed(-2, 2, "-2");} + @Test public void Add_int_fixed_neg_pad1() {tst_Add_int_fixed(-2, 1, "-");} + @Test public void Add_int_fixed_chop_1() {tst_Add_int_fixed(123, 1, "3");} + @Test public void Add_int_fixed_chop_neg() {tst_Add_int_fixed(-21, 2, "-1");} + void tst_Add_int_fixed(int val, int digits, String expd) {Tfds.Eq(expd, String_.new_u8(bb.Add_int_fixed(val, digits).To_bry()));} + @Test public void Add_long_fixed_len3() {tst_Add_long_fixed(123, 3, "123");} + @Test public void Add_long_fixed_pad_1() {tst_Add_long_fixed(2, 1, "2");} + @Test public void Add_long_fixed_pad_2() {tst_Add_long_fixed(2, 2, "02");} + @Test public void Add_long_fixed_pad_16() {tst_Add_long_fixed(2, 16, "0000000000000002");} // test overflows long + @Test public void Add_long_fixed_neg() {tst_Add_long_fixed(-2, 2, "-2");} + @Test public void Add_long_fixed_neg_pad1() {tst_Add_long_fixed(-2, 1, "-");} + @Test public void Add_long_fixed_chop_1() {tst_Add_long_fixed(123, 1, "3");} + @Test public void Add_long_fixed_chop_neg() {tst_Add_long_fixed(-21, 2, "-1");} + @Test public void Add_long_fixed_large() {tst_Add_long_fixed(123456789012345L, 15, "123456789012345");} + void tst_Add_long_fixed(long val, int digits, String expd) {Tfds.Eq(expd, String_.new_u8(bb.Add_long_fixed(val, digits).To_bry()));} + @Test public void AddDte_short() { + tst_AddDte_short("2010-08-26T22:38:36Z"); + } + void tst_AddDte_short(String raw) { +// byte[] ary = String_.XtoByteAryAscii(raw); +// Bry_fmtr_IntBldr ib = new Bry_fmtr_IntBldr(); +// int y = 0, m = 0, d = 0, h = 0, n = 0, s = 0, aryLen = ary.length; +// for (int i = 0; i < aryLen; i++) { +// byte b = ary[i]; +// switch (i) { +// case 4: y = ib.To_int_and_clear(); break; +// case 7: m = ib.To_int_and_clear(); break; +// case 10: d = ib.To_int_and_clear(); break; +// case 13: h = ib.To_int_and_clear(); break; +// case 16: n = ib.To_int_and_clear(); break; +// case 19: s = ib.To_int_and_clear(); break; +// default: ib.Add(b); break; +// } +// } +// long l = Pow38_to(y, m, d, h, n, s); +//// Base85_.Set_bry(l, bb. +// bb.Add_int(l); + } +// @Test public void InsertAt_str() { +// tst_InsertAt_str("", 0, "c", "c"); +// tst_InsertAt_str("ab", 0, "c", "cab"); +// tst_InsertAt_str("ab", 0, "cdefghij", "cdefghijab"); +// } +// void tst_InsertAt_str(String orig, int insertAt, String insertStr, String expd) { +// bb = Bry_bfr_.New(16); +// bb.Add_str(orig); +// bb.InsertAt_str(insertAt, insertStr); +// String actl = bb.To_str_and_clear(); +// Tfds.Eq(expd, actl); +// } + @Test public void To_bry_and_clear_and_trim() { + tst_XtoAryAndClearAndTrim("a" , "a"); + tst_XtoAryAndClearAndTrim(" a " , "a"); + tst_XtoAryAndClearAndTrim(" a b " , "a b"); + tst_XtoAryAndClearAndTrim(" " , ""); + } + void tst_XtoAryAndClearAndTrim(String raw, String expd) { + bb.Add_str_u8(raw); + Tfds.Eq(expd, String_.new_u8(bb.To_bry_and_clear_and_trim())); + } + @Test public void XtoInt() { + tst_XtoInt("123", 123); + tst_XtoInt("a", Int_.Min_value); + tst_XtoInt("9999999999", Int_.Min_value); + } + void tst_XtoInt(String raw, int expd) { + bb.Add_str_u8(raw); + Tfds.Eq(expd, bb.To_int_and_clear(Int_.Min_value)); + } + static long Pow38_to(int year, int month, int day, int hour, int minute, int second, int frac) { + return ((long)year) << 26 + | ((long)month & 0x0f) << 22 // 16 + | ((long)day & 0x1f) << 17 // 32 + | ((long)hour & 0x1f) << 12 // 32 + | ((long)minute & 0x3f) << 6 // 64 + | ((long)second & 0x3f) // 64 + ; + } + static DateAdp Pow38_by(long v) { + int year = (int) (v >> 26); + int month = (int)((v >> 22) & 0x0f); + int day = (int)((v >> 17) & 0x1f); + int hour = (int)((v >> 12) & 0x1f); + int minute = (int)((v >> 6) & 0x3f); + int second = (int)((v ) & 0x3f); + return DateAdp_.new_(year, month, day, hour, minute, second, 0); + } + @Test public void Add_bfr_trimEnd_and_clear() { + tst_Add_bfr_trimEnd_and_clear("a ", "a"); + } + void tst_Add_bfr_trimEnd_and_clear(String raw, String expd) { + Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw); + Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, false, true).To_str_and_clear()); + } + @Test public void Add_bfr_trimAll_and_clear() { + tst_Add_bfr_trimAll_and_clear(" a ", "a"); + tst_Add_bfr_trimAll_and_clear(" a b ", "a b"); + tst_Add_bfr_trimAll_and_clear("a", "a"); + tst_Add_bfr_trimAll_and_clear("", ""); + } + void tst_Add_bfr_trimAll_and_clear(String raw, String expd) { + Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw); + Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, true, true).To_str_and_clear()); + } + @Test public void Add_int_pad_bgn() { + fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 0, "000"); + fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1, "001"); + fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 10, "010"); + fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 100, "100"); + fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1000, "1000"); + } + @Test public void Add_bry_escape() { + fxt.Test__add_bry_escape("abc" , "abc"); // nothing to escape + fxt.Test__add_bry_escape("a'bc" , "a''bc"); // single escape (code handles first quote differently) + fxt.Test__add_bry_escape("a'b'c" , "a''b''c"); // double escape (code handles subsequent quotes different than first) + fxt.Test__add_bry_escape("abc", 1, 2 , "b"); // nothing to escape + } + @Test public void Add_bry_escape_html() { + fxt.Test__add_bry_escape_html("abc" , "abc"); // escape=none + fxt.Test__add_bry_escape_html("a&\"'<>b" , "a&"'<>b"); // escape=all; code handles first escape differently + fxt.Test__add_bry_escape_html("a&b&c" , "a&b&c"); // staggered; code handles subsequent escapes differently + fxt.Test__add_bry_escape_html("abc", 1, 2 , "b"); // by index; fixes bug in initial implementation + } + @Test public void Insert_at() { + fxt.Test_Insert_at("abcd", 0, "xyz" , "xyzabcd"); // bgn + fxt.Test_Insert_at("abcd", 4, "xyz" , "abcdxyz"); // end + fxt.Test_Insert_at("abcd", 2, "xyz" , "abxyzcd"); // mid + fxt.Test_Insert_at("abcd", 2, "xyz", 1, 2 , "abycd"); // mid + } + @Test public void Delete_rng() { + fxt.Test_Delete_rng("abcd", 0, 2 , "cd"); // bgn + fxt.Test_Delete_rng("abcd", 2, 4 , "ab"); // end + fxt.Test_Delete_rng("abcd", 1, 3 , "ad"); // mid + } + @Test public void Delete_rng_to_bgn() { + fxt.Test_Delete_rng_to_bgn("abcd", 2 , "cd"); + } + @Test public void Delete_rng_to_end() { + fxt.Test_Delete_rng_to_end("abcd", 2 , "ab"); + } + @Test public void To_bry_ary_and_clear() { + fxt.Test__to_bry_ary_and_clear("" ); // empty + fxt.Test__to_bry_ary_and_clear("a" , "a"); // lines=1 + fxt.Test__to_bry_ary_and_clear("a\nb\nc" , "a", "b", "c"); // lines=n + fxt.Test__to_bry_ary_and_clear("a\n" , "a"); // nl at end + } +} +class ByteAryBfr_fxt { + private final Bry_bfr bfr = Bry_bfr_.Reset(16); + public Bry_bfr Bfr() {return bfr;} + public void Clear() { + bfr.ClearAndReset(); + } + public void Test_Add_int_pad_bgn(byte pad_byte, int str_len, int val, String expd) {Tfds.Eq(expd, bfr.Add_int_pad_bgn(pad_byte, str_len, val).To_str_and_clear());} + public void Test__add_bry_escape(String src, String expd) {Test__add_bry_escape(src, 0, String_.Len(src), expd);} + public void Test__add_bry_escape(String src, int src_bgn, int src_end, String expd) { + byte[] val_bry = Bry_.new_u8(src); + Tfds.Eq(expd, bfr.Add_bry_escape(Byte_ascii.Apos, Byte_.Ary(Byte_ascii.Apos, Byte_ascii.Apos), val_bry, src_bgn, src_end).To_str_and_clear()); + } + public void Test_Insert_at(String init, int pos, String val, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val)).To_str_and_clear());} + public void Test_Insert_at(String init, int pos, String val, int val_bgn, int val_end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val), val_bgn, val_end).To_str_and_clear());} + public void Test_Delete_rng(String init, int bgn, int end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng(bgn, end).To_str_and_clear());} + public void Test_Delete_rng_to_bgn(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_bgn(pos).To_str_and_clear());} + public void Test_Delete_rng_to_end(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_end(pos).To_str_and_clear());} + public void Test__to_bry_ary_and_clear(String bfr_str, String... expd) { + Tfds.Eq_ary(expd, String_.Ary(bfr.Add_str_u8(bfr_str).To_bry_ary_and_clear())); + } + public void Test__add_bry_escape_html(String src, String expd) {Test__add_bry_escape_html(src, 0, String_.Len(src), expd);} + public void Test__add_bry_escape_html(String src, int src_bgn, int src_end, String expd) { + Gftest.Eq__bry(Bry_.new_u8(expd), bfr.Add_bry_escape_html(Bry_.new_u8(src), src_bgn, src_end).To_bry_and_clear()); + } +} diff --git a/100_core/src/gplx/Bry_find__tst.java b/100_core/src/gplx/Bry_find__tst.java new file mode 100644 index 000000000..38fa5893b --- /dev/null +++ b/100_core/src/gplx/Bry_find__tst.java @@ -0,0 +1,90 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; +public class Bry_find__tst { + private Bry_find__fxt fxt = new Bry_find__fxt(); + @Test public void Find_fwd() { + fxt.Test_Find_fwd("abcba", "b", 0, 1); + fxt.Test_Find_fwd("abcba", "z", 0, -1); + fxt.Test_Find_fwd("abcba", "b", 1, 1); + fxt.Test_Find_fwd("abcba", "b", 2, 3); + fxt.Test_Find_fwd("abcba", "b", 4, -1); + fxt.Test_Find_fwd("abcba", "zb", 4, -1); + fxt.Test_Find_fwd("abcba", "a", 6, -1); + } + @Test public void Find_bwd() { + fxt.Test_Find_bwd("abcba", "b", 4, 3); + fxt.Test_Find_bwd("abcba", "z", 4, -1); + fxt.Test_Find_bwd("abcba", "b", 3, 1); + fxt.Test_Find_bwd("abcba", "b", 2, 1); + fxt.Test_Find_bwd("abcba", "b", 0, -1); + fxt.Test_Find_bwd("abcba", "zb", 4, -1); + fxt.Test_Find_fwd("abcba", "a", -1, -1); + fxt.Test_Find_bwd("abcba", "ab", 4, 0); + } + @Test public void Find_bwd_last_ws() { + fxt.Test_Find_bwd_1st_ws_tst("a b" , 2, 1); // basic + fxt.Test_Find_bwd_1st_ws_tst("a b" , 3, 1); // multiple + fxt.Test_Find_bwd_1st_ws_tst("ab" , 1, Bry_find_.Not_found); // none + } + @Test public void Trim_fwd_space_tab() { + fxt.Test_Trim_fwd_space_tab(" a b" , 1); + fxt.Test_Trim_fwd_space_tab("\ta b" , 1); + fxt.Test_Trim_fwd_space_tab(" \ta b" , 2); + fxt.Test_Trim_fwd_space_tab("a bc" , 0); + fxt.Test_Trim_fwd_space_tab("" , 0); + fxt.Test_Trim_fwd_space_tab(" \t" , 2); + } + @Test public void Trim_bwd_space_tab() { + fxt.Test_Trim_bwd_space_tab("a b " , 3); + fxt.Test_Trim_bwd_space_tab("a b\t" , 3); + fxt.Test_Trim_bwd_space_tab("a b\t " , 3); + fxt.Test_Trim_bwd_space_tab("a bc" , 4); + fxt.Test_Trim_bwd_space_tab("" , 0); + fxt.Test_Trim_bwd_space_tab(" \t" , 0); + } + @Test public void Find_fwd_while_in() { + boolean[] while_ary = fxt.Init__find_fwd_while_in(Byte_ascii.Space, Byte_ascii.Tab, Byte_ascii.Nl); + fxt.Test__find_fwd_while_in(" \t\na", while_ary, 3); + } +} +class Bry_find__fxt { + public void Test_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_fwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));} + public void Test_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));} + public void Test_Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd_last_ws(Bry_.new_a7(src), pos));} + public void Test_Trim_bwd_space_tab(String raw_str, int expd) { + byte[] raw_bry = Bry_.new_u8(raw_str); + int actl = Bry_find_.Trim_bwd_space_tab(raw_bry, raw_bry.length, 0); + Tfds.Eq(expd, actl, raw_str); + } + public void Test_Trim_fwd_space_tab(String raw_str, int expd) { + byte[] raw_bry = Bry_.new_u8(raw_str); + int actl = Bry_find_.Trim_fwd_space_tab(raw_bry, 0, raw_bry.length); + Tfds.Eq(expd, actl, raw_str); + } + public boolean[] Init__find_fwd_while_in(byte... ary) { + boolean[] rv = new boolean[256]; + int len = ary.length; + for (int i = 0; i < len; i++) + rv[ary[i]] = true; + return rv; + } + public void Test__find_fwd_while_in(String src, boolean[] ary, int expd) { + byte[] src_bry = Bry_.new_u8(src); + Gftest.Eq__int(expd, Bry_find_.Find_fwd_while_in(src_bry, 0, src_bry.length, ary)); + } +} diff --git a/100_core/src/gplx/Bry_split__tst.java b/100_core/src/gplx/Bry_split__tst.java new file mode 100644 index 000000000..c6fb53018 --- /dev/null +++ b/100_core/src/gplx/Bry_split__tst.java @@ -0,0 +1,80 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; +public class Bry_split__tst { + private final Bry_split__fxt fxt = new Bry_split__fxt(); + @Test public void Split() { + fxt.Test_split("a" , Byte_ascii.Pipe, Bool_.N, "a"); // no trim + fxt.Test_split("a|" , Byte_ascii.Pipe, Bool_.N, "a"); + fxt.Test_split("|a" , Byte_ascii.Pipe, Bool_.N, "", "a"); + fxt.Test_split("|" , Byte_ascii.Pipe, Bool_.N, ""); + fxt.Test_split("" , Byte_ascii.Pipe, Bool_.N); + fxt.Test_split("a|b|c" , Byte_ascii.Pipe, Bool_.N, "a", "b", "c"); + fxt.Test_split(" a " , Byte_ascii.Pipe, Bool_.Y, "a"); // trim + fxt.Test_split(" a |" , Byte_ascii.Pipe, Bool_.Y, "a"); + fxt.Test_split("| a " , Byte_ascii.Pipe, Bool_.Y, "", "a"); + fxt.Test_split(" | " , Byte_ascii.Pipe, Bool_.Y, ""); + fxt.Test_split(" " , Byte_ascii.Pipe, Bool_.Y); + fxt.Test_split(" a | b | c " , Byte_ascii.Pipe, Bool_.Y, "a", "b", "c"); + fxt.Test_split(" a b | c d " , Byte_ascii.Pipe, Bool_.Y, "a b", "c d"); + fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.N, " a ", " b "); // ws as dlm + fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.Y, "a", "b"); // ws as dlm; trim + fxt.Test_split("a|extend|b" , Byte_ascii.Pipe, Bool_.Y, "a", "extend|b"); // extend + fxt.Test_split("extend|a" , Byte_ascii.Pipe, Bool_.Y, "extend|a"); // extend + fxt.Test_split("a|cancel|b" , Byte_ascii.Pipe, Bool_.Y, "a"); // cancel + } + @Test public void Split__bry() { + fxt.Test_split("a|b|c|d" , 2, 6, "|", "b", "c"); + fxt.Test_split("a|b|c|d" , 2, 4, "|", "b"); + } + @Test public void Empty() { + fxt.Test_split("a\n\nb" , Byte_ascii.Nl, Bool_.N, "a", "", "b"); + } + @Test public void Split_w_max() { + fxt.Test__split_w_max("a|b|c|d" , Byte_ascii.Pipe, 2, "a", "b"); // max is less + fxt.Test__split_w_max("a" , Byte_ascii.Pipe, 2, "a", null); // max is more + fxt.Test__split_w_max("|" , Byte_ascii.Pipe, 2, "", ""); // empty itms + } +} +class Bry_split__fxt { + private final Bry_split_wkr__example wkr = new Bry_split_wkr__example(); + public void Test_split(String raw_str, byte dlm, boolean trim, String... expd) { + byte[] src = Bry_.new_a7(raw_str); + Bry_split_.Split(src, 0, src.length, dlm, trim, wkr); + byte[][] actl_ary = wkr.To_ary(); + Tfds.Eq_ary_str(expd, String_.Ary(actl_ary)); + } + public void Test_split(String src, int src_bgn, int src_end, String dlm, String... expd) { + Tfds.Eq_ary_str(Bry_.Ary(expd), Bry_split_.Split(Bry_.new_u8(src), src_bgn, src_end, Bry_.new_u8(dlm))); + } + public void Test__split_w_max(String src, byte dlm, int max, String... expd) { + Gftest.Eq__ary(expd, String_.Ary(Bry_split_.Split_w_max(Bry_.new_u8(src), dlm, max))); + } +} +class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr { + private final List_adp list = List_adp_.New(); + public int Split(byte[] src, int itm_bgn, int itm_end) { + byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end); + if (Bry_.Eq(bry, Bry_.new_a7("extend"))) return Bry_split_.Rv__extend; + else if (Bry_.Eq(bry, Bry_.new_a7("cancel"))) return Bry_split_.Rv__cancel; + list.Add(bry); + return Bry_split_.Rv__ok; + } + public byte[][] To_ary() { + return (byte[][])list.To_ary_and_clear(byte[].class); + } +} diff --git a/100_core/src/gplx/Byte__tst.java b/100_core/src/gplx/Byte__tst.java new file mode 100644 index 000000000..e6d1194ae --- /dev/null +++ b/100_core/src/gplx/Byte__tst.java @@ -0,0 +1,33 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Byte__tst { + @Test public void int_() { + tst_int_( 0, 0); + tst_int_( 127, 127); + tst_int_( 128, 128); // NOTE: JAVA defines byte as -128 -> 127 + tst_int_( 255, 255); + tst_int_( 256, 0); // NOTE: 256 will cast to 1; (byte)256 works same in both JAVA/.NET + } void tst_int_(int v, int expd) {Tfds.Eq((byte)expd, Byte_.By_int(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints + @Test public void To_int() { + tst_XtoInt( 0, 0); + tst_XtoInt( 127, 127); + tst_XtoInt( 128, 128); + tst_XtoInt( 255, 255); + tst_XtoInt( 256, 0); + } void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.To_int((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints +} diff --git a/100_core/src/gplx/DateAdp__tst.java b/100_core/src/gplx/DateAdp__tst.java new file mode 100644 index 000000000..02d99a22f --- /dev/null +++ b/100_core/src/gplx/DateAdp__tst.java @@ -0,0 +1,86 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; +public class DateAdp__tst { + private final DateAdp__fxt fxt = new DateAdp__fxt(); + @Test public void Parse_gplx() { + fxt.Test__parse_gplx("99991231_235959.999" , "99991231_235959.999"); + fxt.Test__parse_gplx("20090430_213200.123" , "20090430_213200.123"); + fxt.Test__parse_gplx("20090430_213200" , "20090430_213200.000"); + fxt.Test__parse_gplx("20090430" , "20090430_000000.000"); + } + @Test public void Parse_separators() { + fxt.Test__parse_gplx("2009-04-30 21:32:00.123" , "20090430_213200.123"); + fxt.Test__parse_gplx("2009-04-30 21:32:00" , "20090430_213200.000"); + fxt.Test__parse_gplx("2009-04-30" , "20090430_000000.000"); + } + @Test public void Parse_utc() { + fxt.Test__parse_gplx("2015-12-26T10:03:53Z" , "20151226_100353.000"); + } + @Test public void DayOfWeek() { + fxt.Test__day_of_week("2012-01-18", 3); //3=Wed + } + @Test public void WeekOfYear() { + fxt.Test__week_of_year("2006-02-01", 5); // 1-1:Sun;2-1:Wed + fxt.Test__week_of_year("2007-02-01", 5); // 1-1:Mon;2-1:Thu + fxt.Test__week_of_year("2008-02-01", 5); // 1-1:Tue;2-1:Fri + fxt.Test__week_of_year("2009-02-01", 6); // 1-1:Thu;2-1:Sun + fxt.Test__week_of_year("2010-02-01", 6); // 1-1:Fri;2-1:Mon + fxt.Test__week_of_year("2011-02-01", 6); // 1-1:Sat;2-1:Tue + } + @Test public void DayOfYear() { + fxt.Test__day_of_year("2012-01-01", 1); + fxt.Test__day_of_year("2012-02-29", 60); + fxt.Test__day_of_year("2012-12-31", 366); + } + @Test public void Timestamp_unix() { + fxt.Test__timestamp_unix("1970-01-01 00:00:00", 0); + fxt.Test__timestamp_unix("2012-01-01 00:00:00", 1325376000); + } + @Test public void DaysInMonth() { + fxt.Test__days_in_month("2012-01-01", 31); + fxt.Test__days_in_month("2012-02-01", 29); + fxt.Test__days_in_month("2012-04-01", 30); + fxt.Test__days_in_month("2011-02-01", 28); + } + @Test public void XtoUtc() { + fxt.Test__to_utc("2012-01-01 00:00", "2012-01-01 05:00"); //4=Wed + } +} +class DateAdp__fxt { + public void Test__parse_gplx(String raw, String expd) { + Gftest.Eq__str(expd, DateAdp_.parse_gplx(raw).XtoStr_gplx()); + } + public void Test__day_of_week(String raw, int expd) { + Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).DayOfWeek()); + } + public void Test__week_of_year(String raw, int expd) { + Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).WeekOfYear()); + } + public void Test__day_of_year(String raw, int expd) { + Gftest.Eq__int(expd, DateAdp_.parse_gplx(raw).DayOfYear()); + } + public void Test__days_in_month(String raw, int expd) { + Gftest.Eq__int(expd, DateAdp_.DaysInMonth(DateAdp_.parse_gplx(raw))); + } + public void Test__timestamp_unix(String raw, long expd) { + Gftest.Eq__long(expd, DateAdp_.parse_gplx(raw).Timestamp_unix()); + } + public void Test__to_utc(String raw, String expd) { + Tfds.Eq(expd, DateAdp_.parse_gplx(raw).XtoUtc().XtoStr_fmt_yyyy_MM_dd_HH_mm()); + } +} diff --git a/100_core/src/gplx/Decimal_adp__tst.java b/100_core/src/gplx/Decimal_adp__tst.java new file mode 100644 index 000000000..5ee584dc8 --- /dev/null +++ b/100_core/src/gplx/Decimal_adp__tst.java @@ -0,0 +1,86 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Decimal_adp__tst { + private final Decimal_adp__fxt fxt = new Decimal_adp__fxt(); + @Test public void divide_() { + fxt.Test_divide(1, 1000, "0.001"); + fxt.Test_divide(1, 3, "0.33333333333333"); + fxt.Test_divide(1, 7, "0.14285714285714"); + } + @Test public void base1000_() { + fxt.Test_base_1000(1000, "1"); + fxt.Test_base_1000(1234, "1.234"); + fxt.Test_base_1000(123, "0.123"); + } + @Test public void parts_() { + fxt.Test_parts(1, 0, "1"); + fxt.Test_parts(1, 2, "1.2"); + fxt.Test_parts(1, 23, "1.23"); + fxt.Test_parts(123, 4567, "123.4567"); + } + @Test public void parse() { + fxt.Test_parse("1", "1"); + fxt.Test_parse("1.2", "1.2"); + fxt.Test_parse("0.1", "0.1"); + } + @Test public void Truncate_decimal() { + fxt.Test_truncate_decimal("1", "1"); + fxt.Test_truncate_decimal("1.1", "1"); + fxt.Test_truncate_decimal("1.9", "1"); + } + @Test public void Fraction1000() { + fxt.Test_frac_1000(1, 1000, 1); // 0.001 + fxt.Test_frac_1000(1, 3, 333); // 0.33333333 + fxt.Test_frac_1000(1234, 1000, 234); // 1.234 + fxt.Test_frac_1000(12345, 10000, 234); // 1.2345 + } + @Test public void Lt() { + fxt.Test_comp_lt(1,123, 2, true); + fxt.Test_comp_lt(1,99999999, 2, true); + } + @Test public void To_str_fmt() { + fxt.Test_to_str_fmt(1, 2, "0.0", "0.5"); + fxt.Test_to_str_fmt(1, 3, "0.0", "0.3"); + fxt.Test_to_str_fmt(10000, 7, "0,000.000", "1,428.571"); + fxt.Test_to_str_fmt(1, 2, "00.00", "00.50"); + } + @Test public void Round() { + fxt.Test_round("123.456", 3, "123.456"); + fxt.Test_round("123.456", 2, "123.46"); + fxt.Test_round("123.456", 1, "123.5"); + fxt.Test_round("123.456", 0, "123"); + fxt.Test_round("123.456", -1, "120"); + fxt.Test_round("123.456", -2, "100"); + fxt.Test_round("123.456", -3, "0"); + + fxt.Test_round("6", -1, "10"); + fxt.Test_round("5", -1, "10"); + fxt.Test_round("6", -2, "0"); + } +} +class Decimal_adp__fxt { + public void Test_divide(int lhs, int rhs, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).To_str());} + public void Test_base_1000(int val, String expd) {Tfds.Eq(expd, Decimal_adp_.base1000_(val).To_str());} + public void Test_parts(int num, int fracs, String expd) {Tfds.Eq(expd, Decimal_adp_.parts_(num, fracs).To_str());} + public void Test_parse(String raw, String expd) {Tfds.Eq(expd, Decimal_adp_.parse(raw).To_str());} + public void Test_truncate_decimal(String raw, String expd) {Tfds.Eq(Decimal_adp_.parse(expd).To_str(), Decimal_adp_.parse(raw).Truncate().To_str());} + public void Test_frac_1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).Frac_1000());} + public void Test_comp_lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, Decimal_adp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));} + public void Test_to_str_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(l, r).To_str(fmt));} + public void Test_round(String raw, int places, String expd) {Tfds.Eq_str(expd, Decimal_adp_.parse(raw).Round(places).To_str(), "round");} +} diff --git a/100_core/src/gplx/Double__tst.java b/100_core/src/gplx/Double__tst.java new file mode 100644 index 000000000..72c7ece9e --- /dev/null +++ b/100_core/src/gplx/Double__tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Double__tst { + private Double__fxt fxt = new Double__fxt(); + @Test public void Xto_str_loose() { + fxt.Test_Xto_str_loose(2449.6000000d , "2449.6"); + fxt.Test_Xto_str_loose(623.700d , "623.7"); + } +} +class Double__fxt { + public void Test_Xto_str_loose(double v, String expd) {Tfds.Eq(expd, Double_.To_str_loose(v));} +} diff --git a/100_core/src/gplx/Err_tst.java b/100_core/src/gplx/Err_tst.java new file mode 100644 index 000000000..fcc162028 --- /dev/null +++ b/100_core/src/gplx/Err_tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Err_tst { + private final Err_fxt fxt = new Err_fxt(); + @Test public void Trace_to_str__gplx() { + fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 0, String_.Concat_lines_nl_skip_last + ( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line + , "gplx.String_.Len(String_.java:2)" + ), String_.Concat_lines_nl_skip_last + ( "" + , " gplx.String_.Len(String_.java:2)" + )); + } + @Test public void Trace_to_str__gplx_ignore() { + fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 1, String_.Concat_lines_nl_skip_last + ( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line + , "gplx.String_.Fail(String_.java:2)" // ignore this line also + , "gplx.String_.Len(String_.java:3)" + ), String_.Concat_lines_nl_skip_last + ( "" + , " gplx.String_.Len(String_.java:3)" + )); + } +} +class Err_fxt { + public void Test_Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace, String expd) { + String actl = Err.Trace_to_str(is_gplx, called_by_log, ignore_lines, trace); + Tfds.Eq_str_lines(expd, actl); + } +} diff --git a/100_core/src/gplx/GfoMsg_tst.java b/100_core/src/gplx/GfoMsg_tst.java new file mode 100644 index 000000000..0610da5ff --- /dev/null +++ b/100_core/src/gplx/GfoMsg_tst.java @@ -0,0 +1,49 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.langs.gfs.*; +public class GfoMsg_tst { + @Before public void setup() { + GfsCore.Instance.AddObj(new Mok(), "Mok"); + } + @Test public void Write1() { + GfoMsg m = GfoMsg_.root_leafArgs_(String_.Ary("a", "b"), Keyval_.new_("int0", 1)); + tst_Msg(m, "a.b:int0='1';"); + } + @Test public void Write() { + Mok mok = new Mok(); + tst_Msg(Gfo_invk_to_str.WriteMsg(mok, Mok.Invk_Cmd0, true, 1, "a"), "Mok.Cmd0:bool0='y' int0='1' str0='a';"); + mok.Int0 = 2; + mok.Bool0 = true; + mok.Str0 = "b"; + tst_Msg(Gfo_invk_to_str.ReadMsg(mok, Mok.Invk_Cmd0), "Mok.Cmd0:bool0='y' int0='2' str0='b';"); + } + void tst_Msg(GfoMsg m, String expd) {Tfds.Eq(expd, m.To_str());} + class Mok implements Gfo_invk { + public boolean Bool0; + public int Int0; + public String Str0; + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_Cmd0)) { + Bool0 = m.ReadBoolOr("bool0", Bool0); + Int0 = m.ReadIntOr("int0", Int0); + Str0 = m.ReadStrOr("str0", Str0); + if (ctx.Deny()) return this; + } + return this; + } public static final String Invk_Cmd0 = "Cmd0"; + } +} diff --git a/100_core/src/gplx/Gfo_evt_mgr_tst.java b/100_core/src/gplx/Gfo_evt_mgr_tst.java new file mode 100644 index 000000000..28c91d2cc --- /dev/null +++ b/100_core/src/gplx/Gfo_evt_mgr_tst.java @@ -0,0 +1,67 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Gfo_evt_mgr_tst { + @Before public void setup() { + pub = make_(); sub = make_(); + } MockEvObj pub, sub; + @Test public void Basic() { + Gfo_evt_mgr_.Sub_same(pub, "ev1", sub); + Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1"); + sub.tst_Handled("val1"); + } + @Test public void None() {// make sure no subscribers does not cause exception + Gfo_evt_mgr_.Sub_same(pub, "ev1", sub); + Gfo_evt_mgr_.Pub_val(pub, "ev2", "val1"); //ev2 does not exist + sub.tst_Handled(); + } + @Test public void Lnk() { + MockEvObj mid = make_(); + mid.Evt_mgr().Lnk(pub); + Gfo_evt_mgr_.Sub_same(mid, "ev1", sub); + Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1"); + sub.tst_Handled("val1"); + } + @Test public void RlsSub() { + this.Basic(); + + Gfo_evt_mgr_.Rls_sub(sub); + Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1"); + sub.tst_Handled(); + } + @Test public void RlsPub() { + this.Basic(); + + Gfo_evt_mgr_.Rls_sub(pub); + Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1"); + sub.tst_Handled(); + } + MockEvObj make_() {return new MockEvObj();} +} +class MockEvObj implements Gfo_evt_itm { + public Gfo_evt_mgr Evt_mgr() {return eventMgr;} Gfo_evt_mgr eventMgr; + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + handled.Add(m.ReadStr("v")); + return this; + } + List_adp handled = List_adp_.New(); + public void tst_Handled(String... expd) { + Tfds.Eq_ary_str(expd, handled.To_str_ary()); + handled.Clear(); + } + public MockEvObj(){eventMgr = new Gfo_evt_mgr(this);} +} diff --git a/100_core/src/gplx/Guid_adp__tst.java b/100_core/src/gplx/Guid_adp__tst.java new file mode 100644 index 000000000..4eac0e7dd --- /dev/null +++ b/100_core/src/gplx/Guid_adp__tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Guid_adp__tst { + @Test public void parse() { + tst_parse_("467ffb41-cdfe-402f-b22b-be855425784b"); + } + void tst_parse_(String s) { + Guid_adp uuid = Guid_adp_.Parse(s); + Tfds.Eq(uuid.To_str(), s); + } +} diff --git a/100_core/src/gplx/Hash_adp_bry_tst.java b/100_core/src/gplx/Hash_adp_bry_tst.java new file mode 100644 index 000000000..e33f2be9d --- /dev/null +++ b/100_core/src/gplx/Hash_adp_bry_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Hash_adp_bry_tst { + @Before public void setup() {fxt.Clear();} private Hash_adp_bry_fxt fxt = new Hash_adp_bry_fxt(); + @Test public void Add_bry() { + fxt .New_cs() + .Add("a0").Add("b0").Add("c0") + .Get_bry_tst("a0").Get_bry_tst("b0").Get_bry_tst("c0").Get_bry_tst("A0", null) + ; + } + @Test public void Get_mid() { + fxt .New_cs() + .Add("a0").Add("b0").Add("c0") + .Get_mid_tst("xyza0xyz", 3, 5, "a0") + .Get_mid_tst("xyza0xyz", 3, 4, null) + ; + } + @Test public void Case_insensitive() { + fxt .New_ci() + .Add("a0").Add("B0").Add("c0") + .Get_bry_tst("a0", "a0") + .Get_bry_tst("A0", "a0") + .Get_bry_tst("b0", "B0") + .Get_bry_tst("B0", "B0") + .Get_mid_tst("xyza0xyz", 3, 5, "a0") + .Get_mid_tst("xyzA0xyz", 3, 5, "a0") + .Count_tst(3) + ; + } +} +class Hash_adp_bry_fxt { + Hash_adp_bry hash; + public void Clear() {} + public Hash_adp_bry_fxt New_cs() {hash = Hash_adp_bry.cs(); return this;} + public Hash_adp_bry_fxt New_ci() {hash = Hash_adp_bry.ci_a7(); return this;} + public Hash_adp_bry_fxt Add(String key) {byte[] key_bry = Bry_.new_u8(key); hash.Add(key_bry, key_bry); return this;} + public Hash_adp_bry_fxt Count_tst(int expd) {Tfds.Eq(expd, hash.Count()); return this;} + public Hash_adp_bry_fxt Get_bry_tst(String key) {return Get_bry_tst(key, key);} + public Hash_adp_bry_fxt Get_bry_tst(String key, String expd) { + byte[] key_bry = Bry_.new_u8(key); + byte[] actl_bry = (byte[])hash.Get_by_bry(key_bry); + Tfds.Eq(expd, String_.new_u8(actl_bry)); + return this; + } + public Hash_adp_bry_fxt Get_mid_tst(String key, int bgn, int end, String expd) { + byte[] key_bry = Bry_.new_u8(key); + byte[] actl_bry = (byte[])hash.Get_by_mid(key_bry, bgn, end); + Tfds.Eq(expd, String_.new_u8(actl_bry)); + return this; + } +} diff --git a/100_core/src/gplx/Int__tst.java b/100_core/src/gplx/Int__tst.java new file mode 100644 index 000000000..e4efed599 --- /dev/null +++ b/100_core/src/gplx/Int__tst.java @@ -0,0 +1,97 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Int__tst { + @Test public void XtoStr_PadBgn() { + tst_XtoStr_PadLeft_Zeroes(1 , 3, "001"); // pad + tst_XtoStr_PadLeft_Zeroes(123 , 3, "123"); // no pad + tst_XtoStr_PadLeft_Zeroes(1234 , 3, "1234"); // val exceeds pad; confirm noop + tst_XtoStr_PadLeft_Zeroes(-1 , 3, "-01"); // negative + tst_XtoStr_PadLeft_Zeroes(-12 , 3, "-12"); // negative + tst_XtoStr_PadLeft_Zeroes(-123 , 3, "-123"); // negative + tst_XtoStr_PadLeft_Zeroes(-1234 , 3, "-1234"); // negative + } void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.To_str_pad_bgn_zero(val, zeros));} + @Test public void parseOr_() { + tst_ParseOr("", -1); // empty + tst_ParseOr("123", 123); // single + tst_ParseOr("1a", -1); // fail + } void tst_ParseOr(String raw, int expd) {Tfds.Eq(expd, Int_.Parse_or(raw, -1));} + @Test public void Between() { + tst_Between(1, 0, 2, true); // simple true + tst_Between(3, 0, 2, false); // simple false + tst_Between(0, 0, 2, true); // bgn true + tst_Between(2, 0, 2, true); // end true + } void tst_Between(int val, int lhs, int rhs, boolean expd) {Tfds.Eq(expd, Int_.Between(val, lhs, rhs));} + @Test public void Xto_fmt() { + tst_XtoStr_fmt(1, "1"); + tst_XtoStr_fmt(1000, "1,000"); + } void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.To_str_fmt(v, "#,###"));} + @Test public void Log10_pos() { + tst_Log10(0, 0); + tst_Log10(1, 0); + tst_Log10(9, 0); + tst_Log10(10, 1); + tst_Log10(100, 2); + tst_Log10(1000000, 6); + tst_Log10(1000000000, 9); + tst_Log10(Int_.Max_value, 9); + } + @Test public void Log10_neg() { + tst_Log10(-1, 0); + tst_Log10(-10, -1); + tst_Log10(-100, -2); + tst_Log10(-1000000, -6); + tst_Log10(-1000000000, -9); + tst_Log10(Int_.Min_value, -9); + tst_Log10(Int_.Min_value + 1, -9); + } + void tst_Log10(int val, int expd) {Tfds.Eq(expd, Int_.Log10(val));} + @Test public void DigitCount() { + tst_DigitCount(0, 1); + tst_DigitCount(9, 1); + tst_DigitCount(100, 3); + tst_DigitCount(-1, 2); + tst_DigitCount(-100, 4); + } void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.To_str(val));} + @Test public void Log10() { + tst_Log10( 0, 0); + tst_Log10( 1, 0); + tst_Log10( 2, 0); + tst_Log10( 10, 1); + tst_Log10( 12, 1); + tst_Log10( 100, 2); + tst_Log10( 123, 2); + tst_Log10( 1000, 3); + tst_Log10( 1234, 3); + tst_Log10( 10000, 4); + tst_Log10( 12345, 4); + tst_Log10( 100000, 5); + tst_Log10( 123456, 5); + tst_Log10( 1000000, 6); + tst_Log10( 1234567, 6); + tst_Log10( 10000000, 7); + tst_Log10( 12345678, 7); + tst_Log10( 100000000, 8); + tst_Log10( 123456789, 8); + tst_Log10( 1000000000, 9); + tst_Log10( 1234567890, 9); + tst_Log10(Int_.Max_value, 9); + } + @Test public void Xto_int_hex_tst() { + Xto_int_hex("007C", 124); + } void Xto_int_hex(String raw, int expd) {Tfds.Eq(expd, Int_.By_hex_bry(Bry_.new_a7(raw)));} +} diff --git a/100_core/src/gplx/Int_ary__tst.java b/100_core/src/gplx/Int_ary__tst.java new file mode 100644 index 000000000..e2486b2f1 --- /dev/null +++ b/100_core/src/gplx/Int_ary__tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; +public class Int_ary__tst { + private Int_ary__fxt fxt = new Int_ary__fxt(); + + @Test public void Parse() { + fxt.Test__Parse("1,2,3" , 3, Int_ary_.Empty, 1, 2, 3); + fxt.Test__Parse("123,321,213" , 3, Int_ary_.Empty, 123, 321, 213); + fxt.Test__Parse(" 1, 2,3" , 3, Int_ary_.Empty, 1, 2, 3); + fxt.Test__Parse("-1,+2,-3" , 3, Int_ary_.Empty, -1, 2, -3); + fxt.Test__Parse(Int_.To_str(Int_.Min_value) , 1, Int_ary_.Empty, Int_.Min_value); + fxt.Test__Parse(Int_.To_str(Int_.Max_value) , 1, Int_ary_.Empty, Int_.Max_value); + fxt.Test__Parse("1,2" , 1, Int_ary_.Empty); + fxt.Test__Parse("1" , 2, Int_ary_.Empty); + fxt.Test__Parse("a" , 1, Int_ary_.Empty); + fxt.Test__Parse("1-2," , 1, Int_ary_.Empty); + } + + @Test public void Parse_list_or_() { + fxt.Test__Parse_or("1", 1); + fxt.Test__Parse_or("123", 123); + fxt.Test__Parse_or("1,2,123", 1, 2, 123); + fxt.Test__Parse_or("1,2,12,123", 1, 2, 12, 123); + fxt.Test__Parse_or("1-5", 1, 2, 3, 4, 5); + fxt.Test__Parse_or("1-1", 1); + fxt.Test__Parse_or("1-3,7,11-13,21", 1, 2, 3, 7, 11, 12, 13, 21); + + fxt.Test__Parse_or__empty("1 2"); // NOTE: MW would gen 12; treat as invalid + fxt.Test__Parse_or__empty("1,"); // eos + fxt.Test__Parse_or__empty("1,,2"); // empty comma + fxt.Test__Parse_or__empty("1-"); // eos + fxt.Test__Parse_or__empty("3-1"); // bgn > end + fxt.Test__Parse_or__empty("1,a,2"); + fxt.Test__Parse_or__empty("a-1,2"); + fxt.Test__Parse_or__empty("-1"); // no rng bgn + } +} +class Int_ary__fxt { + public void Test__Parse_or__empty(String raw) {Tfds.Eq_ary(Int_ary_.Empty, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));} + public void Test__Parse_or(String raw, int... expd) {Tfds.Eq_ary(expd, Int_ary_.Parse_or(Bry_.new_a7(raw), Int_ary_.Empty));} + + public void Test__Parse(String raw, int reqd_len, int[] or, int... expd) {Gftest.Eq__ary(expd, Int_ary_.Parse(raw, reqd_len, or), "failed to parse: {0}", raw);} +} diff --git a/100_core/src/gplx/Io_mgr__tst.java b/100_core/src/gplx/Io_mgr__tst.java new file mode 100644 index 000000000..5f5a6b912 --- /dev/null +++ b/100_core/src/gplx/Io_mgr__tst.java @@ -0,0 +1,98 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Io_mgr__tst { + @Before public void init() {fxt.Clear();} private final Io_mgr__fxt fxt = new Io_mgr__fxt(); + @Test public void Dir_delete_empty__basic() { + fxt.Exec_itm_create("mem/dir/"); + fxt.Exec_dir_delete_empty("mem/dir/"); + fxt.Test_itm_exists_n("mem/dir/"); + } + @Test public void Dir_delete_empty__no_delete() { + fxt.Exec_itm_create + ( "mem/dir/" + , "mem/dir/fil.txt" + ); + fxt.Exec_dir_delete_empty("mem/dir/"); + fxt.Test_itm_exists_y("mem/dir/"); + } + @Test public void Dir_delete_empty__nested_simple() { + fxt.Exec_itm_create + ( "mem/dir/" + , "mem/dir/1/" + , "mem/dir/1/11/" + ); + fxt.Exec_dir_delete_empty("mem/dir/"); + fxt.Test_itm_exists_n("mem/dir/"); + } + @Test public void Dir_delete_empty__nested_many() { + fxt.Exec_itm_create + ( "mem/dir/" + , "mem/dir/1/" + , "mem/dir/1/11/" + , "mem/dir/2/22/" + , "mem/dir/2/22/222a/" + , "mem/dir/2/22/222b/" + ); + fxt.Exec_dir_delete_empty("mem/dir/"); + fxt.Test_itm_exists_n("mem/dir/"); + } + @Test public void Dir_delete_empty__nested_some() { + fxt.Exec_itm_create + ( "mem/dir/" + , "mem/dir/1/" + , "mem/dir/1/11/" + , "mem/dir/2/22/" + , "mem/dir/2/22/a.txt" + , "mem/dir/2/22/222a/" + , "mem/dir/2/22/222b/" + ); + fxt.Exec_dir_delete_empty("mem/dir/"); + fxt.Test_itm_exists_n + ( "mem/dir/1/" + , "mem/dir/1/11/" + , "mem/dir/2/22/222a/" + , "mem/dir/2/22/222b/" + ); + fxt.Test_itm_exists_y + ( "mem/dir/" + , "mem/dir/2/22/" + ); + } +} +class Io_mgr__fxt { + public void Clear() {Io_mgr.Instance.InitEngine_mem();} + public void Exec_itm_create(String... ary) { + for (String itm : ary) { + Io_url url = Io_url_.new_any_(itm); + if (url.Type_dir()) + Io_mgr.Instance.CreateDir(url); + else + Io_mgr.Instance.SaveFilStr(url, url.NameAndExt()); + } + } + public void Exec_dir_delete_empty(String url) {Io_mgr.Instance.Delete_dir_empty(Io_url_.mem_dir_(url));} + public void Test_itm_exists_n(String... ary) {Test_itm_exists(Bool_.N, ary);} + public void Test_itm_exists_y(String... ary) {Test_itm_exists(Bool_.Y, ary);} + public void Test_itm_exists(boolean expd, String... ary) { + for (String itm : ary) { + Io_url url = Io_url_.new_any_(itm); + boolean actl = url.Type_dir() ? Io_mgr.Instance.ExistsDir(url) : Io_mgr.Instance.ExistsFil(url); + Tfds.Eq(expd, actl, itm); + } + } +} diff --git a/100_core/src/gplx/Io_url__tst.java b/100_core/src/gplx/Io_url__tst.java new file mode 100644 index 000000000..5d2198292 --- /dev/null +++ b/100_core/src/gplx/Io_url__tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*; +public class Io_url__tst { + @Before public void init() {fxt.Clear();} private final Io_url__fxt fxt = new Io_url__fxt(); + @Test public void Basic__lnx() {fxt.Test__New__http_or_null(Bool_.N, "file:///C:/a.txt", "C:/a.txt");} + @Test public void Basic__wnt() {fxt.Test__New__http_or_null(Bool_.Y, "file:///C:/a.txt", "C:\\a.txt");} + @Test public void Null() {fxt.Test__New__http_or_null(Bool_.N, "C:/a.txt", null);} +} +class Io_url__fxt { + public void Clear() {Io_mgr.Instance.InitEngine_mem();} + public void Test__New__http_or_null(boolean os_is_wnt, String raw, String expd) { + Op_sys.Cur_(os_is_wnt ? Op_sys.Tid_wnt : Op_sys.Tid_lnx); + Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw)); + } +} diff --git a/100_core/src/gplx/List_adp_tst.java b/100_core/src/gplx/List_adp_tst.java new file mode 100644 index 000000000..48cb8f3be --- /dev/null +++ b/100_core/src/gplx/List_adp_tst.java @@ -0,0 +1,220 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class List_adp_tst { + @Before public void setup() { + list = List_adp_.New(); + listBase = (List_adp_base)list; + } List_adp list; List_adp_base listBase; + @Test public void Add() { + Tfds.Eq(0, list.Count()); + + list.Add("0"); + Tfds.Eq(1, list.Count()); + } + @Test public void Add_changeCapacity() { + int capacity = 8; + for (int i = 0; i < capacity; i++) + list.Add("0"); + Tfds.Eq(capacity, list.Count()); + Tfds.Eq(capacity, listBase.Capacity()); + + list.Add(capacity); // forces resize + Tfds.Eq(capacity + 1, list.Count()); + Tfds.Eq(capacity * 2, listBase.Capacity()); + } + @Test public void Get_at() { + list.Add("0"); + + Tfds.Eq("0", list.Get_at(0)); + } + @Test public void Fetch_many() { + list_AddMany("0", "1"); + + Tfds.Eq("0", list.Get_at(0)); + Tfds.Eq("1", list.Get_at(1)); + } + @Test public void FetchAt_fail() { + try {list.Get_at(0);} + catch (Exception exc) {Err_.Noop(exc); return;} + Tfds.Fail("Get_at should fail for out of bound index"); + } + @Test public void Del_at() { + list.Add("0"); + Tfds.Eq(1, list.Count()); + + list.Del_at(0); + Tfds.Eq(0, list.Count()); + } + @Test public void DelAt_shiftDown() { + list_AddMany("0", "1"); + Tfds.Eq(list.Count(), 2); + + list.Del_at(0); + Tfds.Eq(1, list.Count()); + Tfds.Eq("1", list.Get_at(0)); + } + @Test public void DelAt_fail() { + try {list.Del_at(0);} + catch (Exception exc) {Err_.Noop(exc); return;} + Tfds.Fail("Del_at should fail for out of bound index"); + } + @Test public void Del() { + list.Add("0"); + Tfds.Eq(1, list.Count()); + + list.Del("0"); + Tfds.Eq(0, list.Count()); + } + @Test public void Del_matchMember() { + list_AddMany("0", "1"); + Tfds.Eq(2, list.Count()); + + list.Del("1"); + Tfds.Eq(1, list.Count()); + Tfds.Eq("0", list.Get_at(0)); + } + @Test public void Del_matchFirst() { + list_AddMany("0", "1", "0"); + Tfds.Eq(3, list.Count()); + + list.Del("0"); + tst_Enumerator("1", "0"); + } + @Test public void Enumerator() { + list_AddMany("0", "1", "2"); + tst_Enumerator("0", "1", "2"); + } + @Test public void Enumerator_stateLess() { // run 2x, to confirm no state is being cached + list_AddMany("0", "1", "2"); + tst_Enumerator("0", "1", "2"); + tst_Enumerator("0", "1", "2"); + } + @Test public void Enumerator_recursive() { // confirm separate enumerator objects are used + int pos = 0; + list_AddMany("0", "1", "2"); + for (Object valObj : list) { + String val = (String)valObj; + Tfds.Eq(Int_.To_str(pos++), val); + tst_Enumerator("0", "1", "2"); + } + } + @Test public void Clear() { + int capacity = 8; + for (int i = 0; i < capacity + 1; i++) + list.Add("0"); + Tfds.Eq(capacity * 2, listBase.Capacity()); + + list.Clear(); + Tfds.Eq(0, list.Count()); + Tfds.Eq(16, listBase.Capacity()); // check that capacity has increased + } + @Test public void Clear_empty() { // confirm no failure + list.Clear(); + Tfds.Eq(0, list.Count()); + } + @Test public void Reverse() { + list_AddMany("0", "1", "2"); + + list.Reverse(); + tst_Enumerator("2", "1", "0"); + } + @Test public void Reverse_empty() {list.Reverse();} + @Test public void Sort() { + list_AddMany("2", "0", "1"); + + list.Sort(); + tst_Enumerator("0", "1", "2"); + } + @Test public void Sort_empty() {list.Sort();} + @Test public void Xto_bry() { + list_AddMany("0", "1"); + String[] ary = (String[])list.To_ary(String.class); + Tfds.Eq_nullNot(ary); + Tfds.Eq(2, Array_.Len(ary)); + } + @Test public void XtoAry_empty() { + String[] ary = (String[])list.To_ary(String.class); + Tfds.Eq_nullNot(ary); + Tfds.Eq(0, Array_.Len(ary)); + } + @Test public void Shuffle() { + for (int i = 0; i < 25; i++) + list.Add(i); + + list.Shuffle(); + int hasMovedCount = 0; + for (int i = 0; i < list.Count(); i++) { + int val = Int_.Cast(list.Get_at(i)); + if (val != i) hasMovedCount++; + } + Tfds.Eq_true(hasMovedCount > 0, "all documents have the same index"); // NOTE: may still fail occasionally (1%) + + int count = list.Count(); + for (int i = 0; i < count; i++) + list.Del(i); + Tfds.Eq(0, list.Count(), "shuffled list does not have the same contents as original list"); + } + @Test public void Shuffle_empty() {list.Shuffle();} + @Test public void Move_to() { + run_ClearAndAdd("0", "1", "2").run_MoveTo(0, 1).tst_Order("1", "0", "2"); + run_ClearAndAdd("0", "1", "2").run_MoveTo(0, 2).tst_Order("1", "2", "0"); + run_ClearAndAdd("0", "1", "2").run_MoveTo(2, 1).tst_Order("0", "2", "1"); + run_ClearAndAdd("0", "1", "2").run_MoveTo(2, 0).tst_Order("2", "0", "1"); + } + @Test public void Del_range() { + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 2, "3"); + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 3); + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(1, 2, "0", "3"); + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(1, 3, "0"); + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 3); + run_ClearAndAdd("0", "1", "2", "3").tst_DelRange(0, 0, "1", "2", "3"); + } + void tst_DelRange(int bgn, int end, String... expd) { + list.Del_range(bgn, end); + Tfds.Eq_ary_str(expd, list.To_str_ary()); + } + List_adp_tst run_ClearAndAdd(String... ary) { + list.Clear(); + for (int i = 0; i < Array_.Len(ary); i++) { + String val = ary[i]; + list.Add(val); + } + return this; + } + List_adp_tst run_MoveTo(int elemPos, int newPos) {list.Move_to(elemPos, newPos); return this;} + List_adp_tst tst_Order(String... expd) { + String[] actl = (String[])list.To_ary(String.class); + Tfds.Eq_ary(expd, actl); + return this; + } + void list_AddMany(String... ary) { + for (int i = 0; i < Array_.Len(ary); i++) { + String val = ary[i]; + list.Add(val); + } + } + void tst_Enumerator(String... expd) { + int pos = 0; + int expdLength = Array_.Len(expd); + for (int i = 0; i < expdLength; i++) { + String val = expd[i]; + Tfds.Eq(expd[pos++], val); + } + Tfds.Eq(pos, expdLength); + } +} diff --git a/100_core/src/gplx/Long__tst.java b/100_core/src/gplx/Long__tst.java new file mode 100644 index 000000000..1fa27a77e --- /dev/null +++ b/100_core/src/gplx/Long__tst.java @@ -0,0 +1,47 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Long__tst { + @Test public void DigitCount() { + tst_DigitCount(0, 1); + tst_DigitCount(1, 1); + tst_DigitCount(9, 1); + tst_DigitCount(10, 2); + tst_DigitCount(100, 3); + tst_DigitCount(10000, 5); + tst_DigitCount(100000, 6); + tst_DigitCount(1000000, 7); + tst_DigitCount(1000000000, 10); + tst_DigitCount(10000000000L, 11); + tst_DigitCount(100000000000L, 12); + tst_DigitCount(10000000000000000L, 17); + tst_DigitCount(-1, 2); + } void tst_DigitCount(long val, int expd) {Tfds.Eq(expd, Long_.DigitCount(val));} + @Test public void Int_merge() { + tst_Int_merge(123, 456, 528280977864L); + tst_Int_merge(123, 457, 528280977865L); + } + void tst_Int_merge(int hi, int lo, long expd) { + Tfds.Eq(expd, Long_.Int_merge(hi, lo)); + Tfds.Eq(hi, Long_.Int_split_hi(expd)); + Tfds.Eq(lo, Long_.Int_split_lo(expd)); + } + @Test public void parse_or() { + parse_or_tst("10000000000", 10000000000L); + } + void parse_or_tst(String raw, long expd) {Tfds.Eq(expd, Long_.parse_or(raw, -1));} +} diff --git a/100_core/src/gplx/Math__tst.java b/100_core/src/gplx/Math__tst.java new file mode 100644 index 000000000..75ba24d8d --- /dev/null +++ b/100_core/src/gplx/Math__tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Math__tst { + @Test public void Abs() { + tst_Abs(1, 1); + tst_Abs(-1, 1); + tst_Abs(0, 0); + } void tst_Abs(int val, int expd) {Tfds.Eq(expd, Math_.Abs(val));} + @Test public void Log10() { + tst_Log10(0, Int_.Min_value); + tst_Log10(9, 0); + tst_Log10(10, 1); + tst_Log10(99, 1); + tst_Log10(100, 2); + } void tst_Log10(int val, int expd) {Tfds.Eq(expd, Math_.Log10(val));} + @Test public void Min() { + tst_Min(0, 1, 0); + tst_Min(1, 0, 0); + tst_Min(0, 0, 0); + } void tst_Min(int val0, int val1, int expd) {Tfds.Eq(expd, Math_.Min(val0, val1));} + @Test public void Pow() { + tst_Pow(2, 0, 1); + tst_Pow(2, 1, 2); + tst_Pow(2, 2, 4); + } void tst_Pow(int val, int exponent, double expd) {Tfds.Eq(expd, Math_.Pow(val, exponent));} + @Test public void Mult() { + tst_Mult(100, .01f, 1); + } void tst_Mult(int val, float multiplier, int expd) {Tfds.Eq(expd, Int_.Mult(val, multiplier));} + @Test public void Base2Ary() { + tst_Base2Ary( 1, 256, 1); + tst_Base2Ary( 2, 256, 2); + tst_Base2Ary( 3, 256, 1, 2); + tst_Base2Ary( 4, 256, 4); + tst_Base2Ary( 5, 256, 1, 4); + tst_Base2Ary( 6, 256, 2, 4); + tst_Base2Ary(511, 256, 1, 2, 4, 8, 16, 32, 64, 128, 256); + } void tst_Base2Ary(int v, int max, int... expd) {Tfds.Eq_ary(expd, Math_.Base2Ary(v, max));} + @Test public void Round() { + tst_Round(1.5 , 0, 2); + tst_Round(2.5 , 0, 3); + tst_Round(2.123 , 2, 2.12); + tst_Round(21.1 , -1, 20); + } void tst_Round(double v, int places, double expd) {Tfds.Eq(expd, Math_.Round(v, places));} +} diff --git a/100_core/src/gplx/Object__tst.java b/100_core/src/gplx/Object__tst.java new file mode 100644 index 000000000..22b51f1c7 --- /dev/null +++ b/100_core/src/gplx/Object__tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Object__tst { + @Before public void init() {} private Object__fxt fxt = new Object__fxt(); + @Test public void Eq() { + fxt.Test_eq(null, null, true); // both null + fxt.Test_eq(5, 5, true); // both non-null + fxt.Test_eq(5, null, false); // rhs non-null + fxt.Test_eq(null, 5, false); // lhs non-null + } + @Test public void Xto_str_loose_or_null() { + fxt.Test_xto_str_loose_or_null(null, null); + fxt.Test_xto_str_loose_or_null(2449.6000000000004d, "2449.6"); + } +} +class Object__fxt { + public void Test_eq(Object lhs, Object rhs, boolean expd) {Tfds.Eq(expd, Object_.Eq(lhs, rhs));} + public void Test_xto_str_loose_or_null(Object v, String expd) {Tfds.Eq(expd, Object_.Xto_str_loose_or(v, null));} +} diff --git a/100_core/src/gplx/Ordered_hash_tst.java b/100_core/src/gplx/Ordered_hash_tst.java new file mode 100644 index 000000000..9865b8b9c --- /dev/null +++ b/100_core/src/gplx/Ordered_hash_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class Ordered_hash_tst { + @Before public void setup() { + hash = Ordered_hash_.New(); + } + @Test public void Get_at() { + hash.Add("key1", "val1"); + Tfds.Eq("val1", hash.Get_at(0)); + } + @Test public void iterator() { + hash.Add("key2", "val2"); + hash.Add("key1", "val1"); + + List_adp list = List_adp_.New(); + for (Object val : hash) + list.Add(val); + Tfds.Eq("val2", list.Get_at(0)); + Tfds.Eq("val1", list.Get_at(1)); + } + Ordered_hash hash; +} diff --git a/100_core/src/gplx/String__tst.java b/100_core/src/gplx/String__tst.java new file mode 100644 index 000000000..5fc7fa9e6 --- /dev/null +++ b/100_core/src/gplx/String__tst.java @@ -0,0 +1,182 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class String__tst { + @Test public void Len() { + tst_Len("", 0); + tst_Len("abc", 3); + } void tst_Len(String v, int expd) {Tfds.Eq(expd, String_.Len(v), "Len");} + + @Test public void LimitToFirst() { + tst_LimitToFirst("abc", 0, ""); + tst_LimitToFirst("abc", 1, "a"); + tst_LimitToFirst("abc", 2, "ab"); + tst_LimitToFirst("abc", 3, "abc"); + tst_LimitToFirst("abc", 4, "abc"); + err_LimitToFirst("abc", -1); + } + void tst_LimitToFirst(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToFirst(s, v));} + void err_LimitToFirst(String s, int v) {try {String_.LimitToFirst(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void LimitToLast() { + tst_LimitToLast("abc", 0, ""); + tst_LimitToLast("abc", 1, "c"); + tst_LimitToLast("abc", 2, "bc"); + tst_LimitToLast("abc", 3, "abc"); + tst_LimitToLast("abc", 4, "abc"); + err_LimitToLast("abc", -1); + } + void tst_LimitToLast(String s, int v, String expd) {Tfds.Eq(expd, String_.LimitToLast(s, v));} + void err_LimitToLast(String s, int v) {try {String_.LimitToLast(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void DelBgn() { + tst_DelBgn("abc", 0, "abc"); + tst_DelBgn("abc", 1, "bc"); + tst_DelBgn("abc", 2, "c"); + tst_DelBgn("abc", 3, ""); + err_DelBgn(null, 0); + err_DelBgn("abc", 4); + } + void tst_DelBgn(String s, int v, String expd) {Tfds.Eq(expd, String_.DelBgn(s, v));} + void err_DelBgn(String s, int v) {try {String_.DelBgn(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void DelBgnIf() { + tst_DelBgnIf("abc", "", "abc"); + tst_DelBgnIf("abc", "a", "bc"); + tst_DelBgnIf("abc", "ab", "c"); + tst_DelBgnIf("abc", "abc", ""); + tst_DelBgnIf("abc", "abcd", "abc"); + tst_DelBgnIf("abc", "bcd", "abc"); + err_DelBgnIf(null, "abc"); + err_DelBgnIf("abc", null); + } + void tst_DelBgnIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelBgnIf(s, v));} + void err_DelBgnIf(String s, String v) {try {String_.DelBgnIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void DelEnd() { + tst_DelEnd("abc", 0, "abc"); + tst_DelEnd("abc", 1, "ab"); + tst_DelEnd("abc", 2, "a"); + tst_DelEnd("abc", 3, ""); + err_DelEnd(null, 0); + err_DelEnd("abc", 4); + } + void tst_DelEnd(String s, int v, String expd) {Tfds.Eq(expd, String_.DelEnd(s, v));} + void err_DelEnd(String s, int v) {try {String_.DelEnd(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void DelEndIf() { + tst_DelEndIf("abc", "", "abc"); + tst_DelEndIf("abc", "c", "ab"); + tst_DelEndIf("abc", "bc", "a"); + tst_DelEndIf("abc", "abc", ""); + tst_DelEndIf("abc", "abcd", "abc"); + tst_DelEndIf("abc", "ab", "abc"); + err_DelEndIf(null, ""); + err_DelEndIf("", null); + } + void tst_DelEndIf(String s, String v, String expd) {Tfds.Eq(expd, String_.DelEndIf(s, v));} + void err_DelEndIf(String s, String v) {try {String_.DelEndIf(s, v);} catch (Exception exc) {Tfds.Err_classMatch(exc, Err.class); return;} Tfds.Fail_expdError();} + @Test public void MidByPos() { + tst_MidByPos("abc", 0, 0, ""); + tst_MidByPos("abc", 0, 1, "a"); + tst_MidByPos("abc", 0, 2, "ab"); + tst_MidByPos("abc", 0, 3, "abc"); + tst_MidByPos("abc", 2, 3, "c"); + err_MidByPos("abc", 1, 5); +// err_MidByPos("abc", 0, 4); + } + void tst_MidByPos(String s, int bgn, int end, String expd) {Tfds.Eq(expd, String_.Mid(s, bgn, end));} + void err_MidByPos(String s, int bgn, int end) {try {String_.Mid(s, bgn, end);} catch (Exception e) {Tfds.Err_classMatch(e, Err.class); return;} Tfds.Fail_expdError();} + @Test public void TrimEnd() { + tst_TrimEnd("a", "a"); + tst_TrimEnd("a ", "a"); + tst_TrimEnd("a\t", "a"); + tst_TrimEnd("a\n", "a"); + tst_TrimEnd("a\r", "a"); + tst_TrimEnd("a\r\n \t", "a"); + tst_TrimEnd(" a", " a"); + tst_TrimEnd(null, null); + } + void tst_TrimEnd(String s, String expd) {Tfds.Eq(expd, String_.TrimEnd(s));} + + @Test public void Count() { + String text = "0 0 0"; + Tfds.Eq(3, String_.Count(text, "0")); + } + @Test public void Has() { + String text = "find word"; + Tfds.Eq_true(String_.Has(text, "word")); + Tfds.Eq_false(String_.Has(text, "nothing")); + } + @Test public void Repeat() { + Tfds.Eq("333", String_.Repeat("3", 3)); + } + @Test public void Format() { + tst_Format("", ""); // empty + tst_Format("no args", "no args"); // no args + tst_Format("0", "{0}", 0); // one + tst_Format("0 and 1", "{0} and {1}", 0, 1); // many + tst_Format("{", "{{", 0); // escape bracketBgn + tst_Format("}", "}}", 0); // escape bracketEnd + tst_Format("{a0c}", "{a{0}c}", 0); // nested; + tst_Format("{a{b}c}", "{a{b}c}", 0); // invalid invalid + tst_Format("{1}", "{1}", 1); // invalid array index + tst_Format("{a} {b}", "{a} {b}", 0); // invalid many + tst_Format("{a}0{b}1", "{a}{0}{b}{1}", 0, 1); // invalid and valid + tst_Format("{0", "{0", 0); // invalid dangling + } void tst_Format(String expd, String fmt, Object... ary) {Tfds.Eq(expd, String_.Format(fmt, ary));} + @Test public void Split() { + tst_Split("ab", " ", "ab"); // no match -> return array with original input + tst_Split("ab cd", " ", "ab", "cd"); // separator.length = 1 + tst_Split("ab+!cd", "+!", "ab", "cd"); // separator.length = 2 + tst_Split("ab+!cd+!ef", "+!", "ab", "cd", "ef"); // terms = 3 + tst_Split("ab+!cd+!", "+!", "ab", "cd", ""); // closing separator + tst_Split("+!ab", "+!", "", "ab"); // opening separator + tst_Split("ab+cd+!ef", "+!", "ab+cd", "ef"); // ignore partial matches + tst_Split("ab+!cd+", "+!", "ab", "cd+"); // ignore partial matches; end of String + + // boundary + tst_Split("ab", "", "ab"); // separator.length = 0 -> return array with input as only member + tst_Split("", " ", ""); // empty input -> return array with empty input + + // acceptance + tst_Split("this\r\nis\na\rtest\r\n.", "\r\n", "this", "is\na\rtest", "."); + } void tst_Split(String text, String separator, String... expd) {Tfds.Eq_ary(expd, String_.Split(text, separator));} + @Test public void Concat_with_obj() { + tst_ConcatWith_any("a|b", "|", "a", "b"); // do not append final delimiter + tst_ConcatWith_any("a||c", "|", "a", null, "c"); // null + tst_ConcatWith_any("a|b", "|", Object_.Ary("a", "b")); // pass array as arg + } void tst_ConcatWith_any(String expd, String delimiter, Object... array) {Tfds.Eq(expd, String_.Concat_with_obj(delimiter, array));} + @Test public void Compare_byteAry() { + tst_Compare_byteAry("a", "a", CompareAble_.Same); + tst_Compare_byteAry("a", "b", CompareAble_.Less); + tst_Compare_byteAry("b", "a", CompareAble_.More); + tst_Compare_byteAry("ab", "ac", CompareAble_.Less); + tst_Compare_byteAry("ac", "ab", CompareAble_.More); + tst_Compare_byteAry("a", "ab", CompareAble_.Less); + tst_Compare_byteAry("ab", "a", CompareAble_.More); + tst_Compare_byteAry("101", "1-0-1", CompareAble_.More); // NOTE: regular String_.Compare_as_ordinals returns Less in .NET, More in Java + tst_Compare_byteAry("1-0-1", "101 (album)", CompareAble_.Less); + } void tst_Compare_byteAry(String lhs, String rhs, int expd) {Tfds.Eq(expd, String_.Compare_byteAry(lhs, rhs));} + @Test public void FindBwd() { // WORKAROUND.CS:String.LastIndexOf returns -1 for multi-chars; + tst_FindRev("abc", "a", 0, 0); + tst_FindRev("abc", "ab", 0, 0); // 2 chars + tst_FindRev("abc", "abc", 0, 0); // 3 chars + tst_FindRev("ab", "abc", 0, -1); // out of index error + tst_FindRev("ababab", "ab", 2, 2); // make sure cs implementation doesn't pick up next + } void tst_FindRev(String s, String find, int pos, int expd) {Tfds.Eq(expd, String_.FindBwd(s, find, pos));} + @Test public void Extract_after_bwd() { + Extract_after_bwd_tst("a/b", "/", "b"); + Extract_after_bwd_tst("a/", "/", ""); + Extract_after_bwd_tst("a", "/", ""); + } void Extract_after_bwd_tst(String src, String dlm, String expd) {Tfds.Eq(expd, String_.Extract_after_bwd(src, dlm));} +} diff --git a/100_core/src/gplx/TfdsTstr_fxt.java b/100_core/src/gplx/TfdsTstr_fxt.java new file mode 100644 index 000000000..de991df69 --- /dev/null +++ b/100_core/src/gplx/TfdsTstr_fxt.java @@ -0,0 +1,97 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import gplx.core.strings.*; +import gplx.core.lists.*; +public class TfdsTstr_fxt { + public TfdsTstr_fxt Eq_str(Object expd, Object actl, String name) { + int nameLen = String_.Len(name); if (nameLen > nameLenMax) nameLenMax = nameLen; + TfdsTstrItm itm = TfdsTstrItm.new_().Expd_(expd).Actl_(actl).Name_(name); + list.Add(itm); + return this; + } + public void SubName_push(String s) { + stack.Push(s); + TfdsTstrItm itm = TfdsTstrItm.new_(); + itm.SubName_make(stack); + itm.TypeOf = 1; + list.Add(itm); + } StackAdp stack = StackAdp_.new_(); + public void Fail() { + manualFail = true; + }boolean manualFail = false; + public int List_Max(List_adp expd, List_adp actl) {return Math_.Max(expd.Count(), actl.Count());} + public int List_Max(String[] expd, String[] actl) {return Math_.Max(expd.length, actl.length);} + public Object List_FetchAtOrNull(List_adp l, int i) {return (i >= l.Count()) ? null : l.Get_at(i);} + + public void SubName_pop() {stack.Pop();} + int nameLenMax = 0; + public void tst_Equal(String hdr) { + boolean pass = true; + for (int i = 0; i < list.Count(); i++) { + TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i); + if (!itm.Compare()) pass = false; // don't break early; Compare all vals + } + if (pass && !manualFail) return; + String_bldr sb = String_bldr_.new_(); + sb.Add_char_crlf(); + sb.Add_str_w_crlf(hdr); + for (int i = 0; i < list.Count(); i++) { + TfdsTstrItm itm = (TfdsTstrItm)list.Get_at(i); + if (itm.TypeOf == 1) { + sb.Add_fmt_line(" /{0}", itm.SubName()); + continue; + } + boolean hasError = itm.CompareResult() != TfdsTstrItm.CompareResult_eq; + String errorKey = hasError ? "*" : " "; + sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd(itm.Name(), nameLenMax, " "), itm.Expd()); + if (hasError) + sb.Add_fmt_line("{0}{1} {2}", errorKey, String_.PadEnd("", nameLenMax, " "), itm.Actl()); + } + sb.Add(String_.Repeat("_", 80)); + throw Err_.new_wo_type(sb.To_str()); + } + List_adp list = List_adp_.New(); + public static TfdsTstr_fxt new_() {return new TfdsTstr_fxt();} TfdsTstr_fxt() {} +} +class TfdsTstrItm { + public String Name() {return name;} public TfdsTstrItm Name_(String val) {name = val; return this;} private String name; + public Object Expd() {return expd;} public TfdsTstrItm Expd_(Object val) {expd = val; return this;} Object expd; + public Object Actl() {return actl;} public TfdsTstrItm Actl_(Object val) {actl = val; return this;} Object actl; + public String SubName() {return subName;} private String subName = ""; + public int TypeOf; + public void SubName_make(StackAdp stack) { + if (stack.Count() == 0) return; + List_adp list = stack.XtoList(); + String_bldr sb = String_bldr_.new_(); + for (int i = 0; i < list.Count(); i++) { + if (i != 0) sb.Add("."); + sb.Add((String)list.Get_at(i)); + } + subName = sb.To_str(); + } + public int CompareResult() {return compareResult;} public TfdsTstrItm CompareResult_(int val) {compareResult = val; return this;} int compareResult; + public boolean Compare() { + boolean eq = Object_.Eq(expd, actl); + compareResult = eq ? 1 : 0; + return eq; + } + public String CompareSym() { + return compareResult == 1 ? "==" : "!="; + } + public static TfdsTstrItm new_() {return new TfdsTstrItm();} TfdsTstrItm() {} + public static final int CompareResult_none = 0, CompareResult_eq = 1, CompareResult_eqn = 2; +} diff --git a/100_core/src/gplx/core/brys/Bry_bfr_mkr_tst.java b/100_core/src/gplx/core/brys/Bry_bfr_mkr_tst.java new file mode 100644 index 000000000..fd801cba5 --- /dev/null +++ b/100_core/src/gplx/core/brys/Bry_bfr_mkr_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bry_bfr_mkr_tst { + private final Bry_bfr_mkr_fxt fxt = new Bry_bfr_mkr_fxt(); + @Before public void setup() {fxt.Clear();} + @Test public void Get_1() {fxt.Clear().Get().Test__used(0);} + @Test public void Get_2() {fxt.Clear().Get().Get().Test__used(0, 1);} + @Test public void Get_3() {fxt.Clear().Get().Get().Get().Test__used(0, 1, 2);} + @Test public void Rls() {fxt.Clear().Get().Rls(0).Test__used();} + @Test public void Rls_skip_1() { + fxt.Clear().Get().Get().Rls(0).Test__used(-1, 1); + fxt.Get().Test__used(0, 1); + } + @Test public void Rls_skip_2_1() { + fxt.Clear().Get().Get().Get().Rls(1).Rls(0).Test__used(-1, -1, 2); + fxt.Get().Test__used(0, -1, 2); + fxt.Get().Test__used(0, 1, 2); + fxt.Get().Test__used(0, 1, 2, 3); + } + @Test public void Get_rls_get() { // PURPOSE: defect in which last rls failed b/c was not doing ++ if rv existed + fxt.Clear().Get().Rls(0).Get().Get().Rls(1).Rls(0).Test__used(); + } +} +class Bry_bfr_mkr_fxt { + private final Bry_bfr_mkr_mgr mkr = new Bry_bfr_mkr_mgr(Byte_.Zero, 32); + public Bry_bfr_mkr_fxt Clear() {mkr.Clear(); return this;} + public Bry_bfr_mkr_fxt Get() {mkr.Get(); return this;} + public Bry_bfr_mkr_fxt Rls(int i) {mkr.Used()[i].Mkr_rls(); return this;} + public Bry_bfr_mkr_fxt Test__used(int... expd) { + int actl_len = mkr.Used_len(); + int[] actl = new int[actl_len]; + for (int i = 0; i < actl_len; i++) { + Bry_bfr bfr = mkr.Used()[i]; + int actl_val = bfr == null ? -2 : bfr.Mkr_idx(); + actl[i] = actl_val; + } + Tfds.Eq_ary(expd, actl); + return this; + } +} diff --git a/100_core/src/gplx/core/brys/Bry_rdr_tst.java b/100_core/src/gplx/core/brys/Bry_rdr_tst.java new file mode 100644 index 000000000..fc38b774e --- /dev/null +++ b/100_core/src/gplx/core/brys/Bry_rdr_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bry_rdr_tst { + @Before public void init() {fxt.Clear();} private Bry_rdr_fxt fxt = new Bry_rdr_fxt(); + @Test public void Int() { + fxt.Init_src("12|3456|789"); + fxt.Test_read_int(12); + fxt.Test_read_int(3456); + fxt.Test_read_int(789); + fxt.Test_read_int(Int_.Min_value); + } + @Test public void Int_negative() { + fxt.Init_src("-1|-2"); + fxt.Test_read_int(-1); + fxt.Test_read_int(-2); + } + @Test public void Bry() { + fxt.Init_src("abc|d||ef"); + fxt.Test_read_bry("abc"); + fxt.Test_read_bry("d"); + fxt.Test_read_bry(""); + fxt.Test_read_bry("ef"); + fxt.Test_read_bry(null); + } +} +class Bry_rdr_fxt { + private Bry_rdr_old rdr; + public void Clear() {rdr = new Bry_rdr_old();} + public Bry_rdr_fxt Init_src(String v) {rdr.Init(Bry_.new_u8(v)); return this;} + public Bry_rdr_fxt Init_pos(int v) {rdr.Pos_(v); return this;} + public void Test_read_int(int expd_val) { + Tfds.Eq(expd_val, rdr.Read_int_to_pipe()); + } + public void Test_read_bry(String expd_str) { + byte[] actl_bry = rdr.Read_bry_to_pipe(); + String actl_str = actl_bry == null ? null : String_.new_u8(actl_bry); + Tfds.Eq(expd_str, actl_str); + } +} diff --git a/100_core/src/gplx/core/brys/args/Bfr_arg__time_tst.java b/100_core/src/gplx/core/brys/args/Bfr_arg__time_tst.java new file mode 100644 index 000000000..8c1faccb9 --- /dev/null +++ b/100_core/src/gplx/core/brys/args/Bfr_arg__time_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*; +import org.junit.*; +public class Bfr_arg__time_tst { + @Test public void Basic() { + Time_fmtr_arg_fxt fxt = new Time_fmtr_arg_fxt().Clear(); + fxt.XferAry( 1, "01s"); // seconds + fxt.XferAry( 62, "01m 02s"); // minutes + fxt.XferAry( 3723, "01h 02m 03s"); // hours + fxt.XferAry( 93784, "01d 02h 03m 04s"); // days + fxt.XferAry( 0, "00s"); // handle 0 seconds + fxt.XferAry( 3601, "01h 00m 01s"); // handle 0 in middle unit + } +} +class Time_fmtr_arg_fxt { + public Time_fmtr_arg_fxt Clear() { + if (arg == null) arg = new Bfr_arg__time(); + return this; + } Bfr_arg__time arg; + public void XferAry(int seconds, String expd) { + Bry_bfr bfr = Bry_bfr_.Reset(255); + arg.Seconds_(seconds); + arg.Bfr_arg__add(bfr); + Tfds.Eq(expd, bfr.To_str()); + } +} diff --git a/100_core/src/gplx/core/brys/fmtrs/Bry_fmtr_tst.java b/100_core/src/gplx/core/brys/fmtrs/Bry_fmtr_tst.java new file mode 100644 index 000000000..c03461a6c --- /dev/null +++ b/100_core/src/gplx/core/brys/fmtrs/Bry_fmtr_tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*; +import org.junit.*; +public class Bry_fmtr_tst { + private final Bry_fmtr_fxt fxt = new Bry_fmtr_fxt(); + @Test public void Text() {fxt.Clear().Fmt("a").Test("a");} + @Test public void Idx__1() {fxt.Clear().Fmt("~{0}").Args("a").Test("a");} + @Test public void Idx__3() {fxt.Clear().Fmt("~{0}~{1}~{2}").Args("a", "b", "c").Test("abc");} + @Test public void Idx__mix() {fxt.Clear().Fmt("a~{0}c~{1}e").Args("b", "d").Test("abcde");} + @Test public void Idx__missing() {fxt.Clear().Fmt("~{0}").Test("~{0}");} + + @Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Keys("key").Args("a").Test("a");} + @Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Keys("key1", "key2").Args("a", "b").Test("ab");} + @Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Keys("key1").Args("a").Test("aa");} + + @Test public void Mix() {fxt.Clear().Fmt("~{key1}~{1}").Keys("key1", "key2").Args("a", "b").Test("ab");} + + @Test public void Simple() { + fxt.Clear().Fmt("0~{key1}1~{key2}2").Keys("key1", "key2").Args(".", ",").Test("0.1,2"); + } + @Test public void Cmd() { + Bry_fmtr_tst_mok mok = new Bry_fmtr_tst_mok(); + Bry_fmtr fmtr = Bry_fmtr.new_("0~{key1}2~{<>3<>}4", "key1").Eval_mgr_(mok); + Tfds.Eq("012~{<>3<>}4", fmtr.Bld_str_many("1")); + mok.Enabled_(true); + Tfds.Eq("01234", fmtr.Bld_str_many("1")); + } + @Test public void Bld_bfr_many_and_set_fmt() { + fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc"); + } + @Test public void Escape_tilde() { + Tfds.Eq("~~~~~~", Bry_fmtr.Escape_tilde("~~~")); + } +} +class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr { + public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled; + public byte[] Eval(byte[] cmd) { + return enabled ? cmd : null; + } +} +class Bry_fmtr_fxt { + private final Bry_fmtr fmtr = Bry_fmtr.new_(); + private final Bry_bfr bfr = Bry_bfr_.New(); + private Object[] args; + public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;} + public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;} + public Bry_fmtr_fxt Keys(String... args) {fmtr.Keys_(args); return this;} + public Bry_fmtr_fxt Args(Object... args) {this.args = args; return this;} + public void Test(String expd) { + fmtr.Bld_bfr_many(bfr, args); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } + public void Bld_bfr_many_and_set_fmt(String fmt, Object[] args, String expd) { + fmtr.Fmt_(fmt); + fmtr.Bld_bfr_many_and_set_fmt(args); + Tfds.Eq(expd, String_.new_a7(fmtr.Fmt())); + } +} diff --git a/100_core/src/gplx/core/brys/fmts/Bry_fmt_tst.java b/100_core/src/gplx/core/brys/fmts/Bry_fmt_tst.java new file mode 100644 index 000000000..119b8b5f6 --- /dev/null +++ b/100_core/src/gplx/core/brys/fmts/Bry_fmt_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*; +import org.junit.*; +public class Bry_fmt_tst { + private final Bry_fmt_fxt fxt = new Bry_fmt_fxt(); + @Test public void Text() {fxt.Clear().Fmt("a").Test("a");} + @Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Vals("a").Test("a");} + @Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Vals("a", "b").Test("ab");} + @Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Vals("a").Test("aa");} + @Test public void Key__missing() {fxt.Clear().Fmt("~{key}").Test("~{key}");} + @Test public void Tilde() {fxt.Clear().Fmt("~~~~").Test("~~");} + @Test public void Simple() {fxt.Clear().Fmt("0~{key1}1~{key2}2").Vals(".", ",").Test("0.1,2");} + @Test public void Arg() {fxt.Clear().Fmt("~{custom}").Args("custom", new Bfr_fmt_arg_mok(123)).Test("123");} + @Test public void Keys() {fxt.Clear().Fmt("~{b}~{c}~{a}").Keys("a", "b", "c").Vals("a", "b", "c").Test("bca");} +} +class Bfr_fmt_arg_mok implements Bfr_arg { + private int num; + public Bfr_fmt_arg_mok(int num) {this.num = num;} + public void Bfr_arg__add(Bry_bfr bfr) { + bfr.Add_int_variable(num); + } +} +class Bry_fmt_fxt { + private final Bry_fmt fmt = new Bry_fmt(Bry_.Empty, Bry_.Ary_empty, Bfr_fmt_arg.Ary_empty); + private final Bry_bfr bfr = Bry_bfr_.New(); + private Object[] vals; + public Bry_fmt_fxt Clear() {vals = Object_.Ary_empty; return this;} + public Bry_fmt_fxt Fmt(String s) {fmt.Fmt_(s); return this;} + public Bry_fmt_fxt Vals(Object... vals) {this.vals = vals; return this;} + public Bry_fmt_fxt Args(String key, Bfr_arg arg) {fmt.Args_(new Bfr_fmt_arg(Bry_.new_u8(key), arg)); return this;} + public Bry_fmt_fxt Keys(String... keys) {fmt.Keys_(Bry_.Ary(keys)); return this;} + public void Test(String expd) { + fmt.Bld_many(bfr, vals); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/100_core/src/gplx/core/brys/fmts/Bry_keys_parser_tst.java b/100_core/src/gplx/core/brys/fmts/Bry_keys_parser_tst.java new file mode 100644 index 000000000..862f31f8f --- /dev/null +++ b/100_core/src/gplx/core/brys/fmts/Bry_keys_parser_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*; +import org.junit.*; +public class Bry_keys_parser_tst { + private final Bry_keys_parser_fxt fxt = new Bry_keys_parser_fxt(); + @Test public void None() {fxt.Test("a");} + @Test public void One() {fxt.Test("~{a}" , "a");} + @Test public void Many() {fxt.Test("~{a}b~{c}d~{e}" , "a", "c", "e");} + @Test public void Dupe() {fxt.Test("~{a}b~{a}" , "a");} + @Test public void Bug__space() {fxt.Test("~{a}~{b} ~{c}" , "a", "b", "c");} // DATE:2016-08-02 +} +class Bry_keys_parser_fxt { + public void Test(String fmt, String... expd) { + Tfds.Eq_ary(expd, String_.Ary(Bry_fmt_parser_.Parse_keys(Bry_.new_u8(fmt)))); + } +} diff --git a/100_core/src/gplx/core/btries/Btrie_bwd_mgr_tst.java b/100_core/src/gplx/core/btries/Btrie_bwd_mgr_tst.java new file mode 100644 index 000000000..11d4e4e03 --- /dev/null +++ b/100_core/src/gplx/core/btries/Btrie_bwd_mgr_tst.java @@ -0,0 +1,85 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.btries; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Btrie_bwd_mgr_tst { + @Before public void init() {} private Btrie_bwd_mgr trie; + private void ini_setup1() { + trie = new Btrie_bwd_mgr(false); + run_Add("c" , 1); + run_Add("abc" , 123); + } + @Test public void Get_by() { + ini_setup1(); + tst_MatchAtCur("c" , 1); + tst_MatchAtCur("abc" , 123); + tst_MatchAtCur("bc" , 1); + tst_MatchAtCur("yzabc" , 123); + tst_MatchAtCur("ab" , null); + } + @Test public void Fetch_intl() { + trie = new Btrie_bwd_mgr(false); + run_Add("a�", 1); + tst_MatchAtCur("a�" , 1); + tst_MatchAtCur("�" , null); + } + @Test public void Eos() { + ini_setup1(); + tst_Match("ab", Byte_ascii.Ltr_c, 2, 123); + } + @Test public void Match_exact() { + ini_setup1(); + tst_MatchAtCurExact("c", 1); + tst_MatchAtCurExact("bc", null); + tst_MatchAtCurExact("abc", 123); + } + private void ini_setup2() { + trie = new Btrie_bwd_mgr(false); + run_Add("a" , 1); + run_Add("b" , 2); + } + @Test public void Match_2() { + ini_setup2(); + tst_MatchAtCur("a", 1); + tst_MatchAtCur("b", 2); + } + private void ini_setup_caseAny() { + trie = Btrie_bwd_mgr.ci_(); + run_Add("a" , 1); + run_Add("b" , 2); + } + @Test public void CaseAny() { + ini_setup_caseAny(); + tst_MatchAtCur("a", 1); + tst_MatchAtCur("A", 1); + } + private void run_Add(String k, int val) {trie.Add(Bry_.new_u8(k), val);} + private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) { + byte[] src = Bry_.new_u8(srcStr); + Object actl = trie.Match(b, src, bgn_pos, -1); + Tfds.Eq(expd, actl); + } + private void tst_MatchAtCur(String srcStr, Object expd) { + byte[] src = Bry_.new_u8(srcStr); + Object actl = trie.Match(src[src.length - 1], src, src.length - 1, -1); + Tfds.Eq(expd, actl); + } + private void tst_MatchAtCurExact(String srcStr, Object expd) { + byte[] src = Bry_.new_u8(srcStr); + Object actl = trie.Match_exact(src, src.length - 1, -1); + Tfds.Eq(expd, actl); + } +} diff --git a/100_core/src/gplx/core/btries/Btrie_fast_mgr_tst.java b/100_core/src/gplx/core/btries/Btrie_fast_mgr_tst.java new file mode 100644 index 000000000..eeaebc16a --- /dev/null +++ b/100_core/src/gplx/core/btries/Btrie_fast_mgr_tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.btries; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Btrie_fast_mgr_tst { + private Btrie_fast_mgr_fxt fxt = new Btrie_fast_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Get_by() { + fxt.Test_matchAtCur("a" , 1); + fxt.Test_matchAtCur("abc" , 123); + fxt.Test_matchAtCur("ab" , 1); + fxt.Test_matchAtCur("abcde" , 123); + fxt.Test_matchAtCur(" a" , null); + } + @Test public void Bos() { + fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123); + } + @Test public void Match_exact() { + fxt.Test_matchAtCurExact("a", 1); + fxt.Test_matchAtCurExact("ab", null); + fxt.Test_matchAtCurExact("abc", 123); + } + @Test public void Del_noop__no_match() { + fxt.Exec_del("d"); + fxt.Test_matchAtCurExact("a" , 1); + fxt.Test_matchAtCurExact("abc" , 123); + } + @Test public void Del_noop__partial_match() { + fxt.Exec_del("ab"); + fxt.Test_matchAtCurExact("a" , 1); + fxt.Test_matchAtCurExact("abc" , 123); + } + @Test public void Del_match__long() { + fxt.Exec_del("abc"); + fxt.Test_matchAtCurExact("a" , 1); + fxt.Test_matchAtCurExact("abc" , null); + } + @Test public void Del_match__short() { + fxt.Exec_del("a"); + fxt.Test_matchAtCurExact("a" , null); + fxt.Test_matchAtCurExact("abc" , 123); + } +} +class Btrie_fast_mgr_fxt { + private Btrie_fast_mgr trie; + public void Clear() { + trie = Btrie_fast_mgr.cs(); + Init_add( 1 , Byte_ascii.Ltr_a); + Init_add(123 , Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c); + } + public void Init_add(int val, byte... ary) {trie.Add(ary, val);} + public void Test_match(String src_str, byte b, int bgn_pos, int expd) { + byte[] src = Bry_.new_a7(src_str); + Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length); + Tfds.Eq(expd, actl); + } + public void Test_matchAtCur(String src_str, Object expd) { + byte[] src = Bry_.new_a7(src_str); + Object actl = trie.Match_bgn(src, 0, src.length); + Tfds.Eq(expd, actl); + } + public void Test_matchAtCurExact(String src_str, Object expd) { + byte[] src = Bry_.new_a7(src_str); + Object actl = trie.Match_exact(src, 0, src.length); + Tfds.Eq(expd, actl); + } + public void Exec_del(String src_str) { + trie.Del(Bry_.new_u8(src_str)); + } +} diff --git a/100_core/src/gplx/core/btries/Btrie_slim_itm_tst.java b/100_core/src/gplx/core/btries/Btrie_slim_itm_tst.java new file mode 100644 index 000000000..3c0b99d33 --- /dev/null +++ b/100_core/src/gplx/core/btries/Btrie_slim_itm_tst.java @@ -0,0 +1,47 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.btries; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Btrie_slim_itm_tst { + private Btrie_slim_itm itm = new Btrie_slim_itm(Byte_.Zero, null, false); + @Before public void init() {itm.Clear();} + @Test public void Find_nil() { + tst_Find(Byte_ascii.Ltr_a, null); + } + @Test public void Add_one() { + run_Add(Byte_ascii.Ltr_a); + tst_Find(Byte_ascii.Ltr_a, "a"); + } + @Test public void Add_many() { + run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B); + tst_Find(Byte_ascii.Ltr_a, "a"); + } + @Test public void Del() { + run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B); + tst_Find(Byte_ascii.Ltr_a, "a"); + run_Del(Byte_ascii.Ltr_a); + tst_Find(Byte_ascii.Ltr_a, null); + tst_Find(Byte_ascii.Num_0, "0"); + tst_Find(Byte_ascii.Ltr_B, "B"); + } + private void tst_Find(byte b, String expd) { + Btrie_slim_itm actl_itm = itm.Ary_find(b); + Object actl = actl_itm == null ? null : actl_itm.Val(); + Tfds.Eq(expd, actl); + } + private void run_Add(byte... ary) {for (byte b : ary) itm.Ary_add(b, Char_.To_str((char)b));} + private void run_Del(byte... ary) {for (byte b : ary) itm.Ary_del(b);} +} diff --git a/100_core/src/gplx/core/btries/Btrie_slim_mgr_tst.java b/100_core/src/gplx/core/btries/Btrie_slim_mgr_tst.java new file mode 100644 index 000000000..1e4e2dfa8 --- /dev/null +++ b/100_core/src/gplx/core/btries/Btrie_slim_mgr_tst.java @@ -0,0 +1,109 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.btries; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +public class Btrie_slim_mgr_tst { + @Before public void init() { + } private Btrie_slim_mgr trie; + private void ini_setup1() { + trie = Btrie_slim_mgr.cs(); + run_Add("a" , 1); + run_Add("abc" , 123); + } + @Test public void Get_by() { + ini_setup1(); + tst_MatchAtCur("a" , 1); + tst_MatchAtCur("abc" , 123); + tst_MatchAtCur("ab" , 1); + tst_MatchAtCur("abcde" , 123); + tst_MatchAtCur(" a" , null); + } + @Test public void Bos() { + ini_setup1(); + tst_Match("bc", Byte_ascii.Ltr_a, -1, 123); + } + @Test public void Match_exact() { + ini_setup1(); + tst_MatchAtCurExact("a", 1); + tst_MatchAtCurExact("ab", null); + tst_MatchAtCurExact("abc", 123); + } + private void ini_setup2() { + trie = Btrie_slim_mgr.cs(); + run_Add("a" , 1); + run_Add("b" , 2); + } + @Test public void Match_2() { + ini_setup2(); + tst_MatchAtCur("a", 1); + tst_MatchAtCur("b", 2); + } + private void ini_setup_caseAny() { + trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:test + run_Add("a" , 1); + run_Add("b" , 2); + } + @Test public void CaseAny() { + ini_setup_caseAny(); + tst_MatchAtCur("a", 1); + tst_MatchAtCur("A", 1); + } + @Test public void Del() { + ini_setup1(); + trie.Del(Bry_.new_a7("a")); // delete "a"; "abc" still remains; + tst_MatchAtCur("a" , null); + tst_MatchAtCur("abc" , 123); + + trie.Del(Bry_.new_a7("abc")); + tst_MatchAtCur("abc" , null); + } + @Test public void Match_none() { + Btrie_slim_mgr_fxt fxt = new Btrie_slim_mgr_fxt(); + fxt.Init__add("k1", "v1"); + fxt.Exec__match("ak1", 1, 3, "v1", 3); // 3 to position after match + fxt.Exec__match("ak2", 1, 1, null, 1); // 1 to position at current pos; used to be 0; de.w:Butter; DATE:2018-04-12 + } + + private void run_Add(String k, int val) {trie.Add_obj(Bry_.new_a7(k), val);} + private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) { + byte[] src = Bry_.new_a7(srcStr); + Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length); + Tfds.Eq(expd, actl); + } + private void tst_MatchAtCur(String srcStr, Object expd) { + byte[] src = Bry_.new_a7(srcStr); + Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length); + Tfds.Eq(expd, actl); + } + private void tst_MatchAtCurExact(String srcStr, Object expd) { + byte[] src = Bry_.new_a7(srcStr); + Object actl = trie.Match_exact(src, 0, src.length); + Tfds.Eq(expd, actl); + } +} +class Btrie_slim_mgr_fxt { + private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs(); + public Btrie_slim_mgr_fxt Init__add(String key, String val) { + trie.Add_str_str(key, val); + return this; + } + public void Exec__match(String src, int bgn_pos, int end_pos, Object expd_val, int expd_pos) { + Btrie_rv trv = new Btrie_rv(); + Object actl_val = trie.Match_at(trv, Bry_.new_u8(src), bgn_pos, end_pos); + Gftest.Eq__obj_or_null(expd_val, actl_val); + Gftest.Eq__int(expd_pos, trv.Pos()); + } +} diff --git a/100_core/src/gplx/core/criterias/Criteria_ioItm_tst.java b/100_core/src/gplx/core/criterias/Criteria_ioItm_tst.java new file mode 100644 index 000000000..c1bd2ec6b --- /dev/null +++ b/100_core/src/gplx/core/criterias/Criteria_ioItm_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.criterias; import gplx.*; import gplx.core.*; +import org.junit.*; +import gplx.core.ios.*; +public class Criteria_ioItm_tst { + IoItmFil fil; Criteria crt; IoItm_fxt fx = IoItm_fxt.new_(); + @Test public void IoType() { + crt = crt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil)); + tst_Match(true, crt, fx.fil_wnt_("C:\\fil.txt")); + tst_Match(false, crt, fx.dir_wnt_("C:\\dir")); + } + @Test public void Ext() { + crt = crt_(IoItm_base_.Prop_Ext, Criteria_.eq_(".txt")); + tst_Match(true, crt, fx.fil_wnt_("C:\\fil.txt")); + tst_Match(false, crt, fx.fil_wnt_("C:\\fil.xml"), fx.fil_wnt_("C:\\fil.txt1"), fx.fil_wnt_("C:\\fil1.txt.xml"), fx.dir_wnt_("C:\\.txt")); + } + @Test public void Modified() { + fil = fx.fil_wnt_("C:\\fil.txt"); + crt = crt_(IoItmFil_.Prop_Modified, Criteria_.mte_(DateAdp_.parse_gplx("2001-01-01"))); + tst_Match(true, crt, fil.ModifiedTime_(DateAdp_.parse_gplx("2001-01-02")), fil.ModifiedTime_(DateAdp_.parse_gplx("2001-01-01"))); + tst_Match(false, crt, fil.ModifiedTime_(DateAdp_.parse_gplx("2000-12-31"))); + } + @Test public void IoMatch() { + Criteria crt = Criteria_ioMatch.parse(true, "*.txt", false); + CriteriaFxt fx_crt = new CriteriaFxt(); + fx_crt.tst_Matches(crt, Io_url_.new_any_("file.txt")); + fx_crt.tst_MatchesNot(crt, Io_url_.new_any_("file.xml")); + } + Criteria crt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);} + void tst_Match(boolean expt, Criteria fieldCrt, IoItm_base... ary) { + for (IoItm_base itm : ary) + Tfds.Eq(expt, fieldCrt.Matches(itm)); + } +} diff --git a/100_core/src/gplx/core/criterias/Criteria_tst.java b/100_core/src/gplx/core/criterias/Criteria_tst.java new file mode 100644 index 000000000..5d6a4c7c0 --- /dev/null +++ b/100_core/src/gplx/core/criterias/Criteria_tst.java @@ -0,0 +1,90 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.criterias; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Criteria_tst { + @Test public void Equal() { + Criteria crt = Criteria_.eq_(true); + fx.tst_Matches(crt, true); + fx.tst_MatchesNot(crt, false); + fx.tst_MatchesFail(crt, "true"); + + fx.tst_Matches(Criteria_.eq_(1), 1); + fx.tst_Matches(Criteria_.eq_("equal"), "equal"); + fx.tst_Matches(Criteria_.eq_(date), date); + } + @Test public void Not() { + Criteria crt = Criteria_.eqn_(true); + fx.tst_Matches(crt, false); + fx.tst_MatchesNot(crt, true); + fx.tst_MatchesFail(crt, "false"); + + fx.tst_Matches(Criteria_.eqn_(1), -1); + fx.tst_Matches(Criteria_.eqn_("equal"), "not equal"); + fx.tst_Matches(Criteria_.eqn_(date), date.Add_minute(1)); + } + @Test public void MoreThan() { + Criteria crt = Criteria_.mt_(0); + fx.tst_Matches(crt, 1, 2); + fx.tst_MatchesNot(crt, 0, -1); + fx.tst_MatchesFail(crt, "1"); + + fx.tst_Matches(Criteria_.mt_(0), 1); + fx.tst_Matches(Criteria_.mt_("a"), "b"); + fx.tst_Matches(Criteria_.mt_(date), date.Add_minute(1)); + fx.tst_Matches(Criteria_.mt_(false), true); // MISC: thus truth is greater than falsehood + } + @Test public void MoreThanEq() { + Criteria crt = Criteria_.mte_(0); + fx.tst_Matches(crt, 0); + } + @Test public void Less() { + Criteria crt = Criteria_.lt_(0); + fx.tst_Matches(crt, -1, -2); + fx.tst_MatchesNot(crt, 0, 1); + fx.tst_MatchesFail(crt, "-1"); + } + @Test public void LessEq() { + Criteria crt = Criteria_.lte_(0); + fx.tst_Matches(crt, 0); + } + @Test public void Between() { + Criteria crt = Criteria_.between_(-1, 1); + fx.tst_Matches(crt, 0, 1, -1); + fx.tst_MatchesNot(crt, -2, 2); + fx.tst_MatchesFail(crt, "0"); + + fx.tst_Matches(Criteria_.between_(1, -1), 0); // reverse range + fx.tst_Matches(Criteria_.between_("a", "c"), "b"); + } + @Test public void In() { + Criteria crt = Criteria_.in_(0, 1, 2); + fx.tst_Matches(crt, 0, 1, 2); + fx.tst_MatchesNot(crt, 3, -1); + fx.tst_MatchesFail(crt, "0"); + } + CriteriaFxt fx = new CriteriaFxt(); + DateAdp date = DateAdp_.parse_gplx("2001-01-01"); +} +class CriteriaFxt { + public void tst_Matches(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(true, crt.Matches(val));} + public void tst_MatchesNot(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(false, crt.Matches(val));} + public void tst_MatchesFail(Criteria crt, Object val) { + try {crt.Matches(val);} + catch(Exception exc) {Err_.Noop(exc); return;} + Tfds.Fail_expdError(); + } +} diff --git a/100_core/src/gplx/core/encoders/B85_fp__tst.java b/100_core/src/gplx/core/encoders/B85_fp__tst.java new file mode 100644 index 000000000..f837e9584 --- /dev/null +++ b/100_core/src/gplx/core/encoders/B85_fp__tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.encoders; import gplx.*; import gplx.core.*; +import org.junit.*; +public class B85_fp__tst { + private final B85_fp__fxt fxt = new B85_fp__fxt(); + @Test public void Double_to_str() { + fxt.Test__to_str(.1d, "/\""); + } +} +class B85_fp__fxt { + public void Test__to_str(double val, String expd) { + byte[] actl = B85_fp_.To_bry(val); + Tfds.Eq_str(expd, String_.new_a7(actl)); + } +} diff --git a/100_core/src/gplx/core/encoders/Base85__tst.java b/100_core/src/gplx/core/encoders/Base85__tst.java new file mode 100644 index 000000000..b5f2e238c --- /dev/null +++ b/100_core/src/gplx/core/encoders/Base85__tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.encoders; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Base85__tst { + private final Base85__fxt fxt = new Base85__fxt(); + @Test public void Log() { + fxt.Test_log( 0, 1); + fxt.Test_log( 84, 1); + fxt.Test_log( 85, 2); + fxt.Test_log( 7224, 2); + fxt.Test_log( 7225, 3); + fxt.Test_log( 614124, 3); + fxt.Test_log( 614125, 4); + fxt.Test_log( 52200624, 4); + fxt.Test_log( 52200625, 5); + fxt.Test_log(Int_.Max_value, 5); + } + @Test public void To_str() { + fxt.Test_to_str( 0, "!"); + fxt.Test_to_str( 84, "u"); + fxt.Test_to_str( 85, "\"!"); + fxt.Test_to_str( 7224, "uu"); + fxt.Test_to_str( 7225, "\"!!"); + fxt.Test_to_str( 614124, "uuu"); + fxt.Test_to_str( 614125, "\"!!!"); + fxt.Test_to_str( 52200624, "uuuu"); + fxt.Test_to_str( 52200625, "\"!!!!"); + } + @Test public void XtoStrAry() { + byte[] ary = new byte[9]; + fxt.Exec_to_str(ary, 0, 2); // !!# + fxt.Exec_to_str(ary, 3, 173); // !#$ + fxt.Exec_to_str(ary, 6, 14709); // #$% + Tfds.Eq("!!#!#$#$%", String_.new_u8(ary)); + } +} +class Base85__fxt { + public void Test_log(int val, int expd) {Tfds.Eq(expd, Base85_.Bry_len(val));} + public void Test_to_str(int val, String expd) { + String actl = Base85_.To_str(val, 0); + Tfds.Eq(expd, actl); + Tfds.Eq(val, Base85_.To_int_by_str(expd)); + } + public void Exec_to_str(byte[] ary, int aryPos, int val) {Base85_.Set_bry(val, ary, aryPos, 3);} +} diff --git a/100_core/src/gplx/core/encoders/Hex_utl__tst.java b/100_core/src/gplx/core/encoders/Hex_utl__tst.java new file mode 100644 index 000000000..ca414e615 --- /dev/null +++ b/100_core/src/gplx/core/encoders/Hex_utl__tst.java @@ -0,0 +1,89 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.encoders; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +public class Hex_utl__tst { + private final Hex_utl__fxt fxt = new Hex_utl__fxt(); + @Test public void To_int() { + fxt.Test__to_int("0" , 0); + fxt.Test__to_int("F" , 15); + fxt.Test__to_int("0F" , 15); + fxt.Test__to_int("10" , 16); + fxt.Test__to_int("20" , 32); + fxt.Test__to_int("FF" , 255); + fxt.Test__to_int("100" , 256); + fxt.Test__to_int("0a" , 10); + fxt.Test__to_int("7FFFFFFF" , Int_.Max_value); + fxt.Test__to_int_bry("100" , 256); + } + @Test public void To_str() { + fxt.Test__to_str(0 , "0"); + fxt.Test__to_str(15 , "F"); + fxt.Test__to_str(16 , "10"); + fxt.Test__to_str(32 , "20"); + fxt.Test__to_str(255 , "FF"); + fxt.Test__to_str(Int_.Max_value, "7FFFFFFF"); + + fxt.Test__to_str(15, 2 , "0F"); + fxt.Test__to_str(15, 3 , "00F"); + } + @Test public void Write() { + fxt.Test__write("[00000000]", 1, 9, 15, "[0000000F]"); + fxt.Test__write("[00000000]", 1, 9, 255, "[000000FF]"); + } + @Test public void Write_bfr() { + fxt.Test__write_bfr(Bool_.Y, 0, "0"); + fxt.Test__write_bfr(Bool_.Y, 15, "f"); + fxt.Test__write_bfr(Bool_.Y, 16, "10"); + fxt.Test__write_bfr(Bool_.Y, 32, "20"); + fxt.Test__write_bfr(Bool_.Y, 255, "ff"); + fxt.Test__write_bfr(Bool_.Y, 256, "100"); + fxt.Test__write_bfr(Bool_.Y, Int_.Max_value, "7fffffff"); + } + @Test public void Encode() { + fxt.Test__parse_hex_to_bry("E2A7BC", 226, 167, 188); + } +} +class Hex_utl__fxt { + public void Test__write(String s, int bgn, int end, int val, String expd) { + byte[] bry = Bry_.new_a7(s); + Hex_utl_.Write(bry, bgn, end, val); + Tfds.Eq(expd, String_.new_a7(bry)); + } + public void Test__to_int(String raw, int expd) { + int actl = Hex_utl_.Parse(raw); + Tfds.Eq(expd, actl); + } + public void Test__to_int_bry(String raw, int expd) {Tfds.Eq(expd, Hex_utl_.Parse_or(Bry_.new_a7(raw), -1));} + public void Test__to_str(int val, String expd) {Test__to_str(val, 0, expd);} + public void Test__to_str(int val, int pad, String expd) { + String actl = Hex_utl_.To_str(val, pad); + Tfds.Eq(expd, actl); + } + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Test__write_bfr(boolean lcase, int val, String expd) { + Hex_utl_.Write_bfr(bfr, lcase, val); + Gftest.Eq__str(expd, bfr.To_str_and_clear()); + } + public void Test__encode_bry(String val, int... expd) { + byte[] actl = Hex_utl_.Encode_bry(Bry_.new_u8(val)); + Gftest.Eq__ary(Byte_.Ary_by_ints(expd), actl, "encode"); + } + public void Test__parse_hex_to_bry(String val, int... expd) { + byte[] actl = Hex_utl_.Parse_hex_to_bry(Bry_.new_u8(val)); + Gftest.Eq__ary(Byte_.Ary_by_ints(expd), actl, "encode"); + } +} diff --git a/100_core/src/gplx/core/envs/Process_adp_tst.java b/100_core/src/gplx/core/envs/Process_adp_tst.java new file mode 100644 index 000000000..d0aad74b6 --- /dev/null +++ b/100_core/src/gplx/core/envs/Process_adp_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.envs; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Process_adp_tst { + private Process_adp_fxt fxt = new Process_adp_fxt(); + @Test public void Escape_ampersands_if_process_is_cmd() { + fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c^&d=e\""); + fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd1", "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\""); + fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.N, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\""); + } +} +class Process_adp_fxt { + public void Test_Escape_ampersands_if_process_is_cmd(boolean os_is_wnt, String exe_url, String exe_args, String expd) { + Tfds.Eq(expd, Process_adp.Escape_ampersands_if_process_is_cmd(os_is_wnt, exe_url, exe_args)); + } +} diff --git a/100_core/src/gplx/core/gfo_regys/GfoRegy_RegDir_tst.java b/100_core/src/gplx/core/gfo_regys/GfoRegy_RegDir_tst.java new file mode 100644 index 000000000..81cfeff7f --- /dev/null +++ b/100_core/src/gplx/core/gfo_regys/GfoRegy_RegDir_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.gfo_regys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class GfoRegy_RegDir_tst { + @Before public void setup() { + regy = GfoRegy.new_(); + Io_mgr.Instance.InitEngine_mem(); + root = Io_url_.mem_dir_("mem/root"); + } GfoRegy regy; Io_url root; + @Test public void Basic() { + ini_fil("101_tsta.txt"); + ini_fil("102_tstb.txt"); + ini_fil("103_tstc.png"); + ini_fil("dir1", "104_tstd.txt"); + regy.RegDir(root, "*.txt", false, "_", "."); + tst_Count(2); + tst_Exists("tsta"); + tst_Exists("tstb"); + } + @Test public void Err_dupe() { + ini_fil("101_tsta.txt"); + ini_fil("102_tsta.txt"); + try {regy.RegDir(root, "*.txt", false, "_", ".");} + catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_Dupe); return;} + Tfds.Fail_expdError(); + } + @Test public void Err_chopBgn() { + ini_fil("123_"); + try {regy.RegDir(root, "*", false, "_", ".");} + catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_ChopBgn); return;} + Tfds.Fail_expdError(); + } + @Test public void Err_chopEnd() { + ini_fil(".txt"); + try {regy.RegDir(root, "*.txt", false, "_", ".");} + catch (Exception e) {Tfds.Err_has(e, GfoRegy.Err_ChopEnd); return;} + Tfds.Fail_expdError(); + } + void tst_Count(int expd) {Tfds.Eq(expd, regy.Count());} + void tst_Exists(String expd) { + GfoRegyItm itm = regy.FetchOrNull(expd); + Tfds.Eq_nullNot(itm); + } + void ini_fil(String... nest) {Io_mgr.Instance.SaveFilStr(root.GenSubFil_nest(nest), "");} +} diff --git a/100_core/src/gplx/core/gfo_regys/GfoRegy_basic_tst.java b/100_core/src/gplx/core/gfo_regys/GfoRegy_basic_tst.java new file mode 100644 index 000000000..5ffb383f3 --- /dev/null +++ b/100_core/src/gplx/core/gfo_regys/GfoRegy_basic_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.gfo_regys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class GfoRegy_basic_tst { + @Before public void setup() { + regy = GfoRegy.new_(); + } GfoRegy regy; + @Test public void RegObjByType() { + regy.Parsers().Add("Io_url", Io_url_.Parser); + Io_url expd = Io_url_.new_any_("C:\\fil.txt"); + regy.RegObjByType("test", expd.Xto_api(), "Io_url"); + Io_url actl = (Io_url)regy.FetchValOr("test", Io_url_.Empty); + Tfds.Eq(expd.Xto_api(), actl.Xto_api()); + } +} diff --git a/100_core/src/gplx/core/interfaces/SrlAble__tst.java b/100_core/src/gplx/core/interfaces/SrlAble__tst.java new file mode 100644 index 000000000..118756e9e --- /dev/null +++ b/100_core/src/gplx/core/interfaces/SrlAble__tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.interfaces; import gplx.*; import gplx.core.*; +import org.junit.*; +public class SrlAble__tst { + @Test public void Basic() { + tst_Srl_ + ( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1) + , "itm:key='a' val='1';" + ); + + } + @Test public void Depth1_1() { + tst_Srl_ + ( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_ + ( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11) + ) + , String_.Concat_lines_crlf_skipLast + ( "itm:key='a' val='1'{itm:key='aa' val='11';}" + ) + ); + } + @Test public void Depth1_2() { + tst_Srl_ + ( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_ + ( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11) + , GfoMsg_.new_cast_("itm").Add("key", "ab").Add("val", 12) + ) + , String_.Concat_lines_crlf_skipLast + ( "itm:key='a' val='1'{" + , " itm:key='aa' val='11';" + , " itm:key='ab' val='12';" + , "}" + ) + ); + } + @Test public void Depth1_1_2() { + tst_Srl_ + ( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_ + ( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11).Subs_( + GfoMsg_.new_cast_("itm").Add("key", "aab").Add("val", 112) + ) + ) + , String_.Concat_lines_crlf_skipLast + ( "itm:key='a' val='1'{itm:key='aa' val='11'{itm:key='aab' val='112';}}" + ) + ); + } + void tst_Srl_(GfoMsg m, String expd) {Tfds.Eq(expd, SrlAble_.To_str(m));} +} +//class SrlAble__tst diff --git a/100_core/src/gplx/core/intls/Utf16__tst.java b/100_core/src/gplx/core/intls/Utf16__tst.java new file mode 100644 index 000000000..2ebb8799b --- /dev/null +++ b/100_core/src/gplx/core/intls/Utf16__tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.intls; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.primitives.*; +public class Utf16__tst { + private Utf16__fxt fxt = new Utf16__fxt(); + @Test public void Encode_decode() { +// fxt.Test_encode_decode(162, 194, 162); // cent +// fxt.Test_encode_decode(8364, 226, 130, 172); // euro + fxt.Test_encode_decode(150370, 240, 164, 173, 162); // example from [[UTF-8]]; should be encoded as two bytes + fxt.Test_encode_decode(143489, 240, 163, 130, 129); // EX: 駣𣂁脁 DATE:2017-04-22 + } + @Test public void Encode_as_bry_by_hex() { + fxt.Test_Encode_hex_to_bry("00", 0); + fxt.Test_Encode_hex_to_bry("41", 65); + fxt.Test_Encode_hex_to_bry("0041", 65); + fxt.Test_Encode_hex_to_bry("00C0", 195, 128); + } + @Test public void Surrogate() { + fxt.Test_surrogate(0x64321, 0xD950, 0xDF21); // example from w:UTF-16 + fxt.Test_surrogate(66643, 55297, 56403); // example from d:Boomerang + } +} +class Utf16__fxt { + private Int_obj_ref hi_ref = Int_obj_ref.New_neg1(), lo_ref = Int_obj_ref.New_neg1(); + public void Test_encode_decode(int expd_c_int, int... expd_int) { + byte[] expd = Bry_.New_by_ints(expd_int); + byte[] bfr = new byte[10]; + int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0); + byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len); + Tfds.Eq_ary(expd, actl); + int actl_c_int = Utf16_.Decode_to_int(bfr, 0); + Tfds.Eq(expd_c_int, actl_c_int); + } + public void Test_surrogate(int v, int hi, int lo) { + Tfds.Eq(v, Utf16_.Surrogate_merge((char)hi, (char)lo)); + Utf16_.Surrogate_split(v, hi_ref, lo_ref); + Tfds.Eq(hi, hi_ref.Val()); + Tfds.Eq(lo, lo_ref.Val()); + } + public void Test_Encode_hex_to_bry(String raw, int... expd) { + byte[] actl = Utf16_.Encode_hex_to_bry(raw); + Tfds.Eq_ary(Byte_.Ary_by_ints(expd), actl); + } +} diff --git a/100_core/src/gplx/core/intls/Utf8__tst.java b/100_core/src/gplx/core/intls/Utf8__tst.java new file mode 100644 index 000000000..5d32c1488 --- /dev/null +++ b/100_core/src/gplx/core/intls/Utf8__tst.java @@ -0,0 +1,67 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.intls; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Utf8__tst { + private Utf8__fxt fxt = new Utf8__fxt(); + @Test public void Get_prv_char_pos0() { + fxt.Test__Get_prv_char_pos0("abcd", 3); // len=1; (note that bry.len = 4) + fxt.Test__Get_prv_char_pos0("a", 0); // len=1; short-String + fxt.Test__Get_prv_char_pos0("abc¢", 3); // len=2; (note that bry.len = 5) + fxt.Test__Get_prv_char_pos0("abc€", 3); // len=3; (note that bry.len = 6) + fxt.Test__Get_prv_char_pos0("abc" + String_.new_u8(Byte_.Ary_by_ints(240, 164, 173, 162)), 3); // len=4; (note that bry.len = 7) + } + @Test public void Increment_char_at_last_pos() { + fxt.Test_Increment_char_at_last_pos("a", "b"); + fxt.Test_Increment_char_at_last_pos("abc", "abd"); + fxt.Test_Increment_char_at_last_pos("É", "Ê"); // len=2 + fxt.Test_Increment_char_at_last_pos("€", "₭"); // len=3 + } +// @Test public void Increment_char_at_last_pos_exhaustive_check() { // check all values; commented for perf +// Bry_bfr bfr = Bry_bfr_.New(); +// int bgn = 32; +// while (true) { +// byte[] bgn_bry = Utf16_.Encode_int_to_bry(bgn); +// int end = Utf8_.Increment_char(bgn); +// if (end == Utf8_.Codepoint_max) break; +//// if (bgn > 1024 * 1024) break; +// byte[] end_by_codepoint_next = Utf16_.Encode_int_to_bry(end); +// byte[] end_by_increment_char = Utf8_.Increment_char_at_last_pos(bgn_bry); +// if (!Bry_.Eq(end_by_codepoint_next, end_by_increment_char)) { +// Tfds.Write(bgn); +// } +//// bfr .Add_int_variable(bgn).Add_byte(Byte_ascii.Tab) +//// .Add(bgn_bry).Add_byte(Byte_ascii.Tab) +//// .Add(end_by_codepoint_next).Add_byte(Byte_ascii.Tab) +//// .Add(end_by_increment_char).Add_byte(Byte_ascii.Tab) +//// .Add_byte_nl() +//// ; +// bgn = end; +// bgn_bry = end_by_codepoint_next; +// } +// Tfds.WriteText(bfr.To_str_and_clear()); +// } +} +class Utf8__fxt { + public void Test__Get_prv_char_pos0(String src_str, int expd) { + byte[] src_bry = Bry_.new_u8(src_str); + Tfds.Eq(expd, Utf8_.Get_prv_char_pos0 (src_bry, src_bry.length)); + Tfds.Eq(expd, Utf8_.Get_prv_char_pos0_old(src_bry, src_bry.length - 1)); + } + public void Test_Increment_char_at_last_pos(String str, String expd) { + Tfds.Eq(expd, String_.new_u8(Utf8_.Increment_char_at_last_pos(Bry_.new_u8(str)))); + } +} diff --git a/100_core/src/gplx/core/ios/IoItm_fxt.java b/100_core/src/gplx/core/ios/IoItm_fxt.java new file mode 100644 index 000000000..c6d41632b --- /dev/null +++ b/100_core/src/gplx/core/ios/IoItm_fxt.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +public class IoItm_fxt { + public IoItmFil fil_wnt_(String s) {return fil_(Io_url_.wnt_fil_(s));} + public IoItmFil fil_(Io_url url) {return IoItmFil_.new_(url, 1, DateAdp_.parse_gplx("2001-01-01"), DateAdp_.parse_gplx("2001-01-01"));} + public IoItmDir dir_wnt_(String s) {return dir_(Io_url_.wnt_dir_(s));} + public IoItmDir dir_(Io_url url, IoItm_base... ary) { + IoItmDir rv = IoItmDir_.top_(url); + for (IoItm_base itm : ary) { + if (itm.Type_dir()) + rv.SubDirs().Add(itm); + else + rv.SubFils().Add(itm); + } + return rv; + } + public static IoItm_fxt new_() {return new IoItm_fxt();} IoItm_fxt() {} +} diff --git a/100_core/src/gplx/core/ios/IoZipWkr_tst.java b/100_core/src/gplx/core/ios/IoZipWkr_tst.java new file mode 100644 index 000000000..a2269374c --- /dev/null +++ b/100_core/src/gplx/core/ios/IoZipWkr_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoZipWkr_tst { + @Test public void Basic() { + wkr = IoZipWkr.new_(Io_url_.Empty, "e \"{0}\" -o\"{1}\" -y"); + tst_Expand_genCmdString(Io_url_.wnt_fil_("C:\\fil1.zip"), Io_url_.wnt_dir_("D:\\out\\"), "e \"C:\\fil1.zip\" -o\"D:\\out\" -y"); // NOTE: not "D:\out\" because .Xto_api + } IoZipWkr wkr; + void tst_Expand_genCmdString(Io_url srcUrl, Io_url trgUrl, String expd) { + Tfds.Eq(expd, wkr.Expand_genCmdString(srcUrl, trgUrl)); + } +} diff --git a/100_core/src/gplx/core/ios/Io_download_fmt_tst.java b/100_core/src/gplx/core/ios/Io_download_fmt_tst.java new file mode 100644 index 000000000..93659a9d4 --- /dev/null +++ b/100_core/src/gplx/core/ios/Io_download_fmt_tst.java @@ -0,0 +1,71 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.envs.*; +public class Io_download_fmt_tst { + Io_download_fmt_fxt fxt = new Io_download_fmt_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Fmt() { + fxt.Clear().Ini("downloading ~{src_name}: ~{prog_left} left (@ ~{prog_rate}); ~{prog_done} of ~{src_len} (~{prog_pct}%)", "http://a.org/b.png", Io_mgr.Len_kb * 10); + fxt.Now_add_f(1000).Prog_done_(1 * Io_mgr.Len_kb).Prog_pct_(1 * 1000).Prog_rate_(Io_mgr.Len_kb).Prog_left_(9 * 1000) + .Prog_msg_("downloading b.png: 09s left (@ 1.000 KBps); 1.000 KB of 10.000 KB (10.00%)") + .Download_(Io_mgr.Len_kb); + fxt.Now_add_f(1000).Prog_done_(2 * Io_mgr.Len_kb).Prog_pct_(2 * 1000).Prog_rate_(Io_mgr.Len_kb).Prog_left_(8 * 1000) + .Prog_msg_("downloading b.png: 08s left (@ 1.000 KBps); 2.000 KB of 10.000 KB (20.00%)") + .Download_(Io_mgr.Len_kb) + ; + fxt.Now_add_f(2000).Prog_done_(3 * Io_mgr.Len_kb).Prog_pct_(3 * 1000).Prog_rate_(768).Prog_left_(9333) + .Prog_msg_("downloading b.png: 09s left (@ 768.000 Bps); 3.000 KB of 10.000 KB (30.00%)") + .Download_(Io_mgr.Len_kb) + ; + } + @Test public void Tilde() { + fxt.Clear().Ini("a~b", "http://a.org/b.png", Io_mgr.Len_kb * 10); + } +} +class Io_download_fmt_fxt { + public Io_download_fmt_fxt Clear() { + if (fmt == null) { + fmt = new Io_download_fmt(); + } + System_.Ticks__test_set(0); + prog_done = prog_rate = prog_pct = prog_left = -1; + prog_msg = null; + return this; + } Io_download_fmt fmt; + public Io_download_fmt_fxt Now_add_f(int v) {System_.Ticks__test_add(v); return this;} + public Io_download_fmt_fxt Prog_done_(int v) {prog_done = v; return this;} long prog_done = -1; + public Io_download_fmt_fxt Prog_pct_ (int v) {prog_pct = v; return this;} long prog_pct = -1; + public Io_download_fmt_fxt Prog_rate_(int v) {prog_rate = v; return this;} long prog_rate = -1; + public Io_download_fmt_fxt Prog_left_(int v) {prog_left = v; return this;} long prog_left = -1; + public Io_download_fmt_fxt Prog_msg_(String v) { + prog_msg = v; return this; + } String prog_msg; + public Io_download_fmt_fxt Download_(int v) { + fmt.Prog(v); + if (prog_done != -1) Tfds.Eq(prog_done, fmt.Prog_done(), "prog_done"); + if (prog_pct != -1) Tfds.Eq(prog_pct , fmt.Prog_pct(), "prog_pct"); + if (prog_rate != -1) Tfds.Eq(prog_rate, fmt.Prog_rate(), "prog_rate"); + if (prog_left != -1) Tfds.Eq(prog_left, fmt.Prog_left(), "prog_left"); + if (prog_msg != null) Tfds.Eq(prog_msg, fmt.Prog_msg(), "prog_msg"); + return this; + } + public Io_download_fmt_fxt Ini(String prog_msg_hdr, String src_url, int src_len) { + fmt.Download_init(src_url, prog_msg_hdr); + fmt.Bgn(src_len); + return this; + } +} diff --git a/100_core/src/gplx/core/ios/Io_size__tst.java b/100_core/src/gplx/core/ios/Io_size__tst.java new file mode 100644 index 000000000..3c1aa7779 --- /dev/null +++ b/100_core/src/gplx/core/ios/Io_size__tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Io_size__tst { + private Io_size__fxt fxt = new Io_size__fxt(); + @Test public void XtoLong() { + fxt.Test_XtoLong("1", 1); + fxt.Test_XtoLong("1 KB", 1024); + fxt.Test_XtoLong("1 MB", 1024 * 1024); + fxt.Test_XtoLong("1 GB", 1024 * 1024 * 1024); + fxt.Test_XtoLong("12 kb", 12 * 1024); + fxt.Test_XtoLong("1.5 kb", 1024 + 512); // 1536 + fxt.Test_XtoLong("1.5 mb", (long)(1024 * 1024 * 1.5)); + fxt.Test_XtoLong("-1", -1); // NOTE: negative bytes allowed + + fxt.Test_XtoLongFail("1 kilobite"); + fxt.Test_XtoLongFail("1 BB"); + // fxt.Test_XtoLongFail("1.1"); // DELETED:do not check for fractional bytes; EX: 10.7 GB DATE:2015-01-06 + // fxt.Test_XtoLongFail("1.51 kb"); + } + @Test public void To_str() { + fxt.Test_XtoStr(1, "1.000 B"); + fxt.Test_XtoStr(1024, "1.000 KB"); + fxt.Test_XtoStr(1536, "1.500 KB"); + fxt.Test_XtoStr(1024 * 1024, "1.000 MB"); + fxt.Test_XtoStr(1016, "1,016.000 B"); // NOTE: 1016 is not 1.016 KB + } + @Test public void Xto_str_full() { + fxt.Test_Xto_str( 500, 1, "#,###", " ", Bool_.Y, "1 KB"); + fxt.Test_Xto_str( 1000, 1, "#,###", " ", Bool_.Y, "1 KB"); + fxt.Test_Xto_str( 2000, 1, "#,###", " ", Bool_.Y, "2 KB"); + fxt.Test_Xto_str( 1234567, 1, "#,###", " ", Bool_.Y, "1,206 KB"); + fxt.Test_Xto_str(1234567890, 1, "#,###", " ", Bool_.Y, "1,205,633 KB"); + } + @Test public void EqualsTest() { + fxt.Test_Equals("1", "1"); + fxt.Test_Equals("1 kb", "1 kb"); + fxt.Test_Equals("1024", "1 kb"); + fxt.Test_Equals("1048576", "1 mb"); + fxt.Test_Equals("1024 kb", "1 mb"); + fxt.Test_Equals("1.5 kb", "1536 b"); + } + @Test public void To_str_new___b___0() {fxt.Test__to_str_new( 0, 2, "0 B");} + @Test public void To_str_new___b___1() {fxt.Test__to_str_new( 1, 2, "1 B");} + @Test public void To_str_new__kb___1_501__1() {fxt.Test__to_str_new( 1538, 1, "1.5 KB");} + @Test public void To_str_new__kb___1_501__2() {fxt.Test__to_str_new( 1538, 2, "1.50 KB");} + @Test public void To_str_new__kb___1_501__3() {fxt.Test__to_str_new( 1538, 3, "1.501 KB");} + @Test public void To_str_new__kb___1_512__1() {fxt.Test__to_str_new( 1549, 1, "1.5 KB");} + @Test public void To_str_new__kb___1_512__2() {fxt.Test__to_str_new( 1549, 2, "1.51 KB");} + @Test public void To_str_new__kb___1_512__3() {fxt.Test__to_str_new( 1549, 3, "1.512 KB");} + @Test public void To_str_new__mb___1_512__1() {fxt.Test__to_str_new((1024 * 1024) + 536871, 1, "1.5 MB");} + @Test public void To_str_new__mb___1_512__2() {fxt.Test__to_str_new((1024 * 1024) + 536871, 2, "1.51 MB");} + @Test public void To_str_new__mb___1_512__3() {fxt.Test__to_str_new((1024 * 1024) + 536871, 3, "1.512 MB");} + @Test public void To_str_new__gb___1() {fxt.Test__to_str_new(1819264175, 2, "1.69 GB");} +} +class Io_size__fxt { + public void Test_XtoLong(String raw, long expd) {Tfds.Eq(expd, Io_size_.parse_or(raw, Long_.Min_value));} + public void Test_XtoLongFail(String raw) { + long val = Io_size_.parse_or(raw, Long_.Min_value); + if (val != Long_.Min_value) Tfds.Fail("expd parse failure; raw=" + raw); + } + public void Test_Equals(String lhs, String rhs) {Tfds.Eq(Io_size_.parse_or(lhs, Long_.Min_value), Io_size_.parse_or(rhs, Long_.Min_value));} + public void Test_XtoStr(long val, String expd) {Tfds.Eq(expd, Io_size_.To_str(val));} + public void Test_Xto_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1, String expd) {Tfds.Eq(expd, Io_size_.To_str(val, exp_1024, val_fmt, unit_pad, round_0_to_1));} + public void Test__to_str_new(long val, int decimal_places, String expd) { + Bry_bfr bfr = Bry_bfr_.New(); + Tfds.Eq_str(expd, Io_size_.To_str_new(bfr, val, decimal_places)); + } +} diff --git a/100_core/src/gplx/core/ios/streams/IoStream_mem_tst.java b/100_core/src/gplx/core/ios/streams/IoStream_mem_tst.java new file mode 100644 index 000000000..bceed5e8d --- /dev/null +++ b/100_core/src/gplx/core/ios/streams/IoStream_mem_tst.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*; +import org.junit.*; //using System.IO; /*Stream*/ +public class IoStream_mem_tst { + @Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer + IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0); + byte[] data = Bry_.New_by_ints(1); + stream.Write(data, 0, Array_.Len(data)); + + Tfds.Eq(1L , stream.Len()); + Tfds.Eq((byte)1 , stream.Buffer()[0]); + stream.Rls(); + } +} diff --git a/100_core/src/gplx/core/ios/streams/IoStream_mock_tst.java b/100_core/src/gplx/core/ios/streams/IoStream_mock_tst.java new file mode 100644 index 000000000..fc04c7a95 --- /dev/null +++ b/100_core/src/gplx/core/ios/streams/IoStream_mock_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*; +import org.junit.*; +public class IoStream_mock_tst { + @Before public void init() {fxt.Clear();} IoStream_mock_fxt fxt = new IoStream_mock_fxt(); + @Test public void Basic() { + fxt.Init_src_str_("abcde").Init_trg_len_(5).Init_rdr_limit_(2).Init_read_len_(2); + fxt.Test_read("ab").Test_read("cd").Test_read("e"); + } + @Test public void Read_limit() { + fxt.Init_src_str_("abcde").Init_trg_len_(5).Init_rdr_limit_(2).Init_read_len_(4); + fxt.Test_read("ab").Test_read("cd").Test_read("e"); + } +} +class IoStream_mock_fxt { + public void Clear() { + if (rdr == null) + rdr = new IoStream_mock(); + rdr.Reset(); + trg_bgn = 0; + } IoStream_mock rdr; byte[] trg_bry; + public IoStream_mock_fxt Init_src_str_(String v) {rdr.Data_bry_(Bry_.new_a7(v)); return this;} + public IoStream_mock_fxt Init_trg_len_(int v) {trg_bry = new byte[v]; return this;} + public IoStream_mock_fxt Init_read_len_(int v) {read_len = v; return this;} int read_len; + public IoStream_mock_fxt Init_rdr_limit_(int v) {rdr.Read_limit_(v); return this;} + public IoStream_mock_fxt Test_read(String expd) { + int bytes_read = rdr.Read(trg_bry, trg_bgn, read_len); + Tfds.Eq(expd, String_.new_a7(trg_bry, trg_bgn, trg_bgn + bytes_read)); + trg_bgn += bytes_read; + return this; + } int trg_bgn; +} diff --git a/100_core/src/gplx/core/ios/streams/Io_stream_rdr__tst.java b/100_core/src/gplx/core/ios/streams/Io_stream_rdr__tst.java new file mode 100644 index 000000000..32e5d1350 --- /dev/null +++ b/100_core/src/gplx/core/ios/streams/Io_stream_rdr__tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*; +import org.junit.*; +public class Io_stream_rdr__tst { + @Before public void init() {fxt.Clear();} private Io_stream_rdr__fxt fxt = new Io_stream_rdr__fxt(); + @After public void term() {fxt.Rls();} + @Test public void Bz2_read() { + fxt .Init_stream("abcd") // read everything at once + .Expd_bytes_read(4).Test_read(0, 4, "abcd"); + fxt .Init_stream("abcd") // read in steps + .Expd_bytes_read(1).Test_read(0, 1, "a") + .Expd_bytes_read(2).Test_read(1, 2, "bc") + .Expd_bytes_read(1).Test_read(3, 1, "d") + ; + } +} +class Io_stream_rdr__fxt { + private java.io.InputStream stream; + private int stream_bry_len; + public void Clear() { + expd_bytes_read = Int_.Min_value; + } + public Io_stream_rdr__fxt Expd_bytes_read(int v) {expd_bytes_read = v; return this;} private int expd_bytes_read = Int_.Min_value; + public Io_stream_rdr__fxt Init_stream(String v) { + byte[] stream_bry = Bry_.new_a7(v); + stream_bry_len = stream_bry.length; + stream = Io_stream_rdr_.New__mem_as_stream(stream_bry); + return this; + } + public Io_stream_rdr__fxt Test_read(int bgn, int len, String expd_str) { + byte[] bfr = new byte[stream_bry_len]; // allocate whole stream; may not use it all + int actl_bytes_read = Io_stream_rdr_.Read_by_parts(stream, 8, bfr, bgn, len); + Tfds.Eq(expd_bytes_read, actl_bytes_read, "bytes_read"); + Tfds.Eq(expd_str, String_.new_u8(bfr, bgn, bgn + actl_bytes_read), "str"); + return this; + } + public void Rls() { + Io_stream_rdr_.Close(stream); + } +} diff --git a/100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java b/100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java new file mode 100644 index 000000000..bf0cf4f43 --- /dev/null +++ b/100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*; +public class Io_zip_mgr_mok implements Io_zip_mgr { + public void Zip_fil(Io_url src_fil, Io_url trg_fil) { + byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil); + byte[] zip_bry = Zip_bry(src_bry, 0, src_bry.length); + Io_mgr.Instance.SaveFilBry(trg_fil, zip_bry); + } + public void Zip_dir(Io_url src_dir, Io_url trg_fil) {} + public byte[] Zip_bry(byte[] src, int bgn, int len) {return Bry_.Add(Bry_zipped, Bry_.Mid(src, bgn, len));} + public byte[] Unzip_bry(byte[] src, int bgn, int len) { + if (src == Bry_.Empty) return src; + byte[] section = Bry_.Mid(src, bgn, bgn + len); + if (!Bry_.Has_at_bgn(section, Bry_zipped, 0, section.length)) throw Err_.new_wo_type("src not zipped", "section", String_.new_u8(section)); + return Bry_.Mid(section, Bry_zipped.length, section.length); + } + public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {} + private static final byte[] Bry_zipped = Bry_.new_a7("zipped:"); + public static final Io_zip_mgr_mok Instance = new Io_zip_mgr_mok(); Io_zip_mgr_mok() {} +} diff --git a/100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java b/100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java new file mode 100644 index 000000000..113d73ba7 --- /dev/null +++ b/100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*; +import org.junit.*; +public class Io_zip_mgr_tst { + @Test public void Zip_unzip() { + Zip_unzip_tst("abcdefghijklmnopqrstuvwxyz"); + } + private void Zip_unzip_tst(String s) { + Io_zip_mgr zip_mgr = Io_zip_mgr_base.Instance; + byte[] src = Bry_.new_a7(s); + byte[] zip = zip_mgr.Zip_bry(src, 0, src.length); + byte[] unz = zip_mgr.Unzip_bry(zip, 0, zip.length); + Tfds.Eq_ary(src, unz); + } +} diff --git a/100_core/src/gplx/core/js/Js_wtr_tst.java b/100_core/src/gplx/core/js/Js_wtr_tst.java new file mode 100644 index 000000000..b4d3053db --- /dev/null +++ b/100_core/src/gplx/core/js/Js_wtr_tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.js; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Js_wtr_tst { + @Before public void Init() {fxt.Clear();} private Js_wtr_fxt fxt = new Js_wtr_fxt(); + @Test public void Basic() { + fxt.Test_write_val_html("abc" , "'abc'"); + fxt.Test_write_val_html("a'b" , "'a\\'b'"); + fxt.Test_write_val_html("a\"b" , "'a\\\"b'"); + fxt.Test_write_val_html("a\nb" , "'a\\nb'"); + fxt.Test_write_val_html("a\rb" , "'ab'"); + fxt.Test_write_val_html("a\\&b" , "'a\\\\&b'"); // PURPOSE: backslashes need to be escaped; need for MathJax and "\&"; PAGE:Electromagnetic_field_tensor; DATE:2014-06-24 + } +} +class Js_wtr_fxt { + private Js_wtr wtr = new Js_wtr(); + public void Clear() { + wtr.Clear(); + wtr.Quote_char_(Byte_ascii.Apos); + } + public void Test_write_val_html(String raw, String expd) { + wtr.Write_val(Bry_.new_u8(raw)); + Tfds.Eq(expd, wtr.To_str_and_clear()); + } +} diff --git a/100_core/src/gplx/core/lists/List_adp_sorter_tst.java b/100_core/src/gplx/core/lists/List_adp_sorter_tst.java new file mode 100644 index 000000000..5eca0abe3 --- /dev/null +++ b/100_core/src/gplx/core/lists/List_adp_sorter_tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists; import gplx.*; import gplx.core.*; +import org.junit.*; +public class List_adp_sorter_tst { + @Test public void Basic() { + Object[] src = new Object[] {0,8,1,7,2,6,3,5,4}; + List_adp_sorter.new_().Sort(src, src.length); + Tfds.Eq_ary(src, Sequential(0, 8)); + } + @Test public void Basic2() { + Object[] src = new Object[] {"0","8","1","7","2","6","3","5","4"}; + List_adp_sorter.new_().Sort(src, src.length); + Tfds.Eq_ary(src, new Object[] {"0","1","2","3","4","5","6","7","8"}); + } + Object[] Sequential(int bgn, int end) { + Object[] rv = new Object[end - bgn + 1]; + for (int i = 0; i < Array_.Len(rv); i++) + rv[i] = i + bgn; + return rv; + } +} diff --git a/100_core/src/gplx/core/lists/StackAdp_tst.java b/100_core/src/gplx/core/lists/StackAdp_tst.java new file mode 100644 index 000000000..99a367b26 --- /dev/null +++ b/100_core/src/gplx/core/lists/StackAdp_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists; import gplx.*; import gplx.core.*; +import org.junit.*; +public class StackAdp_tst { + @Test public void XtoList() { + tst_XtoList(1, 2, 3); + } + void tst_XtoList(int... ary) { + StackAdp stack = StackAdp_.new_(); + for (int i : ary) + stack.Push(i); + List_adp list = stack.XtoList(); + int[] actl = (int[])list.To_ary(int.class); + for (int i = 0; i < ary.length; i++) + Tfds.Eq(ary[i], actl[i]); + } +} diff --git a/100_core/src/gplx/core/lists/rings/Ring__long__tst.java b/100_core/src/gplx/core/lists/rings/Ring__long__tst.java new file mode 100644 index 000000000..0735bc495 --- /dev/null +++ b/100_core/src/gplx/core/lists/rings/Ring__long__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists.rings; import gplx.*; import gplx.core.*; import gplx.core.lists.*; +import org.junit.*; import gplx.core.tests.*; +public class Ring__long__tst { + private final Ring__long__fxt fxt = new Ring__long__fxt(); + @Test public void Basic__1() {fxt.Clear().Add(1) .Test__to_ary(1);} + @Test public void Basic__2() {fxt.Clear().Add(1, 2) .Test__to_ary(1, 2);} + @Test public void Basic__3() {fxt.Clear().Add(1, 2, 3) .Test__to_ary(1, 2, 3);} + @Test public void Wrap__1() {fxt.Clear().Add(1, 2, 3, 4) .Test__to_ary(2, 3, 4);} + @Test public void Wrap__2() {fxt.Clear().Add(1, 2, 3, 4, 5) .Test__to_ary(3, 4, 5);} + @Test public void Wrap__3() {fxt.Clear().Add(1, 2, 3, 4, 5, 6) .Test__to_ary(4, 5, 6);} +} +class Ring__long__fxt { + private Ring__long ring = new Ring__long(3); + public Ring__long__fxt Clear() {ring.Clear(); return this;} + public Ring__long__fxt Add(long... ary) { + for (long itm : ary) + ring.Add(itm); + return this; + } + public Ring__long__fxt Test__to_ary(long... expd) { + Gftest.Eq__ary(expd, ring.To_ary(), "to_ary"); + return this; + } +} diff --git a/100_core/src/gplx/core/lists/rings/Ring__string__tst.java b/100_core/src/gplx/core/lists/rings/Ring__string__tst.java new file mode 100644 index 000000000..aa22a6b71 --- /dev/null +++ b/100_core/src/gplx/core/lists/rings/Ring__string__tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists.rings; import gplx.*; import gplx.core.*; import gplx.core.lists.*; +import org.junit.*; +public class Ring__string__tst { + private final Ring__string__fxt fxt = new Ring__string__fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Clear().Max_(3).Push_many("a") .Expd("a"); + fxt.Clear().Max_(3).Push_many("a", "b") .Expd("a", "b"); + fxt.Clear().Max_(3).Push_many("a", "b", "c") .Expd("a", "b", "c"); + fxt.Clear().Max_(3).Push_many("a", "b", "c", "d") .Expd("b", "c", "d"); + fxt.Clear().Max_(3).Push_many("a", "b", "c", "d", "e") .Expd("c", "d", "e"); + fxt.Clear().Max_(3).Push_many("a", "b", "c", "d", "e", "f") .Expd("d", "e", "f"); + } +} +class Ring__string__fxt { + Ring__string ring = new Ring__string(); + public Ring__string__fxt Clear() {ring.Clear(); return this;} + public Ring__string__fxt Max_(int v) {ring.Max_(v); return this;} + public Ring__string__fxt Push_many(String... ary) { + int ary_len = ary.length; + for (int i = 0; i < ary_len; i++) + ring.Push(ary[i]); + return this; + } + public Ring__string__fxt Expd(String... expd) { + Tfds.Eq_ary_str(expd, ring.Xto_str_ary()); + return this; + } +} diff --git a/100_core/src/gplx/core/log_msgs/Gfo_msg_root_tst.java b/100_core/src/gplx/core/log_msgs/Gfo_msg_root_tst.java new file mode 100644 index 000000000..76bfd0ec9 --- /dev/null +++ b/100_core/src/gplx/core/log_msgs/Gfo_msg_root_tst.java @@ -0,0 +1,60 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.log_msgs; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Gfo_msg_root_tst { + Gfo_msg_root_fxt fxt = new Gfo_msg_root_fxt(); + @Before public void setup() {fxt.Reset();} + @Test public void Str() { + fxt.Clear().Expd_data_str_("failed a0 b0").Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0"); + fxt.Clear().Expd_data_str_("failed a1 b1").Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a1", "b1"); + } +// @Test public void Item() { // DISABLED: no longer registering items with owner; +// fxt.Clear().Expd_item_uid_(0).Expd_item_fmtr_arg_exists_(Bool_.Y).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0"); +// fxt.Clear().Expd_item_uid_(1).Expd_item_fmtr_arg_exists_(Bool_.N).Tst_data_new_many("proj.cls.proc", "err_1", "failed"); +// fxt.Clear().Expd_item_uid_(0).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0"); // make sure item_uid stays the same +// } + @Test public void Cache() { + fxt.Mgr().Data_ary_len_(2); + fxt.Clear().Expd_data_uid_(0).Tst_data_new_many("x", "err_0", "a"); + fxt.Clear().Expd_data_uid_(1).Tst_data_new_many("x", "err_0", "b"); + fxt.Clear().Expd_data_uid_(2).Tst_data_new_many("x", "err_0", "a"); + fxt.Mgr().Data_ary_clear(); + fxt.Clear().Expd_data_uid_(0).Tst_data_new_many("x", "err_0", "a"); + } +} +class Gfo_msg_root_fxt { + Gfo_msg_root root = new Gfo_msg_root("tst"); + public Gfo_msg_root_fxt Reset() {root.Reset(); this.Clear(); return this;} + public Gfo_msg_root_fxt Clear() { + expd_item_uid = -1; + expd_item_fmtr_arg_exists = Bool_.__byte; + expd_data_uid = -1; + expd_data_str = null; + return this; + } + public Gfo_msg_root Mgr() {return root;} + public Gfo_msg_root_fxt Expd_data_uid_(int v) {this.expd_data_uid = v; return this;} int expd_data_uid; + public Gfo_msg_root_fxt Expd_data_str_(String v) {this.expd_data_str = v; return this;} private String expd_data_str; + public Gfo_msg_root_fxt Expd_item_uid_(int v) {this.expd_item_uid = v; return this;} int expd_item_uid; + public Gfo_msg_root_fxt Expd_item_fmtr_arg_exists_(boolean v) {this.expd_item_fmtr_arg_exists = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_item_fmtr_arg_exists; + public void Tst_data_new_many(String path, String key, String fmt, Object... vals) { + Gfo_msg_data data = root.Data_new_many(Gfo_msg_itm_.Cmd_note, path, key, fmt, vals); + if (expd_item_uid != -1) Tfds.Eq(expd_item_uid, data.Item().Uid());; + if (expd_item_fmtr_arg_exists != Bool_.__byte) Tfds.Eq(Bool_.By_int(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist()); + if (expd_data_str != null) Tfds.Eq(expd_data_str, data.Item().Gen_str_many(data.Vals())); + } +} diff --git a/100_core/src/gplx/core/primitives/EnmParser_tst.java b/100_core/src/gplx/core/primitives/EnmParser_tst.java new file mode 100644 index 000000000..b8480ac6f --- /dev/null +++ b/100_core/src/gplx/core/primitives/EnmParser_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.primitives; import gplx.*; import gplx.core.*; +import org.junit.*; +public class EnmParser_tst { + @Before public void setup() { + parser = EnmMgr.new_(); + } + @Test public void Basic() { // 1,2,4,8 + parser.BitRngEnd_(8); + run_Reg(0, "zero"); + run_Reg(1, "one"); + run_Reg(2, "two"); + run_Reg(4, "four"); + run_Reg(8, "eight"); + + tst_Convert("zero", 0); + tst_Convert("one", 1); + tst_Convert("eight", 8); + tst_Convert("one+eight", 9); + } + @Test public void Keys() { + parser.BitRngBgn_(65536).BitRngEnd_(262144); + run_Reg( 65, "a"); + run_Reg( 65536, "shift"); + run_Reg(131072, "ctrl"); + run_Reg(262144, "alt"); + tst_Convert("a", 65); + tst_Convert("shift+a", 65 + 65536); + tst_Convert("ctrl+a", 65 + 131072); + tst_Convert("shift+ctrl+a", 65 + 65536 + 131072); + } + @Test public void Prefix() { + parser.Prefix_("key.").BitRngBgn_(128).BitRngEnd_(128); + run_Reg(65, "a"); + tst_Convert("key.a", 65); + } + void run_Reg(int i, String s) {parser.RegObj(i, s, "NULL");} + void tst_Convert(String raw, int val) { + int actlVal = parser.GetVal(raw); + Tfds.Eq(val, actlVal); + Tfds.Eq(raw, parser.GetStr(val)); + } + EnmMgr parser; +} diff --git a/100_core/src/gplx/core/security/Hash_algo__md5__tst.java b/100_core/src/gplx/core/security/Hash_algo__md5__tst.java new file mode 100644 index 000000000..719c63e6d --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_algo__md5__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors + private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5()); + @Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");} + @Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");} + @Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");} + @Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");} + @Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");} + @Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");} + @Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");} + //@Test + public void Num__x_8() {fxt.Test__hash("57edf4a22be3c955ac49da2e2107b67a", String_.Repeat("1234567890", 8));} + //@Test + public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));} +} +class Hash_algo__fxt { + private final Hash_algo algo; + public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;} + public void Test__hash(String expd, String raw) { + Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw))); + Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw))); + } +} diff --git a/100_core/src/gplx/core/security/Hash_algo__sha1__tst.java b/100_core/src/gplx/core/security/Hash_algo__sha1__tst.java new file mode 100644 index 000000000..b3912eaa6 --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_algo__sha1__tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/ + private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1()); + @Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");} + @Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");} + @Test public void abc() {fxt.Test__hash("a9993e364706816aba3e25717850c26c9cd0d89d", "abc");} + @Test public void message_digest() {fxt.Test__hash("c12252ceda8be8994d5fa0290a47231c1d16aae3", "message digest");} + @Test public void a_z() {fxt.Test__hash("32d10c7b8cf96570ca04ce37f2a19d84240d3a89", "abcdefghijklmnopqrstuvwxyz");} + @Test public void a_q__mixed() {fxt.Test__hash("84983e441c3bd26ebaae4aa1f95129e5e54670f1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");} + @Test public void A_Z__a_z__0_9() {fxt.Test__hash("761c457bf73b14d27e9e9265c46f4b4dda11f940", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");} + // @Test + public void Num() {fxt.Test__hash("50abf5706a150990a08b2c5ea40fa0e585554732", String_.Repeat("1234567890", 8));} + //@Test + public void A_1Million() {fxt.Test__hash("34aa973cd4c4daa4f61eeb2bdbad27316534016f", String_.Repeat("a", 1000000));} +} diff --git a/100_core/src/gplx/core/security/Hash_algo__sha2_256__tst.java b/100_core/src/gplx/core/security/Hash_algo__sha2_256__tst.java new file mode 100644 index 000000000..528317452 --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_algo__sha2_256__tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/ + private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256()); + @Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");} + @Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");} + @Test public void abc() {fxt.Test__hash("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");} + @Test public void message_digest() {fxt.Test__hash("f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650", "message digest");} + @Test public void a_z() {fxt.Test__hash("71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73", "abcdefghijklmnopqrstuvwxyz");} + @Test public void a_q__mixed() {fxt.Test__hash("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");} + @Test public void A_Z__a_z__0_9() {fxt.Test__hash("db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");} + // @Test + public void Num() {fxt.Test__hash("f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e", String_.Repeat("1234567890", 8));} + //@Test + public void A_1Million() {fxt.Test__hash("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0", String_.Repeat("a", 1000000));} +} diff --git a/100_core/src/gplx/core/security/Hash_algo__tth_192__tst.java b/100_core/src/gplx/core/security/Hash_algo__tth_192__tst.java new file mode 100644 index 000000000..9d19d6065 --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_algo__tth_192__tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/ +public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698 + private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192()); + @Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");} + @Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");} + @Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");} + @Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");} + @Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");} + @Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");} + @Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");} + // @Test + public void a__x_1024() {fxt.Test__hash("L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA", String_.Repeat("A", 1024));} + // @Test + public void a__x_1025() {fxt.Test__hash("PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY", String_.Repeat("A", 1025));} + // @Test + public void A__Pow27() {fxt.Test__hash("QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ", String_.Repeat("A", (int)Math_.Pow(2, 27))); + } +} diff --git a/100_core/src/gplx/core/security/Hash_algo__tth_192_tree_tst.java b/100_core/src/gplx/core/security/Hash_algo__tth_192_tree_tst.java new file mode 100644 index 000000000..e2c744568 --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_algo__tth_192_tree_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Hash_algo__tth_192_tree_tst { + @Test public void CalcRecursiveHalves() { + tst_CalcRecursiveHalves(129, 128); + tst_CalcRecursiveHalves(128, 127); + tst_CalcRecursiveHalves(100, 99); + tst_CalcRecursiveHalves(20, 19); + tst_CalcRecursiveHalves(6, 5); + tst_CalcRecursiveHalves(5, 4); + tst_CalcRecursiveHalves(4, 3); + tst_CalcRecursiveHalves(3, 2); + tst_CalcRecursiveHalves(2, 1); + tst_CalcRecursiveHalves(1, 0); + tst_CalcRecursiveHalves(0, 0); + } + @Test public void CalcWorkUnits() { + tst_CalcWorkUnits(101, 21); // leafs; 10 full, 1 part (+11) -> reduce 11 to 5+1 (+5) -> reduce 6 to 3 (+3) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1) + tst_CalcWorkUnits(100, 19); // leafs; 10 full (+10) -> reduce 10 to 5 (+5) -> reduce 5 to 2+1 (+2) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1) + tst_CalcWorkUnits(30, 5); // leafs; 3 full (+3) -> reduce 3 to 1+1 (+1) -> reduce 2 to 1 (+1) + tst_CalcWorkUnits(11, 3); // leafs: 1 full, 1 part (+2) -> reduce 2 to 1 (+1) + tst_CalcWorkUnits(10, 1); + tst_CalcWorkUnits(9, 1); + tst_CalcWorkUnits(1, 1); + tst_CalcWorkUnits(0, 1); + } + void tst_CalcWorkUnits(int length, int expd) { + Hash_algo__tth_192 algo = new Hash_algo__tth_192(); algo.BlockSize_set(10); + int actl = algo.CalcWorkUnits(length); + Tfds.Eq(expd, actl); + } + void tst_CalcRecursiveHalves(int val, int expd) { + int actl = CalcRecursiveHalvesMock(val); + Tfds.Eq(expd, actl); + } + int CalcRecursiveHalvesMock(int val) { + if (val <= 1) return 0; + int rv = 0; + while (true) { + int multiple = val / 2; + int remainder = val % 2; + rv += multiple; + val = multiple + remainder; + if (val == 1) + return remainder == 0 ? rv : ++rv; + } + } +} diff --git a/100_core/src/gplx/core/security/Hash_console_wtr_tst.java b/100_core/src/gplx/core/security/Hash_console_wtr_tst.java new file mode 100644 index 000000000..3e0cd5431 --- /dev/null +++ b/100_core/src/gplx/core/security/Hash_console_wtr_tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/ +public class Hash_console_wtr_tst { + @Before public void setup() { + Hash_algo__tth_192 algo = new Hash_algo__tth_192(); + algo.BlockSize_set(10); + calc = algo; + } + @Test public void Basic() { + tst_Status(10, stringAry_(" - hash: 100%")); + tst_Status(11, stringAry_(" - hash: 66%")); + tst_Status(30, stringAry_(" - hash: 40%", " - hash: 60%", " - hash: 100%")); + } + void tst_Status(int count, String[] expdWritten) { + Console_adp__mem dialog = Console_adp_.Dev(); + String data = String_.Repeat("A", count); + IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data); + calc.Hash_stream_as_str(dialog, stream); + String[] actlWritten = dialog.Written().To_str_ary(); + Tfds.Eq_ary(actlWritten, expdWritten); + } + String[] stringAry_(String... ary) {return ary;} + Hash_algo calc; +} diff --git a/100_core/src/gplx/core/tests/PerfLogMgr_fxt.java b/100_core/src/gplx/core/tests/PerfLogMgr_fxt.java new file mode 100644 index 000000000..4a53129d6 --- /dev/null +++ b/100_core/src/gplx/core/tests/PerfLogMgr_fxt.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.tests; import gplx.*; import gplx.core.*; +import gplx.core.strings.*; import gplx.core.envs.*; +public class PerfLogMgr_fxt { + public void Init(Io_url url, String text) { + this.url = url; + entries.Resize_bounds(1000); + entries.Add(new PerfLogItm(0, text + "|" + Datetime_now.Get().XtoStr_gplx())); + tmr.Bgn(); + } + public void Write(String text) { + long milliseconds = tmr.ElapsedMilliseconds(); + entries.Add(new PerfLogItm(milliseconds, text)); + tmr.Bgn(); + } + public void WriteFormat(String fmt, Object... ary) { + long milliseconds = tmr.ElapsedMilliseconds(); + String text = String_.Format(fmt, ary); + entries.Add(new PerfLogItm(milliseconds, text)); + tmr.Bgn(); + } + public void Flush() { + String_bldr sb = String_bldr_.new_(); + for (Object itmObj : entries) { + PerfLogItm itm = (PerfLogItm)itmObj; + sb.Add(itm.To_str()).Add_char_crlf(); + } + Io_mgr.Instance.AppendFilStr(url, sb.To_str()); + entries.Clear(); + } + List_adp entries = List_adp_.New(); PerfLogTmr tmr = PerfLogTmr.new_(); Io_url url = Io_url_.Empty; + public static final PerfLogMgr_fxt Instance = new PerfLogMgr_fxt(); PerfLogMgr_fxt() {} + class PerfLogItm { + public String To_str() { + String secondsStr = Time_span_.To_str(milliseconds, Time_span_.Fmt_Default); + secondsStr = String_.PadBgn(secondsStr, 7, "0"); // 7=000.000; left-aligns all times + return String_.Concat(secondsStr, "|", text); + } + long milliseconds; String text; + @gplx.Internal protected PerfLogItm(long milliseconds, String text) { + this.milliseconds = milliseconds; this.text = text; + } + } + +} +class PerfLogTmr { + public void Bgn() {bgn = System_.Ticks();} long bgn; + public long ElapsedMilliseconds() {return System_.Ticks() - bgn; } + public static PerfLogTmr new_() {return new PerfLogTmr();} PerfLogTmr() {} +} diff --git a/100_core/src/gplx/core/texts/BaseXXConverter_tst.java b/100_core/src/gplx/core/texts/BaseXXConverter_tst.java new file mode 100644 index 000000000..f8287cc83 --- /dev/null +++ b/100_core/src/gplx/core/texts/BaseXXConverter_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.texts; import gplx.*; import gplx.core.*; +import org.junit.*; +public class BaseXXConverter_tst { + @Test public void Base32() { + tst_Base32("", ""); + tst_Base32("f", "MY"); + tst_Base32("fo", "MZXQ"); + tst_Base32("foo", "MZXW6"); + tst_Base32("foob", "MZXW6YQ"); + tst_Base32("fooba", "MZXW6YTB"); + tst_Base32("foobar", "MZXW6YTBOI"); + tst_Base32("A", "IE"); + tst_Base32("a", "ME"); + tst_Base32("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLIZDGNBVGY3Q"); + } + @Test public void Base64() { + tst_Base64("", ""); + tst_Base64("f", "Zg=="); + tst_Base64("fo", "Zm8="); + tst_Base64("foo", "Zm9v"); + tst_Base64("foob", "Zm9vYg=="); + tst_Base64("fooba", "Zm9vYmE="); + tst_Base64("foobar", "Zm9vYmFy"); +// tst_Base64("A", "IE"); +// tst_Base64("a", "ME"); +// tst_Base64("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLIZDGNBVGY3Q"); + } + void tst_Base32(String orig, String expd) { + String actl = Base32Converter.EncodeString(orig); + Tfds.Eq(expd, actl); + String decode = Base32Converter.DecodeString(actl); + Tfds.Eq(orig, decode); + } + void tst_Base64(String orig, String expd) { + String actl = Base64Converter.EncodeString(orig); + Tfds.Eq(expd, actl); + String decode = Base64Converter.DecodeString(actl); + Tfds.Eq(orig, decode); + } +} +//http://tools.ietf.org/html/rfc4648: test vectors for "foobar" diff --git a/100_core/src/gplx/core/texts/CharStream_tst.java b/100_core/src/gplx/core/texts/CharStream_tst.java new file mode 100644 index 000000000..3466f7c85 --- /dev/null +++ b/100_core/src/gplx/core/texts/CharStream_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.texts; import gplx.*; import gplx.core.*; +import org.junit.*; +public class CharStream_tst { + @Before public void setup() { + stream = CharStream.pos0_("abcdefgh"); + } + @Test public void To_str() { + Tfds.Eq(stream.To_str(), "abcdefgh"); + } + @Test public void CurrentText() { + stream.MoveNextBy(1); + Tfds.Eq(stream.XtoStrAtCur(2), "bc"); + Tfds.Eq(stream.To_str(), "abcdefgh"); + } + @Test public void CurrentText_outOfBounds() { + stream.MoveNextBy(7); + Tfds.Eq(stream.XtoStrAtCur(2), "h"); + } + @Test public void Match() { + stream.MoveNextBy(6); + tst_Match(true, "g"); + tst_Match(false, "z"); + tst_Match(true, "gh"); + tst_Match(false, "gz"); + tst_Match(false, "ghi"); + } + @Test public void AtBounds() { + stream.Move_to(-1); + tst_AtBounds(true, false, false); + + stream.Move_to(0); + tst_AtBounds(false, true, false); + + stream.Move_to(stream.Len()); + tst_AtBounds(false, false, true); + } + void tst_Match(boolean expd, String text) {Tfds.Eq(expd, stream.Match(text));} + void tst_AtBounds(boolean atBgn, boolean atMid, boolean atEnd) { + Tfds.Eq(atBgn, stream.AtBgn()); + Tfds.Eq(atMid, stream.AtMid()); + Tfds.Eq(atEnd, stream.AtEnd()); + } + CharStream stream; +} diff --git a/100_core/src/gplx/core/texts/RegxPatn_cls_ioMatch_tst.java b/100_core/src/gplx/core/texts/RegxPatn_cls_ioMatch_tst.java new file mode 100644 index 000000000..62dfc663c --- /dev/null +++ b/100_core/src/gplx/core/texts/RegxPatn_cls_ioMatch_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.texts; import gplx.*; import gplx.core.*; +import org.junit.*; +public class RegxPatn_cls_ioMatch_tst { + @Test public void SimpleMatches() { + tst_Matches("file.cs", "file.cs", true); // basic + tst_Matches("file.cs", "file.cs.exe", false); // fail: must match name precisely + tst_Matches("file.cs", "tst_file.cs", false); // fail: must match name precisely + } + @Test public void Wildcard() { + tst_Matches("*.cs", "file.cs", true); // pass: before + tst_Matches("file*", "file_valid.cs", true); // pass: after + tst_Matches("*.exe", "file.cs", false); // fail: before + tst_Matches("file*", "invalid_file.cs", false); // fail: after + } + @Test public void DoubleWildcard() { + tst_Matches("*cs*", "file.cs", true); // pass: after + tst_Matches("*cs*", "csFile.exe", true); // pass: before + tst_Matches("*cs*", "file.cs.exe", true); // pass: middle + tst_Matches("*cs*", "file.exe", false); // fail + } + @Test public void Compound() { + tst_Matches("*.cs|*.exe", "file.cs", true); // pass: match first + tst_Matches("*.cs|*.exe", "file.exe", true); // pass: match second + tst_Matches("*.cs|*.exe", "file.dll", false); // fail: match neither + tst_Matches("*.cs|*.exe", "file.cs.exe.dll", false); // fail: match neither (though both are embedded) + } + @Test public void Backslash() { + tst_Matches("*\\bin\\*", "C:\\project\\bin\\", true); // pass: dir + tst_Matches("*\\bin\\*", "C:\\project\\bin\\file.dll", true); // pass: fil + tst_Matches("*\\bin\\*", "C:\\project\\binFiles\\", false); // fail + } + @Test public void MixedCase() { + tst_Matches("file.cs", "file.cs", true); // pass: same case + tst_Matches("file.cs", "File.cS", true); // pass: diff case + } + void tst_Matches(String regx, String raw, boolean expd) { + RegxPatn_cls_ioMatch pattern = RegxPatn_cls_ioMatch_.parse(regx, false); + boolean actl = pattern.Matches(raw); + Tfds.Eq(expd, actl); + } +} diff --git a/100_core/src/gplx/core/texts/RegxPatn_cls_like_tst.java b/100_core/src/gplx/core/texts/RegxPatn_cls_like_tst.java new file mode 100644 index 000000000..c381e8dbc --- /dev/null +++ b/100_core/src/gplx/core/texts/RegxPatn_cls_like_tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.texts; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.langs.regxs.*; +public class RegxPatn_cls_like_tst { + @Test public void Basic() { + tst_Match("abcd", "abcd", true); // basic; pass + tst_Match("abcd", "zbcd", false); // basic; fail + tst_Match("abcd", "abc", false); // no wildcard; must be exact match + tst_Match("a cd", "a cd", true); // check space works + } + @Test public void Wildcard() { + tst_Match("abcd", "a%", true); // bgn; pass + tst_Match("abcd", "b%", false); // bgn; fail + tst_Match("abcd", "%d", true); // end; pass + tst_Match("abcd", "%c", false); // end; fail + tst_Match("abcd", "%b%", true); // flank; pass + tst_Match("abcd", "%e%", false); // flank; fail + tst_Match("abcd", "%a%", true); // flank; bgn; pass + tst_Match("abcd", "%d%", true); // flank; end; pass + } + @Test public void Any() { + tst_Match("abcd", "a_cd", true); // basic; pass + tst_Match("abcd", "z_cd", false); // basic; fail + tst_Match("abcd", "a_c", false); // fail; check no wildcard + } + @Test public void CharSet() { + tst_Match("abcd", "a[b]cd", true); // pass + tst_Match("abcd", "a[x]cd", false); // fail + tst_Match("abcd", "a[bcde]cd", true); // multiple; pass + tst_Match("abcd", "a[xyz]cd", false); // multiple; fail + tst_Match("abcd", "a[^z]cd", true); // not; pass + tst_Match("abcd", "a[^b]cd", false); // not; fail + } + @Test public void Escape() { + tst_Match("a%b", "a|%b", true); // escape wildcard; pass + tst_Match("a%bc", "a|%b", false); // escape wildcard; fail + tst_Match("a|b", "a|b", false); // escape char; fail + tst_Match("a|b", "a||b", true); // escape char; pass + } + @Test public void Escape_diffChar() { + tst_Match("a%b", "a~%b", '~', true); // escape wildcard; pass + tst_Match("a%bc", "a~%b", '~', false); // escape wildcard; fail + tst_Match("a|b", "a|b", '~', true); // no escape needed + tst_Match("a~b", "a~b", '~', false); // escape char; fail + tst_Match("a~b", "a~~b", '~', true); // escape char; pass + } + @Test public void Chars() { // Escape Regx_bldr; ex: LIKE 'a{' -> a\{ + tst_EscapeRegxChar(Regx_bldr.Tkn_Escape); // \ + tst_EscapeRegxChar(Regx_bldr.Tkn_GroupBegin); // [ + tst_EscapeRegxChar(Regx_bldr.Tkn_GroupEnd); // ] + tst_EscapeRegxChar(Regx_bldr.Tkn_LineBegin); // ^ + tst_EscapeRegxChar(Regx_bldr.Tkn_LineEnd); // $ + tst_EscapeRegxChar(Regx_bldr.Tkn_RepBegin); // { + tst_EscapeRegxChar(Regx_bldr.Tkn_RepEnd); // } + tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_0or1); // ? + tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_0Plus); // * + tst_EscapeRegxChar(Regx_bldr.Tkn_Wild_1Plus); // + + } + void tst_Match(String raw, String regx, boolean expd) {tst_Match(raw, regx, RegxPatn_cls_like.EscapeDefault, expd);} + void tst_Match(String raw, String regx, char escape, boolean expd) { + RegxPatn_cls_like like = RegxPatn_cls_like_.parse(regx, escape); + boolean actl = like.Matches(raw); + Tfds.Eq(expd, actl, "raw={0} regx={1} expd={2}", raw, regx, expd); + } + void tst_EscapeRegxChar(char regexChar) { + RegxPatn_cls_like like = RegxPatn_cls_like_.parse(Object_.Xto_str_strict_or_empty(regexChar), '|'); + Tfds.Eq(true, like.Matches(Object_.Xto_str_strict_or_empty(regexChar))); + Tfds.Eq(false, like.Matches("a")); // catches errors for improper escaping of wildcard + } +} diff --git a/100_core/src/gplx/core/texts/StringTableBldr_tst.java b/100_core/src/gplx/core/texts/StringTableBldr_tst.java new file mode 100644 index 000000000..d01f972fe --- /dev/null +++ b/100_core/src/gplx/core/texts/StringTableBldr_tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.texts; import gplx.*; import gplx.core.*; +import org.junit.*; +public class StringTableBldr_tst { + @Before public void setup() { + bldr = StringTableBldr.new_(); + } StringTableBldr bldr; + @Test public void TwoCols() { + bldr.Add("a", "aa") + .Add("bb", "b"); + tst_XtoStr + ( "a aa" + , "bb b " + , "" + ); + } + @Test public void RightAlign() { + bldr.Add("a", "aa") + .Add("bb", "b"); + bldr.FetchAtOrNew(0).Halign_(StringTableColAlign.Right); + bldr.FetchAtOrNew(1).Halign_(StringTableColAlign.Right); + tst_XtoStr + ( " a aa" + , "bb b" + , "" + ); + } + @Test public void CenterAlign() { + bldr.Add("aaaa", "a") + .Add("b", "bbbb"); + bldr.FetchAtOrNew(0).Halign_(StringTableColAlign.Mid); + bldr.FetchAtOrNew(1).Halign_(StringTableColAlign.Mid); + tst_XtoStr + ( "aaaa a " + , " b bbbb" + , "" + ); + } + void tst_XtoStr(String... expdLines) { + String expd = String_.Concat_with_obj(String_.CrLf, (Object[])expdLines); + Tfds.Eq(expd, bldr.To_str()); + } +} diff --git a/100_core/src/gplx/core/threads/poolables/Gfo_poolable_mgr_tst.java b/100_core/src/gplx/core/threads/poolables/Gfo_poolable_mgr_tst.java new file mode 100644 index 000000000..040af5ccc --- /dev/null +++ b/100_core/src/gplx/core/threads/poolables/Gfo_poolable_mgr_tst.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.threads.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*; +import org.junit.*; +public class Gfo_poolable_mgr_tst { + private final Gfo_poolable_mgr_tstr tstr = new Gfo_poolable_mgr_tstr(); + @Before public void init() {tstr.Clear();} + @Test public void Get__one() { + tstr.Test__get(0); + tstr.Test__free__len(0); + tstr.Test__pool__len(2); + } + @Test public void Get__many__expand() { + tstr.Test__get(0); + tstr.Test__get(1); + tstr.Test__get(2); + tstr.Test__free__len(0); + tstr.Test__pool__len(4); + } + @Test public void Rls__lifo() { + tstr.Test__get(0); + tstr.Test__get(1); + tstr.Test__get(2); + tstr.Exec__rls(2); + tstr.Exec__rls(1); + tstr.Exec__rls(0); + tstr.Test__pool__nxt(0); + tstr.Test__free__len(0); + } + @Test public void Rls__fifo() { + tstr.Test__get(0); + tstr.Test__get(1); + tstr.Test__get(2); + tstr.Exec__rls(0); + tstr.Exec__rls(1); + tstr.Test__pool__nxt(3); + tstr.Test__free__len(2); // 2 items in free_ary + tstr.Test__free__ary(0, 1, 0, 0); + + tstr.Test__get(1); + tstr.Exec__rls(1); + + tstr.Exec__rls(2); + tstr.Test__free__len(0); // 0 items in free_ary + tstr.Test__free__ary(0, 0, 0, 0); + } +} +class Gfo_poolable_mgr_tstr { + private final Gfo_poolable_mgr mgr = new Gfo_poolable_mgr(new Sample_poolable_itm(null, -1, Object_.Ary_empty), Object_.Ary("make"), 2, 8); + public void Clear() {mgr.Clear_fast();} + public void Test__get(int expd_idx) { + Sample_poolable_itm actl_itm = (Sample_poolable_itm)mgr.Get_fast(); + Tfds.Eq(expd_idx, actl_itm.Pool__idx(), "pool_idx"); + } + public void Test__free__ary(int... expd) {Tfds.Eq_ary(expd, mgr.Free_ary(), "mgr.Free_ary()");} + public void Test__free__len(int expd) {Tfds.Eq(expd, mgr.Free_len(), "mgr.Free_len()");} + public void Test__pool__len(int expd) {Tfds.Eq(expd, mgr.Pool_len(), "mgr.Pool_len()");} + public void Test__pool__nxt(int expd) {Tfds.Eq(expd, mgr.Pool_nxt(), "mgr.Pool_nxt()");} + public void Exec__rls(int idx) {mgr.Rls_fast(idx);} +} +class Sample_poolable_itm implements Gfo_poolable_itm { + private Gfo_poolable_mgr pool_mgr; + public Sample_poolable_itm(Gfo_poolable_mgr pool_mgr, int pool_idx, Object[] make_args) {this.pool_mgr = pool_mgr; this.pool_idx = pool_idx; this.pool__make_args = make_args;} + public int Pool__idx() {return pool_idx;} private final int pool_idx; + public Object[] Pool__make_args() {return pool__make_args;} private final Object[] pool__make_args; + public void Pool__rls() {pool_mgr.Rls_safe(pool_idx);} + public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {return new Sample_poolable_itm(pool_mgr, idx, args);} +} diff --git a/100_core/src/gplx/core/times/DateAdp_parser_tst.java b/100_core/src/gplx/core/times/DateAdp_parser_tst.java new file mode 100644 index 000000000..dc5a6d10a --- /dev/null +++ b/100_core/src/gplx/core/times/DateAdp_parser_tst.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.times; import gplx.*; import gplx.core.*; +import org.junit.*; +public class DateAdp_parser_tst { + @Before public void init() {} DateAdp_parser_fxt fxt = new DateAdp_parser_fxt(); + @Test public void Parse_gplx() { + fxt.Test_Parse_iso8651_like("2000-01-02T03:04:05.006-05:00" , 2000, 1, 2, 3, 4, 5, 6); + fxt.Test_Parse_iso8651_like("2000-01-02" , 2000, 1, 2, 0, 0, 0, 0); + } +} +class DateAdp_parser_fxt { + DateAdp_parser parser = DateAdp_parser.new_(); int[] actl = new int[7]; + public void Test_Parse_iso8651_like(String s, int... expd) { + byte[] bry = Bry_.new_a7(s); + parser.Parse_iso8651_like(actl, bry, 0, bry.length); + Tfds.Eq_ary(expd, actl, s); + } +} diff --git a/100_core/src/gplx/core/times/Time_span__basic_tst.java b/100_core/src/gplx/core/times/Time_span__basic_tst.java new file mode 100644 index 000000000..e4e643064 --- /dev/null +++ b/100_core/src/gplx/core/times/Time_span__basic_tst.java @@ -0,0 +1,85 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.times; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Time_span__basic_tst { + @Test public void seconds_() { + Time_span expd = Time_span_.fracs_(123987); + Time_span actl = Time_span_.seconds_(123.987); + Tfds.Eq(expd, actl); + } + @Test public void TotalSecs() { + Time_span val = Time_span_.fracs_(1987); + Tfds.Eq_decimal(Decimal_adp_.parts_(1, 987), val.Total_secs()); + } + @Test public void Units() { + tst_Units("01:02:03.987", 1, 2, 3, 987); + tst_Units("01:00:03", 1, 0, 3, 0); + tst_Units("01:00:00.987", 1, 0, 0, 987); + tst_Units("02:00.987", 0, 2, 0, 987); + } + @Test public void Add() { + Time_span val = Time_span_.fracs_(3); + Time_span arg = Time_span_.fracs_(2); + Time_span expd = Time_span_.fracs_(5); + Time_span actl = val.Add(arg); + Tfds.Eq(expd, actl); + } + @Test public void Subtract() { + Time_span val = Time_span_.fracs_(3); + Time_span arg = Time_span_.fracs_(2); + Time_span expd = Time_span_.fracs_(1); + Time_span actl = val.Subtract(arg); + Tfds.Eq(expd, actl); + } + @Test public void Add_unit_identity() { + tst_AddUnit("00:00:01.000", 0, 0, "00:00:01.000"); + } + @Test public void Add_unit_basic() { + tst_AddUnit("01:59:58.987", 0, 1013, "02:00:00.000"); + tst_AddUnit("01:59:58.987", 1, 2, "02:00:00.987"); + tst_AddUnit("01:59:58.987", 2, 1, "02:00:58.987"); + tst_AddUnit("01:59:58.987", 3, 1, "02:59:58.987"); + } + @Test public void Add_unit_negative() { + tst_AddUnit("01:00:00.00", 0, -1, "00:59:59.999"); + tst_AddUnit("01:00:00.00", 1, -1, "00:59:59.000"); + tst_AddUnit("01:00:00.00", 2, -1, "00:59:00.000"); + tst_AddUnit("01:00:00.00", 3, -1, "00:00:00.000"); + } + @Test public void XtoStrUiAbbrv() { + tst_XtoStrUiAbbrv("01:02:03.004", "1h 2m 3s 4f"); + tst_XtoStrUiAbbrv("00:00:03.004", "3s 4f"); + tst_XtoStrUiAbbrv("00:00:03.000", "3s 0f"); + tst_XtoStrUiAbbrv("11:22:33.444", "11h 22m 33s 444f"); + tst_XtoStrUiAbbrv("00:00:00.000", "0f"); + } void tst_XtoStrUiAbbrv(String raw, String expd) {Tfds.Eq(expd, Time_span_.parse(raw).XtoStrUiAbbrv());} + void tst_AddUnit(String valRaw, int unitIdx, int delta, String expdRaw) { + Time_span val = Time_span_.parse(valRaw); + Time_span actl = val.Add_unit(unitIdx, delta); + Tfds.Eq(Time_span_.parse(expdRaw), actl); + } + void tst_Units(String text, int... expd) { + Time_span val = Time_span_.parse(text); + int hour = 0, min = 0, sec = 0, frac = 0; + int[] ary = val.Units(); + hour = ary[Time_span_.Idx_Hour]; min = ary[Time_span_.Idx_Min]; sec = ary[Time_span_.Idx_Sec]; frac = ary[Time_span_.Idx_Frac]; + Tfds.Eq(expd[0], hour); + Tfds.Eq(expd[1], min); + Tfds.Eq(expd[2], sec); + Tfds.Eq(expd[3], frac); + } +} diff --git a/100_core/src/gplx/core/times/Time_span__parse_tst.java b/100_core/src/gplx/core/times/Time_span__parse_tst.java new file mode 100644 index 000000000..8d997d849 --- /dev/null +++ b/100_core/src/gplx/core/times/Time_span__parse_tst.java @@ -0,0 +1,52 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.times; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Time_span__parse_tst { + @Test public void Zero() { + tst_Parse("0", 0); + } + @Test public void Milliseconds() { + tst_Parse("0.987", 987); + tst_Parse("0.00199", 1); // do not parse as 199 + tst_Parse("0.1", 100); // do not parse as 1 + } + @Test public void Seconds() { + tst_Parse("1.987", 1987); + } + @Test public void Minutes() { + tst_Parse("1:02.987", 62987); + } + @Test public void MinuteSecondOnly() { + tst_Parse("1:02", 62000); + } + @Test public void Hour() { + tst_Parse("1:02:03.987", 3723987); + } + @Test public void Negative() { + tst_Parse("-1:02:03.987", -3723987); + } + @Test public void Loopholes() { + tst_Parse("001:02", 62000); // multiple leading zeroes + tst_Parse("1.2.3.4", 1200); // ignore all decimals except first + tst_Parse("60:60.9999", 3660999); // value does not need to be bounded to limits (except fracs, which is always < 1000) + tst_Parse(" 01 : 02 : 03 . 987", 3723987); // whitespace + } + void tst_Parse(String text, long expd) { + Time_span val = Time_span_.parse(text); + Tfds.Eq(expd, val.Fracs()); + } +} diff --git a/100_core/src/gplx/core/times/Time_span__to_str_tst.java b/100_core/src/gplx/core/times/Time_span__to_str_tst.java new file mode 100644 index 000000000..dc265f2c4 --- /dev/null +++ b/100_core/src/gplx/core/times/Time_span__to_str_tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.times; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Time_span__to_str_tst { + @Test public void Zero() { + tst_Default(0, "0"); + } + @Test public void MinuteSeconds() { + tst_Default(77000, "1:17"); + } + @Test public void ZeroSuppression() { + tst_Default(660000, "11:00"); //fractional 0 and leading 0s are suppressed; i.e.: not 00:11:00.000 + } + @Test public void HourTest() { + tst_Default(3723987, "1:02:03.987"); + } + @Test public void NegSeconds() { + tst_Default(-2000, "-2"); + } + @Test public void NegMins() { + tst_Default(-60000, "-1:00"); + } + @Test public void NegHours() { + tst_Default(-3723981, "-1:02:03.981"); + } + @Test public void ZeroPadding() { + tst_ZeroPadding("0", "00:00:00.000"); + tst_ZeroPadding("1:02:03.123", "01:02:03.123"); + tst_ZeroPadding("1", "00:00:01.000"); + tst_ZeroPadding(".987", "00:00:00.987"); + tst_ZeroPadding("2:01.456", "00:02:01.456"); + } + void tst_Default(long fractionals, String expd) { + Time_span ts = Time_span_.fracs_(fractionals); + String actl = ts.To_str(Time_span_.Fmt_Default); + Tfds.Eq(expd, actl); + } + void tst_ZeroPadding(String val, String expd) { + Time_span timeSpan = Time_span_.parse(val); + String actl = timeSpan.To_str(Time_span_.Fmt_PadZeros); + Tfds.Eq(expd, actl); + } +} diff --git a/100_core/src/gplx/core/type_xtns/DateAdpClassXtn_tst.java b/100_core/src/gplx/core/type_xtns/DateAdpClassXtn_tst.java new file mode 100644 index 000000000..5760066ee --- /dev/null +++ b/100_core/src/gplx/core/type_xtns/DateAdpClassXtn_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.type_xtns; import gplx.*; import gplx.core.*; +import org.junit.*; +public class DateAdpClassXtn_tst { + @Test public void XtoDb() { + tst_XtoDb("20091115 220102.999", "2009-11-15 22:01:02.999"); + } + void tst_XtoDb(String val, String expdRaw) { + String actlRaw = (String)DateAdpClassXtn.Instance.XtoDb(DateAdp_.parse_gplx(val)); + Tfds.Eq(expdRaw, actlRaw); + } +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java new file mode 100644 index 000000000..e04413cec --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataRdr_csv_dat_tst.java @@ -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; +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java new file mode 100644 index 000000000..296f36eac --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_dat_tst.java @@ -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")); + } +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java new file mode 100644 index 000000000..164f3a6ee --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_hdr_tst.java @@ -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")); + } +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java new file mode 100644 index 000000000..28f1a7b79 --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataRdr_dsv_misc_tst.java @@ -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")); + } +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java new file mode 100644 index 000000000..1f70bcd79 --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataRdr_layout_tst.java @@ -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; +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java new file mode 100644 index 000000000..8ddf6cd77 --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataWtr_csv_tst.java @@ -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() {} +} diff --git a/100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java b/100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java new file mode 100644 index 000000000..a3472b0f4 --- /dev/null +++ b/100_core/src/gplx/langs/dsvs/DsvDataWtr_tbls_tst.java @@ -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_(); +} diff --git a/100_core/src/gplx/langs/gfs/Gfs_Date_tst.java b/100_core/src/gplx/langs/gfs/Gfs_Date_tst.java new file mode 100644 index 000000000..c6a6ea836 --- /dev/null +++ b/100_core/src/gplx/langs/gfs/Gfs_Date_tst.java @@ -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)); + } +} diff --git a/100_core/src/gplx/langs/regxs/Regx_adp__tst.java b/100_core/src/gplx/langs/regxs/Regx_adp__tst.java new file mode 100644 index 000000000..a9ebfd8fb --- /dev/null +++ b/100_core/src/gplx/langs/regxs/Regx_adp__tst.java @@ -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; + } +} diff --git a/100_core/src/gplx/langs/xmls/HierStrBldr_tst.java b/100_core/src/gplx/langs/xmls/HierStrBldr_tst.java new file mode 100644 index 000000000..5d5044034 --- /dev/null +++ b/100_core/src/gplx/langs/xmls/HierStrBldr_tst.java @@ -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));} +} diff --git a/100_core/src/gplx/langs/xmls/XmlDoc_tst.java b/100_core/src/gplx/langs/xmls/XmlDoc_tst.java new file mode 100644 index 000000000..0a6792344 --- /dev/null +++ b/100_core/src/gplx/langs/xmls/XmlDoc_tst.java @@ -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(""); + 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 + ( "" + , "" + , "" + , "" + , "" + , "" + ); + xdoc = XmlDoc_.parse(xml); + xnde = xdoc.Root().SubNdes().Get_at(0); + Tfds.Eq("a", xnde.Name()); + Tfds.Eq("", xnde.Xml_outer()); + } + @Test public void Text_inner() { + xml = String_.Concat + ( "" + , "" + , "test me" + , "" + , "" + ); + 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 + ( "" + , "" + ); + 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()); + } +} diff --git a/100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java b/100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java new file mode 100644 index 000000000..a2c9129b3 --- /dev/null +++ b/100_core/src/gplx/langs/xmls/XmlFileSplitter_tst.java @@ -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("", "", ""); + } + @Test public void Split() { + splitter.Opts().FileSizeMax_(30).XmlNames_(""); + tst_Split + ( "" + , "" + , "" + , "" + ); + tst_Split + ( "" + , "" + , "" + ); + } + 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); + } +} diff --git a/100_core/src/gplx/langs/xmls/Xpath__tst.java b/100_core/src/gplx/langs/xmls/Xpath__tst.java new file mode 100644 index 000000000..251f6470c --- /dev/null +++ b/100_core/src/gplx/langs/xmls/Xpath__tst.java @@ -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 + ( "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + ); + 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()); + } +} diff --git a/100_core/tst/gplx/GfoMsg_rdr_tst.java b/100_core/tst/gplx/GfoMsg_rdr_tst.java new file mode 100644 index 000000000..d183398a4 --- /dev/null +++ b/100_core/tst/gplx/GfoMsg_rdr_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +import org.junit.*; +public class GfoMsg_rdr_tst { + @Before public void setup() { + msg = msg_().Add("a", "1").Add("b", "2").Add("c", "3"); + ctx.Match("init", "init"); + } GfoMsg msg; GfsCtx ctx = GfsCtx.new_(); + @Test public void Key() { + tst_Msg(msg, "a", "1"); + tst_Msg(msg, "b", "2"); + tst_Msg(msg, "c", "3"); + tst_Msg(msg, "d", null); + } + @Test public void Pos() { + msg = msg_().Add("", "1").Add("", "2").Add("", "3"); + tst_Msg(msg, "", "1"); + tst_Msg(msg, "", "2"); + tst_Msg(msg, "", "3"); + tst_Msg(msg, "", null); + } + @Test public void OutOfOrder() { + tst_Msg(msg, "c", "3"); + tst_Msg(msg, "b", "2"); + tst_Msg(msg, "a", "1"); + } + @Test public void Key3_Pos1_Pos2() { + msg = msg_().Add("", "1").Add("", "2").Add("c", "3"); + tst_Msg(msg, "c", "3"); + tst_Msg(msg, "", "1"); + tst_Msg(msg, "", "2"); + } + @Test public void MultipleEmpty() { + msg = msg_().Add("", "1").Add("", "2").Add("", "3"); + tst_Msg(msg, "", "1"); + tst_Msg(msg, "", "2"); + tst_Msg(msg, "", "3"); + } + GfoMsg msg_() {return GfoMsg_.new_parse_("test");} + void tst_Msg(GfoMsg m, String k, String expd) {Tfds.Eq(expd, m.ReadStrOr(k, null));} +} diff --git a/100_core/tst/gplx/GfoTreeBldr_fxt.java b/100_core/tst/gplx/GfoTreeBldr_fxt.java new file mode 100644 index 000000000..c4398bd40 --- /dev/null +++ b/100_core/tst/gplx/GfoTreeBldr_fxt.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx; +public class GfoTreeBldr_fxt { + public List_adp Atrs() {return atrs;} List_adp atrs = List_adp_.New(); + public List_adp Subs() {return subs;} List_adp subs = List_adp_.New(); + public GfoTreeBldr_fxt atr_(Object key, Object val) { + atrs.Add(new Object[] {key, val}); + return this; + } + public GfoTreeBldr_fxt sub_(GfoTreeBldr_fxt... ary) { + for (GfoTreeBldr_fxt sub : ary) + subs.Add(sub); + return this; + } + public static GfoTreeBldr_fxt new_() {return new GfoTreeBldr_fxt();} GfoTreeBldr_fxt() {} +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_dir_basic_memory_tst.java b/100_core/tst/gplx/core/ios/IoEngine_dir_basic_memory_tst.java new file mode 100644 index 000000000..f29e81d02 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_dir_basic_memory_tst.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_dir_basic_memory_tst extends IoEngine_dir_basic_base { + @Override protected void setup_hook() { + root = Io_url_.mem_dir_("mem"); + } @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();} +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_dir_basic_system_tst.java b/100_core/tst/gplx/core/ios/IoEngine_dir_basic_system_tst.java new file mode 100644 index 000000000..7b4585908 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_dir_basic_system_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_dir_basic_system_tst extends IoEngine_dir_basic_base { + @Override protected void setup_hook() { + root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp"); + IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec(); + } @Override protected IoEngine engine_() {return IoEngine_system.new_();} + @Test @Override public void ScanDir() { + super.ScanDir(); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_dir_deep_memory_tst.java b/100_core/tst/gplx/core/ios/IoEngine_dir_deep_memory_tst.java new file mode 100644 index 000000000..42ada730e --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_dir_deep_memory_tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_dir_deep_memory_tst extends IoEngine_dir_deep_base { + @Override protected void setup_hook() { + root = Io_url_.mem_dir_("mem/root"); + } @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();} + @Test @Override public void SearchDir() { + super.SearchDir(); + } + @Test @Override public void MoveDirDeep() { + super.MoveDirDeep(); + } + @Test @Override public void CopyDir() { + super.CopyDir(); + } + @Test @Override public void DeleteDir() { + super.DeleteDir(); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_dir_deep_system_tst.java b/100_core/tst/gplx/core/ios/IoEngine_dir_deep_system_tst.java new file mode 100644 index 000000000..81d4809d3 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_dir_deep_system_tst.java @@ -0,0 +1,23 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_dir_deep_system_tst extends IoEngine_dir_deep_base { + @Override protected void setup_hook() { + root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp"); + IoEngine_xrg_deleteDir.new_(root).Recur_().ReadOnlyFails_off().Exec(); + } @Override protected IoEngine engine_() {return IoEngine_.Sys;} +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_fil_basic_memory_tst.java b/100_core/tst/gplx/core/ios/IoEngine_fil_basic_memory_tst.java new file mode 100644 index 000000000..654d6cc88 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_fil_basic_memory_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_fil_basic_memory_tst extends IoEngine_fil_basic_base { + @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();} + @Override protected void setup_hook() { + root = Io_url_.mem_dir_("mem"); + fil = root.GenSubFil_nest("root", "fil.txt"); + } + @Test @Override public void OpenStreamRead() { + super.OpenStreamRead (); + } + @Test @Override public void SaveFilText_overwrite() { + super.SaveFilText_overwrite(); + + // bugfix: verify changed file in ownerDir's hash + IoItmDir dirItm = fx.tst_ScanDir(fil.OwnerDir(), fil); + IoItmFil_mem filItm = (IoItmFil_mem)dirItm.SubFils().Get_at(0); + Tfds.Eq(filItm.Text(), "changed"); + } + @Test public void RecycleFil() { + fx.run_SaveFilText(fil, "text"); + fx.tst_ExistsPaths(true, fil); + + IoRecycleBin bin = IoRecycleBin.Instance; + List_adp list = Tfds.RscDir.XtoNames(); +// foreach (String s in list) +// Tfds.Write(s); + list.Del_at(0); // remove drive + IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil) + .RootDirNames_(list) + .AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.Parse("467ffb41-cdfe-402f-b22b-be855425784b")); + recycleXrg.Exec(); + fx.tst_ExistsPaths(false, fil); + fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl()); + + bin.Recover(recycleXrg.RecycleUrl()); + fx.tst_ExistsPaths(true, fil); + fx.tst_ExistsPaths(false, recycleXrg.RecycleUrl()); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_fil_basic_system_tst.java b/100_core/tst/gplx/core/ios/IoEngine_fil_basic_system_tst.java new file mode 100644 index 000000000..edd7593bb --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_fil_basic_system_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_fil_basic_system_tst extends IoEngine_fil_basic_base { + @Override protected void setup_hook() { + root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp"); + fil = root.GenSubFil("fil.txt"); + IoEngine_xrg_deleteDir.new_(fil.OwnerDir()).Recur_().ReadOnlyFails_off().Exec(); + } @Override protected IoEngine engine_() {return IoEngine_system.new_();} + @Test public void ExistsFil_IgnoreDifferentCasing() { + if (root.Info().CaseSensitive()) return; + fx.run_SaveFilText(fil, "text"); + fx.tst_ExistsPaths(true, fil); + fx.tst_ExistsPaths(true, fil.OwnerDir().GenSubFil("FIL.txt")); + } + @Test @gplx.Virtual public void RecycleFil() { + fx.run_SaveFilText(fil, "text"); + fx.tst_ExistsPaths(true, fil); + + IoRecycleBin bin = IoRecycleBin.Instance; + List_adp list = root.XtoNames(); list.Del_at(0); // remove drive + IoEngine_xrg_recycleFil recycleXrg = bin.Send_xrg(fil) + .RootDirNames_(list) + .AppName_("gplx.test").Time_(DateAdp_.parse_gplx("20100102_115559123")).Uuid_(Guid_adp_.Parse("467ffb41-cdfe-402f-b22b-be855425784b")); + recycleXrg.Exec(); + fx.tst_ExistsPaths(false, fil); + fx.tst_ExistsPaths(true, recycleXrg.RecycleUrl()); + + bin.Recover(recycleXrg.RecycleUrl()); + fx.tst_ExistsPaths(true, fil); + fx.tst_ExistsPaths(false, recycleXrg.RecycleUrl()); + } + @Test @Override public void DeleteFil_missing_pass() { + super.DeleteFil_missing_pass(); + } + @Test @Override public void DeleteFil_readOnly_pass() { + super.DeleteFil_readOnly_pass (); + } + @Test @Override public void SaveFilText_readOnlyFails() { + super.SaveFilText_readOnlyFails(); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_memory_tst.java b/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_memory_tst.java new file mode 100644 index 000000000..7be19bb76 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_memory_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_fil_xfer_memory_tst extends IoEngine_fil_xfer_base { + @Override protected void setup_hook() { + root = Io_url_.mem_dir_("mem"); + } @Override protected IoEngine engine_() {return IoEngine_.Mem_init_();} + @Override protected Io_url AltRoot() { + Io_mgr.Instance.InitEngine_mem_("mem2"); + return Io_url_.mem_dir_("mem2"); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_system_tst.java b/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_system_tst.java new file mode 100644 index 000000000..5c6a5955c --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_fil_xfer_system_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_fil_xfer_system_tst extends IoEngine_fil_xfer_base { + @Override protected void setup_hook() { + root = Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp"); + IoEngine_xrg_deleteDir.new_(root.OwnerDir()).Recur_().ReadOnlyFails_off().Exec(); + } @Override protected IoEngine engine_() {return IoEngine_system.new_();} + @Override protected Io_url AltRoot() { + return Tfds.RscDir.GenSubDir_nest("100_core", "ioEngineTest", "_temp"); + } +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_stream_xfer_tst.java b/100_core/tst/gplx/core/ios/IoEngine_stream_xfer_tst.java new file mode 100644 index 000000000..ebea34466 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_stream_xfer_tst.java @@ -0,0 +1,47 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_stream_xfer_tst { + @Before public void setup() { + srcEngine = IoEngine_memory.new_("mock1"); + trgEngine = IoEngine_memory.new_("mock2"); + IoEnginePool.Instance.Add_if_dupe_use_nth(srcEngine); IoEnginePool.Instance.Add_if_dupe_use_nth(trgEngine); + IoUrlInfoRegy.Instance.Reg(IoUrlInfo_.mem_("mem1/", srcEngine.Key())); + IoUrlInfoRegy.Instance.Reg(IoUrlInfo_.mem_("mem2/", trgEngine.Key())); + srcDir = Io_url_.mem_dir_("mem1/dir"); trgDir = Io_url_.mem_dir_("mem2/dir"); + } + @Test public void TransferBetween() { + Io_url srcPath = srcDir.GenSubFil("fil.txt"); + Io_url trgPath = trgDir.GenSubFil("fil.txt"); + tst_TransferStreams(srcEngine, srcPath, trgEngine, trgPath); + } + void tst_TransferStreams(IoEngine srcEngine, Io_url srcPath, IoEngine trgEngine, Io_url trgPath) { + srcEngine.SaveFilText_api(IoEngine_xrg_saveFilStr.new_(srcPath, "test1")); + trgEngine.DeleteFil_api(IoEngine_xrg_deleteFil.new_(trgPath)); // make sure file is deleted + fx.tst_ExistsPaths(true, srcPath); + fx.tst_ExistsPaths(false, trgPath); + + IoEngineUtl utl = IoEngineUtl.new_(); + utl.BufferLength_set(4); + utl.XferFil(srcEngine, IoEngine_xrg_xferFil.copy_(srcPath, trgPath)); + fx.tst_ExistsPaths(true, srcPath, trgPath); + fx.tst_LoadFilStr(trgPath, "test1"); + } + IoEngineFxt fx = IoEngineFxt.new_(); + Io_url srcDir, trgDir; + IoEngine srcEngine, trgEngine; +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_xrg_queryDir_tst.java b/100_core/tst/gplx/core/ios/IoEngine_xrg_queryDir_tst.java new file mode 100644 index 000000000..79bfce9fa --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_xrg_queryDir_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_xrg_queryDir_tst { + @Before public void setup() { + engine = IoEngine_.Mem_init_(); + } IoEngine engine; Io_url[] ary; + @Test public void Basic() { + ary = save_text_(fil_("fil1.txt")); + + tst_ExecPathAry(finder_(), ary); + } + @Test public void FilPath() { + ary = save_text_(fil_("fil1.txt"), fil_("fil2.jpg"), fil_("fil3.txt")); + + tst_ExecPathAry(finder_(), ary); // default: all files + tst_ExecPathAry(finder_().FilPath_("*.txt") // findPattern of *.txt + , fil_("fil1.txt"), fil_("fil3.txt")); + } + @Test public void Recur() { + ary = save_text_(fil_("fil1.txt"), fil_("dirA", "fil1A.jpg")); + + tst_ExecPathAry(finder_(), fil_("fil1.txt")); // default: no recursion + tst_ExecPathAry(finder_().Recur_(), ary); // recurse + } + @Test public void DirPattern() { + save_text_(fil_("fil1.txt"), fil_("dirA", "fil1A.jpg")); + + tst_ExecPathAry(finder_(), fil_("fil1.txt")); // default: files only + tst_ExecPathAry(finder_().DirInclude_() // include dirs; NOTE: fil1A not returned b/c Recur_ is not true + , dir_("dirA"), fil_("fil1.txt")); + } + @Test public void Sort_by() { + save_text_(fil_("fil2a.txt"), fil_("fil1.txt")); + + tst_ExecPathAry(finder_() // default: sortByAscOrder + , fil_("fil1.txt"), fil_("fil2a.txt")); + } + IoEngine_xrg_queryDir finder_() {return IoEngine_xrg_queryDir.new_(Io_url_.mem_dir_("mem/root"));}// NOTE: not in setup b/c finder must be newed several times inside test method + Io_url fil_(String... ary) {return Io_url_.mem_dir_("mem/root").GenSubFil_nest(ary);} + Io_url dir_(String... ary) {return Io_url_.mem_dir_("mem/root").GenSubDir_nest(ary);} + + Io_url[] save_text_(Io_url... ary) { + for (Io_url url : ary) + Io_mgr.Instance.SaveFilStr(url, url.Raw()); + return ary; + } + void tst_ExecPathAry(IoEngine_xrg_queryDir finder, Io_url... expd) {Tfds.Eq_ary(expd, finder.ExecAsUrlAry());} +} diff --git a/100_core/tst/gplx/core/ios/IoEngine_xrg_recycleFil_tst.java b/100_core/tst/gplx/core/ios/IoEngine_xrg_recycleFil_tst.java new file mode 100644 index 000000000..39d0b2779 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoEngine_xrg_recycleFil_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoEngine_xrg_recycleFil_tst { + @Before public void setup() { + IoEngine_.Mem_init_(); + } + @Test public void GenRecycleUrl() { + tst_GenRecycleUrl(recycle_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;;fil.txt")); + tst_GenRecycleUrl(recycle_().Uuid_include_(), Io_url_.mem_fil_("mem/z_trash/20100102/gplx.images;115559123;467ffb41-cdfe-402f-b22b-be855425784b;fil.txt")); + } + IoEngine_xrg_recycleFil recycle_() {return IoEngine_xrg_recycleFil.gplx_(Io_url_.mem_fil_("mem/dir/fil.txt")).AppName_("gplx.images").Uuid_(Guid_adp_.Parse("467ffb41-cdfe-402f-b22b-be855425784b")).Time_(DateAdp_.parse_gplx("20100102_115559123"));} + void tst_GenRecycleUrl(IoEngine_xrg_recycleFil xrg, Io_url expd) { + Tfds.Eq(expd, xrg.RecycleUrl()); + } +} diff --git a/100_core/tst/gplx/core/ios/IoItmDir_FetchDeepOrNull_tst.java b/100_core/tst/gplx/core/ios/IoItmDir_FetchDeepOrNull_tst.java new file mode 100644 index 000000000..a21798af1 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoItmDir_FetchDeepOrNull_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoItmDir_FetchDeepOrNull_tst { + @Before public void setup() { + drive = Io_url_.mem_dir_("mem"); + rootDir = bldr.dir_(drive, bldr.dir_(drive.GenSubDir("sub1"))); + } IoItm_fxt bldr = IoItm_fxt.new_(); Io_url drive; IoItmDir rootDir; + @Test public void FetchDeepOrNull() { + tst_FetchDeepOrNull(rootDir, drive.GenSubDir("sub1"), true); + tst_FetchDeepOrNull(rootDir, drive.GenSubDir("sub2"), false); + tst_FetchDeepOrNull(rootDir.SubDirs().Get_at(0), drive.GenSubDir("sub1"), true); + tst_FetchDeepOrNull(rootDir.SubDirs().Get_at(0), drive.GenSubDir("sub2"), false); + } + void tst_FetchDeepOrNull(Object rootDirObj, Io_url find, boolean expdFound) { + IoItmDir rootDir = IoItmDir_.as_(rootDirObj); + IoItmDir actlDir = rootDir.FetchDeepOrNull(find); + if (actlDir == null) { + if (expdFound) Tfds.Fail("actlDir is null, but expd dir to be found"); + else return; // actlDir is null but expdFound was false; return; + } + Tfds.Eq(find.Raw(), actlDir.Url().Raw()); + } +} diff --git a/100_core/tst/gplx/core/ios/IoUrlInfo_alias_tst.java b/100_core/tst/gplx/core/ios/IoUrlInfo_alias_tst.java new file mode 100644 index 000000000..e6c743874 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoUrlInfo_alias_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoUrlInfo_alias_tst { + IoUrlInfo_alias alias; + @Test public void MapWntToWnt() { + Make("usr:\\", "D:\\usr\\"); + tst_Xto_api("usr:\\dir\\fil.txt", "D:\\usr\\dir\\fil.txt"); + tst_OwnerDir("usr:\\dir\\", "usr:\\"); + tst_OwnerDir("usr:\\", ""); + tst_NameOnly("usr:\\", "usr"); + } + @Test public void MapToLnx() { + Make("usr:\\", "/home/"); + tst_Xto_api("usr:\\dir\\fil.txt", "/home/dir/fil.txt"); + } + @Test public void MapLnxToWnt() { + Make("usr:/", "C:\\usr\\"); + tst_Xto_api("usr:/dir/fil.txt", "C:\\usr\\dir\\fil.txt"); + } + @Test public void WntToWnt() { + Make("C:\\", "X:\\"); + tst_Xto_api("C:\\dir\\fil.txt", "X:\\dir\\fil.txt"); + tst_NameOnly("C:\\", "C"); + } + @Test public void WntToLnx() { + Make("C:\\", "/home/"); + tst_Xto_api("C:\\dir\\fil.txt", "/home/dir/fil.txt"); + } + @Test public void LnxToWnt() { + Make("/home/", "C:\\"); + tst_Xto_api("/home/dir/fil.txt", "C:\\dir\\fil.txt"); + tst_NameOnly("/home/", "home"); + tst_NameOnly("/", "root"); + } + void tst_Xto_api(String raw, String expd) {Tfds.Eq(expd, alias.Xto_api(raw));} + void tst_OwnerDir(String raw, String expd) {Tfds.Eq(expd, alias.OwnerDir(raw));} + void tst_NameOnly(String raw, String expd) {Tfds.Eq(expd, alias.NameOnly(raw));} + void Make(String srcDir, String trgDir) { + alias = IoUrlInfo_alias.new_(srcDir, trgDir, IoEngine_.SysKey); + } +} diff --git a/100_core/tst/gplx/core/ios/IoUrl_lnx_tst.java b/100_core/tst/gplx/core/ios/IoUrl_lnx_tst.java new file mode 100644 index 000000000..4bc122ca4 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoUrl_lnx_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoUrl_lnx_tst { + IoUrlFxt fx = IoUrlFxt.new_(); + @Test public void Raw() { + fx.tst_Xto_gplx(Io_url_.lnx_dir_("/home/"), "/home/"); + fx.tst_Xto_gplx(Io_url_.lnx_dir_("/home"), "/home/"); // add / + fx.tst_Xto_gplx(Io_url_.lnx_dir_("/"), "/"); + fx.tst_Xto_gplx(Io_url_.lnx_fil_("/home/fil.txt"), "/home/fil.txt"); + } + @Test public void Xto_api() { + fx.tst_Xto_api(Io_url_.lnx_fil_("/home/fil.txt"), "/home/fil.txt"); + fx.tst_Xto_api(Io_url_.lnx_dir_("/home/"), "/home"); // del / + fx.tst_Xto_api(Io_url_.lnx_dir_("/"), "/"); + } + @Test public void OwnerRoot() { + fx.tst_OwnerRoot(Io_url_.lnx_dir_("/home/fil.txt"), "/"); + fx.tst_OwnerRoot(Io_url_.lnx_dir_("/home"), "/"); + fx.tst_OwnerRoot(Io_url_.lnx_dir_("root"), "/"); + } + @Test public void XtoNames() { + fx.tst_XtoNames(Io_url_.lnx_dir_("/home/fil.txt"), fx.ary_("root", "home", "fil.txt")); + fx.tst_XtoNames(Io_url_.lnx_dir_("/home"), fx.ary_("root", "home")); + } + @Test public void IsDir() { + fx.tst_IsDir(Io_url_.lnx_dir_("/home"), true); + fx.tst_IsDir(Io_url_.lnx_fil_("/home/file.txt"), false); + } + @Test public void OwnerDir() { + fx.tst_OwnerDir(Io_url_.lnx_dir_("/home/lnxusr"), Io_url_.lnx_dir_("/home")); + fx.tst_OwnerDir(Io_url_.lnx_dir_("/fil.txt"), Io_url_.lnx_dir_("/")); + fx.tst_OwnerDir(Io_url_.lnx_dir_("/"), Io_url_.Empty); + } + @Test public void NameAndExt() { + fx.tst_NameAndExt(Io_url_.lnx_fil_("/fil.txt"), "fil.txt"); + fx.tst_NameAndExt(Io_url_.lnx_dir_("/dir"), "dir/"); + } +} diff --git a/100_core/tst/gplx/core/ios/IoUrl_map_tst.java b/100_core/tst/gplx/core/ios/IoUrl_map_tst.java new file mode 100644 index 000000000..fa8c2ce43 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoUrl_map_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoUrl_map_tst { + IoUrlFxt fx = IoUrlFxt.new_(); + @Test public void Xto_api() { + IoUrlInfo inf = IoUrlInfo_.alias_("tst:\\", "C:\\tst\\", IoEngine_.SysKey); + fx.tst_Xto_api(Io_url_.new_inf_("tst:\\dir\\fil.txt", inf), "C:\\tst\\dir\\fil.txt"); + fx.tst_Xto_api(Io_url_.new_inf_("tst:\\dir\\", inf), "C:\\tst\\dir"); // no trailing \ + } + @Test public void Xto_api_wce() { + IoUrlInfo inf = IoUrlInfo_.alias_("wce:\\", "\\SD Card\\", IoEngine_.SysKey); + fx.tst_Xto_api(Io_url_.new_inf_("wce:\\dir\\", inf), "\\SD Card\\dir"); + } +} diff --git a/100_core/tst/gplx/core/ios/IoUrl_wnt_tst.java b/100_core/tst/gplx/core/ios/IoUrl_wnt_tst.java new file mode 100644 index 000000000..2f051fc85 --- /dev/null +++ b/100_core/tst/gplx/core/ios/IoUrl_wnt_tst.java @@ -0,0 +1,96 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class IoUrl_wnt_tst { + IoUrlFxt fx = IoUrlFxt.new_(); + @Test public void Raw() { + fx.tst_Xto_gplx(Io_url_.wnt_fil_("C:\\dir\\fil.txt"), "C:\\dir\\fil.txt"); + fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir\\"); + fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir") , "C:\\dir\\"); // add \ + } + @Test public void Xto_api() { + fx.tst_Xto_api(Io_url_.wnt_fil_("C:\\fil.txt"), "C:\\fil.txt"); + fx.tst_Xto_api(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir"); // del \ + fx.tst_Xto_api(Io_url_.wnt_dir_("C:"), "C:"); + } + @Test public void OwnerRoot() { + fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\dir") , "C:\\"); + fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\fil.png") , "C:\\"); + fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:") , "C:\\"); + } + @Test public void IsDir() { + fx.tst_IsDir(Io_url_.wnt_dir_("C:\\dir\\"), true); + fx.tst_IsDir(Io_url_.wnt_fil_("C:\\dir"), false); + fx.tst_IsDir(Io_url_.wnt_fil_("C:\\fil.txt"), false); + } + @Test public void OwnerDir() { + fx.tst_OwnerDir(Io_url_.wnt_dir_("C:\\dir\\sub1"), Io_url_.wnt_dir_("C:\\dir")); + fx.tst_OwnerDir(Io_url_.wnt_fil_("C:\\fil.txt"), Io_url_.wnt_dir_("C:")); + fx.tst_OwnerDir(Io_url_.wnt_dir_("C:"), Io_url_.Empty); +// fx.tst_OwnerDir(Io_url_.wnt_fil_("press enter to select this folder"), Io_url_.Empty); + } + @Test public void NameAndExt() { + fx.tst_NameAndExt(Io_url_.wnt_fil_("C:\\fil.txt"), "fil.txt"); + fx.tst_NameAndExt(Io_url_.wnt_dir_("C:\\dir"), "dir\\"); + } + @Test public void NameOnly() { + fx.tst_NameOnly(Io_url_.wnt_fil_("C:\\fil.txt"), "fil"); + fx.tst_NameOnly(Io_url_.wnt_dir_("C:\\dir"), "dir"); + fx.tst_NameOnly(Io_url_.wnt_dir_("C:"), "C"); + } + @Test public void Ext() { + fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.txt"), ".txt"); // fil + fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.multiple.txt"), ".txt"); // multiple ext + fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil"), ""); // no ext + fx.tst_Ext(Io_url_.wnt_dir_("C:\\dir"), "\\"); // dir + } + @Test public void GenSubDir_nest() { + fx.tst_GenSubDir_nest(Io_url_.wnt_dir_("C:"), fx.ary_("dir1", "sub1"), Io_url_.wnt_dir_("C:\\dir1\\sub1")); + } + @Test public void GenNewExt() { + fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.png")); // basic + fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.tst.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.tst.png")); // last in multiple dotted + } + @Test public void GenRelUrl_orEmpty() { + fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\fil.txt") , Io_url_.wnt_dir_("C:\\root") , "fil.txt"); // fil + fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_dir_("C:\\root\\dir") , Io_url_.wnt_dir_("C:\\root") , "dir\\"); // dir + fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt") , Io_url_.wnt_dir_("C:\\root") , "dir\\fil.txt"); // fil: nested1 + fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt") , Io_url_.wnt_dir_("C:") , "root\\dir\\fil.txt"); // fil: nested2 + } + @Test public void GenParallel() { + fx.tst_GenParallel(Io_url_.wnt_fil_("C:\\root1\\fil.txt"), Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_fil_("D:\\root2\\fil.txt")); + fx.tst_GenParallel(Io_url_.wnt_dir_("C:\\root1\\dir") , Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_dir_("D:\\root2\\dir")); + } +} +class IoUrlFxt { + public void tst_Xto_api(Io_url url, String expd) {Tfds.Eq(expd, url.Xto_api());} + public void tst_OwnerRoot(Io_url url, String expd) {Tfds.Eq(expd, url.OwnerRoot().Raw());} + public void tst_XtoNames(Io_url url, String... expdAry) {Tfds.Eq_ary(expdAry, url.XtoNames().To_str_ary());} + public void tst_NameAndExt(Io_url url, String expd) {Tfds.Eq(expd, url.NameAndExt());} + public void tst_Xto_gplx(Io_url url, String expd) {Tfds.Eq(expd, url.Raw());} + public void tst_IsDir(Io_url url, boolean expd) {Tfds.Eq(expd, url.Type_dir());} + public void tst_OwnerDir(Io_url url, Io_url expd) {Tfds.Eq_url(expd, url.OwnerDir());} + public void tst_NameOnly(Io_url url, String expd) {Tfds.Eq(expd, url.NameOnly());} + public void tst_Ext(Io_url url, String expd) {Tfds.Eq(expd, url.Ext());} + public void tst_GenSubDir_nest(Io_url rootDir, String[] parts, Io_url expd) {Tfds.Eq(expd, rootDir.GenSubDir_nest(parts));} + public void tst_GenNewExt(Io_url url, String ext, Io_url expd) {Tfds.Eq_url(expd, url.GenNewExt(ext));} + public void tst_GenRelUrl_orEmpty(Io_url url, Io_url rootDir, String expd) {Tfds.Eq(expd, url.GenRelUrl_orEmpty(rootDir));} + public void tst_GenParallel(Io_url url, Io_url oldRoot, Io_url newRoot, Io_url expd) {Tfds.Eq_url(expd, url.GenParallel(oldRoot, newRoot));} + + public String[] ary_(String... ary) {return String_.Ary(ary);} + public static IoUrlFxt new_() {return new IoUrlFxt();} IoUrlFxt() {} +} diff --git a/100_core/tst/gplx/core/stores/GfoNdeRdr_read_tst.java b/100_core/tst/gplx/core/stores/GfoNdeRdr_read_tst.java new file mode 100644 index 000000000..94ea997e5 --- /dev/null +++ b/100_core/tst/gplx/core/stores/GfoNdeRdr_read_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.stores; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*; +public class GfoNdeRdr_read_tst { + @Test public void ReadInt() { + rdr = rdr_(IntClassXtn.Instance, "id", 1); + Tfds.Eq(rdr.ReadInt("id"), 1); + } + @Test public void ReadIntOr() { + rdr = rdr_(IntClassXtn.Instance, "id", 1); + Tfds.Eq(rdr.ReadIntOr("id", -1), 1); + } + @Test public void ReadIntElse_minus1() { + rdr = rdr_(IntClassXtn.Instance, "id", null); + Tfds.Eq(rdr.ReadIntOr("id", -1), -1); + } + @Test public void ReadInt_parse() { + rdr = rdr_(StringClassXtn.Instance, "id", "1"); + Tfds.Eq(rdr.ReadInt("id"), 1); + } + @Test public void ReadIntElse_parse() { + rdr = rdr_(StringClassXtn.Instance, "id", "2"); + Tfds.Eq(rdr.ReadIntOr("id", -1), 2); + } + GfoNdeRdr rdr_(ClassXtn type, String key, Object val) { // makes rdr with one row and one val + GfoFldList flds = GfoFldList_.new_().Add(key, type); + GfoNde row = GfoNde_.vals_(flds, new Object[] {val}); + boolean parse = type == StringClassXtn.Instance; // assumes type is either StringClassXtn or IntClassXtn + return GfoNdeRdr_.leaf_(row, parse); + } + GfoNdeRdr rdr; +} diff --git a/100_core/tst/gplx/core/stores/GfoNdeRdr_tst.java b/100_core/tst/gplx/core/stores/GfoNdeRdr_tst.java new file mode 100644 index 000000000..eeda8c6d3 --- /dev/null +++ b/100_core/tst/gplx/core/stores/GfoNdeRdr_tst.java @@ -0,0 +1,187 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.stores; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.gfo_ndes.*; +public class GfoNdeRdr_tst { + @Test public void Subs_leafs() { + root = + fx.root_ + ( fx.row_vals_(0) + , fx.row_vals_(1) + , fx.row_vals_(2) + ); + tst_NdeVals(root, 0, 1, 2); + } + @Test public void Subs_ndes() { + root = + fx.root_ + ( leaf_("", 0) + , leaf_("", 1) + , leaf_("", 2) + ); + tst_NdeVals(root, 0, 1, 2); + } + @Test public void Subs_mix() { + root = + fx.root_ + ( leaf_("", 0) + , fx.row_vals_(1) + , fx.row_vals_(2) + ); + tst_NdeVals(root, 0, 1, 2); + } + @Test public void Subs_rdr() { + root = + fx.root_ + ( fx.row_vals_(0) + ); + rootRdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr rdr = rootRdr.Subs(); + Tfds.Eq_true(rdr.MoveNextPeer()); + Tfds.Eq(0, rdr.ReadAt(0)); + Tfds.Eq_false(rdr.MoveNextPeer()); + } + @Test public void MoveNextPeer_implicit() { + root = + fx.root_ + ( fx.csv_dat_ + ( fx.row_vals_(0) + , fx.row_vals_(1) + , fx.row_vals_(2) + ) + ); + GfoNdeRdr rootRdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr subsRdr = rootRdr.Subs(); // pos=-1; bof + DataRdr subRdr = subsRdr.Subs(); // MoveNextPeer not needed; implicitly moves to pos=0 + tst_RdrVals(subRdr, Object_.Ary(0, 1, 2)); + } + @Test public void MoveNextPeer_explicit() { + root = + fx.root_ + ( fx.csv_dat_ + ( fx.row_vals_(0) + , fx.row_vals_(1) + , fx.row_vals_(2) + ) + ); + GfoNdeRdr rootRdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr subsRdr = rootRdr.Subs(); // pos=-1; bof + Tfds.Eq_true(subsRdr.MoveNextPeer()); // explicitly moves to pos=0 + DataRdr subRdr = subsRdr.Subs(); + tst_RdrVals(subRdr, Object_.Ary(0, 1, 2)); + } + @Test public void Xpath_basic() { + root = fx.root_ + ( leaf_("root", 0) + , leaf_("root", 1) + , leaf_("root", 2) + ); + tst_Xpath_all(root, "root", 0, 1, 2); + } + @Test public void Xpath_nested() { + root = fx.root_ + ( fx.tbl_("owner" + , leaf_("root", 0) + , leaf_("root", 1) + , leaf_("root", 2) + )); + tst_Xpath_all(root, "owner/root", 0, 1, 2); + } + @Test public void Xpath_null() { + root = fx.root_ + ( leaf_("match", 0) + ); + rootRdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr sub = rootRdr.Subs_byName("no_match"); + Tfds.Eq_false(sub.MoveNextPeer()); + } + @Test public void Xpath_moveFirst_basic() { + root = fx.root_ + ( leaf_("nde0", 0) + ); + tst_Xpath_first(root, "nde0", 0); + } + @Test public void Xpath_moveFirst_shallow() { + root = fx.root_ + ( leaf_("nde0", 0) + , leaf_("nde1", 1) + , leaf_("nde2", 2) + ); + tst_Xpath_first(root, "nde2", 2); + } + @Test public void Xpath_moveFirst_nested() { + root = fx.root_ + ( node_("nde0", Object_.Ary("0") + , leaf_("nde00", "00") + )); + tst_Xpath_first(root, "nde0", "0"); + tst_Xpath_first(root, "nde0/nde00", "00"); + } + @Test public void Xpath_moveFirst_nested_similarName() { + root = fx.root_ + ( node_("nde0", Object_.Ary("0") + , leaf_("nde00", "00") + ) + , node_("nde1", Object_.Ary("1") + , leaf_("nde00", "10") + )); + tst_Xpath_first(root, "nde1/nde00", "10"); + } + @Test public void Xpath_moveFirst_many() { + root = fx.root_ + ( leaf_("root", 0) + , leaf_("root", 1) + , leaf_("root", 2) + ); + tst_Xpath_first(root, "root", 0); // returns first + } + @Test public void Xpath_moveFirst_null() { + root = fx.root_ + ( leaf_("nde0", 0) + , leaf_("nde1", 1) + , leaf_("nde2", 2) + ); + rootRdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr rdr = rootRdr.Subs_byName("nde3"); + Tfds.Eq_false(rdr.MoveNextPeer()); + } + + GfoNde leaf_(String name, Object... vals) {return GfoNde_.nde_(name, vals, GfoNde_.Ary_empty);} + GfoNde node_(String name, Object[] vals, GfoNde... subs) {return GfoNde_.nde_(name, vals, subs);} + void tst_NdeVals(GfoNde nde, Object... exptVals) { + DataRdr rdr = GfoNdeRdr_.root_parseNot_(nde); + tst_RdrVals(rdr.Subs(), exptVals); + } + void tst_RdrVals(DataRdr rdr, Object[] exptVals) { + int count = 0; + while (rdr.MoveNextPeer()) { + Object actl = rdr.ReadAt(0); + Tfds.Eq(actl, exptVals[count++]); + } + Tfds.Eq(count, exptVals.length); + } + void tst_Xpath_first(GfoNde root, String xpath, Object expt) { + DataRdr rdr = GfoNdeRdr_.root_parseNot_(root); + DataRdr sel = rdr.Subs_byName_moveFirst(xpath); + Object actl = sel.ReadAt(0); + Tfds.Eq(actl, expt); + } + void tst_Xpath_all(GfoNde root, String xpath, Object... exptVals) { + DataRdr rdr = GfoNdeRdr_.root_parseNot_(root); + tst_RdrVals(rdr.Subs_byName(xpath), exptVals); + } + GfoNde root; DataRdr rootRdr; GfoNdeFxt fx = GfoNdeFxt.new_(); +} diff --git a/100_core/tst/gplx/core/stores/xmls/XmlDataRdr_tst.java b/100_core/tst/gplx/core/stores/xmls/XmlDataRdr_tst.java new file mode 100644 index 000000000..ce4822ff4 --- /dev/null +++ b/100_core/tst/gplx/core/stores/xmls/XmlDataRdr_tst.java @@ -0,0 +1,100 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.stores.xmls; import gplx.*; import gplx.core.*; import gplx.core.stores.*; +import org.junit.*; +public class XmlDataRdr_tst { + @Test public void Read() { + DataRdr rdr = fx.rdr_(""); + Tfds.Eq(rdr.NameOfNode(), "title"); + Tfds.Eq(rdr.ReadStr("name"), "first"); + Tfds.Eq(rdr.ReadInt("id"), 1); + Tfds.Eq(rdr.ReadBool("profiled"), false); + } + @Test public void None() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<find/>" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "no_nde", "no_atr"); + } + @Test public void One() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<find id=\"f0\" />" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "find", "id", "f0"); + } + @Test public void One_IgnoreOthers() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<find id=\"f0\" />" + , "<skip id=\"s0\" />" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "find", "id", "f0"); + } + @Test public void Many() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<find id=\"f0\" />" + , "<find id=\"f1\" />" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "find", "id", "f0", "f1"); + } + @Test public void Nested() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<sub1>" + , "<find id=\"f0\" />" + , "<find id=\"f1\" />" + , "</sub1>" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "sub1/find", "id", "f0", "f1"); + } + @Test public void Nested_IgnoreOthers() { + DataRdr rdr = fx.rdr_ + ( "<root>" + , "<sub1>" + , "<find id=\"f0\" />" + , "<skip id=\"s0\" />" + , "</sub1>" + , "<sub1>" + , "<find id=\"f1\" />" // NOTE: find across ndes + , "<skip id=\"s1\" />" + , "</sub1>" + , "</root>" + ); + fx.tst_Subs_ByName(rdr, "sub1/find", "id", "f0", "f1"); + } + XmlDataRdr_fxt fx = XmlDataRdr_fxt.new_(); +} +class XmlDataRdr_fxt { + public DataRdr rdr_(String... ary) {return XmlDataRdr_.text_(String_.Concat(ary));} + public void tst_Subs_ByName(DataRdr rdr, String xpath, String key, String... expdAry) { + DataRdr subRdr = rdr.Subs_byName(xpath); + List_adp list = List_adp_.New(); + while (subRdr.MoveNextPeer()) + list.Add(subRdr.Read(key)); + + String[] actlAry = list.To_str_ary(); + Tfds.Eq_ary(actlAry, expdAry); + } + public static XmlDataRdr_fxt new_() {return new XmlDataRdr_fxt();} XmlDataRdr_fxt() {} +} diff --git a/100_core/tst/gplx/core/stores/xmls/XmlDataWtr_tst.java b/100_core/tst/gplx/core/stores/xmls/XmlDataWtr_tst.java new file mode 100644 index 000000000..5627f345c --- /dev/null +++ b/100_core/tst/gplx/core/stores/xmls/XmlDataWtr_tst.java @@ -0,0 +1,93 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.stores.xmls; import gplx.*; import gplx.core.*; import gplx.core.stores.*; +import org.junit.*; +public class XmlDataWtr_tst { + @Before public void setup() { + wtr = XmlDataWtr.new_(); + } + @Test public void WriteNodeBgn() { + wtr.WriteNodeBgn("chapter"); + tst_XStr(wtr, "<chapter />", String_.CrLf); + } + @Test public void Attributes() { + wtr.WriteNodeBgn("chapter"); + wtr.WriteData("id", 1); + wtr.WriteData("name", "first"); + tst_XStr(wtr, "<chapter id=\"1\" name=\"first\" />", String_.CrLf); + } + @Test public void Subs() { + wtr.WriteNodeBgn("title"); + wtr.WriteNodeBgn("chapters"); + wtr.WriteNodeBgn("chapter"); + tst_XStr(wtr + , "<title>", String_.CrLf + , "<chapters>", String_.CrLf + , "<chapter />", String_.CrLf + , "</chapters>", String_.CrLf + , "", String_.CrLf + ); + } + @Test public void Subs_Iterate() { + wtr.WriteNodeBgn("titles"); + for (int title = 1; title <= 2; title++) { + wtr.WriteNodeBgn("title"); + wtr.WriteData("id", title); + wtr.WriteNodeBgn("chapters"); + wtr.WriteNodeEnd(); // chapters + wtr.WriteNodeEnd(); // title + } + wtr.WriteNodeEnd(); //titles + tst_XStr(wtr + , "", String_.CrLf + , "", String_.CrLf + , "<chapters />", String_.CrLf + , "", String_.CrLf + , "", String_.CrLf + , "<chapters />", String_.CrLf + , "", String_.CrLf + , "", String_.CrLf + ); + } + @Test public void Peers() { + wtr.WriteNodeBgn("title"); + wtr.WriteNodeBgn("chapters"); + wtr.WriteNodeEnd(); + wtr.WriteNodeBgn("audioStreams"); + tst_XStr(wtr + , "", String_.CrLf + , "<chapters />", String_.CrLf + , "<audioStreams />", String_.CrLf + , "", String_.CrLf + ); + } + @Test public void AtrsWithNesting() { + wtr.WriteNodeBgn("title"); + wtr.WriteData("id", 1); + wtr.WriteData("name", "first"); + wtr.WriteNodeBgn("chapters"); + tst_XStr(wtr + , "", String_.CrLf + , "<chapters />", String_.CrLf + , "", String_.CrLf + ); + } + void tst_XStr(XmlDataWtr wtr, String... parts) { + String expd = String_.Concat(parts); + Tfds.Eq(expd, wtr.To_str()); + } + XmlDataWtr wtr; +} diff --git a/110_gfml/tst/gplx/gfml/GfmlDataRdr_tst.java b/110_gfml/tst/gplx/gfml/GfmlDataRdr_tst.java new file mode 100644 index 000000000..e93912241 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/GfmlDataRdr_tst.java @@ -0,0 +1,118 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; import gplx.core.stores.*; +public class GfmlDataRdr_tst { + @Test public void Raw() { + raw = "root:{}"; + rdr = rdr_(raw); + + Tfds.Eq(rdr.NameOfNode(), "root"); + } + @Test public void Atrs() { + raw = "root:id=1 name=me isPresent=true dateOf='2006-12-08';"; + rdr = rdr_(raw); + + Tfds.Eq(rdr.ReadInt("id"), 1); + Tfds.Eq(rdr.ReadStr("name"), "me"); + Tfds.Eq(rdr.ReadBool("isPresent"), true); + Tfds.Eq_date(rdr.ReadDate("dateOf"), DateAdp_.parse_gplx("2006-12-08")); + } + @Test public void Subs() { + raw = String_.Concat_any( + "root:{", + " computers:id=1 {", + " item:name=cpu;", + " item:name=monitor;", + " }", + " person:id=2 {", + " item:name=hardDrive;", + " item:name=networkCard;", + " }", + "}"); + rdr = rdr_(raw); + + DataRdr computers = rdr.Subs(); + int idx = 0; + while (computers.MoveNextPeer()) { + int expd = idx == 0 ? 1 : 2; + Tfds.Eq(computers.ReadInt("id"), expd); + idx++; + } + Tfds.Eq(idx, 2); + + DataRdr items = computers.Subs(); + idx = 0; + while (items.MoveNextPeer()) { + String expdStr = idx == 0 ? "hardDrive" : "networkCard"; + Tfds.Eq(items.ReadStr("name"), expdStr); + idx++; + } + Tfds.Eq(idx, 2); + } + @Test public void SelectRdr() { + raw = String_.Concat_any( + "root:{", + " person:name=me {}", + " computer:brand=noname {}", + "}"); + rdr = rdr_(raw); + + DataRdr person = rdr.Subs_byName_moveFirst("person"); + Tfds.Eq(person.NameOfNode(), "person"); + Tfds.Eq(person.ReadStr("name"), "me"); + DataRdr computer = rdr.Subs_byName_moveFirst("computer"); + Tfds.Eq(computer.NameOfNode(), "computer"); + Tfds.Eq(computer.ReadStr("brand"), "noname"); + } +// @Test public void Subs_byKey() { +// raw = String_.Concat_any( +// "root:", +// " person=(name=me)", +// ";"); +// rdr = rdr_(raw); +// +// DataRdr person = rdr.Subs_byKey("person"); +// Tfds.Eq(person.NameOfNode, "person"); +// Tfds.Eq(person.ReadStr("name"), "me"); +// } +// @Test public void Type() { +// raw = String_.Concat_any( +// "root:{", +// " _type:{example{explicit_val; bool_val; int_val; string_val; long_val; date_val; float_val; decimal_val;}}", +// " example:val1;", +// "}"); +// +// rdr = rdr_(raw); +// DataRdr pointRdr = rdr.Subs(); rdr.MoveNextPeer(); +// +// Tfds.Eq(rdr.FieldCount, 8); +// Tfds.Eq(rdr.ReadStr("explicit_val"), "val1"); +// Tfds.Eq(rdr.ReadBool("bool_val"), false); +// Tfds.Eq(rdr.ReadInt("int_val"), 0); +// Tfds.Eq(rdr.ReadStr("string_val"), null); +// Tfds.Eq(rdr.ReadLongOrFail("long_val"), (long)0); +// Tfds.Eq(rdr.ReadDate("date_val"), DateAdp_.MinValue); +// Tfds.Eq(rdr.ReadFloat("float_val"), (float)0); +// Tfds.Eq(rdr.FieldAt(1), "bool_val"); +// Tfds.Eq(rdr.Read(1), null); +// } + DataRdr rdr_(String raw) { + DataRdr rootRdr = GfmlDataRdr.raw_root_(raw); + return rootRdr; + } + String raw; DataRdr rdr; +} diff --git a/110_gfml/tst/gplx/gfml/yfxts_GfmlParse_fxt.java b/110_gfml/tst/gplx/gfml/yfxts_GfmlParse_fxt.java new file mode 100644 index 000000000..a6a56e8b3 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/yfxts_GfmlParse_fxt.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +class GfmlParse_fxt { + public GfmlNde_mok nde_() {return GfmlNde_mok.new_();} + public GfmlTkn_mok tkn_grp_ary_(String... ary) {return GfmlTkn_mok.new_().Subs_(GfmlTkn_mok.Xto_bry(ary));} + public GfmlTkn_mok tkn_grp_(GfmlTkn_mok... ary) {return GfmlTkn_mok.new_().Subs_(ary);} + public GfmlTkn_mok tkn_itm_(String r) {return GfmlTkn_mok.new_().Raw_(r);} + public void ini_RootLxr_Add(GfmlLxr... ary) {rootLxr.SubLxr_Add(ary);} + public void tst_Doc(String raw, GfmlNde_mok... expdAry) { + GfmlDoc gdoc = bldr.XtoGfmlDoc(raw); + GfmlNde_mok expd = GfmlNde_mok.new_(); + for (GfmlNde_mok itm : expdAry) + expd.Subs_(itm); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gdoc.RootNde())); + tstr.tst_Equal("parse"); + } + public void tst_Tkn(String raw, GfmlTkn_mok... expdAry) { + GfmlDoc gdoc = bldr.XtoGfmlDoc(raw); + GfmlTkn_mok expd = GfmlTkn_mok.new_(); + for (GfmlTkn_mok itm : expdAry) + expd.Subs_(itm); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + GfmlTkn_mok.tst(tstr, expd, GfmlTkn_mok.gfmlNde_(gdoc.RootNde())); + tstr.tst_Equal("parse"); + } + public static GfmlParse_fxt new_() { + GfmlParse_fxt rv = new GfmlParse_fxt(); + rv.rootLxr = GfmlDocLxrs.Root_lxr(); + rv.bldr = GfmlBldr_.new_(); + rv.bldr.Doc().RootLxr_set(rv.rootLxr); + return rv; + } + public void tst_Err(String raw, UsrMsg_mok... expdErrs) { + bldr.ThrowErrors_set(false); + GfmlDoc actlDoc = bldr.XtoGfmlDoc(raw); + List_adp expd = List_adp_.New(), actl = actlDoc.UsrMsgs(); + expd.Add_many((Object[])expdErrs); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + int max = tstr.List_Max(expd, actl); + for (int i = 0; i < max; i++) { + UsrMsg_mok expdUm = (UsrMsg_mok)tstr.List_FetchAtOrNull(expd, i); + UsrMsg actlUm = (UsrMsg)tstr.List_FetchAtOrNull(actl, i); + UsrMsg_mok actlUmm = UsrMsg_mok.new_(actlUm); + tstr.Eq_str(expdUm.Main(), actlUmm.Main(), "main"); + for (int j = 0; j < expdUm.Args().Count(); j++) { + Keyval expdKv = (Keyval)expdUm.Args().Get_at(j); + Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv.Key()); + Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val(); + tstr.Eq_str(expdKv.Val(), actlVal, expdKv.Key()); + } + for (int j = 0; j < expdUm.Required().Count(); j++) { + String expdKv = (String)expdUm.Required().Get_at(j); + Keyval actlKv = (Keyval)actlUmm.Args().Get_by(expdKv); + Object actlVal = actlKv == null ? String_.Null_mark : actlKv.Val(); + Object actlValV = actlKv == null ? "<>" : actlKv.Val(); + tstr.Eq_str(actlValV, actlVal, expdKv); + } + } + tstr.tst_Equal("errs"); + } + GfmlBldr bldr; GfmlLxr rootLxr; +} diff --git a/110_gfml/tst/gplx/gfml/yfxts_GfmlTypeCompiler_fxt.java b/110_gfml/tst/gplx/gfml/yfxts_GfmlTypeCompiler_fxt.java new file mode 100644 index 000000000..6e5b4cfe9 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/yfxts_GfmlTypeCompiler_fxt.java @@ -0,0 +1,100 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +class GfmlTypeCompiler_fxt { + public GfmlTyp_mok typ_() {return GfmlTyp_mok.new_();} + public GfmlNde_mok nde_() {return GfmlNde_mok.new_();} + public GfmlFld_mok fld_() {return GfmlFld_mok.new_();} + public GfmlTypRegy Regy() {return typBldr.TypeRegy();} + public void ini_Typ(List_adp typs, GfmlTyp_mok typ) {typs.Add(typ);} + @gplx.Internal protected void run_InitPragma(GfmlTypRegy regy, GfmlPragma pragma) { + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + GfmlType[] typeAry = pragma.MakePragmaTypes(makr); + regy.Add_ary(typeAry); + } + public void tst_Type(GfmlTyp_mok expd, GfmlTyp_mok actl) { + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + tst(tstr, expd, actl); + tstr.tst_Equal("typ"); + } + public void tst_Compile(GfmlNde_mok nde, GfmlTyp_mok expd) { + GfmlNde gnde = run_Resolve(this.Regy(), "_type/type", nde); + Ordered_hash list = Ordered_hash_.New(); + GfmlType actlType = GfmlTypeCompiler.Compile(gnde, GfmlType_.Root, this.Regy(), list); + GfmlTyp_mok actl = GfmlTyp_mok.type_(actlType); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + tst(tstr, expd, actl); + tstr.tst_Equal("typ"); + } + public void tst_Parse(String raw, GfmlNde_mok... expdAry) { + GfmlDoc gdoc = GfmlDoc_.parse_any_eol_(raw); + GfmlNde_mok expd = GfmlNde_mok.new_(); + for (GfmlNde_mok itm : expdAry) + expd.Subs_(itm); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gdoc.RootNde())); + tstr.tst_Equal("parse"); + } + public static void tst(TfdsTstr_fxt tstr, GfmlTyp_mok expd, GfmlTyp_mok actl) { + if (expd.Name() != null) tstr.Eq_str(expd.Name(), actl.Name(), "name"); + if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key"); + int max = tstr.List_Max(expd.Subs(), actl.Subs()); + for (int i = 0; i < max; i++) { + GfmlFld_mok expdFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(expd.Subs(), i); + GfmlFld_mok actlFld = (GfmlFld_mok)tstr.List_FetchAtOrNull(actl.Subs(), i); + tstr.SubName_push(Int_.To_str(i) + " fld"); + tst(tstr, expdFld, actlFld); + tstr.SubName_pop(); + } + } + static void tst(TfdsTstr_fxt tstr, GfmlFld_mok expd, GfmlFld_mok actl) { + expd = NullObj(expd); actl = NullObj(actl); + if (expd.Name() != null) tstr.Eq_str(expd.Name(), actl.Name(), "name"); + if (expd.TypeKey() != null) tstr.Eq_str(expd.TypeKey(), actl.TypeKey(), "typekey"); + if (expd.DefaultTkn() != null) tstr.Eq_str(expd.DefaultTknRaw(), actl.DefaultTknRaw(), "default"); + } + static GfmlFld_mok NullObj(GfmlFld_mok v) {return (v == null) ? GfmlFld_mok.new_().ini_ndk_(String_.Null_mark, "") : v;} + public void tst_Resolve(GfmlTyp_mok typ, GfmlNde_mok nde, GfmlNde_mok expd) { + typBldr.TypeRegy().Add(typ.XtoGfmlType()); + tst_Resolve(nde, expd); + } + public GfmlNde run_Resolve(GfmlTypRegy regy, String typKey, GfmlNde_mok nde) { + GfmlNde gfmlNde = nde.XtoGfmlItm(regy); + typBldr.OverridePool(regy.FetchOrNull(typKey)); + tst_ResolveNde(gfmlNde, typKey); + return gfmlNde; + } + public void tst_Resolve(GfmlNde_mok nde, GfmlNde_mok expd) { + GfmlNde gfmlNde = nde.XtoGfmlItm(typBldr.TypeRegy()); + tst_ResolveNde(gfmlNde, GfmlType_.AnyKey); + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + GfmlTypeResolver_fxt.tst_Nde(tstr, expd, GfmlNde_mok.gfmlNde_(gfmlNde)); + tstr.tst_Equal("test"); + } + void tst_ResolveNde(GfmlNde nde, String ownerKey) { + typBldr.NdeBgn(nde, ownerKey); + for (int i = 0; i < nde.SubObjs_Count(); i++) { + GfmlItm itm = (GfmlItm)nde.SubObjs_GetAt(i); + if (itm.ObjType() == GfmlObj_.Type_nde) + tst_ResolveNde((GfmlNde)itm, nde.Type().Key()); + else + typBldr.AtrExec(nde, (GfmlAtr)itm); + } + typBldr.NdeEnd(); + } + GfmlTypeMgr typBldr = GfmlTypeMgr.new_(); + public static GfmlTypeCompiler_fxt new_() {return new GfmlTypeCompiler_fxt();} GfmlTypeCompiler_fxt() {} +} diff --git a/110_gfml/tst/gplx/gfml/ymoks_GfmlAtr_GfmlNde_mok.java b/110_gfml/tst/gplx/gfml/ymoks_GfmlAtr_GfmlNde_mok.java new file mode 100644 index 000000000..531da3f99 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/ymoks_GfmlAtr_GfmlNde_mok.java @@ -0,0 +1,180 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import gplx.core.strings.*; +interface GfmlItm_mok { + int ObjType(); +} +class GfmlAtr_mok implements GfmlItm_mok { + public int ObjType() {return GfmlObj_.Type_atr;} + public String Key() {return key;} public GfmlAtr_mok Key_(String v) {key = v; return this;} private String key; + public String Val() {return val;} public GfmlAtr_mok Val_(String v) {val = v; return this;} private String val; + public GfmlAtr XtoGfmlItm() { + GfmlAtr rv = GfmlAtr.new_(GfmlTkn_.raw_(key), GfmlTkn_.raw_(val), GfmlType_.String); + return rv; + } + public String XtoStrStub() { + String_bldr sb = String_bldr_.new_(); + sb.Add_kv("key=", key).Add_kv("val=", val); + return sb.To_str(); + } + public static final GfmlAtr_mok Null = new GfmlAtr_mok().Key_(String_.Null_mark).Val_(String_.Null_mark); + public static GfmlAtr_mok as_(Object obj) {return obj instanceof GfmlAtr_mok ? (GfmlAtr_mok)obj : null;} + public static GfmlAtr_mok new_(String key, String val) { + GfmlAtr_mok rv = new GfmlAtr_mok(); + rv.key = key; rv.val = val; + return rv; + } GfmlAtr_mok() {} +} +class GfmlNde_mok implements GfmlItm_mok { + public int ObjType() {return GfmlObj_.Type_nde;} + public String Key() {return key;} public GfmlNde_mok Key_(String v) {key = v; return this;} private String key; + public String Hnd() {return hnd;} public GfmlNde_mok Hnd_(String v) {hnd = v; return this;} private String hnd; + public String Typ() {return typ;} public GfmlNde_mok Typ_(String v) {typ = v; return this;} private String typ; + public int ChainId() {return chainId;} public GfmlNde_mok ChainId_(int v) {chainId = v; return this;} int chainId = -1; + public boolean KeyedSubObj() {return keyed;} + public GfmlNde_mok KeyedSubObj_() {return KeyedSubObj_(true);} + public GfmlNde_mok KeyedSubObj_(boolean v) {keyed = v; return this;} private boolean keyed; + public List_adp Subs() {return subs;} + public String XtoStrStub() { + String_bldr sb = String_bldr_.new_(); + sb.Add_kv("key=", key).Add_kv("hnd=", hnd).Add_kv("typ=", typ).Add_kv("subs=", Int_.To_str(subs.Count())); + return sb.To_str(); + } + public GfmlNde_mok Subs_(GfmlItm_mok... ary) { + for (GfmlItm_mok itm : ary) + subs.Add(itm); + return this; + } List_adp subs = List_adp_.New(); + + public GfmlNde_mok Atrk_(String k, String v) {subs.Add(GfmlAtr_mok.new_(k, v)); return this;} + public GfmlNde_mok Atru_(String v) {subs.Add(GfmlAtr_mok.new_(GfmlTkn_.NullVal, v)); return this;} + public GfmlNde_mok Atrs_(String... ary) { + for (String itm : ary) + subs.Add(GfmlAtr_mok.new_(GfmlTkn_.NullVal, itm)); + return this; + } + public GfmlNde XtoGfmlItm(GfmlTypRegy regy) {return XtoGfmlNde(regy, this);} + static GfmlNde XtoGfmlNde(GfmlTypRegy regy, GfmlNde_mok ownerMok) { + String tmpTypeKey = ownerMok.typ == null ? GfmlType_.AnyKey : ownerMok.typ; + String tmpHnd = ownerMok.hnd == null ? "" : ownerMok.hnd; + GfmlNde rv = GfmlNde.new_(GfmlTkn_.raw_(tmpHnd), regy.FetchOrNull(tmpTypeKey), ownerMok.key != null); + rv.ChainId_(ownerMok.chainId); + if (ownerMok.keyed) rv.KeyedSubObj_(ownerMok.keyed); + if (ownerMok.key != null) rv.KeyTkn_set(GfmlTkn_.val_(ownerMok.key)); + for (int i = 0; i < ownerMok.subs.Count(); i++) { + GfmlItm_mok itm = (GfmlItm_mok)ownerMok.subs.Get_at(i); + if (itm.ObjType() == GfmlObj_.Type_nde) { + GfmlNde_mok itmMok = (GfmlNde_mok)itm; + rv.SubObjs_Add(itmMok.XtoGfmlItm(regy)); + } + else { + GfmlAtr_mok atrMok = (GfmlAtr_mok)itm; + rv.SubObjs_Add(atrMok.XtoGfmlItm()); + } + } + return rv; + } + public static GfmlNde_mok as_(Object obj) {return obj instanceof GfmlNde_mok ? (GfmlNde_mok)obj : null;} + public static final GfmlNde_mok Null = new GfmlNde_mok().Hnd_(String_.Null_mark).Typ_(String_.Null_mark); + public static final GfmlNde_mok ErrAtr = new GfmlNde_mok().Hnd_("<>").Typ_("<>"); + public static GfmlNde_mok new_() {return new GfmlNde_mok();} GfmlNde_mok() {} + public static GfmlNde_mok gfmlNde_(GfmlNde nde) {return InitNde(nde);} + static GfmlNde_mok InitNde(GfmlNde nde) { + GfmlNde_mok rv = new GfmlNde_mok(); + rv.typ = nde.Type().Key(); + rv.hnd = nde.Hnd(); + rv.keyed = nde.KeyedSubObj(); + rv.chainId = nde.ChainId(); + if (nde.Key() != null) rv.key = nde.Key(); + for (int i = 0; i < nde.SubKeys().Count(); i++) { + GfmlItm subItm = (GfmlItm)nde.SubKeys().Get_at(i); + if (subItm.ObjType() == GfmlObj_.Type_atr) { + GfmlAtr subAtr = (GfmlAtr)subItm; + GfmlAtr_mok mokAtr = GfmlAtr_mok.new_(subAtr.Key(), subAtr.DatTkn().Val()); + if (!String_.Len_eq_0(subAtr.Key())) mokAtr.Key_(subAtr.Key()); + rv.subs.Add(mokAtr); + } + else { + GfmlNde subNde = (GfmlNde)subItm; + GfmlNde_mok mokNde = InitNde(subNde); + rv.subs.Add(mokNde); + } + } + for (int i = 0; i < nde.SubHnds().Count(); i++) { + GfmlNde subNde = (GfmlNde)nde.SubHnds().Get_at(i); + GfmlNde_mok mokNde = InitNde(subNde); + rv.subs.Add(mokNde); + } + return rv; + } +} +class GfmlTypeResolver_fxt { + public GfmlType ini_MakeType(GfmlTyp_mok mok) { + type = mok.XtoGfmlType(); + regy.Add(type); + return type; + } + GfmlType type; + public static void tst_Nde(TfdsTstr_fxt tstr, GfmlNde_mok expd, GfmlNde_mok actl) { + expd = NullObj(expd); actl = NullObj(actl); + if (expd.Typ() != null) tstr.Eq_str(expd.Typ(), actl.Typ(), "typ"); + if (expd.KeyedSubObj()) tstr.Eq_str(expd.KeyedSubObj(), actl.KeyedSubObj(), "keyed"); + if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key"); + if (expd.Hnd() != null) tstr.Eq_str(expd.Hnd(), actl.Hnd(), "hnd"); + if (expd.ChainId() != -1) tstr.Eq_str(expd.ChainId(), actl.ChainId(), "chainId"); + int max = tstr.List_Max(expd.Subs(), actl.Subs()); + for (int i = 0; i < max; i++) { + GfmlItm_mok expdSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(expd.Subs(), i); + GfmlItm_mok actlSub = (GfmlItm_mok)tstr.List_FetchAtOrNull(actl.Subs(), i); + tstr.SubName_push(Int_.To_str(i)); + if (expdSub == null) { + GfmlNde_mok mm = GfmlNde_mok.as_(actlSub); + String actlSubStr = mm == null ? "sub:null" : mm.XtoStrStub(); + tstr.Eq_str("nde:" + "sub:null", actlSubStr, "expdSub null"); + tstr.Fail(); + break; + } + else if (expdSub.ObjType() == GfmlObj_.Type_atr) { + GfmlAtr_mok actlAtrMok = GfmlAtr_mok.as_(actlSub); + tst_Nde(tstr, (GfmlAtr_mok)expdSub, actlAtrMok); + } + else { + GfmlNde_mok actlMok = GfmlNde_mok.as_(actlSub); + if (actlMok == null) { + String actlSubStr = actlSub == null ? "sub:null" : "atr:" + ((GfmlAtr_mok)actlSub).XtoStrStub(); + tstr.Eq_str("nde:" + ((GfmlNde_mok)expdSub).XtoStrStub(), actlSubStr, "actlSub null"); + tstr.Fail(); + break; + } + tst_Nde(tstr, (GfmlNde_mok)expdSub, actlMok); + } + tstr.SubName_pop(); + } + } + static GfmlNde_mok NullObj(GfmlNde_mok v) {return v == null ? GfmlNde_mok.Null : v;} + static GfmlAtr_mok NullObj(GfmlAtr_mok v) {return v == null ? GfmlAtr_mok.Null : v;} + static void tst_Nde(TfdsTstr_fxt tstr, GfmlAtr_mok expd, GfmlAtr_mok actl) { + expd = NullObj(expd); actl = NullObj(actl); + if (expd.Key() != null) tstr.Eq_str(expd.Key(), actl.Key(), "key"); + if (expd.Val() != null) tstr.Eq_str(expd.Val(), actl.Val(), "val"); + } + GfmlTypRegy regy = GfmlTypRegy.new_(); + public static GfmlTypeResolver_fxt new_() { + GfmlTypeResolver_fxt rv = new GfmlTypeResolver_fxt(); + return rv; + } GfmlTypeResolver_fxt() {} +} diff --git a/110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java b/110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java new file mode 100644 index 000000000..b7634c05c --- /dev/null +++ b/110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java @@ -0,0 +1,75 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +class GfmlTkn_mok { + public String Raw() {return raw;} public GfmlTkn_mok Raw_(String v) {raw = v; return this;} private String raw; + public List_adp Subs() {return list;} List_adp list = List_adp_.New(); + public GfmlTkn_mok Subs_(GfmlTkn_mok... ary) { + for (GfmlTkn_mok itm : ary) + list.Add(itm); + return this; + } + // statics + public static GfmlTkn_mok new_() {return new GfmlTkn_mok();} GfmlTkn_mok() {} + public static GfmlTkn_mok gfmlNde_(GfmlNde nde) { + GfmlTkn_mok rv = new GfmlTkn_mok(); + InitItm(rv, nde); + return rv; + } + static void InitItm(GfmlTkn_mok rv, GfmlItm owner) { + for (int i = 0; i < owner.SubObjs_Count(); i++) { + GfmlObj subTkn = (GfmlObj)owner.SubObjs_GetAt(i); + GfmlTkn_mok subMok = GfmlTkn_mok.new_(); + rv.Subs_(subMok); + GfmlItm subItm = GfmlItm_.as_(subTkn); + if (subItm != null) + InitItm(subMok, subItm); + else + InitTkn(subMok, (GfmlTkn)subTkn); + } + } + static void InitTkn(GfmlTkn_mok mok, GfmlTkn tkn) { + if (tkn.SubTkns().length == 0) // leafTkn; no subs; simply set + mok.Raw_(tkn.Raw()); + else { // compTkn; createTkn and iterate + for (int i = 0; i < tkn.SubTkns().length; i++) { + GfmlTkn subTkn = (GfmlTkn)tkn.SubTkns()[i]; + GfmlTkn_mok subMok = GfmlTkn_mok.new_(); + InitTkn(subMok, subTkn); + mok.Subs_(subMok); + } + } + } + public static GfmlTkn_mok[] Xto_bry(String... ary) { + GfmlTkn_mok[] rv = new GfmlTkn_mok[ary.length]; + for (int i = 0; i < rv.length; i++) + rv[i] = GfmlTkn_mok.new_().Raw_(ary[i]); + return rv; + } + public static void tst(TfdsTstr_fxt tstr, GfmlTkn_mok expd, GfmlTkn_mok actl) { + expd = NullObj(expd); actl = NullObj(actl); + if (expd.Raw() != null) tstr.Eq_str(expd.Raw(), actl.Raw(), "raw"); + int max = tstr.List_Max(expd.Subs(), actl.Subs()); + for (int i = 0; i < max; i++) { + GfmlTkn_mok expdSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(expd.Subs(), i); + GfmlTkn_mok actlSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(actl.Subs(), i); + tstr.SubName_push(Int_.To_str(i)); + tst(tstr, expdSub, actlSub); + tstr.SubName_pop(); + } + } + static GfmlTkn_mok NullObj(GfmlTkn_mok v) {return v == null ? GfmlTkn_mok.new_().Raw_(String_.Null_mark) : v;} +} diff --git a/110_gfml/tst/gplx/gfml/ymoks_GfmlTyp_GfmlFld_mok.java b/110_gfml/tst/gplx/gfml/ymoks_GfmlTyp_GfmlFld_mok.java new file mode 100644 index 000000000..58fb6521c --- /dev/null +++ b/110_gfml/tst/gplx/gfml/ymoks_GfmlTyp_GfmlFld_mok.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +class GfmlFld_mok { + public String Name() {return name;} public GfmlFld_mok Name_(String v) {name = v; return this;} private String name; + public String TypeKey() {return typeKey;} public GfmlFld_mok TypeKey_(String v) {typeKey = v; return this;} private String typeKey; + public GfmlObj DefaultTkn() {return defaultTkn;} + public GfmlFld_mok DefaultTkn_(GfmlObj v) {defaultTkn = v; return this;} GfmlObj defaultTkn = GfmlTkn_.Null; + public GfmlFld_mok Default_(String v) {defaultTkn = GfmlTkn_.raw_(v); return this;} + public String DefaultTknRaw() {return GfmlFld_mok.XtoRaw(defaultTkn);} + public boolean KeyedSubObj() {return keyed;} private boolean keyed = false; + public GfmlFld XtoGfmlFld() { + GfmlFld rv = GfmlFld.new_(keyed, name, typeKey); + rv.DefaultTkn_(defaultTkn); + return rv; + } + public GfmlFld_mok ini_atr_(String name) {this.name = name; this.keyed = true; return this;} + public GfmlFld_mok ini_ndk_(String name, String typKey) {this.name = name; this.typeKey = typKey; this.keyed = true; return this;} + public static GfmlFld_mok new_() {return new GfmlFld_mok();} GfmlFld_mok() {} + public static String XtoRaw(GfmlObj gobj) { + if (gobj == null) return String_.Null_mark; + GfmlTkn tkn = GfmlTkn_.as_(gobj); + if (tkn != null) return tkn.Raw(); + GfmlNde nde = GfmlNde.as_(gobj); + return nde.To_str(); + } +} +class GfmlTyp_mok { + public String Name() {return name;} public GfmlTyp_mok Name_(String v) {name = v; return this;} private String name; + public String Key() {return key;} public GfmlTyp_mok Key_(String v) {key = v; return this;} private String key; + public List_adp Subs() {return subFlds;} List_adp subFlds = List_adp_.New(); + public GfmlTyp_mok Atrs_(String... ary) { + for (String itm : ary) + subFlds.Add(GfmlFld_mok.new_().ini_atr_(itm)); + return this; + } + public GfmlTyp_mok Subs_(GfmlFld_mok... ary) { + for (GfmlFld_mok itm : ary) + subFlds.Add(itm); + return this; + } + public GfmlType XtoGfmlType() { + GfmlType rv = GfmlType_.new_(key, name); // all types in tests are top-level + for (int i = 0; i < subFlds.Count(); i++) { + GfmlFld_mok fld = (GfmlFld_mok)subFlds.Get_at(i); + rv.SubFlds().Add(fld.XtoGfmlFld()); + } + return rv; + } + public static GfmlTyp_mok new_() {return new GfmlTyp_mok();} GfmlTyp_mok() {} + public static GfmlTyp_mok simple_(String name, String... flds) { + GfmlTyp_mok rv = new GfmlTyp_mok(); + rv.key = name; rv.name = name; + for (String fld : flds) + rv.subFlds.Add(GfmlFld_mok.new_().ini_atr_(fld)); + return rv; + } + public static GfmlTyp_mok type_(GfmlType typ) { + GfmlTyp_mok rv = new GfmlTyp_mok(); + rv.key = typ.Key(); rv.name = typ.NdeName(); + for (int i = 0; i < typ.SubFlds().Count(); i++) { + GfmlFld fld = (GfmlFld)typ.SubFlds().Get_at(i); + GfmlFld_mok mkFld = GfmlFld_mok.new_().ini_ndk_(fld.Name(), fld.TypeKey()).DefaultTkn_(fld.DefaultTkn()); + rv.subFlds.Add(mkFld); + } + return rv; + } +} diff --git a/110_gfml/tst/gplx/gfml/ymoks_UsrMsg_mok.java b/110_gfml/tst/gplx/gfml/ymoks_UsrMsg_mok.java new file mode 100644 index 000000000..c6a42335b --- /dev/null +++ b/110_gfml/tst/gplx/gfml/ymoks_UsrMsg_mok.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +class UsrMsg_mok { + public String Main() {return main;} public UsrMsg_mok Main_(String v) {main = v; return this;} private String main; + public UsrMsg_mok Add_(String k, Object o) {hash.Add(k, Keyval_.new_(k, o)); return this;} + public UsrMsg_mok Require_(String k) {required.Add(k, k); return this;} + public Ordered_hash Args() {return hash;} Ordered_hash hash = Ordered_hash_.New(); + public Ordered_hash Required() {return required;} Ordered_hash required = Ordered_hash_.New(); + public static UsrMsg_mok new_(UsrMsg um) { + UsrMsg_mok rv = new UsrMsg_mok(); + if (um != null) { + rv.main = um.Hdr(); + for (int i = 0; i < um.Args().Count(); i++) { + Keyval kv = (Keyval)um.Args().Get_at(i); + rv.Add_(kv.Key(), kv.Val()); + } + } + return rv; + } UsrMsg_mok() {} +} diff --git a/110_gfml/tst/gplx/gfml/z011_IntObjHash_tst.java b/110_gfml/tst/gplx/gfml/z011_IntObjHash_tst.java new file mode 100644 index 000000000..4b4efc799 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z011_IntObjHash_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z011_IntObjHash_tst { + @Before public void setup() { + hash = new IntObjHash_base(); + } IntObjHash_base hash; + @Test public void Empty() { + tst_Count(0); + tst_Fetch(1, null); + } + @Test public void Add() { + hash.Add(1, "1"); + tst_Count(1); + tst_Fetch(1, "1"); + tst_Fetch(2, null); + } + @Test public void Del() { + hash.Add(1, "1"); + + hash.Del(1); + tst_Count(0); + tst_Fetch(1, null); + } + @Test public void Clear() { + hash.Add(1, "1"); + hash.Add(32, "32"); + tst_Fetch(1, "1"); + tst_Fetch(32, "32"); + tst_Count(2); + + hash.Clear(); + tst_Count(0); + tst_Fetch(2, null); + tst_Fetch(32, null); + } + @Test public void Add_bug() { // fails after expanding ary, and fetching at key=n*16 + hash.Add(1, "1"); + tst_Count(1); + tst_Fetch(1, "1"); + tst_Fetch(15, null); // works + tst_Fetch(17, null); // works + tst_Fetch(16, null); // used to fail + } + void tst_Fetch(int key, Object expd) {Tfds.Eq(expd, hash.Get_by(key));} + void tst_Count(int expd) {Tfds.Eq(expd, hash.Count());} +} diff --git a/110_gfml/tst/gplx/gfml/z012_GfmlTrie_tst.java b/110_gfml/tst/gplx/gfml/z012_GfmlTrie_tst.java new file mode 100644 index 000000000..2fb1bb426 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z012_GfmlTrie_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +import gplx.core.texts.*; /*CharStream*/ +public class z012_GfmlTrie_tst { + @Before public void setup() { + trie = GfmlTrie.new_(); + } GfmlTrie trie; + @Test public void Null() { + tst_FindMatch_first("", null); + tst_FindMatch_first("{", null); + } + @Test public void OneChar() { + trie.Add("{", "val0"); + tst_FindMatch_first("{", "val0"); + tst_FindMatch_first(":", null); + } + @Test public void TwoChar() { + trie.Add("/*", "val0"); + tst_FindMatch_first("/*", "val0"); + tst_FindMatch_first("//", null); + } + @Test public void ManySym() { + trie.Add(":", "val0"); + trie.Add("{", "val1"); + tst_FindMatch_first(":", "val0"); + tst_FindMatch_first("{", "val1"); + tst_FindMatch_first("-", null); + } + @Test public void Overlap_1_2() { + trie.Add("[", "val0"); + trie.Add("[:", "val1"); + tst_FindMatch_first("[", "val0"); + tst_FindMatch_first("[:", "val1"); + tst_FindMatch_first("[-", "val0"); + tst_FindMatch_first(":", null); + } + @Test public void Overlap_2_1() { + trie.Add("[:", "val0"); + trie.Add("[", "val1"); + tst_FindMatch_first("[:", "val0"); + tst_FindMatch_first("[", "val1"); + tst_FindMatch_first("[-", "val1"); + tst_FindMatch_first(":", null); + } + @Test public void Overlap_1_1() { + trie.Add("[", "val0"); + trie.Add("[", "val1"); + tst_FindMatch_first("[", "val1"); // return last added + tst_FindMatch_first(":", null); + } + void tst_FindMatch_first(String text, String expd) { + CharStream stream = CharStream.pos0_(text); + String actl = (String)trie.FindMatch(stream); + Tfds.Eq(expd, actl); + } +} diff --git a/110_gfml/tst/gplx/gfml/z015_GfmlDocPos_tst.java b/110_gfml/tst/gplx/gfml/z015_GfmlDocPos_tst.java new file mode 100644 index 000000000..6ba899921 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z015_GfmlDocPos_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z015_GfmlDocPos_tst { + GfmlDocPos root = GfmlDocPos_.Root; + @Test public void Root() { + tst_Path(root, "0"); + } + @Test public void MoveDown() { + tst_Path(root.NewDown(0), "0_0"); + tst_Path(root.NewDown(0).NewDown(0), "0_0_0"); + tst_Path(root.NewDown(1).NewDown(2), "0_1_2"); + } + @Test public void MoveUp() { + tst_Path(root.NewDown(1).NewDown(2).NewUp(), "0_1"); + } + @Test public void CompareTo_same() { + GfmlDocPos lhs = root.NewDown(0); + GfmlDocPos rhs = root.NewDown(0); + tst_CompareTo(lhs, rhs, CompareAble_.Same); + } + @Test public void CompareTo_diffIndex() { + GfmlDocPos lhs = root.NewDown(0); + GfmlDocPos rhs = root.NewDown(1); + tst_CompareTo(lhs, rhs, CompareAble_.Less); + tst_CompareTo(rhs, lhs, CompareAble_.More); + } + @Test public void CompareTo_diffLevel() { + GfmlDocPos lhs = root; + GfmlDocPos rhs = root.NewDown(0); + tst_CompareTo(lhs, rhs, CompareAble_.Less); + tst_CompareTo(rhs, lhs, CompareAble_.More); + } + void tst_Path(GfmlDocPos pos, String expdPath) {Tfds.Eq(expdPath, pos.Path());} + void tst_CompareTo(GfmlDocPos lhs, GfmlDocPos rhs, int expd) {Tfds.Eq(expd, lhs.compareTo(rhs));} +} diff --git a/110_gfml/tst/gplx/gfml/z016_GfmlScopeList_tst.java b/110_gfml/tst/gplx/gfml/z016_GfmlScopeList_tst.java new file mode 100644 index 000000000..f1c5e88b4 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z016_GfmlScopeList_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z016_GfmlScopeList_tst { + @Before public void setup() { + list = GfmlScopeList.new_("test"); + } GfmlScopeList list; + @Test public void None() { + tst_Itm(list, GfmlDocPos_.Root, null); + } + @Test public void One() { + run_Add(list, var_("val1")); + tst_Itm(list, GfmlDocPos_.Root, "val1"); + } + @Test public void ByPos() { + run_Add(list, var_("val1").DocPos_(docPos_(0, 0))); + run_Add(list, var_("val2").DocPos_(docPos_(0, 0, 0))); + tst_Itm(list, docPos_(0, 0), "val1"); + tst_Itm(list, docPos_(0, 0, 0), "val2"); + tst_Itm(list, docPos_(0, 1), "val1"); + tst_Itm(list, docPos_(0), null); + } + GfmlVarItm var_(String val) {return GfmlVarItm.new_("key", GfmlTkn_.raw_(val), GfmlVarCtx_.DefaultKey);} + GfmlDocPos docPos_(int... ary) { + int last = ary.length - 1; + int idx = ary[last]; + int[] levels = (int[])Array_.Resize(ary, last); + return new GfmlDocPos(levels, idx); + } + void run_Add(GfmlScopeList list, GfmlScopeItm... ary) { + for (GfmlScopeItm itm : ary) + list.Add(itm); + } + void tst_Itm(GfmlScopeList list, GfmlDocPos pos, String expd) { + GfmlVarItm itm = (GfmlVarItm)list.Get_by(pos); + String actl = itm == null ? null : itm.TknVal(); + Tfds.Eq(expd, actl); + } +} diff --git a/110_gfml/tst/gplx/gfml/z017_GfmlStringHighlighter_tst.java b/110_gfml/tst/gplx/gfml/z017_GfmlStringHighlighter_tst.java new file mode 100644 index 000000000..e18c5a657 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z017_GfmlStringHighlighter_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z017_GfmlStringHighlighter_tst { + @Test public void Short() { + tst_Err(sh_().Raw_("a=").Mark_(1, '=', "key tkn").Mark_(2, '?', "EOS:missing data") + , "< >" + , " a= " + , " =?" + , "" + , "[1] = key tkn" + , "[2] ? EOS:missing data" + ); + } + @Test public void Whitespace() { + tst_Err(sh_().Raw_("a\t\nb").Mark_(0, ' ', "") + , "< tn >" + , " a b " + , " " + ); + } + @Test public void Long() { + tst_Err(sh_().Raw_("abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba").Mark_(0, '{', "bgn").Mark_(50, '}', "end") + , "< >" + , " abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba " + , " { } " + , "" + , "[00] { bgn" + , "[50] } end" + ); + } + GfmlStringHighlighter sh_() {return GfmlStringHighlighter.new_();} + void tst_Err(GfmlStringHighlighter sh, String... expdLines) { + String[] actlLines = sh.Gen(); + Tfds.Eq_ary_str(expdLines, actlLines); + } +} diff --git a/110_gfml/tst/gplx/gfml/z051_GfmlFldPool_keyed_tst.java b/110_gfml/tst/gplx/gfml/z051_GfmlFldPool_keyed_tst.java new file mode 100644 index 000000000..8399959bf --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z051_GfmlFldPool_keyed_tst.java @@ -0,0 +1,75 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z051_GfmlFldPool_keyed_tst { + @Before public void setup() { + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + GfmlType type = makr.MakeSubType("point", "x", "y", "z"); + fldPool = GfmlFldPool.new_(type); + } GfmlFldPool fldPool; + @Test public void PopByKey_inOrder() { + tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z"); + } + @Test public void PopByKey_outOfOrder() { + tst_Keyed_PopByKey(fldPool, "y", "y", "x", "z"); + } + @Test public void PopByKey_unknown() { + tst_Keyed_PopByKey(fldPool, "a", GfmlItmKeys.NullKey, "x", "y", "z"); + } + @Test public void PopByKey_alreadyRemoved() { + tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z"); + tst_Keyed_PopByKey(fldPool, "x", GfmlItmKeys.NullKey, "y", "z"); + } + @Test public void PopByKey_depleted() { + tst_Keyed_PopByKey(fldPool, "x", "x", "y", "z"); + tst_Keyed_PopByKey(fldPool, "y", "y", "z"); + tst_Keyed_PopByKey(fldPool, "z", "z"); + tst_Keyed_PopByKey(fldPool, "x", GfmlItmKeys.NullKey); + } + @Test public void PopNext_inOrder() { + tst_Keyed_PopNext(fldPool, "x", "y", "z"); + tst_Keyed_PopNext(fldPool, "y", "z"); + tst_Keyed_PopNext(fldPool, "z"); + try { + tst_Keyed_PopNext(fldPool, GfmlItmKeys.NullKey); + Tfds.Fail("should have failed"); + } + catch (Exception exc) {Err_.Noop(exc);} + } + @Test public void PopByKey_PopNext() { + tst_Keyed_PopByKey(fldPool, "y", "y", "x", "z"); + tst_Keyed_PopNext(fldPool, "x", "z"); + } + void tst_Keyed_PopByKey(GfmlFldPool fldPool, String key, String expdFldId, String... expdSubs) { + GfmlFld actlFld = fldPool.Keyed_PopByKey(key); + Tfds.Eq(expdFldId, actlFld.Name()); + String[] actlSubs = new String[fldPool.Keyd_Count()]; + for (int i = 0; i < actlSubs.length; i++) { + actlSubs[i] = fldPool.Keyd_FetchAt(i).Name(); + } + Tfds.Eq_ary(expdSubs, actlSubs); + } + void tst_Keyed_PopNext(GfmlFldPool fldPool, String expdFldId, String... expdSubs) { + GfmlFld actlFld = fldPool.Keyed_PopNext(); + Tfds.Eq(expdFldId, actlFld.Name()); + String[] actlSubs = new String[fldPool.Keyd_Count()]; + for (int i = 0; i < actlSubs.length; i++) { + actlSubs[i] = fldPool.Keyd_FetchAt(i).Name(); + } + Tfds.Eq_ary(expdSubs, actlSubs); + } +} diff --git a/110_gfml/tst/gplx/gfml/z081_GfmlDataWtr_tst.java b/110_gfml/tst/gplx/gfml/z081_GfmlDataWtr_tst.java new file mode 100644 index 000000000..4499e1910 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z081_GfmlDataWtr_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; import gplx.core.stores.*; +public class z081_GfmlDataWtr_tst { + @Before public void setup() { + wtr = GfmlDataWtr.new_(); + wtr.WriteNodeBgn("root"); + } DataWtr wtr; + @Test public void Basic() { + tst_XtoStr(wtr, "root:;"); + } + @Test public void Atr_one() { + wtr.WriteData("key", "data");; + tst_XtoStr(wtr, "root:key='data';"); + } + @Test public void Atr_many() { + wtr.WriteData("key1", "data1"); + wtr.WriteData("key2", "data2"); + tst_XtoStr(wtr, "root:key1='data1' key2='data2';"); + } + @Test public void Nde_one() { + wtr.WriteNodeBgn("sub0"); + tst_XtoStr(wtr, "root:{sub0:;}"); + } + @Test public void Nde_many() { + wtr.WriteNodeBgn("sub0"); + wtr.WriteNodeEnd(); + wtr.WriteNodeBgn("sub1"); + tst_XtoStr(wtr, "root:{sub0:;sub1:;}"); + } + @Test public void Nde_nested() { + wtr.WriteNodeBgn("sub0"); + wtr.WriteNodeBgn("sub1"); + tst_XtoStr(wtr, "root:{sub0:{sub1:;}}"); + } + @Test public void OneAtrOneNde() { + wtr.WriteData("key1", "data1"); + wtr.WriteNodeBgn("sub0"); + tst_XtoStr(wtr, "root:key1='data1'{sub0:;}"); + } + @Test public void OneAtrOneNdeOneAtr() { + wtr.WriteData("key1", "data1"); + wtr.WriteNodeBgn("sub0"); + wtr.WriteData("key2", "data2"); + tst_XtoStr(wtr, "root:key1='data1'{sub0:key2='data2';}"); + } + @Test public void EscapeQuote() { + wtr.WriteData("key", "data's");; + tst_XtoStr(wtr, "root:key='data''s';"); + } + void tst_XtoStr(DataWtr wtr, String expd) { + String actl = wtr.To_str(); + Tfds.Eq(expd, actl); + } +} diff --git a/110_gfml/tst/gplx/gfml/z082_GfmlDataWtrOpts_tst.java b/110_gfml/tst/gplx/gfml/z082_GfmlDataWtrOpts_tst.java new file mode 100644 index 000000000..ecb18652e --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z082_GfmlDataWtrOpts_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; import gplx.core.stores.*; +public class z082_GfmlDataWtrOpts_tst { + @Before public void setup() { + wtr = GfmlDataWtr.new_(); + wtr.WriteNodeBgn("root"); + } DataWtr wtr; + @Test public void KeyedSpr() { + wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().KeyedSeparator_("\t")); + wtr.WriteData("key1", "data1"); + wtr.WriteData("key2", "data2"); + tst_XtoStr(wtr, "root:key1='data1'\tkey2='data2';"); + } + @Test public void IndentNamesOn() { + wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().IndentNodesOn_()); + wtr.WriteNodeBgn("nde1"); + wtr.WriteNodeBgn("nde2"); + wtr.WriteNodeEnd(); + tst_XtoStr(wtr, String_.Concat_lines_crlf + ( "root:{" + , " nde1:{" + , " nde2:;" + , " }" + , "}" + )); + } + @Test public void IgnoreNullNamesOn() { + wtr.InitWtr(GfmlDataWtrOpts.Key_const, GfmlDataWtrOpts.new_().IgnoreNullNamesOn_()); + wtr.WriteNodeBgn(""); + wtr.WriteData("key1", "data1"); + tst_XtoStr(wtr, String_.Concat("root:{key1='data1';}")); + } + void tst_XtoStr(DataWtr wtr, String expd) { + String actl = wtr.To_str(); + Tfds.Eq(expd, actl); + } +} diff --git a/110_gfml/tst/gplx/gfml/z091_GfmlLxr_basic_tst.java b/110_gfml/tst/gplx/gfml/z091_GfmlLxr_basic_tst.java new file mode 100644 index 000000000..798cf1263 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z091_GfmlLxr_basic_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +import gplx.core.texts.*; /*CharStream*/ +public class z091_GfmlLxr_basic_tst { + @Before public void setup() { + rootLxr = GfmlLxr_.general_("gfml.root", GfmlTkn_.cmd_("tkn:text", GfmlBldrCmd_.Null)); + } GfmlLxr rootLxr; + @Test public void Empty() { + tst_Fetch(""); + } + @Test public void General() { + tst_Fetch("text", "text"); + } + @Test public void Solo() { + ini_AddSymbol(","); + tst_Fetch(",", ","); + tst_Fetch(",data0", ",", "data0"); + tst_Fetch("data0,", "data0", ","); + tst_Fetch("data0,data1", "data0", ",", "data1"); + } + @Test public void Range() { + ini_AddRange(" ", "\t"); + tst_Fetch(" ", " "); + tst_Fetch(" a", " ", "a"); + tst_Fetch("\t ", "\t "); + tst_Fetch("\ta ", "\t", "a", " "); + } + void ini_AddSymbol(String symbol) { + GfmlTkn tkn = GfmlTkn_.singleton_("tkn", symbol, symbol, GfmlBldrCmd_.Null); + GfmlLxr lxr = GfmlLxr_.solo_(symbol, tkn); + rootLxr.SubLxr_Add(lxr); + } + void ini_AddRange(String... symbols) { + GfmlTkn tkn = GfmlTkn_.cmd_("tkn", GfmlBldrCmd_.Null); + GfmlLxr lxr = GfmlLxr_.range_("merge", symbols, tkn, false); + rootLxr.SubLxr_Add(lxr); + } + GfmlTkn tst_Fetch(String raw, String... expd) { + CharStream stream = CharStream.pos0_(raw); + List_adp list = List_adp_.New(); + GfmlTkn tkn = null; + while (true) { + tkn = rootLxr.MakeTkn(stream, 0); + if (tkn == GfmlTkn_.EndOfStream) break; + list.Add(tkn.Raw()); + } + String[] actl = (String[])list.To_ary(String.class); + Tfds.Eq_ary(expd, actl); + return tkn; + } +} diff --git a/110_gfml/tst/gplx/gfml/z101_core_ndeInline_tst.java b/110_gfml/tst/gplx/gfml/z101_core_ndeInline_tst.java new file mode 100644 index 000000000..232a90010 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z101_core_ndeInline_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z101_core_ndeInline_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add(GfmlDocLxrs.NdeInline_lxr()); + } + @Test public void One() { + fx.tst_Doc("a;", fx.nde_().Atru_("a")); + fx.tst_Tkn("a;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(";") + )); + } + @Test public void Many() { + fx.tst_Doc("a;b;" + , fx.nde_().Atru_("a") + , fx.nde_().Atru_("b") + ); + fx.tst_Tkn("a;b;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(";") + ) + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("b") + , fx.tkn_itm_(";") + ) + ); + } +} + diff --git a/110_gfml/tst/gplx/gfml/z102_core_whitespace_tst.java b/110_gfml/tst/gplx/gfml/z102_core_whitespace_tst.java new file mode 100644 index 000000000..fc9cc5183 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z102_core_whitespace_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z102_core_whitespace_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Whitespace_lxr() + ); + } + @Test public void Space() { + fx.tst_Doc("a b;", fx.nde_().Atru_("a").Atru_("b")); + fx.tst_Tkn("a b;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(" ") + , fx.tkn_grp_ary_("b") + , fx.tkn_itm_(";") + ) + ); + } + @Test public void Tab() { + fx.tst_Doc("a\tb;", fx.nde_().Atru_("a").Atru_("b")); + } + @Test public void NewLine() { + fx.tst_Doc(String_.Format("a{0}b;", String_.CrLf), fx.nde_().Atru_("a").Atru_("b")); + } + @Test public void MergeSameWs() { + fx.tst_Doc("a b;", fx.nde_().Atru_("a").Atru_("b")); + } + @Test public void MergeDiffWs() { + fx.tst_Doc("a\t b;", fx.nde_().Atru_("a").Atru_("b")); + fx.tst_Tkn("a\t b;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_("\t ") + , fx.tkn_grp_ary_("b") + , fx.tkn_itm_(";") + ) + ); + } + @Test public void LeadingWs() { + fx.tst_Doc(" a;", fx.nde_().Atru_("a")); + fx.tst_Tkn(" a;" + , fx.tkn_itm_(" ") + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(";") + ) + ); + } + @Test public void TrailingWs() { + fx.tst_Doc("a ;", fx.nde_().Atru_("a")); + fx.tst_Tkn("a ;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(" ") + , fx.tkn_itm_(";") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z103_core_elmKey_tst.java b/110_gfml/tst/gplx/gfml/z103_core_elmKey_tst.java new file mode 100644 index 000000000..ea64abbf9 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z103_core_elmKey_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z103_core_elmKey_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.ElmKey_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("a=b;", fx.nde_().Atrk_("a", "b")); + fx.tst_Tkn("a=b;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a", "=", "b") + , fx.tkn_itm_(";") + ) + ); + } + @Test public void Ws() { + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Tkn("a = b;" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a", " ", "=", " ", "b") + , fx.tkn_itm_(";") + ) + ); + } +// @Test public void Err_NotNamed() { +// fx.tst_Err("=", GfmlOutCmds.DatTkn_notFound_Err_()); +// } +// @Test public void Err_NotValued() { +// fx.tst_Err("a=;", GfmlOutCmds.elmKey_notValued_Err()); +// } +} diff --git a/110_gfml/tst/gplx/gfml/z111_core_comment0_tst.java b/110_gfml/tst/gplx/gfml/z111_core_comment0_tst.java new file mode 100644 index 000000000..30d75c267 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z111_core_comment0_tst.java @@ -0,0 +1,49 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z111_core_comment0_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Whitespace_lxr() // add whitespace to make sure it has no effect + , GfmlDocLxrs.Comment0_lxr() // bgn=// end=\n + ); + } + @Test public void Basic() { + fx.tst_Doc("//a" + String_.Lf); + fx.tst_Tkn("//a" + String_.Lf + , fx.tkn_grp_ary_("//", "a", String_.Lf) + ); + } + @Test public void Data() { + fx.tst_Doc("a;//b" + String_.Lf, fx.nde_().Atru_("a")); + fx.tst_Tkn("a;//b" + String_.Lf + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(";")) + , fx.tkn_grp_ary_("//", "b", String_.Lf) + ); + } +// @Test public void DanglingBgn() { +// try { +// fx.tst_Err("//", GfmlOutCmds.Frame_danglingBgn_Err_()); +// Tfds.Fail_expdError(); +// } +// catch (Exception exc) {Err_.Noop(exc);} +// } +} diff --git a/110_gfml/tst/gplx/gfml/z112_core_comment1_tst.java b/110_gfml/tst/gplx/gfml/z112_core_comment1_tst.java new file mode 100644 index 000000000..2141994ef --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z112_core_comment1_tst.java @@ -0,0 +1,67 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z112_core_comment1_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Comment1_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("/*a*/"); + fx.tst_Tkn("/*a*/" + , fx.tkn_grp_ary_("/*", "a", "*/") + ); + } + @Test public void Data() { + fx.tst_Doc("a;/*b*/", fx.nde_().Atru_("a")); + fx.tst_Tkn("a;/*b*/" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_itm_(";")) + , fx.tkn_grp_ary_("/*", "b", "*/") + ); + } + @Test public void IgnoreWs() { + fx.tst_Tkn("/* b c */" + , fx.tkn_grp_ary_("/*", " b c ", "*/") + ); + } + @Test public void EscapeBgn() { + fx.tst_Tkn("/* /*/* */" + , fx.tkn_grp_ary_("/*", " ", "/*/*", " ", "*/") + ); + } + @Test public void EscapeEnd() { + fx.tst_Tkn("/* */*/ */" + , fx.tkn_grp_ary_("/*", " ", "*/*/", " ", "*/") + ); + } + @Test public void Nest() { + fx.tst_Tkn("/* b0 /* c */ b1 */" + , fx.tkn_grp_ + ( fx.tkn_itm_("/*") + , fx.tkn_itm_(" b0 ") + , fx.tkn_grp_ary_("/*", " c ", "*/") + , fx.tkn_itm_(" b1 ") + , fx.tkn_itm_("*/") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z120_quotes_eval0_tst.java b/110_gfml/tst/gplx/gfml/z120_quotes_eval0_tst.java new file mode 100644 index 000000000..e656d2401 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z120_quotes_eval0_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z120_quotes_eval0_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Eval0_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("<~t>;", fx.nde_().Atru_("\t")); + fx.tst_Tkn("<~t>;" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ary_("<~", "t", ">")) + , fx.tkn_itm_(";") + ) + ); + } + @Test public void DoublingIsNotEscaping() { + fx.tst_Doc("<~t>>>;", fx.nde_().Atru_("\t").Atru_(">>")); // >> does not resolve to > + } +} diff --git a/110_gfml/tst/gplx/gfml/z121_quotes_quotes0_tst.java b/110_gfml/tst/gplx/gfml/z121_quotes_quotes0_tst.java new file mode 100644 index 000000000..e4928f11c --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z121_quotes_quotes0_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z121_quotes_quotes0_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Quote0_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("'abc';", fx.nde_().Atru_("abc")); + fx.tst_Tkn("'abc';" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ary_("'", "abc", "'")) + , fx.tkn_itm_(";") + ) + ); + } + @Test public void Escape() { + fx.tst_Doc("'a''b';", fx.nde_().Atru_("a'b")); + fx.tst_Tkn("'a''b';" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ary_("'", "a", "''", "b", "'")) + , fx.tkn_itm_(";") + ) + ); + } + @Test public void ManyAtrs_LastQuoted() { // bugfix + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Doc("a 'b';", fx.nde_().Atru_("a").Atru_("b")); + } +} diff --git a/110_gfml/tst/gplx/gfml/z122_quotes_quote0_eval0_tst.java b/110_gfml/tst/gplx/gfml/z122_quotes_quote0_eval0_tst.java new file mode 100644 index 000000000..528182269 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z122_quotes_quote0_eval0_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z122_quotes_quote0_eval0_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Quote0_Eval0_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("'a<~t>b';", fx.nde_().Atru_("a\tb")); + fx.tst_Tkn("'a<~t>b';" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_itm_("'") + , fx.tkn_itm_("a") + , fx.tkn_grp_ary_("<~", "t", ">") + , fx.tkn_itm_("b") + , fx.tkn_itm_("'") + )) + , fx.tkn_itm_(";") + ) + ); + } + @Test public void QuoteInside() { + fx.tst_Doc("'a<~'t'>b';", fx.nde_().Atru_("a\tb")); + fx.tst_Tkn("'a<~'t'>b';" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_itm_("'") + , fx.tkn_itm_("a") + , fx.tkn_grp_ + ( fx.tkn_itm_("<~") + , fx.tkn_grp_ary_("'", "t", "'") + , fx.tkn_itm_(">") + ) + , fx.tkn_itm_("b") + , fx.tkn_itm_("'") + )) + , fx.tkn_itm_(";") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z123_quotes_quoteBlock_tst.java b/110_gfml/tst/gplx/gfml/z123_quotes_quoteBlock_tst.java new file mode 100644 index 000000000..1e997bc0e --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z123_quotes_quoteBlock_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z123_quotes_quoteBlock_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.QuoteBlock_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("|'abc'|;", fx.nde_().Atru_("abc")); + } + @Test public void Escape_bgn() { + fx.tst_Doc("|'a|'|'b'|;", fx.nde_().Atru_("a|'b")); + } + @Test public void Escape_end() { + fx.tst_Doc("|'a'|'|b'|;", fx.nde_().Atru_("a'|b")); + } + @Test public void Nest() { + fx.tst_Doc("|'a|'-'|b'|;", fx.nde_().Atru_("a-b")); + } +} diff --git a/110_gfml/tst/gplx/gfml/z124_quotes_quoteFold_tst.java b/110_gfml/tst/gplx/gfml/z124_quotes_quoteFold_tst.java new file mode 100644 index 000000000..0fdf68650 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z124_quotes_quoteFold_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z124_quotes_quoteFold_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.QuoteFold_lxr() + ); + } + @Test public void Quote() { + fx.tst_Doc("^'a b'^;", fx.nde_().Atru_("a b")); + } + @Test public void Tab() { + fx.tst_Doc("^'a\tb'^;", fx.nde_().Atru_("ab")); + fx.tst_Tkn("^'a\tb'^;" + , fx.tkn_grp_ + ( fx.tkn_grp_ + ( fx.tkn_grp_ary_("^'", "a", "\t", "b", "'^")) + , fx.tkn_itm_(";")) + ); + } + @Test public void NewLine() { + fx.tst_Doc(String_.Concat("^'a", String_.CrLf, "b'^;"), fx.nde_().Atru_("ab")); + } + @Test public void Eval() { + fx.tst_Doc("^'a<~t>b'^;", fx.nde_().Atru_("a\tb")); + } + @Test public void Nest() { + fx.tst_Doc("^'a^'-'^b'^;", fx.nde_().Atru_("a-b")); + } + @Test public void EscapeBgn() { + fx.tst_Doc("^'a^'^'b'^;", fx.nde_().Atru_("a^'b")); + } + @Test public void EscapeEnd() { + fx.tst_Doc("^'a'^'^b'^;", fx.nde_().Atru_("a'^b")); + } + @Test public void Comment0() { + fx.tst_Doc(String_.Concat("^'a//comment", String_.CrLf, "b'^;"), fx.nde_().Atru_("ab")); + } + @Test public void Comment1() { + fx.tst_Doc("^'a/*comment*/b'^;", fx.nde_().Atru_("ab")); + } +} diff --git a/110_gfml/tst/gplx/gfml/z151_ndeSubs_basic_tst.java b/110_gfml/tst/gplx/gfml/z151_ndeSubs_basic_tst.java new file mode 100644 index 000000000..882b8ac00 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z151_ndeSubs_basic_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z151_ndeSubs_basic_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("{}", fx.nde_()); + fx.tst_Tkn("{}" + , fx.tkn_grp_ary_("{", "}") + ); + } + @Test public void Many() { + fx.tst_Doc("{}{}", fx.nde_(), fx.nde_()); + } + @Test public void Nested() { + fx.tst_Doc("{{}}" + , fx.nde_().Subs_ + ( fx.nde_()) + ); + } + @Test public void NestedMany() { + fx.tst_Doc("{{}{}}" + , fx.nde_().Subs_ + ( fx.nde_() + , fx.nde_() + )); + } + @Test public void Complex() { + fx.tst_Doc(String_.Concat + ( "{" + , "{" + , "{}" + , "}" + , "{}" + , "}" + ) + , fx.nde_().Subs_ + ( fx.nde_().Subs_ + ( fx.nde_()) + , fx.nde_() + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z152_ndeSubs_data_tst.java b/110_gfml/tst/gplx/gfml/z152_ndeSubs_data_tst.java new file mode 100644 index 000000000..674a38a37 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z152_ndeSubs_data_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z152_ndeSubs_data_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Whitespace_lxr() + ); + } + @Test public void ToInline() { + fx.tst_Doc("{a;}" + , fx.nde_().Subs_ + ( fx.nde_().Atru_("a")) + ); + } + @Test public void ToInline_many() { + fx.tst_Doc("{a b;}" + , fx.nde_().Subs_ + ( fx.nde_().Atru_("a").Atru_("b")) + ); + } + @Test public void ToBody() { + fx.tst_Doc("{a{}}" + , fx.nde_().Subs_ + ( fx.nde_().Atru_("a")) + ); + } + @Test public void ToBody_many() { + fx.tst_Doc("{a b{}}" + , fx.nde_().Subs_ + ( fx.nde_().Atru_("a").Atru_("b")) + ); + } + @Test public void ToBody_manyNest() { + fx.tst_Doc("a{b;}" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().Atru_("b")) + ); + } + @Test public void ToBody_many2() { + fx.tst_Doc("a{b{c;}}" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().Atru_("b").Subs_ + ( fx.nde_().Atru_("c")) + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z161_ndeHdrs_inline_tst.java b/110_gfml/tst/gplx/gfml/z161_ndeHdrs_inline_tst.java new file mode 100644 index 000000000..4f29e33b5 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z161_ndeHdrs_inline_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z161_ndeHdrs_inline_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeHeader_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.Whitespace_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("a:;", fx.nde_().Hnd_("a")); + fx.tst_Tkn("a:;" + , fx.tkn_grp_ary_("a", ":", ";") + ); + } + @Test public void Many() { + fx.tst_Doc("a:;b:;" + , fx.nde_().Hnd_("a") + , fx.nde_().Hnd_("b") + ); + } + @Test public void Ws() { + fx.tst_Tkn("a : ;" + , fx.tkn_grp_ary_("a", " ", ":", " ", ";") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z162_ndeHdrs_err_tst.java b/110_gfml/tst/gplx/gfml/z162_ndeHdrs_err_tst.java new file mode 100644 index 000000000..b6ae550ac --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z162_ndeHdrs_err_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z162_ndeHdrs_err_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeHeader_lxr() + ); + } + @Test public void NotNamed() { + fx.tst_Err(":", UsrMsg_mok.new_(GfmlUsrMsgs.fail_DatTkn_notFound())); + } + @Test public void Dangling() { + fx.tst_Err("a{", UsrMsg_mok.new_(GfmlUsrMsgs.fail_Frame_danglingBgn())); + } +} diff --git a/110_gfml/tst/gplx/gfml/z163_ndeHdrs_body_tst.java b/110_gfml/tst/gplx/gfml/z163_ndeHdrs_body_tst.java new file mode 100644 index 000000000..fda01eb5e --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z163_ndeHdrs_body_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z163_ndeHdrs_body_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeHeader_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("a:{}", fx.nde_().Hnd_("a")); + } + @Test public void Many() { + fx.tst_Doc("a:{}b:{}" + , fx.nde_().Hnd_("a") + , fx.nde_().Hnd_("b") + ); + } + @Test public void Nested() { + fx.tst_Doc("a:{b:{}}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().Hnd_("b")) + ); + } + @Test public void NestedMany() { + fx.tst_Doc("a:{b:{}c:{}}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().Hnd_("b") + , fx.nde_().Hnd_("c") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z164_hdeHdrs_data_tst.java b/110_gfml/tst/gplx/gfml/z164_hdeHdrs_data_tst.java new file mode 100644 index 000000000..eb9a6b838 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z164_hdeHdrs_data_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z164_hdeHdrs_data_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.Whitespace_lxr() + , GfmlDocLxrs.NdeHeader_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + ); + } + @Test public void Bas1() { + fx.tst_Tkn("a:b;" + , fx.tkn_grp_ + ( fx.tkn_itm_("a") + , fx.tkn_itm_(":") + , fx.tkn_grp_ary_("b") + , fx.tkn_itm_(";") + )); + } + @Test public void Basic3() { + fx.tst_Tkn("a:b{c;}" + , fx.tkn_grp_ + ( fx.tkn_itm_("a") + , fx.tkn_itm_(":") + , fx.tkn_grp_ary_("b") + , fx.tkn_itm_("{") + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("c") + , fx.tkn_itm_(";")) + , fx.tkn_itm_("}") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z181_ndeDots_basic_tst.java b/110_gfml/tst/gplx/gfml/z181_ndeDots_basic_tst.java new file mode 100644 index 000000000..a04f67d29 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z181_ndeDots_basic_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z181_ndeDots_basic_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeDot_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + ); + } + @Test public void One() { + fx.tst_Doc("{a.b;c;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1) + ) + , fx.nde_().Atru_("c").ChainId_(0) + )); + fx.tst_Tkn("{a.b;c;}" + , fx.tkn_grp_ + ( fx.tkn_itm_("{") + , fx.tkn_grp_ + ( fx.tkn_itm_("a") + , fx.tkn_itm_(".") + , fx.tkn_grp_ + ( fx.tkn_itm_("b") + , fx.tkn_itm_(";")) + ) + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("c") + , fx.tkn_itm_(";")) + , fx.tkn_itm_("}") + )); + } + @Test public void Many() { + fx.tst_Doc("{a.b.c.d;e;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("d").ChainId_(1) + ))) + , fx.nde_().ChainId_(0).Atru_("e") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z182_ndeDots_subs_tst.java b/110_gfml/tst/gplx/gfml/z182_ndeDots_subs_tst.java new file mode 100644 index 000000000..adc363c42 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z182_ndeDots_subs_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z182_ndeDots_subs_tst { + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeDot_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + ); + } GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Test public void Basic() { + fx.tst_Doc("{a.b{}z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1) + ) + , fx.nde_().Atru_("z").ChainId_(0) + )); + } + @Test public void Nest() { + fx.ini_RootLxr_Add(GfmlDocLxrs.NdeHeader_lxr()); + fx.tst_Doc("{a.b.c{d:e;}z;}" // shorthand of {a{b{c{d:e;}}}} + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("d").ChainId_(0).Atru_("e") + ) + ) + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } + @Test public void Chain() { + fx.tst_Doc("{a.b.c;z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(1)) + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } + @Test public void NdeHdr() { + fx.ini_RootLxr_Add(GfmlDocLxrs.NdeHeader_lxr()); + fx.tst_Doc("{a:b.c;z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").Atru_("b").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(1)//.Subs_ +// ( fx.nde_().Hnd_("c")) + ) + , fx.nde_().Atru_("z").ChainId_(0) + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z183_ndeDots_parens_tst.java b/110_gfml/tst/gplx/gfml/z183_ndeDots_parens_tst.java new file mode 100644 index 000000000..e928d213a --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z183_ndeDots_parens_tst.java @@ -0,0 +1,138 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z183_ndeDots_parens_tst { + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeDot_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + , GfmlDocLxrs.NdeHdrBgn_lxr() + , GfmlDocLxrs.NdeHdrEnd_lxr() + ); + } GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Test public void Basic() { + fx.tst_Doc("{a.b(c);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c") + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } + @Test public void Basic_tkn() { + //A_('1'); + fx.tst_Tkn("a(c);" + , fx.tkn_grp_ + ( fx.tkn_itm_("a"), fx.tkn_itm_("(") + , fx.tkn_grp_(fx.tkn_itm_("c")) + , fx.tkn_itm_(")"), fx.tkn_itm_(";") + ) + ); + } + @Test public void Basic2_tkn() { + fx.tst_Tkn("a.b(c);" + , fx.tkn_grp_ + ( fx.tkn_itm_("a"), fx.tkn_itm_(".") + , fx.tkn_grp_ + ( fx.tkn_itm_("b"), fx.tkn_itm_("("), fx.tkn_grp_ary_("c"), fx.tkn_itm_(")"), fx.tkn_itm_(";") + ) + ) + ); + } + @Test public void Many() { + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Doc("{a.b(c d e);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Atru_("d").Atru_("e") + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } +// @Test public void Many2() { +// fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); +// fx.tst_Doc("{a.b(c){d();}}" +// , fx.nde_().ChainId_(0).Subs_ +// ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ +// ( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Subs_ +// ( fx.nde_().Hnd_("d") +// ) +// ) +// )); +// } + @Test public void Chain() { + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Doc("{a.b(c).d(e);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).Atru_("c").Subs_ + ( fx.nde_().Hnd_("d").ChainId_(1).Atru_("e") + ) + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } + @Test public void Nest() { + fx.tst_Doc("{a.b(c.d);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).KeyedSubObj_(false).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(2).KeyedSubObj_(true).Subs_ + ( fx.nde_().Hnd_("d").ChainId_(2).KeyedSubObj_(false) + ) + ) + ) + , fx.nde_().Atru_("z") + )); + } + @Test public void Nest_longer() { + fx.tst_Doc("{a.b.c(d.e.f);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").KeyedSubObj_(false).ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").KeyedSubObj_(false).ChainId_(1).Subs_ + ( fx.nde_().Hnd_("d").KeyedSubObj_(true).ChainId_(2).Subs_ + ( fx.nde_().Hnd_("e").KeyedSubObj_(false).ChainId_(2).Subs_ + ( fx.nde_().Hnd_("f").KeyedSubObj_(false).ChainId_(2) + ) + ) + ) + ) + ) + , fx.nde_().Atru_("z") + )); + } + @Test public void Nest_deeper() { + fx.tst_Doc("{a.b(c.d(e.f));z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").KeyedSubObj_(false).ChainId_(1).Subs_ + ( fx.nde_().Hnd_("c").KeyedSubObj_(true).ChainId_(2).Subs_ + ( fx.nde_().Hnd_("d").KeyedSubObj_(false).ChainId_(2).Subs_ + ( fx.nde_().Hnd_("e").KeyedSubObj_(true).ChainId_(3).Subs_ + ( fx.nde_().Hnd_("f").KeyedSubObj_(false).ChainId_(3) + ) + ) + ) + ) + ) + , fx.nde_().Atru_("z") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z184_ndeDots_atrSpr_tst.java b/110_gfml/tst/gplx/gfml/z184_ndeDots_atrSpr_tst.java new file mode 100644 index 000000000..4eafcaf02 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z184_ndeDots_atrSpr_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z184_ndeDots_atrSpr_tst { + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeDot_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + , GfmlDocLxrs.NdeHdrBgn_lxr() + , GfmlDocLxrs.NdeHdrEnd_lxr() + , GfmlDocLxrs.AtrSpr_lxr() + ); + } GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Test public void NestMult() { + fx.ini_RootLxr_Add(GfmlDocLxrs.AtrSpr_lxr()); + fx.tst_Doc("{a.b(c.d,e.f);z;}" + , fx.nde_().ChainId_(0).Subs_ + ( fx.nde_().Hnd_("a").ChainId_(1).Subs_ + ( fx.nde_().Hnd_("b").ChainId_(1).KeyedSubObj_(false).Subs_ + ( fx.nde_().Hnd_("c").ChainId_(2).KeyedSubObj_(true).Subs_ + ( fx.nde_().Hnd_("d").ChainId_(2).KeyedSubObj_(false)) + , fx.nde_().Hnd_("e").ChainId_(3).KeyedSubObj_(true).Subs_ + ( fx.nde_().Hnd_("f").ChainId_(3).KeyedSubObj_(false)) + ) + ) + , fx.nde_().ChainId_(0).Atru_("z") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z191_ndeProps_basic_tst.java b/110_gfml/tst/gplx/gfml/z191_ndeProps_basic_tst.java new file mode 100644 index 000000000..713558a11 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z191_ndeProps_basic_tst.java @@ -0,0 +1,118 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z191_ndeProps_basic_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdePropBgn_lxr() + , GfmlDocLxrs.NdePropEnd_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + , GfmlDocLxrs.NdeHeader_lxr() + , GfmlDocLxrs.NdeInline_lxr() + ); + } + @Test public void Basic() { + fx.tst_Doc("a:[b]{}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b")) + ); + } + @Test public void Basic_empty() { + fx.tst_Tkn("[];" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("[", "]") + , fx.tkn_itm_(";") + )); + } + @Test public void Hdr() { + fx.tst_Tkn("a[];" + , fx.tkn_grp_ + ( fx.tkn_grp_ary_("a") + , fx.tkn_grp_ary_("[", "]") + , fx.tkn_itm_(";") + )); + } + @Test public void WithInnerNde() { + fx.tst_Doc("a:[b]{c;}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b") + , fx.nde_().Atru_("c") + )); + } + @Test public void DoesNotUsurpDatTknForName() { + fx.tst_Doc("a:b[c]{}" + , fx.nde_().Hnd_("a").Atru_("b").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("c") + )); + } + @Test public void NoHeader_body() { + fx.tst_Doc("a[b]{}" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b") + )); + } + @Test public void NoHeader_inline() { + fx.tst_Doc("a[b];" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b") + )); + } + @Test public void Nesting() { + fx.tst_Doc("a:[b:;]{}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Subs_ + ( fx.nde_().Hnd_("b")) + )); + } + @Test public void Nesting2() { + fx.tst_Doc("a:[b{}]{}" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b") + )); + } + @Test public void CanBeKeyed_header() { + fx.ini_RootLxr_Add(GfmlDocLxrs.ElmKey_lxr()); + fx.tst_Doc("a:b=[c];" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Key_("b").Atru_("c") + )); + } + @Test public void CanBeKeyed2_inline() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.Whitespace_lxr() + , GfmlDocLxrs.ElmKey_lxr() + ); + fx.tst_Doc("a b=[c];" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Key_("b").Atru_("c") + )); + } + @Test public void Sole() { + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Doc("[a b]" + , fx.nde_().KeyedSubObj_().Atru_("a").Atru_("b")); + } + @Test public void Nest1() { + fx.ini_RootLxr_Add(GfmlDocLxrs.Whitespace_lxr()); + fx.tst_Doc("[a [b]]" + , fx.nde_().Atru_("a").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("b") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z192_ndeProps_dots_tst.java b/110_gfml/tst/gplx/gfml/z192_ndeProps_dots_tst.java new file mode 100644 index 000000000..38c0375e3 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z192_ndeProps_dots_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z192_ndeProps_dots_tst { + GfmlParse_fxt fx = GfmlParse_fxt.new_(); + @Before public void setup() { + fx.ini_RootLxr_Add + ( GfmlDocLxrs.NdeDot_lxr() + , GfmlDocLxrs.NdeInline_lxr() + , GfmlDocLxrs.NdeBodyBgn_lxr() + , GfmlDocLxrs.NdeBodyEnd_lxr() + , GfmlDocLxrs.NdePropBgn_lxr() + , GfmlDocLxrs.NdePropEnd_lxr() + ); + } + @Test public void Stress() { + fx.tst_Doc("a.b[c];" + , fx.nde_().Hnd_("a").Subs_ + ( fx.nde_().Hnd_("b").Subs_ + ( fx.nde_().KeyedSubObj_().Atru_("c")) + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z400_GfmlTypeMakr_tst.java b/110_gfml/tst/gplx/gfml/z400_GfmlTypeMakr_tst.java new file mode 100644 index 000000000..c12add123 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z400_GfmlTypeMakr_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z400_GfmlTypeMakr_tst { + @Before public void setup() { + makr = GfmlTypeMakr.new_(); + } GfmlTypeMakr makr; GfmlType type; GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void MakeSubType() { + type = makr.MakeSubType("point", "x", "y"); + fx.tst_Type + ( fx.typ_().Key_("point").Subs_ + ( fx.fld_().ini_atr_("x").TypeKey_(GfmlType_.StringKey) + , fx.fld_().ini_atr_("y").TypeKey_(GfmlType_.StringKey) + ) + , GfmlTyp_mok.type_(type) + ); + tst_XtoAry(makr, "point"); + } + @Test public void MakeSubTypeAsOwner() { + type = makr.MakeSubTypeAsOwner("item"); + fx.tst_Type + ( fx.typ_().Key_("item") + , GfmlTyp_mok.type_(type) + ); + tst_Owner(makr, "item"); + tst_XtoAry(makr, "item"); + } + @Test public void MakeSubTypeAsOwner_MakeSubType() { + type = makr.MakeSubTypeAsOwner("item"); + makr.MakeSubType("pos", "x", "y"); + fx.tst_Type + ( fx.typ_().Key_("item").Subs_ + ( fx.fld_().Name_("pos").TypeKey_("item/pos")) + , GfmlTyp_mok.type_(type) + ); + tst_Owner(makr, "item"); + tst_XtoAry(makr, "item", "item/pos"); + } + void tst_Owner(GfmlTypeMakr typeMakr, String expdKey) { + Tfds.Eq(expdKey, typeMakr.Owner().Key()); + } + void tst_XtoAry(GfmlTypeMakr typeMakr, String... expdAry) { + GfmlType[] actlTypeAry = typeMakr.Xto_bry(); + String[] actlAry = new String[actlTypeAry.length]; + for (int i = 0; i < actlAry.length; i++) { + actlAry[i] = actlTypeAry[i].Key(); + } + Tfds.Eq_ary(expdAry, actlAry); + } +} diff --git a/110_gfml/tst/gplx/gfml/z401_types_compile_basic_tst.java b/110_gfml/tst/gplx/gfml/z401_types_compile_basic_tst.java new file mode 100644 index 000000000..f17b701f2 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z401_types_compile_basic_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z401_types_compile_basic_tst { + @Before public void setup() { + fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Basic() { + fx.tst_Compile + ( fx.nde_().Atrs_("point", "gfml.point").Subs_ + ( fx.nde_().Atru_("x") + , fx.nde_().Atru_("y") + ) + , fx.typ_().Name_("point").Key_("gfml.point").Atrs_("x", "y") + ); + } + @Test public void Nest() { + fx.tst_Compile + ( fx.nde_().Atrs_("item", "gfml.item").Subs_ + ( fx.nde_().Atru_("pos").Atrk_("type", "gfml.item.point") + ) + , fx.typ_().Name_("item").Key_("gfml.item").Subs_ + ( fx.fld_().Name_("pos").TypeKey_("gfml.item.point") + ) + ); + } + @Test public void NestMany() { + fx.tst_Compile + ( fx.nde_().Atrs_("item", "gfml.item").Subs_ + ( fx.nde_().Atru_("pos").Atrk_("type", "gfml.item.point") + , fx.nde_().Atru_("size").Atrk_("type", "gfml.item.size") + ) + , fx.typ_().Name_("item").Key_("gfml.item").Subs_ + ( fx.fld_().Name_("pos").TypeKey_("gfml.item.point") + , fx.fld_().Name_("size").TypeKey_("gfml.item.size") + ) + ); + } + @Test public void Recurse() { + fx.tst_Compile + ( fx.nde_().Atrs_("widget", "gfml.widget").Subs_ + ( fx.nde_().Atru_("widget").Atrk_("type", "gfml.widget") + ) + , fx.typ_().Name_("widget").Key_("gfml.widget").Subs_ + ( fx.fld_().Name_("widget").TypeKey_("gfml.widget") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z402_types_compile_implicit_tst.java b/110_gfml/tst/gplx/gfml/z402_types_compile_implicit_tst.java new file mode 100644 index 000000000..7c883b62b --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z402_types_compile_implicit_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z402_types_compile_implicit_tst { + @Before public void setup() { + fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Fld_typeKey_leaf() { + fx.tst_Compile + ( fx.nde_().Atrs_("point", "gfml.point").Subs_ + ( fx.nde_().Atru_("x").Atrk_("type", "gfml.int") // explicit + , fx.nde_().Atru_("y") // implicit: GfmlType_.String + ) + , fx.typ_().Name_("point").Key_("gfml.point").Subs_ + ( fx.fld_().Name_("x").TypeKey_("gfml.int") + , fx.fld_().Name_("y").TypeKey_("gfml.String") + )); + } + @Test public void Fld_typeKey_nest() { + fx.tst_Compile + ( fx.nde_().Atrs_("rect", "gfml.rect").Subs_ + ( fx.nde_().Atru_("pos").Atrk_("type", "gfml.point").Subs_ // explicit + ( fx.nde_().Atru_("x") + , fx.nde_().Atru_("y") + ) + , fx.nde_().Atru_("size").Subs_ // implicit: gfml.rect.size; (needs to have subs) + ( fx.nde_().Atru_("w") + , fx.nde_().Atru_("h") + ) + ) + , fx.typ_().Name_("rect").Key_("gfml.rect").Subs_ + ( fx.fld_().Name_("pos").TypeKey_("gfml.point") + , fx.fld_().Name_("size").TypeKey_("gfml.rect/size") + )); + } + @Test public void Typ_key() { + fx.tst_Compile + ( fx.nde_().Atrs_("point", "gfml.point") // explicit: gfml.point + , fx.typ_().Name_("point").Key_("gfml.point") + ); + + fx.tst_Compile + ( fx.nde_().Atrs_("point") // implicit: point + , fx.typ_().Name_("point").Key_("point") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z403_types_compile_default_tst.java b/110_gfml/tst/gplx/gfml/z403_types_compile_default_tst.java new file mode 100644 index 000000000..d8db39498 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z403_types_compile_default_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z403_types_compile_default_tst { + @Before public void setup() { + fx.run_InitPragma(fx.Regy(), GfmlPragmaType.new_()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Basic() { + fx.tst_Compile + ( fx.nde_().Atrs_("point", "gfml.point").Subs_ + ( fx.nde_().Atru_("x").Atrk_("default", "10") + , fx.nde_().Atru_("y") + ) + , fx.typ_().Name_("point").Key_("gfml.point").Subs_ + ( fx.fld_().Name_("x").Default_("10") + , fx.fld_().Name_("y").Default_(GfmlTkn_.NullRaw) + )); + } + @Test public void Nde() { + fx.tst_Compile + ( fx.nde_().Atrs_("rect", "gfml.rect").Subs_ + ( fx.nde_().Atru_("point").Subs_ + ( fx.nde_().Key_("default").Atrk_("x", "1").Atrk_("y", "2") // NOTE: naming b/c unnamed attribs are not returned in SubKeys + )) + , fx.typ_().Name_("rect").Key_("gfml.rect").Subs_ + ( fx.fld_().Name_("point").DefaultTkn_ + ( ndek_("point", atr_("x", "1"), atr_("y", "2"))) + )); + } + @Test public void Nde_unnamed() { + fx.tst_Compile + ( fx.nde_().Atrs_("rect", "gfml.rect").Subs_ + ( fx.nde_().Atru_("point").Subs_ + ( fx.nde_().Key_("").Atru_("1").Atru_("2") + )) + , fx.typ_().Name_("rect").Key_("gfml.rect").Subs_ + ( fx.fld_().Name_("point").DefaultTkn_ + ( ndek_("point", atr_("", "1"), atr_("", "2"))) + )); + } + static GfmlAtr atr_(String key, String val) {return GfmlAtr.string_(GfmlTkn_.raw_(key), GfmlTkn_.raw_(val));} + static GfmlNde ndek_(String key, GfmlItm... subs) { + GfmlNde rv = GfmlNde.new_(GfmlTkn_.raw_(key), GfmlType_.Null, true); + for (GfmlItm sub : subs) + rv.SubObjs_Add(sub); + return rv; + } +} diff --git a/110_gfml/tst/gplx/gfml/z411_types_apply_atrs_basic_tst.java b/110_gfml/tst/gplx/gfml/z411_types_apply_atrs_basic_tst.java new file mode 100644 index 000000000..36d1945d8 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z411_types_apply_atrs_basic_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z411_types_apply_atrs_basic_tst { + @Before public void setup() { + pointType = fx.typ_().Key_("point").Atrs_("x", "y", "z"); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); GfmlTyp_mok pointType; + @Test public void Unnamed_one() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atru_("10") + , fx.nde_().Typ_("point").Atrk_("x", "10") + ); + } + @Test public void Unnamed_three() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atrs_("10", "20", "30") + , fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30") + ); + } + @Test public void Keys_partial1() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atrk_("x", "10").Atrs_("20", "30") + , fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30") + ); + } + @Test public void Keys_partial2() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atrk_("x", "10").Atrk_("y", "20").Atru_("30") + , fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("y", "20").Atrk_("z", "30") + ); + } + @Test public void OutOfOrder_z_1() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atrk_("z", "30").Atrs_("10", "20") + , fx.nde_().Typ_("point").Atrk_("z", "30").Atrk_("x", "10").Atrk_("y", "20") + ); + } + @Test public void OutOfOrder_z_2() { + fx.tst_Resolve + ( pointType + , fx.nde_().Hnd_("point").Atru_("10").Atrk_("z", "30").Atru_("20") + , fx.nde_().Typ_("point").Atrk_("x", "10").Atrk_("z", "30").Atrk_("y", "20") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z421_types_apply_ndes_basic_tst.java b/110_gfml/tst/gplx/gfml/z421_types_apply_ndes_basic_tst.java new file mode 100644 index 000000000..29f9d5cbb --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z421_types_apply_ndes_basic_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z421_types_apply_ndes_basic_tst { + @Before public void setup() { + fx.Regy().Add( + fx.typ_().Key_("pos").Subs_ + ( GfmlFld_mok.new_().ini_atr_("x") + , GfmlFld_mok.new_().ini_atr_("y") + ).XtoGfmlType()); + fx.Regy().Add( + fx.typ_().Key_("rect").Subs_ + ( GfmlFld_mok.new_().ini_ndk_("pos", "pos") + ).XtoGfmlType()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void NamedNde_but_UnnamedAtr() { + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Key_("pos").Atrs_("1") + ) + , fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Typ_("pos").Atrk_("x", "1") + ) + ); + } + @Test public void UnnamedNde() { + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1") + ) + , fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Typ_("pos").Atrk_("x", "1") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z422_types_apply_ndes_multi_tst.java b/110_gfml/tst/gplx/gfml/z422_types_apply_ndes_multi_tst.java new file mode 100644 index 000000000..34150dbc5 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z422_types_apply_ndes_multi_tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z422_types_apply_ndes_multi_tst { + @Before public void setup() { + fx.Regy().Add + ( fx.typ_().Key_("pos").Subs_ + ( GfmlFld_mok.new_().ini_atr_("x") + , GfmlFld_mok.new_().ini_atr_("y") + ).XtoGfmlType()); + fx.Regy().Add + ( fx.typ_().Key_("size").Subs_ + ( GfmlFld_mok.new_().ini_atr_("w") + , GfmlFld_mok.new_().ini_atr_("h") + ).XtoGfmlType()); + fx.Regy().Add + ( fx.typ_().Key_("rect").Subs_ + ( GfmlFld_mok.new_().ini_ndk_("pos", "pos") + , GfmlFld_mok.new_().ini_ndk_("size", "size") + ).XtoGfmlType()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Unnamed() { + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1") + , fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("3") + ) + , fx.nde_().Typ_("rect").Subs_ + ( fx.nde_().Typ_("pos").Atrk_("x", "1") + , fx.nde_().Typ_("size").Atrk_("w", "3") + ) + ); + } + @Test public void Partial() { + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Key_("pos").Atrs_("1") + , fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("3") + ) + , fx.nde_().Typ_("rect").Subs_ + ( fx.nde_().Typ_("pos").Atrk_("x", "1") + , fx.nde_().Typ_("size").Atrk_("w", "3") + ) + ); + } + @Test public void OutOfOrder() { + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Key_("size").Atrs_("3") + , fx.nde_().Key_(GfmlTkn_.NullRaw).Atrs_("1") + ) + , fx.nde_().Typ_("rect").Subs_ + ( fx.nde_().Typ_("size").Atrk_("w", "3") + , fx.nde_().Typ_("pos").Atrk_("x", "1") + ) + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z423_types_apply_ndes_misc_tst.java b/110_gfml/tst/gplx/gfml/z423_types_apply_ndes_misc_tst.java new file mode 100644 index 000000000..c9b0b6d36 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z423_types_apply_ndes_misc_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z423_types_apply_ndes_misc_tst { + @Before public void setup() { + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Recurse() { + fx.Regy().Add( + fx.typ_().Key_("item").Subs_ + ( GfmlFld_mok.new_().ini_atr_("key") + , GfmlFld_mok.new_().ini_ndk_("item", "item") + ).XtoGfmlType()); + fx.tst_Resolve + ( fx.nde_().Hnd_("item").Atru_("1").Subs_ + ( fx.nde_().Hnd_("item").Atru_("2")) + , fx.nde_().Hnd_("item").Atrk_("key", "1").Subs_ + ( fx.nde_().Hnd_("item").Atrk_("key", "2") + )); + } + @Test public void OwnerTypePrecedesTopLevel() { + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + GfmlType topLevelSize = makr.MakeSubType("size", "width", "height"); + GfmlType rect = makr.MakeSubTypeAsOwner("rect"); + GfmlType rectSize = makr.MakeSubType("size", "w", "h"); + fx.Regy().Add(topLevelSize).Add(rect).Add(rectSize); + fx.tst_Resolve + ( fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Hnd_("size").Atru_("1").Atru_("2")) + , fx.nde_().Hnd_("rect").Subs_ + ( fx.nde_().Typ_("rect/size").Atrk_("w", "1").Atrk_("h", "2") + )); + } +} diff --git a/110_gfml/tst/gplx/gfml/z424_types_apply_ndes_nest_tst.java b/110_gfml/tst/gplx/gfml/z424_types_apply_ndes_nest_tst.java new file mode 100644 index 000000000..233763227 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z424_types_apply_ndes_nest_tst.java @@ -0,0 +1,65 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z424_types_apply_ndes_nest_tst { + @Before public void setup() { + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + makr.MakeRootType("gfml.item", "item"); + makr.MakeSubType("pos", "x", "y"); + fx.Regy().Add_ary(makr.Xto_bry()); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void InvokeByHnd() { + fx.tst_Resolve + ( fx.nde_().Hnd_("gfml.item").Subs_ + ( fx.nde_().Hnd_("pos").Atrs_("10", "20")) + , fx.nde_().Typ_("gfml.item").Subs_ + ( fx.nde_().Typ_("gfml.item/pos").Atrk_("x", "10").Atrk_("y", "20") + )); + } + @Test public void InvokeByTyp() { + fx.tst_Resolve + ( fx.nde_().Hnd_("gfml.item").Subs_ + ( fx.nde_().Hnd_("gfml.item/pos").Atrs_("10", "20")) + , fx.nde_().Typ_("gfml.item").Subs_ + ( fx.nde_().Typ_("gfml.item/pos").Atrk_("x", "10").Atrk_("y", "20") + )); + } + @Test public void NoInvokeByName() { + fx.tst_Resolve + ( fx.nde_().Hnd_("gfml.item").Subs_ + ( fx.nde_().Hnd_("gfml.item").Atrs_("10", "20")) // item is not in .SubFlds, but is in regy + , fx.nde_().Typ_("gfml.item").Subs_ + ( fx.nde_().Typ_("gfml.item").Atrs_("10", "20") + )); + } + @Test public void Name_subLevel() { + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + makr.MakeRootType("font", "size"); + makr.MakeSubType("color", "name"); + fx.Regy().Add_ary(makr.Xto_bry()); + fx.tst_Resolve + ( fx.nde_().Hnd_("color").Atru_("blue") + , fx.nde_().Typ_(GfmlType_.AnyKey).Atru_("blue")// confirm that subFlds in other types are not selectable by name; i.e.: must be font/color, not just color + ); + } + @Test public void Unresolved() { + fx.tst_Resolve + ( fx.nde_().Hnd_("").Atrs_("10", "20") + , fx.nde_().Typ_(GfmlType_.AnyKey).Atrs_("10", "20") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z441_types_parse_basic_tst.java b/110_gfml/tst/gplx/gfml/z441_types_parse_basic_tst.java new file mode 100644 index 000000000..724858067 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z441_types_parse_basic_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z441_types_parse_basic_tst { + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Null() { + fx.tst_Parse(String_.Concat + ( "point:1;" + ) + , fx.nde_().Hnd_("point").Typ_(GfmlType_.AnyKey).Atru_("1") + ); + } + @Test public void Basic() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {" + , "x;" + , "}" + , "}" + , "point:1;" + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1") + ); + } + @Test public void MultipleAtrs() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {" + , "x; y;" + , "}" + , "}" + , "point:1 2;" + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1").Atrk_("y", "2") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z442_types_parse_default_tst.java b/110_gfml/tst/gplx/gfml/z442_types_parse_default_tst.java new file mode 100644 index 000000000..e4fb4cfc6 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z442_types_parse_default_tst.java @@ -0,0 +1,99 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z442_types_parse_default_tst { + @Test public void Basic() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {x;}" + , "}" + , "1;" + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1") + ); + } + @Test public void Pinned() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {x;}" + , "}" + , "1;" // uses point, but should pin + , "2;" // uses pin + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1") + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "2") + ); + } + @Test public void Many() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {x;}" // point is always pinned + , "size {w;}" // size is defined, but can only be invoked by hnd + , "}" + , "1;" + , "2;" + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1") + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "2") + ); + } + @Test public void Nested() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "item {" + , "point {x; y;}" + , "}" + , "}" + , "{1 2;}" + ) + , fx.nde_().Hnd_("item").Typ_("item").Subs_ + ( fx.nde_().Hnd_("point").Typ_("item/point").Atrk_("x", "1").Atrk_("y", "2") + ) + ); + } + @Test public void NestedWithAtr() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "item {" + , "name;" + , "point {x; y;}" + , "}" + , "}" + , "1 {1 2;}" +// , "1 {point:{1 2}}" // breaks b/c point is not resolved as item/point + ) + , fx.nde_().Hnd_("item").Typ_("item").Atrk_("name", "1").Subs_ + ( fx.nde_().Hnd_("point").Typ_("item/point").Atrk_("x", "1").Atrk_("y", "2") + ) + ); + } + //@Test + public void WithDefault() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "point {" + , "x 1;" + , "y;" + , "}" + , "}" + , "2;" + ) + , fx.nde_().Hnd_("point").Typ_("point").Atrk_("x", "1").Atrk_("y", "2") + ); + } + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); +} diff --git a/110_gfml/tst/gplx/gfml/z443_types_parse_keyd_tst.java b/110_gfml/tst/gplx/gfml/z443_types_parse_keyd_tst.java new file mode 100644 index 000000000..1e29f27cd --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z443_types_parse_keyd_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z443_types_parse_keyd_tst { + @Test public void Basic() { + fx.tst_Parse(String_.Concat + ( "[10 12];" + ) + , fx.nde_().Subs_ + ( fx.nde_().Atru_("10").Atru_("12") + ) + ); + } +// @Test // FIX: IGNORE + public void KeydDefault() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , " rect {" + , " point [1 2];" + , " }" + , "}" + , "rect:;" + , "rect:;" + ) + , fx.nde_().Typ_("rect").Subs_ + ( fx.nde_().Hnd_("point").Atru_("1").Atru_("2") + ) + , fx.nde_().Typ_("rect").Subs_ + ( fx.nde_().Hnd_("point").Atru_("1").Atru_("2") + ) + ); + } + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); +} diff --git a/110_gfml/tst/gplx/gfml/z450_fx_GfmlDefaultItem_fxt.java b/110_gfml/tst/gplx/gfml/z450_fx_GfmlDefaultItem_fxt.java new file mode 100644 index 000000000..659de09a0 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z450_fx_GfmlDefaultItem_fxt.java @@ -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.gfml; import gplx.*; +class GfmlDefaultItem_fxt { + @gplx.Internal protected GfmlDefaultItem make_(String typeKey, String key, GfmlTkn val) {return GfmlDefaultItem.new_(typeKey, key, val);} + @gplx.Internal protected GfmlDefaultItem make_(String typeKey, String key, String val) {return GfmlDefaultItem.new_(typeKey, key, GfmlTkn_.raw_(val));} + @gplx.Internal protected void tst_Item(GfmlDefaultItem actl, GfmlDefaultItem expd) { + Tfds.Eq(expd.TypeKey(), actl.TypeKey()); + Tfds.Eq(expd.Key(), actl.Key()); + Tfds.Eq(GfmlFld_mok.XtoRaw(expd.Val()), GfmlFld_mok.XtoRaw(actl.Val())); + Tfds.Eq(Val_to_str_or_null(expd.ValPrev()), Val_to_str_or_null(actl.ValPrev())); + } + @gplx.Internal protected void tst_List(List_adp list, GfmlDefaultItem... expdAry) { + for (int i = 0; i < expdAry.length; i++) { + GfmlDefaultItem actl = (GfmlDefaultItem)list.Get_at(i); + GfmlDefaultItem expd = expdAry[i]; + tst_Item(actl, expd); + } + Tfds.Eq(expdAry.length, list.Count()); + } + String Val_to_str_or_null(GfmlObj gobj) { + GfmlTkn tkn = GfmlTkn_.as_(gobj); + return tkn == null ? null : tkn.Val(); + } + public static GfmlDefaultItem_fxt new_() {return new GfmlDefaultItem_fxt();} GfmlDefaultItem_fxt() {} +} diff --git a/110_gfml/tst/gplx/gfml/z451_dflts_compile_tst.java b/110_gfml/tst/gplx/gfml/z451_dflts_compile_tst.java new file mode 100644 index 000000000..822637c80 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z451_dflts_compile_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z451_dflts_compile_tst { + @Before public void setup() { + regy = fx_typ.Regy(); + pragma = GfmlPragmaDefault.new_(); + fx_typ.run_InitPragma(regy, pragma); + } GfmlTypRegy regy; GfmlPragmaDefault pragma; GfmlDefaultItem_fxt fx = GfmlDefaultItem_fxt.new_(); GfmlTypeCompiler_fxt fx_typ = GfmlTypeCompiler_fxt.new_(); + @Test public void Basic() { + GfmlNde gnde = fx_typ.run_Resolve(regy, "_default/type/atr" + , fx_typ.nde_().Atru_("x").Atru_("10") + ); + GfmlDefaultItem actl = pragma.CompileItem(gnde, "point"); + fx.tst_Item(actl, fx.make_("point", "x", "10")); + } + @Test public void Many() { + GfmlNde gnde = fx_typ.run_Resolve(regy, "_default/type" + , fx_typ.nde_().Atru_("point").Subs_ + ( fx_typ.nde_().Atrs_("x", "10") + , fx_typ.nde_().Atrs_("y", "20") + )); + List_adp list = List_adp_.New(); + pragma.CompileSubNde(gnde, list); + fx.tst_List(list + , fx.make_("point", "x", "10") + , fx.make_("point", "y", "20") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z452_dflts_exec_tst.java b/110_gfml/tst/gplx/gfml/z452_dflts_exec_tst.java new file mode 100644 index 000000000..fe651bb8b --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z452_dflts_exec_tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z452_dflts_exec_tst { + @Before public void setup() { + type = make_("gfml.point", "point", "x"); + } GfmlDefaultItem item; GfmlType type; GfmlDefaultItem_fxt fx_item = GfmlDefaultItem_fxt.new_(); + @Test public void Basic() { + tst_SubFldDefault(type, "x", null); + + item = fx_item.make_("gfml.point", "x", "10"); + item.Exec_bgn(type); + tst_SubFldDefault(type, "x", "10"); + + item.Exec_end(type); + tst_SubFldDefault(type, "x", null); + } + @Test public void Overwrite() { + ini_SubFldDefault_add(type, "x", "0"); + tst_SubFldDefault(type, "x", "0"); + + item = fx_item.make_("gfml.point", "x", "10"); + item.Exec_bgn(type); + tst_SubFldDefault(type, "x", "10"); + + item.Exec_end(type); + tst_SubFldDefault(type, "x", "0"); + } + @Test public void CreateDefault() { + tst_SubFldExists(type, "y", false); + + item = fx_item.make_("gfml.point", "y", "10"); + item.Exec_bgn(type); + + tst_SubFldDefault(type, "y", "10"); + + item.Exec_end(type); + tst_SubFldExists(type, "y", false); + } + @Test public void DefaultTkn() { + Object[] ary = ini_eval_("0"); + GfmlTkn varTkn = (GfmlTkn)ary[0]; + GfmlVarItm varItem = (GfmlVarItm)ary[1]; + item = fx_item.make_("gfml.point", "x", varTkn); + varItem.Tkn_set(GfmlTkn_.raw_("10")); + item.Exec_bgn(type); + + tst_SubFldDefault(type, "x", "10"); + } + Object[] ini_eval_(String text) { + GfmlVarCtx evalContext = GfmlVarCtx.new_("testContext"); + GfmlTkn valTkn = GfmlTkn_.raw_(text); + GfmlVarItm varItem = GfmlVarItm.new_("varKey", valTkn, "testContext"); + evalContext.Add_if_dupe_use_nth(varItem); + GfmlVarTkn rv = new GfmlVarTkn("eval", GfmlTknAry_.ary_(valTkn), evalContext, "varKey"); + return new Object[] {rv, varItem}; + } + void ini_SubFldDefault_add(GfmlType type, String subFldKey, String defaultVal) { + GfmlFld subFld = type.SubFlds().Get_by(subFldKey); + GfmlTkn defaultTkn = GfmlTkn_.raw_(defaultVal);; + subFld.DefaultTkn_(defaultTkn); + } + void tst_SubFldDefault(GfmlType type, String subFldKey, String expdDefaultVal) { + GfmlFld subFld = type.SubFlds().Get_by(subFldKey); + GfmlTkn defaultTkn = GfmlTkn_.as_(subFld.DefaultTkn()); + String actlDefaultVal = defaultTkn == null || defaultTkn == GfmlTkn_.Null ? null : defaultTkn.Val(); + Tfds.Eq(expdDefaultVal, actlDefaultVal); + } + void tst_SubFldExists(GfmlType type, String subFldKey, boolean expd) { + GfmlFld subFld = type.SubFlds().Get_by(subFldKey); + Tfds.Eq(expd, subFld != null); + } + GfmlType make_(String key, String name, String... atrs) { + GfmlTypeMakr typeMakr = GfmlTypeMakr.new_(); + GfmlType rv = typeMakr.MakeRootType(key, name); + for (String atr : atrs) + typeMakr.AddSubFld(GfmlFld.new_(true, atr, GfmlType_.StringKey)); + return rv; + } +} diff --git a/110_gfml/tst/gplx/gfml/z455_dflts_scope_tst.java b/110_gfml/tst/gplx/gfml/z455_dflts_scope_tst.java new file mode 100644 index 000000000..416dc9df2 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z455_dflts_scope_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z455_dflts_scope_tst { + @Before public void setup() { + regy = GfmlTypRegy.new_(); + GfmlTypeMakr makr = GfmlTypeMakr.new_(); + rootPos = GfmlDocPos_.Root.NewDown(0); + GfmlType type = makr.MakeRootType("point", "point", "x", "y").DocPos_(rootPos); + regy.Add(type); + } GfmlDocPos rootPos, currPos; GfmlTypRegy regy; + @Test public void Basic() { + currPos = rootPos.NewDown(0); + tst_FetchOrNullByPos(regy, "point", rootPos, "point", "x", "y"); + tst_FetchOrNullByPos(regy, "point", currPos, "point", "x", "y"); + + List_adp list = List_adp_.New(); + list.Add(GfmlDefaultItem.new_("point", "z", GfmlTkn_.raw_("0"))); + GfmlDefaultPragma_bgnCmd.ExecList(regy, currPos, list); + + tst_FetchOrNullByPos(regy, "point", rootPos, "point", "x", "y"); + tst_FetchOrNullByPos(regy, "point", currPos, "point", "x", "y", "z"); + } + GfmlType tst_FetchOrNullByPos(GfmlTypRegy regy, String key, GfmlDocPos docPos, String expdTypeKey, String... expdSubs) { + GfmlType actl = regy.FetchOrNull(key, docPos); + Tfds.Eq(expdTypeKey, actl.Key()); + String[] actlSubs = new String[actl.SubFlds().Count()]; + for (int i = 0; i < actlSubs.length; i++) + actlSubs[i] = actl.SubFlds().Get_at(i).Name(); + Tfds.Eq_ary(expdSubs, actlSubs); + return actl; + } +} diff --git a/110_gfml/tst/gplx/gfml/z456_dflts_parse_tst.java b/110_gfml/tst/gplx/gfml/z456_dflts_parse_tst.java new file mode 100644 index 000000000..cb35e42c8 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z456_dflts_parse_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z456_dflts_parse_tst { + @Test public void Fix_DefaultChangesPinnedType() { + fx.tst_Parse(String_.Concat + ( "_type:{" + , "item {" + , "name;" + , "}" + , "}" + , "_default:{item {name 10;}}" + , ";" + ) + , fx.nde_().Typ_("item").Atrk_("name", "10") + ); + } + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); +} diff --git a/110_gfml/tst/gplx/gfml/z481_vars_compile_tst.java b/110_gfml/tst/gplx/gfml/z481_vars_compile_tst.java new file mode 100644 index 000000000..e43b7fa49 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z481_vars_compile_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z481_vars_compile_tst { + @Before public void setup() { + regy = fx.Regy(); + pragma = GfmlPragmaVar.new_(); + fx.run_InitPragma(regy, pragma); + } GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); GfmlTypRegy regy; GfmlPragmaVar pragma; + @Test public void Text1() { + GfmlNde gnde = fx.run_Resolve(regy, "_var/text" + , fx.nde_().Atru_("key_test").Atru_("val_test").Atru_("context_test")); + + GfmlVarItm itm = pragma.CompileItmNde(gnde); + Tfds.Eq_rev(itm.Key(), "key_test"); + Tfds.Eq_rev(itm.TknVal(), "val_test"); + Tfds.Eq_rev(itm.CtxKey(), "context_test"); + } +} diff --git a/110_gfml/tst/gplx/gfml/z482_vars_parse_tst.java b/110_gfml/tst/gplx/gfml/z482_vars_parse_tst.java new file mode 100644 index 000000000..7e6fa6796 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z482_vars_parse_tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z482_vars_parse_tst { + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void Basic() { + fx.tst_Parse(String_.Concat + ( "_var:{" + , " size '20,20';" + , "}" + , "'<~size>';" + ) + , fx.nde_().Atru_("20,20") + ); + } + @Test public void Many() { + fx.tst_Parse(String_.Concat + ( "_var:{" + , " size '20,20';" + , " pos '30,30';" + , "}" + , "'<~size>' '<~pos>';" + ) + , fx.nde_().Atru_("20,20").Atru_("30,30") + ); + } + @Test public void Deferred() { + fx.tst_Parse(String_.Concat + ( "_var:{" + , " key0 '<~key1>';" + , "}" + , "_var:{" + , " key1 val1;" + , "}" + , "'<~key0>';" + ) + , fx.nde_().Atru_("val1") + ); + } + @Test public void Swap() { + fx.tst_Parse(String_.Concat + ( "{" + , " _var:{" + , " size '20,20';" + , " }" + , " '<~size>';" + , " _var:{" + , " size '30,30';" + , " }" + , " '<~size>';" + , "}" + ) + , fx.nde_().Subs_ + ( fx.nde_().Atru_("20,20") + , fx.nde_().Atru_("30,30") + ) + ); + } + @Test public void Context() { + fx.tst_Parse(String_.Concat + ( "_var:{" + , " size '20,20' gui;" + , "}" + , "'<~gui.size>' <~size>;" + ) + , fx.nde_().Atru_("20,20").Atru_("<~size>") + ); + } +} diff --git a/110_gfml/tst/gplx/gfml/z501_lxr_parse_tst.java b/110_gfml/tst/gplx/gfml/z501_lxr_parse_tst.java new file mode 100644 index 000000000..78e41ddc7 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z501_lxr_parse_tst.java @@ -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.gfml; import gplx.*; +import org.junit.*; +public class z501_lxr_parse_tst { + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); + @Test public void SymCreate() { + fx.tst_Parse(String_.Concat + ( "_lxr_sym:key='gfml.elm_key_1' raw='<-' cmd='gfml.elm_key';" + , "a<-1;" + ) + , fx.nde_().Atrk_("a", "1") + ); + } + @Test public void SymUpdate() { + fx.tst_Parse(String_.Concat + ( "_lxr_sym:key='gfml.elm_key_0' raw='<-';" + , "a<-1 b=1;" + ) + , fx.nde_().Atrk_("a", "1").Atru_("b=1") + ); + } + @Test public void SwapCreate() { + fx.tst_Parse(String_.Concat + ( "_lxr_sym:key='gfml.swap_0' raw='/?/?' val='/?';" + , "/?/?;" + ) + , fx.nde_().Atru_("/?") + ); + } + @Test public void FrameCreate() { + fx.tst_Parse(String_.Concat + ( "_lxr_frame:key='gfml.comment_2' type='comment' bgn='/-' end='-/';" + , "a=/-ignore-/b;" + ) + , fx.nde_().Atrk_("a", "b") + ); + } + @Test public void FrameUpdate() { + fx.tst_Parse(String_.Concat + ( "_lxr_frame:key='gfml.comment_0' bgn='--' end='!';" + , "a=--ignore!" + , "b;" + ) + , fx.nde_().Atrk_("a", "b") + ); + } + //@Test + public void FrameCreateNest() { + fx.tst_Parse(String_.Concat + ( "_lxr_frame:key='gfml.comment_2' type='comment' bgn='/-' end='-/' {" + , "sym:key='gfml.comment_2_escape_bgn' raw='/-/-' val='/-' cmd='gfml.elm_data';" + , "sym:key='gfml.comment_2_escape_end' raw='-/-/' val='-/' cmd='gfml.elm_data';" + , "}" + , "a=/-/-/-ignore-/b;" + ) + , fx.nde_().Atrk_("a", "b") + ); + // todo: + // cmd should be waitingTkns add, not data (makes invisible + // should resolve type on sym to lxr_sym (since _lxr_sym is not invoked) or create _lxr_frame/sym type + // how to change inner lxrs (lookup by key?) + } + +// @Test public void FrameUpdateEval() { +// raw = String_.Concat +// ( "_lxr_frame:key='gfml.eval_0' bgn='~<' end='>';" // how to handle '<~' where <~ (block quote) +// , "a=~[t];" +// ); +// gdoc = GfmlDoc_.parse_any_eol_(raw); +// fx_nde.tst_SubKeys(gdoc, 0, atr_("a", "\t")); +// } +} diff --git a/110_gfml/tst/gplx/gfml/z601_edit_atr_tst.java b/110_gfml/tst/gplx/gfml/z601_edit_atr_tst.java new file mode 100644 index 000000000..4f08a1aba --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z601_edit_atr_tst.java @@ -0,0 +1,128 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z601_edit_atr_tst { + GfmlUpdateFx fx = GfmlUpdateFx.new_(); + @Test public void Basic() { + fx .Raw_("a=1;").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "2")) + .tst_("a=2;"); + } + @Test public void WhiteSpaceComment() { + fx .Raw_("a = /*comment*/1;").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "2")) + .tst_("a = /*comment*/2;"); + } + @Test public void Quoted() { + fx .Raw_("a='1';").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "2")) + .tst_("a='2';"); + } + @Test public void EmbeddedQuote() { + fx .Raw_("a=1;").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "1'2")) + .tst_("a='1''2';"); + } + @Test public void ReuseQuote() { + fx .Raw_("a=|'1'|;").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "2")) + .tst_("a=|'2'|;"); + } + @Test public void ReuseQuoteWithEmbeddedQuote() { + fx .Raw_("a=|'1'2'|;").Update_(fx.atr_().NdeIdxs_(0).Atr_("a", "2'3")) + .tst_("a=|'2'3'|;"); + } +// @Test public void AtrIdx() { +// fx .Raw_("1;").Update_(fx.atr_().NdeIdxs_(0).AtrIdx_(0, "2")) +// .tst_("2;"); +// } +// @Test public void AtrIdx_parens() { +// fx .Raw_("A_('1');").Update_(fx.atr_().NdeIdxs_(0).AtrIdx_(0, "2")) +// .tst_("A_('2');"); +// } + @Test public void AddNew() { + fx .Raw_("a:;").Update_(fx.atr_().NdeIdxs_(0).Atr_("b", "1")) + .tst_("a:b='1';"); + } + @Test public void AddExisting() { + fx .Raw_("a='1';").Update_(fx.atr_().NdeIdxs_(0).Atr_("b", "2")) + .tst_("a='1' b='2';"); + } + @Test public void Add_many() { + fx .Raw_("a='1';").Update_(fx.atr_().NdeIdxs_(0).Atr_("b", "2")).Update_(fx.atr_().NdeIdxs_(0).Atr_("c", "3")) + .tst_("a='1' b='2' c='3';"); + } + @Test public void AddNode() { + fx .Raw_("a(){}").Update_(fx.nde_().NdeIdxs_(0).Nest_("b")) + .tst_("a(){b(){}}"); + } + @Test public void AddNodeMany() { + fx .Raw_("a(){}").Update_(fx.nde_().NdeIdxs_(0).Nest_("b")).Update_(fx.nde_().NdeIdxs_(0).Nest_("c")) + .tst_("a(){b(){}c(){}}"); + } + @Test public void EditNode() { + fx .Raw_("a(){b(){}}").Update_(fx.nde_().NdeIdxs_(0).Nest_("b")) + .tst_("a(){b(){}}"); + } +} +interface GfmlUpdateCmd { + void Exec(GfmlDoc gdoc); +} +class GfmlUpdateCmd_atr implements GfmlUpdateCmd { + public GfmlUpdateCmd_atr NdeIdxs_(int... v) {ndeIdxs = v; return this;} int[] ndeIdxs; + public GfmlUpdateCmd_atr Atr_(String key, String val) {atrKey = key; atrVal = val; return this;} String atrKey, atrVal; +// public GfmlUpdateCmd_atr AtrIdx_(int idx, String val) {atrIdx = idx; atrVal = val; return this;} int atrIdx = -1; + public void Exec(GfmlDoc gdoc) { + GfmlNde nde = GetNde(ndeIdxs, gdoc.RootNde()); + nde.UpdateAtr(atrKey, atrVal); +// GfmlAtr atr = atrIdx != -1 ? GfmlAtr.as_(nde.SubKeys().Get_at(atrIdx)) : GfmlAtr.as_(nde.SubKeys().Get_by(atrKey)); +// atr.UpdateAtr(atrKey, atrVal); + atrKey = ""; atrVal = "";//atrIdx = -1; + } + public static GfmlNde GetNde(int[] ndeIdxs, GfmlNde owner) { + GfmlNde nde = owner; + for (int i = 0; i < ndeIdxs.length; i++) { + int ndeIdx = ndeIdxs[i]; + nde = (GfmlNde)owner.SubHnds().Get_at(ndeIdx); + } + return nde; + } + public static GfmlUpdateCmd_atr new_() {return new GfmlUpdateCmd_atr();} GfmlUpdateCmd_atr() {} +} +class GfmlUpdateCmd_nde implements GfmlUpdateCmd { + public GfmlUpdateCmd_nde NdeIdxs_(int... v) {ndeIdxs = v; return this;} int[] ndeIdxs; + public GfmlUpdateCmd_nde Nest_(String hnd) {ndeHnd = hnd; return this;} String ndeHnd; + public void Exec(GfmlDoc gdoc) { + GfmlNde nde = GfmlUpdateCmd_atr.GetNde(ndeIdxs, gdoc.RootNde()); + nde.UpdateNde(ndeHnd); + ndeHnd = ""; + } + public static GfmlUpdateCmd_nde new_() {return new GfmlUpdateCmd_nde();} GfmlUpdateCmd_nde() {} +} +class GfmlUpdateFx { + public GfmlUpdateCmd_atr atr_() {return GfmlUpdateCmd_atr.new_();} + public GfmlUpdateCmd_nde nde_() {return GfmlUpdateCmd_nde.new_();} + public String Raw() {return raw;} public GfmlUpdateFx Raw_(String v) {raw = v; return this;} private String raw; + public GfmlUpdateFx Update_(GfmlUpdateCmd cmd) {cmds.Add(cmd); return this;} List_adp cmds = List_adp_.New(); + public GfmlUpdateFx tst_(String expd) { + GfmlDoc actlDoc = GfmlDataNde.new_any_eol_(raw).Doc(); + for (int i = 0; i < cmds.Count(); i++) { + GfmlUpdateCmd cmd = (GfmlUpdateCmd)cmds.Get_at(i); + cmd.Exec(actlDoc); + } + String actl = actlDoc.RootNde().To_str(); + Tfds.Eq(expd, actl); + cmds.Clear(); + return this; + } + public static GfmlUpdateFx new_() {return new GfmlUpdateFx();} GfmlUpdateFx() {} +} diff --git a/110_gfml/tst/gplx/gfml/z602_edit_nde_tst.java b/110_gfml/tst/gplx/gfml/z602_edit_nde_tst.java new file mode 100644 index 000000000..6f40114ee --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z602_edit_nde_tst.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z602_edit_nde_tst { + GfmlUpdateFx fx = GfmlUpdateFx.new_(); + @Test public void Basic() { + } +} diff --git a/110_gfml/tst/gplx/gfml/z801_useCase_DataRdr_tst.java b/110_gfml/tst/gplx/gfml/z801_useCase_DataRdr_tst.java new file mode 100644 index 000000000..7e7fc5f01 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z801_useCase_DataRdr_tst.java @@ -0,0 +1,79 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +import gplx.core.stores.*; +public class z801_useCase_DataRdr_tst { + String raw; + @Test public void Subs_byName() { + raw = String_.Concat + ( "_type:{" + , " item {" + , " point {" + , " x;" + , " y;" + , " }" + , " }" + , "}" + , "item:{" + , " 1 2;" + , "}" + ); + rdr = GfmlDataRdr.raw_root_(raw); + + subRdr = rdr.Subs_byName_moveFirst("point"); + fx_rdr.tst_Atrs(subRdr, kv_("x", "1"), kv_("y", "2")); + } +// @Test + public void Subs_byName3() { + raw = String_.Concat + ( "_type:{" + , " item {" + , " key" + , " point {" + , " x;" + , " y;" + , " }" + , " }" + , "}" + , "abc point=(1 2);" + ); + rdr = GfmlDataRdr.raw_root_(raw); + + subRdr = rdr.Subs_byName_moveFirst("point"); + fx_rdr.tst_Atrs(subRdr, kv_("x", "1"), kv_("y", "2")); + } + Keyval kv_(String key, Object val) {return Keyval_.new_(key, val);} + DataRdr_Fxt fx_rdr = DataRdr_Fxt.Instance; + DataRdr rdr, subRdr; +} +class DataRdr_Fxt { + @gplx.Internal protected DataRdr run_Subs_at(DataRdr rdr, int i) { + DataRdr rv = rdr.Subs(); + int count = -1; + while (count++ < i) { + rv.MoveNextPeer(); + } + return rv; + } + @gplx.Internal protected void tst_Atrs(DataRdr rdr, Keyval... expdAry) { + Keyval[] actlAry = new Keyval[rdr.FieldCount()]; + for (int i = 0; i < actlAry.length; i++) + actlAry[i] = rdr.KeyValAt(i); + Tfds.Eq_ary_str(expdAry, actlAry); + } + public static final DataRdr_Fxt Instance = new DataRdr_Fxt(); DataRdr_Fxt() {} +} diff --git a/110_gfml/tst/gplx/gfml/z803_useCase_KbdKeyboard_tst.java b/110_gfml/tst/gplx/gfml/z803_useCase_KbdKeyboard_tst.java new file mode 100644 index 000000000..00cece517 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z803_useCase_KbdKeyboard_tst.java @@ -0,0 +1,85 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z803_useCase_KbdKeyboard_tst { + String raw; GfmlDoc gdoc; + @Test public void Quote() { // smokeTest; make sure DefaultLxr supports both quoting mechanisms + fx.tst_Parse(String_.Concat + ( "gfui-keyboard-ui:{" + , " keyQuote {" + , " \"'\" 'key.quote';" + , " '\"' 'key.quote+key.shift' shift;" + , " }" + , "}" + ) + , fx.nde_().Hnd_("gfui-keyboard-ui").Subs_ + ( fx.nde_().Atru_("keyQuote").Subs_ + ( fx.nde_().Atrs_("'", "key.quote") + , fx.nde_().Atrs_("\"", "key.quote+key.shift", "shift") + ) + ) + ); + } + @Test public void Key_LtrA() { + fx.tst_Parse(String_.Concat + ( TypeHeader + , "keys:{" + , " keyA {" + , " a 'key.a';" + , " A 'key.a+key.shift' shift;" + , " }" + , "}" + ) + , fx.nde_().Hnd_("keys").Subs_ + ( fx.nde_().Hnd_("key").Typ_("keys/key").Atrk_("size", "48,45").Atrk_("relAnchor", "{previous},rightOf").Atrk_("id", "keyA").Subs_ + ( fx.nde_().Hnd_("sendKeyCode").Typ_("sendKeyCode").Atrk_("modifier", "normal").Atrk_("displayText", "a").Atrk_("keyCode", "key.a") + , fx.nde_().Hnd_("sendKeyCode").Typ_("sendKeyCode").Atrk_("displayText", "A").Atrk_("keyCode", "key.a+key.shift").Atrk_("modifier", "shift") + ) + ) + ); + } + @Test public void Load_Smoke() { + Io_url url = Tfds.RscDir.GenSubFil_nest("110_gfml", "cfgs_archive", "gfui-keyboard-ui.cfg.gfml"); + raw = Io_mgr.Instance.LoadFilStr(url); + gdoc = GfmlDoc_.parse_any_eol_(raw); +// Tfds.Write(gdoc.RootNde().To_str()); + } + String TypeHeader = String_.Concat + ( "_type:{" + , " keys {" + , " key {" + , " id;" + , " size default='48,45';" + , " relAnchor default='{previous},rightOf';" + , " sendKeyCode type=sendKeyCode;" + , " }" + , " }" + , " sendKeyCode {" + , " displayText;" + , " keyCode;" + , " modifier default=normal;" + , " }" + , " changeModifier {" + , " displayText;" + , " modifier default=normal;" + , " newModifierId;" + , " isSticky;" + , " }" + , "}" + ); + GfmlTypeCompiler_fxt fx = GfmlTypeCompiler_fxt.new_(); +} diff --git a/110_gfml/tst/gplx/gfml/z811_useCase_GfmlIoSql_tst.java b/110_gfml/tst/gplx/gfml/z811_useCase_GfmlIoSql_tst.java new file mode 100644 index 000000000..b4d61f33a --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z811_useCase_GfmlIoSql_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; +public class z811_useCase_GfmlIoSql_tst { + @Test public void Basic() { + tst_Doc("fld1=val1", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1")); + tst_Doc("fld1 = val1", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1")); + tst_Doc("fld1='val1'", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1")); + tst_Doc("fld1='val 1'", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val 1")); + } + @Test public void Basic2() { + tst_Doc("1=1 OR 2=2", nde_("fld").Atrs_add_("word", "1").Atrs_add_("op", "=").Atrs_add_("word", "1") + .Atrs_add_("word", "OR") + .Atrs_add_("word", "2").Atrs_add_("op", "=").Atrs_add_("word", "2") + ); + tst_Doc("(1=1)", nde_("fld").Atrs_add_("op", "(").Atrs_add_("word", "1").Atrs_add_("op", "=").Atrs_add_("word", "1") + .Atrs_add_("op", ")") + ); + } + void tst_Doc(String raw, GfmlNdeWrapper expd) { + GfmlDoc doc = SqlDoc.XtoDoc(raw); + GfmlNde actl = (GfmlNde)doc.RootNde(); + Tfds.Eq_ary_str(To_str(expd.Nde()), To_str(actl)); + } + String[] To_str(GfmlNde nde) { + List_adp list = List_adp_.New(); + for (int i = 0; i < nde.SubObjs_Count(); i++) { + GfmlAtr atr = (GfmlAtr)nde.SubObjs_GetAt(i); + list.Add(atr.Key() + "=" + atr.DatTkn().Raw()); + } + return list.To_str_ary(); + } + GfmlNdeWrapper nde_(String name) {return GfmlNdeWrapper.new_().Name_(name);} +} diff --git a/110_gfml/tst/gplx/gfml/z901_perf_tst.java b/110_gfml/tst/gplx/gfml/z901_perf_tst.java new file mode 100644 index 000000000..a26387e91 --- /dev/null +++ b/110_gfml/tst/gplx/gfml/z901_perf_tst.java @@ -0,0 +1,115 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfml; import gplx.*; +import org.junit.*; import gplx.core.strings.*; import gplx.core.envs.*; +public class z901_perf_tst { + TimerWatch tmr = TimerWatch.new_(); + @Test public void EmptyTestSoJunitWillNotFail() {} +// @Test + public void Long() { +// String longText = String_.Repeat("a", 30 * 1000 * 1000); + String longText = Io_mgr.Instance.LoadFilStr(Io_url_.new_any_("C:\\core_weekly.temp.gfio")); +// String_bldr sbXml = String_bldr_.new_(); +// sbXml.Add("<"); +// sbXml.Add(longText); +// sbXml.Add("/>"); +// tmr.Bgn(); +// gplx.langs.xmls.XmlDoc_.parse(sbXml.To_str()); +// tmr.End_and_print("xml"); // 400 + + String_bldr sbGfml = String_bldr_.new_(); + for (int i = 0; i < 10; i++) { + sbGfml.Add(longText); +// sbGfml.Add(longText); +// sbGfml.Add(longText); +// sbGfml.Add(longText); + } +// tmr.Bgn(); +// gplx.core.texts.CharStream.pos0_(sbGfml.To_str()); +// tmr.End_and_print("char"); // 1700 + + tmr.Bgn(); + GfmlDoc_.parse_any_eol_(sbGfml.To_str()); + tmr.End_and_print("gfml"); // 1700 + } + //@Test + public void Prop() { + int max = 100 * 1000 * 1000; + PerfFieldVsProc c = new PerfFieldVsProc(); + int v = 0; + tmr.Bgn(); + for (int i = 0; i < max; i++) + v = member; + tmr.End_and_print("member"); + tmr.Bgn(); + for (int i = 0; i < max; i++) + v = c.Val_field; + tmr.End_and_print("field"); + tmr.Bgn(); + for (int i = 0; i < max; i++) + v = c.Val_proc(); + tmr.End_and_print("proc"); + Tfds.Write(v); + } +// @Test +// public void ClassComp() { +// int max = 100 * 1000 * 1000; +// ClassType ct = new ClassType3(); +// long v = 0; +// // 2625 CS, 718 JAVA +// tmr.Bgn(); +// for (int i = 0; i < max; i++) { +// if (ct.Type() == ClassType_.Type_1) v += 1; +// else if (ct.Type() == ClassType_.Type_2) v += 2; +// else if (ct.Type() == ClassType_.Type_3) v += 3; +// } +// tmr.End_and_print("var"); +// v = 0; +// // 12437 CS, 578 JAVA +// tmr.Bgn(); +// for (int i = 0; i < max; i++) { +// Class type = ct.getClass(); +// if (type == typeof(ClassType1)) v += 1; +// else if (type == typeof(ClassType2)) v += 2; +// else if (type == typeof(ClassType3)) v += 3; +// } +// tmr.End_and_print("type"); +// } + interface ClassType {int Type();} + class ClassType_ {public static final int Type_1 = 1, Type_2 = 2, Type_3 = 3;} + class ClassType1 implements ClassType {public int Type() {return ClassType_.Type_1;}} + class ClassType2 implements ClassType {public int Type() {return ClassType_.Type_2;}} + class ClassType3 implements ClassType {public int Type() {return ClassType_.Type_3;}} + int member = 1; +} +class PerfFieldVsProc { + public int Val_field = 1; + public int Val_proc() {return 1;} +} +class TimerWatch { + public void Bgn() {bgnTime = System_.Ticks();} long bgnTime; + public void End() {duration = System_.Ticks() - bgnTime;} long duration; + public void End_and_print(String text) { + this.End(); + Tfds.Write(XtoStr_ms() + " " + text); + } + public String XtoStr_ms() {return Long_.To_str(duration);} + public static TimerWatch new_() { + TimerWatch rv = new TimerWatch(); + rv.Bgn(); + return rv; + } TimerWatch() {} +} diff --git a/140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java b/140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java new file mode 100644 index 000000000..b48a42026 --- /dev/null +++ b/140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java @@ -0,0 +1,138 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.stores; import gplx.*; import gplx.core.*; +import org.junit.*; +import gplx.dbs.*; /*Db_conn_info*/ +public class DbMaprMgr_tst { + @Before public void setup() { + mgr = DbMaprMgr.new_().RootIndexFlds_(DbMaprArg.new_("id", "disc_id")) + .Root_ + ( DbMaprItm.proto_(MockDisc.Instance, "discs", "mock_discs") + . Flds_add(MockDisc.id_idk, "disc_id").Flds_add(MockDisc.name_idk, "disc_name") + . ContextFlds_add(MockDisc.id_idk).Subs_add + ( DbMaprItm.proto_(MockTitle.Instance, "titles", "mock_titles") + . Flds_add(MockTitle.id_idk, "title_id").Flds_add(MockTitle.name_idk, "title_name") + . ContextFlds_add(MockTitle.id_idk).Subs_add + ( DbMaprItm.proto_(MockChapter.Instance, "chapters", "mock_chapters") + . Flds_add(MockChapter.id_idk, "chapter_id").Flds_add(MockChapter.name_idk, "chapter_name") + , DbMaprItm.proto_(MockStream.Instance, "audios", "mock_streams") + . Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name") + . ConstantFlds_add("stream_type", 0) + , DbMaprItm.proto_(MockStream.Instance, "subtitles", "mock_streams") + . Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name") + . ConstantFlds_add("stream_type", 1) + ))); + wtr = DbMaprWtr.new_by_url_(Db_conn_info_.Test); + wtr.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr); + conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.Test); + Db_qry_fxt.DeleteAll(conn, "mock_discs", "mock_titles", "mock_chapters", "mock_streams"); + } DbMaprMgr mgr; DbMaprWtr wtr; Db_conn conn; MockDisc disc; MockTitle title; MockChapter chapter; MockStream audio, subtitle; SrlMgr rdr; + @Test public void PurgeObjTree() { + disc = MockDisc.new_().Id_(1); + Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1)); + DbMaprWtrUtl.PurgeObjTree(disc, mgr, conn); + Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_discs")); + } + @Test public void PurgeObjTree_deep() { + disc = MockDisc.new_().Id_(1); + Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1)); + Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1)); + Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 2).Add("chapter_id", 3)); + Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 2).Add("title_id", 2).Add("chapter_id", 3)); + DbMaprWtrUtl.PurgeObjTree(disc, mgr, conn); + + Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_discs")); + Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_titles")); + Tfds.Eq(1, Db_qry_fxt.SelectAll_count(conn, "mock_chapters")); // ignore chapter with disc_id=2 + } + @Test public void Save_root() { + disc = MockDisc.new_().Id_(1).Name_("disc"); + + wtr.StoreRoot(disc, "mock_discs"); + Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc")); + } + @Test public void Save_subs() { + disc = MockDisc.new_().Id_(1).Name_("disc"); + title = MockTitle.new_().Id_(2).Name_("title").Disc_(disc); + + wtr.StoreRoot(disc, "mock_discs"); + Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc")); + Db_qry_fxt.tst_Select(conn, "mock_titles", Db_mock_row.vals_only_(1, 2, "title")); + } + @Test public void Save_deep() { + disc = MockDisc.new_().Id_(1).Name_("disc"); + title = MockTitle.new_().Id_(2).Name_("title").Disc_(disc); + chapter = MockChapter.new_().Id_(3).Name_("chap").Title_(title); + audio = MockStream.new_().Id_(4).Name_("audio").Title_(title.Audios()); + subtitle = MockStream.new_().Id_(5).Name_("subtitle").Title_(title.Subtitles()); + + wtr.StoreRoot(disc, "mock_discs"); + Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc")); + Db_qry_fxt.tst_Select(conn, "mock_titles", Db_mock_row.vals_only_(1, 2, "title")); + Db_qry_fxt.tst_Select(conn, "mock_chapters", Db_mock_row.vals_only_(1, 2, 3, "chap")); + Db_qry_fxt.tst_Select(conn, "mock_streams" + , Db_mock_row.vals_only_(1, 2, null, 4, "audio") + , Db_mock_row.vals_only_(1, 2, null, 5, "subtitle") + ); + } + @Test public void Load_root() { + rdr = rdr_(); + Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name")); + disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null); + + Tfds.Eq(1, disc.Id()); + Tfds.Eq("name", disc.Name()); + Tfds.Eq(0, disc.Titles().Count()); + } + @Test public void Load_subs() { + rdr = rdr_(); + Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name")); + Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("title_name", "title1")); + Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 2).Add("title_name", "title2")); + disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null); + + Tfds.Eq(1, disc.Id()); + Tfds.Eq("name", disc.Name()); + Tfds.Eq(2, disc.Titles().Count()); + Tfds.Eq("title1", ((MockTitle)disc.Titles().Get_at(0)).Name()); + Tfds.Eq("title2", ((MockTitle)disc.Titles().Get_at(1)).Name()); + } + @Test public void Load_deep() { + rdr = rdr_(); + Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name")); + Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("title_name", "title1")); + Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("chapter_id", 3).Add("chapter_name", "chapter1")); + Db_qry_fxt.Insert_kvo(conn, "mock_streams", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("stream_id", 4).Add("stream_type", 0).Add("stream_name", "audio1")); + Db_qry_fxt.Insert_kvo(conn, "mock_streams", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("stream_id", 5).Add("stream_type", 1).Add("stream_name", "subtitle1")); + disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null); + + Tfds.Eq(1, disc.Id()); + Tfds.Eq("name", disc.Name()); + Tfds.Eq(1, disc.Titles().Count()); + MockTitle t = ((MockTitle)disc.Titles().Get_at(0)); + Tfds.Eq("title1", t.Name()); + Tfds.Eq("chapter1", ((MockChapter)t.Chapters().Get_at(0)).Name()); + Tfds.Eq(1, t.Audios().Count()); + Tfds.Eq(1, t.Subtitles().Count()); + Tfds.Eq("audio1", ((MockStream)t.Audios().Get_at(0)).Name()); + Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().Get_at(0)).Name()); + } + DbMaprRdr rdr_() { + DbMaprRdr rv = DbMaprRdr.new_(Db_conn_info_.Test, Db_crt_.New_eq("disc_id", 1)); + rv.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr); + return rv; + } +} diff --git a/140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java b/140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java new file mode 100644 index 000000000..59a73fe0f --- /dev/null +++ b/140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs; import gplx.*; +import org.junit.*; import gplx.core.tests.*; import gplx.dbs.qrys.*; +public class Db_attach_mgr__tst { + private final Db_attach_mgr__fxt fxt = new Db_attach_mgr__fxt(); + @Test public void Basic() { + Db_qry__select_cmd qry = Db_qry_.select_() + .Cols_w_tbl_("t1", "fld_1") + .Cols_w_tbl_("t2", "fld_2") + .Cols_w_tbl_("t3", "fld_3") + .From_("db_1", "tbl_1", "t1") + .Join_("db_2", "tbl_2", "t2", Db_qry_.New_join__same("t1", "fld_2")) + .Join_("db_3", "tbl_3", "t3", Db_qry_.New_join__same("t1", "fld_3")) + .Join_( "tbl_4", "t4", Db_qry_.New_join__same("t1", "fld_4")) + ; + fxt.Init("db_2", fxt.Make__other("db_1"), fxt.Make__other("db_2"), fxt.Make__other("db_3")); + fxt.Test__make_stmt_and_attach(qry + , "SELECT t1.fld_1, t2.fld_2, t3.fld_3 " + + "FROM db_1.tbl_1 t1 " + + "INNER JOIN tbl_2 t2 ON t1.fld_2 = t2.fld_2 " // NOTE: curr is db_2 so do not prefix tbl_2 with db_2; fails if "db_2.tbl_2" + + "INNER JOIN db_3.tbl_3 t3 ON t1.fld_3 = t3.fld_3 " + + "INNER JOIN tbl_4 t4 ON t1.fld_4 = t4.fld_4" + , String_.Ary("db_1", "db_3") // NOTE: no "db_2" + ); + } +} +class Db_attach_mgr__fxt { + private Db_attach_mgr mgr; + public Db_attach_mgr__fxt() { + Db_conn_bldr.Instance.Reg_default_mem(); + } + public Db_conn Make__conn(String key) {return Db_conn_bldr.Instance.New(Io_url_.mem_fil_(key));} + public Db_attach_itm Make__other(String key) {return new Db_attach_itm(key, Io_url_.mem_fil_("mem/" + key));} + public void Init(String conn_key, Db_attach_itm... ary) { + Db_conn conn = Make__conn(conn_key); + mgr = new Db_attach_mgr(conn, ary); + } + public void Test__make_stmt_and_attach(Db_qry__select_cmd qry, String expd_sql, String[] expd_dbs) { + mgr.Test__make_stmt_and_attach(qry, qry.From()); + Gftest.Eq__str(expd_sql, mgr.Test__attach_sql()); + Gftest.Eq__ary(expd_dbs, mgr.Test__attach_list_keys()); + } +} diff --git a/140_dbs/src/gplx/dbs/Db_conn_info_tst.java b/140_dbs/src/gplx/dbs/Db_conn_info_tst.java new file mode 100644 index 000000000..0404c2f70 --- /dev/null +++ b/140_dbs/src/gplx/dbs/Db_conn_info_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs; import gplx.*; +import org.junit.*; +public class Db_conn_info_tst { + @Before public void setup() { + regy.Add(Db_conn_info_mock.Instance); + } private final Db_conn_info_pool regy = new Db_conn_info_pool(); + @Test public void Parse() { + tst_Parse("gplx_key=mock;id=1;", kv_("id", "1")); // one; gplx_key removed + tst_Parse("gplx_key=mock;id=1;name=me;", kv_("id", "1"), kv_("name", "me")); // many + tst_Parse("gplx_key=mock;id=1;name=me" , kv_("id", "1"), kv_("name", "me")); // no semi-colon at end + } + private Keyval kv_(String key, Object val) {return Keyval_.new_(key, val);} + private void tst_Parse(String raw, Keyval... expd) { + Db_conn_info_mock mock = (Db_conn_info_mock)regy.Parse(raw); + Tfds.Eq_ary_str(expd, mock.Kvs()); + } +} +class Db_conn_info_mock extends Db_conn_info__base { + public Db_conn_info_mock(String raw, String db_api, String database) {super(raw, db_api, database);} + public Keyval[] Kvs() {return kvs;} Keyval[] kvs; + @Override public String Key() {return Tid_const;} public static final String Tid_const = "mock"; + @Override public Db_conn_info New_self(String raw, Keyval_hash hash) { + Db_conn_info_mock rv = new Db_conn_info_mock("", "", ""); + int len = hash.Count(); + rv.kvs = new Keyval[len]; + for (int i = 0; i < len; ++i) + rv.kvs[i] = hash.Get_at(i); + return rv; + } + public static final Db_conn_info_mock Instance = new Db_conn_info_mock("", "", ""); +} diff --git a/140_dbs/src/gplx/dbs/Db_crt_tst.java b/140_dbs/src/gplx/dbs/Db_crt_tst.java new file mode 100644 index 000000000..a73ad6a2e --- /dev/null +++ b/140_dbs/src/gplx/dbs/Db_crt_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs; import gplx.*; +import org.junit.*; import gplx.core.criterias.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*; +public class Db_crt_tst { + @Before public void setup() { + row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), Object_.Ary(1, "me")); + } + @Test public void EqualTest() { + crt = Db_crt_.New_eq("id", 1); + tst_Match(true, row, crt); + } + @Test public void EqualFalseTest() { + crt = Db_crt_.New_eq("id", 2); + tst_Match(false, row, crt); + } + @Test public void AndCompositeTest() { + crt = Criteria_.And(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "me")); + tst_Match(true, row, crt); + + crt = Criteria_.And(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "you")); + tst_Match(false, row, crt); + } + @Test public void OrCompositeTest() { + crt = Criteria_.Or(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "you")); + tst_Match(true, row, crt); + + crt = Criteria_.Or(Db_crt_.New_eq("id", 2), Db_crt_.New_eq("name", "you")); + tst_Match(false, row, crt); + } + + void tst_Match(boolean epxd, GfoNde row, Criteria crt) { + boolean actl = crt.Matches(row); + Tfds.Eq(epxd, actl); + } + GfoNde row; Criteria crt; +} diff --git a/140_dbs/src/gplx/dbs/Db_qry_fxt.java b/140_dbs/src/gplx/dbs/Db_qry_fxt.java new file mode 100644 index 000000000..b2c4737e7 --- /dev/null +++ b/140_dbs/src/gplx/dbs/Db_qry_fxt.java @@ -0,0 +1,65 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs; import gplx.*; +import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*; +public class Db_qry_fxt { + public static void Insert_kvo(Db_conn conn, String tblName, Keyval_list kvList) { + Db_qry_insert qry = Db_qry_.insert_(tblName); + for (int i = 0; i < kvList.Count(); i++) { + Keyval kv = kvList.Get_at(i); + qry.Val_obj(kv.Key(), kv.Val()); + } + qry.Exec_qry(conn); + } + public static GfoNde SelectAll(Db_conn conn, String tblName) { + return Db_qry_.Exec_as_nde(conn, Db_qry_.select_tbl_(tblName)); + } + public static int SelectAll_count(Db_conn conn, String tblName) { + GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName); + return nde.Subs().Count(); + } + public static void DeleteAll(Db_conn conn, String... ary) { + for (String s : ary) + Db_qry_.delete_tbl_(s).Exec_qry(conn); + } + public static void tst_Select(Db_conn conn, String tblName, Db_mock_row... expdAry) { + GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName); + int len = Array_.Len(expdAry); + for (int i = 0; i < len; i++) { + Db_mock_row expdRow = expdAry[i]; + int actlIdx = (expdRow.Idx() == -1) ? i : expdRow.Idx(); + GfoNde actlNde = nde.Subs().FetchAt_asGfoNde(actlIdx); + int fldLen = Array_.Len(expdRow.Dat()); + for (int j = 0; j < fldLen; j++) { + Db_mock_cell expdDat = expdRow.Dat()[j]; + Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld()); + Tfds.Eq(expdDat.Val(), actlVal); + } + } + } + public static String Db__print_tbl_as_str(Bry_bfr bfr, Db_conn conn, String tbl, String... cols) { + int cols_len = cols.length; + Db_rdr rdr = conn.Stmt_select(tbl, cols).Exec_select__rls_auto(); + while (rdr.Move_next()) { + for (int i = 0; i < cols_len; ++i) { + bfr.Add_obj(rdr.Read_at(i)); + bfr.Add_byte(i == cols_len - 1 ? Byte_ascii.Nl : Byte_ascii.Pipe); + } + } + rdr.Rls(); + return bfr.To_str_and_clear(); + } +} diff --git a/140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java b/140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java new file mode 100644 index 000000000..71194e0a2 --- /dev/null +++ b/140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java @@ -0,0 +1,105 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*; +import org.junit.*; +import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.dbs.engines.mems.*; +public class Gfdb_diff_bldr_tst { + private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Same() { + fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B")); + fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B")); + fxt.Test__bld(); + } + @Test public void Update() { + fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B")); + fxt.Init__tbl__cur(Object_.Ary(1, "A1") , Object_.Ary(2, "B1")); + fxt.Test__bld("U|1|A1", "U|2|B1"); + } + @Test public void Insert() { + fxt.Init__tbl__old(Object_.Ary(1, "A")); + fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B")); + fxt.Test__bld("I|2|B"); + } + @Test public void Delete() { + fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B")); + fxt.Init__tbl__cur(Object_.Ary(1, "A")); + fxt.Test__bld("D|2"); + } + @Test public void Basic() { + fxt.Init__tbl__old + ( Object_.Ary(1, "A") + , Object_.Ary(2, "B") + , Object_.Ary(3, "C") + ); + fxt.Init__tbl__cur + ( Object_.Ary(1, "A") + , Object_.Ary(2, "B1") + , Object_.Ary(4, "D") + ); + fxt.Test__bld("U|2|B1", "D|3", "I|4|D"); + } +} +class Gfdb_diff_bldr_fxt { + private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr(); + private final Db_conn old_conn, new_conn; + private final Gfdb_diff_tbl tbl; + private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test(); + private final Dbmeta_fld_itm[] flds_ary; + private final String tbl_name = "tbl"; + private final Gdif_bldr_ctx ctx = new Gdif_bldr_ctx(); + public Gfdb_diff_bldr_fxt() { + old_conn = Db_conn_utl.Conn__new("old_db"); + new_conn = Db_conn_utl.Conn__new("new_db"); + this.flds_ary = new Dbmeta_fld_itm[] {Dbmeta_fld_itm.new_int("id").Primary_y_(), Dbmeta_fld_itm.new_str("val", 255)}; + tbl = Gfdb_diff_tbl.New(Dbmeta_tbl_itm.New(tbl_name, flds_ary)); + bldr.Init(wkr); + } + public void Clear() { + ctx.Clear(); + old_conn.Meta_tbl_delete("tbl"); + new_conn.Meta_tbl_delete("tbl"); + } + public void Init__tbl__old(Object[]... rows) {Db_conn_utl.Tbl__new(old_conn, "tbl", flds_ary, rows);} + public void Init__tbl__cur(Object[]... rows) {Db_conn_utl.Tbl__new(new_conn, "tbl", flds_ary, rows);} + public void Test__bld(String... expd) { + bldr.Compare(ctx, tbl, old_conn, new_conn); + Tfds.Eq_ary_str(expd, wkr.To_str_ary()); + } +} +class Gfdb_diff_wkr__test implements Gfdb_diff_wkr { + private final List_adp list = List_adp_.New(); + private final Bry_bfr bfr = Bry_bfr_.New(); + private Db_rdr old_rdr, new_rdr; + public void Init_rdrs(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) { + this.old_rdr = old_rdr; this.new_rdr = new_rdr; + } + public void Term_tbls() {} + public void Handle_same() { + String old_val = old_rdr.Read_str("val"); + String new_val = new_rdr.Read_str("val"); + if (!String_.Eq(old_val, new_val)) + list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear()); + } + public void Handle_old_missing() { + String new_val = new_rdr.Read_str("val"); + list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(new_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear()); + } + public void Handle_new_missing() { + list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).To_str_and_clear()); + } + public String[] To_str_ary() {return list.To_str_ary_and_clear();} +} diff --git a/140_dbs/src/gplx/dbs/diffs/cmds/Gfdb_diff_cmd_sql_bldr_tst.java b/140_dbs/src/gplx/dbs/diffs/cmds/Gfdb_diff_cmd_sql_bldr_tst.java new file mode 100644 index 000000000..ee7881039 --- /dev/null +++ b/140_dbs/src/gplx/dbs/diffs/cmds/Gfdb_diff_cmd_sql_bldr_tst.java @@ -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.dbs.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*; +import org.junit.*; +import gplx.dbs.*; import gplx.dbs.engines.mems.*; +public class Gfdb_diff_cmd_sql_bldr_tst { + private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt(); + @Test public void Insert() { + fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last + ( "INSERT INTO db_curr.tbl1" + , "SELECT d.key1, d.key2, d.fld1, d.fld2" + , "FROM db_temp.tbl1_pkey k" + , " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2" + , "WHERE k.diff_type = 1" + , "AND k.diff_uid BETWEEN 0 AND 99;" + )); + } + @Test public void Update() { + fxt.Test__update("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last + ( "REPLACE INTO db_curr.tbl1" + , "SELECT d.key1, d.key2, d.fld1, d.fld2" + , "FROM db_temp.tbl1_pkey k" + , " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2" + , "WHERE k.diff_type = 2" + , "AND k.diff_uid BETWEEN 0 AND 99;" + )); + } + @Test public void Delete() { + fxt.Test__delete("tbl1", String_.Ary("key1", "key2"), 0, 99, String_.Concat_lines_nl_skip_last + ( "DELETE db_curr.tbl1" + , "WHERE key1 || '|' || key2 IN" + , "( SELECT k.key1 || '|' || k.key2" + , " FROM db_temp.tbl1_pkey k" + , " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2" + , " WHERE k.diff_type = 0" + , " AND k.diff_uid BETWEEN 0 AND 99" + , ");" + )); + } +} +class Gfdb_diff_cmd_sql_bldr_fxt { + private Gfdb_diff_cmd_sql_bldr bldr = new Gfdb_diff_cmd_sql_bldr(); + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Test__insert(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) { + bldr.Bld_insert(bfr, tbl_name, keys, flds, 0, 99); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + public void Test__update(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) { + bldr.Bld_update(bfr, tbl_name, keys, flds, 0, 99); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + public void Test__delete(String tbl_name, String[] keys, int rng_bgn, int rng_end, String expd) { + bldr.Bld_delete(bfr, tbl_name, keys, 0, 99); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java b/140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java new file mode 100644 index 000000000..fcf1ac04a --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +class Mem_db_fxt { + public Mem_db_fxt() { + Io_mgr.Instance.InitEngine_mem(); + Db_conn_bldr.Instance.Reg_default_mem(); + } + public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));} + public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) { + Dbmeta_fld_list flds = new Dbmeta_fld_list(); + int len = fld_names.length; + for (int i = 0; i < len; ++i) + flds.Add_str(fld_names[i], 255); + Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(tbl, flds); + conn.Meta_tbl_create(rv); + return rv; + } + public void Exec__insert(Db_conn conn, String tbl_name, String[]... rows) { + Mem_engine engine = (Mem_engine)conn.Engine(); + int rows_len = rows.length; + Mem_tbl tbl = engine.Tbls__get(tbl_name); + Dbmeta_fld_list flds_list = tbl.Meta().Flds().To_fld_list(); + int flds_len = flds_list.Len(); + Db_stmt stmt = conn.Stmt_insert(tbl_name, flds_list); + for (int i = 0; i < rows_len; ++i) { + stmt.Clear(); + String[] row = rows[i]; + for (int j = 0; j < flds_len; ++j) + stmt.Val_str(flds_list.Get_at(j).Name(), row[j]); + stmt.Exec_insert(); + } + } + public void Test__select(Db_conn conn, Db_qry qry, String[]... expd) { + Db_stmt stmt = conn.Stmt_new(qry); + Db_rdr rdr = new Mem_exec_select((Mem_engine)conn.Engine()).Select((Mem_stmt)stmt); + List_adp actl_list = List_adp_.New(); + Bry_bfr tmp_bfr = Bry_bfr_.New(); + int expd_len = expd.length; + String[] expd_rows = new String[expd_len]; + for (int i = 0; i < expd_len; ++i) { + String[] expd_row = expd[i]; + for (int j = 0; j < expd_row.length; ++j) { + if (j != 0) tmp_bfr.Add_byte_pipe(); + tmp_bfr.Add_str_u8(expd_row[j]); + } + expd_rows[i] = tmp_bfr.To_str_and_clear(); + } + while (rdr.Move_next()) { + int fld_len = rdr.Fld_len(); + for (int i = 0; i < fld_len; ++i) { + if (i != 0) tmp_bfr.Add_byte_pipe(); + tmp_bfr.Add_obj_strict(rdr.Read_at(i)); + } + actl_list.Add(tmp_bfr.To_str_and_clear()); + } + Tfds.Eq_ary(expd_rows, (String[])actl_list.To_ary_and_clear(String.class)); + } +} diff --git a/140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java b/140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java new file mode 100644 index 000000000..560c112fe --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java @@ -0,0 +1,128 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +import org.junit.*; import gplx.dbs.sqls.itms.*; +public class Mem_exec_select_tst { + private final Mem_db_fxt__single fxt = new Mem_db_fxt__single(); + @Test public void Basic() { + fxt.Exec__create_tbl("tbl_1", "fld_1"); + fxt.Exec__insert("tbl_1" + , String_.Ary("a_1") + , String_.Ary("a_2") + , String_.Ary("a_0") + ); + + // select all + fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_() + , String_.Ary("a_1") + , String_.Ary("a_2") + , String_.Ary("a_0") + ); + + // order by + fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", Bool_.N) + , String_.Ary("a_2") + , String_.Ary("a_1") + , String_.Ary("a_0") + ); + + // offset + fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Offset_(1) + , String_.Ary("a_2") + , String_.Ary("a_0") + ); + + // limit + fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Limit_(2) + , String_.Ary("a_1") + , String_.Ary("a_2") + ); + } + @Test public void Join__single() { + fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a"); + fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a"); + fxt.Exec__insert("tbl_1" + , String_.Ary("a_0", "1a_0") + , String_.Ary("a_1", "1a_1") + , String_.Ary("a_2", "1a_2") + ); + fxt.Exec__insert("tbl_2" + , String_.Ary("a_0", "2a_0") + , String_.Ary("a_2", "2a_2") + ); + + // inner join + fxt.Test__select(Db_qry_.select_() + .Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a") + .From_("tbl_1", "t1") + . Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a")) + , String_.Ary("a_0", "1a_0", "2a_0") + , String_.Ary("a_2", "1a_2", "2a_2") + ); + + // left join + fxt.Test__select(Db_qry_.select_() + .Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a") + .From_("tbl_1", "t1") + . Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a")) + , String_.Ary("a_0", "1a_0", "2a_0") + , String_.Ary("a_1", "1a_1", Db_null.Null_str) + , String_.Ary("a_2", "1a_2", "2a_2") + ); + } + @Test public void Join__many() { + fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a"); + fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a"); + fxt.Exec__insert("tbl_1" + , String_.Ary("a_0", "1a_0") + , String_.Ary("a_1", "1a_1") + ); + fxt.Exec__insert("tbl_2" + , String_.Ary("a_0", "2a_0") + , String_.Ary("a_0", "2a_1") + ); + + // inner join + fxt.Test__select(Db_qry_.select_() + .Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a") + .From_("tbl_1", "t1") + . Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a")) + , String_.Ary("a_0", "1a_0", "2a_0") + , String_.Ary("a_0", "1a_0", "2a_1") + ); + + // left join + fxt.Test__select(Db_qry_.select_() + .Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a") + .From_("tbl_1", "t1") + . Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a")) + , String_.Ary("a_0", "1a_0", "2a_0") + , String_.Ary("a_0", "1a_0", "2a_1") + , String_.Ary("a_1", "1a_1", Db_null.Null_str) + ); + } +} +class Mem_db_fxt__single { + private final Mem_db_fxt mem_fxt; + private final Db_conn conn; + public Mem_db_fxt__single() { + this.mem_fxt = new Mem_db_fxt(); + this.conn = mem_fxt.Make_conn("mem/test.db"); + } + public void Exec__create_tbl (String tbl, String... fld_names) {mem_fxt.Exec__create_tbl(conn, tbl, fld_names);} + public void Exec__insert (String tbl, String[]... rows) {mem_fxt.Exec__insert(conn, tbl, rows);} + public void Test__select (Db_qry qry, String[]... expd) {mem_fxt.Test__select(conn, qry, expd);} +} diff --git a/140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java b/140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java new file mode 100644 index 000000000..bf1271142 --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +import org.junit.*; +public class TdbConnectInfo_tst { + @Test public void Full() { + Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;"); + tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv"); + } + @Test public void DefaultFormat() { + Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred + tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv"); + } + void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) { + Tfds.Eq(((Tdb_conn_info)connectInfo).Url(), url); + } +} diff --git a/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java b/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java new file mode 100644 index 000000000..ebea35470 --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java @@ -0,0 +1,99 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*; +import gplx.core.stores.*; /*DsvDataRdr*/ import gplx.langs.dsvs.*; /*DsvDataWtr*/ +public class TdbDbLoadMgr_tst { + @Before public void setup() { + Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv"); + db = TdbDatabase.new_(dbInfo); + wtr = DsvDataWtr_.new_(); + } + TdbDatabase db; TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); + DataRdr rdr; DataWtr wtr; + @Test public void ReadDbFiles() { + String raw = String_.Concat_lines_crlf + ( "=======DIF======================, ,\" \",//" + , "_files, ,\" \",#" + , "==DEF==DIF======================, ,\" \",//" + , "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$" + , "id,url,format, ,\" \",@" + , "==DATA=DIF======================, ,\" \",//" + , "1,mem/dir/db0.dsv,dsv" + , "2,C:\\file.dsv,dsv" + ); + rdr = rdr_(raw); + + db.Files().DataObj_Rdr(rdr); + Tfds.Eq(db.Files().Count(), 2); + TdbFile file2 = db.Files().Get_by_or_fail(2); + Tfds.Eq(file2.Path().Raw(), "C:\\file.dsv"); + + db.Files().DataObj_Wtr(wtr); + Tfds.Eq(wtr.To_str(), raw); + } + @Test public void ReadDbTbls() { + String raw = String_.Concat_lines_crlf + ( "=======DIF======================, ,\" \",//" + , "_tables, ,\" \",#" + , "==DEF==DIF======================, ,\" \",//" + , "int," + StringClassXtn.Key_const + ",int, ,\" \",$" + , "id,name,file_id, ,\" \",@" + , "==DATA=DIF======================, ,\" \",//" + , "1,tbl1,1" + ); + rdr = rdr_(raw); + + db.Tables().DataObj_Rdr(rdr, db.Files()); + Tfds.Eq(db.Tables().Count(), 1); + TdbTable table = db.Tables().Get_by_or_fail("tbl1"); + Tfds.Eq(table.Name(), "tbl1"); + Tfds.Eq(table.File().Id(), 1); + + db.Tables().DataObj_Wtr(wtr); + Tfds.Eq(wtr.To_str(), raw); + } + @Test public void ReadTbl() { + String raw = String_.Concat_lines_crlf + ( "=======DIF======================, ,\" \",//" + , "tbl0, ,\" \",#" + , "==DEF==DIF======================, ,\" \",//" + , "int," + StringClassXtn.Key_const + ", ,\" \",$" + , "id,name, ,\" \",@" + , "==DATA=DIF======================, ,\" \",//" + , "0,me" + ); + rdr = rdr_(raw); + + db.MakeTbl("tbl0", TdbFile.MainFileId); + db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr); + Tfds.Eq(db.Tables().Count(), 1); + TdbTable tbl = db.Tables().Get_by_or_fail("tbl0"); + Tfds.Eq(tbl.Rows().Count(), 1); + + GfoNde row = tbl.Rows().FetchAt_asGfoNde(0); + Tfds.Eq(row.Read("id"), 0); + Tfds.Eq(row.Read("name"), "me"); + + tbl.DataObj_Wtr(wtr); + Tfds.Eq(wtr.To_str(), raw); + } + DataRdr rdr_(String raw) { + DataRdr rdr = DsvDataRdr_.dsv_(raw); + rdr.MoveNextPeer(); // must move next as cur is not set and ReadProcs assume cur is set + return rdr; + } +} diff --git a/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java b/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java new file mode 100644 index 000000000..4f004beb1 --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java @@ -0,0 +1,75 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +import org.junit.*; import gplx.core.stores.*; +import gplx.langs.dsvs.*; import gplx.core.type_xtns.*; +public class TdbDbSaveMgr_tst { + @Before public void setup() { + Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv"); + db = TdbDatabase.new_(dbInfo); + wtr.Clear(); + } TdbDatabase db; TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); DataWtr wtr = DsvDataWtr_.new_(); + @Test public void WriteDbFils() { + String expd = String_.Concat_lines_crlf + ( "" + , "" + , "================================, ,\" \",//" + , "_files, ,\" \",#" + , "================================, ,\" \",//" + , "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$" + , "id,url,format, ,\" \",@" + , "================================, ,\" \",//" + , "1,mem/dir/db0.dsv,dsv" + ); + db.Files().DataObj_Wtr(wtr); + String actl = wtr.To_str(); + Tfds.Eq(expd, actl); + } + @Test public void WriteDbTbls() { + String expd = String_.Concat_lines_crlf + ( "" + , "" + , "================================, ,\" \",//" + , "_tables, ,\" \",#" + , "================================, ,\" \",//" + , "int," + StringClassXtn.Key_const + ",int, ,\" \",$" + , "id,name,file_id, ,\" \",@" + , "================================, ,\" \",//" + ); + db.Tables().DataObj_Wtr(wtr); + String actl = wtr.To_str(); + Tfds.Eq(expd, actl); + } + @Test public void WriteTbl() { + String expd = String_.Concat_lines_crlf + ( "" + , "" + , "================================, ,\" \",//" + , "tbl, ,\" \",#" + , "================================, ,\" \",//" + , "int," + StringClassXtn.Key_const + ", ,\" \",$" + , "id,name, ,\" \",@" + , "================================, ,\" \",//" + ); + TdbTable tbl = db.MakeTbl("tbl", TdbFile.MainFileId); + tbl.Flds().Add("id", IntClassXtn.Instance); + tbl.Flds().Add("name", StringClassXtn.Instance); + + tbl.DataObj_Wtr(wtr); + String actl = wtr.To_str(); + Tfds.Eq(expd, actl); + } +} diff --git a/140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java b/140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java new file mode 100644 index 000000000..a880cd20f --- /dev/null +++ b/140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java @@ -0,0 +1,117 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; +import org.junit.*; +import gplx.core.ios.*; /*IoMgrFxt*/ import gplx.dbs.qrys.*; import gplx.core.type_xtns.*; +public class TdbFlush_tst { + @Before public void setup() { + Io_mgr.Instance.InitEngine_mem(); + engine = fx_engine.run_MakeEngine(dbPath); + } + TdbEngine engine; Io_url dbPath = Io_url_.mem_fil_("mem/dir/db0.dsv"); DateAdp time = DateAdp_.parse_gplx("2001-01-01"); + TdbEngineFxt fx_engine = TdbEngineFxt.new_(); IoMgrFxt fx_io = IoMgrFxt.new_(); + @Test public void FlushNewDb() { + fx_engine.tst_FilesCount(engine, 1); + fx_engine.tst_File(engine, 0, TdbFile.MainFileId, Io_url_.mem_fil_("mem/dir/db0.dsv"), "dsv"); + fx_io.tst_Exists(false, dbPath); + + engine.FlushAll(); + fx_io.tst_Exists(true, dbPath); + } + @Test public void IgnoreFlushedDb() { + engine.FlushAll(); + fx_io.tst_Exists(true, dbPath); + fx_io.run_UpdateFilModifiedTime(dbPath, time); + + engine.FlushAll(); + fx_io.tst_QueryFilModified(true, dbPath, time); + } + @Test public void FlushNewTbl() { + engine.FlushAll(); + fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); + fx_io.run_UpdateFilModifiedTime(dbPath, time); + + engine.FlushAll(); + fx_io.tst_QueryFilModified(false, dbPath, time); + } + @Test public void IgnoreFlushedTbl() { + fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); + engine.FlushAll(); + fx_io.run_UpdateFilModifiedTime(dbPath, time); + + engine.FlushAll(); + fx_io.tst_QueryFilModified(true, dbPath, time); + } + @Test public void FlushDirtyTbl() { + fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); + engine.FlushAll(); + fx_io.run_UpdateFilModifiedTime(dbPath, time); + + fx_engine.run_InsertRow(engine, "tbl0", 1); + engine.FlushAll(); + fx_io.tst_QueryFilModified(false, dbPath, time); + } + @Test public void FlushDirtyFilOnly() { + Io_url dbPathOther = Io_url_.mem_fil_("mem/dir/db1.dsv"); + TdbFile filOther = fx_engine.run_MakeFile(engine, dbPathOther); Tfds.Eq(false, Object_.Eq(filOther.Id(), TdbFile.MainFileId)); + fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); fx_engine.run_MakeTbl(engine, "tbl1", filOther.Id()); + engine.FlushAll(); + fx_io.run_UpdateFilModifiedTime(dbPath, time); fx_io.run_UpdateFilModifiedTime(dbPathOther, time); + + fx_engine.run_InsertRow(engine, "tbl1", 1); + engine.FlushAll(); + fx_io.tst_QueryFilModified(true, dbPath, time); + fx_io.tst_QueryFilModified(false, dbPathOther, time); + } +} +class TdbEngineFxt { + public TdbEngine run_MakeEngine(Io_url url) { + Db_conn_info connectInfo = Db_conn_info_.tdb_(url); + TdbEngine engine = (TdbEngine)TdbEngine.Instance.New_clone(connectInfo); + engine.Conn_open(); + return engine; + } + public TdbFile run_MakeFile(TdbEngine engine, Io_url url) {return engine.Db().MakeFile(url);} + public TdbTable run_MakeTbl(TdbEngine engine, String tblName, int srcId) { + TdbTable rv = engine.Db().MakeTbl(tblName, srcId); + rv.Flds().Add("id", IntClassXtn.Instance); + return rv; + } + public void run_InsertRow(TdbEngine engine, String tblName, int idVal) { + Db_qry_insert cmd = new Db_qry_insert(tblName); + cmd.Val_int("id", idVal); + engine.Exec_as_obj(cmd); + } + + public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Count(), count);} + public void tst_File(TdbEngine engine, int index, int id, Io_url url, String format) { + TdbFile src = engine.Db().Files().Get_by_or_fail(id); + Tfds.Eq(src.Path().Raw(), url.Raw()); + } + public static TdbEngineFxt new_() {return new TdbEngineFxt();} TdbEngineFxt() {} +} +class IoMgrFxt { + public void run_UpdateFilModifiedTime(Io_url url, DateAdp val) {Io_mgr.Instance.UpdateFilModifiedTime(url, val);} + public void tst_QueryFilModified(boolean expdMatch, Io_url url, DateAdp expt) { + IoItmFil filItem = Io_mgr.Instance.QueryFil(url); + DateAdp actl = filItem.ModifiedTime(); + boolean actlMatch = String_.Eq(expt.XtoStr_gplx(), actl.XtoStr_gplx()); + Tfds.Eq(expdMatch, actlMatch, expt.XtoStr_gplx() + (expdMatch ? "!=" : "==") + actl.XtoStr_gplx()); + } + public void tst_Exists(boolean expd, Io_url url) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(url));} + + public static IoMgrFxt new_() {return new IoMgrFxt();} IoMgrFxt() {} +} diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__fld_tst.java b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__fld_tst.java new file mode 100644 index 000000000..1885ef312 --- /dev/null +++ b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__fld_tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; +import org.junit.*; +public class Dbmeta_parser__fld_tst { + @Before public void init() {fxt.Clear();} private Dbmeta_parser__fld_fxt fxt = new Dbmeta_parser__fld_fxt(); + @Test public void Parse_type() { + fxt.Test_parse_type("int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int)); + fxt.Test_parse_type("varchar(255)" , fxt.Make_type(Dbmeta_fld_tid.Tid__str, 255)); + fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10)); + fxt.Test_parse_type(" int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int)); + fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10)); + } + @Test public void Parse_fld() { + fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown)); + fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_null)); + fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null)); + fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.N, Bool_.Y)); + fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N)); + fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, -1)); + fxt.Test_parse_fld("name_1 varchar(3) not null default 'abc'" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__str, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc")); + } + @Test public void Comment() { + fxt.Test_parse_fld("name_1 int --a\n" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown)); + } +} +class Dbmeta_parser__fld_fxt { + private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld(); + private final Sql_bry_rdr rdr = new Sql_bry_rdr(); + public void Clear() {} + public Dbmeta_fld_tid Make_type(int tid_ansi) {return new Dbmeta_fld_tid(tid_ansi, -1, null, Int_.Min_value, Int_.Min_value);} + public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, Int_.Min_value);} + public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1, int len_2) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, len_2);} + public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);} + public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key) {return Make_fld(name, tid_ansi, nullable, false, false, null);} + public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) { + Dbmeta_fld_itm rv = new Dbmeta_fld_itm(name, Make_type(tid_ansi)); + rv.Nullable_tid_(nullable); + if (autonumber) rv.Autonum_y_(); + if (primary_key) rv.Primary_y_(); + rv.Default_(default_val); + return rv; + } + public void Test_parse_type(String src, Dbmeta_fld_tid expd_type) { + rdr.Init_by_src(Bry_.new_u8(src)); + Dbmeta_fld_tid actl_type = fld_parser.Parse_type(rdr); + Tfds.Eq(expd_type.Tid_ansi() , actl_type.Tid_ansi()); + Tfds.Eq(expd_type.Len_1() , actl_type.Len_1()); + Tfds.Eq(expd_type.Len_2() , actl_type.Len_2()); + } + public void Test_parse_fld(String src, Dbmeta_fld_itm expd_fld) { + rdr.Init_by_src(Bry_.new_u8(src)); + Dbmeta_fld_itm actl_fld = fld_parser.Parse_fld(rdr); + Tfds.Eq(expd_fld.Name() , actl_fld.Name()); + Tfds.Eq(expd_fld.Type().Tid_ansi() , actl_fld.Type().Tid_ansi()); + Tfds.Eq(expd_fld.Nullable_tid() , actl_fld.Nullable_tid()); + Tfds.Eq(Object_.Xto_str_strict_or_empty(expd_fld.Default()), Object_.Xto_str_strict_or_empty(actl_fld.Default())); + } +} diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__idx_tst.java b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__idx_tst.java new file mode 100644 index 000000000..fe27b2f6f --- /dev/null +++ b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__idx_tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; +import org.junit.*; +public class Dbmeta_parser__idx_tst { + @Before public void init() {fxt.Clear();} private final Dbmeta_parser__idx_fxt fxt = new Dbmeta_parser__idx_fxt(); + @Test public void Unique() {fxt.Test_parse("CREATE UNIQUE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.Y, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));} + @Test public void Normal() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));} + @Test public void Fld_1() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1"));} +} +class Dbmeta_parser__idx_fxt { + private final Dbmeta_parser__idx parser = new Dbmeta_parser__idx(); + public void Clear() {} + public Dbmeta_idx_itm Make_idx(boolean unique, String idx_name, String tbl_name, String... fld_names) {return new Dbmeta_idx_itm(unique, tbl_name, idx_name, Dbmeta_idx_itm.To_fld_ary(fld_names));} + public void Test_parse(String src, Dbmeta_idx_itm expd) { + Dbmeta_idx_itm actl = parser.Parse(Bry_.new_u8(src)); + Tfds.Eq_bool(expd.Unique(), actl.Unique()); + Tfds.Eq_str(expd.Name(), actl.Name()); + Tfds.Eq_str(expd.Tbl(), actl.Tbl()); + Tfds.Eq_bool(Bool_.Y, Dbmeta_idx_fld.Ary_eq(expd.Flds, actl.Flds)); + } +} diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__tbl_tst.java b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__tbl_tst.java new file mode 100644 index 000000000..57151b089 --- /dev/null +++ b/140_dbs/src/gplx/dbs/metas/parsers/Dbmeta_parser__tbl_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; +import org.junit.*; import gplx.dbs.engines.sqlite.*; +public class Dbmeta_parser__tbl_tst { + @Before public void init() {fxt.Clear();} private Dbmeta_parser__tbl_fxt fxt = new Dbmeta_parser__tbl_fxt(); + @Test public void Test_parse() { + fxt.Test_parse("CREATE TABLE tbl_1 (fld_1 int, fld_2 int)", fxt.Make_tbl("tbl_1", "fld_1", "fld_2")); + } + @Test public void Test_smoke() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "CREATE TABLE page" + , "( page_id integer NOT NULL PRIMARY KEY" + , ", page_namespace integer NOT NULL" + , ", page_title varchar(255) NOT NULL" + , ", page_is_redirect integer NOT NULL" + , ", page_touched varchar(14) NOT NULL" + , ", page_len integer NOT NULL" + , ", page_random_int integer NOT NULL" + , ", page_text_db_id integer NOT NULL" + , ", page_html_db_id integer NOT NULL DEFAULT -1" + , ", page_redirect_id integer NOT NULL DEFAULT -1" + , ");" + ), fxt.Make_tbl("page", "page_id", "page_namespace", "page_title", "page_is_redirect", "page_touched", "page_len", "page_random_int", "page_text_db_id", "page_html_db_id", "page_redirect_id")); + } +} +class Dbmeta_parser__tbl_fxt { + private final Dbmeta_parser__tbl tbl_parser = new Dbmeta_parser__tbl(); + public void Clear() {} + public Dbmeta_tbl_itm Make_tbl(String tbl_name, String... fld_names) { + int len = fld_names.length; + Dbmeta_fld_itm[] flds = new Dbmeta_fld_itm[len]; + for (int i = 0; i < len; ++i) + flds[i] = new Dbmeta_fld_itm(fld_names[i], new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__int, Sqlite_tid.Tid_int, Bry_.new_a7("int"), Int_.Min_value, Int_.Min_value)); + return Dbmeta_tbl_itm.New(tbl_name, flds); + } + public void Test_parse(String src, Dbmeta_tbl_itm expd_tbl) { + Dbmeta_tbl_itm actl_tbl = tbl_parser.Parse(Bry_.new_u8(src)); + Tfds.Eq(expd_tbl.Name(), actl_tbl.Name()); + Tfds.Eq_ary_str(To_str_ary(expd_tbl.Flds()), To_str_ary(actl_tbl.Flds())); + } + private static String[] To_str_ary(Dbmeta_fld_mgr fld_mgr) { + int len = fld_mgr.Len(); + String[] rv = new String[len]; + for (int i = 0; i < len; ++i) { + rv[i] = fld_mgr.Get_at(i).Name(); + } + return rv; + } +} diff --git a/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java b/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java new file mode 100644 index 000000000..42946d40b --- /dev/null +++ b/140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; +import org.junit.*; +public class Sql_bry_rdr_tst { + @Before public void init() {fxt.Clear();} private Sql_bry_rdr_fxt fxt = new Sql_bry_rdr_fxt(); + @Test public void Skip_ws() { + fxt.Test_skip_ws("a", 0); // char + fxt.Test_skip_ws("\ta", 1); // tab + fxt.Test_skip_ws("\na", 1); // \n + fxt.Test_skip_ws("\ra", 1); // \r + fxt.Test_skip_ws(" a", 1); // space + fxt.Test_skip_ws("\t\n\r a", 4); // multi + fxt.Test_skip_ws("", 0); // eos + } + @Test public void Read_sql_identifier() { + fxt.Test_read_sql_identifier("a", "a"); // one + fxt.Test_read_sql_identifier("abc_1", "abc_1"); // many + fxt.Test_read_sql_identifier("[abc_1]", "abc_1"); // bracket + fxt.Test_read_sql_identifier(" a ", "a"); // ws + fxt.Test_read_sql_identifier("", null); // eos + fxt.Test_read_sql_identifier("!@#", null); // sym + } +} +class Sql_bry_rdr_fxt { + private final Sql_bry_rdr rdr = new Sql_bry_rdr(); + public void Clear() {} + public void Test_skip_ws(String src, int expd_pos) { + rdr.Init_by_src(Bry_.new_u8(src)); + rdr.Skip_ws(); + Tfds.Eq(expd_pos, rdr.Pos()); + } + public void Test_read_sql_identifier(String src, String expd) { + rdr.Init_by_src(Bry_.new_u8(src)); + Tfds.Eq(expd, String_.new_u8(rdr.Read_sql_identifier())); + } +} diff --git a/140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java b/140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java new file mode 100644 index 000000000..43c14b133 --- /dev/null +++ b/140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java @@ -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.dbs.qrys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +import gplx.core.criterias.*; +public class Db_qry_dml_tst { + @Test public void Delete_basic() { + tst_XtoSql(Db_qry_delete.new_("tbl0", Db_crt_.New_eq("fld0", "val0")) + , "DELETE FROM tbl0 WHERE fld0 = 'val0'"); + } + @Test public void Insert_basic() { + tst_XtoSql(new Db_qry_insert("tbl0").Val_int("id", 0).Val_str("name", "me").Val_date("time", DateAdp_.parse_gplx("2007-12-23")) + , "INSERT INTO tbl0 (id, name, time) VALUES (0, 'me', '2007-12-23 00:00:00.000')"); + } + @Test public void Update_basic() { + Db_qry_update qry = new Db_qry_update(); + qry.From_("tbl0"); + qry.Where_(Db_crt_.New_eq("id", 0)).Val_str("name", "me"); + tst_XtoSql(qry, "UPDATE tbl0 SET name='me' WHERE id = 0"); + } + @Test public void Update_all() { + Db_qry_update qry = new Db_qry_update(); + qry.From_("tbl0"); + qry.Val_int("id", 1).Val_str("name", "me").Val_date("startTime", DateAdp_.parse_gplx("2007-12-23")); + qry.Where_(Criteria_.And(Db_crt_.New_eq("id", 0), Db_crt_.New_mt("startTime", DateAdp_.parse_gplx("2005-01-01")))); + tst_XtoSql(qry, "UPDATE tbl0 SET id=1, name='me', startTime='2007-12-23 00:00:00.000' WHERE (id = 0 AND startTime > '2005-01-01 00:00:00.000')"); + } + void tst_XtoSql(Db_qry qry, String expd) {Tfds.Eq(expd, qry.To_sql__exec(gplx.dbs.sqls.Sql_qry_wtr_.New__basic()));} +} diff --git a/140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java b/140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java new file mode 100644 index 000000000..22c629af5 --- /dev/null +++ b/140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java @@ -0,0 +1,87 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.dbs.sqls.*; +public class Db_qry_select_tst { + @Before public void setup() { + cmd = new Db_qry__select_cmd(); + } Db_qry__select_cmd cmd; String expd; + @Test public void Basic() { + cmd.Cols_("fld0", "fld1").From_("tbl0"); + expd = "SELECT fld0, fld1 FROM tbl0"; + + tst_XtoStr(cmd, expd); + } + @Test public void OrderDoesNotMatter() { + cmd.From_("tbl0").Cols_("fld0", "fld1"); + expd = "SELECT fld0, fld1 FROM tbl0"; + + tst_XtoStr(cmd, expd); + } + @Test public void DefaultAllFields() { + cmd.From_("tbl0"); + expd = "SELECT * FROM tbl0"; + + tst_XtoStr(cmd, expd); + } + @Test public void Where() { + cmd.From_("tbl0").Where_(Db_crt_.New_eq("fld0", 0)); + expd = "SELECT * FROM tbl0 WHERE fld0 = 0"; + + tst_XtoStr(cmd, expd); + } + @Test public void Join() { + cmd.From_("tbl0").Join_("tbl1", "t1", Db_qry_.New_join__join("fld1", "tbl0", "fld0")); + expd = "SELECT * FROM tbl0 INNER JOIN tbl1 t1 ON tbl0.fld0 = t1.fld1"; + + tst_XtoStr(cmd, expd); + } + @Test public void OrderBy() { + cmd.From_("tbl0").Order_("fld0", true); + expd = "SELECT * FROM tbl0 ORDER BY fld0"; + + tst_XtoStr(cmd, expd); + } + @Test public void OrderByMany() { + cmd.From_("tbl0").Order_asc_many_("fld0", "fld1"); + expd = "SELECT * FROM tbl0 ORDER BY fld0, fld1"; + + tst_XtoStr(cmd, expd); + } + @Test public void Limit() { + cmd.From_("tbl0").Limit_(10); + expd = "SELECT * FROM tbl0 LIMIT 10"; + + tst_XtoStr(cmd, expd); + } +// @Test public void GroupBy() { +// cmd.From_("tbl0").groupBy_("fld0", "fld1"); +// expd = "SELECT fld0, fld1 FROM tbl0 GROUP BY fld0, fld1"; +// Tfds.Eq(cmd.To_str(), expd); +// } +// @Test public void Union() { +// cmd.From_("tbl0").select("fld0").union_(qry2.from("tbl1").select("fld0")); +// cmd.From_("tbl0").select("fld0").union_().from("tbl1").select("fld0"); // feasible, but will be bad later when trying to access Db_qry__select_cmd props +// expd = "SELECT fld0 FROM tbl0 UNION SELECT fld0 FROM tbl1"; +// Tfds.Eq(cmd.To_str(), expd); +// } +// @Test public void Having() { +// cmd.From_("tbl0").groupBy_("fld0", "fld1"); +// expd = "SELECT fld0, fld1 FROM tbl0 GROUP BY fld0, fld1 HAVING Count(fld0) > 1"; +// Tfds.Eq(cmd.To_str(), expd); +// } + void tst_XtoStr(Db_qry qry, String expd) {Tfds.Eq(expd, cmd.To_sql__exec(Sql_qry_wtr_.New__basic()));} +} diff --git a/140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java b/140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java new file mode 100644 index 000000000..96ed0cee3 --- /dev/null +++ b/140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.dbs.sqls.*; +public class Db_qry_sql_tst { + @Before public void init() {fxt.Clear();} private Db_qry_sql_fxt fxt = new Db_qry_sql_fxt(); + @Test public void Insert() { + fxt.Test_qry + ( Db_qry_insert.new_("tbl", "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9") + , Object_.Ary(123, Bool_.Y, 1.23d, 123L, 123f, Byte_ascii.Num_1, "123", DateAdp_.parse_iso8561("1981-04-05T14:30:30"), Decimal_adp_.parse("1.23")) + , "INSERT INTO tbl (k1, k2, k3, k4, k5, k6, k7, k8, k9) VALUES (123, 1, 1.23, 123, 123, 1, '123', '1981-04-05 14:30:30.000', 1.23)" + ); + } + @Test public void Update() { + fxt.Test_qry + ( Db_qry_update.New("tbl", String_.Ary("k1", "k2"), "k3", "k4") + , Object_.Ary("v3", "v4", "v1", "v2") + , "UPDATE tbl SET k3='v3', k4='v4' WHERE (k1 = 'v1' AND k2 = 'v2')" + ); + } + @Test public void Delete() { + fxt.Test_qry + ( Db_qry_delete.new_("tbl", String_.Ary("k1", "k2")) + , Object_.Ary("v1", "v2") + , "DELETE FROM tbl WHERE (k1 = 'v1' AND k2 = 'v2')" + ); + } +} +class Db_qry_sql_fxt { + private final Sql_qry_wtr qry_wtr = Sql_qry_wtr_.New__sqlite(); + public void Clear() {} + public void Test_qry(Db_qry qry, Object[] vals, String expd) {Tfds.Eq(expd, Db_qry_sql.Gen_sql(qry_wtr, qry, vals));} +} diff --git a/140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java b/140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java new file mode 100644 index 000000000..3eba54705 --- /dev/null +++ b/140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class Db_stmt_sql_tst { + @Before public void init() {} + @Test public void Basic() { + Db_stmt_sql stmt = new Db_stmt_sql(); + stmt.Parse(null, "UPDATE tbl_0 SET col_0 = ? WHERE col_1 = ?"); + stmt.Add("col_0", "1"); + stmt.Add("col_1", "2"); + Tfds.Eq("UPDATE tbl_0 SET col_0 = 1 WHERE col_1 = 2", stmt.Xto_sql()); + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java b/140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java new file mode 100644 index 000000000..4ea30b47b --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java @@ -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.dbs.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; import gplx.core.strings.*; import gplx.dbs.sqls.*; +import gplx.dbs.sqls.wtrs.*; +public class Db_obj_ary_tst { + @Before public void init() {} private Db_obj_ary_fxt fxt = new Db_obj_ary_fxt(); + @Test public void Int() { + fxt.Init_fld("fld_0", Type_ids_.Id__int).Init_fld("fld_1", Type_ids_.Id__int).Init_vals(1, 10).Init_vals(2, 20).Test_sql("(fld_0=1 AND fld_1=10) OR (fld_0=2 AND fld_1=20)"); + } + @Test public void Str() { + fxt.Init_fld("fld_0", Type_ids_.Id__int).Init_fld("fld_1", Type_ids_.Id__str).Init_vals(1, "a").Init_vals(2, "b").Test_sql("(fld_0=1 AND fld_1='a') OR (fld_0=2 AND fld_1='b')"); + } +} +class Db_obj_ary_fxt { + private final Db_obj_ary_crt crt = new Db_obj_ary_crt(); + private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false); + public Db_obj_ary_fxt Init_fld(String name, int tid) {flds_list.Add(new Db_obj_ary_fld(name, tid)); return this;} private List_adp flds_list = List_adp_.New(); + public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.New(); + public Db_obj_ary_fxt Test_sql(String expd) { + Sql_core_wtr cmd_wtr = (Sql_core_wtr)Sql_qry_wtr_.New__basic(); + crt.Flds_((Db_obj_ary_fld[])flds_list.To_ary_and_clear(Db_obj_ary_fld.class)); + crt.Vals_((Object[][])vals_list.To_ary_and_clear(Object[].class)); + Bry_bfr bfr = Bry_bfr_.New(); + cmd_wtr.Where_wtr().Bld_where__db_obj(bfr, ctx, crt); + Tfds.Eq(expd, bfr.To_str_and_clear()); + return this; + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java new file mode 100644 index 000000000..375e05cd0 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import gplx.core.criterias.*; +class Sql_core_wtr_fxt { + private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite(); + private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false); + private final Bry_bfr bfr = Bry_bfr_.New(); + public Sql_core_wtr_fxt Sql_wtr_(Sql_qry_wtr v) {sql_wtr = v; return this;} private Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__sqlite(); + public void Test__val(Object val, String expd) { + wtr.Val_wtr().Bld_val(bfr, ctx, val); + Tfds.Eq_str(expd, bfr.To_str_and_clear()); + } + public void Test__where(Criteria crt, String... expd) { + wtr.Where_wtr().Bld_where_elem(bfr, ctx, crt); + Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), bfr.To_str_and_clear()); + } + public void Test__qry(Db_qry qry, String expd) { + Tfds.Eq_str_lines(expd, sql_wtr.To_sql_str(qry, Bool_.N)); + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java new file mode 100644 index 000000000..ac637ff40 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; +public class Sql_from_wtr_tst { + private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt(); + @Test public void Abrv() { + fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("tbl", "t"), "SELECT * FROM tbl t"); + } + @Test public void Db() { + fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("db", "tbl", "t"), "SELECT * FROM db.tbl t"); + } + @Test public void Join() { + fxt.Test__qry + ( Db_qry_.select_().Cols_all_().From_("src", "s").Join_("trg", "t", Db_qry_.New_join__join("trg_id", "s", "src_id")) + , "SELECT * FROM src s INNER JOIN trg t ON s.src_id = t.trg_id"); + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java new file mode 100644 index 000000000..f560f3231 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java @@ -0,0 +1,97 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; +import gplx.core.criterias.*; import gplx.dbs.sqls.*; +public class Sql_qry_wtr__ansi__tst { + Sql_qry_wtr sqlWtr = Sql_qry_wtr_.New__basic(); + @Test public void Insert() { + tst_XtoSql + ( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me") + , "INSERT INTO people (id, name) VALUES (1, 'me')" + ); + } + @Test public void Delete() { + Criteria crt = Db_crt_.New_eq("id", 1); + tst_XtoSql + ( Db_qry_.delete_("people", crt) + , "DELETE FROM people WHERE id = 1" + ); + } + @Test public void Update() { + tst_XtoSql + ( Db_qry_.update_("people", Db_crt_.New_eq("id", 1)).Val_str("name", "me") + , "UPDATE people SET name='me' WHERE id = 1" + ); + } + @Test public void SelectAll() { + tst_XtoSql + ( Db_qry_.select_().From_("people") + , "SELECT * FROM people" + ); + } + @Test public void SelectFlds() { + tst_XtoSql + ( Db_qry_.select_().Cols_("id", "name").From_("people") + , "SELECT id, name FROM people" + ); + } + @Test public void SelectOrderBy() { + tst_XtoSql + ( Db_qry_.select_().From_("people").Order_("name", false) + , "SELECT * FROM people ORDER BY name DESC" + ); + } + @Test public void SelectWhere() { + tst_XtoSql + ( Db_qry_.select_().From_("people").Where_(Db_crt_.New_eq("id", 1)) + , "SELECT * FROM people WHERE id = 1" + ); + } + @Test public void Select_From_Alias() { + tst_XtoSql + ( Db_qry_.select_().From_("people", "p") + , "SELECT * FROM people p" + ); + } + @Test public void Select_Join_Alias() { + tst_XtoSql + ( Db_qry_.select_().From_("people", "p").Join_("roles", "r", Db_qry_.New_join__same("p", "id")) + , "SELECT * FROM people p INNER JOIN roles r ON p.id = r.id" + ); + } + @Test public void Prepare() { + tst_XtoSql + ( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me") + , "INSERT INTO people (id, name) VALUES (?, ?)" + , true + ); + + tst_XtoSql + ( Db_qry_.delete_("people", Db_crt_.New_eq("id", 1)) + , "DELETE FROM people WHERE id = ?" + , true + ); + + tst_XtoSql + ( Db_qry_.update_("people", Db_crt_.New_eq("id", 1)).Val_str("name", "me") + , "UPDATE people SET name=? WHERE id = ?" + , true + ); + } + void tst_XtoSql(Db_qry cmd, String expd) {tst_XtoSql(cmd, expd, false);} + void tst_XtoSql(Db_qry cmd, String expd, boolean prepare) {Tfds.Eq(expd, sqlWtr.To_sql_str(cmd, prepare));} +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java new file mode 100644 index 000000000..67b6bce2c --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; import gplx.core.strings.*; +import gplx.core.criterias.*; /*Criteria_base*/ +import gplx.core.ios.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.wtrs.*; +public class Sql_qry_wtr__iosql__tst { + @Test public void Type() { + fld = IoItm_base_.Prop_Type; + tst_Write("type = 1", ioCrt_(fld, Criteria_.eq_(IoItmDir.Type_Dir))); + tst_Write("type = 2", ioCrt_(fld, Criteria_.eq_(IoItmFil.Type_Fil))); + } + @Test public void Ext() { + fld = IoItm_base_.Prop_Ext; + tst_Write("ext = '.txt'", ioCrt_(fld, Criteria_.eq_(".txt"))); + tst_Write("ext IN ('.txt', '.xml', '.html')", ioCrt_(fld, Criteria_.in_(".txt", ".xml", ".html"))); + tst_Write("ext NOT IN ('.dll', '.exe')", ioCrt_(fld, Criteria_.inn_(".dll", ".exe"))); + } + @Test public void Title() { + fld = IoItm_base_.Prop_Title; + tst_Write("title = 'bin'", ioCrt_(fld, Criteria_.eq_("bin"))); + tst_Write("title NOT IN ('bin', 'obj')", ioCrt_(fld, Criteria_.inn_("bin", "obj"))); + } + @Test public void Url() { + fld = IoItm_base_.Prop_Path; + tst_Write("url = 'C:\\fil.txt'", ioCrt_(fld, Criteria_.eq_("C:\\fil.txt"))); + tst_Write("url IOMATCH '*.txt'", ioCrt_(fld, Criteria_ioMatch.parse(true, "*.txt", false))); + } + @Test public void Binary() { + // parentheses around lhs and rhs + tst_Write( + "(type = 1 OR type = 2)" + , Criteria_.Or + ( ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmDir.Type_Dir)), ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil)) + )); + } + Criteria ioCrt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);} + String fld; + private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false); + void tst_Write(String expd, Criteria crt) { + Sql_where_wtr where_wtr = ((Sql_core_wtr)Sql_qry_wtr_.New__basic()).Where_wtr(); + Bry_bfr bfr = Bry_bfr_.New(); + where_wtr.Bld_where_elem(bfr, ctx, crt); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java new file mode 100644 index 000000000..42b19e4c8 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; +public class Sql_schema_wtr_tst { + @Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt(); + @Test public void Idx_unique() { + fxt.Test_create_idx(Dbmeta_idx_itm.new_unique_by_tbl("tbl_name", "idx_name", "fld_1", "fld_2") + , "CREATE UNIQUE INDEX IF NOT EXISTS tbl_name__idx_name ON tbl_name (fld_1, fld_2);" + ); + } + @Test public void Tbl_basic() { + Dbmeta_fld_list flds = new Dbmeta_fld_list(); + flds.Add_int_pkey("fld_int_pkey"); + flds.Add_bool("fld_bool"); + flds.Add_short("fld_short"); + flds.Add_int("fld_int"); + flds.Add_long("fld_long"); + flds.Add_float("fld_float"); + flds.Add_double("fld_double"); + flds.Add_str("fld_str", 123); + flds.Add_text("fld_text"); + flds.Add_bry("fld_bry"); + fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.To_fld_ary()) + , String_.Concat_lines_nl_skip_last + ( "CREATE TABLE IF NOT EXISTS tbl_name" + , "( fld_int_pkey integer NOT NULL PRIMARY KEY" + , ", fld_bool boolean NOT NULL" + , ", fld_short smallint NOT NULL" + , ", fld_int integer NOT NULL" + , ", fld_long bigint NOT NULL" + , ", fld_float float NOT NULL" + , ", fld_double double NOT NULL" + , ", fld_str varchar(123) NOT NULL" + , ", fld_text text NOT NULL" + , ", fld_bry blob NOT NULL" + , ");" + )); + } + @Test public void Tbl_alter_tbl_add() { + Dbmeta_fld_list flds = new Dbmeta_fld_list(); + flds.Add_int_dflt("fld_int", -1); + flds.Add_str_dflt("fld_str", 255, "a"); + fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;"); + fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';"); + } +} +class Sql_schema_wtr_fxt { + private Sql_schema_wtr sqlbldr = Sql_qry_wtr_.New__sqlite().Schema_wtr(); + public void Test_create_idx(Dbmeta_idx_itm idx, String expd) {Tfds.Eq(expd, sqlbldr.Bld_create_idx(idx));} + public void Test_create_tbl(Dbmeta_tbl_itm tbl, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_create_tbl(tbl));} + public void Test_alter_tbl_add(String tbl, Dbmeta_fld_itm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));} +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java new file mode 100644 index 000000000..3d34f71a0 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; +public class Sql_select_wtr_tst { + private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt(); + @Test public void Offset__automatically_add_limit() { + fxt.Test__qry(Db_qry_.select_tbl_("tbl").Offset_(1), "SELECT * FROM tbl LIMIT -1 OFFSET 1"); + } + @Test public void Offset__do_not_overwrite_limit() { + fxt.Test__qry(Db_qry_.select_tbl_("tbl").Limit_(20).Offset_(1), "SELECT * FROM tbl LIMIT 20 OFFSET 1"); + } +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java new file mode 100644 index 000000000..b8e3e057f --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; +public class Sql_val_wtr_tst { + private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt(); + @Test public void Null() {fxt.Test__val(null , "NULL");} + @Test public void Bool__n() {fxt.Test__val(Bool_.N , "0");} + @Test public void Bool__y() {fxt.Test__val(Bool_.Y , "1");} + @Test public void Byte() {fxt.Test__val(Byte_.By_int(2) , "2");} + @Test public void Short() {fxt.Test__val(Short_.By_int(3) , "3");} + @Test public void Int() {fxt.Test__val(4 , "4");} + @Test public void Long() {fxt.Test__val(5 , "5");} + @Test public void Float() {fxt.Test__val(6.1f , "6.1");} + @Test public void Double() {fxt.Test__val(7.1d , "7.1");} + @Test public void Decimal() {fxt.Test__val(Decimal_adp_.float_(8) , "'8'");} + @Test public void Str() {fxt.Test__val("abc" , "'abc'");} + @Test public void Str__apos_mid() {fxt.Test__val("a'b" , "'a''b'");} + @Test public void Str__apos_bgn() {fxt.Test__val("'ab" , "'''ab'");} + @Test public void Str__apos_end() {fxt.Test__val("ab'" , "'ab'''");} + @Test public void Str__apos_many() {fxt.Test__val("a'b'c" , "'a''b''c'");} + @Test public void Str__back() {fxt.Test__val("a\\b" , "'a\\b'");} + @Test public void Date() {fxt.Test__val(DateAdp_.parse_gplx("2016-02-03") , "'2016-02-03 00:00:00.000'");} +} diff --git a/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java new file mode 100644 index 000000000..02a21845d --- /dev/null +++ b/140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*; +import org.junit.*; import gplx.core.criterias.*; +public class Sql_where_wtr_tst { + private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt(); + @Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");} + @Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");} + @Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");} + @Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");} + @Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");} + @Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");} + @Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");} + @Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");} + @Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");} + @Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");} + @Test public void And__subs__2() { + fxt.Test__where + ( Criteria_.And + ( Db_crt_.New_eq("id", 1) + , Db_crt_.New_eq("name", "me") + ), "(id = 1 AND name = 'me')"); + } + @Test public void Or__subs__2() { + fxt.Test__where + ( Criteria_.Or + ( Db_crt_.New_eq("id", 1) + , Db_crt_.New_eq("name", "me") + ), "(id = 1 OR name = 'me')"); + } + @Test public void Nested() { + fxt.Test__where + ( Criteria_.Or + ( Db_crt_.New_eq("id", 1) + , Criteria_.And + ( Db_crt_.New_eq("name", "me") + , Db_crt_.New_eq("id", 2)) + ), "(id = 1 OR (name = 'me' AND id = 2))"); + } +} diff --git a/140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java b/140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java new file mode 100644 index 000000000..7ecb57640 --- /dev/null +++ b/140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.sys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class Db_sys_mgr_tst { + private final Db_sys_mgr_fxt fxt = new Db_sys_mgr_fxt(); + @Test public void FetchNextId() { + fxt.Test__autonum_next("tbl_1.fld", 1); // default to "1" on first creation + fxt.Test__autonum_next("tbl_1.fld", 2); // read "2" from db + } +} +class Db_sys_mgr_fxt { + private final Db_sys_mgr sys_mgr; + public Db_sys_mgr_fxt() { + Db_conn conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.mem_("test")); + sys_mgr = new Db_sys_mgr(conn); + } + public void Test__autonum_next(String key, int expd) {Tfds.Eq_int(expd, sys_mgr.Autonum_next(key));} +} diff --git a/140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java b/140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java new file mode 100644 index 000000000..fff1f6d4b --- /dev/null +++ b/140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.utls; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class Db_cmd_backup_tst { + @Test public void Basic() { + Datetime_now.Manual_y_(); + Db_cmd_backup bkpWkr = Db_cmd_backup.new_() + .ExeUrl_(Io_url_.new_any_("C:\\mysql\\mysqldump.exe")) + .BkpDir_(Io_url_.new_any_("C:\\bkp\\")) + .Usr_("username") + .Pwd_("password") + .DbName_("dbname").InitVars(); + Tfds.Eq("\"C:\\mysql\\mysqldump.exe\" -u username -ppassword dbname > C:\\bkp\\dbname_20010101_0000.sql", bkpWkr.CmdText()); + } +} diff --git a/140_dbs/src/gplx/dbs/utls/PoolIds_tst.java b/140_dbs/src/gplx/dbs/utls/PoolIds_tst.java new file mode 100644 index 000000000..5852a76ae --- /dev/null +++ b/140_dbs/src/gplx/dbs/utls/PoolIds_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.utls; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class PoolIds_tst { + @Before public void setup() { + conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.Test); + Db_qry_fxt.DeleteAll(conn, PoolIds.Tbl_Name); + mgr = PoolIds.Instance; + } + @Test public void FetchNextId() { + tst_Fetch("/test0", 0); + } + @Test public void ChangeNextId_Insert() { + run_Change("/test0", 1); + + tst_Fetch("/test0", 1); + } + @Test public void ChangeNextId_Update() { + run_Change("/test0", 0); + run_Change("/test0", 1); + + tst_Fetch("/test0", 1); + } + @Test public void FetchNextId_Multiple() { + run_Change("/test0", 0); + run_Change("/test1", 1); + + tst_Fetch("/test0", 0); + tst_Fetch("/test1", 1); + } + void run_Change(String url, int expd) { + mgr.Commit(conn, url, expd); + } + void tst_Fetch(String url, int expd) { + int actl = mgr.FetchNext(conn, url); + Tfds.Eq(expd, actl); + } + Db_conn conn; + PoolIds mgr; +} diff --git a/140_dbs/tst/gplx/dbs/Db_conn_fxt.java b/140_dbs/tst/gplx/dbs/Db_conn_fxt.java new file mode 100644 index 000000000..1044f8a21 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/Db_conn_fxt.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs; import gplx.*; +import gplx.core.stores.*; +import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*; import gplx.core.gfo_ndes.*; +public class Db_conn_fxt implements Rls_able { + public Db_conn Conn() {return conn;} public Db_conn_fxt Conn_(Db_conn v) {conn = v; return this;} Db_conn conn; + public void DmlAffectedAvailable_(boolean v) {dmlAffectedAvailable = v;} private boolean dmlAffectedAvailable = true; + public void ini_DeleteAll(String tbl) {conn.Exec_qry(Db_qry_.delete_tbl_(tbl));} + public void tst_ExecDml(int expd, Db_qry qry) { + int actl = conn.Exec_qry(qry); + if (dmlAffectedAvailable) + Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr())); + } + public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));} + public void tst_ExecRdr(int expd, Db_qry qry) { + DataRdr rdr = DataRdr_.Null; + try { + rdr = conn.Exec_qry_as_old_rdr(qry); + tbl = GfoNde_.rdr_(rdr); + } + catch (Exception e) {Err_.Noop(e); rdr.Rls();} + Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr())); + } GfoNde tbl; + public GfoNde tst_RowAry(int index, Object... expdValAry) { + GfoNde record = tbl.Subs().FetchAt_asGfoNde(index); + Object[] actlValAry = new Object[expdValAry.length]; + for (int i = 0; i < actlValAry.length; i++) + actlValAry[i] = record.ReadAt(i); + Tfds.Eq_ary(actlValAry, expdValAry); + return record; + } + public void Rls() {conn.Rls_conn();} + + public static Db_conn Mysql() {return Db_conn_pool.Instance.Get_or_new(Mysql_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));} + public static Db_conn Tdb(String fileName) {return Db_conn_pool.Instance.Get_or_new(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));} + public static Db_conn Postgres() {return Db_conn_pool.Instance.Get_or_new(Postgres_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));} + public static Db_conn Sqlite() {return Db_conn_pool.Instance.Get_or_new(Sqlite_conn_info.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));} + public static final boolean SkipPostgres = Tfds.SkipDb || true; +} \ No newline at end of file diff --git a/140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java b/140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java new file mode 100644 index 000000000..62e816145 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java @@ -0,0 +1,127 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.dbs.qrys.*; +public class db_CrudOps_tst { + CrudOpsFxt fx = new CrudOpsFxt(); + @Test public void Mysql() {if (Tfds.SkipDb) return; + fx.RunAll(Db_conn_fxt.Mysql()); + } + @Test public void Tdb() {if (Tfds.SkipDb) return; + fx.RunAll(Db_conn_fxt.Tdb("100_dbs_crud_ops.dsv")); + } + @Test public void Postgres() {if (Db_conn_fxt.SkipPostgres) return; + fx.RunAll(Db_conn_fxt.Postgres()); + } + @Test public void Sqlite() {if (Tfds.SkipDb) return; + fx.Fx().DmlAffectedAvailable_(false); + fx.RunAll(Db_conn_fxt.Sqlite()); + } +} +class CrudOpsFxt { + public Db_conn_fxt Fx() {return fx;} Db_conn_fxt fx = new Db_conn_fxt(); + void Init() {fx.ini_DeleteAll("dbs_crud_ops");} + public void RunAll(Db_conn conn) { + fx.Conn_(conn); + Insert_hook(); + UpdateOne_hook(); + UpdateMany_hook(); + DeleteOne_hook(); + DeleteMany_hook(); + SelectLike_hook(); + SelectLikeForFileName_hook(); + InsertUnicode_hook(); + Backslash_hook(); + fx.Rls(); + } + public void Insert_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + fx.tst_ExecRdrTbl(1, "dbs_crud_ops"); + fx.tst_RowAry(0, 1, "John Doe"); + } + public void UpdateOne_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "John Doe")); + + fx.tst_ExecDml(1, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.New_eq("id", 2), Keyval_.new_("name", "Jane Smith"))); + fx.tst_ExecRdrTbl(2, "dbs_crud_ops"); + fx.tst_RowAry(0, 1, "John Doe"); + fx.tst_RowAry(1, 2, "Jane Smith"); + } + public void UpdateMany_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "John Doe")); + + fx.tst_ExecDml(2, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.New_eq("name", "John Doe"), Keyval_.new_("name", "Jane Smith"))); + fx.tst_ExecRdrTbl(2, "dbs_crud_ops"); + fx.tst_RowAry(0, 1, "Jane Smith"); + fx.tst_RowAry(1, 2, "Jane Smith"); + } + public void DeleteOne_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "Jane Smith")); + + fx.tst_ExecDml(1, Db_qry_.delete_("dbs_crud_ops", Db_crt_.New_eq("id", 2))); + fx.tst_ExecRdrTbl(1, "dbs_crud_ops"); + fx.tst_RowAry(0, 1, "John Doe"); + } + public void DeleteMany_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "Jane Smith")); + + fx.tst_ExecDml(2, Db_qry_.delete_tbl_("dbs_crud_ops")); + fx.tst_ExecRdrTbl(0, "dbs_crud_ops"); + } + public void SelectLike_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe")); + + fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.New_like("name", "John%"))); + fx.tst_RowAry(0, 1, "John Doe"); + } + public void SelectLikeForFileName_hook() { + this.Init(); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file%")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file|%")); + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file test")); + + fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.New_like("name", "file|%"))); + fx.tst_RowAry(0, 1, "file%"); + } + public void InsertUnicode_hook() { + this.Init(); + String val = "Ω"; + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 3).Val_obj_type("name", val, Db_val_type.Tid_nvarchar)); + Db_qry__select_cmd select = Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("id", 3)); + Tfds.Eq(val, ExecRdr_val(select)); + + fx.tst_ExecDml(1, Db_qry_.update_("dbs_crud_ops", Db_crt_.Wildcard).Val_obj_type("name", val + "a", Db_val_type.Tid_nvarchar)); + Tfds.Eq(val + "a", ExecRdr_val(select)); + } + public void Backslash_hook() { + this.Init(); + String val = "\\"; + fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 3).Val_str("name", val)); + Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("id", 3)))); + Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("name", "\\")))); + } + String ExecRdr_val(Db_qry__select_cmd select) {return (String)Db_qry_.Exec_as_obj(fx.Conn(), select);} +} diff --git a/140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java b/140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java new file mode 100644 index 000000000..06b55a395 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.engines; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.core.type_xtns.*; import gplx.core.stores.*; +public class db_DataTypes_tst { + DataTypes_base_fxt fx = new DataTypes_base_fxt(); + @Test public void Mysql() {if (Tfds.SkipDb) return; + fx.Select_FloatStr_("0.333333"); + fx.RunAll(Db_conn_fxt.Mysql()); + } + @Test public void Tdb() {if (Tfds.SkipDb) return; + fx.Select_FloatStr_(Float_.To_str(Float_.Div(1, 3))); + fx.RunAll(Db_conn_fxt.Tdb("110_dbs_multiple_data_types.dsv")); + } + @Test public void Postgres() {if (Db_conn_fxt.SkipPostgres) return; + fx.Select_FloatStr_("0.33333334"); + fx.RunAll(Db_conn_fxt.Postgres()); + } + @Test public void Sqlite() {if (Tfds.SkipDb) return; + fx.Select_FloatStr_("0.33333334"); + fx.RunAll(Db_conn_fxt.Sqlite()); + } + /* +DROP TABLE dbs_multiple_data_types; +CREATE TABLE dbs_multiple_data_types ( +unique_id int +, full_name varchar(255) +, is_active bit +, last_update timestamp +, quantity float(24) +, amount decimal(12, 3) +); +INSERT INTO dbs_multiple_data_types VALUES (1, 'John Doe', B'1', '3/30/2006 10:22 PM', 0.333333343, 12.345); + */ +} +class DataTypes_base_fxt { + public Db_conn Conn() {return conn;} Db_conn conn; + public DataTypes_base_fxt() {} + public void Rls() {conn.Rls_conn();} + public String Select_FloatStr() {return select_FloatStr;} public DataTypes_base_fxt Select_FloatStr_(String v) {select_FloatStr = v; return this;} private String select_FloatStr; + public void RunAll(Db_conn conn) { + this.conn = conn; + this.Select_hook(select_FloatStr); + conn.Rls_conn(); + } + public void Select_hook(String floatStr) { + DataRdr rdr = conn.Exec_qry_as_old_rdr(Db_qry_.select_tbl_("dbs_multiple_data_types")); + + rdr.MoveNextPeer(); + Tfds.Eq(rdr.ReadInt("unique_id"), 1); + Tfds.Eq(rdr.ReadStr("full_name"), "John Doe"); + Tfds.Eq(rdr.ReadBool("is_active"), true); + Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("2006-03-30 22:22:00.000")); + Tfds.Eq(floatStr, Object_.Xto_str_strict_or_empty(rdr.ReadFloat("quantity"))); + Tfds.Eq_decimal(rdr.ReadDecimal("amount"), Decimal_adp_.parts_(12, 345)); + } + public void UpdateDate_hook() { + conn.Exec_qry(Db_qry_.update_("dbs_multiple_data_types", Db_crt_.New_eq("unique_id", 1)).Val_obj("last_update", DateAdpClassXtn.Instance.XtoDb(DateAdp_.parse_gplx("20091115 220000.000")))); + + DataRdr rdr = conn.Exec_qry_as_old_rdr(Db_qry_.select_tbl_("dbs_multiple_data_types")); + rdr.MoveNextPeer(); + Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("20091115 220000.000")); + } +} diff --git a/140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java new file mode 100644 index 000000000..6a29a90be --- /dev/null +++ b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java @@ -0,0 +1,93 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*; import gplx.core.stores.*; +public abstract class GroupBys_base_tst { + protected abstract Db_conn provider_(); + protected Db_conn conn; + @Before public void setup() { + conn = provider_(); + Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(conn); + } + @After public void teardown() { + conn.Rls_conn(); + } + protected void GroupBy_1fld_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2)); + + DataRdr rdr = conn.Exec_qry_as_old_rdr + (Db_qry_.select_().From_("dbs_group_bys") + .Cols_("key1") + .GroupBy_("key1")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + } + protected void GroupBy_2fld_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 1)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 2)); + + DataRdr rdr = conn.Exec_qry_as_old_rdr + (Db_qry_.select_().From_("dbs_group_bys") + .Cols_("key1", "key2") + .GroupBy_("key1", "key2")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + GfoNdeTstr.tst_ValsByCol(nde, "key2", "b"); + } + protected void MinMax_hook(boolean min) { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2)); + + Db_qry__select_cmd qry = Db_qry_.select_().From_("dbs_group_bys") + .Cols_("key1") + .GroupBy_("key1"); + int expd = min ? 1 : 2; + if (min) + qry.Cols_groupBy_min("val_int", "val_int_func"); + else + qry.Cols_groupBy_max("val_int", "val_int_func"); + + DataRdr rdr = conn.Exec_qry_as_old_rdr(qry); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", expd); + } + protected void Count_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20)); + + DataRdr rdr = conn.Exec_qry_as_old_rdr + (Db_qry_.select_().From_("dbs_group_bys") + .Cols_("key1").Cols_groupBy_count("val_int", "val_int_func") + .GroupBy_("key1")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 2); + } + protected void Sum_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20)); + + DataRdr rdr = conn.Exec_qry_as_old_rdr + (Db_qry_.select_().From_("dbs_group_bys") + .Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func") + .GroupBy_("key1")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 30); + } +} diff --git a/140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.java b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.java new file mode 100644 index 000000000..9ffc2783b --- /dev/null +++ b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class GroupBys_mysql_tst extends GroupBys_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Mysql();} + @Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();} + @Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();} + @Test public void Min() {super.MinMax_hook(true);} + @Test public void Max() {super.MinMax_hook(false);} + @Test public void Count() {super.Count_hook();} + @Test public void Sum() {super.Sum_hook();} +} diff --git a/140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java new file mode 100644 index 000000000..75d1586af --- /dev/null +++ b/140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class GroupBys_tdb_tst extends GroupBys_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("130_dbs_group_bys.dsv");} + @Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();} + @Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();} + @Test public void Min() {super.MinMax_hook(true);} + @Test public void Max() {super.MinMax_hook(false);} + @Test public void Count() {super.Count_hook();} + @Test public void Sum() {super.Sum_hook();} + // Avg, CountDistinct +} diff --git a/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java new file mode 100644 index 000000000..be3598157 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*; import gplx.core.stores.*; +public abstract class InsertIntos_base_tst { + protected abstract Db_conn provider_(); + protected Db_conn conn; + @Before public void setup() { + conn = provider_(); + conn.Exec_qry(Db_qry_delete.new_("dbs_group_bys")); + conn.Exec_qry(Db_qry_delete.new_("dbs_insert_intos")); + } + @After public void teardown() { + conn.Rls_conn(); + } + protected void Select_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1)); + + conn.Exec_qry + (Db_qry_.insert_("dbs_insert_intos") + .Cols_("key1", "val_int") + .Select_ + ( new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_group_bys") + ) + ); + DataRdr rdr = conn.Exec_qry_as_old_rdr(new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_insert_intos")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "key1", "a"); + } + protected void GroupBy_hook() { + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1)); + conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2)); + + conn.Exec_qry + (Db_qry_.insert_("dbs_insert_intos") + .Cols_("key1", "val_int") + .Select_ + ( new Db_qry__select_cmd().Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func") + .From_("dbs_group_bys").GroupBy_("key1") + )); + DataRdr rdr = conn.Exec_qry_as_old_rdr(new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_insert_intos")); + GfoNde nde = GfoNde_.rdr_(rdr); + GfoNdeTstr.tst_ValsByCol(nde, "val_int", 3); + } +} diff --git a/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java new file mode 100644 index 000000000..16119dfd9 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class InsertIntos_mysql_tst extends InsertIntos_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Mysql();} + @Test public void Select() {super.Select_hook();} + @Test public void GroupBy() {super.GroupBy_hook();} +} diff --git a/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java new file mode 100644 index 000000000..527eafe99 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class InsertIntos_tdb_tst extends InsertIntos_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("140_dbs_insert_intos.dsv");} + @Test public void Select() {super.Select_hook();} + @Test public void GroupBy() {super.GroupBy_hook();} +} diff --git a/140_dbs/tst/gplx/dbs/joins/Joins_base_tst.java b/140_dbs/tst/gplx/dbs/joins/Joins_base_tst.java new file mode 100644 index 000000000..a7ea3dc23 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/joins/Joins_base_tst.java @@ -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.dbs.joins; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.core.stores.*; +public abstract class Joins_base_tst { + protected Db_conn conn; + @Before public void setup() { + conn = provider_(); + Db_qry_delete.new_("dbs_crud_ops").Exec_qry(conn); + Db_qry_delete.new_("dbs_join1").Exec_qry(conn); + } + @After public void teardown() { + conn.Rls_conn(); + } + protected void InnerJoin_hook() { + conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me")); + conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 1).Val_str("name", "you")); + conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 0).Val_str("join_data", "data0")); + conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 1).Val_str("join_data", "data1")); + Db_qry__select_cmd select = new Db_qry__select_cmd().From_("dbs_crud_ops").Join_("dbs_join1", "j1", Db_qry_.New_join__join("join_id", "dbs_crud_ops", "id")).Cols_("id", "name", "join_data"); + + DataRdr rdr = conn.Exec_qry_as_old_rdr(select); + GfoNde table = GfoNde_.rdr_(rdr); + Tfds.Eq(table.Subs().Count(), 2); + Tfds.Eq(table.Subs().FetchAt_asGfoNde(0).Read("join_data"), "data0"); + Tfds.Eq(table.Subs().FetchAt_asGfoNde(1).Read("join_data"), "data1"); + } + protected abstract Db_conn provider_(); +} diff --git a/140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java b/140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java new file mode 100644 index 000000000..0503fb77c --- /dev/null +++ b/140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.joins; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class Joins_tdb_tst extends Joins_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("120_dbs_joins.dsv");} + @Test public void InnerJoin() { + try { + InnerJoin_hook(); + } + catch (Exception exc) { + if (String_.Has(Err_.Message_lang(exc), "joins not supported for tdbs")) return; + } + Tfds.Fail("'joins not supported for tdbs' error not thrown"); + } +} diff --git a/140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.java b/140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.java new file mode 100644 index 000000000..f1d38b4a0 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.orderBys; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.dbs.qrys.*; +public abstract class OrderBys_base_tst { + @Before public void setup() { + conn = provider_(); + fx.Conn_(conn); + Db_qry_delete.new_("dbs_crud_ops").Exec_qry(conn); + } protected Db_conn_fxt fx = new Db_conn_fxt(); + @After public void teardown() {conn.Rls_conn();} + protected abstract Db_conn provider_(); protected Db_conn conn; + protected void Basic_hook() { + fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 1).Val_str("name", "you")); + fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me")); + + fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", true)); + fx.tst_RowAry(0, 0, "me"); + fx.tst_RowAry(1, 1, "you"); + + fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", false)); + fx.tst_RowAry(0, 1, "you"); + fx.tst_RowAry(1, 0, "me"); + } + protected void SameVals_hook() { + fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me")); + fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "you")); + + fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", true)); + fx.tst_RowAry(0, 0, "me"); + fx.tst_RowAry(1, 0, "you"); + + fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", false)); + fx.tst_RowAry(0, 0, "me"); + fx.tst_RowAry(1, 0, "you"); + } +} diff --git a/140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java b/140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java new file mode 100644 index 000000000..87c93b877 --- /dev/null +++ b/140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java @@ -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.dbs.orderBys; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class OrderBys_tdb_tst extends OrderBys_base_tst { + @Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("120_dbs_joins.dsv");} + @Test public void Basic() { + Basic_hook(); + } + @Test public void SameVals() { + SameVals_hook(); + } +} +//namespace gplx.dbs.crudOps { +// import org.junit.*; +// public class CrudOps_tdb_tst { +// @Before public void setup() {fx = new CrudOpsFxt(Db_conn_fxt.Tdb("100_dbs_crud_ops.dsv"));} CrudOpsFxt fx; +// @Test public void FlushToDisk() { +// fx.Fx().tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "you")); +// Db_qry_flush.new_("dbs_crud_ops").Exec_qry(fx.Fx().Conn()); +// } +// } +//} \ No newline at end of file diff --git a/150_gfui/src/gplx/gfui/controls/GfuiBorderMgr_tst.java b/150_gfui/src/gplx/gfui/controls/GfuiBorderMgr_tst.java new file mode 100644 index 000000000..98e55c75a --- /dev/null +++ b/150_gfui/src/gplx/gfui/controls/GfuiBorderMgr_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.controls; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.draws.*; import gplx.gfui.imgs.*; +public class GfuiBorderMgr_tst { + @Before public void setup() { + borderMgr = GfuiBorderMgr.new_(); + } + @Test public void NullToEdge() { // all null -> one edge + tst_Eq(borderMgr, null, null, null, null, null); + + borderMgr.Top_(red); + tst_Eq(borderMgr, null, red, null, null, null); + } + @Test public void EdgeToAll() { // one edge -> all edge + borderMgr.Top_(red); + tst_Eq(borderMgr, null, red, null, null, null); + + borderMgr.All_(black); + tst_Eq(borderMgr, black, null, null, null, null); + } + @Test public void AllToEdge() { // all edge -> one new; three old + borderMgr.All_(red); + tst_Eq(borderMgr, red, null, null, null, null); + + borderMgr.Top_(black); + tst_Eq(borderMgr, null, black, red, red, red); + } + void tst_Eq(GfuiBorderMgr borderMgr, PenAdp all, PenAdp top, PenAdp left, PenAdp right, PenAdp bottom) { + Tfds.Eq(borderMgr.All(), all); + Tfds.Eq(borderMgr.Top(), top); + Tfds.Eq(borderMgr.Left(), left); + Tfds.Eq(borderMgr.Right(), right); + Tfds.Eq(borderMgr.Bot(), bottom); + } + GfuiBorderMgr borderMgr; + PenAdp black = PenAdp_.black_(), red = PenAdp_.new_(ColorAdp_.Red, 1); +} diff --git a/150_gfui/src/gplx/gfui/controls/customs/GfuiMoveElemBtn_tst.java b/150_gfui/src/gplx/gfui/controls/customs/GfuiMoveElemBtn_tst.java new file mode 100644 index 000000000..06fed80fa --- /dev/null +++ b/150_gfui/src/gplx/gfui/controls/customs/GfuiMoveElemBtn_tst.java @@ -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.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*; +import org.junit.*; import gplx.gfui.ipts.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*; +public class GfuiMoveElemBtn_tst { + @Before public void setup() { + form = GfuiWin_.app_("form"); form.Size_(100, 100); + moveBtn = GfuiBtn_.new_("moveBtn"); + GfuiMoveElemBnd bnd = GfuiMoveElemBnd.new_(); bnd.TargetElem_set(form); + moveBtn.IptBnds().Add(bnd); + } + @Test public void Basic() { + Tfds.Eq(form.X(), 0); + IptEventMgr.ExecKeyDown(moveBtn, IptEvtDataKey.test_(MoveRightArg())); + Tfds.Eq(form.X(), 10); + } + + IptKey MoveRightArg() {return IptKey_.Ctrl.Add(IptKey_.Right);} + GfuiWin form; GfuiBtn moveBtn; +} diff --git a/150_gfui/src/gplx/gfui/controls/standards/Gfui_tab_itm_data_tst.java b/150_gfui/src/gplx/gfui/controls/standards/Gfui_tab_itm_data_tst.java new file mode 100644 index 000000000..39cd37461 --- /dev/null +++ b/150_gfui/src/gplx/gfui/controls/standards/Gfui_tab_itm_data_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*; +import org.junit.*; +public class Gfui_tab_itm_data_tst { + @Before public void init() {} private Gfui_tab_itm_data_fxt fxt = new Gfui_tab_itm_data_fxt(); + @Test public void Get_idx_after_closing() { + fxt.Test_Get_idx_after_closing(0, 1, -1); + fxt.Test_Get_idx_after_closing(4, 5, 3); + fxt.Test_Get_idx_after_closing(3, 5, 4); + } +} +class Gfui_tab_itm_data_fxt { + public void Test_Get_idx_after_closing(int cur, int len, int expd) { + Tfds.Eq(expd, Gfui_tab_itm_data.Get_idx_after_closing(cur, len)); + } +} diff --git a/150_gfui/src/gplx/gfui/controls/tabs/TabBox_tst.java b/150_gfui/src/gplx/gfui/controls/tabs/TabBox_tst.java new file mode 100644 index 000000000..916265bd7 --- /dev/null +++ b/150_gfui/src/gplx/gfui/controls/tabs/TabBox_tst.java @@ -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.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*; +import org.junit.*; import gplx.gfui.controls.tabs.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; +public class TabBox_tst { +// @Before public void setup() { +// fx = TabBoxFxt.new_(); +// } TabBoxFxt fx; + @Test public void Add() { +// fx.Make(1).tst_Selected("0").FetchBtnAt(0).tst_X(0); +// fx.Make(3).tst_Selected("2").FetchBtnAt(2).tst_X(160); + } +// @Test public void Del_at() { +// fx.Make(2).Del_at(1).tst_Btns("0"); +// fx.Make(2).Del_at(0).tst_Btns("1"); +// fx.Make(3).Del_at(0).tst_Btns("1", "2"); +// fx.Make(3).Del_at(1).tst_Btns("0", "2"); +// fx.Make(3).Del_at(2).tst_Btns("0", "1"); + +// fx.Make(3).Select(1).Del_at(1).tst_Selected("2"); // 1 deleted; 2 shifted down into slot +// fx.Make(3).Select(1).Del_at(0).tst_Selected("1"); // 0 deleted; 1 still remains active (but will have idx of 0 +// fx.Make(3).Select(2).Del_at(2).tst_Selected("1"); // 2 deleted; 1 selected +// } +// @Test public void Selected_byAdd() { +// fx.Make(2).Select(0).tst_Selected("0").Select(1).tst_Selected("1"); +// } +// @Test public void Selected_byBtn() { +// fx.Make(2).tst_Selected("1"); +// +// GfuiBtn btn = fx.TabBox().SubBtnArea().Get_at(0); +// btn.Click(); +// fx.tst_Selected("0"); +// } +// @Test public void ReorderTab() { +// fx.Make(3).Reorder(0, -1).tst_Raised(false); +// fx.Make(3).Reorder(2, 1).tst_Raised(false); +// fx.Make(3).Reorder(0, 1).tst_Btns("1", "0", "2").tst_Raised(true).tst_FocusOrder(); +// fx.Make(3).Reorder(0, 2).tst_Btns("1", "2", "0").tst_Raised(true).tst_FocusOrder(); +// fx.Make(3).Reorder(2, -1).tst_Btns("0", "2", "1").tst_Raised(true).tst_FocusOrder(); +// fx.Make(3).Reorder(0, 1).Reorder(1, 2).tst_Btns("0", "2", "1").tst_Raised(true);//.tst_FocusOrder(); // FIXME: broken after FocusOrder set for entire form (instead of per container) +// } +} +class GfuiElemFxt { + public GfuiElem UnderElem() {return underElem;} GfuiElem underElem; + @gplx.Internal protected GfuiElemFxt tst_X(int expd) {Tfds.Eq(expd, underElem.X()); return this;} + public static GfuiElemFxt new_(GfuiElem elem) { + GfuiElemFxt rv = new GfuiElemFxt(); + rv.underElem = elem; + return rv; + } GfuiElemFxt() {} +} +class TabBoxFxt implements Gfo_invk { + @gplx.Internal protected TabBox TabBox() {return tabBox;} + @gplx.Internal protected TabBoxFxt Make(int count) { + for (int i = 0; i < tabBox.Tabs_Count(); i++) + tabBox.Tabs_DelAt(0); + for (int i = 0; i < count; i++) + tabBox.Tabs_Add(Int_.To_str(i), Int_.To_str(i)); + return this; + } + @gplx.Internal protected TabBoxFxt Del_at(int index) {tabBox.Tabs_DelAt(index); return this;} +// @gplx.Internal protected TabBoxFxt Select(int index) {tabBox.Tabs_Select(index); return this;} + @gplx.Internal protected GfuiElemFxt FetchBtnAt(int index) { + GfuiBtn btn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(index); + GfuiElemFxt fx_elem = GfuiElemFxt.new_(btn); + return fx_elem; + } +// @gplx.Internal protected TabBoxFxt tst_BtnX(int idx, int expdX) { +// Tfds.Eq(expdX, tabBox.SubBtnArea().Get_at(idx).X()); +// return this; +// } + @gplx.Internal protected TabBoxFxt tst_Selected(String expd) { + TabPnlItm curTab = tabBox.Tabs_SelectedItm(); + GfuiBtn btn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(curTab.Idx()); + Tfds.Eq(expd, btn.Text()); + return this; + } + @gplx.Internal protected TabBoxFxt tst_Btns(String... expd) { + String[] actl = new String[tabBox.Tabs_Count() ]; + for (int i = 0; i < tabBox.Tabs_Count() ; i++) { + GfuiBtn button = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(i); + actl[i] = button.TextMgr().Val(); + } + Tfds.Eq_ary(expd, actl); + return this; + } +// @gplx.Internal protected TabBoxFxt tst_Raised(boolean expd) {Tfds.Eq(expd, received != null); return this;} +// @gplx.Internal protected TabBoxFxt Reorder(int i, int delta) { +// tabBox.Width_(240); // needed for lytMgr +// TabBnd_reorderTab reorderBnd = TabBnd_reorderTab.Instance; +// received = null; +// TabPnl pnl = tabBox.Tabs_FetchAt(i); +// reorderBnd.MoveTab(pnl.SubTabBtn(), delta); +// return this; +// } +// @gplx.Internal protected TabBoxFxt tst_FocusOrder() { +// for (int i = 0; i < tabBox.SubBtnArea().SubZones().Get_at(0).Count(); i++) { +// GfuiElem subBtn = (GfuiElem)tabBox.SubBtnArea().SubZones().Get_at(0).Get_at(i); +// Tfds.Eq(i, subBtn.UnderElem().Core().Focus_index()); +// } +// return this; +// } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, OrderChangedReceived_cmd)) OrderChangedReceived(m); + else return Gfo_invk_.Rv_unhandled; + return this; + } public static final String OrderChangedReceived_cmd = "OrderChangedReceived"; + TabBox tabBox; + public static TabBoxFxt new_() { + TabBoxFxt rv = new TabBoxFxt(); + rv.tabBox = TabBox_.new_(); + return rv; + } TabBoxFxt() {} + void OrderChangedReceived(GfoMsg msg) { + } //int[] received = null; +} diff --git a/150_gfui/src/gplx/gfui/controls/windows/GfuiFocusOrderer_tst.java b/150_gfui/src/gplx/gfui/controls/windows/GfuiFocusOrderer_tst.java new file mode 100644 index 000000000..30e3e27de --- /dev/null +++ b/150_gfui/src/gplx/gfui/controls/windows/GfuiFocusOrderer_tst.java @@ -0,0 +1,85 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.controls.windows; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*; +import org.junit.*; import gplx.gfui.controls.elems.*; +public class GfuiFocusOrderer_tst { + @Before public void setup() { + owner = GfuiElem_.new_(); + list = List_adp_.New(); // list of all controls + } + @Test public void Horizontal() { + ini_Subs(owner, list, xy_(40, 0), xy_(20, 0), xy_(0, 0)); + tst_FocusIndxs(owner, list, 0, 1, 2); + + GfuiFocusOrderer.OrderByX(owner); + tst_FocusIndxs(owner, list, 2, 1, 0); + } + @Test public void Vertical() { + ini_Subs(owner, list, xy_(0, 40), xy_(0, 20), xy_(0, 0)); + tst_FocusIndxs(owner, list, 0, 1, 2); + + GfuiFocusOrderer.OrderByY(owner); + tst_FocusIndxs(owner, list, 2, 1, 0); + } + @Test public void Grid() { + ini_Subs(owner, list, xy_(20, 20), xy_(0, 20), xy_(20, 0), xy_(0, 0)); + tst_FocusIndxs(owner, list, 0, 1, 2, 3); + + GfuiFocusOrderer.OrderByX(owner); + tst_FocusIndxs(owner, list, 3, 2, 1, 0); + } + @Test public void Deep() { + ini_Subs(owner, list, xy_(20, 0), xy_(0, 0)); + GfuiElem sub0 = sub_(owner, 0), sub1 = sub_(owner, 1); + ini_Subs(sub0, list, xy_(20, 0), xy_(0, 0)); + ini_Subs(sub1, list, xy_(20, 0), xy_(0, 0)); + tst_FocusIndxs(owner, list, 0, 1, 0, 1, 0, 1); // 2 owner controls (0, 1); each has two subs (0, 1) + + GfuiFocusOrderer.OrderByX(owner); + tst_FocusIndxs(owner, list, 3, 0, 5, 4, 2, 1); + } + @Test public void Manusl() { + ini_Subs(owner, list, xy_(0, 0), xy_(20, 0)); + tst_FocusIndxs(owner, list, 0, 1); + + GfuiElem sub1 = owner.SubElems().Get_at(0); + GfuiElem sub2 = owner.SubElems().Get_at(1); + sub1.Focus_idx_(1); + sub2.Focus_idx_(0); + + GfuiFocusOrderer.OrderByX(owner); + tst_FocusIndxs(owner, list, 1, 0); + } + PointAdp xy_(int x, int y) {return PointAdp_.new_(x, y);} + GfuiElem sub_(GfuiElem owner, int i) {return owner.SubElems().Get_at(i);} + void ini_Subs(GfuiElem owner, List_adp list, PointAdp... points) { + for (int i = 0; i < points.length; i++) { + GfuiElem sub = GfuiElem_.sub_(Int_.To_str(i), owner); + sub.Pos_(points[i]); + sub.UnderElem().Core().Focus_index_set(i); + list.Add(sub); + } + } + void tst_FocusIndxs(GfuiElem owner, List_adp list, int... expd) { + int[] actl = new int[list.Count()]; + for (int i = 0; i < actl.length; i++) { + GfuiElem sub = (GfuiElem)list.Get_at(i); + actl[i] = sub.UnderElem().Core().Focus_index(); + } + Tfds.Eq_ary(expd, actl); + } + GfuiElem owner; List_adp list; +} diff --git a/150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java b/150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java new file mode 100644 index 000000000..f28df31bf --- /dev/null +++ b/150_gfui/src/gplx/gfui/draws/ColorAdp__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.draws; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class ColorAdp__tst { + @Test public void parse_hex_() { + tst_parse_hex_("#00000000", 0, 0, 0, 0); + tst_parse_hex_("#000102FF", 0, 1, 2, 255); + tst_parse_hex_("#FF000102", 255, 0, 1, 2); + } + @Test public void parse_int_() { + tst_parse_int_(0, 0, 0, 0, 0); + tst_parse_int_(255, 0, 0, 0, 255); + tst_parse_int_(65535, 0, 0, 255, 255); + tst_parse_int_(16777215, 0, 255, 255, 255); + tst_parse_int_(Int_.Max_value, 127, 255, 255, 255); + tst_parse_int_(-1, 255, 255, 255, 255); + } + @Test public void parse() { + tst_parse_("0,0,0,0", 0, 0, 0, 0); // parse all ints + tst_parse_("0,0,0", 255, 0, 0, 0); // a=255, parse rest + tst_parse_("255", 0, 0, 0, 255); // parse as single int + } + void tst_parse_hex_(String raw, int a, int r, int g, int b) { + ColorAdp color = ColorAdp_.parse_hex_(raw); + tst_ColorAdp(color, a, r, g, b); + Tfds.Eq(color.XtoHexStr(), raw); + } + void tst_parse_int_(int val, int a, int r, int g, int b) { + ColorAdp color = ColorAdp_.new_int_(val); + tst_ColorAdp(color, a, r, g, b); + Tfds.Eq(color.Value(), val); + } + void tst_parse_(String s, int alpha, int red, int green, int blue) {tst_ColorAdp(ColorAdp_.parse(s), alpha, red, green, blue);} + void tst_ColorAdp(ColorAdp color, int alpha, int red, int green, int blue) { + TfdsTstr_fxt tstr = TfdsTstr_fxt.new_(); + tstr.Eq_str(color.Alpha(), alpha, "alpha"); + tstr.Eq_str(color.Red(), red, "red"); + tstr.Eq_str(color.Green(), green, "green"); + tstr.Eq_str(color.Blue(), blue, "blue"); + tstr.tst_Equal("color"); + } +} diff --git a/150_gfui/src/gplx/gfui/envs/ClipboardAdp__tst.java b/150_gfui/src/gplx/gfui/envs/ClipboardAdp__tst.java new file mode 100644 index 000000000..d4d745976 --- /dev/null +++ b/150_gfui/src/gplx/gfui/envs/ClipboardAdp__tst.java @@ -0,0 +1,24 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.envs; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.envs.*; +public class ClipboardAdp__tst { + @Test public void Basic() { + ClipboardAdp_.SetText("test"); + Tfds.Eq(true, ClipboardAdp_.IsText()); + Tfds.Eq("test", ClipboardAdp_.GetText()); + } +} diff --git a/150_gfui/src/gplx/gfui/envs/ScreenAdp_tst.java b/150_gfui/src/gplx/gfui/envs/ScreenAdp_tst.java new file mode 100644 index 000000000..dea1799d5 --- /dev/null +++ b/150_gfui/src/gplx/gfui/envs/ScreenAdp_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.envs; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.envs.*; +public class ScreenAdp_tst { + @Test public void parse() { + ScreenAdp actl = ScreenAdp_.parse("{screen{0}"); + Tfds.Eq(0, actl.Index()); + } + @Test public void opposite_() { + ScreenAdp actl = ScreenAdp_.from_point_(PointAdp_.new_(2000, 2000)); + Tfds.Eq(0, actl.Index()); + } +} diff --git a/150_gfui/src/gplx/gfui/imgs/ImageAdp_tst.java b/150_gfui/src/gplx/gfui/imgs/ImageAdp_tst.java new file mode 100644 index 000000000..389a9f21d --- /dev/null +++ b/150_gfui/src/gplx/gfui/imgs/ImageAdp_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.imgs; import gplx.*; import gplx.gfui.*; +import org.junit.*; +import gplx.core.consoles.*; +import gplx.core.ios.*; +import gplx.core.security.*; +import gplx.gfui.imgs.*; +public class ImageAdp_tst { + @Before public void setup() { + load = Tfds.RscDir.GenSubFil_nest("150_gfui", "imgs", "strawberry_java.bmp"); + } ImageAdp img; Io_url load; + @Test public void load_() { + img = ImageAdp_.file_(load); + Tfds.Eq(80, img.Width()); + Tfds.Eq(80, img.Height()); + Tfds.Eq("80,80", img.Size().toString()); + Tfds.Eq(img.Url(), load); + } + @Test public void SaveAsBmp() { + img = ImageAdp_.file_(load); + Io_url save = load.GenNewNameOnly("strawberry_temp"); + DateAdp beforeModifiedTime = Io_mgr.Instance.QueryFil(save).ModifiedTime(); + img.SaveAsBmp(save); + DateAdp afterModifiedTime = Io_mgr.Instance.QueryFil(save).ModifiedTime(); + Tfds.Eq_true(CompareAble_.Is(CompareAble_.More, afterModifiedTime, beforeModifiedTime)); + + Hash_algo algo = Hash_algo_.New__md5(); + String loadHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load)); + String saveHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(save)); + Tfds.Eq(loadHash, saveHash); + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/GfuiClickKeyMgr_tst.java b/150_gfui/src/gplx/gfui/ipts/GfuiClickKeyMgr_tst.java new file mode 100644 index 000000000..5b1532ebe --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/GfuiClickKeyMgr_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.ipts.*; import gplx.gfui.controls.windows.*; +public class GfuiClickKeyMgr_tst { + @Test public void ExtractKeyFromText() { + tst_ExtractKey("&click", IptKey_.C); + tst_ExtractKey("&", IptKey_.None); + tst_ExtractKey("trailing &", IptKey_.None); + tst_ExtractKey("me & you", IptKey_.None); + } + void tst_ExtractKey(String text, IptKey expd) { + IptKey actl = GfuiWinKeyCmdMgr.ExtractKeyFromText(text); + Tfds.Eq(expd, actl); + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptArgChainMgr_tst.java b/150_gfui/src/gplx/gfui/ipts/IptArgChainMgr_tst.java new file mode 100644 index 000000000..8ecd8dfd1 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptArgChainMgr_tst.java @@ -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.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class IptArgChainMgr_tst { + @Before public void setup() { + fx = new IptArgChainMgr_fx(); + } IptArgChainMgr_fx fx; + @Test public void Add() { + fx.run_Add(IptKey_.A, IptKey_.B, IptKey_.C); + fx.tst_(IptKey_.A, 1); + fx.tst_(IptKey_.B, 1); + fx.tst_(IptKey_.C, 2); + fx.tst_(IptKey_.B, 0); + fx.tst_(IptKey_.C, 0); + } + @Test public void Del() { + fx.run_Add(IptKey_.A, IptKey_.B, IptKey_.C); + fx.run_Del(IptKey_.A, IptKey_.B, IptKey_.C); + fx.tst_(IptKey_.A, 0); + fx.tst_(IptKey_.B, 0); + fx.tst_(IptKey_.C, 0); + } + class IptArgChainMgr_fx { + public IptArgChainMgr Under() {return under;} IptArgChainMgr under = new IptArgChainMgr(); + public IptArgChainMgr_fx run_Add(IptKey... ary) {under.Add(new IptKeyChain(ary)); return this;} + public IptArgChainMgr_fx run_Del(IptKey... ary) {under.Del(new IptKeyChain(ary)); return this;} + public IptArgChainMgr_fx tst_(IptKey key, int expd) { + String process = under.Process(key); + String activeKey = under.ActiveKey(); + String literal = key.Key(); + if (expd == 0) { + Tfds.Eq(process, "", "0:{0} should be empty:process", literal); + Tfds.Eq(activeKey, "", "0:{0} should be noop:activeKey", literal); + } + else if (expd == 1) { + Tfds.Eq(process, "", "1:{0} should be empty:process", literal); + Tfds.Eq_true(String_.Has_at_end(activeKey, key.Key() + ","), "1:{0} should set key:activeKey,{1}", literal, activeKey); + } + else if (expd == 2) { + Tfds.Eq_true(String_.EqNot(process, ""), "2:{0} should not be empty;process,{1}", literal, process); + Tfds.Eq(activeKey, "", "2:{0} should be empty:activeKey", literal); + } + return this; + } + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptArg_parser_tst.java b/150_gfui/src/gplx/gfui/ipts/IptArg_parser_tst.java new file mode 100644 index 000000000..d9d3f8a02 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptArg_parser_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.ipts.*; +public class IptArg_parser_tst { + @Test public void KeyBasic() { + tst_parse_Key_("key.a", IptKey_.A); + tst_parse_Key_("key.d0", IptKey_.D0); + tst_parse_Key_("key.semicolon", IptKey_.Semicolon); + tst_parse_Key_("key.equal", IptKey_.Equal); + tst_parse_Key_("key.pageUp", IptKey_.PageUp); + tst_parse_Key_("key.ctrl", IptKey_.Ctrl); + tst_parse_Key_("key.none", IptKey_.None); + } void tst_parse_Key_(String raw, IptKey expd) {Tfds.Eq(expd.Val(), IptKey_.parse(raw).Val());} + @Test public void KbdCmdModifiers() { + tst_parse_Key_("key.ctrl+key.enter", IptKey_.Ctrl.Add(IptKey_.Enter)); + tst_parse_Key_("key.alt+key.escape", IptKey_.Alt.Add(IptKey_.Escape)); + tst_parse_Key_("key.shift+key.f1", IptKey_.Shift.Add(IptKey_.F1)); + tst_parse_Key_("key.shift+key.ctrl", IptKey_.Ctrl.Add(IptKey_.Shift)); + tst_parse_Key_("key.ctrl+key.alt+key.slash", IptKey_.Ctrl.Add(IptKey_.Alt).Add(IptKey_.Slash)); + } + @Test public void KeyWhitespace() { + tst_parse_Key_("key.ctrl + key.alt + key.slash", IptKey_.Ctrl.Add(IptKey_.Alt).Add(IptKey_.Slash)); + } + @Test public void MouseBtn() { + tst_parse_MouseBtn_("mouse.left", IptMouseBtn_.Left); + tst_parse_MouseBtn_("mouse.right", IptMouseBtn_.Right); + tst_parse_MouseBtn_("mouse.middle", IptMouseBtn_.Middle); + tst_parse_MouseBtn_("mouse.x1", IptMouseBtn_.X1); + tst_parse_MouseBtn_("mouse.x2", IptMouseBtn_.X2); + } void tst_parse_MouseBtn_(String raw, IptMouseBtn expd) {Tfds.Eq(expd, IptMouseBtn_.parse(raw));} + @Test public void MouseWheel() { + tst_parse_MouseWheel_("wheel.up", IptMouseWheel_.Up); + tst_parse_MouseWheel_("wheel.down", IptMouseWheel_.Down); + } void tst_parse_MouseWheel_(String raw, IptMouseWheel expd) {Tfds.Eq(expd, IptMouseWheel_.parse(raw));} + @Test public void Mod() { + tst_parse_("mod.c", IptKey_.Ctrl); + tst_parse_("mod.cs", IptKey_.add_(IptKey_.Ctrl, IptKey_.Shift)); + tst_parse_("mod.cas", IptKey_.add_(IptKey_.Ctrl, IptKey_.Alt, IptKey_.Shift)); + tst_parse_("mod.c+key.c", IptKey_.add_(IptKey_.Ctrl, IptKey_.C)); + } + @Test public void All() { + tst_parse_("key.c", IptKey_.C); + tst_parse_("mouse.left", IptMouseBtn_.Left); + tst_parse_("wheel.up", IptMouseWheel_.Up); + tst_parse_("mod.c", IptKey_.Ctrl); + } void tst_parse_(String raw, IptArg expd) {Tfds.Eq(expd, IptArg_.parse(raw));} +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptBndMgr_tst.java b/150_gfui/src/gplx/gfui/ipts/IptBndMgr_tst.java new file mode 100644 index 000000000..710397632 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptBndMgr_tst.java @@ -0,0 +1,70 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.core.strings.*; +public class IptBndMgr_tst { + @Before public void setup() { + fx = new IptBndMgr_fx(); + } IptBndMgr_fx fx; + @Test public void Add() { + fx.ini_Clear().run_Add("key.a").tst_Exec_same("key.a").tst_Exec_none("key.b"); + fx.ini_Clear().run_Add("key.ctrl+key.a").tst_Exec_same("key.ctrl+key.a").tst_Exec_none("key.ctrl").tst_Exec_none("key.a"); + fx.ini_Clear().run_Add("key.a|key.b").tst_Exec_same("key.a").tst_Exec_same("key.b").tst_Exec_none("key.c"); + fx.ini_Clear().run_Add("mouse.left").tst_Exec_same("mouse.left"); + fx.ini_Clear().run_Add("key.a,key.b") + .tst_Exec_none("key.a").tst_Exec_same("key.b") + .tst_Exec_none("key.a").tst_Exec_none("key.c").tst_Exec_none("key.a").tst_Exec_same("key.b") + .tst_Exec_none("key.a").tst_Exec_none("key.a").tst_Exec_none("key.b"); + } + class IptBndMgr_fx { + public IptBndMgr Under() {return under;} IptBndMgr under = IptBndMgr.new_(); + public IptBndMgr_fx ini_Clear() {under.Clear(); return this;} + public IptBndMgr_fx run_Add(String raw) { + IptArg[] args = IptArg_.parse_ary_(raw); + List_adp list = List_adp_.New(); + for (IptArg arg : args) + list.Add(arg); + + IptBnd_mok bnd = new IptBnd_mok(output).Key_(raw).Ipts_(list).EventTypes_(IptEventType_.default_(args)); + under.Add(bnd); + return this; + } + public IptBndMgr_fx tst_Exec_none(String key) {return tst_Exec(key, "");} + public IptBndMgr_fx tst_Exec_same(String key) {return tst_Exec(key, key);} + public IptBndMgr_fx tst_Exec(String key, String expd) { + output.Clear(); + IptArg[] args = IptArg_.parse_ary_(key); + for (IptArg arg : args) { + IptEventData evData = IptEventData.new_(null, IptArg_.EventType_default(arg), arg, null, null); + under.Process(evData); + } + Tfds.Eq(expd, output.To_str()); + return this; + } + String_bldr output = String_bldr_.new_(); + public IptBndMgr_fx() {} + } + class IptBnd_mok implements IptBnd { + public String Key() {return key;} public IptBnd_mok Key_(String v) {key = v; return this;} private String key; + public List_adp Ipts() {return args;} public IptBnd_mok Ipts_(List_adp v) {args = v; return this;} List_adp args; + public IptEventType EventTypes() {return eventTypes;} public IptBnd_mok EventTypes_(IptEventType v) {eventTypes = v; return this;} IptEventType eventTypes; + public Object Srl(GfoMsg owner) {return this;} + public void Exec(IptEventData iptData) { + output.Add(iptData.EventArg().Key()); + } + public IptBnd_mok(String_bldr v) {output = v;} String_bldr output; + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptCfg_tst.java b/150_gfui/src/gplx/gfui/ipts/IptCfg_tst.java new file mode 100644 index 000000000..6a4329fd4 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptCfg_tst.java @@ -0,0 +1,82 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class IptCfg_tst { + @Before public void setup() { + IptCfgRegy.Instance.Clear(); + box = new IptBndsOwner_mok(); + cfg = new IptCfg_mok(); + key = IptBndsOwner_mok.Invk_Reg; + } IptBndsOwner_mok box; IptCfg_mok cfg; String key; + @Test public void Basic() { + cfg.run_GetOrDflt(box, key, IptKey_.A); + box.tst_SendKey(IptKey_.A, 1); + } + @Test public void Del() { + cfg.run_GetOrDflt(box, key, IptKey_.A); + box.IptBnds().Cfgs_delAll(); + box.tst_SendKey(IptKey_.A, 0); + } + @Test public void Change() { + cfg.run_GetOrDflt(box, key, IptKey_.A); + cfg.run_Set(key, IptKey_.B); + box.tst_SendKey(IptKey_.B, 1); + + cfg.run_Set(key, IptKey_.C); + box.tst_SendKey(IptKey_.C, 1); + box.tst_SendKey(IptKey_.B, 0); + } + @Test public void SetBeforeInit() { + cfg.run_Set(key, IptKey_.B); + cfg.run_GetOrDflt(box, key, IptKey_.A); + box.tst_SendKey(IptKey_.B, 1); + box.tst_SendKey(IptKey_.A, 0); + } + @Test public void SetBeforeInit_msg() { + cfg.run_Set_msg(key, 2, IptKey_.B); + cfg.run_GetOrDflt(box, key, IptKey_.A); // iptBnd exists; ignore Key_.A (and also msg=1) + box.tst_SendKey(IptKey_.B, 2); + box.tst_SendKey(IptKey_.A, 0); + } + @Test public void Chained() { + cfg.run_GetOrDflt(box, key, IptKeyChain.parse("key.ctrl+key.a,key.b")); + cfg.run_Set(key, IptKey_.A); + box.tst_SendKey(IptKey_.A, 1); + } + class IptCfg_mok { + public IptCfg Cfg() {return cfg;} + public void run_GetOrDflt(IptBndsOwner box, String key, IptArg... ary) {IptBnd_.msg_(cfg, box, key, make_(key, 1), ary);} + public void run_Set(String key, IptArg... ary) {cfg.Set(key, make_(key, 1), ary);} + public void run_Set_msg(String key, int i, IptArg... ary) {cfg.Set(key, make_(key, i), ary);} + GfoMsg make_(String key, int i) {return GfoMsg_.new_cast_(key).Add("val", i);} + public IptCfg_mok() {cfg = (IptCfg_base)IptCfg_.new_("cfg");} IptCfg_base cfg; + } + class IptBndsOwner_mok implements IptBndsOwner { + public IptBndMgr IptBnds() {return iptBnds;} IptBndMgr iptBnds = IptBndMgr.new_(); + public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr; + public void tst_SendKey(IptKey key, int expd) { + iptBnds.Process(IptEventData.new_(null, IptEventType_.KeyDown, key, IptEvtDataKey.new_(key), IptEvtDataMouse.Null)); + Tfds.Eq(expd, actl); + actl = 0; + } int actl; + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Invk_Reg)) {actl = m.ReadIntOr("val", 0);} + else return Gfo_invk_.Rv_unhandled; + return this; + } public static final String Invk_Reg = "Reg"; + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptEventType_tst.java b/150_gfui/src/gplx/gfui/ipts/IptEventType_tst.java new file mode 100644 index 000000000..089f2b325 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptEventType_tst.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; import gplx.gfui.ipts.*; +public class IptEventType_tst { + @Test public void Has() { + tst_Has(IptEventType_.KeyDown, IptEventType_.KeyDown, true); + tst_Has(IptEventType_.KeyUp, IptEventType_.KeyDown, false); + tst_Has(IptEventType_.None, IptEventType_.KeyDown, false); + tst_Has(IptEventType_.KeyDown, IptEventType_.None, false); + tst_Has(IptEventType_.KeyDown.Add(IptEventType_.KeyUp), IptEventType_.KeyDown, true); + tst_Has(IptEventType_.MouseDown.Add(IptEventType_.MouseUp), IptEventType_.KeyDown, false); + tst_Has(IptEventType_.KeyDown.Add(IptEventType_.KeyUp), IptEventType_.None, false); + } void tst_Has(IptEventType val, IptEventType find, boolean expd) {Tfds.Eq(expd, IptEventType_.Has(val, find));} + @Test public void add_() { + tst_add(IptEventType_.KeyDown, IptEventType_.KeyDown, IptEventType_.KeyDown.Val()); + tst_add(IptEventType_.KeyDown, IptEventType_.KeyUp, IptEventType_.KeyDown.Val() + IptEventType_.KeyUp.Val()); + } void tst_add(IptEventType lhs, IptEventType rhs, int expd) {Tfds.Eq(expd, IptEventType_.add_(lhs, rhs).Val());} +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptKeyStrMgr_tst.java b/150_gfui/src/gplx/gfui/ipts/IptKeyStrMgr_tst.java new file mode 100644 index 000000000..f7628302b --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptKeyStrMgr_tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class IptKeyStrMgr_tst { + @Test public void KeyBasic() { + tst_XtoUiStr(IptKey_.A, "a"); + tst_XtoUiStr(IptKey_.Z, "z"); + tst_XtoUiStr(IptKey_.Shift.Add(IptKey_.A), "A"); + tst_XtoUiStr(IptKey_.Shift.Add(IptKey_.Z), "Z"); + tst_XtoUiStrShifted(IptKey_.Equal, "=", "+"); + tst_XtoUiStrShifted(IptKey_.D0, "0", ")"); + tst_XtoUiStrShifted(IptKey_.D1, "1", "!"); + tst_XtoUiStrShifted(IptKey_.D2, "2", "@"); + tst_XtoUiStrShifted(IptKey_.D3, "3", "#"); + tst_XtoUiStrShifted(IptKey_.D4, "4", "$"); + tst_XtoUiStrShifted(IptKey_.D5, "5", "%"); + tst_XtoUiStrShifted(IptKey_.D6, "6", "^"); + tst_XtoUiStrShifted(IptKey_.D7, "7", "&"); + tst_XtoUiStrShifted(IptKey_.D8, "8", "*"); + tst_XtoUiStrShifted(IptKey_.D9, "9", "("); + tst_XtoUiStrShifted(IptKey_.Minus, "-", "_"); + tst_XtoUiStrShifted(IptKey_.Backslash, "\\", "|"); + tst_XtoUiStrShifted(IptKey_.Semicolon, ";", ":"); + tst_XtoUiStrShifted(IptKey_.Quote, "'", "\""); + tst_XtoUiStrShifted(IptKey_.Comma, ",", "<"); + tst_XtoUiStrShifted(IptKey_.Period, ".", ">"); + tst_XtoUiStrShifted(IptKey_.Slash, "?", "/"); + tst_XtoUiStrShifted(IptKey_.Tick, "`", "~"); + tst_XtoUiStrShifted(IptKey_.OpenBracket, "[", "{"); + tst_XtoUiStrShifted(IptKey_.CloseBracket, "]", "}"); + } + @Test public void FetchByKeyPress() { + tst_FetchByKeyPress('a', IptKey_.add_(IptKey_.A)); + tst_FetchByKeyPress('A', IptKey_.add_(IptKey_.A, IptKey_.Shift)); + tst_FetchByKeyPress('1', IptKey_.add_(IptKey_.D1)); + tst_FetchByKeyPress('!', IptKey_.add_(IptKey_.D1, IptKey_.Shift)); + } void tst_FetchByKeyPress(char c, IptKey expd) {Tfds.Eq(expd.Key(), IptKeyStrMgr.Instance.FetchByKeyPress((int)c).Key());} + void tst_XtoUiStr(IptKey key, String expd) {Tfds.Eq(expd, key.XtoUiStr());} + void tst_XtoUiStrShifted(IptKey key, String expdNormal, String expdShifted) { + Tfds.Eq(expdNormal, key.XtoUiStr()); + Tfds.Eq(expdShifted, IptKey_.Shift.Add(key).XtoUiStr()); + } +} diff --git a/150_gfui/src/gplx/gfui/ipts/IptKey__tst.java b/150_gfui/src/gplx/gfui/ipts/IptKey__tst.java new file mode 100644 index 000000000..c447f9491 --- /dev/null +++ b/150_gfui/src/gplx/gfui/ipts/IptKey__tst.java @@ -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.gfui.ipts; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class IptKey__tst { + private final IptKey__fxt fxt = new IptKey__fxt(); + @Test public void To_str() { + fxt.Test_to_str(196608, "mod.cs"); + } + @Test public void To_str__numeric() { + fxt.Test_to_str(12345, "key.#12345"); + } + @Test public void Parse() { + fxt.Test_parse("key.#10", 10); + } +} +class IptKey__fxt { + public void Test_to_str(int keycode, String expd) { + Tfds.Eq(expd, IptKey_.To_str(keycode)); + } + public void Test_parse(String raw, int keycode) { + Tfds.Eq(keycode, IptKey_.parse(raw).Val()); + } +} diff --git a/150_gfui/src/gplx/gfui/layouts/GftBand_tst.java b/150_gfui/src/gplx/gfui/layouts/GftBand_tst.java new file mode 100644 index 000000000..5206b5642 --- /dev/null +++ b/150_gfui/src/gplx/gfui/layouts/GftBand_tst.java @@ -0,0 +1,110 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui.layouts; import gplx.*; import gplx.gfui.*; +import org.junit.*; +public class GftBand_tst { + @Before public void setup() { + fx.Clear().ini_OwnerSize(200, 400); + } GftGrid_fx fx = new GftGrid_fx(); + @Test public void Bands_1() { + fx .ini_AddItms(2) + .ini_Set(0, GftBand.new_().Cells_num_(2)) + .run() + .tst_Filter(0, 1).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(0); + } + @Test public void Bands_1_half() { // only add 1 to 2 cell-band + fx .ini_AddItms(1) + .ini_Set(0, GftBand.new_().Cells_num_(2)) + .run() + .tst_Filter(0).tst_X(0).tst_W(100).tst_H(20).tst_Y(0); + } + @Test public void Bands_2() { // put cells 2, 3 on band 1 + fx .ini_AddItms(4) + .ini_Set(0, GftBand.new_().Cells_num_(2)) + .ini_Set(1, GftBand.new_().Cells_num_(2)) + .run() + .tst_Filter(0, 1).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(0) + .tst_Filter(2, 3).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(20); // put on 2nd row + } + @Test public void Pct_one() { + fx .ini_AddItms(1) + .ini_Set(0, GftBand.new_().Cell_pct_(50)) + .run() + .tst_Filter(0).tst_X(0).tst_W(100).tst_H_all(20).tst_Y_all(0); + } + @Test public void Pct_many() { + fx .ini_AddItms(3) + .ini_Set(0, GftBand.new_().Cell_pct_(20).Cell_pct_(70).Cell_pct_(10)) + .run() + .tst_Filter(0, 2).tst_W(40, 140, 20).tst_X(0, 40, 180).tst_H_all(20).tst_Y_all(0); + } + @Test public void Mix_pctAtEnd() { + fx .ini_AddItms(2) + .ini_Set(0, GftBand.new_().Cell_abs_(60).Cell_pct_(100)) + .run() + .tst_Filter(0, 1).tst_X(0, 60).tst_W(60, 140).tst_H_all(20).tst_Y_all(0); + } + @Test public void Mix_pctAtBgn() { + fx .ini_AddItms(2) + .ini_Set(0, GftBand.new_().Cell_pct_(100).Cell_abs_(60)) + .run() + .tst_Filter(0, 1).tst_X(0, 140).tst_W(140, 60).tst_H_all(20).tst_Y_all(0); + } + @Test public void Mix_pctAtMid() { + fx .ini_AddItms(3) + .ini_Set(0, GftBand.new_().Cell_abs_(60).Cell_pct_(100).Cell_abs_(40)) + .run() + .tst_Filter(0, 2).tst_X(0, 60, 160).tst_W(60, 100, 40).tst_H_all(20).tst_Y_all(0); + } + @Test public void Height_pct() { + fx .ini_AddItms(1) + .ini_Set(0, GftBand.new_().Cell_pct_(100).Len1_pct_(100)) + .run() + .tst_Filter(0).tst_X(0).tst_W(200).tst_H_all(400).tst_Y_all(0); + } + @Test public void Height_mix() { + fx .ini_AddItms(3) + .ini_Set(0, GftBand.new_().Cells_num_(1).Len1_abs_( 60)) + .ini_Set(1, GftBand.new_().Cells_num_(1).Len1_pct_(100)) + .ini_Set(2, GftBand.new_().Cells_num_(1).Len1_abs_( 20)) + .run() + .tst_Filter(0).tst_H( 60).tst_Y_all( 0).tst_X(0).tst_W(200) + .tst_Filter(1).tst_H(320).tst_Y_all( 60).tst_X(0).tst_W(200) + .tst_Filter(2).tst_H( 20).tst_Y_all(380).tst_X(0).tst_W(200); + } + @Test public void RevDir() { + fx .ini_AddItms(2).ini_BandDir(DirInt.Bwd) + .ini_Set(0, 1, GftBand.new_().Cells_num_(1).Len1_abs_(20)) + .run() + .tst_Filter(0).tst_W(200).tst_H(20).tst_X(0).tst_Y(380) + .tst_Filter(1).tst_W(200).tst_H(20).tst_X(0).tst_Y(360); + } + @Test public void SubLyts() { + fx .ini_AddItms(2).ini_AddLyts(2) + .ini_Lyt(0).ini_Set(0, GftBand.new_().Cells_num_(1).Len1_pct_(100)) + .ini_Lyt(1).ini_Set(0, GftBand.new_().Cells_num_(1).Len1_abs_( 20)).ini_BandDir(DirInt.Bwd) + .run() + .tst_Filter(0).tst_W(200).tst_H(400).tst_X(0).tst_Y( 0) + .tst_Filter(1).tst_W(200).tst_H( 20).tst_X(0).tst_Y(380); + } + @Test public void Var() { + fx .ini_AddItms(2) + .ini_ItmWidth(0, 30).ini_ItmWidth(1, 40) + .ini_Set(0, GftBand.new_().Cells_var_(2)) + .run() + .tst_Filter(0, 1).tst_X(0, 30).tst_W(30, 40).tst_H_all(20).tst_Y_all(0); + } +} diff --git a/400_xowa/src/gplx/core/brys/Bit__tst.java b/400_xowa/src/gplx/core/brys/Bit__tst.java new file mode 100644 index 000000000..f5aaf5638 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Bit__tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bit__tst { + @Before public void init() {fxt.Clear();} private Bit__fxt fxt = new Bit__fxt(); + @Test public void XtoBitStr() { + tst_XtoBitStr( 0, "00000000"); + tst_XtoBitStr( 1, "00000001"); + tst_XtoBitStr( 2, "00000010"); + tst_XtoBitStr( 3, "00000011"); + tst_XtoBitStr(255, "11111111"); + } void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.ToBitStr(val));} + @Test public void Shift_lhs() {// simple: shift 1 bit + fxt.Test_shift_lhs(1, 1, 2); + fxt.Test_shift_lhs(2, 1, 4); + fxt.Test_shift_lhs(3, 1, 6); + fxt.Test_shift_lhs(4, 1, 8); + } + @Test public void Shift_rhs() { + fxt.Test_shift_rhs(2, 1, 1); + fxt.Test_shift_rhs(4, 1, 2); + fxt.Test_shift_rhs(6, 1, 3); + fxt.Test_shift_rhs(8, 1, 4); + } + @Test public void Shift_lhs_to_int() { + int[] shift_ary = Int_ary_.New(0, 3, 5); + fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 0), 0); + fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 0, 0), 7); // 1st 3 bits + fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 3, 0), 24); // 2nd 2 bits + fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 1), 32); // 3rd 1 bit + fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 3, 1), 63); // many bits + } + @Test public void Shift_rhs_to_ary() { + int[] shift_ary = Int_ary_.New(0, 3, 5); + fxt.Test_shift_rhs_to_ary(shift_ary, 0, Int_ary_.New(0, 0, 0)); + fxt.Test_shift_rhs_to_ary(shift_ary, 7, Int_ary_.New(7, 0, 0)); // 1st 3 bits + fxt.Test_shift_rhs_to_ary(shift_ary, 24, Int_ary_.New(0, 3, 0)); // 2nd 2 bits + fxt.Test_shift_rhs_to_ary(shift_ary, 32, Int_ary_.New(0, 0, 1)); // 3rd 1 bit + fxt.Test_shift_rhs_to_ary(shift_ary, 63, Int_ary_.New(7, 3, 1)); // many bits + } +} +class Bit__fxt { + public void Clear() {} + public void Test_shift_lhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs(val, shift));} + public void Test_shift_rhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_rhs(val, shift));} + public void Test_shift_lhs_to_int(int[] shift_ary, int[] val_ary, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs_to_int(shift_ary, val_ary));} + public void Test_shift_rhs_to_ary(int[] shift_ary, int val, int[] expd_ary) { + int[] actl_ary = Int_ary_.New(0, 0, 0); + Bit_.Shift_rhs_to_ary(actl_ary, shift_ary, val); + Tfds.Eq_ary(expd_ary, actl_ary); + } +} diff --git a/400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java b/400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java new file mode 100644 index 000000000..ec8b2e071 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Bit_heap_rdr_tst.java @@ -0,0 +1,78 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bit_heap_rdr_tst { + private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt(); + @Test public void Get_bool() { + fxt.Load(255); + fxt.Test__get_bool(Bool_.Y).Test__cur(127, 1, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 63, 2, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 31, 3, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 15, 4, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 7, 5, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 3, 6, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 7, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 0, 1); + fxt.Load(0); + fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0); + fxt.Load(6); + fxt.Test__get_bool(Bool_.N).Test__cur( 3, 1, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 2, 0); + fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 3, 0); + } + @Test public void Get_byte() { + fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0); + fxt.Load(255, 3); + fxt.Test__get_byte(7, 127); + fxt.Test__get_byte(3, 7); + fxt.Load(10); + fxt.Test__get_bool(false); + fxt.Test__get_byte(3, 5); + } + @Test public void Get_int_hzip() { + fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1); + fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3); + fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2); + fxt.Load(250, 3, 88, 0).Test__get_bool(Bool_.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3); + } +} +class Bit_heap_rdr_fxt { + private final Bit_heap_rdr heap = new Bit_heap_rdr(); + public Bit_heap_rdr_fxt Load(int... src) { + byte[] bry = Bry_.New_by_ints(src); + heap.Load(bry, 0, bry.length); + return this; + } + public Bit_heap_rdr_fxt Test__get_bool(boolean expd) { + Tfds.Eq_bool(expd, heap.Get_bool()); + return this; + } + public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) { + Tfds.Eq_byte((byte)expd, heap.Get_byte(bits)); + return this; + } + public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) { + Tfds.Eq_int(expd, heap.Get_int_hzip(reqd)); + return this; + } + public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) { + Tfds.Eq_int(cur_val, heap.Cur_val(), "val"); + Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits"); + Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos"); + return this; + } +} diff --git a/400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java b/400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java new file mode 100644 index 000000000..4060ddfb8 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Bit_heap_wtr_tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bit_heap_wtr_tst { + private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt(); + @Test public void Add_bool() { + fxt.Clear().Add_bool(Bool_.Y).Test__vals(1, 1); + fxt.Clear().Add_bool(Bool_.N).Test__vals(1, 0); + fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Test__vals(4, 15); + fxt.Clear().Add_bool(Bool_.Y, Bool_.N, Bool_.N, Bool_.Y).Test__vals(4, 9); + fxt.Clear().Add_bool(8, Bool_.Y).Test__vals(0, 0, 255); + } + @Test public void Add_byte() { + fxt.Clear().Add_byte(255).Test__vals(0, 0, 255); + } + @Test public void Add_bool_byte() { + fxt.Clear().Add_bool(Bool_.N).Add_byte(255).Test__vals(1, 127, 254); + fxt.Clear().Add_bool(Bool_.Y).Add_byte(255).Test__vals(1, 127, 255); + fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Add_byte(255).Test__vals(4, 15, 255); + } + @Test public void Add_byte_digits() { + fxt.Clear().Add_byte(4, 15).Test__vals(4, 15); + fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255); + fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63); + fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255); + fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54); + } + @Test public void Add_int_hzip() { + fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100); + fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44); + fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100); + fxt.Clear().Add_bool(Bool_.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88); + } +} +class Bit_heap_wtr_fxt { + private final Bit_heap_wtr heap = new Bit_heap_wtr(); + public Bit_heap_wtr_fxt Clear() {heap.Clear(); return this;} + public Bit_heap_wtr_fxt Add_bool(int len, boolean v) { + boolean[] ary = new boolean[len]; + for (int i = 0; i < len; ++i) + ary[i] = v; + Add_bool(ary); + return this; + } + public Bit_heap_wtr_fxt Add_bool(boolean... v) { + int len = v.length; + for (int i = 0; i < len; ++i) + heap.Add_bool(v[i]); + return this; + } + public Bit_heap_wtr_fxt Add_byte(int... v) { + int len = v.length; + for (int i = 0; i < len; ++i) + heap.Add_byte((byte)v[i]); + return this; + } + public Bit_heap_wtr_fxt Add_byte(int bits, int val) { + heap.Add_byte(bits, (byte)val); + return this; + } + public Bit_heap_wtr_fxt Add_int_hzip(int reqd, int val) { + heap.Add_int_hzip(reqd, val); + return this; + } + public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) { + Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits"); + Tfds.Eq_int (expd_cur , heap.Cur() , "cur"); + Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap"); + } +} diff --git a/400_xowa/src/gplx/core/brys/Bry_diff_tst.java b/400_xowa/src/gplx/core/brys/Bry_diff_tst.java new file mode 100644 index 000000000..7d56ab3e3 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Bry_diff_tst.java @@ -0,0 +1,42 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Bry_diff_tst { + @Before public void init() {} private final Bry_diff_fxt fxt = new Bry_diff_fxt(); + @Test public void Diff_1st() { + fxt.Test__diff_1st("a|b|c" , "a|b|c" , null , null); + fxt.Test__diff_1st("a|b|c" , "a|b1|c" , "b" , "b1"); + fxt.Test__diff_1st("a|b|" , "a|b|c" , "<>" , "c"); + fxt.Test__diff_1st("a|b|c" , "a|b|" , "c" , "<>"); + } + @Test public void Diff_1st_show() { + fxt.Test__diff_1st("a|bd|e" , "a|be|e" , "d", "e"); + } +} +class Bry_diff_fxt { + public void Test__diff_1st(String lhs, String rhs, String expd_lhs, String expd_rhs) { + byte[] lhs_src = Bry_.new_u8(lhs); + byte[] rhs_src = Bry_.new_u8(rhs); + byte[][] actl = Bry_diff_.Diff_1st(lhs_src, 0, lhs_src.length, rhs_src, 0, rhs_src.length, Byte_ascii.Pipe_bry, Byte_ascii.Angle_bgn_bry, 255); + if (expd_lhs == null && expd_rhs == null) + Tfds.Eq_true(actl == null, "actl not null"); + else { + Tfds.Eq_bry(Bry_.new_u8(expd_lhs), actl[0]); + Tfds.Eq_bry(Bry_.new_u8(expd_rhs), actl[1]); + } + } +} diff --git a/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java b/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java new file mode 100644 index 000000000..22040179d --- /dev/null +++ b/400_xowa/src/gplx/core/brys/Int_flag_bldr__tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Int_flag_bldr__tst { + private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt(); + @Test public void Bld_pow_ary() { + fxt.Test__bld_pow_ary(fxt.Make__ary(1, 1, 1, 1), fxt.Make__ary(8, 4, 2, 1)); + fxt.Test__bld_pow_ary(fxt.Make__ary(3, 2) , fxt.Make__ary(4, 1)); + } + @Test public void To_int__1_1_1() { + int[] seg_ary = fxt.Make__ary(1, 1, 1); + fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 0, 0), 0); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 1), 7); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 0, 0), 4); + fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 0), 6); + fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 1, 1), 3); + } + @Test public void To_int__2_3() { + fxt.Test__to_int(fxt.Make__ary(2, 3) , fxt.Make__ary(3, 7) , 31); + fxt.Test__to_int(fxt.Make__ary(1, 2, 3) , fxt.Make__ary(1, 3, 7) , 63); + } + @Test public void To_int__11_4_5_5_6() { + fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 17), 2110135761); + fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 18), 2110135762); + } + @Test public void To_int_ary() { + fxt.Test__to_int_ary(fxt.Make__ary(1, 1, 1, 1) , 15, fxt.Make__ary(1, 1, 1, 1)); + fxt.Test__to_int_ary(fxt.Make__ary(3, 2) , 31, fxt.Make__ary(7, 3)); + fxt.Test__to_int_ary(fxt.Make__ary(3, 2, 1) , 63, fxt.Make__ary(7, 3, 1)); + fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135761, fxt.Make__ary(2012, 6, 3, 23, 17)); + fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135762, fxt.Make__ary(2012, 6, 3, 23, 18)); + } + @Test public void To_int_date_short() { + fxt.Test__to_int_date_short("20120604 2359", 117843451); + fxt.Test__to_int_date_short("20120604 2358", 117843450); + fxt.Test__to_int_date_short("20120605 0000", 117843968); + } +} +class Int_flag_bldr__fxt { + public int[] Make__ary(int... v) {return v;} + public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));} + public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) { + int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary); + Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary)); + int[] actl_val_ary = Int_flag_bldr_.To_int_ary(pow_ary, expd); + Tfds.Eq_ary(val_ary, actl_val_ary); + } + public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) { + int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary); + Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val)); + } + public void Test__to_int_date_short(String date_str, int expd) { + DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm"); + int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry()); + Tfds.Eq(expd, date_int); + Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm")); + } +} diff --git a/400_xowa/src/gplx/core/brys/evals/Bry_eval_mgr__tst.java b/400_xowa/src/gplx/core/brys/evals/Bry_eval_mgr__tst.java new file mode 100644 index 000000000..30531fb92 --- /dev/null +++ b/400_xowa/src/gplx/core/brys/evals/Bry_eval_mgr__tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*; +import org.junit.*; import gplx.core.tests.*; +public class Bry_eval_mgr__tst { + private final Bry_eval_mgr__fxt fxt = new Bry_eval_mgr__fxt(); + @Test public void Text() {fxt.Test__eval("abc" , "abc");} + @Test public void Args_0() {fxt.Test__eval("abc~{test}xyz" , "abctestxyz");} + @Test public void Args_n() {fxt.Test__eval("abc~{concat|d|e|f}xyz" , "abcdefxyz");} + @Test public void Recur_1() {fxt.Test__eval("abc~{~{test}}xyz" , "abctestxyz");} + @Test public void Recur_2() {fxt.Test__eval("abc~{t~{concat|e|s}t}xyz" , "abctestxyz");} + @Test public void Grp_end() {fxt.Test__eval("a}b" , "a}b");} + @Test public void Escape() {fxt.Test__eval("a~~b" , "a~b");} + // @Test public void Eos() {fxt.Test__eval("a~" , "a~");} +} +class Bry_eval_mgr__fxt { + private final Bry_eval_mgr mgr = Bry_eval_mgr.Dflt().Add_many(new Bry_eval_wkr__test(), new Bry_eval_wkr__concat()); + public Bry_eval_mgr__fxt Test__eval(String raw, String expd) { + Gftest.Eq__bry(Bry_.new_u8(expd), mgr.Eval(Bry_.new_u8(raw))); + return this; + } +} +class Bry_eval_wkr__test implements Bry_eval_wkr { + public String Key() {return "test";} + public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) { + rv.Add_str_a7("test"); + } +} +class Bry_eval_wkr__concat implements Bry_eval_wkr { + public String Key() {return "concat";} + public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) { + byte[][] ary = Bry_split_.Split(src, src_bgn, src_end, Byte_ascii.Pipe, false); + for (byte[] itm : ary) { + rv.Add(itm); + } + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/core/btries/Btrie_u8_mgr_tst.java b/400_xowa/src/gplx/core/btries/Btrie_u8_mgr_tst.java new file mode 100644 index 000000000..26973d569 --- /dev/null +++ b/400_xowa/src/gplx/core/btries/Btrie_u8_mgr_tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.btries; import gplx.*; import gplx.core.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Btrie_u8_mgr_tst { + @Before public void init() {fxt.Clear();} private Btrie_u8_mgr_fxt fxt = new Btrie_u8_mgr_fxt(); + @Test public void Ascii() { + fxt.Init_add(Bry_.new_a7("a") , "1"); + fxt.Init_add(Bry_.new_a7("abc") , "123"); + fxt.Test_match("a" , "1"); // single.exact + fxt.Test_match("abc" , "123"); // many.exact + fxt.Test_match("ab" , "1"); // single.more + fxt.Test_match("abcde" , "123"); // many.more + fxt.Test_match(" a" , null); // no_match + fxt.Test_match("aBC" , "123"); // upper + } + @Test public void Uft8() { + fxt.Init_add(Bry_.new_u8("aéi") , "1"); + fxt.Test_match("aéi" , "1"); // exact + fxt.Test_match("aÉi" , "1"); // upper.utf8 + fxt.Test_match("AÉI" , "1"); // upper.all + fxt.Test_match("AÉIo" , "1"); // trailing-char + fxt.Test_match("aei" , null); // no_match + } + @Test public void Uft8_match_pos() { + fxt.Init_add(Bry_.new_u8("aéi") , "1"); + fxt.Test_match_pos("aAÉI" , 1, "1"); // match at 1 + fxt.Test_match_pos("aAÉI" , 0, null); // no_match at 0 + } + @Test public void Uft8_asymmetric() { + fxt.Init_add(Bry_.new_u8("İ") , "1"); + fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176) + fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105) + fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry + + fxt.Clear(); + fxt.Init_add(Bry_.new_u8("i") , "1"); + fxt.Test_match("i" , "1"); // exact=y + fxt.Test_match("I" , "1"); // upper=y + fxt.Test_match("İ" , "1"); // utf_8=y; note that "i" matches "İ" b/c hash is case-insensitive and "İ" lower-cases to "i"; DATE:2015-09-07 + } + @Test public void Utf8_asymmetric_multiple() { // PURPOSE: problems in original implementation of Hash_adp_bry and uneven source / target counts; + fxt.Init_add(Bry_.new_u8("İİ") , "1"); + fxt.Test_match("İİ" , "1"); // exact + fxt.Test_match("ii" , "1"); // lower + fxt.Test_match("İi" , "1"); // mixed + fxt.Test_match("iİ" , "1"); // mixed + } + @Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_u8_itm and called_by_match + fxt.Init_add(Bry_.new_u8("İ") , "1"); + fxt.Init_add(Bry_.new_u8("I") , "1"); + fxt.Test_match("İ" , "1"); // exact + fxt.Test_match("I" , "1"); // exact + fxt.Test_match("i" , "1"); // lower + } + @Test public void Utf8_asymmetric_symbols() { // PURPOSE: test Hash_adp_bry and multi-byte syms (chars that will never be cased) + fxt.Init_add(Bry_.new_u8("a_b") , "1"); + fxt.Test_match("a_b" , "1"); // exact: len=3 + fxt.Test_match("a†b" , null); // diff : len=3 + fxt.Test_match("a±b" , null); // diff : len=2 + fxt.Test_match("a_b" , null); // diff : len=1 + } +} +class Btrie_u8_mgr_fxt { + private Btrie_u8_mgr trie; + public void Clear() { + trie = Btrie_u8_mgr.new_(Xol_case_mgr_.U8()); + } + public void Init_add(byte[] key, Object val) {trie.Add_obj(key, val);} + public void Test_match_pos(String src_str, int bgn_pos, String expd) { + byte[] src = Bry_.new_u8(src_str); + Object actl = trie.Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, src.length); + Tfds.Eq(expd, actl, src_str); + } + public void Test_match(String src_str, String expd) { + byte[] src = Bry_.new_u8(src_str); + Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length); + Tfds.Eq(expd, actl, src_str); + } +} diff --git a/400_xowa/src/gplx/core/caches/Gfo_cache_mgr_tst.java b/400_xowa/src/gplx/core/caches/Gfo_cache_mgr_tst.java new file mode 100644 index 000000000..a91cd39da --- /dev/null +++ b/400_xowa/src/gplx/core/caches/Gfo_cache_mgr_tst.java @@ -0,0 +1,71 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.caches; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*; +public class Gfo_cache_mgr_tst { + @Before public void init() {fxt.Clear();} private final Gfo_cache_mgr_fxt fxt = new Gfo_cache_mgr_fxt(); + @Test public void Basic() { + fxt.Exec__add("a"); + fxt.Test__cur_size(1); + fxt.Test__itms("a"); + } + @Test public void Reduce() { + fxt.Exec__add("a", "b", "c", "d", "e"); + fxt.Test__cur_size(2); + fxt.Test__itms("a", "b"); + } + @Test public void Reduce_after_get() { + fxt.Exec__add("a", "b", "c", "d"); + fxt.Exec__get("a", "c"); + fxt.Exec__add("e"); + fxt.Test__itms("a", "c"); + } +} +class Gfo_cache_mgr_fxt { + private final Gfo_cache_mgr mgr = new Gfo_cache_mgr().Max_size_(4).Reduce_by_(2); + public void Clear() {mgr.Clear();} + public Gfo_cache_mgr_fxt Exec__add(String... ary) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + String itm = ary[i]; + byte[] key = Bry_.new_u8(itm); + mgr.Add(key, new Gfo_cache_itm_mock(itm), key.length); + } + return this; + } + public Gfo_cache_mgr_fxt Exec__get(String... ary) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + String itm = ary[i]; + mgr.Get_by_key(Bry_.new_u8(itm)); + } + return this; + } + public Gfo_cache_mgr_fxt Test__cur_size(int expd) {Gftest.Eq__int(expd, mgr.Cur_size(), "cur_size"); return this;} + public Gfo_cache_mgr_fxt Test__itms(String... expd) { + int len = mgr.Test__len(); + String[] actl = new String[len]; + for (int i = 0; i < len; ++i) + actl[i] = ((Gfo_cache_itm_mock)mgr.Test__get_at(i)).Val(); + Gftest.Eq__ary(expd, actl, "itms"); + return this; + } +} +class Gfo_cache_itm_mock implements Rls_able { + public Gfo_cache_itm_mock(String val) {this.val = val;} + public String Val() {return val;} private String val; + public void Rls() {} +} diff --git a/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java b/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java new file mode 100644 index 000000000..8d1b2b8fe --- /dev/null +++ b/400_xowa/src/gplx/core/consoles/Gfo_cmd_arg_mgr_tst.java @@ -0,0 +1,121 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.consoles; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*; +public class Gfo_cmd_arg_mgr_tst { + @Before public void init() {fxt.Clear();} private final Gfo_cmd_arg_mgr_fxt fxt = new Gfo_cmd_arg_mgr_fxt(); + @Test public void Val__many() { + fxt.Init_args(fxt.Make_arg("a"), fxt.Make_arg("b")); + fxt.Exec_process("--a", "0", "--b", "1"); + fxt.Test_errs_none(); + fxt.Test_actl(fxt.Make_chkr("a", "0"), fxt.Make_chkr("b", "1")); + } + @Test public void Val__yn() { + fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn), fxt.Make_arg("b", Gfo_cmd_arg_itm_.Val_tid_yn)); + fxt.Exec_process("--a", "y", "--b", "n"); + fxt.Test_errs_none(); + fxt.Test_actl(fxt.Make_chkr("a", Bool_.Y), fxt.Make_chkr("b", Bool_.N)); + } + @Test public void Dflt() { + fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn).Dflt_(Bool_.Y)); + fxt.Exec_process("--a", "n").Test_actl(fxt.Make_chkr("a", Bool_.N)); // if val, use it + fxt.Exec_process() .Test_actl(fxt.Make_chkr("a", Bool_.Y)); // if no val, use default + } + @Test public void Err__key__unknown() { + fxt.Init_args(fxt.Make_arg("a")); + fxt.Exec_process("--b"); + fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__unknown); + } + @Test public void Err__key__missing() { + fxt.Init_args(fxt.Make_arg("a")); + fxt.Exec_process("a"); + fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__missing); + } + @Test public void Err__key__dupe() { + fxt.Init_args(fxt.Make_arg("a")); + fxt.Exec_process("--a", "0", "--a", "0"); + fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__duplicate); + } + @Test public void Err__val__reqd() { + fxt.Init_args(fxt.Make_arg("a", Bool_.Y), fxt.Make_arg("b", Bool_.N)); + fxt.Exec_process("--b", "1"); + fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__required); + } + @Test public void Err__val__parse__yn() { + fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn)); + fxt.Exec_process("--a", "x"); + fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__invalid__yn); + } + @Test public void Val_as_url_rel_dir_or() { // PURPOSE: "/xowa" -> "/xowa/" + String root_dir = Op_sys.Cur().Tid_is_wnt() ? "C:\\" : "/", dir_spr = Op_sys.Cur().Fsys_dir_spr_str(); + fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" , root_dir + "sub" + dir_spr); // /sub -> /sub/ + fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" + dir_spr , root_dir + "sub" + dir_spr); // /sub/ -> /sub/ + fxt.Test_val_as_url_rel_dir_or(root_dir, dir_spr, "sub" , root_dir + "dir" + dir_spr + "sub" + dir_spr); // sub -> /dir/sub/ + } +} +class Gfo_cmd_arg_mgr_fxt { + private final Tst_mgr tst_mgr = new Tst_mgr(); + public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg; + public Gfo_cmd_arg_mgr Mgr() {return mgr;} private final Gfo_cmd_arg_mgr mgr = new Gfo_cmd_arg_mgr(); + public Gfo_cmd_arg_mgr_fxt Clear() { + if (usr_dlg == null) + usr_dlg = Gfo_usr_dlg_.Test(); + mgr.Reset(); + usr_dlg.Gui_wkr().Clear(); + return this; + } + public Gfo_cmd_arg_itm Make_arg(String key) {return Make_arg(key, false);} + public Gfo_cmd_arg_itm Make_arg(String key, int tid) {return Make_arg(key, false, tid);} + public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd) {return Gfo_cmd_arg_itm_.new_(key, reqd, Gfo_cmd_arg_itm_.Val_tid_string);} + public Gfo_cmd_arg_itm Make_arg(String key, boolean reqd, int tid) {return Gfo_cmd_arg_itm_.new_(key, reqd, tid);} + public Gfo_cmd_itm_chkr Make_chkr(String key, Object val) {return new Gfo_cmd_itm_chkr(key, val);} + public Gfo_cmd_arg_mgr_fxt Init_args(Gfo_cmd_arg_itm... v) {mgr.Reg_many(v); return this;} + public Gfo_cmd_arg_mgr_fxt Exec_process(String... v) {mgr.Parse(v); return this;} + public Gfo_cmd_arg_mgr_fxt Test_actl(Gfo_cmd_itm_chkr... expd) { + Gfo_cmd_arg_itm[] actl = mgr.To_ary(); + tst_mgr.Tst_ary("", expd, actl); + return this; + } + public Gfo_cmd_arg_mgr_fxt Test_errs_none() {return Test_errs(String_.Ary_empty);} + public Gfo_cmd_arg_mgr_fxt Test_errs(String... expd) { + String[] actl = mgr.Errs__to_str_ary(); + int len = actl.length; + for (int i = 0; i < len; ++i) { // extract key part; EX: "unknown key: abc" -> unknown key + actl[i] = String_.GetStrBefore(actl[i], ":"); + } + Tfds.Eq_ary_str(expd, actl); + return this; + } + public Gfo_cmd_arg_mgr_fxt Test_write(String... expd) { + Tfds.Eq_ary_str(expd, ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Msgs().To_str_ary_and_clear()); + return this; + } + public void Test_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) { + Io_url actl = Make_arg("key").Val_(val).Val_as_url__rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null); + Tfds.Eq(expd, actl.Raw()); + } +} +class Gfo_cmd_itm_chkr implements Tst_chkr { + public Gfo_cmd_itm_chkr(String key, Object val) {this.key = key; this.val = val;} private String key; Object val; + public Class TypeOf() {return Gfo_cmd_arg_itm.class;} + public int Chk(Tst_mgr mgr, String path, Object actl_obj) { + Gfo_cmd_arg_itm actl = (Gfo_cmd_arg_itm)actl_obj; + int err = 0; + err += mgr.Tst_val(false, path, "key", key, actl.Key()); + err += mgr.Tst_val(false, path, "val", val, actl.Val()); + return err; + } +} diff --git a/400_xowa/src/gplx/core/flds/Gfo_fld_rdr_tst.java b/400_xowa/src/gplx/core/flds/Gfo_fld_rdr_tst.java new file mode 100644 index 000000000..5e47e67a7 --- /dev/null +++ b/400_xowa/src/gplx/core/flds/Gfo_fld_rdr_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.flds; import gplx.*; import gplx.core.*; +import org.junit.*; +import gplx.core.ios.*; +public class Gfo_fld_rdr_tst { + Gfo_fld_rdr_fxt fxt = new Gfo_fld_rdr_fxt(); + @Test public void Read_int() {fxt.ini_xdat().Raw_("123|") .tst_Read_int(123);} + @Test public void Read_double() {fxt.ini_xdat().Raw_("1.23|") .tst_Read_double(1.23);} + @Test public void Read_str_simple() {fxt.ini_xdat().Raw_("ab|") .tst_Read_str_simple("ab");} + @Test public void Read_str_escape_pipe() {fxt.ini_xdat().Raw_("a~pb|") .tst_Read_str_escape("a|b");} + @Test public void Read_str_escape_tilde() {fxt.ini_xdat().Raw_("a~~b|") .tst_Read_str_escape("a~b");} + @Test public void Read_str_escape_nl() {fxt.ini_xdat().Raw_("a~nb|") .tst_Read_str_escape("a\nb");} + @Test public void Read_str_escape_tab() {fxt.ini_xdat().Raw_("a~tb|") .tst_Read_str_escape("a\tb");} + @Test public void Write_str_escape_pipe() {fxt.ini_xdat().tst_Write_str_escape("a|b", "a~pb|");} + @Test public void Read_str_quoted_comma() {fxt.ini_sql ().Raw_("'a,b',") .tst_Read_str_escape("a,b");} + @Test public void Read_str_quoted_apos() {fxt.ini_sql ().Raw_("'a\\'b',") .tst_Read_str_escape("a'b");} + @Test public void Read_multiple() { + fxt.ini_xdat().Raw_("ab|1|.9|\n") + .tst_Read_str_escape("ab").tst_Read_int(1).tst_Read_double(.9) + ; + } + @Test public void Read_dlm_nl() {fxt.ini_xdat().Raw_("123\n") .tst_Read_int(123);} +} +class Gfo_fld_rdr_fxt { + Gfo_fld_rdr rdr = new Gfo_fld_rdr(); Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_(); + public Gfo_fld_rdr_fxt Raw_(String v) {rdr.Data_(Bry_.new_u8(v)); return this;} + public Gfo_fld_rdr_fxt ini_xdat() {rdr.Ctor_xdat(); return this;} + public Gfo_fld_rdr_fxt ini_sql() {rdr.Ctor_sql(); return this;} + public Gfo_fld_rdr_fxt tst_Read_int(int expd) {Tfds.Eq(expd, rdr.Read_int()); return this;} + public Gfo_fld_rdr_fxt tst_Read_double(double expd) {Tfds.Eq(expd, rdr.Read_double()); return this;} + public Gfo_fld_rdr_fxt tst_Read_str_simple(String expd) {Tfds.Eq(expd, rdr.Read_str_simple()); return this;} + public Gfo_fld_rdr_fxt tst_Read_str_escape(String expd) {Tfds.Eq(expd, rdr.Read_str_escape()); return this;} + public Gfo_fld_rdr_fxt tst_Write_str_escape(String val, String expd) { + byte[] bry = Bry_.new_u8(val); + wtr.Bfr_(bfr); + wtr.Write_bry_escape_fld(bry); + Tfds.Eq(expd, bfr.To_str()); + return this; + } private Bry_bfr bfr = Bry_bfr_.New(); +} diff --git a/400_xowa/src/gplx/core/gfobjs/Gfobj_rdr__json_tst.java b/400_xowa/src/gplx/core/gfobjs/Gfobj_rdr__json_tst.java new file mode 100644 index 000000000..d19e8f40c --- /dev/null +++ b/400_xowa/src/gplx/core/gfobjs/Gfobj_rdr__json_tst.java @@ -0,0 +1,86 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.gfobjs; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +import gplx.langs.jsons.*; +public class Gfobj_rdr__json_tst { + private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt(); + @Test public void Type() { + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "{ 'k1':true" + , ", 'k2':123" + , ", 'k3':9876543210" + , ", 'k4':1.23" + , ", 'k5':null" + , ", 'k6':'abc'" + , "}" + ) + , fxt.Make__nde + ( fxt.Make__fld_bool ("k1", true) + , fxt.Make__fld_int ("k2", 123) + , fxt.Make__fld_long ("k3", 9876543210L) + , fxt.Make__fld_double ("k4", 1.23) + , fxt.Make__fld_str ("k5", null) + , fxt.Make__fld_str ("k6", "abc") + )); + } + @Test public void Nested() { + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "{ 'a1':'1a'" + , ", 'a2':" + , " { 'b1':'1b'" + , " , 'b2':" + , " { 'c1':'1c'" + , " }" + , " }" + , ", 'a3':[1, 2, 3]" + , "}" + ) + , fxt.Make__nde + ( fxt.Make__fld_str ("a1", "1a") + , fxt.Make__fld_nde ("a2" + , fxt.Make__fld_str("b1", "1b") + , fxt.Make__fld_nde("b2" + , fxt.Make__fld_str("c1", "1c")) + ) + , fxt.Make__fld_ary ("a3", 1, 2, 3) + )); + } + @Test public void Array() { + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "[" + , " [1, 2, 3]" + , ", ['a', 'b', 'c']" + , ", [true, false]" + , ", [9876543210, 9876543211, 9876543212]" + //, ", [1.23, 1.24, 1.25]" + , ", [{'a':1}, {'b':2}, {'c':3}]" + , "]" + ) + , fxt.Make__ary + ( fxt.Make__ary (1, 2, 3) + , fxt.Make__ary ("a", "b", "c") + , fxt.Make__ary (true, false) + , fxt.Make__ary (9876543210L, 9876543211L, 9876543212L) + // , fxt.Make__ary (1.23, 1.24, 1.25) + , fxt.Make__ary + ( fxt.Make__nde(fxt.Make__fld_int("a", 1)) + , fxt.Make__nde(fxt.Make__fld_int("b", 2)) + , fxt.Make__nde(fxt.Make__fld_int("c", 3)) + ) + )); + } +} diff --git a/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_fxt.java b/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_fxt.java new file mode 100644 index 000000000..67244e13d --- /dev/null +++ b/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_fxt.java @@ -0,0 +1,52 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.gfobjs; import gplx.*; import gplx.core.*; +import gplx.core.tests.*; import gplx.langs.jsons.*; +public class Gfobj_wtr__json_fxt { + protected final Gfobj_wtr__json mgr = new Gfobj_wtr__json(); + public Gfobj_nde Make__nde(Gfobj_fld... ary) {return Make__nde(Gfobj_nde.New(), ary);} + private Gfobj_nde Make__nde(Gfobj_nde nde, Gfobj_fld[] ary) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + Gfobj_fld fld = (Gfobj_fld)ary[i]; + nde.Add_fld(fld); + } + return nde; + } + public Gfobj_fld Make__fld_bool (String key, boolean val) {return new Gfobj_fld_bool(key, val);} + public Gfobj_fld Make__fld_str (String key, String val) {return new Gfobj_fld_str(key, val);} + public Gfobj_fld Make__fld_int (String key, int val) {return new Gfobj_fld_int(key, val);} + public Gfobj_fld Make__fld_long (String key, long val) {return new Gfobj_fld_long(key, val);} + public Gfobj_fld Make__fld_double (String key, double val) {return new Gfobj_fld_double(key, val);} + public Gfobj_fld Make__fld_nde(String key, Gfobj_fld... ary) { + Gfobj_nde nde = Make__nde(Gfobj_nde.New(), ary); + Gfobj_fld_nde rv = new Gfobj_fld_nde(key, nde); + return rv; + } + public Gfobj_fld Make__fld_ary (String key, Object... ary) {return new Gfobj_fld_ary(key, new Gfobj_ary(ary));} + public Gfobj_ary Make__ary (Object... ary) {return new Gfobj_ary(ary);} + public Gfobj_wtr__json_fxt Test__write(Gfobj_grp root, String... lines) { + String[] expd = Json_doc.Make_str_ary_by_apos(lines); + Gftest.Eq__ary(expd, Bry_.Ary(String_.SplitLines_nl(mgr.Write(root).To_str())), "json_write"); + return this; + } + public Gfobj_wtr__json_fxt Test__parse(String src, Gfobj_grp expd) { + Gfobj_rdr__json rdr = new Gfobj_rdr__json(); + Gfobj_grp actl = rdr.Parse(Bry_.new_u8(Json_doc.Make_str_by_apos(src))); + Gftest.Eq__ary(Bry_.Ary(String_.SplitLines_nl(mgr.Write(expd).To_str())), Bry_.Ary(String_.SplitLines_nl(mgr.Write(actl).To_str())), "json_write"); + return this; + } +} diff --git a/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_tst.java b/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_tst.java new file mode 100644 index 000000000..f06873f8a --- /dev/null +++ b/400_xowa/src/gplx/core/gfobjs/Gfobj_wtr__json_tst.java @@ -0,0 +1,153 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.gfobjs; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +import gplx.langs.jsons.*; +public class Gfobj_wtr__json_tst { + private final Gfobj_wtr__json_fxt fxt = new Gfobj_wtr__json_fxt(); + @Test public void Flds() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_long ("k2", 2) + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':2" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Sub_ndes() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_nde ("k2" + , fxt.Make__fld_str ("k2a", "v2a") + , fxt.Make__fld_int ("k2b", 2) + ) + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':" + , " { 'k2a':'v2a'" + , " , 'k2b':2" + , " }" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Ary_str() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_ary ("k2", "a1", "a2", "a3") + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':" + , " [ 'a1'" + , " , 'a2'" + , " , 'a3'" + , " ]" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Ary_int() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_ary ("k2", 1, 2, 3) + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':" + , " [ 1" + , " , 2" + , " , 3" + , " ]" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Ary_nde() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_ary ("k2" + , fxt.Make__nde (fxt.Make__fld_str("k21", "v21")) + , fxt.Make__nde (fxt.Make__fld_str("k22", "v22")) + ) + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':" + , " [" + , " { 'k21':'v21'" + , " }" + , " ," + , " { 'k22':'v22'" + , " }" + , " ]" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Ary_ary() { + fxt.Test__write + ( fxt.Make__nde + ( fxt.Make__fld_str ("k1", "v1") + , fxt.Make__fld_ary ("k2" + , fxt.Make__ary (1, 2, 3) + , fxt.Make__ary (4, 5, 6) + ) + , fxt.Make__fld_int ("k3", 3) + ) + , "{ 'k1':'v1'" + , ", 'k2':" + , " [" + , " [ 1" + , " , 2" + , " , 3" + , " ]" + , " ," + , " [ 4" + , " , 5" + , " , 6" + , " ]" + , " ]" + , ", 'k3':3" + , "}" + , "" + ); + } + @Test public void Root_ary() { + fxt.Test__write + ( fxt.Make__ary(1, 2, 3) + , "[ 1" + , ", 2" + , ", 3" + , "]" + , "" + ); + } +} diff --git a/400_xowa/src/gplx/core/intls/String_surrogate_utl_tst.java b/400_xowa/src/gplx/core/intls/String_surrogate_utl_tst.java new file mode 100644 index 000000000..ebccb83cd --- /dev/null +++ b/400_xowa/src/gplx/core/intls/String_surrogate_utl_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.intls; import gplx.*; import gplx.core.*; +import org.junit.*; +public class String_surrogate_utl_tst { + @Before public void init() {fxt.Clear();} private String_surrogate_utl_fxt fxt = new String_surrogate_utl_fxt(); + @Test public void Char_idx() { + String test_str = "aé𡼾bî𡼾"; + fxt.Test_count_surrogates__char_idx (test_str, 0, 1, 0, 1); // a + fxt.Test_count_surrogates__char_idx (test_str, 0, 2, 0, 3); // aé + fxt.Test_count_surrogates__char_idx (test_str, 0, 3, 1, 7); // aé𡼾 + fxt.Test_count_surrogates__char_idx (test_str, 7, 1, 0, 8); // b + fxt.Test_count_surrogates__char_idx (test_str, 7, 2, 0, 10); // bî + fxt.Test_count_surrogates__char_idx (test_str, 7, 3, 1, 14); // bî𡼾 + fxt.Test_count_surrogates__char_idx (test_str, 0, 6, 2, 14); // aé𡼾bî𡼾 + fxt.Test_count_surrogates__char_idx (test_str, 14, 7, 0, 14); // PURPOSE: test out of bounds; DATE:2014-09-02 + } + @Test public void Codepoint_idx() { + String test_str = "aé𡼾bî𡼾"; + fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 1, 0, 1); // a + fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 2, 0, 3); // aé + fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 4, 1, 7); // aé𡼾 + fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 1, 0, 8); // b + fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 2, 0, 10); // bî + fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 4, 1, 14); // bî𡼾 + fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 8, 2, 14); // aé𡼾bî𡼾 + } +} +class String_surrogate_utl_fxt { + private String_surrogate_utl codepoint_utl = new String_surrogate_utl(); + public void Clear() {} + public void Test_count_surrogates__char_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) { + byte[] src_bry = Bry_.new_u8(src_str); int src_len = src_bry.length; + Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__char_idx(src_bry, src_len, bgn_byte, char_idx)); + Tfds.Eq(expd_pos , codepoint_utl.Byte_pos()); + } + public void Test_count_surrogates__codepoint_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) { + byte[] src_bry = Bry_.new_u8(src_str); int src_len = src_bry.length; + Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__codepoint_idx1(src_bry, src_len, bgn_byte, char_idx), "count"); + Tfds.Eq(expd_pos , codepoint_utl.Byte_pos(), "pos"); + } +} diff --git a/400_xowa/src/gplx/core/ios/BinaryHeap_Io_line_rdr_tst.java b/400_xowa/src/gplx/core/ios/BinaryHeap_Io_line_rdr_tst.java new file mode 100644 index 000000000..a582915f6 --- /dev/null +++ b/400_xowa/src/gplx/core/ios/BinaryHeap_Io_line_rdr_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class BinaryHeap_Io_line_rdr_tst { + BinaryHeap_Io_line_rdr_fxt fxt = new BinaryHeap_Io_line_rdr_fxt(); + @Test public void Add() { + fxt.Add("c", "a", "b").tst("a", "b", "c"); + fxt.Add("b", "a", "a").tst("a", "a", "b"); + fxt.Add("f", "b", "d", "c", "e", "a").tst("a", "b", "c", "d", "e", "f"); + } +} +class BinaryHeap_Io_line_rdr_fxt { + BinaryHeap_Io_line_rdr heap = new BinaryHeap_Io_line_rdr(Io_sort_split_itm_sorter.Instance); int file_total; + public BinaryHeap_Io_line_rdr_fxt Add(String... ary) { + file_total = ary.length; + for (int i = 0; i < file_total; i++) { + Io_url url = Io_url_.mem_fil_("mem/fil_" + ary[i] + ".txt"); + Io_mgr.Instance.SaveFilStr(url, ary[i]); + Io_line_rdr stream = new Io_line_rdr(Gfo_usr_dlg_.Test(), url); + stream.Read_next(); + heap.Add(stream); + } + return this; + } + public BinaryHeap_Io_line_rdr_fxt tst(String... expd) { + String[] actl = new String[file_total]; + for (int i = 0; i < actl.length; i++) { + Io_line_rdr bfr = heap.Pop(); + actl[i] = String_.new_u8(bfr.Bfr(), 0, bfr.Bfr_len()); + } + Tfds.Eq_ary_str(expd, actl); + return this; + } +} diff --git a/400_xowa/src/gplx/core/ios/Io_buffer_rdr_tst.java b/400_xowa/src/gplx/core/ios/Io_buffer_rdr_tst.java new file mode 100644 index 000000000..fe5e8abd9 --- /dev/null +++ b/400_xowa/src/gplx/core/ios/Io_buffer_rdr_tst.java @@ -0,0 +1,62 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.ios.*; import gplx.core.ios.streams.*; +public class Io_buffer_rdr_tst { + @Before public void init() { + Io_mgr.Instance.InitEngine_mem(); + fil = Io_url_.mem_fil_("mem/byteStreamRdr.txt"); + ini_Write("0123456789"); + rdr = Io_buffer_rdr.new_(Io_stream_rdr_.New__raw(fil), 4); + } Io_buffer_rdr rdr; Io_url fil; + @After public void teardown() {rdr.Rls();} + @Test public void Bfr_load_all() { + tst_Bfr("0", "1", "2", "3").tst_ReadDone(false); + + rdr.Bfr_load_all(); + tst_Bfr("4", "5", "6", "7").tst_ReadDone(false); + + rdr.Bfr_load_all(); + tst_Bfr("8", "9"); + rdr.Bfr_load_all(); // NOTE: change to zip_rdrs make eof detection difficult; force another load to ensure that file_pos goes past file_len + tst_ReadDone(true); // NOTE: bfr truncated from 4 to 2 + } + @Test public void Bfr_load_from() { + tst_Bfr("0", "1", "2", "3").tst_ReadDone(false); + + rdr.Bfr_load_from(3); // read from pos 3 + tst_Bfr("3", "4", "5", "6").tst_ReadDone(false); + + rdr.Bfr_load_from(1); // read from pos 1 + tst_Bfr("4", "5", "6", "7").tst_ReadDone(false); + + rdr.Bfr_load_from(1); + tst_Bfr("5", "6", "7", "8").tst_ReadDone(false); + + rdr.Bfr_load_from(3); + rdr.Bfr_load_all(); // NOTE: change to zip_rdrs make eof detection difficult; force another load to ensure that file_pos goes past file_len + tst_Bfr("8", "9").tst_ReadDone(true); + } + private void ini_Write(String s) {Io_mgr.Instance.SaveFilStr(fil, s);} + Io_buffer_rdr_tst tst_Bfr(String... expdAry) { + String[] actlAry = new String[rdr.Bfr_len()]; + for (int i = 0; i < actlAry.length; i++) + actlAry[i] = String_.new_u8(rdr.Bfr(), i, i + 1); + Tfds.Eq_ary(expdAry, actlAry); + return this; + } + Io_buffer_rdr_tst tst_ReadDone(boolean expd) {Tfds.Eq(expd, rdr.Fil_eof()); return this;} +} diff --git a/400_xowa/src/gplx/core/ios/Io_line_rdr_tst.java b/400_xowa/src/gplx/core/ios/Io_line_rdr_tst.java new file mode 100644 index 000000000..7f43744c1 --- /dev/null +++ b/400_xowa/src/gplx/core/ios/Io_line_rdr_tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.envs.*; +public class Io_line_rdr_tst { + Io_line_rdr_fxt fxt; + @Before public void init() { + fxt = new Io_line_rdr_fxt(Io_url_.new_fil_("mem/test.txt")); + fxt.Clear(); + } + @Test public void Basic() { + fxt.File_lines_(3).tst_Read_til_lines(3, "00", "01", "02"); + fxt.tst_Read_til_lines(1); // make sure nothing more is read + } + @Test public void Load_3x() { + fxt.File_lines_(9).Load_len_lines_(3).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08"); + } + @Test public void Load_irregular() { + fxt.File_lines_(9).Load_len_(4).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08"); + } + @Test public void Load_multiple_files() { + fxt = new Io_line_rdr_fxt(Io_url_.new_fil_("mem/test0.txt"), Io_url_.new_fil_("mem/test1.txt"), Io_url_.new_fil_("mem/test2.txt")); + fxt.File_lines_(0, 0, 3).File_lines_(1, 3, 5).File_lines_(2, 5, 9).Load_len_(4).tst_Read_til_lines(9, "00", "01", "02", "03", "04", "05", "06", "07", "08"); + } + @Test public void Match() { + fxt.File_lines_pipe_(9).Load_len_(6); + fxt.tst_Match("00", "00"); + fxt.tst_Match("01", "01"); + fxt.tst_Match("03", "03"); + fxt.tst_Match("08", "08"); + fxt.tst_Match("12", ""); + } +} +class Io_line_rdr_fxt { + Io_line_rdr rdr; + List_adp lines = List_adp_.New(); Bry_bfr tmp = Bry_bfr_.New(); + public Io_line_rdr_fxt(Io_url... urls) {rdr = new Io_line_rdr(Gfo_usr_dlg_.Test(), urls);} + public Io_line_rdr_fxt Load_len_lines_(int v) {return Load_len_(v * 3);} // 3: 2=##, 1=\n + public Io_line_rdr_fxt Load_len_(int v) {rdr.Load_len_(v); return this;} + public Io_line_rdr_fxt File_lines_(int count) { + for (int i = 0; i < count; i++) + tmp.Add_int_fixed(i, 2).Add_byte_nl(); + Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear()); + return this; + } +// public Io_url[] Src_fils() {return src_fils;} public Io_line_rdr_fxt Src_fils_(Io_url[] v) {src_fils = v; return this;} Io_url[] src_fils; + public Io_line_rdr_fxt tst_Match(String match, String expd) { + rdr.Key_gen_(Io_line_rdr_key_gen_.first_pipe); + boolean match_v = rdr.Match(Bry_.new_u8(match)); + String actl = match_v ? String_.new_u8(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end()) : ""; + Tfds.Eq(expd, actl); + return this; + } + public Io_line_rdr_fxt File_lines_pipe_(int count) { + for (int i = 0; i < count; i++) + tmp.Add_int_fixed(i, 2).Add_byte(Byte_ascii.Pipe).Add_byte_nl(); + Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear()); + return this; + } + + public Io_line_rdr_fxt File_lines_(int fil_idx, int bgn, int end) { + for (int i = bgn; i < end; i++) + tmp.Add_int_fixed(i, 2).Add_byte_nl(); + Io_mgr.Instance.SaveFilBry(rdr.Urls()[fil_idx], tmp.To_bry_and_clear()); + return this; + } + public Io_line_rdr_fxt Clear() {rdr.Clear(); return this;} + public Io_line_rdr_fxt tst_Read_til_lines(int count, String... expd) { + lines.Clear(); + for (int i = 0; i < expd.length; i++) + expd[i] = expd[i] + Op_sys.Lnx.Nl_str(); + for (int i = 0; i < count; i++) { + if (rdr.Read_next()) + lines.Add(String_.new_u8(rdr.Bfr(), rdr.Itm_pos_bgn(), rdr.Itm_pos_end())); + else + break; + } + Tfds.Eq_ary_str(expd, lines.To_str_ary()); + return this; + } +} diff --git a/400_xowa/src/gplx/core/ios/Io_sort_misc_tst.java b/400_xowa/src/gplx/core/ios/Io_sort_misc_tst.java new file mode 100644 index 000000000..8ff23424a --- /dev/null +++ b/400_xowa/src/gplx/core/ios/Io_sort_misc_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Io_sort_misc_tst { + @Before public void init() { + } + @Test public void Io_url_gen_dir() { + tst_Io_url_gen_dir("mem/dir/", "{0}.xdat", 4, 3, "0000.xdat", "0001.xdat", "0002.xdat"); + } + private void tst_Io_url_gen_dir(String dir_str, String fmt, int digits, int calls, String... expd) { + Io_url dir = Io_url_.mem_dir_(dir_str); + List_adp actl_list = List_adp_.New(); + Io_url_gen wkr = Io_url_gen_.dir_(dir, fmt, digits); + for (int i = 0; i < calls; i++) + actl_list.Add(wkr.Nxt_url().Raw()); + String[] actl = actl_list.To_str_ary(); + for (int i = 0; i < expd.length; i++) + expd[i] = dir_str + expd[i]; + Tfds.Eq_ary_str(expd, actl); + } + @Test public void Io_line_rdr_comparer_all() { + tst_Io_line_rdr_fld_comparer(-1, "a", "b"); + tst_Io_line_rdr_fld_comparer( 0, "a", "a"); + tst_Io_line_rdr_fld_comparer( 1, "b", "a"); + tst_Io_line_rdr_fld_comparer(-1, "a", "ab"); + tst_Io_line_rdr_fld_comparer( 1, "ab", "a"); + } + private void tst_Io_line_rdr_fld_comparer(int expd, String lhs_str, String rhs_str) { + byte[] lhs = Bry_.new_u8(lhs_str), rhs = Bry_.new_u8(rhs_str); + Tfds.Eq(expd, Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length)); + } + Io_line_rdr new_Io_line_rdr(String url_str, String text) { + Io_url url = Io_url_.mem_fil_(url_str); + Io_mgr.Instance.SaveFilStr(url, text); + Io_line_rdr rv = new Io_line_rdr(Gfo_usr_dlg_.Test(), url); + rv.Read_next(); + return rv; + } + @Test public void ExternalSort() { + // fxt("c", "a", "b") + } +} diff --git a/400_xowa/src/gplx/core/ios/Io_sort_tst.java b/400_xowa/src/gplx/core/ios/Io_sort_tst.java new file mode 100644 index 000000000..cb333381a --- /dev/null +++ b/400_xowa/src/gplx/core/ios/Io_sort_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.ios; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.strings.*; +public class Io_sort_tst { + Io_sort_fxt fxt = new Io_sort_fxt(); + @Test public void ExternalSort() { + fxt.Clear().Memory_max_(12).Src_(fxt.GenRandom(6, 4)).Sorted_(fxt.GenOrdered(6, 4)).tst(); + fxt.Clear().Memory_max_(64).Src_(fxt.GenRandom(50, 4)).Sorted_(fxt.GenOrdered(50, 4)).tst(); + } +} +class Io_sort_fxt { + Io_sort externalSort = new Io_sort().Memory_max_(Io_mgr.Len_kb); + String_bldr sb = String_bldr_.new_(); + public Io_sort_fxt Clear() {Io_mgr.Instance.InitEngine_mem(); return this;} + public Io_sort_fxt Memory_max_(int v) {externalSort.Memory_max_(v); return this;} + public Io_sort_fxt Src_(String v) {src = v; return this;} private String src; + public Io_sort_fxt Sorted_(String v) {sorted = v; return this;} private String sorted; + public void tst() { + Io_url src_url = Io_url_.mem_fil_("mem/src.txt"); + Io_url trg_url = Io_url_.mem_fil_("mem/trg.txt"); + Io_mgr.Instance.DeleteFil(src_url); Io_mgr.Instance.DeleteFil(trg_url); + + Io_mgr.Instance.SaveFilStr(src_url, src); + + Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test(); + Io_url_gen src_fil_gen = Io_url_gen_.fil_(src_url); + Io_url[] tmp_url_ary = externalSort.Split(usr_dlg, src_fil_gen, Io_url_gen_.dir_(src_url.OwnerDir()), Io_line_rdr_key_gen_.first_pipe); + Io_sort_fil_basic cmd = new Io_sort_fil_basic(usr_dlg, Io_url_gen_.fil_(trg_url), Io_mgr.Len_kb); + externalSort.Merge(usr_dlg, tmp_url_ary, Io_sort_split_itm_sorter.Instance, Io_line_rdr_key_gen_.first_pipe, cmd); + + String actl = Io_mgr.Instance.LoadFilStr(trg_url); + Tfds.Eq_ary_str(String_.SplitLines_nl(sorted), String_.SplitLines_nl(actl)); + } + public String GenRandom(int rows, int pad) { + List_adp list = List_adp_.New(); + for (int i = 0; i < rows; i++) + list.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|"); + list.Shuffle(); + for (int i = 0; i < rows; i++) { + String itm = (String)list.Get_at(i); + sb.Add(itm).Add_char_nl(); + } + return sb.To_str_and_clear(); + } + public String GenOrdered(int rows, int pad) { + for (int i = 0; i < rows; i++) + sb.Add(Int_.To_str_pad_bgn_zero(i, pad) + "|" + "\n"); + return sb.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/core/lists/Queue_adp_tst.java b/400_xowa/src/gplx/core/lists/Queue_adp_tst.java new file mode 100644 index 000000000..7ddcea028 --- /dev/null +++ b/400_xowa/src/gplx/core/lists/Queue_adp_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +public class Queue_adp_tst { + private final Queue_adp_fxt fxt = new Queue_adp_fxt(); + @Test public void Empty() { + boolean pass = true; + try { + fxt.Test__dequeue(null, -1); + pass = false; + } catch (Exception e) { + Err_.Noop(e); + return; + } + if (pass) throw Err_.new_wo_type("empty should have failed"); + } + @Test public void Add_1() { + fxt.Exec__enqueue("a"); + fxt.Test__dequeue("a", 0); + } + @Test public void Add_n() { + fxt.Exec__enqueue("a"); + fxt.Exec__enqueue("b"); + fxt.Exec__enqueue("c"); + fxt.Test__dequeue("a", 2); + fxt.Test__dequeue("b", 1); + fxt.Test__dequeue("c", 0); + } + @Test public void Mix() { + fxt.Exec__enqueue("a"); + fxt.Exec__enqueue("b"); + fxt.Test__dequeue("a", 1); + fxt.Exec__enqueue("c"); + fxt.Test__dequeue("b", 1); + fxt.Test__dequeue("c", 0); + } +} +class Queue_adp_fxt { + private final Queue_adp queue = new Queue_adp(); + public void Exec__enqueue(String s) {queue.Enqueue(s);} + public void Test__dequeue(String expd_data, int expd_len) { + Gftest.Eq__str(expd_data, (String)queue.Dequeue()); + Gftest.Eq__int(expd_len , queue.Count()); + } +} diff --git a/400_xowa/src/gplx/core/lists/StatRng_tst.java b/400_xowa/src/gplx/core/lists/StatRng_tst.java new file mode 100644 index 000000000..928398b1a --- /dev/null +++ b/400_xowa/src/gplx/core/lists/StatRng_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists; import gplx.*; import gplx.core.*; +import org.junit.*; +public class StatRng_tst { +// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance; + StatRng_fxt fx = new StatRng_fxt(); + @Test public void Empty() { + fx.ini_(1, 1, 5); + fx.Count_(7).Lo_(2).Hi_(8).Avg_(5) + .Lo_ary_(2) + .Hi_ary_(8) + .Slots_(3, 4); + fx.tst_(5,7,2,8,3,4,6); + } +//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a=1|b=2|3}}", "{{test|a}}", "1");} +//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|b=2|#default=3|a=1}}", "{{test|a}}", "1");} +//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a|b|c=1|d=2}}", "{{test|a}}", "1");} +} +/* +public class Pf_func_switch_tst { +// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc.Instance; + +*/ \ No newline at end of file diff --git a/400_xowa/src/gplx/core/lists/binary_searches/Binary_search__tst.java b/400_xowa/src/gplx/core/lists/binary_searches/Binary_search__tst.java new file mode 100644 index 000000000..38239e541 --- /dev/null +++ b/400_xowa/src/gplx/core/lists/binary_searches/Binary_search__tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*; +import org.junit.*; import gplx.core.primitives.*; +public class Binary_search__tst { + private final Binary_search__fxt fxt = new Binary_search__fxt(); + @Test public void Basic() { + fxt.Init__ary("", "e", "j", "o", "t", "y"); + fxt.Test__binary_search("a", 0); + fxt.Test__binary_search("f", 1); + fxt.Test__binary_search("k", 2); + fxt.Test__binary_search("p", 3); + fxt.Test__binary_search("u", 4); + fxt.Test__binary_search("z", 5); + } + @Test public void One() { + fxt.Init__ary(""); + fxt.Test__binary_search("a", 0); + } + @Test public void Catpage() { + String[] ary = new String[25]; + for (int i = 0; i < 25; ++i) + ary[i] = Int_.To_str_pad_bgn_zero(i, 2); + fxt.Init__ary(ary); + fxt.Test__binary_search("10", 10); // was 9 + } +} +class Binary_search__fxt { + private String_obj_val[] ary; + public void Init__ary(String... v) { + int ary_len = v.length; + ary = new String_obj_val[ary_len]; + for (int i = 0; i < ary_len; i++) + ary[i] = String_obj_val.new_(v[i]); + } + public void Test__binary_search(String val, int expd) { + int actl = Binary_search_.Search(ary, String_obj_val.new_(val)); + Tfds.Eq(expd, actl, val); + } +} diff --git a/400_xowa/src/gplx/core/net/Gfo_url_parser_fxt.java b/400_xowa/src/gplx/core/net/Gfo_url_parser_fxt.java new file mode 100644 index 000000000..f96bea174 --- /dev/null +++ b/400_xowa/src/gplx/core/net/Gfo_url_parser_fxt.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.net; import gplx.*; import gplx.core.*; +import gplx.core.net.qargs.*; +class Gfo_url_parser_fxt { + private final Gfo_url_parser parser = new Gfo_url_parser(); + private Gfo_url actl; + public Gfo_url_parser_fxt Test__protocol_tid(byte v) {Tfds.Eq_byte(v, actl.Protocol_tid(), "protocol_tid"); return this;} + public Gfo_url_parser_fxt Test__protocol_bry(String v) {Tfds.Eq_str(v, actl.Protocol_bry(), "protocol_bry"); return this;} + public Gfo_url_parser_fxt Test__site(String v) {Tfds.Eq_str(v, actl.Segs__get_at_1st(), "site"); return this;} + public Gfo_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl.Segs__get_at_nth(), "page"); return this;} + public Gfo_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl.Anch(), "anch"); return this;} + public Gfo_url_parser_fxt Test__segs(String... ary) { + Tfds.Eq_str_lines(String_.Concat_lines_nl(ary), String_.Concat_lines_nl(String_.Ary(actl.Segs())), "segs"); + Tfds.Eq_int(ary.length, actl.Segs().length, "segs_len"); + return this; + } + public Gfo_url_parser_fxt Test__qargs(String... ary) {Tfds.Eq_str_lines(String_.To_str__as_kv_ary(ary), Qargs__To_str(actl.Qargs()), "qargs"); return this;} + public Gfo_url_parser_fxt Exec__parse(String v) { + this.actl = parser.Parse(Bry_.new_u8(v), 0, String_.Len(v)); + return this; + } + public void Test_Parse_site_fast(String raw, String expd) { + byte[] raw_bry = Bry_.new_u8(raw); + parser.Parse_site_fast(site_data, raw_bry, 0, raw_bry.length); + String actl = String_.new_u8(raw_bry, site_data.Site_bgn(), site_data.Site_end()); + Tfds.Eq(expd, actl); + } private final Gfo_url_site_data site_data = new Gfo_url_site_data(); + private static String Qargs__To_str(Gfo_qarg_itm[] ary) { + int len = ary.length; + Bry_bfr bfr = Bry_bfr_.New(); + for (int i = 0; i < len; ++i) { + Gfo_qarg_itm itm = ary[i]; + bfr.Add(itm.Key_bry()).Add_byte_eq(); + if (itm.Val_bry() != null) + bfr.Add(itm.Val_bry()); + bfr.Add_byte_nl(); + } + return bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/core/net/Gfo_url_parser_tst.java b/400_xowa/src/gplx/core/net/Gfo_url_parser_tst.java new file mode 100644 index 000000000..7832257b3 --- /dev/null +++ b/400_xowa/src/gplx/core/net/Gfo_url_parser_tst.java @@ -0,0 +1,126 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.net; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Gfo_url_parser_tst { + private final Gfo_url_parser_fxt tstr = new Gfo_url_parser_fxt(); + @Test public void Protocol__relative() { + tstr.Exec__parse("//en.wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_relative_1).Test__protocol_bry("//").Test__site("en.wikipedia.org"); + } + @Test public void Protocol__none() { + tstr.Exec__parse("en.wikipedia.org/wiki/A").Test__protocol_tid(Gfo_protocol_itm.Tid_unknown).Test__segs("en.wikipedia.org", "wiki", "A"); + } + @Test public void Site__parts__3() { + tstr.Exec__parse("https://en.wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__protocol_bry("https://").Test__segs("en.wikipedia.org"); + } + @Test public void Site__parts__2() { + tstr.Exec__parse("https://wikipedia.org").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__segs("wikipedia.org"); + } + @Test public void Site__parts__1() { + tstr.Exec__parse("https://wikipedia").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__segs("wikipedia"); + } + @Test public void Site__slash__none() { + tstr.Exec__parse("https:site").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("site"); + } + @Test public void Site__slash__eos() { + tstr.Exec__parse("https://en.wikipedia.org/").Test__protocol_tid(Gfo_protocol_itm.Tid_https).Test__site("en.wikipedia.org"); + } + @Test public void Paths__1() { + tstr.Exec__parse("https://site/A").Test__segs("site", "A"); + } + @Test public void Paths__2() { + tstr.Exec__parse("https://site/wiki/A").Test__segs("site", "wiki", "A"); + } + @Test public void Paths__n() { + tstr.Exec__parse("https://site/wiki/A/B/C/D").Test__segs("site", "wiki", "A", "B", "C", "D"); + } + @Test public void Qargs__1() { + tstr.Exec__parse("https://site/A?B=C").Test__page("A").Test__qargs("B", "C"); + } + @Test public void Qargs__2() { + tstr.Exec__parse("https://site/A?B=C&D=E").Test__page("A").Test__qargs("B", "C", "D", "E"); + } + @Test public void Qargs__3() { + tstr.Exec__parse("https://site/A?B=C&D=E&F=G").Test__page("A").Test__qargs("B", "C", "D", "E", "F", "G"); + } + @Test public void Qargs__ques__dupe__ques() { + tstr.Exec__parse("https://site/A?B?Y=Z").Test__page("A?B").Test__qargs("Y", "Z"); + } + @Test public void Qargs__ques__dupe__amp() { + tstr.Exec__parse("https://site/A?B=C&D?Y=Z").Test__page("A?B=C&D").Test__qargs("Y", "Z"); + } + @Test public void Qargs__ques__dupe__eq() { + tstr.Exec__parse("https://site/A?B=C?Y=Z").Test__page("A?B=C").Test__qargs("Y", "Z"); + } + @Test public void Qargs__amp__dupe__ques() { + tstr.Exec__parse("https://site/A?B&Y=Z").Test__page("A").Test__qargs("B", null, "Y", "Z"); + } + @Test public void Qargs__amp__dupe__amp() { + tstr.Exec__parse("https://site/A?B=C&D&Y=Z").Test__page("A").Test__qargs("B", "C", "D", null, "Y", "Z"); + } + @Test public void Qargs__missing_val__0() { + tstr.Exec__parse("https://site/A?").Test__page("A?").Test__qargs(); + } + @Test public void Qargs__missing_val__2() { + tstr.Exec__parse("https://site/A?B=C&D&F=G").Test__page("A").Test__qargs("B", "C", "D", null, "F", "G"); + } + @Test public void Qargs__missing_val__n() { + tstr.Exec__parse("https://site/A?B=C&D=E&F").Test__page("A").Test__qargs("B", "C", "D", "E", "F", null); + } + @Test public void Qargs__site_less__missing__0() { + tstr.Exec__parse("A?B").Test__segs("A?B").Test__qargs(); + } + @Test public void Qargs__site_less() { + tstr.Exec__parse("A?B=C&D=E").Test__site("A").Test__qargs("B", "C", "D", "E"); + } + @Test public void Anch__basic() { + tstr.Exec__parse("https://site/A#B").Test__page("A").Test__anch("B"); + } + @Test public void Anch__repeat__2() { + tstr.Exec__parse("https://site/A#B#C").Test__page("A").Test__anch("B#C"); + } + @Test public void Anch__repeat__3() { + tstr.Exec__parse("https://site/A#B#C#D").Test__page("A").Test__anch("B#C#D"); + } + @Test public void Anch__missing() { + tstr.Exec__parse("https://site/A#").Test__page("A#").Test__anch(null); + } + @Test public void Anch__missing__eos() { + tstr.Exec__parse("https://site/A#B#").Test__page("A").Test__anch("B#"); + } + @Test public void Anch__qargs__basic() { + tstr.Exec__parse("https://site/A?B=C&D=E#F").Test__page("A").Test__qargs("B", "C", "D", "E").Test__anch("F"); + } + @Test public void Anch__site_less() { + tstr.Exec__parse("A#B").Test__site("A").Test__anch("B"); + } + @Test public void Encode__page() { + tstr.Exec__parse("http://site/A%27s").Test__site("site").Test__page("A's"); + } + @Test public void Protocol_less__qargs() { + tstr.Exec__parse("Special:Search/Earth?fulltext=yes").Test__segs("Special:Search", "Earth").Test__page("Earth").Test__qargs("fulltext", "yes"); + } + @Test public void Parse_site_fast() { + tstr.Test_Parse_site_fast("http://a.org/B" , "a.org"); + tstr.Test_Parse_site_fast("http://a.org" , "a.org"); + tstr.Test_Parse_site_fast("//a.org/B" , "a.org"); + tstr.Test_Parse_site_fast("//a.org/B:C" , "a.org"); + } + // DELETED: logic isn't right; anch is first # not last; EX: https://en.wikipedia.org/w/index.php?title=Category:2001_albums&pagefrom=Beautiful+#View#mw-pages; DATE:2016-10-10 + // @Test public void Anch__qargs__repeat() { + // tstr.Exec__parse("https://site/A?B=C#&D=E#F").Test__page("A").Test__qargs("B", "C#", "D", "E").Test__anch("F"); + // } +} diff --git a/400_xowa/src/gplx/core/net/Http_request_parser_tst.java b/400_xowa/src/gplx/core/net/Http_request_parser_tst.java new file mode 100644 index 000000000..3b1817720 --- /dev/null +++ b/400_xowa/src/gplx/core/net/Http_request_parser_tst.java @@ -0,0 +1,93 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.net; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +public class Http_request_parser_tst { + @Before public void init() {fxt.Clear();} private final Http_request_parser_fxt fxt = new Http_request_parser_fxt(); + @Test public void Type_post() { + fxt.Test_type_post("POST /url HTTP/1.1", Http_request_itm.Type_post, "/url", "HTTP/1.1"); + } + @Test public void Type_content_type() { + fxt.Test_content_type("Content-Type: multipart/form-data; boundary=---------------------------72432484930026", "multipart/form-data", "-----------------------------72432484930026"); + } + @Test public void Type_content_type__x_www_form_url_encoded() { // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 + fxt.Test_content_type("Content-Type: application/x-www-form-urlencoded", null, null); + } + @Test public void Type_form_data() { + fxt.Test_form_data(String_.Ary + ( "POST /url HTTP/1.1" + , "Content-Type: multipart/form-data; boundary=---------------------------12345678901234" + , "" + , "-----------------------------12345678901234" + , "Content-Disposition: form-data; name=\"key0\"" + , "" + , "val0" + , "-----------------------------12345678901234" + , "Content-Disposition: form-data; name=\"key1\"" + , "" + , "val1" + , "-----------------------------12345678901234--" + ) + , fxt.Make_post_data_itm("key0", "val0") + , fxt.Make_post_data_itm("key1", "val1") + ); + } + @Test public void Type_accept_charset() { + fxt.Test_ignore("Accept-Charset: ISO-8859-1,utf-8;q=0.7"); + } +} +class Http_request_parser_fxt { + private final Http_request_parser parser; + private final Http_client_rdr client_rdr = Http_client_rdr_.new_mem(); + private final Http_server_wtr__mock server_wtr = new Http_server_wtr__mock(); + public Http_request_parser_fxt() { + this.parser = new Http_request_parser(server_wtr, false); + } + public void Clear() { + parser.Clear(); + server_wtr.Clear(); + } + public Http_post_data_itm Make_post_data_itm(String key, String val) {return new Http_post_data_itm(Bry_.new_u8(key), Bry_.new_u8(val));} + public void Test_type_post(String line, int expd_type, String expd_url, String expd_protocol) { + client_rdr.Stream_(String_.Ary(line)); + Http_request_itm req = parser.Parse(client_rdr); + Tfds.Eq(expd_type , req.Type()); + Tfds.Eq(expd_url , String_.new_u8(req.Url())); + Tfds.Eq(expd_protocol , String_.new_u8(req.Protocol())); + } + public void Test_content_type(String line, String expd_content_type, String expd_content_boundary) { + client_rdr.Stream_(String_.Ary(line)); + Http_request_itm req = parser.Parse(client_rdr); + Tfds.Eq(expd_content_type , String_.new_u8(req.Content_type())); + Tfds.Eq(expd_content_boundary , String_.new_u8(req.Content_type_boundary())); + } + public void Test_form_data(String[] ary, Http_post_data_itm... expd) { + client_rdr.Stream_(ary); + Http_request_itm req = parser.Parse(client_rdr); + Http_post_data_hash hash = req.Post_data_hash(); + int len = hash.Len(); + for (int i = 0; i < len; ++i) { + Http_post_data_itm itm = hash.Get_at(i); + Tfds.Eq_bry(itm.Key(), expd[i].Key()); + Tfds.Eq_bry(itm.Val(), expd[i].Val()); + } + } + public void Test_ignore(String line) { + client_rdr.Stream_(String_.Ary(line)); + parser.Parse(client_rdr); + Gftest.Eq__str(null, server_wtr.Data()); + } +} diff --git a/400_xowa/src/gplx/core/primitives/Gfo_number_parser_tst.java b/400_xowa/src/gplx/core/primitives/Gfo_number_parser_tst.java new file mode 100644 index 000000000..4a287e464 --- /dev/null +++ b/400_xowa/src/gplx/core/primitives/Gfo_number_parser_tst.java @@ -0,0 +1,107 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.primitives; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Gfo_number_parser_tst { + @Before public void init() {fxt.Clear();} private final Gfo_number_parser_fxt fxt = new Gfo_number_parser_fxt(); + @Test public void Integer() { + fxt.Test_int("1", 1); + fxt.Test_int("1234", 1234); + fxt.Test_int("1234567890", 1234567890); + fxt.Test_int("-1234", -1234); + fxt.Test_int("+1", 1); + fxt.Test_int("00001", 1); + } + @Test public void Long() { + fxt.Test_long("9876543210", 9876543210L); + } + @Test public void Decimal() { + fxt.Test_dec("1.23", Decimal_adp_.parse("1.23")); + fxt.Test_dec("1.023", Decimal_adp_.parse("1.023")); + fxt.Test_dec("-1.23", Decimal_adp_.parse("-1.23")); + } + @Test public void Double_long() { + fxt.Test_dec(".42190046219457", Decimal_adp_.parse(".42190046219457")); + } + @Test public void Exponent() { + fxt.Test_int("1E2", 100); + fxt.Test_dec("1.234E2", Decimal_adp_.parse("123.4")); + fxt.Test_dec("1.234E-2", Decimal_adp_.parse(".01234")); + fxt.Test_dec("123.4E-2", Decimal_adp_.parse("1.234")); + fxt.Test_dec("+6.0E-3", Decimal_adp_.parse(".006")); + } + @Test public void Err() { + fxt.Test_err("+", true); + fxt.Test_err("-", true); + fxt.Test_err("a", true); + fxt.Test_err("1-2", false); + fxt.Test_err("1..1", true); + fxt.Test_err("1,,1", true); + fxt.Test_err("1", false); + } + @Test public void Hex() { + fxt.Test_hex("0x1" , 1); + fxt.Test_hex("0xF" , 15); + fxt.Test_hex("0x20" , 32); + fxt.Test_hex("x20" , 0, false); + fxt.Test_hex("d" , 0, false); // PURPOSE: d was being converted to 13; no.w:Hovedbanen; DATE:2014-04-13 + } + @Test public void Ignore() { + fxt.Init_ignore("\n\t"); + fxt.Test_int("1" , 1); + fxt.Test_int("1\n" , 1); + fxt.Test_int("1\t" , 1); + fxt.Test_int("1\n2" , 12); + fxt.Test_err("1\r" , true); + } +} +class Gfo_number_parser_fxt { + private final Gfo_number_parser parser = new Gfo_number_parser(); + public void Clear() {parser.Clear();} + public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));} + public void Test_int(String raw, int expd) { + byte[] raw_bry = Bry_.new_a7(raw); + int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int(); + Tfds.Eq(expd, actl, raw); + } + public void Test_long(String raw, long expd) { + byte[] raw_bry = Bry_.new_a7(raw); + Tfds.Eq(expd, parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_long(), raw); + } + public void Test_dec(String raw, Decimal_adp expd) { + byte[] raw_bry = Bry_.new_a7(raw); + Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec(); + Tfds.Eq(expd.To_double(), actl.To_double(), raw); + } + public void Test_err(String raw, boolean expd) { + byte[] raw_bry = Bry_.new_a7(raw); + boolean actl = parser.Parse(raw_bry, 0, raw_bry.length).Has_err(); + Tfds.Eq(expd, actl, raw); + } + public void Test_hex(String raw, int expd_val) {Test_hex(raw, expd_val, true);} + public void Test_hex(String raw, int expd_val, boolean expd_pass) { + parser.Hex_enabled_(true); + byte[] raw_bry = Bry_.new_a7(raw); + int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int(); + if (expd_pass) { + Tfds.Eq(expd_val, actl, raw); + Tfds.Eq(true, !parser.Has_err()); + } + else + Tfds.Eq(false, !parser.Has_err()); + parser.Hex_enabled_(false); + } +} diff --git a/400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.java b/400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.java new file mode 100644 index 000000000..e2ba168cc --- /dev/null +++ b/400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.primitives; import gplx.*; import gplx.core.*; +import org.junit.*; import gplx.core.tests.*; +public class Int_ary_parser_tst { + private final Int_ary_parser_fxt fxt = new Int_ary_parser_fxt(); + @Test public void Many() {fxt.Test__Parse_ary("1,2,3,4,5" , 0, 9, Int_ary_.New(1, 2, 3, 4, 5));} + @Test public void One() {fxt.Test__Parse_ary("1" , 0, 1, Int_ary_.New(1));} + @Test public void None() {fxt.Test__Parse_ary("" , 0, 0, Int_ary_.New());} +} +class Int_ary_parser_fxt { + public void Test__Parse_ary(String raw, int bgn, int end, int[] expd) { + Gftest.Eq__ary(expd, new Int_ary_parser().Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma), "parse_ary failed"); + } +} diff --git a/400_xowa/src/gplx/core/primitives/Int_pool_tst.java b/400_xowa/src/gplx/core/primitives/Int_pool_tst.java new file mode 100644 index 000000000..1a7699bee --- /dev/null +++ b/400_xowa/src/gplx/core/primitives/Int_pool_tst.java @@ -0,0 +1,73 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.primitives; import gplx.*; import gplx.core.*; +import org.junit.*; +public class Int_pool_tst { + private final Int_pool_tstr tstr = new Int_pool_tstr(); + @Before public void init() {tstr.Clear();} + @Test public void Get__one() { + tstr.Test_get(0); + } + @Test public void Get__many() { + tstr.Test_get(0); + tstr.Test_get(1); + tstr.Test_get(2); + } + @Test public void Del__one() { + tstr.Test_get(0); + tstr.Exec_del(0); + tstr.Test_get(0); + } + @Test public void Del__sequential() { + tstr.Test_get(0); + tstr.Test_get(1); + tstr.Test_get(2); + tstr.Exec_del(2).Test_get(2); + tstr.Exec_del(2); + tstr.Exec_del(1); + tstr.Exec_del(0).Test_get(0); + } + @Test public void Del__out_of_order() { + tstr.Test_get(0); + tstr.Test_get(1); + tstr.Test_get(2); + tstr.Exec_del(0).Test_get(0); + tstr.Exec_del(0); + tstr.Exec_del(1); + tstr.Exec_del(2); + tstr.Test_get(0); + } + @Test public void Del__out_of_order_2() { + tstr.Test_get(0); + tstr.Test_get(1); + tstr.Test_get(2); + tstr.Exec_del(1); + tstr.Exec_del(2); + tstr.Exec_del(0); + } +} +class Int_pool_tstr { + private final Int_pool pool = new Int_pool(); + public void Clear() {pool.Clear();} + public Int_pool_tstr Test_get(int expd) { + Tfds.Eq(expd, pool.Get_next()); + return this; + } + public Int_pool_tstr Exec_del(int val) { + pool.Del(val); + return this; + } +} diff --git a/400_xowa/src/gplx/core/progs/rates/Gfo_rate_list_tst.java b/400_xowa/src/gplx/core/progs/rates/Gfo_rate_list_tst.java new file mode 100644 index 000000000..7b24db9e4 --- /dev/null +++ b/400_xowa/src/gplx/core/progs/rates/Gfo_rate_list_tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.progs.rates; import gplx.*; import gplx.core.*; import gplx.core.progs.*; +import org.junit.*; import gplx.core.tests.*; +public class Gfo_rate_list_tst { + private final Gfo_rate_list_fxt fxt = new Gfo_rate_list_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Add__1() {fxt.Add(100, 20).Test(5, 5);} + @Test public void Add__2() {fxt.Add(100, 20).Add(100, 30).Test(4, .20d);} + @Test public void Add__3() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Test(3, .25d);} + @Test public void Add__4() {fxt.Add(100, 20).Add(100, 30).Add(100, 50).Add(600, 0).Test(9, 2);} +} +class Gfo_rate_list_fxt { + private final Gfo_rate_list list = new Gfo_rate_list(6); + public void Clear() {list.Clear();} + public Gfo_rate_list_fxt Add(long data, long time) {list.Add(data, time); return this;} + public void Test(double expd_rate, double expd_delta) { + Gftest.Eq__double(expd_rate , list.Cur_rate() , "cur_rate"); + Gftest.Eq__double(expd_delta, list.Cur_delta() , "cur_delta"); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/core/security/files/Cksum_list_tst.java b/400_xowa/src/gplx/core/security/files/Cksum_list_tst.java new file mode 100644 index 000000000..3977e6f0d --- /dev/null +++ b/400_xowa/src/gplx/core/security/files/Cksum_list_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*; +import org.junit.*; import gplx.core.tests.*; +public class Cksum_list_tst { + private final Cksum_list_fxt fxt = new Cksum_list_fxt(); + @Test public void Basic() { + fxt.Init__file("a.txt").Init__file("ab.txt"); + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a5e54d1fd7bb69a228ef0dcd2431367e *a.txt" + , "90f15b7ca11bd4c70d9047cd29a80040 *ab.txt" + ), 11 + , fxt.Make__itm("a5e54d1fd7bb69a228ef0dcd2431367e", "a.txt", 5) + , fxt.Make__itm("90f15b7ca11bd4c70d9047cd29a80040", "ab.txt", 6) + ); + } +} +class Cksum_list_fxt { + private final Io_url dir = Io_url_.mem_dir_("mem/dir/"); + public Cksum_list_fxt() { + Io_mgr.Instance.InitEngine_mem(); + } + public Cksum_list_fxt Init__file(String fil_name) { + Io_url fil_url = dir.GenSubFil(fil_name); + Io_mgr.Instance.SaveFilStr(fil_url, fil_name); + return this; + } + public Cksum_itm Make__itm(String hash, String file_name, long size) {return new Cksum_itm(Bry_.new_u8(hash), dir.GenSubFil(file_name), size);} + public Cksum_list_fxt Test__parse(String raw, long expd_size, Cksum_itm... expd_itms) { + Cksum_list actl_list = Cksum_list.Parse(gplx.core.security.Hash_algo_.Tid__md5, dir, Bry_.new_u8(raw)); + Gftest.Eq__long(expd_size, actl_list.Itms_size); + Gftest.Eq__ary(expd_itms, actl_list.Itms); + return this; + } +} diff --git a/400_xowa/src/gplx/dbs/bulks/Db_tbl_copy_tst.java b/400_xowa/src/gplx/dbs/bulks/Db_tbl_copy_tst.java new file mode 100644 index 000000000..71f80030b --- /dev/null +++ b/400_xowa/src/gplx/dbs/bulks/Db_tbl_copy_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*; +import org.junit.*; import gplx.core.tests.*; import gplx.dbs.metas.*; +public class Db_tbl_copy_tst { + private final Db_tbl_copy_fxt fxt = new Db_tbl_copy_fxt(); + @Test public void Basic() { + fxt.Test__bld_sql(fxt.Make_tbl("tbl_1", Dbmeta_fld_itm.new_int("fld_1"), Dbmeta_fld_itm.new_int("fld_2")), + String_.Concat_lines_nl_skip_last + ( "INSERT INTO trg" + , "(fld_1, fld_2)" + , "SELECT" + , " fld_1, fld_2" + , "FROM src" + )); + } +} +class Db_tbl_copy_fxt { + private final Db_tbl_copy mgr = new Db_tbl_copy(); + public Dbmeta_tbl_itm Make_tbl(String name, Dbmeta_fld_itm... flds) {return Dbmeta_tbl_itm.New(name, flds);} + public void Test__bld_sql(Dbmeta_tbl_itm tbl, String expd) { + Gftest.Eq__ary__lines(expd, mgr.Bld_sql(tbl, "src", "trg"), "sql"); + } +} diff --git a/400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr_tst.java b/400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr_tst.java new file mode 100644 index 000000000..2b1ce4f4d --- /dev/null +++ b/400_xowa/src/gplx/dbs/metas/updates/Schema_update_mgr_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*; +import org.junit.*; import gplx.dbs.*; +public class Schema_update_mgr_tst { + @Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt(); + @Test public void Create() { + fxt.Test_exec_y(new Schema_update_cmd__mock()); + } + @Test public void Delete() { + fxt.Init_itm(Dbmeta_itm_tid.Tid_table, Schema_update_cmd__mock.Tbl_name); + fxt.Test_exec_n(new Schema_update_cmd__mock()); + } +} +class Schema_update_mgr_fxt { + private Schema_update_mgr update_mgr; private Schema_db_mgr db_mgr; + public void Clear() { + update_mgr = new Schema_update_mgr(); + db_mgr = new Schema_db_mgr(); + } + public void Init_itm(int tid, String name) { + db_mgr.Tbl_mgr().Add(Dbmeta_tbl_itm.New(name)); + } + public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);} + public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);} + private void Test_exec(Schema_update_cmd cmd, boolean expd) { + update_mgr.Add(cmd); + update_mgr.Update(db_mgr, Db_conn_.Noop); + Tfds.Eq(expd, cmd.Exec_is_done()); + } +} +class Schema_update_cmd__mock implements Schema_update_cmd { + public String Name() {return "xowa.user.cfg_regy.create";} + public boolean Exec_is_done() {return exec_is_done;} private boolean exec_is_done; + public void Exec(Schema_db_mgr mgr, Db_conn conn) { + if (mgr.Tbl_mgr().Has(Tbl_name)) return; + exec_is_done = true; + } + public static final String Tbl_name = "tbl_mock"; +} diff --git a/400_xowa/src/gplx/dbs/percentiles/Percentile_rng_tst.java b/400_xowa/src/gplx/dbs/percentiles/Percentile_rng_tst.java new file mode 100644 index 000000000..05396d203 --- /dev/null +++ b/400_xowa/src/gplx/dbs/percentiles/Percentile_rng_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*; +import org.junit.*; +public class Percentile_rng_tst { + private final Percentile_rng_fxt fxt = new Percentile_rng_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Found__000() { + fxt.Test__rng(999994, 1000001); + fxt.Exec__update( 0).Test__rng(999966, 999994); + fxt.Exec__update( 0).Test__rng(999854, 999966); + } + @Test public void Found__025() { + fxt.Test__rng(999994, 1000001); + fxt.Exec__update( 25).Test__rng(999973, 999994); + fxt.Exec__update( 25).Test__rng(999931, 999973); + fxt.Exec__update( 25).Test__rng(999889, 999931); + fxt.Exec__update( 25).Test__rng(999847, 999889); + } + @Test public void Calc_score_unit() { + fxt.Test__calc_score_unit(50, 16000000, 1000000, 4); // to fill 50 -> 16 pages per point -> read every 4 points to get 64 pages + fxt.Test__calc_score_unit(50, 1000, 1000000, 50000); // to fill 50 -> 1000 points per page -> read every 50k points to get 50 pages + fxt.Test__calc_score_unit(50, 25, 1000000, 1000000); // range bounds check; to fill 50, always read full amount + } +} +class Percentile_rng_fxt { + private final Percentile_rng rng = new Percentile_rng(); + public void Clear() { + this.Exec__init_for_wiki(16000000, 1000000); + this.Exec__init_for_search(100, 0); + } + public Percentile_rng_fxt Exec__init_for_wiki (int pages_max, int score_max) { + rng.Init(pages_max, score_max); return this; + } + public Percentile_rng_fxt Exec__init_for_search(int request_count, int score_len_adj) { + rng.Select_init(request_count, Percentile_rng.Score_null, Percentile_rng.Score_null, score_len_adj); return this; + } + public Percentile_rng_fxt Exec__update(int rdr_found) { + rng.Update(rdr_found); return this; + } + public void Test__rng(int expd_bgn, int expd_end) { + Tfds.Eq(expd_end, rng.Score_end(), "rng_end"); + Tfds.Eq(expd_bgn, rng.Score_bgn(), "rng_bgn"); + } + public void Test__calc_score_unit(int request_count, long pages_max, int score_max, int expd) { + Tfds.Eq(expd, Percentile_rng.Calc_score_unit(request_count, pages_max, score_max)); + } +} diff --git a/400_xowa/src/gplx/fsdb/data/Fsd_thm_tbl_tst.java b/400_xowa/src/gplx/fsdb/data/Fsd_thm_tbl_tst.java new file mode 100644 index 000000000..4a98d1984 --- /dev/null +++ b/400_xowa/src/gplx/fsdb/data/Fsd_thm_tbl_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*; +import org.junit.*; +public class Fsd_thm_tbl_tst { + @Before public void init() {fxt.Clear();} private Fsd_thm_tbl_fxt fxt = new Fsd_thm_tbl_fxt(); + @Test public void Basic() { + fxt.Init_list(fxt.Make(100), fxt.Make(200), fxt.Make(400)); + fxt.Test_match_nearest_itm(fxt.Make(400), fxt.Make(400)); + fxt.Test_match_nearest_itm(fxt.Make(200), fxt.Make(200)); + fxt.Test_match_nearest_itm(fxt.Make(100), fxt.Make(100)); + fxt.Test_match_nearest_itm(fxt.Make(350), fxt.Make(400)); + fxt.Test_match_nearest_itm(fxt.Make(150), fxt.Make(200)); + fxt.Test_match_nearest_itm(fxt.Make(999), fxt.Make(400)); + } + @Test public void Empty() { + fxt.Init_list(); // no items + fxt.Test_match_nearest_itm(fxt.Make(100), Fsd_thm_itm.Null); + } +} +class Fsd_thm_tbl_fxt { + private final List_adp list = List_adp_.New(); + public void Clear() {list.Clear();} + public Fsd_thm_itm Make(int w) { + double time = gplx.xowa.files.Xof_lnki_time.Null; + int page = gplx.xowa.files.Xof_lnki_page.Null; + Fsd_thm_itm rv = Fsd_thm_itm.new_(); + rv.Init_by_req(w, time, page); + return rv; + } + public void Init_list(Fsd_thm_itm... ary) {list.Add_many((Object[])ary);} + public void Test_match_nearest_itm(Fsd_thm_itm req, Fsd_thm_itm expd) { + Fsd_thm_tbl.Match_nearest(list, req, Bool_.Y); + if (expd == Fsd_thm_itm.Null) { + Tfds.Eq(req.Req_w(), 0); + } + else { + Tfds.Eq(expd.W(), req.W()); + Tfds.Eq(expd.Time(), req.Time()); + Tfds.Eq(expd.Page(), req.Page()); + } + } +} diff --git a/400_xowa/src/gplx/gfui/Gfui_bnd_parser_tst.java b/400_xowa/src/gplx/gfui/Gfui_bnd_parser_tst.java new file mode 100644 index 000000000..31cb8d57e --- /dev/null +++ b/400_xowa/src/gplx/gfui/Gfui_bnd_parser_tst.java @@ -0,0 +1,62 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.gfui; import gplx.*; +import org.junit.*; +public class Gfui_bnd_parser_tst { + @Before public void init() {fxt.Clear();} private Gfui_bnd_parser_fxt fxt = new Gfui_bnd_parser_fxt(); + @Test public void Norm_one() { + fxt.Test__to_norm("mod.c" , "Ctrl"); + fxt.Test__to_norm("key.ctrl" , "Ctrl"); + fxt.Test__to_norm("key.a" , "A"); + fxt.Test__to_norm("key.left" , "Left"); + } + @Test public void Norm_add() { + fxt.Test__to_norm("mod.c+key.a" , "Ctrl + A"); + fxt.Test__to_norm("mod.ca+key.a" , "Ctrl + Alt + A"); + fxt.Test__to_norm("mod.cas+key.a" , "Ctrl + Alt + Shift + A"); + } + @Test public void Norm_chord() { + fxt.Test__to_norm("key.a,key.b" , "A, B"); + } + @Test public void Norm_add_and_chord() { + fxt.Test__to_norm("mod.c+key.a,mod.a+key.b" , "Ctrl + A, Alt + B"); + } + @Test public void Gfui_add() { + fxt.Test__to_gfui("Ctrl + A" , "mod.c+key.a"); + fxt.Test__to_gfui("Ctrl + Shift + A" , "mod.cs+key.a"); + fxt.Test__to_gfui("Ctrl + Alt + Shift + A" , "mod.cas+key.a"); + } + @Test public void Keypad_enter() { + fxt.Test__to_norm("key.numpad_enter" , "Numpad Enter"); + fxt.Test__to_norm("mod.c+key.numpad_enter" , "Ctrl + Numpad Enter"); + } + @Test public void None() { + fxt.Test__to_gfui("None" , "key.none"); + fxt.Test__to_norm("key.none" , "None"); + } +} +class Gfui_bnd_parser_fxt { + private Gfui_bnd_parser parser; + public void Clear() { + parser = Gfui_bnd_parser.new_en_(); + } + public void Test__to_norm(String key, String expd) { + Tfds.Eq(expd, parser.Xto_norm(key)); + } + public void Test__to_gfui(String key, String expd) { + Tfds.Eq(expd, parser.Xto_gfui(key)); + } +} diff --git a/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java b/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java new file mode 100644 index 000000000..eea30e700 --- /dev/null +++ b/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_int_tst.java @@ -0,0 +1,62 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.dsvs; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Dsv_tbl_parser_int_tst { + private Dsv_mok_fxt fxt = new Dsv_mok_fxt(); + @Test public void Basic() { + fxt .Test_load(String_.Concat_lines_nl_skip_last + ( "a|1|3" + , "b|2|4" + ) + , fxt.mgr_int_() + , fxt.itm_int_("a", 1, 3) + , fxt.itm_int_("b", 2, 4) + ); + } +} +class Mok_int_itm implements To_str_able { + private String fld_0; + private int fld_1, fld_2; + public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;} + public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));} +} +class Mok_int_mgr extends Mok_mgr_base { + public void Clear() {itms.Clear();} + @Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New(); + private String fld_0; + private int fld_1, fld_2; + @Override public Dsv_fld_parser[] Fld_parsers() { + return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance}; + } + @Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) { + switch (fld_idx) { + case 0: fld_0 = String_.new_u8(src, bgn, end); return true; + default: return false; + } + } + @Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) { + switch (fld_idx) { + case 1: fld_1 = val_int; return true; + case 2: fld_2 = val_int; return true; + default: return false; + } + } + @Override public void Commit_itm(Dsv_tbl_parser parser, int pos) { + Mok_int_itm itm = new Mok_int_itm(fld_0, fld_1, fld_2); + itms.Add(itm); + } +} diff --git a/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java b/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java new file mode 100644 index 000000000..2f9b1fd32 --- /dev/null +++ b/400_xowa/src/gplx/langs/dsvs/Dsv_tbl_parser_str_tst.java @@ -0,0 +1,107 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.dsvs; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Dsv_tbl_parser_str_tst { + private Dsv_mok_fxt fxt = new Dsv_mok_fxt(); + @Test public void Basic() { + fxt .Test_load(String_.Concat_lines_nl_skip_last + ( "a|A" + , "b|B" + ) + , fxt.mgr_str_(2) + , fxt.itm_str_("a", "A") + , fxt.itm_str_("b", "B") + ); + } + @Test public void Blank_lines() { + fxt .Test_load(String_.Concat_lines_nl_skip_last + ( "" + , "a|A" + , "" + , "b|B" + , "" + ) + , fxt.mgr_str_(2) + , fxt.itm_str_("a", "A") + , fxt.itm_str_("b", "B") + ); + } + @Test public void Incomplete_row() { + fxt .Test_load(String_.Concat_lines_nl_skip_last + ( "a" + , "b" + , "" + ) + , fxt.mgr_str_(2) + , fxt.itm_str_("a") + , fxt.itm_str_("b") + ); + } + @Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells + fxt .Test_load(String_.Concat_lines_nl_skip_last + ( "a|") + , fxt.mgr_str_(3) + , fxt.itm_str_("a", "") + ); + } +} +abstract class Mok_mgr_base extends Dsv_wkr_base { + public abstract To_str_able[] Itms(); +} +class Dsv_mok_fxt { + private Dsv_tbl_parser tbl_parser = new Dsv_tbl_parser(); + public Dsv_mok_fxt Clear() { + tbl_parser.Clear(); + return this; + } + public Mok_mgr_base mgr_int_() {return new Mok_int_mgr();} + public Mok_mgr_base mgr_str_(int len) {return new Mok_str_mgr(len);} + public Mok_str_itm itm_str_(String... flds) {return new Mok_str_itm(flds);} + public Mok_int_itm itm_int_(String fld_0, int fld_1, int fld_2) {return new Mok_int_itm(fld_0, fld_1, fld_2);} + public void Test_load(String src, Mok_mgr_base mgr, To_str_able... expd) { + mgr.Load_by_bry(Bry_.new_u8(src)); + Tfds.Eq_ary_str(expd, mgr.Itms()); + } +} +class Mok_str_itm implements To_str_able { + private String[] flds; + public Mok_str_itm(String[] flds) {this.flds = flds;} + public String To_str() {return String_.Concat_with_str("|", flds);} +} +class Mok_str_mgr extends Mok_mgr_base { + private int flds_len; + public Mok_str_mgr(int flds_len) { + this.flds_len = flds_len; + } + public void Clear() {itms.Clear();} + @Override public To_str_able[] Itms() {return (To_str_able[])itms.To_ary(To_str_able.class);} private List_adp itms = List_adp_.New(); + private List_adp flds = List_adp_.New(); + @Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) { + flds.Add(String_.new_u8(src, bgn, end)); + return true; + } + @Override public Dsv_fld_parser[] Fld_parsers() { + Dsv_fld_parser[] rv = new Dsv_fld_parser[flds_len]; + for (int i = 0; i < flds_len; i++) + rv[i] = Dsv_fld_parser_.Bry_parser; + return rv; + } + @Override public void Commit_itm(Dsv_tbl_parser parser, int pos) { + Mok_str_itm itm = new Mok_str_itm((String[])flds.To_ary_and_clear(String.class)); + itms.Add(itm); + } +} diff --git a/400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java b/400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java new file mode 100644 index 000000000..8196ac652 --- /dev/null +++ b/400_xowa/src/gplx/langs/gfs/Gfs_msg_bldr_tst.java @@ -0,0 +1,74 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.gfs; import gplx.*; import gplx.langs.*; +import org.junit.*; import gplx.core.strings.*; +public class Gfs_msg_bldr_tst { + @Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt(); + @Test public void Basic() { + fxt.Test_build("a;", fxt.msg_("a")); + } + @Test public void Dot() { + fxt.Test_build("a.b.c;" + , fxt.msg_("a").Subs_ + ( fxt.msg_("b").Subs_ + ( fxt.msg_("c") + ))); + } + @Test public void Args() { + fxt.Test_build("a('b', 'c');", fxt.msg_("a", fxt.kv_("", "b"), fxt.kv_("", "c"))); + } + @Test public void Args_num() { + fxt.Test_build("a(1);", fxt.msg_("a", fxt.kv_("", "1"))); + } + @Test public void Assign() { + fxt.Test_build("a = 'b';", fxt.msg_("a_", fxt.kv_("", "b"))); + } + @Test public void Assign_num() { + fxt.Test_build("a = 1;", fxt.msg_("a_", fxt.kv_("", "1"))); + } +} +class Gfs_msg_bldr_fxt { + public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr.Instance; + public Keyval kv_(String key, String val) {return Keyval_.new_(key, val);} + public GfoMsg msg_(String key, Keyval... args) { + GfoMsg rv = GfoMsg_.new_parse_(key); + int len = args.length; + for (int i = 0; i < len; i++) { + Keyval kv = args[i]; + rv.Add(kv.Key(), kv.Val()); + } + return rv; + } + public void Test_build(String raw, GfoMsg... expd) { + GfoMsg root = msg_bldr.Bld(raw); + Tfds.Eq_str_lines(Xto_str(expd), Xto_str(To_ary(root))); + } + GfoMsg[] To_ary(GfoMsg msg) { + int len = msg.Subs_count(); + GfoMsg[] rv = new GfoMsg[len]; + for (int i = 0; i < len; i++) + rv[i] = msg.Subs_getAt(i); + return rv; + } + String Xto_str(GfoMsg[] ary) { + int len = ary.length; + for (int i = 0; i < len; i++) { + if (i != 0) sb.Add_char_crlf(); + sb.Add(ary[i].To_str()); + } + return sb.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java b/400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java new file mode 100644 index 000000000..712a78551 --- /dev/null +++ b/400_xowa/src/gplx/langs/gfs/Gfs_parser_tst.java @@ -0,0 +1,194 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.gfs; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Gfs_parser_tst { + @Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt(); + @Test public void Semicolon() { + fxt .Test_parse("a;", fxt.nde_("a")); + fxt .Test_parse("a;b;c;", fxt.nde_("a"), fxt.nde_("b"), fxt.nde_("c")); + fxt .Test_parse("a_0;", fxt.nde_("a_0")); + } + @Test public void Dot() { + fxt .Test_parse("a.b;", fxt.nde_("a").Subs_add(fxt.nde_("b"))); + fxt .Test_parse("a.b;c.d;", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d"))); + } + @Test public void Parens() { + fxt .Test_parse("a();b();", fxt.nde_("a"), fxt.nde_("b")); + fxt .Test_parse("a().b();c().d();", fxt.nde_("a").Subs_add(fxt.nde_("b")), fxt.nde_("c").Subs_add(fxt.nde_("d"))); + } + @Test public void Num() { + fxt .Test_parse("a(1,2);", fxt.nde_("a").Atrs_add_many(fxt.val_("1"), fxt.val_("2"))); + } + @Test public void Quote() { + fxt .Test_parse("a('b');", fxt.nde_("a").Atrs_add(fxt.val_("b"))); + } + @Test public void Quote_escaped() { + fxt .Test_parse("a('b''c''d');", fxt.nde_("a").Atrs_add(fxt.val_("b'c'd"))); + } + @Test public void Quote_escaped_2() { + fxt .Test_parse("a('a''''b');", fxt.nde_("a").Atrs_add(fxt.val_("a''b"))); + } + @Test public void Quote_mixed() { + fxt .Test_parse("a('b\"c');", fxt.nde_("a").Atrs_add(fxt.val_("b\"c"))); + } + @Test public void Comma() { + fxt .Test_parse("a('b','c','d');", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c"), fxt.val_("d"))); + } + @Test public void Ws() { + fxt .Test_parse(" a ( 'b' , 'c' ) ; ", fxt.nde_("a").Atrs_add_many(fxt.val_("b"), fxt.val_("c"))); + } + @Test public void Comment_slash_slash() { + fxt .Test_parse("//z\na;//y\n", fxt.nde_("a")); + } + @Test public void Comment_slash_star() { + fxt .Test_parse("/*z*/a;/*y*/", fxt.nde_("a")); + } + @Test public void Curly() { + fxt .Test_parse("a{b;}", fxt.nde_("a").Subs_add(fxt.nde_("b"))); + } + @Test public void Curly_nest() { + fxt .Test_parse("a{b{c{d;}}}" + , fxt.nde_("a").Subs_add + ( fxt.nde_("b").Subs_add + ( fxt.nde_("c").Subs_add + ( fxt.nde_("d") + )))); + } + @Test public void Curly_nest_peers() { + fxt .Test_parse(String_.Concat_lines_nl + ( "a{" + , " a0{" + , " a00{" + , " a000;" + , " }" + , " a01;" + , " }" + , " a1;" + , "}" + ) + , fxt.nde_("a").Subs_add_many + ( fxt.nde_("a0").Subs_add_many + ( fxt.nde_("a00").Subs_add + ( fxt.nde_("a000") + ) + , fxt.nde_("a01") + ) + , fxt.nde_("a1") + )); + } + @Test public void Curly_dot() { + fxt .Test_parse("a{a0.a00;a1.a10;}" + , fxt.nde_("a").Subs_add_many + ( fxt.nde_("a0").Subs_add_many(fxt.nde_("a00")) + , fxt.nde_("a1").Subs_add_many(fxt.nde_("a10")) + )); + } + @Test public void Eq() { + fxt .Test_parse("a='b';", fxt.nde_("a").Atrs_add(fxt.val_("b"))); + fxt .Test_parse("a.b.c='d';" + , fxt.nde_("a").Subs_add + ( fxt.nde_("b").Subs_add_many + ( fxt.nde_("c").Atrs_add(fxt.val_("d")) + ))); + fxt .Test_parse("a.b{c='d'; e='f'}" + , fxt.nde_("a").Subs_add + ( fxt.nde_("b").Subs_add_many + ( fxt.nde_("c").Atrs_add(fxt.val_("d")) + , fxt.nde_("e").Atrs_add(fxt.val_("f")) + ))); + } + @Test public void Curly_nest_peers2() { + fxt .Test_parse(String_.Concat_lines_nl + ( "a() {" + , " k1 = 'v1';" + , "}" + ) + , fxt.nde_("a").Subs_add_many + ( fxt.nde_("k1").Atrs_add(fxt.val_("v1")) + ) + ); + } + @Test public void Fail() { + fxt .Test_parse_fail("a(.);", Gfs_err_mgr.Fail_msg_invalid_lxr); // (.) + fxt .Test_parse_fail("a..b;", Gfs_err_mgr.Fail_msg_invalid_lxr); // .. + fxt .Test_parse_fail("a.;", Gfs_err_mgr.Fail_msg_invalid_lxr); // .; + fxt .Test_parse_fail("a", Gfs_err_mgr.Fail_msg_eos); // eos + fxt .Test_parse_fail("a;~;", Gfs_err_mgr.Fail_msg_unknown_char); // ~ + } +} +class Gfs_parser_fxt { + public void Clear() {} + public Gfs_nde nde_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));} + public Gfs_nde val_(String v) {return new Gfs_nde().Name_(Bry_.new_a7(v));} + public void Test_parse(String src_str, Gfs_nde... expd) { + byte[] src_bry = Bry_.new_u8(src_str); + Gfs_nde root = parser.Parse(src_bry); + Tfds.Eq_str_lines(To_str(null, expd), To_str(src_bry, root.Subs_to_ary())); + } private Bry_bfr tmp_bfr = Bry_bfr_.New(), path_bfr = Bry_bfr_.New(); Gfs_parser parser = new Gfs_parser(); + public void Test_parse_fail(String src_str, String expd_err) { + byte[] src_bry = Bry_.new_u8(src_str); + try {parser.Parse(src_bry);} + catch (Exception e) { + String actl_err = Err_.Message_gplx_full(e); + actl_err = String_.GetStrBefore(actl_err, ":"); + boolean match = String_.Has(actl_err, expd_err); + if (!match) Tfds.Fail("expecting '" + expd_err + "' got '" + actl_err + "'"); + return; + } + Tfds.Fail("expected to fail with " + expd_err); + } + public String To_str(byte[] src, Gfs_nde[] expd) { + int subs_len = expd.length; + for (int i = 0; i < subs_len; i++) { + path_bfr.Clear().Add_int_variable(i); + To_str(tmp_bfr, path_bfr, src, expd[i]); + } + return tmp_bfr.To_str_and_clear(); + } + public void To_str(Bry_bfr bfr, Bry_bfr path, byte[] src, Gfs_nde nde) { + To_str_atr(bfr, path, src, Atr_name, nde.Name(), nde.Name_bgn(), nde.Name_end()); + int atrs_len = nde.Atrs_len(); + for (int i = 0; i < atrs_len; i++) { + Gfs_nde atr = nde.Atrs_get_at(i); + int path_len_old = path.Len(); + path.Add_byte(Byte_ascii.Dot).Add_byte((byte)(Byte_ascii.Ltr_a + i)); + int path_len_new = path.Len(); + To_str(bfr, path, src, atr); + path.Del_by(path_len_new - path_len_old); + } + int subs_len = nde.Subs_len(); + for (int i = 0; i < subs_len; i++) { + Gfs_nde sub = nde.Subs_get_at(i); + int path_len_old = path.Len(); + path.Add_byte(Byte_ascii.Dot).Add_int_variable(i); + int path_len_new = path.Len(); + To_str(bfr, path, src, sub); + path.Del_by(path_len_new - path_len_old); + } + } + private void To_str_atr(Bry_bfr bfr, Bry_bfr path_bfr, byte[] src, byte[] name, byte[] val, int val_bgn, int val_end) { + if (val == null && val_bgn == -1 && val_end == -1) return; + bfr.Add_bfr_and_preserve(path_bfr).Add_byte(Byte_ascii.Colon); + bfr.Add(name); + if (val == null) + bfr.Add_mid(src, val_bgn, val_end); + else + bfr.Add(val); + bfr.Add_byte_nl(); + } + private static final byte[] Atr_name = Bry_.new_a7("name="); +} diff --git a/400_xowa/src/gplx/langs/htmls/Gfh_parser_tst.java b/400_xowa/src/gplx/langs/htmls/Gfh_parser_tst.java new file mode 100644 index 000000000..71e8a03fb --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/Gfh_parser_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Gfh_parser_tst { + @Before public void init() {fxt.Clear();} private Gfh_parser_fxt fxt = new Gfh_parser_fxt(); + @Test public void One() {fxt.Test_parse_find_all("", "id0");} + @Test public void Many() {fxt.Test_parse_find_all("", "id0", "id1", "id2");} + @Test public void Inline() {fxt.Test_parse_find_all("", "id0");} + @Test public void Mix() {fxt.Test_parse_find_all("012id=id2345abc", "id0", "id1", "id2");} + @Test public void Quote_double() {fxt.Test_parse_find_all("", "id'0");} + @Test public void Quote_escape() {fxt.Test_parse_find_all("", "id'0");} +} +class Gfh_parser_fxt { + public void Clear() { + if (parser == null) { + parser = new Gfh_parser(); + } + } private Gfh_parser parser; + public Gfh_parser_fxt Test_parse_find_all(String raw_str, String... expd) {return Test_parse_find(raw_str, Gfh_parser.Wildcard_str, Gfh_parser.Wildcard_str, expd);} + public Gfh_parser_fxt Test_parse_find(String raw_str, String find_key, String find_val, String... expd) { + byte[] raw = Bry_.new_a7(raw_str); + Gfh_nde[] actl_ndes = parser.Parse_as_ary(raw, 0, raw.length, Bry_.new_a7(find_key), Bry_.new_a7(find_val)); + String[] actl = Xto_ids(raw, actl_ndes); + Tfds.Eq_ary_str(expd, actl); + return this; + } + private String[] Xto_ids(byte[] src, Gfh_nde[] ary) { + int len = ary.length; + String[] rv = new String[len]; + for (int i = 0; i < len; i++) { + Gfh_nde itm = ary[i]; + String atr_val = itm.Atrs_val_by_key_str("id"); + rv[i] = atr_val; + } + return rv; + } +} diff --git a/400_xowa/src/gplx/langs/htmls/Gfh_utl__basic__tst.java b/400_xowa/src/gplx/langs/htmls/Gfh_utl__basic__tst.java new file mode 100644 index 000000000..6e5367f42 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/Gfh_utl__basic__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Gfh_utl__basic__tst { + @Before public void init() {fxt.Clear();} private Gfh_class_fxt fxt = new Gfh_class_fxt(); + @Test public void Escape() { + fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a present + fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&\"b" , "a<>'&"b"); + } + @Test public void Escape_for_atr_val() { + fxt.Test_escape_for_atr("abc" , Bool_.N, "abc"); // basic + fxt.Test_escape_for_atr("a'\"b" , Bool_.Y, "a'\"b"); // quote is ' + fxt.Test_escape_for_atr("a'\"b" , Bool_.N, "a'"b"); // quote is " + } + @Test public void Unescape() { + fxt.Test_unescape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&"b" , "a<>'&\"b"); // basic + } +} +class Gfh_class_fxt { + private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); + public void Clear() { + tmp_bfr.Clear(); + } + public void Test_del_comments(String src, String expd) { + byte[] actl = Gfh_utl.Del_comments(tmp_bfr, Bry_.new_u8(src)); + Tfds.Eq(expd, String_.new_a7(actl)); + } + public void Test_escape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) { + byte[] actl = Gfh_utl.Escape_html_as_bry(Bry_.new_a7(src), lt, gt, amp, quote, apos); + Tfds.Eq(expd, String_.new_a7(actl)); + } + public void Test_escape_for_atr(String src, boolean quote_is_apos, String expd) { + byte[] actl = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? Byte_ascii.Apos : Byte_ascii.Quote, src); + Tfds.Eq(expd, String_.new_u8(actl)); + } + public void Test_unescape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) { + byte[] bry = Bry_.new_u8(src); + byte[] actl = Gfh_utl.Unescape(false, tmp_bfr, bry, 0, bry.length, lt, gt, amp, quote, apos); + Tfds.Eq(expd, String_.new_a7(actl)); + } +} diff --git a/400_xowa/src/gplx/langs/htmls/Gfh_utl__comments__tst.java b/400_xowa/src/gplx/langs/htmls/Gfh_utl__comments__tst.java new file mode 100644 index 000000000..35eca35c6 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/Gfh_utl__comments__tst.java @@ -0,0 +1,24 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Gfh_utl__comments__tst { + @Before public void init() {fxt.Clear();} private final Gfh_class_fxt fxt = new Gfh_class_fxt(); + @Test public void Basic() {fxt.Test_del_comments("ac" , "ac");} + @Test public void Bgn_missing() {fxt.Test_del_comments("a b c" , "a b c");} + @Test public void End_missing() {fxt.Test_del_comments("ace" , "ace");} +} diff --git a/400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java b/400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java new file mode 100644 index 000000000..357d21500 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/clses/Gfh_class__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; +import org.junit.*; +public class Gfh_class__tst { + private final Gfh_class__fxt fxt = new Gfh_class__fxt(); + @Test public void Has() { + fxt.Test__has__y("a b c", "a", "b", "c"); + fxt.Test__has__n("a b c", "d"); + fxt.Test__has__n("ab", "a"); + } + @Test public void Cls__has__hash() { + Hash_adp_bry hash = fxt.Make_hash("x", "y", "z"); + fxt.Test__find_1st(hash, 0, "x"); + fxt.Test__find_1st(hash, 2, "z"); + fxt.Test__find_1st(hash, 0, "a x b"); + fxt.Test__find_1st(hash, 0, "a b x"); + fxt.Test__find_1st(hash, Byte_.Max_value_127, "a"); + fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz"); + } +} +class Gfh_class__fxt { + public void Test__has__y(String src, String... ary) {Test__has(Bool_.Y, src, ary);} + public void Test__has__n(String src, String... ary) {Test__has(Bool_.N, src, ary);} + public void Test__has(boolean expd, String src, String... ary) { + byte[] src_bry = Bry_.new_u8(src); + for (String itm : ary) { + byte[] itm_bry = Bry_.new_u8(itm); + Tfds.Eq_bool(expd, Gfh_class_.Has(src_bry, 0, src_bry.length, itm_bry), itm); + } + } + public Hash_adp_bry Make_hash(String... ary) { + Hash_adp_bry rv = Hash_adp_bry.ci_a7(); + int len = ary.length; + for (int i = 0; i < len; ++i) + rv.Add_bry_byte(Bry_.new_u8(ary[i]), (byte)i); + return rv; + } + public void Test__find_1st(Hash_adp_bry hash, int expd, String src) { + byte[] src_bry = Bry_.new_u8(src); + Tfds.Eq_byte((byte)expd, Gfh_class_.Find_1st(src_bry, 0, src_bry.length, hash), src); + } +} diff --git a/400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser__tst.java b/400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser__tst.java new file mode 100644 index 000000000..baf24b949 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/clses/Gfh_class_parser__tst.java @@ -0,0 +1,42 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; +import org.junit.*; +public class Gfh_class_parser__tst { + private final Gfh_class_parser__fxt fxt = new Gfh_class_parser__fxt(); + @Test public void Basic() {fxt.Test__parse("v1" , "v1");} + @Test public void Many() {fxt.Test__parse("v1 v2" , "v1", "v2");} +} +class Gfh_class_parser__fxt { + private final Gfh_class_wkr__list wkr = new Gfh_class_wkr__list(); + public void Test__parse(String src_str, String... expd) { + byte[] src_bry = Bry_.new_u8(src_str); + String[] actl = wkr.Parse(src_bry, 0, src_bry.length); + Tfds.Eq_ary_str(expd, actl); + } +} +class Gfh_class_wkr__list implements Gfh_class_parser_wkr { + private final List_adp list = List_adp_.New(); + public boolean On_cls(byte[] src, int atr_idx, int atr_bgn, int atr_end, int val_bgn, int val_end) { + String s = String_.new_u8(src, val_bgn, val_end); + list.Add(s); // + return true; + } + public String[] Parse(byte[] src, int src_bgn, int src_end) { + Gfh_class_parser_.Parse(src, src_bgn, src_end, this); + return (String[])list.To_ary_and_clear(String.class); + } +} diff --git a/400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java b/400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java new file mode 100644 index 000000000..9d60046c3 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/docs/Gfh_tag_rdr_tst.java @@ -0,0 +1,78 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; +import org.junit.*; +public class Gfh_tag_rdr_tst { + private final Gfh_tag_rdr_fxt fxt = new Gfh_tag_rdr_fxt(); + @Test public void Basic() { + fxt.Init("1
2
3
4
5
6
7"); + fxt.Test__move_fwd_head("
"); fxt.Test__pos("2"); + fxt.Test__peek_fwd_head("
"); fxt.Test__pos("2"); + fxt.Test__move_fwd_head("
"); fxt.Test__pos("4"); + fxt.Test__peek_bwd_tail("
3") ; fxt.Test__pos("4"); + } + @Test public void Comment() { + fxt.Init("135
6
"); + fxt.Test__move_fwd_head(Gfh_tag_.Id__any , "
") ; fxt.Test__pos("6"); + } + @Test public void Meta() { + fxt.Init("1
2
3"); + fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "
") ; fxt.Test__pos("2"); + } + @Test public void Recursive__same_tags() { + fxt.Init("12345"); + fxt.Test__move_fwd_head(Gfh_tag_.Id__a , "") ; fxt.Test__pos("2"); + fxt.Test__move_fwd_tail(Gfh_tag_.Id__a , "") ; fxt.Test__pos("5"); + } + @Test public void Recursive__diff_tags() { + fxt.Init("1
2345
6"); + fxt.Test__move_fwd_head(Gfh_tag_.Id__div , "
") ; fxt.Test__pos("2"); + fxt.Test__move_fwd_tail(Gfh_tag_.Id__div , "
") ; fxt.Test__pos("6"); + } + @Test public void Inline() { + fxt.Init("1
2"); + fxt.Test__move_fwd_head(Gfh_tag_.Id__br , "
") ; fxt.Test__pos("2"); + } +} +class Gfh_tag_rdr_fxt { + private final Gfh_tag_rdr rdr = Gfh_tag_rdr.New__html(); + public void Init(String src_str) { + byte[] src_bry = Bry_.new_u8(src_str); + rdr.Init(Bry_.Empty, src_bry, 0, src_bry.length); + } + public void Test__move_fwd_head(String expd) {Test__move_fwd_head(Gfh_tag_.Id__any, expd);} + public void Test__move_fwd_head(int match_name_id, String expd) { + Gfh_tag actl_tag = rdr.Tag__move_fwd_head(match_name_id).Chk_name_or_fail(match_name_id); + Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end())); + } + public void Test__move_fwd_tail(int match_name_id, String expd) { + Gfh_tag actl_tag = rdr.Tag__move_fwd_tail(match_name_id); + Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end())); + } + public void Test__peek_fwd_head(String expd) { + Gfh_tag actl_tag = rdr.Tag__peek_fwd_head(); + Tfds.Eq_str(expd, String_.new_u8(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_end())); + } + public void Test__peek_bwd_tail(String expd_str) { + byte[] expd_bry = Bry_.new_u8(expd_str); + Gfh_tag actl_tag = rdr.Tag__peek_bwd_tail(-1); + Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), actl_tag.Src_bgn(), actl_tag.Src_bgn() + expd_bry.length)); + } + public void Test__pos(String expd_str) { + byte[] expd_bry = Bry_.new_u8(expd_str); + Tfds.Eq_bry(expd_bry, Bry_.Mid(rdr.Src(), rdr.Pos(), rdr.Pos() + expd_bry.length)); + } +} diff --git a/400_xowa/src/gplx/langs/htmls/encoders/Gfo_url_encoder_tst.java b/400_xowa/src/gplx/langs/htmls/encoders/Gfo_url_encoder_tst.java new file mode 100644 index 000000000..f5ce933d4 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/encoders/Gfo_url_encoder_tst.java @@ -0,0 +1,69 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; +import org.junit.*; +public class Gfo_url_encoder_tst { + private final Gfo_url_encoder_fxt fxt = new Gfo_url_encoder_fxt(); + @Test public void Id__nums() {fxt.Encoder_id().Test__bicode("0123456789" , "0123456789");} + @Test public void Id__ltrs_lower() {fxt.Encoder_id().Test__bicode("abcdefghijklmnopqrstuvwxyz" , "abcdefghijklmnopqrstuvwxyz");} + @Test public void Id__ltrs_upper() {fxt.Encoder_id().Test__bicode("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , "ABCDEFGHIJKLMNOPQRSTUVWXYZ");} + @Test public void Id__syms() {fxt.Encoder_id().Test__encode("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ".21.22.23.24.25.26.27.28.29.2A.2B.2C-..2F:.3B.3C.3D.3E.3F.40.5B.5C.5D.5E_.60.7B.7C.7D.7E");} // NOTE: not reversible since "." is encode_marker but not encoded + @Test public void Id__foreign() {fxt.Encoder_id().Test__bicode("aéb", "a.C3.A9b");} + @Test public void Id__nbsp() {fxt.Encoder_id().Test__encode("a b", "a.C2.A0b");} // NOTE: not just .A0 (160) but utf8-encoded .C2.A0 + @Test public void Id__space() {fxt.Encoder_id().Test__bicode("a b", "a_b");} + @Test public void Id__err() { + byte[] raw = Bry_.new_a7("0%.jpg"); + Bry_bfr tmp_bfr = Bry_bfr_.New(); + fxt.Encoder_id().Encoder().Decode(tmp_bfr, Bool_.N, raw, 0, raw.length); + Tfds.Eq("0%.jpg", tmp_bfr.To_str_and_clear()); + } + @Test public void Ttl__syms__diff() {fxt.Encoder_ttl().Test__encode(" &'=+", "_%26%27%3D%2B");} + @Test public void Ttl__syms__same() {fxt.Encoder_ttl().Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");} + @Test public void Url__syms() {fxt.Encoder_url().Test__bicode("!?^~", "%21%3F%5E%7E");} + @Test public void Url__foreign() {fxt.Encoder_url().Test__bicode("aéb", "a%C3%A9b");} + @Test public void Url__space() {fxt.Encoder_url().Test__bicode("a b", "a+b");} + @Test public void Href__space() { + fxt.Encoder_href().Test__encode("a b", "a_b"); + } + @Test public void Href__special_and_anchor() { // PURPOSE: MediaWiki encodes with % for ttls, but . for anchors; REF:Title.php!(before-anchor)getLocalUrl;wfUrlencode (after-anchor)escapeFragmentForURL + fxt.Encoder_href().Test__bicode("^#^", "%5E#.5E"); + fxt.Encoder_href().Test__encode("A#", "A#"); + } + @Test public void Href__invalid() { // PURPOSE: check that invalid url decodings are rendered literally; DATE:2014-04-10 + fxt.Encoder_href().Test__encode("%GC", "%25GC"); + } + @Test public void Fsys__wnt() { + fxt.Encoder_fsys_safe().Test__encode("Options/HTML", "Options%2FHTML"); + } +} +class Gfo_url_encoder_fxt { + public Gfo_url_encoder Encoder() {return encoder;} private Gfo_url_encoder encoder; + public Gfo_url_encoder_fxt Encoder_id() {encoder = Gfo_url_encoder_.Id; return this;} + public Gfo_url_encoder_fxt Encoder_href() {encoder = Gfo_url_encoder_.Href; return this;} + public Gfo_url_encoder_fxt Encoder_url() {encoder = Gfo_url_encoder_.Http_url; return this;} + public Gfo_url_encoder_fxt Encoder_ttl() {encoder = Gfo_url_encoder_.Mw_ttl; return this;} + public Gfo_url_encoder_fxt Encoder_fsys_safe() {encoder = Gfo_url_encoder_.New__fsys_wnt().Make(); return this;} + public void Test__bicode(String raw, String encoded) { + Test__encode(raw, encoded); + Test__decode(encoded, raw); + } + public void Test__encode(String raw, String expd) { + Tfds.Eq(expd, String_.new_u8(encoder.Encode(Bry_.new_u8(raw)))); + } + public void Test__decode(String raw, String expd) { + Tfds.Eq(expd, String_.new_u8(encoder.Decode(Bry_.new_u8(raw)))); + } +} diff --git a/400_xowa/src/gplx/langs/htmls/styles/Gfh_style_parser__tst.java b/400_xowa/src/gplx/langs/htmls/styles/Gfh_style_parser__tst.java new file mode 100644 index 000000000..a464ab249 --- /dev/null +++ b/400_xowa/src/gplx/langs/htmls/styles/Gfh_style_parser__tst.java @@ -0,0 +1,49 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; +import org.junit.*; +public class Gfh_style_parser__tst { + private final Gfh_style_parser__fxt fxt = new Gfh_style_parser__fxt(); + @Test public void Basic() { + fxt.Test__parse("k_0:v_0" , fxt.Make("k_0", "v_0")); + fxt.Test__parse("k_0:v_0;" , fxt.Make("k_0", "v_0")); + fxt.Test__parse("k_0:v_0;k_1:v_1" , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1")); + } + @Test public void Ws() { + fxt.Test__parse(" k_0 : v_0 ;" , fxt.Make("k_0", "v_0")); + fxt.Test__parse(" k_0 : v_0 ; k_1 : v_1 " , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1")); + fxt.Test__parse(" k_0 : v 0 ;" , fxt.Make("k_0", "v 0")); + } + @Test public void Empty() { + fxt.Test__parse("k_0:v_0;;" , fxt.Make("k_0", "v_0")); + fxt.Test__parse("k_0:v_0; ; " , fxt.Make("k_0", "v_0")); + } + @Test public void Invalid__no_semic() { + fxt.Test__parse("k_0" , fxt.Make("k_0", "")); + } + @Test public void Invalid__dupe_colon() { + fxt.Test__parse("a:b:c:d;" , fxt.Make("a", "b:c:d")); + } +} +class Gfh_style_parser__fxt { + private final Gfh_style_wkr__ary wkr = new Gfh_style_wkr__ary(); + public Gfh_style_itm Make(String k, String v) {return new Gfh_style_itm(-1, Bry_.new_u8(k), Bry_.new_u8(v));} + public void Test__parse(String src_str, Gfh_style_itm... expd) { + byte[] src_bry = Bry_.new_u8(src_str); + Gfh_style_itm[] actl = wkr.Parse(src_bry, 0, src_bry.length); + Tfds.Eq_ary_str(expd, actl); + } +} diff --git a/400_xowa/src/gplx/langs/jsons/Json_doc_tst.java b/400_xowa/src/gplx/langs/jsons/Json_doc_tst.java new file mode 100644 index 000000000..cf12db714 --- /dev/null +++ b/400_xowa/src/gplx/langs/jsons/Json_doc_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.jsons; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Json_doc_tst { + private final Json_qry_mgr_fxt fxt = new Json_qry_mgr_fxt(); + @Test public void Select() { + Json_doc doc = fxt.Make_json + ( "{'0':" + , " {'0_0':" + , " {'0_0_0':'000'" + , " }," + , " '0_1':" + , " {'0_1_0':'010'" + , " }" + , " }" + , "}" + ); + fxt.Test_get_val_as_str(doc, "0/0_0/0_0_0", "000"); + fxt.Test_get_val_as_str(doc, "0/0_1/0_1_0", "010"); + fxt.Test_get_val_as_str(doc, "x", null); + } +} +class Json_qry_mgr_fxt { + private final Json_parser json_parser = new Json_parser(); + public Json_doc Make_json(String... ary) {return json_parser.Parse_by_apos_ary(ary);} + public void Test_get_val_as_str(Json_doc doc, String qry, String expd){ + byte[][] qry_bry = Bry_split_.Split(Bry_.new_u8(qry), Byte_ascii.Slash); + Tfds.Eq(expd, doc.Get_val_as_str_or(qry_bry, null)); + } +} diff --git a/400_xowa/src/gplx/langs/jsons/Json_kv_ary_srl_tst.java b/400_xowa/src/gplx/langs/jsons/Json_kv_ary_srl_tst.java new file mode 100644 index 000000000..8e553e078 --- /dev/null +++ b/400_xowa/src/gplx/langs/jsons/Json_kv_ary_srl_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.jsons; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Json_kv_ary_srl_tst { + @Before public void init() {fxt.Clear();} private Json_kv_ary_srl_fxt fxt = new Json_kv_ary_srl_fxt(); + @Test public void Null() {fxt.Test_parse("{'k0':null}" , fxt.ary_(fxt.kv_str_("k0", null)));} + @Test public void Bool_n() {fxt.Test_parse("{'k0':false}" , fxt.ary_(fxt.kv_bool_("k0", false)));} + @Test public void Num() {fxt.Test_parse("{'k0':123}" , fxt.ary_(fxt.kv_int_("k0", 123)));} + @Test public void Str() {fxt.Test_parse("{'k0':'v0'}" , fxt.ary_(fxt.kv_str_("k0", "v0")));} + @Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.kv_dec_("k0", Decimal_adp_.parse("1.23"))));} + @Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("1", 1), fxt.kv_int_("2", 2), fxt.kv_int_("3", 3)))));} + @Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));} + @Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1,'k01':2}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("k00", 1), fxt.kv_int_("k01", 2)))));} + @Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));} +} +class Json_kv_ary_srl_fxt { + public void Clear() { + if (parser == null) { + parser = new Json_parser(); + } + } private Json_parser parser; + public void Test_parse(String raw_str, Keyval[] expd) { + byte[] raw_bry = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str)); + Json_doc doc = parser.Parse(raw_bry); + Keyval[] actl = Json_kv_ary_srl.Val_by_itm_nde(doc.Root_nde()); + Tfds.Eq_str_lines(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl)); + } + public Keyval[] ary_(Keyval... ary) {return ary;} + public Keyval kv_obj_(String key, Object val) {return Keyval_.new_(key, val);} + public Keyval kv_str_(String key, String val) {return Keyval_.new_(key, val);} + public Keyval kv_int_(String key, int val) {return Keyval_.new_(key, val);} + public Keyval kv_bool_(String key, boolean val) {return Keyval_.new_(key, Bool_.To_str_lower(val));} + public Keyval kv_dec_(String key, Decimal_adp val) {return Keyval_.new_(key, val.To_str());} +} diff --git a/400_xowa/src/gplx/langs/jsons/Json_parser_tst.java b/400_xowa/src/gplx/langs/jsons/Json_parser_tst.java new file mode 100644 index 000000000..51874a6a6 --- /dev/null +++ b/400_xowa/src/gplx/langs/jsons/Json_parser_tst.java @@ -0,0 +1,98 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.jsons; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Json_parser_tst { + private final Json_parser_fxt fxt = new Json_parser_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Null() {fxt.Test_parse_val0("{'k0':null}" , null);} + @Test public void Bool_n() {fxt.Test_parse_val0("{'k0':false}" , false);} + @Test public void Bool_y() {fxt.Test_parse_val0("{'k0':true}" , true);} + @Test public void Num() {fxt.Test_parse_val0("{'k0':123}" , 123);} + @Test public void Num_neg() {fxt.Test_parse_val0("{'k0':-123}" , -123);} + @Test public void Str() {fxt.Test_parse_val0("{'k0':'v0'}" , "v0");} + @Test public void Str_esc_quote() {fxt.Test_parse_val0("{'k0':'a\\\"b'}" , "a\"b");} + @Test public void Str_esc_hex4() {fxt.Test_parse_val0("{'k0':'a\\u0021b'}" , "a!b");} + @Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1.23")));} + @Test public void Num_exp() {fxt.Test_parse("{'k0':1e+2}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "1e+2")));} + @Test public void Num_mix() {fxt.Test_parse("{'k0':-1.23e-1}" , fxt.itm_nde_().Add_many(fxt.itm_kv_dec_("k0", "-1.23e-1")));} + @Test public void Str_many() {fxt.Test_parse("{'k0':'v0','k1':'v1','k2':'v2'}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0"), fxt.itm_kv_("k1", "v1"), fxt.itm_kv_("k2", "v2")));} + @Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0")));} + @Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));} + @Test public void Ary_str() {fxt.Test_parse("{'k0':['a','b','c']}", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_str_("k0", "a", "b", "c")));} + @Test public void Ary_ws() {fxt.Test_parse("{'k0': [ 1 , 2 , 3 ] }", fxt.itm_nde_().Add_many(fxt.itm_kv_ary_int_("k0", 1, 2, 3)));} + @Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));} + @Test public void Subs_empty() {fxt.Test_parse("{'k0':{}}", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_())));} + @Test public void Subs_ws() {fxt.Test_parse("{'k0': { 'k00' : 1 } }", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", fxt.itm_nde_().Add_many(fxt.itm_kv_("k00", 1)))));} + @Test public void Ws() {fxt.Test_parse(" { 'k0' : 'v0' } ", fxt.itm_nde_().Add_many(fxt.itm_kv_("k0", "v0")));} + @Test public void Root_is_ary() {fxt.Test_parse("[ 1 , 2 , 3 ]", fxt.itm_ary_().Add_many(fxt.itm_int_(1), fxt.itm_int_(2), fxt.itm_int_(3)));} + public static String Replace_apos_as_str(String v) {return String_.new_u8(Replace_apos(Bry_.new_u8(v)));} + public static byte[] Replace_apos(byte[] v) {return Bry_.Replace(v, Byte_ascii.Apos, Byte_ascii.Quote);} +} +class Json_parser_fxt { + public void Clear() { + if (parser == null) { + parser = new Json_parser(); + factory = parser.Factory(); + } + } Json_parser parser; Json_factory factory; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); + public Json_itm itm_int_(int v) {return Json_itm_tmp.new_int_(v);} + Json_itm itm_str_(String v) {return Json_itm_tmp.new_str_(v);} + public Json_ary itm_ary_() {return factory.Ary(-1, -1);} + public Json_nde itm_nde_() {return factory.Nde(null, -1);} + public Json_kv itm_kv_null_(String k) {return factory.Kv(itm_str_(k), factory.Null());} + public Json_kv itm_kv_(String k, String v) {return factory.Kv(itm_str_(k), itm_str_(v));} + public Json_kv itm_kv_(String k, int v) {return factory.Kv(itm_str_(k), itm_int_(v));} + public Json_kv itm_kv_(String k, boolean v) {return factory.Kv(itm_str_(k), v ? factory.Bool_y() : factory.Bool_n());} + public Json_kv itm_kv_dec_(String k, String v) {return factory.Kv(itm_str_(k), new Json_itm_tmp(Json_itm_.Tid__decimal, v));} + public Json_kv itm_kv_(String k, Json_nde v) {return factory.Kv(itm_str_(k), v);} + public Json_kv itm_kv_ary_int_(String k, int... v) { + Json_ary ary = factory.Ary(-1, -1); + int len = v.length; + for (int i = 0; i < len; i++) + ary.Add(itm_int_(v[i])); + return factory.Kv(itm_str_(k), ary); + } + public Json_kv itm_kv_ary_str_(String k, String... v) { + Json_ary ary = factory.Ary(-1, -1); + int len = v.length; + for (int i = 0; i < len; i++) + ary.Add(itm_str_(v[i])); + return factory.Kv(itm_str_(k), ary); + } + public void Test_parse(String raw_str, Json_itm... expd_ary) { + byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str)); + Json_doc doc = parser.Parse(raw); + doc.Root_grp().Print_as_json(tmp_bfr, 0); + String actl = tmp_bfr.To_str_and_clear(); + String expd = Xto_str(raw, doc, expd_ary, 0, expd_ary.length); + Tfds.Eq_str_lines(expd, actl, actl); + } + public void Test_parse_val0(String raw_str, Object expd) { + byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str)); + Json_doc doc = parser.Parse(raw); + Json_kv kv = Json_kv.cast(doc.Root_nde().Get_at(0)); // assume root has kv as first sub; EX: {"a":"b"} + Object actl = kv.Val().Data(); // NOTE: Data_bry is escaped val; EX: a\"b has DataBry of a"b + Tfds.Eq(expd, actl); + } + String Xto_str(byte[] raw, Json_doc doc, Json_itm[] ary, int bgn, int end) { + for (int i = bgn; i < end; i++) { + Json_itm itm = ary[i]; + itm.Print_as_json(tmp_bfr, 0); + } + return tmp_bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/langs/jsons/Json_printer_tst.java b/400_xowa/src/gplx/langs/jsons/Json_printer_tst.java new file mode 100644 index 000000000..a24c54a3e --- /dev/null +++ b/400_xowa/src/gplx/langs/jsons/Json_printer_tst.java @@ -0,0 +1,86 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.jsons; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Json_printer_tst { + private final Json_printer_fxt fxt = new Json_printer_fxt(); + @Test public void Root_nde() { + fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':'v1','k2':'v2'}"), String_.Concat_lines_nl + ( "{ 'k1':'v1'" + , ", 'k2':'v2'" + , "}" + )); + } + @Test public void Root_ary() { + fxt.Test_print(Json_doc.Make_str_by_apos("[1,2,3]"), String_.Concat_lines_nl + ( "[ 1" + , ", 2" + , ", 3" + , "]" + )); + } + @Test public void Ary_w_ary() { + fxt.Test_print(Json_doc.Make_str_by_apos("[[1,2],[3,4]]"), String_.Concat_lines_nl + ( "[ " + , " [ 1" + , " , 2" + , " ]" + , ", " + , " [ 3" + , " , 4" + , " ]" + , "]" + )); + } + @Test public void Ary_w_nde() { + fxt.Test_print(Json_doc.Make_str_by_apos("[{'k1':'v1','k2':'v2'},{'k3':'v3','k4':'v4'}]"), String_.Concat_lines_nl + ( "[ " + , " { 'k1':'v1'" + , " , 'k2':'v2'" + , " }" + , ", " + , " { 'k3':'v3'" + , " , 'k4':'v4'" + , " }" + , "]" + )); + } + @Test public void Nde_w_ary() { + fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':[1,2],'k2':[3,4]}"), String_.Concat_lines_nl + ( "{ 'k1':" + , " [ 1" + , " , 2" + , " ]" + , ", 'k2':" + , " [ 3" + , " , 4" + , " ]" + , "}" + )); + } +// @Test public void Smoke() { +// Json_printer printer = new Json_printer(); +// String url = "C:\\temp.json"; +// String s = printer.Pretty_print_as_str(Bry_.new_u8(Io_mgr.Instance.LoadFilStr(url))); +// Io_mgr.Instance.SaveFilStr(url, s); +// } +} +class Json_printer_fxt { + private final Json_printer printer = new Json_printer().Opt_quote_byte_(Byte_ascii.Apos); + public void Test_print(String raw, String expd) { + Tfds.Eq_str_lines(expd, printer.Print_by_bry(Bry_.new_u8(raw)).To_str()); + } +} diff --git a/400_xowa/src/gplx/langs/jsons/Json_wtr_tst.java b/400_xowa/src/gplx/langs/jsons/Json_wtr_tst.java new file mode 100644 index 000000000..a5f630ff6 --- /dev/null +++ b/400_xowa/src/gplx/langs/jsons/Json_wtr_tst.java @@ -0,0 +1,132 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.jsons; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Json_wtr_tst { + @Before public void init() {fxt.Clear();} private final Json_wtr_fxt fxt = new Json_wtr_fxt(); + @Test public void Root() { + fxt.Wtr().Doc_nde_bgn().Doc_nde_end(); + fxt.Test + ( "{" + , "}" + ); + } + @Test public void Kv() { + fxt.Wtr() + .Doc_nde_bgn() + .Kv_str("k0", "v0") + .Kv_str("k1", "v1") + .Doc_nde_end(); + fxt.Test + ( "{ 'k0':'v0'" + , ", 'k1':'v1'" + , "}" + ); + } + @Test public void Escaped() { + fxt.Wtr() + .Doc_nde_bgn() + .Kv_str("backslash", "\\") + .Kv_str("quote", "\"") + .Kv_str("apos", "'") + .Kv_str("nl", "\n") + .Kv_str("cr", "\r") + .Kv_str("tab", "\t") + .Doc_nde_end(); + fxt.Test + ( "{ 'backslash':'\\\\'" + , ", 'quote':'\\\"'" + , ", 'apos':'\''" + , ", 'nl':'\\\\n'" + , ", 'cr':'\\\\r'" + , ", 'tab':'\\\\t'" + , "}" + ); + } + @Test public void Nde() { + fxt.Wtr() + .Doc_nde_bgn() + .Nde_bgn("s0") + .Nde_bgn("s00") + .Nde_end() + .Nde_end() + .Nde_bgn("s1") + .Nde_bgn("s10") + .Nde_end() + .Nde_end() + .Doc_nde_end(); + fxt.Test + ( "{ 's0':" + , " { 's00':" + , " {" + , " }" + , " }" + , ", 's1':" + , " { 's10':" + , " {" + , " }" + , " }" + , "}" + ); + } + @Test public void Ary() { + fxt.Wtr() + .Doc_nde_bgn() + .Ary_bgn("a0") + .Ary_itm_str("v0") + .Ary_itm_str("v1") + .Ary_end() + .Doc_nde_end(); + fxt.Test + ( "{ 'a0':" + , " [ 'v0'" + , " , 'v1'" + , " ]" + , "}" + ); + } + @Test public void Nde__nested() { + fxt.Wtr() + .Doc_nde_bgn() + .Ary_bgn("a0") + .Ary_itm_obj(Keyval_.Ary + ( Keyval_.new_("k1", "v1") + , Keyval_.new_("k2", "v2") + )) + .Ary_end() + .Doc_nde_end(); + fxt.Test + ( "{ 'a0':" + , " [" + , " { 'k1':'v1'" + , " , 'k2':'v2'" + , " }" + , " ]" + , "}" + ); + } +} +class Json_wtr_fxt { + private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos); + public void Clear() {wtr.Clear();} + public Json_wtr Wtr() {return wtr;} + public void Test(String... expd) { + Tfds.Eq_ary_str + ( String_.Ary_add(expd, String_.Ary("")) // json_wtr always ends with "}\n"; rather than add "\n" to each test, just add it here + , String_.SplitLines_nl(String_.new_u8(wtr.To_bry_and_clear())) + ); + } +} diff --git a/400_xowa/src/gplx/langs/mustaches/Mustache_itm_render_tst.java b/400_xowa/src/gplx/langs/mustaches/Mustache_itm_render_tst.java new file mode 100644 index 000000000..3119a132e --- /dev/null +++ b/400_xowa/src/gplx/langs/mustaches/Mustache_itm_render_tst.java @@ -0,0 +1,162 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.mustaches; import gplx.*; import gplx.langs.*; +import org.junit.*; import gplx.core.primitives.*; +public class Mustache_itm_render_tst { + private final Mustache_itm_render_fxt fxt = new Mustache_itm_render_fxt(); + @Test public void Text() { + fxt.Test__parse("a b c", "a b c"); + } + @Test public void Variable() { + fxt.Init__root(fxt.Make_mock(0).Add_prop("prop1", "1").Add_prop("prop2", "2")); + fxt.Test__parse("{{prop1}}", "1"); + fxt.Test__parse("a{{prop1}}b{{prop2}}c", "a1b2c"); + } + @Test public void Escape() { + fxt.Init__root(fxt.Make_mock(0).Add_prop("prop1", "<")); + fxt.Test__parse("{{{prop1}}}", "<"); + fxt.Test__parse("{{prop1}}", "<"); + } + @Test public void Section_bool() { + fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y").Add_bool_n("bool_n")); + fxt.Test__parse("a{{#bool_y}}b{{/bool_y}}c", "abc"); + fxt.Test__parse("a{{#bool_n}}b{{/bool_n}}c", "ac"); + fxt.Test__parse("a{{#bool_y}}b{{/bool_y}}c{{#bool_n}}d{{/bool_n}}e", "abce"); + } + @Test public void Section_not() { + fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y").Add_bool_n("bool_n")); + fxt.Test__parse("a{{^bool_y}}b{{/bool_y}}c", "ac"); + fxt.Test__parse("a{{^bool_n}}b{{/bool_n}}c", "abc"); + fxt.Test__parse("a{{^bool_y}}b{{/bool_y}}c{{^bool_n}}d{{/bool_n}}e", "acde"); + } + @Test public void Section_ws() { + fxt.Init__root(fxt.Make_mock(0).Add_bool_y("bool_y")); + fxt.Test__parse("a\n {{#bool_y}} \nb\n {{/bool_y}} \nc", "a\nb\nc"); + } + @Test public void Section_subs_flat() { + fxt.Init__root(fxt.Make_mock(0).Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "1").Add_subs("subs2") + , fxt.Make_mock(2).Add_prop("prop1", "2").Add_subs("subs2") + )); + fxt.Test__parse("a{{#subs1}}({{prop1}}){{/subs1}}d", "a(1)(2)d"); + } + @Test public void Section_subs_nest_1() { + fxt.Init__root + ( fxt.Make_mock(0).Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2" + , fxt.Make_mock(11).Add_prop("prop2", "1") + , fxt.Make_mock(12).Add_prop("prop2", "2")) + )); + fxt.Test__parse + ( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{/subs1}}" + , "a12" + ); + } + @Test public void Section_subs_nest_2() { + fxt.Init__root + ( fxt.Make_mock(0).Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2" + , fxt.Make_mock(11).Add_prop("prop2", "1") + , fxt.Make_mock(12).Add_prop("prop2", "2") + ) + , fxt.Make_mock(2).Add_prop("prop1", "b") + ) + ); + fxt.Test__parse + ( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{/subs1}}" + , "a12b" + ); + } + @Test public void Section_subs_nest_3() { + fxt.Init__root + ( fxt.Make_mock(0).Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2" + , fxt.Make_mock(11).Add_prop("prop2", "1") + , fxt.Make_mock(12).Add_prop("prop2", "2") + ) + , fxt.Make_mock(2).Add_prop("prop1", "b").Add_subs("subs2" + , fxt.Make_mock(21).Add_prop("prop2", "3") + , fxt.Make_mock(22).Add_prop("prop2", "4") + ) + ) + ); + fxt.Test__parse + ( "{{#subs1}}{{prop1}}{{#subs2}}{{prop2}}{{/subs2}}{{prop1}}{{/subs1}}" + , "a12ab34b" + ); + } + @Test public void Section_bool_subs() { // handle prop written after boolean; should not pick up inner prop + fxt.Init__root + ( fxt.Make_mock(0).Add_bool_y("bool1").Add_prop("prop2", "2").Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "11") + , fxt.Make_mock(2).Add_prop("prop1", "12") + )); + fxt.Test__parse + ( "a{{#bool1}}b{{#subs1}}c{{prop1}}d{{/subs1}}e{{/bool1}}f{{prop2}}g" + , "abc11dc12def2g" + ); + } + @Test public void Section_owner() { + fxt.Init__root + ( fxt.Make_mock(0).Add_subs("subs1" + , fxt.Make_mock(1).Add_prop("prop1", "a").Add_subs("subs2" + , fxt.Make_mock(11).Add_prop("prop2", "1") + ) + )); + fxt.Test__parse + ( "{{#subs1}}{{#subs2}}{{prop1}}{{prop2}}{{/subs2}}{{/subs1}}" // prop1 is cited in subs2, but value belongs to subs1 + , "a1" + ); + } +} +class Mustache_itm_render_fxt { + private final Mustache_tkn_parser parser = new Mustache_tkn_parser(); + private final Mustache_render_ctx ctx = new Mustache_render_ctx(); + private final Mustache_bfr bfr = Mustache_bfr.New(); + private Mustache_doc_itm__mock root; + public Mustache_doc_itm__mock Make_mock(int id) {return new Mustache_doc_itm__mock(id);} + public void Init__root(Mustache_doc_itm__mock v) {this.root = v;} + public void Test__parse(String src_str, String expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Mustache_tkn_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length); + ctx.Init(root); + actl_itm.Render(bfr, ctx); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} +class Mustache_doc_itm__mock implements Mustache_doc_itm { + private final Hash_adp hash_prop = Hash_adp_.New(), hash_bool = Hash_adp_.New(), hash_subs = Hash_adp_.New(); + public Mustache_doc_itm__mock(int id) {this.id = id;} + public int id; + public Mustache_doc_itm__mock Add_prop(String key, String val) {hash_prop.Add(key, Bry_.new_u8(val)); return this;} + public Mustache_doc_itm__mock Add_bool_y(String key) {hash_bool.Add(key, Bool_obj_ref.y_()); return this;} + public Mustache_doc_itm__mock Add_bool_n(String key) {hash_bool.Add(key, Bool_obj_ref.n_()); return this;} + public Mustache_doc_itm__mock Add_subs(String key, Mustache_doc_itm__mock... ary) {hash_subs.Add(key, ary); return this;} + public boolean Mustache__write(String key, Mustache_bfr bfr) { + byte[] rv = (byte[])hash_prop.Get_by(key); + if (rv == null) return false; + bfr.Add_bry(rv); + return true; + } + public Mustache_doc_itm[] Mustache__subs(String key) { + Object rv = hash_bool.Get_by(key); + if (rv != null) { + boolean bool_val = ((Bool_obj_ref)rv).Val(); + return bool_val ? Mustache_doc_itm_.Ary__bool__y : Mustache_doc_itm_.Ary__bool__n; + } + return (Mustache_doc_itm__mock[])hash_subs.Get_by(key); + } +} diff --git a/400_xowa/src/gplx/langs/mustaches/Mustache_tkn_parser_tst.java b/400_xowa/src/gplx/langs/mustaches/Mustache_tkn_parser_tst.java new file mode 100644 index 000000000..8649051f8 --- /dev/null +++ b/400_xowa/src/gplx/langs/mustaches/Mustache_tkn_parser_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.mustaches; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Mustache_tkn_parser_tst { + private final Mustache_tkn_parser_fxt fxt = new Mustache_tkn_parser_fxt(); + @Test public void Basic() { + fxt.Test_parse("a{{b}}c", "ac"); + } + @Test public void Comment() { + fxt.Test_parse("a{{!b}}c", "ac"); + } +} +class Mustache_tkn_parser_fxt { + private final Mustache_tkn_parser parser = new Mustache_tkn_parser(); + private final Mustache_render_ctx ctx = new Mustache_render_ctx(); + private final Mustache_bfr bfr = Mustache_bfr.New(); + public void Test_parse(String src_str, String expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Mustache_tkn_itm actl_itm = parser.Parse(src_bry, 0, src_bry.length); + actl_itm.Render(bfr, ctx); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/langs/phps/Php_parser_fxt.java b/400_xowa/src/gplx/langs/phps/Php_parser_fxt.java new file mode 100644 index 000000000..e91276415 --- /dev/null +++ b/400_xowa/src/gplx/langs/phps/Php_parser_fxt.java @@ -0,0 +1,290 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.phps; import gplx.*; import gplx.langs.*; +import gplx.core.tests.*; import gplx.core.log_msgs.*; +class Php_parser_fxt { + Php_tkn_factory tkn_factory = new Php_tkn_factory(); + Php_parser parser = new Php_parser(); + Php_tkn_wkr_tkn tkn_wkr = new Php_tkn_wkr_tkn(); + Php_evaluator line_wkr = new Php_evaluator(new Gfo_msg_log("test")); + Tst_mgr tst_mgr = new Tst_mgr(); + Gfo_msg_log_chkr log_mgr_chkr = new Gfo_msg_log_chkr(); + public void Clear() {log_mgr_chkr.Clear(); tkn_wkr.Clear(); line_wkr.Clear();} + public Php_tkn_chkr_base tkn_declaration() {return Php_tkn_declaration_chkr.Instance;} + public Php_tkn_chkr_base tkn_txt(int bgn, int end) {return new Php_tkn_txt_chkr(bgn, end);} + public Php_tkn_chkr_base tkn_ws(int bgn, int end) {return new Php_tkn_ws_chkr(bgn, end);} + public Php_tkn_chkr_base tkn_generic(int bgn, int end, byte tid) {return new Php_tkn_generic_chkr(bgn, end, tid);} + public Php_tkn_comment_chkr tkn_comment_mult(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_mult);} + public Php_tkn_comment_chkr tkn_comment_slash(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_slash);} + public Php_tkn_comment_chkr tkn_comment_hash(int bgn, int end) {return new Php_tkn_comment_chkr(bgn, end).Comment_tid_(Php_tkn_comment.Tid_hash);} + public Php_tkn_quote_chkr tkn_quote_apos(int bgn, int end) {return new Php_tkn_quote_chkr(bgn, end).Quote_tid_(Byte_ascii.Apos);} + public Php_tkn_quote_chkr tkn_quote_quote(int bgn, int end) {return new Php_tkn_quote_chkr(bgn, end).Quote_tid_(Byte_ascii.Quote);} + public Php_parser_fxt Msg(Gfo_msg_itm itm, int bgn, int end) { + log_mgr_chkr.Add_itm(itm, bgn, end); + return this; + } + public Php_tkn_var_chkr tkn_var(int bgn, int end, String v) {return new Php_tkn_var_chkr(bgn, end).Var_name_(v);} + public Php_tkn_num_chkr tkn_num(int bgn, int end, int v) {return new Php_tkn_num_chkr(bgn, end).Num_val_int_(v);} + public Php_line_assign_chkr line_assign(String key, Php_itm_chkr_base val) {return new Php_line_assign_chkr().Key_(key).Val_(val);} + public Php_line_assign_chkr line_assign_subs(String key, String[] subs, Php_itm_chkr_base val) {return new Php_line_assign_chkr().Key_(key).Subs_(subs).Val_(val);} + public Php_itm_chkr_base itm_bool_true() {return new Php_itm_generic_chkr(Php_itm_.Tid_bool_true);} + public Php_itm_chkr_base itm_bool_false() {return new Php_itm_generic_chkr(Php_itm_.Tid_bool_false);} + public Php_itm_chkr_base itm_null() {return new Php_itm_generic_chkr(Php_itm_.Tid_null);} + public Php_itm_chkr_base itm_quote(String v) {return new Php_itm_quote_chkr().Val_obj_str_(v);} + public Php_itm_chkr_base itm_int(int v) {return new Php_itm_int_chkr().Val_obj_int_(v);} + public Php_itm_chkr_base itm_txt(String v) {return new Php_itm_txt_chkr().Val_obj_str_(v);} + public Php_itm_ary_chkr itm_ary() {return new Php_itm_ary_chkr();} + public Php_itm_kv_chkr itm_kv_quote(String k, String v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_quote(v));} + public Php_itm_kv_chkr itm_kv_txt(String k, String v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_txt(v));} + public Php_itm_kv_chkr itm_kv_int(String k, int v) {return new Php_itm_kv_chkr().Key_(k).Val_(itm_int(v));} + public Php_itm_kv_chkr itm_kv_itm(String k, Php_itm_chkr_base v) {return new Php_itm_kv_chkr().Key_(k).Val_(v);} + public void tst_tkns(String raw, Php_tkn_chkr_base... expd) { + byte[] raw_bry = Bry_.new_u8(raw); + parser.Parse_tkns(raw_bry, tkn_wkr); + Php_tkn[] actl = (Php_tkn[])tkn_wkr.List().To_ary(Php_tkn.class); + tst_mgr.Vars().Clear().Add("raw_bry", raw_bry); + tst_mgr.Tst_ary("", expd, actl); + log_mgr_chkr.tst(tst_mgr, tkn_wkr.Msg_log()); + } + public void tst_lines(String raw, Php_line_assign_chkr... expd) { + byte[] raw_bry = Bry_.new_u8(raw); + parser.Parse_tkns(raw_bry, line_wkr); + Php_line[] actl = (Php_line[])line_wkr.List().To_ary(Php_line.class); + tst_mgr.Vars().Clear().Add("raw_bry", raw_bry); + tst_mgr.Tst_ary("", expd, actl); + log_mgr_chkr.tst(tst_mgr, line_wkr.Msg_log()); + } +} +abstract class Php_tkn_chkr_base implements Tst_chkr { + public abstract byte Tkn_tid(); + public abstract Class TypeOf(); + public int Src_bgn() {return src_bgn;} private int src_bgn = -1; + public int Src_end() {return src_end;} private int src_end = -1; + public void Src_rng_(int src_bgn, int src_end) {this.src_bgn = src_bgn; this.src_end = src_end;} + public int Chk(Tst_mgr mgr, String path, Object actl_obj) { + Php_tkn actl = (Php_tkn)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "tkn_tid", this.Tkn_tid(), actl.Tkn_tid()); + rv += mgr.Tst_val(src_bgn == -1, path, "src_bgn", src_bgn, actl.Src_bgn()); + rv += mgr.Tst_val(src_end == -1, path, "src_end", src_end, actl.Src_end()); + rv += Chk_tkn(mgr, path, actl); + return rv; + } + @gplx.Virtual public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) {return 0;} +} +class Php_tkn_declaration_chkr extends Php_tkn_chkr_base { + @Override public Class TypeOf() {return Php_tkn_declaration.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_declaration;} + public static final Php_tkn_declaration_chkr Instance = new Php_tkn_declaration_chkr(); +} +class Php_tkn_txt_chkr extends Php_tkn_chkr_base { + public Php_tkn_txt_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_txt.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_txt;} +} +class Php_tkn_ws_chkr extends Php_tkn_chkr_base { + public Php_tkn_ws_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_ws.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_ws;} +} +class Php_tkn_comment_chkr extends Php_tkn_chkr_base { + public Php_tkn_comment_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_comment.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_comment;} + public Php_tkn_comment_chkr Comment_tid_(byte v) {this.comment_tid = v; return this;} private byte comment_tid = Php_tkn_comment.Tid_null; + @Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) { + Php_tkn_comment actl = (Php_tkn_comment)actl_obj; + int rv = 0; + rv += mgr.Tst_val(comment_tid == Php_tkn_comment.Tid_null, path, "comment_tid", comment_tid, actl.Comment_tid()); + return rv; + } +} +class Php_tkn_quote_chkr extends Php_tkn_chkr_base { + public Php_tkn_quote_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_quote.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_quote;} + public Php_tkn_quote_chkr Quote_tid_(byte v) {this.quote_tid = v; return this;} private byte quote_tid = Byte_ascii.Null; + @Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) { + Php_tkn_quote actl = (Php_tkn_quote)actl_obj; + int rv = 0; + rv += mgr.Tst_val(quote_tid == Byte_ascii.Null, path, "quote_tid", quote_tid, actl.Quote_tid()); + return rv; + } +} +class Php_tkn_var_chkr extends Php_tkn_chkr_base { + public Php_tkn_var_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_var.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_var;} + public Php_tkn_var_chkr Var_name_(String v) {this.var_name = v; return this;} private String var_name; + @Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) { + Php_tkn_var actl = (Php_tkn_var)actl_obj; + int rv = 0; + byte[] raw_bry = (byte[])mgr.Vars_get_by_key("raw_bry"); + rv += mgr.Tst_val(var_name == null, path, "var_name", var_name, String_.new_u8(actl.Var_name(raw_bry))); + return rv; + } +} +class Php_tkn_num_chkr extends Php_tkn_chkr_base { + public Php_tkn_num_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);} + @Override public Class TypeOf() {return Php_tkn_num.class;} + @Override public byte Tkn_tid() {return Php_tkn_.Tid_num;} + public Php_tkn_num_chkr Num_val_int_(int v) {this.num_val_int = v; return this;} private int num_val_int = Int_.Min_value; + @Override public int Chk_tkn(Tst_mgr mgr, String path, Php_tkn actl_obj) { + Php_tkn_num actl = (Php_tkn_num)actl_obj; + int rv = 0; + byte[] raw_bry = (byte[])mgr.Vars_get_by_key("raw_bry"); + rv += mgr.Tst_val(num_val_int == Int_.Min_value, path, "num_val_int", num_val_int, actl.Num_val_int(raw_bry)); + return rv; + } +} +class Php_tkn_generic_chkr extends Php_tkn_chkr_base { + public Php_tkn_generic_chkr(int src_bgn, int src_end, byte tkn_tid) {this.Src_rng_(src_bgn, src_end); this.tkn_tid = tkn_tid;} + @Override public Class TypeOf() {return Php_tkn.class;} + @Override public byte Tkn_tid() {return tkn_tid;} private byte tkn_tid; +} +class Php_line_assign_chkr implements Tst_chkr { + public Class TypeOf() {return Php_line_assign.class;} + public Php_line_assign_chkr Key_(String v) {key = v; return this;} private String key; + public Php_line_assign_chkr Subs_(String[] v) { + int subs_len = v.length; + subs = new Php_itm_quote_chkr[subs_len]; + for (int i = 0; i < subs_len; i++) + subs[i] = new Php_itm_quote_chkr().Val_obj_str_(v[i]); + return this; + } Php_itm_chkr_base[] subs; + public Php_line_assign_chkr Val_(Php_itm_chkr_base v) {val = v; return this;} Php_itm_chkr_base val; + public int Chk(Tst_mgr mgr, String path, Object actl_obj) { + Php_line_assign actl = (Php_line_assign)actl_obj; + int rv = 0; + rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key().Val_obj_bry())); + if (subs != null) rv += mgr.Tst_sub_ary(subs, actl.Key_subs(), "subs", rv); + rv += mgr.Tst_sub_obj(val, actl.Val(), "val", rv); + return rv; + } +} +abstract class Php_itm_chkr_base implements Tst_chkr { + public abstract byte Itm_tid(); + public abstract Class TypeOf(); + public int Chk(Tst_mgr mgr, String path, Object actl_obj) { + Php_itm actl = (Php_itm)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "tkn_tid", this.Itm_tid(), actl.Itm_tid()); + rv += Chk_itm(mgr, path, actl); + return rv; + } + @gplx.Virtual public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) {return 0;} + public static final Php_itm_chkr_base[] Ary_empty = new Php_itm_chkr_base[0]; +} +class Php_itm_generic_chkr extends Php_itm_chkr_base { + public Php_itm_generic_chkr(byte itm_tid) {this.itm_tid = itm_tid;} private byte itm_tid; + @Override public byte Itm_tid() {return itm_tid;} + @Override public Class TypeOf() {return Php_itm.class;} +} +class Php_itm_int_chkr extends Php_itm_chkr_base { + @Override public byte Itm_tid() {return Php_itm_.Tid_int;} + @Override public Class TypeOf() {return Php_itm.class;} + public Php_itm_int_chkr Val_obj_int_(int v) {this.val_obj_int = v; return this;} private int val_obj_int; + @Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) { + Php_itm_int actl = (Php_itm_int)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_int, actl.Val_obj_int()); + return rv; + } +} +class Php_itm_txt_chkr extends Php_itm_chkr_base { + @Override public byte Itm_tid() {return Php_itm_.Tid_var;} + @Override public Class TypeOf() {return Php_itm.class;} + public Php_itm_txt_chkr Val_obj_str_(String v) {this.val_obj_str = v; return this;} private String val_obj_str; + @Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) { + Php_itm_var actl = (Php_itm_var)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_str, String_.new_u8(actl.Val_obj_bry())); + return rv; + } +} +class Php_itm_quote_chkr extends Php_itm_chkr_base { + @Override public byte Itm_tid() {return Php_itm_.Tid_quote;} + @Override public Class TypeOf() {return Php_itm.class;} + public Php_itm_quote_chkr Val_obj_str_(String v) {this.val_obj_str = v; return this;} private String val_obj_str; + @Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) { + Php_itm_quote actl = (Php_itm_quote)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "val_obj_str", val_obj_str, String_.new_u8(actl.Val_obj_bry())); + return rv; + } +} +class Php_itm_ary_chkr extends Php_itm_chkr_base { + @Override public byte Itm_tid() {return Php_itm_.Tid_ary;} + @Override public Class TypeOf() {return Php_itm.class;} + public Php_itm_ary_chkr Subs_(Php_itm_chkr_base... v) {this.itms = v; return this;} Php_itm_chkr_base[] itms = Php_itm_chkr_base.Ary_empty; + @Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) { + Php_itm_ary actl = (Php_itm_ary)actl_obj; + int rv = 0; + int actl_subs_len = actl.Subs_len(); + Php_itm[] actl_ary = new Php_itm[actl_subs_len]; + for (int i = 0; i < actl_subs_len; i++) { + actl_ary[i] = (Php_itm)actl.Subs_get(i); + } + rv += mgr.Tst_sub_ary(itms, actl_ary, "subs", rv); + return rv; + } +} +class Php_itm_kv_chkr extends Php_itm_chkr_base { + @Override public byte Itm_tid() {return Php_itm_.Tid_kv;} + @Override public Class TypeOf() {return Php_itm.class;} + public Php_itm_kv_chkr Key_(String v) {key = v; return this;} private String key; + public Php_itm_kv_chkr Val_(Php_itm_chkr_base v) {val = v; return this;} Php_itm_chkr_base val; + @Override public int Chk_itm(Tst_mgr mgr, String path, Php_itm actl_obj) { + Php_itm_kv actl = (Php_itm_kv)actl_obj; + int rv = 0; + rv += mgr.Tst_val(false, path, "key", key, String_.new_u8(actl.Key().Val_obj_bry())); + rv += mgr.Tst_sub_obj(val, actl.Val(), path, rv); + return rv; + } +} +class Gfo_msg_log_chkr implements Tst_chkr { + List_adp itms = List_adp_.New(); + public Class TypeOf() {return Gfo_msg_log.class;} + public void Clear() {itms.Clear();} + public void Add_itm(Gfo_msg_itm itm, int bgn, int end) { + Gfo_msg_data_chkr chkr = new Gfo_msg_data_chkr(); + chkr.Itm_(itm).Excerpt_bgn_(bgn).Excerpt_end_(end); + itms.Add(chkr); + } + public int Chk(Tst_mgr mgr, String path, Object actl_obj) {return 0;} + public void tst(Tst_mgr mgr, Object actl_obj) { + Gfo_msg_log actl = (Gfo_msg_log)actl_obj; + int actl_itms_len = actl.Ary_len(); + Gfo_msg_data[] actl_itms = new Gfo_msg_data[actl_itms_len]; + for (int i = 0; i < actl_itms_len; i++) + actl_itms[i] = actl.Ary_get(i); + mgr.Tst_ary("itms", (Gfo_msg_data_chkr[])itms.To_ary(Gfo_msg_data_chkr.class), actl_itms); + } +} +class Gfo_msg_data_chkr implements Tst_chkr { + public Class TypeOf() {return Gfo_msg_data.class;} + public Gfo_msg_data_chkr Itm_(Gfo_msg_itm v) {itm = v; return this;} Gfo_msg_itm itm; + public Gfo_msg_data_chkr Excerpt_bgn_(int v) {excerpt_bgn = v; return this;} private int excerpt_bgn = -1; + public Gfo_msg_data_chkr Excerpt_end_(int v) {excerpt_end = v; return this;} private int excerpt_end = -1; + public int Chk(Tst_mgr mgr, String path, Object actl_obj) { + Gfo_msg_data actl = (Gfo_msg_data)actl_obj; + int rv = 0; + rv += mgr.Tst_val(itm == null, path, "itm", itm.Path_str(), actl.Item().Path_str()); + rv += mgr.Tst_val(excerpt_bgn == -1, path, "excerpt_bgn", excerpt_bgn, actl.Src_bgn()); + rv += mgr.Tst_val(excerpt_end == -1, path, "excerpt_end", excerpt_end, actl.Src_end()); + return rv; + } +} diff --git a/400_xowa/src/gplx/langs/phps/Php_parser_tst.java b/400_xowa/src/gplx/langs/phps/Php_parser_tst.java new file mode 100644 index 000000000..354f33a88 --- /dev/null +++ b/400_xowa/src/gplx/langs/phps/Php_parser_tst.java @@ -0,0 +1,82 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.phps; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Php_parser_tst { + @Before public void init() {fxt.Clear();} private final Php_parser_fxt fxt = new Php_parser_fxt(); + @Test public void Text() {fxt.tst_tkns("text", fxt.tkn_txt(0, 4)); } + @Test public void Declaration_pass() {fxt.tst_tkns(",()", fxt.tkn_generic(0, 1, Php_tkn_.Tid_semic), fxt.tkn_generic(1, 2, Php_tkn_.Tid_eq), fxt.tkn_generic(2, 4, Php_tkn_.Tid_eq_kv), fxt.tkn_generic(4, 5, Php_tkn_.Tid_comma), fxt.tkn_generic(5, 6, Php_tkn_.Tid_paren_bgn), fxt.tkn_generic(6, 7, Php_tkn_.Tid_paren_end));} + @Test public void Keyword() {fxt.tst_tkns("null=nulla", fxt.tkn_generic(0, 4, Php_tkn_.Tid_null), fxt.tkn_generic(4, 5, Php_tkn_.Tid_eq), fxt.tkn_txt(5, 10));} + @Test public void Num() {fxt.tst_tkns("0=123", fxt.tkn_num(0, 1, 0), fxt.tkn_generic(1, 2, Php_tkn_.Tid_eq), fxt.tkn_num(2, 5, 123));} + @Test public void Quote_apos() {fxt.tst_tkns("'a\"b'", fxt.tkn_quote_apos(0, 5));} + @Test public void Quote_quote() {fxt.tst_tkns("\"a'b\"", fxt.tkn_quote_quote(0, 5));} + @Test public void Quote_escape() {fxt.tst_tkns("'a\\'b'", fxt.tkn_quote_apos(0, 6));} + @Test public void Brack() {fxt.tst_tkns("['a']", fxt.tkn_generic(0, 1, Php_tkn_.Tid_brack_bgn), fxt.tkn_quote_apos(1, 4), fxt.tkn_generic(4, 5, Php_tkn_.Tid_brack_end));} + @Test public void Line_ws() {fxt.tst_lines("\r\n$a = false;", fxt.line_assign("a", fxt.itm_bool_false()));} + @Test public void Line_brack() {fxt.tst_lines("$a['b'] = 'c';", fxt.line_assign_subs("a", String_.Ary("b"), fxt.itm_quote("c")));} + @Test public void Line_assign_false() {fxt.tst_lines("$a = false;", fxt.line_assign("a", fxt.itm_bool_false()));} + @Test public void Line_assign_quote_charcode() {fxt.tst_lines("$a = 'bc';", fxt.line_assign("a", fxt.itm_quote("bc")));} + @Test public void Line_assign_mult() {fxt.tst_lines("$a = 'b';\n$c='d';", fxt.line_assign("a", fxt.itm_quote("b")), fxt.line_assign("c", fxt.itm_quote("d")));} + @Test public void Empty_usr_array() { + fxt.tst_lines("$a = array();\n$b = array();" + , fxt.line_assign("a", fxt.itm_ary()) + , fxt.line_assign("b", fxt.itm_ary()) + ); + } + @Test public void Ary_flat() {fxt.tst_lines("$a = array('b', 'c', 'd');" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_quote("c"), fxt.itm_quote("d"))));} + @Test public void Brack_flat() {fxt.tst_lines("$a = ['b', 'c', 'd'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_quote("c"), fxt.itm_quote("d"))));} + @Test public void Ary_flat_escape() { // PURPOSE.fix: \\' was being interpreted incorrectly; \\ should escape \, but somehow \' was being escaped + fxt.tst_lines("$a = array('b\\\\', 'c');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b\\\\"), fxt.itm_quote("c")))); + } + @Test public void Ary_flat_escape2() { // PURPOSE.fix: \\' was being interpreted incorrectly; \\ should escape \, but somehow \' was being escaped + fxt.tst_lines("$a = array('b\\\\\\'c', 'd');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b\\\\\\'c"), fxt.itm_quote("d")))); + } + @Test public void Ary_kv() {fxt.tst_lines("$a = array(k0 => 'v0', k1 => 'v1', k2 => 'v2');", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_quote("k0", "v0"), fxt.itm_kv_quote("k1", "v1"), fxt.itm_kv_quote("k2", "v2"))));} + @Test public void Brack_kv() {fxt.tst_lines("$a = [k0 => 'v0', k1 => 'v1', k2 => 'v2'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_quote("k0", "v0"), fxt.itm_kv_quote("k1", "v1"), fxt.itm_kv_quote("k2", "v2"))));} + @Test public void Ary_kv_num() {fxt.tst_lines("$a = array(k0 => 0, k1 => 1);", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_int("k0", 0), fxt.itm_kv_int("k1", 1))));} + @Test public void Ary_kv_txt() {fxt.tst_lines("$a = array('k0' => a, 'k1' => b);", fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_kv_txt("k0", "a"), fxt.itm_kv_txt("k1", "b"))));} + @Test public void Ary_nest() {fxt.tst_lines("$a = array('b', array('c', 'd'), 'e');" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_ary().Subs_(fxt.itm_quote("c"), fxt.itm_quote("d")), fxt.itm_quote("e"))));} + @Test public void Brack_nest() {fxt.tst_lines("$a = ['b', ['c', 'd'], 'e'];" , fxt.line_assign("a", fxt.itm_ary().Subs_(fxt.itm_quote("b"), fxt.itm_ary().Subs_(fxt.itm_quote("c"), fxt.itm_quote("d")), fxt.itm_quote("e"))));} + @Test public void Ary_nest_kv() { + fxt.tst_lines("$a = array('i00' => array('01', '02'), 'i10' => array('11', '12'), 'i20' => array('21', '22'));" + , fxt.line_assign + ( "a" + , fxt.itm_ary().Subs_ + ( fxt.itm_kv_itm("i00", fxt.itm_ary().Subs_(fxt.itm_quote("01"), fxt.itm_quote("02"))) + , fxt.itm_kv_itm("i10", fxt.itm_ary().Subs_(fxt.itm_quote("11"), fxt.itm_quote("12"))) + , fxt.itm_kv_itm("i20", fxt.itm_ary().Subs_(fxt.itm_quote("21"), fxt.itm_quote("22"))) + ))); + } + @Test public void Brack_nest_kv() { + fxt.tst_lines("$a = ['i00' => ['01', '02'], 'i10' => ['11', '12'], 'i20' => ['21', '22']];" + , fxt.line_assign + ( "a" + , fxt.itm_ary().Subs_ + ( fxt.itm_kv_itm("i00", fxt.itm_ary().Subs_(fxt.itm_quote("01"), fxt.itm_quote("02"))) + , fxt.itm_kv_itm("i10", fxt.itm_ary().Subs_(fxt.itm_quote("11"), fxt.itm_quote("12"))) + , fxt.itm_kv_itm("i20", fxt.itm_ary().Subs_(fxt.itm_quote("21"), fxt.itm_quote("22"))) + ))); + } +} diff --git a/400_xowa/src/gplx/langs/phps/Php_srl_parser_tst.java b/400_xowa/src/gplx/langs/phps/Php_srl_parser_tst.java new file mode 100644 index 000000000..13d0eb330 --- /dev/null +++ b/400_xowa/src/gplx/langs/phps/Php_srl_parser_tst.java @@ -0,0 +1,110 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.phps; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Php_srl_parser_tst { + Php_srl_parser_fxt fxt = new Php_srl_parser_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Nil() {fxt.Test_parse("N;", fxt.itm_nil_());} + @Test public void Bool_y() {fxt.Test_parse("b:1;", fxt.itm_bool_y_());} + @Test public void Bool_n() {fxt.Test_parse("b:0;", fxt.itm_bool_n_());} + @Test public void Num_int() {fxt.Test_parse("i:123;", fxt.itm_int_(123));} + @Test public void Num_int_neg() {fxt.Test_parse("i:-123;", fxt.itm_int_(-123));} + @Test public void Num_double() {fxt.Test_parse("d:1.23;", fxt.itm_double_(1.23d));} + @Test public void Num_double_inf_pos(){fxt.Test_parse("d:INF;", fxt.itm_double_(Double_.Inf_pos));} + @Test public void Num_double_exp() {fxt.Test_parse("d:1.2e+2;", fxt.itm_double_(120));} + @Test public void Num_double_nan() {fxt.Test_parse("d:NAN;", fxt.itm_double_(Double_.NaN));} + @Test public void Str_len_3() {fxt.Test_parse("s:3:\"abc\";", fxt.itm_str_("abc"));} + @Test public void Str_len_4() {fxt.Test_parse("s:4:\"abcd\";", fxt.itm_str_("abcd"));} + @Test public void Str_len_0() {fxt.Test_parse("s:0:\"\";", fxt.itm_str_(""));} + @Test public void Ary_empty() {fxt.Test_parse("a:0:{}", fxt.itm_ary_());} + @Test public void Ary_flat_one() {fxt.Test_parse("a:1:{i:1;i:9;}", fxt.itm_ary_().Subs_add(fxt.itm_kvi_(1, fxt.itm_int_(9))));} + @Test public void Ary_flat_many() { + fxt.Test_parse(String_.Concat + ( "a:3:{" + , "i:1;i:9;" + , "i:2;i:8;" + , "i:3;i:7;" + , "}"), fxt.itm_ary_().Subs_add_many + ( fxt.itm_kvi_(1, fxt.itm_int_(9)) + , fxt.itm_kvi_(2, fxt.itm_int_(8)) + , fxt.itm_kvi_(3, fxt.itm_int_(7)) + )); + } + @Test public void Ary_nest_one() { + fxt.Test_parse(String_.Concat + ( "a:1:{" + , "i:1;" + , "a:2:{" + , "i:1;i:9;" + , "i:2;i:8;" + , "}" + , "}" + ) + , fxt.itm_ary_().Subs_add_many + ( fxt.itm_kvi_(1, fxt.itm_ary_().Subs_add_many + ( fxt.itm_kvi_(1, fxt.itm_int_(9)) + , fxt.itm_kvi_(2, fxt.itm_int_(8)) + )))); + } + @Test public void Ary_key_str() { + fxt.Test_parse(String_.Concat + ( "a:1:{" + , "s:3:\"abc\";" + , "i:987;" + , "}"), fxt.itm_ary_().Subs_add_many + ( fxt.itm_kvs_("abc", fxt.itm_int_(987)) + )); + } + @Test public void Func() { + fxt.Test_parse("O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:123;}", fxt.itm_func_(123)); + } + @Test public void Smoke() { +// fxt.Test_parse("a:2:{s:6:\"values\";a:1:{i:1;a:9:{s:21:\"makeProt"+"ectedEnvFuncs\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:2;}s:3:\"log\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:3;}s:14:\"clearLogBuffer\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:4;}s:5:\"setup\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:5;}s:5:\"clone\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:6;}s:15:\"getCurrentFrame\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:7;}s:13:\"executeModule\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:8;}s:15:\"executeFunction\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:9;}s:12:\"getLogBuffer\";O:42:\"Scribunto_LuaStandaloneInterpreterFunction\":1:{s:2:\"id\";i:10;}}}s:2:\"op\";s:6:\"return\";}"); + } +} +class Php_srl_parser_fxt { + public void Clear() { + parser = new Php_srl_parser(); + factory = parser.Factory(); + } Php_srl_parser parser; Php_srl_factory factory; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); + public Php_srl_itm itm_nil_() {return factory.Nil();} + public Php_srl_itm itm_bool_n_() {return factory.Bool_n();} + public Php_srl_itm itm_bool_y_() {return factory.Bool_y();} + public Php_srl_itm itm_int_(int v) {return factory.Int(-1, -1, v);} + public Php_srl_itm itm_double_(double v) {return factory.Double(-1, -1, v);} + public Php_srl_itm itm_str_(String v) {return factory.Str(-1, -1, v);} + public Php_srl_itm itm_func_(int v) {return factory.Func(-1, -1, v);} + public Php_srl_itm_ary itm_ary_() {return factory.Ary(-1, -1);} + public Php_srl_itm_kv itm_kvi_(int k, Php_srl_itm v){return factory.Kv().Key_(itm_int_(k)).Val_(v);} + public Php_srl_itm_kv itm_kvs_(String k, Php_srl_itm v){return factory.Kv().Key_(itm_str_(k)).Val_(v);} + public void Test_parse(String raw_str, Php_srl_itm... expd_ary) { + byte[] raw = Bry_.new_u8(raw_str); + Php_srl_itm_ary root = parser.Parse(raw); + Php_srl_itm root_sub = root.Subs_get_at(0).Val(); + root_sub.Xto_bfr(tmp_bfr, 0); + String actl = tmp_bfr.To_str_and_clear(); + String expd = Xto_str(expd_ary, 0, expd_ary.length); + Tfds.Eq_str_lines(expd, actl, actl); + } + String Xto_str(Php_srl_itm[] ary, int bgn, int end) { + for (int i = bgn; i < end; i++) { + Php_srl_itm itm = ary[i]; + itm.Xto_bfr(tmp_bfr, 0); + } + return tmp_bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/langs/phps/Php_text_itm_tst.java b/400_xowa/src/gplx/langs/phps/Php_text_itm_tst.java new file mode 100644 index 000000000..75c000ce1 --- /dev/null +++ b/400_xowa/src/gplx/langs/phps/Php_text_itm_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.phps; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Php_text_itm_tst { + @Before public void init() {fxt.Clear();} private Php_text_itm_fxt fxt = new Php_text_itm_fxt(); + @Test public void Q1_basic() {fxt.Init_q1().Test_parse("abcde" , "abcde");} + @Test public void Q1_apos() {fxt.Init_q1().Test_parse("a\\'b" , "a'b");} + @Test public void Q1_backslash() {fxt.Init_q1().Test_parse("a\\\\b" , "a\\b");} + @Test public void Q1_backslash_eos() {fxt.Init_q1().Test_parse("a\\" , "a\\");} // PURPOSE: allow single trailing backslash; DATE:2014-08-06 + @Test public void Q1_noop() {fxt.Init_q1().Test_parse("a\\$\\nb" , "a\\$\\nb");} + @Test public void Q2_basic() {fxt.Init_q2().Test_parse("abcde" , "abcde");} + @Test public void Q2_quote() {fxt.Init_q2().Test_parse("a\\\"b" , "a\"b");} + @Test public void Q2_backslash() {fxt.Init_q2().Test_parse("a\\\\b" , "a\\b");} + @Test public void Q2_noop() {fxt.Init_q2().Test_parse("a\\%\\cb" , "a\\%\\cb");} + @Test public void Q2_ws() {fxt.Init_q2().Test_parse("a\\tb\\nc" , "a\tb\nc");} + @Test public void Q2_fmt() {fxt.Init_q2().Test_parse("a$1b$2c" , "a~{0}b~{1}c");} + @Test public void Q2_utf_pipe() {fxt.Init_q2().Test_parse("a\\u007Cd" , "a|d");} + @Test public void Q2_hex_nbsp() {fxt.Init_q2().Test_parse("a\\xc2\\xa0d" , "a\\u00c2\\u00a0d");} +} +class Php_text_itm_fxt { + private Php_text_itm_parser parser; + public void Clear() {parser = new Php_text_itm_parser();} + public Php_text_itm_fxt Init_q1() {parser.Quote_is_single_(Bool_.Y); return this;} + public Php_text_itm_fxt Init_q2() {parser.Quote_is_single_(Bool_.N); return this;} + public void Test_parse(String raw_str, String expd) { + List_adp list = List_adp_.New(); + byte[] raw = Bry_.new_u8(raw_str); + parser.Parse(list, raw); + Bry_bfr bfr = Bry_bfr_.Reset(255); + int list_len = list.Count(); + for (int i = 0; i < list_len; i++) { + Php_text_itm itm = (Php_text_itm)list.Get_at(i); + itm.Bld(bfr, raw); + } + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/langs/regxs/Gfo_pattern_tst.java b/400_xowa/src/gplx/langs/regxs/Gfo_pattern_tst.java new file mode 100644 index 000000000..a00972dc6 --- /dev/null +++ b/400_xowa/src/gplx/langs/regxs/Gfo_pattern_tst.java @@ -0,0 +1,91 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.regxs; import gplx.*; import gplx.langs.*; +import org.junit.*; import gplx.core.strings.*; +public class Gfo_pattern_tst { + @Before public void init() {fxt.Clear();} private Gfo_pattern_itm_fxt fxt = new Gfo_pattern_itm_fxt(); + @Test public void Compile() { + fxt.Test_Compile("a" , fxt.itm_text_("a")); + fxt.Test_Compile("*" , fxt.itm_wild_()); + fxt.Test_Compile("a*" , fxt.itm_text_("a"), fxt.itm_wild_()); + fxt.Test_Compile("*a" , fxt.itm_wild_(), fxt.itm_text_("a")); + fxt.Test_Compile("*ab*" , fxt.itm_wild_(), fxt.itm_text_("ab"), fxt.itm_wild_()); + fxt.Test_Compile("" ); + } + @Test public void Match() { + Gfo_pattern pattern = fxt.pattern_("abc"); + fxt.Test_Match_y(pattern, "abc"); + fxt.Test_Match_n(pattern, "ab", "a", "bc", "Abc", ""); + } + @Test public void Match_all() { + Gfo_pattern pattern = fxt.pattern_("*"); + fxt.Test_Match_y(pattern, "a", "abc", ""); + } + @Test public void Match_bgn() { + Gfo_pattern pattern = fxt.pattern_("abc*"); + fxt.Test_Match_y(pattern, "abc", "abcdef"); + fxt.Test_Match_n(pattern, "abd", "aabc", ""); + } + @Test public void Match_end() { + Gfo_pattern pattern = fxt.pattern_("*abc"); + fxt.Test_Match_y(pattern, "abc", "xyzabc"); + fxt.Test_Match_n(pattern, "abcd", ""); + } + @Test public void Match_mid() { + Gfo_pattern pattern = fxt.pattern_("a*c*e"); + fxt.Test_Match_y(pattern, "ace", "abcde"); + fxt.Test_Match_n(pattern, "abc", ""); + } + @Test public void Bug_ctx() { // PURPOSE.fix: cb was true b/c ctx was not reset correctly + Gfo_pattern pattern = fxt.pattern_("b*"); + fxt.Test_Match_y(pattern, "bc"); + fxt.Test_Match_n(pattern, "cb"); + } +} +class Gfo_pattern_itm_fxt { + public void Clear() {} + public Gfo_pattern pattern_(String raw) {return new Gfo_pattern(Bry_.new_u8(raw));} + public void Test_Match_y(Gfo_pattern pattern, String... itms) {Test_Match(pattern, itms, Bool_.Y);} + public void Test_Match_n(Gfo_pattern pattern, String... itms) {Test_Match(pattern, itms, Bool_.N);} + private void Test_Match(Gfo_pattern pattern, String[] itms, boolean expd) { + int len = itms.length; + for (int i = 0; i < len; i++) { + String itm = itms[i]; + Tfds.Eq(expd, pattern.Match(Bry_.new_u8(itm)), "pattern={0} itm={1} expd={2}", String_.new_u8(pattern.Raw()), itm, expd); + } + } + public Gfo_pattern_itm_wild itm_wild_() {return Gfo_pattern_itm_wild.Instance;} + public Gfo_pattern_itm_text itm_text_(String raw) { + Gfo_pattern_itm_text rv = new Gfo_pattern_itm_text(); + byte[] bry = Bry_.new_u8(raw); + rv.Compile(bry, 0, bry.length); + return rv; + } + public void Test_Compile(String raw, Gfo_pattern_itm... expd) { + Gfo_pattern_itm[] actl = Gfo_pattern_itm_.Compile(Bry_.new_u8(raw)); + Tfds.Eq(Ary_xto_str(expd), Ary_xto_str(actl)); + } + private static String Ary_xto_str(Gfo_pattern_itm[] ary) { + int len = ary.length; + String_bldr sb = String_bldr_.new_(); + for (int i = 0; i < len; i++) { + if (i != 0) sb.Add_char_nl(); + Gfo_pattern_itm itm = ary[i]; + itm.Xto_str(sb); + } + return sb.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/langs/xmls/Gfo_xml_wtr_tst.java b/400_xowa/src/gplx/langs/xmls/Gfo_xml_wtr_tst.java new file mode 100644 index 000000000..c06191b3b --- /dev/null +++ b/400_xowa/src/gplx/langs/xmls/Gfo_xml_wtr_tst.java @@ -0,0 +1,79 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.langs.xmls; import gplx.*; import gplx.langs.*; +import org.junit.*; +public class Gfo_xml_wtr_tst { + private final Gfo_xml_wtr_fxt fxt = new Gfo_xml_wtr_fxt(); + @Before public void init() {} + @Test public void Root() { + fxt.Wtr().Nde_lhs("a").Nde_rhs(); + fxt.Test_bld("", ""); + } + @Test public void Nest() { + fxt.Wtr() + .Nde_lhs("a") + . Nde_lhs("a_a") + . Nde_lhs("a_a_a") + . Nde_rhs() + . Nde_rhs() + .Nde_rhs() + ; + fxt.Test_bld + ( "" + , " " + , " " + , " " + , " " + , "" + ); + } + @Test public void Atrs() { + fxt.Wtr() + .Nde_lhs_bgn_itm("a") + .Atr_kv_str_a7("b", "b1") + .Nde_lhs_end() + .Nde_rhs() + ; + fxt.Test_bld(""); + } + @Test public void Atrs_escape() { + fxt.Wtr() + .Nde_lhs_bgn_itm("a") + .Atr_kv_str_a7("b", "'\"<>&") + .Nde_lhs_end() + .Nde_rhs() + ; + fxt.Test_bld(""); + } + @Test public void Nde_txt() { + fxt.Wtr() + .Nde_txt_str("a", "a123") + ; + fxt.Test_bld("a123"); + } + @Test public void Nde_txt_escape() { + fxt.Wtr() + .Nde_txt_str("a", "'\"<>&x") + ; + fxt.Test_bld("'\"<>&x"); + } +} +class Gfo_xml_wtr_fxt { + public Gfo_xml_wtr Wtr() {return wtr;} private final Gfo_xml_wtr wtr = new Gfo_xml_wtr(); + public void Test_bld(String... lines) { + Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(lines), wtr.Bld_str()); + } +} diff --git a/400_xowa/src/gplx/xowa/Xoa_app_fxt.java b/400_xowa/src/gplx/xowa/Xoa_app_fxt.java new file mode 100644 index 000000000..a144d0049 --- /dev/null +++ b/400_xowa/src/gplx/xowa/Xoa_app_fxt.java @@ -0,0 +1,105 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa; import gplx.*; +import gplx.core.envs.*; +import gplx.gfui.kits.core.*; +import gplx.langs.gfs.*; +import gplx.dbs.*; +import gplx.xowa.bldrs.*; +import gplx.xowa.langs.*; +import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*; +import gplx.xowa.apps.*; import gplx.xowa.files.exts.*; +import gplx.xowa.wikis.domains.*; +import gplx.xowa.guis.tabs.*; +public class Xoa_app_fxt { + public static Xoae_app Make__app__edit() { + Io_mgr.Instance.InitEngine_mem(); + Db_conn_bldr.Instance.Reg_default_mem(); + return Make__app__edit("linux", Io_url_.mem_dir_("mem/xowa/")); + } + public static Xoae_app Make__app__edit(String op_sys, Io_url root_dir) { + Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user"); + Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current")); + Xoae_app app = new Xoae_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_cmd, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), op_sys); + GfsCore.Instance.Clear(); // NOTE: must clear + GfsCore.Instance.AddCmd(app, Xoae_app.Invk_app); // NOTE: must add app to GfsCore; app.Gfs_mgr() always adds current app to GfsCore; note this causes old test to leave behind GfsCore for new test + GfsCore.Instance.AddCmd(app, Xoae_app.Invk_xowa); // add alias for app; DATE:2014-06-09 + return app; + } + public static Xoav_app Make__app__view() { + Io_mgr.Instance.InitEngine_mem(); + Db_conn_bldr.Instance.Reg_default_mem(); + return Make__app__view("linux", Io_url_.mem_dir_("mem/xowa/")); + } + public static Xoav_app Make__app__view(String op_sys, Io_url root_dir) { + Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user"); + Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current")); + Xoav_app rv = new Xoav_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_gui, Xog_tab_mgr_.New_mem(), op_sys, root_dir, root_dir.GenSubDir("file"), root_dir.GenSubDir("css"), root_dir); + rv.Init_by_app(user_dir); + rv.Wiki_mgr().Add(new Xowv_wiki(rv, Xow_domain_itm_.Bry__home, user_dir)); + return rv; + } + public static Xowv_wiki Make__wiki__view(Xoa_app app) {return Make__wiki__view(app, "en.wikipedia.org");} + public static Xowv_wiki Make__wiki__view(Xoa_app app, String domain_str) { + byte[] domain_bry = Bry_.new_u8(domain_str); + Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_str); + Xowv_wiki rv = new Xowv_wiki((Xoav_app)app, domain_bry, wiki_dir); + ((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv); + return rv; + } + public static Xowe_wiki Make__wiki__edit__nonwmf(Xoae_app app, String key) { + Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true); + Xol_lang_itm_.Lang_init(lang); + return Make__wiki__edit(app, key, lang); + } + public static Xowe_wiki Make__wiki__edit(Xoae_app app) {return Make__wiki__edit(app, "en.wikipedia.org");} + public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key) {return Make__wiki__edit(app, key, app.Lang_mgr().Lang_en());} + public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key, Xol_lang_itm lang) { + Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key); + Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir); + rv.File_mgr().Dbmeta_mgr().Depth_(2); // TEST: written for 2 depth + rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs) + rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true); + app.Wiki_mgr().Add(rv); + return rv; + } + public static void repo_(Xoae_app app, Xowe_wiki wiki) { + app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); + app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true); + wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki")); + app.File_mgr().Repo_mgr().Set("src:c", "mem/wiki/repo/src/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); + app.File_mgr().Repo_mgr().Set("trg:c", "mem/wiki/repo/trg/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true); + wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c")); + } + public static void repo2_(Xoae_app app, Xowe_wiki wiki) { + app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); + app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true); + wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki")); + app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); + app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true); + wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm")); + } + public static void Init_gui(Xoae_app app, Xowe_wiki wiki) { + app.Gui_mgr().Browser_win().Init_by_kit(Mem_kit.Instance); + app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(wiki, Xoae_page.Empty); + } + public static Xob_bldr bldr_(Xoae_app app) { + Xob_bldr rv = new Xob_bldr(app); + rv.Sort_mem_len_(Io_mgr.Len_kb).Dump_fil_len_(Io_mgr.Len_kb).Make_fil_len_(Io_mgr.Len_kb); + return rv; + } + public static final Io_url Root_dir = Op_sys.Cur().Tid_is_lnx() ? Io_url_.new_dir_("/xowa/") : Io_url_.new_dir_("C:\\xowa\\"); +} diff --git a/400_xowa/src/gplx/xowa/Xoae_page__tst.java b/400_xowa/src/gplx/xowa/Xoae_page__tst.java new file mode 100644 index 000000000..1e06c2abd --- /dev/null +++ b/400_xowa/src/gplx/xowa/Xoae_page__tst.java @@ -0,0 +1,42 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa; import gplx.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoae_page__tst { + private final Xoae_page__fxt fxt = new Xoae_page__fxt(); + @Test public void Ttl() { + fxt.Init__page("Abc"); + fxt.Exec__ttl("Заглавная_страница"); + fxt.Test__url("en.wikipedia.org/wiki/Заглавная_страница"); // fails if "%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"; DATE:2016-11-25 + } +} +class Xoae_page__fxt { + private Xoae_page page; + private Xowe_wiki wiki; + public Xoae_page__fxt() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + public void Init__page(String ttl) { + page = Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_u8(ttl))); + } + public void Exec__ttl(String raw) { + page.Ttl_(wiki.Ttl_parse(Bry_.new_u8(raw))); + } + public void Test__url(String expd) { + Gftest.Eq__str(expd, page.Url().To_str(), "url"); + } +} diff --git a/400_xowa/src/gplx/xowa/Xop_fxt.java b/400_xowa/src/gplx/xowa/Xop_fxt.java new file mode 100644 index 000000000..b53b4b5de --- /dev/null +++ b/400_xowa/src/gplx/xowa/Xop_fxt.java @@ -0,0 +1,485 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa; import gplx.*; +import gplx.core.tests.*; import gplx.core.log_msgs.*; +import gplx.xowa.apps.cfgs.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; +import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; +import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*; +import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*; +import gplx.xowa.wikis.nss.*; +import gplx.xowa.wikis.tdbs.hives.*; +import gplx.xowa.wikis.pages.*; +public class Xop_fxt { + public Xop_fxt() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + ctor(app, wiki); + } + public Xop_fxt(Xoae_app app, Xowe_wiki wiki) { + this.ctor(app, wiki); + } + private void ctor(Xoae_app app, Xowe_wiki wiki) { + this.app = app; + this.wiki = wiki; + app.Wiki_mgr().Add(wiki); + app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); + app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true); + wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki")); + ctx = wiki.Parser_mgr().Ctx(); + mock_wkr.Clear_commons(); // assume all files are in repo 0 + wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr); + parser = wiki.Parser_mgr().Main(); + this.tkn_mkr = app.Parser_mgr().Tkn_mkr(); + ctx.Para().Enabled_n_(); + hdom_wtr = wiki.Html_mgr().Html_wtr(); + wiki.Html_mgr().Img_suppress_missing_src_(false); + wiki.Xtn_mgr().Init_by_wiki(wiki); + Page_ttl_(Ttl_str); + Xot_invk_tkn.Cache_enabled = false;// always disable cache for tests; can cause strange behavior when running entire suite and lnki_temp test turns on; + } + private Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock(); + public Xoae_app App() {return app;} private Xoae_app app; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx; + public Xop_parser Parser() {return parser;} private Xop_parser parser; + public Xoae_page Page() {return ctx.Page();} + public void Lang_by_id_(int id) {ctx.Page().Lang_(wiki.Appe().Lang_mgr().Get_by_or_new(Xol_lang_stub_.Get_by_id(id).Key()));} + public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr; + public Xop_fxt Reset() { + ctx.Clear_all(); + ctx.App().Free_mem(false); + ctx.Page().Clear_all(); + wiki.File_mgr().Clear_for_tests(); + wiki.Db_mgr().Load_mgr().Clear(); + app.Wiki_mgr().Clear(); + Io_mgr.Instance.InitEngine_mem(); // clear created pages + wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false; + return this; + } + public Xop_fxt Reset_for_msgs() { + Io_mgr.Instance.InitEngine_mem(); + wiki.Lang().Msg_mgr().Clear(); // need to clear out lang + wiki.Msg_mgr().Clear(); // need to clear out wiki.Msgs + this.Reset(); + return this; + } + public Xoa_ttl Page_ttl_(String txt) { + Xoa_ttl rv = Xoa_ttl.Parse(wiki, Bry_.new_u8(txt)); + ctx.Page().Ttl_(rv); + return rv; + } + + public Xop_tkn_chkr_base tkn_bry_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_bry).Src_rng_(bgn, end);} + public Xop_tkn_chkr_base tkn_txt_() {return tkn_txt_(String_.Pos_neg1, String_.Pos_neg1);} + public Xop_tkn_chkr_base tkn_txt_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_txt).Src_rng_(bgn, end);} + public Xop_tkn_chkr_base tkn_space_() {return tkn_space_(String_.Pos_neg1, String_.Pos_neg1);} + public Xop_tkn_chkr_base tkn_space_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_space).Src_rng_(bgn, end);} + public Xop_tkn_chkr_base tkn_eq_(int bgn) {return tkn_eq_(bgn, bgn + 1);} + public Xop_tkn_chkr_base tkn_eq_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_eq).Src_rng_(bgn, end);} + public Xop_tkn_chkr_base tkn_colon_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_colon).Src_rng_(bgn, bgn + 1);} + public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);} + public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);} + public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);} + public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);} + public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);} + public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);} + public Xop_tblw_tb_tkn_chkr tkn_tblw_tb_(int bgn, int end) {return (Xop_tblw_tb_tkn_chkr)new Xop_tblw_tb_tkn_chkr().Src_rng_(bgn, end);} + public Xop_tblw_tc_tkn_chkr tkn_tblw_tc_(int bgn, int end) {return (Xop_tblw_tc_tkn_chkr)new Xop_tblw_tc_tkn_chkr().Src_rng_(bgn, end);} + public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);} + public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);} + public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);} + public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid__br);} + public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);} + public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);} + public Xop_tkn_chkr_base tkn_curly_bgn_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tmpl_curly_bgn).Src_rng_(bgn, bgn + 2);} + public Xop_tkn_chkr_base tkn_para_blank_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_none);} + public Xop_tkn_chkr_base tkn_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_pre);} + public Xop_tkn_chkr_base tkn_para_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_para);} + public Xop_tkn_chkr_base tkn_para_mid_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_para);} + public Xop_tkn_chkr_base tkn_para_end_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_none);} + public Xop_tkn_chkr_base tkn_para_end_pre_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_para);} + public Xop_tkn_chkr_base tkn_para_end_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_pre);} + public Xop_tkn_chkr_base tkn_para_end_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_none);} + public Xop_tkn_chkr_base tkn_para_(int pos, byte end, byte bgn) {return new Xop_para_tkn_chkr().Para_end_(end).Para_bgn_(bgn).Src_rng_(pos, pos);} + public Xop_tkn_chkr_base tkn_nl_char_(int bgn, int end) {return tkn_nl_(bgn, end, Xop_nl_tkn.Tid_char);} + public Xop_tkn_chkr_base tkn_nl_char_len1_(int bgn) {return tkn_nl_(bgn, bgn + 1, Xop_nl_tkn.Tid_char);} + public Xop_tkn_chkr_base tkn_nl_char_len0_(int pos) {return tkn_nl_(pos, pos, Xop_nl_tkn.Tid_char);} + public Xop_tkn_chkr_base tkn_nl_(int bgn, int end, byte tid) {return new Xop_nl_tkn_chkr().Nl_tid_(tid).Src_rng_(bgn, end);} + public Xop_list_tkn_chkr tkn_list_bgn_(int bgn, int end, byte listType) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().List_itmTyp_(listType).Src_rng_(bgn, end);} + public Xop_list_tkn_chkr tkn_list_end_(int pos) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().Src_rng_(pos, pos);} + public Xop_tkn_chkr_lnke tkn_lnke_(int bgn, int end) {return new Xop_tkn_chkr_lnke(bgn, end);} + public Xop_lnki_tkn_chkr tkn_lnki_() {return tkn_lnki_(-1, -1);} + public Xop_lnki_tkn_chkr tkn_lnki_(int bgn, int end) {return (Xop_lnki_tkn_chkr)new Xop_lnki_tkn_chkr().Src_rng_(bgn, end);} + public Xop_arg_itm_tkn_chkr tkn_arg_itm_(Xop_tkn_chkr_base... subs) {return (Xop_arg_itm_tkn_chkr)new Xop_arg_itm_tkn_chkr().Subs_(subs);} + public Xop_arg_nde_tkn_chkr tkn_arg_nde_() {return tkn_arg_nde_(String_.Pos_neg1, String_.Pos_neg1);} + public Xop_arg_nde_tkn_chkr tkn_arg_nde_(int bgn, int end) {return (Xop_arg_nde_tkn_chkr)new Xop_arg_nde_tkn_chkr().Src_rng_(bgn, end);} + public Xop_arg_nde_tkn_chkr tkn_arg_val_(Xop_tkn_chkr_base... subs) { + Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr(); + Xop_arg_itm_tkn_chkr val = new Xop_arg_itm_tkn_chkr(); + val.Subs_(subs); + rv.Val_tkn_(val); + return rv; + } + public Xop_arg_nde_tkn_chkr tkn_arg_val_txt_(int bgn, int end) { + Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr(); + Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr(); + rv.Val_tkn_(itm); + itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end)); + return rv; + } + Xop_arg_nde_tkn_chkr tkn_arg_key_txt_(int bgn, int end) { + Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr(); + Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr(); + rv.Key_tkn_(itm); + itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end)); + return rv; + } + public Xot_invk_tkn_chkr tkn_tmpl_invk_(int bgn, int end) {return (Xot_invk_tkn_chkr)new Xot_invk_tkn_chkr().Src_rng_(bgn, end);} + public Xot_invk_tkn_chkr tkn_tmpl_invk_w_name(int bgn, int end, int name_bgn, int name_end) { + Xot_invk_tkn_chkr rv = new Xot_invk_tkn_chkr(); + rv.Src_rng_(bgn, end); + rv.Name_tkn_(tkn_arg_key_txt_(name_bgn, name_end)); + return rv; + } + public Xot_prm_chkr tkn_tmpl_prm_find_(Xop_tkn_chkr_base find) { + Xot_prm_chkr rv = new Xot_prm_chkr(); + rv.Find_tkn_(tkn_arg_itm_(find)); + return rv; + } + public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;} + public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;} + public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.New(); + public void Init_defn_add(String name, String text) {Init_defn_add(name, text, Xow_ns_case_.Tid__all);} + public void Init_defn_add(String name, String text, byte case_match) { + Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.new_a7(name), Bry_.new_u8(text)); + wiki.Cache_mgr().Defn_cache().Add(itm, case_match); + } + public void Init_defn_clear() {wiki.Cache_mgr().Defn_cache().Free_mem_all();} + public Xop_fxt Init_id_create(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Xow_hive_mgr_fxt.Create_id(app, wiki.Hive_mgr(), id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;} + public Xop_fxt Init_page_create(String ttl) {return Init_page_create(wiki, ttl, "");} + public Xop_fxt Init_page_create(String ttl, String txt) {return Init_page_create(wiki, ttl, txt);} + public Xop_fxt Init_page_create(Xowe_wiki wiki, String ttl, String txt) {Init_page_create_static(wiki, ttl, txt);return this;} + public static void Init_page_create_static(Xowe_wiki wiki, String ttl_str, String text_str) { + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)); + byte[] text = Bry_.new_u8(text_str); + wiki.Db_mgr().Save_mgr().Data_create(wiki, ttl, text); + } + public static void Init_msg(Xowe_wiki wiki, String key, String val) { + wiki.Lang().Msg_mgr().Itm_by_key_or_new(key, val); + } + public Xop_fxt Init_page_update(String ttl, String txt) {return Init_page_update(wiki, ttl, txt);} + public Xop_fxt Init_page_update(Xowe_wiki wiki, String ttl, String txt) { + Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl)); + byte[] page_raw = Bry_.new_u8(txt); + Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_ttl); + wiki.Db_mgr().Save_mgr().Data_update(page, page_raw); + return this; + } + public Xop_fxt Init_xwiki_clear() { + wiki.Xwiki_mgr().Clear(); + app.Usere().Wiki().Xwiki_mgr().Clear(); + return this; + } + public Xop_fxt Init_xwiki_add_wiki_and_user_(String alias, String domain) { + wiki.Xwiki_mgr().Add_by_atrs(alias, domain); + app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain); + return this; + } + public Xop_fxt Init_xwiki_add_user_(String domain) {return Init_xwiki_add_user_(domain, domain);} + public Xop_fxt Init_xwiki_add_user_(String alias, String domain) { + app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(alias, domain); + return this; + } + public void Test_parse_template(String tmpl_raw, String expd) {Test_parse_tmpl_str_test(tmpl_raw, "{{test}}", expd);} + public void Test_parse_tmpl_str_test(String tmpl_raw, String page_raw, String expd) { + Init_defn_add("test", tmpl_raw); + Test_parse_tmpl_str(page_raw, expd); + } + public void Test_parse_tmpl_str(String raw, String expd) { + byte[] actl = Test_parse_tmpl_str_rv(raw); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + tst_Log_check(); + } + public byte[] Test_parse_tmpl_str_rv(String raw) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + ctx.Page().Root_(root); + ctx.Page().Db().Text().Text_bry_(raw_bry); + return parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry); + } + public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);} + public void Test_parse_tmpl(String raw, Tst_chkr... expd) { + byte[] raw_bry = Bry_.new_u8(raw); + Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.Empty, raw_bry); + Parse_chk(raw_bry, itm.Root(), expd); + } + public void Test_parse_page_tmpl_str(String raw, String expd) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + byte[] actl = parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry); + Tfds.Eq(expd, String_.new_u8(actl)); + tst_Log_check(); + } + public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry); + return root; + } + public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry); + Parse_chk(raw_bry, root, expd_ary); + } + public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = Test_parse_page_wiki_root(raw_bry); + Parse_chk(raw_bry, root, expd_ary); + } + public Xop_root_tkn Test_parse_page_wiki_root(String raw) {return Test_parse_page_wiki_root(Bry_.new_u8(raw));} + Xop_root_tkn Test_parse_page_wiki_root(byte[] raw_bry) { + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos); + return root; + } + public void Test_parse_page_all(String raw, Tst_chkr... expd_ary) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw)); + Parse_chk(raw_bry, root, expd_ary); + } + public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);} + public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));} + public void Test_parse_page_all_str(String raw, String expd) { + String actl = Exec_parse_page_all_as_str(raw); + Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw); + } + public void Test_parse_page_all_str_and_chk(String raw, String expd, Gfo_msg_itm... ary) { + this.Init_log_(ary); + Test_parse_page_all_str(raw, expd); + this.tst_Log_check(); + } + public Xop_root_tkn Exec_parse_page_all_as_root(byte[] raw_bry) { + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + parser.Parse_page_all_clear(root, ctx, tkn_mkr, raw_bry); + return root; + } + public String Exec_parse_page_all_as_str(String raw) { + Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw)); + Bry_bfr actl_bfr = Bry_bfr_.New(); + hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root); + return actl_bfr.To_str_and_clear(); + } + public Xoh_wtr_ctx Hctx() {return hctx;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic; + public void Hctx_(Xoh_wtr_ctx v) {hctx = v;} + public String Exec_parse_page_wiki_as_str(String raw) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = tkn_mkr.Root(raw_bry); + parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos); + Bry_bfr actl_bfr = Bry_bfr_.New(); + hdom_wtr.Write_doc(actl_bfr, ctx, hctx, raw_bry, root); + return actl_bfr.To_str_and_clear(); + } + private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) { + int subs_len = root.Subs_len(); + Object[] actl_ary = new Object[subs_len]; + for (int i = 0; i < subs_len; i++) + actl_ary[i] = root.Subs_get(i); + tst_mgr.Vars().Clear().Add("raw_bry", raw_bry); + tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary); + tst_Log_check(); + } + public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));} + public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) { + String actl = Exec_parse_page_wiki_as_str(raw); + Tfds.Eq_str_lines(expd, actl, raw); + return this; + } + public void Log_clear() {ctx.App().Msg_log().Clear();} + public String[] Log_xtoAry() { + Gfo_msg_log msg_log = app.Msg_log(); + int len = msg_log.Ary_len(); + List_adp actl_list = List_adp_.New(); + for (int i = 0; i < len; i++) { + Gfo_msg_data eny = msg_log.Ary_get(i); + if (eny.Item().Cmd() > Gfo_msg_itm_.Cmd_note) { + actl_list.Add(String_.new_u8(eny.Item().Path_bry())); + } + } + String[] actl = actl_list.To_str_ary(); + msg_log.Clear(); + return actl; + } + public Xop_fxt tst_Log_check() { + int len = log_itms.Count(); + String[] expd = new String[len]; + for (int i = 0; i < len; i++) { + Gfo_msg_itm itm = (Gfo_msg_itm)log_itms.Get_at(i); + expd[i] = itm.Path_str(); + } + log_itms.Clear(); + String[] actl = Log_xtoAry(); + Tfds.Eq_ary_str(expd, actl); + return this; + } + public void tst_Warn(String... expd) { + Gfo_usr_dlg usr_dlg = app.Usr_dlg(); + Gfo_usr_dlg__gui_test ui_wkr = (Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr(); + String[] actl = ui_wkr.Warns().To_str_ary(); + Tfds.Eq_ary_str(expd, actl); + } + public void Test_parse_page(String ttl, String expd) { + byte[] actl = Load_page(wiki, ttl); + Tfds.Eq(expd, String_.new_u8(actl)); + } + public static byte[] Load_page(Xowe_wiki wiki, String ttl_str) { + byte[] ttl_bry = Bry_.new_u8(ttl_str); + Xoa_url page_url = Xoa_url.New(wiki.Domain_bry(), ttl_bry); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry); + return wiki.Data_mgr().Load_page_and_parse(page_url, ttl).Db().Text().Text_bry(); + } + public static void Reg_xwiki_alias(Xowe_wiki wiki, String alias, String domain) { + byte[] domain_bry = Bry_.new_a7(domain); + wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_a7(alias), domain_bry, Bry_.Add(domain_bry, Bry_.new_a7("/wiki/~{0}"))); + wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain_bry, domain_bry); + } + public static String html_img_none(String trg, String alt, String src, String ttl) { + return String_.Format(String_.Concat_lines_nl_skip_last("\"{1}\""), trg, alt, src, ttl); + } + private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);} + private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);} + public void Test_html_wiki_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_wiki(raw));} + public void Test_html_full_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_full(raw));} + public void Test_html_wiki_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_wiki(raw), expd_frags);} + public void Test_html_full_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_full(raw), expd_frags);} + public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);} + public void Test__parse__tmpl_to_html(String raw, String expd) {Test_str_full(raw, gplx.langs.htmls.Gfh_utl.Replace_apos(expd), Exec_html_full(raw));} + public void Test__parse__wtxt_to_html(String raw, String expd) { + String actl = Exec_html_wiki(raw); + Tfds.Eq_str_lines(gplx.langs.htmls.Gfh_utl.Replace_apos(expd), actl, raw); + } + + public void Test_str_full(String raw, String expd, String actl) { + Tfds.Eq_str_lines(expd, actl, raw); + } + public void Test_str_part_y(String actl, String... expd_parts) { + int expd_parts_len = expd_parts.length; + for (int i = 0; i < expd_parts_len; i++) { + String expd_part = expd_parts[i]; + boolean pass = String_.Has(actl, expd_part); + if (!pass) + Tfds.Eq_true(false, expd_part + "\n" + actl); + } + } + private void Test_str_part_n(String actl, String... expd_parts) { + int expd_parts_len = expd_parts.length; + for (int i = 0; i < expd_parts_len; i++) { + String expd_part = expd_parts[i]; + boolean has = String_.Has(actl, expd_part); + if (has) + Tfds.Eq_true(false, expd_part + "\n" + actl); + } + } + public void Test_html_modules_js(String expd) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004(); + this.Page().Html_data().Head_mgr().Init(app, wiki, this.Page()); + this.Page().Html_data().Head_mgr().Bfr_arg__add(bfr); + bfr.Mkr_rls(); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + + private Tst_mgr tst_mgr = new Tst_mgr(); private Xop_tkn_mkr tkn_mkr; + public static final String Ttl_str = "Test page"; + public Xop_fxt Init_lang_numbers_separators_en() {return Init_lang_numbers_separators(",", ".");} + public Xop_fxt Init_lang_numbers_separators(String grp_spr, String dec_spr) {return Init_lang_numbers_separators(wiki.Lang(), grp_spr, dec_spr);} + public Xop_fxt Init_lang_numbers_separators(Xol_lang_itm lang, String grp_spr, String dec_spr) { + gplx.xowa.langs.numbers.Xol_transform_mgr separator_mgr = lang.Num_mgr().Separators_mgr(); + separator_mgr.Clear(); + separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_u8(grp_spr)); + separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__dec, Bry_.new_u8(dec_spr)); + return this; + } + public void Init_lang_kwds(int kwd_id, boolean case_match, String... kwds) {Init_lang_kwds(wiki.Lang(), kwd_id, case_match, kwds);} + public void Init_lang_kwds(Xol_lang_itm lang, int kwd_id, boolean case_match, String... kwds) { + Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr(); + Xol_kwd_grp kwd_grp = kwd_mgr.Get_or_new(kwd_id); + kwd_grp.Srl_load(case_match, Bry_.Ary(kwds)); + } + public void Init_lang_vnts(String... vnts) { + wiki.Lang().Vnt_mgr().Enabled_(true); + gplx.xowa.langs.vnts.Xol_vnt_regy vnt_regy = wiki.Lang().Vnt_mgr().Regy(); + for (int i = 0; i < vnts.length; i++) { + byte[] vnt = Bry_.new_u8(vnts[i]); + vnt_regy.Add(vnt, vnt); + if (i == 0) { + wiki.Lang().Vnt_mgr().Cur_itm_(vnt); + } + } + wiki.Lang().Vnt_mgr().Init_end(); + } + public void Init_xtn_pages() { + Io_mgr.Instance.InitEngine_mem(); + wiki.Xtn_mgr().Xtn_proofread().Enabled_y_(); + wiki.Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory; + wiki.Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init(); + } + public void Clear_ref_mgr() {this.Page().Ref_mgr().Grps_clear();} // clear to reset count + public static Xop_fxt new_nonwmf() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + return new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit__nonwmf(app, "nethackwiki")); + } + private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255); + public String Exec__parse_to_hdump(String src_str) { + byte[] src_bry = Bry_.new_u8(src_str); + Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry); + Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump; + Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr(); + html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show + ctx.Page().Html_data().Redlink_list().Clear(); + html_wtr.Write_doc(tmp_bfr, ctx, hctx, src_bry, root); + // Tfds.Dbg(tmp_bfr.To_str()); + return tmp_bfr.To_str_and_clear(); + } + public void Test__parse_to_html_mgr(String src_str, String expd) { + byte[] src_bry = Bry_.new_u8(src_str); + Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry); + Xoae_page page = this.Page(); + page.Root_(root); + byte[] actl = wiki.Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } + public String Exec__parse_to_html_w_skin(String raw) { + Bry_bfr bfr = Bry_bfr_.New(); + Xow_html_mgr html_mgr = wiki.Html_mgr(); + this.Wiki().Html__wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}"); + + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = this.Exec_parse_page_all_as_root(raw_bry); + this.Page().Root_(root); + + html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, this.Page(), this.Ctx(), Xoh_page_html_source_.Wtr); + return bfr.To_str_and_clear(); + } + public void Test__parse_to_html_w_skin(String raw, String expd) { + Tfds.Eq_str_lines(expd, Exec__parse_to_html_w_skin(raw)); + } + public static Xop_fxt New_app_html() { + Xop_fxt fxt = new Xop_fxt(); + fxt.Wiki().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}"); + return fxt; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/cfgs/mgrs/caches/Xocfg_cache_mgr__tst.java b/400_xowa/src/gplx/xowa/addons/apps/cfgs/mgrs/caches/Xocfg_cache_mgr__tst.java new file mode 100644 index 000000000..e154c12ea --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/cfgs/mgrs/caches/Xocfg_cache_mgr__tst.java @@ -0,0 +1,78 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*; +import org.junit.*; import gplx.core.tests.*; import gplx.dbs.*; +import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.specials.maints.services.*; +public class Xocfg_cache_mgr__tst { + private final Xocfg_cache_mgr__fxt fxt = new Xocfg_cache_mgr__fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Get__wiki() { + fxt.Init__db_add("en.w", "key_1", "val_1"); + fxt.Test__get("en.w", "key_1", "val_1"); + fxt.Test__get("en.d", "key_1", "dflt"); + } + @Test public void Get__app() { + String ctx = Xocfg_mgr.Ctx__app; + fxt.Init__db_add(ctx, "key_1", "val_1"); + fxt.Test__get(ctx, "key_1", "val_1"); + fxt.Test__get("en.w", "key_1", "val_1"); + fxt.Test__get("en.d", "key_1", "val_1"); + } + @Test public void Set__app() { + String ctx = Xocfg_mgr.Ctx__app; + fxt.Init__db_add(ctx, "key_1", "123"); + fxt.Init__sub(ctx, "key_1", "key_1"); + fxt.Exec__set(ctx, "key_1", "234"); + fxt.Test__get(ctx, "key_1", "234"); + fxt.Sub().Test__key_1(234); + } +} +class Xocfg_cache_mgr__fxt { + private Xocfg_cache_mgr mgr = new Xocfg_cache_mgr(); + private int id; + public void Clear() { + gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem(); + Db_conn conn = Db_conn_bldr.Instance.Get_or_autocreate(true, Io_url_.new_any_("mem/xowa/wiki/en.wikipedia.org/")); + mgr.Init_by_app(conn, conn); + } + public Xocfg_cache_sub_mock Sub() {return sub;} private Xocfg_cache_sub_mock sub = new Xocfg_cache_sub_mock(); + public void Init__db_add(String ctx, String key, Object val) { + Xocfg_maint_svc.Create_grp(mgr.Db_app(), "", id++, "test_grp", "", ""); + Xocfg_maint_svc.Create_itm(mgr.Db_app(), "test_grp", id++, key, "", "", "wiki", String_.Cls_val_name, "dflt", "", ""); + mgr.Db_usr().Set_str(ctx, key, Object_.Xto_str_strict_or_null(val)); + } + public void Init__sub(String ctx, String key, String evt) { + mgr.Sub(sub, ctx, key, evt); + } + public void Test__get(String ctx, String key, String expd) { + Gftest.Eq__str(expd, mgr.Get(ctx, key), "ctx={0} key={1}", ctx, key); + } + public void Exec__set(String ctx, String key, String val) { + mgr.Set(ctx, key, val); + } +} +class Xocfg_cache_sub_mock implements Gfo_invk { + private int key_1; + public void Test__key_1(int expd) { + Gftest.Eq__int(expd, key_1); + } + public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { + if (ctx.Match(k, Evt__key_1)) {key_1 = m.ReadInt("v");} + else return Gfo_invk_.Rv_unhandled; + return this; + } + public static final String Evt__key_1 = "key_1"; +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/cfgs/specials/maints/services/Xocfg_maint_parser__tst.java b/400_xowa/src/gplx/xowa/addons/apps/cfgs/specials/maints/services/Xocfg_maint_parser__tst.java new file mode 100644 index 000000000..b184bc185 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/cfgs/specials/maints/services/Xocfg_maint_parser__tst.java @@ -0,0 +1,43 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*; +import org.junit.*; import gplx.core.tests.*; +public class Xocfg_maint_parser__tst { + private final Xocfg_maint_parser__fxt fxt = new Xocfg_maint_parser__fxt(); + @Test public void Parse_grp() { + fxt.Exec__parse("grp {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'}" + , fxt.Make__grp("owner_1", 123, "key_1", "name_1", "help_1") + ); + } + @Test public void Parse_itm() { + fxt.Exec__parse("itm {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'; scope='scope_1'; type='type_1'; dflt='dflt_1'; html_atrs='html_atrs_1'; html_cls='html_cls_1'}" + , fxt.Make__itm("owner_1", 123, "key_1", "name_1", "help_1", "scope_1", "type_1", "dflt_1", "html_atrs_1", "html_cls_1") + ); + } +} +class Xocfg_maint_parser__fxt { + private Xocfg_maint_parser parser = new Xocfg_maint_parser(); + public void Exec__parse(String raw, Xocfg_maint_nde... expd) { + Xocfg_maint_nde[] actl = parser.Parse(raw); + Gftest.Eq__ary(expd, actl); + } + public Xocfg_maint_grp Make__grp(String owner, int id, String key, String name, String help) { + return new Xocfg_maint_grp(owner, id, key, name, help); + } + public Xocfg_maint_itm Make__itm(String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) { + return new Xocfg_maint_itm(owner, id, key, name, help, scope, type, dflt, html_atrs, html_cls); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/apps/cfgs/upgrades/Xocfg_upgrade_mgr__tst.java b/400_xowa/src/gplx/xowa/addons/apps/cfgs/upgrades/Xocfg_upgrade_mgr__tst.java new file mode 100644 index 000000000..9ad15c544 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/cfgs/upgrades/Xocfg_upgrade_mgr__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; +import org.junit.*; import gplx.core.tests.*; +public class Xocfg_upgrade_mgr__tst { + private final Xocfg_upgrade_mgr__fxt fxt = new Xocfg_upgrade_mgr__fxt(); + @Test public void Parse__one() { + fxt.Test__parse("app.cfgs.get('k_1', 'app').val = 'v_1';\n", Keyval_.new_("k_1", "v_1")); + } + @Test public void Parse__apos() { + fxt.Test__parse("app.cfgs.get('k_1(''k_1a'')', 'app').val = 'v_1';\n", Keyval_.new_("k_1('k_1a')", "v_1")); + } + @Test public void Parse__many() { + fxt.Test__parse + ( "app.cfgs.get('k_1', 'app').val = 'v_1';\n" + + "app.cfgs.get('k_2', 'app').val = 'v_2';\n" + , Keyval_.new_("k_1", "v_1"), Keyval_.new_("k_2", "v_2")); + } + @Test public void Parse__multi_line() { + fxt.Test__parse + ( "app.cfgs.get('k_1', 'app').val = '''v_1'';\n" + + "v_2\n" + + "v_3';\n" + , Keyval_.new_("k_1", "'v_1';\nv_2\nv_3")); + } + @Test public void Parse__io_cmd() { + fxt.Test__parse + ( "app.cfgs.get('a.cmd', 'app').val = 'cmd_1';\n" + + "app.cfgs.get('a.args', 'app').val = 'args_1';\n" + , Keyval_.new_("a.cmd", "cmd_1|args_1")); + } + @Test public void Parse__gui_binding() { + fxt.Test__parse + ( "app.cfgs.get('app.cfg.get.gui.bnds.init(''xowa.app.exit-1'').src', 'app').val = 'box=''browser'';ipt=''key.none'';';\n" + , Keyval_.new_("xowa.gui.shortcuts.xowa.app.exit-1", "browser|key.none")); + } +} +class Xocfg_upgrade_mgr__fxt { + public void Test__parse(String raw, Keyval... expd) { + Keyval[] actl = Xocfg_upgrade_mgr.Parse(Bry_.new_u8(raw)); + Gftest.Eq__str(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl)); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/apps/scripts/apis/Xoscript_doc_head__tst.java b/400_xowa/src/gplx/xowa/addons/apps/scripts/apis/Xoscript_doc_head__tst.java new file mode 100644 index 000000000..a9ef53981 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/scripts/apis/Xoscript_doc_head__tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoscript_doc_head__tst { + private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt(); + @Before public void init() { + fxt.Init__sect("head"); + fxt.Exec__reg_marker("", "top", Xoscript_doc_head.Pos__default); + fxt.Exec__reg_marker("", "bot"); + fxt.Exec__doc__html("abc"); + } + @Test public void Add_html() { + fxt.Exec__add_html("top", "add_1"); + fxt.Exec__add_html("top", "add_2"); + fxt.Test__html("aadd_1add_2bc"); + } + @Test public void Add_html__default() { + fxt.Exec__add_html("add_1"); + fxt.Test__html("aadd_1bc"); + } + @Test public void Add_tag() { + fxt.Exec__add_tag("top", "div", "div_body", "k0", "v0", "k1", "v1"); + fxt.Test__html + ( "a
div_body
" + , "bc"); + } + @Test public void Add_js_file() { + fxt.Exec__add_js_file("top", "./a.js"); + fxt.Test__html + ( "a" + , "bc"); + } +} +class Xoscript_doc_head__fxt { + private final Xoscript_page spg; + private Xoscript_doc_sect_base sect; + public Xoscript_doc_head__fxt() { + Bry_bfr rv = Bry_bfr_.New(); + Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/")); + Xoscript_url url = new Xoscript_url("test_wiki", "test_page"); + spg = new Xoscript_page(rv, env, url); + } + public void Init__sect(String sect_name) { + if (String_.Eq(sect_name, "head")) + sect = spg.doc().head(); + else if (String_.Eq(sect_name, "tail")) + sect = spg.doc().tail(); + } + public void Exec__doc__html(String html) {spg.doc().html(html);} + public void Exec__reg_marker(String marker, String... pos_ary) {sect.reg_marker(marker, pos_ary);} + public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);} + public void Exec__add_html(String html) {sect.add_html(html);} + public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);} + public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);} + public void Test__html(String... expd) { + Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html"); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/apps/updates/specials/svcs/Xoa_update_svc__tst.java b/400_xowa/src/gplx/xowa/addons/apps/updates/specials/svcs/Xoa_update_svc__tst.java new file mode 100644 index 000000000..13c6bd646 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/apps/updates/specials/svcs/Xoa_update_svc__tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.apps.updates.specials.svcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*; import gplx.xowa.addons.apps.updates.specials.*; +import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*; +public class Xoa_update_svc__tst { + private final Xoa_update_svc__fxt fxt = new Xoa_update_svc__fxt(); + @Test public void Restart_cmd() { + Io_url jar_fil = Io_url_.new_dir_("/home/gnosygnu/xowa/xowa.jar"); + fxt.Test__restart_cmd("manual" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "manual"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_linux_64.sh"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_lnx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_linux.sh"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_64, "sh /home/gnosygnu/xowa/xowa_macosx_64"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_osx, Op_sys.Bitness_32, "sh /home/gnosygnu/xowa/xowa_macosx"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_64, "/home/gnosygnu/xowa/xowa_64.exe"); + fxt.Test__restart_cmd("" , jar_fil, Op_sys.Tid_wnt, Op_sys.Bitness_32, "/home/gnosygnu/xowa/xowa.exe"); + } +} +class Xoa_update_svc__fxt { + public void Test__restart_cmd(String current, Io_url app_url, byte op_sys_tid, byte bitness, String expd) { + Gftest.Eq__str(expd, Xoa_update_svc.App__update__restart_cmd(current, app_url, op_sys_tid, bitness), "restart_cmd"); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/app_cfgs/Xob_wiki_cfg_bldr_tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/app_cfgs/Xob_wiki_cfg_bldr_tst.java new file mode 100644 index 000000000..475408e43 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/app_cfgs/Xob_wiki_cfg_bldr_tst.java @@ -0,0 +1,177 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.app_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; +import org.junit.*; import gplx.core.strings.*; +public class Xob_wiki_cfg_bldr_tst { + Xob_wiki_cfg_bldr_fxt fxt = new Xob_wiki_cfg_bldr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Exec() { + fxt .Init_cmd("en.wikipedia.org", "key0", "en.val0") + .Init_cmd("en.wikipedia.org", "key1", "en.val1") + .Init_cmd("fr.wikipedia.org", "key0", "fr.val0") + .Init_cmd("fr.wikipedia.org", "key1", "fr.val1") + .Expd_txt("en.wikipedia.org", String_.Concat_lines_nl + ( "// key0.bgn" + , "en.val0" + , "// key0.end" + , "// key1.bgn" + , "en.val1" + , "// key1.end" + )) + .Expd_txt("fr.wikipedia.org", String_.Concat_lines_nl + ( "// key0.bgn" + , "fr.val0" + , "// key0.end" + , "// key1.bgn" + , "fr.val1" + , "// key1.end" + )) + .Test() + ; + fxt .Clear() + .Init_cmd("en.wikipedia.org", "key2", "en.val2") + .Expd_txt("en.wikipedia.org", String_.Concat_lines_nl + ( "// key0.bgn" + , "en.val0" + , "// key0.end" + , "// key1.bgn" + , "en.val1" + , "// key1.end" + , "// key2.bgn" + , "en.val2" + , "// key2.end" + )); + } +// @Test public void Lang_names_run() { +// Io_url dir = Io_url_.new_dir_("/var/www/mediawiki/languages/messages/"); +// Io_url[] fils = Io_mgr.Instance.QueryDir_args(dir).ExecAsUrlAry(); +// int fils_len = fils.length; +// String_bldr sb = String_bldr_.new_(); +// for (int i = 0; i < fils_len; i++) { +// Io_url fil = fils[i]; +// String lang_code = String_.Lower(String_.Replace(fil.NameOnly(), "Messages", "")); +// String txt = Io_mgr.Instance.LoadFilStr(fil); +// String[] lines = String_.Split(txt, '\n'); +// String line = lines[1]; +// line = String_.Replace(line, "/** ", ""); +// int pos = String_.FindBwd(line, " ("); +// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line +// if ( String_.Has_at_bgn(lang_code, "be_") +// || String_.Has_at_bgn(lang_code, "crh_") +// || String_.Has_at_bgn(lang_code, "kk_") +// || String_.Has_at_bgn(lang_code, "ku_") +// || String_.Has_at_bgn(lang_code, "sr_") +// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no") +// ) { +// int new_pos = String_.FindBwd(line, " (", pos - 1); +// if (new_pos != String_.Find_none) +// pos = new_pos; +// } +// line = Replace_by_pos(line, pos, pos + 2, "|"); +// int line_len = String_.Len(line); +// if (line_len > 0) +// line = String_.MidByLen(line, 0, line_len - 1); +// String[] terms = String_.Split(line, '|'); +// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n"); +// } +// Tfds.Dbg(sb.To_str_and_clear()); +// } + @Test public void Ns_aliases() { + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl + ( "" + , "" + , "" + , "WP" + , "" + , "WT" + , "" + , "Image" + , "" + , "Image talk" + , "" + , "" + , "" + , "" + )); + String[] wikis = new String[] {"en.wikipedia.org"}; String protocol = "mem/"; + Tfds.Eq_str_lines(Query_ns(protocol, gplx.core.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl + ( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"" + , "4|WP" + , "5|WT" + , "6|Image" + , "7|Image_talk" + , "\");');" + )); + } + String Query_ns(String protocol, String trg_engine_key, String[] wikis) { + String_bldr sb = String_bldr_.new_(); + int wikis_len = wikis.length; + for (int i = 0; i < wikis_len; i++) { + String wiki = wikis[i]; + if (String_.Len_eq_0(wiki)) continue; + try { + String api = protocol + wiki + "/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases"; + String xml = String_.new_u8(Io_mgr.Instance.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api)); + if (xml == null) continue; // not found + gplx.langs.xmls.XmlDoc xdoc = gplx.langs.xmls.XmlDoc_.parse(xml); + gplx.langs.xmls.XmlNde xnde = gplx.langs.xmls.Xpath_.SelectFirst(xdoc.Root(), "query/namespacealiases"); + sb.Add("app.bldr.wiki_cfg_bldr.get('").Add(wiki).Add("').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"\n"); + int xndes_len = xnde.SubNdes().Count(); + for (int j = 0; j < xndes_len; j++) { + gplx.langs.xmls.XmlNde ns_nde = xnde.SubNdes().Get_at(j); + if (!String_.Eq(ns_nde.Name(), "ns")) continue; + int id = Int_.Parse(ns_nde.Atrs().FetchValOr("id", "-1")); + String name = String_.Replace(String_.Replace(ns_nde.Text_inner(), " ", "_"), "'", "''"); + sb.Add(Int_.To_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl(); + } + sb.Add("\");');\n"); + } + catch(Exception e) {sb.Add("// fail: " + wiki + " " + Err_.Message_gplx_full(e)).Add_char_nl();} + } + return sb.To_str_and_clear(); + } +} +class Xob_wiki_cfg_bldr_fxt { + public Xob_wiki_cfg_bldr_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki_cfg_bldr = app.Bldr().Wiki_cfg_bldr(); + } + wiki_cfg_bldr.Clear(); + hash.Clear(); + return this; + } private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.New(); + public Xob_wiki_cfg_bldr_fxt Init_cmd(String wiki, String key, String text) { + wiki_cfg_bldr.Itms_get_or_new(wiki).Itms_add(key, text); + return this; + } + public Xob_wiki_cfg_bldr_fxt Expd_txt(String wiki, String text) { + hash.Add(wiki, Keyval_.new_(wiki, text)); + return this; + } + public void Test() { + wiki_cfg_bldr.Exec(); + int len = hash.Count(); + for (int i = 0; i < len; i++) { + Keyval kv = (Keyval)hash.Get_at(i); + String wiki = kv.Key(); + String expd = (String)kv.Val(); + String actl = Io_mgr.Instance.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs")); + Tfds.Eq_str_lines(expd, actl); + } + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/centrals/hosts/Host_eval_wkr__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/centrals/hosts/Host_eval_wkr__tst.java new file mode 100644 index 000000000..43f423117 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/centrals/hosts/Host_eval_wkr__tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.centrals.hosts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*; +public class Host_eval_wkr__tst { + private final Host_eval_wkr__fxt fxt = new Host_eval_wkr__fxt(); + @Test public void En_w() {fxt.Test__resolve_quick("en.wikipedia.org" , "Xowa_enwiki_latest");} + @Test public void Fr_d() {fxt.Test__resolve_quick("fr.wiktionary.org" , "Xowa_frwiki_latest");} + @Test public void Species() {fxt.Test__resolve_quick("species.wikimedia.org" , "Xowa_enwiki_latest");} +} +class Host_eval_wkr__fxt { + public void Test__resolve_quick(String domain_str, String expd) { + Host_eval_itm eval_itm = new Host_eval_itm(); + Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str)); + Gftest.Eq__bry(Bry_.new_u8(expd), eval_itm.Eval_dir_name(domain_itm)); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/centrals/utils/Time_dhms__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/centrals/utils/Time_dhms__tst.java new file mode 100644 index 000000000..796f0da71 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/centrals/utils/Time_dhms__tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.centrals.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*; +import org.junit.*; import gplx.core.tests.*; +public class Time_dhms__tst { + private final Time_dhms__fxt fxt = new Time_dhms__fxt(); + @Test public void S__0() {fxt.Test__to_str( 0, 4, "0 s");} + @Test public void S__1() {fxt.Test__to_str( 1, 4, "1 s");} + @Test public void S__2() {fxt.Test__to_str( 30, 4, "30 s");} + @Test public void M__1() {fxt.Test__to_str( 60, 4, "1:00 m");} + @Test public void M__2() {fxt.Test__to_str( 600, 4, "10:00 m");} + @Test public void H__1() {fxt.Test__to_str( 3600, 4, "1:00:00 h");} + @Test public void H__2() {fxt.Test__to_str( 5025, 4, "1:23:45 h");} + @Test public void D__1() {fxt.Test__to_str( 86400, 4, "1:00:00:00 d");} + @Test public void Max_places() {fxt.Test__to_str( 86400, 2, "1:00 d");} +} +class Time_dhms__fxt { + private final Bry_bfr bfr = Bry_bfr_.New(); + public Time_dhms__fxt Test__to_str(long v, int max_places, String expd) { + Gftest.Eq__str(expd, Time_dhms_.To_str(bfr, v, Bool_.Y, max_places)); + return this;} +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/exports/packs/files/Pack_zip_name_bldr__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/exports/packs/files/Pack_zip_name_bldr__tst.java new file mode 100644 index 000000000..12db35412 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/exports/packs/files/Pack_zip_name_bldr__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*; +import org.junit.*; import gplx.core.tests.*; +public class Pack_zip_name_bldr__tst { + private Pack_zip_name_bldr__fxt fxt = new Pack_zip_name_bldr__fxt(); + @Test public void Basic() { + fxt.Test__to_wiki_url("mem/wiki/en.wikipedia.org/", "mem/wiki/en.wikipedia.org/tmp/Xowa_enwiki_2016-09_file_deletion_2016.09/", "mem/wiki/en.wikipedia.org/en.wikipedia.org-file-deletion-2016.09.xowa"); + } + @Test public void Bld_by_suffix() { + Pack_zip_name_bldr bldr = fxt.Make__bldr("mem/wiki/en.wikipedia.org/tmp/pack/", "en.wikipedia.org", "enwiki", "2017-03", null); + fxt.Test__bld_by_suffix(bldr, "xtn.fulltext_search", 1, "mem/wiki/en.wikipedia.org/tmp/pack/Xowa_enwiki_2017-03_xtn.fulltext_search.002.zip"); + } +} +class Pack_zip_name_bldr__fxt { + public void Test__to_wiki_url(String wiki_dir, String zip_fil, String expd) { + Gftest.Eq__str(expd, Pack_zip_name_bldr.To_wiki_url(Io_url_.mem_fil_(wiki_dir), Io_url_.mem_dir_(zip_fil)).Raw(), "wiki_url"); + } + + public Pack_zip_name_bldr Make__bldr(String wiki_dir, String domain, String wiki_abrv, String wiki_date, String custom_name) { + return new Pack_zip_name_bldr(Io_url_.new_dir_(wiki_dir), domain, wiki_abrv, wiki_date, custom_name); + } + public void Test__bld_by_suffix(Pack_zip_name_bldr bldr, String suffix, int pack_num, String expd) { + Gftest.Eq__str(expd, bldr.Bld_by_suffix(suffix, pack_num).Xto_api()); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__image__create_tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__image__create_tst.java new file mode 100644 index 000000000..31c66308e --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__image__create_tst.java @@ -0,0 +1,49 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; +import org.junit.*; import gplx.core.ios.*; import gplx.xowa.files.*; +public class Xobldr__image__create_tst { + private Xobldr__image__create_fxt fxt = new Xobldr__image__create_fxt(); + @Test public void Basic() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_png, 220, 110) .Test(Xof_ext_.Id_png);} // A.png -> png + @Test public void Ogg_VIDEO() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 220, 110) .Test(Xof_ext_.Id_ogv);} // A.ogg and VIDEO -> ogv + @Test public void Ogg_VIDEO_null_size() {fxt.Init_("A.ogg" , Xof_media_type.Name_video , Xof_ext_.Bry_ogg, 0, 0) .Test(Xof_ext_.Id_ogg);} // A.ogg but 0,0 -> ogg (not ogv) + @Test public void Png_is_jpg() {fxt.Init_("A.png" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpg);} // A.png and jpg -> jpg + @Test public void Jpeg_is_jpeg() {fxt.Init_("A.jpeg" , Xof_media_type.Name_bitmap , Xof_ext_.Bry_jpg, 220, 110) .Test(Xof_ext_.Id_jpeg);} // A.jpeg and jpg -> jpeg (unchanged) +} +class Xobldr__image__create_fxt { + private byte[] name, media_type, minor_mime; int w, h; + public Xobldr__image__create_fxt Init_png() {Name_("A.png").Media_type_(Xof_media_type.Name_bitmap).Minor_mime_(Xof_ext_.Bry_png).W_(220).H_(110); + return this; + } + public Xobldr__image__create_fxt Init_(String name, String media_type, byte[] minor_mime, int w, int h) { + Name_(name); + Media_type_(media_type); + Minor_mime_(minor_mime); + W_(w); + H_(h); + return this; + } + public Xobldr__image__create_fxt Name_(String v) {name = Bry_.new_a7(v); return this;} + public Xobldr__image__create_fxt Media_type_(String v) {media_type = Bry_.new_a7(v); return this;} + public Xobldr__image__create_fxt Minor_mime_(byte[] v) {minor_mime = v; return this;} + public Xobldr__image__create_fxt Minor_mime_(String v) {return Minor_mime_(Bry_.new_a7(v));} + public Xobldr__image__create_fxt W_(int v) {w = v; return this;} + public Xobldr__image__create_fxt H_(int v) {h = v; return this;} + public Xobldr__image__create_fxt Test(int expd) { + Tfds.Eq(expd, Xobldr__image__create.Calc_ext_id(Gfo_usr_dlg_.Noop, name, media_type, minor_mime, w, h)); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__lnki_temp__create__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__lnki_temp__create__tst.java new file mode 100644 index 000000000..f948e8c0c --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/files/cmds/Xobldr__lnki_temp__create__tst.java @@ -0,0 +1,41 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.files.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; +import org.junit.*; +public class Xobldr__lnki_temp__create__tst { + private Xobldr__lnki_temp__create__fxt fxt = new Xobldr__lnki_temp__create__fxt(); + @Test public void Xto_commons() { + fxt.Init__to_commons(true); + fxt.Test__to_commons("a", "A"); + fxt.Test__to_commons("A", null); + fxt.Init__to_commons(false); + fxt.Test__to_commons("a", null); + fxt.Test__to_commons("A", null); + } +} +class Xobldr__lnki_temp__create__fxt { + private boolean wiki_ns_file_is_case_match_all; + private Xowe_wiki commons_wiki; + public Xobldr__lnki_temp__create__fxt Init__to_commons(boolean wiki_ns_file_is_case_match_all) { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all; + this.commons_wiki = Xoa_app_fxt.Make__wiki__edit(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st + return this; + } + public void Test__to_commons(String ttl, String expd) { + Tfds.Eq(expd, String_.new_u8(gplx.xowa.addons.bldrs.mass_parses.parses.utls.Xomp_lnki_temp_wkr.To_commons_ttl(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_u8(ttl)))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/files/missing_origs/apis/Xowmf_imageinfo_item__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/files/missing_origs/apis/Xowmf_imageinfo_item__tst.java new file mode 100644 index 000000000..ac39b0dbf --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/files/missing_origs/apis/Xowmf_imageinfo_item__tst.java @@ -0,0 +1,41 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.files.missing_origs.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; import gplx.xowa.addons.bldrs.files.missing_origs.*; +import org.junit.*; import gplx.core.tests.*; +public class Xowmf_imageinfo_item__tst { + private final Xowmf_imageinfo_item__fxt fxt = new Xowmf_imageinfo_item__fxt(); + + @Test public void Normalize_ttl() { + fxt.Test__Normalize_ttl("File:A b.png", "A_b.png"); + } + @Test public void Normalize_minor_mime() { + fxt.Test__Normalize_minor_mime("image/svg+xml", "svg+xml"); + } + @Test public void Normalize_timestamp() { + fxt.Test__Normalize_timestamp("2017-03-06T08:09:10Z", "20170306080910"); + } +} +class Xowmf_imageinfo_item__fxt { + public void Test__Normalize_ttl(String src, String expd) { + Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_ttl(Bry_.new_u8(src))); + } + public void Test__Normalize_timestamp(String src, String expd) { + Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_timestamp(Bry_.new_u8(src))); + } + public void Test__Normalize_minor_mime(String src, String expd) { + Gftest.Eq__str(expd, Xowmf_imageinfo_item.Normalize_minor_mime(Bry_.new_u8(src))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/files/utls/Xob_xfer_temp_itm_tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/files/utls/Xob_xfer_temp_itm_tst.java new file mode 100644 index 000000000..789707cd9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/files/utls/Xob_xfer_temp_itm_tst.java @@ -0,0 +1,190 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.files.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*; +import org.junit.*; +import gplx.core.gfo_ndes.*; +import gplx.core.stores.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*; +import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*; +import gplx.xowa.addons.bldrs.files.dbs.*; +public class Xob_xfer_temp_itm_tst { + private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Pass() {fxt.Test_pass().Test_itm_chk_fail_id_none();} + @Test public void Missing_orig() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_page_id_is_null , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_page_id, null));} + @Test public void File_is_audio() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type, Xof_media_type.Name_audio));} + @Test public void File_is_mid() { + fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext, Xof_ext_.Id_mid)); + } + @Test public void Redirect_src_is_empty() { // orig_cmd sets all direct files to have "orig_join" == "lnki_ttl" + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "A.png") + , Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png") + ); + fxt.Test_lnki_redirect_src(""); // confirm redirect_src set to "" + } + @Test public void Redirect_src_has_val() { // orig_cmd sets all redirect files to have "orig_join" = redirect and "lnki_ttl" as orig; EX: A.png redirects to B.png; orig_join will be B.png (the actual image) and redirect_src will be A.png (the original lnki) + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.png") + , Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png") + ); + fxt.Test_lnki_redirect_src("A.png"); // confirm redirect_src set to "" + } + @Test public void Redirect_should_take_trg_ext() {// if "A.png" redirects to "B.jpg", ext_id should be ".jpg" (the actual file) not ".png (lnki_ext_id) + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.jpg") + , Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png") + , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) // .png b/c B.jpg + ); + fxt.Test_lnki_ext_id(Xof_ext_.Id_jpg); // confirm ext changed to .jpg + } + @Test public void Thumbtime_check() {// PURPOSE: one image actually had a thumbtime defined; EX: General_Dynamics_F-16_Fighting_Falcon; [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]] + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3) + ); + fxt.Test_lnki_thumbtime(Xof_lnki_time.Null); + fxt.Reset().Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3) + ); + fxt.Test_lnki_thumbtime(3); + } + @Test public void Page_check() { + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3) + ); + fxt.Test_lnki_page(Xof_lnki_page.Null); + fxt.Reset().Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf) + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3) + ); + fxt.Test_lnki_page(3); + fxt.Reset().Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_djvu) + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3) + ); + fxt.Test_lnki_page(3); + } + @Test public void Media_should_be_ignored() {// ignore [[Media:]] for xfer_thumb (needed for xfer_orig) + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png") + , Keyval_.new_(Xob_lnki_regy_tbl.Fld_lnki_src_tid , Xop_file_logger_.Tid__media) + ); + fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media); + } + @Test public void Orig_width_is_0() {// PURPOSE: ignore files with an orig width of 0; note that ogg files that are sometimes flagged as VIDEO; EX:2009_10_08_Marc_Randazza_interview.ogg; DATE:2014-08-20 + fxt.Test_bgn + ( Keyval_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.ogg") + , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video) // VIDEO + , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_w , 0) // no width defined in image table + , Keyval_.new_(Xob_orig_regy_tbl.Fld_orig_h , 0) + ); + fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_orig_w_is_0); + } +} +class Xob_xfer_temp_itm_fxt { + private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm(); + private Xof_img_size img_size = new Xof_img_size(); + private DataRdr_mem rdr; + private GfoNde nde; + public static String[] Flds = new String[] + { Xob_lnki_regy_tbl.Fld_lnki_ext + , Xob_lnki_regy_tbl.Fld_lnki_id + , Xob_lnki_regy_tbl.Fld_lnki_tier_id + , Xob_orig_regy_tbl.Fld_orig_repo + , Xob_orig_regy_tbl.Fld_orig_file_ttl + , Xob_orig_regy_tbl.Fld_orig_file_ext + , Xob_orig_regy_tbl.Fld_lnki_ttl + , Xob_lnki_regy_tbl.Fld_lnki_type + , Xob_lnki_regy_tbl.Fld_lnki_src_tid + , Xob_lnki_regy_tbl.Fld_lnki_w + , Xob_lnki_regy_tbl.Fld_lnki_h + , Xob_lnki_regy_tbl.Fld_lnki_count + , Xob_lnki_regy_tbl.Fld_lnki_page_id + , Xob_orig_regy_tbl.Fld_orig_w + , Xob_orig_regy_tbl.Fld_orig_h + , Xob_orig_regy_tbl.Fld_orig_page_id + , Xob_lnki_regy_tbl.Fld_lnki_upright + , Xob_lnki_regy_tbl.Fld_lnki_time + , Xob_lnki_regy_tbl.Fld_lnki_page + , Xob_orig_regy_tbl.Fld_orig_media_type + , Xob_orig_regy_tbl.Fld_orig_minor_mime + } + ; + public Xob_xfer_temp_itm_fxt Reset() { + itm.Clear(); + return this; + } + public Xob_xfer_temp_itm_fxt Init_rdr_image() { + GfoFldList flds = GfoFldList_.str_(Flds); + nde = GfoNde_.vals_(flds, Object_.Ary + ( Xof_ext_.Id_png, 1, 1, Xof_repo_tid_.Tid__remote + , "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xop_file_logger_.Tid__file + , 220, 200, 1, 2, 440, 400, 3 + , Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null, Xof_lnki_page.Null + , Xof_media_type.Name_bitmap, "png" + )); + GfoNdeList subs = GfoNdeList_.new_(); + subs.Add(nde); + GfoNde root = GfoNde_.root_(nde); + rdr = DataRdr_mem.new_(root, flds, subs); + rdr.MoveNextPeer(); + return this; + } + public Xob_xfer_temp_itm_fxt Init_rdr(String key, Object val) { + nde.Write(key, val); + return this; + } + public Xob_xfer_temp_itm_fxt Test_pass() {return Test_bgn();} + public Xob_xfer_temp_itm_fxt Test_fail(byte fail_tid, Keyval... kvs) { + Test_bgn(kvs); + this.Test_itm_chk_fail_id(fail_tid); + return this; + } + public Xob_xfer_temp_itm_fxt Test_bgn(Keyval... kvs) { + Init_rdr_image(); + int len = kvs.length; + for (int i = 0; i < len; i++) { + Keyval kv = kvs[i]; + Init_rdr(kv.Key(), kv.Val()); + } + this.Exec_load(); + this.Exec_chk(); + return this; + } + public Xob_xfer_temp_itm_fxt Test_atr(String key, Object val) { + Tfds.Eq(rdr.Read(key), val); + return this; + } + public Xob_xfer_temp_itm_fxt Exec_load() { + itm.Load(rdr); + return this; + } + public Xob_xfer_temp_itm_fxt Exec_chk() { + itm.Chk(img_size); + return this; + } + public Xob_xfer_temp_itm_fxt Test_lnki_ext_id(int expd) {Tfds.Eq(expd, itm.Lnki_ext()); return this;} + public Xob_xfer_temp_itm_fxt Test_lnki_thumbtime(double expd) {Tfds.Eq(expd, itm.Lnki_thumbtime()); return this;} + public Xob_xfer_temp_itm_fxt Test_lnki_page(int expd) {Tfds.Eq(expd, itm.Lnki_page()); return this;} + public Xob_xfer_temp_itm_fxt Test_lnki_redirect_src(String expd) {Tfds.Eq(expd, itm.Redirect_src()); return this;} + public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id_none() {return Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_none);} + public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id(byte expd) { + Tfds.Eq(expd, itm.Chk_tid()); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_html__tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_html__tst.java new file mode 100644 index 000000000..05ecc3f18 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/infos/Xobc_info_html__tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*; +public class Xobc_info_html__tst { + private final Xobc_info_html__fxt fxt = new Xobc_info_html__fxt(); + @Test public void Torrent__en_w() {fxt.Test__torrent_link("en.wikipedia.org" , "https://archive.org/download/Xowa_enwiki_latest_archive.torrent");} + @Test public void Torrent__fr_d() {fxt.Test__torrent_link("fr.wiktionary.org" , "https://archive.org/download/Xowa_frwiki_latest_archive.torrent");} +} +class Xobc_info_html__fxt { + public void Test__torrent_link(String domain_str, String expd) { + Gftest.Eq__str(expd, Xobc_info_html.Make_torrent_fil("https://archive.org/download/", Xow_domain_itm_.parse(Bry_.new_u8(domain_str)))); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/bldrs/volumes/Volume_prep_rdr_tst.java b/400_xowa/src/gplx/xowa/addons/bldrs/volumes/Volume_prep_rdr_tst.java new file mode 100644 index 000000000..f000100fa --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/bldrs/volumes/Volume_prep_rdr_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; +import org.junit.*; import gplx.core.tests.*; +public class Volume_prep_rdr_tst { + private final Volume_prep_rdr_fxt fxt = new Volume_prep_rdr_fxt(); + @Test public void Parse() { + fxt.Test__parse(String_.Concat_lines_nl_skip_last("A", "", "B") + , fxt.Make__itm("A") + , fxt.Make__itm("B") + ); + } +} +class Volume_prep_rdr_fxt { + private final Volume_prep_rdr rdr = new Volume_prep_rdr(); + public Volume_prep_rdr_fxt Test__parse(String raw, Volume_prep_itm... expd) { + Gftest.Eq__ary(expd, rdr.Parse(Bry_.new_u8(raw))); + return this; + } + public Volume_prep_itm Make__itm(String page_ttl) { + Volume_prep_itm rv = new Volume_prep_itm(); + rv.Page_ttl = Bry_.new_u8(page_ttl); + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/htmls/sidebars/Xoh_sidebar_mgr_tst.java b/400_xowa/src/gplx/xowa/addons/htmls/sidebars/Xoh_sidebar_mgr_tst.java new file mode 100644 index 000000000..5d9e4ecbd --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/htmls/sidebars/Xoh_sidebar_mgr_tst.java @@ -0,0 +1,235 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; +import org.junit.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; +public class Xoh_sidebar_mgr_tst { + @Before public void init() {fxt.Clear();} private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt(); + @Test public void Grp() { + fxt.Init__msg__grp("key", "text", "title"); + fxt.Exec__make("* key"); + fxt.Test__objs(fxt.Make__grp("text", "title")); + } + @Test public void Grp_missing_msg() { + fxt.Exec__make("* key"); + fxt.Test__objs(fxt.Make__grp("key", Null_str)); + } + @Test public void Itm() { + fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href"); + fxt.Exec__make("** href_key|main_key"); + fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href")); + } + @Test public void Itm_missing_msg() { + fxt.Exec__make("** href_key|main_key"); + fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Href_key")); + } + @Test public void Itm_text() { // PURPOSE: only text msg exists; EX: ** Portal:Contents|contents; no href, accesskey, title + fxt.Init__msg__itm("href_key", "main_key", "text", Null_str, Null_str, Null_str); // only define msg for text + fxt.Exec__make("** href_key|main_key"); + fxt.Test__objs(fxt.Make__itm("text", Null_str, Null_str, "/wiki/Href_key")); + } + @Test public void Itm_href_absolute() { + fxt.Exec__make("** http://a.org|main_key"); + fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "http://a.org")); + } + @Test public void Itm_href_manual() { + fxt.Exec__make("** Help:Contents|main_key"); + fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Help:Contents")); + } + @Test public void Itm_href_xwiki() { + Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), "c", "commons.wikimedia.org"); + fxt.Exec__make("** c:Help:Contents|main_key"); + fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/site/commons.wikimedia.org/wiki/Help:Contents")); + } + @Test public void Itm_err_missing_key() { + fxt.Exec__make("** no_main_key"); + fxt.Test__objs(); + } + @Test public void Itm_ignore() { // PURPOSE: ignore SEARCH, TOOLBOX, LANGUAGES + fxt.Exec__make + ( "** SEARCH" + , "** TOOLBOX" + , "** LANGUAGES" + ); + fxt.Test__objs(); + } + @Test public void Itm_comment() { // PURPOSE: ignore comment; EX:de.v:MediaWiki:Sidebar; DATE:2014-03-08 + fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href"); + fxt.Exec__make("** href_key|main_key"); + fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href")); + } + @Test public void Smoke() { + fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title"); + fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href"); + fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str); + fxt.Exec__make + ( "* navigation" + , "** mainpage|mainpage-description" + , "** Portal:Contents|contents" + , "* SEARCH" + , "* interaction" + , "** helppage|help" + , "* TOOLBOX" + , "** TOOLBOXEND" + , "* LANGUAGES" + ); + fxt.Test__objs + ( fxt.Make__grp("Grp_0_text", "Grp_0_title").Subs__add + ( fxt.Make__itm("Itm_0_text", "Itm_0_title [a]", "a", "/wiki/Itm_0_href") + , fxt.Make__itm("Itm_1_text", Null_str, Null_str, "/wiki/Portal:Contents") + ) + , fxt.Make__grp("interaction", Null_str).Subs__add + ( fxt.Make__itm("help", Null_str, Null_str, "/wiki/Helppage") + )); + fxt.Test__html + ( "
" + , "

Grp_0_text

" + , "
" + , " " + , "
" + , "
" + , "
" + , "

interaction

" + , "
" + , "
    " + , "
  • help
  • " + , "
" + , "
" + , "
" + ); + } + @Test public void Itm_template_msg() { + fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random"); + fxt.Exec__make("** href|main"); + fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random")); + } + @Test public void Itm_template_key() { + fxt.Exec__make("** {{ns:Special}}:Random|main"); + fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random")); + } + @Test public void Popups() { + fxt.Init__popups_enabled(true); + fxt.Exec__make + ( "* navigation" + , "** mainpage|mainpage-description" + ); + fxt.Test__objs + ( fxt.Make__grp("navigation", "").Subs__add + ( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage") + )); + fxt.Test__html + ( "
" + , "

navigation

" + , "
" + , " " + , "
" + , "
" + ); + } + private static final String Null_str = ""; +} +class Xoh_sidebar_mgr_fxt { + private Xoae_app app; private Xowe_wiki wiki; private Xoh_sidebar_mgr sidebar_mgr; private Bry_bfr bfr; + public Xoh_sidebar_mgr_fxt Clear() { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + sidebar_mgr = wiki.Html_mgr().Portal_mgr().Sidebar_mgr(); + bfr = Bry_bfr_.Reset(Io_mgr.Len_kb); + Init__popups_enabled(false); + return this; + } + public Xowe_wiki Wiki() {return wiki;} + public Xoh_sidebar_itm Make__grp(String text, String title, Xoh_sidebar_itm... itms) { + Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.N, Bry_.new_a7(text), Bry_.new_a7(text), null); + rv.Init_by_title_and_accesskey(Bry_.new_a7(title), null, null); + return rv; + } + public Xoh_sidebar_itm Make__itm(String text, String title, String accesskey, String href) { + Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.Y, Bry_.new_a7(text), Bry_.new_a7(text), Bry_.new_a7(href)); + rv.Init_by_title_and_accesskey(Bry_.new_a7(title), Bry_.new_a7(accesskey), null); + return rv; + } + public Xoh_sidebar_mgr_fxt Init__popups_enabled(boolean v) { + wiki.Html_mgr().Head_mgr().Popup_mgr().Enabled_(v); + return this; + } + public Xoh_sidebar_mgr_fxt Init__msg__grp(String key, String text, String title) { + Init_msg(key, text); + Init_msg("tooltip-n-" + key, title); + return this; + } + public Xoh_sidebar_mgr_fxt Init__msg__itm(String href_key, String main_key, String text, String title, String accesskey, String href) { + if (text != null) Init_msg(main_key, text); + if (href != null) Init_msg(href_key, href); + if (title != null) Init_msg("tooltip-n-" + main_key, title); + if (accesskey != null) Init_msg("accesskey-n-" + main_key, accesskey); + return this; + } + public Xoh_sidebar_mgr_fxt Init_msg(String key, String val) { + Xol_msg_mgr msg_mgr = wiki.Lang().Msg_mgr(); + Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(Bry_.new_a7(key)); + msg_itm.Atrs_set(Bry_.new_a7(val), false, String_.Has(val, "{{")); + return this; + } + public void Exec__make(String... raw) { + sidebar_mgr.Make(bfr, Bry_.new_u8(String_.Concat_lines_nl_skip_last(raw))); + } + public void Test__objs(Xoh_sidebar_itm... expd) { + Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr)); + } + public void Test__objs(String raw, Xoh_sidebar_itm... expd) { + Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr)); + } + public void Test__html(String... expd) { + Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), String_.new_u8(sidebar_mgr.Html_bry())); + } + private static String To_str_by_mgr(Xoh_sidebar_mgr mgr) { + List_adp grps = mgr.Grps(); + int len = grps.Len(); + Xoh_sidebar_itm[] ary = new Xoh_sidebar_itm[len]; + for (int i = 0; i < len; i++) + ary[i] = (Xoh_sidebar_itm)grps.Get_at(i); + return To_str_by_itms(ary); + } + + private static String To_str_by_itms(Xoh_sidebar_itm[] ary) { + Bry_bfr bfr = Bry_bfr_.New(); + int ary_len = ary.length; + for (int i = 0; i < ary_len; i++) + To_str_by_itm(bfr, ary[i]); + return bfr.To_str_and_clear(); + } + private static void To_str_by_itm(Bry_bfr bfr, Xoh_sidebar_itm cur) { + boolean tid_is_itm = cur.Tid_is_itm(); + bfr.Add_str_a7(tid_is_itm ? "itm|" : "grp|"); + bfr.Add(cur.Text()).Add_byte_pipe(); + bfr.Add(cur.Title()).Add_byte_pipe(); + if (tid_is_itm) { + bfr.Add(cur.Accesskey()).Add_byte_pipe(); + bfr.Add(cur.Href()).Add_byte_pipe(); + } + bfr.Add_byte_nl(); + + int len = cur.Subs__len(); + for (int i = 0; i< len; ++i) + To_str_by_itm(bfr, cur.Subs__get_at(i)); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_htmlr__basic__tst.java b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_htmlr__basic__tst.java new file mode 100644 index 000000000..82050394d --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_htmlr__basic__tst.java @@ -0,0 +1,175 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoh_toc_htmlr__basic__tst { + @Before public void init() {fxt.Clear();} private final Xoh_toc_htmlr__basic__fxt fxt = new Xoh_toc_htmlr__basic__fxt(); + @Test public void D1_S0_S0() { + fxt.Init__add(2, "a"); + fxt.Init__add(2, "b"); + fxt.Init__add(2, "c"); + fxt.Test__html_itms + ( "
    " + , "
  • 1 a" + , "
  • " + , "
  • 2 b" + , "
  • " + , "
  • 3 c" + , "
  • " + , "
" + ); + } + @Test public void D1_D1_D1() { + fxt.Init__add(2, "a"); + fxt.Init__add(3, "a_a"); + fxt.Init__add(4, "a_a_a"); + fxt.Test__html_itms + ( "
    " + , "
  • 1 a" + , " " + , "
  • " + , "
" + ); + } + @Test public void D1_D1_S0_U1() { + fxt.Init__add(2, "a"); + fxt.Init__add(3, "a_a"); + fxt.Init__add(3, "a_b"); + fxt.Init__add(2, "b"); + fxt.Test__html_itms + ( "
    " + , "
  • 1 a" + , " " + , "
  • " + , "
  • 2 b" + , "
  • " + , "
" + ); + } + @Test public void D1_D1_U1_D1() { + fxt.Init__add(2, "a"); + fxt.Init__add(3, "a_a"); + fxt.Init__add(2, "b"); + fxt.Init__add(3, "b_a"); + fxt.Test__html_itms + ( "
    " + , "
  • 1 a" + , " " + , "
  • " + , "
  • 2 b" + , " " + , "
  • " + , "
" + ); + } + @Test public void D1_D1_D1_U2() { + fxt.Init__add(2, "a"); + fxt.Init__add(3, "a_a"); + fxt.Init__add(4, "a_a_a"); + fxt.Init__add(2, "b"); + fxt.Test__html_itms + ( "
    " + , "
  • 1 a" + , " " + , "
  • " + , "
  • 2 b" + , "
  • " + , "
" + ); + } + @Test public void D1_D2_U1_D1() { + fxt.Init__add(2, "a"); + fxt.Init__add(4, "a_a_a_a"); + fxt.Init__add(3, "a_a_a"); + fxt.Init__add(4, "a_a_a_b"); + fxt.Test__html_itms + ( " " + ); + } + @Test public void Div() { + fxt.Init__init_page("Table of contents", false); + fxt.Init__add(2, "a"); + fxt.Init__add(2, "b"); + fxt.Init__add(2, "c"); + fxt.Test__html_div + ( "
" + , "
" + , "

Table of contents

" + , "
" + , "
    " + , "
  • 1 a" + , "
  • " + , "
  • 2 b" + , "
  • " + , "
  • 3 c" + , "
  • " + , "
" + , "
" + ); + } +} +class Xoh_toc_htmlr__basic__fxt { + private final Xoh_toc_mgr wtr = new Xoh_toc_mgr(); + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Clear() {wtr.Clear();} + public void Init__add(int hdr_num, String hdr_txt) {wtr.Add(hdr_num, Bry_.new_u8(hdr_txt));} + public void Init__init_page(String toc_title, boolean page_banner) {wtr.Init(gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface_.Noop, Bry_.new_u8(toc_title), Bry_.Empty);} + public void Test__html_itms(String... expd_ary) { + Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.Test__to_html()))); + } + public void Test__html_div(String... expd_ary) { + wtr.To_html(bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, false); + Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(bfr.To_bry_and_clear()))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__lvl__basic__tst.java b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__lvl__basic__tst.java new file mode 100644 index 000000000..86491c836 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__lvl__basic__tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoh_toc_wkr__lvl__basic__tst { + @Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__lvl__fxt fxt = new Xoh_toc_wkr__lvl__fxt(); + @Test public void D1_S0_S0() { + fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1))); + fxt.Test__calc(2, fxt.Make(2, 1, Int_ary_.New(2))); + fxt.Test__calc(2, fxt.Make(3, 1, Int_ary_.New(3))); + } + @Test public void D1_D1_D1() { + fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1))); + fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1))); + fxt.Test__calc(4, fxt.Make(3, 3, Int_ary_.New(1, 1, 1))); + } + @Test public void D1_D1_S0_U1() { + fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1))); + fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1))); + fxt.Test__calc(3, fxt.Make(3, 2, Int_ary_.New(1, 2))); + fxt.Test__calc(2, fxt.Make(4, 1, Int_ary_.New(2))); + } + @Test public void D1_D1_U1_D1() { + fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1))); + fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1))); + fxt.Test__calc(2, fxt.Make(3, 1, Int_ary_.New(2))); + fxt.Test__calc(3, fxt.Make(4, 2, Int_ary_.New(2, 1))); + } + @Test public void D1_D1_D1_U2() { + fxt.Test__calc(2, fxt.Make(1, 1, Int_ary_.New(1))); + fxt.Test__calc(3, fxt.Make(2, 2, Int_ary_.New(1, 1))); + fxt.Test__calc(4, fxt.Make(3, 3, Int_ary_.New(1, 1, 1))); + fxt.Test__calc(2, fxt.Make(4, 1, Int_ary_.New(2))); + } +} +class Xoh_toc_wkr__lvl__fxt { + private final Xoh_toc_wkr__lvl wkr = new Xoh_toc_wkr__lvl(); + private final Xoh_toc_itm actl = new Xoh_toc_itm(); + public void Clear() {wkr.Clear();} + public Xoh_toc_itm Make(int uid, int lvl, int[] path) { + Xoh_toc_itm rv = new Xoh_toc_itm(); + rv.Set__lvl(uid, lvl, path); + return rv; + } + public void Test__calc(int lvl, Xoh_toc_itm expd) { + wkr.Calc_level(actl, lvl); + Gftest.Eq__int(expd.Uid(), actl.Uid(), "uid"); + Gftest.Eq__int(expd.Lvl(), actl.Lvl(), "lvl"); + Gftest.Eq__ary(expd.Path(), actl.Path(), "path"); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__basic__tst.java b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__basic__tst.java new file mode 100644 index 000000000..b43de84d9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xoh_toc_wkr__txt__basic__tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; +import org.junit.*; import gplx.core.tests.*; import gplx.langs.htmls.*; +public class Xoh_toc_wkr__txt__basic__tst { + @Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt(); + @Test public void Basic() { + fxt.Test__both("a b c", "a_b_c", "a b c"); + } + @Test public void Ws() { + fxt.Test__both(" a b ", "a_b", "a b"); + } + @Test public void Nl() { + fxt.Test__both("\na b\n", "a_b", "a b"); + } + @Test public void Empty() { // PAGE:s.w:Colac,_Victoria DATE:2016-07-17 + fxt.Test__both("", "", ""); + } + @Test public void Amp__ncr() { + fxt.Test__both("[a]", ".5Ba.5D", "[a]"); + } + @Test public void Encode() { + fxt.Test__both("a+b", "a.2Bb", "a+b"); + } + @Test public void Comment() { + fxt.Test__text("ac", "ac"); + } + @Test public void Remove_comment__one() { + fxt.Test__remove_comment("ac", "ac"); + } + @Test public void Remove_comment__many() { + fxt.Test__remove_comment("135", "135"); + } + @Test public void Remove_comment__dangling() { + fxt.Test__remove_comment("13ac==" + ), fxt.toc_tbl_nl_y + ( "
    " + , "
  • 1 ac" + , "
  • " + , "
" + )); + } + @Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23 + fxt.Test_html_all(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==ab==" + ) + , String_.Concat_lines_nl + ( fxt.toc_tbl_nl_n + ( "
    " + , "
  • 1 a[1]" + , "
  • " + , "
" + ) + , "

a[1]

" + )); + } + @Test public void Category() { // PURPOSE: Category should not show in in TOC; DATE:2013-12-09 + fxt.Test_html_all(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==A[[Category:B]]==" + ) + , String_.Concat_lines_nl + ( fxt.toc_tbl_nl_n + ( "
    " + , "
  • 1 A" + , "
  • " + , "
" + ) + , "

A

" + )); + } + @Test public void Category_literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21 + fxt.Test_html_all(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==A[[:Category:B]]==" + ) + , String_.Concat_lines_nl + ( fxt.toc_tbl_nl_n + ( " " + ) + , "

ACategory:B

" + )); + } + @Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D�nya_Miraslari; DATE:2014-06-06 + fxt.Test_html_all(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==[[File:A.png]] b==" + ) + , String_.Concat_lines_nl + ( fxt.toc_tbl_nl_n + ( "
    " + , "
  • 1 b" + , "
  • " + , "
" + ) + , "

\"\" b

" + )); + } + @Test public void Lnki_invalid() { // PURPOSE: invalid lnki was causing null ref; DATE:2014-02-07 + fxt.Test_html_all(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==[[]]==" + ) + , String_.Concat_lines_nl + ( fxt.toc_tbl_nl_n + ( "
    " + , "
  • 1 [[]]" + , "
  • " + , "
" + ) + , "

[[]]

" + )); + } + @Test public void File_in_tbl() { // PURPOSE: two issues (a) don't show file if in tbl; (b) if v2, file inside tbl fails; PAGE:en.w:Holmes County,_Mississippi; DATE:2014-06-22 + fxt.Test_html_frag(String_.Concat_lines_nl_skip_last + ( "__FORCETOC__" + , "==a
[[File:A.png]]b
c==" + ) + , "a b c" // note that "b" inside tbl shows + ); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr_fxt.java b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr_fxt.java new file mode 100644 index 000000000..219903fe8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/htmls/tocs/Xowe_hdr_bldr_fxt.java @@ -0,0 +1,69 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; +import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; +public class Xowe_hdr_bldr_fxt { + private final Bry_bfr tmp = Bry_bfr_.New(); + public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt(); + public void Clear() { + fxt.Reset(); + tmp.Clear(); + } + public void Test_html_toc(String raw, String expd) { + fxt.Wtr_cfg().Toc__show_(Bool_.Y); + String actl = Bld_page_with_toc(tmp, fxt, raw); + + // HACK: proc only tests TOC; remove " + , "
" + , "

Contents

" + , "
" + , String_.Concat_lines_nl_skip_last(ary) + , "
" + (nl ? "\n" : "") + ); + } + public static String Bld_page_with_toc(Bry_bfr bfr, Xop_fxt fxt, String raw) { + gplx.xowa.parsers.Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw)); + fxt.Ctx().Page_data().Copy_to(fxt.Page()); + fxt.Wiki().Html_mgr().Html_wtr().Write_doc(bfr, fxt.Ctx(), fxt.Hctx(), root.Root_src(), root); + + gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(bfr, fxt.Page(), Xoh_wtr_ctx.Basic); + return bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr__tst.java b/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr__tst.java new file mode 100644 index 000000000..6aaa50088 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr__tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.parsers.mediawikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.parsers.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_mediawiki_wkr__tst { + private final Xop_mediawiki_wkr__fxt fxt = new Xop_mediawiki_wkr__fxt(); + @After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;} + @Test public void Basic() { + fxt.Init__wkr("en.wikipedia.org", null); + fxt.Test__parse("Page_1", "''{{PAGENAME}}''" + , "

Page 1" + , "

" + ); + } + @Test public void Template() { + fxt.Init__wkr("en.wikipedia.org", new Xop_mediawiki_loader__mock()); + fxt.Test__parse("Page_1", "{{bold}}" + , "

bold" + , "

" + ); + } +} +class Xop_mediawiki_wkr__fxt { + private final Xop_mediawiki_mgr mgr = new Xop_mediawiki_mgr("mem/xowa/wiki/en.wikipedia.org/", false); + private Xop_mediawiki_wkr wkr; + public Xop_mediawiki_wkr__fxt() { + gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem(); + } + public void Init__wkr(String wiki, Xop_mediawiki_loader cbk) { + this.wkr = mgr.Make(wiki, cbk); + } + public void Test__parse(String page, String wtxt, String... expd) { + Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), wkr.Parse(page, wtxt), "parse failed; wtxt={0}", wtxt); + } +} +class Xop_mediawiki_loader__mock implements Xop_mediawiki_loader { + public String LoadWikitext(String page) { + if (String_.Eq(page, "Template:Bold")) return "'''bold'''"; + else return "text"; + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__basic__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__basic__tst.java new file mode 100644 index 000000000..ddcbaf1ff --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__basic__tst.java @@ -0,0 +1,311 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; +import org.junit.*; import gplx.xowa.htmls.core.htmls.*; import gplx.core.intls.ucas.*; +import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*; +public class Xoctg_catpage_mgr__basic__tst { + @Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt(); + @Test public void Page_itm() { + fxt .Init_itms__pages("A1") + .Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n
  • A1
  • "); + } + @Test public void Page_itm_missing() { + fxt.Init_itms__pages("A1"); + Xoctg_catpage_itm itm = fxt.Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0); + itm.Page_ttl_(Xoa_ttl.Null); + itm.Sortkey_handle_make(Bry_bfr_.New(), Bry_.Empty); + fxt.Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n
  • missing page (0)
  • "); + } + @Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space + byte[] page_bry = Bry_.new_a7("A 1"); + Xoa_url url = Xoa_url.New(Bry_.new_a7("en.wikipedia.org"), page_bry); + Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry); + fxt.Wiki().Appe().Usere().History_mgr().Add(fxt.Wiki().App(), url, ttl, page_bry); + fxt .Init_itms__pages("A_1") + .Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Pages in category \"Ctg_1\"

    " + , "

    This category contains only the following page.

    " + , "
    " + , " " + , " " + , " " + , " " + , "
    " + , "

    A

    " + , "
      " + , "
    • A 1
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Page_all() { + fxt .Init_itms__pages("A1") + .Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Pages in category \"Ctg_1\"

    " + , "

    This category contains only the following page.

    " + , "
    " + , " " + , " " + , " " + , " " + , "
    " + , "

    A

    " + , "
      " + , "
    • A1
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void File_all() { + fxt .Init_itms__files("File:A1.png") + .Test__html__all(Xoa_ctg_mgr.Tid__file, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Media in category \"Ctg_1\"

    " + , "

    This category contains only the following file.

    " + , "
    " + , " " + , " " + , " " + , " " + , "
    " + , "

    A

    " + , " " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Subc_all() { + fxt .Init_itms__subcs("Category:Subc_1") + .Test__html__all(Xoa_ctg_mgr.Tid__subc, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Subcategories

    " + , "

    This category has only the following subcategory.

    " + , "
    " + , " " + , " " + , " " + , " " + , "
    " + , "

    S

    " + , "
      " + , "
    • " + , "
      " + , "
      " + , " " + , " " + , " " + , " " + , " Subc 1" + , " " + , " " + , " " + , "
      " + , "
      " + , "
      " + , "
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Page_all_cols() { + fxt.Init_itms__pages("A1", "A2", "A3", "B1", "C1"); + fxt.Init__grp_max_(6); + fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Pages in category \"Ctg_1\"

    " + , "

    The following 5 pages are in this category, out of 5 total.

    " + , "
    " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    " + , "

    A

    " + , "
      " + , "
    • A1
    • " + , "
    • A2
    • " + , "
    " + , "
    " + , "

    A cont.

    " + , "
      " + , "
    • A3
    • " + , "
    " + , "

    B

    " + , "
      " + , "
    • B1
    • " + , "
    " + , "
    " + , "

    C

    " + , "
      " + , "
    • C1
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Page__numeric() { // PURPOSE: check numeric sorting; 0, 9, 10; not 0, 10, 9; DATE:2016-10-09 + fxt.Init_itms__pages("0", "9", "10"); + fxt.Init__grp_max_(6); + fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Pages in category \"Ctg_1\"

    " + , "

    The following 3 pages are in this category, out of 3 total.

    " + , "
    " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    " + , "

    0-9

    " + , "
      " + , "
    • 0
    • " + , "
    " + , "
    " + , "

    0-9 cont.

    " + , "
      " + , "
    • 9
    • " + , "
    " + , "
    " + , "

    0-9 cont.

    " + , "
      " + , "
    • 10
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28 + fxt .Init_itms__pages("A\"1") + .Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last + ( "" + , "
    " + , "

    Pages in category \"Ctg_1\"

    " + , "

    This category contains only the following page.

    " + , "
    " + , " " + , " " + , " " + , " " + , "
    " + , "

    A

    " + , "
      " + , "
    • A"1
    • " + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Calc_col_len() { + fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items + fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items + fxt.Test__calc_col_len(10, 2, 3); // for 10 items, col 2 has 3 items + fxt.Test__calc_col_len(11, 0, 4); + fxt.Test__calc_col_len(11, 1, 4); + fxt.Test__calc_col_len(11, 2, 3); + fxt.Test__calc_col_len(12, 0, 4); + fxt.Test__calc_col_len(12, 1, 4); + fxt.Test__calc_col_len(12, 2, 4); + } +} +class Xoctg_catpage_mgr_fxt { + private int grp_max; + private Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true); + public Xoctg_catpage_mgr_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + ctg_html = wiki.Ctg__catpage_mgr(); + } + ctg = new Xoctg_catpage_ctg(1, Bry_.new_a7("Ctg_1")); + grp_max = 3; // default to 3 paer page + return this; + } private Xoae_app app; private Xoctg_catpage_mgr ctg_html; + public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));} + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg; + public void Init__grp_max_(int v) {this.grp_max = v;} + public void Init__prev_hide_y_(byte tid) {ctg.Grp_by_tid(tid).Prev_disable_(true);} + public void Init__next_sortkey_(byte tid, String v) {ctg.Grp_by_tid(tid).Next_sortkey_(Bry_.new_u8(v));} + public void Test__navlink(boolean next, String ctg_str, String expd) { + byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid__page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid__page), grp_max); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } + public Xoctg_catpage_mgr_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__page, titles);} + public Xoctg_catpage_mgr_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__file, titles);} + public Xoctg_catpage_mgr_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__subc, titles);} + private Xoctg_catpage_mgr_fxt Init_itms(byte tid, String[] ttls) { + int len = ttls.length; + Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp(); + Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid); + grp.Count_all_(len); + for (int i = 0; i < len; ++i) { + byte[] page_ttl_bry = Bry_.new_u8(ttls[i]); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page_ttl_bry); + Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl); + tmp.Add(itm); + } + tmp.Make_by_grp(grp); + return this; + } + public void Test__html__page(byte tid, byte grp_char_0, String expd) { + Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid); + Xoctg_fmt_itm_base itm_fmt = list_mgr.Itm_fmt(); + Xoctg_catpage_grp list = ctg.Grp_by_tid(tid); + itm_fmt.Init_from_ltr(wiki, list, ltr_extractor); + itm_fmt.Set_ltr_and_bgn(new byte[] {grp_char_0}, 0); + itm_fmt.Col_end_(0, 0); + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + itm_fmt.Bfr_arg__add(bfr); + Tfds.Eq_str_lines(expd, bfr.To_str_and_rls()); + } + public void Test__html_grp(byte tid, String expd) { + Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid); + Xoctg_fmt_ltr fmtr_grp = new Xoctg_fmt_ltr(list_mgr.Itm_fmt()); + fmtr_grp.Init_from_grp(wiki, ctg.Grp_by_tid(tid), ltr_extractor); + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + fmtr_grp.Bfr_arg__add(bfr); + Tfds.Eq_str_lines(expd, bfr.To_str_and_rls()); + } + public void Test__html__all(byte tid, String expd) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ltr_extractor, ctg, grp_max); + Tfds.Eq_str_lines(expd, bfr.To_str_and_rls()); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__navlink__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__navlink__tst.java new file mode 100644 index 000000000..4a730634b --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/Xoctg_catpage_mgr__navlink__tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; +import org.junit.*; import gplx.xowa.htmls.core.htmls.*; +import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*; +public class Xoctg_catpage_mgr__navlink__tst { + @Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt(); + @Test public void Navlink__basic() { + fxt.Init_itms__pages("A2", "A3", "A4"); + fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5"); + fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl + ( "" + , "(previous 3)" + , "(next 3)" + )); + } + @Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11 + fxt.Init_itms__pages("A\" 2", "A\" 3", "A\" 4"); + fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A\" 5"); + fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl + ( "" + , "(previous 3)" + , "(next 3)" + )); + } + @Test public void Navlink__bos() { + fxt.Init_itms__pages("A2", "A3", "A4"); + fxt.Init__prev_hide_y_(Xoa_ctg_mgr.Tid__page); + fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5"); + fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl + ( "" + , "(previous 3)" + , "(next 3)" + )); + } + @Test public void Navlink__eos() { + fxt.Init_itms__pages("A2", "A3", "A4"); + fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl + ( "" + , "(previous 3)" + , "(next 3)" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/dbs/Xoctg_catlink_loader__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/dbs/Xoctg_catlink_loader__tst.java new file mode 100644 index 000000000..bb2d86bb6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/dbs/Xoctg_catlink_loader__tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*; +import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*; +public class Xoctg_catlink_loader__tst { + private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt(); + @Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record + fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'" + } + @Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed + fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'" + } +} +class Xoctg_catlink_loader__fxt { + public void Test__build_sortkey_sql(int version, String sortkey, String expd) { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation + Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki); + + Bry_bfr bfr = Bry_bfr_.New(); + Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java new file mode 100644 index 000000000..d788cfe78 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/langs/Xoctg_collation_wkr___tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoctg_collation_wkr___tst { + private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt(); + @Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");} + @Test public void Identity() {fxt.Test__make("identity" , "identity");} + @Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");} + @Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);} + @Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);} + @Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);} + @Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);} + @Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);} +} +class Xoctg_collation_wkr___fxt { + public void Test__make(String wm_name, String expd_type) { + Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name); + Gftest.Eq__str(expd_type, actl.Type_name()); + } + public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) { + Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name); + Gftest.Eq__str(expd_locale, actl.Icu_locale()); + Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting()); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/urls/Xoctg_catpage_url__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/urls/Xoctg_catpage_url__tst.java new file mode 100644 index 000000000..1c5ec4d5d --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/catpages/urls/Xoctg_catpage_url__tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*; +public class Xoctg_catpage_url__tst { + @Before public void init() {fxt.Clear();} private Xoctg_catpage_url__fxt fxt = new Xoctg_catpage_url__fxt(); + @Test public void Specific() { + fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y); + fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N); + } + @Test public void General() { + fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y); + fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N); + } + @Test public void Url_encoded() { + fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y); + } +} +class Xoctg_catpage_url__fxt { + private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url; + public void Clear() { + Xoa_app app = Xoa_app_fxt.Make__app__edit(); + this.xo_url_parser = app.User().Wikii().Utl__url_parser(); + } + public Xoctg_catpage_url__fxt Exec__parse(String url_str) { + Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str)); + this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url); + return this; + } + public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;} + public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;} +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/doubles/Xoctg_double_box__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/doubles/Xoctg_double_box__tst.java new file mode 100644 index 000000000..e7489aaa8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/doubles/Xoctg_double_box__tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; +import org.junit.*; +import gplx.xowa.wikis.data.tbls.*; +public class Xoctg_double_box__tst { + @Before public void init() {fxt.Clear();} private Xoctg_double_box__fxt fxt = new Xoctg_double_box__fxt(); + @Test public void Basic() { + fxt.Init_ctg_hidden("Category:A", "Category:B", "Category:C"); + fxt.Init_ctg_normal("Category:D", "Category:E", "Category:F"); + fxt.Test_print_hidden(String_.Concat_lines_nl + ( "
    " + , "
    " + , "Categories:" + , "
      " + , "
    • " + , "D" + , "
    • " + , "
    • " + , "E" + , "
    • " + , "
    • " + , "F" + , "
    • " + , "
    " + , "
    " + , "" + , "
    " + )); + } +} +class Xoctg_double_box__fxt { + private Xop_fxt fxt; private Xoctg_double_box hidden_wtr; + private final List_adp init_ctgs = List_adp_.New(); + public void Clear() { + fxt = new Xop_fxt(); + hidden_wtr = new Xoctg_double_box(); + hidden_wtr.Init_by_wiki(fxt.Wiki()); + init_ctgs.Clear(); + } + public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);} + public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);} + public void Init_ctg(boolean hidden, String[] ary) { + int len = ary.length; + for (int i = 0; i < len; i++) { + Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ary[i])); + Xoctg_pagebox_itm itm = Xoctg_pagebox_itm.New_by_ttl(ttl); + itm.Load_by_cat_core(hidden, 0, 0, 0); + init_ctgs.Add_many(itm); + } + } + public void Test_print_hidden(String expd) { + Bry_bfr bfr = Bry_bfr_.New(); + Xoctg_pagebox_itm[] ary = (Xoctg_pagebox_itm[])init_ctgs.To_ary_and_clear(Xoctg_pagebox_itm.class); + hidden_wtr.Write_pagebox(bfr, ary); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/singles/Xoctg_single_box__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/singles/Xoctg_single_box__tst.java new file mode 100644 index 000000000..847a7e55a --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/ctgs/htmls/pageboxs/singles/Xoctg_single_box__tst.java @@ -0,0 +1,60 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; +import org.junit.*; +import gplx.xowa.htmls.core.htmls.*; +public class Xoctg_single_box__tst { + @Before public void init() {fxt.Clear();} private final Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt(); + @Test public void Basic() { + fxt.Init__ctgs("Category:A", "Category:B").Test_html(String_.Concat_lines_nl + ( "
    " + , "
    " + , "Categories:" + , "
      " + , "
    • " + , "A" + , "
    • " + , "
    • " + , "B" + , "
    • " + , "
    " + , "
    " + , "
    " + )); + } +} +class Xoh_ctg_mgr_fxt { + private Xoctg_single_box ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr_.New(); + private Xoae_page page; + public void Clear() { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + page = wiki.Parser_mgr().Ctx().Page(); + ctg_grp_mgr = new Xoctg_single_box(); + ctg_grp_mgr.Init_by_wiki(wiki); + } + public Xoh_ctg_mgr_fxt Init__ctgs(String... ary) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + page.Wtxt().Ctgs__add(wiki.Ttl_parse(Bry_.new_u8(ary[i]))); + } + return this; + } + public void Test_html(String expd) { + ctg_grp_mgr.Write_pagebox(tmp_bfr, Xoctg_pagebox_itm.New_ary(page)); + Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/directorys/dbs/Xowdir_wiki_props_mgr__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/directorys/dbs/Xowdir_wiki_props_mgr__tst.java new file mode 100644 index 000000000..d709b4e36 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/directorys/dbs/Xowdir_wiki_props_mgr__tst.java @@ -0,0 +1,70 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*; +import org.junit.*; import gplx.core.tests.*; +import gplx.langs.jsons.*; +import gplx.xowa.wikis.data.*; +public class Xowdir_wiki_props_mgr__tst { + private final Xowdir_wiki_props_mgr__fxt fxt = new Xowdir_wiki_props_mgr__fxt(); + + @Test public void Import__wiki__missing_all() { + // handle all imported .xowa wikis pre v4.3 + fxt.Init__wiki_props(null, null, null); + fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page")); + } + @Test public void Import__wiki__missing_domain() { + // handle personal wikis from v4.2 + fxt.Init__wiki_props(null, null, "Main_Page"); + fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page")); + } + @Test public void Import__wiki__wmf_domain() { + // handle wmf wikis with a core-file of "test-core.xowa" + fxt.Init__wiki_props(null, null, "Main_Page"); + fxt.Test__verify(Bool_.Y, "/dir/test-core.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page")); + } + @Test public void Import__wiki__clean() { + // handle clean wiki + fxt.Init__wiki_props("test", "test", "Main_Page"); + fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.N, fxt.Make__json("test", "test", "Main_Page")); + } + @Test public void Open__wiki__missing_name() { + // handle missing name + fxt.Init__user_json("test", "my test", "Main_Page"); + fxt.Init__wiki_props(null, null, "Main_Page"); + fxt.Test__verify(Bool_.N, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "my test", "Main_Page")); + } +} +class Xowdir_wiki_props_mgr__fxt { + private final Xowdir_wiki_props_mgr mgr = new Xowdir_wiki_props_mgr__mock(); + public Xowdir_wiki_props Make__json(String domain, String name, String main_page) { + return new Xowdir_wiki_props(domain, name, main_page); + } + public void Init__user_json(String domain, String name, String main_page) { + Xowdir_wiki_json wiki_json = new Xowdir_wiki_json(name, main_page); + mgr.User_reg__upsert(domain, wiki_json.To_str(new Json_wtr())); + } + public void Init__wiki_props(String domain, String name, String main_page) { + mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__domain, domain); + mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__wiki__core__name, name); + mgr.Wiki_cfg__upsert(Xowd_cfg_key_.Key__init__main_page, main_page); + } + public void Test__verify(boolean mode_is_import, String url, boolean expd_dirty, Xowdir_wiki_props expd) { + Xowdir_wiki_props actl = mgr.Verify(mode_is_import, "", Io_url_.new_any_(url)); + + Gftest.Eq__ary__lines(expd.To_str(), actl.To_str(), "expd"); + Gftest.Eq__bool(expd_dirty, actl.Dirty(), "dirty"); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/core/Xofulltext_extractor__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/core/Xofulltext_extractor__tst.java new file mode 100644 index 000000000..2bca75e26 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/core/Xofulltext_extractor__tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.fulltexts.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*; +import org.junit.*; import gplx.core.tests.*; +public class Xofulltext_extractor__tst { + private final Xofulltext_extractor__fxt fxt = new Xofulltext_extractor__fxt(); + @Test public void Basic() { + // simple node + fxt.Test__extract("a b c", "a b c"); + + // node with attributes + fxt.Test__extract("a f g", "a f g"); + + // nested nodes + fxt.Test__extract("a b c d e", "a b c d e"); + + // periods + fxt.Test__extract("a b. c d", "a b. c d"); + + // parens + fxt.Test__extract("(a b)", "(a b)"); + + // parens + fxt.Test__extract("a (b)", "a (b)"); + } +} +class Xofulltext_extractor__fxt { + private final Xofulltext_extractor extractor = new Xofulltext_extractor(); + public void Test__extract(String src, String expd) { + Gftest.Eq__str(expd, extractor.Extract(Bry_.new_u8(src))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/mgrs/brutes/finders/Xofulltext_finder_cbk__eval__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/mgrs/brutes/finders/Xofulltext_finder_cbk__eval__tst.java new file mode 100644 index 000000000..0133743a9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/fulltexts/searchers/mgrs/brutes/finders/Xofulltext_finder_cbk__eval__tst.java @@ -0,0 +1,122 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.finders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.fulltexts.*; import gplx.xowa.addons.wikis.fulltexts.searchers.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.*; import gplx.xowa.addons.wikis.fulltexts.searchers.mgrs.brutes.*; +import org.junit.*; import gplx.core.tests.*; +public class Xofulltext_finder_cbk__eval__tst { + private final Xofulltext_finder_cbk__eval__fxt fxt = new Xofulltext_finder_cbk__eval__fxt(); + @Test public void Exact() { + fxt.Init__search("a"); + // y: basic match + fxt.Test__eval_y("a"); + // n: no match + fxt.Test__eval_n("z"); + // n: wildcard_bgn not enabled + fxt.Test__eval_n("az"); + } + @Test public void Or() { + fxt.Init__search("a, c"); + // y: lone char + fxt.Test__eval_y("a" , "c"); + // y: one char + fxt.Test__eval_y("a b", "b c"); + // y: both chars + fxt.Test__eval_y("a c", "a b c"); + // n: no chars + fxt.Test__eval_n("b"); + } + @Test public void And() { + fxt.Init__search("a + c"); + // y: both chars + fxt.Test__eval_y("a c", "a b c"); + // n: one char only + fxt.Test__eval_n("a", "c", "a b", "b c"); + } + @Test public void And__shorthand() { + fxt.Init__search("a c"); + // y: both chars + fxt.Test__eval_y("a b c"); + // n: one char only + fxt.Test__eval_n("a", "c"); + } + @Test public void Not() { + fxt.Init__search("-a"); + // y: no chars + fxt.Test__eval_y("b"); + // n: char exists + fxt.Test__eval_n("a"); + } + @Test public void Trim_end() { + fxt.Init__search("a"); + // y: single + fxt.Test__eval_y("a!"); + // y: many + fxt.Test__eval_y("a!!!"); + } + @Test public void Trim_bgn() { + fxt.Init__search("a"); + // y: single + fxt.Test__eval_y("!a"); + // y: many + fxt.Test__eval_y("!!!a"); + } + @Test public void Trim_both() { + fxt.Init__search("a"); + // y: single + fxt.Test__eval_y("'a'"); + // y: many + fxt.Test__eval_y("'''a'''"); + } + @Test public void Slash() { + fxt.Init__search("a"); + // y: slash before, after + fxt.Test__eval_y("a/b/c", "b/a/c", "b/c/a"); + } + @Test public void Brack() { + fxt.Init__search("a"); + // y + fxt.Test__eval_y("[[a]]"); + } + // . + // ... + // - + // a'b + // https://site/page + // () + // [] + // <> +} +class Xofulltext_finder_cbk__eval__fxt { + private boolean case_match = false; + private boolean auto_wildcard_bgn = false; + private boolean auto_wildcard_end = false; + private byte wildcard_byte = Byte_ascii.Star; + private byte not_byte = Byte_ascii.Dash; + private final Xofulltext_finder_mgr finder = new Xofulltext_finder_mgr(); + private final Xofulltext_finder_cbk__eval cbk = new Xofulltext_finder_cbk__eval(); + public void Init__search(String query) { + finder.Init(Bry_.new_u8(query), case_match, auto_wildcard_bgn, auto_wildcard_end, wildcard_byte, not_byte); + } + public void Test__eval_y(String... texts) {Test__eval(Bool_.Y, texts);} + public void Test__eval_n(String... texts) {Test__eval(Bool_.N, texts);} + public void Test__eval(boolean expd, String... texts) { + for (String text : texts) { + byte[] text_bry = Bry_.new_u8(text); + cbk.found = false; + finder.Match(text_bry, 0, text_bry.length, cbk); + Gftest.Eq__bool(expd, cbk.found, "query={0} text={1}", finder.Query(), text); + } + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/htmls/css/mgrs/Xowd_css_core_mgr_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/htmls/css/mgrs/Xowd_css_core_mgr_tst.java new file mode 100644 index 000000000..606ca28f5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/htmls/css/mgrs/Xowd_css_core_mgr_tst.java @@ -0,0 +1,118 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.htmls.css.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.htmls.*; import gplx.xowa.addons.wikis.htmls.css.*; +import org.junit.*; import gplx.core.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.htmls.css.dbs.*; +public class Xowd_css_core_mgr_tst { + @Before public void init() {fxt.Clear();} private Xowd_css_core_mgr_fxt fxt = new Xowd_css_core_mgr_fxt(); + @Test public void Basic() { + Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary + ( fxt.Make_skin_itm(1, "desktop", "20010101_050200") + ); + Xowd_css_file_itm[] file_ary = fxt.Make_file_ary + ( fxt.Make_file_itm(1, "a.css", "a_data") + , fxt.Make_file_itm(1, "b/b.png", "b/b_data") + ); + Io_url src_dir = Io_url_.mem_dir_("mem/src/"); + fxt.Init_fs(src_dir, file_ary); + fxt.Exec_set(src_dir, "desktop"); + fxt.Test_skin_tbl(skin_ary); + fxt.Test_file_tbl(file_ary); + + Io_url trg_dir = Io_url_.mem_dir_("mem/trg/"); + fxt.Exec_get(trg_dir, "desktop"); + fxt.Test_fs(trg_dir, file_ary); + } + @Test public void Update() { // update css files; keep same skin_id; insert new files + Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary + ( fxt.Make_skin_itm(1, "desktop", "20010101_050500") + ); + Xowd_css_file_itm[] file_ary = fxt.Make_file_ary + ( fxt.Make_file_itm(1, "a.css", "a_data") + , fxt.Make_file_itm(1, "b/b.png", "b/b_data") + ); + Io_url src_dir = Io_url_.mem_dir_("mem/src/"); + fxt.Init_fs(src_dir, file_ary); + fxt.Exec_set(src_dir, "desktop"); + + file_ary = fxt.Make_file_ary + ( fxt.Make_file_itm(1, "a1.css", "a1_data") + , fxt.Make_file_itm(1, "b/b1.png", "b/b1_data") + ); + Io_mgr.Instance.DeleteDirDeep(src_dir); + fxt.Init_fs(src_dir, file_ary); + fxt.Exec_set(src_dir, "desktop"); + fxt.Test_skin_tbl(skin_ary); + fxt.Test_file_tbl(file_ary); + } +} +class Xowd_css_core_mgr_fxt { + private final Bry_bfr bfr = Bry_bfr_.Reset(32); + private Xowd_css_core_tbl core_tbl; private Xowd_css_file_tbl file_tbl; + public void Clear() { + Datetime_now.Manual_y_(); + Io_mgr.Instance.InitEngine_mem(); + Db_conn_bldr.Instance.Reg_default_mem(); + Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/css.sqlite3")); + this.core_tbl = new Xowd_css_core_tbl(conn); + this.file_tbl = new Xowd_css_file_tbl(conn); + core_tbl.Create_tbl(); + file_tbl.Create_tbl(); + } + public Xowd_css_core_itm Make_skin_itm(int id, String key, String updated_on) {return new Xowd_css_core_itm(id, key, DateAdp_.parse_gplx(updated_on));} + public Xowd_css_file_itm Make_file_itm(int skin_id, String path, String data) {return new Xowd_css_file_itm(skin_id, path, Bry_.new_u8(data));} + public Xowd_css_file_itm[] Make_file_ary(Xowd_css_file_itm... ary) {return ary;} + public Xowd_css_core_itm[] Make_skin_ary(Xowd_css_core_itm... ary) {return ary;} + public void Init_fs(Io_url css_dir, Xowd_css_file_itm[] file_ary) { + for (Xowd_css_file_itm itm : file_ary) + Io_mgr.Instance.SaveFilBry(css_dir.GenSubFil(itm.Path()), itm.Data()); + } + public void Exec_set(Io_url css_dir, String key) {Xowd_css_core_mgr.Set(core_tbl, file_tbl, css_dir, key);} + public void Exec_get(Io_url css_dir, String key) {Xowd_css_core_mgr.Get(core_tbl, file_tbl, css_dir, key);} + public void Test_skin_tbl(Xowd_css_core_itm[] expd) { + Xowd_css_core_itm[] actl = core_tbl.Select_all(); + Tfds.Eq_str_lines(To_str(expd), To_str(actl)); + } + public void Test_file_tbl(Xowd_css_file_itm[] expd) { + Xowd_css_file_itm[] actl = file_tbl.Select_all(); + Tfds.Eq_str_lines(To_str(expd), To_str(actl)); + } + public void Test_fs(Io_url css_dir, Xowd_css_file_itm[] expd) { + Io_url[] actl = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry(); + int len = expd.length; + Tfds.Eq(len, actl.length); + for (int i = 0; i < len; ++i) { + Xowd_css_file_itm expd_itm = expd[i]; + Tfds.Eq_bry(expd_itm.Data(), Io_mgr.Instance.LoadFilBry(actl[i])); + } + } + private String To_str(Xowd_css_file_itm[] ary) { + int len = ary.length; + for (int i = 0; i < len; ++i) { + Xowd_css_file_itm itm = ary[i]; + bfr.Add_int_variable(itm.Css_id()).Add_byte_pipe().Add_str_u8(itm.Path()).Add_byte_pipe().Add(itm.Data()).Add_byte_nl(); + } + return bfr.To_str_and_clear(); + } + private String To_str(Xowd_css_core_itm[] ary) { + Bry_bfr bfr = Bry_bfr_.New(); + int len = ary.length; + for (int i = 0; i < len; ++i) { + Xowd_css_core_itm itm = ary[i]; + bfr.Add_int_variable(itm.Id()).Add_byte_pipe().Add_str_u8(itm.Key()).Add_byte_pipe().Add_str_u8(itm.Updated_on().XtoStr_fmt_yyyyMMdd_HHmmss()).Add_byte_nl(); + } + return bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/randoms/specials/Rndm_root_special_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/randoms/specials/Rndm_root_special_tst.java new file mode 100644 index 000000000..4757a7c0e --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/randoms/specials/Rndm_root_special_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.randoms.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.randoms.*; +import org.junit.*; import gplx.xowa.specials.*; +public class Rndm_root_special_tst { + @Before public void init() {fxt.Clear();} private Rndm_root_special_fxt fxt = new Rndm_root_special_fxt(); + @Test public void Ns_main() { + fxt.Init_create_page("A"); + fxt.Init_create_page("A/B/C"); + fxt.Test_open("Special:RandomRootPage/Main", "A"); // NOTE: result will always be "A"; "A" -> "A"; "A/B/C" -> "A" + } + @Test public void Ns_help() { + fxt.Init_create_page("Help:A"); + fxt.Init_create_page("Help:A/B/C"); + fxt.Test_open("Special:RandomRootPage/Help", "Help:A"); + } +} +class Rndm_root_special_fxt { + private Xop_fxt parser_fxt; private Rndm_root_special special_page; private Xowe_wiki wiki; + public void Clear() { + parser_fxt = new Xop_fxt(); + parser_fxt.Reset(); + wiki = parser_fxt.Wiki(); + special_page = new gplx.xowa.addons.wikis.pages.randoms.specials.Rndm_root_special(); + } + public void Init_create_page(String page) {parser_fxt.Init_page_create(page, page);} + public void Test_open(String special_url, String expd) { + Xoae_page page = Test_special_open(wiki, special_page, special_url); + Tfds.Eq(expd, String_.new_a7(page.Url().Page_bry())); + Tfds.Eq(expd, String_.new_a7(page.Db().Text().Text_bry())); + } + public static Xoae_page Test_special_open(Xowe_wiki wiki, Xow_special_page special_page, String special_url) { + Xoae_page page = wiki.Parser_mgr().Ctx().Page(); + Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(special_url)); + page.Url_(url); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(special_url)); + page.Ttl_(ttl); + special_page.Special__gen(wiki, page, url, ttl); + return page; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__fxt.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__fxt.java new file mode 100644 index 000000000..dd686a671 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__fxt.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import gplx.core.tests.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.*; +import gplx.xowa.files.*; import gplx.xowa.files.repos.*; +import gplx.xowa.addons.wikis.pages.syncs.core.parsers.*; +public class Xosync_page_loader__fxt { + private final Xosync_page_loader mgr = new Xosync_page_loader(); + private final Bry_bfr tmp_bfr = Bry_bfr_.New(); + private final Xoh_page hpg = new Xoh_page(); + private Xowe_wiki wiki; + public void Clear() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + hpg.Clear(); + } + public Xosync_page_loader__fxt Exec__parse(String raw) { + mgr.Parse(wiki, hpg, Bry_.new_u8(raw)); + return this; + } + public Xosync_page_loader__fxt Test__html(String expd) { + Gftest.Eq__ary__lines(expd, hpg.Db().Html().Html_bry(), "converted html"); + return this; + } + public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, String orig_ext_str, int file_w, double file_time, int file_page) { + Xof_fsdb_itm itm = new Xof_fsdb_itm(); + Xof_ext orig_ext = Xof_ext_.new_by_ext_(Bry_.new_u8(orig_ext_str)); + itm.Init_by_wm_parse(wiki.Domain_itm().Abrv_xo(), repo_is_commons, file_is_orig, Bry_.new_u8(file_ttl), orig_ext, file_w, file_time, file_page); + return itm; + } + public Xosync_page_loader__fxt Test__fsdb(Xof_fsdb_itm expd) { + Xof_fsdb_itm actl = (Xof_fsdb_itm)hpg.Img_mgr().Get_at(0); + Gftest.Eq__str(Xosync_hdoc_parser__fxt.To_str(tmp_bfr, expd), Xosync_hdoc_parser__fxt.To_str(tmp_bfr, actl)); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__tst.java new file mode 100644 index 000000000..ec9e111ed --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/loaders/Xosync_page_loader__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import org.junit.*; +import gplx.langs.htmls.*; +public class Xosync_page_loader__tst { + @Before public void init() {fxt.Clear();} private final Xosync_page_loader__fxt fxt = new Xosync_page_loader__fxt(); + @Test public void File() { + fxt.Exec__parse(Gfh_utl.Replace_apos("ab")) + .Test__html(Gfh_utl.Replace_apos("ab")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "Commons-logo.svg", "svg", 12, -1, -1)) + ; + } + @Test public void Math() { + fxt.Exec__parse(Gfh_utl.Replace_apos("ab")) + .Test__html(Gfh_utl.Replace_apos("ab")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.Y, "596f8baf206a81478afd4194b44138715dc1a05c", "svg", -1, -1, -1)) + ; + } + @Test public void Ogg() { + fxt.Exec__parse(Gfh_utl.Replace_apos("ab")) + .Test__html(Gfh_utl.Replace_apos("ab")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, -1, -1)) + ; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__err__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__err__tst.java new file mode 100644 index 000000000..06a092ff5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__err__tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import org.junit.*; +import gplx.langs.htmls.*; +public class Xosync_hdoc_parser__err__tst { + @Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt(); + @Test public void Url_does_not_start_with_upload_wikimedia_org() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")); + } + @Test public void Unknown_repo() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")); + } + @Test public void Bad_md5() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")); + } + @Test public void Missing_px() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")); + } + @Test public void Bad_file_w() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")); + } + @Test public void Comment() { + fxt.Exec__parse(Gfh_utl.Replace_apos("abc")) + .Test__html(Gfh_utl.Replace_apos("abc")); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__file__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__file__tst.java new file mode 100644 index 000000000..cce71150e --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__file__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import org.junit.*; +import gplx.langs.htmls.*; +public class Xosync_hdoc_parser__file__tst { + @Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt(); + @Test public void Commons__thumb() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.png", 320, -1, -1)); + } + @Test public void Url_encoded() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A,B.png", 320, -1, -1)); + } + @Test public void Local__orig() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.N, Bool_.Y, "A.png", -1, -1, -1)); + } + @Test public void Svg() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.svg", 12, -1, -1)); + } + @Test public void Ogg() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, -1, -1)); + } + @Test public void Ogg__time() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.ogg", "ogv", 320, 1.2, -1)); + } + @Test public void Pdf__page() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.N, "A.djvu", 320, -1, 1)); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__fxt.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__fxt.java new file mode 100644 index 000000000..55293161e --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__fxt.java @@ -0,0 +1,69 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import gplx.core.tests.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.*; +import gplx.xowa.files.*; import gplx.xowa.files.repos.*; +public class Xosync_hdoc_parser__fxt { + private final Xosync_update_mgr mgr = new Xosync_update_mgr(); + private final Bry_bfr tmp_bfr = Bry_bfr_.New(); + private final Xoh_page hpg = new Xoh_page(); + private Xowe_wiki wiki; + public void Clear() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + Xoa_app_fxt.repo2_(app, wiki); + mgr.Init_by_app(app); + mgr.Init_by_page(wiki, hpg); + } + public Xosync_hdoc_parser__fxt Exec__parse(String raw) { + mgr.Parse(hpg, wiki, Bry_.Empty, Bry_.new_u8(raw)); + return this; + } + public Xosync_hdoc_parser__fxt Test__html(String expd) { + Gftest.Eq__ary__lines(expd, hpg.Db().Html().Html_bry(), "converted html"); + return this; + } + public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, int file_w, double file_time, int file_page) { + return Make__fsdb(repo_is_commons, file_is_orig, file_ttl, Xof_ext_.new_by_ttl_(Bry_.new_u8(file_ttl)), file_w, file_time, file_page); + } + public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, String file_ext, int file_w, double file_time, int file_page) { + return Make__fsdb(repo_is_commons, file_is_orig, file_ttl, Xof_ext_.new_by_ext_(Bry_.new_u8(file_ext)), file_w, file_time, file_page); + } + public Xof_fsdb_itm Make__fsdb(boolean repo_is_commons, boolean file_is_orig, String file_ttl, Xof_ext file_ext, int file_w, double file_time, int file_page) { + Xof_fsdb_itm itm = new Xof_fsdb_itm(); + itm.Init_by_wm_parse(wiki.Domain_itm().Abrv_xo(), repo_is_commons, file_is_orig, Bry_.new_u8(file_ttl), file_ext, file_w, file_time, file_page); + return itm; + } + public Xosync_hdoc_parser__fxt Test__fsdb(Xof_fsdb_itm expd) { + Xof_fsdb_itm actl = (Xof_fsdb_itm)hpg.Hdump_mgr().Imgs().Get_at(0); + Gftest.Eq__str(To_str(tmp_bfr, expd), To_str(tmp_bfr, actl)); + return this; + } + public static String To_str(Bry_bfr tmp_bfr, Xof_fsdb_itm itm) { + To_bfr(tmp_bfr, itm); + return tmp_bfr.To_str_and_clear(); + } + private static void To_bfr(Bry_bfr bfr, Xof_fsdb_itm itm) { + bfr.Add_str_a7(itm.Orig_repo_id() == Xof_repo_tid_.Tid__remote ? "remote" : "local").Add_byte_pipe(); + bfr.Add_str_a7(itm.File_is_orig() ? "orig" : "thumb").Add_byte_pipe(); + bfr.Add(itm.Orig_ttl()).Add_byte_pipe(); + bfr.Add(itm.Orig_ext().Ext()).Add_byte_pipe(); + bfr.Add_int_variable(itm.File_w()).Add_byte_pipe(); + bfr.Add_double(itm.Lnki_time()).Add_byte_pipe(); + bfr.Add_int_variable(itm.Lnki_page()).Add_byte_pipe(); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__misc__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__misc__tst.java new file mode 100644 index 000000000..37e6bc779 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__misc__tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import org.junit.*; +import gplx.langs.htmls.*; +public class Xosync_hdoc_parser__misc__tst { + @Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt(); + @Test public void Math() { + fxt.Exec__parse(Gfh_utl.Replace_apos("")) + .Test__html(Gfh_utl.Replace_apos("")) + .Test__fsdb(fxt.Make__fsdb(Bool_.Y, Bool_.Y, "596f8baf206a81478afd4194b44138715dc1a05c.svg", -1, -1, -1)); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__tst.java b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__tst.java new file mode 100644 index 000000000..4b1c97f33 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/pages/syncs/core/parsers/Xosync_hdoc_parser__tst.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.pages.syncs.core.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*; +import org.junit.*; +import gplx.langs.htmls.*; +public class Xosync_hdoc_parser__tst { + @Before public void init() {fxt.Clear();} private final Xosync_hdoc_parser__fxt fxt = new Xosync_hdoc_parser__fxt(); + @Test public void Remove_edit() { + fxt.Exec__parse(Gfh_utl.Replace_apos_concat_lines + ( "

    Section_1" + , "" + , "[edit" + , "]" + , "" + , "

    " + )).Test__html(Gfh_utl.Replace_apos_concat_lines + ( "

    Section_1" + , "" + , "

    " + )); + } +// @Test public void Smoke() { +// fxt.Exec__parse(Io_mgr.Instance.LoadFilStr("C:\\xowa\\dev\\wm.updater.src.html")); +// Io_mgr.Instance.SaveFilBry("C:\\xowa\\dev\\wm.updater.trg.html", fxt.Hdoc().Converted()); +// } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_highlight_mgr_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_highlight_mgr_tst.java new file mode 100644 index 000000000..72fd4468f --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_highlight_mgr_tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; +import org.junit.*; import gplx.xowa.langs.cases.*; +public class Srch_highlight_mgr_tst { + private final Srch_highlight_mgr_tstr tstr = new Srch_highlight_mgr_tstr(); + @Test public void Full__one() {tstr.Test("a" , "A" , "A");} + @Test public void Full__many() {tstr.Test("a b" , "A B" , "A B");} + @Test public void Part__one() {tstr.Test("a" , "A1" , "A1");} + @Test public void Part__many() {tstr.Test("a b" , "A1 B1" , "A1 B1");} + @Test public void Unordered() {tstr.Test("b a" , "A1 B1" , "A1 B1");} + @Test public void Repeat__part() {tstr.Test("a ab" , "Ab A" , "Ab A");} + @Test public void Repeat__full() {tstr.Test("a" , "A A" , "A A");} + @Test public void Close() {tstr.Test("a" , "Ba Aa" , "Ba Aa");} + @Test public void Comma() {tstr.Test("a" , "A, b" , "A, b");} + @Test public void Dash() {tstr.Test("b" , "A-B c" , "A-B c");} + @Test public void Parens() {tstr.Test("a" , "(A)" , "(A)");} + @Test public void Strong() {tstr.Test("strong" , "strong strong" , "strong strong");} + @Test public void Dash_w_mixed_cases() {tstr.Test("b" , "A-a B" , "A-a B");} // search_parser treats A-a separately from a-a + @Test public void Acronymn() {tstr.Test("ab" , "A.B." , "A.B.");} + // @Test public void Slash() {tstr.Test("b" , "A/B/C" , "A/B/C");} +} +class Srch_highlight_mgr_tstr { + private final Srch_highlight_mgr mgr; + private final Xol_case_mgr case_mgr = Xol_case_mgr_.A7(); + public Srch_highlight_mgr_tstr() { + mgr = new Srch_highlight_mgr(case_mgr); + } + public void Test(String search, String title, String expd) { + Tfds.Eq(expd, String_.new_u8(mgr.Search_(Bry_.new_u8(search)).Highlight(Bry_.new_u8(title)))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_text_parser_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_text_parser_tst.java new file mode 100644 index 000000000..7c07f16f5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/parsers/Srch_text_parser_tst.java @@ -0,0 +1,145 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; +import org.junit.*; import gplx.xowa.langs.cases.*; +public class Srch_text_parser_tst { + private final Srch_text_parser_fxt fxt = new Srch_text_parser_fxt(); + @Before public void init() {fxt.Init();} + @Test public void Word__one() {fxt.Clear().Test__split("abcd" , "abcd");} + @Test public void Word__many() {fxt.Clear().Test__split("abc d ef" , "abc", "d", "ef");} + @Test public void Ws__many() {fxt.Clear().Test__split("a b" , "a", "b");} + @Test public void Ws__bgn() {fxt.Clear().Test__split(" a" , "a");} + @Test public void Ws__end() {fxt.Clear().Test__split("a " , "a");} + @Test public void Under() {fxt.Clear().Test__split("a_b" , "a", "b");} // NOTE: same as space + @Test public void Lowercase() {fxt.Clear().Test__split("A B C" , "a", "b", "c");} + @Test public void Dupe() {fxt.Clear().Test__split("a a a" , fxt.Make_word("a", 3));} + @Test public void Dupe__lowercase() {fxt.Clear().Test__split("a A" , fxt.Make_word("a", 2));} + @Test public void Comma__end() {fxt.Clear().Test__split("a, b" , "a", "b");} // EX: "Henry VI, Part 3"; "Bergen County, New Jersey" + @Test public void Comma__mid() {fxt.Clear().Test__split("a,b" , "a,b");} // EX: "20,000 Leagues Under the Sea" + @Test public void Comma__bgn() {fxt.Clear().Test__split(",a b" , "a", "b");} // EX: skip bad usages; EX: "Little Harbour,Pictou ,Nova Scotia"; "The Hindu Succession Act ,1956" + @Test public void Colon__end() {fxt.Clear().Test__split("a: b" , "a", "b");} + @Test public void Colon__mid() {fxt.Clear().Test__split("a:b" , "a:b");} // EX: "3:10 to Yuma (2007 film)"; "6:02 AM EST"; "24:7 Theatre Festival"; "Library of Congress Classification:Class P -- Language and Literature" + @Test public void Colon__bgn() {fxt.Clear().Test__split(":a b" , "a", "b");} + @Test public void Semic__end() {fxt.Clear().Test__split("a; b" , "a", "b");} + @Test public void Semic__mid() {fxt.Clear().Test__split("a;b" , "a;b");} + @Test public void Semic__bgn() {fxt.Clear().Test__split(";a b" , "a", "b");} + @Test public void Bang__end() {fxt.Clear().Test__split("a! b" , "a", "b");} + @Test public void Bang__mid() {fxt.Clear().Test__split("a!b" , "a!b");} + @Test public void Bang__bgn() {fxt.Clear().Test__split("!a b" , "a", "b");} + @Test public void Question__end() {fxt.Clear().Test__split("a? b" , "a", "b");} + @Test public void Question__mid() {fxt.Clear().Test__split("a?b" , "a?b");} + @Test public void Question__bgn() {fxt.Clear().Test__split("?a b" , "a", "b");} + @Test public void Question__sentence() {fxt.Clear().Test__split("a?" , "a");} + @Test public void Multiple__1() {fxt.Clear().Test__split("a?!" , "a");} + @Test public void Multiple__2() {fxt.Clear().Test__split("a!?" , "a");} + @Test public void Dot__word() {fxt.Clear().Test__split("a.org" , "a.org");} // EX: "en.wikipedia.org"; "Earth.png"; "IEEE_802.15" + @Test public void Dot__abrv() {fxt.Clear().Test__split("a vs. b" , "a", "vs.", "vs", "b");} // EX: "vs.", "no.", "dr.", "st.", "inc." + @Test public void Dot__initials() {fxt.Clear().Test__split("a. b. cde" , "a.", "a", "b.", "b", "cde");} // EX: "H. G. Wells" + @Test public void Dot__acronym() {fxt.Clear().Test__split("abc D.E.F. ghi" , "abc", "d.e.f.", "def", "ghi");} // EX: "History of U.S.A. Science", "G.I. Bill", "Washington, D.C."; "Barcelona F.C."; "The Office (U.S.)"; "Agents of S.H.I.E.L.D."; "Gunfight at the O.K. Corral"; "H.M.S. Pinafore"; "R.E.M. discography" + @Test public void Dot__bgn() {fxt.Clear().Test__split("a .bcd e" , "a", ".bcd", "bcd", "e");} // EX: "Colt .45", "List of organizations with .int domain names" + @Test public void Dot__bgn__end() {fxt.Clear().Test__split("a .b. c" , "a", ".b.", "c");} + @Test public void Dot__ellipsis_like() {fxt.Clear().Test__split("a . . . b" , "a", "b");} // EX: "Did you know . . ." + @Test public void Ellipsis__len_3() {fxt.Clear().Test__split("a... bc d" , "a", "...", "bc", "d");} // EX: "Nights into Dreams..." + @Test public void Ellipsis__len_3__bgn() {fxt.Clear().Test__split("a ...b" , "a", "...", "b"); ;} // NOTE: make sure "dot_bgn" code doesn't break this + @Test public void Ellipsis__len_2() {fxt.Clear().Test__split("a.. b" , "a", "..", "b");} // EX: "3.. 6.. 9 Seconds of Light" + @Test public void Ellipsis__bgn() {fxt.Clear().Test__split("...a" , "...", "a");} + @Test public void Ellipsis__end() {fxt.Clear().Test__split("a..." , "a", "...");} + @Test public void Ellipsis__no_ws() {fxt.Clear().Test__split("a...b" , "a", "...", "b");} + @Test public void Ellipsis__term() {fxt.Clear().Test__split("a...?!" , "a", "...");} // EX: "Wetten, dass..?" + @Test public void Apos__merge__end__eos() {fxt.Clear().Test__split("ab's" , "ab's", "abs");} // EX: "A Midsummer Night's Dream"; "Director's cut" + @Test public void Apos__merge__end__word() {fxt.Clear().Test__split("ab's c" , "ab's", "abs", "c");} // EX: "Director's cut"; "Cap'n Crunch"; + @Test public void Apos__merge__bgn() {fxt.Clear().Test__split("a o'bc" , "a", "o'bc", "obc");} // EX: "Twelve O'Clock High"; "Shaqille O'Neal"; "Banca d'Italia" + @Test public void Apos__merge__mid() {fxt.Clear().Test__split("i'm" , "i'm", "im");} + @Test public void Apos__bgn__long() {fxt.Clear().Test__split("a 'tis b" , "a", "'tis", "tis", "b");} // EX: "My Country, 'Tis of Thee"; "Omaha hold 'em"; "Slash'EM"; "Expo '92" + @Test public void Apos__end__eos() {fxt.Clear().Test__split("a'" , "a");} + @Test public void Apos__end__short() {fxt.Clear().Test__split("a' b" , "a", "b");} // EX: "Will-o'-the-wisp"; "Portuguese man o' war"; + @Test public void Apos__end__long() {fxt.Clear().Test__split("ab' c" , "ab", "c");} // EX: "Dunkin' Donuts"; "'Allo 'Allo!"; "Catherine de' Medici" + @Test public void Apos__both__n() {fxt.Clear().Test__split("a 'n' b" , "a", "'n'", "n", "b");} // EX: "Rock 'n' Roll"; "Town 'n' Country, Florida"; "Hill 'n Dale, Florida"; "Chip 'n Dale Rescue Rangers" + @Test public void Apos__multiple() {fxt.Clear().Test__split("ab''cd" , "ab''cd");} + @Test public void Apos__lone() {fxt.Clear().Test__split("' a" , "'", "a");} // EX: "' (disambiguation)" + @Test public void Dash__one() {fxt.Clear().Test__split("a-b" , "a", "b", "a-b");} // EX: "The Amazing Spider-Man"; "On-super percentage"; "Basic Role-Playing"; "Context-sensitive"; "Cross-country skiing"; "Double-barreled shotgun"; "Dot-com bubble"; "Many-worlds interpretation"; "Faster-than-light"; "Gram-positive bacteria"; "Half-life", "Jean-Paul Sartre"; "Austria-Hungary" + @Test public void Dash__many() {fxt.Clear().Test__split("a-b-c" , "a", "b", "c", "a-b-c");} + @Test public void Dash__ws() {fxt.Clear().Test__split("a - b" , "a", "-", "b");} + @Test public void Dash__eos() {fxt.Clear().Test__split("a-" , "a", "a-");} + @Test public void Dash__bos() {fxt.Clear().Test__split("-a" , "a", "-a");} + @Test public void Dash__mult__2() {fxt.Clear().Test__split("--" , "--");} + @Test public void Dash__mult__3() {fxt.Clear().Test__split("---" , "---");} + @Test public void Dash__mult__2__words() {fxt.Clear().Test__split("a--b" , "a", "b", "a--b");} + @Test public void Dash__w_comma() {fxt.Clear().Test__split("a-, b" , "a", "a-", "b");} + @Test public void Slash__one() {fxt.Clear().Test__split("a/b" , "a", "b");} // EX: "Good cop/bad cop"; "Snooker world rankings 2004/2005"; "Debian GNU/Hurd"; "HIV/AIDS in the United States"; "List of minor planets/1�100" + @Test public void Slash__many() {fxt.Clear().Test__split("a/b/c" , "a", "b", "c");} // EX: "Age/sex/location"; + @Test public void Slash__ws() {fxt.Clear().Test__split("a / b" , "a", "b");} + @Test public void Dash__slash() {fxt.Clear().Test__split("a-b/c-d-e/f-g" , "a", "b", "a-b", "c", "d", "e", "c-d-e", "f", "g", "f-g");} + @Test public void Paren__both__one() {fxt.Clear().Test__split("a (b) c" , "a", "b", "c");} // EX: "A (letter)" + @Test public void Paren__both__many() {fxt.Clear().Test__split("a (b c) d" , "a", "b", "c", "d");} // EX: "A (2016 film)" + @Test public void Paren__bgn__multiple() {fxt.Clear().Test__split("a (((b)))" , "a", "b");} + @Test public void Paren__unmatched() {fxt.Clear().Test__split("a(b" , "a(b");} + @Test public void Paren__unmatched__bgn() {fxt.Clear().Test__split("a (b" , "a", "b");} + @Test public void Paren__mid() {fxt.Clear().Test__split("a(b)c" , "a(b)c");} // EX: "Chloro(pyridine)cobaloxime"; "Exi(s)t" + @Test public void Paren__end() {fxt.Clear().Test__split("a(b)" , "a(b)", "a");} // EX: "Come What(ever) May"; "501(c) organization"; "Reindeer(s) Are Better Than People"; "(Miss)understood"; "Chromium(III) picolinate" + @Test public void Paren__bgn() {fxt.Clear().Test__split("(a)b" , "(a)b", "b");} // EX: "International Student Congress of (bio)Medical Sciences" + @Test public void Paren__end__dash() {fxt.Clear().Test__split("a(b-c) d" , "a(b-c)", "a", "d");} // EX: "Bis(2-ethylhexyl) phthalate" + @Test public void Paren__end__comma() {fxt.Clear().Test__split("a(b,c) d" , "a(b,c)", "a", "d");} // EX: "Iron(II,III) oxide" + @Test public void Paren__comma() {fxt.Clear().Test__split("a (b), c" , "a", "b", "c");} // EX: "Corning (city), New York" + @Test public void Paren__multiple() {fxt.Clear().Test__split("(a) (b)" , "a", "b");} + @Test public void Quote__both() {fxt.Clear().Test__split("a \"b\" c" , "a", "b", "c");} + @Test public void Word_bgn__at() {fxt.Clear().Test__split("@a" , "@a", "a");} + @Test public void Word_bgn__tilde() {fxt.Clear().Test__split("~a~" , "a");} // EX: "Phantom ~Requiem for the Phantom~" +} +class Srch_text_parser_fxt { + private final Srch_text_parser word_parser = new Srch_text_parser(); + private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32); + private Xol_case_mgr case_mgr; + public void Init() { + case_mgr = Xol_case_mgr_.A7(); + word_parser.Init_for_ttl(case_mgr); + } + public Srch_text_parser_fxt Clear() { + word_parser.word_hash.Clear(); + return this; + } + public Srch_word_itm Make_word(String raw, int count) {return new Srch_word_itm(Bry_.new_u8(raw)).Count_(count);} + public void Test__split(String src, String... expd_words) { + int len = expd_words.length; + Srch_word_itm[] ary = new Srch_word_itm[len]; + for (int i = 0; i < len; ++i) { + ary[i] = Make_word(expd_words[i], 1); + } + Test__split(src, ary); + } + public void Test__split(String src, Srch_word_itm... expd_words) { + byte[] src_bry = Bry_.new_u8(src); + word_parser.Parse(Bool_.Y, src_bry, 0, src_bry.length); + Tfds.Eq_str_lines(To_str(expd_words), To_str(word_parser.word_hash)); + } + private String To_str(Srch_word_itm[] word_ary) { + int len = word_ary.length; + for (int i = 0; i < len; ++i) { + if (i != 0) tmp_bfr.Add_byte_nl(); + Srch_word_itm word = word_ary[i]; + tmp_bfr.Add(word.Word).Add_byte_pipe(); + tmp_bfr.Add_int_variable(word.Count()); + } + return tmp_bfr.To_str_and_clear(); + } + private String To_str(Srch_word_hash word_mgr) { + int len = word_mgr.Len(); + Srch_word_itm[] ary = new Srch_word_itm[len]; + for (int i = 0; i < len; ++i) + ary[i] = word_mgr.Get_at(i); + return To_str(ary); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/Srch_search_phrase_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/Srch_search_phrase_tst.java new file mode 100644 index 000000000..064ccb09f --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/Srch_search_phrase_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; +import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*; +public class Srch_search_phrase_tst { + private final Srch_search_phrase_fxt fxt = new Srch_search_phrase_fxt(); + @Test public void Word() {fxt.Test__auto_wildcard("a" , "a*");} + @Test public void Paren_end() {fxt.Test__auto_wildcard("(a)" , "(a*)");} + @Test public void Quoted() {fxt.Test__auto_wildcard("\"a\"" , "\"a\"");} + @Test public void Space() {fxt.Test__auto_wildcard(" " , " ");} + @Test public void Not() {fxt.Test__auto_wildcard("-" , "-");} + @Test public void And() {fxt.Test__auto_wildcard("+" , "+");} + @Test public void Or() {fxt.Test__auto_wildcard("," , ",");} + @Test public void Paren_bgn() {fxt.Test__auto_wildcard("(" , "(");} + @Test public void Star() {fxt.Test__auto_wildcard("*" , "*");} + @Test public void Wildcard__exists__y() {fxt.Test__auto_wildcard("a*b" , "a*b");} + @Test public void Wildcard__exists__escaped() {fxt.Test__auto_wildcard("a\\*b" , "a\\*b*");} + @Test public void Wildcard__exists__n() {fxt.Test__auto_wildcard("a* bc" , "a* bc*");} + @Test public void Escape() {fxt.Test__auto_wildcard("\\*" , "\\**");} + @Test public void Escape__incomplete() {fxt.Test__auto_wildcard("a\\" , "a\\");} + @Test public void Escape__escaped() {fxt.Test__auto_wildcard("a\\\\" , "a\\\\*");} + @Test public void Auto_wildcard_n() {fxt.Init__auto_wildcard_n_().Test__auto_wildcard("a", "a");} +} +class Srch_search_phrase_fxt { + private final Srch_crt_scanner_syms syms = Srch_crt_scanner_syms.Dflt; + private boolean auto_wildcard = true; + public Srch_search_phrase_fxt Init__auto_wildcard_n_() {this.auto_wildcard = false; return this;} + public void Test__auto_wildcard(String src_str, String expd) { + byte[] src_raw = Bry_.new_u8(src_str); + byte[] actl = Srch_search_phrase.Auto_wildcard(src_raw, auto_wildcard, syms); + Tfds.Eq(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_parser_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_parser_tst.java new file mode 100644 index 000000000..9f2be3a02 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_parser_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*; +import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*; +public class Srch_crt_parser_tst { + private final Srch_crt_parser_fxt fxt = new Srch_crt_parser_fxt(); + @Test public void Word__one() {fxt.Test__parse("a" , "a");} + @Test public void And__one() {fxt.Test__parse("a + b" , "(a AND b)");} + @Test public void And__many() {fxt.Test__parse("a + b + c" , "(a AND b AND c)");} + @Test public void And__dangling() {fxt.Test__parse("a +" , "a");} + @Test public void And__dupe() {fxt.Test__parse("a + + b" , "(a AND b)");} + @Test public void Quote() {fxt.Test__parse("\"a b\"" , "\"a b\"");} + @Test public void Auto__word() {fxt.Test__parse("a b" , "(a AND b)");} + @Test public void Auto__quote() {fxt.Test__parse("a \"b\"" , "(a AND \"b\")");} + @Test public void Auto__parens() {fxt.Test__parse("a (b , c)" , "(a AND (b OR c))");} + @Test public void Or__one() {fxt.Test__parse("a , b" , "(a OR b)");} + @Test public void Or__many() {fxt.Test__parse("a , b , c" , "(a OR b OR c)");} + @Test public void Mixed__3() {fxt.Test__parse("a + b , c" , "((a AND b) OR c)");} + @Test public void Mixed__5() {fxt.Test__parse("a + b , c + d , e" , "((((a AND b) OR c) AND d) OR e)");} + @Test public void Parens__basic() {fxt.Test__parse("a + (b , c)" , "(a AND (b OR c))");} + @Test public void Parens__nest() {fxt.Test__parse("a + (b , (c + d))" , "(a AND (b OR (c AND d)))");} + @Test public void Parens__mid() {fxt.Test__parse("a + (b , c) + d)" , "(a AND (b OR c) AND d)");} + @Test public void Parens__mixed() {fxt.Test__parse("a + (b , c) , d)" , "((a AND (b OR c)) OR d)");} + @Test public void Parens__dupe() {fxt.Test__parse("((a))" , "a");} + @Test public void Parens__dangling__lhs() {fxt.Test__parse("(a" , "a");} + @Test public void Parens__dangling__rhs() {fxt.Test__parse("a)" , "a");} + @Test public void Parens__empty__bos() {fxt.Test__parse("()" , "");} + @Test public void Parens__empty__mid() {fxt.Test__parse("a () b" , "(a AND b)");} + @Test public void Not__bos() {fxt.Test__parse("-abc" , "NOT abc");} + @Test public void Not__mid() {fxt.Test__parse("a -b" , "(a AND NOT b)");} + @Test public void Not__2() {fxt.Test__parse("a -b -c" , "(a AND NOT b AND NOT c)");} + @Test public void Not__dangling__eos() {fxt.Test__parse("a -" , "a");} + @Test public void Not__dangling__mid() {fxt.Test__parse("a -- b" , "(a AND b)");} // NOTE: scanner will remove spaces and convert to "a", "--", "b" + @Test public void Not__dupe__2() {fxt.Test__parse("a --b" , "(a AND b)");} + @Test public void Not__dupe__3() {fxt.Test__parse("a ---b" , "(a AND NOT b)");} + @Test public void Not__parens() {fxt.Test__parse("a -(b + c)" , "(a AND NOT (b AND c))");} + @Test public void Escape__eos() {fxt.Test__parse("\\" , "");} + @Test public void Escape__escaped() {fxt.Test__parse("\\\\*" , "\\*");} // '\\' -> '\*' +} +class Srch_crt_parser_fxt { + private final Srch_crt_parser crt_parser; + private final Srch_crt_visitor__print visitor__to_str = new Srch_crt_visitor__print(); + public Srch_crt_parser_fxt() { + crt_parser = new Srch_crt_parser(Srch_crt_scanner_syms.Dflt); + Srch_text_parser text_parser = new Srch_text_parser(); + text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); + } + public void Test__parse(String src_str, String expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Srch_crt_mgr crt_mgr = crt_parser.Parse_or_invalid(src_bry); + Tfds.Eq(expd, String_.new_u8(visitor__to_str.Print(crt_mgr.Root))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_scanner_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_scanner_tst.java new file mode 100644 index 000000000..b64426b31 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_scanner_tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*; +import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; +public class Srch_crt_scanner_tst { + private final Srch_crt_scanner_fxt fxt = new Srch_crt_scanner_fxt(); + @Test public void Word() {fxt.Test__scan("abc" , "abc");} + @Test public void Word__many() {fxt.Test__scan("abc d ef" , "abc", "d", "ef");} + @Test public void Word__symbol() {fxt.Test__scan("a; b" , "a;", "b");} + @Test public void And() {fxt.Test__scan("a + b" , "a", "+", "b");} + @Test public void And__parens() {fxt.Test__scan("a +(b)" , "a", "+", "(", "b", ")");} // check that ( causes and to be treated as separate word + @Test public void Or() {fxt.Test__scan("a , b" , "a", ",", "b");} + @Test public void Or__no_space() {fxt.Test__scan("a, b" , "a", ",", "b");} + @Test public void Not() {fxt.Test__scan("-abc" , "-", "abc");} + @Test public void Not__mid__1() {fxt.Test__scan("a-b" , "a-b");} // fails if "a", "-", "b" + @Test public void Not__mid__2() {fxt.Test__scan("a b-c" , "a", "b-c");} // ignore - if in middle of word + @Test public void Not__and() {fxt.Test__scan("a -bc" , "a", "-", "bc");} // auto-add AND for - + @Test public void Not__dangling() {fxt.Test__scan("a -" , "a", "-");} + @Test public void Space() {fxt.Test__scan(" a b " , "a", "b");} // spaces should not generate tkns + @Test public void Quote() {fxt.Test__scan("\"a b\"" , "a b");} + @Test public void Quote__mid() {fxt.Test__scan("a\"b" , "a", "b");} + @Test public void Quote__double() {fxt.Test__scan("\"a\"\"b\"" , "a\"b");} + @Test public void Quote__missing__one() {fxt.Test__scan("\"abc" , "abc");} + @Test public void Quote__missing__many() {fxt.Test__scan("\"abc a" , "abc", "a");} + @Test public void Escape__bgn() {fxt.Test__scan("\\-a" , "-a");} // fails if "-", "a" + @Test public void Escape__and__bgn() {fxt.Test__scan("\\+" , "+");} // fails if "a", "&", "b" + @Test public void Escape__and__mid() {fxt.Test__scan("a\\+b" , "a+b");} // fails if "a", "&", "b" + @Test public void Escape__eos__1() {fxt.Test__scan("\\" , String_.Ary_empty);} + @Test public void Escape__eos__2() {fxt.Test__scan("a \\" , "a");} + @Test public void Escape__eos__3() {fxt.Test__scan("a\\" , "a");} + @Test public void Escape__many() {fxt.Test__scan("c\\+\\+" , "c++");} + @Test public void Escape__end() {fxt.Test__scan("a\\\\" , "a\\");} + @Test public void Complicated() {fxt.Test__scan("(a + \"b\") , -c", "(", "a", "+", "b", ")", ",", "-", "c");} +} +class Srch_crt_scanner_fxt { + private final Srch_crt_scanner scanner; + public Srch_crt_scanner_fxt() { + this.scanner = new Srch_crt_scanner(Srch_crt_scanner_syms.Dflt); + Srch_text_parser text_parser = new Srch_text_parser(); + text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); + } + public void Test__scan(String src_str, String... expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Srch_crt_tkn[] actl_itms = scanner.Scan(src_bry); + Tfds.Eq_ary(expd, To_vals(src_bry, actl_itms)); + } + public void Test__scan_tids(String src_str, byte... expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Srch_crt_tkn[] actl_itms = scanner.Scan(src_bry); + Tfds.Eq_ary(expd, To_tids(actl_itms)); + } + private String[] To_vals(byte[] src, Srch_crt_tkn[] ary) { + int len = ary.length; + String[] rv = new String[len]; + for (int i = 0; i < len; i++) { + Srch_crt_tkn tkn = ary[i]; + rv[i] = String_.new_a7(tkn.Val); + } + return rv; + } + private byte[] To_tids(Srch_crt_tkn[] ary) { + int len = ary.length; + byte[] rv = new byte[len]; + for (int i = 0; i < len; i++) { + Srch_crt_tkn tkn = ary[i]; + rv[i] = tkn.Tid; + } + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_sql_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_sql_tst.java new file mode 100644 index 000000000..e94d18103 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/crts/Srch_crt_sql_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*; +import org.junit.*; +public class Srch_crt_sql_tst { + private final Srch_crt_sql_fxt fxt = new Srch_crt_sql_fxt(); + @Test public void Eq() {fxt.Exec__new_or_null("a").Test__tid(Srch_crt_sql.Tid__eq).Test__eq("a");} + @Test public void Rng() {fxt.Exec__new_or_null("a*").Test__tid(Srch_crt_sql.Tid__rng).Test__rng_bgn("a").Test__rng_end("b").Test__pattern("a*");} + @Test public void Like() {fxt.Exec__new_or_null("a*b").Test__tid(Srch_crt_sql.Tid__like).Test__like("a%b").Test__pattern("a*b");} + @Test public void Like__escape() {fxt.Exec__new_or_null("a|\\*b").Test__tid(Srch_crt_sql.Tid__like).Test__like("a|\\%b").Test__pattern("a\\*b");} // "a\*b" + @Test public void Quote() {fxt.Exec__new_or_null("\"a b\"").Test__tid(Srch_crt_sql.Tid__eq).Test__eq("\"a b\"");} +} +class Srch_crt_sql_fxt { + private Srch_crt_sql actl; + public Srch_crt_sql_fxt Exec__new_or_null(String src_str) { + this.actl = Srch_crt_sql.New_or_null(Bry_.new_u8(src_str), Srch_search_addon.Wildcard__star); + return this; + } + public Srch_crt_sql_fxt Test__tid(int expd) {Tfds.Eq(expd, actl.Tid); return this;} + public Srch_crt_sql_fxt Test__eq(String expd) {Tfds.Eq(expd, actl.Eq); return this;} + public Srch_crt_sql_fxt Test__rng_bgn(String expd) {Tfds.Eq(expd, actl.Rng_bgn); return this;} + public Srch_crt_sql_fxt Test__rng_end(String expd) {Tfds.Eq(expd, actl.Rng_end); return this;} + public Srch_crt_sql_fxt Test__like(String expd) {Tfds.Eq(expd, actl.Like); return this;} + public Srch_crt_sql_fxt Test__pattern(String expd) {Tfds.Eq(expd, String_.new_u8(actl.Pattern.Raw()), "pattern"); return this;} +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_link_wkr_sql_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_link_wkr_sql_tst.java new file mode 100644 index 000000000..fb54670e4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_link_wkr_sql_tst.java @@ -0,0 +1,37 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*; +import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*; +public class Srch_link_wkr_sql_tst { + private final Srch_link_wkr_sql_fxt fxt = new Srch_link_wkr_sql_fxt(); + @Test public void Rng() { + fxt.Run__search("a").Test__eq + ( "select" + ); + } +} +class Srch_link_wkr_sql_fxt { + private final Srch_link_wkr_sql link_wkr = new Srch_link_wkr_sql(); + public Srch_link_wkr_sql_fxt Run__search(String search) { + // attach_mgr.Init(cur_link_tbl.conn, new Db_attach_itm("page_db", ctx.Db__core.Conn()), new Db_attach_itm("word_db", ctx.Tbl__word.conn)); + // link_wkr.Init(ctx, attach_mgr); + // this.actl_sql = link_wkr.Write(ctx, attach_mgr); + link_wkr.Clear(); + return this; + } + public void Test__eq(String... v) { + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_page_tbl_wkr_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_page_tbl_wkr_tst.java new file mode 100644 index 000000000..3e6fa88c8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/searchers/wkrs/Srch_page_tbl_wkr_tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.searchers.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*; +import org.junit.*; import gplx.xowa.addons.wikis.searchs.parsers.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.*; import gplx.xowa.addons.wikis.searchs.searchers.crts.visitors.*; +public class Srch_page_tbl_wkr_tst { + private final Srch_page_tbl_wkr_fxt fxt = new Srch_page_tbl_wkr_fxt(); + @Test public void Word__one() {fxt.Test__to_bry_or_null("a" , "a");} + @Test public void Word__many() {fxt.Test__to_bry_or_null("a b c" , "a b c");} + @Test public void Wild__end() {fxt.Test__to_bry_or_null("a*" , "a");} + @Test public void Wild__both() {fxt.Test__to_bry_or_null("a*b*" , null);} + @Test public void Quote() {fxt.Test__to_bry_or_null("\"a b\"" , "a b");} + @Test public void Quote__mixed() {fxt.Test__to_bry_or_null("a \"b \"\" c\" d" , "a b \" c d");} + @Test public void Escape() {fxt.Test__to_bry_or_null("a\\+" , "a+");} + @Test public void Not() {fxt.Test__to_bry_or_null("a -b" , null);} + @Test public void And() {fxt.Test__to_bry_or_null("a + b" , null);} + @Test public void Or() {fxt.Test__to_bry_or_null("a , b" , null);} + @Test public void Parens() {fxt.Test__to_bry_or_null("(a)" , null);} +} +class Srch_page_tbl_wkr_fxt { + private final Srch_crt_parser crt_parser; + private final Bry_bfr tmp_bfr = Bry_bfr_.New(); + public Srch_page_tbl_wkr_fxt() { + crt_parser = new Srch_crt_parser(Srch_crt_scanner_syms.Dflt); + Srch_text_parser text_parser = new Srch_text_parser(); + text_parser.Init_for_ttl(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); + } + public void Test__to_bry_or_null(String src_str, String expd) { + byte[] src_bry = Bry_.new_a7(src_str); + Srch_crt_mgr crt_mgr = crt_parser.Parse_or_invalid(src_bry); + Tfds.Eq(expd, String_.new_u8(Srch_page_tbl_wkr.To_bry_or_null(tmp_bfr, Srch_search_addon.Wildcard__star, crt_mgr))); + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/Srch_special_searcher_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/Srch_special_searcher_tst.java new file mode 100644 index 000000000..c7787a1be --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/Srch_special_searcher_tst.java @@ -0,0 +1,221 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +//namespace gplx.xowa.addons.wikis.searchs.v1s { +// import org.junit.*; using gplx.xowa.wikis.tdbs; using gplx.xowa.wikis.data.tbls; +// public class Xosrh_core_tst { +// @Before public void Init() {fxt.Clear();} private Xos_search_mgr_fxt fxt = new Xos_search_mgr_fxt(); +// @Test public void Basic() { +// fxt.Init_basic(); +// fxt.Test_search_exact("b2", "B2_22", "B2_12", "B2__2"); +// fxt.Test_search_exact("a" , "A___0"); +// fxt.Test_search_exact("b1a"); // missing: mid +// fxt.Test_search_exact("d"); // missing: end +// fxt.Test_search_exact("$"); // missing: bgn +// fxt.Test_search_match_bgn("b*", "B3_23", "B2_22", "B1_21", "B3_13", "B2_12", "B1_11", "B3__3", "B2__2", "B1__1"); +// } +// @Test public void Page_size() { +// fxt.Init_basic(); +// fxt.Search_mgr().Page_mgr().Itms_per_page_(1); +// fxt.Test_search("b*", 0, "B3_23"); +// fxt.Test_search("b*", 1, "B2_22"); +// fxt.Test_search("b*", 2, "B1_21"); +// fxt.Test_search("b*", 3, "B3_13"); +// } +// @Test public void Url() { +// Xoa_url url = Xow_url_parser_old.Parse_url(fxt.App(), fxt.Wiki(), "Special:Search/Abc?fulltext=y&xowa_sort=len_desc"); +// fxt.Search_mgr().Args_mgr().Clear().Parse(url.Args()); +// Tfds.Eq(Srch_rslt_row_sorter.Tid_len_dsc, fxt.Search_mgr().Args_mgr().Sort_tid()); +// } +// @Test public void Url_arg_title() {// http://en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes&title=Mars +// fxt.Test_url_search_bry("Special:Search?fulltext=y&search=Abc" , "Abc"); // query arg +//// fxt.Test_url_search_bry("Special:Search/Abc?fulltext=y" , "Abc"); // leaf +// fxt.Test_url_search_bry("Special:Search/Abc?fulltext=y&search=Def" , "Def"); // leaf overrides query arg +// } +// @Test public void Url_ns() { +// fxt.Test_url__ns("Special:Search?search=Abc&ns0=1&ns1=1", "0|1"); +// fxt.Test_url__ns("Special:Search?search=Abc&ns*=1", "*"); +// fxt.Test_url__ns("Special:Search?search=Abc", "0"); +// } +// @Test public void Html() { +// fxt.Init_basic(); +// fxt.Test_html_by_url("B1", "", String_.Concat_lines_nl +// ( "Result '''1''' of '''3''' for '''B1'''
    " +// , "{|" +// , "|-" +// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=0|<]]" +// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|>]]" +// , "|-" +// , "| [[Special:Search/B1?fulltext=y&xowa_sort=len_desc|length]]" +// , "| [[Special:Search/B1?fulltext=y&xowa_sort=title_asc|title]]" +// , "|-" +// , "| 42 || [[B1 21]]" +// , "|-" +// , "| 22 || [[B1 11]]" +// , "|-" +// , "| 2 || [[B1 1]]" +// , "|-" +// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=0|<]]" +// , "| [[Special:Search/B1?fulltext=y&xowa_page_index=1|>]]" +// , "|}" +// )); +// } +//// @Test public void Page_next() { +//// fxt.Init_basic(); +//// fxt.Search_mgr().Page_size_(1); +//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 0, "B1 1"); +//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 1, "B1 11"); +//// } +//// @Test public void Misc_url() { +//// fxt.Init_basic(); +//// fxt.Search_mgr().Page_size_(1); +//// fxt.Expd_address_page_("Special:Search/B1"); +//// fxt.Test_search(Srch_special_page.Match_tid_all, "B1", 0, "B1 1"); +//// } +// @Test public void Sort_defaults_to_len_desc() { +// fxt.Init_basic(); +// fxt.Search_mgr().Page_mgr().Itms_per_page_(3); +// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b" , 0, Srch_rslt_row_sorter.Tid_ttl_asc , "B1_11", "B1_21", "B1__1"); // sort by name; note that _ sorts after alphabet +// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b" , 1, Srch_rslt_row_sorter.Tid_none , "B2_12", "B2_22", "B2__2"); // sort by name still; next page should not reset +// fxt.Test_search2(Srch_special_page.Match_tid_bgn, "b2" , 0, Srch_rslt_row_sorter.Tid_none , "B2_22", "B2_12", "B2__2"); // sort by len desc; new search should reset +// } +// } +// class Xos_search_mgr_fxt { +// Xoae_app app; Xowe_wiki wiki; Bry_bfr bfr = Bry_bfr_.Reset(500); Srch_special_page search_mgr; +// public Xoae_app App() {return app;} +// public Xowe_wiki Wiki() {return wiki;} +// public Xobl_regy_itm regy_itm_(int id, String bgn, String end, int count) {return new Xobl_regy_itm(id, Bry_.new_u8(bgn), Bry_.new_u8(end), count);} +// public Xowd_page_itm data_ttl_(int id, String ttl) {return data_ttl_(id, 0, 0, false, 0, ttl);} +// public Xowd_page_itm data_ttl_(int id, int fil, int row, boolean redirect, int len, String ttl) {return new Xowd_page_itm().Init(id, Bry_.new_u8(ttl), redirect, len, fil, row);} +// public Xowd_page_itm data_id_(int id, String ttl) {return data_id_(id, Xow_ns_.Tid__main, ttl);} +// public Xowd_page_itm data_id_(int id, int ns, String ttl) {return new Xowd_page_itm().Id_(id).Ns_id_(ns).Ttl_page_db_(Bry_.new_u8(ttl)).Text_db_id_(0).Text_len_(0);} +// public Xobl_search_ttl data_sttl_(String word, params int[] ids) {return new Xobl_search_ttl(Bry_.new_u8(word), data_ttl_word_page_ary_(ids));} +// public Xobl_search_ttl_page[] data_ttl_word_page_ary_(params int[] ids) { +// int ids_len = ids.length; +// Xobl_search_ttl_page[] rv = new Xobl_search_ttl_page[ids_len]; +// for (int i = 0; i < ids_len; i++) { +// int id = ids[i]; +// rv[i] = new Xobl_search_ttl_page(id, id * 2); +// } +// return rv; +// } +// public void Init_regy_site(byte dir_info, params Xobl_regy_itm[] ary) {Init_regy(wiki.Tdb_fsys_mgr().Url_site_reg(dir_info), ary);} +// public void Init_regy_ns (String ns_num, byte tid, params Xobl_regy_itm[] ary) {Init_regy(wiki.Tdb_fsys_mgr().Url_ns_reg(ns_num, tid), ary);} +// public void Init_regy(Io_url url, Xobl_regy_itm[] ary) { +// int ary_len = ary.length; +// for (int i = 0; i < ary_len; i++) { +// Xobl_regy_itm itm = ary[i]; +// itm.Srl_save(tmp_bfr); +// } +// Io_mgr.Instance.SaveFilBfr(url, tmp_bfr); +// } private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); +// public void Init_data(Io_url fil, params Xobl_data_itm[] ary) { +// Xob_xdat_file xdat_file = new Xob_xdat_file(); +// int ary_len = ary.length; +// for (int i = 0; i < ary_len; i++) { +// Xobl_data_itm itm = ary[i]; +// itm.Srl_save(tmp_bfr); +// xdat_file.Insert(bfr, tmp_bfr.To_bry_and_clear()); +// } +// xdat_file.Save(fil); +// } +// public void Init_basic() { +// this.Init_regy_ns(wiki.Ns_mgr().Ns_main().Num_str(), Xotdb_dir_info_.Tid_search_ttl, this.regy_itm_(0, "A", "C", 5)); +// this.Init_data(wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, Xow_ns_.Tid__main, 0) +// , this.data_sttl_("a" , 0) +// , this.data_sttl_("b1" , 1, 11, 21) +// , this.data_sttl_("b2" , 2, 12, 22) +// , this.data_sttl_("b3" , 3, 13, 23) +// , this.data_sttl_("c" , 4) +// ); +// this.Init_regy_site(Xotdb_dir_info_.Tid_id, this.regy_itm_(0, "A", "C", 11)); +// this.Init_data(wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_id, 0) +// , this.data_id_( 0, "A___0") +// , this.data_id_( 1, "B1__1") +// , this.data_id_( 2, "B2__2") +// , this.data_id_( 3, "B3__3") +// , this.data_id_( 4, "C___4") +// , this.data_id_(11, "B1_11") +// , this.data_id_(12, "B2_12") +// , this.data_id_(13, "B3_13") +// , this.data_id_(21, "B1_21") +// , this.data_id_(22, "B2_22") +// , this.data_id_(23, "B3_23") +// ); +// search_mgr.Page_mgr().Ns_mgr().Add_all(); // WORKAROUND: xdat fmt does not store ns with search data; pages will be retrieved with ns_id = null; force ns_all (instead of allowing ns_main default); +// } +// public void Clear() { +// Io_mgr.Instance.InitEngine_mem(); +// app = Xoa_app_fxt.Make__app__edit(); +// wiki = Xoa_app_fxt.Make__wiki__edit(app); +// search_mgr = wiki.Special_mgr().Page_search(); +// wiki.Appe().Gui_mgr().Search_suggest_mgr().Args_default_str_("ns*=1"); // WORKAROUND: xdat fmt does not store ns with search data; pages will be retrieved with ns_id = null; force ns_all (instead of allowing ns_main default); +// } +// public Srch_special_page Search_mgr() {return search_mgr;} +// public void Test_url_search_bry(String url_str, String expd) { +// Xoa_url url = Xow_url_parser_old.Parse_url(app, wiki, url_str); +// search_mgr.Args_mgr().Clear().Parse(url.Args()); +// Tfds.Eq(expd, String_.new_u8(search_mgr.Args_mgr().Search_bry())); +// } +// public void Test_url__ns(String url_str, String expd) { +// Xoa_url url = Xow_url_parser_old.Parse_url(app, wiki, url_str); +// search_mgr.Args_mgr().Clear().Parse(url.Args()); +// Tfds.Eq(expd, String_.new_a7(search_mgr.Args_mgr().Ns_mgr().Xto_hash_key())); +// } +// public void Test_search_exact(String ttl_str, params String[] expd_ary) {Test_search(ttl_str, 0, expd_ary);} +// public void Test_search_match_bgn(String ttl_str, params String[] expd_ary) {Test_search(ttl_str, 0, expd_ary);} +// public void Test_search(String ttl_str, int page_idx, params String[] expd_ary) { +// byte[] ttl_bry = Bry_.new_a7(ttl_str); +// Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128(); +// Xosrh_rslt_grp page = search_mgr.Page_mgr().Search(bfr, wiki, ttl_bry, page_idx, search_mgr.Page_mgr()); +// bfr.Mkr_rls(); +// Tfds.Eq_ary(expd_ary, Search_itms_to_int_ary(page)); +// } +// public void Test_html_by_url(String ttl_str, String args_str, String expd_html) { +// wiki.Init_needed_(false); +// byte[] ttl_bry = Bry_.new_a7(ttl_str); +// Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry); +// Xoae_page page = Xoae_page.New_test(wiki, ttl); +// byte[] url_bry = Bry_.new_a7("http://en.wikipedia.org/wiki/Special:Search/" + ttl_str + args_str); +// Xoa_url url = wiki.Appe().Url_parser().Parse(url_bry); +// search_mgr.Special__gen(url, page, wiki, ttl); +// Tfds.Eq_str_lines(expd_html, String_.new_u8(page.Root().Data_htm())); +// } +// public void Test_search2(byte match_tid, String ttl_str, int page_idx, byte sort_tid, params String[] expd_ary) { +// Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128(); +// Xow_url_parser_old url_parser = new Xow_url_parser_old(); +// byte[] url_raw = Bry_.new_a7("Special:Search/" + ttl_str + ((match_tid == Srch_special_page.Match_tid_all) ? "" : "*") + "?fulltext=y" + Srch_rslt_row_sorter.Xto_url_arg(sort_tid) + "&xowa_page_size=1&xowa_page_index=" + page_idx); +// Xoa_url url = url_parser.Parse(url_raw); +// Xoa_ttl ttl = Xoa_ttl.Parse(wiki, url_raw); +// Xoae_page page = wiki.Ctx().Page(); +// search_mgr.Special__gen(url, page, wiki, ttl); +// Xosrh_rslt_grp cur_grp = search_mgr.Cur_grp(); +// bfr.Mkr_rls(); +// Tfds.Eq_ary(expd_ary, Search_itms_to_int_ary(cur_grp)); +// } +// String[] Search_itms_to_int_ary(Xosrh_rslt_grp page) { +// int itms_len = page.Itms_len(); +// String[] rv = new String[itms_len]; +// for (int i = 0; i < itms_len; i++) { +// Xowd_page_itm itm = page.Itms_get_at(i); +// rv[i] = String_.new_u8(itm.Ttl_page_db()); +// } +// return rv; +// } +// } +// interface Xobl_data_itm { +// void Srl_save(Bry_bfr bfr); +// } +//} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_html_page_bldr_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_html_page_bldr_tst.java new file mode 100644 index 000000000..ad36189b3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_html_page_bldr_tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*; +import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.wikis.tdbs.*; +import gplx.xowa.wikis.domains.*; +import gplx.xowa.wikis.data.tbls.*; +import gplx.xowa.addons.wikis.searchs.searchers.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*; +public class Srch_html_page_bldr_tst { + @Before public void init() {fxt.Clear();} private Srch_html_page_bldr_fxt fxt = new Srch_html_page_bldr_fxt(); + @Test public void Paging() { + fxt.Test_paging(Bool_.Y, 1, "Next"); + fxt.Test_paging(Bool_.N, 1, "Previous"); + fxt.Test_paging(Bool_.Y, 2, "Next"); + fxt.Test_paging(Bool_.N, 0, " "); + } + @Test public void Rows() { + fxt.Test_rows(new Srch_rslt_row[] {fxt.Make_row(10, "A"), fxt.Make_row(20, "B")}, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " 10" + , " " + , " A" + , " " + , " " + , " " + , " 20" + , " " + , " B" + , " " + , " " + )); + } +} +class Srch_html_page_bldr_fxt { + private Xoae_app app; private Xowe_wiki wiki; private Srch_html_page_bldr html_mgr; private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255); + private int page_id; + public Srch_html_page_bldr_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + html_mgr = new Srch_html_page_bldr(); + } + page_id = 0; + return this; + } + public void Test_paging(boolean fwd, int slab_idx, String expd) { + byte[] search_orig = Bry_.new_a7("A"); + Srch_search_qry qry = Srch_search_qry.New__search_page(Xow_domain_itm_.Ary_empty, wiki, app.Addon_mgr().Itms__search__special().Ns_mgr(), Bool_.N, search_orig, slab_idx, 100); + html_mgr.Init_by_wiki(wiki, wiki.Lang().Num_mgr(), qry); + byte[] paging_link = html_mgr.Bld_paging_link(fwd); + Tfds.Eq(expd, String_.new_a7(paging_link)); + } + public void Test_rows(Srch_rslt_row[] rows, String expd) { + Srch_rslt_list rslts = new Srch_rslt_list(); + Srch_html_row_bldr row_bldr = new Srch_html_row_bldr(wiki.Html__lnki_bldr()); + row_bldr.Init(rslts, 0, rows.length); + for (int i = 0; i < rows.length; ++i) + rslts.Add(rows[i]); + row_bldr.Bfr_arg__add(tmp_bfr); + Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear()); + } + public Srch_rslt_row Make_row(int len, String ttl_str) { + byte[] wiki_bry = Bry_.new_a7("w"); + byte[] ttl_bry = Bry_.new_u8(ttl_str); + ++page_id; + Srch_rslt_row rv = new Srch_rslt_row(Srch_rslt_row.Bld_key(wiki_bry, page_id), wiki_bry, wiki.Ttl_parse(ttl_bry), gplx.xowa.wikis.nss.Xow_ns_.Tid__main, ttl_bry, page_id, len, len, Srch_rslt_row.Page_redirect_id_null); + rv.Page_ttl_highlight = rv.Page_ttl.Full_txt_w_ttl_case(); + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_rslt_cbk_tst.java b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_rslt_cbk_tst.java new file mode 100644 index 000000000..84bb1ddf3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/addons/wikis/searchs/specials/htmls/Srch_rslt_cbk_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*; +import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.guis.cbks.js.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*; +public class Srch_rslt_cbk_tst { + @Before public void init() {fxt.Clear();} private Srch_rslt_cbk_fxt fxt = new Srch_rslt_cbk_fxt(); + @Test public void Basic() { + fxt.Test_add(fxt.Make_rslt(50, "L"), fxt.Make_args_append("xowa_insert_w" , "w.7CL")); // insert new + fxt.Test_add(fxt.Make_rslt(30, "N"), fxt.Make_args_append("xowa_insert_w" , "w.7CN")); // insert below last + fxt.Test_add(fxt.Make_rslt(70, "J"), fxt.Make_args_append("w.7CL" , "w.7CJ")); // insert above first + fxt.Test_add(fxt.Make_rslt(60, "K"), fxt.Make_args_append("w.7CL" , "w.7CK")); // insert above mid + fxt.Test_add(fxt.Make_rslt(40, "M"), fxt.Make_args_append("w.7CN" , "w.7CM")); // insert below mid + fxt.Test_add(fxt.Make_rslt(10, "P")); // insert noop + fxt.Test_add(fxt.Make_rslt(80, "I"), fxt.Make_args_append("w.7CJ" , "w.7CI") , fxt.Make_args_replace("w.7CN")); // insert displace all + fxt.Test_add(fxt.Make_rslt(61, "K1"), fxt.Make_args_append("w.7CK" , "w.7CK1"), fxt.Make_args_replace("w.7CM")); // insert displace mid + } +} +class Srch_rslt_cbk_fxt { + private Srch_html_row_bldr html_row; private static final byte[] Bry_enwiki = Bry_.new_a7("w"); + private Srch_html_row_wkr async; + private Xog_js_wkr__log js_wkr = new Xog_js_wkr__log(); + private Xowe_wiki wiki; + private int page_id; + public void Clear() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app, "w"); + html_row = new Srch_html_row_bldr(wiki.Html__lnki_bldr()); + html_row.Fmtr().Fmt_("~{page_key}"); + async = new Srch_html_row_wkr(html_row, js_wkr, 5, Bry_enwiki); + page_id = 0; + } + public Srch_rslt_row Make_rslt(int len, String ttl) { + byte[] ttl_bry = Bry_.new_a7(ttl); + ++page_id; + byte[] key = Bry_.Add(Bry_enwiki, Byte_ascii.Pipe_bry, ttl_bry); // NOTE: deliberately changing key to use ttl instead of id to make tests more readable + return new Srch_rslt_row(key, Bry_enwiki, wiki.Ttl_parse(ttl_bry), gplx.xowa.wikis.nss.Xow_ns_.Tid__main, ttl_bry, page_id, len, len, Srch_rslt_row.Page_redirect_id_null); + } + public Object[] Make_args_append(String uid, String html) {return Object_.Ary(Xog_js_wkr__log.Proc_append_above, uid, html);} + public Object[] Make_args_replace(String uid) {return Object_.Ary(Xog_js_wkr__log.Proc_replace_html, uid, "");} + public void Test_add(Srch_rslt_row row, Object[]... expd) { + async.On_rslt_found(row); + int expd_len = expd.length; + Tfds.Eq(expd_len, js_wkr.Log__len()); + for (int i = 0; i < expd_len; ++i) { + String expd_str = String_.Concat_with_obj("\n", expd[i]); + String actl_str = String_.Concat_with_obj("\n", js_wkr.Log__get_at(i)); + Tfds.Eq_str_lines(expd_str, actl_str); + } + js_wkr.Log__clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java b/400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java new file mode 100644 index 000000000..8150156f5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/Xoa_app_eval_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps; import gplx.*; import gplx.xowa.*; +import org.junit.*; +import gplx.core.brys.fmtrs.*; +import gplx.xowa.apps.gfs.*; +public class Xoa_app_eval_tst { + Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]"); + } +} +class Xoa_app_eval_fxt { + public void Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + fmtr = Bry_fmtr.new_(); + eval = new Xoa_app_eval(); + fmtr.Eval_mgr_(eval); + Xoa_gfs_mgr.Msg_parser_init(); + } + } private Xoae_app app; Bry_fmtr fmtr; Xoa_app_eval eval; + public void Eval_test(String raw, String expd) { + Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java b/400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java new file mode 100644 index 000000000..df5ad6f49 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps; import gplx.*; import gplx.xowa.*; +import org.junit.*; import gplx.xowa.apps.gfs.*; +public class Xoa_shell_tst { + @Test public void Fetch_page() { // PURPOSE.fix: fetch_page failed with nullRef; DATE:2013-04-12 + Xop_fxt parser_fxt = new Xop_fxt(); + Xoae_app app = parser_fxt.App(); Xowe_wiki wiki = parser_fxt.Wiki(); + parser_fxt.Init_page_create("A", "test"); // need to create page in order for html output to gen + wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); // need to set html_capable in order for div_home to load + Xoa_gfs_mgr.Msg_parser_init(); + wiki.Html_mgr().Portal_mgr().Div_home_fmtr().Fmt_("~{<>app.user.msgs.get('mainpage-description');<>}"); + app.Gfs_mgr().Run_str("app.shell.fetch_page('en.wikipedia.org/wiki/A' 'html');"); // this causes a nullRef error b/c app.user.lang is null + } +} diff --git a/400_xowa/src/gplx/xowa/apps/apis/xowa/addons/bldrs/Xopg_match_mgr__tst.java b/400_xowa/src/gplx/xowa/apps/apis/xowa/addons/bldrs/Xopg_match_mgr__tst.java new file mode 100644 index 000000000..f10d892e9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/apis/xowa/addons/bldrs/Xopg_match_mgr__tst.java @@ -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.apps.apis.xowa.addons.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*; +import org.junit.*; import gplx.core.tests.*; +public class Xopg_match_mgr__tst { + private final Xopg_match_mgr__fxt fxt = new Xopg_match_mgr__fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Specific() { + fxt.Init__set("en.w:A"); + fxt.Test__match_y("A"); + fxt.Test__match_n("AB"); + } + @Test public void Other_wiki() { + fxt.Init__set("fr.w:A"); + fxt.Test__match_n("A"); // note that test defaults to "en.w" as primary wiki + } + @Test public void Wildcard__app() { + fxt.Init__set("*"); + fxt.Test__match_y("A", "B"); + } + @Test public void Wildcard__page() { + fxt.Init__set("en.w:*"); + fxt.Test__match_y("A", "B"); + } + @Test public void Wildcard__page__other() { + fxt.Init__set("fr.w:*"); + fxt.Test__match_n("A", "B"); + } + @Test public void Wildcard__wiki() { + fxt.Init__set("*:A"); + fxt.Test__match_y("A"); + fxt.Test__match_n("B"); + } +} +class Xopg_match_mgr__fxt { + private final Xopg_match_mgr match_mgr = new Xopg_match_mgr(); + private Xowe_wiki wiki; + public void Clear() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + app.User().Wikii().Xwiki_mgr().Add_by_atrs(wiki.Domain_bry(), wiki.Domain_bry()); + } + public void Init__set(String url) { + match_mgr.Set(url); + } + public void Test__match_y(String... urls) {Test__match(Bool_.Y, urls);} + public void Test__match_n(String... urls) {Test__match(Bool_.N, urls);} + private void Test__match(boolean expd, String... urls) { + for (int i = 0; i < urls.length; i++) { + String url = urls[i]; + boolean actl = match_mgr.Match(wiki, Bry_.new_u8(url)); + Gftest.Eq__bool(expd, actl, "match failed", "expd", expd, "url", url); + } + } +} diff --git a/400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java b/400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java new file mode 100644 index 000000000..ef719d09c --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/cfgs/Xowc_xtn_pages_tst.java @@ -0,0 +1,70 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*; +public class Xowc_xtn_pages_tst { + @Before public void init() {fxt.Clear();} private Xowc_xtn_pages_fxt fxt = new Xowc_xtn_pages_fxt(); + @Test public void Init() { + fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by + fxt.Init_names("Foreign_page", "Foreign_page_talk", "Foreign_index", "Foreign_index_talk"); // ns set by .gfs files in /user/wiki/#cfg + fxt.Exec_init(); + fxt.Test_ns_ids(200, 201, 202, 203); + fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk"); + } + @Test public void Spaces() { // PURPOSE: ensure underlines, not space; EX:"Mục_lục" not "Mục lục"; PAGE:vi.s:Việt_Nam_sử_lược/Quyển_II DATE:2015-10-27 + fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by + fxt.Init_names("Foreign page", "Foreign page talk", "Foreign index", "Foreign index talk"); // ns set by .gfs files in /user/wiki/#cfg + fxt.Exec_init(); + fxt.Test_ns_ids(200, 201, 202, 203); + fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk"); + } +} +class Xowc_xtn_pages_fxt { + private Xow_ns_mgr ns_mgr; + private Xowc_xtn_pages cfg_pages; + public void Clear() { + ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); + cfg_pages = new Xowc_xtn_pages(); + } + public Xowc_xtn_pages_fxt Init_ns(int id, String name) { + ns_mgr.Add_new(id, name); + return this; + } + public void Init_names(String page_name, String page_talk_name, String index_name, String index_talk_name) { + cfg_pages.Ns_names_(Bry_.new_a7(page_name), Bry_.new_a7(page_talk_name), Bry_.new_a7(index_name), Bry_.new_a7(index_talk_name)); + } + public void Exec_init() { + ns_mgr.Init_w_defaults(); // init ns_msg + cfg_pages.Init(ns_mgr); // init cfg + } + public void Test_ns_ids(int page_id, int page_talk_id, int index_id, int index_talk_id) { + Tfds.Eq(page_id , cfg_pages.Ns_page_id()); + Tfds.Eq(page_talk_id , cfg_pages.Ns_page_talk_id()); + Tfds.Eq(index_id , cfg_pages.Ns_index_id()); + Tfds.Eq(index_talk_id , cfg_pages.Ns_index_talk_id()); + } + public void Test_ns_canonical(String page_name, String page_talk_name, String index_name, String index_talk_name) { + Test_ns_canonical_itm(page_name , cfg_pages.Ns_page_id()); + Test_ns_canonical_itm(page_talk_name , cfg_pages.Ns_page_talk_id()); + Test_ns_canonical_itm(index_name , cfg_pages.Ns_index_id()); + Test_ns_canonical_itm(index_talk_name , cfg_pages.Ns_index_talk_id()); + } + private void Test_ns_canonical_itm(String name, int expd_ns_id) { + Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_a7(name)); + int actl_ns_id = ns == null ? Int_.Min_value : ns.Id(); + Tfds.Eq(expd_ns_id, actl_ns_id); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java b/400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java new file mode 100644 index 000000000..cd23a65e1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/fmtrs/Xoa_fmtr_itm_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.langs.gfs.*; +public class Xoa_fmtr_itm_tst { + @Before public void init() {fxt.Clear();} private Xoa_fmtr_itm_fxt fxt = new Xoa_fmtr_itm_fxt(); + @Test public void Basic() { + fxt.Init_src("app.wikis;"); + fxt.Init_fmt("domain=~{<>domain;<>};"); + fxt.Test_run("domain=en.wikipedia.org;"); + } +} +class Xoa_fmtr_itm_fxt { + private Xoae_app app; private Xoa_fmtr_itm itm; + public void Clear() { + app = Xoa_app_fxt.Make__app__edit(); + Xoa_app_fxt.Make__wiki__edit(app); // create enwiki + itm = new Xoa_fmtr_itm(app); + GfsCore.Instance.MsgParser_(gplx.langs.gfs.Gfs_msg_bldr.Instance); + } + public Xoa_fmtr_itm_fxt Init_src(String v) {itm.Src_(v); return this;} + public Xoa_fmtr_itm_fxt Init_fmt(String v) {itm.Fmt_(Bry_.new_a7(v)); return this;} + public void Test_run(String expd) { + String actl = itm.Run(); + Tfds.Eq(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java b/400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java new file mode 100644 index 000000000..056f5e3b2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/fsys/Xoa_url_finder_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.core.tests.*; +import gplx.xowa.users.*; +public class Xoa_url_finder_tst { + private final Xoa_url_finder_fxt fxt = new Xoa_url_finder_fxt(); + @Test public void Find_by_css_or_null() { + // init + String wiki = "en.wikipedia.org"; + String file = "logo_night.png"; + String[] subs = String_.Ary("bin", "any", "xowa", "html", "css", "nightmode"); + String expd = null; + + // null case + expd = null; + fxt.Test__Find_by_css_or_null(expd, wiki, file, subs); + + // app_bin + expd = "mem/xowa/bin/any/xowa/html/css/nightmode/logo_night.png"; + fxt.Init__Fsys__save(expd); + fxt.Test__Find_by_css_or_null(expd, wiki, file, subs); + + // usr_bin + expd = "mem/xowa/user/anonymous/app/overrides/bin/any/xowa/html/css/nightmode/logo_night.png"; + fxt.Init__Fsys__save(expd); + fxt.Test__Find_by_css_or_null(expd, wiki, file, subs); + + // wiki_css + expd = "mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo_night.png"; + fxt.Init__Fsys__save(expd); + fxt.Test__Find_by_css_or_null(expd, wiki, file, subs); + } +} +class Xoa_url_finder_fxt { + private final Xoa_url_finder finder; + public Xoa_url_finder_fxt() { + Io_url root_dir = Io_url_.mem_dir_("mem/xowa/"); + Xoa_fsys_mgr app_fsys_mgr = Xoa_fsys_mgr.New_by_plat("lnx", root_dir); + Xou_fsys_mgr usr_fsys_mgr = new Xou_fsys_mgr(root_dir.GenSubDir_nest("user", "anonymous")); + this.finder = new Xoa_url_finder(app_fsys_mgr); + finder.Init_by_user(usr_fsys_mgr); + } + public void Init__Fsys__save(String url) { + Io_mgr.Instance.SaveFilStr(url, ""); + } + public void Test__Find_by_css_or_null(String expd, String wiki, String file, String[] dir_parts) { + Io_url actl = finder.Find_by_css_or(wiki, file, dir_parts, false); + Gftest.Eq__str(expd, actl == null ? null : actl.Raw()); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_gfs__tst.java b/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_gfs__tst.java new file mode 100644 index 000000000..60e7d21d5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_gfs__tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Gfs_php_converter__to_gfs__tst { + @Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt(); + @Test public void Escape_sequences() { + fxt.Test__to_gfs("a\\\"b" , "a\"b"); + fxt.Test__to_gfs("a\\'b" , "a'b"); + fxt.Test__to_gfs("a\\$b" , "a$b"); + fxt.Test__to_gfs("a\\\\b" , "a\\b"); + fxt.Test__to_gfs("a\\nb" , "a\nb"); + fxt.Test__to_gfs("a\\tb" , "a\tb"); + fxt.Test__to_gfs("a\\rb" , "a\rb"); + fxt.Test__to_gfs("a\\ b" , "a\\ b"); // "\ " seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12 + fxt.Test__to_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape + fxt.Test__to_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail + } + @Test public void Tilde() { + fxt.Test__to_gfs("a~b" , "a~~b"); // tilde.escape + } + @Test public void Arguments() { + fxt.Test__to_gfs("a$1b" , "a~{0}b"); // dollar + fxt.Test__to_gfs("a $ b" , "a $ b"); // noop + } +} +class Gfs_php_converter_fxt { + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Clear() {} + public void Test__to_gfs(String raw, String expd) { + byte[] actl = Gfs_php_converter.To_gfs(bfr, Bry_.new_u8(raw)); + Tfds.Eq(expd, String_.new_u8(actl)); + } + public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);} + public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);} + public void Test_Xto_php(String raw, boolean escape_backslash, String expd) { + byte[] actl = Gfs_php_converter.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw)); + Tfds.Eq(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_php__tst.java b/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_php__tst.java new file mode 100644 index 000000000..89474a359 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/gfs/Gfs_php_converter__to_php__tst.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Gfs_php_converter__to_php__tst { + @Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt(); + @Test public void Xto_php() { + fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one + fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many + fxt.Test_Xto_php_escape_y("a~{9}" , "a$10"); // tilde.arg.9 -> 10 + fxt.Test_Xto_php_escape_y("a~~b" , "a~b"); // tilde.escape + fxt.Test_Xto_php_escape_y("a\\b'c\"d$e" , "a\\\\b\\'c\\\"d\\$e"); // backslash.escape_y + fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n + } +} diff --git a/400_xowa/src/gplx/xowa/apps/servers/http/Http_server_wkr__tst.java b/400_xowa/src/gplx/xowa/apps/servers/http/Http_server_wkr__tst.java new file mode 100644 index 000000000..98e6b4345 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/servers/http/Http_server_wkr__tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*; +import org.junit.*; +public class Http_server_wkr__tst { + @Before public void init() {fxt.Clear();} private Http_server_wkr__fxt fxt = new Http_server_wkr__fxt(); + @Test public void Assert_main_page() { + fxt.Init_wiki_main_page("fr.wikiversity.org", "Accueil"); + fxt.Test_assert_main_page("/fr.wikiversity.org/" , "/fr.wikiversity.org/wiki/Accueil"); + fxt.Test_assert_main_page("/fr.wikiversity.org/wiki" , "/fr.wikiversity.org/wiki/Accueil"); + fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/" , "/fr.wikiversity.org/wiki/Accueil"); + fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/A" , "/fr.wikiversity.org/wiki/A"); + } +} +class Http_server_wkr__fxt { + private Xoae_app app; + public void Clear() { + this.app = Xoa_app_fxt.Make__app__edit(); + } + public void Init_wiki_main_page(String domain, String main_page) { + Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(Bry_.new_u8(domain)); + wiki.Props().Main_page_(Bry_.new_u8(main_page)); + } + public void Test_assert_main_page(String url, String expd) { + Tfds.Eq(expd, Http_server_wkr_.Assert_main_page(app, url)); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_msg_rdr_tst.java b/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_msg_rdr_tst.java new file mode 100644 index 000000000..b58dcd165 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_msg_rdr_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*; +import org.junit.*; +import gplx.core.ios.*; import gplx.core.ios.streams.*; +public class Xosrv_msg_rdr_tst { + @Before public void init() {fxt.Clear();} private Xosrv_msg_rdr_fxt fxt = new Xosrv_msg_rdr_fxt(); + @Test public void Parse() { + String raw = "0|0000000045|0000000091|cmd_0|id_0|sender_0|recipient_0|date_0|text_0"; + Xosrv_msg msg = fxt.Test_parse_msg(raw, "cmd_0", "id_0", "sender_0", "recipient_0", "date_0", "text_0"); + fxt.Test_print(msg, raw); + } + @Test public void Err_header_is_invalid() {fxt.Test_parse_err("abcde", "header is invalid");} + @Test public void Err_checksum_failed() {fxt.Test_parse_err("0|0000000000|0000000000|", "checksum failed");} + @Test public void Err_cmd_missing() {fxt.Test_parse_err("0|0000000001|0000000003|a", "pipe not found for cmd_name");} +} +class Xosrv_msg_rdr_fxt { + public Xosrv_msg_rdr_fxt Clear() { + if (msg_rdr == null) { + msg_rdr_stream = new IoStream_mock(); + msg_rdr = new Xosrv_msg_rdr(Bry_.Empty, msg_rdr_stream); + } + msg_rdr_stream.Reset(); + return this; + } private Xosrv_msg_rdr msg_rdr; private IoStream_mock msg_rdr_stream; + public Xosrv_msg Test_parse_msg(String raw, String expd_cmd, String expd_id, String expd_sender, String expd_recipient, String expd_date, String expd_text) { + byte[] raw_bry = Bry_.new_a7(raw); + msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length); + Xosrv_msg msg = msg_rdr.Read(); + Tfds.Eq(String_.new_a7(msg.Cmd_name()) , expd_cmd); + Tfds.Eq(String_.new_a7(msg.Msg_id()) , expd_id); + Tfds.Eq(String_.new_a7(msg.Sender()) , expd_sender); + Tfds.Eq(String_.new_a7(msg.Recipient()) , expd_recipient); + Tfds.Eq(String_.new_a7(msg.Msg_date()) , expd_date); + Tfds.Eq(String_.new_a7(msg.Msg_text()) , expd_text); + return msg; + } + public void Test_parse_err(String raw, String expd_err) { + byte[] raw_bry = Bry_.new_a7(raw); + msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length); + Xosrv_msg msg = msg_rdr.Read(); + String msg_text = String_.new_a7(msg.Msg_text()); + Tfds.Eq_true(String_.Has_at_bgn(msg_text, expd_err), msg_text); + } + public void Test_print(Xosrv_msg msg, String expd) { + Bry_bfr bfr = Bry_bfr_.New(); + msg.Print(bfr); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_server_tst.java b/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_server_tst.java new file mode 100644 index 000000000..c56442f7c --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/servers/tcp/Xosrv_server_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*; +import org.junit.*; +import gplx.core.ios.*; +public class Xosrv_server_tst { + @Before public void init() {fxt.Clear();} private Xosrv_server_fxt fxt = new Xosrv_server_fxt(); + @Test public void Exec_js() { + fxt.Test_exec_js("{\"args\":[\"xowa_exec_test\",\"a\",\"b\"]}", "{\"xowa_js_result\":\"xowa_exec_test|a|b\"}"); + } + @Test public void Exec_js_ary() { + fxt.Test_exec_js("{\"args\":[\"xowa_exec_test_as_array\",\"a\",\"b\"]}", "{\"xowa_js_result\":[\"xowa_exec_test_as_array\",\"a\",\"b\"]}"); + } +} +class Xosrv_server_fxt { + public Xosrv_server_fxt Clear() { + app = Xoa_app_fxt.Make__app__edit(); + Xoa_app_fxt.Init_gui(app, null); // NOTE: null wiki does not matter for test + return this; + } private Xoae_app app; + public void Test_exec_js(String raw, String expd) { + String actl = app.Tcp_server().Exec_js(null, Bry_.new_a7(raw)); + Tfds.Eq(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java b/400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java new file mode 100644 index 000000000..38ee53348 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/setups/Xoa_setup_mgr_tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xoa_setup_mgr_tst { + @Before public void init() {fxt.Clear();} private Xoa_setup_mgr_fxt fxt = new Xoa_setup_mgr_fxt(); + @Test public void Compare() { + fxt.Test_delete_old_dir("mem/dir/", "1.8.1.1" , "1.8.2.1", Bool_.Y); // version is earlier than checkpoint; delete + fxt.Test_delete_old_dir("mem/dir/", "1.8.2.1" , "1.8.2.1", Bool_.N); // version is not earlier than checkpoint; don't delete + fxt.Test_delete_old_dir("mem/dir/", "" , "1.8.2.1", Bool_.Y); // version is empty; delete; + } +} +class Xoa_setup_mgr_fxt { + public void Clear() {} + public void Test_delete_old_dir(String dir_str, String version_prv, String version_del, boolean expd) { + Io_url dir = Io_url_.new_fil_(dir_str); + Io_mgr.Instance.CreateDirIfAbsent(dir); + Xoa_setup_mgr.Delete_old_dir(Gfo_usr_dlg_.Noop, version_prv, version_del, dir); + Tfds.Eq(expd, !Io_mgr.Instance.ExistsDir(dir), version_prv + "|" + version_del); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java b/400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java new file mode 100644 index 000000000..b087cf35a --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/site_cfgs/Xoa_site_cfg_mgr_tst.java @@ -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.apps.site_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +import gplx.core.btries.*; +import gplx.dbs.cfgs.*; +import gplx.langs.jsons.*; import gplx.xowa.wikis.nss.*; +import gplx.xowa.parsers.*; import gplx.xowa.bldrs.wms.*; +public class Xoa_site_cfg_mgr_tst { + private final Xoa_site_cfg_mgr_fxt fxt = new Xoa_site_cfg_mgr_fxt(); + @Before public void init() {fxt.Init();} + @After public void term() {fxt.Term();} + @Test public void Extensiontags__cfg() { + fxt.Init_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 1, "math", "source")); + fxt.Exec_load(); + fxt.Test_extensiontags_y("math" , "source"); + fxt.Test_extensiontags_n("ref" , "graph"); + fxt.Test_extensiontags_y("translate", "languages"); // always whitelist , DATE:2015-10-13 + } + @Test public void Extensiontags__fsys() { + fxt.Init_fsys(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__null, 1, "math", "source")); + fxt.Exec_load(); + fxt.Test_extensiontags_y("math", "source"); + fxt.Test_extensiontags_n("ref" , "graph"); + fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__fsys, 1, "math", "source")); + } + @Test public void Extensiontags__inet() { + fxt.Init_inet(fxt.Make_api(fxt.Make_api_extensiontags("math", "source"))); + fxt.Exec_load(); + fxt.Test_extensiontags_y("math", "source"); + fxt.Test_extensiontags_n("ref" , "graph"); + fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 1, "math", "source")); + } + @Test public void Extensiontags__fallback() { + fxt.Exec_load(); + fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__extensiontags, fxt.Make_data(Xoa_site_cfg_loader_.Tid__fallback, 1)); + fxt.Test_extensiontags_y("math", "source", "ref", "graph"); + } + @Test public void Interwikimap__inet() { + fxt.Init_inet(fxt.Make_api(fxt.Make_api_interwikimap("w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org"))); + fxt.Exec_load(); + fxt.Test_db(Xoa_site_cfg_loader__inet.Qarg__interwikimap, fxt.Make_data(Xoa_site_cfg_loader_.Tid__inet, 2, "w", "https://en.wikipedia.org", "c", "https://commons.wikimedia.org")); + } +// @Test public void Print() { +// String s = fxt.Make_api(fxt.Make_api_interwikimap("k1", "v1", "k2", "v2"), fxt.Make_api_extensiontags2("k3", "v3", "k4", "v4")); +// Tfds.Dbg(s); +// } +} +class Xoa_site_cfg_mgr_fxt { + private final Xoae_app app; private final Xowe_wiki wiki; + private final Xoa_site_cfg_mgr site_cfg_mgr; + private final Db_cfg_tbl cfg_tbl; + private final Json_printer printer = new Json_printer(); + private final Bry_bfr tmp_bfr = Bry_bfr_.New(); + public Xoa_site_cfg_mgr_fxt() { + // Xoa_app_.Usr_dlg_(Xoa_app_.New__usr_dlg__console()); + gplx.core.ios.IoEngine_system.Web_access_enabled = true; // HACK: must manually enable web_access else above tests will fail due to some other test disabling singleton; DATE:2016-12-15 + Xoa_test_.Inet__init(); + this.app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + Xoa_test_.Init__db__edit(wiki); + this.cfg_tbl = wiki.Data__core_mgr().Tbl__cfg(); + this.site_cfg_mgr = app.Site_cfg_mgr(); + } + public void Init() { + Datetime_now.Manual_y_(); Datetime_now.Autoincrement_n_(); + Io_mgr.Instance.InitEngine_mem(); + cfg_tbl.Delete_grp(Xoa_site_cfg_loader__db.Grp__xowa_wm_api); + site_cfg_mgr.Init_loader_bgn(wiki); + app.Utl__inet_conn().Clear(); + } + public void Term() { + Datetime_now.Manual_n_(); + } + public void Init_db(String key, String data) { + cfg_tbl.Assert_bry(Xoa_site_cfg_loader__db.Grp__xowa_wm_api, key, Bry_.new_u8(data)); + } + public void Test_db(String key, String expd) { + byte[] actl = cfg_tbl.Select_bry_or(Xoa_site_cfg_loader__db.Grp__xowa_wm_api, key, null); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } + public void Init_inet(String data) { + String url = Xoa_site_cfg_loader__inet.Bld_url(tmp_bfr, wiki.Domain_str(), site_cfg_mgr.Data_hash(), site_cfg_mgr.Itm_ary()); + app.Utl__inet_conn().Upload_by_bytes(url, Bry_.new_u8(data)); + } + public void Init_fsys(String key, String data) { + Xoa_site_cfg_loader__fsys loader = Xoa_site_cfg_loader__fsys.new_(app); + Io_url url = loader.Make_load_url(wiki.Domain_str(), key); + Io_mgr.Instance.SaveFilStr(url, data); + } + public Xoa_site_cfg_mgr_fxt Exec_load() { + site_cfg_mgr.Load(wiki); + return this; + } + public void Test_extensiontags_y(String... ary) {Test_extensiontags(Bool_.Y, ary);} + public void Test_extensiontags_n(String... ary) {Test_extensiontags(Bool_.N, ary);} + public void Test_extensiontags(boolean expd_exists, String... ary) { + Btrie_slim_mgr trie = wiki.Mw_parser_mgr().Xnde_tag_regy().Get_trie(Xop_parser_tid_.Tid__defn); + int len = ary.length; + for (int i = 0; i < len; ++i) { + String str = ary[i]; + byte[] bry = Bry_.new_u8(str); + boolean actl_exists = trie.Match_exact(bry, 0, bry.length) != null; + Tfds.Eq_bool(expd_exists, actl_exists, str); + } + } + public void Test_inet_qarg(String expd) { + Xoa_site_cfg_loader__inet loader__inet = (Xoa_site_cfg_loader__inet)site_cfg_mgr.Loader_ary()[2]; + String api_url = loader__inet.Api_url(); + Tfds.Eq(expd, String_.Mid(api_url, String_.FindBwd(api_url, "=") + 1)); + } + public String Make_api(byte[]... sections) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + bfr.Add_str_a7("{'query':"); + int len = sections.length; + bfr.Add_str_a7("{"); + for (int i = 0; i < len; ++i) { + if (i != 0) bfr.Add_str_a7(","); + bfr.Add(sections[i]); + } + bfr.Add_str_a7("}"); + bfr.Add_str_a7("}"); + return printer.Print_by_bry(Bry_.new_u8(Json_doc.Make_str_by_apos(bfr.To_str_and_rls()))).To_str(); + } + public byte[] Make_api_interwikimap(String... ary) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + bfr.Add_str_a7("'interwikimap':"); + int len = ary.length; + bfr.Add_str_a7("["); + for (int i = 0; i < len; i += 2) { + if (i != 0) bfr.Add_str_a7(","); + bfr.Add_str_a7("{'prefix':'" + ary[i] + "'"); + bfr.Add_str_a7(",'url':'" + ary[i + 1] + "'"); + bfr.Add_str_a7("}"); + } + bfr.Add_str_a7("]"); + return bfr.To_bry_and_clear(); + } + public byte[] Make_api_extensiontags(String... ary) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + bfr.Add_str_a7("'extensiontags':"); + int len = ary.length; + bfr.Add_str_a7("["); + for (int i = 0; i < len; ++i) { + if (i != 0) bfr.Add_str_a7(","); + bfr.Add_str_a7("'<" + ary[i] + ">'"); + } + bfr.Add_str_a7("]"); + return bfr.To_bry_and_clear(); + } + public String Make_data(int loader_tid, int flds, String... ary) { + Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512(); + if (loader_tid != Xoa_site_cfg_loader_.Tid__null) // null when constructing data for fsys + bfr.Add_str_u8(Xoa_site_cfg_loader__db.Bld_meta(loader_tid)).Add_byte_nl(); + int len = ary.length; + for (int i = 0; i < len; i += flds) { + if (i != 0) bfr.Add_byte_nl(); + for (int j = 0; j < flds; ++j) { + if (j != 0) bfr.Add_byte_pipe(); + bfr.Add_str_u8(ary[i + j]); + } + } + return bfr.To_str_and_rls(); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java new file mode 100644 index 000000000..4cf1d1080 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__basic__tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xoa_url__basic__tst { + private final Xoa_url_fxt fxt = new Xoa_url_fxt(); + @Test public void Eq_page() { + fxt.Test_eq_page(Bool_.Y, "en.wikipedia.org/wiki/A?redirect=yes", "en.wikipedia.org/wiki/A?redirect=yes"); + fxt.Test_eq_page(Bool_.N, "en.wikipedia.org/wiki/A?redirect=no" , "en.wikipedia.org/wiki/A?redirect=yes"); + } +} +class Xoa_url_fxt extends Xow_url_parser_fxt { public void Test_eq_page(boolean expd, String lhs_str, String rhs_str) { + Xoa_url lhs_url = parser.Parse(Bry_.new_u8(lhs_str)); + Xoa_url rhs_url = parser.Parse(Bry_.new_u8(rhs_str)); + Tfds.Eq_bool(expd, lhs_url.Eq_page(rhs_url), "Eq_page"); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java new file mode 100644 index 000000000..abbfc06a4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xoa_url__to_str__tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.xowa.htmls.hrefs.*; +import gplx.xowa.wikis.nss.*; +public class Xoa_url__to_str__tst { + private final Xoa_url__to_str__fxt fxt = new Xoa_url__to_str__fxt(); + @Test public void Http() {fxt.Chk_to_str_href(Bool_.N, "http://a.org/b" , "http://a.org/b");} + @Test public void File() {fxt.Chk_to_str_href(Bool_.N, "file:///C/xowa/file/a.png" , "file:///C/xowa/file/a.png");} + @Test public void Abrv__page() {fxt.Chk_to_str_href(Bool_.N, "/wiki/A" , "A");} + @Test public void Abrv__anch() {fxt.Chk_to_str_href(Bool_.N, "#b" , "#b");} + @Test public void Full__page() {fxt.Chk_to_str_href(Bool_.Y, "/wiki/A" , "en.wikipedia.org/wiki/A");} + @Test public void Full__anch() {fxt.Chk_to_str_href(Bool_.Y, "#b" , "en.wikipedia.org/wiki/Page_1#b");} + @Test public void Vnt() { + Xowe_wiki zh_wiki = fxt.Prep_create_wiki("zh.wikipedia.org"); + gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(zh_wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant")); + fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hans/A" , "zh.wikipedia.org/zh-hans/A"); + fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-hant/A" , "zh.wikipedia.org/zh-hant/A"); + fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/zh-cn/A" , "zh.wikipedia.org/wiki/A"); + fxt.Chk_to_str_href(zh_wiki, Bool_.Y, "/site/zh.wikipedia.org/wiki/A" , "zh.wikipedia.org/wiki/A"); + } + @Test public void Xwiki() { + fxt.Prep_add_xwiki_to_user("fr.wikipedia.org"); + fxt.Chk_to_str_href(Bool_.N, "/site/fr.wikipedia.org/wiki/Page", "fr.wikipedia.org/wiki/Page"); + } + @Test public void Alias() { + fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org"); + Xow_wiki en_d = fxt.Prep_create_wiki("en.wiktionary.org"); + en_d.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all); + fxt.Chk_to_str_href(Bool_.N, "/wiki/wikt:a" , "en.wiktionary.org/wiki/a"); + } + @Test public void Unknown() {fxt.Chk_to_str_href(Bool_.N, "/wiki/{{{extlink}}}" , "");} // {{{extlink}}} not a valid title; return empty +} +class Xoa_url__to_str__fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser(); + public void Chk_to_str_href(boolean full, String raw, String expd) {Chk_to_str_href(cur_wiki, full, raw, expd);} + public void Chk_to_str_href(Xowe_wiki wiki, boolean full, String raw, String expd) { + href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), wiki, Bry__page); + this.Test__to_str(full, expd); + } + private static final byte[] Bry__page = Bry_.new_a7("Page_1"); +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java new file mode 100644 index 000000000..0a20b8973 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xoav_url_parser_tst.java @@ -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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xoav_url_parser_tst { + @Before public void init() {fxt.Clear();} private final Xoav_url_parser_fxt fxt = new Xoav_url_parser_fxt(); + @Test public void Page() { + fxt.Exec_parse_xo_href("http:/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth"); + } + @Test public void Site() { + fxt.Exec_parse_xo_href("http:/site/en.wikipedia.org/wiki/Earth").Test_wiki("en.wikipedia.org").Test_page("Earth"); + } +} +class Xoav_url_parser_fxt { + private Xoav_url_parser url_parser = new Xoav_url_parser(); private Xoav_url url = new Xoav_url(); + public void Clear() { + cur_wiki = Bry_.new_a7("en.wikipedia.org"); + url.Clear(); + } + public Xoav_url_parser_fxt Init_cur_wiki(String v) {cur_wiki = Bry_.new_u8(v); return this;} private byte[] cur_wiki; + public Xoav_url_parser_fxt Test_wiki(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Wiki_bry()); return this;} + public Xoav_url_parser_fxt Test_page(String v) {Tfds.Eq_bry(Bry_.new_u8(v), url.Page_bry()); return this;} + public Xoav_url_parser_fxt Exec_parse_xo_href(String src_str) { + byte[] src_bry = Bry_.new_u8(src_str); + url_parser.Parse_xo_href(url, src_bry, cur_wiki); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__proto_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__proto_tst.java new file mode 100644 index 000000000..956ed259e --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__proto_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__proto_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Relative() { + tstr.Exec__parse("//en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Http__basic() { + tstr.Exec__parse("http://en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Upload__basic() { + tstr.Prep_add_xwiki_to_user("commons.wikimedia.org"); // NOTE: need to add xwiki to be able to resolve "/commons/" + tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg").Test__wiki("commons.wikimedia.org").Test__page("File:C.svg"); // orig + tstr.Exec__parse("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png").Test__wiki("commons.wikimedia.org").Test__page("File:A.png"); // thum + } + @Test public void File__basic() { + tstr.Exec__parse("file:///C:/a/b/c").Test__tid(Xoa_url_.Tid_file); + } + @Test public void Ftp__basic() { + tstr.Exec__parse("ftp://en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_inet); + } + @Test public void Extended() { + tstr.Exec__parse("http://en.wikipedia.org/w/index.php?A=B").Test__wiki("en.wikipedia.org").Test__page("index.php").Test__qargs("?A=B").Test__anch(null); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__qarg__tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__qarg__tst.java new file mode 100644 index 000000000..6dda076bc --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__qarg__tst.java @@ -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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__qarg__tst { + private final Xow_url_parser_fxt fxt = new Xow_url_parser_fxt(); + @Test public void Redirect() { + fxt.Exec__parse("A?redirect=no").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?redirect=no"); + } + @Test public void Action_is_edit() { + fxt.Exec__parse("A?action=edit").Test__wiki("en.wikipedia.org").Test__page("A").Test__action_is_edit_y(); + } + @Test public void Assert_state_cleared() { // PURPOSE.fix: action_is_edit (et. al.) was not being cleared on parse even though Xoa_url reused; DATE:20121231 + fxt.Exec__parse("A?action=edit") .Test__action_is_edit_y(); + fxt.Exec__parse_reuse("B") .Test__action_is_edit_n(); + } + @Test public void Query_arg() { // PURPOSE.fix: query args were not printing out + fxt.Exec__parse("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes").Test__build_str_is_same(); + } + @Test public void Dupe_key() { + fxt.Exec__parse("A?B=C1&B=C2").Test__page("A").Test__qargs("?B=C1&B=C2"); + } + @Test public void Question_is_eos() { + fxt.Exec__parse("A?").Test__wiki("en.wikipedia.org").Test__page("A?").Test__qargs(""); + } + @Test public void Question_is_page() { + fxt.Exec__parse("A?B").Test__wiki("en.wikipedia.org").Test__page("A?B").Test__qargs(""); + } + @Test public void Question_is_anchor() { + fxt.Exec__parse("A#b?c").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b.3Fc"); + } + @Test public void Title_remove_w() { // PURPOSE: fix /w/ showing up as seg; DATE:2014-05-30 + fxt.Exec__parse("http://en.wikipedia.org/w/index.php?title=A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Ctg() { + fxt.Exec__parse("Category:A?pagefrom=A#mw-pages").Test__page("Category:A").Test__qargs("?pagefrom=A").Test__anch("mw-pages"); + } + @Test public void Anch() { + fxt.Exec__parse("A?k1=v1#anch"); + fxt.Test__page("A"); + fxt.Test__anch("anch"); + fxt.Test__qargs("?k1=v1"); + fxt.Test__to_str("en.wikipedia.org/wiki/A?k1=v1#anch"); + } + // DELETED: this is wrong as url should not handle html_entities like = instead # should strictly designate anch_href; DATE:2016-10-10 + // @Test public void Encoded() { + // fxt.Exec__parse("en.wikipedia.org/wiki/A?action=edit&preload=B").Test__wiki("en.wikipedia.org").Test__page("A").Test__qargs("?action==edit=&preload=&=").Test__anch("61.3BB"); // NOTE: this is wrong; fix later + // } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__ttl_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__ttl_tst.java new file mode 100644 index 000000000..512df316e --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__ttl_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__ttl_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Name() { + tstr.Exec__parse("A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Sub_1() { + tstr.Exec__parse("A/b").Test__wiki("en.wikipedia.org").Test__page("A/b"); + } + @Test public void Sub_2() { + tstr.Exec__parse("A/b/c").Test__wiki("en.wikipedia.org").Test__page("A/b/c"); + } + @Test public void Anch() { + tstr.Exec__parse("A#b").Test__wiki("en.wikipedia.org").Test__page("A").Test__anch("b"); + } + @Test public void Anch_w_slash() { // PURPOSE: A/b#c/d was not parsing correctly; PAGE:en.w:Enlightenment_Spain#Enlightened_despotism_.281759%E2%80%931788.29 + tstr.Exec__parse("A/b#c/d").Test__page("A/b").Test__anch("c.2Fd"); + } + @Test public void Ns_category() { + tstr.Exec__parse("Category:A").Test__wiki("en.wikipedia.org").Test__page("Category:A"); + } + @Test public void Main_page__basic() { + tstr.Exec__parse("en.wikipedia.org") .Test__wiki("en.wikipedia.org").Test__page_is_main_y(); + tstr.Exec__parse("en.wikipedia.org/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y(); + tstr.Exec__parse("en.wikipedia.org/wiki") .Test__wiki("en.wikipedia.org").Test__page_is_main_y(); + tstr.Exec__parse("en.wikipedia.org/wiki/") .Test__wiki("en.wikipedia.org").Test__page_is_main_y(); + tstr.Exec__parse("en.wikipedia.org/wiki/A") .Test__wiki("en.wikipedia.org").Test__page_is_main_n(); + } + @Test public void Ns_file__basic() {// PURPOSE: "File:A" should not be mistaken for "file:///" ns + tstr.Exec__parse("File:A").Test__wiki("en.wikipedia.org").Test__page("File:A"); + } + @Test public void Ns_file__nested() {// PURPOSE: handle fictitious "File:A/B/C.png" + tstr.Exec__parse("File:A/B/C.png").Test__wiki("en.wikipedia.org").Test__page("File:A/B/C.png"); // should not be C.png b/c of Gfo_url_parser_old + } + @Test public void Anch__basic() {// DATE:2015-07-26 + tstr.Exec__parse("#A").Test__tid(Xoa_url_.Tid_anch).Test__wiki_is_missing(true).Test__page("").Test__anch("A"); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__url_bar_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__url_bar_tst.java new file mode 100644 index 000000000..45c4b0ac7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__url_bar_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__url_bar_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Basic() { + tstr.Exec__parse_from_url_bar("Page_1").Test__to_str("en.wikipedia.org/wiki/Page_1"); // basic + } + @Test public void Lang() { + tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org"); + tstr.Exec__parse_from_url_bar("uk").Test__to_str("en.wikipedia.org/wiki/Uk"); // lang-like page (uk=Ukraine) should not try to open wiki; DATE:2014-02-07 + } + @Test public void Lang_like() { + tstr.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org", "http://~{1}.wikipedia.org"); // NOTE: fmt needed for Type_is_lang + tstr.Exec__parse_from_url_bar("uk/A").Test__to_str("en.wikipedia.org/wiki/Uk/A"); // uk/A should not try be interpreted as wiki="uk" page="A"; DATE:2014-04-26 + } + @Test public void Macro() { + tstr.Prep_add_xwiki_to_user("fr.wikisource.org"); + tstr.Exec__parse_from_url_bar("fr.s:Auteur:Shakespeare").Test__to_str("fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros + } + @Test public void Main_page__home() { + tstr.Exec__parse_from_url_bar("home").Test__to_str("en.wikipedia.org/wiki/Home"); // home should go to current wiki's home; DATE:2014-02-09 + tstr.Exec__parse_from_url_bar("home/wiki/Main_Page").Test__to_str("home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09 + } + @Test public void Main_page__zhw() { + Xowe_wiki zh_wiki = tstr.Prep_create_wiki("zh.wikipedia.org"); + zh_wiki.Props().Main_page_(Bry_.new_a7("Zh_Main_Page")); + tstr.Exec__parse_from_url_bar("zh.w:Main_Page") .Test__page_is_main_n().Test__to_str("zh.wikipedia.org/wiki/Main_Page"); + tstr.Exec__parse_from_url_bar("zh.w:") .Test__page_is_main_y().Test__to_str("zh.wikipedia.org/wiki/Zh_Main_Page"); + tstr.Exec__parse_from_url_bar("en.w:") .Test__page_is_main_y().Test__to_str("en.wikipedia.org/wiki/Main_Page"); // old bug: still stuck at zh main page due to reused objects + } + @Test public void Mobile() { // PURPOSE: handle mobile links; DATE:2014-05-03 + tstr.Exec__parse_from_url_bar("en.m.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // basic + tstr.Exec__parse_from_url_bar("en.M.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/A"); // upper + tstr.Exec__parse_from_url_bar("A" ).Test__to_str("en.wikipedia.org/wiki/A"); // bounds-check: 0 + tstr.Exec__parse_from_url_bar("A." ).Test__to_str("en.wikipedia.org/wiki/A."); // bounds-check: 1 + tstr.Exec__parse_from_url_bar("A.b" ).Test__to_str("en.wikipedia.org/wiki/A.b"); // bounds-check: 2 + tstr.Exec__parse_from_url_bar("A.b.m." ).Test__to_str("en.wikipedia.org/wiki/A.b.m."); // false-match + tstr.Exec__parse_from_url_bar("en.x.wikipedia.org/wiki/A" ).Test__to_str("en.wikipedia.org/wiki/En.x.wikipedia.org/wiki/A"); // fail + } + @Test public void Missing_page() { + tstr.Exec__parse_from_url_bar("http://a.org").Test__is_null(); // unknown wiki; return null; + tstr.Exec__parse_from_url_bar("http://en.wikipedia.org").Test__to_str("en.wikipedia.org/wiki/Main_Page"); // known wiki; return Main_Page + } + @Test public void Invalid_names() { + tstr.Exec__parse_from_url_bar("http://a/b/c").Test__is_null(); // unknown url + tstr.Exec__parse_from_url_bar("war").Test__to_str("en.wikipedia.org/wiki/War"); // word looks like lang, but is actually page; default to current + } + @Test public void Proper_case() { + tstr.Exec__parse_from_url_bar("a" ).Test__to_str("en.wikipedia.org/wiki/A"); // "a" -> "A" x> "a" + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__wiki_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__wiki_tst.java new file mode 100644 index 000000000..d4011d33f --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__wiki_tst.java @@ -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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__wiki_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Basic() { + tstr.Exec__parse("en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void No_wiki() { // PURPOSE: no "/wiki/" + tstr.Exec__parse("en.wikipedia.org/A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Nested() { + tstr.Exec__parse("en.wikipedia.org/wiki/A/b").Test__wiki("en.wikipedia.org").Test__page("A/b"); + } + @Test public void Slash() { + tstr.Exec__parse("en.wikipedia.org/wiki//A").Test__wiki("en.wikipedia.org").Test__page("/A"); + tstr.Exec__parse("en.wikipedia.org/wiki/A//b").Test__wiki("en.wikipedia.org").Test__page("A//b"); + tstr.Exec__parse("en.wikipedia.org/wiki///A").Test__wiki("en.wikipedia.org").Test__page("//A"); + } + @Test public void Vnt() { + Xowe_wiki wiki = tstr.Wiki(); + gplx.xowa.langs.vnts.Xol_vnt_regy_fxt.Init__vnt_mgr(wiki.Lang().Vnt_mgr(), 0, String_.Ary("zh-hans", "zh-hant")); + tstr.Exec__parse("en.wikipedia.org/zh-hans/A").Test__wiki("en.wikipedia.org").Test__page("A").Test__vnt("zh-hans"); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xcmd_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xcmd_tst.java new file mode 100644 index 000000000..ccd585fef --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xcmd_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xow_url_parser__xcmd_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Basic() { + tstr.Exec__parse("xowa-cmd:xowa.app.version").Test__tid(Xoa_url_.Tid_xcmd).Test__page("xowa.app.version"); + } + @Test public void Encoded() { + tstr.Exec__parse("xowa-cmd:a%22b*c").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a\"b*c"); + } + @Test public void Ignore_anchor_and_qargs() { + tstr.Exec__parse("xowa-cmd:a/b/c?d=e#f").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a/b/c?d=e#f"); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xwiki_tst.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xwiki_tst.java new file mode 100644 index 000000000..37299b134 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser__xwiki_tst.java @@ -0,0 +1,78 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.xowa.wikis.nss.*; +public class Xow_url_parser__xwiki_tst { + private final Xow_url_parser_fxt tstr = new Xow_url_parser_fxt(); + @Test public void Commons() { // PURPOSE: "C" was being picked up as an xwiki to commons; PAGE:no.b:C/Variabler; DATE:2014-10-14 + tstr.Prep_add_xwiki_to_user("c", "commons.wikimedia.org"); // add alias of "c" + tstr.Exec__parse("C/D").Test__tid(Xoa_url_.Tid_page).Test__wiki("en.wikipedia.org").Test__page("C/D"); // should use current wiki (enwiki), not xwiki to commons; also, page should be "C/D", not "D" + } + @Test public void Parse_lang() { + tstr.Prep_add_xwiki_to_wiki("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/~{0}"); + tstr.Exec__parse("http://en.wikipedia.org/wiki/fr:A").Test__tid(Xoa_url_.Tid_page).Test__wiki("fr.wikipedia.org").Test__page("A"); + } + @Test public void Alias_wiki() { + tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org"); + tstr.Exec__parse("s:A/b/c").Test__wiki("en.wikisource.org").Test__page("A/b/c"); + } + @Test public void Xwiki_no_segs() { // PURPOSE: handle xwiki without full url; EX: "commons:Commons:Media_of_the_day"; DATE:2014-02-19 + tstr.Prep_add_xwiki_to_wiki("s", "en.wikisource.org"); + tstr.Exec__parse("s:Project:A").Test__wiki("en.wikisource.org").Test__page("Project:A"); + } + @Test public void Domain_only() { + tstr.Prep_add_xwiki_to_user("fr.wikipedia.org"); + tstr.Exec__parse("fr.wikipedia.org").Test__wiki("fr.wikipedia.org").Test__page(""); + } + @Test public void Domain_and_wiki() { + tstr.Prep_add_xwiki_to_user("fr.wikipedia.org"); + tstr.Exec__parse("fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page(""); + } + @Test public void Domain_and_wiki_w_http() { + tstr.Prep_add_xwiki_to_user("fr.wikipedia.org"); + tstr.Exec__parse("http://fr.wikipedia.org/wiki").Test__wiki("fr.wikipedia.org").Test__page(""); + } + @Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki + Xowe_wiki en_s = tstr.Prep_create_wiki("en.wikisource.org"); + tstr.Exec__parse(en_s, "Category:A").Test__wiki("en.wikisource.org").Test__page("Category:A"); + } + @Test public void Case_sensitive() { + // tstr.Exec__parse("en.wikipedia.org/wiki/a").Test__wiki("en.wikipedia.org").Test__page("A"); + Xowe_wiki en_d = tstr.Prep_create_wiki("en.wiktionary.org"); + Xow_ns_mgr ns_mgr = en_d.Ns_mgr(); + + ns_mgr.Ns_main().Case_match_(Xow_ns_case_.Tid__all); + tstr.Exec__parse("en.wiktionary.org/wiki/a").Test__wiki("en.wiktionary.org").Test__page("a"); + + ns_mgr.Ns_category().Case_match_(Xow_ns_case_.Tid__all); + tstr.Exec__parse("en.wiktionary.org/wiki/Category:a").Test__wiki("en.wiktionary.org").Test__page("Category:a"); + + tstr.Exec__parse("en.wiktionary.org/wiki/A/B/C").Test__page("A/B/C"); + } + @Test public void Xwiki__to_enwiki() { // PURPOSE: handle alias of "wikipedia" and sv.wikipedia.org/wiki/Wikipedia:Main_Page; DATE:2015-07-31 + Xowe_wiki xwiki = tstr.Prep_create_wiki("sv.wikipedia.org"); + tstr.Prep_xwiki(xwiki, "wikipedia", "en.wikipedia.org", null); + tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Wikipedia"); + tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("wikipedia:X"); + tstr.Exec__parse(xwiki, "sv.wikipedia.org/wiki/Wikipedia:X").Test__wiki("sv.wikipedia.org").Test__page("Wikipedia:X"); + } + @Test public void Xwiki__to_ns() { // PURPOSE: handle alias of "wikipedia" in current, but no "Wikipedia" ns in other wiki; PAGE:pt.w:Wikipedia:P�gina_de_testes DATE:2015-09-17 + tstr.Prep_create_wiki("pt.wikipedia.org"); + tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns + tstr.Prep_xwiki(tstr.Wiki(), "wikipedia", "en.wikipedia.org", null); // add alias of "wikipedia" in current wiki + tstr.Exec__parse(tstr.Wiki(), "pt.wikipedia.org/wiki/Wikipedia:X").Test__wiki("pt.wikipedia.org").Test__page("Wikipedia:X"); // should get "pt.wikipedia.org", not "en.wikipedia.org" (through alias) + } +} diff --git a/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java new file mode 100644 index 000000000..ff8fa4fc6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/urls/Xow_url_parser_fxt.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import gplx.xowa.wikis.nss.*; +public class Xow_url_parser_fxt { + protected final Xoae_app app; protected final Xowe_wiki cur_wiki; + protected final Xow_url_parser parser; + protected Xoa_url actl_url; + public Xow_url_parser_fxt() { + this.app = Xoa_app_fxt.Make__app__edit(); + this.cur_wiki = Prep_create_wiki("en.wikipedia.org"); + this.parser = cur_wiki.Utl__url_parser(); + this.actl_url = Xoa_url.blank(); // default to blank for subclasses + } + public Xoae_app App() {return app;} + public Xowe_wiki Wiki() {return cur_wiki;} + public Xowe_wiki Prep_create_wiki(String domain) { + Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(app, domain); + Prep_add_xwiki_to_user(domain); + return rv; + } + public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain) {return Prep_xwiki(cur_wiki, alias, domain, null);} + public Xow_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain, String fmt) {return Prep_xwiki(cur_wiki, alias, domain, fmt);} + public Xow_url_parser_fxt Prep_add_xwiki_to_user(String domain) {return Prep_xwiki(app.Usere().Wiki(), domain, domain, null);} + public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, null);} + public Xow_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain, String fmt) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, fmt);} + public Xow_url_parser_fxt Prep_xwiki(Xow_wiki wiki, String alias, String domain, String fmt) { + wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), Bry_.new_u8_safe(fmt)); + return this; + } + public Xow_ns_mgr Prep_get_ns_mgr_from_meta(String wiki) { + return app.Dbmeta_mgr().Ns__get_or_load(Bry_.new_u8(wiki)); + } + public Xow_url_parser_fxt Exec__parse(String actl_str) {return Exec__parse(cur_wiki, actl_str);} + public Xow_url_parser_fxt Exec__parse(Xow_wiki wiki, String actl_str) { + this.actl_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(actl_str)); + return this; + } + public Xow_url_parser_fxt Exec__parse_reuse(String actl_str) { + this.actl_url = parser.Parse(Bry_.new_u8(actl_str)); + return this; + } + public Xow_url_parser_fxt Exec__parse_from_url_bar(String raw) { + this.actl_url = parser.Parse_by_urlbar_or_null(raw); + return this; + } + public Xow_url_parser_fxt Test__tid(int v) {Tfds.Eq_int(v, actl_url.Tid() , "tid"); return this;} + public Xow_url_parser_fxt Test__is_null() {Tfds.Eq_bool(true, actl_url == null); return this;} + public Xow_url_parser_fxt Test__vnt(String v) {Tfds.Eq_str(v, actl_url.Vnt_bry() , "vnt"); return this;} + public Xow_url_parser_fxt Test__wiki(String v) {Tfds.Eq_str(v, actl_url.Wiki_bry() , "wiki"); return this;} + public Xow_url_parser_fxt Test__wiki_is_missing(boolean v) {Tfds.Eq_bool(v, actl_url.Wiki_is_missing(), "wiki_is_missing"); return this;} + public Xow_url_parser_fxt Test__page(String v) {Tfds.Eq_str(v, actl_url.Page_bry() , "page"); return this;} + public Xow_url_parser_fxt Test__qargs(String v) {Tfds.Eq_str(v, actl_url.Qargs_mgr().To_bry(), "qargs"); return this;} + public Xow_url_parser_fxt Test__page_is_main_y() {return Test__page_is_main(Bool_.Y);} + public Xow_url_parser_fxt Test__page_is_main_n() {return Test__page_is_main(Bool_.N);} + public Xow_url_parser_fxt Test__page_is_main(boolean v) {Tfds.Eq_bool(v, actl_url.Page_is_main() , "page_is_main"); return this;} + public Xow_url_parser_fxt Test__anch(String v) {Tfds.Eq_str(v, actl_url.Anch_bry(), "anch"); return this;} + public Xow_url_parser_fxt Test__action_is_edit_y() {return Test__action_is_edit_(Bool_.Y);} + public Xow_url_parser_fxt Test__action_is_edit_n() {return Test__action_is_edit_(Bool_.N);} + private Xow_url_parser_fxt Test__action_is_edit_(boolean v) {Tfds.Eq_bool(v, actl_url.Qargs_mgr().Match(Xoa_url_.Qarg__action, Xoa_url_.Qarg__action__edit), "action_is_edit"); return this;} + public Xow_url_parser_fxt Test__to_str(String v) {return Test__to_str(Bool_.Y, v);} + public Xow_url_parser_fxt Test__to_str(boolean full, String v) {Tfds.Eq_str(v, actl_url.To_bry(full, Bool_.Y), "To_bry"); return this;} + public Xow_url_parser_fxt Test__build_str_is_same() { + Xow_url_parser parser = new Xow_url_parser(cur_wiki); + Tfds.Eq_str(actl_url.Raw(), parser.Build_str(actl_url), "build_str"); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java b/400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java new file mode 100644 index 000000000..03bcb7d07 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/utls/Xoa_url_encoder__tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; import gplx.core.tests.*; +public class Xoa_url_encoder__tst { + private final Xoa_url_encoder__fxt fxt = new Xoa_url_encoder__fxt(); + @Test public void Syms__diff() {fxt.Test__encode(" &'=+", "_%26%27%3D%2B");} + @Test public void Syms__same() {fxt.Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");} + @Test public void Mixed() {fxt.Test__encode("a &'=+b", "a_%26%27%3D%2Bb");} // PURPOSE: make sure dirty flag is set +} +class Xoa_url_encoder__fxt { + private final Xoa_url_encoder encoder = new Xoa_url_encoder(); + public void Test__encode(String raw, String expd) { + Gftest.Eq__bry(Bry_.new_u8(expd), encoder.Encode(Bry_.new_u8(raw))); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java b/400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java new file mode 100644 index 000000000..7d67d8662 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/versions/Xoa_version_tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; +import org.junit.*; +public class Xoa_version_tst { + @Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt(); + @Test public void Compare() { + fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less + fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more + fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same + fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less + fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less + fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more + fxt.Test_compare("", "" , CompareAble_.Same); // empty:more + } +} +class Xoa_version_fxt { + public void Clear() {} + public void Test_compare(String lhs, String rhs, int expd) { + Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_base_tst.java b/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_base_tst.java new file mode 100644 index 000000000..5f8d64016 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_base_tst.java @@ -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.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*; +import org.junit.*; +// https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main Page&rvprop=timestamp|content +public class Xoapi_orig_base_tst { + Xoapi_orig_base_fxt fxt = new Xoapi_orig_base_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Bld_api_url() { + fxt.Bld_api_url_tst("A.png" , 220, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220&iiurlheight=110"); + fxt.Bld_api_url_tst("A.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220"); + fxt.Bld_api_url_tst("A.png" , 0, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png"); // assert that null width does not write height + fxt.Bld_api_url_tst("A b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A_b.png&iiurlwidth=220"); + fxt.Bld_api_url_tst("A&b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A%26b.png&iiurlwidth=220"); + } + @Test public void Parse_size() { + String raw = ""; + fxt.Parse_size_tst(raw, 220, 110); + } + @Test public void Parse_reg() { + String raw = ""; + fxt.Parse_reg_tst(raw, "commons.wikimedia.org", "Berkheyde-Haarlem.png"); + } +} +class Xoapi_orig_base_fxt { + private Xoae_app app; private Xowe_wiki wiki; private Xoapi_orig_rslts rv = new Xoapi_orig_rslts(); + public void Clear() { + this.app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + public void Bld_api_url_tst(String ttl_str, int w, int h, String expd) { + String actl = Xoapi_orig_wmf.Bld_api_url(wiki.Domain_bry(), Bry_.new_u8(ttl_str), w, h); + Tfds.Eq(expd, actl); + } + public void Parse_size_tst(String xml_str, int expd_w, int expd_h) { + byte[] xml_bry = Bry_.new_u8(xml_str); + Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry); + Tfds.Eq(expd_w, rv.Orig_w()); + Tfds.Eq(expd_h, rv.Orig_h()); + } + public void Parse_reg_tst(String xml_str, String expd_wiki, String expd_page) { + byte[] xml_bry = Bry_.new_u8(xml_str); + Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry); + Tfds.Eq(expd_wiki, String_.new_u8(rv.Orig_wiki())); + Tfds.Eq(expd_page, String_.new_u8(rv.Orig_page())); + } +} diff --git a/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_mok.java b/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_mok.java new file mode 100644 index 000000000..923b5fc76 --- /dev/null +++ b/400_xowa/src/gplx/xowa/apps/wms/apis/origs/Xoapi_orig_mok.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*; +import gplx.xowa.files.downloads.*; +public class Xoapi_orig_mok extends Xoapi_orig_base { + private String wiki_str = "", ttl_str = "", redirect_str = ""; private int orig_w, orig_h; private boolean fail = false; + public Xoapi_orig_mok Ini(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h, boolean pass) { + this.wiki_str = wiki_str; this.ttl_str = ttl_str; this.redirect_str = redirect_str; this.orig_w = orig_w; this.orig_h = orig_h; this.fail = !pass; + return this; + } + public void Clear() {wiki_str = ttl_str = redirect_str = ""; orig_w = orig_h = 0;} + @Override public boolean Api_query_size_exec(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, byte[] ttl, int width, int height, Gfo_usr_dlg usr_dlg, byte[] repo_wiki_key) { + if (!Bry_.Eq(ttl, Bry_.new_u8(ttl_str))) return false; + if (!String_.Eq(wiki_str, String_.new_a7(repo_wiki_key))) return false; + if (fail) return false; + byte[] orig_page = String_.Eq(redirect_str, "") ? ttl : Bry_.new_u8(redirect_str); + rv.Init_all(repo_wiki_key, orig_page, orig_w, orig_h); + return true; + } + public static final Xoapi_orig_mok Instance = new Xoapi_orig_mok(); Xoapi_orig_mok() {} +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java b/400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java new file mode 100644 index 000000000..d8a8a7e52 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java @@ -0,0 +1,92 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs; import gplx.*; import gplx.xowa.*; +import gplx.core.primitives.*; import gplx.core.strings.*; +import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.addons.wikis.ctgs.*; +import gplx.xowa.wikis.nss.*; +import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; +import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.infos.*; +import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; +public class Db_mgr_fxt { + public Db_mgr_fxt Ctor_fsys() {bldr_fxt = new Xob_fxt().Ctor(Xoa_test_.Url_root().GenSubDir("root")); return this;} + public Db_mgr_fxt Ctor_mem() {bldr_fxt = new Xob_fxt().Ctor_mem(); return this;} private Xob_fxt bldr_fxt; + public Xowd_page_itm page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xowd_page_itm().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Redirected_(type_redirect).Text_len_(text_len);} + public Xowe_wiki Wiki() {return bldr_fxt.Wiki();} + public Xob_bldr Bldr() {return bldr_fxt.Bldr();} + public Db_mgr_fxt doc_ary_(Xowd_page_itm... v) {bldr_fxt.doc_ary_(v); return this;} + public Xowd_page_itm doc_(int id, String date, String title, String text) {return bldr_fxt.doc_(id, date, title, text);} + public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, text);} + public Xowd_page_itm doc_ttl_(int id, String title) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, "IGNORE");} + public Db_mgr_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);} + public Db_mgr_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;} + public Db_mgr_fxt Exec_run(Xob_page_wkr wkr) {bldr_fxt.Run_page_wkrs(wkr); return this;} + public Db_mgr_fxt Exec_run(Xob_cmd cmd) {bldr_fxt.Run_cmds(cmd); return this;} + public Db_mgr_fxt Exec_run(Xobd_parser_wkr wkr) {bldr_fxt.Run(wkr); return this;} + public void Init_page_insert(Int_obj_ref page_id_next, int ns_id, String[] ttls) { + Xowe_wiki wiki = this.Wiki(); + int len = ttls.length; + DateAdp modified_on = Datetime_now.Dflt_add_min_(0); + Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page(); + tbl_page.Insert_bgn(); + for (int i = 0; i < len; i++) { + String ttl = ttls[i]; + int page_id = page_id_next.Val(); + tbl_page.Insert_cmd_by_batch(page_id, ns_id, Bry_.new_u8(ttl), false, modified_on, 0, page_id, 0, 0, -1); + page_id_next.Val_add(1); + } + tbl_page.Insert_end(); + } + public void Test_load_ttl(int ns_id, String ttl_str, Xowd_page_itm expd) { + Xowe_wiki wiki = bldr_fxt.Wiki(); + Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id); + byte[] ttl_bry = Bry_.new_a7(ttl_str); + wiki.Db_mgr_as_sql().Load_mgr().Load_by_ttl(actl, ns, ttl_bry); + Tfds.Eq(expd.Id(), actl.Id()); + Tfds.Eq_date(expd.Modified_on(), actl.Modified_on()); + Tfds.Eq(expd.Redirected(), actl.Redirected()); + Tfds.Eq(expd.Text_len(), actl.Text_len()); + } private Xowd_page_itm actl = new Xowd_page_itm(); + public void Test_load_page(int ns_id, int page_id, String expd) { + Xowe_wiki wiki = bldr_fxt.Wiki(); + Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id); + wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns); + Tfds.Eq(expd, String_.new_a7(actl.Text())); + } + int[] Xto_int_ary(List_adp rslts) { + int len = rslts.Count(); + int[] rv = new int[len]; + for (int i = 0; i < len; i++) { + Xowd_page_itm page = (Xowd_page_itm)rslts.Get_at(i); + rv[i] = page.Id(); + } + return rv; + } + public void Test_file(String url, String expd) { + String actl = Io_mgr.Instance.LoadFilStr(url); + Tfds.Eq_str_lines(expd, actl); + } + public void Init_db_sqlite() { + Xowe_wiki wiki = this.Wiki(); + Db_conn_pool.Instance.Rls_all(); + Db_conn_bldr.Instance.Reg_default_sqlite(); + Io_mgr.Instance.DeleteDir_cmd(wiki.Fsys_mgr().Root_dir()).MissingIgnored_().Exec(); + wiki.Db_mgr_create_as_sql().Core_data_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test); + Io_mgr.Instance.SaveFilStr(wiki.Import_cfg().Src_dir().GenSubFil("a.xml"), ""); + } + public void Rls() { + this.Wiki().Db_mgr_as_sql().Core_data_mgr().Rls(); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java b/400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java new file mode 100644 index 000000000..68a69aa33 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/Xob_base_fxt.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs; import gplx.*; import gplx.xowa.*; +import gplx.core.ios.*; +import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.wikis.data.tbls.*; +public class Xob_base_fxt { + public Xob_base_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + bldr = Xoa_app_fxt.bldr_(app); + } + this.Init_(bldr, wiki); + Clear_hook(); + return this; + } + @gplx.Virtual public void Clear_hook() {} + public Xob_base_fxt Init_(Xob_bldr bldr, Xowe_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;} + public Xoae_app App() {return app;} private Xoae_app app; + public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public Gfo_invk Bldr_itm() {return bldr_itm;} Gfo_invk bldr_itm; + public Xowd_page_itm page_(String ttl) {return page_(ttl, "");} + public Xowd_page_itm page_(String ttl, String text) {return new Xowd_page_itm().Ttl_(Bry_.new_u8(ttl), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));} + public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);} + public void Init_fxts(Xob_bldr bldr, Xowe_wiki wiki, Xob_base_fxt... fxt_ary) { + int fxt_ary_len = fxt_ary.length; + for (int i = 0; i < fxt_ary_len; i++) + fxt_ary[i].Init_(bldr, wiki); + } + public Xob_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);} + public Xob_base_fxt Init_fil(Io_url url, String raw) {Io_mgr.Instance.SaveFilStr(url, raw); return this;} + public Xob_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) { + Xob_cmd cmd = (Xob_cmd)bldr.Cmd_mgr().Add_cmd(wiki, cmd_key); + this.bldr_itm = cmd; + int len = msgs.length; + GfsCtx ctx = GfsCtx.new_(); + for (int i = 0; i < len; i++) { + GfoMsg msg = msgs[i]; + cmd.Invk(ctx, GfsCtx.Ikey_null, msg.Key(), msg); + } + Run_cmd(bldr, cmd); + return this; + } + public Xob_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);} + public Xob_base_fxt Test_fil(Io_url url, String expd) { + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); + return this; + } + public static void Run_cmd(Xob_bldr bldr, Xob_cmd cmd) { + cmd.Cmd_bgn(bldr); + cmd.Cmd_run(); + cmd.Cmd_end(); + } + public static void Run_wkr(Xob_bldr bldr, Xob_page_wkr wkr, Xowd_page_itm[] page_ary) { + wkr.Page_wkr__bgn(); + int page_ary_len = page_ary.length; + for (int i = 0; i < page_ary_len; i++) { + Xowd_page_itm page = page_ary[i]; + wkr.Page_wkr__run(page); + } + wkr.Page_wkr__end(); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java b/400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java new file mode 100644 index 000000000..f9cf96fb8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java @@ -0,0 +1,154 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs; import gplx.*; import gplx.xowa.*; +import gplx.core.tests.*; import gplx.core.ios.*; import gplx.core.times.*; +import gplx.dbs.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*; +import gplx.xowa.bldrs.wkrs.*; +public class Xob_fxt { + private final Tst_mgr tst_mgr = new Tst_mgr(); + private final DateAdp_parser dateParser = DateAdp_parser.new_(); + public Xob_fxt Ctor_mem() { + Io_mgr.Instance.InitEngine_mem(); + return Ctor(Io_url_.mem_dir_("mem/xowa/")); + } + public Xob_fxt Ctor(Io_url root_dir) { + Db_conn_bldr.Instance.Reg_default_sqlite(); + app = Xoa_app_fxt.Make__app__edit("linux", root_dir); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + bldr = Xoa_app_fxt.bldr_(app); + return this; + } + public Xoae_app App() {return app;} private Xoae_app app; + public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public Xob_fxt Fil_expd(Io_url url, String... expd) { + String text = String_.Concat_lines_nl_skip_last(expd); // skipLast b/c if trailing line wanted, easier to pass in extra argument for "" + expd_list.Add(new Io_fil_chkr(url, text)); + return this; + } List_adp expd_list = List_adp_.New(); + public Xob_fxt Fil_skip(Io_url... urls) { + for (int i = 0; i < urls.length; i++) + skip_list.Add(urls[i]); + return this; + } List_adp skip_list = List_adp_.New(); + public Xob_fxt doc_ary_(Xowd_page_itm... v) {doc_ary = v; return this;} private Xowd_page_itm[] doc_ary; + public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);} + public Xowd_page_itm doc_(int id, String date, String title, String text) { + Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_u8(title), wiki.Ns_mgr()).Text_(Bry_.new_u8(text)); + int[] modified_on = new int[7]; + dateParser.Parse_iso8651_like(modified_on, date); + rv.Modified_on_(DateAdp_.seg_(modified_on)); + return rv; + } + public Xob_fxt Run_id() { + Xob_make_id_wkr wkr = new Xob_make_id_wkr(bldr, wiki); + Run_page_wkrs(wkr); + return this; + } + private void Run_wkr(Xob_page_wkr wkr) { + wkr.Page_wkr__bgn(); + for (int i = 0; i < doc_ary.length; i++) { + Xowd_page_itm page = doc_ary[i]; + wkr.Page_wkr__run(page); + } + wkr.Page_wkr__end(); + } + private void tst_fils(Io_url[] ary) { + Io_fil[] actls = Get_actl(ary); + Io_fil_chkr[] expds = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class); + tst_mgr.Tst_ary("all", expds, actls); + } + Io_fil[] Get_actl(Io_url[] ary) { + int len = ary.length; + Io_fil[] rv = new Io_fil[len]; + for (int i = 0; i < len; i++) { + Io_url url = ary[i]; + String data = Io_mgr.Instance.LoadFilStr(url); + rv[i] = new Io_fil(url, data); + } + return rv; + } + public Xob_fxt Run_tmpl_dump() { + Xob_parse_dump_templates_cmd wkr = new Xob_parse_dump_templates_cmd(bldr, wiki); + Run_wkr(wkr); + tst_fils(wkr.Dump_url_gen().Prv_urls()); + return this; + } + public Xob_fxt Run(Xobd_parser_wkr... wkrs) { + Xobd_parser parser_wkr = new Xobd_parser(bldr); + int len = wkrs.length; + for (int i = 0; i < len; i++) + parser_wkr.Wkr_add(wkrs[i]); + Run_page_wkrs(parser_wkr); + return this; + } + public Xob_fxt Run_page_wkrs(Xob_page_wkr... wkrs) { + int doc_ary_len = doc_ary.length; + for (int j = 0; j < wkrs.length; j++) { + Xob_page_wkr wkr = wkrs[j]; + wkr.Page_wkr__bgn(); + for (int i = 0; i < doc_ary_len; i++) { + Xowd_page_itm page = doc_ary[i]; + wkr.Page_wkr__run(page); + } + wkr.Page_wkr__end(); + } + Test_expd_files(); + return this; + } + public Xob_fxt Run_cmds(Xob_cmd... cmds) { + for (int j = 0; j < cmds.length; j++) { + Xob_cmd cmd = cmds[j]; + cmd.Cmd_bgn(bldr); + cmd.Cmd_run(); + cmd.Cmd_end(); + } + Test_expd_files(); + return this; + } + private void Test_expd_files() { + if (expd_list.Count() > 0) { + Io_fil_chkr[] expd = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class); + Io_fil[] actl = wiki_(); + tst_mgr.Tst_ary("all", expd, actl); + } + } + Io_fil[] wiki_() { + List_adp rv = List_adp_.New(); + wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Ns_dir()); + wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Site_dir()); + rv.Sort(); + return (Io_fil[])rv.To_ary(Io_fil.class); + } + private void wiki_fil_add(List_adp list, Io_url root_dir) { + Io_url[] ary = Io_mgr.Instance.QueryDir_args(root_dir).Recur_().ExecAsUrlAry(); + for (int i = 0; i < ary.length; i++) { + Io_url url = ary[i]; + Io_fil fil = new Io_fil(url, Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec()); + list.Add(fil); + } + } + + public void Run_page_wkr(Xob_page_wkr wkr, Xowd_page_itm... pages) { + int len = pages.length; + wkr.Page_wkr__bgn(); + for (int i = 0; i < len; i++) { + Xowd_page_itm page = pages[i]; + wkr.Page_wkr__run(page); + } + wkr.Page_wkr__end(); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/cmds/texts/tdbs/Xob_init_base_tst.java b/400_xowa/src/gplx/xowa/bldrs/cmds/texts/tdbs/Xob_init_base_tst.java new file mode 100644 index 000000000..68ce799b4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/cmds/texts/tdbs/Xob_init_base_tst.java @@ -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.bldrs.cmds.texts.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*; +import org.junit.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.xwikis.*; +public class Xob_init_base_tst { + @Before public void init() {fxt.Clear();} private Xob_init_base_fxt fxt = new Xob_init_base_fxt(); + @Test public void Dirty_wiki_itms() { + Xoae_app app = fxt.App(); Xowe_wiki wiki = fxt.Wiki(); + Xoa_available_wikis_mgr wikis_list = fxt.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis(); + Tfds.Eq("", wikis_list.Itms_as_html()); // assert + Xow_xwiki_itm xwiki_itm = app.Usere().Wiki().Xwiki_mgr().Add_by_atrs("en.wikipedia.org", "en.wikipedia.org"); + xwiki_itm.Offline_(Bool_.Y); // simulate add via Available_from_fsys; DATE:2014-09-21 + Tfds.Eq("", wikis_list.Itms_as_html()); // still empty + new Xob_init_tdb(app.Bldr(), wiki).Cmd_end(); // mock "init" task + Tfds.Eq("\n
  • en.wikipedia.org
  • ", wikis_list.Itms_as_html()); // no longer empty + } +} +class Xob_init_base_fxt { + public void Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + Io_mgr.Instance.InitEngine_mem(); + } + public Xoae_app App() {return app;} private Xoae_app app; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; +} diff --git a/400_xowa/src/gplx/xowa/bldrs/cmds/texts/xmls/Xob_siteinfo_parser__tst.java b/400_xowa/src/gplx/xowa/bldrs/cmds/texts/xmls/Xob_siteinfo_parser__tst.java new file mode 100644 index 000000000..182407d7b --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/cmds/texts/xmls/Xob_siteinfo_parser__tst.java @@ -0,0 +1,108 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.cmds.texts.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.*; +import org.junit.*; import gplx.xowa.wikis.nss.*; +public class Xob_siteinfo_parser__tst { + private final Xob_siteinfo_parser__fxt fxt = new Xob_siteinfo_parser__fxt(); + @Test public void Basic__simplewikt() { // PURPOSE: basic test of siteinfo parse; DATE:2015-11-01 + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( " " + , " Wiktionary" + , " simplewiktionary" + , " https://simple.wiktionary.org/wiki/Main_Page" + , " MediaWiki 1.27.0-wmf.3" + , " case-sensitive" + , " " + , " Media" + , " Special" + , " " + , " Talk" + , " User" + , " User talk" + , " Wiktionary" + , " Wiktionary talk" + , " File" + , " File talk" + , " MediaWiki" + , " MediaWiki talk" + , " Template" + , " Template talk" + , " Help" + , " Help talk" + , " Category" + , " Category talk" + , " Module" + , " Module talk" + , " Gadget" + , " Gadget talk" + , " Gadget definition" + , " Gadget definition talk" + , " Topic" + , " " + , " " + ), String_.Concat_lines_nl + ( "Main_Page|case-sensitive|Wiktionary|simplewiktionary|MediaWiki 1.27.0-wmf.3" + , "-2|case-sensitive|Media" + , "-1|first-letter|Special" + , "0|case-sensitive|" + , "1|case-sensitive|Talk" + , "2|first-letter|User" + , "3|first-letter|User talk" + , "4|case-sensitive|Wiktionary" + , "5|case-sensitive|Wiktionary talk" + , "6|case-sensitive|File" + , "7|case-sensitive|File talk" + , "8|first-letter|MediaWiki" + , "9|first-letter|MediaWiki talk" + , "10|case-sensitive|Template" + , "11|case-sensitive|Template talk" + , "12|case-sensitive|Help" + , "13|case-sensitive|Help talk" + , "14|case-sensitive|Category" + , "15|case-sensitive|Category talk" + , "828|case-sensitive|Module" + , "829|case-sensitive|Module talk" + , "2300|case-sensitive|Gadget" + , "2301|case-sensitive|Gadget talk" + , "2302|case-sensitive|Gadget definition" + , "2303|case-sensitive|Gadget definition talk" + , "2600|first-letter|Topic" + , "2601|first-letter|2601" // NOTE: Topic_talk doesn't exist in , but added by XOWA b/c every subj ns must have a talk ns + )); + } + @Test public void Case_dflt() { // PURPOSE: missing case should use dflt DATE:2015-11-01 + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( " " + , " case-sensitive" + , " " + , " Media" + , " " + , " " + ), String_.Concat_lines_nl + ( "Main_Page|case-sensitive|||" + , "-2|case-sensitive|Media" + )); + } +} +class Xob_siteinfo_parser__fxt { + private final Xow_ns_mgr ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.U8()); + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Test__parse(String src_str, String expd) { + Xob_siteinfo_nde nde = Xob_siteinfo_parser_.Parse(src_str, ns_mgr); + nde.To_bfr(bfr); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_basic_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_basic_tst.java new file mode 100644 index 000000000..615e9fb29 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_basic_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.ios.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.wikis.data.*; import gplx.xowa.files.downloads.*; +import gplx.xowa.wikis.data.fetchers.*; +public class Xoa_css_extractor_basic_tst { + @Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt(); + @Test public void Logo_download() { + fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html); + fxt.Init_fil("mem/http/wiki.png" , "download"); + fxt.Exec_logo_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "download"); + } + @Test public void Logo_download_mw_wiki_logo() { + fxt.Init_fil("mem/http/en.wikipedia.org" , ""); + fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/a/wiki.png" , "download"); + fxt.Init_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css" , ".mw-wiki-logo{background-image:url(\"//a/wiki.png\");"); + fxt.Exec_logo_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png" , "download"); + } + @Test public void Logo_failover() { + fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/logo.png" , "failover"); + fxt.Exec_logo_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png", "failover"); + } + @Test public void Css_common_download_failover() { + fxt.Css_installer().Opt_download_css_common_(true); + fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover"); + fxt.Exec_css_common_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover"); + } + @Test public void Css_common_copy() { + fxt.Css_installer().Opt_download_css_common_(false); + fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover"); + fxt.Exec_css_common_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover"); + } + @Test public void Css_common_copy_specific_wiki() { // PURPOSE: css for specific wiki + fxt.Css_installer().Opt_download_css_common_(false).Wiki_code_(Bry_.new_a7("enwiki")); + fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_override/xowa_common_enwiki.css", "failover"); + fxt.Exec_css_common_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover"); + } + @Test public void Css_scrape_download() { + fxt.Css_installer().Url_encoder_(Gfo_url_encoder_.Http_url); + fxt.Init_fil("mem/http/en.wikipedia.org" , Xoa_css_extractor_fxt.Main_page_html); + fxt.Init_fil("mem/http/en.wikipedia.org/common.css" , "download"); + fxt.Init_fil("mem/http/www/a&0|b,c" , "data=css_0"); + fxt.Init_fil("mem/http/www/a&1|b,c" , "data=css_1"); + fxt.Exec_css_mainpage_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", String_.Concat_lines_nl + ( "/*XOWA:mem/http/www/a&0|b,c*/" + , "data=css_0" + , "" + , "/*XOWA:mem/http/www/a&1|b,c*/" + , "data=css_1" + )); + } + @Test public void Css_scrape_failover() { + fxt.Init_fil("mem/xowa/bin/any/html/xowa/import/xowa_common_ltr.css", "failover"); + fxt.Exec_css_mainpage_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_common.css", "failover"); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java new file mode 100644 index 000000000..fcd30c7a7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_fxt.java @@ -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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import gplx.core.ios.*; +import gplx.xowa.wikis.data.fetchers.*; +import gplx.xowa.files.downloads.*; +public class Xoa_css_extractor_fxt { + public void Clear() { + Io_mgr.Instance.InitEngine_mem(); + Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test(); + css_installer = new Xoa_css_extractor(); + css_installer.Download_xrg().Trg_engine_key_(IoEngine_.MemKey); + css_installer + .Usr_dlg_(usr_dlg) + .Wiki_domain_(Bry_.new_a7("en.wikipedia.org")) + .Protocol_prefix_("mem/http/") + .Mainpage_url_("mem/http/en.wikipedia.org") + .Failover_dir_(Io_url_.new_any_("mem/xowa/bin/any/html/xowa/import/")) // "mem/xowa/user/anonymous/wiki/home/html/" + .Wiki_html_dir_(Io_url_.new_any_("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/")) + ; + page_fetcher = new Xow_page_fetcher_test(); + css_installer.Page_fetcher_(page_fetcher); + Xoa_css_img_downloader css_img_downloader = new Xoa_css_img_downloader(); + css_img_downloader.Ctor(usr_dlg, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/")); + css_installer.Css_img_downloader_(css_img_downloader); + } private Xow_page_fetcher_test page_fetcher; + public Xoa_css_extractor Css_installer() {return css_installer;} private Xoa_css_extractor css_installer; + public void Init_page(int ns_id, String ttl, String text) { + page_fetcher.Add(ns_id, Bry_.new_a7(ttl), Bry_.new_a7(text)); + } + public void Init_fil_empty(String url) {Init_fil(url, "");} + public void Init_fil(String url, String text) {Io_mgr.Instance.SaveFilStr(url, text);} + public void Test_fil(String url, String expd) {Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(Io_url_.new_any_(url)));} + public void Exec_logo_setup() { + css_installer.Mainpage_download(); + css_installer.Logo_setup(); + } + public void Exec_css_common_setup() { + css_installer.Mainpage_download(); + css_installer.Css_common_setup(); + } + public void Exec_css_wiki_setup() {css_installer.Css_wiki_setup();} + public void Exec_css_mainpage_setup() { + css_installer.Mainpage_download(); + css_installer.Css_scrape_setup(); + } + public static String Main_page_html = String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , "
    " + , "" + ); +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_wiki_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_wiki_tst.java new file mode 100644 index 000000000..2e9b42da6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_extractor_wiki_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*; +public class Xoa_css_extractor_wiki_tst { + @Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt(); + @Test public void Css_wiki_generate() { + fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "css_0"); + fxt.Init_page(Xow_ns_.Tid__mediawiki, "Vector.css" , "css_1"); + fxt.Exec_css_wiki_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl + ( "/*XOWA:MediaWiki:Common.css*/" + , "css_0" + , "" + , "/*XOWA:MediaWiki:Vector.css*/" + , "css_1" + )); + } + @Test public void Css_wiki_missing() { + fxt.Exec_css_wiki_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", ""); + } + @Test public void Css_wiki_tab() { // PURPOSE: swap out for xdat files + fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "a b"); + fxt.Exec_css_wiki_setup(); + fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl + ( "/*XOWA:MediaWiki:Common.css*/" + , "a\tb" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java new file mode 100644 index 000000000..b18aecc0b --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xoa_css_img_downloader_tst.java @@ -0,0 +1,181 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.xowa.files.downloads.*; +public class Xoa_css_img_downloader_tst { + @Before public void init() {fxt.Clear();} private Xoa_css_img_downloader_fxt fxt = new Xoa_css_img_downloader_fxt(); + @Test public void Basic() { + fxt.Test_css_convert + ( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg\")}" + , "x {url(\"site/a.jpg\")} y {url(\"site/b.jpg\")}" + , "site/a.jpg" + , "site/b.jpg" + ); + } + @Test public void Unquoted() { + fxt.Test_css_convert + ( "x {url(//site/a.jpg)}" + , "x {url(\"site/a.jpg\")}" + , "site/a.jpg" + ); + } + @Test public void Http() { + fxt.Test_css_convert + ( "x {url(http://site/a.jpg)}" + , "x {url(\"site/a.jpg\")}" + , "site/a.jpg" + ); + } + @Test public void Base64() { + fxt.Test_css_convert + ( "x {url(\"//site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}" + , "x {url(\"site/a.jpg\")} y {url(\"data:image/png;base64,BASE64DATA;ABC=\")} z {}" + , "site/a.jpg" + ); + } + @Test public void Exc_missing_quote() { + fxt.Test_css_convert + ( "x {url(\"//site/a.jpg\")} y {url(\"//site/b.jpg} z {}" + , "x {url(\"site/a.jpg\")} y {url(\"//site/b.jpg} z {}" + , "site/a.jpg" + ); + } + @Test public void Exc_empty() { + fxt.Test_css_convert + ( "x {url(\"//site/a.jpg\")} y {url(\"\"} z {}" + , "x {url(\"site/a.jpg\")} y {url(\"\"} z {}" + , "site/a.jpg" + ); + } +// @Test public void Exc_name_only() { // COMMENTED: not sure how to handle "b.jpg" (automatically add "current" path?); RESTORE: when example found +// fxt.Test_css_convert +// ( "x {url(\"//site/a.jpg\")} y {url(\"b.jpg\"} z {}" +// , "x {url(\"site/a.jpg\")} y {url(\"b.jpg\"} z {}" +// , "site/a.jpg" +// ); +// } + @Test public void Repeat() {// PURPOSE.fix: exact same item was being added literally + fxt.Test_css_convert + ( "x {url(\"//site/a.jpg?a=b\")} y {url(\"//site/a.jpg?a=b\"}" + , "x {url(\"site/a.jpg\")} y {url(\"site/a.jpg\"}" + , "site/a.jpg" + ); + } + @Test public void Clean_basic() {fxt.Test_clean_img_url("//site/a.jpg" , "site/a.jpg");} + @Test public void Clean_query() {fxt.Test_clean_img_url("//site/a.jpg?key=val" , "site/a.jpg");} + @Test public void Clean_dir() {fxt.Test_clean_img_url("//site/a/b/c.jpg?key=val" , "site/a/b/c.jpg");} + @Test public void Clean_exc_site_only() {fxt.Test_clean_img_url("//site" , null);} + @Test public void Clean_exc_site_only_2() {fxt.Test_clean_img_url("//site/" , null);} + @Test public void Import_url() { + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem/www/b.css", "imported_css"); + fxt.Test_css_convert + ( "x @import url(\"mem/www/b.css\") screen; z" + , String_.Concat_lines_nl + ( "x " + , "/*XOWA:mem/www/b.css*/" + , "imported_css" + , "" + , " z" + ) + ); + } + @Test public void Import_url_make() { + fxt.Test_import_url("a.org/b" , "http:a.org/b"); // add "stylesheet_prefix" + fxt.Test_import_url("http://a.org" , "http://a.org"); // unless it starts with http + fxt.Test_import_url("https://a.org" , "https://a.org"); // unless starts with https EX:: handle @import(https://...); PAGE:tr.n:Main_Page; DATE:2014-06-04 + } + @Test public void Import_url_relative() { // PURPOSE: if directory, add domain; "/a/b.css" -> "//domain/a/b.css"; DATE:2014-02-03 + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem/en.wikipedia.org/www/b.css", "imported_css"); + fxt.Test_css_convert + ( "x @import url(\"/www/b.css\") screen; z" // starts with "/" + , String_.Concat_lines_nl + ( "x " + , "/*XOWA:mem/en.wikipedia.org/www/b.css*/" + , "imported_css" + , "" + , " z" + ) + ); + } + @Test public void Import_url_relative_skip() { // PURPOSE: if rel path, skip; "//site/a/b.css"; DATE:2014-02-03 + fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem//en.wikipedia.org/a/b.css", "imported_css"); + fxt.Test_css_convert + ( "x @import url(\"//en.wikipedia.org/a/b.css\") screen; z" // starts with "//" + , String_.Concat_lines_nl + ( "x " + , "/*XOWA://en.wikipedia.org/a/b.css*/" + , "imported_css" + , "" + , " z" + ) + ); + } + @Test public void Import_url_space() { // PURPOSE: some css has spaces; replace with underlines else fails when downloaded; EX: https://it.wikivoyage.org/w/index.php?title=MediaWiki:Container e Infobox.css&action=raw&ctype=text/css; DATE:2015-03-08 + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem/www/b_c.css", "imported_css"); + fxt.Test_css_convert + ( "x @import url(\"mem/www/b c.css\") screen; z" + , String_.Concat_lines_nl + ( "x " + , "/*XOWA:mem/www/b_c.css*/" + , "imported_css" + , "" + , " z" + ) + ); + } + @Test public void Wikisource_freedimg() { // PURPOSE: check that "wikimedia" is replaced for FreedImg hack; PAGE:en.s:Page:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species.pdf/3 DATE:2014-09-06 + fxt.Downloader().Stylesheet_prefix_(Bry_.new_a7("mem")); // stylesheet prefix prefix defaults to ""; set to "mem", else test will try to retrieve "//url" which will fail + Io_mgr.Instance.InitEngine_mem(); + Io_mgr.Instance.SaveFilStr("mem//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css", ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {"); + fxt.Test_css_convert + ( "x @import url(\"//en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css\") screen; z" // starts with "//" + , String_.Concat_lines_nl + ( "x " + , "/*XOWA://en.wikisource.org/w/index.php?title=MediaWiki:Dynimg.css*/" + , ".freedImg img[src*=\"wikipedia\"], .freedImg img[src*=\"wikisource\"], /*XOWA:handle file:// paths which will have /commons.wikimedia.org/ but not /wikipedia/ */ .freedImg img[src*=\"wikimedia\"], .freedImg img[src*=\"score\"], .freedImg img[src*=\"math\"] {" + , "" + , " z" + ) + ); + } +} +class Xoa_css_img_downloader_fxt { + public Xoa_css_img_downloader Downloader() {return downloader;} private Xoa_css_img_downloader downloader; + public void Clear() { + downloader = new Xoa_css_img_downloader(); + downloader.Ctor(Gfo_usr_dlg_.Test(), new Xof_download_wkr_test(), Bry_.Empty); + } + public void Test_css_convert(String raw, String expd, String... expd_img_ary) { + List_adp actl_img_list = List_adp_.New(); + byte[] actl_bry = downloader.Convert_to_local_urls(Bry_.new_a7("mem/en.wikipedia.org"), Bry_.new_u8(raw), actl_img_list); + Tfds.Eq_str_lines(expd, String_.new_u8(actl_bry)); + Tfds.Eq_ary_str(expd_img_ary, actl_img_list.To_str_ary()); + } + public void Test_clean_img_url(String raw_str, String expd) { + byte[] raw = Bry_.new_a7(raw_str); + byte[] actl = downloader.Clean_img_url(raw, raw.length); + Tfds.Eq(expd, actl == null ? null : String_.new_a7(actl)); + } + public void Test_import_url(String raw, String expd) { + byte[] actl = Xoa_css_img_downloader.Import_url_build(Bry_.new_a7("http:"), Bry_.new_a7("//en.wikipedia.org"), Bry_.new_u8(raw)); + Tfds.Eq(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__import_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__import_tst.java new file mode 100644 index 000000000..94d950771 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__import_tst.java @@ -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.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +public class Xob_css_parser__import_tst { + @Before public void init() {fxt.Clear();} private Xob_css_parser__import_fxt fxt = new Xob_css_parser__import_fxt(); + @Test public void Basic() {fxt.Test_parse_import (" @import url(//site/a.png)" , " @import url('site/a.png')");} + @Test public void Warn_eos() {fxt.Test_parse_warn (" @import" , " @import" , "EOS");} + @Test public void Warn_missing() {fxt.Test_parse_warn (" @import ('//site/a.png')" , " @import" , "missing");} // no "url(" + @Test public void Warn_invalid() {fxt.Test_parse_warn (" @import url('//site')" , " @import url('//site')" , "invalid");} // invalid +} +class Xob_css_parser__import_fxt extends Xob_css_parser__url_fxt { private Xob_css_parser__import import_parser; + @Override public void Clear() { + super.Clear(); + this.import_parser = new Xob_css_parser__import(url_parser); + } + @Override protected void Exec_parse_hook() { + this.cur_frag = import_parser.Parse(src_bry, src_bry.length, 0, 8); // 8=" @import".length + } + public void Test_parse_import(String src_str, String expd) { + Exec_parse(src_str, Xob_css_tkn__base.Tid_import, expd); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__url_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__url_tst.java new file mode 100644 index 000000000..b7a60a6e4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xob_css_parser__url_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +public class Xob_css_parser__url_tst { + @Before public void init() {fxt.Clear();} private Xob_css_parser__url_fxt fxt = new Xob_css_parser__url_fxt(); + @Test public void Quote_none() {fxt.Test_parse_url(" url(//site/A.png) b" , " url('site/A.png')");} + @Test public void Quote_apos() {fxt.Test_parse_url(" url('//site/A.png') b" , " url('site/A.png')");} + @Test public void Quote_quote() {fxt.Test_parse_url(" url(\"//site/A.png\") b" , " url(\"site/A.png\")");} + @Test public void Base64() {fxt.Test_parse_base64(" url('data:image/png;base64,BASE64DATA;ABC=') b", " url('data:image/png;base64,BASE64DATA;ABC=')");} + @Test public void Base64_dangling() {fxt.Test_parse_warn(" url('data:image/png;base64,BASE64DATA;ABC=' ", " url('data:image/png;base64,BASE64DATA;ABC='", "base64 dangling");} + @Test public void Warn_eos() {fxt.Test_parse_warn(" url(" , " url(" , "EOS");} + @Test public void Warn_dangling() {fxt.Test_parse_warn(" url(a" , " url(" , "dangling");} + @Test public void Warn_empty() {fxt.Test_parse_warn(" url()" , " url(" , "empty");} + @Test public void Warn_site() {fxt.Test_parse_warn(" url('//site')" , " url('//site')" , "invalid");} +} +class Xob_css_parser__url_fxt { + protected Xob_css_parser__url url_parser; private final Bry_bfr bfr = Bry_bfr_.New_w_size(32); + protected Xob_css_tkn__base cur_frag; protected byte[] src_bry; + @gplx.Virtual public void Clear() { + url_parser = new Xob_css_parser__url(Bry_.new_a7("site")); + } + protected void Exec_parse(String src_str, int expd_tid, String expd_str) { + this.src_bry = Bry_.new_u8(src_str); + this.Exec_parse_hook(); + cur_frag.Write(bfr, src_bry); + String actl_str = bfr.To_str_and_clear(); + Tfds.Eq(expd_tid, cur_frag.Tid(), "wrong tid; expd={0}, actl={1}", expd_tid, cur_frag.Tid()); + Tfds.Eq(expd_str, actl_str); + } + @gplx.Virtual protected void Exec_parse_hook() { + this.cur_frag = url_parser.Parse(src_bry, src_bry.length, 0, 5); // 5=" url(".length + } + public void Test_parse_url(String src_str, String expd) { + Exec_parse(src_str, Xob_css_tkn__base.Tid_url, expd); + } + public void Test_parse_base64(String src_str, String expd) { + Exec_parse(src_str, Xob_css_tkn__base.Tid_base64, expd); + } + public void Test_parse_warn(String src_str, String expd, String warn) { + Exec_parse(src_str, Xob_css_tkn__base.Tid_warn, expd); + Xob_css_tkn__warn sub_frag = (Xob_css_tkn__warn)cur_frag; + Tfds.Eq(true, String_.Has(sub_frag.Fail_msg(), warn)); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java new file mode 100644 index 000000000..b67ef17f4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xob_mirror_mgr_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +import gplx.xowa.files.downloads.*; +public class Xob_mirror_mgr_tst { + @Before public void init() {fxt.Clear();} private Xob_mirror_mgr_fxt fxt = new Xob_mirror_mgr_fxt(); + @Test public void Download_1() { + fxt.Fsys().Init_fil("mem/http/enwiki/file/a.png"); + fxt.Fsys().Init_fil("mem/http/enwiki/wiki/Main_Page", "url('//enwiki/wiki/a.png')"); +// fxt.Test_css(); +// fxt.Fsys().Test_fil("url('//enwiki/wiki/a.png')", "url('enwiki/wiki/a.png')"); // remove "//" +// fxt.Fsys().Test_fil("mem/fsys/enwiki/file/a.png"); + } +} +class Xob_mirror_mgr_fxt { +// private Xob_mirror_mgr mirror_mgr; + public Io_fsys_fxt Fsys() {return fsys;} private final Io_fsys_fxt fsys = new Io_fsys_fxt(); + public void Clear() { + fsys.Clear(); +// mirror_mgr = new Xob_mirror_mgr(Gfo_usr_dlg_.Noop, new Xof_download_wkr_test(), Bry_.new_a7("mem/http/enwiki"), Bry_.new_a7("mem/http/enwiki/wiki/Main_Page"), Io_url_.new_dir_("mem/fsys")); + } + public void Test_css(String raw, String expd) { +// byte[] raw_bry = Bry_.new_u8(raw); +// mirror_mgr.Exec(); + } +} +class Io_fsys_fxt { + public void Clear() { + Io_mgr.Instance.InitEngine_mem(); + } + public void Init_fil(String url_str) { + Io_url url = Io_url_.new_fil_(url_str); + Init_fil(url, url.NameAndExt()); + } + public void Init_fil(String url_str, String text) {Init_fil(Io_url_.new_fil_(url_str), text);} + public void Init_fil(Io_url url, String text) { + Io_mgr.Instance.SaveFilStr(url, text); + } + public void Test_fil(String url_str) { + Io_url url = Io_url_.new_fil_(url_str); + Test_fil(url, url.NameAndExt()); + } + public void Test_fil(String url, String expd) {Test_fil(Io_url_.new_fil_(url), expd);} + public void Test_fil(Io_url url, String expd) { + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java b/400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java new file mode 100644 index 000000000..c1b73238c --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/css/Xob_url_fixer_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +public class Xob_url_fixer_tst { + @Before public void init() {fxt.Clear();} private Xob_url_fixer_fxt fxt = new Xob_url_fixer_fxt(); + @Test public void Slash2() {fxt.Test_fix("//site/a.png" , "site/a.png");} + @Test public void Http() {fxt.Test_fix("http://site/a.png" , "site/a.png");} + @Test public void Https() {fxt.Test_fix("https://site/a.png" , "site/a.png");} + @Test public void Qarg() {fxt.Test_fix("//site/a.png?key=val" , "site/a.png");} + @Test public void Qarg_dir() {fxt.Test_fix("//site/a/b/c.png?key=val" , "site/a/b/c.png");} + @Test public void Root() {fxt.Test_fix("/a/b.png" , "site/a/b.png");} // EX:/static/images/project-logos/wikivoyage.png; DATE:2015-05-09 + @Test public void Rel_dot2() {fxt.Test_fix("//site/a/../b/c.png" , "site/b/c.png");} // DATE:2015-05-09 + @Test public void Rel_dot2_mult() {fxt.Test_fix("//site/a/../b/../c/d.png" , "site/c/d.png");} // DATE:2015-05-09 + @Test public void Rel_dot1() {fxt.Test_fix("//site/a/./b/c.png" , "site/a/b/c.png");} // DATE:2015-05-09 + @Test public void Site_only() {fxt.Test_fix("//site" , null);} +} +class Xob_url_fixer_fxt { + public void Site_(String v) {site_bry = Bry_.new_u8(v);} private byte[] site_bry; + public void Clear() { + this.Site_("site"); + } + public void Test_fix(String raw, String expd) { + byte[] raw_bry = Bry_.new_u8(raw); + Tfds.Eq(expd, String_.new_u8(Xob_url_fixer.Fix(site_bry, raw_bry, raw_bry.length))); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_srl_tst.java b/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_srl_tst.java new file mode 100644 index 000000000..ce45da9cb --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_srl_tst.java @@ -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.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*; +import org.junit.*; +public class Xob_ttl_filter_mgr_srl_tst { + @Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_srl_fxt fxt = new Xob_ttl_filter_mgr_srl_fxt(); + @Test public void One() {fxt.Test_parse("a" , 1, "a");} + @Test public void Two() {fxt.Test_parse("a\nb" , 2, "a", "b");} + @Test public void Comment() {fxt.Test_parse("|x" , 0);} + @Test public void Comment_many() {fxt.Test_parse("|x||" , 0);} + @Test public void Blank() {fxt.Test_parse("\n" , 0);} + @Test public void Mix() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "|comment 1" + , "a" + , "" + , "|comment 2" + , "b" + ) + , 2, "a", "b") + ;} +} +class Xob_ttl_filter_mgr_srl_fxt { + private final Xob_ttl_filter_mgr_srl mgr = new Xob_ttl_filter_mgr_srl(); + private final Hash_adp_bry hash = Hash_adp_bry.cs(); + public void Clear() { + hash.Clear(); + } + public void Test_parse(String src, int expd_count, String... expd_itms) { + mgr.Init(hash); + mgr.Load_by_bry(Bry_.new_u8(src)); + Tfds.Eq(expd_count, hash.Count()); + int expd_len = expd_itms.length; + for (int i = 0; i < expd_len; ++i) { + String expd_itm = expd_itms[i]; + Tfds.Eq_true(hash.Has(Bry_.new_u8(expd_itm))); + } + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_tst.java b/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_tst.java new file mode 100644 index 000000000..742408b2f --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/filters/core/Xob_ttl_filter_mgr_tst.java @@ -0,0 +1,49 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.filters.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*; +import org.junit.*; +public class Xob_ttl_filter_mgr_tst { + @Before public void init() {fxt.Clear();} private final Xob_ttl_filter_mgr_fxt fxt = new Xob_ttl_filter_mgr_fxt(); + @Test public void One() { + fxt.Init_load_exclude("A"); + fxt.Init_load_include("B"); + fxt.Test_match_exclude_y("A"); + fxt.Test_match_exclude_n("B", "C"); + fxt.Test_match_include_y("B"); + fxt.Test_match_include_n("A", "C"); + } +} +class Xob_ttl_filter_mgr_fxt { + private final Xob_ttl_filter_mgr mgr = new Xob_ttl_filter_mgr(); + public void Clear() { + mgr.Clear(); + } + public void Init_load_exclude(String itm) {mgr.Load(Bool_.Y, Bry_.new_u8(itm));} + public void Init_load_include(String itm) {mgr.Load(Bool_.N, Bry_.new_u8(itm));} + public void Test_match_exclude_y(String... itms) {Test_match(Bool_.Y, Bool_.Y, itms);} + public void Test_match_exclude_n(String... itms) {Test_match(Bool_.Y, Bool_.N, itms);} + public void Test_match_include_y(String... itms) {Test_match(Bool_.N, Bool_.Y, itms);} + public void Test_match_include_n(String... itms) {Test_match(Bool_.N, Bool_.N, itms);} + private void Test_match(boolean exclude, boolean expd, String... itms) { + for (String itm : itms) { + byte[] itm_bry = Bry_.new_u8(itm); + if (exclude) + Tfds.Eq(expd, mgr.Match_exclude(itm_bry), itm); + else + Tfds.Eq(expd, mgr.Match_include(itm_bry), itm); + } + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_match_mgr_tst.java b/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_match_mgr_tst.java new file mode 100644 index 000000000..6663bce9d --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_match_mgr_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.filters.dansguardians; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*; +import org.junit.*; import gplx.dbs.*; +public class Dg_match_mgr_tst { + @Before public void init() {fxt.Clear();} private Dg_match_mgr_fxt fxt = new Dg_match_mgr_fxt(); + @Test public void One() { + fxt.Init_line(100, "a"); + fxt.Test_match_many_y("a", "ab", "ba", "abc"); + fxt.Test_match_many_n("b"); + } +} +class Dg_match_mgr_fxt { + private Dg_match_mgr match_mgr; + private final List_adp rule_list = List_adp_.New(); + public void Clear() { + Db_conn_bldr.Instance.Reg_default_mem(); + Io_url root_dir = Io_url_.mem_dir_("mem/dg/"); + match_mgr = new Dg_match_mgr(root_dir.GenSubDir("words"), 1, 0, Bool_.Y, Bool_.Y, root_dir.GenSubDir("log")); + rule_list.Clear(); + } + public void Init_line(int score, String... words) { + Dg_rule line = new Dg_rule(-1, -1, -1, Dg_rule.Tid_rule, Bry_.new_a7("key"), score, Dg_word.Ary_new_by_str_ary(words)); + rule_list.Add(line); + } + public void Test_match_many_y(String... words) {Test_match_many(Bool_.Y, words);} + public void Test_match_many_n(String... words) {Test_match_many(Bool_.N, words);} + public void Test_match_many(boolean expd, String... words) { + int words_len = words.length; + for (int i = 0; i < words_len; ++i) + Test_match_one(expd, words[i]); + } + public void Test_match_one(boolean expd, String word_str) { + match_mgr.Clear(); + int rule_list_len = rule_list.Count(); + for (int j = 0; j < rule_list_len; ++j) { + Dg_rule rule = (Dg_rule)rule_list.Get_at(j); + match_mgr.Init_by_rule(rule); + } + byte[] word_bry = Bry_.new_u8(word_str); + Tfds.Eq(expd, match_mgr.Match(1, 101, 0, Bry_.Empty, Bry_.Empty, null, word_bry), (expd ? "pass:" : "fail:") + word_str); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_parser_tst.java new file mode 100644 index 000000000..da5c271a2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/filters/dansguardians/Dg_parser_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.filters.dansguardians; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.filters.*; +import org.junit.*; +public class Dg_parser_tst { + @Before public void init() {fxt.Init();} private Dg_parser_fxt fxt = new Dg_parser_fxt(); + @Test public void One() {fxt.Test_parse_line("<123>", fxt.Make_line(123, "a"));} + @Test public void Many() {fxt.Test_parse_line(",,<-123>", fxt.Make_line(-123, "a", "b", "c"));} + @Test public void Score_0() {fxt.Test_parse_line("<0>", fxt.Make_line(Dg_rule.Score_banned, "a"));} + @Test public void Noscore() {fxt.Test_parse_line("", fxt.Make_line(Dg_rule.Score_banned, "a"));} + @Test public void Noscore_2() {fxt.Test_parse_line(",", fxt.Make_line(Dg_rule.Score_banned, "a", "b"));} + @Test public void Comment() {fxt.Test_parse_line("# comment", Dg_rule.Itm_comment);} + @Test public void Blank() {fxt.Test_parse_line("", Dg_rule.Itm_blank);} + @Test public void Invalid_line_bgn() {fxt.Test_parse_line(" <1>", Dg_rule.Itm_invalid);} + @Test public void Dangling_word() {fxt.Test_parse_line("<12", fxt.Make_line(Dg_rule.Score_banned, "a"));} + @Test public void Invalid_dlm() {fxt.Test_parse_line(" <1>", fxt.Make_line(Dg_rule.Score_banned, "a"));} + @Test public void Invalid_dlm_2() {fxt.Test_parse_line(",<2>", fxt.Make_line(Dg_rule.Score_banned, "a", "b"));} + @Test public void Invalid_score() {fxt.Test_parse_line("<1a>", fxt.Make_line(Dg_rule.Score_banned, "a"));} +// @Test public void Parse_dir() { +// Dg_parser parser = new Dg_parser(); +// Gfo_usr_dlg_.I = Xoa_app_.New__usr_dlg__console(); +// parser.Parse_dir(Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\bldr\\filters\simple.wikipedia.org\\Dansguardian\\\\")); +// } +} +class Dg_parser_fxt { + private final Dg_parser parser = new Dg_parser(); private final Bry_bfr bfr = Bry_bfr_.Reset(32); + private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(16); + public void Init() {} + public Dg_rule Make_line(int score, String... words) {return new Dg_rule(-1, -1, -1, Dg_rule.Tid_rule, null, score, Dg_word.Ary_new_by_str_ary(words));} + public void Test_parse_line(String str, Dg_rule expd) { + byte[] src = Bry_.new_u8(str); + Dg_rule actl = parser.Parse_line("rel_path", 0, 0, src, 0, src.length); + Tfds.Eq_str_lines(Xto_str(bfr, expd), Xto_str(bfr, actl)); + } + private String Xto_str(Bry_bfr bfr, Dg_rule line) { + bfr .Add_str_a7("score=").Add_int_variable(line.Score()).Add_byte_nl() + .Add_str_a7("words=").Add_str_u8(String_.Concat_with_str(";", Dg_word.Ary_concat(line.Words(), tmp_bfr, Byte_ascii.Tick))).Add_byte_nl() + ; + return bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile_tst.java b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile_tst.java new file mode 100644 index 000000000..4a0538372 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_dumpfile_tst.java @@ -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.xowa.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +public class Xoi_cmd_dumpfile_tst { + @Before public void init() {fxt.Clear();} private Xoi_cmd_dumpfile_fxt fxt = new Xoi_cmd_dumpfile_fxt(); + @Test public void Bz2__unzip() { + fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml.bz2", "", "unzip") + .Test_domain("en.wikipedia.org") + .Test_vals("mem/en.wikipedia.org/fil.xml.bz2", "mem/en.wikipedia.org/fil.xml", true) + ; + } + @Test public void Bz2__unzip__assert_xml_ext() { // xml ext relies on removing ".bz2" from ".xml.bz2"; if just ".bz2" add an ".xml" + fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "unzip") + .Test_vals("mem/en.wikipedia.org/fil.bz2", "mem/en.wikipedia.org/fil.xml", true) + ; + } + @Test public void Bz2__direct() { + fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.bz2", "", "") + .Test_vals("mem/en.wikipedia.org/fil.bz2", null, false) + ; + } + @Test public void Xml__unzip_n() { + fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "") + .Test_vals(null, "mem/en.wikipedia.org/fil.xml", false) + ; + } + @Test public void Xml__unzip_y() { + fxt .Exec_parse_msg("mem/en.wikipedia.org/fil.xml", "", "") + .Test_vals(null, "mem/en.wikipedia.org/fil.xml", false) + ; + } +} +class Xoi_cmd_dumpfile_fxt { + public void Clear() { + dumpfile.Clear(); + } private Xoi_cmd_dumpfile dumpfile = new Xoi_cmd_dumpfile(); + public Xoi_cmd_dumpfile_fxt Exec_parse_msg(String url, String domain, String args) { + GfoMsg m = GfoMsg_.new_parse_("").Add("url", url).Add("domain", domain).Add("args", args); + dumpfile.Parse_msg(m); + return this; + } + public Xoi_cmd_dumpfile_fxt Test_vals(String expd_bz2, String expd_xml, boolean expd_unzip) { + Eq_url(expd_bz2, dumpfile.Bz2_url()); + Eq_url(expd_xml, dumpfile.Xml_url()); + Tfds.Eq(expd_unzip, dumpfile.Bz2_unzip()); + return this; + } + public Xoi_cmd_dumpfile_fxt Test_domain(String expd_domain) { + Tfds.Eq(expd_domain, String_.new_u8(dumpfile.Domain())); + return this; + } + private void Eq_url(String expd, Io_url actl) { + if (expd == null && actl == null) return; + else if (expd != null && actl != null) { + Tfds.Eq(expd, actl.Raw()); + } + else if (expd == null) throw Err_.new_wo_type("actl should be null", "expd", expd); + else if (actl == null) throw Err_.new_wo_type("actl should not be null", "expd", expd); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java new file mode 100644 index 000000000..5357a226d --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_cmd_wiki_tst.java @@ -0,0 +1,128 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +import gplx.core.consoles.*; +import gplx.core.brys.args.*; import gplx.core.threads.*; import gplx.xowa.bldrs.setups.maints.*; import gplx.xowa.xtns.wbases.imports.*; +import gplx.xowa.wikis.domains.*; +import gplx.xowa.bldrs.wms.*; import gplx.xowa.bldrs.wms.dumps.*; +public class Xoi_cmd_wiki_tst { + @Test public void Run() { // MAINT:2017-03-28 +// Bld_import_list(Xow_domain_regy.All); +// Bld_cfg_files(Xow_domain_regy.All); // NOTE: remember to carry over the wikisource / page / index commands from the existing xowa_build_cfg.gfs; also, only run the xowa_build_cfg.gfs once; DATE:2013-10-15; last run: DATE:2014-09-09 + } + public void Bld_import_list(String... ary) { + int ary_len = ary.length; + Bry_bfr bfr = Bry_bfr_.Reset(255); + Wmf_latest_parser parser = new Wmf_latest_parser(); + Bfr_arg__time time_fmtr = new Bfr_arg__time(); + for (int i = 0; i < ary_len; i++) + Bld_import_list_itm2(bfr, parser, time_fmtr, ary, i); + Io_mgr.Instance.SaveFilStr("C:\\xowa\\user\\temp.txt", bfr.To_str()); + } + private void Bld_import_list_itm2(Bry_bfr bfr, Wmf_latest_parser parser, Bfr_arg__time time_fmtr, String[] ary, int i) { + String domain_str = ary[i]; + byte[] domain_bry = Bry_.new_a7(domain_str); + Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry); + byte[] wmf_key_bry = Bry_.Replace(Xow_abrv_wm_.To_abrv(domain_itm), Byte_ascii.Dash, Byte_ascii.Underline); + String wmf_key = String_.new_u8(wmf_key_bry); + String url = "https://dumps.wikimedia.org/" + wmf_key + "/latest"; + byte[] latest_html = null; + for (int j = 0; j < 5; ++j) { + latest_html = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty).Exec_as_bry(url); + if (latest_html != null) break; + Tfds.Dbg("fail|" + domain_str + "|" + url); + if (j == 4) return; + } + parser.Parse(latest_html); + Xowm_dump_file dump_file = new Xowm_dump_file(domain_str, "latest", Xowm_dump_type_.Str__pages_articles); + dump_file.Server_url_(Xowm_dump_file_.Server_wmf_https); + byte[] pages_articles_key = Bry_.new_a7(wmf_key + "-latest-pages-articles.xml.bz2"); + Wmf_latest_itm latest_itm = parser.Get_by(pages_articles_key); + if (latest_itm == null) {Tfds.Dbg("missing|" + domain_str + "|" + url); return;} // NOTE: commonswiki missing entry for commonswiki-latest-pages-articles.xml.bz2 DATE:2016-05-01 + Tfds.Dbg("pass|" + domain_str + "|" + url); + bfr.Add(domain_bry).Add_byte_pipe(); + bfr.Add_str_u8(dump_file.File_url()).Add_byte_pipe(); + bfr.Add(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id())).Add_byte_pipe(); + long src_size = latest_itm.Size(); + bfr.Add_long_variable(src_size).Add_byte_pipe(); + bfr.Add_str_a7(gplx.core.ios.Io_size_.To_str(src_size)).Add_byte_pipe(); + time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).Bfr_arg__add(bfr); + bfr.Add_byte_pipe(); + bfr.Add_str_a7(latest_itm.Date().XtoStr_fmt_yyyy_MM_dd_HH_mm()); + bfr.Add_byte_pipe(); + bfr.Add_str_a7(dump_file.Dump_date()); + bfr.Add_byte_nl(); + } + /* + private void Bld_import_list_itm(Bry_bfr bfr, Xowm_dump_file dump_file, Bry_fmtr_arg_time time_fmtr, String[] ary, int i) { + String itm = ary[i]; + dump_file.Ctor(itm, "latest", Xowm_dump_type_.Str__pages_articles); + int count = 0; + while (count++ < 1) { + dump_file.Server_url_(Xowm_dump_file_.Server_wmf); + if (dump_file.Connect()) break; + Tfds.WriteText(String_.Format("retrying: {0} {1}\n", count, dump_file.File_modified())); + Thread_adp_.Sleep(15000); // wait for connection to reset + } + if (count == 10) { + Tfds.WriteText(String_.Format("failed: {0}\n", dump_file.File_url())); + return; + } + else + Tfds.WriteText(String_.Format("passed: {0}\n", itm)); + bfr.Add_str(itm).Add_byte_pipe(); + bfr.Add_str(dump_file.File_url()).Add_byte_pipe(); + bfr.Add(Xow_domain_tid_.Get_type_as_bry(dump_file.Wiki_type().Wiki_tid())).Add_byte_pipe(); +// Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key(wiki_type.Lang_key()); +// if (lang_itm == null) lang_itm = Xol_lang_stub_.Get_by_key(Xol_lang_itm_.Key_en); // commons, species, meta, etc will have no lang +// bfr.Add(lang_itm.Local_name()).Add_byte_pipe(); +// bfr.Add(lang_itm.Canonical_name()).Add_byte_pipe(); + long src_size = dump_file.File_len(); + bfr.Add_long_variable(src_size).Add_byte_pipe(); + bfr.Add_str(gplx.core.ios.Io_size_.To_str(src_size)).Add_byte_pipe(); + time_fmtr.Seconds_(Math_.Div_safe_as_long(src_size, 1000000)).XferAry(bfr, 0); + bfr.Add_byte_pipe(); + bfr.Add_str(dump_file.File_modified().XtoStr_fmt_yyyy_MM_dd_HH_mm()); + bfr.Add_byte_pipe(); +// bfr.Add_str(String_.Concat_with_obj(",", (Object[])dump_file.Dump_available_dates())); +// bfr.Add_byte_pipe(); + bfr.Add_str(dump_file.Dump_date()); + bfr.Add_byte_nl(); + Thread_adp_.Sleep(1000); + } + */ + public void Bld_cfg_files(String... ary) { + Bry_bfr bfr = Bry_bfr_.Reset(255); + gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api api = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_api(); + gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki wiki = new gplx.xowa.bldrs.wiki_cfgs.Xoi_wiki_props_wiki(); + int ary_len = ary.length; + for (int i = 0; i < ary_len; i++) { + String wiki_domain = ary[i]; + try { + byte[] xml = api.Exec_api(api.Api_src(wiki_domain)); + wiki.Wiki_domain_(Bry_.new_a7(wiki_domain)); + api.Parse(wiki, String_.new_u8(xml)); + api.Build_cfg(bfr, wiki); + } + catch (Exception e) { + Console_adp__sys.Instance.Write_str_w_nl(Err_.Message_gplx_full(e)); + } + } + bfr.Add_str_a7("app.bldr.wiki_cfg_bldr.run;").Add_byte_nl(); + Io_mgr.Instance.SaveFilStr("C:\\user\\xowa_build_cfg.gfs", bfr.To_str()); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser_tst.java new file mode 100644 index 000000000..c11c2ed99 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/installs/Xoi_mirror_parser_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.installs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; +public class Xoi_mirror_parser_tst { + @Test public void Basic() { + Tst_parse(String_.Concat_lines_nl + ( "" + , "" + , "" + , "" + , "Index of /simplewiki/" + , "" + , "" + , "" + , "

    Index of /simplewiki/

    " + , "
    " + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "
    NameLast ModifiedSizeType
    Parent Directory/ -  Directory
    20120516/2012-May-17 01:04:39-  Directory
    20121220/2012-Dec-20 20:15:55-  Directory
    20130214/2013-Feb-14 06:28:41-  Directory
    latest/2013-Feb-14 06:28:41-  Directory
    " + , "
    " + , "
    lighttpd
    " + , "" + , "" + ), String_.Ary("20120516", "20121220", "20130214", "latest")); + } + @Test public void Find_last_lte() { + Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20130101", "20121220"); + Tst_find_last_lte(String_.Ary("20120516", "20121220", "20130214", "latest"), "20120101", ""); + } + private void Tst_parse(String raw, String[] expd) { + Xoi_mirror_parser parser = new Xoi_mirror_parser(); + Tfds.Eq_ary_str(expd, parser.Parse(raw)); + } + private void Tst_find_last_lte(String[] ary, String comp, String expd) { + Tfds.Eq(expd, Xoi_mirror_parser.Find_last_lte(ary, comp)); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/setups/addons/Xoi_firefox_installer_tst.java b/400_xowa/src/gplx/xowa/bldrs/setups/addons/Xoi_firefox_installer_tst.java new file mode 100644 index 000000000..993ad4e9a --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/setups/addons/Xoi_firefox_installer_tst.java @@ -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.bldrs.setups.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*; +import org.junit.*; +import gplx.core.ios.*; +public class Xoi_firefox_installer_tst { + private Xoi_firefox_pref_fxt fxt = new Xoi_firefox_pref_fxt(); + @Test public void Pref_update() { + fxt.Test_pref_update(String_.Concat_lines_nl + ( "pref(\"key_0\", \"val_0\"); // comment_0" + , "pref(\"key_1\", \"val_1\"); // comment_1" + , "pref(\"key_2\", \"val_2\"); // comment_2" + ) + , "key_1", "val_1_updated" + , String_.Concat_lines_nl + ( "pref(\"key_0\", \"val_0\"); // comment_0" + , "pref(\"key_1\", \"val_1_updated\");" + , "pref(\"key_2\", \"val_2\"); // comment_2" + ) + ); + } +} +class Xoi_firefox_pref_fxt { + public void Test_pref_update(String src, String key, String val, String expd) { + String actl = Xoi_firefox_installer.Pref_update(src, key, val); + Tfds.Eq_str_lines(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_list_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_list_parser_tst.java new file mode 100644 index 000000000..36ef5bb21 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_dump_list_parser_tst.java @@ -0,0 +1,135 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.setups.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*; +import org.junit.*; +import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; +public class Wmf_dump_list_parser_tst { + @Before public void init() {fxt.Clear();} private Wmf_dump_list_parser_fxt fxt = new Wmf_dump_list_parser_fxt(); + @Test public void Parse() { + fxt.Test_parse + ( "
  • 2013-07-17 00:32:33 enwiki: Dump complete
  • " + , fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-07-17 00:32:33") + ); + fxt.Test_parse(String_.Concat_lines_nl + ( "
  • 2013-07-24 02:02:13 kawiki: Dump in progress
  • " + , "
    • 2013-07-24 00:54:55 in-progress All pages with complete page edit history (.bz2)
      2013-07-24 02:02:13: kawiki (ID 18587) 22046 pages (5.5|11140.9/sec all|curr), 869000 revs (215.2|505.3/sec all|curr), 99.9%|99.9% prefetched (all|curr), ETA 2013-07-24 04:09:41 [max 2514872]
      " + , "
      • kawiki-20130724-pages-meta-history.xml.bz2 245.2 MB (written)
    " + ) + , fxt.itm("kawiki", "20130724", Wmf_dump_itm.Status_tid_working, "Dump in progress", "2013-07-24 02:02:13") + ); + fxt.Test_parse + ( "
  • 2013-07-17 00:32:33 enwiki: Error
  • " + , fxt.itm("enwiki", "20130708", Wmf_dump_itm.Status_tid_error, "Error", "2013-07-17 00:32:33") + ); + fxt.Test_parse + ( "
  • 2013-11-28 06:08:56 zh_classicalwiki: Dump complete
  • " + , fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56") + ); + } +// @Test public void Update() { // MAINT:QUARTERLY:2017-03-28; COUNT=830; must run home/wiki/Dashboard/Wiki_maintenance and click "update dump status" +// Hash_adp_bry excluded_domains = Hash_adp_bry.cs().Add_many_str +// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org" +// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org" +// , "strategy.wikipedia.org", "ten.wikipedia.org", "test2.wikipedia.org", "test.wikipedia.org" +// , "usability.wikipedia.org", "vote.wikipedia.org" +// , "bd.wikimedia.org", "dk.wikimedia.org", "mx.wikimedia.org", "nyc.wikimedia.org", "nz.wikimedia.org", "pa-us.wikimedia.org", "rs.wikimedia.org", "ua.wikimedia.org" +// ); +// Wmf_dump_itm[] itms = new Wmf_dump_list_parser().Parse(Io_mgr.Instance.LoadFilBry("C:\\xowa\\bin\\any\\xowa\\xtns\\xowa\\maintenance\\backup-index.html")); +// Array_.Sort(itms); +// Bry_bfr sql_bfr = Bry_bfr_.New(); +// Bry_bfr bld_bfr = Bry_bfr_.New(); +// int itms_len = itms.length; +// int counter = 1; +// for (int i = 0; i < itms_len; i++) { +// Wmf_dump_itm itm = itms[i]; +// byte[] abrv = itm.Wiki_abrv(); +// if (Bry_.Eq(abrv, Bry_.new_a7("testwikidatawiki"))) continue; +// byte[] domain_bry = Xow_abrv_wm_.Parse_to_domain_bry(abrv); +// if (domain_bry == null) continue; // not a standard WMF wiki; ignore +// if (Bry_find_.Find_fwd(domain_bry, Bry_.new_a7("wikimania")) != Bry_find_.Not_found) continue; +// if (excluded_domains.Has(domain_bry)) continue; +// Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry); +// byte[] tid_name = Xto_display_name(Xow_domain_tid_.Get_type_as_bry(domain_itm.Domain_type_id())); +// sql_bfr +// .Add_byte(Byte_ascii.Paren_bgn) +// .Add_int_variable(counter++) +// .Add_byte(Byte_ascii.Comma) +// .Add_int_variable(1) +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Apos) +// .Add(domain_itm.Lang_orig_key()) +// .Add_byte(Byte_ascii.Apos) +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Apos) +// .Add(tid_name) +// .Add_byte(Byte_ascii.Apos) +// .Add_byte(Byte_ascii.Paren_end) +// .Add_byte(Byte_ascii.Comma) +// .Add_str_u8("--" + String_.new_u8(abrv)) +// .Add_byte_nl() +// ; +// bld_bfr +// .Add_byte(Byte_ascii.Comma) +// .Add_byte(Byte_ascii.Space) +// .Add_byte(Byte_ascii.Quote) +// .Add(domain_bry) +// .Add_byte(Byte_ascii.Quote) +// .Add_byte_nl() +// ; +// } +// Io_url temp = Io_url_.new_fil_("C:\\xowa\\user\\import_update.txt"); +// Io_mgr.Instance.SaveFilBfr(temp, sql_bfr); +//// Io_mgr.Instance.AppendFilBfr(temp, bld_bfr); +// } +// private static byte[] Xto_display_name(byte[] v) { +// if (Bry_.Eq(v, Xow_domain_tid_.Bry__wmforg)) return Bry_.new_a7("Wikimedia Foundation"); +// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__species)) return Bry_.new_a7("Wikispecies"); +// else if (Bry_.Eq(v, Xow_domain_tid_.Bry__mediawiki)) return Bry_.new_a7("MediaWiki"); +// else return Bry_.Add(Byte_ascii.Case_upper(v[0]), Bry_.Mid(v, 1, v.length)); +// } +} +class Wmf_dump_list_parser_fxt { + public void Clear() {} + private Wmf_dump_list_parser parser = new Wmf_dump_list_parser(); + public String itm(String wiki_abrv, String dump_date, byte status_done, String status_msg, String status_time) { + return String_.Concat_with_str("\n", wiki_abrv, dump_date + , Byte_.To_str(status_done) + , status_msg + , status_time + ); + } + public void Test_parse(String raw, String... expd) { + Wmf_dump_itm[] actl = parser.Parse(Bry_.new_a7(raw)); + Tfds.Eq_str_lines(String_.Concat_lines_nl(expd), String_.Concat_lines_nl(Xto_str(actl))); + } + public String[] Xto_str(Wmf_dump_itm[] ary) { + int len = ary.length; + String[] rv = new String[len]; + for (int i = 0; i < len; i++) + rv[i] = Xto_str(ary[i]); + return rv; + } + public static String Xto_str(Wmf_dump_itm itm) { + DateAdp status_time = itm.Status_time(); + String status_time_str = status_time == null ? "" : status_time.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time); + return String_.Concat_with_str("\n", String_.new_a7(itm.Wiki_abrv()), itm.Dump_date().XtoStr_fmt("yyyyMMdd") + , Byte_.To_str(itm.Status_tid()) + , String_.new_a7(itm.Status_msg()) + , status_time_str + ); + + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_latest_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_latest_parser_tst.java new file mode 100644 index 000000000..330e1211c --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/setups/maints/Wmf_latest_parser_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.setups.maints; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*; +import org.junit.*; import gplx.core.ios.*; +public class Wmf_latest_parser_tst { + @Before public void init() {fxt.Clear();} private Wmf_latest_parser_fxt fxt = new Wmf_latest_parser_fxt(); + @Test public void Parse() { + fxt.Test_parse + ( "\nenwiki-latest-pages-articles.xml.bz2 15-Jan-2015 05:43 11575640561\r\n" + , fxt.itm("enwiki-latest-pages-articles.xml.bz2", "2015-01-15 05:43", "10.781 GB") + ); + } +// @Test public void Smoke() { +// Wmf_latest_parser parser = new Wmf_latest_parser(); +// parser.Parse(Io_mgr.Instance.LoadFilBry("C:\\wmf_latest.html")); +// Tfds.Dbg(String_.Concat_lines_nl(Wmf_latest_parser_fxt.Xto_str_ary(parser.To_ary()))); +// } +} +class Wmf_latest_parser_fxt { + public void Clear() {} + private Wmf_latest_parser parser = new Wmf_latest_parser(); + public Wmf_latest_itm itm(String name, String date, String size) {return new Wmf_latest_itm(Bry_.new_a7(name), DateAdp_.parse_iso8561(date), Io_size_.parse_or(size, 0));} + public void Test_parse(String raw, Wmf_latest_itm... expd) { + parser.Parse(Bry_.new_a7(raw)); + Wmf_latest_itm[] actl = parser.To_ary(); + Tfds.Eq_str_lines(String_.Concat_lines_nl(Xto_str_ary(expd)), String_.Concat_lines_nl(Xto_str_ary(actl))); + } + public static String[] Xto_str_ary(Wmf_latest_itm[] ary) { + int len = ary.length; + String[] rv = new String[len]; + for (int i = 0; i < len; i++) + rv[i] = Xto_str(ary[i]); + return rv; + } + public static String Xto_str(Wmf_latest_itm itm) { + return String_.Concat_with_str("\n", String_.new_a7(itm.Name()), itm.Date().XtoStr_fmt_iso_8561(), Io_size_.To_str(itm.Size())); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/setups/upgrades/Xoa_upgrade_mgr_tst.java b/400_xowa/src/gplx/xowa/bldrs/setups/upgrades/Xoa_upgrade_mgr_tst.java new file mode 100644 index 000000000..39983ea1d --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/setups/upgrades/Xoa_upgrade_mgr_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.setups.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.setups.*; +import org.junit.*; +public class Xoa_upgrade_mgr_tst { + @Test public void Run() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Io_url old_history_dir = app.Usere().Fsys_mgr().App_data_dir(); + Io_url new_history_dir = app.Usere().Fsys_mgr().App_data_dir().GenSubDir("history"); + Io_mgr.Instance.SaveFilStr(old_history_dir.GenSubFil("page_history.csv"), "test"); + Xoa_upgrade_mgr.Check(app); + Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(old_history_dir.GenSubFil("page_history.csv"))); // old file still exists + Tfds.Eq("test", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // new file exists + Io_mgr.Instance.SaveFilStr(new_history_dir.GenSubFil("page_history.csv"), "test1"); // dirty file + Xoa_upgrade_mgr.Check(app); // rerun + Tfds.Eq("test1", Io_mgr.Instance.LoadFilStr(new_history_dir.GenSubFil("page_history.csv"))); // dirty file remains (not replaced by old file) + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_dump_parser__tst.java b/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_dump_parser__tst.java new file mode 100644 index 000000000..9075198c2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_dump_parser__tst.java @@ -0,0 +1,88 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.sql_dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.ios.*; import gplx.core.tests.*; +public class Xosql_dump_parser__tst { + private final Xosql_dump_parser__fxt fxt = new Xosql_dump_parser__fxt(); + private static final String table_def = "\n KEY \n) ENGINE; "; + @Test public void One() { + fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2);", "2|"); + } + @Test public void Many() { + fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2),(3,4),(5,6);", "2|\n4|\n6|"); + } + @Test public void Quote_basic() { + fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a','b');", "a|b|"); + } + @Test public void Escape_backslash() { + fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a\\\\b','c');", "a\\b|c|"); + } + @Test public void Escape_quote() { + fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'a\"b','c');", "a\"b|c|"); + } + @Test public void Fld_paren_end() { + fxt.Init(String_.Ary("c1", "c2", "c3"), "c2", "c3").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,'Психостимуляторы_(лекарственные_средства)','c');", "Психостимуляторы_(лекарственные_средства)|c|"); + } + @Test public void Insert_multiple() { + fxt.Init(String_.Ary("c1", "c2"), "c2").Test__parse(table_def + "INSERT INTO 'tbl_1' VALUES (1,2);INSERT INTO 'tbl_1' VALUES (3,4)", "2|\n4|"); + } +} +class Xosql_dump_parser__fxt { + private Xosql_dump_parser parser; + private Xosql_dump_cbk__test cbk; + private String[] tbl_flds; + public Xosql_dump_parser__fxt Init(String[] tbl_flds, String... cbk_flds) { + this.tbl_flds = tbl_flds; + this.cbk = new Xosql_dump_cbk__test(); + this.parser = new Xosql_dump_parser(cbk, cbk_flds); + return this; + } + public void Test__parse(String raw_str, String expd) { + Io_url src_fil = Io_url_.new_fil_("mem/test.sql"); + Io_mgr.Instance.SaveFilBry(src_fil, Make_dump(tbl_flds, raw_str)); + parser.Src_fil_(src_fil); + parser.Parse(Gfo_usr_dlg_.Test()); + Gftest.Eq__str(expd, cbk.To_bry_and_clear()); + } + private byte[] Make_dump(String[] tbl_flds, String insert) { + Bry_bfr bfr = Bry_bfr_.New(); + bfr.Add_str_a7("CREATE TABLE tbl_0 ("); + for (int i = 0; i < tbl_flds.length; ++i) { + bfr.Add_byte_nl(); + bfr.Add_byte(Byte_ascii.Tick); + bfr.Add_str_a7(tbl_flds[i]); + bfr.Add_byte(Byte_ascii.Tick); + bfr.Add_byte_comma(); + } + bfr.Add_str_a7("\nUNIQUE KEY idx_0 (fld_0));\n"); + bfr.Add_str_u8(insert); + return bfr.To_bry_and_clear(); + } +} +class Xosql_dump_cbk__test implements Xosql_dump_cbk { + private int prv_idx = -1; + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Clear() {prv_idx = -1; bfr.Clear();} + public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) { + if (fld_idx <= prv_idx) { + if (prv_idx != -1) bfr.Add_byte_nl(); + } + bfr.Add_mid(src, val_bgn, val_end).Add_byte_pipe(); + prv_idx = fld_idx; + } + public void On_row_done() {} + public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();} +} diff --git a/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_tbl_parser__tst.java b/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_tbl_parser__tst.java new file mode 100644 index 000000000..5065d3954 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/sql_dumps/Xosql_tbl_parser__tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.sql_dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.tests.*; +public class Xosql_tbl_parser__tst { + private final Xosql_tbl_parser__fxt fxt = new Xosql_tbl_parser__fxt(); + @Test public void Unique_key() { + fxt.Exec__parse(String_.Concat_lines_nl + ( "ignore" + , "CREATE TABLE tbl_0 (" + , " `fld_2` int," + , " `fld_1` int," + , " `fld_0` int," + , " UNIQUE KEY idx_0 (fld_2)" + , ") ENGINE;" + )); + fxt.Test__count(3); + fxt.Test__get("fld_0", 2); + fxt.Test__get("fld_1", 1); + fxt.Test__get("fld_2", 0); + fxt.Test__get("fld_3", -1); + } + @Test public void Primary_key() { + fxt.Test__extract(String_.Concat_lines_nl + ( "ignore" + , "CREATE TABLE tbl_0 (" + , " `fld_0` int," + , " PRIMARY KEY idx_0 (fld_2)" + , ") ENGINE;" + ), String_.Concat_lines_nl + ( " `fld_0` int," + )); + } + @Test public void Key() { + fxt.Test__extract(String_.Concat_lines_nl + ( "ignore" + , "CREATE TABLE tbl_0 (" + , " `fld_0` int," + , " KEY idx_0 (fld_2)" + , ") ENGINE;" + ), String_.Concat_lines_nl + ( " `fld_0` int," + )); + } + @Test public void Unique_key__key__primary_key() { + fxt.Test__extract(String_.Concat_lines_nl + ( "ignore" + , "CREATE TABLE tbl_0 (" + , " `fld_0` int," + , " UNIQUE KEY idx_0 (fld_2)," + , " KEY idx_0 (fld_2)," + , " PRIMARY KEY idx_0 (fld_2)," + , ") ENGINE;" + ), String_.Concat_lines_nl + ( " `fld_0` int," + )); + } +} +class Xosql_tbl_parser__fxt { + private final Xosql_tbl_parser parser = new Xosql_tbl_parser(); + private Ordered_hash tbl_flds; + public void Exec__parse(String v) {this.tbl_flds = parser.Parse(Bry_.new_a7(v));} + public void Test__count(int expd) {Gftest.Eq__int(expd, tbl_flds.Len());} + public void Test__get(String key, int expd) { + Xosql_fld_itm actl_itm = (Xosql_fld_itm)tbl_flds.Get_by(Bry_.new_u8(key)); + Gftest.Eq__int(expd, actl_itm == null ? Bry_find_.Not_found : actl_itm.Idx()); + } + public void Test__extract(String raw, String expd) { + Gftest.Eq__ary__lines(expd, parser.Extract_flds(Bry_.new_u8(raw)), "extract"); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wiki_cfgs/Xoi_wiki_props_api_tst.java b/400_xowa/src/gplx/xowa/bldrs/wiki_cfgs/Xoi_wiki_props_api_tst.java new file mode 100644 index 000000000..25dda1b04 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wiki_cfgs/Xoi_wiki_props_api_tst.java @@ -0,0 +1,140 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.wiki_cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.strings.*; +import gplx.langs.xmls.*; +import gplx.xowa.addons.bldrs.app_cfgs.*; +public class Xoi_wiki_props_api_tst { + private Xoi_wiki_props_fxt fxt = new Xoi_wiki_props_fxt(); + @Before public void init() {} // private Xob_subpage_tst_fxt fxt = new] Xob_subpage_tst_fxt(); + @Test public void Parse() { + fxt.Test_parse(String_.Concat_lines_nl + ( "" + , "" + , " " + , " WP" + , " WT" + , " " + , " " + , " " + , " Talk" + , " " + , "" + , "" + ), fxt.wiki_() + .Alias_ary_(fxt.alias_(4, "WP"), fxt.alias_(5, "WT")) + .Ns_ary_(fxt.ns_(0, false), fxt.ns_(1, true)) + ); + } +// @Test public void Build() { +// fxt.Test_build(fxt.wiki_("enwiki") +// .Alias_ary_(fxt.alias_(4, "WP"), fxt.alias_(5, "WT")) +// .Ns_ary_(fxt.ns_(0, false), fxt.ns_(1, true)) +// , ""); +// } +// Tfds.Eq_str_lines(Query_ns(protocol, gplx.core.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl +// ( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"" +// , "4|WP" +// , "5|WT" +// , "6|Image" +// , "7|Image_talk" +// , "\");');" +// fxt.Test_parse(String_.Concat_lines_nl +// ( "'wgNamespacesWithSubpages' => array" +// , "( 'default' => array(2 => 1)" +// , ", 'enwiki' => array(0 => 1)" +// , ")" +// )); +} +class Xoi_wiki_props_fxt { + private Xoi_wiki_props_api api = new Xoi_wiki_props_api(); + private Bry_bfr bfr = Bry_bfr_.New(); + public Xoi_wiki_props_wiki wiki_() {return wiki_("domain_doesnt_matter");} + public Xoi_wiki_props_wiki wiki_(String wiki_domain) {return new Xoi_wiki_props_wiki().Wiki_domain_(Bry_.new_a7(wiki_domain));} + public Xoi_wiki_props_alias alias_(int id, String alias) {return new Xoi_wiki_props_alias().Init_by_ctor(id, alias);} + public Xoi_wiki_props_ns ns_(int id, boolean subpages_enabled) {return new Xoi_wiki_props_ns().Init_by_ctor(id, subpages_enabled);} + public void Test_parse(String xml, Xoi_wiki_props_wiki expd) { + Xoi_wiki_props_wiki actl = new Xoi_wiki_props_wiki(); + api.Parse(actl, xml); + Tfds.Eq_str_lines(Xto_str(expd), Xto_str(actl)); + } + public void Test_build(Xoi_wiki_props_wiki wiki, String expd) { + api.Build_cfg(bfr, wiki); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + private String Xto_str(Xoi_wiki_props_wiki v) { + int len = v.Alias_ary().length; + bfr.Add_str_a7("aliases").Add_byte_nl(); + for (int i = 0; i < len; i++) { + Xoi_wiki_props_alias alias = v.Alias_ary()[i]; + bfr.Add_int_variable(alias.Id()).Add_byte_pipe().Add_str_u8(alias.Alias()).Add_byte_nl(); + } + bfr.Add_str_a7("ns").Add_byte_nl(); + len = v.Ns_ary().length; + for (int i = 0; i < len; i++) { + Xoi_wiki_props_ns ns = v.Ns_ary()[i]; + bfr.Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_bool(ns.Subpages_enabled()).Add_byte_nl(); + } + bfr.Add_byte_nl(); + return bfr.To_str_and_clear(); + } +} +class Xob_subpage_tst_fxt { + public Xob_subpage_tst_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + mgr = app.Bldr().Wiki_cfg_bldr(); + } + mgr.Clear(); + hash.Clear(); + return this; + } private Xoae_app app; Xob_wiki_cfg_bldr mgr; Ordered_hash hash = Ordered_hash_.New(); + private Xob_subpage_parser parser = new Xob_subpage_parser(); + public Xob_subpage_tst_fxt Init_cmd(String wiki, String key, String text) { +// mgr.Itms_get_or_new(wiki).Itms_add(key, text); + return this; + } + public Xob_subpage_tst_fxt Expd_txt(String wiki, String text) { +// hash.Add(wiki, Keyval_.new_(wiki, text)); + return this; + } + private String_bldr sb = String_bldr_.new_(); + public void Test_parse(String s) { + Xob_subpage_wiki[] actl = parser.Parse(Bry_.new_u8(s)); + Tfds.Eq_str_lines("", X_str_wikis(actl)); + } + public String X_str_wikis(Xob_subpage_wiki[] ary) { + X_str_wikis(sb, ary); + return sb.To_str_and_clear(); + + } + private void X_str_wikis(String_bldr sb, Xob_subpage_wiki[] ary) { + int len = ary.length; + for (int i = 0; i < len; i++) { + Xob_subpage_wiki wiki = ary[i]; + X_str_wiki(sb, wiki); + } + } + private void X_str_wiki(String_bldr sb, Xob_subpage_wiki wiki) { + sb.Add(wiki.Name()).Add_char_nl(); + int ns_len = wiki.Ns_list().Count(); + for (int i = 0; i < ns_len; i++) { + Xob_subpage_ns ns = (Xob_subpage_ns)wiki.Ns_list().Get_at(i); + sb.Add(ns.Id()).Add("=").Add(Bool_.To_str_lower(ns.Enabled())).Add_char_nl(); + } + sb.Add_char_nl(); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java b/400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java new file mode 100644 index 000000000..ab9a99a41 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wkrs/Xob_io_utl__tst.java @@ -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.bldrs.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; +import org.junit.*; import gplx.core.tests.*; +public class Xob_io_utl__tst { + private final Xob_io_utl__fxt fxt = new Xob_io_utl__fxt(); + @Test public void Basic() { + fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b", String_.Ary(".txt"), "b.txt"); + } + @Test public void Include__ext() {// PURPOSE: handle calls like "a.sql", ".sql", ".gz" + fxt.Test__match(String_.Ary("a.txt", "b.txt", "c.txt"), "b.txt", String_.Ary(".txt"), "b.txt"); + } + @Test public void Dupe__pick_last() { + fxt.Test__match(String_.Ary("b0.txt", "b1.txt", "b2.txt"), "b", String_.Ary(".txt"), "b2.txt"); + } + @Test public void Ext() { + fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".xml", ".bz2"), "b.xml"); + } + @Test public void Ext__dupes() { + fxt.Test__match(String_.Ary("b.txt", "b.png", "b.xml"), "b", String_.Ary(".txt", ".xml"), "b.xml"); + } +} +class Xob_io_utl__fxt { + public void Test__match(String[] path_ary, String name_pattern, String[] ext_ary, String expd) { + Io_url actl = Xob_io_utl_.Find_nth_by_wildcard_or_null(Io_url_.Ary(path_ary), name_pattern, ext_ary); + Gftest.Eq__str(expd, actl == null ? "<>" : actl.Raw()); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/bldrs/wms/dump_pages/Xowmf_wiki_dump_dirs_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/wms/dump_pages/Xowmf_wiki_dump_dirs_parser_tst.java new file mode 100644 index 000000000..a7b34f6f3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wms/dump_pages/Xowmf_wiki_dump_dirs_parser_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.wms.dump_pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*; +import org.junit.*; +import gplx.xowa.wikis.domains.*; +public class Xowmf_wiki_dump_dirs_parser_tst { + @Before public void init() {fxt.Clear();} private final Xowmf_wiki_dump_dirs_parser_fxt fxt = new Xowmf_wiki_dump_dirs_parser_fxt(); + @Test public void Basic() { + fxt.Test_parse("20141230/20150118/", "20141230", "20150118"); + } + @Test public void Example() { // http://dumps.wikimedia.org/jawiki/ + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "" + , "Index of /jawiki/" + , "" + , "

    Index of /jawiki/


    ../"
    +		, "20141122/                                          25-Nov-2014 22:04                   -"
    +		, "20141211/                                          14-Dec-2014 09:25                   -"
    +		, "20141230/                                          02-Jan-2015 09:02                   -"
    +		, "20150118/                                          21-Jan-2015 04:39                   -"
    +		, "20150221/                                          24-Feb-2015 17:51                   -"
    +		, "20150313/                                          16-Mar-2015 14:37                   -"
    +		, "20150402/                                          05-Apr-2015 06:19                   -"
    +		, "20150422/                                          25-Apr-2015 13:52                   -"
    +		, "20150512/                                          15-May-2015 08:17                   -"
    +		, "20150602/                                          16-Jun-2015 01:34                   -"
    +		, "20150703/                                          08-Jul-2015 14:44                   -"
    +		, "latest/                                            08-Jul-2015 14:44                   -"
    +		, "

    " + , "" + ) + , "20141122" + , "20141211" + , "20141230" + , "20150118" + , "20150221" + , "20150313" + , "20150402" + , "20150422" + , "20150512" + , "20150602" + , "20150703" + , "latest" + ); + } +} +class Xowmf_wiki_dump_dirs_parser_fxt { + public void Clear() {} + public void Test_parse(String src, String... expd_dates) { + String[] actl_dates = Xowmf_wiki_dump_dirs_parser.Parse(Xow_domain_itm_.Bry__enwiki, Bry_.new_u8(src)); + Tfds.Eq_ary_str(expd_dates, actl_dates); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_file_tst.java b/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_file_tst.java new file mode 100644 index 000000000..d4fe9f897 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_file_tst.java @@ -0,0 +1,43 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*; +import org.junit.*; +public class Xowm_dump_file_tst { + private final Xowm_dump_file_fxt fxt = new Xowm_dump_file_fxt(); + @Test public void Parse() {fxt.Test_parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xowm_dump_type_.Int__pages_articles);} + @Test public void Bld_dump_dir_url() { + fxt.Test_bld_dump_dir_url("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/"); + } + @Test public void Bld_dump_file_name() { + fxt.Test_bld_dump_file_name("simplewiki", "latest", Xowm_dump_type_.Str__pages_articles, "simplewiki-latest-pages-articles.xml.bz2"); + } +} +class Xowm_dump_file_fxt { + public void Test_parse(String name, String domain, String date, int tid) { + Xowm_dump_file dump_file = Xowm_dump_file_.parse(Bry_.new_u8(name)); + Tfds.Eq(domain , dump_file.Domain_itm().Domain_str()); + Tfds.Eq(date , dump_file.Dump_date()); + Tfds.Eq(tid , Xowm_dump_type_.parse_by_file(Bry_.new_u8(dump_file.Dump_type_str()))); + } + public void Test_bld_dump_dir_url(String dump_file, String date, String expd) { + byte[] actl = Xowm_dump_file_.Bld_dump_dir_url(Bry_.new_a7(Xowm_dump_file_.Server_your_org), Bry_.new_a7(dump_file), Bry_.new_a7(date)); + Tfds.Eq(expd, String_.new_a7(actl)); + } + public void Test_bld_dump_file_name(String dump_file, String date, String dump_type, String expd) { + byte[] actl = Xowm_dump_file_.Bld_dump_file_name(Bry_.new_a7(dump_file), Bry_.new_a7(date), Bry_.new_a7(dump_type), Xowm_dump_file_.Ext_xml_bz2); + Tfds.Eq(expd, String_.new_a7(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_type__tst.java b/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_type__tst.java new file mode 100644 index 000000000..d6fce505f --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wms/dumps/Xowm_dump_type__tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*; +import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.wikis.*; +public class Xowm_dump_type__tst { + private final Xowm_dump_type__fxt fxt = new Xowm_dump_type__fxt(); + @Test public void Parse() { + fxt.Test_parse("pages-articles.xml" , Xowm_dump_type_.Int__pages_articles); + fxt.Test_parse("pages-meta-current.xml" , Xowm_dump_type_.Int__pages_meta_current); + } +} +class Xowm_dump_type__fxt { + public void Test_parse(String raw_str, int expd) {Tfds.Eq_int(expd, Xowm_dump_type_.parse_by_file(Bry_.new_u8(raw_str)), "dump_type");} +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wms/revs/Xowm_rev_wkr__meta__wm_tst.java b/400_xowa/src/gplx/xowa/bldrs/wms/revs/Xowm_rev_wkr__meta__wm_tst.java new file mode 100644 index 000000000..45d9304f6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wms/revs/Xowm_rev_wkr__meta__wm_tst.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*; +import org.junit.*; import gplx.langs.jsons.*; import gplx.core.net.*; import gplx.xowa.wikis.nss.*; +import gplx.xowa.wikis.domains.*; +public class Xowm_rev_wkr__meta__wm_tst { + private final Xowm_rev_wkr__meta__wm_fxt fxt = new Xowm_rev_wkr__meta__wm_fxt(); + @Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();} + @After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;} + @Test public void Basic() { + Wmapi_itm__pge[] expd = fxt.Make_pge_ary + ( fxt.Make_pge(Xow_ns_.Tid__main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1") + , fxt.Make_pge(Xow_ns_.Tid__main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2") + ); + fxt.Init_inet_upload(expd); + fxt.Test_fetch(String_.Ary("A", "B"), expd); // test get both + fxt.Init_inet_upload(expd); + fxt.Test_fetch(String_.Ary("A") , expd[0]); // test get 1 + fxt.Init_inet_upload(expd); + fxt.Test_fetch(String_.Ary("C"), fxt.Make_pge_empty(0, "C")); // test get none + fxt.Init_inet_upload(expd); + fxt.Test_fetch(String_.Ary("A", "B", "C"), expd[0], expd[1], fxt.Make_pge_empty(0, "C")); // test get too many + } +} +class Xowm_rev_wkr__meta__wm_fxt { + private final String domain_str = Xow_domain_itm_.Str__enwiki; + private final Ordered_hash rev_hash = Ordered_hash_.New_bry(); + private final Xowm_rev_wkr__meta__wm meta_wkr = new Xowm_rev_wkr__meta__wm(); + private final Wmapi_itm_json_wtr json_wtr = new Wmapi_itm_json_wtr(); + public Xowm_rev_wkr__meta__wm_fxt() { + meta_wkr.Inet_conn_(Gfo_inet_conn_.new_mem_pile()); + } + public Wmapi_itm__pge[] Make_pge_ary(Wmapi_itm__pge... ary) {return ary;} + public Wmapi_itm__pge Make_pge_empty(int page_ns, String page_ttl) { + Wmapi_itm__pge rv = Make_pge(page_ns, page_ttl, 0, 0, 0, null, null, null); + rv.Rvn_ary_(Wmapi_itm__rvn.Ary_empty); + return rv; + } + public Wmapi_itm__pge Make_pge(int page_ns, String page_ttl, int page_id, int rev_id, int rev_len, String rev_time, String rev_user, String rev_note) { + Wmapi_itm__pge rv = new Wmapi_itm__pge(); + rv.Init_id(page_id); + rv.Init_ttl(page_ns, Bry_.new_u8(page_ttl)); + Wmapi_itm__rvn rvn = new Wmapi_itm__rvn(); + rv.Rvn_ary_(rvn); + rvn.Init(rev_id, rev_len, Bry_.new_a7(rev_time), Bry_.new_a7(rev_user), Bry_.new_a7(rev_note)); + return rv; + } + public void Init_inet_upload(Wmapi_itm__pge... ary) { + Gfo_inet_conn inet_conn = meta_wkr.Inet_conn(); + byte[] page = json_wtr.To_bry(ary); + inet_conn.Clear(); + inet_conn.Upload_by_bytes(domain_str, page); + } + public void Test_fetch(String[] ttl_ary, Wmapi_itm__pge... expd) { + Init_rev_hash(ttl_ary); + meta_wkr.Fetch_meta(domain_str, rev_hash, 0, rev_hash.Count()); + Tfds.Eq_str_lines(String_.new_u8(json_wtr.To_bry(expd)), String_.new_u8(json_wtr.To_bry((Wmapi_itm__pge[])rev_hash.To_ary_and_clear(Wmapi_itm__pge.class)))); + } + private void Init_rev_hash(String[] ttl_ary) { + rev_hash.Clear(); + int len = ttl_ary.length; + for (int i = 0; i < len; ++i) { + String ttl_str = ttl_ary[i]; + byte[] ttl_bry = Bry_.new_u8(ttl_str); + rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Tid__main, ttl_bry)); + } + } +} diff --git a/400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java new file mode 100644 index 000000000..35d6d5498 --- /dev/null +++ b/400_xowa/src/gplx/xowa/bldrs/wms/sites/Site_json_parser_tst.java @@ -0,0 +1,429 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*; +import org.junit.*; import gplx.langs.jsons.*; import gplx.xowa.wikis.nss.*; +public class Site_json_parser_tst { + private final Site_json_parser_fxt fxt = new Site_json_parser_fxt(); + @Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();} + @After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;} + @Test public void General() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'general':" + , " { 'mainpage': 'Main Page'" + , " , 'imagewhitelistenabled': ''" + , " , 'timeoffset': 0" + , " , 'thumblimits': " + , " [ 120" + , " , 150" + , " ]" + , " , 'imagelimits': " + , " [ " + , " { 'width': 320" + , " , 'height': 240" + , " }" + , " , " + , " { 'width': 640" + , " , 'height': 480" + , " }" + , " ]" + , " }" + , "}" + )); + fxt.Test_general(Keyval_.new_("mainpage", "Main Page"), Keyval_.new_("imagewhitelistenabled", ""), Keyval_.new_("timeoffset", "0"), Keyval_.new_("thumblimits", "120|150"), Keyval_.new_("imagelimits", "320=240|640=480")); + } + @Test public void Namespace() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'namespaces':" + , " { '0':" + , " { 'id': 0" + , " , 'case': 'first-letter'" + , " , 'content': ''" + , " , '*': ''" + , " }" + , " , '2': " + , " { 'id': 2" + , " , 'case': 'first-letter'" + , " , 'subpages': ''" + , " , 'canonical': 'User'" + , " , '*': 'User'" + , " }" + , " ,'4': " + , " { 'id': 4" + , " , 'case': 'first-letter'" + , " , 'subpages': ''" + , " , 'canonical': 'Project'" + , " , '*': 'Wikipedia'" + , " }" + , " ,'2600': " + , " { 'id': 2600" + , " , 'case': 'case-sensitive'" + , " , 'canonical': 'Topic'" + , " , 'defaultcontentmodel': 'flow-board'" + , " , '*': 'Topic'" + , " }" + , " }" + , "}" + )); + fxt.Test_namespace + ( fxt.Make_namespace(0 , Bool_.N, null , "" , Bool_.N, Bool_.Y, null) + , fxt.Make_namespace(2 , Bool_.N, "User" , "User" , Bool_.Y, Bool_.N, null) + , fxt.Make_namespace(4 , Bool_.N, "Project" , "Wikipedia" , Bool_.Y, Bool_.N, null) + , fxt.Make_namespace(2600 , Bool_.Y, "Topic" , "Topic" , Bool_.N, Bool_.N, "flow-board") + ); + } + @Test public void Statistic() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'statistics':" + , " { 'pages': 1" + , " , 'articles': 2" + , " , 'edits': 3" + , " , 'images': 4" + , " , 'users': 5" + , " , 'activeusers': 6" + , " , 'admins': 7" + , " , 'jobs': 8" + , " , 'queued-massmessages': 9" + , " }" + , "}" + )); + fxt.Test_statistic + ( fxt.Make_statistic(1, 2, 3, 4, 5, 6, 7, 8, 9) + ); + } + @Test public void Interwikimap() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'interwikimap':" + , " [" + , " { 'prefix': 'aquariumwiki'" + , " , 'url': 'http://www.theaquariumwiki.com/$1'" + , " }" + , " , { 'prefix': 'ar'" + , " , 'local': ''" + , " , 'extralanglink': ''" + , " , 'linktext': 'More languages'" + , " , 'sitename': 'Multilingual Wikisource'" + , " , 'language': '\u0627\u0644\u0639\u0631\u0628\u064a\u0629'" + , " , 'url': 'https://ar.wikipedia.org/wiki/$1'" + , " , 'protorel': ''" + , " }" + , " ]" + , "}" + )); + fxt.Test_interwikimap + ( fxt.Make_interwikimap("aquariumwiki" , Bool_.N, Bool_.N, null , null , null , Bool_.N, "http://www.theaquariumwiki.com/$1" , Bool_.N) + , fxt.Make_interwikimap("ar" , Bool_.Y, Bool_.Y, "More languages", "Multilingual Wikisource" , "العربية" , Bool_.N, "https://ar.wikipedia.org/wiki/$1" , Bool_.Y) + ); + } + @Test public void Namespacealias() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'namespacealiases':" + , " [ " + , " { 'id': 4" + , " , '*': 'WP'" + , " }" + , " , " + , " { 'id': 7" + , " , '*': 'Image talk'" + , " }" + , " ]" + , "}" + )); + fxt.Test_namespacealias + ( fxt.Make_namespacealias(4 ,"WP") + , fxt.Make_namespacealias(7 , "Image talk") + ); + } + @Test public void Specialpagealias() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'specialpagealiases':" + , " [ " + , " { 'realname': 'BrokenRedirects'" + , " , 'aliases': " + , " [ 'BrokenRedirects'" + , " ]" + , " }" + , " , " + , " { 'realname': 'Lonelypages'" + , " , 'aliases': " + , " [ 'LonelyPages'" + , " , 'OrphanedPages'" + , " ]" + , " }" + , " ]" + , "}" + )); + fxt.Test_specialpagealias + ( fxt.Make_specialpagealias("BrokenRedirects" , "BrokenRedirects") + , fxt.Make_specialpagealias("Lonelypages" , "LonelyPages", "OrphanedPages") + ); + } + @Test public void Library() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'libraries':" + , " [ " + , " { 'name': 'cssjanus/cssjanus'" + , " , 'version': '1.1.1'" + , " }" + , " , " + , " { 'name': 'leafo/lessphp'" + , " , 'version': '0.5.0'" + , " }" + , " ]" + , "}" + )); + fxt.Test_library + ( fxt.Make_library("cssjanus/cssjanus" , "1.1.1") + , fxt.Make_library("leafo/lessphp" , "0.5.0") + ); + } + @Test public void Extension() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'extensions':" + , " [ " + , " { 'type': 'media'" + , " , 'name': 'PagedTiffHandler'" + , " , 'descriptionmsg': 'tiff-desc'" + , " , 'author': '[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland'" + , " , 'url': 'https://www.mediawiki.org/wiki/Extension:PagedTiffHandler'" + , " , 'vcs-system': 'git'" + , " , 'vcs-version': 'b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'" + , " , 'vcs-url': 'https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'" + , " , 'vcs-date': '2015-03-27T16:44:25Z'" + , " , 'license-name': 'GPL-2.0+'" + , " , 'license': '/wiki/Special:Version/License/PagedTiffHandler'" + , " }" + , " , " + , " { 'type': 'media'" + , " , 'name': 'A'" + , " , 'namemsg': 'A-name'" + , " , 'description': 'desc'" + , " , 'descriptionmsg': 'A-desc'" + , " , 'author': 'B'" + , " , 'url': 'C'" + , " , 'version': '0.1.0'" + , " , 'vcs-system': 'git'" + , " , 'vcs-version': 'd'" + , " , 'vcs-url': 'e'" + , " , 'vcs-date': '2015-03-27T16:44:25Z'" + , " , 'license-name': 'f'" + , " , 'license': 'g'" + , " }" + , " ]" + , "}" + )); + fxt.Test_extension + ( fxt.Make_extension("media", "PagedTiffHandler", "", "", "tiff-desc", "[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland", "https://www.mediawiki.org/wiki/Extension:PagedTiffHandler", null, "git", "b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "2015-03-27T16:44:25Z", "GPL-2.0+", "/wiki/Special:Version/License/PagedTiffHandler", null) + , fxt.Make_extension("media", "A", "A-name", "desc", "A-desc", "B", "C", "0.1.0", "git", "d", "e", "2015-03-27T16:44:25Z", "f", "g", null) + ); + } + @Test public void Skin() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'skins':" + , " [ " + , " { 'code': 'vector'" + , " , 'default': ''" + , " , '*': 'Vector'" + , " }" + , " , " + , " { 'code': 'monobook'" + , " , '*': 'MonoBook'" + , " }" + , " , " + , " { 'code': 'fallback'" + , " , 'unusable': ''" + , " , '*': 'Fallback'" + , " }" + , " ]" + , "}" + )); + fxt.Test_skin + ( fxt.Make_skin("vector" , Bool_.Y, "Vector" , Bool_.N) + , fxt.Make_skin("monobook" , Bool_.N, "MonoBook" , Bool_.N) + , fxt.Make_skin("fallback" , Bool_.N, "Fallback" , Bool_.Y) + ); + } + @Test public void Magicword() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'magicwords':" + , " [ " + , " { 'name': 'expr'" + , " , 'aliases': " + , " [ 'expr'" + , " ]" + , " }" + , " , " + , " { 'name': 'currentmonth'" + , " , 'aliases': " + , " [ 'CURRENTMONTH'" + , " , 'CURRENTMONTH2'" + , " ]" + , " , 'case-sensitive': ''" + , " }" + , " ]" + , "}" + )); + fxt.Test_magicword + ( fxt.Make_magicword("expr" , Bool_.N, "expr") + , fxt.Make_magicword("currentmonth" , Bool_.Y, "CURRENTMONTH", "CURRENTMONTH2") + ); + } + @Test public void Functionhook() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'functionhooks':" + , " [ 'ns'" + , " , 'nse'" + , " ]" + , "}" + )); + fxt.Test_functionhook("ns", "nse"); + } + @Test public void Showhook() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'showhooks':" + , " [ " + , " { 'name': 'APIAfterExecute'" + , " , 'subscribers': " + , " [ 'ApiParseExtender::onAPIAfterExecute'" + , " , 'ZeroBanner\\\\MccMncLogging::onAPIAfterExecute'" + , " , 'XAnalytics::onAPIAfterExecute'" + , " ]" + , " }" + , " , " + , " { 'name': 'ParserLimitReport'" + , " , 'subscribers': " + , " { 'scribunto': 'ScribuntoHooks::reportLimits'" + , " }" + , " }" + , " ]" + , "}" + )); + fxt.Test_showhook + ( fxt.Make_showhook("APIAfterExecute" , "", "ApiParseExtender::onAPIAfterExecute", "ZeroBanner\\MccMncLogging::onAPIAfterExecute", "XAnalytics::onAPIAfterExecute") + , fxt.Make_showhook("ParserLimitReport" , "ScribuntoHooks::reportLimits") + ); + } + @Test public void Extensiontag() { + fxt.Exec_parse(String_.Concat_lines_nl_skip_last + ( "{ 'extensiontags':" + , " [ '
    '"
    +		, "  , ''"
    +		, "  ]"
    +		, "}"
    +		));
    +		fxt.Test_extensiontag("
    ", "");
    +	}
    +	@Test  public void Protocol() {
    +		fxt.Exec_parse(String_.Concat_lines_nl_skip_last
    +		( "{ 'protocols':"
    +		, "  [ 'bitcoin:'"
    +		, "  , 'ftp://'"
    +		, "  ]"
    +		, "}"
    +		));
    +		fxt.Test_protocol("bitcoin:", "ftp://");
    +	}
    +	@Test  public void Defaultoption() {
    +		fxt.Exec_parse(String_.Concat_lines_nl_skip_last
    +		( "{ 'defaultoptions':"
    +		, "  { 'globaluserpage': true"
    +		, "  , 'cols': 80"
    +		, "  , 'echo-email-format': 'html'"
    +		, "  }"
    +		, "}"
    +		));
    +		fxt.Test_defaultoption(Keyval_.new_("globaluserpage", "true"), Keyval_.new_("cols", "80"), Keyval_.new_("echo-email-format", "html"));
    +	}
    +	@Test  public void Language() {
    +		fxt.Exec_parse(String_.Concat_lines_nl_skip_last
    +		( "{ 'languages':"
    +		, "  [ "
    +		, "    { 'code': 'aa'"
    +		, "    , '*': 'Qaf\u00e1r af'"
    +		, "    }"
    +		, "  , "
    +		, "    { 'code': 'ab'"
    +		, "    , '*': '\u0410\u04a7\u0441\u0448\u04d9\u0430'"
    +		, "    }"
    +		, "  ]"
    +		, "}"
    +		));
    +		fxt.Test_language
    +		( fxt.Make_language("aa"	, "Qafár af")
    +		, fxt.Make_language("ab"	, "Аҧсшәа")
    +		);
    +	}
    +//		@Test   public void Smoke() {
    +//			Io_url json_url = Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta__en.wikipedia.org.json");
    +//			byte[] src = Io_mgr.Instance.LoadFilBry(json_url);
    +//			Site_json_parser parser = new Site_json_parser();
    +//			Site_meta_itm meta_itm = new Site_meta_itm();
    +//			parser.Parse_root(meta_itm, "en.wikipedia.org", src);
    +//			gplx.dbs.Db_conn_bldr.Instance.Reg_default_sqlite();
    +//			Site_core_db core_db = new Site_core_db(Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta.sqlite3"));
    +//			core_db.Save(meta_itm, Bry_.new_a7("en.w"));
    +//		}
    +}
    +class Site_json_parser_fxt {
    +	private final    Json_parser json_parser = new Json_parser();
    +	private final    Site_json_parser site_meta_parser;
    +	private Site_meta_itm site_meta;
    +	public Site_json_parser_fxt() {
    +		this.site_meta_parser = new Site_json_parser(json_parser);
    +	}
    +	public void Exec_parse(String raw) {
    +		Json_doc jdoc = json_parser.Parse_by_apos(raw);
    +		site_meta = new Site_meta_itm();
    +		site_meta_parser.Parse_root(site_meta, "en.wikipedia.org", jdoc.Root_nde());
    +	}
    +	public Site_namespace_itm Make_namespace(int id, boolean case_tid_is_cs, String canonical, String localized, boolean subpages, boolean content, String defaultcontentmodel) {
    +		return new Site_namespace_itm(id, case_tid_is_cs ? Xow_ns_case_.Bry__all : Xow_ns_case_.Bry__1st, Bry_.new_u8_safe(canonical), Bry_.new_u8_safe(localized), subpages, content, Bry_.new_u8_safe(defaultcontentmodel));
    +	}
    +	public Site_statistic_itm Make_statistic(long pages, long articles, long edits, long images, long users, long activeusers, long admins, long jobs, long queued_massmessages) {return new Site_statistic_itm().Ctor(pages, articles, edits, images, users, activeusers, admins, jobs, queued_massmessages);}
    +	public Site_interwikimap_itm Make_interwikimap(String prefix, boolean local, boolean extralanglink, String linktext, String sitename, String language, boolean localinterwiki, String url, boolean protorel) {
    +		return new Site_interwikimap_itm(Bry_.new_u8_safe(prefix), local, extralanglink, Bry_.new_u8_safe(linktext), Bry_.new_u8_safe(sitename), Bry_.new_u8_safe(language), localinterwiki, Bry_.new_u8_safe(url), protorel);
    +	}
    +	public Site_namespacealias_itm Make_namespacealias(int id, String alias) {return new Site_namespacealias_itm(id, Bry_.new_u8_safe(alias));}
    +	public Site_specialpagealias_itm Make_specialpagealias(String realname, String... aliases) {return new Site_specialpagealias_itm(Bry_.new_u8_safe(realname), Bry_.Ary(aliases));}
    +	public Site_library_itm Make_library(String name, String version) {return new Site_library_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(version));}
    +	public Site_extension_itm Make_extension
    +		( String type, String name, String namemsg, String description, String descriptionmsg, String author, String url, String version
    +		, String vcs_system, String vcs_version, String vcs_url, String vcs_date, String license_name, String license, String credits) {
    +		return new Site_extension_itm
    +		( Bry_.new_u8_safe(type), Bry_.new_u8_safe(name), Bry_.new_u8_safe(namemsg), Bry_.new_u8_safe(description), Bry_.new_u8_safe(descriptionmsg), Bry_.new_u8_safe(author), Bry_.new_u8_safe(url), Bry_.new_u8_safe(version)
    +		, Bry_.new_u8_safe(vcs_system), Bry_.new_u8_safe(vcs_version), Bry_.new_u8_safe(vcs_url), Bry_.new_u8_safe(vcs_date), Bry_.new_u8_safe(license_name), Bry_.new_u8_safe(license), Bry_.new_u8_safe(credits)
    +		);
    +	}
    +	public Site_skin_itm Make_skin(String code, boolean dflt, String name, boolean unusable) {return new Site_skin_itm(Bry_.new_u8_safe(code), dflt, Bry_.new_u8_safe(name), unusable);}
    +	public Site_magicword_itm Make_magicword(String name, boolean case_match, String... aliases) {return new Site_magicword_itm(Bry_.new_u8_safe(name), case_match, Bry_.Ary(aliases));}
    +	public Site_showhook_itm Make_showhook(String name, String scribunto, String... subscribers) {return new Site_showhook_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(scribunto), Bry_.Ary(subscribers));}
    +	public Site_language_itm Make_language(String code, String name) {return new Site_language_itm(Bry_.new_u8_safe(code), Bry_.new_u8_safe(name));}
    +	public void Test_general(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.General_list().To_ary(Keyval.class));}
    +	public void Test_namespace(Site_namespace_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespace_itm[])site_meta.Namespace_list().To_ary(Site_namespace_itm.class));}
    +	public void Test_statistic(Site_statistic_itm expd) {Tfds.Eq_str_intf(expd, site_meta.Statistic_itm());}
    +	public void Test_interwikimap(Site_interwikimap_itm... expd) {Tfds.Eq_ary_str(expd, (Site_interwikimap_itm[])site_meta.Interwikimap_list().To_ary(Site_interwikimap_itm.class));}
    +	public void Test_namespacealias(Site_namespacealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespacealias_itm[])site_meta.Namespacealias_list().To_ary(Site_namespacealias_itm.class));}
    +	public void Test_specialpagealias(Site_specialpagealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_specialpagealias_itm[])site_meta.Specialpagealias_list().To_ary(Site_specialpagealias_itm.class));}
    +	public void Test_library(Site_library_itm... expd) {Tfds.Eq_ary_str(expd, (Site_library_itm[])site_meta.Library_list().To_ary(Site_library_itm.class));}
    +	public void Test_extension(Site_extension_itm... expd) {Tfds.Eq_ary_str(expd, (Site_extension_itm[])site_meta.Extension_list().To_ary(Site_extension_itm.class));}
    +	public void Test_skin(Site_skin_itm... expd) {Tfds.Eq_ary_str(expd, (Site_skin_itm[])site_meta.Skin_list().To_ary(Site_skin_itm.class));}
    +	public void Test_magicword(Site_magicword_itm... expd) {Tfds.Eq_ary_str(expd, (Site_magicword_itm[])site_meta.Magicword_list().To_ary(Site_magicword_itm.class));}
    +	public void Test_functionhook(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Functionhook_list().To_ary(byte[].class)));}
    +	public void Test_showhook(Site_showhook_itm... expd) {Tfds.Eq_ary_str(expd, (Site_showhook_itm[])site_meta.Showhook_list().To_ary(Site_showhook_itm.class));}
    +	public void Test_extensiontag(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Extensiontag_list().To_ary(byte[].class)));}
    +	public void Test_protocol(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Protocol_list().To_ary(byte[].class)));}
    +	public void Test_defaultoption(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.Defaultoption_list().To_ary(Keyval.class));}
    +	public void Test_language(Site_language_itm... expd) {Tfds.Eq_ary_str(expd, (Site_language_itm[])site_meta.Language_list().To_ary(Site_language_itm.class));}
    +}
    diff --git a/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java b/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java
    new file mode 100644
    index 000000000..b6eb98bdf
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_dumper_tst.java
    @@ -0,0 +1,100 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
    +import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
    +public class Xob_xml_dumper_tst {
    +	private final Xob_xml_dumper_fxt fxt = new Xob_xml_dumper_fxt();
    +	@Before public void init() {fxt.Clear();}
    +	@Test   public void Basic() {
    +		fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Tid__main, "A", "A_text")), String_.Concat_lines_nl_skip_last
    +		( ""
    +		, "  "
    +		, "    other"
    +		, "    "
    +		, "    Main_Page"
    +		, "    XOWA 2.5.2.2"
    +		, "    first-letter"
    +		, "  "
    +		, "  "
    +		, "    Media"
    +		, "    Special"
    +		, "    "
    +		, "    Talk"
    +		, "    User"
    +		, "    User_talk"
    +		, "    Wikipedia"
    +		, "    Wikipedia_talk"
    +		, "    File"
    +		, "    File_talk"
    +		, "    MediaWiki"
    +		, "    MediaWiki_talk"
    +		, "    Template"
    +		, "    Template_talk"
    +		, "    Help"
    +		, "    Help_talk"
    +		, "    Category"
    +		, "    Category_talk"
    +		, "    Portal"
    +		, "    Portal_talk"
    +		, "    Book"
    +		, "    Book_talk"
    +		, "    Module"
    +		, "    Module_talk"
    +		, "  "
    +		, "  "
    +		, "    A"
    +		, "    1"
    +		, "    "
    +		, "      -1"
    +		, "      -1"
    +		, "      0001-01-01 00:00:00"
    +		, "      "
    +		, "        "
    +		, "        -1"
    +		, "      "
    +		, "      "
    +		, "      wikitext"
    +		, "      text/x-wiki"
    +		, "      A_text"
    +		, "      "
    +		, "    "
    +		, "  "
    +		, ""
    +		));
    +	}
    +}
    +class Xob_xml_dumper_fxt {
    +	private Xowe_wiki wiki;
    +	private final Xob_xml_dumper export_wtr = new Xob_xml_dumper();
    +	public void Clear() {
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		this.wiki = Xoa_app_fxt.Make__wiki__edit(app, "enwiki");
    +	}
    +	public Xowd_page_itm[] Make_ary(Xowd_page_itm... ary) {return ary;}
    +	public Xowd_page_itm Make_page(int id, int ns_id, String ttl_str, String text) {
    +		Xoa_ttl ttl = wiki.Ttl_parse(ns_id, Bry_.new_u8(ttl_str));
    +		return new Xowd_page_itm().Id_(id).Ns_id_(ns_id).Ttl_(ttl).Text_(Bry_.new_u8(text));
    +	}
    +	public void Test_page(Xowd_page_itm[] ary, String expd) {
    +		export_wtr.Write_root_bgn(wiki.Ns_mgr(), wiki.Domain_itm(), "", String_.new_u8(wiki.Props().Main_page()), "first-letter", "XOWA 2.5.2.2");
    +		int len = ary.length;
    +		for (int i = 0; i < len; ++i)
    +			export_wtr.Write_page(ary[i]);
    +		export_wtr.Write_root_end();
    +		String actl = export_wtr.Bld_str();
    +		Tfds.Eq_str_lines(expd, actl);
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java b/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java
    new file mode 100644
    index 000000000..934889181
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/bldrs/xmls/Xob_xml_parser_tst.java
    @@ -0,0 +1,146 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
    +import org.junit.*; import gplx.core.ios.*; import gplx.core.times.*;
    +import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*;
    +public class Xob_xml_parser_tst {
    +	@Before public void init() {
    +		Io_mgr.Instance.InitEngine_mem();
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		bldr = new Xob_bldr(app);
    +	}	private Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
    +	@Test  public void Basic_docs_1() {
    +		Xowd_page_itm doc = doc_(1, "a", "a a", Date_1);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc, 0);
    +	}
    +	@Test  public void Basic_docs_2() {
    +		Xowd_page_itm doc1 = doc_(1, "a", "a a", Date_1);
    +		Xowd_page_itm doc2 = doc_(2, "b", "b b", Date_2);
    +		fil = page_bldr.Add_ary(doc1, doc2).XtoByteStreamRdr();
    +		int pos = tst_parse(fil, doc1, 0);
    +		tst_parse(fil, doc2, pos);
    +	}
    +	@Test  public void Basic_space() {
    +		Xowd_page_itm doc1 = doc_(1, "a_b", "abc", Date_1);
    +		fil = page_bldr.Add_ary(doc1).Upd("a_b", "a b").XtoByteStreamRdr();
    +		tst_parse(fil, doc1, 0);
    +	}
    +	@Test  public void Xml() {
    +		Xowd_page_itm doc = doc_(1, "a", ""a & b <> a | b"", Date_1);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc.Text_(Bry_.new_a7("\"a & b <> a | b\"")), 0);
    +	}
    +	@Test  public void Tab() {
    +		Xowd_page_itm doc = doc_(1, "a", "a \t b", Date_1);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc.Text_(Bry_.new_a7("a 	 b")), 0);
    +	}
    +	@Test  public void Tab_disable() {
    +		Xowd_page_itm doc = doc_(1, "a", "a \t b", Date_1);
    +		page_parser.Trie_tab_del_();
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc.Text_(Bry_.new_a7("a \t b")), 0);
    +	}
    +	@Test  public void Cr_nl() {
    +		Xowd_page_itm doc = doc_(1, "a", "a \r\n b", Date_1);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc.Text_(Bry_.new_a7("a \n b")), 0);
    +	}
    +	@Test  public void Cr() {
    +		Xowd_page_itm doc = doc_(1, "a", "a \r b", Date_1);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr();
    +		tst_parse(fil, doc.Text_(Bry_.new_a7("a \n b")), 0);
    +	}
    +	@Test  public void Text_long() {
    +		String s = String_.Repeat("a", 1024);
    +		Xowd_page_itm doc = doc_(1, "a", s, Date_1);
    +		page_parser.Tag_len_max_(32);
    +		fil = page_bldr.Add(doc).XtoByteStreamRdr(512);
    +		tst_parse(fil, doc, 0);
    +	}
    +	@Test  public void Text_empty() {
    +		Xowd_page_itm doc = doc_(1, "a", "", Date_1);
    +		fil = page_bldr.Add(doc).Upd("", "").XtoByteStreamRdr();
    +		tst_parse(fil, doc, 0);
    +	}
    +	@Test  public void Text_frag() {
    +		Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
    +		fil = page_bldr.Add(doc).Upd("a", "a").XtoByteStreamRdr();
    +		tst_parse(fil, doc, 0);
    +	}
    +	@Test  public void Ns_file() {
    +		Xowd_page_itm doc = doc_(1, "File:a", "a", Date_1);
    +		Tfds.Eq(Xow_ns_.Tid__file, doc.Ns_id());
    +		Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
    +	}
    +	@Test  public void Ns_main() {
    +		Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
    +		Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
    +		Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
    +	}
    +	@Test  public void Ns_main_book() {
    +		Xowd_page_itm doc = doc_(1, "Book", "a", Date_1);
    +		Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
    +		Tfds.Eq("Book", String_.new_u8(doc.Ttl_page_db()));
    +	}
    +	@Test  public void XmlEntities() {
    +		Xowd_page_itm orig = doc_(1, "A&b", "a", Date_1);
    +		Xowd_page_itm actl = new Xowd_page_itm();
    +		fil = page_bldr.Add(orig).XtoByteStreamRdr();
    +		page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), 0, ns_mgr);
    +		Tfds.Eq("A&b", String_.new_u8(actl.Ttl_full_db()));
    +	}
    +	@Test  public void Root() {
    +		Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
    +		page_bldr.Bfr().Add_str_a7("\n");
    +		page_bldr.Add(doc);
    +		page_bldr.Bfr().Add_str_a7("");
    +		fil = page_bldr.XtoByteStreamRdr();
    +		tst_parse(fil, doc, 0);
    +	}
    +	private static final    String Date_1 = "2012-01-01T01:01:01Z", Date_2 = "2012-02-02T02:02:02Z"; DateAdp_parser dateParser = DateAdp_parser.new_();
    +	Bry_bfr bfr = Bry_bfr_.New();
    +	Xob_xml_page_bldr page_bldr = new Xob_xml_page_bldr(); Io_buffer_rdr fil; Xob_xml_parser page_parser = new Xob_xml_parser(); Xob_bldr bldr;
    +	Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Test();
    +	int tst_parse(Io_buffer_rdr fil, Xowd_page_itm expd, int cur_pos) {
    +		Xowd_page_itm actl = new Xowd_page_itm();
    +		int rv = page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), cur_pos, ns_mgr);
    +		Tfds.Eq(expd.Id(), actl.Id(), "id");
    +		Tfds.Eq(String_.new_u8(expd.Ttl_full_db()), String_.new_u8(actl.Ttl_full_db()), "title");
    +		Tfds.Eq(String_.new_u8(expd.Text()), String_.new_u8(actl.Text()), "text");
    +		Tfds.Eq_date(expd.Modified_on(), actl.Modified_on(), "timestamp");
    +		return rv;
    +	}
    +	Xowd_page_itm doc_(int id, String title, String text, String date) {
    +		Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_a7(title), ns_mgr).Text_(Bry_.new_a7(text));
    +		int[] modified_on = new int[7];
    +		dateParser.Parse_iso8651_like(modified_on, date);
    +		rv.Modified_on_(DateAdp_.seg_(modified_on));
    +		return rv;
    +	}
    +}
    +class Xob_xml_parser_fxt {
    +//		private final    Xob_xml_parser page_parser = new Xob_xml_parser();
    +//		public void Test__parse(Io_buffer_rdr fil, Xowd_page_itm expd, int cur_pos) {
    +//			Xowd_page_itm actl = new Xowd_page_itm();
    +//			int rv = page_parser.Parse_page(actl, usr_dlg, fil, fil.Bfr(), cur_pos, ns_mgr);
    +//			Tfds.Eq(expd.Id(), actl.Id(), "id");
    +//			Tfds.Eq(String_.new_u8(expd.Ttl_full_db()), String_.new_u8(actl.Ttl_full_db()), "title");
    +//			Tfds.Eq(String_.new_u8(expd.Text()), String_.new_u8(actl.Text()), "text");
    +//			Tfds.Eq_date(expd.Modified_on(), actl.Modified_on(), "timestamp");
    +//		}
    +}
    diff --git a/400_xowa/src/gplx/xowa/drds/Xod_app_tst.java b/400_xowa/src/gplx/xowa/drds/Xod_app_tst.java
    new file mode 100644
    index 000000000..21b216e6b
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/drds/Xod_app_tst.java
    @@ -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.drds; import gplx.*; import gplx.xowa.*;
    +import org.junit.*; import gplx.xowa.drds.pages.*; import gplx.xowa.wikis.*; import gplx.xowa.htmls.sections.*;
    +public class Xod_app_tst {
    +	private final    Xod_app_tstr tstr = new Xod_app_tstr();
    +	@Before		public void init() {tstr.Init_mem();}
    +	// COMMENTED: broke from changes to auto-init wiki; DATE:2016-06-16
    +//		@Test  public void Get() {
    +//			tstr.Data_mgr().Page__insert(1, "A", "2015-10-19 00:01:02");
    +//			tstr.Data_mgr().Html__insert(1, "abc");
    +//			tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19T00:01:02Z", tstr.Make_section(0, 2, "", "", "abc")));
    +//		}
    +	@Test   public void To_page_db() {
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A"			, "A");
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A:B"		, "A:B");
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/Help:A"	, "Help:A");
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A B"		, "A_B");	// NOTE:canonical url has spaces;
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A%27B"		, "A'B");	// NOTE:canonical url has percent-encoding;
    +		tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A+B"		, "A_B");	// NOTE:canonical url sometimes has "+" for space
    +	}
    +}
    +class Xod_app_tstr {
    +	private final    gplx.xowa.apps.Xoav_app app; private final    Xowv_wiki wiki;
    +	private final    Xod_app drd_provider;
    +	public Xod_app_tstr() {
    +		this.app = Xoa_app_fxt.Make__app__view();
    +		this.wiki = Xoa_app_fxt.Make__wiki__view(app);
    +		data_mgr.Wiki_(wiki);
    +		Xoa_test_.Init__db__view(wiki);
    +		drd_provider = new Xod_app(app);
    +	}
    +	public Xowd_data_tstr Data_mgr() {return data_mgr;} private final    Xowd_data_tstr data_mgr = new Xowd_data_tstr();
    +	public void Init_mem() {
    +		Io_mgr.Instance.InitEngine_mem();
    +	}
    +	public void Test__get(String ttl, Xod_page_itm expd) {
    +		Xow_wiki wiki = drd_provider.Wikis__get_by_domain("en.wikipedia.org");
    +		Xoa_url page_url = wiki.Utl__url_parser().Parse(Bry_.new_u8(ttl));
    +		Xod_page_itm itm = drd_provider.Wiki__get_by_url(wiki, page_url);
    +		Tfds.Eq(expd.To_str(), itm.To_str());
    +	}
    +	public void Test__to_page_url(String raw, String expd) {
    +		// // canonical url has spaces as well as %-encoding; PAGE:en.w:List_of_Fire_Emblem:Shadow_Dragon_characters
    +		Tfds.Eq_bry(Bry_.new_u8(expd), Xod_app.To_page_url(wiki, raw));
    +	}
    +	public Xod_page_itm Make_page(int page_id, String ttl, String modified_on, Xoh_section_itm... section_ary) {
    +		Xod_page_itm rv = new Xod_page_itm();
    +		rv.Init(page_id, page_id, ttl, ttl, null, null, modified_on, Bool_.N, Bool_.N, Bool_.N, 1, null, null, null);
    +		int len = section_ary.length;
    +		for (int i = 0; i < len; ++i) {
    +			Xoh_section_itm itm = section_ary[i];
    +			rv.Section_list().Add(itm);
    +		}			
    +		return rv;
    +	}
    +	public Xoh_section_itm Make_section(int id, int level, String anchor, String heading, String content) {return new Xoh_section_itm(id, level, Bry_.new_u8(anchor), Bry_.new_u8(heading)).Content_(Bry_.new_u8(content));}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_file_fxt.java b/400_xowa/src/gplx/xowa/files/Xof_file_fxt.java
    new file mode 100644
    index 000000000..8631d1830
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_file_fxt.java
    @@ -0,0 +1,48 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
    +import gplx.dbs.*;
    +import gplx.xowa.files.origs.*; import gplx.xowa.files.repos.*;
    +public class Xof_file_fxt {
    +	private final    Xowe_wiki wiki;
    +	Xof_file_fxt(Xowe_wiki wiki) {
    +		this.wiki = wiki;
    +		Io_mgr.Instance.InitEngine_mem();
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		wiki.File_mgr().Version_2_y_();
    +	}
    +	public static Xof_file_fxt new_(Xowe_wiki wiki) {return new Xof_file_fxt(wiki);}
    +	public static Xof_file_fxt new_all(Xowe_wiki wiki) {return new Xof_file_fxt(wiki).Init_repos().Init_cache().Init_orig();}
    +	public Xof_file_fxt Init_repos() {
    +		Xow_repo_mgr_.Assert_repos(wiki.Appe(), wiki);
    +		return this;
    +	}
    +	public Xof_file_fxt Init_cache() {
    +		wiki.App().User().User_db_mgr().Init_by_app(Bool_.N, wiki.App().Fsys_mgr().Root_dir().GenSubFil_nest("user", "xowa.user.anonymous.sqlite3"));
    +		return this;
    +	}
    +	public Xof_file_fxt Init_orig() {
    +		Db_conn conn = Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/xowa/wiki/" + wiki.Domain_str() + "/orig.xowa")).Conn();
    +		Xof_orig_tbl orig_tbl = new Xof_orig_tbl(conn, Bool_.Y);
    +		orig_tbl.Create_tbl();
    +		wiki.File_mgr().Orig_mgr().Init_by_wiki(wiki, Xof_fsdb_mode.New__v2__gui(), new Xof_orig_tbl[] {orig_tbl}, Xof_url_bldr.new_v2());
    +		return this;
    +	}
    +	public void Exec_orig_add(boolean repo_is_commons, String orig_ttl, int orig_ext_id, int orig_w, int orig_h, String orig_redirect) {
    +		byte repo_tid = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
    +		wiki.File_mgr().Orig_mgr().Insert(repo_tid, Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h, Bry_.new_u8(orig_redirect));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_file_wkr__tst.java b/400_xowa/src/gplx/xowa/files/Xof_file_wkr__tst.java
    new file mode 100644
    index 000000000..81f7298b0
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_file_wkr__tst.java
    @@ -0,0 +1,31 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
    +import org.junit.*;
    +public class Xof_file_wkr__tst {		
    +	private final    Xof_file_wkr___fxt fxt = new Xof_file_wkr___fxt();
    +	@Test 	public void Ttl_standardize() {
    +		fxt.Test__ttl_standardize("Abc.png"		, "Abc.png");		// basic
    +		fxt.Test__ttl_standardize("A b.png"		, "A_b.png");		// spaces -> unders
    +		fxt.Test__ttl_standardize("A b c.png"	, "A_b_c.png");		// spaces -> unders; multiple
    +		fxt.Test__ttl_standardize("abc.png"		, "Abc.png");		// ucase 1st
    +	}
    +}
    +class Xof_file_wkr___fxt {
    +	public void Test__ttl_standardize(String src_str, String expd) {
    +		Tfds.Eq_bry(Bry_.new_u8(expd), Xof_file_wkr_.Ttl_standardize(Bry_.new_u8(src_str)));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_fsdb_itm_fxt.java b/400_xowa/src/gplx/xowa/files/Xof_fsdb_itm_fxt.java
    new file mode 100644
    index 000000000..88f7b3f4a
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_fsdb_itm_fxt.java
    @@ -0,0 +1,79 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
    +import gplx.xowa.wikis.domains.*;
    +import gplx.xowa.files.repos.*;
    +import gplx.xowa.parsers.lnkis.*;
    +public class Xof_fsdb_itm_fxt {
    +	private byte[] wiki_abrv;
    +	private byte[] lnki_ttl;
    +	private byte lnki_type;
    +	private double lnki_upright;
    +	private int lnki_w;
    +	private int lnki_h;
    +	private double lnki_time;
    +	private int lnki_page;
    +	private byte orig_repo_id;
    +	private byte[] orig_repo_name;
    +	private byte[] orig_ttl;
    +	private Xof_ext orig_ext;
    +	private int orig_w;
    +	private int orig_h;
    +	private byte[] orig_redirect;
    +	public Xof_fsdb_itm_fxt() {this.Clear();}
    +	public void Clear() {
    +		this.wiki_abrv = lnki_ttl = null;
    +		this.lnki_type = Xop_lnki_type.Id_null;
    +		this.lnki_upright = Xof_img_size.Upright_null;
    +		this.lnki_w = this.lnki_h = this.orig_w = this.orig_h = Xof_img_size.Size__neg1;
    +		this.lnki_h = Xof_img_size.Size__neg1;
    +		this.lnki_time = Xof_lnki_time.Null;
    +		this.lnki_page = Xof_lnki_page.Null;
    +		this.orig_repo_id = Xof_repo_tid_.Tid__null;
    +		this.orig_repo_name = orig_ttl = orig_redirect = null;
    +		this.orig_ext = null;
    +	}
    +	public Xof_fsdb_itm_fxt Lnki__en_w(String lnki_ttl_str) {
    +		this.wiki_abrv = Abrv__en_w;
    +		this.lnki_ttl = Bry_.new_u8(lnki_ttl_str);
    +		return this;
    +	}
    +	public Xof_fsdb_itm_fxt Orig__commons__lnki() {
    +		this.orig_repo_name = Xow_domain_itm_.Bry__commons;
    +		this.orig_repo_id = Xof_repo_tid_.Tid__remote;
    +		this.orig_ttl = lnki_ttl;
    +		this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
    +		this.orig_w = 880;
    +		this.orig_w = 440;
    +		return this;
    +	}
    +	public Xof_fsdb_itm_fxt Orig__enwiki__lnki() {
    +		this.orig_repo_name = Xow_domain_itm_.Bry__enwiki;
    +		this.orig_repo_id = Xof_repo_tid_.Tid__local;
    +		this.orig_ttl = lnki_ttl;
    +		this.orig_ext = Xof_ext_.new_by_ttl_(orig_ttl);
    +		this.orig_w = 880;
    +		this.orig_w = 440;
    +		return this;
    +	}
    +	public Xof_fsdb_itm Make() {
    +		Xof_fsdb_itm rv = new Xof_fsdb_itm();
    +		rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_abrv, lnki_ttl, lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, Xof_patch_upright_tid_.Tid_all); 
    +		rv.Init_at_orig(orig_repo_id, orig_repo_name, orig_ttl, orig_ext, orig_w, orig_h, orig_redirect);
    +		return rv;
    +	}
    +	private final    static byte[] Abrv__en_w = Bry_.new_a7("en.w");
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_img_size_tst.java b/400_xowa/src/gplx/xowa/files/Xof_img_size_tst.java
    new file mode 100644
    index 000000000..dd2f33698
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_img_size_tst.java
    @@ -0,0 +1,105 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
    +import org.junit.*; import gplx.core.bits.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_img_size_tst {
    +	private final Xof_img_size_fxt fxt = new Xof_img_size_fxt();
    +	@Before public void init() {
    +		fxt.Reset();
    +		fxt.Orig_(400, 200);
    +	}
    +	@Test  	public void Lnki_lt_orig_null() 		{fxt.Lnki_type_(Xop_lnki_type.Id_null)		.Lnki_(200, 100).Test_html(200, 100, Bool_.N);}	// [[File:A.png|200px]]           -> 200,100; File_is_orig = n
    +	@Test  	public void Lnki_lt_orig_thumb() 		{fxt.Lnki_type_(Xop_lnki_type.Id_thumb)		.Lnki_(200, 100).Test_html(200, 100, Bool_.N);}	// [[File:A.png|thumb|200px]]     -> 200,100; File_is_orig = n
    +	@Test  	public void Lnki_lt_orig_frameless() 	{fxt.Lnki_type_(Xop_lnki_type.Id_frameless)	.Lnki_(200, 100).Test_html(200, 100, Bool_.N);}	// [[File:A.png|frameless|200px]] -> 200,100; File_is_orig = n
    +	@Test  	public void Lnki_lt_orig_frame() 		{fxt.Lnki_type_(Xop_lnki_type.Id_frame)		.Lnki_(200,  -1).Test_html(400, 200, Bool_.Y);}	// [[File:A.png|frame|200px]]     -> 400,200; File_is_orig = y; frame always ignores parameters and returns orig
    +	@Test  	public void Lnki_gt_orig_null() 		{fxt.Lnki_type_(Xop_lnki_type.Id_null)		.Lnki_(800, 400).Test_html(800, 400, Bool_.Y);}	// [[File:A.png|800px]]           -> 800,400; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_thumb() 		{fxt.Lnki_type_(Xop_lnki_type.Id_thumb)		.Lnki_(800, 400).Test_html(400, 200, Bool_.Y);}	// [[File:A.png|thumb|800px]]     -> 400,200; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_frameless() 	{fxt.Lnki_type_(Xop_lnki_type.Id_frameless)	.Lnki_(800, 400).Test_html(400, 200, Bool_.Y);}	// [[File:A.png|frameless|800px]] -> 400,200; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_frame() 		{fxt.Lnki_type_(Xop_lnki_type.Id_frame)		.Lnki_(800,  -1).Test_html(400, 200, Bool_.Y);}	// [[File:A.png|frame|800px]]     -> 400,200; File_is_orig = y; frame always ignores parameters and returns orig
    +	@Test  	public void Lnki_eq_orig_null() 		{fxt.Lnki_type_(Xop_lnki_type.Id_null)		.Lnki_(400, 200).Test_html(400, 200, Bool_.Y);}	// make sure File_is_orig = y
    +	@Test  	public void Lnki_gt_orig_null_svg() 	{fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null)		.Lnki_(800, 400).Test_html(800, 400, Bool_.N);}	// [[File:A.svg|800px]]           -> 800,400; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_thumb_svg() 	{fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_thumb)		.Lnki_(800, 400).Test_html(800, 400, Bool_.N);}	// [[File:A.svg|thumb|800px]]     -> 800,400; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_frameless_svg(){fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_frameless)	.Lnki_(800, 400).Test_html(800, 400, Bool_.N);}	// [[File:A.svg|frameless|800px]] -> 800,400; File_is_orig = n
    +	@Test  	public void Lnki_gt_orig_frame_svg() 	{fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_frame)		.Lnki_(800,  -1).Test_html(400, 200, Bool_.N);}	// [[File:A.svg|frame|800px]]     -> 400,200; File_is_orig = n; frame always ignores parameters and returns orig
    +	@Test   public void Width_missing()				{fxt.Lnki_( -1, 100).Test_html(200, 100);}	// calc width based on height and orig
    +	@Test   public void Height_missing()			{fxt.Lnki_(200,  -1).Test_html(200, 100);}
    +	@Test  	public void Orig_missing() 				{fxt.Lnki_(400, 200).Orig_( -1,  -1).Test_html(400, 200);}	// no orig_size; use lnki_w and lnki_h
    +	@Test  	public void Lnki_missing() 				{fxt.Lnki_( -1,  -1).Test_html(220, 110);}					// w=thumbnail default; h=calc from orig
    +	@Test   public void Lnki_missing_frameless()    {fxt.Lnki_( -1,  -1).Lnki_type_(Xop_lnki_type.Id_frameless) .Test_html(220, 110, Bool_.N);}	// default to thumb width
    +	@Test   public void Lnki_missing_null()         {fxt.Lnki_( -1,  -1).Lnki_type_(Xop_lnki_type.Id_null)		.Test_html(400, 200, Bool_.Y);}	// default to orig width
    +	@Test  	public void Lnki_missing__orig_missing(){fxt.Lnki_( -1,  -1).Orig_( -1,  -1).Test_html(220,  -1);}	// no lnki or orig size; default to 220 with unknown height
    +	@Test   public void Prefer_height_over_width()	{fxt.Lnki_(200, 100).Test_html(200, 100);}					// prefer height; if width were preferred, size would be 200,134
    +	@Test  	public void Upright() 					{fxt.Lnki_upright_(1).Lnki_(-1, -1).Orig_(440, 400).Test_html(220, 200);}	
    +	@Test  	public void Upright_w_thumb() 			{fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_upright_(2).Lnki_(-1, -1).Orig_(1500, 1125).Test_html(440, 330);}
    +	@Test  	public void Upright_ignored_by_w() 		{fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_upright_(3.2).Lnki_(900, -1).Orig_(4653, 854).Test_html(900, 165);}// PAGE: fr.w:Bogota; DATE:2014-05-22
    +	@Test   public void Explicit_ratio_large()		{fxt.Lnki_(120,  40).Test_html( 80,  40);}	// see NOTE_2: lnki_ratio > orig_ratio
    +	@Test   public void Explicit_ratio_small()		{fxt.Lnki_(120,  80).Test_html(120,  60);}	// see NOTE_2: lnki_ratio > orig_ratio
    +	@Test   public void Lnki_gt_orig_null_svg_example() {	// EX:[[File:Crystal Clear app kedit.svg|50x40px]]
    +		fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null).Lnki_( 50,  40).Orig_( 40,  40).Test_html( 40,  40);
    +	}	
    +	@Test   public void Prefer_height_over_width_example() {// EX:[[File:Firma B.Ohiggins.svg|128x80px|alt=|Bernardo O'Higgins's signature]]
    +		fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_type_(Xop_lnki_type.Id_null).Lnki_(128,  80).Orig_(720, 194).Test_html(128,  34);
    +	}	
    +	@Test   public void Lnki_gt_orig_thumb_example() {// EX:[[File:Adhanema Lasva.jpg|thumb|300px|The Firman given to the Bosnian Franciscans]]
    +		fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_(300,  -1).Orig_(149, 408).Test_html(149, 408, Bool_.Y);
    +	}
    +	@Test  	public void Upright_and_null_width_fails() {// PURPOSE: if width = -1, but upright is specified, ignore upright (was calculating 0 for width); DATE:2013-11-23
    +		fxt.Lnki_type_(Xop_lnki_type.Id_null).Lnki_(-1, 110).Orig_(440, 220).Lnki_upright_(.50f).Test_html(220, 110, Bool_.N);
    +	}
    +	@Test  	public void Svg_null_width() {	// PURPOSE: if svg and only height is specified, default width to 2048 (and recalc); DATE: 2013-11-26
    +		fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_(-1, 40).Orig_(1, 1).Test_html(40, 40, Bool_.N);	// NOTE: used to be 1,1
    +	}
    +	@Test  	public void Svg_max_width() {	// PURPOSE: large width causes int overflow; vi.w:Danh_sách_quốc_kỳ DATE:2014-04-26
    +		fxt.Lnki_ext_(Xof_ext_.Id_svg).Lnki_(Int_.Max_value, 90).Orig_(900, 600).Test_html(135, 90, Bool_.N);	// NOTE: used to be Int_.Max_value,90
    +	}
    +	@Test  	public void Pdf_none_defaults_to_thumb() {	// PURPOSE: if no width is specified, pdf uses thumb width default, not orig width); DATE: 2013-11-27
    +		fxt.Lnki_type_(Xop_lnki_type.Id_none).Lnki_ext_(Xof_ext_.Id_pdf).Lnki_(-1, -1).Orig_(440, 220).Test_html(220, 110, Bool_.N);	// NOTE: used to be 1,1
    +	}
    +	@Test  	public void Frame() {	// PURPOSE: frame incorrectly defaulted to file_is_orig; [[File:MESSENGER.jpg|200x200px|framed]]; DATE:2013-12-22
    +		fxt.Lnki_type_(Xop_lnki_type.Id_frame).Lnki_ext_(Xof_ext_.Id_png).Lnki_(200, 200).Orig_(2038, 1529).Test_html(200, 150, Bool_.N);
    +	}
    +	@Test  	public void Frame_and_thumb(){ // PURPOSE: frame and thumb should be treated as frame; Enm.Has(val, Id_frame) vs val == Id_frame; PAGE:en.w:History_of_Western_Civilization; DATE:2015-04-16
    +		fxt.Lnki_type_(Bitmask_.Add_byte(Xop_lnki_type.Id_frame, Xop_lnki_type.Id_thumb)).Lnki_(200,  -1).Test_html(400, 200, Bool_.Y);	// mut return same as Lnki_lt_orig_frame above
    +	}
    +	@Test  	public void Video__use_orig_w(){ // PURPOSE: video should use orig_w; DATE:2015-08-07
    +		fxt.Lnki_type_(Xop_lnki_type.Id_none).Lnki_ext_(Xof_ext_.Id_ogv).Lnki_(-1,  -1).Orig_(500, 250).Test_html(500, 250, Bool_.N);
    +	}
    +	@Test  	public void Video__use_thumb(){ // PURPOSE: video should use thumb_w, not orig_w; PAGE:en.w:Edward_Snowden DATE:2015-08-17
    +		fxt.Lnki_type_(Xop_lnki_type.Id_thumb).Lnki_ext_(Xof_ext_.Id_ogv).Lnki_(-1,  -1).Orig_(440, 220).Test_html(220, 110, Bool_.N);
    +	}
    +}
    +class Xof_img_size_fxt {
    +	private Xof_img_size img_size = new Xof_img_size();
    +	public Xof_img_size_fxt Reset() {
    +		lnki_type = Xop_lnki_type.Id_thumb;
    +		lnki_ext = Xof_ext_.Id_jpg;
    +		lnki_upright = Xof_img_size.Upright_null;
    +		orig_w = orig_h = lnki_w = lnki_h = Xof_img_size.Null;
    +		return this;
    +	}
    +	public Xof_img_size_fxt Lnki_type_(byte v) {lnki_type = v; return this;} private byte lnki_type;
    +	public Xof_img_size_fxt Lnki_ext_(int v) {lnki_ext = v; return this;} private int lnki_ext;
    +	public Xof_img_size_fxt Lnki_upright_(double v) {lnki_upright = v; return this;} private double lnki_upright;
    +	public Xof_img_size_fxt Orig_(int w, int h) {orig_w = w; orig_h = h; return this;} private int orig_w, orig_h;
    +	public Xof_img_size_fxt Lnki_(int w, int h) {lnki_w = w; lnki_h = h; return this;} private int lnki_w, lnki_h;
    +	public void Test_html(int expd_w, int expd_h) {Test_html(expd_w, expd_h, false);}
    +	public void Test_html(int expd_html_w, int expd_html_h, boolean expd_file_is_orig) {
    +		img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki_w, lnki_h, lnki_type, Xof_patch_upright_tid_.Tid_all, lnki_upright, lnki_ext, orig_w, orig_h, Xof_img_size.Thumb_width_img);
    +		Tfds.Eq(expd_html_w, img_size.Html_w(), "html_w");
    +		Tfds.Eq(expd_html_h, img_size.Html_h(), "html_h");
    +		Tfds.Eq(expd_file_is_orig, img_size.File_is_orig(), "file_is_orig");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_url_bldr__tst.java b/400_xowa/src/gplx/xowa/files/Xof_url_bldr__tst.java
    new file mode 100644
    index 000000000..7e3e2e9ba
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_url_bldr__tst.java
    @@ -0,0 +1,65 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files; import gplx.*; import gplx.xowa.*;
    +import org.junit.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*;
    +public class Xof_url_bldr__tst {
    +	private Xof_url_bldr__fxt fxt = new Xof_url_bldr__fxt();
    +	@Before public void init() {fxt.Clear().Dir_spr_http_();}
    +	@Test 	public void Ogv() 			{fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px--A.ogv.jpg").Test();}
    +	@Test 	public void Ogv__seek() 	{fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_(220).Expd_src_("http://test/thumb/d/d0/A.ogv/220px-seek%3D5-A.ogv.jpg").Seek_(5).Test();}
    +	@Test 	public void Ogv__no_w() 	{fxt.Root_("http://test/").Md5_("d0").Ttl_("A.ogv").W_( -1).Expd_src_("http://test/thumb/d/d0/A.ogv/-1px--A.ogv.jpg").Test();}	// TODO_OLD: use orig_w, not -1
    +	@Test 	public void Xcf() 			{fxt.Root_("http://test/").Md5_("44").Ttl_("A.xcf").W_(220).Expd_src_("http://test/thumb/4/44/A.xcf/220px-A.xcf.png").Test();}
    +	@Test 	public void Bmp() 			{fxt.Root_("http://test/").Md5_("70").Ttl_("A.bmp").W_(220).Expd_src_("http://test/thumb/7/70/A.bmp/220px-A.bmp.png").Test();}
    +	@Test 	public void Pdf() 			{fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg").Test();}
    +	@Test 	public void Pdf__page_2() 	{fxt.Root_("http://test/").Md5_("ef").Ttl_("A.pdf").W_(220).Expd_src_("http://test/thumb/e/ef/A.pdf/page2-220px-A.pdf.jpg").Page_(2).Test();}
    +	@Test 	public void Long() {
    +		String filename = String_.Repeat("A", 200) + ".png";
    +		fxt.Root_("http://test/").Md5_("14").Ttl_(filename).W_(220)
    +			.Expd_src_("http://test/thumb/1/14/" + filename + "/220px-thumbnail.png")
    +			.Test()
    +			;
    +	}
    +	@Test 	public void Math__http() 	{fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.N).Root_("http://test/").Ttl_("random_md5.svg").Expd_src_("http://test/random_md5").Test();}	// NOTE: strip ".svg" if online
    +	@Test 	public void Math__file() 	{fxt.Repo_tid_(Xof_repo_tid_.Tid__math).Fsys_is_wnt_(Bool_.Y).Root_("file://xowa/").Ttl_("random_md5.svg").Expd_src_("file://xowa/random_md5.svg").Test();}	// NOTE: keep ".svg" if online
    +}
    +class Xof_url_bldr__fxt {
    +	private final    Xof_url_bldr url_bldr = new Xof_url_bldr();
    +	public Xof_url_bldr__fxt Clear() {
    +		dir_spr = Byte_.Zero; ext = null; root = md5 = ttl = expd_src = null;
    +		seek = Xof_lnki_time.Null;
    +		page = Xof_lnki_page.Null;
    +		w = Xof_img_size.Null;
    +		return this;
    +	}
    +	public Xof_url_bldr__fxt Dir_spr_http_() {return Dir_spr_(Byte_ascii.Slash);}
    +	public Xof_url_bldr__fxt Dir_spr_fsys_wnt_() {return Dir_spr_(Byte_ascii.Backslash);}
    +	public Xof_url_bldr__fxt Dir_spr_(byte v) {dir_spr = v; return this;} private byte dir_spr;
    +	public Xof_url_bldr__fxt Root_(String v) {root = v; return this;} private String root;
    +	public Xof_url_bldr__fxt Md5_(String v) {md5 = v; return this;} private String md5;
    +	public Xof_url_bldr__fxt Ttl_(String v) {ttl = v; ext = Xof_ext_.new_by_ttl_(Bry_.new_u8(v)); return this;} private String ttl; Xof_ext ext;
    +	public Xof_url_bldr__fxt W_(int v) {this.w = v; return this;} private int w;
    +	public Xof_url_bldr__fxt Page_(int v) {page = v; return this;} private int page = Xof_lnki_page.Null;
    +	public Xof_url_bldr__fxt Seek_(int v) {seek = v; return this;} private double seek = Xof_lnki_time.Null;
    +	public Xof_url_bldr__fxt Repo_tid_(byte v) {repo_tid = v; return this;} private byte repo_tid = Xof_repo_tid_.Tid__null;
    +	public Xof_url_bldr__fxt Fsys_is_wnt_(boolean v) {fsys_is_wnt = v; return this;} private boolean fsys_is_wnt;
    +	public Xof_url_bldr__fxt Expd_src_(String v) {expd_src = v; return this;} private String expd_src;
    +	public Xof_url_bldr__fxt Test() {
    +		url_bldr.Init_by_repo(repo_tid, Bry_.new_u8(root), fsys_is_wnt, dir_spr, Bool_.Y, Bool_.N, 2);
    +		url_bldr.Init_by_itm (Xof_img_mode_.Tid__thumb, Bry_.new_u8(ttl), Bry_.new_u8_safe(md5), ext, w, seek, page);
    +		Tfds.Eq(expd_src, url_bldr.Xto_str());
    +		return this;
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xof_xfer_itm_tst.java b/400_xowa/src/gplx/xowa/files/Xof_xfer_itm_tst.java
    new file mode 100644
    index 000000000..7ca2f74ee
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xof_xfer_itm_tst.java
    @@ -0,0 +1,63 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
    +import org.junit.*; import gplx.core.primitives.*; import gplx.gfui.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_xfer_itm_tst {		
    +	@Before public void init() {fxt.ini();} Xof_xfer_itm_fxt fxt = new Xof_xfer_itm_fxt();
    +	@Test  public void Box()						{tst_Calc_view("40,50"	, "40,40"	, "40,40");}	// EX:[[File:Crystal Clear app kedit.svg|50x40px]]
    +	@Test  public void Long_w()						{tst_Calc_view("128,80"	, "720,194"	, "128,34");}	// EX:[[File:Firma B.Ohiggins.svg|128x80px|alt=|Bernardo O'Higgins's signature]]
    +	@Test  public void Long_h()						{tst_Calc_view("300,-1"	, "149,408"	, "149,408");}	// EX:[[File:Adhanema Lasva.jpg|thumb|300px|The Firman given to the Bosnian Franciscans]]
    +	@Test  public void Width_too_long()				{tst_Calc_view("100,-1"	, "40,40"	, "40,40");}	// limit to height;
    +	@Test  public void Width_missing()				{tst_Calc_view("-1,20"	, "80,40"	, "40,20");}	// calc width based on height and file_size
    +	@Test  public void Prefer_height_over_width()	{tst_Calc_view("60,20"	, "120,60"	, "40,20");}	// prefer height; if width was preferred, size would be 60,30
    +	@Test  public void Height_missing()				{tst_Calc_view("50,-1"	, "100,200"	, "50,100");}
    +	@Test  public void Explicit_ratio_large()		{tst_Calc_view("120,40"	, "200,100"	, "80,40");}		// see NOTE_1:view ratio > file ratio
    +	@Test  public void Explicit_ratio_small()		{tst_Calc_view("120,80"	, "200,100"	, "120,60");}		// see NOTE_1:view ratio > file ratio
    +	private void tst_Calc_view(String lnki_str, String file_str, String expd_str) {
    +		Int_2_ref rv = new Int_2_ref();
    +		Int_2_val lnki = Int_2_val.parse(lnki_str);
    +		Int_2_val file = Int_2_val.parse(file_str);
    +		Int_2_val expd = Int_2_val.parse(expd_str);
    +		Xof_xfer_itm_.Calc_view(rv, Xop_lnki_type.Id_thumb, lnki.Val_0(), lnki.Val_1(), file.Val_0(), file.Val_1(), true);
    +		Tfds.Eq(expd.Val_0(), rv.Val_0());
    +		Tfds.Eq(expd.Val_1(), rv.Val_1());
    +	}
    +	@Test 	public void Thumb_lnkY() 						{fxt.Lnki_(300, 200).tst(300, 200);}							// size provided; use
    +	@Test 	public void Thumb_lnkN() 						{fxt.Lnki_( -1,  -1).tst(220,  -1);}							// w=thumbnail default
    +	@Test 	public void Thumb_lnkN_sqlY() 					{fxt.Lnki_( -1,  -1).File_(220, 200).tst(220, 200);}			// w=thumbnail default; h=calc from sql
    +	@Test 	public void Thumb_lnkN_sqlY_adjH() 				{fxt.Lnki_( -1,  -1).File_(440, 500).tst(220, 250);}			// w=thumbnail default; h=calc from sql
    +	@Test 	public void Thumb_lnkW_sqlY() 					{fxt.Lnki_(200,  -1).File_(400, 500).tst(200, 250);}			// w=lnki; h=calc from sql
    +	@Test 	public void Thumb_lnkH_sqlY() 					{fxt.Lnki_( -1, 250).File_(400, 500).tst(200, 250);}			// w=calc from sql
    +	@Test 	public void Thumb_lnkW_sqlY_W_too_large() 		{fxt.Lnki_(600, 750).File_(400, 500).tst(400, 500);}			// w/h: truncate to file
    +	@Test 	public void Thumb_w_is_wrong() 					{fxt.Lnki_( 20,  20).File_( 80, 100).tst( 16,  20);}
    +	@Test 	public void Thumb_w_is_wrong_2() 				{fxt.Lnki_( 65,  50).File_(160, 160).tst( 50,  50);}
    +	@Test 	public void Thumb_size_is_wrong() 				{fxt.Lnki_(128,  80).File_(720, 194).tst(128,  34);}
    +}
    +class Xof_xfer_itm_fxt {
    +	public Xof_xfer_itm_fxt ini() {lnki_img_type = Xop_lnki_type.Id_thumb; lnki_upright = -1; file_w = file_h = lnki_w = lnki_h = -1; return this;}
    +	public Xof_xfer_itm_fxt Lnki_img_type_(byte v) {lnki_img_type = v; return this;} private byte lnki_img_type;
    +	public Xof_xfer_itm_fxt Lnki_upright_(double v) {lnki_upright = v; return this;} double lnki_upright;
    +	public Xof_xfer_itm_fxt File_(int w, int h) {file_w = w; file_h = h; return this;} private int file_w, file_h;
    +	public Xof_xfer_itm_fxt Lnki_(int w, int h) {lnki_w = w; lnki_h = h; return this;} private int lnki_w, lnki_h;
    +	public Xof_xfer_itm_fxt tst(int expd_w, int expd_h) {
    +		boolean wmf_thumbable = Xof_xfer_itm_.Lnki_thumbable_calc(lnki_img_type, lnki_w, lnki_h);
    +		Int_2_ref calc_size = new Int_2_ref();
    +		Xof_xfer_itm_.Calc_xfer_size(calc_size, Xop_lnki_type.Id_thumb, Xof_img_size.Thumb_width_img, file_w, file_h, lnki_w, lnki_h, wmf_thumbable, lnki_upright);
    +		Tfds.Eq(expd_w, calc_size.Val_0());
    +		Tfds.Eq(expd_h, calc_size.Val_1());
    +		return this;
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/Xofv_file_mgr_tst.java b/400_xowa/src/gplx/xowa/files/Xofv_file_mgr_tst.java
    new file mode 100644
    index 000000000..05c6b992a
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/Xofv_file_mgr_tst.java
    @@ -0,0 +1,184 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files; import gplx.*; import gplx.xowa.*;
    +import org.junit.*; import gplx.core.primitives.*; import gplx.dbs.*;
    +import gplx.xowa.files.fsdb.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*;
    +import gplx.xowa.apps.*; import gplx.xowa.wikis.*; import gplx.xowa.files.origs.*;
    +public class Xofv_file_mgr_tst {
    +//		@Before public void init() {fxt.Clear();} private final Xofv_file_mgr_fxt fxt = new Xofv_file_mgr_fxt();
    +	@After  public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
    +	@Test  public void Stub() {}
    +//		@Test   public void Thumb() {
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
    +//				.Exec_process_lnki()
    +//				.Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/220px.png", 220, 200))
    +//				.Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/220px.png")
    +//				.Test_fsdb_download(1);
    +//				;
    +//		}
    +//		@Test   public void Orig() {
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_orig("A.png", 440, 400))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_none(0, "A.png"))
    +//				.Exec_process_lnki()
    +//				.Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/orig/7/0/A.png", 440, 400))
    +//				.Test_fsys_get("mem/xowa/file/comm/orig/7/0/A.png")
    +//				.Test_fsdb_download(1);
    +//				;
    +//		}
    +//		@Test   public void Img_size() {	// PURPOSE: test integration of Xof_img_size
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 110, 100))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", Xof_img_size.Null, Xof_img_size.Null).Upright_(.5f))
    +//				.Exec_process_lnki()
    +//				.Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/110px.png", 110, 100))
    +//				.Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/110px.png")
    +//				.Test_fsdb_download(1);
    +//				;
    +//		}
    +//		@Test   public void Orig_mgr() {	// PURPOSE: test integration of Orig_mgr
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm_redirect("B.jpg", "A.png", 440, 400))	// B.jpg redirects to A.png
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "B.jpg", 220, 200))
    +//				.Exec_process_lnki()
    +//				.Test_html_get(fxt.Mkr_html().Init(0, "file:///mem/xowa/file/comm/thumb/7/0/A.png/220px.png", 220, 200))
    +//				.Test_fsys_get("mem/xowa/file/comm/thumb/7/0/A.png/220px.png")
    +//				.Test_fsdb_download(1);
    +//				;
    +//		}
    +//		@Test   public void Cache_exists() {
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
    +//				.Init_cache_add(fxt.Mkr_cache().Init("comm", "A.png", Bool_.N, 220))	// add to cache
    +//				.Init_fsys_add("mem/xowa/file/comm/thumb/7/0/A.png/220px.png")			// copy file to fsys
    +//				.Exec_process_lnki()
    +//				.Test_fsdb_download(0)	// skip download
    +//				;
    +//		}
    +//		@Test   public void Cache_absent() {
    +//			fxt	.Init_orig_add(fxt.Mkr_orig().Init_comm("A.png", 440, 400))
    +//				.Init_fsdb_add(fxt.Mkr_fsdb().Init_comm_thum("A.png", 220, 200))
    +//				.Init_xfer_add(fxt.Mkr_xfer().Init_thumb(0, "A.png", 220, 200))
    +//				.Init_cache_add(fxt.Mkr_cache().Init("commons", "A.png", Bool_.N, 220))	// add to cache
    +//				.Exec_process_lnki()
    +//				.Test_fsdb_download(1)	// do download
    +//				;
    +//		}
    +}
    +//	class Xofv_file_mgr_fxt {
    +//		private Xofv_file_mgr file_mgr;
    +//		public Xof_xfer_mkr Mkr_xfer() {return mkr_xfer;} private final Xof_xfer_mkr mkr_xfer = new Xof_xfer_mkr();
    +//		public Xof_orig_itm_mkr Mkr_orig() {return mkr_orig;} private final Xof_orig_itm_mkr mkr_orig = new Xof_orig_itm_mkr();
    +//		public Xof_fsdb_mkr Mkr_fsdb() {return mkr_fsdb;} private final Xof_fsdb_mkr mkr_fsdb = new Xof_fsdb_mkr();		
    +//		public Xou_cache_itm_mkr Mkr_cache() {return mkr_cache;} private final Xou_cache_itm_mkr mkr_cache = new Xou_cache_itm_mkr();
    +//		public void Clear() {
    +//			file_mgr = new Xofv_file_mgr(Bry_.Empty);
    +//			Clear_repos();
    +//		}
    +//		private void Clear_repos() {
    +//			Xofv_repo_mgr repo_mgr = file_mgr.Repo_mgr();
    +//			Io_url root_dir = Io_url_.mem_dir_("mem/xowa/file/");
    +//			Xofv_repo_itm repo_comm = Xofv_repo_itm.new_trg_fsys(Xofv_repo_itm.Tid_val_comm, Bry_.new_a7("comm"), root_dir.GenSubDir("comm"));
    +//			Xofv_repo_itm repo_wiki = Xofv_repo_itm.new_trg_fsys(Xofv_repo_itm.Tid_val_wiki, Bry_.new_a7("wiki"), root_dir.GenSubDir("wiki"));
    +//			repo_mgr.Add(repo_comm).Add(repo_wiki);
    +//			mkr_orig.Setup_repos(repo_comm, repo_wiki);
    +//			mkr_fsdb.Setup_repos(Bry_.new_a7("comm"), Bry_.new_a7("wiki"));
    +//		}
    +//		public Xofv_file_mgr_fxt Init_xfer_add(Xof_xfer_mkr mkr)	{file_mgr.Reg(mkr.Make()); return this;}
    +//		public Xofv_file_mgr_fxt Init_cache_add(Xou_cache_itm_mkr mkr)	{mkr.Make(file_mgr.Cache_mgr()); return this;}
    +//		public Xofv_file_mgr_fxt Init_fsys_add(String s) {Io_mgr.Instance.SaveFilStr(s, ""); return this;}
    +//		public Xofv_file_mgr_fxt Exec_process_lnki() {file_mgr.Process_lnki(); return this;}
    +//		public Xofv_file_mgr_fxt Test_fsys_get(String path) {
    +//			Tfds.Eq_true(Io_mgr.Instance.ExistsFil(Io_url_.mem_fil_(path)), "fsys: " + path);
    +//			return this;
    +//		}
    +//	}
    +class Xof_orig_itm_mkr {
    +	private byte[] ttl_bry; private int ext, orig_w, orig_h; private Xofv_repo_itm repo;
    +	private byte[] redirect_bry;
    +	private Xofv_repo_itm repo_comm, repo_wiki;
    +	public Xof_orig_itm_mkr() {this.Reset();}
    +	private void Reset() {
    +		redirect_bry = Bry_.Empty;
    +	}
    +	public void Setup_repos(Xofv_repo_itm repo_comm, Xofv_repo_itm repo_wiki) {this.repo_comm = repo_comm; this.repo_wiki = repo_wiki;}
    +	public Xof_orig_itm_mkr Init_comm_redirect(String src, String trg, int orig_w, int orig_h) {return Init(Bool_.Y, src, trg, orig_w, orig_h);}
    +	public Xof_orig_itm_mkr Init_comm(String ttl_str, int orig_w, int orig_h) {return Init(Bool_.Y, ttl_str, null, orig_w, orig_h);}
    +	public Xof_orig_itm_mkr Init_wiki(String ttl_str, int orig_w, int orig_h) {return Init(Bool_.N, ttl_str, null, orig_w, orig_h);}
    +	private Xof_orig_itm_mkr Init(boolean repo_is_comm, String ttl_str, String redirect_str, int orig_w, int orig_h) {
    +		repo = repo_is_comm ? repo_comm : repo_wiki;
    +		this.ttl_bry = Bry_.new_u8(ttl_str); this.orig_w = orig_w; this.orig_h = orig_h;
    +		this.redirect_bry = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
    +		this.ext = Xof_ext_.new_by_ttl_(ttl_bry).Id();
    +		return this;
    +	}
    +	public void Make(Xof_orig_wkr wkr) {
    +		wkr.Add_orig(repo.Tid(), ttl_bry, ext, orig_w, orig_h, redirect_bry);
    +		this.Reset();
    +	}
    +}
    +class Xof_fsdb_mkr {
    +	private byte[] repo_comm, repo_wiki, repo;
    +	private byte[] ttl_bry; private byte lnki_type; private int file_w, file_h;
    +	private double upright, time; private int page;
    +	public Xof_fsdb_mkr() {this.Reset();}
    +	public void Setup_repos(byte[] repo_comm, byte[] repo_wiki) {this.repo_comm = repo_comm; this.repo_wiki = repo_wiki;}
    +	private void Reset() {
    +		upright = Xop_lnki_tkn.Upright_null;
    +		time = Xof_lnki_time.Null;
    +		page = Xof_lnki_page.Null;
    +	}
    +	public Xof_fsdb_mkr Init_comm_thum(String ttl_str, int file_w, int file_h)	{return Init(Bool_.Y, Bool_.N, ttl_str, file_w, file_h);}
    +	public Xof_fsdb_mkr Init_comm_orig(String ttl_str, int file_w, int file_h)	{return Init(Bool_.Y, Bool_.Y, ttl_str, file_w, file_h);}
    +	public Xof_fsdb_mkr Init(boolean repo_is_commons, boolean file_is_orig, String ttl_str, int file_w, int file_h) {
    +		this.lnki_type = file_is_orig ? Xop_lnki_type.Id_none : Xop_lnki_type.Id_thumb; 
    +		this.repo = repo_is_commons ? repo_comm : repo_wiki;
    +		this.ttl_bry = Bry_.new_u8(ttl_str);
    +		this.file_w = file_w; this.file_h = file_h;
    +		return this;
    +	}
    +	public Xof_fsdb_itm Make() {
    +		Xof_fsdb_itm rv = new Xof_fsdb_itm();
    +		rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_a7("en.w"), ttl_bry, lnki_type, upright, file_w, file_h, time, page, Xof_patch_upright_tid_.Tid_all);
    +		rv.Orig_repo_name_(repo);
    +		this.Reset();
    +		return rv;
    +	}
    +}
    +class Xou_cache_itm_mkr {
    +//		private byte[] dir; private byte[] ttl; private boolean is_orig; private int w, h; private double time; private int page; private long size;
    +	public Xou_cache_itm_mkr() {this.Reset();}
    +	private void Reset() {
    +//			this.time = Xof_lnki_time.Null;
    +//			this.page = Xof_lnki_page.Null;
    +//			this.h = 200;
    +//			this.size = 1;
    +	}
    +	public Xou_cache_itm_mkr Init(String dir_str, String ttl_str, boolean is_orig, int w) {
    +//			this.dir = Bry_.new_u8(dir_str);
    +//			this.ttl = Bry_.new_u8(ttl_str);
    +//			this.is_orig = is_orig;
    +//			this.w = w;
    +		return this;
    +	}
    +	public void Make(Xof_cache_mgr cache_mgr) {
    +//			cache_mgr.Fil__make(dir, ttl, is_orig, w, h, time, page, size);
    +		this.Reset();
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/bins/Xof_bin_wkr__http_wmf__tst.java b/400_xowa/src/gplx/xowa/files/bins/Xof_bin_wkr__http_wmf__tst.java
    new file mode 100644
    index 000000000..31e987f1d
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/bins/Xof_bin_wkr__http_wmf__tst.java
    @@ -0,0 +1,65 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files.bins; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.xowa.files.repos.*;
    +public class Xof_bin_wkr__http_wmf__tst {
    +	private final    Xof_bin_wkr__http_wmf__fxt fxt = new Xof_bin_wkr__http_wmf__fxt();
    +	@Before public void init() {fxt.Clear();}
    +	@Test   public void Basic() {
    +		fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", "test_data");
    +		fxt.Exec__Get_as_rdr(fxt.Fsdb_itm_mkr().Lnki__en_w("A.png").Orig__commons__lnki(), Bool_.Y, 220);
    +		fxt.Test__Get_as_rdr__rdr("test_data");
    +	}
    +	@Test   public void Enwiki_fails__fallback_to_commons() {
    +		fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", "test_data");			// put file in commons
    +		Xof_fsdb_itm fsdb_itm = fxt.Fsdb_itm_mkr().Lnki__en_w("A.png").Orig__enwiki__lnki().Make();
    +		fxt.Exec__Get_as_rdr(fsdb_itm, Bool_.Y, 220);														// look in enwiki
    +		fxt.Test__Get_as_rdr__rdr("test_data");																// test that enwiki tries commons again
    +		Tfds.Eq_str("commons.wikimedia.org", fsdb_itm.Orig_repo_name(), "repo_name");						// test that it's now commons
    +		Tfds.Eq_byte(Xof_repo_tid_.Tid__remote, fsdb_itm.Orig_repo_id(), "repo_tid");						// test that it's now commons
    +	}
    +	@Test   public void Long_filename_becomes_thumbnail() {
    +		String filename = String_.Repeat("A", 200) + ".png";
    +		fxt.Init__Http("mem/http/commons.wikimedia.org/thumb/1/14/" + filename + "/220px-thumbnail.png", "test_data");	// add file as "thumbnail.png"
    +		Xof_fsdb_itm fsdb_itm = fxt.Fsdb_itm_mkr().Lnki__en_w(filename).Orig__enwiki__lnki().Make();
    +		fxt.Exec__Get_as_rdr(fsdb_itm, Bool_.Y, 220);														// look in enwiki
    +		fxt.Test__Get_as_rdr__rdr("test_data");																// test that file is there
    +	}
    +}
    +class Xof_bin_wkr__http_wmf__fxt {
    +	private final    Xof_bin_wkr__http_wmf wkr;
    +	private final    Io_download_mgr__memory download_mgr;
    +	private Io_stream_rdr get_as_rdr__rdr;
    +	public Xof_fsdb_itm_fxt Fsdb_itm_mkr() {return fsdb_itm_mkr;} private final    Xof_fsdb_itm_fxt fsdb_itm_mkr = new Xof_fsdb_itm_fxt();
    +	public Xof_bin_wkr__http_wmf__fxt() {
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		Xoa_app_fxt.repo2_(app, wiki);
    +		this.download_mgr = Io_download_mgr_.new_memory();
    +		this.wkr = Xof_bin_wkr__http_wmf.new_(wiki, download_mgr);
    +	}
    +	public void Clear() {
    +		download_mgr.Clear();
    +	}
    +	public void Init__Http(String url, String data) {download_mgr.Upload_data(url, Bry_.new_u8(data));}
    +	public void Exec__Get_as_rdr(Xof_fsdb_itm_fxt fsdb_itm_mkr, boolean is_thumb, int w) {Exec__Get_as_rdr(fsdb_itm_mkr.Make(), is_thumb, w);}
    +	public void Exec__Get_as_rdr(Xof_fsdb_itm fsdb_itm , boolean is_thumb, int w) {
    +		this.get_as_rdr__rdr = wkr.Get_as_rdr(fsdb_itm, is_thumb, w);
    +	}
    +	public void Test__Get_as_rdr__rdr(String expd) {
    +		Tfds.Eq_str(expd, Io_stream_rdr_.Load_all_as_str(get_as_rdr__rdr), "rdr_contents");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/caches/Xof_cache_mgr_tst.java b/400_xowa/src/gplx/xowa/files/caches/Xof_cache_mgr_tst.java
    new file mode 100644
    index 000000000..86ba73843
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/caches/Xof_cache_mgr_tst.java
    @@ -0,0 +1,70 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.dbs.*;
    +public class Xof_cache_mgr_tst {
    +//		@Before public void init() {fxt.Reset();} private Xof_cache_mgr_fxt fxt = new Xof_cache_mgr_fxt();
    +	@Test  	public void Basic() {
    +//			Xou_cache_itm itm = fxt.Bldr_itm("A.png").Make();
    +//			fxt.Test_get_n(itm);
    +//			fxt.Exec_update(itm);
    +//			fxt.Test_get_y(itm);
    +//			fxt.Test_viewed_data(1, 123);
    +//			fxt.Exec_update(itm);
    +//			fxt.Test_viewed_data(2, 124);
    +//			fxt.Exec_db_save(itm);
    +//			fxt.Test_db_itms(itm);
    +	}
    +}
    +//	class Xof_cache_mgr_fxt {
    +//		public Xof_cache_mgr_fxt Reset() {
    +//			return this;
    +//		}
    +//	}
    +//	class Xof_cache_itm_mkr {
    +////		private byte[] dir; private byte[] ttl; private boolean is_orig; private int w, h; private double time; private int page; private long size;
    +//		private byte db_state;
    +//		private int lnki_site; private byte[] lnki_ttl; private int lnki_type; private double lnki_upright; private int lnki_w; private int lnki_h; private double lnki_time; private int lnki_page;
    +//		private int orig_wiki; private byte[] orig_ttl; private int orig_ext; private int file_w; private int file_h; private double file_time; private int file_page;
    +//		private long temp_file_size; private int temp_view_count; private long temp_view_date; private int temp_w;
    +//		private Bry_bfr key_bfr = Bry_bfr_.New();
    +//		public Xof_cache_itm_mkr() {this.Reset();}
    +//		private void Reset() {
    +//			db_state = Db_cmd_mode.Tid_ignore;
    +//			lnki_site = orig_wiki = -1;
    +//			lnki_ttl = orig_ttl = null;
    +//			lnki_type = Byte_.Max_value_127;
    +//			lnki_upright = Xof_img_size.Upright_null;
    +//			lnki_w = lnki_h = file_w = file_h = temp_w = Xof_img_size.Size_null;
    +//			lnki_time = file_time = Xof_lnki_time.Null;
    +//			lnki_page = file_page = Xof_lnki_page.Null;
    +//			orig_ext = Xof_ext_.Id_unknown;
    +//			temp_file_size = -1;
    +//			temp_view_count = -1;
    +//			temp_view_date = -1;			
    +//		}
    +//		public Xof_cache_itm_mkr Init(String dir_str, String ttl_str, boolean is_orig, int w) {
    +////			this.dir = Bry_.new_u8(dir_str);
    +////			this.ttl = Bry_.new_u8(ttl_str);
    +////			this.is_orig = is_orig;
    +////			this.w = w;
    +//			return this;
    +//		}
    +//		public Xou_cache_itm Make() {
    +//			return new Xou_cache_itm(key_bfr, db_state, lnki_site, lnki_ttl, lnki_type, lnki_upright, lnki_w, lnki_h, file_w, file_h, );
    +//			this.Reset();
    +//		}
    +//	}
    diff --git a/400_xowa/src/gplx/xowa/files/caches/Xou_cache_mgr_tst.java b/400_xowa/src/gplx/xowa/files/caches/Xou_cache_mgr_tst.java
    new file mode 100644
    index 000000000..e0cc39167
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/caches/Xou_cache_mgr_tst.java
    @@ -0,0 +1,112 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.repos.*;
    +public class Xou_cache_mgr_tst {
    +	@Before public void init() {fxt.Clear();} private final    Xou_cache_mgr_fxt fxt = new Xou_cache_mgr_fxt();
    +	@Test   public void Update() {
    +		Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
    +		fxt.Exec_update(itm_1);
    +		fxt.Test_get(itm_1, 1, 0);
    +	}
    +	@Test   public void Update_mult() {
    +		Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
    +		fxt.Exec_update(itm_1, itm_1, itm_1);
    +		fxt.Test_get(itm_1, 3, 2);
    +	}
    +	@Test   public void Reload() {
    +		Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
    +		fxt.Exec_update(itm_1, itm_1, itm_1);
    +		fxt.Test_get(itm_1, 3, 2);
    +		fxt.Exec_save_and_clear();
    +		fxt.Test_get(itm_1, 3, 2);
    +	}
    +	@Test  public void Reduce() {
    +		fxt.Init_delete(3, 5);
    +		Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
    +		Xof_fsdb_itm itm_2 = fxt.Make_itm("en.w", "2.png", 2);
    +		Xof_fsdb_itm itm_3 = fxt.Make_itm("en.w", "3.png", 2);
    +		fxt.Exec_update(itm_1, itm_2, itm_3);
    +		fxt.Exec_reduce();
    +		fxt.Test_get_y(itm_3);
    +		fxt.Test_get_n(itm_1, itm_2);
    +	}
    +	@Test  public void Reduce_same() {
    +		fxt.Init_delete(3, 5);
    +		Xof_fsdb_itm itm_1 = fxt.Make_itm("en.w", "1.png", 2);
    +		Xof_fsdb_itm itm_2 = fxt.Make_itm("fr.w", "1.png", 2);
    +		Xof_fsdb_itm itm_3 = fxt.Make_itm("en.w", "2.png", 2);
    +		fxt.Exec_update(itm_3, itm_2, itm_1);
    +		fxt.Exec_reduce();
    +		fxt.Test_get_y(itm_3);
    +		fxt.Test_get_n(itm_1, itm_2);
    +	}
    +}
    +class Xou_cache_mgr_fxt {
    +	private Xou_cache_mgr mgr;
    +	private long cache_min;
    +	public void Clear() {
    +		Datetime_now.Manual_(DateAdp_.new_(1970, 1, 1, 0, 0, 0, 0));
    +		Io_mgr.Instance.InitEngine_mem();
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();			
    +		app.User().User_db_mgr().Init_by_app(Bool_.N, app.Fsys_mgr().Root_dir().GenSubFil_nest("user", "xowa.user.anonymous.sqlite3"));
    +		Xoa_app_fxt.repo_(app, Xoa_app_fxt.Make__wiki__edit(app, "en.wikipedia.org"));
    +		Xoa_app_fxt.repo_(app, Xoa_app_fxt.Make__wiki__edit(app, "fr.wikipedia.org"));
    +		this.mgr = new Xou_cache_mgr(app.Wiki_mgr(), app.Fsys_mgr().File_dir(), app.User().User_db_mgr().Db_file());
    +	}
    +	public void Init_delete(long min, long max) {
    +		cache_min = min;
    +		mgr.Fsys_size_(min, max);
    +	}
    +	public Xof_fsdb_itm Make_itm(String wiki, String file, int size) {
    +		Xof_fsdb_itm rv = new Xof_fsdb_itm();
    +		byte[] wiki_domain = Bry_.new_a7(wiki);
    +		byte[] file_ttl = Bry_.new_a7(file);
    +		rv.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, wiki_domain, file_ttl, Byte_.Zero, 1, 1, 1 ,1, 1, 1);
    +		rv.Init_at_orig(Xof_repo_tid_.Tid__local, wiki_domain, file_ttl, Xof_ext_.new_by_id_(Xof_ext_.Id_png), 120, 120, Bry_.Empty);
    +		rv.File_size_(size);
    +		return rv;
    +	}
    +	public void Exec_update(Xof_fsdb_itm... ary) {
    +		for (Xof_fsdb_itm itm : ary)
    +			mgr.Update(itm);
    +	}
    +	public void Exec_save_and_clear() {
    +		mgr.Db_save();
    +		mgr.Clear();
    +	}
    +	public void Exec_reduce() {
    +		mgr.Reduce(cache_min);
    +	}
    +	public void Test_get(Xof_fsdb_itm fsdb, int expd_view_count, long expd_view_date) {
    +		Xou_cache_itm cache = mgr.Get_or_null(fsdb);
    +		Tfds.Eq(expd_view_count, cache.View_count(), "count");
    +		Tfds.Eq(expd_view_date , (cache.View_date() / 60) - 1, "time");	// Tfds.Now increments by 60 seconds; also -1 b/c Gfo_log now calls Datetime_now.Get once
    +	}
    +	public void Test_get_n(Xof_fsdb_itm... ary) {
    +		for (Xof_fsdb_itm itm : ary) {
    +			Xou_cache_itm cache = mgr.Get_or_null(itm);
    +			Tfds.Eq_null(cache, String_.new_u8(itm.Lnki_ttl()));
    +		}
    +	}
    +	public void Test_get_y(Xof_fsdb_itm... ary) {
    +		for (Xof_fsdb_itm itm : ary) {
    +			Xou_cache_itm cache = mgr.Get_or_null(itm);
    +			Tfds.Eq_nullNot(cache, String_.new_u8(itm.Lnki_ttl()));
    +		}
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/caches/Xou_cache_tbl_tst.java b/400_xowa/src/gplx/xowa/files/caches/Xou_cache_tbl_tst.java
    new file mode 100644
    index 000000000..2c9441a20
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/caches/Xou_cache_tbl_tst.java
    @@ -0,0 +1,59 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.dbs.*;
    +public class Xou_cache_tbl_tst {
    +	@Before public void init() {fxt.Clear();} private final    Xou_cache_tbl_fxt fxt = new Xou_cache_tbl_fxt();
    +	@Test  public void Orig_ttl__same()			{fxt.Test_save_orig_ttl("A.png", "A.png", "");}
    +	@Test  public void Orig_ttl__redirect()		{fxt.Test_save_orig_ttl("A.png", "B.png", "B.png");}
    +}
    +class Xou_cache_tbl_fxt {
    +	private final    Bry_bfr lnki_key_bfr = Bry_bfr_.New_w_size(255);
    +	private Xou_cache_tbl tbl;
    +	public void Clear() {
    +		Io_mgr.Instance.InitEngine_mem();
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/test.xowa"));
    +		this.tbl = new Xou_cache_tbl(conn_data.Conn());
    +		tbl.Create_tbl();
    +	}
    +	public Xou_cache_itm Make_itm(String lnki_wiki_abrv_xo, String lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, int user_thumb_w
    +	, int orig_repo_id, String orig_ttl, int orig_ext_id, int orig_w, int orig_h
    +	, int html_w, int html_h, double html_time, int html_page
    +	, boolean file_is_orig, int file_w, double file_time, int file_page, long file_size
    +	, int view_count, long view_date) {
    +		return new Xou_cache_itm(lnki_key_bfr, Db_cmd_mode.Tid_create
    +		, Bry_.new_u8(lnki_wiki_abrv_xo), Bry_.new_u8(lnki_ttl), lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, user_thumb_w
    +		, orig_repo_id, Bry_.new_u8(orig_ttl), orig_ext_id, orig_w, orig_h
    +		, html_w, html_h, html_time, html_page
    +		, file_is_orig, file_w, file_time, file_page, file_size
    +		, view_count, view_date
    +		);
    +	}
    +	public Xou_cache_itm Exec_select_one(String lnki_wiki_abrv_xo, String lnki_ttl, int lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, int user_thumb_w) {
    +		return tbl.Select_one(Bry_.new_u8(lnki_wiki_abrv_xo), Bry_.new_u8(lnki_ttl), 1, 1, 1, 1, 1, 1, 1);
    +	}
    +	public void Test_save_orig_ttl(String lnki_ttl, String orig_ttl, String expd_orig_ttl) {
    +		Xou_cache_itm itm = Make_itm("en.w", lnki_ttl, 1, 1, 1, 1, 1, 1, 1, 1, orig_ttl, 1, 1, 1, 1, 1, 1, 1, Bool_.Y, 1, 1, 1, 1, 1, 1);
    +		tbl.Db_save(itm);
    +		Db_rdr rdr = tbl.Select_all_for_test();
    +		try {
    +			Tfds.Eq_true(rdr.Move_next());
    +			Tfds.Eq(expd_orig_ttl, rdr.Read_str(tbl.Fld_orig_ttl()));
    +		}
    +		finally {rdr.Rls();}
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/cnvs/Xof_img_wkr_resize_img_mok.java b/400_xowa/src/gplx/xowa/files/cnvs/Xof_img_wkr_resize_img_mok.java
    new file mode 100644
    index 000000000..1f9b56ede
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/cnvs/Xof_img_wkr_resize_img_mok.java
    @@ -0,0 +1,30 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import gplx.core.primitives.*;
    +import gplx.gfui.*; import gplx.gfui.imgs.*;
    +import gplx.xowa.files.cnvs.*;
    +public class Xof_img_wkr_resize_img_mok implements Xof_img_wkr_resize_img {
    +	public boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
    +		SizeAdp src_size = ImageAdp_.txt_fil_(src).Size();
    +		int src_w = src_size.Width(), src_h = src_size.Height();
    +		if (trg_w < 1) throw Err_.new_wo_type("trg_w must be > 0", "trg_w", trg_w);
    +		if (trg_h < 1) trg_h = Xof_xfer_itm_.Scale_h(src_w, src_h, trg_w);
    +		Io_mgr.Instance.SaveFilStr(trg, SizeAdp_.new_(trg_w, trg_h).To_str());
    +		return true;
    +	}
    +	public static final    Xof_img_wkr_resize_img_mok Instance = new Xof_img_wkr_resize_img_mok(); Xof_img_wkr_resize_img_mok() {}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/fs_roots/Fs_root_wkr_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/fs_roots/Fs_root_wkr_tst.java
    new file mode 100644
    index 000000000..c7b9bc6c1
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/fs_roots/Fs_root_wkr_tst.java
    @@ -0,0 +1,82 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.files.imgs.*;
    +import gplx.fsdb.meta.*;
    +public class Fs_root_wkr_tst {
    +	@Before public void init() {fxt.Reset();} private Fs_root_wkr_fxt fxt = new Fs_root_wkr_fxt();
    +	@Test   public void Basic() {
    +		fxt.Init_fs("mem/dir/7/70/A.png", 200, 100);
    +		fxt.Test_get("A.png", fxt.itm_().Url_("mem/dir/7/70/A.png").Size_(200, 100));
    +		fxt.Test_db("A.png", fxt.itm_().Init(1, "mem/dir/7/70/A.png", 200, 100));
    +	}
    +	@Test   public void Recurse() {
    +		fxt.Init_fs("mem/dir/A/A1.png", 200, 100);
    +		fxt.Test_get("A1.png", fxt.itm_().Url_("mem/dir/A/A1.png").Size_(200, 100));
    +	}
    +}
    +class Fs_root_wkr_fxt {
    +	private Fs_root_wkr root_dir = new Fs_root_wkr();
    +	private Io_url url;
    +	public void Reset() {
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		Io_mgr.Instance.InitEngine_mem();
    +		url = Io_url_.mem_dir_("mem/dir/");
    +		root_dir = new Fs_root_wkr();
    +		Xof_img_wkr_query_img_size img_size_wkr = new Xof_img_wkr_query_img_size_test();
    +		root_dir.Init(img_size_wkr, url);
    +	}
    +	public Orig_fil_mok itm_() {return new Orig_fil_mok();}
    +	public void Init_fs(String url, int w, int h) {Save_img(url, w, h);}
    +	public void Test_get(String name, Orig_fil_mok expd) {
    +		Orig_fil_row actl = root_dir.Get_by_ttl(Bry_.new_u8(name));
    +		expd.Test(actl);
    +	}
    +	public void Test_db(String ttl, Orig_fil_mok expd) {
    +		Orig_fil_row actl = root_dir.Orig_tbl().Select_itm_or_null(url, Bry_.new_u8(ttl));
    +		expd.Test(actl);
    +	}
    +	public static void Save_img(String url, int w, int h) {
    +		gplx.gfui.SizeAdp img_size = gplx.gfui.SizeAdp_.new_(w, h);
    +		Io_mgr.Instance.SaveFilStr(url, img_size.To_str());
    +	}
    +}
    +class Orig_fil_mok {
    +	private int uid = -1;
    +	private int ext_id = -1;
    +	private String name = null;
    +	private int w = -1;
    +	private int h = -1;
    +	public Orig_fil_mok Url_(String v) {url = v; return this;} private String url = null;
    +	public Orig_fil_mok Size_(int w, int h) {this.w = w; this.h = h; return this;}
    +	public Orig_fil_mok Init(int uid, String url, int w, int h) {
    +		this.uid = uid;
    +		this.url = url; this.w = w; this.h = h;
    +		this.name = Io_url_.new_any_(url).NameAndExt();
    +		this.ext_id = Xof_ext_.new_by_ttl_(Bry_.new_u8(name)).Id();
    +		return this;
    +	}
    +	public void Test(Orig_fil_row actl) {
    +		if (actl == null) Tfds.Fail("actl itm is null");
    +		if (w != -1)			Tfds.Eq(w, actl.W());
    +		if (h != -1)			Tfds.Eq(h, actl.H());
    +		if (url != null)		Tfds.Eq(url, actl.Url().Raw());
    +		if (uid != -1)			Tfds.Eq(uid, actl.Uid());
    +		if (ext_id != -1)		Tfds.Eq(uid, actl.Ext_id());
    +		if (name != null)		Tfds.Eq(name, String_.new_u8(actl.Name()));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__bmp_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__bmp_tst.java
    new file mode 100644
    index 000000000..fb51c157e
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__bmp_tst.java
    @@ -0,0 +1,31 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__bmp_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Make_orig() {
    +		fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/440px.png", "440,400");
    +	}
    +	@Test   public void Make_thumb() {
    +		fxt.Init__orig_w_fsdb__commons_orig("A.bmp", 440, 400);
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.bmp").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.bmp/220px.png", "220,200");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__flac_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__flac_tst.java
    new file mode 100644
    index 000000000..0c02bc8ee
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__flac_tst.java
    @@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__flac_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Orig_page() {	// .flac is on page [[File:A.flac]]
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Rslt_orig_exists_y().Rslt_file_exists_n());	// check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2015-02-15
    +		fxt.Test_fsys_exists_n("mem/root/common/orig/8/b/A.flac");
    +	}
    +	@Test   public void Orig_app() {	// .flac is clicked; get file
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.flac"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.flac"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.flac").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys_exists_y("mem/root/common/orig/8/b/A.flac");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__oga_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__oga_tst.java
    new file mode 100644
    index 000000000..2b61cfb33
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__oga_tst.java
    @@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__oga_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Orig_page() {	// .oga is on page [[File:A.oga]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately)
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Rslt_orig_exists_y().Rslt_file_exists_n());
    +		fxt.Test_fsys_exists_n("mem/root/common/orig/4/f/A.oga");
    +	}
    +	@Test   public void Orig_app() {	// .oga is clicked; get file
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.oga"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.oga"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.oga").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys_exists_y("mem/root/common/orig/4/f/A.oga");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogg_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogg_tst.java
    new file mode 100644
    index 000000000..e4c9ec104
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogg_tst.java
    @@ -0,0 +1,35 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +import gplx.xowa.files.bins.*;
    +public class Xof_file_ext__ogg_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +//		@Test   public void Video() {	// disabled; .ogg will never be video; DATE:2014-02-02
    +//			fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 440, 400));
    +//			fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400));	// create a thumb at 440,400 (needed for preview of video)
    +//			fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Rslt_orig_missing().Rslt_fsdb_xowa().Rslt_conv_n());
    +//			fxt.Test_fsys("mem/root/common/thumb/4/2/A.ogg/440px.jpg", "440,400");
    +//			Xof_fsdb_itm itm = fxt.Test_regy_pass("A.ogg");
    +//			fxt.Test_itm_ext(itm, Xof_ext_.Id_ogv);// chk that file is now ogv
    +//		}
    +	@Test   public void Audio() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogg", 0, 0));	// audio has no size
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogg", 440, 400));	// create a thumb but it should never be used
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.ogg").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_n().Rslt_file_resized_n());
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogv_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogv_tst.java
    new file mode 100644
    index 000000000..3bd58f262
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__ogv_tst.java
    @@ -0,0 +1,34 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__ogv_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Copy_orig() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
    +		fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px.jpg", "440,400");
    +	}
    +	@Test   public void Copy_orig_w_thumbtime() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.ogv", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.ogv", 440, 400, 10));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.ogv").Lnki_time_(10).Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_n());
    +		fxt.Test_fsys("mem/root/common/thumb/d/0/A.ogv/440px-10.jpg", "440,400");
    +		// fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130)); DELETE: not needed; tests if new A.png can be resized from existing; DATE:2015-03-03
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__pdf_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__pdf_tst.java
    new file mode 100644
    index 000000000..dc2e7e4ff
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__pdf_tst.java
    @@ -0,0 +1,27 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__pdf_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test  public void Copy_thumb() {// PURPOSE: download pdf thumb only; [[File:Physical world.pdf|thumb]]
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.pdf", 2200, 1700));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.pdf", 220, 170));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.pdf", 220));
    +		fxt.Test_fsys("mem/root/common/thumb/e/f/A.pdf/220px.jpg", "220,170");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__png_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__png_tst.java
    new file mode 100644
    index 000000000..60c9456d9
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__png_tst.java
    @@ -0,0 +1,61 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_file_ext__png_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Copy_thumb() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png"));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
    +	}
    +	@Test   public void Copy_orig() {
    +		fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.png").Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
    +	}
    +	@Test   public void Copy_orig_w_width() {	// PURPOSE: if not thumb, but width is specified; do not download orig and convert; EX: [[File:The Earth seen from Apollo 17.jpg|250px]]
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 220, 200));
    +		fxt.Exec_get(Xof_exec_arg.new_("A.png", Xop_lnki_type.Id_null, 220, Xop_lnki_tkn.Height_null).Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
    +	}
    +	@Test   public void Make_thumb() {
    +		fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.png").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/220px.png", "220,200");
    +	}
    +	@Test  public void Height_only() {	// PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 12591, 1847));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 887, 130));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, 130));
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/887px.png", "887,130");
    +	}
    +	@Test  public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 4884, 4932));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 150, 150));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", 150, Xop_lnki_tkn.Height_null));
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/150px.png", "150,150");
    +	}
    +	@Test  public void Upright() {	// PURPOSE.fix: upright not working;  EX: w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 1378, 1829));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_thumb("A.png", 170, 226));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.png", Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null).Lnki_upright_(Xof_img_size.Upright_default_marker));
    +		fxt.Test_fsys("mem/root/common/thumb/7/0/A.png/170px.png", "170,226");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__svg_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__svg_tst.java
    new file mode 100644
    index 000000000..d6add5058
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__svg_tst.java
    @@ -0,0 +1,38 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__svg_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Make_orig() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/440px.png", "440,400");
    +	}
    +	@Test   public void Make_thumb() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.svg", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.svg", 440, 400));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/220px.png", "220,200");
    +	}
    +	@Test  public void Thumb_can_be_bigger_than_orig() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
    +		fxt.Init__orig_w_fsdb__commons_orig("A.svg", 110, 100);							// create orig of 110,100
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.svg", 330).Rslt_file_exists_y());	// get 330
    +		fxt.Test_fsys("mem/root/common/thumb/7/5/A.svg/330px.png", "330,300");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__unknown_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__unknown_tst.java
    new file mode 100644
    index 000000000..8d3b5a8e0
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__unknown_tst.java
    @@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__unknown_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Orig_page() {	// .bin is on page [[File:A.bin]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Rslt_orig_exists_y().Rslt_file_exists_n());
    +		fxt.Test_fsys_exists_n("mem/root/common/orig/f/b/A.bin");
    +	}
    +	@Test   public void Orig_app() {	// .bin is clicked; get file
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.bin"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.bin"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.bin").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys_exists_y("mem/root/common/orig/f/b/A.bin");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__wav_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__wav_tst.java
    new file mode 100644
    index 000000000..fd718c41d
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__wav_tst.java
    @@ -0,0 +1,34 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +import gplx.xowa.files.bins.*;
    +public class Xof_file_ext__wav_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Orig_page() {	// .wav is on page [[File:A.wav]]; check orig (since orig may redirect) but do not get file; (since file is not "viewable" immediately); DATE:2014-08-17
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Rslt_orig_exists_y().Rslt_file_exists_n());
    +		fxt.Test_fsys_exists_n("mem/root/common/orig/c/3/A.wav");
    +	}
    +	@Test   public void Orig_app() {	// .wav is clicked; get file
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_file("A.wav"));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_file("A.wav"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.wav").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_orig_exists_y().Rslt_file_exists_y());
    +		fxt.Test_fsys_exists_y("mem/root/common/orig/c/3/A.wav");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__xcf_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__xcf_tst.java
    new file mode 100644
    index 000000000..a55d35edd
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_ext__xcf_tst.java
    @@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_ext__xcf_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test   public void Make_orig() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/440px.png", "440,400");
    +	}
    +	@Test   public void Make_thumb() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.xcf", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.xcf", 440, 400));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("A.xcf").Rslt_orig_exists_y().Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/common/thumb/4/4/A.xcf/220px.png", "220,200");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_fxt.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_fxt.java
    new file mode 100644
    index 000000000..aeebe67be
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_fxt.java
    @@ -0,0 +1,190 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import gplx.core.envs.*;
    +import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.guis.cbks.js.*;
    +import gplx.fsdb.data.*;
    +import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
    +import gplx.xowa.wikis.nss.*;
    +import gplx.xowa.parsers.lnkis.*;
    +class Xof_file_fxt {		
    +	private Xoae_app app; private Xof_fsdb_mgr__sql fsdb_mgr; private Xowe_wiki wiki; private Xof_orig_mgr orig_mgr;
    +	private final    Fsd_thm_itm tmp_thm = Fsd_thm_itm.new_();
    +	public void Rls() {}
    +	public void Reset() {
    +		Io_mgr.Instance.InitEngine_mem();	// NOTE: files are downloaded to mem_engine, regardless of Db being mem or sqlite; always reset
    +		Io_url root_url = Xoa_test_.Url_root();
    +		Xoa_test_.Db_init(root_url);
    +		app = Xoa_app_fxt.Make__app__edit(Op_sys.Cur().Os_name(), root_url);
    +		wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		wiki.File__fsdb_mode().Tid__v2__bld__y_();
    +		this.fsdb_mgr = (Xof_fsdb_mgr__sql)wiki.File_mgr().Fsdb_mgr();
    +		this.orig_mgr = wiki.File__orig_mgr();
    +		Xof_repo_fxt.Repos_init(app.File_mgr(), true, wiki);
    +		Xowe_wiki_.Create(wiki, 1, "dump.xml");
    +		Xow_db_file text_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__text); text_db.Tbl__text().Create_tbl();
    +		Fsdb_db_mgr__v2 fsdb_core = Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, Bool_.Y);
    +		fsdb_mgr.Mnt_mgr().Ctor_by_load(fsdb_core);
    +		fsdb_mgr.Mnt_mgr().Mnts__get_main().Bin_mgr().Dbs__make("temp.xowa");
    +		wiki.File_mgr().Init_file_mgr_by_load(wiki);
    +		fsdb_mgr.Bin_mgr().Wkrs__del(Xof_bin_wkr_.Key_http_wmf);	// never use http_wmf wkr for these tests
    +		Xof_bin_wkr__fsdb_sql bin_wkr_fsdb = (Xof_bin_wkr__fsdb_sql)fsdb_mgr.Bin_mgr().Wkrs__get_or_null(Xof_bin_wkr_.Key_fsdb_wiki);
    +		fsdb_mgr.Bin_mgr().Resizer_(Xof_img_wkr_resize_img_mok.Instance);
    +		bin_wkr_fsdb.Resize_allowed_(true);
    +	}
    +	public void Init__orig_w_fsdb__commons_orig(String ttl, int w, int h) {
    +		this.Init_fsdb_db(Xof_fsdb_arg.new_comm(Bool_.N, ttl, w, h));
    +		this.Init_orig_db(Xof_orig_arg.new_comm(ttl, w, h));
    +	}
    +	public void Init_orig_db(Xof_orig_arg arg) {
    +		orig_mgr.Insert(arg.Repo(), arg.Page(), Xof_ext_.new_by_ttl_(arg.Page()).Id(), arg.W(), arg.H(), arg.Redirect());
    +	}
    +	public void Init_fsdb_db(Xof_fsdb_arg arg) {
    +		Fsm_mnt_itm mnt_itm = fsdb_mgr.Mnt_mgr().Mnts__get_main();
    +		Fsm_atr_fil atr_fil = mnt_itm.Atr_mgr().Db__core();
    +		Fsm_bin_fil bin_fil = mnt_itm.Bin_mgr().Dbs__get_nth();
    +		if (arg.Is_thumb())
    +			mnt_itm.Insert_thm(tmp_thm, atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Time(), arg.Page(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.New__mem(arg.Bin()));
    +		else
    +			mnt_itm.Insert_img(atr_fil, bin_fil, arg.Wiki(), arg.Ttl(), arg.Ext(), arg.W(), arg.H(), arg.Bin().length, gplx.core.ios.streams.Io_stream_rdr_.New__mem(arg.Bin()));
    +	}
    +	public void Exec_get(Xof_exec_arg arg) {
    +		byte[] ttl_bry = arg.Ttl();
    +		Xof_fsdb_itm itm = new Xof_fsdb_itm();
    +		itm.Init_at_lnki(arg.Exec_tid(), wiki.Domain_itm().Abrv_xo(), ttl_bry, arg.Lnki_type(), arg.Lnki_upright(), arg.Lnki_w(), arg.Lnki_h(), arg.Lnki_time(), Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
    +		List_adp itms_list = List_adp_.New(); itms_list.Add(itm);
    +		orig_mgr.Find_by_list(Ordered_hash_.New_bry(), itms_list, Xof_exec_tid.Tid_wiki_page);
    +		Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Xow_ns_.Tid__main, ttl_bry);
    +		Xoae_page page = Xoae_page.New(wiki, ttl);
    +		fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
    +		if (arg.Rslt_orig_exists()  != Bool_.__byte)	Tfds.Eq(arg.Rslt_orig_exists()  == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");
    +		if (arg.Rslt_file_exists()  != Bool_.__byte)	Tfds.Eq(arg.Rslt_file_exists()  == Bool_.Y_byte, itm.File_exists(), "file_exists");
    +		if (arg.Rslt_file_resized() != Bool_.__byte)	Tfds.Eq(arg.Rslt_file_resized() == Bool_.Y_byte, itm.File_resized(), "file_resize");
    +	}
    +	public void Test_fsys_exists_y(String url)			{Test_fsys_exists(url, Bool_.Y);}
    +	public void Test_fsys_exists_n(String url)			{Test_fsys_exists(url, Bool_.N);}
    +	public void Test_fsys_exists(String url, boolean expd) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(Io_url_.new_any_(url)));}
    +	public void Test_fsys(String url, String expd_bin)	{Tfds.Eq(expd_bin, Io_mgr.Instance.LoadFilStr(url));}
    +}
    +class Xof_repo_fxt {
    +	public static void Repos_init(Xof_file_mgr file_mgr, boolean src_repo_is_wmf, Xowe_wiki wiki) {
    +		byte[] src_commons = Bry_.new_a7("src_commons");
    +		byte[] src_en_wiki = Bry_.new_a7("src_en_wiki");
    +		byte[] trg_commons = Bry_.new_a7("trg_commons");
    +		byte[] trg_en_wiki = Bry_.new_a7("trg_en_wiki");
    +		Ini_repo_add(file_mgr, src_commons, "mem/src/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, false);
    +		Ini_repo_add(file_mgr, src_en_wiki, "mem/src/en.wikipedia.org/"		, Xow_domain_itm_.Str__enwiki, false);
    +		Ini_repo_add(file_mgr, trg_commons, "mem/root/common/", Xow_domain_itm_.Str__commons, true).Primary_(true);
    +		Ini_repo_add(file_mgr, trg_en_wiki, "mem/root/enwiki/", Xow_domain_itm_.Str__enwiki, true).Primary_(true);
    +		Xowe_repo_mgr wiki_repo_mgr = wiki.File_mgr().Repo_mgr();
    +		Xof_repo_pair pair = null;
    +		pair = wiki_repo_mgr.Add_repo(src_commons, trg_commons);
    +		pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf).Tarball_(!src_repo_is_wmf);
    +		pair.Trg().Fsys_is_wnt_(true);
    +
    +		pair = wiki_repo_mgr.Add_repo(src_en_wiki, trg_en_wiki);
    +		pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf);
    +		pair.Trg().Fsys_is_wnt_(true);
    +	}
    +	private static Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) {
    +		return file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
    +	}
    +}
    +class Xof_orig_arg {
    +	Xof_orig_arg(byte repo, byte[] page, int w, int h, byte[] redirect) {this.repo = repo; this.page = page; this.w = w; this.h = h; this.redirect = redirect;}
    +	public byte			Repo() {return repo;} private final    byte repo;
    +	public byte[]		Page() {return page;} private final    byte[] page;
    +	public int			W() {return w;} private final    int w;
    +	public int			H() {return h;} private final    int h;
    +	public byte[]		Redirect() {return redirect;} private final    byte[] redirect;
    +	public static Xof_orig_arg new_comm_file(String page)								{return new_(Bool_.Y, page, Xof_img_size.Size_null, Xof_img_size.Size_null);}
    +	public static Xof_orig_arg new_comm(String page, int w, int h)						{return new_(Bool_.Y, page, w, h);}
    +	public static Xof_orig_arg new_wiki(String page, int w, int h)						{return new_(Bool_.N, page, w, h);}
    +	public static Xof_orig_arg new_wiki_redirect(String src, String trg)				{return new_(Bool_.N, src, 440, 400, trg);}
    +	public static Xof_orig_arg new_comm_redirect(String src, String trg)				{return new_(Bool_.Y, src, 440, 400, trg);}
    +	private static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h)	{return new_(repo_is_commons, page, w, h, null);}
    +	public static Xof_orig_arg new_(boolean repo_is_commons, String page, int w, int h, String redirect_str) {
    +		byte repo = repo_is_commons ? Xof_repo_tid_.Tid__remote : Xof_repo_tid_.Tid__local;
    +		byte[] redirect = redirect_str == null ? Bry_.Empty : Bry_.new_u8(redirect_str);
    +		return new Xof_orig_arg(repo, Bry_.new_u8(page), w, h, redirect);
    +	}
    +}
    +class Xof_fsdb_arg {
    +	Xof_fsdb_arg(byte[] wiki, byte[] ttl, boolean is_thumb, int ext, int w, int h, int time, byte[] bin) {
    +		this.wiki = wiki; this.ttl = ttl; this.is_thumb = is_thumb; this.w = w; this.h = h; this.time = time; this.ext = ext; this.bin = bin;
    +	}
    +	public byte[] Wiki() {return wiki;} private final    byte[] wiki;
    +	public byte[] Ttl() {return ttl;} private final    byte[] ttl;
    +	public int Ext() {return ext;} private final    int ext;
    +	public boolean Is_thumb() {return is_thumb;} private final    boolean is_thumb;
    +	public int W() {return w;} private final    int w;
    +	public int H() {return h;} private final    int h;
    +	public double Time() {return time;} private final    double time;
    +	public int Page() {return page;} private final    int page = Xof_lnki_page.Null;
    +	public byte[] Bin() {return bin;} private final    byte[] bin;
    +	public DateAdp Modified() {return modified;} private final    DateAdp modified = Fsd_thm_tbl.Modified_null;
    +	public String Hash() {return hash;} private final    String hash = Fsd_thm_tbl.Hash_null;
    +	public static Xof_fsdb_arg new_comm_file(String ttl)						{return new_(Xow_domain_itm_.Bry__commons, Bool_.N, ttl, Xof_img_size.Null, Xof_img_size.Null, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_comm_thumb(String ttl)						{return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, W_default, H_default, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h)			{return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_comm_thumb(String ttl, int w, int h, int s)	{return new_(Xow_domain_itm_.Bry__commons, Bool_.Y, ttl, w, h, s);}
    +	public static Xof_fsdb_arg new_comm_orig(String ttl, int w, int h)			{return new_(Xow_domain_itm_.Bry__commons, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_comm(boolean thumb, String ttl, int w, int h)	{return new_(Xow_domain_itm_.Bry__commons, thumb, ttl, w, h, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_wiki_thumb(String ttl, int w, int h)			{return new_(Xow_domain_itm_.Bry__enwiki, Bool_.Y, ttl, w, h, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_wiki_orig(String ttl, int w, int h)			{return new_(Xow_domain_itm_.Bry__enwiki, Bool_.N, ttl, w, h, Xof_lnki_time.Null_as_int);}
    +	public static Xof_fsdb_arg new_(byte[] wiki, boolean is_thumb, String ttl_str, int w, int h, int time) {
    +		byte[] ttl = Bry_.new_u8(ttl_str);
    +		int ext = Xof_ext_.new_by_ttl_(ttl).Id();
    +		String bin_str = ext == Xof_ext_.Id_svg ? file_svg_(w, h) : file_img_(w, h);
    +		byte[] bin = Bry_.new_a7(bin_str);
    +		return new Xof_fsdb_arg(wiki, ttl, is_thumb, ext, w, h, time, bin);
    +	}
    +	private static final int W_default = 220, H_default = 200;
    +	private static String file_img_(int w, int h) {return String_.Format("{0},{1}", w, h);}
    +	private static String file_svg_(int w, int h) {return String_.Format("", w, h);}
    +}
    +class Xof_exec_arg {
    +	public byte[] Ttl() {return ttl;} private byte[] ttl;
    +	public byte Lnki_type() {return lnki_type;} private byte lnki_type = Xop_lnki_type.Id_thumb;
    +	public int Lnki_w() {return lnki_w;} private int lnki_w;
    +	public int Lnki_h() {return lnki_h;} private int lnki_h = Xop_lnki_tkn.Height_null;
    +	public double Lnki_upright() {return lnki_upright;} public Xof_exec_arg Lnki_upright_(double v) {lnki_upright = v; return this;} private double lnki_upright = Xop_lnki_tkn.Upright_null;
    +	public int Lnki_time() {return lnki_time;} public Xof_exec_arg Lnki_time_(int v) {lnki_time = v; return this;} private int lnki_time = Xof_lnki_time.Null_as_int;
    +	public int Lnki_page() {return lnki_page;} public Xof_exec_arg Lnki_page_(int v) {lnki_page = v; return this;} private int lnki_page = Xof_lnki_page.Null;
    +	public int Exec_tid() {return exec_tid;} public Xof_exec_arg Exec_tid_(int v) {exec_tid = v; return this;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
    +	public byte Rslt_orig_exists() {return rslt_orig_exists;} private byte rslt_orig_exists = Bool_.__byte;
    +	public byte Rslt_file_exists() {return rslt_file_exists;} private byte rslt_file_exists = Bool_.__byte;
    +	public byte Rslt_file_resized() {return rslt_file_resized;} private byte rslt_file_resized = Bool_.__byte;
    +	public boolean Lnki_type_is_thumb() {return Xop_lnki_type.Id_defaults_to_thumb(lnki_type);}
    +	public Xof_exec_arg Rslt_orig_exists_n()	{rslt_orig_exists = Bool_.N_byte; return this;}
    +	public Xof_exec_arg Rslt_orig_exists_y()	{rslt_orig_exists = Bool_.Y_byte; return this;}
    +	public Xof_exec_arg Rslt_file_exists_n()	{rslt_file_exists = Bool_.N_byte; return this;}
    +	public Xof_exec_arg Rslt_file_exists_y()	{rslt_file_exists = Bool_.Y_byte; return this;}
    +	public Xof_exec_arg Rslt_file_resized_n()	{rslt_file_resized = Bool_.N_byte; return this;}
    +	public Xof_exec_arg Rslt_file_resized_y()	{rslt_file_resized = Bool_.Y_byte; return this;}
    +	public static Xof_exec_arg new_thumb(String ttl)					{return new_(ttl, Xop_lnki_type.Id_thumb, 220, Xop_lnki_tkn.Height_null);}
    +	public static Xof_exec_arg new_thumb(String ttl, int w)				{return new_(ttl, Xop_lnki_type.Id_thumb, w, Xop_lnki_tkn.Height_null);}
    +	public static Xof_exec_arg new_thumb(String ttl, int w, int h)		{return new_(ttl, Xop_lnki_type.Id_thumb, w, h);}
    +	public static Xof_exec_arg new_orig(String ttl)						{return new_(ttl, Xop_lnki_type.Id_null, Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null);}
    +	public static Xof_exec_arg new_(String ttl, byte type, int w, int h) {
    +		Xof_exec_arg rv = new Xof_exec_arg();
    +		rv.ttl = Bry_.new_u8(ttl);
    +		rv.lnki_type = type;
    +		rv.lnki_w = w;
    +		rv.lnki_h = h;
    +		return rv;
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_redirect_tst.java b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_redirect_tst.java
    new file mode 100644
    index 000000000..dc2bdefda
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/fsdb/tsts/Xof_file_redirect_tst.java
    @@ -0,0 +1,64 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import org.junit.*;
    +public class Xof_file_redirect_tst {
    +	@Before public void init() {fxt.Reset();} private final Xof_file_fxt fxt = new Xof_file_fxt();
    +	@After public void term() {fxt.Rls();}
    +	@Test  public void Same_wiki_orig_copy() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/enwiki/orig/7/0/A.png", "440,400");
    +	}
    +	@Test  public void Same_wiki_thumb_copy() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_thumb("A.png", 220, 200));
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
    +	}
    +	@Test  public void Same_wiki_thumb_make() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_wiki_orig("A.png", 440, 400));
    +		fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
    +		fxt.Exec_get(Xof_exec_arg.new_thumb("B.png", 220).Rslt_file_exists_y().Rslt_file_resized_y());
    +		fxt.Test_fsys("mem/root/enwiki/thumb/7/0/A.png/220px.png", "220,200");
    +	}
    +	@Test  public void Diff_wiki_orig_copy() {
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm("A.png", 440, 400));
    +		fxt.Init_fsdb_db(Xof_fsdb_arg.new_comm_orig("A.png", 440, 400));
    +		fxt.Init_orig_db(Xof_orig_arg.new_comm_redirect("B.png", "A.png"));
    +		fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_file_exists_y());
    +		fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
    +	}
    +//		@Test  public void Cross_wiki() {
    +//			fxt.Init__orig_w_fsdb__commons_orig("A.png", 440, 400);
    +//			fxt.Init_orig_db(Xof_orig_arg.new_wiki_redirect("B.png", "A.png"));
    +//			fxt.Exec_get(Xof_exec_arg.new_orig("B.png").Rslt_fsdb_xowa());
    +//			fxt.Test_fsys("mem/root/common/orig/7/0/A.png", "440,400");
    +
    +//			fxt	.ini_page_create_en_wiki_redirect	("File:B.png", "File:A.png");
    +//			fxt	.ini_page_create_commons			("File:A.png");
    +//			fxt	.Lnki_orig_("B.png")
    +//				.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
    +//				.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +//					,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv"		, "B.png|y|A.png|1?900,800|")
    +//					);
    +//			fxt.tst();
    +//		}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/origs/Xof_orig_tbl_tst.java b/400_xowa/src/gplx/xowa/files/origs/Xof_orig_tbl_tst.java
    new file mode 100644
    index 000000000..83f946284
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/origs/Xof_orig_tbl_tst.java
    @@ -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.xowa.files.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*;
    +import gplx.dbs.*; import gplx.xowa.*;
    +import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
    +import gplx.xowa.parsers.lnkis.*;
    +public class Xof_orig_tbl_tst {
    +	@Before public void init() {fxt.Clear();} private Xof_orig_tbl_fxt fxt = new Xof_orig_tbl_fxt();
    +	@Test   public void Select_in() {
    +		Xof_orig_itm itm_1 = fxt.Exec_insert("A.png", 220, 330);
    +		fxt.Exec_insert("B.png", 220, 330);
    +		Xof_orig_itm itm_3 = fxt.Exec_insert("C.png", 220, 330);
    +		fxt.Test_select_in(String_.Ary("A.png", "C.png"), itm_1, itm_3);
    +	}
    +}
    +class Xof_orig_tbl_fxt {
    +	private Xof_orig_tbl tbl;
    +	public void Clear() {
    +		Io_url test_url = Io_url_.mem_fil_("mem/file/en.wikipedia.org/file/orig_regy");
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		Db_conn conn = Db_conn_bldr.Instance.New(test_url);
    +		tbl = new Xof_orig_tbl(conn, Bool_.Y);
    +		tbl.Create_tbl();
    +	}
    +	public Xof_orig_itm Exec_insert(String ttl, int w, int h) {
    +		byte[] ttl_bry = Bry_.new_u8(ttl);
    +		Xof_orig_itm rv = new Xof_orig_itm(Xof_orig_itm.Repo_comm, ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
    +		tbl.Insert(rv.Repo(), rv.Ttl(), rv.Ext_id(), rv.W(), rv.H(), rv.Redirect());
    +		return rv;
    +	}
    +	public void Test_select_in(String[] itms, Xof_orig_itm... expd) {
    +		Ordered_hash rv = Ordered_hash_.New();
    +		List_adp list = List_adp_.New();
    +		int itms_len = itms.length;
    +		for (int i = 0; i < itms_len; ++i) {
    +			String itm = itms[i];
    +			Xof_fsdb_itm fsdb_itm = new Xof_fsdb_itm();
    +			fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_a7("en.w"), Bry_.new_u8(itm), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null, Xof_lnki_time.Null, Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
    +			list.Add(fsdb_itm);
    +		}
    +		tbl.Select_by_list(rv, list);
    +		Tfds.Eq_str_lines(To_str_ary(expd), To_str_ary((Xof_orig_itm[])rv.To_ary(Xof_orig_itm.class)));
    +	}
    +	private static String To_str_ary(Xof_orig_itm... ary) {
    +		Bry_bfr bfr = Bry_bfr_.Reset(255);
    +		int len = ary.length;
    +		for (int i = 0; i < len; ++i) {
    +			Xof_orig_itm itm = ary[i];
    +			bfr	.Add_byte(itm.Repo()).Add_byte_pipe()
    +				.Add(itm.Ttl()).Add_byte_pipe()
    +				.Add_int_variable(itm.Ext_id()).Add_byte_pipe()
    +				.Add_int_variable(itm.W()).Add_byte_pipe()
    +				.Add_int_variable(itm.H()).Add_byte_pipe()
    +				.Add(itm.Redirect()).Add_byte_pipe()
    +				;
    +			bfr.Add_byte_nl();
    +		}
    +		return bfr.To_str_and_clear();
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/repos/Xof_repo_itm__tst.java b/400_xowa/src/gplx/xowa/files/repos/Xof_repo_itm__tst.java
    new file mode 100644
    index 000000000..1e5afbe6c
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/repos/Xof_repo_itm__tst.java
    @@ -0,0 +1,56 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.repos; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.core.tests.*;
    +import gplx.core.envs.*;
    +import gplx.xowa.apps.fsys.*;
    +import gplx.xowa.files.exts.*;
    +public class Xof_repo_itm__tst {
    +	private final    Xof_repo_itm__fxt fxt = new Xof_repo_itm__fxt();
    +	@Test 	public void Gen_name_trg__long() {
    +		// make a windows repo with a long directory name
    +		Xof_repo_itm repo = fxt.Make__repo(Op_sys.Wnt.Os_name(), "C:\\xowa0123456789", "commons.wikimedia.org");
    +
    +		// mark it as wnt repo and reduce max ttl_len from 160 to 99 for shorter test vars
    +		repo.Fsys_is_wnt_(true).Url_max_len_(99);
    +
    +		// short: full name
    +		fxt.Test__gen_name_trg(repo, "A.png", "A.png");
    +
    +		// long: truncated_ttl + md5
    +		fxt.Test__gen_name_trg(repo, "0123456789012345678901234567890123456789.png", "0123456789_965d037bf686058361510201be299ed4.png");
    +
    +		// extremely long; md5 only
    +		repo.Root_str_("C:\\xowa012345678901234567890123456789");
    +		fxt.Test__gen_name_trg(repo, "0123456789012345678901234567890123456789.png", "965d037bf686058361510201be299ed4.png");
    +	}
    +}
    +class Xof_repo_itm__fxt {
    +	private final    Bry_bfr tmp_bfr = Bry_bfr_.New();
    +	public Xof_repo_itm Make__repo(String plat_name, String root_dir_str, String wiki_domain) {
    +		String key = "test_repo";
    +		Io_url root_dir = Io_url_.new_dir_(root_dir_str);
    +		Xoa_fsys_mgr fsys_mgr = Xoa_fsys_mgr.New_by_plat(plat_name, root_dir);
    +		Xof_repo_itm repo = new Xof_repo_itm(Bry_.new_u8(key), fsys_mgr, new Xof_rule_mgr(), Bry_.new_u8(wiki_domain));
    +		repo.Root_str_(root_dir.Raw());
    +		return repo;
    +	}
    +	public void Test__gen_name_trg(Xof_repo_itm repo, String ttl_str, String expd) {
    +		byte[] ttl_bry = Bry_.new_u8(ttl_str);
    +		byte[] md5 = Xof_file_wkr_.Md5(ttl_bry);
    +		Gftest.Eq__str(expd, repo.Gen_name_trg(tmp_bfr, ttl_bry, md5, Xof_ext_.new_by_ttl_(ttl_bry)));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_base_fxt.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_base_fxt.java
    new file mode 100644
    index 000000000..397b80e10
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_base_fxt.java
    @@ -0,0 +1,113 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import gplx.core.ios.*;
    +import gplx.xowa.wikis.domains.*;
    +import gplx.xowa.files.cnvs.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.imgs.*;
    +import gplx.xowa.apps.wms.apis.*; import gplx.xowa.apps.wms.apis.origs.*;	
    +public class Xof_xfer_queue_base_fxt {
    +	public Xoapi_orig_mok Api_size() {return api_size;} private Xoapi_orig_mok api_size = Xoapi_orig_mok.Instance;
    +	public Xof_repo_itm Src_commons_repo() {return src_commons_repo;} private Xof_repo_itm src_commons_repo;
    +	public Xof_repo_itm Src_en_wiki_repo() {return src_en_wiki_repo;} private Xof_repo_itm src_en_wiki_repo;
    +	@gplx.Virtual public void Clear(boolean src_repo_is_wmf) {
    +		Io_mgr.Instance.InitEngine_mem();
    +		if (app == null) {
    +			app = Xoa_app_fxt.Make__app__edit();
    +			en_wiki = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__enwiki);
    +			commons = Xoa_app_fxt.Make__wiki__edit(app, Xow_domain_itm_.Str__commons);
    +			app.Wiki_mgr().Add(commons);
    +			app.Wiki_mgr().Add(en_wiki);
    +			
    +			Xof_file_mgr file_mgr = app.File_mgr();
    +			file_mgr.Img_mgr().Wkr_resize_img_(Xof_img_wkr_resize_img_mok.Instance);
    +			file_mgr.Img_mgr().Wkr_query_img_size_(new Xof_img_wkr_query_img_size_test());
    +			app.Wmf_mgr().Api_mgr().Api_orig_(api_size);
    +
    +			byte[] src_commons = Bry_.new_a7("src_commons");
    +			byte[] src_en_wiki = Bry_.new_a7("src_en_wiki");
    +			byte[] trg_commons = Bry_.new_a7("trg_commons");
    +			byte[] trg_en_wiki = Bry_.new_a7("trg_en_wiki");
    +			src_commons_repo = Ini_repo_add(file_mgr, src_commons, "mem/src/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, false);
    +			src_en_wiki_repo = Ini_repo_add(file_mgr, src_en_wiki, "mem/src/en.wikipedia.org/"		, Xow_domain_itm_.Str__enwiki, false);
    +			Ini_repo_add(file_mgr, trg_commons, "mem/trg/commons.wikimedia.org/", Xow_domain_itm_.Str__commons, true).Primary_(true);
    +			Ini_repo_add(file_mgr, trg_en_wiki, "mem/trg/en.wikipedia.org/"		, Xow_domain_itm_.Str__enwiki, true).Primary_(true);
    +			Xowe_repo_mgr wiki_repo_mgr = en_wiki.File_mgr().Repo_mgr();
    +			Xof_repo_pair pair = null;
    +			pair = wiki_repo_mgr.Add_repo(src_commons, trg_commons);
    +			pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf).Tarball_(!src_repo_is_wmf);
    +			pair.Trg().Fsys_is_wnt_(true);
    +
    +			pair = wiki_repo_mgr.Add_repo(src_en_wiki, trg_en_wiki);
    +			pair.Src().Fsys_is_wnt_(true).Wmf_fsys_(src_repo_is_wmf);
    +			pair.Trg().Fsys_is_wnt_(true);
    +		}
    +		en_wiki.Clear_for_tests();
    +		commons.Clear_for_tests();
    +		src_fils = trg_fils = Io_fil.Ary_empty;
    +		html_view_str = null;
    +		html_w = html_h = -1;
    +	}
    +	public Xoae_app App() {return app;} private Xoae_app app;
    +	public Xowe_wiki En_wiki() {return en_wiki;} private Xowe_wiki en_wiki;
    +	public Xowe_wiki Commons() {return commons;} private Xowe_wiki commons;
    +	public void ini_page_create_commons(String ttl)								{Init_page_create(commons, ttl, "");}
    +	public void ini_page_create_commons_redirect(String ttl, String redirect)	{Init_page_create(commons, ttl, "#REDIRECT [[" + redirect + "]]");}
    +	public void ini_page_create_en_wiki(String ttl)								{Init_page_create(en_wiki, ttl, "");}
    +	public void ini_page_create_en_wiki_redirect(String ttl, String redirect)	{Init_page_create(en_wiki, ttl, "#REDIRECT [[" + redirect + "]]");}
    +	public void Init_page_create(Xowe_wiki wiki, String ttl, String txt) {
    +		Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl));
    +		byte[] page_raw = Bry_.new_u8(txt);
    +		wiki.Db_mgr().Save_mgr().Data_create(wiki, page_ttl, page_raw);
    +	}
    +	Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) {
    +		Xof_repo_itm repo = file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
    +		if (trg) {
    +			byte[][] ary = repo.Mode_names();
    +			ary[0] = Bry_.new_a7("raw");
    +			ary[1] = Bry_.new_a7("fit");
    +		}
    +		return repo;
    +	}
    +	public Xof_xfer_queue_base_fxt Src_base(Io_fil... v) {src_fils = v; return this;} Io_fil[] src_fils = Io_fil.Ary_empty;
    +	public Xof_xfer_queue_base_fxt Trg_base(Io_fil... v) {trg_fils = v; return this;} Io_fil[] trg_fils = Io_fil.Ary_empty;
    +	public String Html_view_src() {return html_view_str;} protected Xof_xfer_queue_base_fxt Html_src_base_(String v) {html_view_str = v; return this;} private String html_view_str;
    +	public int Html_w() {return html_w;} public Xof_xfer_queue_base_fxt Html_w_(int v) {html_w = v; return this;} private int html_w = -1;
    +	public int Html_h() {return html_h;} public Xof_xfer_queue_base_fxt Html_h_(int v) {html_h = v; return this;} private int html_h = -1;
    +	public void ini_src_fils() {
    +		if (src_fils != null) {
    +			for (int i = 0; i < src_fils.length; i++) {
    +				Io_fil src_fil = src_fils[i];
    +				Io_mgr.Instance.SaveFilStr(src_fil.Url(), src_fil.Data());
    +			}
    +		}
    +	}
    +	public void tst_trg_fils() {
    +		for (int i = 0; i < trg_fils.length; i++) {
    +			Io_fil trg_fil = trg_fils[i];
    +			String data = Io_mgr.Instance.LoadFilStr(trg_fil.Url());
    +			Tfds.Eq_str_lines(trg_fil.Data(), data, trg_fil.Url().Raw());
    +		}		
    +	}
    +	public void	 save_(Io_fil v)						{Io_mgr.Instance.SaveFilStr(v.Url(), v.Data());}
    +	public Io_fil reg_(String url, String... v)	{return new Io_fil(Io_url_.mem_fil_(url), String_.Concat_lines_nl(v));}
    +	public Io_fil img_(String url_str, int w, int h)	{return file_(url_str, file_img(w, h));}
    +	public Io_fil svg_(String url_str, int w, int h)	{return file_(url_str, file_svg(w, h));}
    +	public Io_fil ogg_(String url_str)					{return file_(url_str, "");}
    +	public void fil_absent(String url)					{Tfds.Eq_false(Io_mgr.Instance.ExistsFil(Io_url_.mem_fil_(url)), "fil should not exist: {0}", url);}
    +	Io_fil file_(String url_str, String data)			{return new Io_fil(Io_url_.mem_fil_(url_str), data);}
    +	String file_img(int w, int h) {return String_.Format("{0},{1}", w, h);}
    +	String file_svg(int w, int h) {return String_.Format("", w, h);}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_basic_tst.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_basic_tst.java
    new file mode 100644
    index 000000000..4ee963715
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_basic_tst.java
    @@ -0,0 +1,132 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*;
    +import gplx.core.ios.*; import gplx.gfui.*; import gplx.xowa.files.*;
    +public class Xof_xfer_queue_html_basic_tst {
    +	Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
    +	@Before public void init() {fxt.Clear(true);}
    +	@Test  public void Main_orig() {
    +		fxt	.ini_page_create_en_wiki("File:A.png");
    +		fxt	.Lnki_orig_("A.png")
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?900,800|")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Main_thumb_download() {
    +		fxt	.ini_page_create_en_wiki("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 90)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?0,0|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Main_thumb_convert() {
    +		fxt	.ini_page_create_en_wiki("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 90)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?900,800|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Ptr_orig() {
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.ini_page_create_en_wiki_redirect	("File:B.png", "File:A.png");
    +		fxt	.Lnki_orig_("B.png")
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|1?900,800|")
    +				);
    +		fxt.tst();
    +		fxt	.Lnki_orig_("B.png")
    +			.Html_src_("file:///mem/trg/en.wikipedia.org/raw/7/0/A.png")
    +			.tst();
    +	}
    +	@Test  public void Ptr_thumb_download() {
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.ini_page_create_en_wiki_redirect	("File:B.png", "File:A.png");
    +		fxt	.Lnki_thumb_("B.png", 90)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|2?0,0|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Ptr_thumb_convert() {
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.ini_page_create_en_wiki_redirect	("File:B.png", "File:A.png");
    +		fxt	.Lnki_thumb_("B.png", 90)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|1?900,800|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Vrtl_orig() {
    +		fxt	.ini_page_create_commons			("File:A.png");
    +		fxt	.Lnki_orig_("A.png")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|0||1?900,800|")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Vrtl_thumb_download() {
    +		fxt	.ini_page_create_commons			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 90)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|0||2?0,0|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Vrtl_thumb_convert() {
    +		fxt	.ini_page_create_commons			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 90)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|0||1?900,800|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Vrtl_ptr_orig() {
    +		fxt	.ini_page_create_commons_redirect	("File:B.png", "File:A.png");
    +		fxt	.ini_page_create_commons			("File:A.png");
    +		fxt	.Lnki_orig_("B.png")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv"		, "B.png|0|A.png|1?900,800|")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Ptr_vrtl_orig() {
    +		fxt	.ini_page_create_en_wiki_redirect	("File:B.png", "File:A.png");
    +		fxt	.ini_page_create_commons			("File:A.png");
    +		fxt	.Lnki_orig_("B.png")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv"		, "B.png|y|A.png|1?900,800|")
    +				);
    +		fxt.tst();
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_cases_tst.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_cases_tst.java
    new file mode 100644
    index 000000000..4d6534d3d
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_cases_tst.java
    @@ -0,0 +1,288 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*;
    +import gplx.xowa.files.*; import gplx.xowa.files.imgs.*;
    +public class Xof_xfer_queue_html_cases_tst {
    +	Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
    +	@Before public void init() {
    +		fxt.Clear(true);
    +	}
    +	@Test  public void Png_missing() {
    +		fxt	.Lnki_orig_("A.png")
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Png_missing_2() {	// PURPOSE: orig is missing; do not download again; NOTE: simulating "do not download again" check by putting in thumb and making sure it doesn't get downloaded
    +		fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|"));	// save reg file and mark file as missing
    +		fxt	.Lnki_thumb_("A.png", 90)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||0?0,0|")	// NOTE: 90,80 should not show up
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Png_encode() {	// PURPOSE: make sure \s is converted to _; also ' should not be encoded on trg; done
    +		fxt	.ini_page_create_commons			("File:A'b c.png");
    +		fxt	.Lnki_orig_("A'b c.png")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/9/9c/A%27b_c.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/9/c/A'b_c.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/9/9c.csv", "A'b_c.png|0||1?90,80|")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Ogg_vid_thumb() {
    +		fxt	.ini_page_create_commons			("File:A.ogg");
    +		fxt	.Lnki_orig_("A.ogg")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/4/42/A.ogg/-1px--A.ogg.jpg", 300, 40))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/4/2/A.ogg/300px.jpg", 300, 40)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|0||0?0,0|1?300,40")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Ogg_vid_missing_thumb() {
    +		fxt	.Lnki_orig_("A.ogg")
    +			.Src(	)
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||0?0,0|0?0,0")	// NOTE: mark thumb not found (since xfer_mgr checked all repos)
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Aud_do_not_download() {
    +		fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||2?0,0|0?0,0"));		// save reg file and mark file as aud
    +		fxt	.Lnki_orig_("A.ogg")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/4/42/A.ogg/mid-A.ogg.jpg", 300, 40)		// simulate thumb (make sure test does not download)
    +				)
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||2?0,0|0?0,0")		// 300,40 should not show up
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Img_thumb_djvu() {// PURPOSE: exact djvu thumbs are not on server; always seems to retrieve 1 off;
    +		fxt	.ini_page_create_commons			("File:A.djvu");
    +		fxt	.App().File_mgr().Img_mgr().Wkr_convert_djvu_to_tiff_(Xof_img_wkr_convert_djvu_to_tiff_.new_mok(199, 299));
    +		fxt	.Lnki_thumb_("A.djvu", 200)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/76/A.djvu", 1990, 2990)
    +				)
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/7/6/A.djvu/199px.jpg", 199, 299)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/76.csv", "A.djvu|0||1?0,0|1?199,299")
    +				);
    +		fxt.tst();
    +		fxt	.Lnki_thumb_("A.djvu", 200)
    +			.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/7/6/A.djvu/199px.jpg")
    +			.Html_size_(200, 301)
    +			.tst();
    +	}
    +	@Test  public void Img_thumb_pdf() {// PURPOSE: download pdf thumb only; [[File:Physical world.pdf|thumb]]
    +		fxt	.ini_page_create_commons			("File:A.pdf");
    +		fxt	.Lnki_thumb_("A.pdf", 220)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/e/ef/A.pdf", 2200, 1700)
    +				,	fxt.img_("mem/src/commons.wikimedia.org/thumb/e/ef/A.pdf/page1-220px-A.pdf.jpg", 220, 170)
    +				)
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/e/f/A.pdf/220px.jpg", 220, 170)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/e/ef.csv", "A.pdf|0||2?0,0|1?220,170")
    +				);
    +		fxt.tst();
    +		fxt	.Lnki_thumb_("A.pdf", 220)
    +			.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/e/f/A.pdf/220px.jpg")
    +			.Html_size_(220, 170)
    +			.tst();
    +	}
    +	@Test  public void Img_missing_wiki_0() {	// PURPOSE.outlier: page is in wiki_1 but file is actually in wiki_0; download from wiki_0; occurs when working with old commons/en.wikipedia.org against current wmf servers; EX: Mars Science Laboratory and File:Curiosity wheel pattern morse code.png; Curiosity rover
    +		fxt	.ini_page_create_en_wiki			("File:A.png");							// page is in en_wiki
    +		fxt	.Lnki_orig_("A.png")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/7/70/A.png", 900, 800))		// file is in commons
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/7/0/A.png", 900, 800)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||1?900,800|")
    +				);
    +		fxt.tst();
    +	}
    +//		@Test  public void Img_missing_wiki_1() {	// PURPOSE.outlier: page is in wiki_0 and in wiki_1; file is in wiki_1; EX:[[Image:Alcott-L.jpg|thumb|right|Louisa May Alcott]]
    +//			fxt	.ini_page_create_commons			("File:A.png");														// page is in commons also
    +//			fxt	.ini_page_create_en_wiki			("File:A.png");														// page is in en_wiki
    +//			fxt	.Lnki_thumb_("A.png", 220)
    +//				.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 110))					// file is in en_wiki
    +//				.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 110)							// download en_wiki
    +//					,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "2|A.png|y||2?0,0|1?220,110")
    +//					);
    +//			fxt.tst();
    +//		}
    +	@Test  public void Do_not_download_orig_0() {// PURPOSE: do not download orig if size can be inferred from thumb; EX: [[File:Vanadium etched.jpg|350x250px|Vanadium]]
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 350, 250)																			// requesting w=350 and h=250; note that h trumps w
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/350px-A.png", 350, 309)						// w=350 exists, but should not be used
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/283px-A.png", 283, 250)						// h=250 exists, and should be used
    +				,	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3808, 3364)										// orig image exists, and should not be downloaded
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/283px.png"		, 283, 250)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?283,250")	// note that orig does not exist
    +				);
    +		fxt.tst();
    +		fxt.fil_absent(		 "mem/trg/en.wikipedia.org/raw/7/0/A.png");
    +		fxt	.Lnki_thumb_("A.png", 350, 250)
    +			.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/283px.png")
    +			.tst();
    +	}
    +	@Test  public void Do_not_download_orig_1() {// PURPOSE: allow variance of 1 for thumbs (rounding errors); EX:Image:President Woodrow Wilson portrait December 2 1912.jpg|US President Woodrow Wilson
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 120, 120)																			// requesting 120,120 (gallery default); note that h trumps w
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/120px-A.png", 120, 146)						// w=120 exists, but should not be used
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/99px-A.png",  99, 121)						// true width should be w=98, but b/c of rounding off of large 2976, getting 99 instead
    +				,	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 2976, 3623)										// orig image exists, and should not be downloaded
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/99px.png"		, 99, 121)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?99,121")	// note that orig does not exist
    +				);
    +		fxt.tst();
    +		fxt.fil_absent(		 "mem/trg/en.wikipedia.org/raw/7/0/A.png");
    +		fxt	.Lnki_thumb_("A.png", 120, 120)																			// note that 120 is requested
    +			.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/99px.png")									// note that image used is 99
    +			.Html_size_(98, 120)																					// note that view width is 98
    +			.tst();
    +	}
    +	@Test  public void Do_not_download_orig_3() {// PURPOSE.defect: account for multiple thumbs; EX: File:Rembrandt van Rijn-De Nachtwacht-1642.jpg|1642.
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 454, 380)																			// standard request
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/454px-A.png", 454, 380)
    +				,	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3344, 2796)
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/454px.png"		, 454, 380)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?454,380")	// note that orig does not exist
    +				);
    +		fxt.tst();
    +		fxt.fil_absent(		 "mem/trg/en.wikipedia.org/raw/7/0/A.png");
    +		fxt	.Lnki_thumb_("A.png", 718, 600)																			// this is the defect; 718 was not being brought down; instead 454 was being reused
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/718px-A.png", 718, 600)
    +				,	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 3344, 2796)
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/718px.png"		, 718, 600)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?454,380;1?718,600")	// note that orig does not exist
    +				)
    +			.tst();
    +	}
    +	@Test  public void Do_not_download_orig_height() {// PURPOSE: handles links with only height specified; EX: [[File:Fresh_Pesto.jpeg|x210px|center]]
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", -1, 210)																			// height-only request
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/291px-A.png", 291, 210)
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 159)	
    +				,	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 2910, 2100)
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/291px.png"		, 291, 210)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?220,159;1?291,210")	// note that orig does not exist
    +				);
    +		fxt.tst();
    +		fxt	.Lnki_thumb_("A.png", -1, 210)																	
    +		.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/291px.png")									
    +		.Html_size_(291, 210)																					
    +		.tst();
    +	}
    +	@Test  public void Upright_size_incorrect() {// PURPOSE.fix: incorrect image size being brought down; EX: w:ASCII; [[Image:ASCII Code Chart.svg|thumb|right|upright=1.6]]; 264, but should be 350 
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_("A.png", true, -1, -1, 1.6, Xof_lnki_time.Null_as_int)											// upright
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 830, 328)
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/350px-A.png", 350, 138)	
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/350px.png"		, 350, 138)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?350,138")
    +				);
    +		fxt.tst();
    +	}
    +	@Test  public void Width_height_retrieves_wrong_size() {// PURPOSE.fix: EX: c:Yellowstone Park; [[Image:YellowstoneLake.jpg|Yellowstone Lake|120x120px|thumb]];
    +		fxt	.ini_page_create_en_wiki			("File:A.png");
    +		fxt	.Lnki_thumb_("A.png", 120, 120)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 1756, 1204)
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/120px-A.png", 119, 82)						// NOTE: wmf has 119px width, even though 120px file_name
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/119px.png"		, 119, 82)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?0,0|1?119,82")
    +				);
    +		fxt.tst();
    +		fxt	.Lnki_thumb_("A.png", 120, 120)																	
    +		.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/119px.png")
    +		.Html_size_(120, 83)
    +		.tst();
    +	}
    +	@Test  public void Svg_thumb_can_be_bigger_than_orig__convert() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
    +		fxt	.ini_page_create_en_wiki			("File:A.svg");
    +		fxt	.Lnki_thumb_("A.svg", 220)																					// thumb = 220
    +			.Src(	fxt.svg_("mem/src/en.wikipedia.org/7/75/A.svg", 110, 100)											// orig = 110
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png"		, 220, 200)							// thumb = 220; not limited to 110
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/75.csv"		, "A.svg|y||1?110,100|1?220,200")
    +				)
    +			.tst(
    +			);
    +		fxt	.Lnki_thumb_("A.svg", 220)																	
    +		.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png")
    +		.Html_size_(220, 200)
    +		.tst();
    +	}
    +	@Test  public void Ogv_width_seek_again_should_dirty() { // PURPOSE: outlier case wherein (a) downloading thumb then (b) downloading thumb seek; (b) does not dirty file since (a) exists; PAGE:en.w:Wikipedia
    +		fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogv).View_max_(0);
    +		Io_mgr.Instance.SaveFilStr("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||2?0,0|1?300,40\n");	// simulate (a)
    +		fxt	.Lnki_("A.ogv", true, -1, -1, -1, 5)															
    +		.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/d/d0/A.ogv/-1px-seek%3D5-A.ogv.jpg", 300, 40)	
    +				)
    +		.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px@5.jpg", 300, 40)
    +			,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||2?0,0|1?300,40@5")
    +			)
    +		.tst();
    +		fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogv).View_max_(-1);
    +	}
    +	@Test   public void Webm() {
    +		fxt	.ini_page_create_commons			("File:A.webm");
    +		fxt	.Lnki_thumb_("A.webm", 220)
    +		.Src(	fxt.ogg_("mem/src/commons.wikimedia.org/3/34/A.webm")
    +			,	fxt.img_("mem/src/commons.wikimedia.org/thumb/3/34/A.webm/220px--A.webm.jpg", 300, 40)	
    +				)
    +		.Trg(	fxt.ogg_("mem/trg/commons.wikimedia.org/raw/3/4/A.webm")
    +			,	fxt.img_("mem/trg/commons.wikimedia.org/fit/3/4/A.webm/300px.jpg", 300, 40)
    +			,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/3/34.csv", "A.webm|0||1?0,0|1?300,40")
    +			)
    +		.tst();
    +	}
    +	@Test  public void Ogv_thumb() {// d00d1d5019e37cc219a91a2f8ad47bfe
    +		fxt	.ini_page_create_commons			("File:A.ogv");
    +		fxt	.Lnki_orig_("A.ogv")
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/d/d0/A.ogv/-1px--A.ogv.jpg", 300, 40))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px.jpg", 300, 40)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/d/d0.csv", "A.ogv|0||0?0,0|1?300,40")
    +				)
    +			.tst();
    +		fxt	.Lnki_orig_("A.ogv")																	
    +		.Html_src_("file:///mem/trg/commons.wikimedia.org/fit/d/0/A.ogv/300px.jpg")
    +		.Html_size_(300, 40)
    +		.tst();
    +	}
    +	@Test  public void Thumbtime_ignored_if_non_media() { // PURPOSE: ignore thumbtime if not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0.02]] DATE:2014-07-22
    +		fxt	.ini_page_create_en_wiki("File:A.png");
    +		fxt	.Lnki_("A.png", true, 90, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, 2)	// thumbtime of 2 specified; will be ignored below
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?0,0|1?90,80")
    +				);
    +		fxt.tst();
    +	}
    +
    +//		@Test  public void Ogg_full_skip() {	// DISABLED: 2012-12-03; not sure about logic
    +//			fxt	.ini_page_create_commons			("File:A.ogg");
    +//			fxt .En_wiki().File_mgr().Repo_mgr().Repos_get_at(0).Src().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(0);		// set ogg to do not download
    +//			fxt	.Lnki_orig_("A.ogg")
    +//				.Src(	fxt.ogg_("mem/src/commons.wikimedia.org/4/2/A.ogg"))
    +//				.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "2|A.ogg|0|2?0,0|")
    +//					);
    +//			fxt.tst();
    +//			fxt .En_wiki().File_mgr().Repo_mgr().Repos_get_at(0).Src().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(1000);	// undo above
    +//		}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_fxt.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_fxt.java
    new file mode 100644
    index 000000000..e70307b88
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_fxt.java
    @@ -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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import gplx.core.primitives.*; import gplx.dbs.*;
    +import gplx.core.ios.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.files.*;
    +import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_xfer_queue_html_fxt extends Xof_xfer_queue_base_fxt {
    +	private final    Xof_xfer_queue queue = new Xof_xfer_queue();
    +	@Override public void Clear(boolean src_repo_is_wmf) {
    +		Db_conn_bldr.Instance.Reg_default_mem();
    +		super.Clear(src_repo_is_wmf);
    +		this.Api_size().Clear();
    +	}
    +	public Xof_xfer_queue_html_fxt Lnki_orig_ (String lnki_ttl)							{return Lnki_(lnki_ttl, Bool_.N, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
    +	public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w)				{return Lnki_(lnki_ttl, Bool_.Y, lnki_w, Xof_img_size.Size__neg1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
    +	public Xof_xfer_queue_html_fxt Lnki_thumb_(String lnki_ttl, int lnki_w, int lnki_h) {return Lnki_(lnki_ttl, Bool_.Y, lnki_w, lnki_h, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int);}
    +	public Xof_xfer_queue_html_fxt Lnki_(String lnki_ttl, boolean thumb, int lnki_w, int lnki_h, double upright, int seek_time) { // NOTE: only one xfer_itm; supports one Lnki_ per test only
    +		Xowe_wiki wiki = this.En_wiki();
    +		Xop_ctx ctx = wiki.Parser_mgr().Ctx();
    +		xfer_itm = wiki.Html_mgr().Html_wtr().Lnki_wtr().File_wtr().Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, ctx.Page(), queue, Bry_.new_u8(lnki_ttl), thumb ? Xop_lnki_type.Id_thumb : Xop_lnki_type.Id_null, upright, lnki_w, lnki_h, Xof_lnki_time.X_int(seek_time), Xof_lnki_page.Null, false);
    +		return this;
    +	}
    +	public Xof_file_itm Xfer_itm() {return xfer_itm;} private Xof_file_itm xfer_itm; 
    +	public Xof_xfer_queue_html_fxt Src(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Src_base(v);}
    +	public Xof_xfer_queue_html_fxt Trg(Io_fil... v) {return (Xof_xfer_queue_html_fxt)Trg_base(v);}
    +	public Xof_xfer_queue_html_fxt Html_src_(String v) {return (Xof_xfer_queue_html_fxt)Html_src_base_(v);}
    +	public Xof_xfer_queue_html_fxt Html_size_(int w, int h) {this.Html_w_(w); this.Html_h_(h); return this;}
    +	public Xof_xfer_queue_html_fxt Html_orig_src_(String v) {html_orig_src = v; return this;} private String html_orig_src;
    +	public Xof_xfer_queue_html_fxt ini_page_api(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h) {return ini_page_api(wiki_str, ttl_str, redirect_str, orig_w, orig_h, true);}
    +	public Xof_xfer_queue_html_fxt ini_page_api(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h, boolean pass) {
    +		String wiki_key = String_.Eq(wiki_str, "commons") ? Xow_domain_itm_.Str__commons : Xow_domain_itm_.Str__enwiki;
    +		this.Api_size().Ini(wiki_key, ttl_str, redirect_str, orig_w, orig_h, pass);
    +		return this;
    +	}
    +	@gplx.Virtual public void tst() {
    +		Xowe_wiki wiki = this.En_wiki();
    +		ini_src_fils();
    +		wiki.File_mgr().Cfg_download().Enabled_(true);
    +		queue.Exec(wiki, Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_a7("A"))));
    +		tst_trg_fils();
    +		if (this.html_orig_src   != null)	Tfds.Eq(this.html_orig_src  , xfer_itm.Html_orig_url().To_http_file_str());
    +		if (this.Html_view_src() != null)	Tfds.Eq(this.Html_view_src(), xfer_itm.Html_view_url().To_http_file_str());
    +		if (this.Html_w() != -1)			Tfds.Eq(this.Html_w(), xfer_itm.Html_w());
    +		if (this.Html_h() != -1)			Tfds.Eq(this.Html_h(), xfer_itm.Html_h());
    +		queue.Clear();
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_offline_tst.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_offline_tst.java
    new file mode 100644
    index 000000000..f44314cf1
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_offline_tst.java
    @@ -0,0 +1,28 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_xfer_queue_html_offline_tst {
    +	Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
    +	@Before public void init()		{fxt.Clear(true); fxt.Src_commons_repo().Tarball_(true); fxt.Src_en_wiki_repo().Tarball_(true);}
    +	@Test  public void Missing() {	// PURPOSE.fix: missing image was not being marked as missing; DATE:20121227
    +		fxt	.Lnki_("A.png", true, 220, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
    +			.Src()
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|x||0?0,0|")
    +				)
    +			.tst();
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_wmf_api_tst.java b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_wmf_api_tst.java
    new file mode 100644
    index 000000000..add7ec38f
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/files/xfers/Xof_xfer_queue_html_wmf_api_tst.java
    @@ -0,0 +1,171 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: 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.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
    +import org.junit.*; import gplx.xowa.parsers.lnkis.*;
    +public class Xof_xfer_queue_html_wmf_api_tst {
    +	private final    Xof_xfer_queue_html_fxt fxt = new Xof_xfer_queue_html_fxt();
    +	@Before public void init()		{
    +		gplx.core.ios.IoEngine_system.Web_access_enabled = true;	// NOTE: must set to true, else Wmf_api calls below will always return false
    +		fxt.Clear(true); fxt.Src_commons_repo().Wmf_api_(true); fxt.Src_en_wiki_repo().Wmf_api_(true);
    +	}
    +	@Test  public void Thumb() {
    +		fxt	.ini_page_api("en_wiki", "A.png", "", 2200, 2000);
    +		fxt	.Lnki_thumb_("A.png", 220)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 200)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||2?2200,2000|1?220,200")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Redirect() {
    +		fxt	.ini_page_api("en_wiki", "B.png", "A.png", 2200, 2000);
    +		fxt	.Lnki_thumb_("B.png", 220)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/220px.png", 220, 200)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/5/57.csv", "B.png|y|A.png|2?2200,2000|1?220,200")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Svg_thumb_can_be_bigger_than_orig__download() {// PURPOSE: svg thumbs allowed to exceed orig in size; EX: w:Portal:Music; [[File:Treble a.svg|left|160px]]
    +		fxt	.ini_page_api("en_wiki", "A.svg", "", 110, 100);															// put orig of 110,100 on server
    +		fxt	.Lnki_thumb_("A.svg", 220)																					// request 220
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/75/A.svg/220px-A.svg.png", 220, 200)						// thumb = 220
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png"		, 220, 200)							// thumb = 220
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/75.csv"		, "A.svg|y||2?110,100|1?220,200")
    +			)
    +			.tst();
    +		fxt	.Lnki_thumb_("A.svg", 220)																	
    +		.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/5/A.svg/220px.png")
    +		.Html_size_(220, 200)
    +		.tst();
    +	}
    +	@Test  public void Pdf() {// PURPOSE: main page always assumes size of 800x600; if actual size does not scale to 800x600, don't redownload; [[File:Physical world.pdf|thumb]]
    +		fxt.ini_page_api("en_wiki", "A.pdf", "", 6600, 5100);
    +		fxt	.ini_page_create_commons			("File:A.pdf");
    +		fxt	.Lnki_thumb_("A.pdf", 800, 600)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/e/ef/A.pdf", 6600, 5100)
    +				,	fxt.img_("mem/src/en.wikipedia.org/thumb/e/ef/A.pdf/page1-777px-A.pdf.jpg", 777, 600)
    +				)
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/e/f/A.pdf/777px.jpg", 777, 600)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/e/ef.csv", "A.pdf|y||2?6600,5100|1?777,600")
    +				)
    +			.tst();
    +		fxt	.Lnki_thumb_("A.pdf", 800, 600)
    +			.Html_src_("file:///mem/trg/en.wikipedia.org/fit/e/f/A.pdf/777px.jpg")
    +			.Html_size_(777, 600)
    +			.tst();
    +	}
    +	@Test  public void Upright_defect() {	// PURPOSE.fix: upright not working;  PAGE:en.w:Beethoven; [[File:Rudolf-habsburg-olmuetz.jpg|thumb|upright|]]; changed upright to = Upright_default; DATE:2014-05-23
    +		fxt	.ini_page_api("en_wiki", "A.png", "", 1378, 1829);
    +		fxt	.Lnki_("A.png", true, -1, -1, Xof_img_size.Upright_default_marker, Xof_lnki_time.Null_as_int)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/170px-A.png", 170, 226))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/170px.png", 170, 226)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?1378,1829|1?170,226")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Height_only() {	// PURPOSE.fix: height only was still using old infer-size code; EX:w:[[File:Upper and Middle Manhattan.jpg|x120px]]; DATE:2012-12-27
    +		fxt	.ini_page_api("en_wiki", "A.png", "", 12591, 1847);
    +		fxt	.Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/887px-A.png", 887, 130))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/887px.png", 887, 130)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?12591,1847|1?887,130")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Width_only_height_ignored() {// PURPOSE.fix: if height is not specified, do not recalc; needed when true scaled height is 150x151 but WM has 150x158; defect would discard 150x158; EX:[[File:Tokage_2011-07-15.jpg|150px]] simple.wikipedia.org/wiki/2011_Pacific_typhoon_season; DATE:2013-06-03
    +		fxt	.ini_page_api("en_wiki", "A.png", "", 4884, 4932);
    +		fxt	.Lnki_("A.png", true, 150, -1, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/7/70/A.png/150px-A.png", 150, 158))
    +			.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/7/0/A.png/150px.png", 150, 158)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|y||2?4884,4932|1?150,158")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Missing_was_not_being_marked() {	// PURPOSE.fix: missing image was not showing up as repo=x in meta; DATE:2013-01-10
    +		fxt	.Lnki_("A.png", false, -1, 130, Xop_lnki_tkn.Upright_null, Xof_lnki_time.Null_as_int)
    +			.Src()
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|x||0?0,0|")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Missing_was_not_redownloaded() {	// PURPOSE.fix: missing image was not being redownloaded; DATE:2013-01-26
    +		fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|x||0?0,0|"));			// mark file as missing
    +		fxt	.ini_page_api("en_wiki", "A.png", "", 220, 200);
    +		fxt.En_wiki().File_mgr().Cfg_download().Redownload_(Xof_cfg_download.Redownload_missing);			// redownload for missing
    +		fxt	.Lnki_orig_("A.png")
    +			.Src(	fxt.img_("mem/src/en.wikipedia.org/7/70/A.png", 220, 200))
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"		, "A.png|x||1?220,200|")// check that file shows up
    +				)
    +			.tst();
    +		fxt.En_wiki().File_mgr().Cfg_download().Redownload_(Xof_cfg_download.Redownload_none);				// redownload back to none (for other tests)
    +	}
    +	@Test  public void Error_should_not_abort() {	// PURPOSE: API sometimes returns xml but no  node; try to download anyway
    +		fxt	.ini_page_api("commons", "A.png", "", 2200, 2000, false);
    +		fxt	.Lnki_thumb_("A.png", 220)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/220px-A.png", 220, 200))
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0||0?0,0|1?220,200")
    +				)
    +			.tst();
    +	}
    +	@Test   public void Tilde() {
    +		fxt	.ini_page_api("en_wiki", "A~.png", "", 2200, 2000);
    +		fxt	.Lnki_thumb_("A~.png", 220)
    +		.Src(	fxt.img_("mem/src/en.wikipedia.org/thumb/a/a5/A%7E.png/220px-A%7E.png", 220, 200))
    +		.Trg(	fxt.img_("mem/trg/en.wikipedia.org/fit/a/5/A~.png/220px.png", 220, 200)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/a/a5.csv", "A~~.png|y||2?2200,2000|1?220,200")	// NOTE: tildes are doubled in meta file
    +				)
    +				.tst();
    +	}
    +	@Test  public void Missing_from_1st_repo() {	// PURPOSE: WMF now requires that API goes to image's actual repo (used to accept http://en.wikipedia.org and return back http://commons.wikimedia.org) DATE:2013-03-11
    +		fxt	.ini_page_api("commons", "A.png", "B.png", 2200, 2000);	// put the redirect in commons wiki
    +		fxt	.Lnki_thumb_("A.png", 220)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/5/57/B.png/220px-B.png", 220, 200))
    +			.Trg(	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0|B.png|2?2200,2000|1?220,200")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Ogg_audio() {	// PURPOSE: ogg is audio; (a) do not download thumb; (b) get from correct wiki;  DATE:2013-08-03
    +		fxt	.ini_page_create_commons("File:A.ogg");
    +		fxt	.ini_page_api("commons", "A.ogg", "", 0, 0);
    +		fxt	.Lnki_("A.ogg", false, -1, -1, 1, Xof_lnki_time.Null_as_int)
    +			.Src(	fxt.img_("mem/src/commons.wikimedia.org/4/42/A.ogg", 0, 0))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/raw/4/2/A.ogg", 0, 0)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv"		, "A.ogg|0||1?0,0|0?0,0")
    +				)
    +			.tst();
    +	}
    +	@Test  public void Height_should_precede_width() {// PURPOSE: height should precede width; EX: David_Self_Portrait.jpg; c:Jacques-Louis David
    +		fxt.save_(fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|z||2?0,0|1?86,121;1?120,168"));
    +		fxt	.Lnki_thumb_("A.png", 120, 120)
    +		.Html_src_("file:///mem/trg/en.wikipedia.org/fit/7/0/A.png/86px.png")	
    +		.Html_size_(85, 120)
    +		.tst();
    +	}
    +	@Test  public void Imap() { // PURPOSE: check that imap downloads orig, even when thumb is requested; DATE:2014-08-08
    +		fxt	.ini_page_create_commons("File:A.png");
    +		fxt	.ini_page_api("commons", "A.png", "", 180, 160);
    +		fxt	.Lnki_("A.png", true, 90, Xof_img_size.Size__neg1, Xof_img_size.Size__neg1, Xof_lnki_time.Null_as_int);	// thumbtime of 2 specified; will be ignored below
    +		fxt	.Xfer_itm().Html_elem_tid_(Xof_html_elem.Tid_imap);
    +		fxt	.Src(	fxt.img_("mem/src/commons.wikimedia.org/thumb/7/70/A.png/90px-A.png", 90, 80))
    +			.Trg(	fxt.img_("mem/trg/commons.wikimedia.org/fit/7/0/A.png/90px.png", 90, 80)
    +				,	fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|0||2?180,160|1?90,80")	// check that orig has 180,160, not 0,0
    +				);
    +		fxt.tst();
    +	}
    +}
    +
    diff --git a/400_xowa/src/gplx/xowa/guis/cbks/swts/Gfobj_wtr__json__browser__tst.java b/400_xowa/src/gplx/xowa/guis/cbks/swts/Gfobj_wtr__json__browser__tst.java
    new file mode 100644
    index 000000000..6fed5e652
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/cbks/swts/Gfobj_wtr__json__browser__tst.java
    @@ -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.guis.cbks.swts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
    +import org.junit.*; import gplx.core.tests.*;
    +import gplx.core.gfobjs.*;
    +public class Gfobj_wtr__json__browser__tst {
    +	private final    Gfobj_wtr__json__browser__fxt fxt = new Gfobj_wtr__json__browser__fxt();
    +	@Test   public void Json_proc() {
    +		fxt.Test__json_proc 
    +		( "proc_name"
    +		, fxt.Make__nde
    +		(   fxt.Make__fld_str	("k1", "v1")
    +		,   fxt.Make__fld_long	("k2", 2)
    +		,   fxt.Make__fld_int	("k3", 3)
    +		)
    +		, "return proc_name('{\"k1\":\"v1\",\"k2\":2,\"k3\":3}');"
    +		);
    +	}
    +}
    +class Gfobj_wtr__json__browser__fxt extends Gfobj_wtr__json_fxt {		public Gfobj_wtr__json__browser__fxt Test__json_proc() {return this;}
    +	public void Test__json_proc(String proc_name, Gfobj_nde root, String expd) {
    +		Gfobj_wtr__json__browser wtr = new Gfobj_wtr__json__browser();
    +		String actl = wtr.Write_as_func__swt(proc_name, root);
    +		Gftest.Eq__str(expd, actl, "json_write");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/guis/history/Xog_history_stack_tst.java b/400_xowa/src/gplx/xowa/guis/history/Xog_history_stack_tst.java
    new file mode 100644
    index 000000000..708977913
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/history/Xog_history_stack_tst.java
    @@ -0,0 +1,83 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.guis.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
    +import org.junit.*;
    +public class Xog_history_stack_tst {		
    +	@Before public void init() {fxt.Clear();} private Xog_history_stack_fxt fxt = new Xog_history_stack_fxt();
    +	@Test  public void Init()				{fxt.Test_cur(null);}
    +	@Test  public void Add_1()				{fxt.Exec_add_many("A").Test_cur("A").Test_len(1).Test_pos(0);}
    +	@Test  public void Add_same()			{fxt.Exec_add_many("A", "A").Test_cur("A").Test_len(1).Test_pos(0);}
    +	@Test  public void Add_3()				{fxt.Exec_add_many("A", "B", "C").Test_cur("C").Test_len(3).Test_pos(2);}
    +	@Test  public void Add_3_bwd()			{fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Test_cur("B").Test_pos(1);}
    +	@Test  public void Add_3_bwd_fwd()		{fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_go_fwd().Test_cur("C").Test_pos(2);}
    +	@Test  public void Add_3_bwd_add()		{fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_add_many("D").Test_len(3).Test_cur("D").Test_pos(2);}
    +	@Test  public void Add_3_bwd_bwd_add()	{fxt.Exec_add_many("A", "B", "C").Exec_go_bwd().Exec_go_bwd().Exec_add_many("D").Test_len(2).Test_cur("D").Test_pos(1);}
    +	@Test  public void Add_dif_ns()			{fxt.Exec_add_many("A", "Help:A").Test_cur("Help:A");}	// PURPOSE.fix: page_stack was only differtiating by Page_db, not Full; EX: Unicode -> Category:Unicode
    +	@Test  public void Add_qargs() {// PURPOSE.fix: page_stack was only differentiating by qtxt args
    +		fxt	.Exec_add_one("Special:AllPages", "?from=A")
    +			.Exec_add_one("Special:AllPages", "?from=B")
    +			.Exec_add_many("B")
    +			.Exec_go_bwd()
    +			.Test_cur("Special:AllPages")
    +			.Test_cur_qargs("?from=B")
    +			;
    +	}
    +}
    +class Xog_history_stack_fxt {
    +	public Xog_history_stack_fxt Clear() {
    +		stack.Clear();
    +		if (app == null) {
    +			app = Xoa_app_fxt.Make__app__edit();
    +			wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		}
    +		return this;
    +	}	private Xoae_app app; private Xowe_wiki wiki; private Xog_history_stack stack = new Xog_history_stack();
    +	public Xog_history_stack_fxt Test_cur(String expd) {
    +		Xog_history_itm page = stack.Cur_itm();
    +		String actl = page == null ? null : String_.new_u8(page.Page());
    +		Tfds.Eq(expd, actl, "cur");
    +		return this;
    +	}
    +	public Xog_history_stack_fxt Test_cur_qargs(String expd) {
    +		Xog_history_itm page = stack.Cur_itm();
    +		String actl = page == null ? null : String_.new_u8(page.Qarg());
    +		Tfds.Eq(expd, actl, "cur_qargs");
    +		return this;
    +	}
    +	public Xog_history_stack_fxt Exec_go_bwd() {stack.Go_bwd(); return this;}
    +	public Xog_history_stack_fxt Exec_go_fwd() {stack.Go_fwd(); return this;}
    +	public Xog_history_stack_fxt Exec_add_many(String... ary) {
    +		int len = ary.length;
    +		for (int i = 0; i < len; i++) {
    +			String ttl = ary[i];
    +			Exec_add_one(ttl, null);
    +		}
    +		return this;
    +	}
    +	public Xog_history_stack_fxt Exec_add_one(String ttl_str, String arg_str) {
    +		byte[] ttl_bry = Bry_.new_u8(ttl_str);
    +		Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
    +		Xoae_page page = Xoae_page.New_test(wiki, ttl);
    +		byte[] url_bry = ttl_bry;
    +		if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_u8(arg_str));			
    +		Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(url_bry);
    +		page.Url_(url);  // set url b/c history_mgr.Add uses url
    +		stack.Add(Xog_history_mgr.new_(page));
    +		return this;
    +	}
    +	public Xog_history_stack_fxt Test_pos(int expd) {Tfds.Eq(expd, stack.Cur_pos(), "pos"); return this;}
    +	public Xog_history_stack_fxt Test_len(int expd) {Tfds.Eq(expd, stack.Len(), "len"); return this;}
    +}
    diff --git a/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__file__tst.java b/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__file__tst.java
    new file mode 100644
    index 000000000..c94734273
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__file__tst.java
    @@ -0,0 +1,66 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.guis.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
    +import org.junit.*; import gplx.core.tests.*;
    +import gplx.xowa.files.origs.*;
    +public class Xog_url_wkr__file__tst {
    +	private final    Xog_url_wkr__file__fxt fxt = new Xog_url_wkr__file__fxt();
    +	@Test   public void Basic() {
    +		fxt.Test__extract("A.png", "file:///mem/xowa/file/commons.wikimedia.org/orig/7/0/A.png", 300, 200);
    +	}
    +	@Test   public void Url_encoded() {
    +		fxt.Test__extract("A,b.png", "file:///mem/xowa/file/commons.wikimedia.org/orig/d/6/A%2Cb.png", 300, 200);
    +	}
    +	@Test   public void Utf8() {
    +		fxt.Test__extract("Volcán_Chimborazo,_\"El_Taita_Chimborazo\".jpg", "file:///mem/xowa/file/commons.wikimedia.org/orig/3/c/Volc%C3%A1n_Chimborazo%2C_%22El_Taita_Chimborazo%22.jpg", 300, 200);
    +	}
    +}
    +class Xog_url_wkr__file__fxt {
    +	private final    Xowe_wiki wiki;
    +	private final    Bry_bfr bfr = Bry_bfr_.New();
    +	private final    Xog_url_wkr__file wkr;
    +	private final    Xof_orig_wkr__mock orig_wkr = new Xof_orig_wkr__mock();
    +	public Xog_url_wkr__file__fxt() {
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		Xoa_app_fxt.repo2_(app, wiki);
    +		wiki.File__orig_mgr().Wkrs__add(orig_wkr);
    +		this.wkr = new Xog_url_wkr__file(app, wiki, Xoae_page.New_edit(wiki, wiki.Ttl_parse(Bry_.new_a7("Test_page"))));
    +	}
    +	public String Make__html(byte[] href_bry, byte[] xowa_ttl) {
    +		bfr.Add_str_u8_fmt("Full resolution", href_bry, xowa_ttl);
    +		return bfr.To_str_and_clear();
    +	}
    +	public void Make__orig(byte repo, byte[] page, int w, int h, byte[] redirect) {
    +		orig_wkr.Add_orig(repo, page, gplx.xowa.files.Xof_ext_.new_by_ttl_(page).Id(), w, h, redirect);
    +	}
    +	public void Exec__extract_data(byte[] href_bry, String html_doc) {
    +		wkr.Extract_data(html_doc, href_bry);
    +	}
    +	public void Test__extract(String file_page_db, String a_href_str, int orig_w, int orig_h) {
    +		byte[] a_href = Bry_.new_u8(a_href_str);
    +		this.Make__orig(Xof_orig_itm.Repo_wiki, Bry_.new_u8(file_page_db), orig_w, orig_h, Bry_.Empty);
    +		
    +		byte[] xowa_title_bry = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_file_fmtr__basic.Escape_xowa_title(Bry_.new_u8(file_page_db));
    +		this.Exec__extract_data(a_href, this.Make__html(a_href, xowa_title_bry));
    +
    +		Gftest.Eq__str(file_page_db	, wkr.File_page_db()							, "file_page_db");
    +		Gftest.Eq__bry(a_href		, wkr.File_url().To_http_file_bry()				, "file_url");
    +		Gftest.Eq__bry(a_href		, wkr.Fsdb().Html_view_url().To_http_file_bry()	, "fsdb.view_url");
    +		Gftest.Eq__int(orig_w		, wkr.Fsdb().Orig_w()							, "fsdb.orig_w");
    +		Gftest.Eq__int(orig_h		, wkr.Fsdb().Orig_h()							, "fsdb.orig_h");
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__tst.java b/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__tst.java
    new file mode 100644
    index 000000000..01ef381a8
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/urls/Xog_url_wkr__tst.java
    @@ -0,0 +1,46 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.guis.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
    +import org.junit.*; import gplx.core.tests.*;
    +public class Xog_url_wkr__tst {
    +	private final    Xog_url_wkr__fxt fxt = new Xog_url_wkr__fxt();
    +	@Test   public void Basic() {
    +		fxt.Exec__parse("/wiki/A?k1=B%26C");
    +		fxt.Test__raw("/wiki/A?k1=B%26C");
    +	}
    +	@Test   public void Anch_early() {	// de.wikipedia.org/wiki/Kategorie:Begriffskl%C3%A4rung?pagefrom=#::12%20PANZERDIVISION#mw-pages
    +		fxt.Exec__parse("/wiki/A?pagefrom=%23%3A7p#mw-pages");
    +		fxt.Test__qarg("?pagefrom=#:7p");
    +		fxt.Test__anch("mw-pages");
    +	}		
    +}
    +class Xog_url_wkr__fxt {
    +	private final    Xowe_wiki wiki;
    +	private final    Xog_url_wkr wkr = new Xog_url_wkr();
    +	private Xoa_url url;
    +	public Xog_url_wkr__fxt() {
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		wkr.Init(wiki);
    +	}
    +	public void Exec__parse(String href) {
    +		this.url = wiki.Utl__url_parser().Parse(Bry_.new_u8(href));
    +		this.url = wkr.Exec_url(url);
    +	}
    +	public void Test__raw(String expd)	{Gftest.Eq__str(expd, String_.new_u8(url.Raw()));}
    +	public void Test__qarg(String expd) {Gftest.Eq__str(expd, String_.new_u8(url.Qargs_mgr().To_bry()));}
    +	public void Test__anch(String expd) {Gftest.Eq__str(expd, String_.new_u8(url.Anch_bry()));}
    +}
    diff --git a/400_xowa/src/gplx/xowa/guis/urls/url_macros/Xog_url_macro_mgr_tst.java b/400_xowa/src/gplx/xowa/guis/urls/url_macros/Xog_url_macro_mgr_tst.java
    new file mode 100644
    index 000000000..10926040c
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/urls/url_macros/Xog_url_macro_mgr_tst.java
    @@ -0,0 +1,54 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.guis.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.urls.*;
    +import org.junit.*;
    +public class Xog_url_macro_mgr_tst {
    +	@Before public void init() {fxt.Clear();} private Xog_url_macro_mgr_fxt fxt = new Xog_url_macro_mgr_fxt();
    +	@Test  public void Custom_basic()		{fxt.Test("?:Page"				, "Special:Search/Page?fulltext=y");}
    +	@Test  public void Type_basic()			{fxt.Test("en.w:Page"			, "en.wikipedia.org/wiki/Page");}
    +	@Test  public void Type_main()			{fxt.Test("en.w:"				, "en.wikipedia.org/wiki/");}
    +	@Test  public void Type_tid()			{fxt.Test("w:Page"				, "en.wikipedia.org/wiki/Page");}
    +	@Test  public void Type_lang()			{fxt.Test("fr.w:Page"			, "fr.wikipedia.org/wiki/Page");}
    +	@Test  public void Type_unhandled()		{fxt.Test("x:A"					, null);}
    +	@Test  public void Type_unhandled_ns()	{fxt.Test("Help:A"				, null);}
    +	@Test  public void Type_custom()		{fxt.Test("wd.q:123"			, "www.wikidata.org/wiki/Q123");}
    +	@Test  public void Type_del() {
    +		fxt.Test("w:A", "en.wikipedia.org/wiki/A");
    +		fxt.Abrv_mgr().Types_mgr().Del(Bry_.new_a7("w"));
    +		fxt.Test("w:A", null);
    +	}
    +	@Test  public void Type_set() {
    +		fxt.Abrv_mgr().Types_mgr().Set("w", "~{0}.~{1}");
    +		fxt.Test("w.A", null);
    +	}
    +	@Test  public void Lang_default() {
    +		fxt.Abrv_mgr().Lang_default_(Bry_.new_a7("fr"));
    +		fxt.Test("w:Page", "fr.wikipedia.org/wiki/Page");
    +	}
    +	@Test  public void Precedence()	{	// PURPOSE: Custom should take precedence over type
    +		fxt.Abrv_mgr().Custom_mgr().Set("w", "custom:~{0}");
    +		fxt.Test("w:Page"				, "custom:Page");
    +	}
    +}
    +class Xog_url_macro_mgr_fxt {
    +	public void Clear() {
    +		abrv_mgr = new Xog_url_macro_mgr();
    +	}
    +	public Xog_url_macro_mgr Abrv_mgr() {return abrv_mgr;} private Xog_url_macro_mgr abrv_mgr;
    +	public void Test(String raw, String expd) {
    +		Tfds.Eq(expd, String_.new_a7(abrv_mgr.Fmt_or_null(Bry_.new_a7(raw))));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java
    new file mode 100644
    index 000000000..cf27e0de5
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/guis/views/url_box_fmts/Xog_urlfmtr_mgr_tst.java
    @@ -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.guis.views.url_box_fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
    +import org.junit.*; import gplx.core.tests.*;
    +import gplx.xowa.apps.urls.*;
    +public class Xog_urlfmtr_mgr_tst {
    +	private Xog_urlfmtr_mgr_fxt fxt = new Xog_urlfmtr_mgr_fxt();
    +	@Test  public void Basic() {
    +		String fmt_suffix = "domain:~{wiki_domain}; page_unders:~{page_title_unders}; page_spaces:~{page_title_spaces}";
    +		fxt.Init__init_by_parse
    +		( "*|wild -- " + fmt_suffix
    +		, "en.wikipedia.org|en.w -- " + fmt_suffix
    +		, "de.wikibooks.org|de.b -- " + fmt_suffix
    +		);
    +		fxt.Test__gen_or_null("en.wikipedia.org/wiki/Page_1", "en.w -- domain:en.wikipedia.org; page_unders:Page_1; page_spaces:Page 1");
    +		fxt.Test__gen_or_null("de.wikibooks.org/wiki/Page_1", "de.b -- domain:de.wikibooks.org; page_unders:Page_1; page_spaces:Page 1");
    +		fxt.Test__gen_or_null("fr.wikibooks.org/wiki/Page_1", "wild -- domain:fr.wikibooks.org; page_unders:Page_1; page_spaces:Page 1");
    +	}
    +	@Test  public void Wildcard_default() {
    +		String fmt_suffix = "domain:~{wiki_domain}; page_unders:~{page_title_unders}; page_spaces:~{page_title_spaces}";
    +		fxt.Init__init_by_parse
    +		( "en.wikipedia.org|en.w -- " + fmt_suffix
    +		, "de.wikibooks.org|de.b -- " + fmt_suffix
    +		);
    +		fxt.Test__gen_or_null("en.wikipedia.org/wiki/Page_1", "en.w -- domain:en.wikipedia.org; page_unders:Page_1; page_spaces:Page 1");
    +		fxt.Test__gen_or_null("fr.wikibooks.org/wiki/Page_1", "fr.wikibooks.org/wiki/Page_1");
    +	}
    +}
    +class Xog_urlfmtr_mgr_fxt {
    +	private final    Xog_urlfmtr_mgr mgr = new Xog_urlfmtr_mgr();
    +	private final    Xow_url_parser url_parser;
    +	public Xog_urlfmtr_mgr_fxt() {
    +		// create url parser
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		Xow_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		this.url_parser = new Xow_url_parser(wiki);
    +
    +		// reg xwikis
    +		wiki.App().User().Wikii().Xwiki_mgr().Add_by_atrs("de.wikibooks.org", "de.wikibooks.org");
    +		wiki.App().User().Wikii().Xwiki_mgr().Add_by_atrs("fr.wikibooks.org", "fr.wikibooks.org");
    +	}
    +	public void Init__init_by_parse(String... lines) {
    +		mgr.Parse(Bry_.new_u8(String_.Concat_lines_nl_skip_last(lines)));
    +	}
    +	public void Test__gen_or_null(String url_str, String expd) {
    +		Xoa_url url = url_parser.Parse(Bry_.new_u8(url_str));
    +		Gftest.Eq__str(expd, mgr.Gen(url));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java
    new file mode 100644
    index 000000000..f8f8e0f0a
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java
    @@ -0,0 +1,45 @@
    +/*
    +XOWA: the XOWA Offline Wiki Application
    +Copyright (C) 2012-2017 gnosygnu@gmail.com
    +
    +XOWA is licensed under the terms of the General Public License (GPL) Version 3,
    +or alternatively under the terms of the Apache License Version 2.0.
    +
    +You may use XOWA according to either of these licenses as is most appropriate
    +for your project on a case-by-case basis.
    +
    +The terms of each license can be found in the source code repository:
    +
    +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
    +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
    +*/
    +package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
    +import org.junit.*;
    +import gplx.xowa.guis.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.pages.*;
    +public class Xoh_page_wtr_mgr_tst {
    +	@Before public void init() {}
    +	@Test  public void Logo_has_correct_main_page() {	// PURPOSE: Logo href should be "/site/en.wikipedia.org/wiki/", not "/wiki/Main_Page"
    +		Xoae_app app = Xoa_app_fxt.Make__app__edit();
    +		Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
    +		Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr();
    +		Gfo_invk_.Invk_by_val(portal_mgr, Xow_portal_mgr.Invk_div_logo_, Bry_.new_a7("~{portal_nav_main_href}"));
    +		portal_mgr.Init_assert();
    +		Xoh_page_wtr_mgr page_wtr_mgr = new Xoh_page_wtr_mgr(true);
    +		page_wtr_mgr.Gen(wiki.Parser_mgr().Ctx().Page(), Xopg_page_.Tid_read);
    +		Tfds.Eq(String_.new_a7(portal_mgr.Div_logo_bry(true)), "/site/en.wikipedia.org/wiki/");
    +	}
    +	@Test   public void Skip__math__basic() {
    +		Xop_fxt fxt = Xop_fxt.New_app_html();
    +		fxt.Init_lang_vnts("zh-hans", "zh-hant");
    +
    +		fxt.Test__parse_to_html_mgr(String_.Concat_lines_nl_skip_last
    +		( "x_{1}-1"
    +		, "x-{1+2}-1"
    +		, "-{zh-hans:A;zh-hant:B;}-"
    +		), String_.Concat_lines_nl_skip_last
    +		( "x_{1}-1"		// not converted
    +		, "x-{1+2}-1"		// not converted
    +		, "A" // converted
    +		));
    +	}
    +}
    diff --git a/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java
    new file mode 100644
    index 000000000..402dc216c
    --- /dev/null
    +++ b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java
    @@ -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.xowa.htmls; import gplx.*; import gplx.xowa.*;
    +import org.junit.*;
    +import gplx.xowa.guis.*; import gplx.xowa.wikis.pages.*;
    +import gplx.xowa.htmls.core.htmls.*;
    +public class Xoh_page_wtr_wkr_tst {
    +	@Before public void init() {fxt.Clear();} private Xoh_page_wtr_fxt fxt = new Xoh_page_wtr_fxt();
    +	@Test  public void Page_name() {
    +		fxt.Test_page_name_by_ttl("Earth", "Earth");
    +		fxt.Test_page_name_by_ttl("File:A.png", "File:A.png");
    +		fxt.Test_page_name_by_ttl("Special:Search/earth?fulltext=y", "Special:Search/earth");
    +		fxt.Test_page_name_by_ttl("Special:Search/earth", "Special:Search/earth");
    +		fxt.Test_page_name_by_display("Special:Allpages", "All pages", "All pages");
    +	}
    +	@Test  public void Edit() {
    +		fxt.Test_edit("	", "&#9;\n");	// NOTE: cannot by 	 or will show up in edit box as "\t" and save as "\t" instead of 	
    +	}
    +	@Test  public void Css() {
    +		fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("
    ~{page_text}
    "); + fxt.Test_read("MediaWiki:Common.css", ".xowa {}", "
    .xowa {}
    "); + fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("
    ~{page_text}
    "); + } + @Test public void Amp_disable() { // PURPOSE: in js documents; " should be rendered as ", not as "; DATE:2013-11-07 + fxt.Test_read("MediaWiki:Gadget.js", """, "
    &quot;
    "); + } +} +class Xoh_page_wtr_fxt { + public void Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + } private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); private Xowe_wiki wiki; + public Xoae_app App() {return app;} private Xoae_app app; + public void Test_page_name_by_display(String ttl, String display, String expd) { + Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl)), Bry_.new_a7(display)))); + } + public void Test_page_name_by_ttl(String raw, String expd) { + Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(raw)), null))); + } + public void Test_edit(String raw, String expd) { + wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); + Xoae_page page = wiki.Parser_mgr().Ctx().Page(); + page.Db().Text().Text_bry_(Bry_.new_u8(raw)); + Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr(); + Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_edit); + wkr.Write_body(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Basic, page); + Tfds.Eq(expd, tmp_bfr.To_str_and_clear()); + } + public void Test_read(String page_name, String page_text, String expd) { + wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); + Xoae_page page = wiki.Parser_mgr().Ctx().Page(); + page.Ttl_(Xoa_ttl.Parse(wiki, Bry_.new_a7(page_name))); + page.Db().Text().Text_bry_(Bry_.new_u8(page_text)); + Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr(); + Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_read); + wkr.Write_body(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Basic, page); + Tfds.Eq(expd, tmp_bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr_tst.java b/400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr_tst.java new file mode 100644 index 000000000..e83300419 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +public class Bridge_msg_bldr_tst { + @Before public void init() {fxt.Clear();} private Bridge_msg_bldr_fxt fxt = new Bridge_msg_bldr_fxt(); + @Test public void Bld() { + fxt.Bldr().Rslt_pass_y_().Notify_pass_("passed").Data("key1", true).Data("key2", 1).Data("key3", "val3"); + fxt.Test_to_json_str("{'rslt':{'pass':true},'notify':{'text':'passed','status':'success'},'data':{'key1':true,'key2':1,'key3':'val3'}}"); + } +} +class Bridge_msg_bldr_fxt { + public Bridge_msg_bldr Bldr() {return bldr;} private final Bridge_msg_bldr bldr = new Bridge_msg_bldr().Opt_quote_byte_apos_(); + public void Clear() {} + public void Test_to_json_str(String expd) { + Tfds.Eq_str_lines(expd, bldr.To_json_str()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/bridges/dbuis/fmtrs/Dbui_tbl_fmtr_tst.java b/400_xowa/src/gplx/xowa/htmls/bridges/dbuis/fmtrs/Dbui_tbl_fmtr_tst.java new file mode 100644 index 000000000..be7444eae --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/bridges/dbuis/fmtrs/Dbui_tbl_fmtr_tst.java @@ -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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*; +import gplx.xowa.htmls.bridges.dbuis.tbls.*; +import org.junit.*; +public class Dbui_tbl_fmtr_tst { + @Before public void init() {fxt.Clear();} private final Dbui_tbl_fmtr_fxt fxt = new Dbui_tbl_fmtr_fxt(); + @Test public void Basic() { +// fxt.Test_write +// ( fxt.Make_tbl() +// , String_.Concat_lines_nl_skip_last() +// ); + } +} +class Dbui_tbl_fmtr_fxt { + private final Bry_bfr bfr = Bry_bfr_.New_w_size(255); + private final Dbui_tbl_fmtr tbl_fmtr = new Dbui_tbl_fmtr(); + public void Clear() {} + public Dbui_tbl_itm Make_tbl() { + return null; + } + public void Test_write(Dbui_tbl_itm tbl, String expd) { + tbl_fmtr.Write(bfr, tbl, null, null, null); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_html_wtr_tst.java b/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_html_wtr_tst.java new file mode 100644 index 000000000..d23fe3972 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_html_wtr_tst.java @@ -0,0 +1,348 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import org.junit.*; +public class Xoh_html_wtr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_(); fxt.Reset();} + @Test public void Hr_basic() {fxt.Test_parse_page_wiki_str("----" , "
    ");} + @Test public void Hr_extended() {fxt.Test_parse_page_wiki_str("--------" , "
    ");} + @Test public void Lnki_basic() {fxt.Test_parse_page_wiki_str("[[a]]" , "a");} + @Test public void Lnki_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]" , "b");} + @Test public void Lnki_caption_fmt() {fxt.Test_parse_page_wiki_str("[[a|''b'']]" , "b");} + @Test public void Lnki_tail_trg() {fxt.Test_parse_page_wiki_str("[[a]]b" , "ab");} + @Test public void Lnki_tail_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]c" , "bc");} + @Test public void Lnki_title() { + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_wiki_str("[[a|b]]", "b"); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Lnki_title_page_text() { + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_wiki_str("[[a_b]]", "a_b"); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Lnki_category() {fxt.Test_parse_page_wiki_str("[[Category:A]]" , "");} // NOTE: Category does not get written in main page bfr + @Test public void Lnki_category_force() {fxt.Test_parse_page_wiki_str("[[:Category:A]]" , "Category:A");} + @Test public void Lnki_matches_page() {fxt.Test_parse_page_wiki_str("[[test page|t1]]", "t1");} // NOTE: "Test page" is hardcoded to be the test page name + @Test public void Lnki_matches_page_but_has_anchor() {fxt.Test_parse_page_wiki_str("[[Test page#a|test 1]]", "test 1");} // NOTE: "Test page" is hardcoded to be the test page name + @Test public void Lnki_anchor() {fxt.Test_parse_page_wiki_str("[[A#b]]" , "A#b");} +// @Test public void Img_invalid_wnt_char() { +// fxt.Test_parse_page_wiki_str +// ( "[[File:A*b.png]]" +// , "
    \"\"
    " +// ); +// } +// @Test public void Img_alt() { // FUTURE: enable; WHEN: after fixing xnde to handle bad xnde; EX: France +// fxt.Test_parse_page_wiki_str("[[File:A.png|none|9x8px|alt=ab\"c\"d]]", Xop_fxt.html_img_none("File:A.png", "ab"c"d")); +// } + @Test public void Url_encode() {fxt.Test_parse_page_wiki_str("[[a;@$!*(),/ _^b|z]]" , "z");} // NOTE: was "a" instead of "A"; "__" instead of "_" DATE:2014-09-07 + @Test public void Url_encode_space() {fxt.Test_parse_page_wiki_str("[[a _b|z]]" , "z");} + @Test public void Apos_i() {fxt.Test_parse_page_wiki_str("''a''" , "a");} + @Test public void Apos_b() {fxt.Test_parse_page_wiki_str("'''a'''" , "a");} + @Test public void Apos_ib() {fxt.Test_parse_page_wiki_str("'''''a'''''" , "a");} + @Test public void Html_ent() {fxt.Test_parse_page_wiki_str("!" , "!");} // PURPOSE:ncrs should be literal, not decoded (!); DATE:2014-11-06 + @Test public void Html_ref() {fxt.Test_parse_page_wiki_str(">" , ">");} + @Test public void List_1_itm() { + fxt.Test_parse_page_wiki_str("*a", String_.Concat_lines_nl_skip_last + ( "
      " + , "
    • a" + , "
    • " + , "
    " + )); + } + @Test public void List_2_itms() { + fxt.Test_parse_page_wiki_str("*a\n*b", String_.Concat_lines_nl_skip_last + ( "
      " + , "
    • a" + , "
    • " + , "
    • b" + , "
    • " + , "
    " + )); + } + @Test public void List_nest_ul() { + fxt.Test_parse_page_wiki_str("*a\n**b", String_.Concat_lines_nl_skip_last + ( "
      " + , "
    • a" + , "
        " + , "
      • b" + , "
      • " + , "
      " + , "
    • " + , "
    " + )); + } + @Test public void List_dt_dd() { + fxt.Test_parse_page_wiki_str(";a:b", String_.Concat_lines_nl_skip_last + ( "
    " + , "
    a" + , "
    " + , "
    b" + , "
    " + , "
    " + )); + } + @Test public void List_dd_nest2() { + fxt.Test_parse_page_wiki_str("::a", String_.Concat_lines_nl_skip_last + ( "
    " + , "
    " + , "
    " + , "
    a" + , "
    " + , "
    " + , "
    " + , "
    " + )); + } + @Test public void Tblw_basic() { + fxt.Test_parse_page_wiki_str("{|\n|+a\n!b||c\n|-\n|d||e\n|}", String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    a" + , "
    b" + , " c" + , "
    d" + , " e" + , "
    " + )); + } + @Test public void Tblw_atrs() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|style='z'" + , "|+a" + , "!style='y'|b||style='x'|c" + , "|-style='w'" + , "|style='v'|d||style='u'|e" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    a" + , "
    b" + , " c" + , "
    d" + , " e" + , "
    " + )); + } + @Test public void Para_hdr_list() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "==a==" + , "" + , "*b" + , "*c" + ), String_.Concat_lines_nl_skip_last + ( "

    a

    " + , "" + , "
      " + , "
    • b" + , "
    • " + , "
    • c" + , "
    • " + , "
    " + )); + fxt.Init_para_n_(); + } + @Test public void Para_nl_is_space() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

    a" + , "b" + , "

    " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Para_nl_2_2() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , "" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

    a" + , "

    " + , "" + , "

    b" + , "

    " + , "" + , "

    c" + , "

    " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Div_2() { // WP:[[Air]]#Density of air + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
    a
    " + , "" + , "
    b
    " + ), String_.Concat_lines_nl_skip_last + ( "
    a
    " + , "
    b
    " + )); + fxt.Init_para_n_(); + } + @Test public void Tblw() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "|-" + , "|a" + , "|b" + , "|-" + , "|c" + , "|d" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    a" + , " b" + , "
    c" + , " d" + , "
    " + , "" + )); + } + @Test public void Tblw_lnki_bang() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "|-" + , "|[[a|!]]" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
    !" + , "
    " + , "" + )); + } + @Test public void Tr_inside_tblw_td() { // WP:[[Earth]] + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "|-" + , "a" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
    a" + , "
    " + , "" + )); + } + @Test public void Tblw_tr_with_newlines() {// WP:[[John Adams]] Infobox Officeholder + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "|-" + , "" + , "" + , "" + , "|a" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
    a" + , "
    " + , "" + )); + } + @Test public void Bang_doesnt_force_tbl() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str("a! b! c", "

    a! b! c\n

    \n"); + fxt.Init_para_n_(); + } + @Test public void Err_nlOnly() { + fxt.Test_parse_page_wiki_str("{{\n}}", "{{\n}}"); // NOTE: was {{}} + } + @Test public void Xnde_inline() { + fxt.Test_parse_page_wiki_str("
    ", "
    "); + } + @Test public void Xnde_id_encode() { // PURPOSE: id should be url-encoded; DATE: 2013-11-13; + fxt.Test_parse_page_wiki_str("
    ", "
    "); + fxt.Test_parse_page_wiki_str("
    ", "
    "); + } + @Test public void Timeline() {// PURPOSE: embed timeline contents in pre; DATE:2014-05-22 + fxt.Test_parse_page_wiki_str("a", "
    a
    "); + } + @Test public void Amp_ncr_should_not_be_rendered_as_bytes() { // PURPOSE:   should be rendered as   not as literal bytes {192,160}; DATE:2013-12-09 + fxt.Test_parse_page_wiki_str("a b", "a b"); + } + + // @Test public void Fix_PositionAbsolute_stripped() { +// fxt.Test_parse_page_wiki_str("", ""); +// } +// @Test public void Xnde_nl() { +// fxt.Test_parse_page_wiki_str("
    c
    ", String_.Concat_lines_nl_skip_last +// ( "
    c
    " +// )); +// } +// @Test public void Tblw() { +// fxt.Test_parse_page_wiki_str("{|\n|}", String_.Concat_lines_nl +// ( "" +// , " " +// , " " +// , " " +// , " " +// , "
    a" +// , " b" +// , "
    " +// )); +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_mgr_tst.java new file mode 100644 index 000000000..dd19390c5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_mgr_tst.java @@ -0,0 +1,90 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; +import org.junit.*; +public class Xoh_tidy_mgr_tst { + @Before public void init() {fxt.Clear();} private Xoh_tidy_mgr_fxt fxt = new Xoh_tidy_mgr_fxt(); + @Test public void Wrap() { + fxt.Test_wrap("a" + , "" + + "" + + "" + + "test" + + "" + + "a" + + "" + + "" + ); + } + @Test public void Unwrap_pass() { + fxt.Test_unwrap + ( "" + + "" + + "" + + "test" + + "" + + "a" + + "" + + "" + , Bool_.Y, "a" + ); + } + @Test public void Unwrap_fail_bgn() { + fxt.Test_unwrap + ( "" + + "" + + "" + + "test" + + "" + + "a" + + "" + + "" + , Bool_.N, "" + ); + } + @Test public void Unwrap_fail_end() { + fxt.Test_unwrap + ( "" + + "" + + "" + + "test" + + "" + + "a" + + "" + + "" + , Bool_.N, "" + ); + } +} +class Xoh_tidy_mgr_fxt { + private Bry_bfr bfr = Bry_bfr_.Reset(255); + public void Clear() { + bfr.Clear(); + } + public void Test_wrap(String val, String expd) { + bfr.Add_str_u8(val); + Xow_tidy_mgr.Tidy_wrap(bfr); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } + public void Test_unwrap(String val, boolean expd_pass, String expd) { + bfr.Add_str_u8(val); + boolean actl_pass = Xow_tidy_mgr.Tidy_unwrap(bfr); + if (actl_pass != expd_pass) Tfds.Fail("expd={0} actl={1}", expd_pass, actl_pass); + else if (expd_pass) { + Tfds.Eq(expd, bfr.To_str_and_clear()); + } + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_wkr_jtidy_tst.java b/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_wkr_jtidy_tst.java new file mode 100644 index 000000000..70f0f9938 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/htmls/tidy/Xoh_tidy_wkr_jtidy_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; +import gplx.core.envs.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import org.w3c.tidy.Tidy; +import org.junit.*; +public class Xoh_tidy_wkr_jtidy_tst { + @Before public void init() {fxt.Clear();} private Jtidy_fxt fxt = new Jtidy_fxt(); + @Test public void Image_full() { + String nl = Op_sys.Cur().Tid_is_wnt() ? "\r\n" : "\n"; // NOTE: JTidy uses different line-endings based on OS; DATE:2015-05-11 + fxt.Test_tidy("𐎍𐎁_𐎜", "𐎍𐎁_𐎜" + nl); + } +} +class Jtidy_fxt { + public void Clear() { + } + public void Test_tidy(String raw, String expd) { + Tidy tidy = new Tidy(); + tidy.setPrintBodyOnly(true); + tidy.setWraplen(0); + tidy.setQuiet(true); + tidy.setShowWarnings(false); + tidy.setShowErrors(0); + ByteArrayInputStream rdr = null; + try { + rdr = new ByteArrayInputStream(raw.getBytes("UTF-8")); + } catch (Exception e) {} + ByteArrayOutputStream wtr = new ByteArrayOutputStream(); + tidy.parse(rdr, wtr); + String actl = wtr.toString(); + Test_mgr.Eq_str(expd, actl); + } +} +class Test_mgr { + public static void Eq_str(String expd, String actl) { +// byte[] expd_bry = Bry_.new_u8(expd); +// byte[] actl_bry = Bry_.new_u8(actl); +// int expd_len = expd_bry.length; +// int actl_len = actl_bry.length; +// if (expd_len != actl_len) throw new RuntimeException(String.format("expd != actl; expd:%s actl:%s", Int_.To_str(expd_len), Int_.To_str(actl_len))); +// for (int i = 0; i < expd_len; ++i) { +// byte expd_byte = expd_bry[i]; +// byte actl_byte = actl_bry[i]; +// if (expd_byte != actl_byte) throw new RuntimeException(String.format("expd != actl; %s expd:%s actl:%s", Int_.To_str(i), Byte_.To_str(expd_byte), Byte_.To_str(actl_byte))); +// } + if (!expd.equals(actl)) throw new RuntimeException(String.format("expd != actl; expd:%s actl:%s", expd, actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/hzips/Gfo_decimal_parser_tst.java b/400_xowa/src/gplx/xowa/htmls/core/hzips/Gfo_decimal_parser_tst.java new file mode 100644 index 000000000..994aeb5c6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/hzips/Gfo_decimal_parser_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import org.junit.*; +public class Gfo_decimal_parser_tst { + private final Gfo_decimal_parser_fxt fxt = new Gfo_decimal_parser_fxt(); + @Test public void Positive() { + fxt.Test__parse("123" , Bool_.Y, 0, 123); + fxt.Test__parse("12.3" , Bool_.Y, -1, 123); + fxt.Test__parse("1.23" , Bool_.Y, -2, 123); + fxt.Test__parse(".123" , Bool_.Y, -3, 123); + fxt.Test__parse("0.123" , Bool_.Y, -3, 123); + } + @Test public void Negative() { + fxt.Test__parse("-123" , Bool_.N, 0, 123); + fxt.Test__parse("-12.3" , Bool_.N, -1, 123); + fxt.Test__parse("-1.23" , Bool_.N, -2, 123); + fxt.Test__parse("-.123" , Bool_.N, -3, 123); + fxt.Test__parse("-0.123" , Bool_.N, -3, 123); + } +} +class Gfo_decimal_parser_fxt { + private final Gfo_decimal_parser bicoder = new Gfo_decimal_parser(); + public void Test__parse(String src_str, boolean expd_sign, int expd_exponent, long expd_number) { + byte[] src_bry = Bry_.new_u8(src_str); + bicoder.Parse(src_bry, 0, src_bry.length); + Tfds.Eq_bool(expd_sign, bicoder.Sign()); + Tfds.Eq_int(expd_exponent, bicoder.Exponent()); + Tfds.Eq_long(expd_number, bicoder.Number()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int__tst.java b/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int__tst.java new file mode 100644 index 000000000..bddcbfb78 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int__tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import org.junit.*; import gplx.core.encoders.*; +public class Xoh_hzip_int__tst { + private final Xoh_hzip_int__fxt fxt = new Xoh_hzip_int__fxt(); + @Test public void Reqd__1() { + fxt.Test__encode(1, 0, "!"); + fxt.Test__encode(1, 84, "u"); + fxt.Test__encode(1, 85, "{\"!"); + fxt.Test__encode(1, 7225, "|\"!!"); + fxt.Test__encode(1, 614125, "}\"!!!"); + fxt.Test__encode(1, 52200625, "~\"!!!!"); + } + @Test public void Reqd__2() { + fxt.Test__encode(2, 0, "!!"); + fxt.Test__encode(2, 84, "!u"); + fxt.Test__encode(2, 85, "\"!"); + fxt.Test__encode(2, 7225, "|\"!!"); + fxt.Test__encode(2, 614125, "}\"!!!"); + fxt.Test__encode(2, 52200625, "~\"!!!!"); + } +} +class Xoh_hzip_int__fxt { + private final Bry_bfr bfr = Bry_bfr_.New(); + private final gplx.core.primitives.Int_obj_ref count_ref = gplx.core.primitives.Int_obj_ref.New_neg1(); + public void Test__encode(int reqd, int val, String expd) { + Gfo_hzip_int_.Encode(reqd, bfr, val); + byte[] actl = bfr.To_bry_and_clear(); + Tfds.Eq(expd, String_.new_u8(actl)); + Tfds.Eq(val, Gfo_hzip_int_.Decode(reqd, actl, actl.length, 0, count_ref)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int_tst.java b/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int_tst.java new file mode 100644 index 000000000..7e0d37c0a --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_hzip_int_tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import org.junit.*; +public class Xoh_hzip_int_tst { + private final Xoh_hzip_int_fxt fxt = new Xoh_hzip_int_fxt(); + @Test public void B256__reqd__1() { + fxt.Init__b256(); + fxt.Test__b256(1, 0 , 0); + fxt.Test__b256(1, 252 , 252, 252); + fxt.Test__b256(1, 253 , 252, 253); + fxt.Test__b256(1, 254 , 252, 254); + fxt.Test__b256(1, 255 , 252, 255); + fxt.Test__b256(1, 256 , 253, 1, 0); + fxt.Test__b256(1, 65535 , 253, 255, 255); + fxt.Test__b256(1, 65536 , 254, 1, 0, 0); + fxt.Test__b256(1, 16777216 , 255, 1, 0, 0, 0); + } + @Test public void B256__reqd__2() { + fxt.Init__b256(); + fxt.Test__b256(2, 0 , 0, 0); + fxt.Test__b256(2, 252 , 0, 252); + fxt.Test__b256(2, 253 , 0, 253); + fxt.Test__b256(2, 254 , 0, 254); + fxt.Test__b256(2, 255 , 0, 255); + fxt.Test__b256(2, 256 , 1, 0); + fxt.Test__b256(2, 64511 , 251, 255); + fxt.Test__b256(2, 64512 , 253, 252, 0); + fxt.Test__b256(2, 65535 , 253, 255, 255); + fxt.Test__b256(2, 65536 , 254, 1, 0, 0); + fxt.Test__b256(2, 16777216 , 255, 1, 0, 0, 0); + } + @Test public void B085__reqd__1() { + fxt.Init__b085(); + fxt.Test__b085(1, 0, "!"); + fxt.Test__b085(1, 84, "u"); + fxt.Test__b085(1, 85, "{\"!"); + fxt.Test__b085(1, 7225, "|\"!!"); + fxt.Test__b085(1, 614125, "}\"!!!"); + fxt.Test__b085(1, 52200625, "~\"!!!!"); + } + @Test public void B085__reqd__2() { + fxt.Init__b085(); + fxt.Test__b085(2, 0, "!!"); + fxt.Test__b085(2, 84, "!u"); + fxt.Test__b085(2, 85, "\"!"); + fxt.Test__b085(2, 7225, "|\"!!"); + fxt.Test__b085(2, 614125, "}\"!!!"); + fxt.Test__b085(2, 52200625, "~\"!!!!"); + } +} +class Xoh_hzip_int_fxt { + private final Bry_bfr bfr = Bry_bfr_.New(); + private final gplx.core.primitives.Int_obj_ref count_ref = gplx.core.primitives.Int_obj_ref.New_neg1(); + private final Xoh_hzip_int hzint = new Xoh_hzip_int(); + public void Init__b256() {hzint.Mode_is_b256_(Bool_.Y);} + public void Init__b085() {hzint.Mode_is_b256_(Bool_.N);} + public void Test__b256(int reqd, int val, int... expd_ints) { + hzint.Encode(reqd, bfr, val); + byte[] actl = bfr.To_bry_and_clear(); + byte[] expd = Byte_.Ary_by_ints(expd_ints); + Tfds.Eq_ary(expd, actl, Int_.To_str(val)); + Tfds.Eq(val, hzint.Decode(reqd, actl, actl.length, 0, count_ref)); + } + public void Test__b085(int reqd, int val, String expd) { + hzint.Encode(reqd, bfr, val); + byte[] actl = bfr.To_bry_and_clear(); + Tfds.Eq(expd, String_.new_u8(actl)); + Tfds.Eq(val, hzint.Decode(reqd, actl, actl.length, 0, count_ref)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/makes/tests/Xoh_make_fxt.java b/400_xowa/src/gplx/xowa/htmls/core/makes/tests/Xoh_make_fxt.java new file mode 100644 index 000000000..03af24c02 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/makes/tests/Xoh_make_fxt.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.*; +import gplx.xowa.htmls.sections.*; +public class Xoh_make_fxt { + public Xoh_make_fxt() { + Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/" + parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki()); + parser_fxt.Wiki().Html_mgr().Html_wtr().Cfg().Lnki__id_(Bool_.Y).Lnki__title_(Bool_.Y); + } + public void Clear() { + parser_fxt.Reset(); + page_chkr.Clear(); + } + public Xoh_page_chkr Page_chkr() {return page_chkr;} private final Xoh_page_chkr page_chkr = new Xoh_page_chkr(); + public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt(); + public void Init_img_cache + ( String wiki_abrv, String lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page + , boolean repo_is_commons, String html_ttl, int html_w, int html_h, double html_time, int html_page + ) { + // fxt.Init_cache("en.wikipedia.org", "A.png", 0, 220, 110, 0.5, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1); + } + public void Test__html(String wtxt, String expd) {Test__html(wtxt, expd, true);} + public void Test__html(String wtxt, String expd, boolean escape_apos) { + if (escape_apos) expd = String_.Replace(expd, "'", "\""); + String actl = parser_fxt.Exec__parse_to_hdump(wtxt); + Tfds.Eq_str_lines(expd, actl); + } + public void Test__make(String html, Xoh_page_chkr chkr) { + html = String_.Replace(html, "'", "\""); + Xoh_page actl = new Xoh_page(); + actl.Ctor_by_hview(parser_fxt.Wiki(), Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1); + Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console(); + Xoh_make_mgr make_mgr = parser_fxt.Wiki().Html__hdump_mgr().Load_mgr().Make_mgr(); + byte[] actl_body = make_mgr.Parse(Bry_.new_u8(html), actl, parser_fxt.Wiki()); + actl.Db().Html().Html_bry_(actl_body); + Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop; + chkr.Check(actl); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_fxt.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_fxt.java new file mode 100644 index 000000000..51d61412c --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_hzip_fxt.java @@ -0,0 +1,115 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; +import gplx.xowa.files.caches.*; +public class Xoh_hzip_fxt { + private final Xowe_wiki wiki; + private final Xop_fxt parser_fxt = new Xop_fxt(); + private final Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(32); + private final Xoh_hzip_mgr hzip_mgr; + private final Xoh_page hpg = new Xoh_page(); + private boolean mode_is_b256; + public Xoh_hzip_fxt() { + this.wiki = parser_fxt.Wiki(); + Xoa_app_fxt.repo2_(parser_fxt.App(), wiki); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/" + wiki.Html__hdump_mgr().Init_by_db(parser_fxt.Wiki()); + this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr(); + hpg.Ctor_by_hview(wiki, Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1); + } + public Xow_wiki Wiki() {return wiki;} + public Xoa_page Page() {return hpg;} + public Xoh_hzip_fxt Init_mode_is_b256_(boolean v) {bfr.Mode_is_b256_(v); mode_is_b256 = v; return this;} + public Xoh_hzip_fxt Init_mode_diff_y_() {hzip_mgr.Hctx().Mode_is_diff_(Bool_.Y); return this;} + public void Clear() {hpg.Clear();} + public void Init_wiki_installed(String domain) {parser_fxt.Init_xwiki_add_user_(domain);} + public Xou_cache_finder_mem Init_file_mgr__mem() { + Xou_cache_finder_mem rv = Xou_cache_finder_.New_mem(); + hzip_mgr.Hctx().Test__cache__mgr_(rv); + return rv; + } + public void Init_file_mgr__noop() { + hzip_mgr.Hctx().Test__cache__mgr_(Xou_cache_finder_.Noop); + } + public Xowe_wiki Init_wiki_alias(String alias, String domain) { + Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(parser_fxt.App(), domain); + parser_fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), null); + return rv; + } + public void Init__ns_alias__add(String alias, int ns_id) { + parser_fxt.Wiki().Ns_mgr().Aliases_add(ns_id, alias).Init(); + } + public void Init__ns_alias__del(String alias) { + parser_fxt.Wiki().Ns_mgr().Aliases_del(alias); + } + public void Test__bicode(String hzip, String html) {Test__bicode(hzip, html, html);} + public void Test__bicode(String hzip, String html_enc, String html_dec) { + html_enc = Gfh_utl.Replace_apos(html_enc); + html_dec = Gfh_utl.Replace_apos(html_dec); + Test__bicode_raw(hzip, html_enc, html_dec); + } + public void Test__bicode_raw(String hzip, String html_enc, String html_dec) { + hzip = Xoh_hzip_fxt.Escape(hzip); + Test__encode__raw(hzip, html_enc); + Test__decode__raw(hzip, html_dec); + } + public void Test__encode(String hzip, String html) { + hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html); + Test__encode__raw(hzip, html); + } + public void Test__decode(String hzip, String html) { + hzip = Xoh_hzip_fxt.Escape(hzip); html = Gfh_utl.Replace_apos(html); + Test__decode__raw(hzip, html); + } + public void Test__encode__fail(String expd, String html) { + hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html)); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + private void Test__encode__raw(String hzip, String html) { + Gfo_usr_dlg_.Test__show__init(); + hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(html)); + Gfo_usr_dlg_.Test__show__term(); + Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear()); + } + public void Test__decode__raw(String hzip, String html) { + Gfo_usr_dlg_.Test__show__init(); + hpg.Section_mgr().Clear(); + hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, Bry_.new_u8(hzip)); + Gfo_usr_dlg_.Test__show__term(); + Tfds.Eq_str_lines(html, bfr.To_str_and_clear()); + } + public void Exec_write_to_fsys(Io_url dir, String fil) { + try { + Xoh_hzip_bfr bfr = Xoh_hzip_bfr.New_txt(32).Mode_is_b256_(mode_is_b256); + Gfo_usr_dlg_.Test__show__init(); + hzip_mgr.Encode(bfr, parser_fxt.Wiki(), hpg, Io_mgr.Instance.LoadFilBry(dir.GenSubFil(fil))); + Gfo_usr_dlg_.Test__show__term(); + byte[] actl = bfr.To_bry_and_clear(); + Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.html"), actl); + Gfo_usr_dlg_.Test__show__init(); + gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 4; + hzip_mgr.Hctx().Mode_is_diff_(Bool_.Y); + hzip_mgr.Decode(bfr, parser_fxt.Wiki(), hpg, actl); + hzip_mgr.Hctx().Mode_is_diff_(Bool_.N); + gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_hzip.Md5_depth = 2; + Gfo_usr_dlg_.Test__show__term(); + Io_mgr.Instance.SaveFilBry(dir.GenSubFil(fil).GenNewExt(".hzip.decode.html"), bfr.To_bry_and_clear()); + } catch (Exception e) { + Tfds.Dbg(e); + } + } + public static String Escape(String v) {return String_.Replace(v, "~", "");} +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser_fxt.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser_fxt.java new file mode 100644 index 000000000..2aa086e9e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/Xoh_itm_parser_fxt.java @@ -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.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; +import gplx.core.brys.*; +import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; +public abstract class Xoh_itm_parser_fxt { + protected final Xoae_app app; + protected final Xowe_wiki wiki; + private final Bry_err_wkr err_wkr = new Bry_err_wkr(); + protected byte[] src; protected int src_len; + protected final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx(); + public Xoh_itm_parser_fxt() { + this.app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + hctx.Init_by_app(app); + } + private Xoh_itm_parser Parser() {return Parser_get();} + public abstract Xoh_itm_parser Parser_get(); + public void Test__parse__fail(String src_str, String expd) { + Gfo_usr_dlg_.Test__list__init(); + Parser().Fail_throws_err_(Bool_.N); + Exec_parse(src_str); + Parser().Fail_throws_err_(Bool_.Y); + Tfds.Eq_str(expd, Gfo_usr_dlg_.Test__list__term__get_1st()); + } + public void Exec_parse(String src_str) { + this.src = Bry_.new_u8(src_str); this.src_len = src.length; + Xoh_page hpg = new Xoh_page(); // NOTE: no need to pass url and ttl now + hctx.Init_by_page(wiki, hpg); + err_wkr.Init_by_page(Xoa_page_.Main_page_str, src); + Exec_parse_hook(err_wkr, hctx, 0, src_len); + } + public abstract void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end); +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/gallerys/Xoh_gallery_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/gallerys/Xoh_gallery_hzip_tst.java new file mode 100644 index 000000000..e24ad48bd --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/gallerys/Xoh_gallery_hzip_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.addons.gallerys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.addons.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_gallery_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { + fxt.Test__decode + ( "
      " + , "
        " + ); + Gftest.Eq__bool_y(fxt.Page().Xtn__gallery_exists()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/medias/Xoh_media_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/medias/Xoh_media_hzip_tst.java new file mode 100644 index 000000000..b845c5e13 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/medias/Xoh_media_hzip_tst.java @@ -0,0 +1,93 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +//namespace gplx.xowa.htmls.core.wkrs.addons.medias { +// import org.junit.*; using gplx.core.tests; +// using gplx.langs.htmls; using gplx.xowa.htmls.core.makes.tests; +// public class Xoh_media_hzip_tst { +// private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); +// @Test public void Video__full__ogv__width_y() { // EX: [[File:A.ogv|320px|bcd|alt=efg]]; DATE:2016-08-05 +// fxt.Test__bicode // NOTE: caption not rendered; may need to reconsider; +// ( "*!!aA.ogv~)$bA.ogv~efg~", String_.Concat_lines_nl_skip_last +// ( "
        " +// , "
        " +// + "" +// + "efg" +// + "" +// + "
        " +// , "
        " +// + "" +// + "" +// + "
        " +// , "
        " +// )); +// } +// @Test public void Video__full__ogv__width_n() { // EX: [[File:A.ogv]]; DATE:2016-08-05 +// fxt.Test__bicode +// ( "*!!aA.ogv~!A.ogv~efg~", String_.Concat_lines_nl_skip_last +// ( "
        " +// , "
        " +// + "" +// + "efg" +// + "" +// + "
        " +// , "" +// , "
        " +// )); +// } +// @Test public void Audio__thumb() { +// String html = Gfh_utl.Replace_apos(String_.Concat_lines_nl +// ( "
        " +// , "
        " +// , "
        " +// , "
        " +// , "
        " +// , "
        " +// , "
        " +// , "
        b" +// , "
        " +// , "
        " +// , "
        " +// )); +// +// String hzip = String_.Concat_lines_nl +// ( "
        " +// , "
        " +// , " ~*#$bA.oga" +// , "
        " +// , "
        $|%%,)A.ogaEnlarge
        b" +// , "
        " +// , "
        " +// , "
        " +// ); +// fxt.Test__bicode(hzip, html); +// } +// @Test public void Audio__noicon() { +// String html = Gfh_utl.Replace_apos(String_.Concat_lines_nl +// ( "
        " +// , "
        " +// , "
        " +// )); +// +// String hzip = String_.Concat_lines_nl +// ( " ~*$$bA.oga" +// ); +// fxt.Test__bicode(hzip, html); +// } +// } +//} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/timelines/Xoh_timeline_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/timelines/Xoh_timeline_hzip_tst.java new file mode 100644 index 000000000..772216ee7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/addons/timelines/Xoh_timeline_hzip_tst.java @@ -0,0 +1,24 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.addons.timelines; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.addons.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_timeline_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { // EX: code + fxt.Test__decode__raw("
        abc
        ", "
        abc
        "); + Gftest.Eq__bool_y(fxt.Page().Xtn__timeline_exists()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/escapes/Xoh_escape_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/escapes/Xoh_escape_hzip_tst.java new file mode 100644 index 000000000..05383b6ad --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/escapes/Xoh_escape_hzip_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.escapes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_escape_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Test public void Escape() { + fxt.Test__bicode("!" , String_.new_a7(Bry_.New_by_byte(Xoh_pool_mgr__hzip.Hook__core))); + } + @Test public void Html() { + fxt.Test__bicode("!" , String_.new_a7(Bry_.New_by_byte(Xoh_pool_mgr__hzip.Hook__html))); + } + @Test public void Mw() { + fxt.Test__bicode("!", ""); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_html__dump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_html__dump__tst.java new file mode 100644 index 000000000..094d69d8b --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_html__dump__tst.java @@ -0,0 +1,104 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_gly_html__dump__tst { + @Before public void init() {fxt.Clear();} private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Test public void Basic() { + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "" + , "File:A.png|A1" + , "File:B.png|B1" + , "" + ), String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Atrs() { + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "" + , "File:A.png|A1" + , "" + ), String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Packed() { + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "" + , "File:A.png|A1" + , "" + ), String_.Concat_lines_nl_skip_last + ( "")); + } +// case Gallery_xnde_atrs.Mode_tid: mode = Gallery_mgr_base_.Get_or_traditional(xatr.Val_as_bry()); break; +// case Gallery_xnde_atrs.Perrow_tid: itms_per_row = xatr.Val_as_int_or(Null); break; +// case Gallery_xnde_atrs.Widths_tid: itm_w = xatr.Val_as_int_or(Null); break; +// case Gallery_xnde_atrs.Heights_tid: itm_h = xatr.Val_as_int_or(Null); break; +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__basic__tst.java new file mode 100644 index 000000000..37213c37a --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__basic__tst.java @@ -0,0 +1,179 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_gly_hzip__basic__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { + fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last + ( "abc")); + } + @Test public void Clear_state() { // page # wasn't being cleared between gallery itms; PAGE:en.w:Almagest; DATE:2016-01-05 + fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~{\"d\"D\"D!#{\"g{\"b0!B1~!1B.png~{\"d\"D\"D!$abc", String_.Concat_lines_nl_skip_last + ( "abc")); + } + @Test public void Extra_cls() { // PURPOSE: handle extra cls; EX: + fxt.Test__bicode("~'1!cls1 cls2~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Caption() { // handle
      • A
      • ; PAGE:en.d:a; DATE:2016-06-24 + fxt.Test__bicode("~'{\"L!Z\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Extra_cls__gallery() { // handle redundant gallery; EX: ; PAGE:en.w:Butuan; DATE:2016-01-05 + fxt.Test__bicode("~'1!gallery~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Xtra_atr() { // PURPOSE: handle extra atr; EX: + fxt.Test__bicode("~'A! id=\"abc\"\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Tidy__br_at_end() { // PURPOSE: handle inconsistent tidy behavior where

        is put on one line ("

        a

        ") unless it ends with
        ("

        a
        \n

        ") + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~'!!\"{\"g{\"b0!A1
        " + , "~!1A.png~9\"D\"D" + ), String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Tidy__empty() { // PURPOSE: no items should place
      on same line + fxt.Test__bicode("~'!!!", String_.Concat_lines_nl_skip_last + ( "")); // TIDY:
        should be on same line if 0 items + } + @Test public void Xnde_atrs() { + fxt.Test__bicode("~'{6({,L!!#?!!$N&#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last + ( "abc")); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__caption__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__caption__tst.java new file mode 100644 index 000000000..b6ecb635b --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__caption__tst.java @@ -0,0 +1,122 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_gly_hzip__caption__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Capt_is_empty() { // PURPOSE: handle empty caption + fxt.Test__bicode("~'!!#{\"g{\"b0#~!1A.png~9\"D\"D{\"g{\"b0#!1A.png9\"D\"D

        abc

        ", String_.Concat_lines_nl_skip_last + ( "

        abc

        ")); + } + @Test public void Capt_is_br() { // PURPOSE: handle captions which have
        , not

        ; PAGE:s.w:Sociology; DATE:2015-12-20 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~'!!\"{\"g{\"b0\"A1" + , "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last + ( "

        ")); + } + @Test public void Capt_has_multiple_p() { // PURPOSE: handle captions with multiple

        ; PAGE:en.w:Wikipedia:Bot_requests/Archive_25; DATE:2016-01-12 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~'!!\"{\"g{\"b0!a
        " + , "b

        " + , "


        " + , "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last + ( "

        ")); + } + @Test public void Capt_has_complicated_nl_behavior() {// handle complicated captions which force
        on different line PAGE:en.w:Tamago_kake_gohan; DATE:2016-01-05 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~'!!\"{\"g{\"b>\"
        \"\"
        " + , "abc~\"\\A.png~#9\"D\"D" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "" + , "
      " + )); + } + @Test public void Capt_has_hr() {// handle
      which causes

      to end early; PAGE:de.v:Kurs:Photoshop_Einzell�sungen/HighKey_mit_CS5; DATE:2016-06-24 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~'!!\"{\"g{\"b>%a

      " + , "
      " + , "b" + , "~\"\\A.png~#9\"D\"D") + , String_.Concat_lines_nl_skip_last + ( "" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__style__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__style__tst.java new file mode 100644 index 000000000..6dffdc43f --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_hzip__style__tst.java @@ -0,0 +1,142 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_gly_hzip__style__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Style__no_max_width() { // PURPOSE: if no perrow=# then no "style='max-width:###; _width:###;'" + fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Style__no_width() { // PURPOSE: if "_width" omitted, do not add back; EX: style="max-width:648px; margin:auto; background:transparent;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12 + fxt.Test__bicode("~'i{,L! color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Style__max_width_duped() { // PURPOSE: if max-width duped, do not delete 2nd; EX: style="max-width:648px; color:blue; max-width:648px;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12 + fxt.Test__bicode("~'){(Z max-width:648px; color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Style__append() { // PURPOSE: handle appended style; EX: + fxt.Test__bicode("~'){,L color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Style__invalid_unclosed() { // handle broken styles; EX: + fxt.Test__bicode("~'9!center~center~\"{\"g{\"bl!abc~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "" + )); + } + @Test public void Style__extra_colon() { // handle broken styles; EX: " + , "
    • " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "

      abc

      " + , "
      " + , "
      " + , "
    • " + , "" + )); + } + @Test public void Style__replace() { // PURPOSE: handle replaced style; EX: + fxt.Test__bicode("~')!color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last + ( "")); + } + @Test public void Style__ws() { // PURPOSE: handle ws in style; EX: " + , "
    • " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "

      A1

      " + , "
      " + , "
      " + , "
    • " + , "")); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_itm_wtr_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_itm_wtr_tst.java new file mode 100644 index 000000000..2880ed57b --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/glys/Xoh_gly_itm_wtr_tst.java @@ -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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.xtns.gallery.*; +public class Xoh_gly_itm_wtr_tst { + private final Xoh_gly_itm_wtr_fxt fxt = new Xoh_gly_itm_wtr_fxt(); + @Test public void Basic() { + fxt.Init__gly(Gallery_mgr_base_.Tid__traditional, -1, -1, -1, 0, 155, 150, 5, "caption"); + fxt.Init__img("/wiki/File:A.png", "A.png", "0|120|120|-1|-1|-1"); + fxt.Test__write(String_.Concat_lines_nl_skip_last + ( "" + , "
    • " + , "" + , "
    • " + )); + } +} +class Xoh_gly_itm_wtr_fxt { + private final Xoh_gly_itm_wtr wtr = new Xoh_gly_itm_wtr(); + private final Bry_bfr tmp_bfr = Bry_bfr_.New(); + public void Init__gly(byte mode, int xnde_w, int xnde_h, int xnde_per_row, int id, int itm_w, int div_1_w, int div_3_margin, String caption) { + wtr.Init(Bool_.N, mode, xnde_w, xnde_h, xnde_per_row, id, 0, 0, itm_w, div_1_w, div_3_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption)); + } + public void Init__img(String href, String xowa_title, String xoimg) { + wtr.Img_wtr().Init_by_gly(gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(href)), Bry_.new_u8(xowa_title), gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(xoimg))); + } + public void Test__write(String expd) { + expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); + wtr.Bfr_arg__add(tmp_bfr); + Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_html_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_html_tst.java new file mode 100644 index 000000000..dd153cb60 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_html_tst.java @@ -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.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_hdr_html_tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Test public void Basic() { + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "z" + , "==A 1==" + , "a 1" + , "==B==" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "z" + , "" + , "

      A 1

      " + , "a 1" + , "" + , "

      B

      " + , "b" + )); + } + @Test public void Uniq() { + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "== a c e ==" + , "text" + ), String_.Concat_lines_nl_skip_last + ( "

      a c e

      " + , "text" + ) + , false); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip_tst.java new file mode 100644 index 000000000..a30b75186 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_hzip_tst.java @@ -0,0 +1,106 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.addons.htmls.tocs.*; +public class Xoh_hdr_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Before public void init() {Xoh_toc_mgr.Enabled = false;} + @After public void term() {Xoh_toc_mgr.Enabled = true;} + @Test public void Same() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"'A~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "
      A
      " + , "a" + )); + } + @Test public void Diff() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"+A~A~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

      A

      " + , "a" + )); + } + @Test public void Diff_by_underscore() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"#A 1~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

      A 1

      " + , "a" + )); + } + @Test public void Diff_by_lnki() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"+Category:A~Category:A~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

      Category:A

      " + , "a" + )); + } + @Test public void Same_w_underscore() { + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~\"#A_1~" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

      A_1

      " + , "a" + )); + } + @Test public void Tidy__bad_end() { + fxt.Test__bicode( + "~\"?A~AB~B~" + , "
      AB
      " + ); + } + @Test public void Tidy__no_span() { // PURPOSE.TIDY: tidy will duplicate hdr if content has center; will fail if span/div is nearby; EX: ==
      A
      ==\n
      ; PAGE:en.s:On_the_Vital_Principle/Book_2/Prelude_to_Chapter_2 DATE:2016-01-21 + fxt.Test__encode(String_.Concat_lines_nl_skip_last + ( "\"+A" + , "
      " + , "

      A

      " + , "
      " + , "" + , "
      " + , "

      abc

      " + , "
      " + ), String_.Concat_lines_nl_skip_last + ( "

      " + , "
      " + , "

      A

      " + , "
      " + , "" + , "
      " + , "

      abc

      " + , "
      " + )); + } + @Test public void Manual__no_id() {// PURPOSE: ignore manual "

      " with no id; PAGE:fr.w:Portail:Nord-Am�rindiens/Image_s�lectionn�e; DATE:2016-07-01 + fxt.Test__bicode + ( "

      A
      " + , "
      A
      " + ); + } + @Test public void Manual__h_has_atrs() {// PURPOSE: ignore manual "

      " with atrs; PAGE:fr.w:Wikip�dia:LiveRC/ToDo; DATE:2016-07-02 + fxt.Test__bicode + ( "

      B
      " + , "
      B
      " + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java new file mode 100644 index 000000000..7929c9865 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/hdrs/Xoh_hdr_make_tst.java @@ -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.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_hdr_make_tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Test public void Basic() { + String html = String_.Concat_lines_nl_skip_last + ( "z" + , "

      A 1

      " + , "a 1" + , "

      B

      " + , "b" + ); + fxt.Test__make(html, fxt.Page_chkr().Body_(html) // make sure body is same + .Sections__add(0, 2, "" , "" , "z") + .Sections__add(1, 2, "A_1" , "A 1" , "a 1") + .Sections__add(2, 2, "B" , "B" , "b") + ); + } + @Test public void Consecutive() { + String html = String_.Concat_lines_nl_skip_last + ( "abc" + , "

      A

      " + , "

      B

      " + , "xyz" + ); + fxt.Test__make(html, fxt.Page_chkr().Body_(html) // make sure body is same + .Sections__add(0, 2, "" , "" , "abc") + .Sections__add(1, 2, "A" , "A" , "") + .Sections__add(2, 2, "B" , "B" , "xyz") + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_bare_hzip__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_bare_hzip__tst.java new file mode 100644 index 000000000..09bf20afc --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_bare_hzip__tst.java @@ -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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.core.envs.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_img_bare_hzip__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + private int prv_os_tid = -1; + @Before public void init() { + fxt.Clear(); + prv_os_tid = Op_sys.Cur().Tid(); + Op_sys.Cur_(Op_sys.Drd.Tid()); // force drd mode; needed for img_bare + } + @After public void term() { + Op_sys.Cur_(prv_os_tid); // revert back to previous mode; otherwise global Op_sys is set to Drd which will cause other tests to fail (notably tidy) + } + @Test public void Hiero() { + fxt.Test__bicode + ( "~(!\"t\"~" + , "t" + ); + } + @Test public void Imap_btn() { + fxt.Test__bicode + ( "~(\"\"About~" + , "\"About" + ); + } + @Test public void Imap_map() { + fxt.Test__bicode + ( "~%}*BhtA.png~#$m#T\"A.png~" + , "\"\"" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java new file mode 100644 index 000000000..1c051e33a --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_html__dump__tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_img_html__dump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Test__html + ( "[[File:A.png|220x110px|upright=.5|abc]]" + , "abc"); + } + @Test public void Empty_link() { + fxt.Test__html("[[File:A.png|220x110px|link=|abc]]", "abc"); + } + @Test public void Lcase_img() { + Make_ns_case_sensitive(fxt.Parser_fxt().Wiki(), gplx.xowa.wikis.nss.Xow_ns_.Tid__file); + fxt.Test__html("[[File:a_b.png]]", "\"\"/"); + } + @Test public void Lcase_video() { + Make_ns_case_sensitive(fxt.Parser_fxt().Wiki(), gplx.xowa.wikis.nss.Xow_ns_.Tid__file); + fxt.Test__html("[[File:a b.ogv]]" + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      \"\"/" + , "
      " + , "
      " + , "
      " + ) + ); + } + private static void Make_ns_case_sensitive(Xow_wiki wiki, int ns_id) { + gplx.xowa.wikis.nss.Xow_ns_mgr ns_mgr = wiki.Ns_mgr(); + gplx.xowa.wikis.nss.Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id); + ns.Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all); + ns_mgr.Init(); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__basic__tst.java new file mode 100644 index 000000000..20d4f7424 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__basic__tst.java @@ -0,0 +1,108 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.wikis.nss.*; +public class Xoh_img_hzip__dump__basic__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void Clear() {fxt.Clear();} + @Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]] + fxt.Test__bicode + ( "~%!!A.png~)#Sabc~" + , "abc" + ); + } + @Test public void Anch() { // [[File:A.png#b|abc]] + fxt.Test__bicode + ( "~%\"abc" + ); + } + @Test public void Href__encoding_foreign() { // [[File:Aéb.png|abc]] + fxt.Test__bicode + ( "~%\"abc" + ); + } + @Test public void Href__encoding_question() { // [[File:A?.png|abc]]; PAGE:en.w:Voiceless_alveolar_affricate; DATE:2016-01-04 + fxt.Test__bicode + ( "~%!qA?.png~)#Sabc~" + , "abc" + ); + } + @Test public void Href__encoding__link() { // [[File:Aéb.png|abc|link=Aéb]] + fxt.Test__bicode + ( "~%#gA%C3%A9b~Aéb.png~#)#Sabc~" + , "abc" + ); + } + @Test public void Href__encoding_percent() { + fxt.Test__bicode + ( "~%!q%24%3F%3D%27.png~)#Sabc~" + , "abc" + ); + } + @Test public void Href__apos() { // [[File:A'b.png|border|link=A'b_link|A'b_capt]] + String html = "\"A'b_capt\""; + fxt.Test__bicode_raw("~%#oA%27b_link~A'b.png~#)#SA'b_capt~", html, html); + } + @Test public void Href__image() { // [[Image:A.png|abc]] + fxt.Test__bicode + ( "~%-%A.png~Image~)#Sabc~" + , "abc" + ); + } + @Test public void Ns__cs() { // [[image:a.png|abc]]; PAGE:en.d:freedom_of_speech DATE:2016-01-21 + fxt.Wiki().Ns_mgr().Ns_file().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all); + fxt.Test__bicode + ( "~%-%a.png~image~)#Sabc~" + , "abc" + ); + fxt.Wiki().Ns_mgr().Ns_file().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__1st); + } + @Test public void Ns__foreign() { // [[Fichier:a.png|abc]]; PAGE:fr.w: DATE:2016-01-21 + Xow_ns_mgr ns_mgr = fxt.Wiki().Ns_mgr(); + ns_mgr.Ns_file().Name_bry_(Bry_.new_u8("Fichier")); ns_mgr.Init_w_defaults(); + fxt.Test__bicode + ( "~%!!a.png~)#Sabc~" + , "abc" + ); + ns_mgr.Ns_file().Name_bry_(Bry_.new_u8("File")); ns_mgr.Init_w_defaults(); + } + @Test public void Missing() { // PURPOSE: bad dump shouldn't write corrupt data + fxt.Test__bicode + ( "%|\"\\QA.png!!!!A" + , "A" + ); + } + @Test public void Manual_img_cls() { // PURPOSE: handle manual class; EX: [[File:A.png|class=noviewer]] en.w:ASCII; DATE:2015-12-21 + fxt.Test__bicode + ( "~%95A.png~)#Sabc~cls1~" + , "abc" + ); + } + @Test public void Manual_img_cls_empty() { // PURPOSE: handle empty class; EX: [[File:A.png|class=""]] de.w:Butter; DATE:2018-04-11 + fxt.Test__bicode + ( "~%!-A.png~)#Sabc~" + , "abc" + ); + } + @Test public void Imap() { + fxt.Test__bicode + ( "~%}#P`uA.png~#:#S#+\"" + , "" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__link__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__link__tst.java new file mode 100644 index 000000000..3be02725e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__link__tst.java @@ -0,0 +1,117 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.wikis.nss.*; +public class Xoh_img_hzip__dump__link__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void Clear() {fxt.Clear();} + @Test public void Link__cs() { // [[File:A.png|link=File:a.ogg|abc]] + fxt.Test__bicode + ( "~%!Aa.ogg~A.png~)#Sabc~" + , "abc" + ); + } + @Test public void Link__anchor() { // [[File:A.png|link=A#B_C|abc]]; PAGE:en.w:Arabic; DATE:2016-01-06 + fxt.Test__bicode + ( "~%#'A#B_C~D.png~#9!I!I" + , "" + ); + } + @Test public void Link__wm__n() { // [[File:A.png|link=http://a.org|abc]] + fxt.Test__bicode + ( "~%!Dhttp://a.org~A.png~)#Sabc~" + , "abc" + ); + } + @Test public void Link__wm__n__encoded() { // PURPOSE: do not double-encode A%C3%A9b.org; [[File:A.png|link=http://Aéb.org|abc]] + fxt.Test__bicode + ( "~%!Dhttp://A%C3%A9b.org~A.png~)#Sabc~" + , "abc" + ); + } + @Test public void Link__wm__y() { // [[File:A.png|link=http://en.wikitionary.org/wiki/Special:Search/A|abc]] + fxt.Test__bicode + ( "~%\"men.wiktionary.org|Search/A~A.png~\")#Sabc~" + , "abc" + ); + } + @Test public void Link__wm__n_2() { // [[File:A.png|link=creativecommons:by/2.5]] + fxt.Test__bicode + ( "~%#(creativecommons.org|by/2.5/~CC-BY-icon-80x15.png~#)!q" + , "" + ); + } + @Test public void Link__media() { // [[File:A.png|link=file:///C:/A.ogg]] + fxt.Test__bicode + ( "~%!D~A.ogg~)!,B~" + , "B" + ); + } + @Test public void Link__encoding() { // [[File:A.svg|24px|text-top|link=wikt:𬖾|𬖾]]; PAGE:en.w:Pho; DATE:2016-01-04 + fxt.Test__bicode + ( "~%#Xen.wiktionary.org|%F0%AC%96%BE~A.png~#)!,abc~B~" + , "B" + ); + } + @Test public void Link__invalid() { // handle invalid titles in link arg; EX:[[File:A.png|link=wikt:]]; PAGE:en.w:List_of_Saint_Petersburg_Metro_stations; DATE:2016-01-04 + fxt.Test__bicode + ( "~%\"mcommons.wikimedia.org|~A.png~1!Abc~" + , "Abc" + ); + } + @Test public void Link__empty() { // empty link should not create anchor; EX:[[File:A.png|link=|abc]]; PAGE:en.w:List_of_counties_in_New_York; DATE:2016-01-10 + fxt.Test__bicode + ( "~%|iVPA.png~#9#S\":abc~" + , "abc" + ); + } + @Test public void Link__empty__tidy() {// should not trigger empty link code; PAGE:en.w:Wikipedia:Reference_Desk_archive_unanswered_2005 ; DATE:2016-01-13 + fxt.Test__bicode + ( "~%|iVPA.png~#!abc~" + , "abc" + ); + } + @Test public void Link__ns_alias() { // [[File:A.png|link=WP:MCB]]; PAGE:en.w:Wikipedia:WikiProject_Molecular_and_Cell_Biology; DATE:2016-01-11 + fxt.Init__ns_alias__add("WP", Xow_ns_.Tid__project); + fxt.Test__bicode + ( "~%/+MCB~A.png~'WP~)!q" + , "" + ); + fxt.Init__ns_alias__del("WP"); + } + @Test public void Link__xwiki_lc() { // [[File:A.png|link=wikt:Category:en:A]]; PAGE:en.w:Portal:Trucks/Wikimedia; DATE:2016-01-11 + fxt.Test__bicode + ( "~%#(en.wiktionary.org|en:A~A.png~1)!q" + , "" + ); + } + @Test public void Link__xwiki_under() {// EX: [[File:A.png|link=User talk:B]]; PAGE:de.b:Wikibooks:Benutzersperrung/_InselFahrer DATE:2016-06-24 + fxt.Test__bicode + ( "~%/,meta.wikimedia.org|B~A.png~&User Talk~!", String_.Concat + ( "" + , "" + , "" + )); + } + @Test public void Link__xwiki_foreign() { // PURPOSE:ns in linked wikis should use canonical name, not current wiki's name PAGE:pl.w:Terytoria_Północno-Zachodnie DATE:2016-10-28 + fxt.Wiki().Ns_mgr().Ids_get_or_null(gplx.xowa.wikis.nss.Xow_ns_.Tid__help).Name_bry_(Bry_.new_a7("Aide")); // simulate non-English wiki with non-english names + fxt.Test__bicode // fails if "Aide:" instead of "Help:" + ( "~%.qen.wiktionary.org|~A.png~/Help~)#Sabc~" + , "abc" + ); + fxt.Wiki().Ns_mgr().Ids_get_or_null(gplx.xowa.wikis.nss.Xow_ns_.Tid__help).Name_bry_(Bry_.new_a7("Help")); // revert + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__orig__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__orig__tst.java new file mode 100644 index 000000000..b0dd19f2f --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__orig__tst.java @@ -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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.wikis.nss.*; +public class Xoh_img_hzip__dump__orig__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void Clear() {fxt.Clear();} + @Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]] + fxt.Test__bicode + ( "~%|\"\\QA.png~$m#Tabc~" + , "abc" + ); + } + @Test public void Orig() { // PURPOSE: orig with width was causing "!!" in alt; EX:[[File:A.png|abc]]; DATE:2016-08-09 + fxt.Test__bicode + ( "~%|#gqA.png~!b!Babc~" + , "abc" + ); + } + @Test public void Gallery() { + fxt.Test__bicode + ( "~%|3]3A.png~!b!B\"Mabc~" + , "abc" + ); + } + @Test public void Encode() { // [[File:A+C.png|abc]] + fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_(); + fxt.Test__bicode + ( "~%|\"\\qA%2BC.png~A+C.png~$m#Tabc~" + , "abc" + ); + } + @Test public void Link() { // [[File:A.png|link=File:a.ogg|abc]]; [[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/9/7/4/e/En-us-Alabama.ogg|Listen]] + fxt.Test__bicode + ( "~%}'h(qA.ogg~\"M!babc~A.png~" + , "abc" + ); + } + @Test public void Link__empty() { // [[File:A.png|link=|abc]]; PAGE:en.w:Lackawanna_Cut-Off; DATE:2016-08-19 + fxt.Test__bicode + ( "~%}([^KA.png~#\"M!babc~A.png~" + , "abc" + ); + } + @Test public void Encode_2() { // [[File:A*C.png|abc]]; PAGE:en.w:Fibonacci_number; DATE:2016-08-10 + // Tfds.Write(gplx.xowa.files.Xof_file_wkr_.Md5(Bry_.new_a7("A*C.png"))); + fxt.Test__bicode + ( "~%|\"\\QA*C.png~$m#Tabc~" + , "abc" + ); + } + @Test public void Video() { // handle thumbnail + fxt.Test__bicode + ( "~%|=nTA.ogv~$m#T#T4.5~abc~" + , "abc" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__pgbnr__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__pgbnr__tst.java new file mode 100644 index 000000000..2fac4480c --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__dump__pgbnr__tst.java @@ -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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.wikis.nss.*; +public class Xoh_img_hzip__dump__pgbnr__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void Clear() {fxt.Clear();} + @Test public void Basic() { + fxt.Test__bicode + ( "~%}$DP@A.png~\"A~~wpb-banner-image ~00" + , "" + ); + } + @Test public void Data_pos_x() { // PAGE:en.v:Antartica; DATE:2016-07-12 + fxt.Test__bicode + ( "~%}$DP@A.png~\"A~~wpb-banner-image ~1.20" + , "" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java new file mode 100644 index 000000000..7058bd2b7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip__view__tst.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_img_hzip__view__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Before public void Clear() {fxt.Clear();} + @Test public void Basic__border__class__caption() { // [[File:A.png|border|class=other|220px|abc]] + fxt.Test__bicode + ( "~%iAA.png#T\";abc~other~" + , "abc" + ); + } + @Test public void Link() { // [[File:A.png|link=B]] + fxt.Test__bicode + ( "~%}'h+RB~A.png##T\";B~A.png~A.png~" + , "A.png" + ); + } + // link_site: [[File:A.png|link=//en.wiktionary.org/B]] -> [[File:Wiktionary-logo-en.svg|25x25px|link=//en.wiktionary.org/wiki/Special:Search/Earth|Search Wiktionary]] -> Search Wiktionary +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java new file mode 100644 index 000000000..5cde3d6e7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_make__dump__tst.java @@ -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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_img_make__dump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Before public void Init() {fxt.Clear();} + @Test public void Html_exists__n() { + String + orig = "abc" + , expd = "abc" + ; + fxt.Test__make(orig, fxt.Page_chkr().Body_(expd) + .Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1) + ); + } + @Test public void Utf8() { + String + orig = "abc" + , expd = "abc" + ; + fxt.Test__make(orig, fxt.Page_chkr().Body_(expd) + .Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1) + ); + } +// @Test public void Html_exists__y__cache() { +// String +// orig = "abc" +// , expd = "abc" +// ; +// fxt.Init_img_cache("en.w", "A.png", 0, 0.5, 220, 110, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1); +// fxt.Test__make(orig +// , fxt.Page_chkr().Body_(expd) +// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1) +// ); +// } +// @Test public void Html_exists__y__html() { +// String +// orig = "abc" +// , expd = "abc" +// ; +// fxt.Test__make(orig +// , fxt.Page_chkr().Body_(expd) +// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1) +// ); +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java new file mode 100644 index 000000000..7a46b196c --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_cls__tst.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; +import org.junit.*; +public class Xoh_img_cls__tst { + private Xoh_img_cls__fxt fxt = new Xoh_img_cls__fxt(); + @Test public void To_html() { + fxt.Test__to_html(Xoh_img_cls_.Tid__none , null , ""); + fxt.Test__to_html(Xoh_img_cls_.Tid__none , "a" , " class=\"a\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbimage , null , " class=\"thumbimage\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , null , " class=\"thumbborder\""); + fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , "a" , " class=\"thumbborder a\""); + } +} +class Xoh_img_cls__fxt { + public void Test__to_html(byte tid, String other, String expd) { + Tfds.Eq(expd, String_.new_u8(Xoh_img_cls_.To_html(tid, Bry_.new_u8_safe(other)))); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_data_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_data_tst.java new file mode 100644 index 000000000..4a1a9a73e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/atrs/Xoh_img_src_data_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; +import org.junit.*; import gplx.core.brys.*; +import gplx.xowa.wikis.domains.*; +public class Xoh_img_src_data_tst { + private final Xoh_img_src_data_fxt fxt = new Xoh_img_src_data_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1); + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, -1); + } + @Test public void Video() { + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.ogv/220px-5.jpg" , "commons.wikimedia.org" , Bool_.N, "A.ogv", 220, 5, -1); + } + @Test public void Pdf() { + fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.pdf/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.pdf", 220, -1, 5); + } + @Test public void Md5_depth_4() { + fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/1/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1); + } + @Test public void Math() { // PURPOSE: "xowa:/math" shouldn't cause img_src_parser to fail; DATE:2016-11-17 + fxt.Test__parse("xowa:/math/596f8baf206a81478afd4194b44138715dc1a05c" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1); + } +// @Test public void Fail__orig_mode() { +// fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'"); +// } +// @Test public void Fail__repo_mode() { +// fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'"); +// } +} +class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_src_data parser = new Xoh_img_src_data(); + public void Clear() { + Xoa_app_fxt.repo2_(app, wiki); + hctx.Init_by_page(wiki, new Xoh_page()); + } + @Override public Xoh_itm_parser Parser_get() {return parser;} + public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) { + Exec_parse(src_str); + if (parser.Repo_end() != -1) // need for Math() + Tfds.Eq_str(expd_repo, String_.new_u8(src, parser.Repo_bgn(), parser.Repo_end())); + if (parser.File_ttl_end() != -1) // need for Math() + Tfds.Eq_str(expd_file, String_.new_u8(src, parser.File_ttl_bgn(), parser.File_ttl_end())); + Tfds.Eq_bool(expd_file_is_orig, parser.File_is_orig()); + Tfds.Eq_int(expd_w, parser.File_w()); + Tfds.Eq_double(expd_time, parser.File_time()); + Tfds.Eq_int(expd_page, parser.File_page()); + } + @Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) { + parser.Fail_throws_err_(true); + parser.Parse(err_wkr, new Xoh_hdoc_ctx(), Xow_domain_itm_.Bry__enwiki, src_bgn, src_end); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__basic__tst.java new file mode 100644 index 000000000..3583935ec --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__basic__tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnke_html__basic__tst { + @After public void term() {fxt.Init_para_n_(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Auto__one() {fxt.Test_parse_page_wiki_str("[https://a]" , "[1]");} + @Test public void Auto__many() {fxt.Test_parse_page_wiki_str("[https://a] [https://b]" , "[1] [2]");} + @Test public void Text__basic() {fxt.Test_parse_page_wiki_str("[https://a b]" , "b");} + @Test public void Text__wtxt() {fxt.Test_parse_page_wiki_str("[https://a ''b'']" , "b");} + @Test public void Xowa_protocol() { + String img = ""; + fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(true); + fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" z]" , "z" + img + ""); + fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a.b('c_d');\" z]" , "z" + img + ""); + fxt.Test_parse_page_wiki_str("[xowa-cmd:*\"a\"b*c\"* z]" , "z" + img + ""); + fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(false); + fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" b]" , "[xowa-cmd:"a" b]"); // protocol is disabled: literalize String (i.e.: don't make it an anchor) + } + @Test public void Xwiki() { + String wtxt = "[//en.wiktionary.org/wiki/A B]"; + String html_https = "B"; + String html_xwiki = "B"; + fxt.Test__parse__wtxt_to_html(wtxt, html_https); // https b/c wiki not installed + fxt.Init_xwiki_add_user_("en.wiktionary.org"); + fxt.Test__parse__wtxt_to_html(wtxt, html_xwiki); // xwiki b/c wiki installed + fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump); + fxt.Test__parse__wtxt_to_html(wtxt, html_https); // https b/c hdump, even though wiki installed + fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__hdump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__hdump__tst.java new file mode 100644 index 000000000..64970520d --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_html__hdump__tst.java @@ -0,0 +1,28 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_lnke_html__hdump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + public static final String + Html__free = "http://a.org" + , Html__auto = "[1]" + , Html__text = "a" + ; + @Test public void Free() {fxt.Test__html("http://a.org" , Html__free);} + @Test public void Auto() {fxt.Test__html("[http://a.org]" , Html__auto);} + @Test public void Text() {fxt.Test__html("[http://a.org a]" , Html__text);} +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip_tst.java new file mode 100644 index 000000000..73f0bf350 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkes/Xoh_lnke_hzip_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.hzips.*; +public class Xoh_lnke_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt(); + @Test public void Free() { + fxt.Test__bicode("~#!http://a.org~", Xoh_lnke_html__hdump__tst.Html__free); + } + @Test public void Free__ws_at_end() { + fxt.Test__bicode("~#%https://a.org/. ~https://a.org/.~", "https://a.org/."); + } + @Test public void Auto() { + fxt.Test__bicode("~#*http://a.org~\"", Xoh_lnke_html__hdump__tst.Html__auto); + } + @Test public void Auto__tidy() { // PURPOSE:handle reparenting of html elements by HTML tidy EX:[http://a.org]; DATE:2015-08-25 + fxt.Test__bicode + ( "~#&http://a.org~[123]~" + , "[123]" + ); + } + @Test public void Auto__invalid_number() { + String html = "[abc]"; + fxt.Test__bicode("~#&http://a.org~[abc]~", html); + } + @Test public void Text() { + fxt.Test__bicode("~#'http://a.org~a~", Xoh_lnke_html__hdump__tst.Html__text); + } + @Test public void Wikivoyage__sleep() { + fxt.Test__bicode + ( "~#7http://a.org~c~b~" + , "c"); + } +// @Test public void Xwiki__exists() { +// String hzip = "~#'https://en.wiktionary.org/wiki/A~A~"; +// String html_https = "A"; +// String html_xwiki = "A"; +// fxt.Test__bicode(hzip, html_https); +// fxt.Init_wiki_installed("en.wiktionary.org"); +// fxt.Test__decode(hzip, html_xwiki); +// } + @Test public void Fail__href() { + String html = "a"; + fxt.Test__encode__fail(html, html); + } + @Test public void Fail__lnke_type() { + String html = "a"; + fxt.Test__encode__fail(html, html); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__basic__tst.java new file mode 100644 index 000000000..a0a6f73f9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__basic__tst.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_html__basic__tst { + @After public void term() {fxt.Init_para_n_(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Ns__title() { // PURPOSE: title should have full ns; "title='Help talk:A'" not "title='A'" DATE:2015-11-16 + fxt.Wtr_cfg().Lnki__title_(Bool_.Y); + fxt.Test__parse__wtxt_to_html("[[Help talk:A b]]" , "Help talk:A b"); + fxt.Wtr_cfg().Lnki__title_(Bool_.N); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java new file mode 100644 index 000000000..bb9efb4e8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_html__hdump__tst.java @@ -0,0 +1,32 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_lnki_html__hdump__tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Same() {fxt.Test__html("[[A]]" , "A");} + @Test public void Diff() {fxt.Test__html("[[A|b]]" , "b");} + @Test public void Trail() {fxt.Test__html("[[A]]b" , "Ab");} + @Test public void Xwiki() { + fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org"); + fxt.Test__html("[[wikt:a]]", "wikt:a"); + } + @Test public void Anch() {fxt.Test__html("[[#a]]" , "#a");} + @Test public void Alt_has_quotes() { + fxt.Test__html("[[File:A.png|alt=[[\"A\"]] B c]]", "\""A""); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__anch__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__anch__tst.java new file mode 100644 index 000000000..f4ccb877f --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__anch__tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_hzip__anch__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { // EX: [[#a]] + fxt.Test__bicode("~$Ba~#a~", "#a"); + } + @Test public void Capt() { // EX: [[#a|b]] + fxt.Test__bicode("~$Ba~b~", "b"); + } + @Test public void Capt_similar() { // EX: [[#a|a]] + fxt.Test__bicode("~$Ba~a~", "a"); + } + @Test public void Error() { // EX: [[#a|b]]; make sure bad title character does not cause error + fxt.Test__bicode("~$Ba|b~#a|b~", "#a|b"); // NOTE: the "|" should be url-encoded + } + @Test public void Inet__file() { + fxt.Test__bicode("~$Rfile:///C://A.png~b~", "b"); + } + @Test public void Inet__enc() { + fxt.Test__bicode("~${'Thttps://simple.wikisource.org/wiki/A%C3%A6e~b~Aæe~", "b"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__diff__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__diff__tst.java new file mode 100644 index 000000000..dee968307 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__diff__tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_hzip__diff__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Diff__basic() { // EX: [[A|b]] + fxt.Test__bicode("~$\"A~b~" , "b"); + } + @Test public void Diff__cs__lo() { // EX: [[A|a]] + fxt.Test__bicode("~$%A~" , "a"); + } + @Test public void Diff__page_w_anch() { // EX: [[A#b|c]] + fxt.Test__bicode("~${'$A#b~b~A~", "b"); + } + @Test public void Capt__nest() { // EX: [[A|B[[C|C1]]D]] + fxt.Test__bicode + ( "~$\"A~BC1D~" + , "BC1D" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__ns__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__ns__tst.java new file mode 100644 index 000000000..3dfbc8726 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__ns__tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_hzip__ns__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Ns__same() { // EX: [[Help:A]] + fxt.Test__bicode("~${#7/A~", "Help:A"); + } + @Test public void Ns__diff() { // EX: [[Help:A_b|c]] + fxt.Test__bicode("~$b/A b~c~", "c"); + } + @Test public void Ns__more() { // EX: [[Help:A|a b]] + fxt.Test__bicode("~$g/A~ b~", "a b"); + } + @Test public void Ns__less() { // EX: [[Help:A_b|a]] + fxt.Test__bicode("~$h/A~ b~", "a"); + } + @Test public void Ns__talk() { // EX: [[Help talk:A b]] + fxt.Test__bicode("~${#70A b~", "Help talk:A b"); + } + @Test public void Ns__talk__diff() { // EX: [[Help talk:A b|cde]] + fxt.Test__bicode("~$b0A b~cde~", "cde"); + } + @Test public void Ns__under() { // EX: [[Help_talk:A_b]]; rare; just make sure codec can handle it; + fxt.Test__bicode("~$b0A b~Help_talk:A_b~", "Help_talk:A_b"); + } + @Test public void Ns__pipe() { // EX: [[Help:A|]] + fxt.Test__bicode("~$a/A~", "A"); + } + @Test public void Ns__pipe_w_words() { // EX: [[Help:A b|]] + fxt.Test__bicode("~$a/A b~", "A b"); + } + @Test public void Ns__anch() { // EX: [[Help:A_b#c|a]] + fxt.Test__bicode("~${'j/A~ b#c~Help:A b~", "a"); + } + @Test public void Ns__anch__alias() { // EX: [[Help:A_b#c|a]] + fxt.Test__bicode("~${3h)Image~A.png#b~c~Image:A.png~", "c"); + } + @Test public void Fake__ns() { // EX: [[Fake:A]] + fxt.Test__bicode("~$!Fake:A~", "Fake:A"); + } + @Test public void Alias__basic() { // EX: [[Image:A]] + fxt.Test__bicode("~${-f)Image~A~B~", "B"); + } + @Test public void Alias__talk() { // EX: [[Image talk:A]] + fxt.Test__bicode("~${/;*Image talk~Human-woman.png~", "Image talk:Human-woman.png"); + } + @Test public void Alias__words() { // EX: [[Image:A b]] + fxt.Test__bicode("~${/;)Image~A b~", "Image:A b"); + } + @Test public void Alias__url_encoding() { // EX: [[Image:Aü.png|b]] + fxt.Test__bicode("~${3h)Image~A%C3%BC.png~b~Image:Aü.png~", "b"); + } + @Test public void Ctg__main() { // links at bottom of pages in main ns; DATE:2015-12-28 + fxt.Test__bicode("~$|%\"(1A~", "A"); + fxt.Test__decode("~$|$t'1A~", "A"); // NOTE:backward compatibility for en.w:2015-12; delete after 2016-01 is uploaded + } + @Test public void Ctg__tree() { // links on Category pages; + fxt.Test__bicode("~$|&3J1A~", "A"); + } + @Test public void Ctg__xnav__space() { // previous / next 200 links on Category pages + fxt.Test__bicode("~$|&`Z1A B?pageuntil=C, D#mw-pages~previous 200~Category:A_B~", "previous 200"); + } + @Test public void Ctg__xnav__under() { // previous / next 200 links on Category pages; PAGE:en.w:Category:Public_transit_articles_with_unsupported_infobox_fields; DATE:2016-01-14 + fxt.Test__bicode("~$|&`Z1A B?pageuntil=C,_D#mw-pages~previous 200~Category:A_B~", "previous 200"); + } + @Test public void Outlier__title_wo_ns() {// should not happen, but handle situation wherein title doesnot have ns PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20 + fxt.Test__bicode("~${Tr/A B~", "A B"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__same__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__same__tst.java new file mode 100644 index 000000000..5710b8618 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__same__tst.java @@ -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.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_hzip__same__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Same__basic() { // EX: [[A]] + fxt.Test__decode("~$!A~", "A"); + } + @Test public void Same__encoded() { // EX: [[A's]] + String html = "A's"; + fxt.Test__bicode_raw("~${$#A%27s~A's~", html, html); + } + @Test public void Same__encoded__anch() { // EX: [[A#90.51]] + fxt.Test__bicode("~${$%A~#90.51~", "A"); + } + @Test public void Same__encoded__anch__nbsp() { // EX: [[A# B|abc]] + fxt.Test__bicode("~${$#A#.C2.A0B~abc~", "abc"); + } + @Test public void Same__amp() { // EX: [[A&b]] + fxt.Test__bicode("~${$#A%26b~A&b~", "A&b"); + } + @Test public void More__basic() { // EX: [[A]]b + fxt.Test__bicode("~$#A~b~", "Ab"); + } + @Test public void Less__cs__eq() { // EX: [[Ab|A]] + fxt.Test__bicode("~$$A~b~", "A"); + } + @Test public void Less__cs__lo() { // EX: [[Ab|a]] + fxt.Test__bicode("~$(A~b~", "a"); + } + @Test public void Less__ns__cs() { // EX: [[Help:A_b|a]]; make sure ns is added correctly, not "aHelp:b" + fxt.Test__bicode("~$h/Ab~ c~", "ab"); + } + @Test public void Ignore__audio() { + String html = "a"; + fxt.Test__bicode(html, html); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__site__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__site__tst.java new file mode 100644 index 000000000..6eec057ea --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/Xoh_lnki_hzip__site__tst.java @@ -0,0 +1,82 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; +public class Xoh_lnki_hzip__site__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { // EX: [[wikt:A]] + fxt.Test__bicode("~${$3en.wiktionary.org~A~wikt:A~" , "wikt:A"); + } + @Test public void Capt__lower() { // EX: [[wikt:A|a]] + fxt.Test__bicode("~$5en.wiktionary.org~A~" , "a"); + } + @Test public void Capt__upper() { // EX: [[wikt:a|A]] + fxt.Test__bicode("~$9en.wiktionary.org~a~" , "A"); + } + @Test public void Ns__href() { // EX: [[wikt:help:a]] + fxt.Test__bicode("~${a2en.wiktionary.org~/help~a~wikt:help:a~" , "wikt:help:a"); + } + @Test public void Ns__capt() { // EX: [[wikt:help:a|b]] + fxt.Test__bicode("~${d3en.wiktionary.org~/help~a~b~wikt:help:a~" , "b"); // MW: also adds class="extiw" + } + @Test public void Ns__anch() { // EX: [[wikt:Help:A#b]] + fxt.Test__bicode("~${'sen.wiktionary.org~/A#b~Help:A~" , "A#b"); + } + @Test public void Ns__more() { // EX: [[wikt:Help:A]]b + fxt.Test__bicode("~${#Ien.wiktionary.org~/A~b~" , "Help:Ab"); + } + @Test public void Ns__more__name() { // EX: [[wikt:Help:A|Ab|]] + fxt.Test__bicode("~$sen.wiktionary.org~/A~b~" , "Ab"); + } + @Test public void Ns__url_encoding() { // EX: [[wikt:Category:A & B|]] + fxt.Test__bicode("~${$sen.wiktionary.org~1A %26 B~A & B~" , "A & B"); + } + @Test public void Less__eq() { // EX: [[wikt:Ab|A]] + fxt.Test__bicode("~${*7en.wiktionary.org~A~b~" , "A"); + } + @Test public void Less__lo() { // EX: [[wikt:Ab|a]] + fxt.Test__bicode("~$8en.wiktionary.org~A~b~" , "a"); + } + @Test public void Less__hi() { // EX: [[wikt:ab|A]] + fxt.Test__bicode("~$A"); + } + @Test public void More__hi() { // EX: [[wikt:a|Ab]] + fxt.Test__bicode("~$;en.wiktionary.org~a~b~" , "Ab"); + } + @Test public void Encode__lnki() { // EX: [[wikt:eorðe|eorðe]] + fxt.Test__bicode("~${$3en.wiktionary.org~eor%C3%B0e~eorðe~" , "eorðe"); + } +// @Test public void Encode__lnke() { // EX: [//en.wiktionary.org/wiki/eorðe eorðe]; NOTE:MW inconsistently does not URL-encode external links (but does URL-encode @gplx.Internal protected ones) +// fxt.Test__bicode("~$)en.wiktionary.org~eorðe~" , "eorðe"); +// } + @Test public void Lnke__ns() { + fxt.Test__bicode("~$qen.wiktionary.org~/a~" , "a"); + } + @Test public void Qarg_lnke() { // EX: [//en.wiktionary.org/wiki/A?b=c d] + fxt.Test__bicode("~${*5en.wiktionary.org~A?b=c~d~" , "d"); + } + @Test public void Qarg_lnki() { // EX: [[wikt:A?b=c|d]] + fxt.Test__bicode("~$2en.wiktionary.org~A?b=c~d~" , "d"); // NOTE: mw encodes as A%3Fb%3Dc + } + @Test public void Main_page() { // EX: [[wikt:]] + fxt.Test__bicode("~${<wikt:"); + } + @Test public void Wikivoyage__email() { + fxt.Test__bicode + ( "$|)%6mailto:ab" + , ""); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_capt_itm_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_capt_itm_tst.java new file mode 100644 index 000000000..5fe53d587 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_capt_itm_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.docs.*; +public class Xoh_anch_capt_itm_tst { + private final Xoh_anch_capt_itm_fxt fxt = new Xoh_anch_capt_itm_fxt(); + @Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_anch_capt_itm.Tid__same);} + @Test public void Basic__diff() {fxt.Test__match("Abc" , "ABC", Xoh_anch_capt_itm.Tid__diff);} + @Test public void Space__same() {fxt.Test__match("A_b" , "A b", Xoh_anch_capt_itm.Tid__same);} + @Test public void Case__same() {fxt.Test__match("Abc" , "abc", Xoh_anch_capt_itm.Tid__same);} +// @Test public void Case__reverse() {fxt.Test__match("abc" , "Abc", Xoh_anch_capt_itm.Tid__diff);} +// @Test public void Case__disabled() { +// fxt.Wiki().Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all); +// fxt.Test__match("Abcde", "abcde", Xoh_anch_capt_itm.Tid__diff); +// } + @Test public void Ns__href() {fxt.Test__match("Help_talk:Ab" , "Help talk:Ab" , Xoh_anch_capt_itm.Tid__same);} + @Test public void Capt_trail() {fxt.Test__match("A" , "Abc" , Xoh_anch_capt_itm.Tid__more, 1);} + @Test public void Href_trail() {fxt.Test__match("Ab" , "A" , Xoh_anch_capt_itm.Tid__less, 1);} +} +class Xoh_anch_capt_itm_fxt { + private final Xoh_anch_capt_itm matcher = new Xoh_anch_capt_itm(); + private final Bry_rdr rdr = new Bry_rdr(); + public Xoh_anch_capt_itm_fxt() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki; + public void Test__match(String page_str, String capt_str, int expd_tid) {Test__match(page_str, capt_str, expd_tid, -1);} + public void Test__match(String page_str, String capt_str, int expd_tid, int expd_trail_bgn) { + byte[] page_bry = Bry_.new_u8(page_str); + byte[] capt_bry = Bry_.new_u8(capt_str); + Xoa_ttl href_ttl = wiki.Ttl_parse(page_bry); + boolean ns_is_cs = href_ttl.Ns().Case_match() == gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all; + Tfds.Eq_int(expd_tid , matcher.Parse(rdr.Init_by_page(Bry_.Empty, page_bry, page_bry.length), ns_is_cs, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length)); + Tfds.Eq_int(expd_trail_bgn , matcher.Split_pos()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_data_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_data_tst.java new file mode 100644 index 000000000..17d0951c5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/anchs/Xoh_anch_href_data_tst.java @@ -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.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*; +public class Xoh_anch_href_data_tst { + private final Xoh_anch_href_data_fxt fxt = new Xoh_anch_href_data_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Site() { + fxt.Test__parse("/site/A/wiki/B", "A", "B"); + } + @Test public void Page() { + fxt.Test__parse("/wiki/B", "", "B"); + } + @Test public void Href() { + fxt.Test__parse("#A", "", "A"); + } + @Test public void None() { + fxt.Test__parse("", "", ""); + } + @Test public void Inet() { + fxt.Test__parse("http://a.org", "", "http://a.org"); + } +// @Test public void Inet__mw() { +// fxt.Test__parse("https://en.wikipedia.org/wiki/A", "en.wikipedia.org", "A"); +// } + @Test public void Fail__1st_seg_must_be_site_or_wiki() { + fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' page='Main_Page' sect='href' text=/fail/A"); + } + @Test public void Fail__2nd_seg_must_be_wiki() { + fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' page='Main_Page' sect='href' text=/site/A/B/C"); + } +} +class Xoh_anch_href_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_anch_href_data parser = new Xoh_anch_href_data(); + public void Clear() { + Xoa_app_fxt.repo2_(app, wiki); + hctx.Init_by_page(wiki, new Xoh_page()); + } + @Override public Xoh_itm_parser Parser_get() {return parser;} + public void Test__parse(String src_str, String expd_site, String expd_page) { + Exec_parse(src_str); + Tfds.Eq_str(expd_site, parser.Site_bgn() == -1 ? "" : String_.new_u8(src, parser.Site_bgn(), parser.Site_end())); + Tfds.Eq_str(expd_page, String_.new_u8(src, parser.Ttl_bgn(), parser.Ttl_end())); + } + @Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) { + parser.Parse(err_wkr, hctx, err_wkr.Src(), src_bgn, src_end); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__audio__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__audio__tst.java new file mode 100644 index 000000000..6ece14e5e --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__audio__tst.java @@ -0,0 +1,102 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xoh_file_wtr__audio__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Audio__full() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.oga|noicon]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Audio__full_ogg() {// PURPOSE: ogg should show src on first load + fxt.Wiki().Html_mgr().Img_suppress_missing_src_(true); // simulate release-mode wherein missing images will not have src + fxt.Test_parse_page_all_str + ( "[[File:A.ogg]]", String_.Concat_lines_nl_skip_last + ( " " + )); + fxt.Wiki().Html_mgr().Img_suppress_missing_src_(false); + } + @Test public void Audio__thumb() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.oga|thumb|a|alt=b]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      a" + , "
      " + , "
      " + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Audio__full_width() { // ISSUE: width arg ignored for v2; zh.b:小学数学/自然数; DATE:2014-05-03 + fxt.Wiki().File_mgr().Version_2_y_(); + fxt.App().Usere().Init_by_app(fxt.App()); // TEST: init cache else null reference + fxt.Test_html_wiki_frag("[[File:A.oga|30px|a]]", "
      "); + fxt.Wiki().File_mgr().Version_1_y_(); + } + @Test public void Audio__noicon() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.oga|thumb|noicon|a|alt=b]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      a" + , "
      " + , "
      " + , "
      " + , "
      b" + , "
      " + , "
      " + )); + } +} +// @Test public void Ogg() { +// fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(0); +// fxt .ini_page_api("commons", "A.ogg", "", 0, 0); +// fxt .Lnki_orig_("A.ogg") +// .Src( ) +// .Trg( +// fxt.reg_("mem/xowa/file/#meta/en.wikipedia.org/4/42.csv", "A.ogg|z||2?0,0|0?0,0") +// ) +// .tst(); +// fxt .Lnki_orig_("A.ogg") +// .Html_orig_src_("file:///mem/trg/en.wikipedia.org/raw/4/2/A.ogg") +// .tst(); +// fxt.Src_en_wiki_repo().Ext_rules().Get_or_new(Xof_ext_.Bry_ogg).View_max_(-1); +// } diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__basic__tst.java new file mode 100644 index 000000000..60792850f --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__basic__tst.java @@ -0,0 +1,378 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xoh_file_wtr__image__basic__tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Img__full() { // PURPOSE: full with title was outputting invalid html; DATE:2013-12-31 + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png]]" + , String_.Concat_lines_nl_skip_last + ( "\"\"" // NOTE: used to output class=\"image\"A.png + )); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Xowa_title__quotes() { // PURPOSE: xowa_title should encode quotes DATE:2015-11-27 + fxt.Test_parse_page_wiki_str + ( "[[File:A%22b.png]]" + , String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + } + @Test public void Img__embed() { + fxt.Test_parse_page_wiki_str("[[File:A.png|9x8px|alt=abc]]", Xop_fxt.html_img_none("File:A.png", "abc", "file:///mem/wiki/repo/trg/thumb/7/0/A.png/9px.png", "A.png")); + } + @Test public void Embed_audio() { + fxt.Test_parse_page_wiki_str("[[File:A.jpg|thumb|b[[File:C.ogg|right|140x140px]]d]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b
      " + , "
      \"\"" + , "
      " + , "
      " + , "
      d" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Img__none() { // NOTE: floatnone is WP behavior; MW omits div tag + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|none|20x30px|b]]" + , String_.Concat_lines_nl_skip_last + ( "
      " + , "\"b\"
      " + )); + } + @Test public void Img__thumb_none() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|thumb|none|b]]" + , Img_thumb_str("none") + ); + } + @Test public void Img__thumb_ltr() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|thumb|b]]" + , Img_thumb_str("right") + ); + } + @Test public void Img__thumb_rtl() { + fxt.Wiki().Lang().Dir_ltr_(false); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|thumb|b]]" + , Img_thumb_str("left") + ); + fxt.Wiki().Lang().Dir_ltr_(true); + } + private String Img_thumb_str(String align) { + return String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "" + ); + } + @Test public void Img__frame() { // PURPOSE: lnki with "frame" is same as thumb; DATE:2013-12-23 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|frame|220x110px|b]]" + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Img__frame_and_thumb() { // PURPOSE: lnki with "frame and thumb" was not showing box due to bit-adding; PAGE:en.w:History_of_Western_Civilization DATE:2015-04-16 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|frame|thumb|220x110px|b]]" // NOTE: frame AND thumb + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Thm__alt_is_ws() { // PURPOSE: alt with space should not output
      ; EX:[[File:A.png|thumb|alt= ]]; en.w:Bird; DATE:2015-12-28 + fxt.Test_parse_page_all_str + ( "[[File:A.png|thumb|220x110px|alt= ]]" + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Cls_border() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|border]]" + , "\"\""); + } + @Test public void Cls_custom() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|class=abc]]" + , "\"\""); + } + @Test public void Cls_border_custom() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|border|class=abc]]" + , "\"\""); + } + @Test public void Lnki_full_svg() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.svg|a|alt=b]]", String_.Concat_lines_nl_skip_last + ( "\"b\"" // HACK: tries to get orig_w which is not available + )); + } + @Test public void Lnki_file_alt_link() { // PURPOSE: lnki in caption should not create alt="bcd" + fxt.Test_parse_page_wiki_str("[[File:A.png|thumb|alt=b [[c]] d]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"b" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      b c d" + , "
      " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Pre_in_caption() { // PURPOSE: ignore pre if in caption; PAGE:s.w:Virus; DATE:2015-03-31 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "[[File:A.png|thumb|a\n b]]" // "\n " is pre + ), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      a" // no pre + , " b" + , "
      " + , "
      " + , "
      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Img__title() { + fxt.Wtr_cfg().Lnki__title_(true); + Tst_img_title("[[File:A.png|frameless|a b]]", "a b"); + Tst_img_title("[[File:A.png|thumb|a b]]", "Enlarge"); // caption should not replace text + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Title_escape() { // PURPOSE: escape quotes in title; PAGE:none; DATE:2014-10-27 + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_wiki_str("[[A\"B]]", "A\"B"); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Img__title__caption_has_lnki() { // PURPOSE: caption with lnki should show in title; PAGE:en.w:Earth; DATE:2014-08-06 + fxt.Wtr_cfg().Lnki__title_(true); + Tst_img_title("[[File:A.png|frameless|[[A]]]]" , "A"); // ttl only + Tst_img_title("[[File:A.png|frameless|[[A|B]]]]" , "B"); // caption + Tst_img_title("[[File:A.png|frameless|[[A]]b]]" , "Ab"); // tail + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Lnki_alt_is_text() { // PURPOSE: (a) alt should default to caption; (b) alt should not show html chars (like \"abc\"" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Alt_ignore_apos() {// PURPOSE: alt should ignore apos; EX: [[File:A.png|''A'']] should have alt of A; DATE:2013-10-25 + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_all_str + ( "[[File:A.png|''b'']]" + , "\"b\"" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Alt_ignore_lnke() {// PURPOSE: alt should ignore lnke + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_all_str + ( "[[File:A.png|b[http://c.org d] e]]" + , "\"bd" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Alt_ignore_list() {// PURPOSE: alt should ignore list + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_all_str + ( "[[File:A.png|b\n*c]]" + , "\"b*c\"" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Alt_ignore_tblw() {// PURPOSE: alt should ignore tblw + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_all_str + ( "[[File:A.png|\n{|\n|-\n|b\n|}\n]]" + , "\"" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Alt_ignore_para() {// PURPOSE: alt should ignore para + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str + ( "[[File:A.png|b\nc]]" + , String_.Concat_lines_nl + ( "

      \"b" + , "

      " + )); + fxt.Init_para_n_(); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Lnki_empty_alt_is_omitted() {// PURPOSE: empty alt should be ignored; DATE:2013-07-30 + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_all_str + ( "[[File:A.png|a|alt=]]" + , "\"\"" + ); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Href_anchor_leading_space() { // PURPOSE: space before anchor should be preserved, not " " -> "#" + fxt.Test_parse_page_all_str("[[A #b]]", "A #b"); + } + @Test public void Href_anchor_leading_space_ns() { // PURPOSE: same as above, but with ns; DATE:2013-08-29 + fxt.Test_parse_page_all_str("[[Help:A #b]]", "Help:A #b"); + } + @Test public void Href_anchor_leading_ns_lc() { // PURPOSE: same as above but with lc title + fxt.Test_parse_page_all_str("[[Help:a#b]]", "Help:A#b"); + } + @Test public void Href_anchor_leading_space_ns_lc() { // PURPOSE: same as above but with lc title + fxt.Test_parse_page_all_str("[[Help:a #b]]", "Help:A #b"); + } + @Test public void Lnki_caption_nested_file() { // PURPOSE: nested lnki in caption breaks alt with html chars; EX:de.w:Wien; DATE:2013-12-16 + fxt.Wtr_cfg().Lnki__title_(true); + fxt.Test_parse_page_wiki_str("[[File:A.png|none|[[File:B.png|20px|d]] c]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "\"d
      " + , "" + )); + fxt.Wtr_cfg().Lnki__title_(false); + } + @Test public void Link__file() { // PURPOSE.FIX: link=file:/// was creating "href='/wiki/file'" handle IPA links; EX:[[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/c/7/a/3/En-LudwigVanBeethoven.ogg|Listen]]; PAGE:en.w:Beethoven DATE:2015-12-28 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=file:///C:/A.ogg|b]]", String_.Concat_lines_nl_skip_last + ( "" + + "\"b\"" + + "" + )); + } + @Test public void Link__empty() { // empty link should not create anchor; EX:[[File:A.png|link=|abc]]; PAGE:en.w:List_of_counties_in_New_York; DATE:2016-01-10 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=|abc]]", String_.Concat_lines_nl_skip_last + ( "\"abc\"" + )); + } + @Test public void Link__lc() { // links to items in same Srch_rslt_cbk should automatically title-case words; DATE:2016-01-11 + fxt.Init_xwiki_add_wiki_and_user_("en", "en.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=en:Help:a?b=c#d|abc]]", String_.Concat_lines_nl_skip_last + ( "" // "Help:A" not "Help:a" + + "\"abc\"" + + "")); + fxt.Init_xwiki_clear(); + } + @Test public void Redirect() {// PURPOSE: redirect should use trg_lnki, not src_lnki; DATE:2016-08-10 + Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki()); + file_fxt.Exec_orig_add(Bool_.Y, "A.png", Xof_ext_.Id_png, 320, 300, "B.png"); + fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_(); + + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|320px|bcd|alt=efg]]" + , "\"efg\"" + ); + + fxt.Wiki().File__fsdb_mode().Tid__v2__bld__y_(); + } + @Test public void Imap() { + Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki()); + file_fxt.Exec_orig_add(Bool_.Y, "A.png", Xof_ext_.Id_png, 320, 300, ""); + fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_(); + fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump); + + fxt.Test_parse_page_wiki_str + ( String_.Concat_lines_nl_skip_last + ( "" + , "File:A.png|thumb|320px|a1" + , "circle 0 0 5 [[B|b1]]" + , "rect 0 0 4 8 [[C|c1]]" + , "desc none" + , "" + ) + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , " " + , " \"b1\"" + , " \"c1\"" + , " " + , " \"\"" + , "
      " + , "
      " + , "
      a1" + , "
      " + , "
      " + , "
      " + )); + + fxt.Wiki().File__fsdb_mode().Tid__v2__bld__y_(); + } + private void Tst_img_title(String raw, String expd_ttl) { + String actl = fxt.Exec_parse_page_wiki_as_str(raw); + String actl_ttl = null; + int title_bgn = String_.FindFwd(actl, " title=\""); + if (title_bgn != String_.Find_none) { + title_bgn += String_.Len(" title=\""); + int title_end = String_.FindFwd(actl, "\"", title_bgn); + if (title_end != String_.Find_none) actl_ttl = String_.Mid(actl, title_bgn, title_end); + } + Tfds.Eq(expd_ttl, actl_ttl, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__link__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__link__tst.java new file mode 100644 index 000000000..8dd97c983 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__image__link__tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xoh_file_wtr__image__link__tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Link__file() { // PURPOSE.FIX: link=file:/// was creating "href='/wiki/file'" handle IPA links; EX:[[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/c/7/a/3/En-LudwigVanBeethoven.ogg|Listen]]; PAGE:en.w:Beethoven DATE:2015-12-28 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=file:///C:/A.ogg|b]]", String_.Concat_lines_nl_skip_last + ( "" + + "\"b\"" + + "" + )); + } + @Test public void Link__empty() { // empty link should not create anchor; EX:[[File:A.png|link=|abc]]; PAGE:en.w:List_of_counties_in_New_York; DATE:2016-01-10 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=|abc]]", String_.Concat_lines_nl_skip_last + ( "\"abc\"" + )); + } + @Test public void Link__lc() { // links to items in same Srch_rslt_cbk should automatically title-case words; DATE:2016-01-11 + fxt.Init_xwiki_add_wiki_and_user_("en", "en.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|11px|link=en:Help:a?b=c#d|abc]]", String_.Concat_lines_nl_skip_last + ( "" // "Help:A" not "Help:a" + + "\"abc\"" + + "")); + fxt.Init_xwiki_clear(); + } + @Test public void Link__xwiki_empty_ns() { // handle NPE in odd case where link has xwiki,ns, but no ttl; EX:"|link=en.w:User_talk:" PAGE:en.w:Wikipedia:Teahouse/The_menu; DATE:2017-12-02 + fxt.Init_xwiki_add_wiki_and_user_("en", "en.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|link=en:User_talk:|abc]]", String_.Concat_lines_nl_skip_last + ( "" // NOTE: href is to "File:A.png", not "en:User_talk:" + + "\"abc\"" + + "" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__media__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__media__tst.java new file mode 100644 index 000000000..eb28734be --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__media__tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; +public class Xoh_file_wtr__media__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Page_only() { // if no caption, then use page name; DATE:2017-05-20 + fxt.Test_parse_page_wiki_str("[[Media:A.png]]", String_.Concat_lines_nl_skip_last + ( "Media:A.png" + , "" + )); + } + @Test public void Nested_caption() { // PAGE:en.w:Beethoven; + fxt.Test_parse_page_wiki_str("[[File:A.png|thumb|b [[Media:A.ogg|media_caption]] c]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b media_caption" + , " c" + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Caption() { + fxt.Test_parse_page_wiki_str("[[Media:A.png|b]]", String_.Concat_lines_nl_skip_last + ( "b" + , "" + )); + } + @Test public void Literal() { + fxt.Test_parse_page_wiki_str("[[:Media:A.ogg|b]]", String_.Concat_lines_nl_skip_last + ( "b" + , "" + )); + } + @Test public void Literal_w_missing() { + fxt.Wiki().Html_mgr().Img_suppress_missing_src_(true); // simulate missing file; DATE:2014-01-30 + fxt.Test_parse_page_wiki_str("[[Media:A.pdf|b]]", String_.Concat_lines_nl_skip_last + ( "b" + , "" + )); + Tfds.Eq(0, fxt.Page().File_queue().Count()); // make sure media does not add to queue + fxt.Wiki().Html_mgr().Img_suppress_missing_src_(false); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__video__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__video__tst.java new file mode 100644 index 000000000..3443d5ed5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_file_wtr__video__tst.java @@ -0,0 +1,130 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xoh_file_wtr__video__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Video__full__ogv__width_y() {// EX: [[File:A.ogv|320px|bcd|alt=efg]]; DATE:2016-08-05 + fxt.Test_parse_page_wiki_str + ( "[[File:A.ogv|320px|bcd|alt=efg]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + + "" + + "\"efg\"" + + "" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Video__full__ogv__width_n() {// EX: [[File:A.ogv]]; DATE:2016-08-05 + fxt.Test_parse_page_wiki_str + ( "[[File:A.ogv]]", String_.Concat_lines_nl_skip_last + ( "
      " + , " " + , "
      " + , "
      " + )); + } + @Test public void Video__full__ogv__time() { + Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki()); + file_fxt.Exec_orig_add(Bool_.Y, "A.ogv", Xof_ext_.Id_ogv, 220, 300, ""); + fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_(); + fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump); + + fxt.Test_parse_page_wiki_str + ( "[[File:A.ogv|thumbtime=4]]", String_.Concat_lines_nl_skip_last + ( "
      " + , " " + , "
      " + , "
      " + )); + } + @Test public void Video__full_ogg() {// PURPOSE: ogg w/ width should default to video; otherwise dynamic-update won't be able to convert audio-button to thumb; DATE:2016-08-05 + // NOTE: simulates app w/ fsdb + Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki()); + file_fxt.Exec_orig_add(Bool_.Y, "A.ogg", Xof_ext_.Id_ogv, 320, 300, ""); + + fxt.Test_parse_page_wiki_str + ( "[[File:A.ogg|320px|bcd|alt=efg]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      \"efg\"" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Video__thumb() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.ogv|thumb|320px|bcd|alt=efg]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 + , "
      " + , "
      " + + "" + + "\"efg\"" + + "" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      bcd" + , "
      " + , "
      " + , "
      " + , "
      efg" + , "
      " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Video__thumb_webm() { // PURPOSE: webm thumb wasn't being shown; DATE:2014-01-25 + fxt.Test_parse_page_wiki_str + ( "[[File:A.webm|thumb|320px|a|alt=b]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 + , "
      " + , "
      " + + "" + + "\"b\"" + + "" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      a" + , "
      " + , "
      " + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "
      " + , "" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_title_bldr_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_title_bldr_tst.java new file mode 100644 index 000000000..2e08caa52 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/lnkis/htmls/Xoh_lnki_title_bldr_tst.java @@ -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.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; +import org.junit.*; import gplx.xowa.parsers.*; +public class Xoh_lnki_title_bldr_tst { + private final Xoh_lnki_title_bldr_fxt fxt = new Xoh_lnki_title_bldr_fxt(); + @Test public void Basic() { + fxt.Test__parse("a b c", "a b c"); + fxt.Test__parse("a ''b'' c", "a b c"); + fxt.Test__parse("a b c", "a b c"); + fxt.Test__parse("a\nb", "a b"); + fxt.Test__parse("a\"b", "a"b"); + } + @Test public void Lnki__quotes() { // PURPOSE: handle titles with quotes; PAGE:s.w:Styx_(band) DATE:2015-11-29 + fxt.Test__parse("[[A\"B]]", "A"B"); + } +} +class Xoh_lnki_title_bldr_fxt { + private final Xop_fxt fxt = new Xop_fxt(); + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Test__parse(String raw, String expd) { + byte[] raw_bry = Bry_.new_u8(raw); + Xop_root_tkn root = fxt.Ctx().Tkn_mkr().Root(raw_bry); + fxt.Parser().Parse_page_all_clear(root, fxt.Ctx(), fxt.Ctx().Tkn_mkr(), raw_bry); + Xoh_lnki_title_bldr.Add(bfr, raw_bry, root); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java new file mode 100644 index 000000000..ef9ee8c86 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_html_tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_thm_html_tst { + private final Xoh_make_fxt fxt = new Xoh_make_fxt(); + @Test public void Image() { + fxt.Test__html("[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " " + , "
      " + , "
      test_caption" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Audio__link() { // PURPOSE: handle IPA links; EX:[[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/c/7/a/3/En-LudwigVanBeethoven.ogg|Listen]]; PAGE:en.w:Beethoven DATE:2015-12-28 + fxt.Test__html("[[File:A.oga|11px|link=file:///C:/A.ogg|b]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Video() { + fxt.Test__html("[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      \"\"/" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      test_caption" + , "
      " + , "
      " + , "
      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__avo__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__avo__tst.java new file mode 100644 index 000000000..4893f98e5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__avo__tst.java @@ -0,0 +1,64 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; +import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_thm_hzip__avo__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void setup() {fxt.Clear();} + @Test public void Video() { + fxt.Test__bicode("~&%test_caption~|E9eA.ogv~%A.ogv~~", Gfh_utl.Replace_apos(String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "test_caption
      " + , "
      " + , "
      " + ))); + } + @Test public void Audio() { + fxt.Test__bicode(Gfh_utl.Replace_apos(String_.Concat_lines_nl + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      $|#na)A.ogaAbout this file
      " + , "
      " + , "
      " + , "
      ~$|%%,)~A.oga~Enlarge~
      b" + , "
      " + , "
      " + , "
      " + )), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      b" + , "
      " + , "
      " + , "
      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__basic__tst.java new file mode 100644 index 000000000..858406214 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__basic__tst.java @@ -0,0 +1,122 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; +import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_thm_hzip__basic__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void setup() {fxt.Clear();} + @Test public void Image_wo_alt_text() {// LEGACY: pre xowa_alt_text + fxt.Test__bicode("~&3abc~abc~!uA.png~)#Sabc~", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      abc " + , "
      " + , "
      " + , "abc
      " + , "
      " + , "
      abc
      " + , "
      " + , "
      " + )); + } + @Test public void Image_w_alt_text() {// NOTE: xowa_alt_text; PAGE:es.w:Biome DATE:2017-09-04 + fxt.Test__bicode("~&{\"^abc~abc~!uA.png~)#Sabc~", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      abc " + , "
      " + , "
      " + , "abc
      " + , "
      " + , "
      " + , "
      abc
      " + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Capt_is_missing() { // [[File:A.png|thumb]] + fxt.Test__bicode("~&#~!%A.png~)#S~", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Fix__omitted_table_tail() { // PURPOSE.hdiff: handle omitted ; PAGE:en.w:Alphabet; DATE:2016-01-06 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~&]&D~" + , "" + , "" + , "" + , "" + , "
      " + , "abc" + , "
      " + , "~!5A.png~-&D" + ), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "" + , "" + , "" + , "" + , "
      " + , "abc" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Div_width_uses_img_width() { + Xof_fsdb_itm itm = new Xof_fsdb_itm(); + itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_a7("en.w"), Bry_.new_a7("A.png"), Xop_lnki_type.Id_null, -1, 220, -1, -1, -1, 0); + itm.Init_at_cache(true, 400, 440, Io_url_.mem_fil_("mem/A.png")); + Xou_cache_finder_mem finder = fxt.Init_file_mgr__mem(); + finder.Add(itm); + + fxt.Test__decode("~&3abc~abc~!uA.png~)#Sabc~", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      abc " + , "
      " + , "
      " + , "abc
      " + , "
      " + , "
      abc
      " + , "
      " + , "
      " + )); + + fxt.Init_file_mgr__noop(); + } +// @Test public void Dump() { +// Xowe_wiki en_d = fxt.Init_wiki_alias("wikt", "en.wiktionary.org"); +// gplx.xowa.wikis.nss.Xow_ns_mgr ns_mgr = en_d.Ns_mgr(); +// ns_mgr.Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all); +// +// fxt.Wiki().Ns_mgr().Aliases_add(gplx.xowa.wikis.nss.Xow_ns_.Tid__portal, "WP"); +// fxt.Wiki().Ns_mgr().Init(); +// +// fxt.Init_mode_is_b256_(Bool_.N); +// fxt.Exec_write_to_fsys(Io_url_.new_dir_("C:\\xowa\\debug\\html\\"), "hzip.html"); +// fxt.Init_mode_is_b256_(Bool_.N); +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__pseudo__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__pseudo__tst.java new file mode 100644 index 000000000..d576a6534 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__pseudo__tst.java @@ -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.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; +import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_thm_hzip__pseudo__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void setup() {fxt.Clear();} + @Test public void Fake__div_1__next_nde() { // PURPOSE: handle fake-thumbs with pseudo thumbimage class; PAGE:s.w:Mars + fxt.Test__bicode(String_.Replace(String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      ~%-eA.jpg~Image~)#?A.jpg~abc~
      " + , "
      abc
      " + , "
      " + , "
      " + , "
      " + ), "'", "\""), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      abc
      " + , "
      abc
      " + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Fake__div_1__style() { // PURPOSE.hdiff: handle fake-thumbs with bad style; PAGE:en.w:Carlisle_United_F.C. + fxt.Test__bicode(String_.Replace(String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "~%-eA.jpg~Image~)#?A.jpg~abc~
      " + , "
      " + , "
      ~${#7)A.jpg~
      " + , "abc" + , "
      " + , "
      " + , "
      " + ), "'", "\""), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "abc
      " + , "
      " + , "" + , "abc" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Fake__div_1__width_w_space() { // PURPOSE.hdiff: handle fake-thumbs with style of "width "; PAGE:en.w:Abraham_Lincoln + fxt.Test__bicode(String_.Replace(String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "~%-eA.jpg~Image~)#?A.jpg~abc~
      " + , "
      " + , "
      ~${#7)A.jpg~
      " + , "abc" + , "
      " + , "
      " + , "
      " + ), "'", "\""), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "abc
      " + , "
      " + , "" + , "abc" + , "
      " + , "
      " + , "
      " + )); + } + @Test public void Fake__div_1__thumbimage() { // PURPOSE.hdiff: handle fake-thumbs with image-map style; PAGE:en.w:UK + String html = String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "{0}" + , "
      " + , "
      abc
      " + , "
      " + , "
      " + , "
      " + , "
      " + , "
      def
      " + , "
      " + , "
      " + ); + fxt.Test__bicode(String_.Replace(String_.Format(html, "
      ~%!!A.svg~)#q~
      "), "'", "\""), String_.Format(html, "
      ")); + } + @Test public void Fake__div_1__extra_attribs() {// PURPOSE.hdiff: handle fake thumbs with extra attribs; PAGE:en.w:Wikipedia:New_CSS_framework; DATE:2016-01-11 + String html = String_.Concat_lines_nl_skip_last + ( "
      " + , "
      {0}" // "color:blue;" is invalid attribs + , "
      abc" + , "abc
      " + , "
      " + , "
      " + ); + fxt.Test__bicode(String_.Replace(String_.Format(html, "~%!!A.png~)#g~"), "'", "\""), String_.Format(html, "")); + } + @Test public void Fake__div_2__not_media() { // PURPOSE.hdiff: handle fake-thumbs created through en.w:Template:Image_label_begin; PAGE:en.w:Blackburnshire; DATE:2016-01-04 + String html = String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "{0}" + , "
      abc" + , "
      " + , "
      " + , "
      " + , "{1}" + , "bcd
      " + , "
      " + , "
      " + ); + fxt.Test__bicode(String_.Replace(String_.Format(html, "
      ~%!!A.png~)#g~
      ", "
      ~$a)A.png~
      "), "'", "\""), String_.Format(html, "
      ", "")); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__tidy__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__tidy__tst.java new file mode 100644 index 000000000..a90dc5097 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/thms/Xoh_thm_hzip__tidy__tst.java @@ -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.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; +import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.parsers.lnkis.*; +public class Xoh_thm_hzip__tidy__tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Before public void setup() {fxt.Clear();} + @Test public void Tidy__moved_capt() { + fxt.Test__bicode("~&S~abc\n~!uA.png~)#Sabc~", String_.Concat_lines_nl_skip_last + ( "
      " + , "
      abc " + , "
      " + , "
      " + , "
      abc" + , "
      " + , "
      " + )); + } + @Test public void Tidy__extra_closing_div() {// handle extra closing div in caption; PAGE:en.w:Damask; DATE:2016-01-05 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~&U
      A
      " + , "B~" + , "C~!1A.png~-\"b"), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "
      " + , "
      " + , "
      A
      " + , "B
      " + , "C
      " + , "
      " + )); + } + @Test public void Tidy__ul() { // tidy will move
      on to different lines depending on
        ; PAGE:en.w:Chimney_sweep; DATE:2016-01-05 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~&=$b* ABC~" + , "
          " + , "
        • ABC
        • " + , "
        " + , "~!uA.png~-$bABC~"), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        ABC " + , "
        " + , "
        " + , "* ABC
        " + , "
        " + , "
        " + , "
          " + , "
        • ABC
        • " + , "
        " + , "
        " + , "
        " + , "
        " + )); + } + @Test public void Tidy__video() { // tidy may relocate xowa-alt-div to last div; PAGE:en.w:Non-helical_models_of_DNA_structure; DATE:2016-01-11 + fxt.Test__bicode(String_.Concat_lines_nl_skip_last + ( "~&eabc~" + , "
        " + , "
        bcd
        " + , "~|E9eA.ogv~%A.ogv~~"), Gfh_utl.Replace_apos(String_.Concat_lines_nl_skip_last + ( "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "abc
        " + , "
        " + , "
        " + , "
        bcd
        " + , "
        " + ))); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/tocs/Xoh_toc_hzip_tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/tocs/Xoh_toc_hzip_tst.java new file mode 100644 index 000000000..7ab8f05f4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/tocs/Xoh_toc_hzip_tst.java @@ -0,0 +1,23 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.htmls.core.makes.tests.*; +public class Xoh_toc_hzip_tst { + private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_(); + @Test public void Basic() { // EX:
        + fxt.Test__bicode("~)!", "
        "); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/Xoh_xnde_hzip_nde__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/Xoh_xnde_hzip_nde__tst.java new file mode 100644 index 000000000..b171164f1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/Xoh_xnde_hzip_nde__tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.wkrs.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; +import org.junit.*; import gplx.langs.htmls.*; +import gplx.xowa.htmls.core.wkrs.xndes.atrs.*; import gplx.xowa.htmls.core.wkrs.xndes.tags.*; +public class Xoh_xnde_hzip_nde__tst { +// private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_is_b256_(Bool_.N); + @Test public void Basic() { +// fxt.Test__bicode(" ?#%", ""); + } + @Test public void Style() { +// fxt.Test__bicode(" ?#%", ""); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/dicts/Xoh_xnde_dict__tst.java b/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/dicts/Xoh_xnde_dict__tst.java new file mode 100644 index 000000000..81fc27855 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/core/wkrs/xndes/dicts/Xoh_xnde_dict__tst.java @@ -0,0 +1,76 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.core.wkrs.xndes.dicts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.xndes.*; +import org.junit.*; import gplx.core.brys.*; +public class Xoh_xnde_dict__tst { + private final Xoh_xnde_dict__fxt fxt = new Xoh_xnde_dict__fxt(); + @Test public void Basic() { + fxt.Exec__add("a"); + fxt.Test__get_by_key_or_new("a", 0); + fxt.Test__get_by_key_or_new("b", 1); + byte[] dump = fxt.Dump_bldr().Add(0, "a").Add(1, "b").To_bry(); + fxt.Test__save(dump); + fxt.Exec__clear(); +// fxt.Test__load(dump, fxt.Make__itm(0, "a"), fxt.Make__itm(1, "b")); + } +} +class Xoh_xnde_dict__fxt { + private final Xoh_xnde_dict_grp grp = new Xoh_xnde_dict_grp(1); + private final Xoh_hzip_bfr bfr = new Xoh_hzip_bfr(32, Bool_.Y, Byte_ascii.Escape); + private final Bry_rdr rdr = new Bry_rdr(); + public Xoh_xnde_dict__fxt() { + this.dump_bldr = new Xoh_xnde_dict__dump_bldr(bfr); + } + public Xoh_xnde_dict__dump_bldr Dump_bldr() {return dump_bldr;} private final Xoh_xnde_dict__dump_bldr dump_bldr; + public void Exec__add(String val) {grp.Add(Bry_.new_u8(val));} + public void Exec__clear() {grp.Clear();} + public void Test__get_by_key_or_new(String val, int expd_id) { + byte[] val_bry = Bry_.new_u8(val); + Xoh_xnde_dict_itm actl_itm = grp.Get_by_key_or_new(val_bry, 0, val_bry.length); + Tfds.Eq_int(expd_id, actl_itm.Id()); + Tfds.Eq_bry(val_bry, actl_itm.Val()); + } + public void Test__save(byte[] expd) { + grp.Save(bfr); + Tfds.Eq_bry(expd, bfr.To_bry_and_clear()); + } + public void Test__load(byte[] dump, Xoh_xnde_dict_itm... itms) { + rdr.Init_by_page(Bry_.Empty, dump, dump.length); + grp.Load(rdr); + int itms_len = itms.length; + for (int i = 0; i < itms_len; ++i) { + Xoh_xnde_dict_itm expd_itm = itms[i]; + Xoh_xnde_dict_itm actl_itm = grp.Get_by_id_or_null(expd_itm.Id()); + Tfds.Eq_int(expd_itm.Id(), actl_itm.Id()); + Tfds.Eq_bry(expd_itm.Val(), actl_itm.Val()); + } + } + public Xoh_xnde_dict_itm Make__itm(int id, String val) {return new Xoh_xnde_dict_itm(id, Bry_.new_u8(val));} +} +class Xoh_xnde_dict__dump_bldr { + private final Xoh_hzip_bfr bfr; + public Xoh_xnde_dict__dump_bldr(Xoh_hzip_bfr bfr) {this.bfr = bfr;} + public Xoh_xnde_dict__dump_bldr Add(int id, String val) { + bfr.Add_hzip_int(1, (byte)id); + bfr.Add_str_u8(val); + bfr.Add_byte_nl(); + return this; + } + public byte[] To_bry() { + bfr.Add(Xoh_xnde_dict_grp.Bry__stop); + return bfr.To_bry_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java b/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java new file mode 100644 index 000000000..c1b69e118 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java @@ -0,0 +1,43 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +public class Xoh_dom_tst { + @Test public void Find_atr() { + String src = "a b c"; + tst_Find(src, "nde0", "atr0", "val0", "atr1", "val1"); // match nde0 + tst_Find(src, "nde1", "atr0", "val3", "atr1", "val4"); // match nde1 + tst_Find(src, "nde0", "atr0", "val5", "atr1", null); // wrong val + tst_Find(src, "nde0", "atr2", "val0", "atr1", null); // wrong key + tst_Find(src, "nde2", "atr0", "val0", "atr1", null); // wrong nde + } + @Test public void Title_by_href() {// PURPOSE: handle content-editable=n and finding file directly for download + Title_by_href_tst + ( "/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg" + , "" + , "find_me" + ); + } + private void tst_Find(String src, String where_nde, String where_key, String where_val, String select_key, String expd) { + Xoh_find rv = new Xoh_find(); + byte[] actl = Xoh_dom_.Query_val_by_where(rv, Bry_.new_u8(src), Bry_.new_u8(where_nde), Bry_.new_u8(where_key), Bry_.new_u8(where_val), Bry_.new_u8(select_key), 0); + Tfds.Eq(expd, String_.new_u8(actl)); + } + private void Title_by_href_tst(String href, String html_src, String expd) { + String actl = Xoh_dom_.Title_by_href(Bry_.new_u8(href), Bry_.new_u8(html_src)); + Tfds.Eq(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java new file mode 100644 index 000000000..18e1ccc5a --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java @@ -0,0 +1,146 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +import gplx.xowa.guis.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; +public class Xoh_head_mgr_tst { + @Before public void init() {fxt.Clear();} private Xoh_head_mgr_fxt fxt = new Xoh_head_mgr_fxt(); + @Test public void Css() { + fxt.Mgr().Itm__css().Enabled_y_(); + fxt.Test_write(String_.Concat_lines_nl_skip_last + ( "" + , " " + )); + } + @Test public void Toc() { + fxt.Init_msg(Xoh_head_itm__toc.Key_showtoc, "Sh\"ow"); + fxt.Init_msg(Xoh_head_itm__toc.Key_hidetoc, "Hi'de"); + fxt.Mgr().Itm__toc().Enabled_y_(); + fxt.Test_write(String_.Concat_lines_nl_skip_last + ( "" + , " " + )); + } + @Test public void Globals() { + fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "Jan'uary" ); // add apos to simulate apostrophes in Hebrew months; DATE:2014-07-28 + fxt.Mgr().Itm__globals().Enabled_y_(); + fxt.Test_write(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + )); + fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "January" ); // set it back + } + @Test public void Globals_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13 + Xol_lang_itm la_lang = fxt.Wiki().Lang(); + gplx.xowa.langs.numbers.Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr(); + separators_mgr.Clear(); + separators_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_a7(" ")); + fxt.Mgr().Itm__globals().Enabled_y_(); + fxt.Test_write(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + )); + } +} +class Xoh_head_mgr_fxt { + private final Xop_fxt fxt = new Xop_fxt(); + private Xoh_head_mgr mgr; + private Bry_bfr bfr = Bry_bfr_.Reset(255); + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public Xoh_head_mgr Mgr() {return mgr;} + public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));} + public void Clear() { + fxt.Reset(); + mgr = fxt.Page().Html_data().Head_mgr(); + wiki = fxt.Wiki(); + } + public void Init_msg(byte[] key, String val) { + wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false); + } + public void Init_msg(int id, String val) { + Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(id); + msg_itm.Atrs_set(Bry_.new_a7(val), false, false); + } + public void Test_write(String expd) { + fxt.Page().Page_guid_empty_(); + mgr.Write(bfr, fxt.App(), wiki, fxt.Page()); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java new file mode 100644 index 000000000..24e2ce185 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +import gplx.xowa.guis.*; +public class Xoh_head_wtr_tst { + @Before public void init() {fxt.Clear();} private Xoh_head_wtr_fxt fxt = new Xoh_head_wtr_fxt(); + @Test public void Globals_none() { + Xoh_head_wtr wtr = fxt.Wtr(); + wtr.Write_js_head_global_bgn(); + wtr.Write_js_head_global_end(); + fxt.Test(""); + } + @Test public void Globals_some() { + Xoh_head_wtr wtr = fxt.Wtr(); + wtr.Write_js_head_global_bgn(); + fxt.Exec_Write_js_global_ini_atr_val("key_1", "val_1"); + fxt.Exec_Write_js_global_ini_atr_val("key_2", "val_2"); + fxt.Exec_Write_js_global_ini_atr_val("key_3", "apos_'_1"); + wtr.Write_js_head_global_end(); + fxt.Test(String_.Concat_lines_nl_skip_last + ( "" + , "var xowa_global_values = {" + , " 'key_1' : 'val_1'," + , " 'key_2' : 'val_2'," + , " 'key_3' : 'apos_\\'_1'," + , "}" + )); + } +} +class Xoh_head_wtr_fxt { + private Bry_bfr bfr = Bry_bfr_.Reset(255); + public Xoh_head_wtr Wtr() {return wtr;} private Xoh_head_wtr wtr = new Xoh_head_wtr(); + public void Clear() { + wtr.Init(bfr); + } + public void Exec_Write_js_global_ini_atr_val(String key, String val) {wtr.Write_js_global_ini_atr_val(Bry_.new_u8(key), Bry_.new_u8(val));} + public void Test(String expd) { + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +// public void Init_msg(byte[] key, String val) { +// wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false); +// } +// public void Test_write(String expd) { +// mgr.Write(bfr, fxt.App(), wiki, fxt.Page()); +// Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); +// } +} diff --git a/400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java new file mode 100644 index 000000000..2a1395cee --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*; +public class Xow_fragment_mgr_tst { + Xow_fragment_mgr_fxt fxt = new Xow_fragment_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Html_js_edit_toolbar_fmt() { + fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_edit_toolbar, String_.Concat_lines_nl + ( " var xowa_edit_i18n = {" + , " 'bold_tip' : 'Bold text'," + , " 'bold_sample' : 'Bold text'," + , " 'italic_tip' : 'Italic text'," + , " 'italic_sample' : 'Italic text'," + , " 'link_tip' : 'Internal link'," + , " 'link_sample' : 'Link title'," + , " 'headline_tip' : 'Level 2 headline'," + , " 'headline_sample' : 'Headline text'," + , " 'ulist_tip' : 'Bulleted list'," + , " 'ulist_sample' : 'Bulleted list item'," + , " 'olist_tip' : 'Numbered list'," + , " 'olist_sample' : 'Numbered list item'" + , " };" + )); + } +} +class Xow_fragment_mgr_fxt { + public void Clear() { + if (wiki == null) { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + } private Xowe_wiki wiki; + public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));} + public void Test_fragment(String key, String expd) {Test_fragment(wiki.Lang(), key, expd);} + public void Test_fragment(Xol_lang_itm lang, String key, String expd) { + wiki.Fragment_mgr().Evt_lang_changed(lang); + byte[] actl = (byte[])Gfo_invk_.Invk_by_key(wiki.Fragment_mgr(), key); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java new file mode 100644 index 000000000..204aa876c --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +import gplx.core.primitives.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.guis.views.*; +public class Xoh_href_gui_utl_tst { + @Before public void init() {fxt.Clear();} private Xoh_href_gui_utl_fxt fxt = new Xoh_href_gui_utl_fxt(); + @Test public void Extract_href__text() { + fxt.Test_extract_href("0|" , ""); + fxt.Test_extract_href("1|selected_text" , "selected_text"); + fxt.Test_extract_href("2|http://a.org" , "http://a.org"); + } + @Test public void Extract_href__file() { + fxt.Test_extract_href("2|file:///site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1"); + fxt.Test_extract_href("2|file:///wiki/Page_2" , "en.wikipedia.org/wiki/Page_2"); + fxt.Test_extract_href("2|file://#anchor" , "en.wikipedia.org/wiki/Page_0#anchor"); + } + @Test public void Extract_href__internal() { + fxt.Test_extract_href("2|/site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1"); + fxt.Test_extract_href("2|/wiki/Page_2" , "en.wikipedia.org/wiki/Page_2"); + fxt.Test_extract_href("2|#anchor" , "en.wikipedia.org/wiki/Page_0#anchor"); + } + @Test public void Html_window_vpos_parse() { + fxt.Test_Html_window_vpos_parse("0|0,1,2", "0", "'0','1','2'"); + fxt.Test_Html_window_vpos_parse("org.eclipse.swt.SWTException: Permission denied for to get property Selection.rangeCount", null, null); // check that invalid path doesn't fail; DATE:2014-04-05 + } + @Test public void Standardize_xowa_link() { + fxt.Test_standardize_xowa_link("file:///site/en.wikipedia.org/wiki/A" , "/site/en.wikipedia.org/wiki/A"); + fxt.Test_standardize_xowa_link("file:///wiki/A" , "/wiki/A"); + fxt.Test_standardize_xowa_link("file://#A" , "#A"); + } +} +class Xoh_href_gui_utl_fxt { + public void Clear() { + cur_wiki = "en.wikipedia.org"; + cur_page = "Page_0"; + } + public String Cur_wiki() {return cur_wiki;} public Xoh_href_gui_utl_fxt Cur_wiki_(String v) {cur_wiki = v; return this;} private String cur_wiki; + public String Cur_page() {return cur_page;} public Xoh_href_gui_utl_fxt Cur_page_(String v) {cur_page = v; return this;} private String cur_page; + public void Test_extract_href(String text_str, String expd) { + Tfds.Eq(expd, Xoh_href_gui_utl.Html_extract_text(cur_wiki, cur_page, text_str)); + } + private String_obj_ref scroll_top = String_obj_ref.null_(), node_path = String_obj_ref.null_(); + public void Test_Html_window_vpos_parse(String raw, String expd_scroll_top, String expd_node_path) { + scroll_top.Val_null_(); node_path.Val_null_(); + Xog_html_itm.Html_window_vpos_parse(raw, scroll_top, node_path); + Tfds.Eq(expd_scroll_top, scroll_top.Val(), expd_scroll_top); + Tfds.Eq(expd_node_path, node_path.Val(), expd_node_path); + } + public void Test_standardize_xowa_link(String raw, String expd) { + Tfds.Eq_str(expd, Xoh_href_gui_utl.Standardize_xowa_link(raw), "standardize"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__basic__tst.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__basic__tst.java new file mode 100644 index 000000000..0f54d8014 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__basic__tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*; +public class Xoh_href_parser__basic__tst { + private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt(); + @Test public void Site__basic() { + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__to_str("en.wikipedia.org/wiki/A").Test__page("A"); + } + @Test public void Site__ns_case() { + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/file:A").Test__page("File:A"); + } + @Test public void Site__main_page() { + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/").Test__page("Main_Page").Test__page_is_main_y(); + } + @Test public void Site__anch() { + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A#b_c").Test__page("A").Test__anch("b_c"); + } + @Test public void Site__qarg() { + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A?action=edit").Test__page("A").Test__qargs("?action=edit"); + } + @Test public void Site__invalid_ttl_shouldnt_fail() { // PURPOSE: invalid title shouldn't fail; EX: A{{B}} is invalid (b/c of braces); + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/A{{B}}").Test__page(""); + } + @Test public void Site__xwiki_cases_correctly() { // PURPOSE: xwiki links should use case_match of xwiki (en.wiktionary.org) not cur_wiki (en.wikipedia.org); EX:w:Alphabet + Xowe_wiki en_wiktionary_org = fxt.Prep_create_wiki("en.wiktionary.org"); + en_wiktionary_org.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all); + fxt.Prep_add_xwiki_to_user("en.wiktionary.org", "en.wiktionary.org"); + fxt.Exec__parse_as_url("/site/en.wiktionary.org/wiki/alphabet"); + fxt.Test__to_str("en.wiktionary.org/wiki/alphabet").Test__page("alphabet"); + } + @Test public void Site__xwiki_compound() { // PURPOSE: [[[w:wikt:]] not handled; DATE:2013-07-25 + fxt.Prep_add_xwiki_to_wiki("wikt", "en.wiktionary.org"); + fxt.Exec__parse_as_url("/site/en.wikipedia.org/wiki/wikt:") + .Test__tid(Xoa_url_.Tid_page) + .Test__page("Main_Page") + .Test__to_str("en.wiktionary.org/wiki/Main_Page") + ; + } +// @Test public void Vnt() { +// Xowe_wiki wiki = fxt.Wiki(); +// fxt.Prep_add_xwiki_to_user("zh.wikipedia.org"); +// wiki.Lang().Vnt_mgr().Enabled_(true); +// wiki.Lang().Vnt_mgr().Vnt_grp().Add(new gplx.xowa.langs.vnts.Vnt_mnu_itm(Bry_.new_a7("zh-hans"), Bry_.new_a7("zh-hant"))); +// fxt.Exec__parse_as_url("/site/zh.wikipedia.org/zh-hant/A").Test__page("A").Chk_vnt("zh-hant"); +// } + @Test public void Http__basic() { + fxt.Exec__parse_as_url("http://a.org/b").Test__tid(Xoa_url_.Tid_inet); + } + @Test public void Prot__ftp() { // PURPOSE: check that urls with form of "ftp://" return back Tid_ftp; DATE:2014-04-25 + fxt.Exec__parse_as_url("ftp://a.org").Test__tid(Xoa_url_.Tid_inet); + } + @Test public void File__basic() { + fxt.Exec__parse_as_url("file:///C/xowa/file/a.png").Test__tid(Xoa_url_.Tid_file); + } + @Test public void Anchor__basic() { + fxt.Exec__parse_as_url("#a").Test__tid(Xoa_url_.Tid_anch).Test__to_str("en.wikipedia.org/wiki/Page 1#a").Test__anch("a"); + } + @Test public void Xcmd__basic() { + fxt.Exec__parse_as_url("/xcmd/page_edit").Test__tid(Xoa_url_.Tid_xcmd).Test__page("page_edit"); + } + @Test public void Xowa__basic() { + fxt.Exec__parse_as_url("xowa-cmd:a%22b*c").Test__tid(Xoa_url_.Tid_xcmd).Test__page("a\"b*c"); + } + // COMMENTED: this seems wrong; [//wikisource.org] should go to https://wikisource.org not https://en.wikisource.org; both sites are different; DATE:2015-08-02 +// @Test public void Site__user_wiki() {// PURPOSE: outlier for wikisource.org which is alias to en.wikisource.org; alias added in user_wiki; EX: [//wikisource.org a]; in browser, automatically goes to http://wikisource.org; in xowa, should go to /site/en.wikisource.org +// fxt.Prep_xwiki(fxt.App().User().Wikii(), "en_wiki_alias", "en.wikipedia.org", null); +// fxt.Exec__parse_as_url("/site/en_wiki_alias/wiki/") +// .Test__tid(Xoa_url_.Tid_page) +// .Test__page("Main_Page") +// .Test__to_str("en.wikipedia.org/wiki/Main_Page") +// ; +// } +} +class Xoh_href_parser_fxt extends Xow_url_parser_fxt { private final Xoh_href_parser href_parser = new Xoh_href_parser(); + public Xoh_href_parser_fxt Exec__parse_as_url(String raw) { + href_parser.Parse_as_url(actl_url, Bry_.new_u8(raw), cur_wiki, Bry__page_1); + return this; + } + private static final byte[] Bry__page_1 = Bry_.new_a7("Page 1"); +} diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__qargs__tst.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__qargs__tst.java new file mode 100644 index 000000000..59f94e189 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__qargs__tst.java @@ -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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*; +public class Xoh_href_parser__qargs__tst { + private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt(); + @Test public void Basic() { + fxt.Exec__parse_as_url("/wiki/A?k1=v1&k2=v2"); + fxt.Test__page("A"); + fxt.Test__to_str("en.wikipedia.org/wiki/A?k1=v1&k2=v2"); + } + @Test public void Anch() { // PURPOSE.fix: anchor was being placed before qargs; DATE:2016-10-08 + fxt.Exec__parse_as_url("/wiki/Category:A?pagefrom=A#mw-pages"); + fxt.Test__page("Category:A"); + fxt.Test__to_str("en.wikipedia.org/wiki/Category:A?pagefrom=A#mw-pages"); // was Category:A#mw-page?pagefrom=A + } + // FUTURE: qargs should be unencoded by default; decoded on request + @Test public void Encoded() { // PURPOSE.fix: do not use decoded String; DATE:2016-10-08 + fxt.Exec__parse_as_url("/wiki/Category:A?pagefrom=A%26B#mw-pages"); + fxt.Test__page("Category:A"); + fxt.Test__qargs("?pagefrom=A&B"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__wiki__tst.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__wiki__tst.java new file mode 100644 index 000000000..6d5df0941 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser__wiki__tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.apps.urls.*; import gplx.xowa.wikis.nss.*; +public class Xoh_href_parser__wiki__tst { + private final Xoh_href_parser_fxt fxt = new Xoh_href_parser_fxt(); + @Test public void Basic() { + fxt.Exec__parse_as_url("/wiki/A").Test__tid(Xoa_url_.Tid_page).Test__to_str("en.wikipedia.org/wiki/A").Test__wiki("en.wikipedia.org").Test__page("A"); + } + @Test public void Page__w_question() { + fxt.Exec__parse_as_url("/wiki/%3F").Test__page("?"); + } + @Test public void Qarg() { + fxt.Exec__parse_as_url("/wiki/A?action=edit").Test__page("A").Test__qargs("?action=edit").Test__to_str("en.wikipedia.org/wiki/A?action=edit"); + } + @Test public void Qarg__w_question() { + fxt.Exec__parse_as_url("/wiki/A%3F?action=edit").Test__page("A?").Test__qargs("?action=edit"); + } + @Test public void Anchor() { + fxt.Exec__parse_as_url("/wiki/A#b").Test__to_str("en.wikipedia.org/wiki/A#b").Test__anch("b"); + } + @Test public void Xwiki__only() { + fxt.Prep_add_xwiki_to_wiki("c", "commons.wikimedia.org"); + fxt.Exec__parse_as_url("/wiki/c:").Test__page_is_main_y().Test__page("Main_Page").Test__to_str("commons.wikimedia.org/wiki/Main_Page"); + } + @Test public void Encoded() { + fxt.Exec__parse_as_url("/wiki/A%22b%22c").Test__page("A\"b\"c"); + } + @Test public void Triple_slash() { // PURPOSE: handle triple slashes; PAGE:esolangs.org/wiki/Language_list; DATE:2015-11-14 + fxt.Exec__parse_as_url("/wiki////").Test__to_str("en.wikipedia.org/wiki////").Test__wiki("en.wikipedia.org").Test__page("///"); + } + @Test public void Http() { // PURPOSE: variant of triple slashes; DATE:2015-11-14 + fxt.Exec__parse_as_url("/wiki/http://a").Test__to_str("en.wikipedia.org/wiki/Http://a").Test__wiki("en.wikipedia.org").Test__page("Http://a"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr_tst.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr_tst.java new file mode 100644 index 000000000..3fc66b5a6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr_tst.java @@ -0,0 +1,57 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +import gplx.core.net.*; import gplx.xowa.wikis.nss.*; +public class Xoh_href_wtr_tst { + private final Xoh_href_wtr_fxt fxt = new Xoh_href_wtr_fxt(); + @Test public void Xwiki_enc() {fxt.Test_build("wikt:abc?d" , "/site/en.wiktionary.org/wiki/abc%3Fd");} + @Test public void Page_quote() {fxt.Test_build("a\"b\"c" , "/wiki/A%22b%22c");} + @Test public void Page() {fxt.Test_build("abc" , "/wiki/Abc");} + @Test public void Page_ns() {fxt.Test_build("Image:A.png" , "/wiki/Image:A.png");} + @Test public void Anchor() {fxt.Test_build("#abc" , "#abc");} + @Test public void Page_anchor() {fxt.Test_build("Abc#def" , "/wiki/Abc#def");} + @Test public void Xwiki() {fxt.Test_build("wikt:abc" , "/site/en.wiktionary.org/wiki/abc");} // NOTE: "abc" not capitalized, b/c other wiki's case sensitivity is not known; this emulates WP's behavior + @Test public void Xwiki_2() {fxt.Test_build("wikt:Special:Search/a" , "/site/en.wiktionary.org/wiki/Special:Search/a");} + @Test public void Category() {fxt.Test_build("Category:abc" , "/wiki/Category:Abc");} + @Test public void Xwiki_wikimedia_mail() { // PURPOSE: DATE:2015-04-22 + fxt.Prep_xwiki_by_many("0|mail|https://lists.wikimedia.org/mailman/listinfo/~{0}|Wikitech Mailing List"); + fxt.Test_build("mail:A" , "https://lists.wikimedia.org/mailman/listinfo/A"); + } +} +class Xoh_href_wtr_fxt { + private final Xowe_wiki wiki; + private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); + private final Xoh_href_wtr href_wtr = new Xoh_href_wtr(); + public Xoh_href_wtr_fxt() { + this.app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + wiki.Xwiki_mgr().Add_by_csv(Bry_.new_a7("1|wikt|en.wiktionary.org")); + app.Usere().Wiki().Xwiki_mgr().Add_by_csv(Bry_.new_a7("1|en.wiktionary.org|en.wiktionary.org")); + } + public Xoae_app App() {return app;} private final Xoae_app app; + public Xoh_href_wtr_fxt Prep_wiki_cs(String domain) { + Xow_wiki wiki = app.Wiki_mgr().Get_by_or_make_init_n(Bry_.new_u8(domain)); + wiki.Ns_mgr().Ns_main().Case_match_(Xow_ns_case_.Tid__all); + return this; + } + public Xoh_href_wtr_fxt Prep_xwiki_by_many(String raw) {wiki.Xwiki_mgr().Add_by_csv(Bry_.new_u8(raw)); return this;} // need to add to wiki's xwiki_mgr for ttl_parse + public void Test_build(String raw, String expd) { + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(raw)); + href_wtr.Build_to_bfr(tmp_bfr, app, wiki.Domain_bry(), ttl); + Tfds.Eq(expd, tmp_bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_tst.java b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_tst.java new file mode 100644 index 000000000..762e78e64 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.xtns.wbases.*; +import gplx.xowa.guis.views.*; +public class Xoh_js_cbk_tst { + @Before public void init() {fxt.Clear();} private Xoh_js_cbk_fxt fxt = new Xoh_js_cbk_fxt(); + @Test public void Get_title() { + fxt.Fxt().Init_page_create("exists"); + fxt.Test_get_title("exists", "1" , "0" , Int_.To_str(Int_.Min_value), "Exists", "false", "0001-01-01 00:00:00", "0"); + fxt.Test_get_title("absent", "0", "-1", Int_.To_str(Int_.Min_value), null , "false", "0001-01-01 00:00:00", "0"); + } +} +class Xoh_js_cbk_fxt { + public void Clear() { + fxt = new Xop_fxt(); + Xoa_app_fxt.Init_gui(fxt.App(), fxt.Wiki()); + } private Xop_fxt fxt; + public Xop_fxt Fxt() {return fxt;} + public void Test_get_title(String ttl, Object... expd) { + Xoae_app app = fxt.App(); + Xowe_wiki wiki = fxt.Wiki(); + Xoae_page page = Xoae_page.New_test(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7("mock_page"))); + Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab(); + tab.Page_(page); + Xoh_js_cbk exec = tab.Html_itm().Js_cbk(); + GfoMsg msg = GfoMsg_.new_cast_(Xoh_js_cbk.Invk_get_titles_meta).Add("ttl", ttl); + String[][] actl = (String[][])Gfo_invk_.Invk_by_msg(exec, Xoh_js_cbk.Invk_get_titles_meta, msg); + Tfds.Eq_ary_str(expd, actl[0]); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_wdata_labels_tst.java b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_wdata_labels_tst.java new file mode 100644 index 000000000..69333dc51 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cbk_wdata_labels_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; +public class Xoh_js_cbk_wdata_labels_tst { + @Before public void init() {fxt.Init();} private final Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt(); + @Test public void Basic() { + fxt.Init__docs__add(fxt.Wdoc_bldr("q1").Add_label("en", "en_q1").Xto_wdoc()); + fxt.Init__docs__add(fxt.Wdoc_bldr("q2").Add_label("en", "en_q2").Xto_wdoc()); + fxt.Init__docs__add(fxt.Wdoc_bldr("Property:P1").Add_label("en", "en_property_p1").Xto_wdoc()); + Tst_wikidata_label_get(String_.Ary("en", "q1", "q2", "Property:P1"), String_.Ary("en_q1", "en_q2", "en_property_p1")); + } + @Test public void Outliers() { + fxt.Init__docs__add(fxt.Wdoc_bldr("q1").Add_label("en", "en_q1").Add_label("de", "de_q1").Xto_wdoc()); + Tst_wikidata_label_get(String_.Ary("fr", "q1"), String_.Ary((String)null)); + Tst_wikidata_label_get(String_.Ary("de", "q1"), String_.Ary("de_q1")); + Tst_wikidata_label_get(String_.Ary("xowa_title", "q1"), String_.Ary("q1")); + Tst_wikidata_label_get(String_.Ary("xowa_ui_lang", "q1"), String_.Ary("en_q1")); + Tst_wikidata_label_get(String_.Ary("fr;de", "q1"), String_.Ary("de_q1")); + } + @Test public void Escaped() { // PURPOSE: \t should be escaped; EX:wd.q:2; DATE:2014-04-23 + Wdata_doc d = doc_("q1", String_.Concat_lines_nl + ( "{ 'entity':['item',1]" + , ", 'label':" + , " { 'en':'\\ta'" // NOTE: json literally has "\t", not (char)8 + , " }" + , "}" + )); + fxt.Init__docs__add(d); + Tst_wikidata_label_get(String_.Ary("en", "q1"), String_.Ary("\ta")); + } + private Wdata_doc doc_(String qid, String src) { + Json_doc jdoc = fxt.Make_json(src); + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Wdata_doc rv = new Wdata_doc(Bry_.new_a7(qid), app.Wiki_mgr().Wdata_mgr(), jdoc); + return rv; + } + private void Tst_wikidata_label_get(String[] args, String[] expd) { + Xoa_app_fxt.Init_gui(fxt.App(), fxt.Wiki()); + Xoh_js_cbk exec = fxt.App().Gui_mgr().Browser_win().Active_html_itm().Js_cbk(); + GfoMsg msg = GfoMsg_.new_cast_(Xoh_js_cbk.Invk_wikidata_get_label); + int args_len = args.length; + for (int i = 0; i < args_len; i++) + msg.Add("v", args[i]); + String[] actl = (String[])Gfo_invk_.Invk_by_msg(exec, Xoh_js_cbk.Invk_wikidata_get_label, msg); + Tfds.Eq_ary_str(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cleaner_tst.java b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cleaner_tst.java new file mode 100644 index 000000000..eb54821b3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/js/Xoh_js_cleaner_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +public class Xoh_js_cleaner_tst { + @Before public void init() {fxt.Init();} private Xoh_js_cleaner_fxt fxt = new Xoh_js_cleaner_fxt(); + @Test public void Basic() {fxt.Test_clean("a", "a");} + @Test public void Js_nde() {fxt.Test_clean("ac", "a<script>bc");} + @Test public void Js_atr() {fxt.Test_clean("abc", "abc");} + @Test public void Js_atr_noop() {fxt.Test_clean("a onmouseover b", "a onmouseover b");} + @Test public void Js_atr_noop_regionSelect() {fxt.Test_clean("regionSelect=2", "regionSelect=2");} +} +class Xoh_js_cleaner_fxt { + public void Init() { + if (mgr == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + mgr = wiki.Html_mgr().Js_cleaner(); + } + } private Xoae_app app; Xowe_wiki wiki; Xoh_js_cleaner mgr; + public void Test_clean(String raw_str, String expd) { + byte[] raw = Bry_.new_a7(raw_str); + byte[] actl = mgr.Clean(wiki, raw, 0, raw.length); + if (actl == null) actl = raw; + Tfds.Eq(expd, String_.new_a7(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__hdr_tst.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__hdr_tst.java new file mode 100644 index 000000000..6ace9d35a --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__hdr_tst.java @@ -0,0 +1,83 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.modules.*; +import org.junit.*; +import gplx.xowa.apps.apis.xowa.html.modules.*; +import gplx.xowa.guis.views.*; +public class Xow_popup_anchor_finder__hdr_tst { + @Before public void init() {fxt.Clear();} private Xop_popup_hdr_finder_fxt fxt = new Xop_popup_hdr_finder_fxt(); + @Test public void Basic() { + String src_str = String_.Concat_lines_nl_skip_last + ( "a" + , "==b1==" + , "c" + ); + fxt.Test_find(src_str, "b1", 1); + fxt.Test_find_not(src_str, "b"); + fxt.Test_find_not(src_str, "a"); + } + @Test public void Mid() { + String src_str = String_.Concat_lines_nl_skip_last + ( "a" + , "==b==" + , "c" + , "==d==" + , "e" + ); + fxt.Test_find(src_str, "d", 9); + } + @Test public void Eos() { + String src_str = String_.Concat_lines_nl_skip_last + ( "a" + , "==b==" + ); + fxt.Test_find(src_str, "b", 1); + } + @Test public void Bos() { + String src_str = String_.Concat_lines_nl_skip_last + ( "==a==" + , "b" + ); + fxt.Test_find(src_str, "a", -1); + } + @Test public void Trim() { + String src_str = String_.Concat_lines_nl_skip_last + ( "a" + , "== b ==" + , "c" + ); + fxt.Test_find(src_str, "b", 1); + } + @Test public void Ws() { + String src_str = String_.Concat_lines_nl_skip_last + ( "a" + , "== b c ==" + , "d" + ); + fxt.Test_find(src_str, "b c", 1); + } +} +class Xop_popup_hdr_finder_fxt { + private Xow_popup_anchor_finder finder = new Xow_popup_anchor_finder(); + public void Clear() { + } + public void Test_find_not(String src_str, String hdr_str) {Test_find(src_str, hdr_str, Bry_find_.Not_found);} + public void Test_find(String src_str, String hdr_str, int expd) { + byte[] src = Bry_.new_u8(src_str); + byte[] hdr = Bry_.new_u8(hdr_str); + Tfds.Eq(expd, finder.Find(src, src.length, hdr, 0), hdr_str); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__id_tst.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__id_tst.java new file mode 100644 index 000000000..af91a8cb0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_anchor_finder__id_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.modules.*; +import org.junit.*; +import gplx.xowa.apps.apis.xowa.html.modules.*; +import gplx.xowa.guis.views.*; +public class Xow_popup_anchor_finder__id_tst { + @Before public void init() {fxt.Clear();} private Xop_popup_hdr_finder_fxt fxt = new Xop_popup_hdr_finder_fxt(); + @Test public void Basic() { + String src_str = String_.Concat_lines_nl_skip_last + ( "b" + , "" + , "c" + ); + fxt.Test_find(src_str, "a", 1); + fxt.Test_find_not(src_str, "b"); + fxt.Test_find_not(src_str, "c"); + } + @Test public void Ws() { + String src_str = String_.Concat_lines_nl_skip_last + ( "b" + , "" + , "c" + ); + fxt.Test_find(src_str, "a", 1); + } + @Test public void Fail() { + String src_str = String_.Concat_lines_nl_skip_last + ( "b" + , "" + , "c" + ); + fxt.Test_find_not(src_str, "a"); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java new file mode 100644 index 000000000..fa9e4b874 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/Xow_popup_parser_tst.java @@ -0,0 +1,520 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.modules.*; +import org.junit.*; import gplx.core.primitives.*; +import gplx.xowa.apps.apis.xowa.html.modules.*; +import gplx.xowa.wikis.nss.*; +import gplx.xowa.guis.views.*; +public class Xow_popup_parser_tst { + @Before public void init() {fxt.Clear();} private final Xop_popup_parser_fxt fxt = new Xop_popup_parser_fxt(); + @Test public void Text_chars_one() { + fxt.Test_parse + ( "a b c d", String_.Concat_lines_nl_skip_last + ( "

        a b" + , "

        " + )); + } + @Test public void Text_chars_many() { // PURPOSE: text.read_spans_scan + fxt.Test_parse + ( "abc def ghi", String_.Concat_lines_nl_skip_last + ( "

        abc def" + , "

        " + )); + } + @Test public void Text_chars_bound() {// PURPOSE: text.word_spans_scan + fxt.Test_parse + ( "abcde fghij k l", String_.Concat_lines_nl_skip_last + ( "

        abcde fghij" + , "

        " + )); + } + @Test public void Apos() { + fxt.Test_parse + ( "'''ab''' ''c'' de", String_.Concat_lines_nl_skip_last + ( "

        ab c" + , "

        " + , "" + )); + } + @Test public void Lnki() { + fxt.Test_parse("a [[b|c d e]] f" + , String_.Concat_lines_nl_skip_last + ( "

        a c d e" + , "

        " + )); + } + @Test public void Lnke_brack() { // PURPOSE: count lnke caption words; DATE:2014-06-20 + fxt.Init_tmpl_read_len_(32).Init_word_needed_(5).Test_parse + ( "a [http://b.org b c] d e f g", String_.Concat_lines_nl_skip_last + ( "

        a b c d e" + , "

        " + )); + } + @Test public void Lnke_text() { // PURPOSE: count entire lnke as one word + fxt.Init_tmpl_read_len_(32).Init_word_needed_(5).Test_parse + ( "a http://b.org c d e f g", String_.Concat_lines_nl_skip_last + ( "

        a http://b.org c d e" + , "

        " + )); + } + @Test public void Lnke_dangling() { // PURPOSE: handle dangling lnke; DATE:2014-06-20 + fxt.Test_parse + ( "a [http://b.org c d] e f g", String_.Concat_lines_nl_skip_last // NOTE: scan_len = 4, so 1st pass will be "a [h" + ( "

        a c d" // NOTE: (a) lnke correctly parsed, else would see "[" or "http"; (b) "c d" counts as 1 word + , "

        " + )); + } + @Test public void Hdr() { + fxt.Test_parse + ( "a\n===b===\n c", String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "

        b

        " + )); + } + @Test public void Hdr_one_word() { // PURPOSE: hdr.entire_tkn_counts_as_one_word + fxt.Test_parse + ( "===a b c===\nd", String_.Concat_lines_nl_skip_last + ( "

        a b c

        " + , "" + , "

        d" + , "

        " + )); + } + @Test public void Hdr_para() { // PURPOSE: hdr.para; handle para mode and hdr (para causes trailing \n to be para, not \n); PAGE:en.w:Flavius_Valerius_Severus DATE:2014-06-17 + fxt.Init_para_enabled_(true).Test_parse(String_.Concat_lines_nl_skip_last + ( "" + , "a" + , "" + , "==b==" + , "c" + , "" + , "d" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "

        b

        " + , "" + )); + } + @Test public void List() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a" + , "*b" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "
          " + , "
        • b" + , "
        • " + , "
        " + )); + } + @Test public void Xnde_pair() { + fxt.Test_parse + ( "b" + , String_.Concat_lines_nl_skip_last + ( "

        b" + , "

        " + )); + } + @Test public void Xnde_inline() { + fxt.Test_parse + ( "" + , String_.Concat_lines_nl_skip_last + ( "

        " + , "

        " + )); + } + @Test public void Xnde_br() { // PURPOSE: check that br is added correctly; PAGE:en.q:Earth; DATE:2014-06-30 + fxt.Init_word_needed_(3).Test_parse + ( "a
        b
        " + , String_.Concat_lines_nl_skip_last + ( "

        a
        b
        " + , "

        " + )); + } + @Test public void Xnde_math() { // PURPOSE: should be treated as one word; PAGE:en.w:System_of_polynomial_equations; DATE:2014-07-01 + fxt .Init_word_needed_(5) // need to read more words to pick up 1st word after header + .Init_read_til_stop_bwd_(2) // need to do read_bwd to start counting before ==e== into node + .Test_parse + ( "a b c d \n==e==\nf g h i" + , String_.Concat_lines_nl_skip_last + ( "

        a b c d (e)" // used to fail as

        a <math>b c d (e) + , "

        " + )); + } + @Test public void Ignore_tblw() {// also checks for tbl spanning multiple blocks; PAGE:en.w:Stratosphere; DATE:2014-06-17 + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a " + , "{|" + , "|-" + , "|b" + , "|} c" + ), String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Ignore_tblw_nested() {// PAGE:en.w:Cosmoloyg; DATE:2014-06-17 + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a" + , "{|" + , "|-" + , "|b" + , "|}" + , "" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "" + , "

        " + )); + } + @Test public void Ignore_tblx() { + fxt.Test_parse + ( "a
        b
        c" + , String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Ignore_ref() { + fxt.Test_parse + ( "a b c" + , String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Ignore_div() { + fxt.Test_parse + ( "a
        b
        c" + , String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Ignore_space_bos() { // pre. ignore spaces, else pre; PAGE:en.w:Volcano; en.w:War_elephant; DATE:2014-06-17 + fxt.Test_parse + ( "
        a
        b c d" // spaces before "b" are ignored + , String_.Concat_lines_nl_skip_last + ( "

        b c" + , "

        " + )); + } + @Test public void Ignore_space_nl() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a" + , "
        b
        c" // space before "c" is ignored + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "c" + , "

        " + )); + } + @Test public void Ignore_nl_bos() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + )); + } + @Test public void Ignore_nl_multiple() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "" + , "" // ignored + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "

        b" + , "

        " + )); + } + @Test public void Ignore_nl_hdr() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "" + , "" // ignored + , "==b==" + ), String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "

        b

        " + )); + } + @Test public void Ignore_lnki_file() { + fxt.Test_parse + ( "a [[File:b.png|thumb]] c" + , String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Ignore_gallery() { + fxt.Test_parse + ( "a File:B.png|c d" + , String_.Concat_lines_nl_skip_last + ( "

        a d" + , "

        " + )); + } + @Test public void Ignore_xnde() { + fxt.Test_parse + ( "a b c" + , String_.Concat_lines_nl_skip_last + ( "

        a c" + , "

        " + )); + } + @Test public void Dangling() { // make sure dangling nodes don't fail + fxt.Test_parse + ( "a" + , String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + )); + } + @Test public void End_early_dangling() { // PURPOSE: dangling tkn is too long; end early; PAGE:en.w:List_of_air_forces; DATE:2014-06-18 + fxt.Init_tmpl_read_max_(8).Test_parse + ( "a [[File:Test.png]] k" + , String_.Concat_lines_nl_skip_last + ( "

        a " + , "

        " + )); + } + @Test public void Ellipsis_() { + fxt.Init_ellipsis_("...").Test_parse + ( "a b c d" + , String_.Concat_lines_nl_skip_last + ( "

        a b..." + , "

        " + )); + fxt.Test_parse // no ellipsis: entire extract + ( "a" + , String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + )); + fxt.Test_parse // no ellipsis: entire extract multiple reads + ( "a
        b
        " + , String_.Concat_lines_nl_skip_last + ( "

        a " + , "

        " + )); + } + @Test public void Ns_allowed() { + fxt.Test_ns_allowed("Help" , Xow_ns_.Tid__help); + fxt.Test_ns_allowed("(Main)" , Xow_ns_.Tid__main); + fxt.Test_ns_allowed("" ); + fxt.Test_ns_allowed("(Main)|Help" , Xow_ns_.Tid__main, Xow_ns_.Tid__help); + } + @Test public void Read_til_stop_fwd() { + fxt.Init_word_needed_(2).Init_read_til_stop_fwd_(2) // read fwd found hdr + .Test_parse("a b c\n==d==", String_.Concat_lines_nl_skip_last + ( "

        a b c (d)" + , "

        " + )); + fxt.Init_word_needed_(2).Init_read_til_stop_fwd_(2) // read fwd did not find hdr; reset back to min + .Test_parse("a b c d", String_.Concat_lines_nl_skip_last + ( "

        a b" + , "

        " + )); + } + @Test public void Read_til_stop_bwd() { + fxt.Init_word_needed_(8).Init_read_til_stop_bwd_(4) // read bwd found hdr + .Test_parse("01 02 03 04 05\n==06==\n07 08 09 10 11 12 13 14 15 16", String_.Concat_lines_nl_skip_last + ( "

        01 02 03 04 05 (06)" + , "

        " + )); + fxt.Init_tmpl_read_len_(40).Init_word_needed_(5).Init_read_til_stop_bwd_(3) // read bwd at eos should not return "next_sect"; DATE:2014-07-01 + .Test_parse("01 02 03 \n==04==\n", String_.Concat_lines_nl_skip_last + ( "

        01 02 03 " + , "

        " + , "" + , "

        04

        " + )); + } + @Test public void Stop_if_hdr_after() { + fxt.Init_word_needed_(5).Init_stop_if_hdr_after_(1) + .Test_parse("a b\n==c==\nd e", String_.Concat_lines_nl_skip_last + ( "

        a b" + , "

        " + , "" + , "

        c

        " + )); + } + @Test public void Anchor() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a b c d" + , "" + , "== e ==" + , "f g h i" + ), "#e", String_.Concat_lines_nl_skip_last + ( "

        e

        " + , "" + , "

        f" + , "

        " + )); + } + @Test public void Anchor_underline() { + fxt.Test_parse(String_.Concat_lines_nl_skip_last + ( "a b c d" + , "" + , "== e f ==" + , "g h i" + ), "#e_f", String_.Concat_lines_nl_skip_last + ( "

        e f

        " + , "" + , "

        g" + , "

        " + )); + } + @Test public void Tmpl_tkn_max() { + fxt.Init_tmpl_tkn_max_(5).Init_page("Template:A", "a"); // eval + fxt.Test_parse + ( "{{A}}" + , String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + )); + fxt.Test_parse("{{A|b|c}}" , ""); // skip; NOTE: output should be blank, not

        \n

        ; PAGE:en.w:List_of_countries_by_GDP_(PPP); DATE:2014-07-01 + } + @Test public void Tmpl_tkn_max__comment_and_tblw() { // PURPOSE: garbled popup when tmpl_tkn_max is set and comments in front of tblw; PAGE:en.w:Gwynedd; DATE:2014-07-01 + fxt .Init_tmpl_tkn_max_(5) // set tmpl_tkn_max + .Init_tmpl_read_len_(20) // set read_len to 20 (must read entire "\n{|" at once + .Test_parse(String_.Concat_lines_nl_skip_last + ( "{{A|b}}" + , "{{A|b}}" + , "{|" + , "|-" + , "|a b c d" + , "|}" + ), ""); // should be blank, not ] + } + @Test public void Tmpl_tkn_max__apos() { // PURPOSE: handle apos around skipped tmpl token; PAGE:en.w:Somalia; DATE:2014-07-02 + fxt.Init_tmpl_tkn_max_(5).Test_parse("a''{{A|b}}''b", String_.Concat_lines_nl_skip_last + ( "

        a b" + , "

        " + )); + } + @Test public void Notoc_and_para_issue() { // PURPOSE.fix: issue with "\s__NOTOC__" and "a\n"b; PAGE:en.w:Spain; DATE:2014-07-05 + fxt.Init_word_needed_(3).Init_notoc_(" __NOTOC__").Test_parse("a\nb", String_.Concat_lines_nl_skip_last + ( "

        a" // was

        a

        b + , "b " + , "

        " + )); + } + @Test public void Test_Assert_at_end() { + fxt.Test_Assert_at_end("a" , "a\n"); // add one + fxt.Test_Assert_at_end("a\n" , "a\n"); // noop + fxt.Test_Assert_at_end("a\n\n\n" , "a\n"); // remove til one + fxt.Test_Assert_at_end("" , ""); // empty check + } + @Test public void Skip_to_end__tblw() { // PURPOSE: skip to end of tblw; PAGE:en.w:List_of_countries_and_dependencies_by_area; DATE:2014-07-19 + fxt.Init_tmpl_read_len_(4).Test_parse + ( String_.Concat_lines_nl_skip_last + ( "a" + , "{|" + , "|-" + , "|b" + , "|c" + , "|d" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + )); + fxt.Expd_tmpl_loop_count(2); + } +} +class Xop_popup_parser_fxt { + private Xow_popup_parser parser; private Xowe_wiki wiki; + private int word_min = 2; + public void Clear() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app, "en.wiki"); + parser = wiki.Html_mgr().Head_mgr().Popup_mgr().Parser(); + parser.Init_by_wiki(wiki); + parser.Cfg().Tmpl_read_len_(4); + parser.Cfg().Tmpl_read_max_(32 * Io_mgr.Len_kb); + parser.Cfg().Ellipsis_(Bry_.Empty); + parser.Cfg().Notoc_(Bry_.Empty); + parser.Cfg().Show_all_if_less_than_(-1); + parser.Cfg().Read_til_stop_fwd_(-1); + parser.Cfg().Read_til_stop_bwd_(-1); + parser.Cfg().Stop_if_hdr_after_(-1); + parser.Html_mkr().Fmtr_popup().Fmt_("~{content}"); + parser.Html_mkr().Output_js_clean_(false); + parser.Html_mkr().Output_tidy_(false); + parser.Html_mkr().Fmtr_next_sect().Fmt_(" (~{next_sect_val})"); + parser.Wrdx_mkr().Xnde_ignore_ids_(Bry_.new_a7("coordinates")); + word_min = 2; + } + public Xop_popup_parser_fxt Init_notoc_(String v) {parser.Cfg().Notoc_(Bry_.new_u8(v)); return this;} + public Xop_popup_parser_fxt Init_tmpl_read_len_(int v) {parser.Cfg().Tmpl_read_len_(v); return this;} + public Xop_popup_parser_fxt Init_tmpl_read_max_(int v) {parser.Cfg().Tmpl_read_max_(v); return this;} + public Xop_popup_parser_fxt Init_word_needed_(int v) {word_min = v; return this;} + public Xop_popup_parser_fxt Init_para_enabled_(boolean v) {parser.Wtxt_ctx().Para().Enabled_(v); return this;} + public Xop_popup_parser_fxt Init_ellipsis_(String v) {parser.Cfg().Ellipsis_(Bry_.new_u8(v)); return this;} + public Xop_popup_parser_fxt Init_read_til_stop_fwd_(int v) {parser.Cfg().Read_til_stop_fwd_(v); return this;} + public Xop_popup_parser_fxt Init_read_til_stop_bwd_(int v) {parser.Cfg().Read_til_stop_bwd_(v); return this;} + public Xop_popup_parser_fxt Init_stop_if_hdr_after_(int v) {parser.Cfg().Stop_if_hdr_after_(v); return this;} + public Xop_popup_parser_fxt Init_tmpl_tkn_max_(int v) {parser.Tmpl_tkn_max_(v); return this;} + public Xop_popup_parser_fxt Init_fmtr_next_sect_(String v) {parser.Html_mkr().Fmtr_next_sect().Fmt_(v); return this;} + public Xop_popup_parser_fxt Init_page(String ttl, String txt) {Xop_fxt.Init_page_create_static(wiki, ttl, txt); return this;} + public Xop_popup_parser_fxt Expd_tmpl_loop_count(int expd) {Tfds.Eq(expd, parser.Data().Tmpl_loop_count()); return this;} + public Xop_popup_parser_fxt Test_ns_allowed(String raw, int... expd) { + Int_obj_ref[] ids = Xow_popup_mgr.Ns_allowed_parse(wiki, Bry_.new_u8(raw)); + Tfds.Eq_ary(expd, To_int_ary(ids)); + return this; + } + private static int[] To_int_ary(Int_obj_ref[] ary) { + int len = ary.length; + int[] rv = new int[len]; + for (int i = 0; i < len; ++i) + rv[i] = ary[i].Val(); + return rv; + } + public void Test_parse(String raw, String expd) {Test_parse(raw, "Test_1", expd);} + public void Test_parse(String raw, String ttl, String expd) { + Xoae_page page = Xoae_page.New_edit(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl))); + page.Db().Text().Text_bry_(Bry_.new_u8(raw)); + Xow_popup_itm itm = new Xow_popup_itm(1, Bry_.new_u8(raw), Bry_.Empty, word_min); + itm.Init(wiki.Domain_bry(), page.Ttl()); + byte[] actl = parser.Parse(wiki, page, null, itm); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } + public void Test_Assert_at_end(String raw, String expd) { + if (test_bfr == null) test_bfr = Bry_bfr_.New(); + test_bfr.Clear().Add_str_u8(raw); + Bry_bfr_.Assert_at_end(test_bfr, Byte_ascii.Nl); + Tfds.Eq(expd, test_bfr.To_str_and_clear()); + } private Bry_bfr test_bfr; +} diff --git a/400_xowa/src/gplx/xowa/htmls/modules/popups/keeplists/Xop_keeplist_wiki_tst.java b/400_xowa/src/gplx/xowa/htmls/modules/popups/keeplists/Xop_keeplist_wiki_tst.java new file mode 100644 index 000000000..d65e749ad --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/modules/popups/keeplists/Xop_keeplist_wiki_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.modules.popups.keeplists; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.modules.*; import gplx.xowa.htmls.modules.popups.*; +import org.junit.*; +public class Xop_keeplist_wiki_tst { + @Before public void init() {fxt.Clear();} private Xop_keeplist_wiki_fxt fxt = new Xop_keeplist_wiki_fxt(); + @Test public void Tmpl_keeplist() { + Xop_keeplist_wiki keeplist_wiki = fxt.keeplist_wiki_(String_.Concat_lines_nl + ( "enwiki|a*|abc*" + )); + fxt.Test_Match_y(keeplist_wiki, "a", "ab"); + fxt.Test_Match_n(keeplist_wiki, "abc", "abcd", "d"); + } + @Test public void Tmpl_keeplist2() { + Xop_keeplist_wiki keeplist_wiki = fxt.keeplist_wiki_(String_.Concat_lines_nl + ( "enwiki|a*|abc*" + , "enwiki|b*|*xyz" + )); + fxt.Test_Match_y(keeplist_wiki, "a", "ab"); + fxt.Test_Match_n(keeplist_wiki, "d", "abc", "abcd"); + fxt.Test_Match_y(keeplist_wiki, "b", "bxy"); + fxt.Test_Match_n(keeplist_wiki, "bxyz", "bcdxyz"); + } +} +class Xop_keeplist_wiki_fxt { + public void Clear() { + } + public Xop_keeplist_wiki keeplist_wiki_(String raw) { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "enwiki"); + Xow_popup_mgr popup_mgr = wiki.Html_mgr().Head_mgr().Popup_mgr(); + popup_mgr.Init_by_wiki(wiki); + popup_mgr.Parser().Tmpl_keeplist_init_(Bry_.new_u8(raw)); + Xop_keeplist_wiki rv = popup_mgr.Parser().Tmpl_keeplist(); + return rv; + } + public void Test_Match_y(Xop_keeplist_wiki keeplist_wiki, String... itms) {Test_Match(keeplist_wiki, itms, Bool_.Y);} + public void Test_Match_n(Xop_keeplist_wiki keeplist_wiki, String... itms) {Test_Match(keeplist_wiki, itms, Bool_.N);} + private void Test_Match(Xop_keeplist_wiki keeplist_wiki, String[] itms, boolean expd) { + int len = itms.length; + for (int i = 0; i < len; i++) { + String itm = itms[i]; + Tfds.Eq(expd, keeplist_wiki.Match(Bry_.new_u8(itm)), "itm={0} expd={1}", itm, expd); + } + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/ns_files/Xoh_ns_file_page_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/ns_files/Xoh_ns_file_page_mgr_tst.java new file mode 100644 index 000000000..806701204 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/ns_files/Xoh_ns_file_page_mgr_tst.java @@ -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.xowa.htmls.ns_files; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xoh_ns_file_page_mgr_tst { + private final Xoh_ns_file_page_mgr_fxt fxt = new Xoh_ns_file_page_mgr_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Image() { + fxt.Ttl_str_("Test.png").Html_src_("mem/file/cur.png").Html_orig_src_("mem/file/orig.png").Html_w_(300).Html_h_(200).Html_file_size_(100) + .tst(String_.Concat_lines_nl_skip_last + ( Xoh_ns_file_page_mgr_fxt.Hdr + , "
        " + , " " + , " \"Test.png\"" + , " " + , "
        Size of this preview: " + , " " + , " 300 × 200 pixels" + , " " + , " ." +// , " " +// , " Other resolutions:" +// , "" +// , " " + , "
        " + , "
        " + , "
        " + , " " + , " Full resolution" + , " " + , " ‎" + , " " + , " (0 × 0 pixels, file size: 100, MIME type: image/png)" + , " " + , "
        " + , "" + )); + } + @Test public void Audio() { + fxt.Ttl_str_("Test.oga").Html_src_("mem/file/cur.oga").Html_orig_src_("mem/file/orig.oga").Html_w_(300).Html_h_(200).Html_file_size_(100) + .tst(String_.Concat_lines_nl_skip_last + ( Xoh_ns_file_page_mgr_fxt.Hdr + , "
        " + , "
        " + , "
        " + , "" + )); + } + @Test public void Video() { + fxt.Ttl_str_("Test.ogv").Html_src_("mem/file/thumb.png").Html_orig_src_("mem/file/orig.ogv").Html_w_(300).Html_h_(200).Html_file_size_(100) + .tst(String_.Concat_lines_nl_skip_last + ( Xoh_ns_file_page_mgr_fxt.Hdr + , "
        " + , "
        " + , " " + , " \"\"" + , " " + , "
        " + , "
        " + , "
        " + , "" + )); + } +} +class Xoh_ns_file_page_mgr_fxt { + private final Xoh_ns_file_page_mgr wkr = new Xoh_ns_file_page_mgr(); + private Xoae_app app; private Xowe_wiki wiki; private Xoh_file_page_wtr opt; + private final Xof_file_itm file = new Xof_fsdb_itm(); private final Bry_bfr bfr = Bry_bfr_.New(); + public Xoh_ns_file_page_mgr_fxt Ttl_str_(String v) {this.ttl_str = v; return this;} private String ttl_str; + public Xoh_ns_file_page_mgr_fxt Html_src_(String v) {this.html_src = v; return this;} private String html_src; + public Xoh_ns_file_page_mgr_fxt Html_orig_src_(String v) {this.html_orig_src = v; return this;} private String html_orig_src; + public Xoh_ns_file_page_mgr_fxt Html_w_(int v) {this.html_w = v; return this;} private int html_w; + public Xoh_ns_file_page_mgr_fxt Html_h_(int v) {this.html_h = v; return this;} private int html_h; + public Xoh_ns_file_page_mgr_fxt Html_file_size_(int v) {this.html_file_size = v; return this;} private int html_file_size; + public void Reset() { + if (app != null) return; + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + opt = new Xoh_file_page_wtr(); + } + public void tst(String expd) { + byte[] ttl_bry = Bry_.new_u8(ttl_str); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry); + file.Init_at_gallery_end(html_w, html_h, Io_url_.mem_fil_(html_src), Io_url_.mem_fil_(html_orig_src)); +// file.Orig_ttl_and_redirect_(ttl_bry, Bry_.Empty); + file.Init_at_orig(Byte_.Zero, wiki.Domain_bry(), ttl_bry, Xof_ext_.new_by_ttl_(ttl_bry), 0, 0, Bry_.Empty); + file.Init_at_hdoc(0, Xof_html_elem.Tid_img); + wkr.Bld_html(wiki, bfr, file, ttl, opt, Bry_.To_a7_bry(html_file_size, 0)); // TEST: must pass in elem_val b/c test only uses 2nd Bld_html while app uses 1st + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } + public static final String Hdr = String_.Concat_lines_nl_skip_last("
        "); +// ( "" +// ); +} + diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls_tst.java new file mode 100644 index 000000000..61cd87bc7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_page_body_cls_tst.java @@ -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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wbases.*; +public class Xoh_page_body_cls_tst { + @Before public void init() {} private Xoh_page_body_cls_fxt fxt = new Xoh_page_body_cls_fxt(); + @Test public void Escape_cls() { + fxt.Test_escape_cls("0123456789", "0123456789"); // noop: num + fxt.Test_escape_cls("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // noop: ucase + fxt.Test_escape_cls("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); // noop: lcase + fxt.Test_escape_cls("!\"#$%&'()*+,.\\/:;<=>?@[]^`{|}~", "______________________________"); // underline: syms + fxt.Test_escape_cls("a.bcd..ef.", "a_bcd__ef_"); // letters + syms + fxt.Test_escape_cls("a__b___c" , "a_b_c"); // multiple underlines + fxt.Test_escape_cls("a b", "a_b"); // nbsp + } + @Test public void Calc() { + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "A" , "ns-0 ns-subject page-A"); + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Talk:A" , "ns-1 ns-talk page-Talk_A"); + fxt.Test_calc(Xow_page_tid.Tid_wikitext , "Wikipedia:Página principal" , "ns-4 ns-subject page-Wikipedia_Página_principal"); + fxt.Test_calc(Xow_page_tid.Tid_json , "Q2" , "ns-0 ns-subject page-Q2 wb-entitypage wb-itempage wb-itempage-Q2"); + fxt.Test_calc(Xow_page_tid.Tid_json , "Property:P1" , "ns-120 ns-subject page-Property_P1 wb-entitypage wb-propertypage wb-propertypage-P1"); + } +} +class Xoh_page_body_cls_fxt { + private Bry_bfr tmp_bfr; private Xoae_app app; private Xowe_wiki wiki; + public void Test_escape_cls(String raw, String expd) { + Tfds.Eq(expd, String_.new_u8(Xoh_page_body_cls.Escape_cls(Bry_.new_u8(raw)))); + } + public void Test_calc(byte page_tid, String ttl_str, String expd) { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + tmp_bfr = Bry_bfr_.Reset(255); + wiki.Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, Wdata_wiki_mgr.Ns_property_name); + } + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)); + Tfds.Eq(expd, String_.new_u8(Xoh_page_body_cls.Calc(tmp_bfr, ttl, page_tid))); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.java new file mode 100644 index 000000000..0f2fbde7f --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_rtl_utl_tst.java @@ -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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; +public class Xoh_rtl_utl_tst { + @Before public void init() {fxt.Init();} private Xoh_rtl_utl_fxt fxt = new Xoh_rtl_utl_fxt(); + @Test public void Basic() { + fxt.Test_reverse_li("
        • a
        • b
        ", "
        • b
        • a
        "); + } + @Test public void Zero() { + fxt.Test_reverse_li("a", "a"); + } + @Test public void One() { + fxt.Test_reverse_li("
        • a
        ", "
        • a
        "); + } + @Test public void Example() { + fxt.Test_reverse_li(String_.Concat_lines_nl_skip_last + ( "
        " + , "
          " + , "
        • a" + , "
        • " + , "
        • b" + , "
        • " + , "
        • c" + , "
        • " + , "
        " + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
          " + , "
        • c" + , "
        • " + , "
        • b" + , "
        • " + , "
        • a" + , "
        • " + , "
        " + , "
        " + )); + } +} +class Xoh_rtl_utl_fxt { + public void Init() { + } + public void Test_reverse_li(String raw, String expd) { + byte[] actl = Xoh_rtl_utl.Reverse_li(Bry_.new_u8(raw)); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java new file mode 100644 index 000000000..e4b0366b9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xoh_subpages_bldr_tst.java @@ -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.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.xowa.wikis.nss.*; +public class Xoh_subpages_bldr_tst { + @Before public void init() {fxt.Init();} private Xoh_subpages_bldr_fxt fxt = new Xoh_subpages_bldr_fxt(); + @Test public void Basic() { + fxt.Test_bld("Help:A/B/C", String_.Concat_lines_nl_skip_last + ( "" + , " < Help:A" + , " ‎ | B" + , "" + )); + } + @Test public void Skip_page() { + fxt.Wiki().Ns_mgr().Add_new(104, "Page"); + fxt.Wiki().Ns_mgr().Ns_page_id_(104); + fxt.Test_bld("Page:A/B/C", ""); + } +} +class Xoh_subpages_bldr_fxt { + private Xoae_app app; + private Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr(); + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public void Init() { + this.app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__help).Subpages_enabled_(true); + } + public void Test_bld(String ttl_str, String expd) { + byte[] actl = subpages_bldr.Bld(wiki.Ns_mgr(), Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str))); + Tfds.Eq_str_lines(expd, String_.new_u8(actl)); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java new file mode 100644 index 000000000..04aba7d39 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/portal/Xow_portal_mgr_tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; +import org.junit.*; import gplx.core.tests.*; +public class Xow_portal_mgr_tst { + @Before public void init() {fxt.Init();} private Xowh_portal_mgr_fxt fxt = new Xowh_portal_mgr_fxt(); + @Test public void Div_ns_bry() { + fxt.Test_div_ns_bry("A" , "/wiki/A;selected;/wiki/Talk:A;xowa_display_none;"); + fxt.Test_div_ns_bry("Talk:A" , "/wiki/A;;/wiki/Talk:A;selected;"); + } + @Test public void Div_personal_bry() { + fxt.Test_div_personal_bry("/wiki/User:anonymous;anonymous;xowa_display_none;/wiki/User_talk:anonymous;xowa_display_none;"); + } + @Test public void Missing_ns_cls() { + fxt.Test_missing_ns_cls("xowa_display_none"); + } + @Test public void Logo() { + fxt.Portal_mgr().Div_logo_fmtr().Fmt_("~{portal_logo_url}"); + + // day-mode + fxt.Portal_mgr().Init(); + fxt.Test_logo_frag(Bool_.N, "file:///mem/xowa/user/test_user/wiki/en.wikipedia.org/html/logo.png"); + + // night-mode: app + fxt.Test_logo_frag(Bool_.Y, "file:///mem/xowa/bin/any/xowa/html/css/nightmode/logo_night.png"); + + // night-mode: wiki + Io_mgr.Instance.SaveFilStr("mem/xowa/user/test_user/wiki/en.wikipedia.org/html/logo_night.png", ""); + fxt.Portal_mgr().Init(); + fxt.Test_logo_frag(Bool_.Y, "file:///mem/xowa/user/test_user/wiki/en.wikipedia.org/html/logo_night.png"); + } +} +class Xowh_portal_mgr_fxt { + private Xow_portal_mgr portal_mgr; + public void Init() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + wiki.Ns_mgr().Ns_main().Exists_(true); // needed for ns + this.portal_mgr = wiki.Html_mgr().Portal_mgr(); + portal_mgr.Init_assert(); // needed for personal + portal_mgr.Missing_ns_cls_(Bry_.new_a7("xowa_display_none")); + } + } private Xoae_app app; Xowe_wiki wiki; + public void Test_div_ns_bry(String ttl, String expd) { + Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Div_ns_bry(wiki.Utl__bfr_mkr(), Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl)), wiki.Ns_mgr()))); + } + public void Test_div_personal_bry(String expd) { + Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Div_personal_bry())); + } + public void Test_missing_ns_cls(String expd) { + Tfds.Eq(expd, String_.new_a7(wiki.Html_mgr().Portal_mgr().Missing_ns_cls())); + } + public Xow_portal_mgr Portal_mgr() {return wiki.Html_mgr().Portal_mgr();} + public void Test_logo_frag(boolean nightmode, String expd) { + String actl = String_.new_a7(wiki.Html_mgr().Portal_mgr().Div_logo_bry(nightmode)); + Gftest.Eq__str(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/htmls/portal/vnts/Vnt_mnu_grp_fmtr_tst.java b/400_xowa/src/gplx/xowa/htmls/portal/vnts/Vnt_mnu_grp_fmtr_tst.java new file mode 100644 index 000000000..61f8c0d67 --- /dev/null +++ b/400_xowa/src/gplx/xowa/htmls/portal/vnts/Vnt_mnu_grp_fmtr_tst.java @@ -0,0 +1,65 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.htmls.portal.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*; +import org.junit.*; import gplx.xowa.langs.vnts.*; +public class Vnt_mnu_grp_fmtr_tst { + @Before public void init() {fxt.Clear();} private final Vnt_mnu_grp_fmtr_fxt fxt = new Vnt_mnu_grp_fmtr_fxt(); + @Test public void Basic() { +// fxt.Test_to_str("Earth", "zh-hk", String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// )); + } +} +class Vnt_mnu_grp_fmtr_fxt { + private final Xol_vnt_regy mgr = new Xol_vnt_regy(); + public void Clear() { + this.Init_grp("Choose lang", "zh-hans", "Simplified", "zh-hant", "Traditional", "zh-cn", "China", "zh-hk", "Hong Kong", "zh-mo", "Macau", "zh-sg", "Singapore", "zh-tw", "Taiwan"); + } + public void Init_grp(String text, String... langs) { + mgr.Clear(); + int len = langs.length; + String lang_code = ""; + for (int i = 0; i < len; ++i) { + String lang = langs[i]; + if (i % 2 == 0) + lang_code = lang; + else { + mgr.Add(Bry_.new_u8(lang_code), Bry_.new_u8(lang)); + } + } + } + public void Test_to_str(String page_href, String selected_vnt, String expd) { + Vnt_mnu_grp_fmtr vnt_grp_fmtr = new Vnt_mnu_grp_fmtr(); + Bry_bfr bfr = Bry_bfr_.New(); + vnt_grp_fmtr.Init(mgr, Bry_.new_u8(page_href), Bry_.new_a7("zh.wikipedia.org"), Bry_.new_u8(selected_vnt)); + vnt_grp_fmtr.Bfr_arg__add(bfr); + Tfds.Eq_str_lines(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java b/400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java new file mode 100644 index 000000000..f42a32c62 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/bldrs/Xob_i18n_parser_tst.java @@ -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]); + } + } +} diff --git a/400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java b/400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java new file mode 100644 index 000000000..a741d90bc --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/bldrs/Xobc_utl_make_lang_tst.java @@ -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(); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java new file mode 100644 index 000000000..5a048d8bf --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/bldrs/Xol_mw_lang_parser_tst.java @@ -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}}", "Template:Si:");} // 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; + } +} diff --git a/400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java b/400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java new file mode 100644 index 000000000..ea944e963 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/cases/Xol_case_mgr_tst.java @@ -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";}} +*/ \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/langs/kwds/Xol_kwd_parse_data_tst.java b/400_xowa/src/gplx/xowa/langs/kwds/Xol_kwd_parse_data_tst.java new file mode 100644 index 000000000..e957dec1b --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/kwds/Xol_kwd_parse_data_tst.java @@ -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; + } +} diff --git a/400_xowa/src/gplx/xowa/langs/lnki_trails/Xol_lnki_trail_mgr_tst.java b/400_xowa/src/gplx/xowa/langs/lnki_trails/Xol_lnki_trail_mgr_tst.java new file mode 100644 index 000000000..dacaa9f1c --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/lnki_trails/Xol_lnki_trail_mgr_tst.java @@ -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); + } + } +} diff --git a/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java b/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java new file mode 100644 index 000000000..6ac480b0d --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_itm_tst.java @@ -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"); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java b/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java new file mode 100644 index 000000000..bfeefd900 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/msgs/Xol_msg_mgr_tst.java @@ -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", ""); // check that key is enclosed in <> + fxt.Test__get_msg_val("Missing", ""); // check that val matches key; used to match 1st case-insensitive variant; EX: "" b/c "" 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(wiki, 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); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/msgs/Xow_mainpage_finder_tst.java b/400_xowa/src/gplx/xowa/langs/msgs/Xow_mainpage_finder_tst.java new file mode 100644 index 000000000..3bec4e41a --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/msgs/Xow_mainpage_finder_tst.java @@ -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)); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java b/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java new file mode 100644 index 000000000..cfa601b83 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java @@ -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 +*/ \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_grp_fmtr_tst.java b/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_grp_fmtr_tst.java new file mode 100644 index 000000000..8bfa739e8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/numbers/Xol_num_grp_fmtr_tst.java @@ -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)); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java b/400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java new file mode 100644 index 000000000..66c7dac78 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/parsers/Xol_csv_parser_tst.java @@ -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()); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java new file mode 100644 index 000000000..915140a18 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/parsers/Xol_lang_srl_tst.java @@ -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_(); +} diff --git a/400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java b/400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java new file mode 100644 index 000000000..1484be5d6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java @@ -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); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java b/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java new file mode 100644 index 000000000..3ca7b96cf --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_fxt.java @@ -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)); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java b/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java new file mode 100644 index 000000000..814ba5487 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/vnts/Xol_vnt_regy_tst.java @@ -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") + ); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_convert_regy_tst.java b/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_convert_regy_tst.java new file mode 100644 index 000000000..872370753 --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_convert_regy_tst.java @@ -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); + } +} diff --git a/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java b/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java new file mode 100644 index 000000000..a779ddd7b --- /dev/null +++ b/400_xowa/src/gplx/xowa/langs/vnts/converts/Xol_mw_parse_tst.java @@ -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)); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/Xop_ctx__tst.java b/400_xowa/src/gplx/xowa/parsers/Xop_ctx__tst.java new file mode 100644 index 000000000..9f0512fd4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/Xop_ctx__tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*; +import org.junit.*; +public class Xop_ctx__tst { + @Before public void init() {fxt.Clear();} private Xop_ctx__fxt fxt = new Xop_ctx__fxt(); + @Test public void Src_limit_and_escape_nl() { + fxt.Test_Src_limit_and_escape_nl("abcdefg", 4, 3, "efg"); // PURPOSE: bug fix; outOfBounds thrown; DATE:2014-03-31 + } +} +class Xop_ctx__fxt { + public void Clear() { + } + public void Test_Src_limit_and_escape_nl(String src, int bgn, int limit, String expd) { + String actl = Xop_ctx_.Src_limit_and_escape_nl(Bry_.new_u8(src), bgn, limit); + Tfds.Eq(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/Xop_parser__tst.java b/400_xowa/src/gplx/xowa/parsers/Xop_parser__tst.java new file mode 100644 index 000000000..232053c45 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/Xop_parser__tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers; import gplx.*; import gplx.xowa.*; +import org.junit.*; +public class Xop_parser__tst { + @Before public void init() {fxt.Clear();} private Xop_parser__fxt fxt = new Xop_parser__fxt(); + @Test public void Para_y() { + fxt.Test_parse_to_html(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + ), true, String_.Concat_lines_nl_skip_last + ( "

        a" + , "

        " + , "" + , "

        b" + , "

        " + , "" + )); + } + @Test public void Para_n() { + fxt.Test_parse_to_html(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + ), false, String_.Concat_lines_nl_skip_last + ( "a" + , "b" + )); + } +} +class Xop_parser__fxt { + private final Xop_fxt fxt = new Xop_fxt(); + private Bry_bfr bfr = Bry_bfr_.Reset(255); + public void Clear() { + fxt.Reset(); + } + public void Test_parse_to_html(String raw, boolean para_enabled, String expd) { + byte[] raw_bry = Bry_.new_u8(raw); + fxt.Wiki().Parser_mgr().Main().Parse_text_to_html(bfr, fxt.Ctx(), fxt.Page(), para_enabled, raw_bry); + Tfds.Eq(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__decode__tst.java b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__decode__tst.java new file mode 100644 index 000000000..c409ac651 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__decode__tst.java @@ -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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_amp_mgr__decode__tst { + @Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt(); + @Test public void Text() {fxt.Test__decode_as_bry("a" , "a");} + @Test public void Name() {fxt.Test__decode_as_bry("&" , "&");} + @Test public void Name_w_text() {fxt.Test__decode_as_bry("a&b" , "a&b");} + @Test public void Name_fail_semic_missing() {fxt.Test__decode_as_bry("a&b" , "a&b");} + @Test public void Name_fail_amp_only() {fxt.Test__decode_as_bry("a&" , "a&");} + @Test public void Num_fail() {fxt.Test__decode_as_bry("&#!;" , "&#!;");} // ! is not valid num + @Test public void Hex_fail() {fxt.Test__decode_as_bry("&#x!;" , "&#x!;");} // ! is not valid hex + @Test public void Num_basic() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Num_zero_padded() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Hex_upper() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Hex_lower() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Hex_zero_padded() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Hex_upper_x() {fxt.Test__decode_as_bry("Σ" , "Σ");} + @Test public void Num_fail_large_codepoint() {fxt.Test__decode_as_bry("�" , "�");} + @Test public void Num_ignore_extra_x() {fxt.Test__decode_as_bry("&#xx26D0;" , Char_.To_str(Char_.By_int(9936)));} // 2nd x is ignored +} +class Xop_amp_mgr_fxt { + private final Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance; + public void Test__decode_as_bry(String raw, String expd) { + Gftest.Eq__str(expd, String_.new_u8(amp_mgr.Decode_as_bry(Bry_.new_u8(raw)))); + } + public void Test__parse_tkn__ent(String raw, String expd) { + Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw); + Xop_amp_tkn_ent tkn = (Xop_amp_tkn_ent)rv.Tkn(); + Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ref, tkn.Tkn_tid()); + Gftest.Eq__str(expd, tkn.Xml_name_bry()); + } + public void Test__parse_tkn__ncr(String raw, int expd) { + Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw); + Xop_amp_tkn_num tkn = (Xop_amp_tkn_num)rv.Tkn(); + Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ncr, tkn.Tkn_tid()); + Gftest.Eq__int(expd, tkn.Val()); + } + public void Test__parse_tkn__txt(String raw, int expd) { + Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw); + Gftest.Eq__null(Bool_.Y, rv.Tkn()); + Gftest.Eq__int(expd, rv.Pos()); + } + private Xop_amp_mgr_rslt Exec__parse_tkn(String raw) { + byte[] src = Bry_.new_u8(raw); + return amp_mgr.Parse_tkn(new Xop_tkn_mkr(), src, src.length, 0, 1); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__parse_tkn__tst.java b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__parse_tkn__tst.java new file mode 100644 index 000000000..09eba83e7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_mgr__parse_tkn__tst.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_amp_mgr__parse_tkn__tst { + @Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt(); + @Test public void Ent() {fxt.Test__parse_tkn__ent("&" , "&");} // check for html_ref + @Test public void Ent__fail() {fxt.Test__parse_tkn__txt("&nil;" , 1);} + @Test public void Num__nex() {fxt.Test__parse_tkn__ncr("Σ" , 931);} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference + @Test public void Num__dec() {fxt.Test__parse_tkn__ncr("Σ" , 931);} + @Test public void Num__fail() {fxt.Test__parse_tkn__txt("&#" , 1);} +} diff --git a/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_wkr_tst.java b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_wkr_tst.java new file mode 100644 index 000000000..cbf3331c8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/amps/Xop_amp_wkr_tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_amp_wkr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Convert_to_named() {fxt.Test_parse_page_wiki_str("&" , "&");} // note that & is printed, not & + @Test public void Convert_to_named_amp() {fxt.Test_parse_page_wiki_str("&" , "&");} // PURPOSE: html_wtr was not handling & only + @Test public void Convert_to_numeric() {fxt.Test_parse_page_wiki_str("á" , "á");} // testing that á is outputted, not á + @Test public void Defect_bad_code_fails() { // PURPOSE: early rewrite of Xop_amp_mgr caused Xoh_html_wtr_escaper to fail with array out of bounds error; EX:w:Czech_Republic; DATE:2014-05-11 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|alt=

        ]]" // basically checks amp parsing inside xnde inside lnki's alt (which uses different parsing code + , "\"
\"" + ); + } + @Test public void Ignore_ncr() { // PURPOSE: check that ncr is unescaped; PAGE:de.w:Cross-Site-Scripting; DATE:2014-07-23 + fxt.Test_parse_page_all_str + ( "a <iframe>) b" + , "a <iframe>) b" // < should not become < + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/apos/Xop_apos_wkr_tst.java b/400_xowa/src/gplx/xowa/parsers/apos/Xop_apos_wkr_tst.java new file mode 100644 index 000000000..71fa8f40c --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/apos/Xop_apos_wkr_tst.java @@ -0,0 +1,151 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.parsers.lists.*; +public class Xop_apos_wkr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_parse_page_wiki("''a''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn) , fxt.tkn_txt_(2, 3), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); + fxt.Test_parse_page_wiki("'''a'''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) , fxt.tkn_txt_(3, 4), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + fxt.Test_parse_page_wiki("'''''a'''''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_ib_bgn) , fxt.tkn_txt_(5, 6), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_bi_end)); + } + @Test public void Advanced() { + fxt.Test_parse_page_wiki("''''a''''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn).Apos_lit_(1) , fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end).Apos_lit_(1)); // 1 apos + bold + fxt.Test_parse_page_wiki("''''''''a''''''''" , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_ib_bgn).Apos_lit_(3) , fxt.tkn_txt_(), fxt.tkn_apos_( Xop_apos_tkn_.Cmd_bi_end).Apos_lit_(3)); // 3 apos + dual + } + @Test public void Combo() { + fxt.Test_parse_page_wiki("''a'''b'''c''", fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); // b{i} + fxt.Test_parse_page_wiki("'''a''b''c'''", fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); // i{b} + fxt.Test_parse_page_wiki("''a''b'''c'''", fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); // b_i + } + @Test public void Assume_apos() { + fxt.Test_parse_page_wiki("a01'''b01 '''c0 1'''d01''" // pick c0 1, b/c it is idxNeg2 + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end) + , fxt.tkn_txt_(), fxt.tkn_space_(), fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn) + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); // idx_neg2 + fxt.Test_parse_page_wiki("a01 '''b01 '''c01'''d01''" // pick c01, b/c it is idxNone + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end) + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn) + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); // idx_none + fxt.Test_parse_page_wiki("a01 '''b01 '''c01 '''d01''" // pick a01 , b/c it is idxNeg1 + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn) + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) + , fxt.tkn_txt_(), fxt.tkn_space_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end) + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); // idx_neg1 + fxt.Test_parse_page_wiki("a''''b''" // strange outlier condition + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn).Apos_lit_(2) + , fxt.tkn_txt_() , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); // 4 apos -> 2 apos + ital + } + @Test public void Dual() { + fxt.Test_parse_page_wiki("'''''a'''b''" // +ib -b -i; 5apos defaults to ib + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_ib_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); + fxt.Test_parse_page_wiki("'''''a''b'''" // +bi -i -b; change 5apos to bi + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_bi_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + fxt.Test_parse_page_wiki("''b'''''c'''" // 5q toggles ital n, bold y + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end__b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + } + @Test public void Unclosed() { + fxt.Test_parse_page_wiki("''a" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); + fxt.Test_parse_page_wiki("'''a" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + fxt.Test_parse_page_wiki("'''''a" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_ib_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_bi_end)); + } + @Test public void Outliers() { + fxt.Test_parse_page_wiki("''a'''b'''c'''" // '''b -> ' +i b + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end).Apos_lit_(1) + , fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + fxt.Test_parse_page_wiki("''a'''b''c''" // '''b -> ' +i b; double check with closing itals + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end).Apos_lit_(1) + , fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); + fxt.Test_parse_page_wiki("''a'''b''c" // ''c -> -bi + b + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_bgn) + , fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_bi_end__b_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_b_end)); + } + @Test public void MultiLines() { + fxt.Test_parse_page_wiki("a''b\nc''d" + , fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(3, 4), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end), fxt.tkn_nl_char_len1_(4) + , fxt.tkn_txt_(5, 6), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end)); + } + @Test public void Lnki() { + fxt.Test_parse_page_wiki_str("[[''a''']]", "''a'''"); + } + @Test public void Dual_exceptions() { + fxt.Test_parse_page_wiki("'''''a''b''" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_bi_bgn), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end), fxt.tkn_txt_(), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn), fxt.tkn_apos_(Xop_apos_tkn_.Cmd_ib_end) + ); + } + @Test public void Mix_list_autoClose() { + fxt.Test_parse_page_wiki("''a\n*b" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn).Src_rng_(0, 2) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end).Src_rng_(3, 3) + , fxt.tkn_list_bgn_(3, 5, Xop_list_tkn_.List_itmTyp_ul) + , fxt.tkn_txt_(5, 6) + , fxt.tkn_list_end_(6) + ); + } + @Test public void Mix_hr_autoClose() { + fxt.Test_parse_page_wiki("''a\n----" + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_bgn).Src_rng_(0, 2) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_apos_(Xop_apos_tkn_.Cmd_i_end).Src_rng_(3, 3) + , fxt.tkn_para_blank_(3) + , fxt.tkn_hr_(3, 8) + ); + } + @Test public void Mix_hdr_autoClose() { + fxt.Test_parse_page_wiki_str("''a\n==b==", "a\n\n

        b

        "); + } + @Test public void Apos_broken_by_tblw_th() { // DATE:2013-04-24 + fxt.Test_parse_page_all_str("A ''[[b!!]]'' c", "A b!! c"); + } + @Test public void Nowiki() { // PAGE:en.w:Wiki; DATE:2013-05-13 + fxt.Test_parse_page_all_str("''a''", "''a''"); + } + @Test public void Lnki_multi_line() { // PURPOSE: handle apos within multi-line lnki caption; DATE:2013-11-10 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "[[A|b '' c" + , "d '' e ]]" + ) + , "b c d e"); // NOTE: c d should be italicized, not c e (latter occurs when apos is ended on each line) + } + @Test public void French() { // PURPOSE: L'''A'' -> L'A; DATE:2014-01-06 + fxt.Test_parse_page_all_str("L''''A'''", "L'A"); + fxt.Test_parse_page_all_str("L'''A''", "L'A"); + } +// @Test public void Mix_lnke() { // FUTURE: requires rewrite of apos +// fxt.Test_parse_page_wiki("''a[irc://b c''d''e]f''" +// , fxt.tkn_apos_(0, 2, Xop_apos_tkn_.Cmd_i_bgn) +// , fxt.tkn_txt_(2, 3) +// , fxt.tkn_lnke_(3, 20).Subs_add_ary +// ( fxt.tkn_txt_(12, 13) +// , fxt.tkn_apos_(13, 15, Xop_apos_tkn_.Cmd_i_bgn) +// , fxt.tkn_txt_(15, 16) +// , fxt.tkn_apos_(16, 18, Xop_apos_tkn_.Cmd_i_end) +// , fxt.tkn_txt_(18, 19) +// ) +// , fxt.tkn_txt_(20, 21) +// , fxt.tkn_apos_(21, 23, Xop_apos_tkn_.Cmd_i_bgn) +// ); +// } +} +/* +*/ diff --git a/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java new file mode 100644 index 000000000..497848586 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__basic_tst.java @@ -0,0 +1,125 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_hdr_wkr__basic_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void H2() {fxt.Test_parse_page_wiki_str("==a==" , "

        a

        \n");} + @Test public void H3() {fxt.Test_parse_page_wiki_str("===a===" , "

        a

        \n");} + @Test public void H6_limit() {fxt.Test_parse_page_wiki_str("=======a=======" , "
        =a=
        \n");} + @Test public void Mismatch_bgn() {fxt.Test_parse_page_wiki_str("=====a==" , "

        ===a

        \n");} + @Test public void Mismatch_end() {fxt.Test_parse_page_wiki_str("==a=====" , "

        a===

        \n");} + @Test public void Dangling() {fxt.Test_parse_page_wiki_str("==a" , "==a");} + @Test public void Comment_bgn() {fxt.Test_parse_page_all_str ("==a==" , "

        a

        \n");} + @Test public void Comment_end() {fxt.Test_parse_page_all_str ("==a==" , "

        a

        \n");} + @Test public void Ws_end() { // PURPOSE: "==\n" merges all ws following it; \n\n\n is not transformed by Para_wkr to "
        " + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "==a== \t" + , "" + , "" + , "" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "b" + )); + } + @Test public void Many() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "==a==" + , "===b===" + ), String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "" + , "

        b

        " + , "" + )); + } + @Test public void Hdr_w_tblw() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "==a==" + , "{|" + , "|+" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "
        " + , " " + , "
        " + , "
        " + , "" + )); + } + @Test public void Hdr_w_hr() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "==a==" + , "----" + ), String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "
        " + )); + } + @Test public void Mix_apos_dangling() {fxt.Test_parse_page_wiki_str("==''a==" , "

        a

        \n");} + @Test public void Mix_xnde_dangling() {fxt.Test_parse_page_wiki_str("==a==" , "

        a

        \n");} + @Test public void Mix_tblw_cell() {fxt.Test_parse_page_wiki_str("==a!!==" , "

        a!!

        \n");} + @Test public void Ws() {fxt.Test_parse_page_wiki_str("== a b ==" , "

        a b

        \n");} + @Test public void Err_hdr() {fxt.Init_log_(Xop_hdr_log.Mismatched) .Test_parse_page_wiki_str("====a== ==" , "

        ==a==

        \n").tst_Log_check();} + @Test public void Err_end_hdr_is_1() {fxt.Init_log_(Xop_hdr_log.Mismatched, Xop_hdr_log.Len_1).Test_parse_page_wiki_str("==a=" , "

        =a

        \n").tst_Log_check();} + @Test public void Html_hdr_many() { + fxt.Wtr_cfg().Toc__show_(Bool_.Y); + fxt.Test_parse_page_wiki_str__esc(String_.Concat_lines_nl_skip_last + ( "==a==" + , "==a==" + , "==a==" + ), String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "" + , "

        a

        " + , "" + , "

        a

        " + , "" + )); + fxt.Wtr_cfg().Toc__show_(Bool_.N); + } + @Test public void Hdr_inside_dangling_tmpl_fix() { // PURPOSE: one-off fix to handle == inside dangling tmpl; DATE:2014-02-11 + fxt.Test_parse_page_all_str("{{a|}\n==b==" + , String_.Concat_lines_nl_skip_last + ( "{{a|}" + , "" + , "

        b

        " + , "" + )); + } + @Test public void Pfunc() {// multiple = should not be interpreted as key-val equals; PAGE:en.w:Wikipedia:Picture_of_the_day/June_2014 DATE:2014-07-21 + fxt.Test_parse_page_all_str + ( "{{#if:exists|==a==|no}}" + , String_.Concat_lines_nl_skip_last + ( "

        a

        " + , "" + )); + } +// @Test public void Hdr_inside_dangling_tmpl_fix_2() { // PURPOSE: hdr == inside dangling tmpl; DATE:2014-06-10 +// fxt.Init_defn_add("Print", "{{{1}}}"); +// fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last +// ( "=={{Print|b==" +// , "}}" +// ), String_.Concat_lines_nl_skip_last +// ( "==b=" +// , "" +// )); +// } +} diff --git a/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__para_tst.java b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__para_tst.java new file mode 100644 index 000000000..297f2bbf4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/hdrs/Xop_hdr_wkr__para_tst.java @@ -0,0 +1,24 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_hdr_wkr__para_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Hdr_at_bos() { // PURPOSE: check that BOS==a== does not throw null ref in para; DATE:2014-02-18 + fxt.Test_parse_page_all_str("==a==", "

        a

        \n"); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__merge__tst.java b/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__merge__tst.java new file mode 100644 index 000000000..a87220343 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__merge__tst.java @@ -0,0 +1,177 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.hdrs.sections; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.hdrs.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_section_list__merge__tst { + private final Xop_section_list__fxt fxt = new Xop_section_list__fxt(); + @Test public void Basic() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + , "" + , "== Hdr 3 ==" + , "Para 3" + ); + fxt.Test__merge_bry_or_null("Hdr_2", String_.Concat_lines_nl_skip_last + ( "== Hdr 2 ==" + , "Para 2a" + ), String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2a" + , "" + , "== Hdr 3 ==" + , "Para 3" + ) + ); + } + @Test public void Nl_many() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "" + , "" + , "== Hdr 2 ==" + , "Para 2" + , "" + , "" + , "" + , "== Hdr 3 ==" + , "Para 3" + ); + fxt.Test__merge_bry_or_null("Hdr_2", String_.Concat_lines_nl_skip_last + ( "== Hdr 2 ==" + , "Para 2a" + ), String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "" + , "" + , "== Hdr 2 ==" + , "Para 2a" + , "" + , "" + , "" + , "== Hdr 3 ==" + , "Para 3" + ) + ); + } + @Test public void Bos() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__merge_bry_or_null("Hdr_1", String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1a" + ), String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1a" + , "" + , "== Hdr 2 ==" + , "Para 2" + ) + ); + } + @Test public void Bos__ws() { + fxt.Exec__parse + ( "" + , "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__merge_bry_or_null("Hdr_1", String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1a" + ), String_.Concat_lines_nl_skip_last + ( "" + , "== Hdr 1 ==" + , "Para 1a" + , "" + , "== Hdr 2 ==" + , "Para 2" + ) + ); + } + @Test public void Eos() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__merge_bry_or_null("Hdr_2", String_.Concat_lines_nl_skip_last + ( "== Hdr 2 ==" + , "Para 2a" + ), String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2a" + ) + ); + } + @Test public void Lead() { + fxt.Exec__parse + ( "lead para" + , "" + , "== Hdr 1 ==" + , "Para 1" + ); + fxt.Test__merge_bry_or_null("", String_.Concat_lines_nl_skip_last + ( "lead para 1" + , "" + , "lead para 2" + ), String_.Concat_lines_nl_skip_last + ( "lead para 1" + , "" + , "lead para 2" + , "== Hdr 1 ==" + , "Para 1" + ) + ); + } + @Test public void Lead__new() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + ); + fxt.Test__merge_bry_or_null("", String_.Concat_lines_nl_skip_last + ( "lead para 1" + , "" + ), String_.Concat_lines_nl_skip_last + ( "lead para 1" + , "== Hdr 1 ==" + , "Para 1" + ) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__slice__tst.java b/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__slice__tst.java new file mode 100644 index 000000000..044d9d965 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/hdrs/sections/Xop_section_list__slice__tst.java @@ -0,0 +1,160 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.hdrs.sections; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.hdrs.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.htmls.core.htmls.tidy.*; +public class Xop_section_list__slice__tst { + private final Xop_section_list__fxt fxt = new Xop_section_list__fxt(); + @Test public void Basic() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + , "" + , "== Hdr 3 ==" + , "Para 3" + ); + fxt.Test__slice_bry_or_null("Hdr_1" + , "== Hdr 1 ==" + , "Para 1" + ); + fxt.Test__slice_bry_or_null("Hdr_2" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__slice_bry_or_null("Hdr_3" + , "== Hdr 3 ==" + , "Para 3" + ); + } + @Test public void Covering() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "=== Hdr 1a ===" + , "Para 1a" + , "" + , "=== Hdr 1b ===" + , "Para 1b" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__slice_bry_or_null("Hdr_1" + , "== Hdr 1 ==" + , "Para 1" + , "" + , "=== Hdr 1a ===" + , "Para 1a" + , "" + , "=== Hdr 1b ===" + , "Para 1b" + ); + } + @Test public void Xml() { + fxt.Exec__parse + ( "== Hdr 1 ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__slice_bry_or_null("Hdr_1", String_.Concat_lines_nl_skip_last + ( "== Hdr 1 ==" + , "Para 1" + )); + } + @Test public void Math() { + fxt.Exec__parse + ( "== \\delta ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__slice_bry_or_null(".5Cdelta", String_.Concat_lines_nl_skip_last + ( "== \\delta ==" + , "Para 1" + )); + } + @Test public void Template() { + fxt.Init__template("mock", "''{{{1}}}''"); + fxt.Exec__parse + ( "== {{mock|a}} ==" + , "Para 1" + , "" + , "== Hdr 2 ==" + , "Para 2" + ); + fxt.Test__slice_bry_or_null("a", String_.Concat_lines_nl_skip_last + ( "== {{mock|a}} ==" + , "Para 1" + )); + } + @Test public void Lead() { + fxt.Exec__parse + ( "lead text" + , "" + , "== Hdr 1 ==" + , "Para 1" + , "" + ); + fxt.Test__slice_bry_or_null("" + , "lead text" + ); + } + @Test public void Lead__none() { + fxt.Exec__parse + ( "" + , "== Hdr 1 ==" + , "Para 1" + , "" + ); + fxt.Test__slice_bry_or_null(""); + } + @Test public void Lead__eos() { + fxt.Exec__parse + ( "lead text" + , "" + , "para 1" + , "" + ); + fxt.Test__slice_bry_or_null("" + , "lead text" + , "" + , "para 1" + ); + } +} +class Xop_section_list__fxt { + private final Xop_section_list list = new Xop_section_list(); + private final Xop_fxt parser_fxt = new Xop_fxt(); + public void Init__template(String page, String text) {parser_fxt.Init_defn_add(page, text);} + public void Exec__parse(String... lines) { + list.Parse(parser_fxt.Wiki(), Xow_tidy_mgr_interface_.Noop, Bry_.new_u8(String_.Concat_lines_nl_skip_last(lines))); + } + public void Test__slice_bry_or_null(String key, String... lines) { + String expd = String_.Concat_lines_nl_skip_last(lines); + byte[] actl = list.Slice_bry_or_null(Bry_.new_u8(key)); + Gftest.Eq__ary__lines(expd, actl, key); + } + public void Test__merge_bry_or_null(String key, String edit, String expd) { + byte[] actl = list.Merge_bry_or_null(Bry_.new_u8(key), Bry_.new_u8(edit)); + Gftest.Eq__ary__lines(expd, actl, key); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_mgr_tst.java b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_mgr_tst.java new file mode 100644 index 000000000..2c28c0302 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_mgr_tst.java @@ -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.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Mwh_atr_mgr_tst { + private final Mwh_atr_mgr_fxt fxt = new Mwh_atr_mgr_fxt(); + @Test public void Atr_utl_make() { + // key="val" + fxt.Test_atr_utl_make(Mwh_atr_itm_.Qte_tid__qute, Mwh_atr_itm_.Mask__valid__y, Mwh_atr_itm_.Mask__repeated__n, Mwh_atr_itm_.Mask__key_exists__y, Mwh_atr_itm_.Mask__val_made__n, 42); + // key=val key=val + fxt.Test_atr_utl_make(Mwh_atr_itm_.Qte_tid__none, Mwh_atr_itm_.Mask__valid__y, Mwh_atr_itm_.Mask__repeated__y, Mwh_atr_itm_.Mask__key_exists__y, Mwh_atr_itm_.Mask__val_made__y, 120); + } +} +class Mwh_atr_mgr_fxt { + public void Test_atr_utl_make(int qte_tid, boolean valid, boolean repeated, boolean key_exists, boolean val_made, int expd) { + int atr_utl = Mwh_atr_itm_.Calc_atr_utl(qte_tid, valid, repeated, key_exists, val_made); + Tfds.Eq_int(expd, atr_utl); + Tfds.Eq_int(qte_tid, Mwh_atr_itm_.Calc_qte_tid(atr_utl)); + Tfds.Eq_bool(valid, (atr_utl & Mwh_atr_itm_.Mask__valid) == Mwh_atr_itm_.Mask__valid); + Tfds.Eq_bool(repeated, (atr_utl & Mwh_atr_itm_.Mask__repeated) == Mwh_atr_itm_.Mask__repeated); + Tfds.Eq_bool(key_exists, (atr_utl & Mwh_atr_itm_.Mask__key_exists) == Mwh_atr_itm_.Mask__key_exists); + Tfds.Eq_bool(val_made, (atr_utl & Mwh_atr_itm_.Mask__val_made) == Mwh_atr_itm_.Mask__val_made); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_fxt.java b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_fxt.java new file mode 100644 index 000000000..2dda3f80f --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_fxt.java @@ -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.xowa.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +class Mwh_atr_parser_fxt { + private final Bry_bfr expd_bfr = Bry_bfr_.New(), actl_bfr = Bry_bfr_.New(); + private final Mwh_atr_parser parser = new Mwh_atr_parser(); + private final Mwh_doc_wkr__atr_bldr wkr = new Mwh_doc_wkr__atr_bldr(); + public Mwh_atr_itm Make_pair(String key, String val) {return new Mwh_atr_itm(Bry_.Empty, Bool_.Y, Bool_.N, Bool_.Y, -1, -1, -1, -1, Bry_.new_u8(key) , -1, -1, Bry_.new_u8(val) , -1, -1);} + public Mwh_atr_itm Make_name(String key) {return new Mwh_atr_itm(Bry_.Empty, Bool_.Y, Bool_.N, Bool_.N, -1, -1, -1, -1, Bry_.new_u8(key) , -1, -1, Bry_.new_u8(key) , -1, -1);} + public Mwh_atr_itm Make_fail(int bgn, int end) {return new Mwh_atr_itm(Bry_.Empty, Bool_.N, Bool_.N, Bool_.N, bgn, end, -1, -1, null , -1, -1, null , -1, -1);} + public void Test_val_as_int(String raw, int expd) { + byte[] src = Bry_.new_u8(raw); + Mwh_atr_itm itm = new Mwh_atr_itm(src, true, false, false, 0, src.length, -1, -1, null, 0, src.length, src, -1, -1); + Tfds.Eq_int(expd, itm.Val_as_int_or(-1)); + } + public void Test_parse(String raw, Mwh_atr_itm... expd) { + Mwh_atr_itm[] actl = Exec_parse(raw); + Test_print(expd, actl); + } + private Mwh_atr_itm[] Exec_parse(String raw) { + byte[] bry = Bry_.new_u8(raw); + parser.Parse(wkr, -1, -1, bry, 0, bry.length); + return wkr.To_atr_ary(); + } + public void Test_print(Mwh_atr_itm[] expd_ary, Mwh_atr_itm[] actl_ary) { + int expd_len = expd_ary.length; + int actl_len = actl_ary.length; + int len = expd_len > actl_len ? expd_len : actl_len; + for (int i = 0; i < len; ++i) { + To_bfr(expd_bfr, i < expd_len ? expd_ary[i] : null, actl_bfr, i < actl_len ? actl_ary[i] : null); + } + Tfds.Eq_str_lines(expd_bfr.To_str_and_clear(), actl_bfr.To_str_and_clear()); + } + private void To_bfr(Bry_bfr expd_bfr, Mwh_atr_itm expd_itm, Bry_bfr actl_bfr, Mwh_atr_itm actl_itm) { + To_bfr__main(expd_bfr, expd_itm); + To_bfr__main(actl_bfr, actl_itm); + To_bfr__head(expd_bfr, expd_itm); + To_bfr__head(actl_bfr, actl_itm); + if (expd_itm != null && expd_itm.Atr_bgn() != -1) { + To_bfr__atr_rng(expd_bfr, expd_itm); + To_bfr__atr_rng(actl_bfr, actl_itm); + } + } + private void To_bfr__head(Bry_bfr bfr, Mwh_atr_itm itm) { + if (itm == null) return; + bfr.Add_str_a7("head:").Add_yn(itm.Valid()).Add_byte_semic().Add_yn(itm.Repeated()).Add_byte_semic().Add_yn(itm.Key_exists()).Add_byte_nl(); + } + private void To_bfr__main(Bry_bfr bfr, Mwh_atr_itm itm) { + if (itm == null) return; + if (itm.Valid()) { + bfr.Add_str_a7("key:").Add(itm.Key_bry()).Add_byte_nl(); + bfr.Add_str_a7("val:").Add(itm.Val_as_bry()).Add_byte_nl(); + } +// else +// To_bfr__atr_rng(bfr, itm); + } + private void To_bfr__atr_rng(Bry_bfr bfr, Mwh_atr_itm itm) { + if (itm == null) return; + bfr.Add_str_a7("rng:").Add_int_variable(itm.Atr_bgn()).Add_byte_semic().Add_int_variable(itm.Atr_end()).Add_byte_nl(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_tst.java b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_tst.java new file mode 100644 index 000000000..986202db9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_atr_parser_tst.java @@ -0,0 +1,76 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Mwh_atr_parser_tst { + private final Mwh_atr_parser_fxt fxt = new Mwh_atr_parser_fxt(); + @Test public void Pair__quote__double() {fxt.Test_parse("a=\"b\"" , fxt.Make_pair("a" , "b"));} + @Test public void Pair__quote__single() {fxt.Test_parse("a='b'" , fxt.Make_pair("a" , "b"));} + @Test public void Pair__quote__none() {fxt.Test_parse("a=b" , fxt.Make_pair("a" , "b"));} + @Test public void Pair__quote__none__amp() {fxt.Test_parse("a=&bc" , fxt.Make_pair("a" , "&bc"));} + @Test public void Pair__empty() {fxt.Test_parse("a=''" , fxt.Make_pair("a" , ""));} + @Test public void Pair__key_w_underline() {fxt.Test_parse("a_b=c" , fxt.Make_pair("a_b" , "c"));} + + @Test public void Name__quote__none() {fxt.Test_parse("b" , fxt.Make_name("b"));} + @Test public void Name__ws() {fxt.Test_parse(" b " , fxt.Make_name("b"));} // PURPOSE:discovered while writing test for ref's "lower-alpha" DATE:2014-07-03 + @Test public void Name__mult() {fxt.Test_parse("a b1 c" , fxt.Make_name("a"), fxt.Make_name("b1"), fxt.Make_name("c"));} + + @Test public void Fail__key_w_plus() {fxt.Test_parse("a+b" , fxt.Make_fail(0, 3));} + @Test public void Fail__key_w_plus__many() {fxt.Test_parse("a+b c=d" , fxt.Make_fail(0, 3) , fxt.Make_pair("c", "d"));} + @Test public void Fail__val_w_plus() {fxt.Test_parse("a=b+c" , fxt.Make_fail(0, 5));} + @Test public void Fail__recover() {fxt.Test_parse("* a=b" , fxt.Make_fail(0, 1) , fxt.Make_pair("a", "b"));} // PURPOSE: * is invalid, but should not stop parsing of a=b + @Test public void Fail__incomplete() {fxt.Test_parse("a= c=d" , fxt.Make_fail(0, 3) , fxt.Make_pair("c", "d"));} // PURPOSE: discard xatr if incomplete and followed by valid atr; PAGE:en.w:2013_in_American_television DATE:2014-09-25 + @Test public void Fail__incomplete_2() {fxt.Test_parse("a=c=d" , fxt.Make_fail(0, 5));} // PURPOSE: variation of above; per MW regex, missing space invalidates entire attribute; DATE:2014-09-25 + @Test public void Fail__incomplete_pair() {fxt.Test_parse("a= b=" , fxt.Make_fail(0, 3) , fxt.Make_fail(3, 5));} // PURPOSE: "b=" should be invalid not a kv of "b" = "b"; PAGE:en.s:Notes_by_the_Way/Chapter_2; DATE:2015-01-31 + + @Test public void Dangling_eos() {fxt.Test_parse("a='b' c='d" , fxt.Make_pair("a", "b") , fxt.Make_fail(5, 10));} // PURPOSE: handle dangling quote at eos; PAGE:en.w:Aubervilliers DATE:2014-06-25 + @Test public void Dangling_bos() {fxt.Test_parse("a='b c=d" , fxt.Make_fail(0, 4) , fxt.Make_pair("c", "d"));}// PURPOSE: handle dangling quote at bos; resume at next valid atr; PAGE:en.w:Aubervilliers DATE:2014-06-25 + + @Test public void Ws__ini() {fxt.Test_parse(" a='b'" , fxt.Make_pair("a", "b").Atr_rng(0, 6));} + @Test public void Ws__end() {fxt.Test_parse(" a='b' c='d'" , fxt.Make_pair("a", "b").Atr_rng(0, 6), fxt.Make_pair("c", "d").Atr_rng(6, 12));} + @Test public void Ws() {fxt.Test_parse("a = 'b'" , fxt.Make_pair("a", "b"));} // PURPOSE: fix wherein multiple space was causing "a=a"; PAGE:fr.s:La_Sculpture_dans_les_cimetières_de_Paris/Père-Lachaise; DATE:2014-01-18 + + @Test public void Many__quote__apos() {fxt.Test_parse("a='b' c='d' e='f'" , fxt.Make_pair("a", "b"), fxt.Make_pair("c", "d"), fxt.Make_pair("e", "f"));} + @Test public void Many__naked() {fxt.Test_parse("a=b c=d e=f" , fxt.Make_pair("a", "b"), fxt.Make_pair("c", "d"), fxt.Make_pair("e", "f"));} + @Test public void Many__naked__pair() {fxt.Test_parse("a b=c" , fxt.Make_name("a"), fxt.Make_pair("b", "c"));} + + @Test public void Quote__ws__nl() {fxt.Test_parse("a='b\nc'" , fxt.Make_pair("a", "b c"));} + @Test public void Quote__ws__mult() {fxt.Test_parse("a='b c'" , fxt.Make_pair("a", "b c"));} + @Test public void Quote__ws__mult_mult() {fxt.Test_parse("a='b c d'" , fxt.Make_pair("a", "b c d"));} // PURPOSE: fix wherein 1st-gobble gobbled rest of spaces (was b cd) + @Test public void Quote__apos() {fxt.Test_parse("a=\"b c'd\"" , fxt.Make_pair("a", "b c'd"));} // PURPOSE: fix wherein apos was gobbled up; PAGE:en.s:Alice's_Adventures_in_Wonderland; DATE:2013-11-22 + @Test public void Quote__apos_2() {fxt.Test_parse("a=\"b'c d\"" , fxt.Make_pair("a", "b'c d"));} // PURPOSE: fix wherein apos was causing "'b'c d"; PAGE:en.s:Grimm's_Household_Tales,_Volume_1; DATE:2013-12-22 +// @Test public void Quote__angle() {fxt.Test_parse("a='<'" , fxt.Make_fail(0, 5));} // PURPOSE: "<" inside quotes is always invalid + @Test public void Quote__invalid() {fxt.Test_parse("a='b'c" , fxt.Make_fail(0, 6));} + + @Test public void Nowiki__atr() {fxt.Test_parse("a=b" , fxt.Make_pair("a", "b").Atr_rng(8, 20));} + @Test public void Nowiki__key() {fxt.Test_parse("abc=d" , fxt.Make_pair("abc", "d").Atr_rng(0, 22));} + @Test public void Nowiki__eql() {fxt.Test_parse("a=\"b\"" , fxt.Make_pair("a", "b").Atr_rng(0, 22));} // EX:fr.w:{{Portail|Transpédia|Californie}} + @Test public void Nowiki__val__naked() {fxt.Test_parse("a=bcd" , fxt.Make_pair("a", "bcd").Atr_rng(0, 22));} + @Test public void Nowiki__val__quote() {fxt.Test_parse("a='b'" , fxt.Make_pair("a", "b").Atr_rng(0, 22));} + @Test public void Nowiki__val__quote_2() {fxt.Test_parse("a=\"bcdef\"", fxt.Make_pair("a", "bcdef"));} + + @Test public void Val__as_int() {fxt.Test_val_as_int("-123" , -123);} + +// @Test public void Embedded() { // PURPOSE: handle html inside attrib; PAGE:en.w:Economy_of_Greece DATE:2015-10-15 +// fxt.Test_parse("title='[1] c'" +// , fxt.Make_fail(0, 11) // "title='[1]" invalid b/c no ws after ' +// , fxt.Make_fail(89, 91) // " c'" invalid b/c name (c) cannot have apos +// ); +// } +} diff --git a/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_fxt.java b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_fxt.java new file mode 100644 index 000000000..ba2036eaf --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_fxt.java @@ -0,0 +1,73 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +class Mwh_doc_parser_fxt { + private final Bry_bfr expd_bfr = Bry_bfr_.New(), actl_bfr = Bry_bfr_.New(); + private final Mwh_doc_parser parser = new Mwh_doc_parser(); + private final Mwh_doc_wkr__itm_bldr wkr = new Mwh_doc_wkr__itm_bldr(); + public Mwh_doc_itm Make_txt (String raw) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__txt , -1, Bry_.new_u8(raw));} + public Mwh_doc_itm Make_txt (String raw, int nde_tid) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__txt , nde_tid, Bry_.new_u8(raw));} + public Mwh_doc_itm Make_comment (String raw) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__comment , -1, Bry_.new_u8(raw));} + public Mwh_doc_itm Make_entity (String raw) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__entity , -1, Bry_.new_u8(raw));} + public Mwh_doc_itm Make_nde_head(String raw) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__nde_head , -1, Bry_.new_u8(raw));} + public Mwh_doc_itm Make_nde_tail(String raw) {return new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__nde_tail , -1, Bry_.new_u8(raw));} + public void Test_parse(String raw, Mwh_doc_itm... expd) { + Mwh_doc_itm[] actl = Exec_parse(raw); + Test_print(expd, actl); + } + public Mwh_doc_itm[] Exec_parse(String raw) { + byte[] bry = Bry_.new_u8(raw); + parser.Parse(wkr, bry, 0, bry.length); + return wkr.To_atr_ary(); + } + public void Test_print(Mwh_doc_itm[] expd_ary, Mwh_doc_itm[] actl_ary) { + int expd_len = expd_ary.length; + int actl_len = actl_ary.length; + int len = expd_len > actl_len ? expd_len : actl_len; + for (int i = 0; i < len; ++i) { + To_bfr(expd_bfr, i < expd_len ? expd_ary[i] : null, actl_bfr, i < actl_len ? actl_ary[i] : null); + } + Tfds.Eq_str_lines(expd_bfr.To_str_and_clear(), actl_bfr.To_str_and_clear()); + } + private void To_bfr(Bry_bfr expd_bfr, Mwh_doc_itm expd_itm, Bry_bfr actl_bfr, Mwh_doc_itm actl_itm) { + To_bfr__main(expd_bfr, expd_itm); To_bfr__main(actl_bfr, actl_itm); + if (expd_itm != null && expd_itm.Nde_tid() != -1) { + To_bfr__nde_tid(expd_bfr, expd_itm); To_bfr__nde_tid(actl_bfr, actl_itm); + } + } + private void To_bfr__main(Bry_bfr bfr, Mwh_doc_itm itm) { + if (itm == null) return; + bfr.Add_str_a7("itm_tid:").Add_int_variable(itm.Itm_tid()).Add_byte_nl(); + bfr.Add_str_a7("txt:").Add(itm.Itm_bry()).Add_byte_nl(); + } + private void To_bfr__nde_tid(Bry_bfr bfr, Mwh_doc_itm itm) { + if (itm == null) return; + bfr.Add_str_a7("nde_tid:").Add_int_variable(itm.Nde_tid()).Add_byte_nl(); + } +} +class Mwh_doc_wkr__itm_bldr implements Mwh_doc_wkr { + private final List_adp list = List_adp_.New(); + public Hash_adp_bry Nde_regy() {return nde_regy;} private final Hash_adp_bry nde_regy = Mwh_doc_wkr_.Nde_regy__mw(); + public void On_atr_each (Mwh_atr_parser mgr, byte[] src, int nde_tid, boolean valid, boolean repeated, boolean key_exists, byte[] key_bry, byte[] val_bry_manual, int[] itm_ary, int itm_idx) {} + public void On_txt_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end) {list.Add(new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__txt , nde_tid, Bry_.Mid(src, itm_bgn, itm_end)));} + public void On_nde_head_bgn (Mwh_doc_parser mgr, byte[] src, int nde_tid, int key_bgn, int key_end) {} + public void On_nde_head_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end, boolean inline) {list.Add(new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__nde_head , nde_tid, Bry_.Mid(src, itm_bgn, itm_end)));} + public void On_nde_tail_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end) {list.Add(new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__nde_tail , nde_tid, Bry_.Mid(src, itm_bgn, itm_end)));} + public void On_comment_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end) {list.Add(new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__comment , nde_tid, Bry_.Mid(src, itm_bgn, itm_end)));} + public void On_entity_end (Mwh_doc_parser mgr, byte[] src, int nde_tid, int itm_bgn, int itm_end) {list.Add(new Mwh_doc_itm(Mwh_doc_itm.Itm_tid__entity , nde_tid, Bry_.Mid(src, itm_bgn, itm_end)));} + + public Mwh_doc_itm[] To_atr_ary() {return (Mwh_doc_itm[])list.To_ary_and_clear(Mwh_doc_itm.class);} +} diff --git a/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_tst.java b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_tst.java new file mode 100644 index 000000000..4ceb6a3ef --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/htmls/Mwh_doc_parser_tst.java @@ -0,0 +1,59 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.xndes.*; +public class Mwh_doc_parser_tst { + private final Mwh_doc_parser_fxt fxt = new Mwh_doc_parser_fxt(); + @Test public void Text__basic() {fxt.Test_parse("abc" , fxt.Make_txt("abc"));} + @Test public void Comment() {fxt.Test_parse("ac" , fxt.Make_txt("a"), fxt.Make_comment(""), fxt.Make_txt("c"));} + @Test public void Entity() {fxt.Test_parse("a b" , fxt.Make_txt("a"), fxt.Make_entity(" "), fxt.Make_txt("b"));} + @Test public void Fail__inline_eos() {fxt.Test_parse("ad" , fxt.Make_txt("ad"));} + @Test public void Node__inline() {fxt.Test_parse("ac" , fxt.Make_txt("a"), fxt.Make_nde_head("") , fxt.Make_txt("c"));} + @Test public void Node__pair() {fxt.Test_parse("acd" , fxt.Make_txt("a"), fxt.Make_nde_head("") , fxt.Make_txt("c"), fxt.Make_nde_tail(""), fxt.Make_txt("d"));} + @Test public void Atrs__pair() { + fxt.Test_parse("
        a
        " + , fxt.Make_nde_head("
        ") + , fxt.Make_txt("a") + , fxt.Make_nde_tail("
        ")); + } + @Test public void Atrs__inline() { + fxt.Test_parse("a
        b" + , fxt.Make_txt("a") + , fxt.Make_nde_head("
        ") + , fxt.Make_txt("b")); + } + @Test public void Node__single_only() { + fxt.Test_parse("a
        b
        c" + , fxt.Make_nde_head("") + , fxt.Make_txt("a", Xop_xnde_tag_.Tid__b) + , fxt.Make_nde_head("
        ") + , fxt.Make_txt("b", Xop_xnde_tag_.Tid__b) // not
        + , fxt.Make_nde_tail("
        ") + , fxt.Make_txt("c", Xop_xnde_tag_.Tid__null) + ); + } + @Test public void Node__pre() { + fxt.Test_parse("
        a
        b
        c" + , fxt.Make_nde_head("
        ")
        +		, fxt.Make_txt("a", Xop_xnde_tag_.Tid__pre)
        +		, fxt.Make_nde_head("
        ") + , fxt.Make_txt("b", Xop_xnde_tag_.Tid__pre) //
         not 
        + , fxt.Make_nde_tail("
        ") + , fxt.Make_txt("c", Xop_xnde_tag_.Tid__null) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java b/400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java new file mode 100644 index 000000000..b48625915 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lists/HierPosAryBldr_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class HierPosAryBldr_tst { + @Before public void init() {bldr.Init();} HierPosAryBldr bldr = new HierPosAryBldr(256); + @Test public void Basic() { + tst_ary(Int_ary_.Empty); + } + @Test public void Move_d() { + bldr.MoveDown(); + tst_ary(0); + } + @Test public void Move_dd() { + bldr.MoveDown(); + bldr.MoveDown(); + tst_ary(0, 0); + } + @Test public void Move_ddu() { + bldr.MoveDown(); + bldr.MoveDown(); + bldr.MoveUp(); + tst_ary(1); + } + @Test public void Move_ddud() { + bldr.MoveDown(); + bldr.MoveDown(); + bldr.MoveUp(); + bldr.MoveDown(); + tst_ary(1, 0); + } + @Test public void Move_dud() { + bldr.MoveDown(); + bldr.MoveUp(); + bldr.MoveDown(); + tst_ary(1); + } + @Test public void Move_dn() { + bldr.MoveDown(); + bldr.MoveNext(); + tst_ary(1); + } + @Test public void Move_ddn() { + bldr.MoveDown(); + bldr.MoveDown(); + bldr.MoveNext(); + tst_ary(0, 1); + } + private void tst_ary(int... expd) {Tfds.Eq_ary(expd, bldr.XtoIntAry());} +} diff --git a/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_basic_tst.java b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_basic_tst.java new file mode 100644 index 000000000..73aa480a4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_basic_tst.java @@ -0,0 +1,351 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_list_wkr_basic_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void List_1() { + fxt.Test_parse_page_wiki("\n*a" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_end_(3).List_path_(0).List_uid_(0) + ); + } + @Test public void Bos() { + fxt.Test_parse_page_wiki("*a" + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(1, 2) + , fxt.tkn_list_end_(2).List_path_(0).List_uid_(0) + ); + } + @Test public void List_1_2() { + fxt.Test_parse_page_wiki("\n*a\n**b" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_end_(7).List_path_(0, 0) + , fxt.tkn_list_end_(7).List_path_(0) + ); + } + @Test public void List_1_2_2() { + fxt.Test_parse_page_wiki("\n*a\n**b\n**c" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_end_(7).List_path_(0, 0) + , fxt.tkn_list_bgn_(7, 10, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 1).List_uid_(0) + , fxt.tkn_txt_(10, 11) + , fxt.tkn_list_end_(11).List_path_(0, 1) + , fxt.tkn_list_end_(11).List_path_(0) + ); + } + @Test public void List_1_2_3() { + fxt.Test_parse_page_wiki("\n*a\n**b\n***c" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_bgn_(7, 11, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0, 0).List_uid_(0) + , fxt.tkn_txt_(11, 12) + , fxt.tkn_list_end_(12).List_path_(0, 0, 0) + , fxt.tkn_list_end_(12).List_path_(0, 0) + , fxt.tkn_list_end_(12).List_path_(0) + ); + } + @Test public void List_2() { + fxt.Test_parse_page_wiki("\n**a" + , fxt.tkn_list_bgn_(0, 3, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(0, 3, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(3, 4) + , fxt.tkn_list_end_(4).List_path_(0, 0) + , fxt.tkn_list_end_(4).List_path_(0) + ); + } + @Test public void List_1_3() { + fxt.Test_parse_page_wiki("\n*a\n***b" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 7, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_list_bgn_(3, 7, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0, 0).List_uid_(0) + , fxt.tkn_txt_(7, 8) + , fxt.tkn_list_end_(8).List_path_(0, 0, 0) + , fxt.tkn_list_end_(8).List_path_(0, 0) + , fxt.tkn_list_end_(8).List_path_(0) + ); + } + @Test public void List_1_2_1() { + fxt.Test_parse_page_wiki("\n*a\n**b\n*c" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_end_(7).List_path_(0, 0) + , fxt.tkn_list_end_(7).List_path_(0) + , fxt.tkn_list_bgn_(7, 9, Xop_list_tkn_.List_itmTyp_ul).List_path_(1).List_uid_(0) + , fxt.tkn_txt_(9, 10) + , fxt.tkn_list_end_(10).List_path_(1) + ); + } + @Test public void List_1_1_1() { + fxt.Test_parse_page_wiki("\n*a\n*b\n*c" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_end_(3).List_path_(0) + , fxt.tkn_list_bgn_(3, 5, Xop_list_tkn_.List_itmTyp_ul).List_path_(1).List_uid_(0) + , fxt.tkn_txt_(5, 6) + , fxt.tkn_list_end_(6).List_path_(1) + , fxt.tkn_list_bgn_(6, 8, Xop_list_tkn_.List_itmTyp_ul).List_path_(2).List_uid_(0) + , fxt.tkn_txt_(8, 9) + , fxt.tkn_list_end_(9).List_path_(2) + ); + } + @Test public void List_1___1() { + fxt.Test_parse_page_wiki("\n*a\n\n*b" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_end_(3).List_path_(0) + , fxt.tkn_nl_char_len1_(3) + , fxt.tkn_list_bgn_(4, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(1) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_end_(7).List_path_(0) + ); + } + @Test public void List_1_3_1() { + fxt.Test_parse_page_wiki("\n*a\n***b\n*c" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_bgn_(3, 7, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_list_bgn_(3, 7, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0, 0).List_uid_(0) + , fxt.tkn_txt_(7, 8) + , fxt.tkn_list_end_(8).List_path_(0, 0, 0) + , fxt.tkn_list_end_(8).List_path_(0, 0) + , fxt.tkn_list_end_(8).List_path_(0) + , fxt.tkn_list_bgn_(8, 10, Xop_list_tkn_.List_itmTyp_ul).List_path_(1).List_uid_(0) + , fxt.tkn_txt_(10, 11) + , fxt.tkn_list_end_(11).List_path_(1) + ); + } + @Test public void Mix_2o_2u() { + fxt.Test_parse_page_wiki("\n**a\n##b" + , fxt.tkn_list_bgn_(0, 3, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(0, 3, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(3, 4) + , fxt.tkn_list_end_(4).List_path_(0, 0) + , fxt.tkn_list_end_(4).List_path_(0) + , fxt.tkn_list_bgn_(4, 7, Xop_list_tkn_.List_itmTyp_ol).List_path_(0).List_uid_(1) + , fxt.tkn_list_bgn_(4, 7, Xop_list_tkn_.List_itmTyp_ol).List_path_(0, 0).List_uid_(1) + , fxt.tkn_txt_(7, 8) + , fxt.tkn_list_end_(8).List_path_(0, 0) + , fxt.tkn_list_end_(8).List_path_(0) + ); + } + @Test public void Dt_dd() { + fxt.Test_parse_page_wiki(";a\n:b" + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_dt).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(1, 2) + , fxt.tkn_list_end_(2).List_path_(0) + , fxt.tkn_list_bgn_(2, 4, Xop_list_tkn_.List_itmTyp_dd).List_path_(1).List_uid_(0) + , fxt.tkn_txt_(4, 5) + , fxt.tkn_list_end_(5).List_path_(1) + ); + } + @Test public void Dt_dd_inline() { + fxt.Test_parse_page_wiki(";a:b" // NOTE: no line break + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_dt).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(1, 2) + , fxt.tkn_list_end_(2).List_path_(0) + , fxt.tkn_list_bgn_(2, 3, Xop_list_tkn_.List_itmTyp_dd).List_path_(1).List_uid_(0) + , fxt.tkn_txt_(3, 4) + , fxt.tkn_list_end_(4).List_path_(1) + ); + } + @Test public void Mix_1dd_1ul() { + fxt.Test_parse_page_wiki(":*a" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_dd).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_end_(3).List_path_(0, 0) + , fxt.tkn_list_end_(3).List_path_(0) + ); + } + @Test public void Mix_1ul__1dd_1ul() { + fxt.Test_parse_page_wiki("*a\n:*b" + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_ul).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(1, 2) + , fxt.tkn_list_end_(2).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(2, 5, Xop_list_tkn_.List_itmTyp_dd).List_path_(0).List_uid_(1) + , fxt.tkn_list_bgn_(2, 5, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(1) + , fxt.tkn_txt_(5, 6) + , fxt.tkn_list_end_(6).List_path_(0, 0) + , fxt.tkn_list_end_(6).List_path_(0) + ); + } + @Test public void Mix_1dd_1ul__1dd_1ul() { + fxt.Test_parse_page_wiki(":*a\n:*b" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_dd).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 0).List_uid_(0) + , fxt.tkn_txt_(2, 3) + , fxt.tkn_list_end_(3).List_path_(0, 0) + , fxt.tkn_list_bgn_(3, 6, Xop_list_tkn_.List_itmTyp_ul).List_path_(0, 1).List_uid_(0) + , fxt.tkn_txt_(6, 7) + , fxt.tkn_list_end_(7).List_path_(0, 1) + , fxt.tkn_list_end_(7).List_path_(0) + ); + } + @Test public void Mix_1ul_1hdr() { + fxt.Test_parse_page_wiki_str("*a\n==a==\n", String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + , "

        a

        " + )); + } + @Test public void Mix_1ul_1hdr_1ul() { + fxt.Test_parse_page_wiki_str("*a\n==a==\n*b", String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + , "

        a

        " + , "" + , "
          " + , "
        • b" + , "
        • " + , "
        " + )); + } + @Test public void Mix_1ol_1hr_1ol() { + fxt.Test_parse_page_wiki("#a\n----\n#b" + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_ol).List_path_(0).List_uid_(0) + , fxt.tkn_txt_(1, 2) + , fxt.tkn_list_end_(2) + , fxt.tkn_para_blank_(2) + , fxt.tkn_hr_(2, 7) + , fxt.tkn_list_bgn_(7, 9, Xop_list_tkn_.List_itmTyp_ol).List_path_(0).List_uid_(1) + , fxt.tkn_txt_(9, 10) + , fxt.tkn_list_end_(10) + ); + } + @Test public void Mix_tblw() { + fxt.Test_parse_page_wiki("::{|\n|a\n|}" + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_dd).List_path_(0).List_uid_(0) + , fxt.tkn_list_bgn_(0, 2, Xop_list_tkn_.List_itmTyp_dd).List_path_(0, 0).List_uid_(0) + , fxt.tkn_tblw_tb_(2, 10).Subs_ + ( fxt.tkn_tblw_tr_(4, 7).Subs_ + ( fxt.tkn_tblw_td_(4, 7).Subs_(fxt.tkn_txt_(6, 7), fxt.tkn_para_blank_(8))) + + ) + , fxt.tkn_list_end_(10).List_path_(0, 0) + , fxt.tkn_list_end_(10).List_path_(0) + ); + } + @Test public void Mix_tblw_w_space() { + fxt.Test_html_full_str(": {|\n|a\n|}", String_.Concat_lines_nl_skip_last + ( "
        " + , "
        " + , " " + , " " + , " " + , " " + , "
        a" + , "
        " + , "
        " + , "
        " + )); + } + @Test public void Dif_lvls_1_3_1() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*1" + , "***3" + , "*1" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • 1" + , "
            " + , "
          • " + , "
              " + , "
            • 3" + , "
            • " + , "
            " + , "
          • " + , "
          " + , "
        • " + , "
        • 1" + , "
        • " + , "
        " + )); + } + @Test public void Dif_lvls_1_3_2() {// uneven lists + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*1" + , "***3" + , "**2" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • 1" + , "
            " + , "
          • " + , "
              " + , "
            • 3" + , "
            • " + , "
            " + , "
          • " + , "
          • 2" + , "
          • " + , "
          " + , "
        • " + , "
        " + )); + } + @Test public void New_lines() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "" + , "**b" + , "" + , "**c" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + , "
          " + , "
        • " + , "
            " + , "
          • b" + , "
          • " + , "
          " + , "
        • " + , "
        " + , "" + , "
          " + , "
        • " + , "
            " + , "
          • c" + , "
          • " + , "
          " + , "
        • " + , "
        " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_para_tst.java b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_para_tst.java new file mode 100644 index 000000000..be255be17 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_para_tst.java @@ -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.xowa.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_list_wkr_para_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Basic() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*a" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + ) + ); + } + @Test public void Multiple() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "*b" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        • b" + , "
        • " + , "
        " + ) + ); + } + @Test public void Multiple_w_1_nl() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "" + , "*b" + ) , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + , "
          " + , "
        • b" + , "
        • " + , "
        " + ) + ); + } + @Test public void Pre_between_lists() { // PURPOSE: list should close pre; EX:en.b:Knowing Knoppix/Other applications; DATE:2014-02-18 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "#a" + , " b" + , "#c" // should close
         opened by b
        +			) ,	String_.Concat_lines_nl_skip_last
        +			(	"
          " + , "
        1. a" + , "
        2. " + , "
        " + , "" + , "
        b"
        +			,	"
        " + , "" + , "
          " + , "
        1. c" + , "
        2. " + , "
        " + ) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_uncommon_tst.java b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_uncommon_tst.java new file mode 100644 index 000000000..b57c6d67d --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lists/Xop_list_wkr_uncommon_tst.java @@ -0,0 +1,407 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_list_wkr_uncommon_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Bug_specified_div() { // FIX:
        was not clearing state for lnki; PAGE:en.w:Ananke (moon) + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "
        " + , "#a" + , "
        " + , "*b" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
          " + , "
        1. a" + , "" + , "
        2. " + , "
        " + , "
          " + , "
        • b" + , "
        • " + , "
        " + )); + } + @Test public void Bug_mismatched() { // FIX:
        was not clearing state for lnki; PAGE:en.w:Ananke (moon) + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "::a" + , ":::1" + , "::::11" + , ":::::111" + , "::b" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        " + , "
        " + , "
        a" + , "
        " + , "
        1" + , "
        " + , "
        11" + , "
        " + , "
        111" + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "
        b" + , "
        " + , "
        " + , "
        " + , "
        " + )); + } + @Test public void Empty_li_ignored() { // PURPOSE: inner template can cause dupe li; PAGE:en.w:any Calendar day and NYT link; NOTE:deactivated prune_empty_list logic; DATE:2014-09-05 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "* " + , "*b" + , "*c" + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        • " + , "
        • " + , "
        • b" + , "
        • " + , "
        • c" + , "
        • " + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void List_in_tblw() { // PURPOSE: list inside table should not be close outer list; PAGE:en.w:Cato the Elder + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "{|" + , "|b" + , "::c" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        " + , "" + , " " + , " " + , " " + , "
        b" + , "" + , "
        " + , "
        " + , "
        " + , "
        c" + , "
        " + , "
        " + , "
        " + , "
        " + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Dt_dd_colon_at_eol() { // PURPOSE: dangling ":" should not put next line in
        ; PAGE:en.w:Stein; b was being wrapped in
        b
        ; NOTE:deactivated prune_empty_list logic; DATE:2014-09-05 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( ";a:" + , "*b" + , "" + , ";c" + , "*d" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        a" + , "
        " + , "
        " + , "
        " + , "
        " + , "
          " + , "
        • b" + , "
        • " + , "
        " + , "" + , "
        " + , "
        c" + , "
        " + , "
        " + , "
          " + , "
        • d" + , "
        • " + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Dd_should_not_print_colon() {// PURPOSE: ;a:\n should show as ";a" not ";a:". colon should still be considered as part of empty list; DATE:2013-11-07; NOTE:deactivated prune_empty_list logic; DATE:2014-09-05 + fxt.Test_parse_page_all_str + ( ";a:\nb" + , String_.Concat_lines_nl_skip_last + ( "
        " + , "
        a" + , "
        " + , "
        " + , "
        " + , "
        " + , "b" + )); + } + @Test public void Dt_dd_colon_in_lnki() { // PURPOSE: "; [[Portal:a]]" should not split lnki; PAGE:en.w:Wikipedia:WikiProject Military history/Operation Majestic Titan; "; [[Wikipedia:WikiProject Military history/Operation Majestic Titan/Phase I|Phase I]]: a b" + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( ";[[Portal:a]]" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        Portal:A" + , "
        " + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Max_list_depth() { // PURPOSE: 256+ * caused list parser to fail; ignore; PAGE:en.w:Bariatric surgery + String multiple = String_.Repeat("*", 300); + fxt.Test_parse_page_all_str(multiple, multiple); + } + @Test public void Numbered_list_resets_incorrectly() { // PURPOSE: as description + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "#A" + , "#*Aa" + , "#**Aaa" + , "#*Ab" + , "#B" + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        1. A" + , "" + , "
            " + , "
          • Aa" + , "" + , "
              " + , "
            • Aaa" + , "
            • " + , "
            " + , "
          • " + , "
          • Ab" + , "
          • " + , "
          " // was showing as
        + , " " + , "
      • B" + , "
      • " + , "" + , "" + )); + fxt.Init_para_n_(); + } + @Test public void List_should_not_end_indented_table() {// PURPOSE: :{| was being closed by \n*; EX:w:Maxwell's equations; DATE:20121231 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( ":{|" + , "|-" + , "|" + , "*a" + , "|b" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        " + , " " + , " " + , " " + , " " + , " " + , "
        " + , "
          " + , "
        • a" + , "
        • " + , "
        " + , "
        b" + , "
        " + , "
        " + , "
        " + )); + } + @Test public void Dt_dd_broken_by_xnde() { // PURPOSE.fix: xnde was resetting dl incorrectly; EX:w:Virus; DATE:2013-01-31 + fxt.Test_parse_page_all_str(";a:c" + , String_.Concat_lines_nl_skip_last + ( "
        " + , "
        a" + , "
        " + , "
        c" + , "
        " + , "
        " + )); + } + @Test public void Trim_empty_list_items() { // PURPOSE: empty list items should be ignored; DATE:2013-07-02; NOTE:deactivated prune_empty_list logic; DATE:2014-09-05 + fxt.Test_parse_page_all_str + ("*** \n" + , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • " + , "
            " + , "
          • " + , "
              " + , "
            • " + , "
            • " + , "
            " + , "
          • " + , "
          " + , "
        • " + , "
        " + , "" + )); + } + @Test public void Trim_empty_list_items_error() { // PURPOSE.fix: do not add empty itm's nesting to current list; DATE:2013-07-07; NOTE:deactivated prune_empty_list logic; DATE:2014-09-05 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "* a" + , "** " // was: do not add ** to nest; now: add ** and \s + , "*** b" + , "* c" + ), String_.Concat_lines_nl + ( "
          " + , "
        • a" + , "
            " + , "
          • " + , "
              " + , "
            • b" + , "
            • " + , "
            " + , "
          • " + , "
          " + , "
        • " + , "
        • c" + , "
        • " + , "
        " + )); + } + @Test public void Tblw_should_autoclose() {// PURPOSE: tblw should auto-close open list + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "#a" + , "{|" + , "|b" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        1. a" + , "
        2. " + , "
        " + , "" + , " " + , " " + , " " + , "
        b" + , "
        " + , "" + )); + } + @Test public void Tblx_should_not_autoclose() { // PURPOSE: do not auto-close list if table is xnde; DATE:2014-02-05 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "#a" + , "#
        b
        " + , "c" + ), String_.Concat_lines_nl + ( "
          " + , "
        1. a" + , "
        2. " + , "
        3. " + , " " + , " " + , " " + , " " + , "
          b" + , "
          " + , "
        4. " + , "
        " + , "c" + )); + } + @Test public void Li_disappears() { // PURPOSE: "\n*" disappears when followed by "
      • "; PAGE:en.w:Bristol_Bullfinch; DATE:2014-06-24 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "*b
      • " + ), String_.Concat_lines_nl_skip_last // NOTE: tag sequence matches MW output + ( "a" + , "
          " + , "
        • b" + , "
        • " + , "
        • " + , " " + , "
        " + )); + } + @Test public void Ul_should_end_wlst() { // PURPOSE:
      should end wiki_list; PAGE:en.w:Bristol_Bullfinch; DATE:2014-06-24 + fxt.Test_parse_page_all_str + ( "*ab" + , String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a
      b" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + , " " + , "" + )); + } + @Test public void Colon_causes_dd() { // PURPOSE: colon was mistakenly being ignored due to proximity to "\n;"; PAGE:de.w:Schmach_von_Tirana#Kuriosit.C3.A4t:_EM-Qualifikationsspiel_vom_20._November_1983 DATE:2014-07-11 + fxt.Test_parse_page_all_str + ( String_.Concat_lines_nl_skip_last + ( "a:b" + , ";c" + ), String_.Concat_lines_nl_skip_last + ( "a:b" + , "
      " + , "
      c" + , "
      " + , "
      " + )); + } + @Test public void Pre_and_nested() { // PURPOSE: pre should interrupt list; PAGE:fi.w:Luettelo_hyönteisistä; DATE:2015-03-31 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str + ( String_.Concat_lines_nl_skip_last + ( "*a" + , "**b" + , " c" // pre + , "*d" // *d treated mistakenly as **d + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a" + , "" + , "
          " + , "
        • b" + , "
        • " + , "
        " + , "
      • " + , "
      " + , "" + , "
      c"
      +		, "
      " + , "" + , "
        " + , "
      • d" + , "
      • " + , "
      " + , "" + )); + fxt.Init_para_n_(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_brack_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_brack_tst.java new file mode 100644 index 000000000..19d882d72 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_brack_tst.java @@ -0,0 +1,92 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.xndes.*; +public class Xop_lnke_wkr_brack_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Brace_noText() { + fxt.Test_parse_page_wiki("[irc://a]", fxt.tkn_lnke_(0, 9).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack).Lnke_rng_(1, 8)); + } + @Test public void Brace_eos() { + fxt.Test_parse_page_wiki("[irc://a", fxt.tkn_txt_(0, 1), fxt.tkn_lnke_(1, 8).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling).Lnke_rng_(1, 8)); + } + @Test public void Brace_text() { + fxt.Test_parse_page_wiki("[irc://a b c]", fxt.tkn_lnke_(0, 13).Lnke_rng_(1, 8).Subs_(fxt.tkn_txt_(9, 10), fxt.tkn_space_(10, 11), fxt.tkn_txt_(11, 12))); + } + @Test public void Brace_lt() { + fxt.Init_log_(Xop_xnde_log.Eos_while_closing_tag).Test_parse_page_wiki("[irc://ac]" + , "c" + ); + } + @Test public void Brace_newLine() { + fxt.Test_parse_page_wiki("[irc://a\n]", fxt.tkn_txt_(0, 8), fxt.tkn_nl_char_len1_(8), fxt.tkn_txt_(9, 10)); + } + @Test public void Html_brack() { + fxt.Test_parse_page_wiki_str("[irc://a]", "[1]"); + } + @Test public void Apos() { + fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "b"); + fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "[1]"); + } + @Test public void Nowiki() { + fxt.Test_parse_page_all_str + ( "http://a.org" + , "http://a.org" + ); + } + @Test public void Lnki_one() { // PURPOSE: parallel test for "http://a.org[[B]]"; DATE:2014-07-11 + fxt.Test_parse_page_wiki_str + ( "[http://a.org b [[C]] d]" + ,String_.Concat_lines_nl_skip_last + ( "b C d" + )); + } + @Test public void Encode_xwiki() { // PURPOSE: href title and args should always be encoded; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15 + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("commons.wikimedia.org"), Bry_.new_a7("commons.wikimedia.org")); + fxt.Test__parse__wtxt_to_html // encode page + ( "[http://commons.wikimedia.org/%22%3E_A B]" + , "B" // '%22%3E' not '">' + ); + fxt.Test__parse__wtxt_to_html // encode args + ( "[http://commons.wikimedia.org/A?b=%22%3E_C D]" + , "D" // '%22%3E' not '">' + ); + } + @Test public void Encode_basic() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15 + fxt.Test_parse_page_wiki_str // encode page + ( "[http://a.org/%22%3E_A B]" + , "B" // '%22%3E' not '">' + ); + fxt.Test_parse_page_wiki_str // encode args + ( "[http://a.org/A?b=%22%3E_C D]" + , "D" // '%22%3E' not '">' + ); + } + @Test public void Encode_relative() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15 + fxt.Test_parse_page_wiki_str // encode page + ( "[//a.org/%22%3E_A B]" + , "B" // '%22%3E' not '">' + ); + fxt.Test_parse_page_wiki_str // encode args + ( "[//a.org/A?b=%22%3E_C D]" + , "D" // '%22%3E' not '">' + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_dangling_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_dangling_tst.java new file mode 100644 index 000000000..a6699406b --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_dangling_tst.java @@ -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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnke_wkr_dangling_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Dangling_eos() { + fxt.Test_parse_page_wiki("[irc://a b" + , fxt.tkn_lnke_(0, 8).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling) + , fxt.tkn_txt_(9, 10) + ); + } + @Test public void Dangling_newLine() { + fxt.Test_parse_page_wiki("[irc://a b\nc]" + , fxt.tkn_lnke_(0, 8).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling) + , fxt.tkn_txt_(9, 10) + , fxt.tkn_nl_char_len1_(10) + , fxt.tkn_txt_(11, 13) + ); + } + @Test public void Dangling_gt() { + fxt.Test_parse_page_wiki("[irc://a>b c]", fxt.tkn_lnke_(0, 13).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack).Subs_(fxt.tkn_txt_(8, 10), fxt.tkn_space_(10, 11), fxt.tkn_txt_(11, 12))); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_relative_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_relative_tst.java new file mode 100644 index 000000000..69be997bc --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_relative_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnke_wkr_relative_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Relative_obj() { + fxt.Test_parse_page_wiki("[//a b]" + , fxt.tkn_lnke_(0, 7).Lnke_rng_(1, 4).Subs_(fxt.tkn_txt_(5, 6)) + ); + } + @Test public void Relative_external() { + fxt.Test__parse__wtxt_to_html("[//www.a.org a]", "a"); + } + @Test public void Relative_internal() { + fxt.Init_xwiki_add_user_("en.wikipedia.org"); + fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/wiki Wikipedia]", "Wikipedia"); + } + @Test public void Relative_w_category() { // EX: [//commons.wikimedia.org/wiki/Category:Diomedeidae A] + fxt.Init_xwiki_add_user_("en.wikipedia.org"); + fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/wiki/Category:A A]", "A"); + } + @Test public void Relurl() { + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[[//en.wikipedia.org/ a]]", "[a]"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_text_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_text_tst.java new file mode 100644 index 000000000..e7de5184c --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_text_tst.java @@ -0,0 +1,97 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.langs.cases.*; +public class Xop_lnke_wkr_text_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Text_obj() { + fxt.Test_parse_page_wiki("irc://a", fxt.tkn_lnke_(0, 7).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_text).Lnke_rng_(0, 7)); + } + @Test public void Text_html() { + fxt.Test_parse_page_wiki_str("irc://a", "irc://a"); + } + @Test public void Text_after() { + fxt.Test_parse_page_wiki("irc://a b c", fxt.tkn_lnke_(0, 7).Lnke_rng_(0, 7), fxt.tkn_space_(7, 8), fxt.tkn_txt_(8, 9), fxt.tkn_space_(9, 10), fxt.tkn_txt_(10, 11)); + } + @Test public void Text_before_ascii() { // PURPOSE: free form external urls should not match if preceded by letters; EX:de.w:Sylvie_und_Bruno; DATE:2014-05-11 + fxt.Ctx().Lang().Case_mgr_u8_(); + String expd_lnke_html = "tel:a"; + fxt.Test_parse_page_wiki_str("titel:a" , "titel:a"); + fxt.Test_parse_page_wiki_str(" tel:a" , " " + expd_lnke_html); + fxt.Test_parse_page_wiki_str("!tel:a" , "!" + expd_lnke_html); + fxt.Test_parse_page_wiki_str("ätel:a" , "ätel:a"); + fxt.Test_parse_page_wiki_str("€tel:a" , "€" + expd_lnke_html); + } + @Test public void Invalid_lnki_and_list_dt_dd() { // PURPOSE: invalid lnke should still allow processing of ":" in list
      ; PAGE:de.w:Mord_(Deutschland)#Besonders_verwerfliche_Begehungsweise DATE:2015-01-08 + fxt.Test_parse_page_wiki_str("; atel: b" , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      atel" + , "
      " + , "
      b" + , "
      " + , "
      " + )); + } + @Test public void Xnde() {// NOTE: compare to Brace_lt + fxt.Test_parse_page_wiki("irc://a" + , fxt.tkn_xnde_(0, 20).Subs_ + ( fxt.tkn_lnke_(6, 13) + ) + ); + } + @Test public void List() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*irc://a" + , "*irc://b" + ),String_.Concat_lines_nl_skip_last + ( "" + )); + } + @Test public void Defect_reverse_caption_link() { // PURPOSE: bad lnke formatting (caption before link); ] should show up at end, but only [ shows up; PAGE:en.w:Paul Philippoteaux; [caption http://www.americanheritage.com] + fxt.Test_parse_page_wiki_str("[caption irc://a]", "[caption irc://a]"); + } + @Test public void Lnki() { // PURPOSE: trailing lnki should not get absorbed into lnke; DATE:2014-07-11 + fxt.Test_parse_page_wiki_str + ( "http://a.org[[B]]" // NOTE: [[ should create another lnki + ,String_.Concat_lines_nl_skip_last + ( "http://a.orgB" + )); + } + @Test public void Protocol_only() { // PURPOSE: protocol only should return text; DATE:2014-10-09 + fxt.Test_parse_page_wiki_str("http://" , "http://"); + fxt.Test_parse_page_wiki_str("http:" , "http:"); + fxt.Test_parse_page_wiki_str("[http://]" , "[http://]"); + fxt.Test_parse_page_wiki_str("[http:]" , "[http:]"); + } + @Test public void Ignore_punctuation_at_end() { // PURPOSE: ignore "," and related punctuation at end; DATE:2014-10-09 + fxt.Test_parse_page_wiki_str("http://a.org," , "http://a.org,"); // basic + fxt.Test_parse_page_wiki_str("http://a.org,," , "http://a.org,,"); // many + fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "http://a.org/b,c"); // do not ignore if in middle + fxt.Test_parse_page_wiki_str("http://a.org:" , "http://a.org:"); // colon at end; compare to "http:" + } + @Test public void Ignore_punctuation_at_end__paren_end() { // PURPOSE: end parent has special rules; DATE:2014-10-10 + fxt.Test_parse_page_wiki_str("(http://a.org)" , "(http://a.org)"); // trim=y + fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "http://a.org/b(c)"); // trim=n + } + @Test public void Sym_quote() { // PURPOSE: quote should interrupt lnke; DATE:2014-10-10 + fxt.Test_parse_page_wiki_str("http://a.org/b\"c", "http://a.org/b"c"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_uncommon_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_uncommon_tst.java new file mode 100644 index 000000000..66a915df8 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_uncommon_tst.java @@ -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.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnke_wkr_uncommon_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Err_multiple() { + fxt.Test_parse_page_wiki("[irc://a][irc://b]" + , fxt.tkn_lnke_(0, 9) + , fxt.tkn_lnke_(9, 18) + ); + } + @Test public void Err_txt_is_protocol() { + fxt.Test_parse_page_wiki("[irc://a irc://b]" + , fxt.tkn_lnke_(0, 17).Lnke_rng_(1, 8).Subs_(fxt.tkn_txt_(9, 16)) + ); + } + @Test public void Lnke_should_precede_lnki() { // PURPOSE: [[ should not be interpreted as lnki if [irc is available + fxt.Test_parse_page_wiki("[[irc://a/b c]]" + , fxt.tkn_txt_(0, 1) + , fxt.tkn_lnke_(1, 14).Subs_ + ( fxt.tkn_txt_(12, 13) + ) + , fxt.tkn_txt_(14, 15) + ); + } + @Test public void Defect_2nd_consecutive_lnke() { // PURPOSE: bad code that was causing lnkes to show up; PAGE:en.w:Template:Infobox_country; + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "[[http://a.org a]] [[http://b.org b]]" + ), String_.Concat_lines_nl_skip_last + ( "[a] [b]" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_xwiki_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_xwiki_tst.java new file mode 100644 index 000000000..c2fce00d4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkes/Xop_lnke_wkr_xwiki_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnke_wkr_xwiki_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Xwiki() { + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/A a]", "a"); + } + @Test public void Xwiki_relative() { + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[//en.wikipedia.org/ a]", "a"); + } + @Test public void Xwiki_qarg() {// DATE:2013-02-02 + fxt.Init_xwiki_add_user_("en.wikipedia.org"); + fxt.Test__parse__wtxt_to_html("http://en.wikipedia.org/wiki/Special:Allpages?from=Earth", "http://en.wikipedia.org/wiki/Special:Allpages?from=Earth"); + } + @Test public void Lang_prefix() { + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("fr"), Bry_.new_a7("fr.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/fr:A a]", "a"); + } + @Test public void Xwiki_query_arg() { + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/wiki/A?action=edit a]", "a"); + } + @Test public void Xwiki__history() { // PURPOSE: handle xwiki lnke's to history page else null ref; EX:[http://ru.wikipedia.org/w/index.php?title&diff=19103464&oldid=18910980 извещен]; PAGE:ru.w:Project:Заявки_на_снятие_флагов/Архив/Патрулирующие/2009 DATE:2016-11-24 + fxt.App().Usere().Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("en.wikipedia.org"), Bry_.new_a7("en.wikipedia.org")); + fxt.Test__parse__wtxt_to_html("[http://en.wikipedia.org/w/index.php?title&diff=1&oldid=2 abc]", "abc"); + } + @Test public void Ignore_proto() { // PURPOSE: handle other protocols; PAGE:uk.w:Маскалі; DATE:2015-07-28 + fxt.Test__parse__wtxt_to_html("[mailto:a b]", "b");// should be /w/, not /en.wikipedia.org + } + @Test public void Ignore_alias() { // PURPOSE: fictitious example to make sure aliases are not subbed for domains; DATE:2015-07-28 + fxt.Init_xwiki_add_user_("w", "en.wikipedia.org"); + fxt.Test__parse__wtxt_to_html("[https://w/b c]", "c");// should be /w/, not /en.wikipedia.org + } + @Test public void Xwiki__qargs() { // PURPOSE: fix null ref error; PAGE:en.w:Wikipedia:Template_standardisation/demometa DATE:2015-08-02 + fxt.Init_xwiki_add_user_("en.wikipedia.org"); + fxt.Test__parse__wtxt_to_html + ( "[http://en.wikipedia.org/w/index.php?action=edit&preload=Template:Afd2+starter&editintro=Template:Afd3+starter&title=Wikipedia:Articles+for+deletion/Template_standardisation/demometa]" + // CHANGED: lnke_now decodes html_entities; DATE:2016-10-10 + //, "[1]" + , "[1]" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java new file mode 100644 index 000000000..718b615a6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__basic_tst.java @@ -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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; import gplx.xowa.langs.funcs.*; import gplx.xowa.langs.lnki_trails.*; +import gplx.xowa.wikis.nss.*; +import gplx.xowa.parsers.paras.*; import gplx.xowa.wikis.ttls.*; +public class Xop_lnki_wkr__basic_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_parse_page_wiki("[[a]]", fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3))); + } + @Test public void HtmlRef() { + fxt.Test_parse_page_wiki_str("[[a&b]]" + , "a&b" + ); + } + @Test public void Url_encode() { // PURPOSE:title should automatically do url decoding; DATE:2013-08-26 + fxt.Test_parse_page_all_str("[[A%20b]]", "A b"); + } + @Test public void Url_encode_plus() { // PURPOSE:do not decode plus; DATE:2013-08-26 + fxt.Test_parse_page_all_str("[[A+b]]", "A+b"); + } + @Test public void Caption() { + fxt.Test_parse_page_wiki("[[a|b]]" , fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3)).Caption_tkn_(fxt.tkn_arg_val_txt_(4, 5))); + fxt.Test_parse_page_wiki("[[a|b:c]]", fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3)).Caption_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(4, 5), fxt.tkn_colon_(5), fxt.tkn_txt_(6, 7)))); + } + @Test public void Caption_equal() { // should ignore = if only caption arg (2 args) + fxt.Test_parse_page_wiki("[[a|=]]", fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3)).Caption_tkn_(fxt.tkn_arg_val_(fxt.tkn_eq_(4)))); + } + @Test public void Caption_ampersand() {fxt.Test_parse_page_wiki_str("[[A|a & b]]", "a & b");} + @Test public void Tail() { + fxt.Test_parse_page_wiki("[[a|b]]c" , fxt.tkn_lnki_(0, 8).Tail_bgn_(7).Tail_end_(8)); + fxt.Test_parse_page_wiki("[[a|b]] c", fxt.tkn_lnki_(0, 7).Tail_bgn_(-1), fxt.tkn_space_(7, 8), fxt.tkn_txt_(8, 9)); + fxt.Test_parse_page_wiki("[[a|b]]'c", fxt.tkn_lnki_(0, 7).Tail_bgn_(-1), fxt.tkn_txt_(7, 9)); + } + @Test public void Tail_number() {fxt.Test_parse_page_wiki("[[a|b]]1" , fxt.tkn_lnki_(0, 7).Tail_bgn_(-1), fxt.tkn_txt_(7, 8));} + @Test public void Tail_upper() {fxt.Test_parse_page_wiki("[[a|b]]A" , fxt.tkn_lnki_(0, 7).Tail_bgn_(-1), fxt.tkn_txt_(7, 8));} // make sure trie is case-insensitive + @Test public void Tail_image() {fxt.Test_parse_page_wiki("[[Image:a|b]]c", fxt.tkn_lnki_(0, 13).Tail_bgn_(-1).Tail_end_(-1), fxt.tkn_txt_(13, 14));} // NOTE: this occurs on some pages; + @Test public void Image() { + fxt.Test_parse_page_wiki("[[Image:a]]" , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))); + fxt.Test_parse_page_wiki("[[Image:a|border]]" , fxt.tkn_lnki_().Border_(Bool_.Y_byte)); + fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb)); + fxt.Test_parse_page_wiki("[[Image:a|left]]" , fxt.tkn_lnki_().HAlign_(Xop_lnki_align_h_.Left)); + fxt.Test_parse_page_wiki("[[Image:a|top]]" , fxt.tkn_lnki_().VAlign_(Xop_lnki_align_v_.Top)); + fxt.Test_parse_page_wiki("[[Image:a|10px]]" , fxt.tkn_lnki_().Width_(10).Height_(-1)); + fxt.Test_parse_page_wiki("[[Image:a|20x30px]]" , fxt.tkn_lnki_().Width_(20).Height_(30)); + fxt.Test_parse_page_wiki("[[Image:a|alt=b]]" , fxt.tkn_lnki_().Alt_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 13))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(14, 15))))); + fxt.Test_parse_page_wiki("[[Image:a|link=a]]" , fxt.tkn_lnki_().Link_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 14))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(15, 16))))); + fxt.Test_parse_page_wiki("[[Image:a|thumb|alt=b|c d]]" + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) + .Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) + .Alt_tkn_(fxt.tkn_arg_nde_().Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(16, 19))).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(20, 21)))) + .Caption_tkn_(fxt.tkn_arg_nde_(22, 25).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(22, 23), fxt.tkn_space_(23, 24), fxt.tkn_txt_(24, 25))))) + ; + } + @Test public void Image_upright() { + fxt.Test_parse_page_wiki("[[Image:a|upright=.123]]" , fxt.tkn_lnki_().Upright_(.123)); + fxt.Test_parse_page_wiki("[[Image:a|upright]]" , fxt.tkn_lnki_().Upright_(gplx.xowa.files.Xof_img_size.Upright_default_marker)); // no eq tokn + fxt.Test_parse_page_wiki("[[Image:a|upright=.42190046219457]]", fxt.tkn_lnki_().Upright_(.42190046219457)); // many decimal places breaks upright + fxt.Init_log_(Xop_lnki_log.Upright_val_is_invalid) + .Test_parse_page_wiki("[[Image:a|upright=y]]" , fxt.tkn_lnki_().Upright_(-1)); // invalid + } + @Test public void Recurse() { + fxt.Test_parse_page_wiki("[[Image:a|b-[[c]]-d]]" + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) + .Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) + .Caption_tkn_(fxt.tkn_arg_nde_(10, 19).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 12), fxt.tkn_lnki_(12, 17), fxt.tkn_txt_(17, 19)))) + ); + } + @Test public void Outliers() { + fxt.Test_parse_page_wiki("[[Image:a=b.svg|thumb|10px]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9), fxt.tkn_eq_(9), fxt.tkn_txt_(10, 15))))); + fxt.Test_parse_page_wiki("[[Category:a|b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__category)); + } + @Test public void Exc_caption_has_eq() { + fxt.Test_parse_page_wiki("[[Image:a.svg|thumb|a=b]]", fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file) + .Caption_tkn_(fxt.tkn_arg_nde_(20, 23).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(20, 21), fxt.tkn_eq_(21), fxt.tkn_txt_(22, 23))))); + } + @Test public void Border_with_space_should_not_be_caption() {// happens with {{flag}}; EX: [[Image:Flag of Argentina.svg|22x20px|border |alt=|link=]] + Xop_root_tkn root = fxt.Test_parse_page_wiki_root("[[Image:a.svg|22x20px|border |alt=|link=]]"); + Xop_lnki_tkn lnki = (Xop_lnki_tkn)root.Subs_get(0); + Tfds.Eq(Xop_tkn_itm_.Tid_null, lnki.Caption_tkn().Tkn_tid()); + } + @Test public void Ws_key_bgn() { + fxt.Test_parse_page_wiki("[[Image:a| alt=b]]", fxt.tkn_lnki_() + .Alt_tkn_(fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_space_(10, 11).Ignore_y_(), fxt.tkn_txt_(11, 14))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(15, 16))) + )); + } + @Test public void Ws_key_end() { + fxt.Test_parse_page_wiki("[[Image:a|alt =b]]", fxt.tkn_lnki_() + .Caption_tkn_(fxt.tkn_arg_nde_(10, 16) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 13), fxt.tkn_space_(13, 14), fxt.tkn_eq_(14), fxt.tkn_txt_(15, 16))) + )); + } + @Test public void Ws_val_bgn() { + fxt.Test_parse_page_wiki("[[Image:a|alt= b]]", fxt.tkn_lnki_() + .Alt_tkn_(fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 13))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_space_(14, 15), fxt.tkn_txt_(15, 16))) + )); + } + @Test public void Ws_val_end() { + fxt.Test_parse_page_wiki("[[Image:a|alt=b ]]", fxt.tkn_lnki_() + .Alt_tkn_(fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 13))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(14, 15), fxt.tkn_space_(15, 16).Ignore_y_())) + )); + } + @Test public void Ws_val_only() { // simpler variation of Ws_val_size + fxt.Test_parse_page_wiki("[[Image:a| b ]]", fxt.tkn_lnki_() + .Caption_tkn_(fxt.tkn_arg_nde_() + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_space_(10, 11), fxt.tkn_txt_(11, 12), fxt.tkn_space_(12, 13))) + )); + } + @Test public void Ws_val_size() { + fxt.Test_parse_page_wiki("[[Image:a| 20x30px ]]" , fxt.tkn_lnki_().Width_(20).Height_(30)); + } + @Test public void Nl_pipe() { // PURPOSE: "\n|" triggers tblw; PAGE:fr.w:France; [[Fichier:Carte demographique de la France.svg + fxt.Test_parse_page_wiki("[[Image:A.png|thumb\n|alt=test]]", fxt.tkn_lnki_() + .Alt_tkn_(fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(21, 24))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(25, 29))) + )); + } + @Test public void Exc_empty_caption() { + fxt.Test_parse_page_wiki("[[a|]]", fxt.tkn_lnki_().Trg_tkn_(fxt.tkn_arg_val_txt_(2, 3))); + } + @Test public void Exc_empty() { + fxt.Init_log_(Xop_lnki_log.Invalid_ttl); + fxt.Test_parse_page_wiki("[[]]", fxt.tkn_txt_(0, 2), fxt.tkn_txt_(2, 4)); + fxt.Init_log_(Xop_lnki_log.Invalid_ttl); + fxt.Test_parse_page_wiki("[[ ]]", fxt.tkn_txt_(0, 2), fxt.tkn_space_(2, 3), fxt.tkn_txt_(3, 5)); + } + @Test public void Exc_invalid_u8() { // PURPOSE: "%DO" is an invalid UTF-8 sequence (requires 2 bytes, not just %D0); DATE:2013-11-11 + fxt.Ctx().Lang().Case_mgr_u8_(); // NOTE: only occurs during Universal + fxt.Test_parse_page_all_str("[[%D0]]", "[[%D0]]"); // invalid titles render literally + } + @Test public void Ex_eq() { // make sure that eq is not evaluated for kv delimiter + fxt.Test_parse_page_wiki("[[=]]", fxt.tkn_lnki_(0, 5)); + fxt.Test_parse_page_wiki("[[a|=]]", fxt.tkn_lnki_(0, 7)); + } + @Test public void Unclosed() { // PURPOSE: unclosed lnki skips rendering of next table; PAGE:en.w:William Penn (Royal Navy officer) + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a [[b|c]" + , "" + , "{|" + , "|-" + , "|d" + , "|}" + ),String_.Concat_lines_nl_skip_last + ( "a [[b|c] " // NOTE: \n is converted to \s b/c caption does not allow \n + , "" + , " " + , " " + , " " + , "
      d" + , "
      " + , "" + )); + } + @Test public void Caption_nl() { // PURPOSE: \n in caption should be rendered as space; PAGE:en.w:Schwarzschild radius; and the stellar [[Velocity dispersion|velocity\ndispersion]] + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a [[b|c" + , "" + , "" + , "d]]" + ), String_.Concat_lines_nl_skip_last + ( "

      a c d" // NOTE: this depends on html viewer to collapse multiple spaces into 1 + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Caption_nl_2() { // PURPOSE: unclosed lnki breaks paragraph unexpectedly; PAGE:en.w:Oldsmobile; + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b [[c" + , "" // NOTE: this new line is needed to produce strange behavior + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b [[c" // NOTE: \n is converted to \s b/c caption does not allow \n; NOTE: removed \s after "c" due to new lnki invalidation;DATE:2014-04-03 + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Caption_ref() { // PURPOSE: not handled in lnki; PAGE:en.w:WWI + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "[[File:A.png|thumb|b c]]" + ), String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      b [1]" + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Html_ent_pound() { + fxt.Test_parse_page_wiki_str + ( "[[A#b|c]]", String_.Concat_lines_nl_skip_last + ( "c" + )); + } + @Test public void Html_ent_ltr_a() { + fxt.Test_parse_page_wiki_str + ( "[[Ab|c]]", String_.Concat_lines_nl_skip_last + ( "c" + )); + } + @Test public void Pipe_trick() { + fxt.Test_parse_page_wiki_str("[[Page1|]]" , "Page1"); + fxt.Test_parse_page_wiki_str("[[Help:Page1|]]" , "Page1"); + } + @Test public void Thumb_first_align_trumps_all() { // PURPOSE: if there are multiple alignment instructions, take the first EX:[[File:A.png|thumb|center|left]] DATE:20121226 + fxt.Test_parse_page_wiki_str("[[File:A.png|thumb|right|center]]" // NOTE: right trumps center + , String_.Concat_lines_nl_skip_last + ( Xop_para_wkr_basic_tst.File_html("File", "A.png", "7/0", "") + , "" + )); + } + @Test public void Eq() { + fxt.Test_parse_page_all_str("[[B|=]]", "="); + } + @Test public void Href_encode_anchor() { // PURPOSE: test separate encoding for ttl (%) and anchor (.) + fxt.Test_parse_page_all_str("[[^#^]]", "^#^"); + } + @Test public void Href_question() { // PURPOSE.fix: ttl with ? at end should not be considered qarg; DATE:2013-02-08 + fxt.Test_parse_page_all_str("[[A?]]", "A?"); + } + @Test public void Href_question_2() { // PURPOSE: ?action=edit should be encoded; DATE:2013-02-10 + fxt.Test_parse_page_all_str("[[A?action=edit]]", "A?action=edit"); + } + @Test public void Href_question_3() { // PURPOSE.fix: DATE:2014-01-16 + fxt.Test_parse_page_all_str("[[A?b]]", "A?b"); + } + @Test public void Encoded_url() { // PURPOSE.fix: url-encoded characters broke parser when embedded in link; DATE:2013-03-01 + fxt.Init_xwiki_add_user_("commons.wikimedia.org"); + fxt.Test_parse_page_wiki_str("[[File:A.png|link=//commons.wikimedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0?uselang=ru|b]]" + , "\"b\""); + } + @Test public void Link__invalid() { // PURPOSE.fix: do not render invalid text; EX: link={{{1}}}; [[Fil:Randers_-_Hadsund_railway.png|120x160px|link={{{3}}}|Randers-Hadsund Jernbane]]; DATE:2013-03-04 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link={{{1}}}|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link__html_ent() {// PURPOSE:html entities should be converted to chars; EX:  -> _; DATE:2013-12-16 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|link=b c]]", String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + } + @Test public void Link__encode() {// PURPOSE:spaces should become underscore; DATE:2015-11-27 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|link=File:A b ç.ogg]]", String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + } + @Test public void Href_anchor_leading_space() { // PURPOSE: ?action=edit should be encoded; DATE:2013-02-10 + fxt.Test_parse_page_all_str("[[A #b]]", "A #b"); + } + @Test public void Anchor_not_shown_for_wikipedia_ns() { // PURPOSE: Help:A#b was omitting anchor; showing text of "Help:A"; DATE:2013-06-21 + fxt.Test_parse_page_all_str("[[Help:A#b]]", "Help:A#b"); + } + @Test public void Anchor_shown_for_main_ns() { // PURPOSE: counterpart to Anchor_not_shown_for_wikipedia_ns; DATE:2013-06-21 + fxt.Test_parse_page_all_str("[[A#b]]", "A#b"); + } + @Test public void Trail_en() { + fxt.Test_parse_page_all_str("[[Ab]]cd e", "Abcd e"); + } + @Test public void Trail_fr() { + byte[] ltr_c_in_french = Bry_.new_u8("ç"); + Xol_lnki_trail_mgr lnki_trail_mgr = fxt.Wiki().Lang().Lnki_trail_mgr(); + lnki_trail_mgr.Add(ltr_c_in_french); + fxt.Test_parse_page_all_str("[[Ab]]çd e", "Abçd e"); + lnki_trail_mgr.Del(ltr_c_in_french); + } + @Test public void Page() { + fxt.Test_parse_page_wiki("[[File:A.pdf|page=12]]" , fxt.tkn_lnki_().Page_(12)); + } + @Test public void Visited() { // PURPOSE: show redirected titles as visited; EX:fr.w:Alpes_Pennines; DATE:2014-02-28 + Xowe_wiki wiki = fxt.Wiki(); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7("Src")); // simulate requrest for "Src" page + Xoae_page previous_page = Xoae_page.New_test(wiki, ttl); + previous_page.Redirect_trail().Itms__add__article(previous_page.Url(), ttl, null); // simulate redirect from "Src" + fxt.App().Usere().History_mgr().Add(previous_page); // simulate "Src" already being clicked once; this is the key call + fxt.Wtr_cfg().Lnki__visited_y_(); + fxt.Test_parse_page_all_str("[[Src]]" , "Src"); // show [[Src]] as visited since it exists in history + fxt.Test_parse_page_all_str("[[Other]]" , "Other"); // show other pages as not visited + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__ctg_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__ctg_tst.java new file mode 100644 index 000000000..ebec52c40 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__ctg_tst.java @@ -0,0 +1,130 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Xop_lnki_wkr__ctg_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Pre() { // PURPOSE: Category should trim preceding nl; EX:w:Mount Kailash + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , " [[Category:b]]" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "c" + , "

      " + , "" + )); + } + @Test public void Ws() { // FUTURE: needs more para rework; conflicts with Li() test; WHEN: when issue is found + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "x [[Category:b]]" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "x " + , "c" + , "

      " + , "" + )); + } + @Test public void Li() { // PURPOSE: Category strips all preceding ws; PAGE:en.w:NYC (in external links) + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "*b" + , " [[Category:c]]" + , "*d" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a" + , "
      • " + , "
      • b" + , "
      • " + , "
      • d" + , "
      • " + , "
      " + )); + } + @Test public void Li_w_lnke() { // PURPOSE: [[Category]] was being absorbed into lnke; PAGE:de.w:ISO/IEC/IEEE_29119_Software_Testing DATE:2014-07-11 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "* http://a.org" + , "[[Category:B]]" // category should not show below + ), String_.Concat_lines_nl_skip_last + ( "" + , "" + )); + } + @Test public void Merge_li() { // PURPOSE: trim ws preceding [[Category:; de.d:plant; DATE:2014-03-27 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "*a" + , "" + , " [[Category:B]] c" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a c" + , "
      • " + , "
      " + , "" + )); + } + @Test public void Merge_pre() { // PURPOSE: leading spaces / nls should be removed from normal Category, else false pre's or excessive line breaks + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( " [[Category:A]]" // removes \s + , " [[Category:B]]" // removes \n\s + ), String_.Concat_lines_nl + ( "

      " + , "

      " + )); + } + @Test public void Literal() { // PURPOSE: do not trim ws if literal Category; EX:fr.wikiquote.org/wiki/Accueil; REF: https://sourceforge.net/p/xowa/tickets/167/; DATE:2013-07-10 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "[[:Category:A]]" + , "[[:Category:B]]" + ), String_.Concat_lines_nl + ( "

      Category:A" // NOTE: technically WP converts to " " not "\n" (via HtmlTidy?) + , "Category:B" + , "

      " + )); + } + @Test public void Hdr_w_nl() { // PURPOSE: hdr code broken by Category; DATE:2014-04-17 + fxt.Test_parse_page_all_str("==a==\n[[Category:C]]" + , String_.Concat_lines_nl_skip_last + ( "

      a

      " + , "" + )); + } + @Test public void Hdr_only() { // PURPOSE: check that == is hdr; EX:ar.d:جَبَّارَة; DATE:2014-04-17 + fxt.Test_parse_page_wiki_str("==a==[[Category:C]]" + , String_.Concat_lines_nl_skip_last + ( "

      a

      " + , "" + )); + } + @Test public void Hdr_ignore() { // PURPOSE: check that hdr is ignored if next char is not nl; DATE:2014-04-17 + fxt.Test_parse_page_wiki_str("==a==[[Category:C]]b" + , String_.Concat_lines_nl_skip_last + ( "==a==b" + , "" + )); + } +} + diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__frame_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__frame_tst.java new file mode 100644 index 000000000..1a18354e5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__frame_tst.java @@ -0,0 +1,23 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnki_wkr__frame_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + // PURPOSE:use 1st imgtype param; changed between mw1.22.2 and mw1.25.2 PAGE:he.w:מספן_המודיעין EX: [[File:Osa-I class Project205 DN-SN-84-01770.jpg|thumb|frame|abcde]] + @Test public void Use_1st__thumb() {fxt.Test_parse_page_wiki("[[File:A.png|thumb|frame]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));} + @Test public void Use_1st__frame() {fxt.Test_parse_page_wiki("[[File:A.png|frame|thumb]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_frame));} +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__invalid_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__invalid_tst.java new file mode 100644 index 000000000..2c377c447 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__invalid_tst.java @@ -0,0 +1,95 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; import gplx.xowa.wikis.ttls.*; +public class Xop_lnki_wkr__invalid_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Ignore_invalid_url_encodings() { // PURPOSE: if url encoding is invalid, still render lnki as ; EX: fr.w:Bordetella; + fxt.Test_parse_page_all_str("[[%GC]]", "%GC"); + } + @Test public void Caption_still_parsed() { // PURPOSE: failed lnki should still parse xml in caption; EX:ar.w:الصومال; DATE:2014-03-04 + fxt.Test_parse_page_all_str("[[|''a'']]" , "[[|a]]"); + } + @Test public void Ttl_still_parsed() { // PURPOSE: invalid lnki should still parse ttl; BASED_ON:ar.w:الصومال; DATE:2014-03-26 + fxt.Test_parse_page_all_str("[[''[a]'']]" , "[[[a]]]"); + } + @Test public void Pipe_only() { + fxt.Init_log_(Xop_lnki_log.Invalid_ttl); + fxt.Test_parse_page_wiki("[[|]]", fxt.tkn_txt_(0, 2), fxt.tkn_pipe_(2), fxt.tkn_txt_(3, 5)); + } + @Test public void Xnde_should_force_ttl_parse() { // PURPOSE: reparse should be forced at xnde not at pipe; EX: [[ac|d]] reparse should start at ; DATE:2014-03-30 + fxt.Test_parse_page_all_str_and_chk("[[ac|d]]" , "[[ac|d]]", Xop_lnki_log.Invalid_ttl); + } + @Test public void Tblw_tb() { // PURPOSE: reparse should be forced at tblw.tb; DATE:2014-04-03 + fxt.Test_parse_page_all_str_and_chk("[[a\n{||b]]", String_.Concat_lines_nl_skip_last + ( "[[a" + , "|b]]" + , "
      " + , "" + ), Xop_lnki_log.Invalid_ttl); + } + @Test public void Tblw_tr() { // PURPOSE: reparse should be forced at tblw.tr; DATE:2014-04-03 + fxt.Test_parse_page_all_str_and_chk("[[a\n|-b]]", String_.Concat_lines_nl_skip_last + ( "[[a" + , "|-b]]" + ), Xop_lnki_log.Invalid_ttl); + } + @Test public void Tblw_tr_like() { // PURPOSE: do not invalidate if pseudo-tr; DATE:2014-04-03 + fxt.Test_parse_page_all_str_and_chk("[[a|-b]]", "-b"); + } + @Test public void Nl() { // PURPOSE: invalidate if nl; DATE:2014-04-03 + fxt.Test_parse_page_all_str_and_chk("''[[\n]]", "[[\n]]", Xop_lnki_log.Invalid_ttl); + } + @Test public void Nl_with_apos_shouldnt_fail() { // PURPOSE: apos, lnki and nl will cause parser to fail; DATE:2013-10-31 + fxt.Test_parse_page_all_str("''[[\n]]", "[[\n]]"); + } +// @Test public void Brack_end_invalid() { // PURPOSE: invalidate if ]; DATE:2014-04-03; // TODO_OLD: backout apos changes +// fxt.Test_parse_page_all_str_and_chk("[[A] ]", "[[A] ]", Xop_lnki_log.Invalid_ttl); +// } + @Test public void Module() { // PURPOSE: handle lnki_wkr parsing Module text (shouldn't happen); apos, tblw, lnki, and nl will cause parser to fail; also handles scan-bwd; EX:Module:Taxobox; DATE:2013-11-10 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( " [[''" + , " [[" + , " |" // NOTE: this is actually a tblw_ws_tkn ("\n |") not a pipe_tkn + , "]]" + ) + , String_.Concat_lines_nl_skip_last + ( "
      [["	// NOTE: should be  but scan_bwd can't undo previous apos
      +		, "[["
      +		, " |"
      +		, "
      " + , "" + , "

      ]]" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Tblw_in_lnki() { // PURPOSE: handle invalid tblw tkn inside lnki; DATE:2014-06-06 + fxt.Test_parse_page_all_str("[[A[]\n|b]]", "[[A[]\n|b]]"); // NOTE: \n| is tblw code for td + } +// @Test public void Tmpl() { // PURPOSE: invalid lnki breaks template +// fxt.Init_defn_clear(); +// fxt.Init_defn_add("a", "b"); +// fxt.Test_parse_page_all_str("{{a|[[}}", "b"); +// } + @Test public void Ns_is_not_main_and_starts_with_anchor() { // PURPOSE:page cannot start with # if non-main ns; PAGE:en.w:Spindale,_North_Carolina; DATE:2015-12-28 + fxt.Test_parse_page_all_str("[[File:#A]]" , "[[File:#A]]"); + } +} + diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__basic__tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__basic__tst.java new file mode 100644 index 000000000..fd328336e --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__basic__tst.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Xop_lnki_wkr__link__basic__tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Link() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=File:B.png|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_blank() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_external() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://www.b.org|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_file_system() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=file:///C/B.png|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_file_ns() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=File:B.png|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_external_relative() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_external_absolute() { + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Link_external_double_http() {// PURPOSE.fix: link=http://a.org?b=http://c.org breaks lnki; DATE:2013-02-03 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=//a.org?b=http://c.org]]", String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + } + @Test public void Encode() {// PURPOSE: encode invalid characters in link; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan DATE:2014-07-16 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|link=//b?c\">|d]]" + , "\"d\"" + ); + } + @Test public void Anchor() {// PURPOSE: handle anchors; PAGE:en.w: en.w:History_of_Nauru; DATE:2015-12-27 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|link=#b]]" + , "\"\"" + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__xwiki__tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__xwiki__tst.java new file mode 100644 index 000000000..311b97091 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__link__xwiki__tst.java @@ -0,0 +1,102 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Xop_lnki_wkr__link__xwiki__tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Relative() { // NOTE: changed href to return "wiki/" instead of "wiki"; DATE:2013-02-18 + fxt.Init_xwiki_add_user_("fr.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Relative_domain_only() { // lnki_wtr fails if link is only domain; EX: wikimediafoundation.org; [[Image:Wikispecies-logo.png|35px|link=//species.wikimedia.org]]; // NOTE: changed href to return "/wiki/" instead of ""; DATE:2013-02-18 + fxt.Init_xwiki_add_user_("fr.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=//fr.wikipedia.org]]", String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + } + @Test public void Absolute() { // NOTE: changed href to return "wiki/" instead of "wiki"; DATE:2013-02-18 + fxt.Init_xwiki_add_user_("fr.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://fr.wikipedia.org/wiki/|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Absolute_upload() { // PURPOSE: link to upload.wikimedia.org omits /wiki/; EX: wikimediafoundation.org: [[File:Page1-250px-WMF_AR11_SHIP_spreads_15dec11_72dpi.png|right|125px|border|2010–2011 Annual Report|link=https://upload.wikimedia.org/wikipedia/commons/4/48/WMF_AR11_SHIP_spreads_15dec11_72dpi.pdf]] + fxt.Init_xwiki_add_user_("commons.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://upload.wikimedia.org/wikipedia/commons/7/70/A.png|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Relative_deep() { + fxt.Init_xwiki_add_user_("fr.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=//fr.wikipedia.org/wiki/A/b|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + } + @Test public void Url_w_alias() { // [[File:Commons-logo.svg|25x25px|link=http://en.wikipedia.org/wiki/commons:Special:Search/Earth|alt=|Search Commons]] + fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org"); + fxt.Init_xwiki_add_wiki_and_user_("en.wikipedia.org", "en.wikipedia.org"); // DATE:2015-07-22 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://en.wikipedia.org/wiki/commons:B|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + fxt.Init_xwiki_clear(); + } + @Test public void Url_w_alias_and_sub_page() { // same as above, but for sub-page; [[File:Commons-logo.svg|25x25px|link=http://en.wikipedia.org/wiki/commons:Special:Search/Earth|alt=|Search Commons]] + fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org"); + fxt.Init_xwiki_add_wiki_and_user_("en.wikipedia.org", "en.wikipedia.org"); // DATE:2015-07-22 + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=http://en.wikipedia.org/wiki/commons:Special:Search/B|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + fxt.Init_xwiki_clear(); + } + @Test public void Alias__basic() { // alias: basic; [[File:Commons-logo.svg|25x25px|link=commons:Special:Search/Earth]]; fictitious example; DATE:2013-02-18 + fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=commons:Special:Search/B|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + fxt.Init_xwiki_clear(); + } + @Test public void Alias__prepended_colon() { // alias prepended with ":"; [[File:Wikipedia-logo.svg|40px|link=:w:|Wikipedia]]; DATE:2013-05-06 + fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=:commons:A/B|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + fxt.Init_xwiki_clear(); + } + @Test public void Alias__colon_only() {// alias: w/ only colon; EX: [[File:Commons-logo.svg|25x25px|link=commons:]]; PAGE:en.w:Wikipedia:Main_Page_alternative_(CSS_Update) DATE:2016-08-18 + // make commons wiki + fxt.Init_xwiki_add_wiki_and_user_("commons", "commons.wikimedia.org"); + Xowe_wiki commons_wiki = (Xowe_wiki)fxt.App().Wiki_mgr().Get_by_or_make_init_n(gplx.xowa.wikis.domains.Xow_domain_itm_.Bry__commons); + commons_wiki.Props().Main_page_(Bry_.new_a7("Test:Commons_main_page")); + + fxt.Test_parse_page_wiki_str + ( "[[File:A.png|12x10px|link=commons:|c]]", String_.Concat_lines_nl_skip_last + ( "\"c\"" + )); + fxt.Init_xwiki_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__pre_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__pre_tst.java new file mode 100644 index 000000000..8d2f8a26b --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__pre_tst.java @@ -0,0 +1,102 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Xop_lnki_wkr__pre_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Previous_pre() { // PURPOSE: if pre is already in effect, end it; EX: en.b:Knowing_Knoppix/Other_applications + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "[[File:A.png|thumb]]" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"			// NOTE: pre is ended; " b\n[[" -> 
      b
      " + , "
      " + , "" + , Html_A_png + , "" + , "

      c" + , "

      " + , "" + )); + } + @Test public void Current_pre_and_thumb() { // PURPOSE: current pre should be ended by thumb; EX: w:Roller coaster; it.w:Provincia_di_Pesaro_e_Urbino; DATE:2014-02-17 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " [[File:A.png|thumb]]" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19 + , Html_A_png + , "" + , "

      b" + , "

      " + , "" + )); + } + @Test public void Current_pre_and_halign() { // PURPOSE: current pre should be ended by halign since they also produce divs; EX: w:Trombiculidae; DATE:2014-02-17 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " [[File:A.png|right]]" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "
      " // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19 + , "\"\"
      " + , "" + , "

      b" + , "

      " + , "" + )); + } + @Test public void Current_pre() { // PURPOSE: current pre should exist if not div; DATE:2014-02-17 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " [[File:A.png]]" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
       \"\""	// NOTE: capture " "; confirmed against MW; DATE:2014-04-14
      +		, "
      " + , "" + , "

      b" + , "

      " + , "" + )); + } + private static final String Html_A_png = String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      " + , "
      " + , "
      " + , "
      " + ); +} + diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__size_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__size_tst.java new file mode 100644 index 000000000..ab91a5296 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__size_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.xndes.*; +public class Xop_lnki_wkr__size_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Width__w__ws() { + fxt.Test_parse_page_wiki("[[Image:a| 123 px]]" , fxt.tkn_lnki_().Width_(123)); + } + @Test public void Height() { + fxt.Test_parse_page_wiki("[[Image:a|x40px]]" , fxt.tkn_lnki_().Height_(40).Width_(-1)); + } + @Test public void Invalid_px__accept_double() { + fxt.Test_parse_page_wiki("[[Image:a|40pxpx]]" , fxt.tkn_lnki_().Width_(40).Height_(-1)); + } + @Test public void Invalid_px__accept_double__w_ws() { + fxt.Test_parse_page_wiki("[[Image:a|40pxpx ]]" , fxt.tkn_lnki_().Width_(40).Height_(-1)); + } + @Test public void Invalid_px__accept_double__w_ws_2() {// PURPOSE: handle ws between px's; EX:sv.w:Drottningholms_slott; DATE:2014-03-01 + fxt.Test_parse_page_wiki("[[Image:a|40px px]]" , fxt.tkn_lnki_().Width_(40).Height_(-1)); + } + @Test public void Invalid_px__ignore_if_w() { + fxt.Test_parse_page_wiki("[[Image:a|40px20px]]" , fxt.tkn_lnki_().Width_(-1).Height_(-1)); // -1 b/c "40px" + } + @Test public void Large_number() { // PURPOSE: perf code identified large sizes as caption; DATE:2014-02-15 + fxt.Test_parse_page_wiki("[[Image:a|1234567890x1234567890px]]" , fxt.tkn_lnki_().Width_(1234567890).Height_(1234567890)); + } + @Test public void Large_number__discard_if_gt_int() { // PURPOSE: size larger than int should be discarded, not be Int_.Max_value: PAGE:id.w:Baho; DATE:2014-06-10 + fxt.Test_html_wiki_frag("[[File:A.png|9999999999x30px]]", " width=\"0\" height=\"30\""); // width should not be Int_.Max_value + } + @Test public void Dangling_xnde() { // PURPOSE: dangling xnde should not eat rest of lnki; PAGE:sr.w:Сићевачка_клисура DATE:2014-07-03 + fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("[[Image:a.png|c|40px]]" , fxt.tkn_lnki_().Width_(40).Height_(-1)); + } + @Test public void Ws_para() { // PURPOSE:

      in arg_bldr causes parse to fail; EX: w:Supreme_Court_of_the_United_States; DATE:2014-04-05; updated test; DATE:2015-03-31 + fxt.Init_para_y_(); + fxt.Test_parse_page_all("[[File:A.png| \n 40px]]" + , fxt.tkn_para_bgn_para_(0) + , fxt.tkn_lnki_().Width_(40).Height_(-1) + , fxt.tkn_para_end_para_(22)); + fxt.Init_para_n_(); + } + @Test public void Invalid_size() { // PURPOSE: handle invalid sizes + fxt.Test_parse_page_wiki("[[File:A.png|1234xSomeTextpx]]" , fxt.tkn_lnki_().Width_(-1).Height_(-1)); // PAGE:es.b:Alimentación_infantil; DATE:2015-07-10 + fxt.Test_parse_page_wiki("[[File:A.png|100 KBpx]]" , fxt.tkn_lnki_().Width_(-1).Height_(-1)); // PAGE:en.w:Bahamas; DATE:2015-08-05 + fxt.Test_parse_page_wiki("[[File:A.png|size100px]]" , fxt.tkn_lnki_().Width_(-1).Height_(-1)); // PAGE:en.w:Data_compression; DATE:2015-08-05 + fxt.Test_parse_page_wiki("[[File:A.png|20\n0px]]" , fxt.tkn_lnki_().Width_(-1).Height_(-1)); // PAGE:en.w:Double_bass; DATE:2015-08-05 + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java new file mode 100644 index 000000000..f8bea1af7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__subpage_tst.java @@ -0,0 +1,66 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.wikis.nss.*; +public class Xop_lnki_wkr__subpage_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]] + fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(false); + fxt.Test_parse_page_all_str("[[/dev/null]]", "/dev/null"); + fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true); + } + @Test public void False_match() {// PAGE:en.w:en.wiktionary.org/wiki/Wiktionary:Requests for cleanup/archive/2006 + fxt.Test_parse_page_wiki_str + ( "[[.../compare ...]]" + , ".../compare ..." + ); + } + @Test public void Owner() { // PURPOSE: ../c does "A/c", not "c"; DATE:2014-01-02 + fxt.Page_ttl_("A/b"); + fxt.Test_parse_page_wiki_str + ( "[[../c]]" + , "A/c" + ); + } + @Test public void Owner_w_slash() { // PURPOSE: ../c/ does "c", not "A/c"; DATE:2014-01-02 + fxt.Page_ttl_("A/b"); + fxt.Test_parse_page_wiki_str + ( "[[../c/]]" + , "c" + ); + } + @Test public void Slash() { // PURPOSE: /B should show /B, not A/B; DATE:2014-01-02 + fxt.Page_ttl_("A"); + fxt.Test_parse_page_wiki_str + ( "[[/B]]", String_.Concat_lines_nl_skip_last + ( "/B" + )); + } + @Test public void Slash_w_slash() { // PURPOSE: /B/ should show B, not /B; DATE:2014-01-02 + fxt.Page_ttl_("A"); + fxt.Test_parse_page_wiki_str + ( "[[/B/]]", String_.Concat_lines_nl_skip_last + ( "B" + )); + } + @Test public void Leaf_w_ncr() { // PURPOSE: /Bc should not encode c PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07 + fxt.Page_ttl_("A"); + fxt.Test_parse_page_wiki_str + ( "[[/Bc|B]]", String_.Concat_lines_nl_skip_last + ( "B" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__uncommon_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__uncommon_tst.java new file mode 100644 index 000000000..7061672b9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__uncommon_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; +public class Xop_lnki_wkr__uncommon_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Double_bracket() { // PURPOSE: handle [[[[A]]]] constructions; PAGE:ru.w:Меркатале_ин_Валь_ди_Песа; DATE:2014-02-04 + fxt.Test_parse_page_all_str("[[[[Test_1]]]]" , "[[Test_1]]"); + } + @Test public void Single_bracket() { // PURPOSE: handle [[A|[b]]] PAGE:en.w:Aubervilliers DATE:2014-06-25 + fxt.Test_html_full_str("[[A|[B]]]", "[B]"); + } + @Test public void Triple_bracket() { // PURPOSE: "]]]" shouldn't invalidate tkn; PAGE:en.w:Tall_poppy_syndrome; DATE:2014-07-23 + fxt.Test_parse_page_all_str("[[A]]]" , "A]"); // title only + fxt.Test_parse_page_all_str("[[A|B]]]" , "B]"); // title + caption; note that ] should be outside b/c MW has more logic that says "if caption starts with '['", but leaving as is; DATE:2014-07-23 + } + @Test public void Triple_bracket_with_lnke_lnki() { // PURPOSE: handle [http://a.org [[File:A.png|123px]]]; PAGE:ar.w:محمد DATE:2014-08-20 + fxt.Test_parse_page_all_str("[http://a.org [[File:A.png|123px]]]" + , "\"\"" + ); + } + @Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/0000–0FFF; DATE:2014-05-05 + fxt.Test_parse_page_all_str("[[A|B|C|D]]" , "B|C|D"); + } + @Test public void Multiple_captions_file() { // PURPOSE: multiple captions should take last; EX:none; DATE:2014-05-05 + fxt.Test_html_wiki_frag("[[File:A|B|C|D|thumb]]" , "

      D\n
      "); + } + @Test public void Multiple_captions_pipe() { // PURPOSE.fix: multiple captions caused multiple pipes; PAGE:w:Wikipedia:Administrators'_noticeboard/IncidentArchive24; DATE:2014-06-08 + fxt.Test_parse_page_all_str("[[a|b|c d e]]", "b|c d e"); // was b|c| |d| |e + } + @Test public void Toc_fails() { // PURPOSE: null ref when writing hdr with lnki inside xnde; EX:pl.d:head_sth_off;DATE:2014-05-07 + fxt.Test_parse_page_all_str("== [[A]] ==", "

      A

      \n"); + } + @Test public void Upright_is_large() { // PURPOSE: handle large upright which overflows int; PAGE:de.w:Feuerland DATE:2015-02-03 + fxt.Test_html_wiki_frag("[[File:A.png|upright=1.333333333333333333333333333333333333333333333333333333333333333333333]]", " width=\"0\" height=\"0\""); // failure would print out original lnki + } + @Test public void Persian() { // PURPOSE: handle il8n nums; EX:[[پرونده:Shahbazi 3.jpg|۲۰۰px]] -> 200px; PAGE:fa.w:فهرست_آثار_علیرضا_شاپور_شهبازی; DATE:2015-07-18 + Xol_lang_itm lang = fxt.Wiki().Lang(); + fxt.App().Gfs_mgr().Run_str_for(lang, gplx.xowa.xtns.pfuncs.numbers.Pf_formatnum_fa_tst.Persian_numbers_gfs); + lang.Evt_lang_changed(); // force rebuild of size_trie + fxt.Test_html_wiki_frag("[[File:A.png|۲۰۰px]]", " width=\"200\" height=\"0\""); + } +} + diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__video_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__video_tst.java new file mode 100644 index 000000000..5094681c9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__video_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xop_lnki_wkr__video_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Thumbtime() { + fxt.Test_parse_page_wiki("[[File:A.ogv|thumbtime=123]]" , fxt.tkn_lnki_().Thumbtime_(123)); + fxt.Test_parse_page_wiki("[[File:A.ogv|thumbtime=1:23]]" , fxt.tkn_lnki_().Thumbtime_(83)); + fxt.Test_parse_page_wiki("[[File:A.ogv|thumbtime=1:01:01]]" , fxt.tkn_lnki_().Thumbtime_(3661)); + fxt.Init_log_(Xop_lnki_log.Upright_val_is_invalid).Test_parse_page_wiki("[[File:A.ogv|thumbtime=a]]", fxt.tkn_lnki_().Thumbtime_(-1)); + } + @Test public void Size__null() { // NOTE: make sure that no size defaults to -1; needed for Xof_img_size logic of defaulting -1 to orig_w; DATE:2015-08-07 + fxt.Test_parse_page_wiki("[[File:A.ogv]]" , fxt.tkn_lnki_().Width_(Xof_img_size.Size__neg1)); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__xwiki_tst.java b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__xwiki_tst.java new file mode 100644 index 000000000..729550661 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/lnkis/Xop_lnki_wkr__xwiki_tst.java @@ -0,0 +1,113 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_lnki_wkr__xwiki_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt(); + @Test public void Xwiki_file() { // PURPOSE: if xwiki and File, ignore xwiki (hackish); DATE:2013-12-22 + Reg_xwiki_alias("test", "test.wikimedia.org"); // must register xwiki, else ttl will not parse it + fxt.Wiki().Cfg_parser().Lnki_cfg().Xwiki_repo_mgr().Add_or_mod(Bry_.new_a7("test")); // must add to xwiki_repo_mgr + fxt.Test_parse_page_wiki_str + ( "[[test:File:A.png|12x10px]]", String_.Concat_lines_nl_skip_last + ( "\"\"" + )); + fxt.Wiki().Cfg_parser_lnki_xwiki_repos_enabled_(false); // disable for other tests + } + @Test public void Xwiki_anchor() { + Reg_xwiki_alias("test", "test.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[test:A#b]]", String_.Concat_lines_nl_skip_last + ( "test:A#b" + )); + } + @Test public void Xwiki_empty() { + Reg_xwiki_alias("test", "test.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[test:]]", String_.Concat_lines_nl_skip_last + ( "test:" + )); + } + @Test public void Xwiki_empty_literal() { + Reg_xwiki_alias("test", "test.wikimedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[:test:]]", String_.Concat_lines_nl_skip_last + ( "test:" + )); + } + @Test public void Xwiki_not_registered() { + fxt.App().Usere().Wiki().Xwiki_mgr().Clear(); + fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_a7("test"), Bry_.new_a7("test.wikimedia.org")); // register alias only, but not in user_wiki + fxt.Test_parse_page_wiki_str + ( "[[test:A|A]]", String_.Concat_lines_nl_skip_last + ( "A" + )); + } + @Test public void Literal_lang() { + Reg_xwiki_alias("fr", "fr.wikipedia.org"); + fxt.Test_parse_page_wiki_str + ( "[[:fr:A]]", String_.Concat_lines_nl_skip_last + ( "A" + )); + Tfds.Eq(0, fxt.Page().Slink_list().Count()); + } + @Test public void Simple_and_english() { // PURPOSE: s.w xwiki links to en were not working b/c s.w and en had same super lang of English; PAGE:s.q:Anonymous DATE:2014-09-10 + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "simple.wikipedia.org"); + fxt = new Xop_fxt(app, wiki); // change fxt to simple.wikipedia.org + Reg_xwiki_alias("en", "en.wikipedia.org"); // register "en" alias + fxt.Test_parse_page_wiki_str // test nothing printed + ( "[[en:A]]" + , "" + ); + Tfds.Eq(1, fxt.Page().Slink_list().Count()); // test 1 xwiki lang + } + @Test public void Species_and_commons() { // PURPOSE: species xwiki links to commons should not put link in wikidata langs; PAGE:species:Scarabaeidae DATE:2014-09-10 + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "species.wikimedia.org"); + fxt = new Xop_fxt(app, wiki); // change fxt to species.wikimedia.org + Reg_xwiki_alias("commons", "commons.wikimedia.org"); // register "en" alias + fxt.Test_parse_page_wiki_str // test something printed + ( "[[commons:A]]" + , "commons:A" + ); + Tfds.Eq(0, fxt.Page().Slink_list().Count()); // no xwiki langs + } + @Test public void Wiktionary_and_wikipedia() { // PURPOSE: do not create xwiki links if same lang and differet type; PAGE:s.d:water DATE:2014-09-14 + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "simple.wiktionary.org"); + fxt = new Xop_fxt(app, wiki); // change fxt to simple.wiktionary.org + Reg_xwiki_alias("w", "simple.wikipedia.org"); // register "w" alias + fxt.Test_parse_page_wiki_str // test something printed + ( "[[w:A]]" + , "w:A" + ); + Tfds.Eq(0, fxt.Page().Slink_list().Count()); // test 0 xwiki lang + } + @Test public void Species_and_wikipedia() { // PURPOSE: species creates xwiki links to wikipedia; PAGE:species:Puccinia DATE:2014-09-14 + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "species.wikimedia.org"); + fxt = new Xop_fxt(app, wiki); // change fxt to species.wikimedia.org + Reg_xwiki_alias("fr", "fr.wikipedia.org"); // register "fr" alias + fxt.Test_parse_page_wiki_str // nothing printed + ( "[[fr:A]]" + , "" + ); + Tfds.Eq(1, fxt.Page().Slink_list().Count()); // 1 xwiki lang + } + private void Reg_xwiki_alias(String alias, String domain) { + Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), alias, domain); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_comm_lxr_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_comm_lxr_tst.java new file mode 100644 index 000000000..c90cb58a7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_comm_lxr_tst.java @@ -0,0 +1,100 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_comm_lxr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_parse_page_all_str("ac", "ac"); + } + @Test public void Err() { + fxt.Init_log_(Xop_comm_log.Eos).Test_parse_page_all_str(" " + , "c" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "c" + )); + } + @Test public void Ws_bgn_end() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " " + , "c" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "c" + )); + } + @Test public void Ws_noop() { // PURPOSE: assert that comments do not strip ws + fxt.Test_parse_page_all_str("a c", "a c"); + } + @Test public void Noinclude() {// PURPOSE: templates can construct comments; EX:WBK: {{Subjects/allbooks|subject=Computer programming|origin=Computer programming languages|diagnose=}} + fxt.Test_parse_page_all_str("a - b -->c", "a c"); + } + @Test public void Comment_can_cause_pre() {// PURPOSE: assert that comment causes pre; DATE:2014-02-18 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " c" + , "d" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      c"
      +		, "
      " + , "" + , "

      d" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Ws_bgn_needs_nl() { // PURPOSE: do not strip new line unles *entire* line is comment + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " " + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "c" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Ws_strip_nl() { // PURPOSE: handle multiple "\n"; was only trimming 1st; DATE:2014-02-24 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "" + , "b" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "b" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_basic_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_basic_tst.java new file mode 100644 index 000000000..99ba91c36 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_basic_tst.java @@ -0,0 +1,29 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_hr_lxr_basic_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() {fxt.Test_parse_page_wiki("----" , fxt.tkn_hr_(0, 4));} + @Test public void Basic_w_nl() {fxt.Test_parse_page_wiki("\n----a" , fxt.tkn_para_blank_(0), fxt.tkn_hr_(0, 5), fxt.tkn_txt_(5, 6));} + @Test public void Many() {fxt.Test_parse_page_wiki("---------" , fxt.tkn_hr_(0, 9).Hr_len_(9));} + @Test public void Exc_short() {fxt.Test_parse_page_wiki("---" , fxt.tkn_txt_(0, 3));} + @Test public void Exc_interrupt() {fxt.Test_parse_page_wiki("\na----" , fxt.tkn_nl_char_len1_(0), fxt.tkn_txt_(1, 6));} + @Test public void Html_basic() {fxt.Test_parse_page_wiki_str("----" , "
      ");} + @Test public void Html_extended() {fxt.Test_parse_page_wiki_str("------" , "
      ");} + @Test public void Nl_bgn() {fxt.Test_parse_page_wiki_str("a\n----" , "a\n
      ");} + @Test public void Nl_end() {fxt.Test_parse_page_wiki_str("----\na" , "
      \na");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_para_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_para_tst.java new file mode 100644 index 000000000..dd1e5ad59 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_hr_lxr_para_tst.java @@ -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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_hr_lxr_para_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Bos() { // PURPOSE: check that bos rendered correctly; DATE:2014-04-18 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "----" + , "a" + ), String_.Concat_lines_nl_skip_last + ( "
      " + , "" + , "

      a" + , "

      " + )); + } + @Test public void Multiple() { // PURPOSE.fix: hr disables para for rest of page; ca.b:Xarxes; DATE:2014-04-18 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "----" + , "b" + , "" + , "" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "
      " + , "" + , "

      b" + , "

      " + , "" + , "


      " + , "c" + , "

      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_space_lxr_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_space_lxr_tst.java new file mode 100644 index 000000000..357e4077c --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_space_lxr_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_space_lxr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @After public void term() {fxt.Init_para_n_();} + @Test public void Toc_basic() { // PURPOSE: make sure nbsp char is not converted to space; PAGE:en.w:Macedonian–Carthaginian_Treaty; DATE:2014-06-07 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str("     a", String_.Concat_lines_nl_skip_last // NOTE: ws is actually nbsp; + ( "

           a" // should be

      not

      "); +// fxt.Test_parse_page_all_str +// ( "{{pre2|a}}" +// , String_.Concat_lines_nl_skip_last +// ( "
      a
      " +// )); +// } + @Test public void Noinclude_inline_w_space_inside_safesubst() { // PURPOSE: "" did not work with safesubst b/c of space; PAGE:en.w:Wikipedia:Featured_picture_candidates; DATE:2014-06-24 + fxt.Test_parse_tmpl_str_test("{{SAFESUBST:#if:val_exists|y|n}}", "{{test}}", "y"); + } + @Test public void Subst() {// PURPOSE: handle subst-includeonly-subst combination; PAGE:pt.w:Argentina DATE:2014-09-24 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "{{subst:#switch:1|1=y|default=n}}"); + //fxt.Init_defn_add("test", "{{subst:#switch:1|1=y|default=n}}"); // keeping around for debugging purposes + //fxt.Init_defn_add("test", "{{#switch:1|1=y|default=n}}"); // keeping around for debugging purposes + fxt.Test_parse_page_all_str("{{test}}", "{{subst:#switch:1|1=y|default=n}}"); // note that subst is preserved b/c of + fxt.Test_parse_page_all_str("{{subst:test}}", "y"); // note that expression is evaluated b/c of subst: + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__li_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__li_tst.java new file mode 100644 index 000000000..273e1becf --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__li_tst.java @@ -0,0 +1,102 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__li_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Inside_tblx() { // PURPOSE: auto-close
    • (EX: "
    • a
    • ") was causing 3rd
    • to close incorrectly + fxt.Test_parse_page_wiki_str + ( "
      • a
      • b
      • c
      " + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        " + , "
      • a
      • " + , "
      • b
      • " + , "
      • c
      " + , "
      " + , "" + )); + } + @Test public void Li_nested_inside_ul() { // PURPOSE: nested li in ul should not be escaped; DATE:2013-12-04 + fxt.Test_parse_page_wiki_str + ( "
      • a
        • b
      " + , String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a
          " + , "
        • b
      " // note that
    • b becomes
    • <li>b but
      • b should stay the same + )); + } + @Test public void Empty_ignored() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        • b" + , "
        • " + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        • b" + , "
        • " + , "
        " + )); + } + @Test public void Empty_ignored_error() { // PAGE:en.w:Sukhoi_Su-47; "*
      • " causes error b/c tries to close non-existent node + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "* a" + , "* " + ), String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a" + , "
        • " + , "
        • " // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + , " " + , "
        " + )); + } + @Test public void Insert_nl() {// PURPOSE:
      • should always be separated by nl, or else items will merge, creating long horizontal scroll bar; EX:w:Music + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str("
        • a
        • b
        " + , String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • a
        • " + , "
        • b
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Duplicate() { // PURPOSE: redundant li; EX: "*
      • "; PAGE:it.w:Milano#Bibliographie; DATE:2013-07-23 + fxt.Test_parse_page_all_str("*
      • x
      • ", String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • " + , "
        • x
        • " // TIDY: duplicate li will be stripped out; DATE:2014-06-26 + , " " + , "
        " + )); + } + @Test public void Dangling_inside_xnde() { // PURPOSE.TIDY: handle "
      • a
      • b"; PAGE:ro.w:Pagina principala; DATE:2014-06-26 + fxt.Test_parse_page_all_str("
      • a
      • b", String_.Concat_lines_nl_skip_last + ( "
      • a" + , "
      • b
      • " // TIDY: will (a) move to 1st line + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__nowiki_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__nowiki_tst.java new file mode 100644 index 000000000..454532400 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__nowiki_tst.java @@ -0,0 +1,142 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__nowiki_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Basic() { + fxt.Test_parse_page_wiki_str + ( "''a''b" + , "''a''b" + ); + } + @Test public void Template() { + fxt.Init_para_y_(); + fxt.Init_defn_add("nowiki_test", "#a"); + fxt.Test_parse_page_all_str + ( "{{nowiki_test}}" + , String_.Concat_lines_nl_skip_last + ( "

        #a" + , "

        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void H2() { // PAGE:en.w:HTML + fxt.Test_parse_page_all_str + ( "a

        b

        c" + , String_.Concat_lines_nl_skip_last + ( "a<h1>b<h6>c" + )); + } + @Test public void Lnke() { // PAGE:en.w:Doomsday_argument; [0, 1] + fxt.Test_parse_page_wiki_str("a [0, 1] b", "a [0, 1] b"); // NOTE: not "0" + Byte_.To_str(160) + "1"; depend on browser to translate   + } + @Test public void Xatrs_val_text() { + fxt.Test_parse_page_all_str + ( "
        a>b
        " + , String_.Concat_lines_nl_skip_last + ( "
        b
        " + )); + } + @Test public void Xatrs_val_quote() { + fxt.Test_parse_page_all_str + ( "
        d
        " + , String_.Concat_lines_nl_skip_last + ( "
        d
        " + )); + } + @Test public void Xatrs_eq() { + fxt.Test_parse_page_all_str("
          =\"a\" class=\"b\">
        • d
        ", String_.Concat_lines_nl_skip_last + ( "
          " + , "
        • d
        " + )); + } + @Test public void Tblw_atr() {// PURPOSE: nowiki breaks token + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|style=\"background-color:#FFCC99\"" + , "|a" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        a" + , "
        " + , "" + )); + } + @Test public void Prex() { // PURPOSE: nowikis inside pre should be ignored; DATE:2013-03-30 + fxt.Test_parse_page_all_str("
        a<b
        " , "
        a<b
        "); // basic + fxt.Test_parse_page_all_str("
        a<b
        " , "
        a<nowiki><<nowiki>b
        "); // not closed + fxt.Test_parse_page_all_str("
        abc
        " , "
        <nowiki>abc</nowiki>
        "); // nested; this is wrong, but leave for now; should be abc + } + @Test public void Prew() { // PURPOSE: space inside nowiki should be ignored; ru.b:Rubyn DATE:2014-07-03 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( " a" + , " " // note that "\s" must remain "\s" so that
         continues uninterrupted
        +		), String_.Concat_lines_nl
        +		( "
        a"
        +		, "<b></b>"
        +		, "
        " + ) + ); + fxt.Init_para_n_(); + } + @Test public void Prew_2() { // PURPOSE: prew should continue over nowiki, even if no space DATE:2014-07-03 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( " a" + , "b" // note that "b" should be in pre b/c it is part of which is pre'd (even though there is no \n\s) + ), String_.Concat_lines_nl + ( "
        a"
        +		, "b"
        +		, "
        " + ) + ); + fxt.Init_para_n_(); + } + @Test public void Code() { // PURPOSE.fix:HtmlNcr-escaped refs were being ignored; caused by HtmlTidy fix for frwiki templates;DATE:2013-06-27 + fxt.Test_parse_page_all_str("|:", "|:"); + } + @Test public void Brack_end() { // PURPOSE: check that "]" is escaped; PAGE:en.w:Tall_poppy_syndrome; DATE:2014-07-23 + fxt.Test_parse_page_all_str + ( "[[[A]]]" + , "[A]"); // was showing up as [[[A]]] + } + @Test public void Tblw_tr() { // PURPOSE: dash should be escaped in nowiki PAGE:de.w:Liste_von_Vereinen_und_Vereinigungen_von_Gläubigen_(römisch-katholische_Kirche) DATE:2015-01-08 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "|-" // do not treat as "|-" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
        a" + , " -" // "|" creates ; "-" is rendered literally + , "
        " + , "" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tblx_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tblx_tst.java new file mode 100644 index 000000000..547d071de --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tblx_tst.java @@ -0,0 +1,78 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__tblx_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Table() { + fxt.Test_parse_page_wiki("a
        b
        c" + , fxt.tkn_txt_ ( 0, 1) + , fxt.tkn_tblw_tb_(1, 35).Subs_ + ( fxt.tkn_tblw_tr_(8, 27).Subs_ + ( fxt.tkn_tblw_td_(12, 22).Subs_(fxt.tkn_txt_(16, 17)) + ) + ) + , fxt.tkn_txt_ (35, 36) + ); + } + @Test public void Ws_bgn() { // PURPOSE: some templates return leading ws; PAGE:en.w:UK + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " " + , " " + , " " + , " " + , "
        a" + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        a" + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Td_in_lnki_should_be_ignored() {// PURPOSE: \n| inside lnki should not be interpreted as table cell; EX: uk.w:Дніпро; DATE:2014-03-11 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
        " + , "[[File:A.png|150px" + , "|B]]
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        " + , "\"B\"" + , "
        " + )); + fxt.Init_para_n_(); + } + @Test public void Nl() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str + ( "\n\n\n\n\n
        " + , "\n" + + "
        \n" + ); + fxt.Init_para_n_(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__text_block_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__text_block_tst.java new file mode 100644 index 000000000..1cc42d491 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__text_block_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__text_block_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Source_wikitext() { // PURPOSE.ASSERT: wikitext should be rendered literally; DATE:2014-03-11 + fxt.Test_parse_page_wiki_str("''a''", "
        ''a''
        "); + } + @Test public void Source_nowiki() { // PURPOSE.ASSERT: onlyinclude should be rendered literally; DATE:2014-03-11 + fxt.Test_parse_page_wiki_str("a", "
        <onlyinclude>a</onlyinclude>
        "); + } + @Test public void Source_escape() { + fxt.Test_parse_page_wiki_str("", "
        <b>
        "); + } + @Test public void Source_escape_amp() { // PURPOSE: < should be rendered as &lt; PAGE:uk.b:HTML; DATE:2014-03-11 + fxt.Test_parse_page_wiki_str("<", "
        &lt;
        "); + } + @Test public void Source_pre() { // PURPOSE: handle pre; PAGE:en.w:Comment_(computer_programming); DATE:2014-06-23 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " " + , " a" + , " " + ), String_.Concat_lines_nl_skip_last + ( "
        "
        +		, "  a"
        +		, "
        " + )); + fxt.Init_para_n_(); + } + @Test public void Code_dangling() { // PAGE:en.w:HTML; <i> and <center> tags. There are + fxt.Test_parse_page_wiki_str("abc", "abc"); + } + @Test public void Code_do_not_escape() { // PURPOSE: was mistakenly marked as escape, causing inner tags to be rendered incorrectly; PAGE:en.w:UTF8 + fxt.Test_parse_page_all_str + ( "0100100" + , "0100100" + ); + } + @Test public void Pre_and_html_chars() {// PURPOSE:
         should handle '"<> according to context
        +		fxt.Test_parse_page_all_str("
        a	b
        " , "
        a	b
        "); // known ncr/dec; embed and depend on browser transforming; EX: de.w:Wikipedia:Technik/Skin/Werkstatt + fxt.Test_parse_page_all_str("
        a�b
        " , "
        a&#9999999999;b
        "); // unknown ncr/dec; escape & (since browser cannot render); + fxt.Test_parse_page_all_str("
        a&#af ;b
        " , "
        a&#af ;b
        "); // unknown ncr/dec 2 + fxt.Test_parse_page_all_str("
        a	b
        " , "
        a	b
        "); // known ncr/hex + fxt.Test_parse_page_all_str("
        a'b
        " , "
        a'b
        "); // known name; embed + fxt.Test_parse_page_all_str("
        a&apox;b
        " , "
        a&apox;b
        "); // unknown name; escape + fxt.Test_parse_page_all_str("
        &\"<>
        " , "
        &"<>
        "); // no ncr or name; escape; needed for
        ; PAGE:en.w:Alt attribute + } + @Test public void Pre_and_space() {// PURPOSE: make sure pre does not careate

        around it; also, make sure " a" is preserved; DATE:2014-02-20 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
        "
        +		, " a"
        +		, "
        " + ), String_.Concat_lines_nl_skip_last + ( "
        "
        +		, " a"
        +		, "
        " + )); + fxt.Init_para_n_(); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tidy_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tidy_tst.java new file mode 100644 index 000000000..7cb8cd37a --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__tidy_tst.java @@ -0,0 +1,44 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__tidy_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Sub_sup_autocorrect() { + fxt.Test_parse_page_wiki_str("ab", "ab"); + fxt.Test_parse_page_wiki_str("ab", "ab"); + } + @Test public void Span_font_autocorrect() { // PURPOSE: force
        to close ; EX:w:Rupee; DATE:2014-04-07 + fxt.Test_parse_page_wiki_str("ab", "ab"); + } + @Test public void Move_ws_char() { + fxt.Test_parse_page_all_str("a b c", "a b c"); + } + @Test public void Move_ws_ent() { + fxt.Test_parse_page_all_str("a b c", "a b c"); + } + @Test public void Ignore_empty_tags() { // PURPOSE: ignore tag if marked ignore_empty; EX:uk.b:HTML; DATE:2014-03-12 + fxt.Test_parse_page_all_str("a
        b", "ab");
        +	}
        +//		@Test  public void Escaped_div() {	// NOTE: WP 
        a
        b; MW:
        a
        b
        // REVISIT: 2012-05-11; WP does harder split-span +// fxt.Init_log_(Xop_xnde_log.Auto_closing_section, Xop_xnde_log.Escaped_xnde).Test_parse_page_wiki("
        " +// , fxt.tkn_xnde_(0, 17).Subs_ +// ( fxt.tkn_xnde_(5, 11)) +// , fxt.tkn_ignore_(17, 24) +// ); +// } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__xatrs_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__xatrs_tst.java new file mode 100644 index 000000000..9cdde21e1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__xatrs_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__xatrs_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Inline() { + fxt.Test_parse_page_wiki("" , fxt.tkn_xnde_(0, 15).Atrs_rng_(5, 13)); + fxt.Test_parse_page_wiki("" , fxt.tkn_xnde_(0, 21).Atrs_rng_(5, 19)); // ws + } + @Test public void Bgn() { + fxt.Test_parse_page_wiki("
        " , fxt.tkn_xnde_(0, 19).Atrs_rng_(5, 12)); // basic + } + @Test public void Repeated() { // PURPOSE: if atr is repeated, take 1st, not last; EX: it.u:Dipartimento:Fisica_e_Astronomia; DATE:2014-02-09 + fxt.Test_parse_page_all_str("a" , "a"); // two + fxt.Test_parse_page_all_str("a" , "a"); // three + } + @Test public void Non_ws() { // PURPOSE: is valid; symbols function as ws + fxt.Test_parse_page_wiki("" , fxt.tkn_xnde_(0, 7).Atrs_rng_(3, 5)); + } + @Test public void Invalid() { // PURPOSE: make sure brx does not match br + fxt.Test_parse_page_wiki("" , fxt.tkn_bry_(0, 1), fxt.tkn_txt_(1, 6)); + } + @Test public void Id_encode() { + fxt.Test_parse_page_all_str("
        ", "
        "); + } + @Test public void Lt_should_not_be_escaped_in_input() { // PURPOSE: options textboxes were escaped if input's value had "<"; DATE:2014-07-04 + fxt.Page().Html_data().Html_restricted_n_(); + fxt.Test_parse_page_wiki_str("", ""); // NOTE: do not call parse_page_all_str which will call Page.Clear and reset Restricted + fxt.Page().Html_data().Html_restricted_y_(); + } + @Test public void Style__decode() { // PURPOSE: style values should be decoded; PAGE:en.w:Boron; DATE:2015-07-29 + fxt.Test_parse_page_all_str("a", "a"); + } +// @Test public void Unclosed() { // PURPOSE: unclosed atr should be treated as key, which should be ignored; PAGE:en.w:Palace of Versailles +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "a" // id="1� -> key named 'id="1�' which fails whitelist keys +// , "" +// ), String_.Concat_lines_nl_skip_last +// ( "a" +// , "" +// )); +// } +} diff --git a/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages_tst.java b/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages_tst.java new file mode 100644 index 000000000..1f8090f21 --- /dev/null +++ b/400_xowa/src/gplx/xowa/specials/allPages/Xows_page_allpages_tst.java @@ -0,0 +1,204 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.specials.allPages; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; +import org.junit.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.data.tbls.*; +import gplx.xowa.wikis.nss.*; +import gplx.xowa.wikis.tdbs.hives.*; +public class Xows_page_allpages_tst { + @Before public void init() {fxt.Clear();} private Xows_page_allpages_fxt fxt = new Xows_page_allpages_fxt(); + @Test public void Build_data() { + Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 5, 7); + fxt.Clear().Init_ttl_leaf("/B1").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // SpecialPage:AllPages/B1 + fxt.Clear().Init_arg("from", "B1").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // single file + fxt.Clear().Init_arg("from", "A6").Expd_prv("A1").Expd_nxt("B4").Expd_ttls("A6", "B0", "B1", "B2", "B3").Test_build_data(); // overflow rhs + fxt.Clear().Init_arg("from", "E4").Expd_prv("D6").Expd_nxt("E6").Expd_ttls("E4", "E5", "E6", null, null).Test_build_data(); // bounds rhs + fxt.Clear().Init_arg("from", "A0").Expd_prv("A0").Expd_nxt("A5").Expd_ttls("A0", "A1", "A2", "A3", "A4").Test_build_data(); // bounds lhs + fxt.Clear().Init_arg("from", "B0a").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // inexact match; B0a matches "hi" value + fxt.Clear().Init_arg("from", "B1").Init_arg("hideredirects", "1").Expd_prv("A0").Expd_nxt("C4").Expd_ttls("B2", "B4", "B6", "C0", "C2").Test_build_data(); // hide redirects + fxt.Clear().Init_arg("from", "A6").Expd_prv("A0").Expd_nxt("E1").Init_itms_per_page(23).Expd_ttls("A6", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "E0").Test_build_data(); // overflow rhs x2 + } + @Test public void Build_html_main() { + Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 5, 7); + fxt.Clear().Init_arg("from", "B2").Init_itms_per_page(5).Test_build_html(String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
        " + , "Previous page (A4) |" + , "Next page (C0)" + , "
        " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "" + , "
        B2B4
        B6
        " + , "
        " + , "
        " + , "Previous page (A4) |" + , "Next page (C0)" + , "
        " + )); + } + @Test public void Build_html_redirect() { + Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 1, 7); + fxt.Clear().Init_arg("from", "A2").Init_arg("hideredirects", "1").Init_itms_per_page(2).Test_build_html(String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
        " + , "Previous page (A0) |" + , "Next page (A6)" + , "
        " + , "" + , "" + , " " + , " " + , " " + , " " + , "" + , "
        A2A4
        " + , "
        " + , "
        " + , "Previous page (A0) |" + , "Next page (A6)" + , "
        " + )); + } + @Test public void Build_html_ns() { + Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), fxt.Wiki().Ns_mgr().Ns_template(), 1, 7); + fxt.Clear().Init_arg("from", "A2").Init_arg("namespace", "10").Init_itms_per_page(2).Test_build_html(String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
        " + , "Previous page (Template:A0) |" + , "Next page (Template:A4)" + , "
        " + , "" + , "" + , " " + , " " + , " " + , " " + , "" + , "
        Template:A2
        " + , "
        " + , "" + )); + } + @Test public void Misc() { + Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), fxt.Wiki().Ns_mgr().Ns_template(), 1, 7); + fxt.Clear().Init_arg("from", "Template:B1").Expd_arg("from", "B1").Expd_arg("namespace", "10").Test_build_data(); // extract ns from ttl + fxt.Clear().Init_arg("from", "Template:B1").Expd_display_ttl("All pages").Expd_address_page("Special:AllPages").Test_special_gen(); // display ttl + } +} +class Xows_page_allpages_fxt { + public Xows_page_allpages_fxt Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + allpages = wiki.Special_mgr().Page_allpages(); + Gfo_invk_.Invk_by_val(allpages, Xows_page_allpages.Invk_itms_per_page_, 5); + } + init_ttl_leaf = ""; + expd_prv = expd_nxt = null; + expd_ttls = null; + expd_display_ttl = null; + return this; + } private Xoae_app app; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; Xows_page_allpages allpages; + public Xows_page_allpages_fxt Init_arg(String key, String val) {init_args.Add(new Gfo_qarg_itm(Bry_.new_a7(key), Bry_.new_a7(val))); return this;} private List_adp init_args = List_adp_.New(); + public Xows_page_allpages_fxt Init_ttl_leaf(String val) {init_ttl_leaf = val; return this;} private String init_ttl_leaf; + public Xows_page_allpages_fxt Init_itms_per_page(int v) {init_itms_per_page = v; return this;} private int init_itms_per_page = 5; + public Xows_page_allpages_fxt Expd_arg(String key, String val) {expd_args.Add(new Gfo_qarg_itm(Bry_.new_a7(key), Bry_.new_a7(val))); return this;} private List_adp expd_args = List_adp_.New(); + public Xows_page_allpages_fxt Expd_prv(String v) {expd_prv = v; return this;} private String expd_prv; + public Xows_page_allpages_fxt Expd_nxt(String v) {expd_nxt = v; return this;} private String expd_nxt; + public Xows_page_allpages_fxt Expd_ttls(String... v) {expd_ttls = v; return this;} private String[] expd_ttls; + public Xows_page_allpages_fxt Expd_display_ttl(String v) {expd_display_ttl = v; return this;} private String expd_display_ttl; + public Xows_page_allpages_fxt Expd_address_page(String v) {expd_address_page = v; return this;} private String expd_address_page; + + public static String Xto_str(Xowe_wiki wiki, Xowd_page_itm v) { + if (v == null) return null; + Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(v.Ns_id()); + String ns_str = ns == null ? "" : String_.new_a7(ns.Name_db_w_colon()); + return ns_str + String_.new_a7(v.Ttl_page_db()); + } + public static String[] Xto_str_ary(Xowe_wiki wiki, Xowd_page_itm[] ary) { + int ary_len = ary.length; + String[] rv = new String[ary_len]; + for (int i = 0; i < ary_len; i++) { + Xowd_page_itm itm = ary[i]; + rv[i] = Xto_str(wiki, itm); + } + return rv; + } + public static String[] Xto_str_ary(Gfo_qarg_itm[] ary) { + int ary_len = ary.length; + String[] rv = new String[ary_len]; + for (int i = 0; i < ary_len; i++) { + Gfo_qarg_itm itm = ary[i]; + rv[i] = String_.new_u8(itm.Key_bry()) + "=" + String_.new_u8(itm.Val_bry()); + } + return rv; + } + public Xows_page_allpages_fxt Test_special_gen() { + init_url = app.User().Wikii().Utl__url_parser().Parse(Xow_special_meta_.Itm__all_pages.Ttl_bry()); + Xoa_ttl init_ttl = Make_init_ttl(); + allpages.Special__gen(wiki, wiki.Parser_mgr().Ctx().Page(), init_url, init_ttl); + if (expd_display_ttl != null) Tfds.Eq(expd_display_ttl, String_.new_u8(wiki.Parser_mgr().Ctx().Page().Html_data().Display_ttl())); + if (expd_address_page != null) Tfds.Eq(expd_address_page, String_.new_u8(init_url.Page_bry())); + return this; + } + public Xows_page_allpages_fxt Test_build_data() { + Exec_build(); + if (expd_ttls != null) Tfds.Eq_ary_str(expd_ttls, Xto_str_ary(wiki, allpages.Rslt_list_ttls())); + if (expd_nxt != null) Tfds.Eq(expd_nxt, Xto_str(wiki, allpages.Rslt_nxt())); + if (expd_prv != null) Tfds.Eq(expd_prv, Xto_str(wiki, allpages.Rslt_prv())); + if (expd_args.Count() > 0) { + Gfo_qarg_itm[] expd_args_ary = (Gfo_qarg_itm[])expd_args.To_ary(Gfo_qarg_itm.class); + Tfds.Eq_ary_str(Xto_str_ary(expd_args_ary), Xto_str_ary(init_url.Qargs_ary())); + } + return this; + } private Xoa_url init_url = Xoa_url.blank(); + public Xows_page_allpages_fxt Test_build_html(String expd) { + Exec_build(); + allpages.Build_html(wiki.Parser_mgr().Ctx().Page()); + Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Parser_mgr().Ctx().Page().Db().Text().Text_bry())); + return this; + } + private void Exec_build() { + if (allpages.Itms_per_page() != init_itms_per_page) allpages.Itms_per_page_(init_itms_per_page); + init_url.Qargs_ary_((Gfo_qarg_itm[])init_args.To_ary(Gfo_qarg_itm.class)); + init_args.Clear(); + Xoa_ttl init_ttl = Make_init_ttl(); + allpages.Build_data(init_url, init_ttl); + } + private Xoa_ttl Make_init_ttl() {return Xoa_ttl.Parse(wiki, Bry_.new_u8(Xow_special_meta_.Itm__all_pages.Ttl_str() + init_ttl_leaf));} +} diff --git a/400_xowa/src/gplx/xowa/specials/nearby/Nearby_mgr_tst.java b/400_xowa/src/gplx/xowa/specials/nearby/Nearby_mgr_tst.java new file mode 100644 index 000000000..f13adb913 --- /dev/null +++ b/400_xowa/src/gplx/xowa/specials/nearby/Nearby_mgr_tst.java @@ -0,0 +1,75 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.specials.nearby; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; +import org.junit.*; +public class Nearby_mgr_tst { + @Before public void init() {fxt.Clear();} Nearby_mgr_fxt fxt = new Nearby_mgr_fxt(); + @Test public void Basic() { + fxt.Init_page("A", "[[B]]"); + fxt.Test_find("A", "B", "A|B"); + } + @Test public void Shortest() { + fxt.Init_page("A", "[[B]]"); + fxt.Init_page("B", "[[C]] [[D]]"); + fxt.Init_page("C", "[[D]]"); + fxt.Test_find("A", "D", "A|B|D"); + fxt.Init_results_max(2).Test_find("A", "D", "A|B|D", "A|B|C|D"); + } + @Test public void Circular() { + fxt.Init_page("A", "[[B]]"); + fxt.Init_page("B", "[[C]]"); + fxt.Init_page("C", "[[A]]"); + fxt.Test_find("A", "D", ""); + } + @Test public void Page_doesnt_exist() { + fxt.Init_page("A", "[[B]]"); + fxt.Test_find("A", "C", ""); + } +} +class Nearby_mgr_fxt { + public Nearby_mgr_fxt Clear() { + if (fxt == null) { + fxt = new Xop_fxt(); + nearby_mgr = new Nearby_mgr(); + excluded = Hash_adp_bry.ci_a7(); + tmp_bfr = Bry_bfr_.New(); + } + fxt.Reset(); + Io_mgr.Instance.InitEngine_mem(); + nearby_mgr.Results_max_(1); + return this; + } private Xop_fxt fxt; Nearby_mgr nearby_mgr; Hash_adp_bry excluded; Bry_bfr tmp_bfr; + public void Init_page(String ttl, String text) {fxt.Init_page_create(ttl, text);} + public Nearby_mgr_fxt Init_results_max(int v) {nearby_mgr.Results_max_(v); return this;} + public void Test_find(String src, String trg, String... expd) { + List_adp actl = nearby_mgr.Find_from_to(fxt.Wiki(), Bry_.new_a7(src), Bry_.new_a7(trg), excluded); + Tfds.Eq_ary(String_.SplitLines_nl(Xto_str(actl)), expd); + } + String Xto_str(List_adp list) { + int len = list.Count(); + for (int i = 0; i < len; i++) { + Nearby_rslt rslt = (Nearby_rslt)list.Get_at(i); + int ttls = rslt.Len(); + if (i != 0) tmp_bfr.Add_byte_nl(); + for (int j = 0; j < ttls; j++) { + Xoa_ttl ttl = rslt.Get_at(j); + if (j != 0) tmp_bfr.Add_byte(Byte_ascii.Pipe); + tmp_bfr.Add(ttl.Page_db()); + } + } + return tmp_bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page_tst.java b/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page_tst.java new file mode 100644 index 000000000..5def6f603 --- /dev/null +++ b/400_xowa/src/gplx/xowa/specials/statistics/Xop_statistics_page_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.specials.statistics; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; +import org.junit.*; +public class Xop_statistics_page_tst { +@Before public void init() {fxt.Clear();} private Xop_statistics_page_fxt fxt = new Xop_statistics_page_fxt(); + @Test public void Basic() { + fxt.Test_html(String_.Concat_lines_nl_skip_last + ( "
        " + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
        Page statistics
        Content pages0
        Pages
        All pages in the wiki, including talk pages, redirects, etc.
        0
        Namespace statistics
        " + , "
        " + )); + } +} +class Xop_statistics_page_fxt { + public void Clear() { + parser_fxt = new Xop_fxt(); + parser_fxt.Reset(); + wiki = parser_fxt.Wiki(); + special_page = wiki.Special_mgr().Page_statistics(); + } private Xop_fxt parser_fxt; private Xop_statistics_page special_page; private Xowe_wiki wiki; + public void Test_html(String expd) { + Tfds.Eq_str_lines(expd, String_.new_u8(special_page.Build_html(wiki))); + } +} diff --git a/400_xowa/src/gplx/xowa/users/Xou_user_tst.java b/400_xowa/src/gplx/xowa/users/Xou_user_tst.java new file mode 100644 index 000000000..3da511b04 --- /dev/null +++ b/400_xowa/src/gplx/xowa/users/Xou_user_tst.java @@ -0,0 +1,42 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.users; import gplx.*; import gplx.xowa.*; +import org.junit.*; import gplx.xowa.wikis.xwikis.*; +public class Xou_user_tst { + private final Xou_user_fxt fxt = new Xou_user_fxt(); + @Test public void Available_from_fsys() { + Io_mgr.Instance.CreateDir(fxt.App().Fsys_mgr().Wiki_dir().GenSubDir("en.wikipedia.org")); + fxt.App().Usere().Available_from_fsys(); + fxt.Test_xwikis + ( fxt.Make_xwiki(Bool_.N, "home") + , fxt.Make_xwiki(Bool_.Y, "en.wikipedia.org") // available_from_fsys should mark as offline=y + ); + } +} +class Xou_user_fxt { + public Xoae_app App() {return app;} private Xoae_app app = Xoa_app_fxt.Make__app__edit(); + public String Make_xwiki(boolean offline, String name) {return String_.Concat_with_str("|", Yn.To_str(offline), name);} + public void Test_xwikis(String... expd) { + Xow_xwiki_mgr xwiki_mgr = app.Usere().Wiki().Xwiki_mgr(); + int len = xwiki_mgr.Len(); + String[] actl = new String[len]; + for (int i = 0; i < len; ++i) { + Xow_xwiki_itm xwiki_itm = xwiki_mgr.Get_at(i); + actl[i] = Make_xwiki(xwiki_itm.Offline(), String_.new_u8(xwiki_itm.Domain_name())); + } + Tfds.Eq_ary_str(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java b/400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java new file mode 100644 index 000000000..3c3caf565 --- /dev/null +++ b/400_xowa/src/gplx/xowa/users/data/Xoud_opt_scope_tst.java @@ -0,0 +1,50 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.users.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*; +import org.junit.*; import gplx.xowa.langs.*; +import gplx.xowa.wikis.domains.*; +public class Xoud_opt_scope_tst { + private Xoud_opt_scope_fxt fxt = new Xoud_opt_scope_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Test_parse("en.w" , fxt.Make(Xol_lang_stub_.Id_en, Xow_domain_tid_.Tid__wikipedia)); + fxt.Test_parse("en.*" , fxt.Make(Xol_lang_stub_.Id_en, Xoud_opt_scope.Type_id_wildcard)); + fxt.Test_parse("*.w" , fxt.Make(Xoud_opt_scope.Lang_id_wildcard, Xow_domain_tid_.Tid__wikipedia)); + fxt.Test_parse("" , Xoud_opt_scope.App); + fxt.Test_parse("en.w,fr.d" , fxt.Make(Xol_lang_stub_.Id_en, Xow_domain_tid_.Tid__wikipedia), fxt.Make(Xol_lang_stub_.Id_fr, Xow_domain_tid_.Tid__wiktionary)); + } +} +class Xoud_opt_scope_fxt { + private final Xoud_opt_scope_parser parser = new Xoud_opt_scope_parser(); + public void Clear() { + // Gfo_usr_dlg_.I = Xoa_app_.New__usr_dlg__console(); + } + public Xoud_opt_scope Make(int lang_id, int type_id) {return new Xoud_opt_scope(lang_id, type_id);} + public void Test_parse(String raw, Xoud_opt_scope... expd) { + Xoud_opt_scope[] actl = parser.Parse(Bry_.new_u8(raw)); + Tfds.Eq(To_str(expd), To_str(actl)); + } + private static String To_str(Xoud_opt_scope[] ary) { + Bry_bfr bfr = Bry_bfr_.New(); + int len = ary.length; + for (int i = 0; i < len; ++i) { + Xoud_opt_scope itm = ary[i]; + if (i != 0) bfr.Add_str_a7(","); + bfr.Add_str_a7(itm.To_str()); + } + return bfr.To_str_and_clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/users/history/Xou_history_mgr_tst.java b/400_xowa/src/gplx/xowa/users/history/Xou_history_mgr_tst.java new file mode 100644 index 000000000..1516b7cb2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/users/history/Xou_history_mgr_tst.java @@ -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.xowa.users.history; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*; +import org.junit.*; +public class Xou_history_mgr_tst { + private Xou_history_mgr_fxt fxt = new Xou_history_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Archive() { + Datetime_now.Manual_y_(); // NOTE: each DateTime_.Now() advances clock by 1 min; adding a new Datetime_now.Get() anywhere will throw off times on this test; DATE:2014-04-01 + fxt.Invk(Xou_history_mgr.Invk_current_itms_max_, 4).Invk(Xou_history_mgr.Invk_current_itms_reset_, 2); + fxt.Add_many("A", "B", "C", "D", "E"); + fxt.Save(); + fxt.List_tst("E", "D"); + fxt.Fil_tst("mem/xowa/user/test_user/app/data/history/20010101_001000.000.csv", String_.Concat_lines_nl + ( "20010101 000500.000|20010101 000500.000|1|en.wikipedia.org|C" + , "20010101 000300.000|20010101 000300.000|1|en.wikipedia.org|B" + , "20010101 000100.000|20010101 000100.000|1|en.wikipedia.org|A" + )); + } + @Test public void Normalize() { + fxt.Clear(); + fxt.Add_many("Category:A_B", "Category:A B", "Category:a B", "Category:_A B_"); + fxt.List_tst("Category:A_B"); + } + @Test public void Args() { + fxt.Clear(); + fxt.Add_one("Special:AllPages", "?from=A"); + fxt.List_tst("Special:AllPages?from=A"); + } + @Test public void Remove_nl() { + fxt.Clear(); + fxt.Add_many("Category:A?pagefrom=B\nB"); + fxt.List_tst("Category:A?pagefrom=B"); + } +} +class Xou_history_mgr_fxt { + Xoae_app app; Xowe_wiki wiki; + Xou_history_mgr under; + public void Clear() { + if (app == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + under = app.Usere().History_mgr(); + } + Io_mgr.Instance.DeleteDirDeep(Io_url_.new_dir_("mem/xowa/user/test_user/app/data/history/")); + under.Clear(); + } + public Xou_history_mgr_fxt Add_many(String... ary) { + int ary_len = ary.length; + for (int i = 0; i < ary_len; i++) { + String itm = ary[i]; + Add_one(itm, null); + } + return this; + } + public Xou_history_mgr_fxt Add_one(String ttl_str, String arg_str) { + byte[] ttl_bry = Bry_.new_u8(ttl_str); + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry); + Xoae_page page = Xoae_page.New_test(wiki, ttl); + page.Db().Page().Modified_on_(Datetime_now.Get()); + byte[] url_bry = ttl_bry; + if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_u8(arg_str)); + Xoa_url url = wiki.Utl__url_parser().Parse(url_bry); + page.Url_(url); // set url b/c history_mgr.Add uses url + under.Add(page); + return this; + } + public Xou_history_mgr_fxt List_tst(String... expd) { + int actl_len = under.Len(); + String[] actl = new String[actl_len]; + for (int i = 0; i < actl_len; i++) { + Xou_history_itm itm = under.Get_at(i); + actl[i] = String_.new_u8(itm.Page()); + } + Tfds.Eq_ary_str(expd, actl); + return this; + } + public Xou_history_mgr_fxt Invk(String key, Object v) {Gfo_invk_.Invk_by_val(under, key, v); return this;} + public Xou_history_mgr_fxt Save() {under.Save(app); return this;} + public Xou_history_mgr_fxt Fil_tst(String expd_url, String expd) { + String actl = Io_mgr.Instance.LoadFilStr(expd_url); + Tfds.Eq_str_lines(expd, actl); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/users/wikis/Xofs_url_itm_parser_tst.java b/400_xowa/src/gplx/xowa/users/wikis/Xofs_url_itm_parser_tst.java new file mode 100644 index 000000000..ebbeebdc2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/users/wikis/Xofs_url_itm_parser_tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.users.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.users.*; +import org.junit.*; import gplx.core.envs.*; +public class Xofs_url_itm_parser_tst { + @Before public void init() {fxt.Clear();} private Xofs_url_itm_parser_fxt fxt = new Xofs_url_itm_parser_fxt(); + @Test public void Custom() {fxt.Test_parse_custom("/xowa/wiki/en.wikipedia.org/");} + @Test public void Lnx() {fxt.Init_dir_spr_lnx().Init_name("xowa", "/xowa") .Test_parse("xowa-fs://~{xowa}/bin/any/", "/xowa/bin/any/");} + @Test public void Wnt() {fxt.Init_dir_spr_wnt().Init_name("xowa", "C:\\xowa") .Test_parse("xowa-fs://~{xowa}/bin/any/", "C:\\xowa\\bin\\any\\");} + @Test public void Outliers() { + fxt.Init_name("xowa", "/xowa"); + fxt.Test_parse("xowa-fs://ab" , "ab"); // no subst + fxt.Test_parse("xowa-fs://a~b" , "a~b"); // tilde + fxt.Test_parse("xowa-fs://a~{~{b" , "a~{b"); // escape + fxt.Test_parse("xowa-fs://ab~" , "ab~"); // eos + fxt.Test_parse("xowa-fs://ab~{~{" , "ab~{"); // eos + } +} +class Xofs_url_itm_parser_fxt { + private Xofs_url_itm_parser parser; + private Xofs_url_itm itm = new Xofs_url_itm(); + public void Clear() { + parser = new Xofs_url_itm_parser(); + } + public Xofs_url_itm_parser_fxt Init_name(String key, String val) {parser.Names_add(key, val); return this;} + public Xofs_url_itm_parser_fxt Init_dir_spr_lnx() {parser.Dir_spr_(Op_sys.Lnx.Fsys_dir_spr_byte()); return this;} + public Xofs_url_itm_parser_fxt Init_dir_spr_wnt() {parser.Dir_spr_(Op_sys.Wnt.Fsys_dir_spr_byte()); return this;} + public void Test_parse_custom(String raw) { + parser.Parse(itm, raw); + Tfds.Eq(Bool_.N, itm.Tid_is_xowa()); + Tfds.Eq(raw, itm.Url()); + } + public void Test_parse(String raw, String expd) { + parser.Parse(itm, raw); + Tfds.Eq(Bool_.Y, itm.Tid_is_xowa()); + Tfds.Eq(expd, itm.Url()); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java new file mode 100644 index 000000000..a9c73f8cc --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/data/Xow_data_mgr_tst.java @@ -0,0 +1,162 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; import gplx.xowa.wikis.tdbs.*; +import gplx.xowa.wikis.nss.*; +public class Xow_data_mgr_tst { + Xow_data_mgr_fxt fxt = new Xow_data_mgr_fxt(); + @Before public void init() {fxt.Clear(); Datetime_now.Manual_y_();} + @After public void term() {Datetime_now.Manual_n_();} + @Test public void Create() { + fxt .Create("A1", "A1 data") + .Create("B12", "B12 data") + .Create("C123", "C123 data") + .Tst_regy_title("0|A1|C123|3\n") + .Tst_data_title(String_.Concat_lines_nl + ( "!!!!>|!!!!?|!!!!@|" + , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1" + , "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12" + , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123" + )) + .Tst_data_page(String_.Concat_lines_nl + ( "!!!!9|!!!!;|!!!!=|" + , "!!!!!\t##PX+\tA1\tA1 data\t" + , "!!!!\"\t##PX/\tB12\tB12 data\t" + , "!!!!#\t##PX0\tC123\tC123 data\t" + )) + ; + } + @Test public void Update() { + fxt .Create("A1", "A1 data") + .Create("B12", "B12 data") + .Create("C123", "C123 data") + .Update("B12", "B12 changed") + .Tst_regy_title("0|A1|C123|3\n") + .Tst_data_title(String_.Concat_lines_nl + ( "!!!!>|!!!!?|!!!!@|" + , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1" + , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12" + , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123" + )) + .Tst_data_page(String_.Concat_lines_nl + ( "!!!!9|!!!!>|!!!!=|" + , "!!!!!\t##PX+\tA1\tA1 data\t" + , "!!!!\"\t##PX/\tB12\tB12 changed\t" + , "!!!!#\t##PX0\tC123\tC123 data\t" + )) + ; + } + @Test public void Update_zip() { +// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.streams.Io_stream_tid_.Tid__zip); +// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok()); +// fxt .Create("A1", "A1 data") +// .Create("B12", "B12 data") +// .Create("C123", "C123 data") +// .Update("B12", "B12 changed") +// .Tst_regy_title("0|A1|C123|3\n") +// .Tst_data_title(String_.Concat_lines_nl +// ( "!!!!>|!!!!?|!!!!@|" +// , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1" +// , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12" +// , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123" +// )) +// .Tst_data_page(String_.Concat_lines_nl +// ( "zipped:!!!!9|!!!!>|!!!!=|" +// , "!!!!!\t##PX+\tA1\tA1 data\t" +// , "!!!!\"\t##PX/\tB12\tB12 changed\t" +// , "!!!!#\t##PX0\tC123\tC123 data\t" +// )) +// ; + } + @Test public void Create_out_of_order() { + fxt .Create("C123", "C123 data") + .Create("B12", "B12 data") + .Create("A1", "A1 data") + .Tst_regy_title("0|A1|C123|3\n") + .Tst_data_title(String_.Concat_lines_nl + ( "!!!!>|!!!!?|!!!!@|" + , "!!!!#|!!!!!|!!!!#|0|!!!!(|A1" + , "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12" + , "!!!!!|!!!!!|!!!!!|0|!!!!*|C123" + )) + .Tst_data_page(String_.Concat_lines_nl + ( "!!!!=|!!!!;|!!!!9|" + , "!!!!!\t##PX+\tC123\tC123 data\t" + , "!!!!\"\t##PX/\tB12\tB12 data\t" + , "!!!!#\t##PX0\tA1\tA1 data\t" + )) + ; + } + @Test public void Rename() { + fxt .Create("A1", "A1 data") + .Create("B12", "B12 data") + .Create("C123", "C123 data") + .Rename("C123", "C1234") + .Tst_regy_title("0|A1|C123|3\n") + .Tst_data_title(String_.Concat_lines_nl + ( "!!!!>|!!!!?|!!!!@|" + , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1" + , "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12" + , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123" + )) + .Tst_data_page(String_.Concat_lines_nl + ( "!!!!9|!!!!;|!!!!=|" + , "!!!!!\t##PX+\tA1\tA1 data\t" + , "!!!!\"\t##PX/\tB12\tB12 data\t" + , "!!!!#\t##PX0\tC123\tC123 data\t" + )) + ; + } +} +class Xow_data_mgr_fxt { + Xoae_app app; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public void Clear() { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + wiki.Db_mgr().Save_mgr().Page_id_next_(0); + } + public Xow_data_mgr_fxt Create(String ttl_str, String data) { + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)); + wiki.Db_mgr().Save_mgr().Data_create(wiki, ttl, Bry_.new_u8(data)); + return this; + } + public Xow_data_mgr_fxt Update(String ttl_str, String data) { + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)); + Xoae_page page = Xoae_page.New_test(wiki, ttl); + wiki.Db_mgr().Save_mgr().Data_update(page, Bry_.new_u8(data)); + return this; + } + public Xow_data_mgr_fxt Rename(String old_ttl, String new_ttl) { + Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(old_ttl)); + Xoae_page page = Xoae_page.New_test(wiki, ttl); + wiki.Db_mgr().Save_mgr().Data_rename(page, ttl.Ns().Id(), Bry_.new_u8(new_ttl)); + return this; + } + public Xow_data_mgr_fxt Tst_regy_title(String expd) {return Tst_regy(Xotdb_dir_info_.Name_title, expd);} + Xow_data_mgr_fxt Tst_regy(String name, String expd) { + Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/" + name + "/reg.csv"); + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig)); + return this; + } + public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Tid__main, 0, expd);} + public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Tid__main, 0, expd);} + public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) { + Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil); + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java new file mode 100644 index 000000000..d51907c24 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_itm_tst.java @@ -0,0 +1,40 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; +import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*; +public class Xowd_page_itm_tst { + @Before public void init() {fxt.Init();} private Xowd_page_itm_fxt fxt = new Xowd_page_itm_fxt(); + @Test public void Ttl_() { + fxt.Test_ttl_("User_talk:A", Xow_ns_.Tid__user_talk, "A"); + fxt.Test_ttl_("User talk:A", Xow_ns_.Tid__user_talk, "A"); + } +} +class Xowd_page_itm_fxt { + public void Init() { + if (ns_mgr == null) { + ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.A7()); + ns_mgr.Add_new(Xow_ns_.Tid__main, ""); + ns_mgr.Add_new(Xow_ns_.Tid__user_talk, "User talk"); + ns_mgr.Init_w_defaults(); + tmp_page = new Xowd_page_itm(); + } + } private Xow_ns_mgr ns_mgr; Xowd_page_itm tmp_page; + public void Test_ttl_(String ttl, int expd_ns, String expd_ttl) { + tmp_page.Ttl_(Bry_.new_a7(ttl), ns_mgr); + Tfds.Eq(expd_ns, tmp_page.Ns_id()); + Tfds.Eq(expd_ttl, String_.new_a7(tmp_page.Ttl_page_db())); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl_tst.java b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl_tst.java new file mode 100644 index 000000000..8f07ccfa9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/data/tbls/Xowd_page_tbl_tst.java @@ -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.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; +import org.junit.*; import gplx.xowa.bldrs.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; +public class Xowd_page_tbl_tst { + private Xowd_page_tbl_fxt fxt = new Xowd_page_tbl_fxt(); + @Test public void Find_search_end() { + fxt.Test_find_search_end("ab", "ac"); + fxt.Test_find_search_end("ab%", "ac%"); + } +} +class Xowd_page_tbl_fxt { + public void Test_find_search_end(String val, String expd) {Tfds.Eq(expd, String_.new_u8(Find_search_end(Bry_.new_u8(val))));} + private static byte[] Find_search_end(byte[] orig) { // NOTE: moved from old Xowd_page_tbl; is probably obsolete + byte[] rv = Bry_.Copy(orig); + int rv_len = rv.length; + int increment_pos = rv[rv_len - 1] == Byte_ascii.Percent ? rv_len - 2 : rv_len - 1; // increment last char, unless it is %; if %, increment one before it + return Bry_.Increment_last(rv, increment_pos); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java b/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java new file mode 100644 index 000000000..a611e76f5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; import gplx.xowa.langs.*; +public class Xow_abrv_wm_tst { + private Xow_abrv_wm_fxt fxt = new Xow_abrv_wm_fxt(); + @Test public void Parse() { + fxt.Test_parse("foundationwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__wmfblog); + fxt.Test_parse("wikidatawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__wikidata); + fxt.Test_parse("mediawikiwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__mediawiki); + fxt.Test_parse("commonswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__commons); + fxt.Test_parse("specieswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__species); + fxt.Test_parse("metawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__meta); + fxt.Test_parse("incubatorwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__incubator); + fxt.Test_parse("enwiki" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikipedia); + fxt.Test_parse("enwiktionary" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wiktionary); + fxt.Test_parse("enwikisource" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikisource); + fxt.Test_parse("enwikibooks" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikibooks); + fxt.Test_parse("enwikiversity" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikiversity); + fxt.Test_parse("enwikiquote" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikiquote); + fxt.Test_parse("enwikinews" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikinews); + fxt.Test_parse("enwikivoyage" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikivoyage); + fxt.Test_parse("frwiki" , Xol_lang_stub_.Id_fr , Xow_domain_tid_.Tid__wikipedia); + fxt.Test_parse_null("unknown"); + fxt.Test_parse("plwikimedia" , Xol_lang_stub_.Id_pl , Xow_domain_tid_.Tid__wikimedia); + } + @Test public void Parse_override() { + fxt.Test_parse("arwikimedia" , Xol_lang_stub_.Id_es , Xow_domain_tid_.Tid__wikimedia); + fxt.Test_parse("ukwikimedia" , Xol_lang_stub_.Id_uk , Xow_domain_tid_.Tid__wikimedia); + } + @Test public void To_domain_itm() { + fxt.Test_to_domain_itm("enwiki" , "en" , "en.wikipedia.org"); + fxt.Test_to_domain_itm("zh_yuewiki" , "zh-yue" , "zh-yue.wikipedia.org"); + } + @Test public void To_domain_bry() { + fxt.Test_to_domain_bry("enwiki" , "en.wikipedia.org"); + fxt.Test_to_domain_bry("zh_yuewiki" , "zh-yue.wikipedia.org"); + fxt.Test_to_domain_bry("arwikimedia", "ar.wikimedia.org"); + fxt.Test_to_domain_bry("ukwikimedia", "ua.wikimedia.org"); + } + @Test public void To_abrv() { + fxt.Test_to_abrv("simple.wikipedia.org" , "simplewiki"); + fxt.Test_to_abrv("en.wikipedia.org" , "enwiki"); + fxt.Test_to_abrv("commons.wikimedia.org" , "commonswiki"); + } + @Test public void To_abrv_by_lang() { + fxt.Test_to_abrv_by_lang("en", Xow_domain_tid_.Tid__wikipedia, "enwiki"); + } +} +class Xow_abrv_wm_fxt { + public void Test_parse(String raw, int expd_lang_id, int expd_domain_tid) { + byte[] raw_bry = Bry_.new_a7(raw); + Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry); + Xol_lang_stub actl_lang_itm = abrv.Lang_actl(); + Tfds.Eq(expd_lang_id , actl_lang_itm == null ? Xol_lang_stub_.Id__unknown : actl_lang_itm.Id()); + Tfds.Eq(expd_domain_tid , abrv.Domain_type()); + } + public void Test_parse_null(String raw) { + byte[] raw_bry = Bry_.new_a7(raw); + Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry); + Tfds.Eq_true(abrv == null); + } + public void Test_to_abrv(String domain_str, String expd) { + Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_a7(domain_str)); + byte[] actl = Xow_abrv_wm_.To_abrv(domain); + Tfds.Eq(expd, String_.new_a7(actl)); + } + public void Test_to_abrv_by_lang(String lang_key, int wiki_tid, String expd) { + Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); + Xow_abrv_wm_.To_abrv(tmp_bfr, Bry_.new_a7(lang_key), gplx.core.primitives.Int_obj_ref.New(wiki_tid)); + Tfds.Eq_str(expd, tmp_bfr.To_str_and_clear(), "to_abrv"); + } + public void Test_to_domain_bry(String wmf_key, String expd_domain) { + Tfds.Eq(expd_domain , String_.new_a7(Xow_abrv_wm_.Parse_to_domain_bry(Bry_.new_a7(wmf_key)))); + } + public void Test_to_domain_itm(String wmf_key, String expd_lang_key, String expd_domain) { + Xow_domain_itm domain = Xow_abrv_wm_.Parse_to_domain_itm(Bry_.new_a7(wmf_key)); + Tfds.Eq(expd_lang_key , String_.new_a7(domain.Lang_actl_key())); + Tfds.Eq(expd_domain , String_.new_a7(domain.Domain_bry())); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_xo__tst.java b/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_xo__tst.java new file mode 100644 index 000000000..1ac4659e2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_xo__tst.java @@ -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.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; +public class Xow_abrv_xo__tst { + @Before public void init() {fxt.Clear();} private final Xow_abrv_xo__fxt fxt = new Xow_abrv_xo__fxt(); + @Test public void Basic() { + fxt.Test("en.wikipedia.org" , "en.w"); // multi.enwiki + fxt.Test("fr.wiktionary.org" , "fr.d"); // multi.frwiktionary + fxt.Test("commons.wikimedia.org" , "c"); // important.unique.commons + fxt.Test("species.wikimedia.org" , "species"); // important.unique.species + fxt.Test("www.wikidata.org" , "wd"); // important.unique.wikidata + fxt.Test("home" , "home"); // important.unique.xowa + fxt.Test("meta.wikimedia.org" , "meta"); // wikimedia.unique + fxt.Test("pl.wikimedia.org" , "pl.m"); // wikimedia.multi + fxt.Test("a.b.c" , "a.b.c"); // unkonwn + } +} +class Xow_abrv_xo__fxt { + public void Clear() {} + public void Test(String domain_str, String expd_abrv) { + Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domain_str)); + byte[] actl_abrv = Xow_abrv_xo_.To_bry(domain.Domain_bry(), domain.Lang_actl_key(), domain.Domain_type()); + Tfds.Eq(expd_abrv, String_.new_u8(actl_abrv), "To_bry"); + domain = Xow_abrv_xo_.To_itm(actl_abrv); + Tfds.Eq(domain_str, domain.Domain_str(), "To_itm"); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java b/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java new file mode 100644 index 000000000..ece3a194d --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java @@ -0,0 +1,53 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; import gplx.core.tests.*; +public class Xow_domain_itm_tst { + private final Xow_domain_fxt fxt = new Xow_domain_fxt(); + @Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , "en" , Xow_domain_tid_.Tid__wikipedia);} + @Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , "fr" , Xow_domain_tid_.Tid__wikipedia);} + @Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , "en" , Xow_domain_tid_.Tid__wiktionary);} + @Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "zh-classical" , "lzh" , Xow_domain_tid_.Tid__wikipedia);} + @Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , "" , Xow_domain_tid_.Tid__commons);} + @Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , "" , Xow_domain_tid_.Tid__species);} + @Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , "ru" , Xow_domain_tid_.Tid__wikimedia);} + @Test public void Parse_home() {fxt.Test_parse("home" , "" , "" , Xow_domain_tid_.Tid__home);} + @Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , "" , Xow_domain_tid_.Tid__other);} + @Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_tid_.Tid__wikimedia);} + @Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_tid_.Tid__wikimedia);} + @Test public void Parse_blank() {fxt.Test_parse("" , "" , "" , Xow_domain_tid_.Tid__other);} + @Test public void Match_lang() { + fxt.Test__match_lang_y("en", "en.wikipedia.org", "en.wiktionary.org", "simple.wikipedia.org", "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org"); + fxt.Test__match_lang_y("fr", "fr.wikipedia.org", "fr.wiktionary.org"); + fxt.Test__match_lang_y("zh", "zh-classical.wikipedia.org"); + } +} +class Xow_domain_fxt { + public void Test_parse(String domain, String expd_orig_lang, String expd_actl_lang, int expd_tid) { + Xow_domain_itm actl = Xow_domain_itm_.parse(Bry_.new_a7(domain)); + Tfds.Eq_str(expd_orig_lang, String_.new_a7((actl.Lang_orig_key()))); + Tfds.Eq_str(expd_actl_lang, String_.new_a7((actl.Lang_actl_key()))); + Tfds.Eq_int(expd_tid, actl.Domain_type_id()); + } + public void Test__match_lang_y(String lang_code, String... domains) {Test__match_lang(Bool_.Y, lang_code, domains);} + public void Test__match_lang(boolean expd, String lang_key_str, String[] domains) { + int len = domains.length; + for (int i = 0; i < len; ++i) { + Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domains[i])); + Gftest.Eq__bool(expd, Xow_domain_itm_.Match_lang(domain, lang_key_str), lang_key_str + "|" + domains[i]); + } + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_uid__tst.java b/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_uid__tst.java new file mode 100644 index 000000000..2807be403 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_uid__tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; +public class Xow_domain_uid__tst { + @Before public void init() {fxt.Clear();} private final Xow_domain_uid__fxt fxt = new Xow_domain_uid__fxt(); + @Test public void Basic() { + fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_tid_.Tid__commons); + fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_tid_.Tid__wikipedia); + } +} +class Xow_domain_uid__fxt { + public void Clear() {} + public void Test(int tid, String domain_str, String expd_lang, int expd_tid) { + byte[] domain_bry = Bry_.new_a7(domain_str); + Xow_domain_itm actl_domain = Xow_domain_uid_.To_domain(tid); + Tfds.Eq_bry(domain_bry , actl_domain.Domain_bry()); + Tfds.Eq_bry(Bry_.new_a7(expd_lang) , actl_domain.Lang_actl_key()); + Tfds.Eq(expd_tid , actl_domain.Domain_type_id()); + Tfds.Eq(tid, Xow_domain_uid_.To_int(actl_domain)); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java new file mode 100644 index 000000000..95c027793 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java @@ -0,0 +1,77 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; +import gplx.xowa.langs.cases.*; +public class Xow_ns_mgr_tst { + @Before public void init() {fxt.Clear();} private Xow_ns_mgr_fxt fxt = new Xow_ns_mgr_fxt(); + @Test public void Basic() {fxt.ini_ns_(-2, 0, 1).run_Ords_sort().tst_Ords(-2, -100, 0, 1);} + @Test public void Talk_skip() {fxt.ini_ns_(-2, 0, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);} + @Test public void Subj_skip() {fxt.ini_ns_(-2, 1, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);} + @Test public void Out_of_order() {fxt.ini_ns_(3, 1, 2, -2).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);} + @Test public void Skip_odd() {fxt.ini_ns_(-2, 1, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);} + @Test public void Skip_even() {fxt.ini_ns_(-2, 2, 4).run_Ords_sort().tst_Ords(-2, -100, 2, 3, 4, 5);} + @Test public void Ns_alias() { + fxt.Ns_mgr().Aliases_clear(); + fxt.Ns_mgr().Add_new(Xow_ns_.Tid__template, "Template"); + fxt.Ns_mgr().Aliases_add(Xow_ns_.Tid__template, "Templatex"); + fxt.Ns_mgr().Init(); + byte[] name = Bry_.new_a7("Templatex:Abc"); + Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length)); + } + @Test public void Utf8() {// PURPOSE: handle different casings for ns_names; PAGE:ru.w:Портрет_итальянского_Ренессанса DATE:2014-07-04 + Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.U8()); + ns_mgr.Add_new(1234, "Test"); + ns_mgr.Add_new(1235, "файл"); + fxt.Ns_mgr_(ns_mgr); + fxt.Test_ns_name(1234, "Test", "test", "TEST", "tesT"); + fxt.Test_ns_name(1235, "файл", "Файл"); + } +} +class Xow_ns_mgr_fxt { + private Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.A7()); + public Xow_ns_mgr Ns_mgr() {return ns_mgr;} + public void Ns_mgr_(Xow_ns_mgr v) {this.ns_mgr = v;} + public void Clear() {ns_mgr.Clear();} + public Xow_ns_mgr_fxt ini_ns_(int... ids) { + int ids_len = ids.length; + for (int i = 0; i < ids_len; i++) { + int id = ids[i]; + ns_mgr.Add_new(id, Int_.To_str(id)); + } + return this; + } + public Xow_ns_mgr_fxt run_Ords_sort() {ns_mgr.Init(); return this;} + public Xow_ns_mgr_fxt tst_Ords(int... expd) { + int actl_len = ns_mgr.Ords_len(); + int[] actl = new int[actl_len]; + for (int i = 0; i < actl_len; i++) { + Xow_ns ns_itm = ns_mgr.Ords_ary()[i]; + actl[i] = ns_itm == null ? -100 : ns_itm.Id(); + } + Tfds.Eq_ary(expd, actl); + return this; + } + public void Test_ns_name(int expd_id, String... ns_names) { + int ns_names_len = ns_names.length; + for (int i = 0; i < ns_names_len; ++i) { + String ns_name = ns_names[i]; + Xow_ns actl_ns = ns_mgr.Names_get_or_null(Bry_.new_u8(ns_name)); + int actl_id = actl_ns == null ? Int_.Min_value : actl_ns.Id(); + Tfds.Eq(expd_id, actl_id, ns_name); + } + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java new file mode 100644 index 000000000..72c269cb2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java @@ -0,0 +1,61 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; +public class Xow_ns_tst { + @Before public void init() {fxt.Clear();} private Xow_ns_fxt fxt = new Xow_ns_fxt(); + @Test public void Category() { + fxt .Expd_id_subjId_(Xow_ns_.Tid__category) + .Expd_id_talkId_(Xow_ns_.Tid__category_talk) + .Expd_id_subj_(Bool_.Y) + .Expd_id_talk_(Bool_.N) + .Test(Xow_ns_.Tid__category) + ; + } + @Test public void Category_talk() { + fxt .Expd_id_subjId_(Xow_ns_.Tid__category) + .Expd_id_talkId_(Xow_ns_.Tid__category_talk) + .Expd_id_subj_(Bool_.N) + .Expd_id_talk_(Bool_.Y) + .Test(Xow_ns_.Tid__category_talk) + ; + } + @Test public void Special() { + fxt .Expd_id_subjId_(Xow_ns_.Tid__special) + .Expd_id_talkId_(Xow_ns_.Tid__special) + .Expd_id_subj_(Bool_.Y) + .Expd_id_talk_(Bool_.N) + .Test(Xow_ns_.Tid__special) + ; + } +} +class Xow_ns_fxt { + public void Clear() { + expd_id_subjId = expd_id_talkId = Int_.Max_value; + expd_id_subj = expd_id_talk = false; + } + public Xow_ns_fxt Expd_id_subjId_(int v) {expd_id_subjId = v; return this;} private int expd_id_subjId; + public Xow_ns_fxt Expd_id_talkId_(int v) {expd_id_talkId = v; return this;} private int expd_id_talkId; + public Xow_ns_fxt Expd_id_subj_(boolean v) {expd_id_subj = v; return this;} private boolean expd_id_subj; + public Xow_ns_fxt Expd_id_talk_(boolean v) {expd_id_talk = v; return this;} private boolean expd_id_talk; + public void Test(int nsId) { + Xow_ns actl = new Xow_ns(nsId, Xow_ns_case_.Tid__1st, Bry_.Empty, false); + Tfds.Eq(expd_id_subjId, actl.Id_subj_id()); + Tfds.Eq(expd_id_talkId, actl.Id_talk_id()); + Tfds.Eq(expd_id_subj, actl.Id_is_subj()); + Tfds.Eq(expd_id_talk, actl.Id_is_talk()); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/pages/redirects/Xopg_redirect_mgr__tst.java b/400_xowa/src/gplx/xowa/wikis/pages/redirects/Xopg_redirect_mgr__tst.java new file mode 100644 index 000000000..c5e1eeca5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/pages/redirects/Xopg_redirect_mgr__tst.java @@ -0,0 +1,51 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.pages.redirects; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.pages.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.specials.*; +public class Xopg_redirect_mgr__tst { + @Before public void init() {fxt.Clear();} private final Xopg_redirect_mgr__fxt fxt = new Xopg_redirect_mgr__fxt(); + @Test public void Basic() { + fxt.Test__Itms__add__special(fxt.Make_meta("XowaTest"), Keyval_.Ary_empty, fxt.Make__itm("en.wikipedia.org/wiki/Special:XowaTest", "Special:XowaTest", null)); + } + @Test public void Args() { + fxt.Test__Itms__add__special + ( fxt.Make_meta("XowaTest"), Keyval_.Ary(Keyval_.new_("k1", "v1"), Keyval_.new_("k2", "v2"), Keyval_.new_("k3", "v3")) + , fxt.Make__itm("en.wikipedia.org/wiki/Special:XowaTest?k1=v1&k2=v2&k3=v3", "Special:XowaTest", null) + ); + } +} +class Xopg_redirect_mgr__fxt { + private Xow_wiki wiki; + private final Xopg_redirect_mgr mgr = new Xopg_redirect_mgr(); + public void Clear() { + mgr.Clear(); + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + this.wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + public Xow_special_meta Make_meta(String key) {return Xow_special_meta.New_xo(key, "test display name");} + public Xopg_redirect_itm Make__itm(String url_str, String ttl_str, String wikitext) { + Xoa_url url = wiki.Utl__url_parser().Parse(Bry_.new_u8(url_str)); + Xoa_ttl ttl = wiki.Ttl_parse(Bry_.new_u8(ttl_str)); + return new Xopg_redirect_itm(url, ttl, Bry_.new_u8_safe(wikitext)); + } + public void Test__Itms__add__special(Xow_special_meta meta, Keyval[] url_args, Xopg_redirect_itm expd) { + mgr.Itms__add__special(wiki, meta, url_args); + Xopg_redirect_itm actl = mgr.Itms__get_at(0); + Gftest.Eq__bry(expd.Ttl().Raw(), actl.Ttl().Raw(), "ttl"); + Gftest.Eq__str(expd.Url().To_str(), actl.Url().To_str(), "url"); + Gftest.Eq__bry(expd.Wikitext(), actl.Wikitext(), "wikitext"); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java new file mode 100644 index 000000000..ff8d36c78 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java @@ -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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; import gplx.xowa.wikis.tdbs.*; +import gplx.xowa.wikis.nss.*; +public class Xotdb_fsys_mgr_tst { + @Before public void init() {fxt.Clear();} private final Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt(); + @Test public void Basic() { + fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat"); + fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip"); + } +} +class Xow_fsys_mgr_fxt { + public void Clear() { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + } + Xoae_app app; Xowe_wiki wiki; + public Xow_fsys_mgr_fxt Zip_(byte tid, boolean v) {wiki.Tdb_fsys_mgr().Tdb_dir_regy()[tid].Ext_tid_(v ? gplx.core.ios.streams.Io_stream_tid_.Tid__zip : gplx.core.ios.streams.Io_stream_tid_.Tid__raw); return this;} + public void Url_ns_fil(byte tid, int ns_id, int fil_idx, String expd) { + Tfds.Eq(expd, wiki.Tdb_fsys_mgr().Url_ns_fil(tid, ns_id, fil_idx).Raw()); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr_tst.java new file mode 100644 index 000000000..e5ae8a86b --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +public class Xob_hive_mgr_tst { + Xow_hive_mgr_fxt fxt = new Xow_hive_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Drilldown() { +// fxt.Files_create_range(10, 10); +// fxt.Drilldown("A00", "J09", "A00", "B09", "C00", "D09", "E00", "F09", "G00", "H09", "I00", "J09"); +// fxt.Drilldown("E00", "F09", "E00", "E03", "E04", "E07", "E08", "F01", "F02", "F05", "F06", "F09"); +// fxt.Drilldown("E08", "F01", "E08", "E09", "F00", "F01"); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java new file mode 100644 index 000000000..3b60e5bd9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java @@ -0,0 +1,111 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import gplx.core.encoders.*; +import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.tdbs.xdats.*; +public class Xow_hive_mgr_fxt { + public void Clear() { + if (hive_mgr == null) { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + hive_mgr = new Xob_hive_mgr(wiki); + } + hive_mgr.Clear(); + Io_mgr.Instance.InitEngine_mem(); + } private Xob_hive_mgr hive_mgr; Xoae_app app; + public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; + public void Find_nearby(String key, int count, boolean include_redirects, String... expd) { + List_adp list = List_adp_.New(); + wiki.Hive_mgr().Find_bgn(list, wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), count, include_redirects); + int actl_len = list.Count(); + String[] actl = new String[actl_len]; + for (int i = 0; i < actl_len; i++) { + Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i); + actl[i] = String_.new_a7(itm.Ttl_page_db()); + } + Tfds.Eq_ary_str(expd, actl); + } + public static void Ttls_create_rng(Xowe_wiki wiki, int files, int ttls_per_file) {Ttls_create_rng(wiki, wiki.Ns_mgr().Ns_main(), files, ttls_per_file);} + public static void Ttls_create_rng(Xowe_wiki wiki, Xow_ns ns, int files, int ttls_per_file) { + Xob_reg_wtr reg_wtr = new Xob_reg_wtr(); + byte dir_tid = Xotdb_dir_info_.Tid_ttl; + int id = 0; + int ttl_bry_len = Int_.DigitCount(ttls_per_file); + Xob_xdat_file_wtr xdat_wtr = Xob_xdat_file_wtr.new_file_(ttls_per_file * 8, wiki.Tdb_fsys_mgr().Url_ns_dir(ns.Num_str(), Xotdb_dir_info_.Tid_ttl)); + Bry_bfr tmp_bfr = Bry_bfr_.New(); + byte ltr = Byte_ascii.Ltr_A; byte[] ttl_0 = Bry_.Empty, ttl_n = Bry_.Empty; + for (int fil_idx = 0; fil_idx < files; fil_idx++) { + for (int ttl_idx = 0; ttl_idx < ttls_per_file; ttl_idx++) { + tmp_bfr.Add_byte(ltr).Add_int_fixed(ttl_idx, ttl_bry_len); + byte[] ttl_bry = tmp_bfr.To_bry_and_clear(); + if (ttl_idx == 0) ttl_0 = ttl_bry; + else if (ttl_idx == ttls_per_file - 1) ttl_n = ttl_bry; + Xotdb_page_itm_.Txt_ttl_save(xdat_wtr.Bfr(), id++, 0, ttl_idx, ttl_idx % 2 == 1, 1, ttl_bry); + xdat_wtr.Add_idx(Byte_ascii.Null); + } + xdat_wtr.Flush(wiki.Appe().Usr_dlg()); + reg_wtr.Add(ttl_0, ttl_n, ttls_per_file); + ++ltr; + } + reg_wtr.Flush(wiki.Tdb_fsys_mgr().Url_ns_reg(ns.Num_str(), dir_tid)); + } + public Xow_hive_mgr_fxt Create_ctg(String key_str, int... pages) {Create_ctg(app, hive_mgr, key_str, pages); return this;} + public static void Create_ctg(Xoae_app app, Xob_hive_mgr hive_mgr, String key_str, int... pages) { + byte[] key_bry = Bry_.new_a7(key_str); + Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512(); + bfr.Add(key_bry); + int pages_len = pages.length; + for (int i = 0; i < pages_len; i++) + bfr.Add_byte_pipe().Add_base85_len_5(pages[i]); + bfr.Add_byte_nl(); + byte[] row = bfr.To_bry_and_rls(); + hive_mgr.Create(Xotdb_dir_info_.Tid_category, key_bry, row); + } + public Xow_hive_mgr_fxt Create_id(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Create_id(app, hive_mgr, id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;} + public static void Create_id(Xoae_app app, Xob_hive_mgr hive_mgr, int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) { + Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512(); + byte[] key_bry = Base85_.To_bry(id, 5); + bfr .Add(key_bry) .Add_byte_pipe() + .Add_base85_len_5(fil_idx) .Add_byte_pipe() + .Add_base85_len_5(row_idx) .Add_byte_pipe() + .Add_byte(type_redirect ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe() + .Add_base85_len_5(itm_len) .Add_byte_pipe() + .Add_base85_len_5(ns_id) .Add_byte_pipe() + .Add_str_u8(ttl) .Add_byte_nl(); + byte[] row = bfr.To_bry_and_clear(); + bfr.Mkr_rls(); + hive_mgr.Create(Xotdb_dir_info_.Tid_id, key_bry, row); + } + public Xow_hive_mgr_fxt Load(String url, String... expd) { + String actl = Io_mgr.Instance.LoadFilStr(url); + Tfds.Eq_ary_str(expd, String_.SplitLines_nl(actl)); + return this; + } +} +class Xob_reg_wtr { + Bry_bfr bfr = Bry_bfr_.New(); int fil_count = 0; + public void Add(byte[] bgn, byte[] end, int itm_count) { + bfr + .Add_int_variable(fil_count++).Add_byte(Byte_ascii.Pipe) + .Add(bgn).Add_byte(Byte_ascii.Pipe) + .Add(end).Add_byte(Byte_ascii.Pipe) + .Add_int_variable(itm_count).Add_byte(Byte_ascii.Nl); + } + public void Flush(Io_url url) { + Io_mgr.Instance.SaveFilBfr(url, bfr); +// Tfds.Dbg(url.Raw() + "\n" + Io_mgr.Instance.LoadFilStr(url)); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java new file mode 100644 index 000000000..d3acdf7e5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr_tst.java @@ -0,0 +1,97 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +import gplx.xowa.wikis.nss.*; +public class Xowd_hive_mgr_tst { + Xowd_hive_mgr_fxt fxt = new Xowd_hive_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Create() { + fxt.Create("A", "A|A data\n") + .Tst_reg(String_.Concat_lines_nl("0|A|A|1")) + .Tst_fil(0, String_.Concat("!!!!*|\n", "A|A data\n")) + ; + } + @Test public void Create_2() { + fxt .Create("A", "A|1\n") + .Create("B", "B|12\n") + .Tst_reg(String_.Concat_lines_nl("0|A|B|2")) + .Tst_fil(0, String_.Concat("!!!!%|!!!!&|\n", "A|1\n", "B|12\n")) + ; + } + @Test public void Create_3() { + fxt .Create("A", "A|1\n") + .Create("B", "B|12\n") + .Create("C", "C|123\n") + .Tst_reg(String_.Concat_lines_nl("0|A|C|3")) + .Tst_fil(0, String_.Concat("!!!!%|!!!!&|!!!!'|\n", "A|1\n", "B|12\n", "C|123\n")) + ; + } + @Test public void Create_sort() { + fxt .Create_and_sort("C", "C|1\n") + .Create_and_sort("A", "A|12\n") + .Create_and_sort("B", "B|123\n") + .Tst_reg(String_.Concat_lines_nl("0|A|C|3")) + .Tst_fil(0, String_.Concat("!!!!&|!!!!'|!!!!%|\n", "A|12\n", "B|123\n", "C|1\n")) + ; + } + @Test public void Update() { + fxt .Create("A", "A|A data\n") + .Create("B", "B|B data\n") + .Create("C", "C|C data\n") + .Tst_reg(String_.Concat_lines_nl("0|A|C|3")) + .Tst_fil(0, String_.Concat("!!!!*|!!!!*|!!!!*|\n", "A|A data\n", "B|B data\n", "C|C data\n")) + .Update("B", "B|changed\n") + .Tst_reg(String_.Concat_lines_nl("0|A|C|3")) + .Tst_fil(0, String_.Concat("!!!!*|!!!!+|!!!!*|\n", "A|A data\n", "B|changed\n", "C|C data\n")) + ; + } +} +class Xowd_hive_mgr_fxt { + Xoae_app app; Xowe_wiki wiki; Xowd_hive_mgr mgr; + public void Clear() { + app = Xoa_app_fxt.Make__app__edit(); + wiki = Xoa_app_fxt.Make__wiki__edit(app); + mgr = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_page); + } + public Xowd_hive_mgr_fxt Tst_reg(String expd) { + Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/title/reg.csv"); + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig)); + return this; + } + public Xowd_hive_mgr_fxt Tst_fil(int fil, String expd) { + Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, fil); + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url)); + return this; + } + public Xowd_hive_mgr_fxt Update(String key, String data) { + mgr.Update(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), null, Bry_.new_a7(data), 0, Byte_ascii.Pipe, true, true); + return this; + } + public Xowd_hive_mgr_fxt Create(String key, String data) { + mgr.Create(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), Bry_.new_a7(data), null); + return this; + } + public Xowd_hive_mgr_fxt Create_and_sort(String key, String data) { + mgr.Create(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), Bry_.new_a7(data), new Bry_comparer_bgn_eos(0)); + return this; + } +// public void Get(String ttl_str, boolean exists) { +// Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str)); +// Xowd_page_itm row = mgr.Get(ttl.Ns(), ttl.Full_txt()); +// Tfds.Eq(exists, row != null); +// } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr__tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr__tst.java new file mode 100644 index 000000000..3361947ae --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr__tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; import gplx.core.lists.*; +public class Xowd_regy_mgr__tst implements ComparerAble { + @Test public void Basic() { + String[] slotAry = new String[] {"b", "e", "h"}; // 0=b 1=e 2=h + tst_FindSlot(slotAry, "f", "h"); // f -> 1 2 -> 2 + tst_FindSlot(slotAry, "c", "e"); // c -> -1 1 -> 0 -> 0 1 -> 1 + tst_FindSlot(slotAry, "a", "b"); // a -> -1 1 -> 0 -> -1 0 -> 0 + } + @Test public void Null() { + String[] slotAry = new String[] {"b", "g", "l", "q", "v", null}; + tst_FindSlot(slotAry, "a", "b"); + tst_FindSlot(slotAry, "b", "b"); + tst_FindSlot(slotAry, "c", "g"); + tst_FindSlot(slotAry, "v", "v"); + tst_FindSlot(slotAry, "w", null); + } + public int compare(Object lhsObj, Object rhsObj) {return CompareAble_.Compare_obj(lhsObj, rhsObj);} + void tst_FindSlot(String[] slotAry, String s, String expd) {Tfds.Eq(expd, slotAry[gplx.xowa.wikis.tdbs.hives.Xowd_regy_mgr_.FindSlot(this, slotAry, s)]);} +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr_tst.java new file mode 100644 index 000000000..90f549473 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr_tst.java @@ -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.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +public class Xowd_regy_mgr_tst { + Xowd_regy_mgr_fxt fxt = new Xowd_regy_mgr_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Create_cur_is_empty() {fxt.Create("A").Save().Tst_file(String_.Concat_lines_nl("0|A|A|1"));} + @Test public void Create_cur_has_one() {fxt.Load(String_.Concat_lines_nl("0|A|A|1")).Create("B").Save().Tst_file(String_.Concat_lines_nl("0|A|A|1", "1|B|B|1"));} + @Test public void Update_1st_end() {fxt.Load(String_.Concat_lines_nl("0|B|B|1")).Update_add(0, "C").Save().Tst_file(String_.Concat_lines_nl("0|B|C|2"));} + @Test public void Update_1st_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|B|1")).Update_add(0, "A").Save().Tst_file(String_.Concat_lines_nl("0|A|B|2"));} + @Test public void Update_mid() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "C").Save().Tst_file(String_.Concat_lines_nl("0|B|D|3"));} + @Test public void Update_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "A").Save().Tst_file(String_.Concat_lines_nl("0|A|D|3"));} + @Test public void Update_end() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "E").Save().Tst_file(String_.Concat_lines_nl("0|B|E|3"));} + @Test public void Update_change_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "B", "A").Save().Tst_file(String_.Concat_lines_nl("0|A|D|2"));} + @Test public void Update_change_end() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "D", "E").Save().Tst_file(String_.Concat_lines_nl("0|B|E|2"));} + @Test public void Update_change_mid() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "C1", "C2").Save().Tst_file(String_.Concat_lines_nl("0|B|D|2"));} + @Test public void Find_none() {fxt.Tst_find("A", Xowd_regy_mgr.Regy_null);} + @Test public void Find_existing() { + fxt.Load(String_.Concat_lines_nl + ( "0|B|D|3" + , "1|E|G|3" + , "2|H|J|3" + )) + .Tst_find("B", 0).Tst_find("C", 0).Tst_find("D", 0) + .Tst_find("A", 0) + .Tst_find("Z", 2) + .Tst_find("Da", 1) + ; + } + @Test public void Find_existing_null() { + fxt.Load(String_.Concat_lines_nl + ( "0|B|D|3" + , "1|D|H|0" + , "2|H|J|3" + )) + .Tst_find("B", 0).Tst_find("C", 0).Tst_find("D", 0) + .Tst_find("A", 0) + .Tst_find("Z", 2) + .Tst_find("Da", 1) // rely on + ; + } +} +class Xowd_regy_mgr_fxt { + Xowd_regy_mgr mgr; Io_url mgr_url; + public void Clear() { + if (mgr == null) { + mgr_url = Io_url_.mem_fil_("mem/hive_regy.csv"); + Io_mgr.Instance.DeleteFil(mgr_url); + mgr = new Xowd_regy_mgr(mgr_url); + } + else { + mgr.Clear(); + } + } + public Xowd_regy_mgr_fxt Create(String key) {mgr.Create(Bry_.new_a7(key)); return this;} + public Xowd_regy_mgr_fxt Update_add(int fil_idx, String key) {mgr.Update_add(fil_idx, Bry_.new_a7(key)); return this;} + public Xowd_regy_mgr_fxt Update_change(int fil_idx, String old_key, String new_key) {mgr.Update_change(fil_idx, Bry_.new_a7(old_key), Bry_.new_a7(new_key)); return this;} + public Xowd_regy_mgr_fxt Load(String lines) { + Io_mgr.Instance.SaveFilStr(mgr_url, lines); + mgr = new Xowd_regy_mgr(mgr_url); + return this; + } + public Xowd_regy_mgr_fxt Save() {mgr.Save(); return this;} + public Xowd_regy_mgr_fxt Tst_file(String expd) { + Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(mgr_url)); + return this; + } + public Xowd_regy_mgr_fxt Tst_find(String find, int expd) { + Tfds.Eq(expd, mgr.Files_find(Bry_.new_a7(find))); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil_tst.java new file mode 100644 index 000000000..4f008c73c --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil_tst.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; import gplx.xowa.files.*; +public class Xof_meta_fil_tst { + Xof_meta_fil_fxt fxt = new Xof_meta_fil_fxt(); + @Before public void init() {fxt.Ini();} + @Test public void Bld_url() {fxt.Bld_url("mem/root/", "abcdef", 3, "mem/root/a/b/abc.csv");} +} +class Xof_meta_fil_fxt { + byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5(name);} + public void Ini() {} + public void Bld_url(String root, String md5, int depth, String expd) {Tfds.Eq(expd, Xof_meta_fil.Bld_url(Io_url_.new_dir_(root), Bry_.new_a7(md5), depth).Raw());} +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr_tst.java new file mode 100644 index 000000000..4da87fd00 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr_tst.java @@ -0,0 +1,94 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +import gplx.core.primitives.*; +import gplx.gfui.*; import gplx.xowa.files.*; +public class Xof_meta_mgr_tst { + Xof_file_regy_fxt fxt = new Xof_file_regy_fxt(); + @Before public void init() {fxt.Ini();} + @Test public void Set_one() { + fxt .Set("A.png", 440, 400, true, "440,400", "220,200") + .tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?440,400|1?440,400;1?220,200"); + } + @Test public void Set_many() { + fxt .Set("A.png" , 440, 400, true, "440,400", "220,200") + .Set("Cabbage.jpg" , 640, 456, false, "220,200", "200,180") + .tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" + , "A.png|y||1?440,400|1?440,400;1?220,200" + , "Cabbage.jpg|y||2?640,456|1?220,200;1?200,180" + ); + } + @Test public void Load_and_add() { + fxt.Save_fil("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" + , "A.png|y||1?440,400|" + , "Cabbage.jpg|y||2?640,456|1?440,220;1?220,200" + ) + .Set("Wooden_hourglass_3.jpg", 967, 1959, false, "220,200") + .tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" + , "A.png|y||1?440,400|" + , "Cabbage.jpg|y||2?640,456|1?440,220;1?220,200" + , "Wooden_hourglass_3.jpg|y||2?967,1959|1?220,200" + ); + } + @Test public void Load_and_update() { + fxt.Save_fil("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" + , "A.png|y||0?440,400|" + , "Cabbage.jpg|y||2?640,456|1?440,400;1?220,200" + ) + .Set("A.png", 550, 500, false, "220,200") + .tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv" + , "A.png|y||2?550,500|1?220,200" + , "Cabbage.jpg|y||2?640,456|1?440,400;1?220,200" + ); + } +} +class Xof_file_regy_fxt { + Xof_meta_mgr regy_mgr; + byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5(name);} + public void Ini() { + Io_mgr.Instance.InitEngine_mem(); + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); + regy_mgr = new Xof_meta_mgr(wiki); + regy_mgr.Clear(); + regy_mgr.Depth_(2); + } + public Xof_file_regy_fxt Save_fil(String url, String... data) {Io_mgr.Instance.SaveFilStr(Io_url_.mem_fil_(url), String_.Concat_lines_nl(data)); return this;} + public Xof_file_regy_fxt Set(String name_str, int w, int h, boolean orig_exists, String... thumbs) { + byte[] name = Bry_.new_u8(name_str); + byte[] md5 = md5_(name); + Xof_meta_itm itm = regy_mgr.Get_itm_or_new(name, md5); + itm.Vrtl_repo_(Xof_meta_itm.Repo_same); // all tests above assume this is main + itm.Update_all(Bry_.Empty, w, h, orig_exists ? Xof_meta_itm.Exists_y : Xof_meta_itm.Exists_unknown, To_ary(thumbs)); + return this; + } + Xof_meta_thumb[] To_ary(String[] ary) { + int len = ary.length; + Xof_meta_thumb[] rv = new Xof_meta_thumb[len]; + Int_ary_parser parser = new Int_ary_parser(); + for (int i = 0; i < len; i++) { + int[] size = parser.Parse_ary(ary[i], Byte_ascii.Comma); + rv[i] = new Xof_meta_thumb().Width_(size[0]).Height_(size[1]).Exists_y_(); + } + return rv; + } + public Xof_file_regy_fxt tst_Save(String url_str, String... expd_ary) { + regy_mgr.Save(); + Tfds.Eq_ary_str(expd_ary, Io_mgr.Instance.LoadFilStr_args(Io_url_.new_fil_(url_str)).ExecAsStrAryLnx()); + return this; + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb_parser_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb_parser_tst.java new file mode 100644 index 000000000..804db0228 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb_parser_tst.java @@ -0,0 +1,48 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; import gplx.core.strings.*; +public class Xof_meta_thumb_parser_tst { + Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser(); + @Test public void Exists_y() {Tst_parse("1?45,40", itm_y_(45, 40));} + @Test public void Exists_n() {Tst_parse("0?45,40", itm_n_(45, 40));} + @Test public void Many() {Tst_parse("1?45,40;0?90,80", itm_y_(45, 40), itm_n_(90, 80));} + @Test public void Seek() {Tst_parse("1?45,40@2,3,4", itm_y_(45, 40, 2, 3, 4));} + private void Tst_parse(String raw_str, Xof_meta_thumb... expd) { + byte[] raw = Bry_.new_a7(raw_str); + parser.Parse_ary(raw, 0, raw.length); + Tfds.Eq_str_lines(Xto_str(expd, 0, expd.length), Xto_str(parser.Ary(), 0, parser.Len())); + } + String Xto_str(Xof_meta_thumb[] ary, int bgn, int end) { + for (int i = bgn; i < end; i++) { + Xof_meta_thumb itm = ary[i]; + sb .Add(itm.Exists()).Add(":") + .Add(itm.Width()).Add(",") + .Add(itm.Height()); + int seeks_len = itm.Seeks().length; + for (int j = 0; j < seeks_len; j++) { + int seek = itm.Seeks()[j]; + sb.Add(i == 0 ? "@" : ","); + sb.Add(seek); + } + sb.Add_char_nl(); + } + return sb.To_str_and_clear(); + } String_bldr sb = String_bldr_.new_(); +// Xof_meta_img_chkr img_(int w, int h, params int[] seeks) {return new Xof_meta_img_chkr().Width_(w).Height_(h).Seeks_(seeks);} + Xof_meta_thumb itm_y_(int w, int h, int... seeks) {return new Xof_meta_thumb(Xof_meta_itm.Exists_y, w, h, seeks);} + Xof_meta_thumb itm_n_(int w, int h, int... seeks) {return new Xof_meta_thumb(Xof_meta_itm.Exists_n, w, h, seeks);} +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java new file mode 100644 index 000000000..901cee3f1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java @@ -0,0 +1,30 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.tdbs.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +import gplx.core.ios.*; +public class Xos_url_gen_tst { + @Test public void Url_gen() { + tst_url_gen("mem/root/", 0, "mem/root/00/00/00/00/0000000000.csv"); + tst_url_gen("mem/root/", 99, "mem/root/00/00/00/00/0000000099.csv"); + tst_url_gen("mem/root/", 1234567890, "mem/root/12/34/56/78/1234567890.csv"); + } + private void tst_url_gen(String root_str, int idx, String expd) { + Io_url root = Io_url_.mem_fil_(root_str); + Io_url actl_url = Xos_url_gen.bld_fil_(root, idx, Bry_.new_a7(".csv")); + Tfds.Eq(expd, actl_url.Xto_api()); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java new file mode 100644 index 000000000..f79797209 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java @@ -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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; import gplx.core.strings.*; import gplx.xowa.wikis.tdbs.hives.*; +public class Xob_xdat_file_tst { + @Test public void Find() { + Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j"); + tst_ReadAt(rdr, 0, "0|b"); + tst_ReadAt(rdr, 1, "1|d"); + tst_ReadAt(rdr, 2, "2|f"); + tst_ReadAt(rdr, 3, "3|h"); + tst_ReadAt(rdr, 4, "4|j"); + tst_Find(rdr, "b", 0, false); + tst_Find(rdr, "j", 4, false); + tst_Find(rdr, "a", 0, false); + tst_Find(rdr, "c", 1, false); + tst_Find(rdr, "k", 4, false); + } + @Test public void Update() { + Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j"); + tst_Update(rdr, 3, "3|h1\n", String_.Concat_lines_nl_skip_last + ( "!!!!%|!!!!%|!!!!%|!!!!&|!!!!%|" + , "0|b" + , "1|d" + , "2|f" + , "3|h1" + , "4|j" + , "" + )); + } + @Test public void Insert() { + Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j"); + tst_Insert(rdr, "5|k\n", String_.Concat_lines_nl_skip_last + ( "!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|" + , "0|b" + , "1|d" + , "2|f" + , "3|h" + , "4|j" + , "5|k" + , "" + )); + } + @Test public void Sort() { + Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "4|j", "2|f", "0|b", "1|d", "3|h"); + Bry_comparer_bgn_eos comparer = new Bry_comparer_bgn_eos(2); + tst_Sort(rdr, comparer, String_.Concat_lines_nl_skip_last + ( "!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|" + , "0|b" + , "1|d" + , "2|f" + , "3|h" + , "4|j" + , "" + )); + } + @Test public void Rebuild_header() { + String orig = String_.Concat_lines_nl("" , "4|j", "2|f", "0|b", "1|d", "3|h"); + String expd = String_.Concat_lines_nl("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|" , "4|j", "2|f", "0|b", "1|d", "3|h"); + Rebuild_header_tst(orig, expd); + } + private void Rebuild_header_tst(String orig, String expd) { + Tfds.Eq_str_lines(expd, String_.new_a7(Xob_xdat_file.Rebuid_header(Bry_.new_a7(orig), Bry_.new_a7("\n")))); + } + Bry_bfr tmp = Bry_bfr_.New(); + private void tst_Sort(Xob_xdat_file rdr, gplx.core.lists.ComparerAble comparer, String expd) { + rdr.Sort(tmp, comparer); + Chk_file(rdr, expd); + } + private void tst_Insert(Xob_xdat_file rdr, String new_val, String expd) { + rdr.Insert(tmp, Bry_.new_u8(new_val)); + Chk_file(rdr, expd); + } + private void tst_Update(Xob_xdat_file rdr, int idx, String new_val, String expd) { + Xob_xdat_itm itm = new Xob_xdat_itm(); + rdr.GetAt(itm, idx); + rdr.Update(tmp, itm, Bry_.new_u8(new_val)); + Chk_file(rdr, expd); + } + private void Chk_file(Xob_xdat_file rdr, String expd) { + Io_url url = Io_url_.new_fil_("mem/test.xdat"); + rdr.Save(url); + String actl = Io_mgr.Instance.LoadFilStr(url); + Tfds.Eq_str_lines(expd, actl); + } + private void tst_Find(Xob_xdat_file rdr, String find, int expd, boolean exact) { + rdr.Find(itm, Bry_.new_u8(find), 2, Byte_ascii.Nl, exact); + int id = Bry_.To_int_or(Bry_.Mid(itm.Itm_bry(), 0, 1), -1); + Tfds.Eq(expd, id); + } + private void tst_ReadAt(Xob_xdat_file rdr, int i, String expd) {rdr.GetAt(itm, i); Tfds.Eq(expd, String_.new_u8(itm.Itm_bry()));} + Xob_xdat_itm itm = new Xob_xdat_itm(); + Xob_xdat_file rdr_(String... lines) { + String_bldr sb = String_bldr_.new_(); + int len = lines.length; + for (int i = 0; i < len; i++) { + String line = lines[i]; + sb.Add(line).Add_char_nl(); + } + byte[] bry = Bry_.new_u8(sb.To_str()); + return new Xob_xdat_file().Parse(bry, bry.length, Io_url_.Empty); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr_tst.java b/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr_tst.java new file mode 100644 index 000000000..4e86b470f --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr_tst.java @@ -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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; +import org.junit.*; +public class Xob_xdat_file_wtr_tst { + @Test public void Write() { + Io_mgr.Instance.InitEngine_mem(); + Io_url dir = Io_url_.mem_dir_("mem/dir"); + Xob_xdat_file_wtr wtr = Xob_xdat_file_wtr.new_file_(1000, dir); + tst_Write(wtr, "<1", "<1"); + tst_Write(wtr, ">a", "<1>a"); + tst_Write(wtr, ">b", "<1>a>b"); + tst_Add_idx(wtr, 7); + wtr.Bfr().Add(Bry_.new_a7("<2>b>cc")); + tst_Add_idx(wtr, 15); + wtr.Bfr().Add(Bry_.new_a7("<3>c>dd")); + tst_Add_idx(wtr, 23); + tst_Flush(wtr, String_.Concat + ( "!!!!(|!!!!)|!!!!)|\n" + , "<1>a>b\n" + , "<2>b>cc\n" + , "<3>c>dd\n" + )); + } + private void tst_Write(Xob_xdat_file_wtr wtr, String val, String expd) { + wtr.Bfr().Add(Bry_.new_u8(val)); + Tfds.Eq(expd, String_.new_u8(wtr.Bfr().Bfr(), 0, wtr.Bfr().Len())); + } + private void tst_Add_idx(Xob_xdat_file_wtr wtr, int expd) { + wtr.Add_idx(Byte_ascii.Nl); + Tfds.Eq(expd, wtr.Idx()[wtr.Idx_pos() - 1]); + } + private void tst_Flush(Xob_xdat_file_wtr wtr, String expd) { + Io_url url = wtr.Fil_url(); + wtr.Flush(Gfo_usr_dlg_.Test()); + String actl = Io_mgr.Instance.LoadFilStr(url); + Tfds.Eq(expd, actl); + } +} diff --git a/400_xowa/src/gplx/xowa/wikis/ttls/Xoa_ttl__err_tst.java b/400_xowa/src/gplx/xowa/wikis/ttls/Xoa_ttl__err_tst.java new file mode 100644 index 000000000..7d15326a7 --- /dev/null +++ b/400_xowa/src/gplx/xowa/wikis/ttls/Xoa_ttl__err_tst.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; +import org.junit.*; +public class Xoa_ttl__err_tst { + @Before public void init() {fxt.Clear();} private final Xoa_ttl_fxt fxt = new Xoa_ttl_fxt(); + @Test public void Invalid__angle() {fxt.Parse("").Expd_page_txt("Ab").Test();} + @Test public void Comment_eos() {fxt.Init_ttl("Ab" + , "" + ); + fxt.Test__html(fxt.Make__html__itms__null("B", "A")); + } + @Test public void Error_skip_line() { // PURPOSE: error should skip rest of line; was failing with array out of bounds; en.n:Portal:Austria/Wikipedia; DATE:2014-01-18 + fxt.Init__warns("dynamic_page_list:unknown_key: page=Test page key=Ctg_0 order"); // ignore warning message + fxt.Exec__parse(" category=Ctg_0 order=descending"); + fxt.Test__html("No pages meet these criteria."); + } + @Test public void Atr_has_template() { // PURPOSE: attribute also has template; DATE:2014-01-31 + fxt.Init__create_ctg("Test_page", "B", "A"); + fxt.Exec__parse + ( "" + , "category={{PAGENAME}}" + , "" + ); + fxt.Test__html(fxt.Make__html__itms__null("B", "A")); + } + @Test public void Err_page_ns_doesnt_exist() {// PURPOSE: check that is not enabled if wiki does not have Page / Index ns; PAGE:fr.w:Wikipedia:Le_Bistro/novembre_2006 DATE:2014-11-28 + // reset categories to (a) remove ns for Page / Index; (b) add back Category (else null error) + fxt.Wiki().Ns_mgr().Clear(); + fxt.Wiki().Ns_mgr().Add_new(14, "Category").Init(); + + fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached valid ns_page from previous tests + fxt.Fxt().Test_parse_page_wiki_str("category=a", "No pages meet these criteria."); + fxt.Wiki().Cfg_parser().Xtns().Itm_pages().Reset(); // must reset to clear cached invalid ns_page for next tests + + // reset categories for rest of tests + fxt.Wiki().Ns_mgr().Add_new(0, "").Init(); // call .Clear() to remove ns for Page / Index + } + @Test public void Ordermethod__invalid() { // PURPOSE: do not fail if ordermethod is invalid; PAGE:sr.d:Викиречник:Википројекат_1001_арапска_реч/Списак_уноса; DATE:2015-10-16 + fxt.Init__create_ctg("Ctg_0", "A", "B", "C"); + fxt.Exec__parse + ( "" + , "category=Ctg_0" + , "ordermethod=ascending" // should not throw error + , "ordermethod=sortkey" + , "" + ); + fxt.Test__html(fxt.Make__html__itms__null("A", "B", "C")); + } + @Test public void Encode_spaces() {// PURPOSE:encode spaces in href; PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19 + fxt.Init__create_ctg("Ctg_0", "A B"); + fxt.Exec__parse + ( "" + , "category=Ctg_0" + , "nofollow=true" + , "" + ); + fxt.Test__html(Gfh_utl.Replace_apos_concat_lines + ( "
          " + , "
        • A B
        • " // "/wiki/A_B" not "/wiki/A B" + , "
        " + )); + } + @Test public void Encode_quotes() {// PURPOSE:encode quotes; PAGE:en.b:Wikibooks:Alphabetical_classification/All_Books; DATE:2016-01-21 + fxt.Init__create_ctg("Ctg_0", "A\"B"); + fxt.Exec__parse + ( "" + , "category=Ctg_0" + , "nofollow=true" + , "" + ); + fxt.Test__html(Gfh_utl.Replace_apos_concat_lines + ( "
          " + , "
        • A"B
        • " // "/wiki/A_B" not "/wiki/A B" + , "
        " + )); + } + @Test public void Err__bad_key_causes_out_of_bound() { // PURPOSE: bad key causes out of bounds error; PAGE:de.n:Portal:Brandenburg DATE:2016-04-21 + fxt.Exec__parse + ( "" + , "category=Aa=b c=d" + , "category=B" + ); + fxt.Test__html(String_.Concat_lines_nl_skip_last + ( "<DynamicPageList>" + , "No pages meet these criteria.a=b c=d" + , "No pages meet these criteria." + )); + } +} +class Dpl_page_mok { + public Dpl_page_mok(int id, String ttl) {this.id = id; this.ttl = ttl;} + public int Id() {return id;} private int id; + public String Ttl() {return ttl;} private String ttl; + public static Dpl_page_mok new_(int id, String ttl) {return new Dpl_page_mok(id, ttl);} +} +class Dpl_xnde_fxt { + private final Xop_fxt fxt = new Xop_fxt(); + private final Bry_bfr bfr = Bry_bfr_.New(); + private String exec__raw; + private int next_id; + public void Clear() { + next_id = 100; + fxt.Reset(); + this.exec__raw = String_.Empty; + this.expd_warns = String_.Ary_empty; + fxt.App().Usr_dlg().Gui_wkr().Clear(); + fxt.Wiki().Hive_mgr().Clear(); + fxt.Wiki().Db_mgr().Save_mgr().Clear(); // NOTE: must clear to reset next_id to 0; Init__create_ctg assumes clean slate from 0 + fxt.Wiki().Xtn_mgr().Xtn_proofread().Enabled_y_(); + fxt.Wiki().Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory; + fxt.Wiki().Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init(); + Io_mgr.Instance.InitEngine_mem(); + } + public Xowe_wiki Wiki() {return fxt.Wiki();} + public Xop_fxt Fxt() {return fxt;} + public void Init__warns(String... v) {expd_warns = v;} private String[] expd_warns; + public void Init__create_ctg(String ctg, String... ttls) { + int len = ttls.length; + Dpl_page_mok[] ary = new Dpl_page_mok[len]; + for (int i = 0; i < len; i++) + ary[i] = Dpl_page_mok.new_(++next_id, ttls[i]); + Init__create_ctg_pages(ctg, ary); + } + public void Init__create_ctg_pages(String ctg_ttl, Dpl_page_mok... pages) { + Xoctg_catpage_ctg ctg = new Xoctg_catpage_ctg(1, Bry_.new_u8(ctg_ttl)); + int pages_len = pages.length; + Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp(); + for (int i = 0; i < pages_len; i++) { + Dpl_page_mok page = pages[i]; + int id = page.Id(); + String ttl_str = page.Ttl(); + Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ttl_str)); + Xoae_page page_obj = fxt.Wiki().Data_mgr().Load_page_by_ttl(ttl); + if (page_obj.Db().Page().Exists_n()) { + fxt.Init_page_create(ttl_str, ttl_str); + fxt.Init_id_create (id, 0, 0, false, 5, Xow_ns_.Tid__main, ttl_str); + } + byte tid = gplx.xowa.addons.wikis.ctgs.Xoa_ctg_mgr.Tid__page; + Xoctg_catpage_itm catpage_itm = Xoctg_catpage_itm.New_by_ttl(tid, page.Id(), ttl); + tmp.Add(catpage_itm); + } + tmp.Make_by_ctg(ctg); + Xoctg_catpage_mgr catpage_mgr = fxt.Wiki().Ctg__catpage_mgr(); + catpage_mgr.Cache__add(Bry_.new_u8("Category:" + ctg_ttl), ctg); + } + public String Make__html__itms__null(String... pages) {return this.Make__html(null, pages);} + public String Make__html(String itm_html, String... pages) { + bfr.Add_str_a7("
          ").Add_byte_nl(); + int pages_len = pages.length; + for (int i = 0; i < pages_len; i++) { + String page = pages[i]; + bfr.Add_str_a7("
        • ").Add_str_a7(page).Add_str_a7("
        • ").Add_byte_nl(); + } + bfr.Add_str_a7("
        ").Add_byte_nl(); + return bfr.To_str_and_clear(); + } + public void Exec__parse(String... raw_lines) {this.exec__raw = String_.Concat_lines_nl_skip_last(raw_lines);} + public void Test__html(String expd) { + fxt.Test_parse_page_wiki_str(exec__raw, expd); + fxt.tst_Warn(expd_warns); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pages_using_pending_changes_func_tst.java b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pages_using_pending_changes_func_tst.java new file mode 100644 index 000000000..f57048f0f --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pages_using_pending_changes_func_tst.java @@ -0,0 +1,23 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import org.junit.*; import gplx.xowa.wikis.pages.skins.*; +public class Pages_using_pending_changes_func_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_html_full_str("{{PAGESUSINGPENDINGCHANGES}}", "0"); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pending_change_level_func_tst.java b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pending_change_level_func_tst.java new file mode 100644 index 000000000..8b5a02a77 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/Pending_change_level_func_tst.java @@ -0,0 +1,23 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.flaggedRevs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import org.junit.*; import gplx.xowa.wikis.pages.skins.*; +public class Pending_change_level_func_tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_html_full_str("{{PENDINGCHANGELEVEL}}", ""); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/flaggedRevs/scribunto/Flagged_revs_lib_tst.java b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/scribunto/Flagged_revs_lib_tst.java new file mode 100644 index 000000000..eaf1a3110 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/flaggedRevs/scribunto/Flagged_revs_lib_tst.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.flaggedRevs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.flaggedRevs.*; +import org.junit.*; +import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.mocks.*; +public class Flagged_revs_lib_tst { + private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Flagged_revs_lib lib; + @Before public void init() { + fxt.Clear(); + lib = new Flagged_revs_lib(); + lib.Init(); + lib.Core_(fxt.Core()); + } + @Test public void GetStabilitySettings() { + fxt.Test__proc__objs__nest(lib, Flagged_revs_lib.Invk_getStabilitySettings, Object_.Ary("Page1"), String_.Concat_lines_nl_skip_last + ( "1=" + , " over"+"ride=0" + , " autoreview=" + , " expiry=infinity" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/gallery/Gallery_mgr_base__basic__tst.java b/400_xowa/src/gplx/xowa/xtns/gallery/Gallery_mgr_base__basic__tst.java new file mode 100644 index 000000000..b60629d45 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/gallery/Gallery_mgr_base__basic__tst.java @@ -0,0 +1,185 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import org.junit.*; +import gplx.xowa.htmls.*; import gplx.xowa.files.fsdb.*; +public class Gallery_mgr_base__basic__tst { + private Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Basic() { + fxt.Test_html_str(String_.Concat_lines_nl_skip_last + ( "" + , "A.png|''a1''" + , "B.png|''b1''" + , "" + ), String_.Concat_lines_nl_skip_last + ( "" + )); + fxt.Test_html_modules_js(String_.Concat_lines_nl_skip_last + ( "" + , " " + )); + } + @Test public void Tmpl() { + fxt.Fxt().Init_defn_add("test_tmpl", "b"); + fxt.Test_html_frag("File:A.png|a{{test_tmpl}}c", "

        abc\n

        "); + } + @Test public void Itm_defaults_to_120() { + fxt.Test_html_frag("File:A.png|a", "\"\""); + } + @Test public void Height_fix() { + fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "y"); + fxt.Test_html_frag("File:A.png|a
        c
        ", " width=\"120\" height=\"250\""); + fxt.Test_html_frag("
        "); + fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "n"); + } + @Test public void Alt() { + fxt.Test_html_frag("File:A.png|b|alt=c" + , "\"c\"" + , "

        b\n

        " + ); + } + @Test public void Link() { + fxt.Test_html_frag("File:A.png|b|link=c", "File:A.pdf|b|page=8" + , "A.pdf/120px-8.jpg" // make sure page 8 shows up + ); + } + @Test public void Alt_caption_multiple() { + fxt.Test_html_frag("File:A.png|alt=b|c[[d|e]]f", "

        cef\n

        "); + } + @Test public void Alt_escape_quote() { + fxt.Test_html_frag("File:A.png|b|alt=c\"d'e", "alt=\"c"d'e\""); + } + @Test public void Caption_null() { // PURPOSE: null caption causes page to fail; EX: de.w:Lewis Caroll; Datei:A.png; DATE:2013-10-09 + fxt.Test_html_frag("File:A.png", "
        \n"); + } + @Test public void Ttl_has_no_ns() { // PURPOSE: MW allows ttl to not have ns; DATE: 2013-11-18 + fxt.Test_html_frag("A.png|b", "\"\""); // make sure image is generated + } + @Test public void Ref() { // PURPOSE: inside was not showing up in ; DATE:2013-10-09 + fxt.Test_html_frag("File:A.png|b" + , "

        [1]\n

        " + , String_.Concat_lines_nl + ( "
        " + , "
      1. ^ b
      2. " + , "
      " + ) + ); + } + @Test public void Packed() { + fxt.Test_html_frag("File:A.png|a", "
    • +		, "

      " + , "" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java new file mode 100644 index 000000000..e022fdccb --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/miscs/Xop_under_lxr_tst.java @@ -0,0 +1,226 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; +public class Xop_under_lxr_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @After public void term() {fxt.Init_para_n_();} + @Test public void Toc_basic() { + fxt.Test_parse_page_all_str("a__TOC__b", "ab"); + } + @Test public void Toc_match_failed() { + fxt.Test_parse_page_all_str("a__TOCA__b", "a__TOCA__b"); + } + @Test public void Toc_match_ci() { + fxt.Test_parse_page_all_str("a__toc__b", "ab"); + } + @Test public void Notoc_basic() { + fxt.Wtr_cfg().Toc__show_(Bool_.Y); // NOTE: must enable in order for TOC to show (and to make sure NOTOC suppresses) + fxt.Test_parse_page_all_str__esc(String_.Concat_lines_nl + ( "__NOTOC__" + , "==a==" + , "==b==" + , "==c==" + , "==d==" + ), String_.Concat_lines_nl + ( "

      a

      " + , "" + , "

      b

      " + , "" + , "

      c

      " + , "" + , "

      d

      " + )); + fxt.Wtr_cfg().Toc__show_(Bool_.N); + } + @Test public void Ignore_pre() { + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str("a\n __NOTOC__\n", String_.Concat_lines_nl + ( "

      a" + , "

      " // NOTE: do not capture " " in front of __NOTOC__; confirmed against MW; DATE:2014-02-19 + , "" + , "


      " + , "

      " + )); + fxt.Init_para_n_(); + } + @Test public void Toc_works() { // PURPOSE: make sure "suppressed" pre does not somehow suppress TOC + fxt.Wtr_cfg().Toc__show_(Bool_.Y); + fxt.Init_para_y_(); + Bry_bfr tmp = Bry_bfr_.New(); + String expd = String_.Concat_lines_nl + ( "

      a" + , "

      " + , "
      " + , "
      " + , "

      Contents

      " + , "
      " + , "
        " + , "
      • 1 b" + , "
      • " + , "
      " + , "
      " + , "" + , "

      b

      " + ); + String actl = gplx.xowa.addons.htmls.tocs.Xowe_hdr_bldr_fxt.Bld_page_with_toc(tmp, fxt, "a\n__TOC__\n==b==\n"); + Tfds.Eq_str_lines(expd, actl); + fxt.Init_para_n_(); + fxt.Wtr_cfg().Toc__show_(Bool_.N); + } + @Test public void Ignore_pre_after() { // PURPOSE: "__TOC__\s\n" must be trimmed at end, else false pre; assertion only (no code exists to handle this test); DATE:2013-07-08 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "__NOTOC__ " + , "b" + ), String_.Concat_lines_nl + ( "

      a" + , "

      " // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19 + , "" + , "

      b" + , "

      " + )); + fxt.Init_para_n_(); + } + @Test public void Disambig() { // PURPOSE: ignore "__DISAMBIG__"; EX:{{disambiguation}} DATE:2013-07-24 + fxt.Test_parse_page_all_str("__DISAMBIG__", ""); + } + @Test public void Nocontentconvert() { // simple test; test for flag only; DATE:2014-02-06 + gplx.xowa.parsers.Xop_ctx_page_data page_data = fxt.Ctx().Page_data(); + Tfds.Eq(page_data.Lang_convert_content(), true); + Tfds.Eq(page_data.Lang_convert_title(), true); + fxt.Test_parse_page_all_str("__NOCONTENTCONVERT__ __NOTITLECONVERT__", " "); + Tfds.Eq(page_data.Lang_convert_content(), false); + Tfds.Eq(page_data.Lang_convert_title(), false); + } + @Test public void Eos() { // PURPOSE: check that __ at eos doesn't fail; es.s:Luisa de Bustamante: 3; DATE:2014-02-15 + fxt.Test_parse_page_all_str("__", "__"); + } + @Test public void Pre_toc() { // PURPOSE: make sure that "\n\s__TOC" does not create pre; PAGE:de.w:Main_Page; DATE:2014-04-07 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " __TOC__ " // NOTE: this should not be a pre; DATE:2014-07-05 + , "b" + ), String_.Concat_lines_nl + ( "

      a" + , "

      " + , " " // NOTE: \s should not be captured, but leaving for now + , "" + , "

      b" + , "

      " + )); + fxt.Init_para_n_(); + } + @Test public void Pre_notoc() { // PURPOSE: make sure that "\n\s__NOTOC" does not create pre. note that mechanism is different from TOC; DATE:2014-07-05 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " __NOTOC__ " // NOTE: does not capture " "; confirmed against MW + , "b" + ), String_.Concat_lines_nl + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + )); + fxt.Init_para_n_(); + } + @Test public void Hook_alt() { // PURPOSE: ja wikis use alternate __; DATE:2014-03-04 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, true, "__TOC__"); + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__TOC__b", "ab"); + } + @Test public void Ascii_ci() { // PURPOSE: case-insensitive ascii; DATE:2014-07-10 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__TOC__"); + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__TOC__b", "ab"); + fxt.Test_parse_page_all_str("a__toc__b", "ab"); + } + @Test public void Utf8_ci() { // PURPOSE: case-insensitive UTF8; DATE:2014-07-10 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + lang.Case_mgr_u8_(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__AÉI__"); + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__AÉI__b", "ab"); + fxt.Test_parse_page_all_str("a__aéi__b", "ab"); + } + @Test public void Utf8_ci_asymmetric() { // PURPOSE: case-insensitive UTF8; asymmetric; DATE:2014-07-10 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + lang.Case_mgr_u8_(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc, false, "__İÇİNDEKİLER__"); // __TOC__ for tr.w + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__İçindekiler__b", "ab"); + } + @Test public void Cs() { // PURPOSE: cs (ascii / utf8 doesn't matter); DATE:2014-07-11 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc , Bool_.Y, "__TOC__"); + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__TOC__b" , "ab"); // ci.pass + fxt.Test_parse_page_all_str("a__toc__b" , "a__toc__b"); // ci.pass + } + @Test public void Ascii_cs_ci() { // PURPOSE: test simultaneous cs and ci; DATE:2014-07-11 + Xowe_wiki wiki = fxt.Wiki(); Xol_lang_itm lang = wiki.Lang(); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_toc , Bool_.N, "__TOC__"); + fxt.Init_lang_kwds(lang, Xol_kwd_grp_.Id_notoc , Bool_.Y, "__NOTOC__"); + wiki.Parser_mgr().Main().Init_by_lang(lang); + fxt.Test_parse_page_all_str("a__TOC__b" , "ab"); // ci.pass + fxt.Test_parse_page_all_str("a__toc__b" , "ab"); // ci.pass + fxt.Test_parse_page_all_str("a__NOTOC__b" , "ab"); // cs.pass + fxt.Test_parse_page_all_str("a__notoc__b" , "a__notoc__b"); // cs.fail + } + @Test public void Notoc_in_tmpl() { // PURPOSE: test simultaneous cs and ci; DATE:2017-06-11 + fxt.Init_page_create("Template:Notoc", "page_text\n__NOTOC__"); + fxt.Wiki().Html_mgr().Html_wtr().Cfg().Toc__show_(true); + + fxt.Test__parse_to_html_w_skin(String_.Concat_lines_nl + ( "==A1==" + , "==A2==" + , "==A3==" + , "==A4==" + , "{{Notoc}}" + ), String_.Concat_lines_nl + ( "
      " + , "
      " + , "

      Contents

      " + , "
      " + , "
        " + , "
      • 1 A1" + , "
      • " + , "
      • 2 A2" + , "
      • " + , "
      • 3 A3" + , "
      • " + , "
      • 4 A4" + , "
      • " + , "
      " + , "
      " + , "

      A1

      " + , "" + , "

      A2

      " + , "" + , "

      A3

      " + , "" + , "

      A4

      " + , "page_text" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/paras/Xop_nl_tab_lxr_tst.java b/400_xowa/src/gplx/xowa/parsers/paras/Xop_nl_tab_lxr_tst.java new file mode 100644 index 000000000..ca2d68cc5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/paras/Xop_nl_tab_lxr_tst.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_nl_tab_lxr_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void teardown() {fxt.Init_para_n_();} + @Test public void Basic() { // PURPOSE: \n\t|- should be recognized as tblw; EX:zh.v:西安; DATE:2014-05-06 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "\t|-" + , "|a" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + )); + } + @Test public void Ws() { // PURPOSE: \n\t|- should be recognized as tblw; EX:zh.v:西安; DATE:2014-05-06 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "\t |-" // \t + , "|a" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + )); + } + @Test public void Ignore() {// PURPOSE: \n\t should not be pre; EX:pl.w:Main_Page; DATE:2014-05-06 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "\t b" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "\t b" + , "c" + , "

      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_basic_tst.java b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_basic_tst.java new file mode 100644 index 000000000..e665c230e --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_basic_tst.java @@ -0,0 +1,1026 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.lists.*; +public class Xop_para_wkr_basic_tst { + private final Xop_fxt fxt = new Xop_fxt(); String raw; + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} + @After public void teardown() {fxt.Init_para_n_();} + @Test public void Nl_0() { + raw = "a"; + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_end_para_(1) // t2/x1: a -> a\n

      1=bgn 2=blank + ); + } + @Test public void Nl_1() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "b" // NOTE: depend on html editor removing \n between a and b + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_blank_(2) // t2/x1: a\n -> a\n<-p> 1=bgn 2=blank + , fxt.tkn_txt_(2, 3), fxt.tkn_para_end_para_(3) // t3/x1: b -> b\n

      2=blank 3=blank + ); + } + @Test public void Nl_2() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_blank_(2) // t2/x1: a\n -> a\n<-p> 1=bgn + , fxt.tkn_para_mid_para_(3) // n3 : \n ->

      3=mid NOTE:

      doesn't get converted until t1 + , fxt.tkn_txt_(3, 4), fxt.tkn_para_end_para_(4) // t1/x1: b -> b\n

      2=mid 3=blank + ); + } + @Test public void Nl_3() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "" + , "b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "


      " // NOTE: this looks strange, but it emulates MW + , "b" + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_blank_(2) // t2/x1: a\n -> a\n<-p> 1=bgn + , fxt.tkn_para_mid_para_(3) // n3 : \n ->

      3=mid NOTE:

      doesn't get converted until n1 + , fxt.tkn_xnde_br_(3), fxt.tkn_para_blank_(4) // n1/x1: \n ->
      \n<-p> 2=mid 3=blank + , fxt.tkn_txt_(4, 5), fxt.tkn_para_end_para_(5) // t1/x1: b -> b\n

      4=blank + ); + } + @Test public void Nl_4() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , "" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + , "" + , "

      c" + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_blank_(2) // t2/x1: a\n -> a\n<-p> 1=bgn + , fxt.tkn_para_mid_para_(3) // n3 : \n ->

      3=mid NOTE:

      doesn't get converted until n1 + , fxt.tkn_txt_(3, 4), fxt.tkn_para_blank_(5) + , fxt.tkn_para_mid_para_(6) + , fxt.tkn_txt_(6, 7), fxt.tkn_para_end_para_(7) + ); + } + @Test public void Nl_5() { + raw = String_.Concat_lines_nl_skip_last + ( "

      a" + , "b" + , "

      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "b" + , "

      " + )); + } + @Test public void Pre() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      c" + , "

      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) + , fxt.tkn_txt_(0, 1), fxt.tkn_para_end_para_bgn_pre_(2) + , fxt.tkn_txt_(3, 4), fxt.tkn_para_end_pre_bgn_para_(5) + , fxt.tkn_txt_(5, 6), fxt.tkn_para_end_para_(6) + ); + } + @Test public void Pre_2() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , " c" + , "d" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "c"
      +			, "
      " + , "" + , "

      d" + , "

      " + )); + } + @Test public void Pre_3() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , " c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + , "" + , "
      c"
      +			, "
      " + )); + } + @Test public void Pre_4() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , " b" + , "" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      c" + , "

      " + )); + } + @Test public void Pre_5() { // PAGE:en.w:SHA-2 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "" + , " c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "
      c"
      +			, "
      " + )); + } + @Test public void Pre_6() { // PURPOSE: close list if open; PAGE:en.w:SHA-2 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "*a" + , " b" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a" + , "
      • " + , "
      " + , "" + , "
      b"
      +			, "
      " + )); + } + @Test public void Pre_init() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " a" + ), String_.Concat_lines_nl_skip_last + ( "
      a"
      +			, "
      " + )); + } + @Test public void Pre_leading_ws() { // PURPOSE: preserve leading ws; PAGE:en.w:Merge sort + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " a" + , " b" + , " c" + ), String_.Concat_lines_nl_skip_last + ( "
      a"
      +			, "  b"
      +			, "    c"
      +			, "
      " + )); + } + @Test public void Pre_newLine() { // PURPOSE: "\n \n" inside pre should be ignored; trims to "" + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , " " + , " c" + , "d" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, ""
      +			, "c"
      +			, "
      " + , "" + , "

      d" + , "

      " + )); + } + @Test public void Pre_xnde() { // PURPOSE:
      and other xndes should invalidate pre on same line; EX: "\n a
      b"; SEE: any {{refimprove}} article + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b
      c
      d" + , "e" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , " b
      c
      d" + , "" + , "

      e" + , "

      " + )); + } + @Test public void Pre_lnki_in_td() { // PURPOSE: ]] in td causes strange parsing; SEE: any {{Commons category}} article; updated test; DATE:2015-03-31 + raw = String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "" + , "
      [[File:A.png|alt=" + , " ]]b" + , "
      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      \"" + , " b" + , "
      " + )); + } + @Test public void Pre_trailing_end() { // PURPOSE: "\n " at end was failing + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + )); + } + @Test public void Pre_xnde_code() { // PAGE:en.w:cURL + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      c" + , "

      " + )); + } + @Test public void Pre_xnde_pre() { + raw = String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • " + , "
        "
        +			, "*a"
        +			, "
        " + , "
      • " + , "
      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • " + , "
        "
        +			, "*a"
        +			, "
        " + , "
      • " + , "
      " + )); + } + @Test public void Pre_td() { // PURPOSE: EX: "\n a"; deactivates pre; PAGE:en.w:AGPLv3 + raw = String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
      " + , " [[File:A.png|30x30px]]
      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , " \"\"" + , "
      " + )); + } + @Test public void Nl_2_2_space() { // test trim + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , " " + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19 + , "" + , "

      c" + , "

      " + )); + } + @Test public void File_1() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "[[Image:Test.png|thumb|caption]]" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , File_html() + , "" + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) + , fxt.tkn_txt_(0, 1), fxt.tkn_para_end_para_(2) + , fxt.tkn_lnki_(2, 34) + , fxt.tkn_para_blank_(34) + ); + } + @Test public void File_2() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "[[Image:Test.png|thumb|caption]]" + , "b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , File_html() + , "" + , "

      b" + , "

      " + , "" + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_end_para_(2) + , fxt.tkn_lnki_(2, 34) + , fxt.tkn_para_bgn_para_(35) + , fxt.tkn_txt_(35, 36), fxt.tkn_para_end_para_(36) + ); + } + @Test public void File_3() { + raw = String_.Concat_lines_nl_skip_last + ( "[[Image:Test.png|thumb|caption]]" + , "" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( File_html() + , "" + , "

      c" + , "

      " + , "" + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_blank_(0) // x0: ->

      1=blank + , fxt.tkn_lnki_(0, 32) + , fxt.tkn_para_blank_(33) + , fxt.tkn_para_bgn_para_(34) + , fxt.tkn_txt_(34, 35), fxt.tkn_para_end_para_(35) + ); + } + @Test public void File_4() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "[[Image:Test.png|thumb|caption]]" + , "" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , File_html() + , "" + , "

      c" + , "

      " + , "" + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_blank_(2) + , fxt.tkn_para_end_para_(3) + , fxt.tkn_lnki_(3, 35) + , fxt.tkn_para_blank_(36) + , fxt.tkn_para_bgn_para_(37) + , fxt.tkn_txt_(37, 38), fxt.tkn_para_end_para_(38) + ); + } + @Test public void File_5() { // PURPOSE: \n in caption should not force paragraph + raw = String_.Concat_lines_nl_skip_last + ( "[[Image:Test.png|thumb|" + , "caption]]" + , "a" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( File_html() + , "" + , "

      a" + , "

      " + , "" + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_blank_(0) + , fxt.tkn_lnki_(0, 33) + , fxt.tkn_para_bgn_para_(34) + , fxt.tkn_txt_(34, 35), fxt.tkn_para_end_para_(35) + ); + } + @Test public void File_6() { // PAGE:en.w:Pyotr Ilyich Tchaikovsky + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " [[Image:Test.png|thumb|caption]]" + , "" + , "b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , File_html() + , "" + , "

      b" + , "

      " + , "" + )); + } + @Test public void List() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "*b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
        " + , "
      • b" + , "
      • " + , "
      " + )); + fxt.Test_parse_page_wiki(raw + , fxt.tkn_para_bgn_para_(0) // x0: ->

      1=blank + , fxt.tkn_txt_(0, 1), fxt.tkn_para_end_para_(2) // t2/x1: a\n -> a\n

      1=bgn 2=blank + , fxt.tkn_list_bgn_(1, 3, Xop_list_tkn_.List_itmTyp_ul) + , fxt.tkn_txt_(3, 4) + , fxt.tkn_list_end_(4) + , fxt.tkn_para_blank_(4) + ); + } + @Test public void Hdr_1() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "==b==" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b

      " + , "" + )); + } + @Test public void Hdr_2() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "==b==" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b

      " + , "" + )); + } + @Test public void Hdr_list() { + raw = String_.Concat_lines_nl_skip_last + ( "==a==" + , "*b" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a

      " + , "" + , "
        " + , "
      • b" + , "
      • " + , "
      " + )); + } + @Test public void Hdr_list_multi() { + raw = String_.Concat_lines_nl_skip_last + ( "==a==" + , "" + , "" + , "*b" + , "*c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a

      " + , "" + , "
        " + , "
      • b" + , "
      • " + , "
      • c" + , "
      • " + , "
      " + )); + } + @Test public void Para_hdr() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "b" + , "" + , "==c==" + , "d" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + , "" + , "

      c

      " + , "" + , "

      d" + , "

      " + , "" + )); + } + @Test public void Div() { // PURPOSE:
      should not go into para + raw = String_.Concat_lines_nl_skip_last + ( "a" + , "" + , "==b==" + , "
      c
      " + , "d" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b

      " + , "
      c
      " + , "" + , "

      d" + , "

      " + , "" + )); + } + @Test public void Div_para() { // PURPOSE:

      inserted between closing divs + raw = String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "a" + , "
      " + , "
      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , "" + , "

      a" + , "

      " + , "
      " + , "
      " + )); + } + @Test public void Tbl() { + raw = String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "" + , "
      a" + , "b" + , "
      " + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + )); + } + @Test public void Tbl_leading_ws() { // REF: [[Corneal dystrophy (human)]] + raw = String_.Concat_lines_nl_skip_last + ( " {|" + , " |-" + , " |a" + , " |}" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Bos_pipe() { // PURPOSE: | is interpreted as a tblw dlm and calls a different section of code + fxt.Test_parse_page_wiki_str("|", String_.Concat_lines_nl_skip_last + ( "

      |" + , "

      " + , "" + )); + } + @Test public void Ws_mistakenly_ignored() {// PURPOSE: ws before ''' somehow gets ignored; EX: en.w:Vacuum tube; {{Unreferenced section|date=July 2010|reason=date taken from existing cn}} + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "
      a" + , " '''b'''
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + )); + } + @Test public void Pre_7() { // PURPOSE: alternating pres; EX:w:World Wide Web + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "c" + , " d" + , "e" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +		, "
      " + , "" + , "

      c" + , "

      " + , "" + , "
      d"
      +		, "
      " + , "" + , "

      e" + , "

      " + , "" + )); + } + @Test public void Nowiki() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "c" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +		, "
      " + , "" + , "

      c" + , "

      " + , "" + )); + } + @Test public void Nowiki_tbl() { // EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " bc" + , "" + , "{|" + , "|-" + , "|d" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      bc"
      +		, "
      " +// , "" + , "" + , " " + , " " + , " " + , "
      d" + , "
      " + , "" + )); + } + @Test public void Pre_at_end_should_autoclose() { // PURPOSE: as per proc_name + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +		, "
      " + , "" + )); + } + @Test public void Pre_xtn() { // PURPOSE: (and other xtn) was unnecessarily canceling pre; PAGE:en.w:MD5_Hash + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( " a" + , " b" + , " c" + , "" + , "d" + ), String_.Concat_lines_nl_skip_last + ( "
      a"
      +		, "[1]"
      +		, "c"
      +		, "
      " + , "" + , "

      d" + , "

      " + , "" + )); + } + @Test public void Pre_tbl() { // PURPOSE: pre was being garbled by tables b/c table was ignoring whitespace; DATE:2013-02-11 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|a" + , "|}" + , "" + , "c" + , "" + , " d" + , "" + , "{|" + , "| e" + , "|}" + , "" + , "f" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + , "

      c" + , "

      " + , "" + , "
      d"
      +		, "
      " + , "" + , " " + , " " + , " " + , "
      e" + , "
      " + , "" + , "

      f" + , "

      " + , "" + )); + } + @Test public void Nowiki_tbl2() { // EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|a" + , "|}" + , "" + , "b" + , "" + , " c d" + , "" + , "{|" + , "|e" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + , "

      b" + , "

      " + , "" + , "
      c d"
      +		, "
      " + , "" + , " " + , " " + , " " + , "
      e" + , "
      " + )); + } + @Test public void Pre_nowiki() { // PURPOSE: nowikis inside pre should be ignored; DATE:2013-03-30 + fxt.Test_parse_page_all_str("\n a<b" , "\n
      a<b\n
      \n"); // basic + } + @Test public void Para_bos_tblw() { + raw = String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "|}" + ); + fxt.Test_parse_page_all_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Para_bos_tblx() { + raw = String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
      a" + , "
      " + ); + fxt.Test_parse_page_all_str(raw, String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Pre_tblw_td() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "|" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      |" + , "c" + , "

      " + , "" + )); + } + @Test public void Pre_tblw_tr() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "|-" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      |-" + , "c" + , "

      " + , "" + )); + } + @Test public void Pre_tblw_te() { + raw = String_.Concat_lines_nl_skip_last + ( "a" + , " b" + , "|}" + , "c" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "
      b"
      +			, "
      " + , "" + , "

      |}" + , "c" + , "

      " + , "" + )); + } + private String File_html() {return File_html("Image", "Test.png", "d/9", "caption");} + public static String File_html(String ns, String ttl, String md5, String caption) { + return String_.Concat_lines_nl_skip_last + ( "
      " + , "
      " + , " \"\"" + , "
      " + , "
      " + caption + "" + , "
      " + , "
      " + , "
      " + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_para_tst.java b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_para_tst.java new file mode 100644 index 000000000..75e77f065 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_para_tst.java @@ -0,0 +1,107 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_para_wkr_para_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void teardown() {fxt.Init_para_n_();} + @Test public void Pre_then_xnde_pre() { // PURPOSE: if ws_pre is in effect, xnde_pre should end it; EX: b:Knowing Knoppix/Other applications + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( " a" + , "b
      c"
      +		,	"d
      " + , "e" + ), String_.Concat_lines_nl_skip_last + ( "
      a"
      +		,	"
      " + , "b
      c"
      +		,	"d
      " + , "" + , "

      e" + , "

      " + , "" + )); + } + @Test public void List_ignore_pre_lines() { // PURPOSE: "\s\n" should create new list; was continuing previous list; DATE:2013-07-12 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( ": a" + , ":* b" + , " " + , ": c" + , ":* d" + ) + , String_.Concat_lines_nl_skip_last + ( "
      " + , "
      a" + , "" + , "
        " + , "
      • b" + , "
      • " + , "
      " + , "
      " + , "
      " + , "" + , "
      " + , "
      c" + , "" + , "
        " + , "
      • d" + , "
      • " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Multiple_nl_in_tblx() { // PURPOSE: "\n\n\n" was causing multiple breaks; EX:fr.w:Portail:G�nie m�canique; DATE:2014-02-17 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "" + , "" + , "" + , "" + , "" + , "" + , "
      a" + , "
      " + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + ) + ); + } + @Test public void Ignore_cr() { // PURPOSE: handle "\r\n"; EX: Special:MovePage; DATE:2014-03-02 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a\r" + , "\r" + , "b\r" + ) + , String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "" + , "

      b" + , "

      " + , "" + ) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_pre_tst.java b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_pre_tst.java new file mode 100644 index 000000000..ab3266d75 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/paras/Xop_para_wkr_pre_tst.java @@ -0,0 +1,258 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.paras; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_para_wkr_pre_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void teardown() {fxt.Init_para_n_();} + @Test public void Pre_ignore_bos() { // PURPOSE: ignore pre at bgn; DATE:2013-07-09 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( " " + , "b" + ), String_.Concat_lines_nl + ( "

      " + , "b" + , "

      " + )); + } + @Test public void Pre_ignore_bos_tblw() { // PURPOSE: ignore pre at bgn shouldn't break tblw; EX:commons.wikimedia.org; DATE:2013-07-11 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( " " + , "{|" + , "|-" + , "|a" + , "|}" + ), String_.Concat_lines_nl + ( "

      " // NOTE:

      added for TRAILING_TBLW fix; DATE:2017-04-08 + , "

      " + , "" + , " " + , " " + , " " + , "
      a" + , "
      " + )); + } + @Test public void Ignore_bos_xnde() { // PURPOSE: space at bgn shouldn't create pre; EX:commons.wikimedia.org; "
      a\n
      "; DATE:2013-11-28 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      a" // NOTE: leading " " matches MW; DATE:2014-06-23 + , "
      " + ), String_.Concat_lines_nl_skip_last + ( "
      a" + , "
      " + , "" + )); + } + @Test public void Ignore_pre_in_gallery() {// PURPOSE: pre in gallery should be ignored; EX:uk.w:EP2; DATE:2014-03-11 + gplx.xowa.xtns.gallery.Gallery_mgr_wtr.File_found_mode = Bool_.Y_byte; + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + , " " + , " File:A.png" + , " " + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , " " + ,"" + )); + gplx.xowa.xtns.gallery.Gallery_mgr_wtr.File_found_mode = Bool_.N_byte; + } + @Test public void Pre_xnde_gallery() { // PURPOSE: should invalidate pre; EX: en.w:Mary, Queen of Scots + gplx.xowa.xtns.gallery.Gallery_mgr_wtr.File_found_mode = Bool_.Y_byte; + fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki()); + String raw = String_.Concat_lines_nl_skip_last + ( " " + , "File:A.png|b" + , "" + ); + fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last + ( " " + )); + gplx.xowa.xtns.gallery.Gallery_mgr_wtr.File_found_mode = Bool_.N_byte; + } + @Test public void Ignore_pre_in_center() {// PURPOSE: pre in gallery should be ignored; EX:uk.w:EP2; DATE:2014-03-11 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "a" + , "
      b" + , "
      " + , "d" + ), String_.Concat_lines_nl_skip_last + ( "

      a" + , "

      " + , "
      b" + , "
      " + , "" + , "

      d" + , "

      " + ) + ); + } + @Test public void Remove_only_1st_space() { // PURPOSE: pre should only remove 1st space]; EX: w:Wikipedia:WikiProject_History/CategoryExample; DATE:2014-04-14 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " a" + , " b" + , " c" + ), String_.Concat_lines_nl_skip_last + ( "
         a"
      +		, "   b"
      +		, "   c"
      +		, "
      " + ) + ); + } + @Test public void Remove_only_1st_space__bos() { // PURPOSE: similar to above but check that pre at \n\s is indented correctly; DATE:2014-04-14 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , " a" + , " b" + ), String_.Concat_lines_nl_skip_last + ( "" + , "
         a"
      +		, "   b"
      +		, "
      " + ) + ); + } + @Test public void Ignore_tblw_td() {// PURPOSE: \n\s| should continue pre; EX:w:Wikipedia:WikiProject_History/CategoryExample; DATE:2014-04-14 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( " a" + , " |" + , " b" + ), String_.Concat_lines_nl_skip_last + ( "
      a"
      +		, "|"
      +		, "b"
      +		, "
      " + ) + ); + } + @Test public void Tab() { // PURPOSE: tab inside pre was being converted to space; PAGE:en.w:Cascading_Style_Sheets DATE:2014-06-23 + fxt.Test_html_full_str + ( " \ta" + , String_.Concat_lines_nl + ( "
      \ta"
      +		, "
      " + )); + } + @Test public void Style() { // PURPOSE: " " + ), String_.Concat_lines_nl + ( "
      <style>"
      +		, "</style>"
      +		, "
      " + )); + } + @Test public void Nl_only() { // PURPOSE: wiki_pre with \n only was being dropped; PAGE:en.w:Preferred_number DATE:2014-06-24 + fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last + ( " a" + , " " // was being dropped + , " b" + ), String_.Concat_lines_nl + ( "
      a"
      +		, ""	// make sure it's still there
      +		, "b"
      +		, "
      " + )); + } + @Test public void Nl_w_ws() { // PURPOSE: based on Nl_only; make sure that 1 or more spaces does not add extra \n; PAGE:en.w:Preferred_number DATE:2014-06-24 + fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last + ( " a" + , " " // 2 spaces + , " b" + ), String_.Concat_lines_nl + ( "
      a"
      +		, " "	// 1 space
      +		, "b"
      +		, "
      " + )); + } + @Test public void Nl_many() { // PURPOSE: handle alternating \n\s; PAGE:en.w:Preferred_number DATE:2014-06-24 + fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last + ( " a" + , " " + , " b" + , " " + , " c" + ), String_.Concat_lines_nl + ( "
      a"
      +		, ""
      +		, "b"
      +		, ""
      +		, "c"
      +		, "
      " + )); + } + @Test public void Source() { // PURPOSE: " " in pre has issues; PAGE:en.w:Comment_(computer_programming) DATE:2014-06-23 + fxt.Init_para_y_(); + fxt.Test_html_wiki_str(String_.Concat_lines_nl + ( " " + , " " + , " a" + , " " + , " " + ), String_.Concat_lines_nl + ( "

      " // this is wrong, but will be stripped by tidy + , "

      " + , "
      "
      +		, " a"
      +		, "
      " + , "" + , "


      " // also wrong, but leave for now + , "

      " + )); + } + @Test public void False_match_xnde() { // PURPOSE: "\s" being evaluted as "\s"; PAGE:de.v:Via_Jutlandica/Gpx DATE:2014-11-29 + fxt.Init_para_y_(); + fxt.Test_html_wiki_str(String_.Concat_lines_nl + ( "" + , " " + ), String_.Concat_lines_nl + ( "" + , "
      <trk>"
      +		, "
      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__atrs_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__atrs_tst.java new file mode 100644 index 000000000..8f8259a39 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__atrs_tst.java @@ -0,0 +1,210 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__atrs_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Tr() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-style='a'" + , "|b" + , "|}" + ), fxt.tkn_tblw_tb_(0, 20).Subs_ + ( fxt.tkn_tblw_tr_(2, 17).Atrs_rng_(5, 14).Subs_ + ( fxt.tkn_tblw_td_(14, 17).Subs_(fxt.tkn_txt_(16, 17), fxt.tkn_para_blank_(18)) + )) + ); + } + @Test public void Td() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|style='a'|b" + , "|}" + ), fxt.tkn_tblw_tb_(0, 21).Subs_ + ( fxt.tkn_tblw_tr_(2, 18).Subs_ + ( fxt.tkn_tblw_td_(5, 18).Atrs_rng_(7, 16).Subs_(fxt.tkn_txt_(17, 18), fxt.tkn_para_blank_(19)) + )) + ); + } + @Test public void Td_mult() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , " {|" + , " |-" + , " | id='1'|" + , " | id='2'|a" + , " | id='3'|" + , " |}" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , " " + , " " + , " " + , " " + , " " + , " " + , "
      " + , " a" + , " " + , "
      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Tc() { // PAGE:en.w:1920_Palm_Sunday_tornado_outbreak + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|id='1'" + , "|+id='2'|a" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , "
      a" + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Td_mixed() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|style='a'|b||c" + , "|}" + ), fxt.tkn_tblw_tb_(0, 24).Subs_ + ( fxt.tkn_tblw_tr_(2, 21).Subs_ + ( fxt.tkn_tblw_td_( 5, 18).Atrs_rng_(7, 16).Subs_(fxt.tkn_txt_(17, 18), fxt.tkn_para_blank_(19)) + , fxt.tkn_tblw_td_(18, 21).Subs_(fxt.tkn_txt_(20, 21), fxt.tkn_para_blank_(22)) + )) + ); + } + @Test public void Th() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "!style='a'|b" + , "|}" + ), fxt.tkn_tblw_tb_(0, 21).Subs_ + ( fxt.tkn_tblw_tr_(2, 18).Subs_ + ( fxt.tkn_tblw_th_(5, 18).Atrs_rng_(7, 16).Subs_(fxt.tkn_txt_(17, 18), fxt.tkn_para_blank_(19)) + )) + ); + } + @Test public void Skip_hdr() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|+b" + , "!style='a'|b" + , "|}" + ), fxt.tkn_tblw_tb_(0, 22).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tc_(2, 6).Subs_(fxt.tkn_txt_( 5, 6)) + , fxt.tkn_tblw_tr_(6, 19).Subs_ + ( fxt.tkn_tblw_th_(6, 19).Atrs_rng_(8, 17).Subs_(fxt.tkn_txt_(18, 19), fxt.tkn_para_blank_(20)) + ) + )); + } + @Test public void Td_bg_color() { // PURPOSE: atr_parser should treat # as valid character in unquoted val; PAGE:en.w:UTF8; |bgcolor=#eeeeee|Indic
      0800*
      '''''224''''' + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|bgcolor=#eeeeee|a" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Xnde_tb() { // PURPOSE: xnde should close any open xatrs; PAGE:en.w:Western_Front_(World_War_I); stray > after == Dramatizations == + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|id='1'

      " + , "|a" + , "|}"), String_.Concat_lines_nl_skip_last + ( "

      " + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Xnde_tr() { // PURPOSE: xnde should disable all tkns; PAGE:en.w:A DATE:2014-07-16 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-cid='d'
      " // note that id='d' should not show up since invalidates entire line + , "|a" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + )); + } + @Test public void Xnde_mix_tblw_tblx() { // PURPOSE: issue with somehow rolling up everything after ; PAGE:en.w:20th_century; {{Decades and years}} + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      a" + , "{|id=1" + , "|-" + , "|b" + , "|}
      " + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , " " + , " " + , " " + , " " + , "
      b" + , "
      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__basic_tst.java new file mode 100644 index 000000000..eaf70c836 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__basic_tst.java @@ -0,0 +1,814 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__basic_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Td() { // Tb_tr_td_te + fxt.Test_parse_page_wiki("{|\n|-\n|a\n|}" + , fxt.tkn_tblw_tb_(0, 11).Subs_ + ( fxt.tkn_tblw_tr_(2, 8).Subs_ + ( fxt.tkn_tblw_td_(5, 8).Subs_(fxt.tkn_txt_(7, 8), fxt.tkn_para_blank_(9)))) + ); + } + @Test public void Td2() { // Tb_tr_td_td2_te + fxt.Test_parse_page_wiki("{|\n|-\n|a||b\n|}" + , fxt.tkn_tblw_tb_(0, 14).Subs_ + ( fxt.tkn_tblw_tr_(2, 11).Subs_ + ( fxt.tkn_tblw_td_(5, 8).Subs_(fxt.tkn_txt_( 7, 8), fxt.tkn_para_blank_(9)) + , fxt.tkn_tblw_td_(8, 11).Subs_(fxt.tkn_txt_(10, 11), fxt.tkn_para_blank_(12)) + ))); + } + @Test public void Tc() { // Tb_tc_te + fxt.Test_parse_page_wiki("{|\n|+a\n|}" + , fxt.tkn_tblw_tb_(0, 9).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tc_(2, 6).Subs_ + ( fxt.tkn_txt_(5, 6) + , fxt.tkn_para_blank_(7) + ) + ) + ); + } + @Test public void Tc_longer() { // Tb_tc_tr_td_te + fxt.Test_parse_page_wiki("{|\n|+a\n|-\n|b\n|}" + , fxt.tkn_tblw_tb_(0, 15).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tc_(2, 6).Subs_(fxt.tkn_txt_(5, 6)) + , fxt.tkn_tblw_tr_(6, 12).Subs_ + ( fxt.tkn_tblw_td_(9, 12).Subs_(fxt.tkn_txt_(11, 12), fxt.tkn_para_blank_(13)) + ) + )); + } + @Test public void Th() { // Tb_th_te + fxt.Test_parse_page_wiki("{|\n|-\n!a\n|}" + , fxt.tkn_tblw_tb_(0, 11).Subs_ + ( fxt.tkn_tblw_tr_(2, 8).Subs_ + ( fxt.tkn_tblw_th_(5, 8).Subs_(fxt.tkn_txt_(7, 8), fxt.tkn_para_blank_(9)) + ))); + } + @Test public void Th2() { // Tb_th_th2_te + fxt.Test_parse_page_wiki("{|\n|-\n!a!!b\n|}" + , fxt.tkn_tblw_tb_(0, 14).Subs_ + ( fxt.tkn_tblw_tr_(2, 11).Subs_ + ( fxt.tkn_tblw_th_(5, 8).Subs_(fxt.tkn_txt_( 7, 8)) + , fxt.tkn_tblw_th_(8, 11).Subs_(fxt.tkn_txt_(10, 11), fxt.tkn_para_blank_(12)) + ))); + } + @Test public void Th2_td_syntax() { // Tb_th_td; || should be treated as th + fxt.Test_parse_page_wiki("{|\n|-\n!a||b\n|}" + , fxt.tkn_tblw_tb_(0, 14).Subs_ + ( fxt.tkn_tblw_tr_(2, 11).Subs_ + ( fxt.tkn_tblw_th_(5, 8).Subs_(fxt.tkn_txt_( 7, 8)) + , fxt.tkn_tblw_th_(8, 11).Subs_(fxt.tkn_txt_(10, 11), fxt.tkn_para_blank_(12)) + ))); + } + @Test public void Tb_td2() { // PAGE:en.w:Hectare; {| class="wikitable" || style="border: 1px solid #FFFFFF;" + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|id='1' || class='a'" + , "|-" + , "|a" + , "|}") + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Td_lnki() { + fxt.Test_parse_page_wiki("{|\n|-\n|[[a|b]]\n|}" + , fxt.tkn_tblw_tb_(0, 17).Subs_ + ( fxt.tkn_tblw_tr_(2, 14).Subs_ + ( fxt.tkn_tblw_td_(5, 14).Subs_(fxt.tkn_lnki_(7, 14), fxt.tkn_para_blank_(15)))) + ); + } + @Test public void Tr_dupe_xnde() { // PURPOSE: redundant tr should not be dropped; see [[Jupiter]] + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "a" + , "|-" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + ) + ); + } + @Test public void Tr_dupe_xnde_2() { // causes problems + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "a" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + ) + ); + } + @Test public void Bang_should_not_make_cell_td_1_bang() { // PURPOSE: "| a! b" ! should not separate cell + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last("{|", "|-", "|a!b", "|}"), String_.Concat_lines_nl_skip_last("", " ", " ", " ", "
      a!b" , "
      ", "")); + } + @Test public void Bang_should_not_make_cell_td_2_bang() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last("{|", "|-", "|a!!b", "|}"), String_.Concat_lines_nl_skip_last("", " ", " ", " ", "
      a!!b" , "
      ", "")); + } + @Test public void Bang_should_not_make_cell_th_1_bang() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last("{|", "|-", "!a!b", "|}"), String_.Concat_lines_nl_skip_last("", " ", " ", " ", "
      a!b" , "
      ", "")); + } + @Test public void Bang_should_not_make_cell_th_2_bang() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last("{|", "|-", "!a!!b", "|}") + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + )); + } + @Test public void Bang_should_not_make_cell_th_mult_line() { // FIX: make sure code does not disable subsequent bangs + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last("{|", "|-", "!a", "!b", "|}") + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + )); + } + @Test public void Fix_extra_cell() { // PURPOSE: trim should not affect td; WP:Base32 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "!id='1'|a" + , "|" + , "!id='2'|b" + , "|-" + , "|a1|| ||b1" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
      a" + , " " + , " b" + , "
      a1" + , " " + , " b1" + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Nl_td() { // PURPOSE:

      inside does not get enclosed + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
      " + , "" + , "" + , "a" + , "" + , "" + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , "" + , "


      " + , "a" + , "

      " + , "" + , "


      " + , "

      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Trim_ws() { // PURPOSE: trim should be done from both sides + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "" + , "" + , "a" + , "" + , "" + , "
      " + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "a" + , "
      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Trim_ws_tr() { // PURPOSE: trim should be done from both sides + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "" + , "
      " + , "
      " + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
      " + , "
      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Trim_ws_td() { // PURPOSE: trim should not affect td + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
      " + , "" + , "" + , "a" + , "" + , "" + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , "" + , "


      " + , "a" + , "

      " + , "" + , "


      " + , "

      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void No_wiki_3() { + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|style='a[b]c'|d" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      d" + , "
      " + , "" + )); + } + @Test public void Trailing_tr_breaks_para_mode() {// PURPOSE.fix: empty trailing tr breaks para mode; EX:w:Sibelius + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|a" + , "|-" // causes lines below not to be put in paras + , "|}" + , "b" + , "" + , "c" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + , "

      b" + , "

      " + , "" + , "

      c" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Blank_line_should_be_own_para() {// PURPOSE.fix: caption does not begin on own line; EX:w:Old St. Peter's Basilica + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|a" + , "b" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "" + , "

      b" + , "

      " + , "
      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Blank_line_should_be_own_para_2() {// PURPOSE.fix: caption does not begin on own line; EX:w:Old St. Peter's Basilica + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|a" + , "b" + , "|-" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "" + , "

      b" + , "

      " + , "
      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Bold_stops_at_table() { // PURPOSE: do not allow unclosed bold to extend over tables; + fxt.Test_parse_page_all_str("'''
      a
      ", String_.Concat_lines_nl_skip_last + ( "" + , "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + fxt.Init_defn_clear(); + } + @Test public void Orphaned_tr_breaks_nested_tables() { // PUPRPOSE: should not match outside scope; EX:w:Enthalpy_of_fusion; {{States of matter}} + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "" + , "
      " + , "" + , "" + , "
      " + , "
      a" + , "
      " + ), + String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      " + , " " + , "
      " + , "
      a" + , "
      " + , "" + ) + ); + } + @Test public void Space_causes_extra_p() {// PURPOSE: "\n\s" should be equivalent to "\n"; EX: w:Earth + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "
      " + , "b" + , "
      c" + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , "" + , "

      b" // used to close

      here;

      b

      + , "
      c" + , "

      " + , "
      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Br_should_not_be_ignored() {// PURPOSE: document
      's should not be ignored between tables; 20121226 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "|}" + , "
      " + , "{|" + , "|-" + , "|b" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + , "


      " // (a)
      was being ignored; (b)

      added for TRAILING_TBLW fix; DATE:2017-04-08 + , "

      " + , "" + , " " + , " " + , " " + , "
      b" + , "
      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void AutoClose_td_when_new_tr() { // retain; needed for de.w:Main_Page; DATE:2013-12-09 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "==a==" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , "" + , "

      a

      " // NOTE: malformed html matches MW + , " " + , " " + , " " + , "
      " + , "
      " + , "" + )); + } + @Test public void Auto_create_table() {// PURPOSE: should create table; EX:w:Hatfield-McCoy_feud; DATE:20121226 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "a" + , "" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void List_and_orphaned_td2_should_not_create_tblw() {// PURPOSE: !! was creating table; DATE:2013-04-28 + fxt.Test_parse_page_all_str("*a !! b", String_.Concat_lines_nl_skip_last + ( "
        " + , "
      • a !! b" + , "
      • " + , "
      " + )); + } + @Test public void Tr_trailing_dashes_should_be_stripped() {// PURPOSE: trailing dashes should be stripped; |--- -> |-; EX: |--style="x" was being ignored; DATE:2013-06-21 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-----style='a'" + , "|b" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      b" + , "
      " + )); + } + @Test public void Th_without_tr() { // PURPOSE: !! without preceding ! should not create table-cell; DATE:2013-12-18 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "a!!b" + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      " + , "a!!b" + , "
      " + )); + } + @Test public void Td_at_eos() {// PURPOSE.fix: !! at eos fails; EX:es.s:Si_mis_manos_pudieran_deshojar; DATE:2014-02-11 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "| !!" // note that "!!" is eos inside the src + , "|}" + ), String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      " + , "

      " + , "!!" + , "

      " + , "
      " + , "
      " + )); + } + @Test public void Tr_without_tb_should_start_tb() {// PURPOSE: orphaned tr should automatically start table; EX: pl.w:Portal:Technika; DATE:2014-02-13 + fxt.Test_parse_page_all_str("a" + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + )); + } + @Test public void Tblx_should_not_close_tblw() {// PURPOSE: should not close {|; EX:fr.w:Exp%C3%A9dition_Endurance; DATE:2014-02-13 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      " + , "
      " + )); + } + @Test public void Tblx_should_not_close_tblw_2() {// PURPOSE: should close {|; ignore latter |}; EX:ru.q:Авель; DATE:2014-02-22 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "" + , "{|" + , "|-" + , "|b" + , "" + , "{|" + , "|-" + , "|c" + , "" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + , " " + , " " + , " " + , "
      b" + , "
      " + , "" + , " " + , " " + , " " + , "
      c" + , "
      " + )); + } + @Test public void Td_in_list_in_tblw_should_be_ignored() {// PURPOSE: || should be ignored if in list; EX:es.d:casa; DATE:2014-02-15 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "* a || b" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      " + , "
        " + , "
      • a || b" + , "
      • " + , "
      " + , "
      " + )); + } + @Test public void List_in_tblw() {// PURPOSE: list should close previous cell; EX: ru.d:Викисловарь:Условные_сокращения; DATE:2014-02-22 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "{|" + , "*a" + , "|}" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
      " + , " " + , "
        " // NOTE: this should probably be inside
      , but this matches MW behavior; DATE:2014-02-22 + , "
    • a" + , "
    • " + , " " + , " " + , " " + , " " + , "
      " + , "
      " + , "
      " + )); + } +} +// @Test public void Tb_under_tr_is_ignored() { // PURPOSE: table directly under tr is ignored; PAGE:en.w:Category:Dessert stubs; TODO_OLD: complicated, especially to handle 2nd |} +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "{|" +// , "|-id='a'" +// , "{|style='border:1px;'" +// , "|-id='b'" +// , "|b" +// , "|}" +// , "|}" +// ), String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// , " " +// , " " +// , "
      b" +// , "
      " +// , "" +// )); +// } +// @Test public void Leading_ws() { // PAGE:en.w:Corneal dystrophy (human) +// fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last +// ( " {|" +// , " |-" +// , " |a" +// , " |}" +// ) +// , fxt.tkn_tblw_tb_(1, 15).Subs_ +// ( fxt.tkn_tblw_tr_(3, 11).Subs_ +// ( fxt.tkn_tblw_td_(7, 11).Subs_ +// ( fxt.tkn_txt_()) +// ) +// ) +// ); +// } +// @Test public void Atrs_tb() { // Tb_te // FUTURE: reinstate; WHEN: Template +// fxt.Init_log_(Xop_tblw_log.Tbl_empty).Test_parse_page_wiki("{|style='a'\n|}" +// , fxt.tkn_tblw_tb_(0, 14).Atrs_rng_(2, 11).Subs_ +// ( fxt.tkn_tblw_tr_(11, 11).Subs_ +// ( fxt.tkn_tblw_td_(11, 11) +// ))); +// } +// @Test public void Td_p() { // PURPOSE:

      not being closed correctly +// fxt.Init_para_y_(); +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "{|" +// , "|-" +// , "|" +// , "a" +// , "|}"), String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// , " " +// , " " +// , "
      " +// , "" +// , "

      a" +// , "

      " +// , "
      " +// , "" +// )); +// fxt.Init_para_n_(); +// } +// @Test public void Tb_tb() { +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "{|id='1'" +// , "{|id='2'" +// , "|-id='3'" +// , "|a" +// , "|}" +// , "|}"), String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// , " " +// , " " +// , "
      a" +// , "
      " +// , "" +// )); +// } +// @Test public void Tb_tb_2() { +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "{|id='1'" +// , "{|id='2' " +// , "|a" +// , "
      " +// , "|}" +// , "|}"), String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// , " " +// , " " +// , "
      a" +// , "
      " +// , "" +// )); +// } diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__dangling_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__dangling_tst.java new file mode 100644 index 000000000..3040f4583 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__dangling_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__dangling_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Dangling_tb_in_xnde() {// PURPOSE: dangling tblw incorrectly auto-closed by ; PAGE:en.w:Atlanta_Olympics; DATE:2014-03-18 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "

      " + , "{|" + , "|-" + , "|" + , "{|" + , "|-" + , "|a" + , "|}" + , "
      " + , "b" + ) + , String_.Concat_lines_nl + ( "
      " + , "" + , " " + , " " + , " " + , "
      " + , " " + , " " + , " " + , " " + , "
      a" + , "
      " + , "" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + , "" + , "

      b" + , "

      " + , "
      " + , "

      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__double_pipe_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__double_pipe_tst.java new file mode 100644 index 000000000..9354c205c --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__double_pipe_tst.java @@ -0,0 +1,106 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__double_pipe_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void No_tblw() { // PURPOSE: if || has no tblw, treat as lnki; none; DATE:2014-05-06 + fxt.Test_parse_page_all_str("[[A||b|c]]", String_.Concat_lines_nl_skip_last + ( "

      b|c" // NOTE: technically this should be "|b|c", but difficult to implement; DATE:2014-05-06 + , "

      " + , "" + )); + } + @Test public void Lnki_nth() { // PURPOSE: if || is nth pipe, then treat as lnki; PAGE:en.w:Main_Page;de.w:Main_Page; DATE:2014-05-06 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|[[File:A.png|b||c]]" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      \"c\"" + , "
      " + , "" + ) + ); + } + @Test public void Lnki_list_1st() { // PURPOSE: if || is 1st pipe, but inside list, then treat as lnki; EX:w:Second_Boer_War; DATE:2014-05-05 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|" + , "*[[A||b]]" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , "" + , "
        " + , "
      • b" // NOTE: technically this should be "|b", but difficult to implement; DATE:2014-05-06 + , "
      • " + , "
      " + , "
      " + , "" + ) + ); + } + @Test public void Double_bang_lnki() { // PURPOSE: do not treat !! as tblw; PAGE:en.w:Pink_(singer); DATE:2014-06-25 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|" + , "[[A!!b]]" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      " + , "" + , "

      A!!b" + , "

      " + , "
      " + , "" + ) + ); + } + @Test public void Double_bang_list() { // PURPOSE: do not treat !! as tblw; PAGE:en.w:Wikipedia:Featured_picture_candidates; DATE:2014-10-19 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "* a !! b" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , "
        " + , "
      • a !! b" + , "
      • " + , "
      " + , " " + , " " + , " " + , "
      " + , "
      " + , "

      " // NOTE:

      is incorrect, but benign + ) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__errs_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__errs_tst.java new file mode 100644 index 000000000..fb0e0830f --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__errs_tst.java @@ -0,0 +1,92 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__errs_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Err_row_empty() { + fxt.Test_parse_page_wiki("{|\n|-\n|-\n|a\n|}" + , fxt.tkn_tblw_tb_(0, 14).Subs_ + ( fxt.tkn_tblw_tr_(2, 5) + , fxt.tkn_tblw_tr_(5, 11).Subs_ + ( fxt.tkn_tblw_td_(8, 11).Subs_(fxt.tkn_txt_(10, 11), fxt.tkn_para_blank_(12)) + )) + ); + } + @Test public void Err_row_trailing() { + fxt.Test_parse_page_wiki("{|\n|-\n|a\n|-\n|}" + , fxt.tkn_tblw_tb_(0, 14).Subs_ + ( fxt.tkn_tblw_tr_(2, 8).Subs_ + ( fxt.tkn_tblw_td_(5, 8).Subs_(fxt.tkn_txt_(7, 8), fxt.tkn_para_blank_(9)) + )) + ); + } + @Test public void Err_caption_after_tr() { + fxt.Test_parse_page_wiki("{|\n|-\n|+a\n|}" + , fxt.tkn_tblw_tb_(0, 12).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tr_(2, 5) + , fxt.tkn_tblw_tc_(5, 9).Subs_(fxt.tkn_txt_(8, 9), fxt.tkn_para_blank_(10))) + ); + } + @Test public void Err_caption_after_td() { + fxt.Init_log_(Xop_tblw_log.Caption_after_td).Test_parse_page_wiki("{|\n|-\n|a\n|+b\n|}" + , fxt.tkn_tblw_tb_(0, 15).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tr_(2, 8).Subs_ + ( fxt.tkn_tblw_td_(5, 8).Subs_(fxt.tkn_txt_(7, 8))) + , fxt.tkn_tblw_tc_(8, 12).Subs_(fxt.tkn_txt_(11, 12), fxt.tkn_para_blank_(13))) + ); + } + @Test public void Err_caption_after_tc() { + fxt.Init_log_(Xop_tblw_log.Caption_after_tc).Test_parse_page_wiki("{|\n|+a\n|+b\n|}" + , fxt.tkn_tblw_tb_(0, 13).Caption_count_(2).Subs_ + ( fxt.tkn_tblw_tc_(2, 6).Subs_(fxt.tkn_txt_( 5, 6)) + , fxt.tkn_tblw_tc_(6, 10).Subs_(fxt.tkn_txt_( 9, 10), fxt.tkn_para_blank_(11))) + ); + } + @Test public void Err_row_auto_opened() { + fxt.Test_parse_page_wiki("{|\n|a\n|}" + , fxt.tkn_tblw_tb_(0, 8).Subs_ + ( fxt.tkn_tblw_tr_(2, 5).Subs_ + ( fxt.tkn_tblw_td_(2, 5).Subs_(fxt.tkn_txt_(4, 5), fxt.tkn_para_blank_(6)) + ))); + } + @Test public void Err_caption_auto_closed() { + fxt.Test_parse_page_wiki("{|\n|+a\n|b\n|}" + , fxt.tkn_tblw_tb_(0, 12).Caption_count_(1).Subs_ + ( fxt.tkn_tblw_tc_(2, 6).Subs_(fxt.tkn_txt_(5, 6)) + , fxt.tkn_tblw_tr_(6, 9).Subs_ + ( fxt.tkn_tblw_td_(6, 9).Subs_(fxt.tkn_txt_(8, 9),fxt.tkn_para_blank_(10)) + ))); + } + @Test public void Err_Atrs_dumped_into_text() { // PURPOSE: [[Prawn]] and {{Taxobox}} was dumping text + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|-id='a'" + , "|b" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      b" + , "
      " + , "" + ) + ); + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__nested_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__nested_tst.java new file mode 100644 index 000000000..0413d28d3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__nested_tst.java @@ -0,0 +1,163 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__nested_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { + fxt.Test_parse_page_wiki(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "{|" + , "|-" + , "|a" + , "|}" + , "|b" + , "|}" + ) + , fxt.tkn_tblw_tb_(0, 25).Subs_ + ( fxt.tkn_tblw_tr_(2, 22).Subs_ + ( fxt.tkn_tblw_td_(5, 19).Subs_ + ( fxt.tkn_tblw_tb_(7, 19).Subs_ + ( fxt.tkn_tblw_tr_(10, 16).Subs_ + ( fxt.tkn_tblw_td_(13, 16).Subs_(fxt.tkn_txt_(15, 16), fxt.tkn_para_blank_(17)) + ) + ) + , fxt.tkn_para_blank_(20) + ) + , fxt.tkn_tblw_td_(19, 22).Subs_(fxt.tkn_txt_(21, 22), fxt.tkn_para_blank_(23)) + ) + ) + ); + } + @Test public void Leading_ws() { + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|id='a'" + , "|-" + , "|a" + , "|-" + , "|id='b'|" + , " {|id='c'" + , " |-" + , " |d" + , " |}" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
      a" + , "
      " + , " " + , " " + , " " + , " " + , "
      d" + , "
      " + , "
      " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Tblx_tblw() { // PURPOSE: if followed by {|, ignore 2nd table; EX: en.b:Wikibooks:Featured_books; DATE:2014-02-08 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      " + , "{| cellspacing=\"0\"" + , "|a" + , "|}" + , "
      " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + )); + } + @Test public void Caption_and_tblw() { // TIDY: don't try to fix sequence; PAGE:es.w:Sevilla; DATE:2014-06-29 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|+" + , "{|" + , "|}" + , "|}"), String_.Concat_lines_nl_skip_last + ( "
      " + , " " + , "
      " + , " " + , " " + , " " + , " " + , "
      " + , "
      " + , "
      " + , "" + )); + } + @Test public void Tb_tr_tb() { // PURPOSE: if , auto-create " + , "
      ; EX:w:Paris; DATE:2014-03-18 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "{|" + , "|}" + , "|}"), String_.Concat_lines_nl_skip_last + ( "" + , " " + , "
      " + , " " + , " " + , " " + , "
      " + , "
      " + , "
      " + , "" + )); + } +// @Test public void Nested_tbl_missing() { // PURPOSE: nested table not rendering properly; EX:ar.s:; DATE:2014-03-18 +// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last +// ( "{|" +// , "|-" +// , "{|" +// , "|-" +// , "|}" +// , "| width='50%' | a" +// , "|}" +// ), String_.Concat_lines_nl_skip_last +// ( "" +// , " " +// , " " +// , " " +// , " " +// , "
      a" +// , " [[b|c" +// , "
      " +// , "" +// , "

      d" +// , "

      " +// )); +// } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__para_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__para_tst.java new file mode 100644 index 000000000..a2dac3194 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__para_tst.java @@ -0,0 +1,175 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__para_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Para() { // PURPOSE: para causing strange breaks; SEE:[[John F. Kennedy]] and "two Supreme Court appointments" + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "

      " + , "|a" + , "

      " + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "

      " + , " " + , " " + , " " + , "
      a" + , "

      " + , "
      " + , "" + ) + ); + } + @Test public void Nl() { // PURPOSE: para causing strange breaks; SEE:[[John F. Kennedy]] and "two Supreme Court appointments" + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "!a" + , "" + , "|-" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "
      " + , "" + ) + ); + } + @Test public void Unnecessary_para() { // PURPOSE: tblw causes unnecessary

      ; home/wiki/Dashboard/Image_databases; DATE:2014-02-20 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|" + , "a
      " + , "b" + , "|" + , "c
      " + , "d" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      " + , "" + , "

      a
      " + , "b" + , "

      " + , "
      " + , "" + , "

      c
      " + , "d" + , "

      " + , "
      " + , "" + ) + ); + } + @Test public void Ws_leading() { // PAGE:en.w:AGPLv3 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , " !a" + , " !b" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + ) + ); + } + @Test public void Ws_th_2() { // "\n\s!" should still be interpreted as tblw; s.w:Manchester; DATE:2014-02-14 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|!style='color:red'|a" + , " !style=\"color:blue\"|b" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " b" + , "
      " + , "" + ) + ); + } + @Test public void Ws_th_3() { // "\n\s!" and "!!" breaks tblw; ru.w:Храмы_Санкт-Петербурга (List of churches in St Petersburg); DATE:2014-02-20 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , " ! id='1' | a !! id='2' | b" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a " + , " b" + , "
      " + , "" + ) + ); + } + @Test public void Tblw_td2_should_not_create_ws() { // PURPOSE: a||b -> a\n||b; EX:none;discovered during luaj test; DATE:2014-04-14 + fxt.Test_parse_page_wiki_str("a||b", "

      a||b\n

      "); + } + @Test public void Para_on_tblw() { // PURPOSE:table following link should automatically add para around link; PAGE:en.w:Template_engine_(web) DATE:2017-04-08 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "[[A]] b" + , "{|" + , "|-" + , "|c" + , "|}" + ) + , String_.Concat_lines_nl_skip_last + ( "

      A b" // NOTE: previously,

      was not included; now added for TRAILING_TBLW fix; DATE:2017-04-08 + , "

      " + , "" + , " " + , " " + , " " + , "
      c" + , "
      " + , "" + ) + ); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__tblx_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__tblx_tst.java new file mode 100644 index 000000000..024e9f775 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__tblx_tst.java @@ -0,0 +1,152 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__tblx_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Ignore_td() { // PURPOSE: do not parse pipe as td if in ; EX:ru.w:Сочи; DATE:2014-02-22 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      " + , " " + , " " + , " " + , "
      a" + , "| b" + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "| b" + , "
      " + , "" + ) + ); + } + @Test public void Ignore_tr() { // PURPOSE: do not parse "\n|-", "\n!" if in ; EX:s.w:Uranus; DATE:2014-05-05 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      " + , " " + , " " + , " " + , "
      a" + , "|-" + , "! b" + , "| c" + , "
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      a" + , "" + , "

      |-" + , "! b" + , "| c" + , "

      " + , "
      " + , "" + ) + ); + } + @Test public void Tblw_tblx_tblw_fails() { // PURPOSE: {| -> -> \n| was not rendering as " + , "" + , " " + , " fragment within lnki should be ignored; PAGE:en.w:Aargau DATE:2016-08-14 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      ; PAGE:en.w:Paris#Demographics; DATE:2014-03-18 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "
      " + , "" + , "" + , "|c" + , "
      b
      " + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
      a" + , "
      " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
      b" + , "
      c" + , "
      " + , "
      " + )); + } + @Test public void Auto_tr_after_td() { // PURPOSE: "
      \n|" -> "
      "; PAGE:fi.w:Salibandyn_maailmanmestaruuskilpailut_2012 DATE:2015-09-07 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "
      a" + , " " + , "|b" + , "|}" + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " // inserted by transition from " + , " " + , "
      a" + , " " // NOTE: dangling from above just gets auto-closed; no logic in tblw_wkr to actually remove it + , "
      to "\n|" + , " b" + , "
      " + , "" + ) + ); + } + @Test public void Ignore_tr_in_lnki() { // PURPOSE:
      " + , "" + , "]]" + , "" + , "" + , "
      [[A|B
      t_1
      " + ) , String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "" + , " " + , " " + , "
      B" + , "
      t_1" + , "
      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__uncommon_tst.java b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__uncommon_tst.java new file mode 100644 index 000000000..46186e8fa --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tblws/Xop_tblw_wkr__uncommon_tst.java @@ -0,0 +1,127 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tblws; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tblw_wkr__uncommon_tst { + @Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Tr_pops_entire_stack() { // PURPOSE: in strange cases, tr will pop entire stack; PAGE:en.w:Turks_in_Denmark; DATE:2014-03-02 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "a" + , "|b" + , "|-" + , "|c" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
      a" + , "
      b" + , "
      c" + , "
      " + )); + } + @Test public void Atrs_defect() { // PURPOSE: < in atrs was causing premature termination; PAGE:en.w:Wikipedia:List of hoaxes on Wikipedia + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|id=\"a" + , " " + , " a" + , " " + , " " + , "" + , "" + )); + } + @Test public void Broken_lnki() { // PURPOSE: broken lnki was not closing table properly; PAGE:en.w:Wikipedia:Changing_attribution_for_an_edit; DATE:2014-03-16 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|a" + , "|[[b|c" + , "|}" + , "d" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , "
      a" + , " [[b|c" + , "
      " + , "" + , "

      d" + , "

      " + )); + } + @Test public void Broken_lnki_2() { // PURPOSE: variation on above; PAGE:hr.b:Knjiga_pojmova_u_zrakoplovstvu/Kratice_u_zrakoplovstvu/S; DATE:2014-09-05 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "| [[A | b" + , "|-" + , "| B" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
      [[A | b" + , "
      B" + , "
      " + )); + } + @Test public void Tr_with_pipe_ignores_content() { // PURPOSE: "|-" followed by "|" ignores rest of content; EX: {|\n|-|a\n|} PAGE:lv.w:Starptautiska_kosmosa_stacija; DATE:2015-11-21 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|- |a" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , "
      " + )); + } + @Test public void Tr_with_pipe_should_ignore() { // PURPOSE: ignore sequences like "\n|- ||"; PAGE: nl.w:Tabel_van_Belgische_gemeenten; DATE:2015-12-03 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|- ||" + , "|a|b" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      b" + , "
      " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_subst_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_subst_tst.java new file mode 100644 index 000000000..4c70a1802 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_subst_tst.java @@ -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.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.wikis.ttls.*; +public class Xop_subst_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() { + fxt.Reset(); + fxt.Init_defn_clear(); + fxt.Init_defn_add("xo_print", "{{{1}}}"); + fxt.Init_defn_add("!", "|"); + } + @Test public void Wiki_txt_subst() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{subst:test|a}}" , "a");} + @Test public void Wiki_txt_subst_ws() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{ subst:test|a}}" , "a");} + @Test public void Wiki_txt_safesubst() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{safesubst:test|a}}" , "a");} + @Test public void Tmpl_txt_subst_empty() {fxt.Test_parse_tmpl_str_test("{{subst:}}" , "{{test}}" , "{{subst:}}");} + @Test public void Tmpl_txt_safesubst() {fxt.Test_parse_tmpl_str_test("{{safesubst:xo_print|a}}" , "{{test}}" , "a");} + @Test public void Tmpl_prm_subst() {fxt.Test_parse_tmpl_str_test("{{{{{1|subst:}}}xo_print|a}}" , "{{test}}" , "{{subst:xo_print|a}}");} + @Test public void Tmpl_prm_subst_ws() {fxt.Test_parse_tmpl_str_test("{{{{{1| subst:}}}xo_print|a}}" , "{{test}}" , "{{ subst:xo_print|a}}");} + @Test public void Tmpl_prm_safesubst() {fxt.Test_parse_tmpl_str_test("{{{{{1|safesubst:}}}xo_print|a}}" , "{{test}}" , "a");} + @Test public void Tmpl_prm_safesubst_empty() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}xo_print|a}}" , "{{test}}" , "a");} + @Test public void Tmpl_txt_subst_pf() {fxt.Test_parse_tmpl_str_test("{{subst:#expr:0}}" , "{{test}}" , "0");} + @Test public void Tmpl_txt_safesubst_prm() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}#if:{{{1|}}}{{{{{|safesubst:}}}!}}c1|c2}}" , "{{test}}" , "c2");} + @Test public void Exc_tmpl_prm_safesubst_ns() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst}}}:NAMESPACE}}" , "{{test}}" , "");} + @Test public void Unreferenced() { // PURPOSE: if subst, but in tmpl stage, do not actually subst; PAGE:en.w:Unreferenced; DATE:2013-01-31 + fxt.Init_defn_clear(); + fxt.Init_defn_add("substcheck", "SUBST"); + fxt.Init_defn_add("ifsubst", String_.Concat_lines_nl + ( "{{ {{{|safesubst:}}}#ifeq:{{ {{{|safesubst:}}}NAMESPACE}}|{{NAMESPACE}}" + , " |{{{no|{{{2|}}}}}}" + , " |{{{yes|{{{1|}}}}}}" + , "}}" + )); + fxt.Test_parse_tmpl_str_test("{{ {{{|safesubst:}}}ifsubst |yes|{{subst:substcheck}}}}", "{{test}}", "{{subst:substcheck}}"); + } + @Test public void Urlencode_missing_ttl() { // PURPOSE: handle missing ttl inside {{does-template-exist}}; EX: en.d:Kazakhstan; DATE:2014-03-25 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "{{safesubst:urlencode:{{safesubst:Template:{{{1}}}}}}}"); + fxt.Test_parse_page_tmpl_str("{{test|xyz}}", "%5B%5BTemplate%3Axyz%5D%5D"); // url-encoded version of [[:Template:xyz]]; NOTE: removed leading ":" from ":Template:" DATE:2016-06-24 + } + @Test public void Urlencode_invalid_ttl() { // PURPOSE: handle invalid ttl inside does-template-exist; EX: en.d:peace; DATE:2014-03-31 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "{{safesubst:urlencode:{{safesubst:Template:{{{1}}}}}}}"); + fxt.Test_parse_page_tmpl_str("{{test|[xyz]}}", "%7B%7Bsafesubst%3ATemplate%3A%5Bxyz%5D%7D%7D"); // url-encoded version of {{safesubst:Template:xyz}} + } + @Test public void Urlencode_template_ttl() { // PURPOSE: handle template ttl inside does-template-exist; based on above; DATE:2014-03-31 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "{{safesubst:urlencode:{{Template:{{{1}}}}}}}"); + fxt.Test_parse_page_tmpl_str("{{test|Template:[xyz]}}", "%7B%7BTemplate%3ATemplate%3A%5Bxyz%5D%7D%7D"); // url-encoded version of {{safesubst:Template:xyz}} + } + @Test public void Nowiki() { // PURPOSE: stack overflow; PAGE:Близкие_друзья_(Сезон_2) DATE:2014-10-21 + fxt.Init_defn_add("ET", ""); + fxt.Init_defn_add("ds", "{{subst:ET|{{subst:ds}}}}"); + fxt.Test_parse_page_tmpl_str("{{subst:ds}}", ""); // {{subst:ds}} causes stack overflow; {{ds}} does not + } + // NOTE: these are actually not good tests; MW does subst just before save; it doesn't do subst on load; in this case, the tests are testing load (which will noop); they need to test save (which xowa doesn't do) + // @Test public void Tmpl_txt_subst() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|a}}" , "{{test}}" , "a");} + // @Test public void Tmpl_txt_subst_prm() {fxt.Test_parse_tmpl_str_test("{{subst:xo_print|{{{1}}}}}" , "{{test|a}}" , "a");} + //@Test public void Tmpl_txt_safesubst_prm() {fxt.Test_parse_tmpl_str_test("{{{{{|safesubst:}}}ns:Category}}" , "{{test}}" , "Category");} + //@Test public void Tmpl_txt_subst_immed() {fxt.Test_parse_tmpl_str_test("{{xo_print{{subst:!}}a}}" , "{{test}}" , "a");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_tkn_print_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_tkn_print_tst.java new file mode 100644 index 000000000..6a3048a15 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xop_tkn_print_tst.java @@ -0,0 +1,38 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_tkn_print_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Text() {tst_Print("a ''b'' c [[d]] e");} + @Test public void Prm() {tst_Print("{{{1}}}");} + @Test public void Prm_dflt() {tst_Print("{{{1|a}}}");} + @Test public void Prm_dflt_prm() {tst_Print("{{{1|{{{2}}}}}}");} + @Test public void Tmpl() {tst_Print("{{a}}");} + @Test public void Tmpl_arg() {tst_Print("{{a|1|2}}");} + @Test public void Tmpl_arg_prm() {tst_Print("{{a|1|{{{1}}}}}");} + @Test public void Tmpl_arg_tmpl() {tst_Print("{{a|1|{{b}}}}");} + @Test public void Tmpl_pf() {tst_Print("{{#expr:1}}");} + private void tst_Print(String raw) { + Xop_ctx ctx = fxt.Ctx(); + byte[] raw_bry = Bry_.new_u8(raw); + Xot_defn_tmpl defn = fxt.run_Parse_tmpl(Bry_.Empty, raw_bry); + Xot_fmtr_prm raw_fmtr = new Xot_fmtr_prm(); + defn.Root().Tmpl_fmt(ctx, raw_bry, raw_fmtr); + raw_fmtr.Print(tst_Print_bb); + Tfds.Eq(raw, tst_Print_bb.To_str_and_clear()); + } private Bry_bfr tst_Print_bb = Bry_bfr_.New(); +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_brief_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_brief_tst.java new file mode 100644 index 000000000..0f3bcfa76 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_brief_tst.java @@ -0,0 +1,56 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.strings.*; +public class Xot_defn_trace_brief_tst { + Xot_defn_trace_fxt fxt = new Xot_defn_trace_fxt(); + @Before public void init() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("leaf_a", "{{{1}}}"); + fxt.Init_defn_add("leaf_b", "{{{1}}}"); + fxt.Ctx().Defn_trace_(new Xot_defn_trace_brief()); + } + @Test public void Basic_a_1() {fxt.tst_("{{leaf_a}}" , "0001 leaf_a");} + @Test public void Basic_a_2() {fxt.tst_("{{leaf_a}} {{leaf_a}}" , "0002 leaf_a");} + @Test public void Basic_a_b() {fxt.tst_("{{leaf_a}} {{leaf_b}}" , "0001 leaf_a", "0001 leaf_b");} +} +class Xot_defn_trace_fxt { + private final Xop_fxt fxt = new Xop_fxt(); + public Xop_ctx Ctx() {return fxt.Ctx();} + public void Init_defn_clear() {fxt.Init_defn_clear();} + public void Init_defn_add(String name, String raw) {fxt.Init_defn_add(name, raw);} + public void tst_(String raw, String... expd_ary) { + Xop_ctx ctx = fxt.Ctx(); + ctx.Defn_trace().Clear(); + byte[] src = Bry_.new_u8(raw); + ctx.Page().Ttl_(Xoa_ttl.Parse(fxt.Wiki(), Bry_.new_a7("test"))); + Xop_root_tkn root = ctx.Tkn_mkr().Root(src); + fxt.Parser().Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), src); + ctx.Defn_trace().Print(src, tmp); + String[] actl_ary = String_.Split(tmp.To_str_and_clear(), (char)Byte_ascii.Nl); + Tfds.Eq_ary(expd_ary, actl_ary); + } private Bry_bfr tmp = Bry_bfr_.New(); + String[] To_str(Xot_defn_trace_itm_brief[] ary) { + String[] rv = new String[ary.length]; + for (int i = 0; i < rv.length; i++) { + Xot_defn_trace_itm_brief itm = ary[i]; + sb.Add(String_.new_u8(itm.Name())).Add("|").Add(itm.Count()); + rv[i] = sb.To_str_and_clear(); + } + return rv; + } + String_bldr sb = String_bldr_.new_(); +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_dbg_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_dbg_tst.java new file mode 100644 index 000000000..f6cd4730d --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_defn_trace_dbg_tst.java @@ -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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_defn_trace_dbg_tst { + Xot_defn_trace_fxt fx = new Xot_defn_trace_fxt(); + @Before public void init() { + fx.Init_defn_clear(); + fx.Init_defn_add("print", "{{{1}}}"); + fx.Init_defn_add("concat", "{{{1}}}{{{2}}}"); + fx.Init_defn_add("bool_str", "{{#ifeq:{{{1}}}|1|y|n}}"); + fx.Init_defn_add("mid_1", "{{print|[ {{concat|{{{1}}}|{{{2}}}}} ]}}"); + fx.Ctx().Defn_trace_(Xot_defn_trace_dbg.Instance); + } + @Test public void Tmpl() { + fx.tst_ + ( "{{print|a|key1=b}}" + , "*source" + , "{{print|a|key1=b}}" + , " *invk" + , " {{print|a|key1=b}}" + , " *lnk: [[Template:print]]" + , " *args" + , " 1: a" + , " 2: b" + , " key1: b" + , " *eval" + , " a" + , "*result" + , "a" + ); + } + //@Test public void Basic_b() {fx.tst_("{{mwo_b|2}}" , "[[Test page]]", "00 11 {{mwo_b|1}} -> b");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_examples_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_examples_tst.java new file mode 100644 index 000000000..fb23ee64b --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_examples_tst.java @@ -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.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_examples_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() { + Io_mgr.Instance.InitEngine_mem(); + fxt.Reset(); + } + @Test public void Arg_0() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For}}" , "For other uses, see [[Test page (disambiguation)]].");} + @Test public void Arg_1() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For|a}}" , "For a, see [[Test page (disambiguation)]].");} + @Test public void Arg_2() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For|a|b}}" , "For a, see [[b]].");} + @Test public void Arg_3() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For|a|b|c}}" , "For a, see [[b]] and [[c]].");} + @Test public void Arg_4() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For|a|b|c|d}}" , "For a, see [[b]], [[c]], and [[d]].");} + @Test public void Arg_5() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For|a|b|c|d|e}}" , "For a, see [[b]], [[c]], [[d]], and [[e]].");} + @Test public void Arg_1_nil() {Init_tmpl_for(); fxt.Test_parse_tmpl_str("{{For||a|b}}" , "For other uses, see [[a]] and [[b]].");} + @Test public void Main() { + Init_tmpl_main(); fxt.Test_parse_tmpl_str("{{Main|a}}", "Main article: [[a|a]]"); + } + @Test public void About() { + Init_tmpl_about(); fxt.Test_parse_tmpl_str("{{About|abc}}", "This article is about abc. For other uses, see [[Test page (disambiguation)]]."); + } + @Test public void About_2() { // PAGE:en.w:{{About|the NASA space mission||Messenger (disambiguation)}} + Init_tmpl_about(); fxt.Test_parse_tmpl_str("{{About|a||b{{!}}c}}", "This article is about a. For other uses, see [[b|c]]."); + } + @Test public void OtherUses() { + Init_tmpl_other_uses(); fxt.Test_parse_tmpl_str("{{Other uses|abc}}", "For other uses, see [[abc]]."); + } + @Test public void SeeAlso() { + Init_tmpl_see_also(); fxt.Test_parse_tmpl_str("{{See also|abc}}", "See also: [[abc]]"); + } + @Test public void Redirect() { + Init_tmpl_redirect(); fxt.Test_parse_tmpl_str("{{Redirect|abc}}", "\"abc\" redirects here. For other uses, see [[abc (disambiguation)]]."); + } + private void Init_tmpl_main() { + fxt.Init_page_create("Template:Main", String_.Concat_lines_nl + ( "{{#ifeq:{{SUBJECTSPACE}}|Category|The main {{#ifeq:{{NAMESPACE:{{{1}}}}}||article|page}}{{#if:{{{2|}}}|s}} for this [[Wikipedia:Categorization|category]] {{#if:{{{2|}}}|are|is}}|Main {{#ifeq:{{NAMESPACE:{{{1}}}}}||article|page}}{{#if:{{{2|}}}|s}}:}} [[{{{1|{{PAGENAME}}}}}|{{{l1|{{{1|{{PAGENAME}}}}}}}}]]{{#if:{{{2| }}}" + , " |{{#if:{{{3|}}}|, | and }}[[{{{2}}}|{{{l2|{{{2}}}}}}]]}}{{#if:{{{3|}}}" + , " |{{#if:{{{4|}}}|, |, and }}[[{{{3}}}|{{{l3|{{{3}}}}}}]]}}{{#if:{{{4|}}}" + , " |{{#if:{{{5|}}}|, |, and }}[[{{{4}}}|{{{l4|{{{4}}}}}}]]}}{{#if:{{{5|}}}" + , " |{{#if:{{{6|}}}|, |, and }}[[{{{5}}}|{{{l5|{{{5}}}}}}]]}}{{#if:{{{6|}}}" + , " |{{#if:{{{7|}}}|, |, and }}[[{{{6}}}|{{{l6|{{{6}}}}}}]]}}{{#if:{{{7|}}}" + , " |{{#if:{{{8|}}}|, |, and }}[[{{{7}}}|{{{l7|{{{7}}}}}}]]}}{{#if:{{{8|}}}" + , " |{{#if:{{{9|}}}|, |, and }}[[{{{8}}}|{{{l8|{{{8}}}}}}]]}}{{#if:{{{9|}}}" + , " |{{#if:{{{10|}}}|, |, and }}[[{{{9}}}|{{{l9|{{{9}}}}}}]]}}{{#if:{{{10|}}}" + , " |, and [[{{{10}}}|{{{l10|{{{10}}}}}}]]}}{{#if:{{{11| }}}| (too many parameters in {{[[Template:main|main]]}})}}" + )); + } + private void Init_tmpl_for() { + fxt.Init_page_create("Template:For", "For {{#if:{{{1|}}}|{{{1}}}|other uses}}, see [[{{{2|{{PAGENAME}} (disambiguation)}}}]]{{#if:{{{3|}}}|{{#if:{{{4|}}}|, [[{{{3}}}]], {{#if:{{{5|}}}|[[{{{4}}}]], and [[{{{5}}}]]|and [[{{{4}}}]]}}| and [[{{{3}}}]]}}}}."); + } + private void Init_tmpl_other_uses() { + Init_tmpl_about(); + fxt.Init_page_create("Template:Other uses", "{{#if:{{{2|}}}|{{about|||{{{1}}}|and|{{{2|}}}|_nocat=1}}|{{about|||{{{1|{{PAGENAME}} (disambiguation)}}}|_nocat=1}}}}"); + } + private void Init_tmpl_about() { + fxt.Init_page_create("Template:!", "|"); + fxt.Init_page_create("Template:About", String_.Concat_lines_nl + ( "{{#if: {{{1|}}}|This {{#ifeq:{{NAMESPACE}}|{{ns:0}}|article|page}} is about {{{1}}}. }}For {{#if:{{{2|}}}|{{{2}}}|other uses}}, see {{#if:{{{3|}}}|[[{{{3}}}]]{{#ifeq:{{{4|}}}|and| and {{#if:{{{5|}}}|[[{{{5}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.{{#if:{{{2|}}}|{{#if:{{{4|}}}|{{#ifeq:{{{4|}}}|and|| For {{#ifeq:{{{4}}}|1|other uses|{{{4}}}}}, see {{#if:{{{5|}}}|[[{{{5}}}]]{{#ifeq:{{{6|}}}|and| and {{#if:{{{7|}}}|[[{{{7}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.}}{{#if:{{{6|}}}|{{#ifeq:{{{6|}}}|and|| For {{#ifeq:{{{6}}}|1|other uses|{{{6}}}}}, see {{#if:{{{7|}}}|[[{{{7}}}]]{{#ifeq:{{{8|}}}|and| and {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.}}{{#if:{{{8|}}}|{{#ifeq:{{{8|}}}|and|| For {{#ifeq:{{{8}}}|1|other uses|{{{8}}}}}, see {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{PAGENAME}} (disambiguation)]]}}.}}}}}}}}}}{{#if:{{{_nocat|}}}||{{#if:{{{1|}}}{{{2|}}}||{{#if:{{{3|}}}|[[Category:Hatnote templates using unusual parameters|A{{PAGENAME}}]]}}}}{{#ifeq:{{str left|{{{1}}}|3}}|is |[[Category:Hatnote templates using unusual parameters|B{{PAGENAME}}]]}}}}" + )); + } + private void Init_tmpl_see_also() { + fxt.Init_page_create("Template:See also", String_.Concat_lines_nl + ( "See also: {{#if:{{{1|}}} |[[{{{1}}}{{#if:{{{label 1|{{{l1|}}}}}}|{{!}}{{{label 1|{{{l1}}}}}}}}]] |'''Error: [[Template:See also|Template must be given at least one article name]]'''" + , "}}{{#if:{{{2|}}}|{{#if:{{{3|}}}|, | and }} [[{{{2}}}{{#if:{{{label 2|{{{l2|}}}}}}|{{!}}{{{label 2|{{{l2}}}}}}}}]]" + , "}}{{#if:{{{3|}}}|{{#if:{{{4|}}}|, |, and }} [[{{{3}}}{{#if:{{{label 3|{{{l3|}}}}}}|{{!}}{{{label 3|{{{l3}}}}}}}}]]" + , "}}{{#if:{{{4|}}}|{{#if:{{{5|}}}|, |, and }} [[{{{4}}}{{#if:{{{label 4|{{{l4|}}}}}}|{{!}}{{{label 4|{{{l4}}}}}}}}]]" + , "}}{{#if:{{{5|}}}|{{#if:{{{6|}}}|, |, and }} [[{{{5}}}{{#if:{{{label 5|{{{l5|}}}}}}|{{!}}{{{label 5|{{{l5}}}}}}}}]]" + , "}}{{#if:{{{6|}}}|{{#if:{{{7|}}}|, |, and }} [[{{{6}}}{{#if:{{{label 6|{{{l6|}}}}}}|{{!}}{{{label 6|{{{l6}}}}}}}}]]" + , "}}{{#if:{{{7|}}}|{{#if:{{{8|}}}|, |, and }} [[{{{7}}}{{#if:{{{label 7|{{{l7|}}}}}}|{{!}}{{{label 7|{{{l7}}}}}}}}]]" + , "}}{{#if:{{{8|}}}|{{#if:{{{9|}}}|, |, and }} [[{{{8}}}{{#if:{{{label 8|{{{l8|}}}}}}|{{!}}{{{label 8|{{{l8}}}}}}}}]]" + , "}}{{#if:{{{9|}}}|{{#if:{{{10|}}}|, |, and }} [[{{{9}}}{{#if:{{{label 9|{{{l9|}}}}}}|{{!}}{{{label 9|{{{l9}}}}}}}}]]" + , "}}{{#if:{{{10|}}}|{{#if:{{{11|}}}|, |, and }} [[{{{10}}}{{#if:{{{label 10|{{{l10|}}}}}}|{{!}}{{{label 10|{{{l10}}}}}}}}]]" + , "}}{{#if:{{{11|}}}|{{#if:{{{12|}}}|, |, and }} [[{{{11}}}{{#if:{{{label 11|{{{l11|}}}}}}|{{!}}{{{label 11|{{{l11}}}}}}}}]]" + , "}}{{#if:{{{12|}}}|{{#if:{{{13|}}}|, |, and }} [[{{{12}}}{{#if:{{{label 12|{{{l12|}}}}}}|{{!}}{{{label 12|{{{l12}}}}}}}}]]" + , "}}{{#if:{{{13|}}}|{{#if:{{{14|}}}|, |, and }} [[{{{13}}}{{#if:{{{label 13|{{{l13|}}}}}}|{{!}}{{{label 13|{{{l13}}}}}}}}]]" + , "}}{{#if:{{{14|}}}|{{#if:{{{15|}}}|, |, and }} [[{{{14}}}{{#if:{{{label 14|{{{l14||}}}}}}|{{!}}{{{label 14|{{{l14}}}}}}}}]]" + , "}}{{#if:{{{15|}}}|, and [[{{{15}}}{{#if:{{{label 15|{{{l15}}}}}}|{{!}}{{{label 15|{{{l15}}}}}}}}]]" + , "}}{{#if:{{{16|}}}| — '''
      Error: [[Template:See also|Too many links specified (maximum is 15)]]'''" + , "}}" + )); + } + private void Init_tmpl_redirect() { + fxt.Init_page_create("Template:Redirect", String_.Concat_lines_nl + ( "\"{{{1}}}\" redirects here. For {{#if:{{{2|}}}|{{{2}}}|other uses}}, see {{#if:{{{3|}}}|[[{{{3}}}]]{{#ifeq:{{{4|}}}|and| and {{#if:{{{5|}}}|[[{{{5}}}]]|[[{{{1}}} (disambiguation)]]}}}}|[[{{{1}}} (disambiguation)]]}}.{{#if:{{{2|}}}|{{#if:{{{4|}}}|{{#ifeq:{{{4|}}}|and|| For {{#ifeq:{{{4}}}|1|other uses|{{{4}}}}}, see {{#if:{{{5|}}}|[[{{{5}}}]]{{#ifeq:{{{6|}}}|and| and {{#if:{{{7|}}}|[[{{{7}}}]]|[[{{{4}}} (disambiguation)]]}}}}|[[{{{4}}} (disambiguation)]]}}.}}{{#if:{{{6|}}}|{{#ifeq:{{{6|}}}|and|| For {{#ifeq:{{{6}}}|1|other uses|{{{6}}}}}, see {{#if:{{{7|}}}|[[{{{7}}}]]{{#ifeq:{{{8|}}}|and| and {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{{6}}} (disambiguation)]]}}}}|[[{{{6}}} (disambiguation)]]}}.}}{{#if:{{{8|}}}|{{#ifeq:{{{8|}}}|and|| For {{#ifeq:{{{8}}}|1|other uses|{{{8}}}}}, see {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{{8}}} (disambiguation)]]}}.}}}}}}}}}}" + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_sandbox_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_sandbox_tst.java new file mode 100644 index 000000000..2377e4152 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_sandbox_tst.java @@ -0,0 +1,46 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_invk_sandbox_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() { + fxt.Reset(); + fxt.Init_defn_clear(); + fxt.Init_defn_add("concat", "{{{1}}}{{{2}}}"); + } + @Test public void Basic() { + fxt.Test_parse_tmpl_str("{{concat|a|b}}", "ab"); + } + @Test public void Basic_too_many() { // c gets ignored + fxt.Test_parse_tmpl_str("{{concat|a|b|c}}", "ab"); + } + @Test public void Basic_too_few() { + fxt.Test_parse_tmpl_str("{{concat|a}}", "a{{{2}}}"); + } + @Test public void Basic_else() { + fxt.Init_defn_add("concat", "{{{1}}}{{{2|?}}}"); + fxt.Test_parse_tmpl_str("{{concat|a}}", "a?"); + } + @Test public void Eq_2() { + fxt.Init_defn_add("concat", "{{{lkp1}}}"); + fxt.Test_parse_tmpl_str("{{concat|lkp1=a=b}}", "a=b"); + } + @Test public void Recurse() {fxt.Test_parse_tmpl_str_test("<{{concat|{{{1}}}|{{{2}}}}}>" , "{{test|a|b}}", "");} + @Test public void Recurse_mix() {fxt.Test_parse_tmpl_str_test("{{concat|.{{{1}}}.|{{{2}}}}}" , "{{test|a|b}}", ".a.b");} + @Test public void Recurse_err() {fxt.Test_parse_tmpl_str_test("{{concat|{{{1}}}|{{{2}}}}}" , "{{test1|a|b}}", "[[:Template:test1]]");} // NOTE: make sure test1 does not match test + @Test public void KeyNewLine() {fxt.Test_parse_tmpl_str_test("{{\n concat|a|b}}" , "{{\n test}}", "ab");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__basic__tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__basic__tst.java new file mode 100644 index 000000000..789c5f917 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__basic__tst.java @@ -0,0 +1,438 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*; +public class Xot_invk_wkr__basic__tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Basic() { + fxt.Test_parse_page_tmpl("{{a}}", fxt.tkn_tmpl_invk_w_name(0, 5, 2, 3)); + } + @Test public void Arg_many() { + fxt.Test_parse_page_tmpl("{{a|b|c|d}}", fxt.tkn_tmpl_invk_w_name(0, 11, 2, 3) + .Args_(fxt.tkn_arg_val_txt_(4, 5), fxt.tkn_arg_val_txt_(6, 7), fxt.tkn_arg_val_txt_(8, 9))); + } + @Test public void Kv() { + fxt.Test_parse_page_tmpl("{{a|b=c}}", fxt.tkn_tmpl_invk_w_name(0, 9, 2, 3) + .Args_ + ( fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(4, 5))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(6, 7))) + )); + } + @Test public void Kv_arg() { + fxt.Test_parse_tmpl("{{a|b={{{1}}}}}", fxt.tkn_tmpl_invk_w_name(0, 15, 2, 3) + .Args_ + ( fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(4, 5))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_tmpl_prm_find_(fxt.tkn_txt_(9, 10)))) + )); + } + @Test public void Kv_tmpl_compiled() { + fxt.Test_parse_tmpl("{{a|b={{c}}}}", fxt.tkn_tmpl_invk_w_name(0, 13, 2, 3) + .Args_ + ( fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(4, 5))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_tmpl_invk_w_name(6, 11, 8, 9))) + )); + } + @Test public void Kv_tmpl_dynamic() { + fxt.Test_parse_tmpl("{{a|b={{c|{{{1}}}}}}}", fxt.tkn_tmpl_invk_w_name(0, 21, 2, 3) + .Args_ + ( fxt.tkn_arg_nde_() + . Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(4, 5))) + . Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_tmpl_invk_w_name(6, 19, 8, 9).Args_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_().Subs_(fxt.tkn_tmpl_prm_find_(fxt.tkn_txt_(13, 14)))))) + ) + )); + } + @Test public void Nest() { + fxt.Test_parse_page_tmpl("{{a|b{{c|d}}e}}", fxt.tkn_tmpl_invk_w_name(0, 15, 2, 3).Args_ + ( fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_ + ( fxt.tkn_txt_(4, 5) + , fxt.tkn_tmpl_invk_w_name(5, 12, 7, 8).Args_ + ( fxt.tkn_arg_val_txt_(9, 10) + ) + , fxt.tkn_txt_(12, 13) + )) + )); + } + @Test public void Whitespace() { + fxt.Test_parse_page_tmpl("{{a| b = c }}", fxt.tkn_tmpl_invk_w_name(0, 13, 2, 3).Args_ + ( fxt.tkn_arg_nde_() + .Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_space_(4, 5).Ignore_y_(), fxt.tkn_txt_(5, 6), fxt.tkn_space_( 6, 7).Ignore_y_())) + .Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_space_(8, 9).Ignore_y_(), fxt.tkn_txt_(9, 10), fxt.tkn_space_(10, 11).Ignore_y_())) + )); + } + @Test public void Whitespace_nl() { + fxt.Test_parse_page_tmpl("{{a|b=c\n}}", fxt.tkn_tmpl_invk_w_name(0, 10, 2, 3).Args_ + ( fxt.tkn_arg_nde_() + .Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(4, 5))) + .Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(6, 7), fxt.tkn_nl_char_(7, 8).Ignore_y_())) + )); + } + @Test public void Err_noName() { // WP: [[Russian language]] + fxt.Test_parse_page_tmpl("{{|}}", fxt.tkn_curly_bgn_(0), fxt.tkn_pipe_(2), fxt.tkn_txt_(3, 5)); + } + @Test public void Err_noName_nl() { + fxt.Test_parse_page_tmpl("{{\n|}}", fxt.tkn_curly_bgn_(0), fxt.tkn_nl_char_len1_(2), fxt.tkn_pipe_(3), fxt.tkn_txt_(4, 6)); + } + @Test public void Err_noName_tab() { + fxt.Test_parse_page_tmpl("{{\t|}}", fxt.tkn_curly_bgn_(0), fxt.tkn_tab_(2), fxt.tkn_pipe_(3), fxt.tkn_txt_(4, 6)); + } + @Test public void Err_empty() { // WP: [[Set theory]] + fxt.Test_parse_page_tmpl("{{}}", fxt.tkn_txt_(0, 4)); + } + @Test public void DynamicName() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("proc_1", "proc_1 called"); + fxt.Init_defn_add("proc_2", "proc_2 called"); + fxt.Test_parse_tmpl_str_test("{{proc_{{{1}}}}}" , "{{test|1}}" , "proc_1 called"); + fxt.Test_parse_tmpl_str_test("{{proc_{{{1}}}}}" , "{{test|2}}" , "proc_2 called"); + fxt.Test_parse_tmpl_str_test("{{proc_{{#expr:1}}}}" , "{{test}}" , "proc_1 called"); + } + @Test public void Comment() { + fxt.Test_parse_tmpl_str_test("b" , "{{test}}" , "b"); + } + @Test public void Err_equal() { // WP:[[E (mathematical constant)]] + fxt.Test_parse_page_tmpl("{{=}}", fxt.tkn_tmpl_invk_(0, 5).Name_tkn_(fxt.tkn_arg_nde_(2, 3).Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_eq_(2))))); + } + @Test public void Err_dangling() { // WP:[[Antoni Salieri]]; {{icon it}\n + fxt.Test_parse_page_tmpl("{{fail} {{pass}}", fxt.tkn_curly_bgn_(0), fxt.tkn_txt_(2, 7), fxt.tkn_space_(7, 8), fxt.tkn_tmpl_invk_w_name(8, 16, 10, 14)); + } + @Test public void MultipleColon() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("H:IPA", "{{{1}}}"); + fxt.Test_parse_tmpl_str_test("{{H:IPA|{{{1}}}}}" , "{{test|a}}" , "a"); + } + @Test public void RedundantTemplate() { // {{Template:a}} == {{a}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("a", "a"); + fxt.Test_parse_tmpl_str_test("{{Template:a}}" , "{{test}}" , "a"); + fxt.Init_defn_clear(); + } + @Test public void Lnki() { // PURPOSE: pipe inside lnki should not be interpreted for tmpl: WP:[[Template:Quote]] + fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|[[a|b]]|c}}" , "[[a|b]]c"); + } + @Test public void Lnki2() {// PURPOSE: pipe inside lnki inside tmpl should be interpreted WP:[[H:IPA]] + fxt.Test_parse_tmpl_str_test("[[a|{{#switch:{{{1}}}|b=c]]|d=e]]|f]]}}" , "{{test|b}}" , "[[a|c]]"); + } + @Test public void Nowiki() { // PURPOSE: nowiki tag should be ignored: en.w:Template:Main + fxt.Test_parse_tmpl_str_test("
      class='a' />" , "{{test}}" , "
      class='a' />"); + } + @Test public void Nowiki_if() { // PURPOSE: templates and functions inside nowiki should not be evaluated + fxt.Test_parse_tmpl_str_test("a {{#if:|y|n}} b" , "{{test}}" , "a {{#if:|y|n}} b"); + } + @Test public void Nowiki_endtag() { // PURPOSE: should not match + fxt.Test_parse_page_all_str(" ''b'' c" , " b c"); + } + @Test public void Nowiki_xnde_frag() { // PURPOSE: nowiki did not handle xnde frag and literalized; nowiki_xnde_frag; DATE:2013-01-27 + fxt.Test_parse_page_all_str("
      {{#expr:1}}
      b
      " , "<pre>1
      b
      "); + } + @Test public void Nowiki_lnki() { // PURPOSE: nowiki should noop lnkis; DATE:2013-01-27 + fxt.Test_parse_page_all_str("[[A]]" , "[[A]]"); + } + @Test public void Nowiki_underscore() { // PURPOSE: nowiki did not handle __DISAMBIG__; DATE:2013-07-28 + fxt.Test_parse_page_all_str("__DISAMBIG__" , "__DISAMBIG__"); + } + @Test public void Nowiki_asterisk() { // PURPOSE: nowiki should noop lists; DATE:2013-08-26 + fxt.Test_parse_page_all_str("*a", "*a"); + } + @Test public void Nowiki_space() { // PURPOSE: nowiki should noop space (else pre); DATE:2013-09-03 + fxt.Init_para_y_(); + fxt.Test_parse_page_all_str("a\n b", "

      a\n b\n

      \n"); + fxt.Init_para_n_(); + } + @Test public void LnkiWithPipe_basic() { // PURPOSE: pipe in link should not count towards tmpl: WP:{{H:title|dotted=no|pronunciation:|[[File:Loudspeaker.svg|11px|link=|alt=play]]}} + fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|[[b=c|d]]}}" , "[[b=c|d]]{{{2}}}"); + } + @Test public void LnkiWithPipe_nested() { + fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|[[b=c|d[[e|f]]g]]}}" , "[[b=c|d[[e|f]]g]]{{{2}}}"); + } + @Test public void LnkiWithPipe_unclosed() { + fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|[[b=c|d}}" , "{{test|[[b=c|d}}"); + } + @Test public void Err_tmp_empty() { // PURPOSE: {{{{R from misspelling}} }} + fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{ {{a}} }}" , "{{[[:Template:a]]}}"); + } + @Test public void Mismatch_bgn() { // PURPOSE: handle {{{ }}; WP:Paris Commune; Infobox Former Country + fxt.Init_defn_clear(); + fxt.Init_defn_add("!", "|"); + fxt.Test_parse_tmpl_str_test("{{#if:|{{{!}}{{!}}}|x}}" , "{{test}}" , "x"); + } + @Test public void Mismatch_tblw() { // PURPOSE: handle {{{!}}; WP:Soviet Union + fxt.Init_defn_clear(); + fxt.Init_defn_add("!", "|"); + fxt.Test_parse_page_all_str("a\n{{{!}}\n|b\n|}", String_.Concat_lines_nl_skip_last + ( "a" + , "" + , " " + , " " + , " " + , "
      b" + , "
      " + , "" + ) + ); + fxt.Init_defn_clear(); + } + @Test public void Lnki_space() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("c", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{c|[[a|b ]]}}", "[[a|b ]]"); + } + @Test public void Bug_innerTemplate() { // PURPOSE: issue with inner templates not using correct key + fxt.Init_defn_clear(); + fxt.Init_defn_add("temp_1", "{{temp_2|key1=val1}}"); + fxt.Init_defn_add("temp_2", "{{{key1}}}"); + fxt.Test_parse_tmpl_str("{{temp_1}}", "val1"); + } + @Test public void Xnde_xtn_preserved() { // PURPOSE: tmpl was dropping .Xtn ndes; + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_template", "{{{1}}}"); + fxt.Test_parse_page_all_str("{{test_template|a1b}}", "a
      1
      b"); // was just ab + fxt.Init_defn_clear(); + } + @Test public void Recurse() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_recurse", "bgn:{{test_recurse}}:end"); + fxt.Test_parse_page_all_str("{{test_recurse}}", "bgn::end"); + fxt.Init_defn_clear(); + } + @Test public void Ws_nl() { + fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{test|\na}}" , "\na"); + } + @Test public void Ws_trimmed_key_0() { // PURPOSE: control test for key_1, key_2 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{test_2|{{{1}}}}}"); + fxt.Init_defn_add("test_2", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{test_1| a }}", " a "); + fxt.Init_defn_clear(); + } + @Test public void Ws_trimmed_key_1() { // PURPOSE: trim prm when passed as key; + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{test_2|key={{{1}}}}}"); + fxt.Init_defn_add("test_2", "{{{key}}}"); + fxt.Test_parse_tmpl_str("{{test_1| a }}", "a"); + fxt.Init_defn_clear(); + } + @Test public void Ws_trimmed_key_2() { // PURPOSE: trim prm; note that 1 is key not idx; PAGE:en.w:Coord in Chernobyl disaster, Sahara + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{test_2|1={{{1}}}}}"); + fxt.Init_defn_add("test_2", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{test_1| a }}", "a"); + fxt.Init_defn_clear(); + } + @Test public void Ws_trimmed_key_3() { // PURPOSE: trim entire arg only, not individual prm + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{test_2|1={{{1}}}{{{2}}}}}"); + fxt.Init_defn_add("test_2", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{test_1| a | b }}", "a b"); + fxt.Init_defn_clear(); + } + @Test public void Ws_eval_prm() { // PURPOSE: skip ws in prm_idx; EX:it.w:Portale:Giochi_da_tavolo; it.w:Template:Alternate; DATE:2014-02-09 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", String_.Concat_lines_nl_skip_last + ( "{{{ {{#expr: 1}} }}}" + )); + fxt.Test_parse_tmpl_str("{{test_1|a}}", "a"); + fxt.Init_defn_clear(); + } + @Test public void Keyd_arg_is_trimmed() { // PURPOSE: trim entire arg only, not individual prm; PAGE:en.w:William Shakespeare; {{Relatebardtree}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{test_2|1={{{{{{1}}}}}}}}"); + fxt.Init_defn_add("test_2", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{test_1| b | b = x }}", "x"); + fxt.Init_defn_clear(); + } + @Test public void Ws_arg() { // PURPOSE: whitespace arg should not throw array index out of bounds; EX.WIKT: wear one's heart on one's sleeve + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{{{{1}}}}}"); + fxt.Test_parse_tmpl_str("{{test_1| }}", ""); + fxt.Init_defn_clear(); + } + @Test public void Xnde_xtn_ref_not_arg() { // PURPOSE: }}; arg1 is a not "b"; PAGE:en.w:WWI + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{{1}}}"); + fxt.Test_parse_page_tmpl_str("{{test_1|a}}", "a"); + fxt.Init_defn_clear(); + } + @Test public void Multi_bgn_5_end_3_2() { + fxt.Test_parse_tmpl("{{{{{1}}}|a}}", fxt.tkn_tmpl_invk_(0, 13) + .Name_tkn_(fxt.tkn_arg_nde_(2, 9).Key_tkn_(fxt.tkn_arg_itm_(fxt.tkn_tmpl_prm_find_(fxt.tkn_txt_(5, 6))))) + .Args_ + ( fxt.tkn_arg_val_txt_(10, 11) + ) + ); + } + @Test public void Lnki_has_invk_end() {// PURPOSE: [[A|bcd}}]] should not break enclosing templates; EX.CM:Template:Protect + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{#switch:y" + , " |y=[[A|b}}]]" + , " |#default=n" + , "}}" + ), "[[A|b}}]]"); + } + @Test public void Lnki_has_prm_end() {// PURPOSE: [[A|bcd}}}]] should not break enclosing templates; EX.CM:Template:Protect + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{#switch:y" + , " |y=[[A|b}}}]]" + , " |#default=n" + , "}}" + ), "[[A|b}}}]]"); + } + @Test public void Tmpl_overrides_pfunc() { // PURPOSE: {{plural|}} overrides {{plural:}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("plural", "{{{1}}}"); + fxt.Test_parse_tmpl_str("{{plural|a}}" , "a"); + fxt.Test_parse_tmpl_str("{{plural:2|a|b}}" , "b"); // make sure pfunc still works + fxt.Init_defn_clear(); + } + @Test public void Tmpl_aliases() { // PURPOSE: handled aliases for Template ns + fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Tid__template, "TemplateAlias"); + fxt.Wiki().Ns_mgr().Init(); + fxt.Init_defn_clear(); + fxt.Init_defn_add("tmpl_key", "tmpl_val"); + fxt.Test_parse_tmpl_str("{{TemplateAlias:tmpl_key}}" , "tmpl_val"); + fxt.Init_defn_clear(); + } + @Test public void Tmpl_aliases_2() { // PURPOSE: handled aliases for other ns; DATE:2013-02-08 + fxt.Wiki().Ns_mgr().Aliases_add(Xow_ns_.Tid__project, "WP"); + fxt.Wiki().Ns_mgr().Init(); + fxt.Init_defn_clear(); + fxt.Init_page_create("Project:tmpl_key", "tmpl_val"); + fxt.Test_parse_tmpl_str("{{WP:tmpl_key}}" , "tmpl_val"); + fxt.Init_defn_clear(); + } + @Test public void Template_loop_across_namespaces() {// PURPOSE: {{Institution:Louvre}} results in template loop b/c it calls {{Louvre}}; EX: c:Mona Lisa + fxt.Init_page_create("Template:Test", "test"); + fxt.Init_page_create("Category:Test", "{{Test}}"); + fxt.Test_parse_page_all_str("{{Category:Test}}", "test"); + } + @Test public void Closing_braces_should_not_extend_beyond_lnki() { // PURPOSE: extra }} should not close any frames beyond lnki; EX:w:Template:Cite wikisource; w:John Fletcher (playwright) + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_b", "{{{test_b_0|}}}"); + fxt.Init_defn_add("test_a", "{{test_b|test_b_0=[[{{{test_a_0}}}}}]]}}"); // NOTE: extra 2 }}; should render literally and not close "{{test_b" + fxt.Test_parse_tmpl_str("{{test_a|test_a_0=1}}" , "[[1}}]]"); + fxt.Init_defn_clear(); + } +// @Test public void Trim_ws_on_sub_tmpls() { // PURPOSE: ws should be trimmed on eval tkns; EX:w:Lackawanna Cut-Off; {{Lackawanna Cut-Off}}; DELETE: no longer needed; DATE:2014-02-04 +// fxt.Init_defn_clear(); +// fxt.Init_defn_add("test_b", "\n\nb\n\n"); +// fxt.Init_defn_add("test_a", "a{{test_b}}c"); +// fxt.Test_parse_tmpl_str("{{test_a}}" , "a\n\nbc"); +// fxt.Init_defn_clear(); +// } + @Test public void Nowiki_tblw() { // PURPOSE: nowiki does not exclude sections with pipe; will cause tables to fail; EX: de.wikipedia.org/wiki/Hilfe:Vorlagenprogrammierung + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|{{ #time:M|Jan}}" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
      {{ #time:M|Jan}}" + , "
      " + , "" + )); + } + @Test public void Template_plus_other_ns() { // PURPOSE.fix: Template:Wikipedia:A was transcluding "Wikipedia:A" instead of "Template:Wikipedia:A"; DATE:2013-04-03 + fxt.Init_defn_clear(); + fxt.Init_page_create("Template:Wikipedia:A" , "B"); + fxt.Test_parse_tmpl_str("{{Template:Wikipedia:A}}" , "B"); + fxt.Init_defn_clear(); + } + @Test public void Return_nl() { // PURPOSE: allow \n to be returned by tmpl; do not trim; EX: zh.wikipedia.org/wiki/北區_(香港); DATE:2014-02-04 + fxt.Init_defn_add("1x", "{{{1}}}"); + fxt.Test_parse_tmpl_str("a{{1x|\n}}b", "a\nb"); + fxt.Init_defn_clear(); + } + @Test public void Ignore_hdr() { // PURPOSE: hdr-like tkns inside tmpl should not be treated as "=" in tmpl_prm; EX: key_1\n==a==; EX:it.b:Wikibooks:Vetrina; DATE:2014-02-09 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{{key_1|null_key_1}}}"); + fxt.Test_parse_tmpl_str(String_.Concat_lines_nl_skip_last // == a === should be treated as hdr; + ( "{{test_1|key_1" + , "== a ==" + , "}}" + ) + , "null_key_1" + ); + fxt.Test_parse_tmpl_str(String_.Concat_lines_nl_skip_last // = a = should not be treated as hdr; + ( "{{test_1|key_1" + , "= a =" + , "}}" + ) + , "a =" + ); + fxt.Init_defn_clear(); + } + @Test public void Ignore_hdr_2() { // PURPOSE: hdr-like logic did not work for "== \n"; PAGE:nl.q:Geert_Wilders; DATE:2014-06-05 + fxt.Init_defn_clear(); + fxt.Init_defn_add("Hdr_w_space", String_.Concat_lines_nl_skip_last + ( "{{#if:{{{key|}}} | " + , "==={{{key}}}=== " // NOTE " " after "===" + , "|}}" + )); + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{Hdr_w_space" + , "|key=A" + , "}}" + ), "===A===" + ); + fxt.Init_defn_clear(); + } + @Test public void Ignore_hdr_3() { // PURPOSE: tkn with multiple eq should have be treated as value, not header; PAGE:zh.w:Wikipedia:条目评选; DATE:2014-08-27 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{{key_1|null_key_1}}}"); + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{test_1" + , "|key_1===A==" // note that this is not "===A==", but "=","===A==" + , "}}" + ), "==A==" + ); + fxt.Init_defn_clear(); + } + @Test public void Ignore_hdr_4() { // PURPOSE: variation of above; make sure 2nd "==" doesn't trigger another key; DATE:2014-08-27 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_1", "{{{key_1|null_key_1}}}"); + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{test_1" + , "|key_1===A===B" // = should be at "==A", not "==B" + , "}}" + ), "==A===B" + ); + fxt.Init_defn_clear(); + } + @Test public void Tmpl_case_match() { // PURPOSE: template name should match by case; EX:es.d:eclipse; DATE:2014-02-12 + fxt.Init_defn_clear(); + fxt.Init_defn_add("CASE_MATCH", "found", Xow_ns_case_.Tid__all); + fxt.Test_parse_tmpl_str("{{case_match}}", "[[:Template:case_match]]"); // Xot_invk_tkn will do 2 searches: "test" and "Test" + fxt.Test_parse_tmpl_str("{{cASE_MATCH}}", "found"); // Xot_invk_tkn will do 2 searches: "tEST" and "TEST" + fxt.Init_defn_clear(); + } + @Test public void Kv_same() { // PURPOSE: multiple identical keys should retrieve last, not first; EX: {{A|1=a|1=b}}; PAGE:el.d:ἔχω DATE:2014-07-23 + fxt.Init_defn_clear(); + fxt.Init_defn_add("tmpl_1", "{{{1}}}"); + fxt.Test_parse_tmpl_str_test("{{tmpl_1|1=a|1=b}}" , "{{test}}" , "b"); // duplicate "1"; use last + fxt.Test_parse_tmpl_str_test("{{tmpl_1|a|1=b}}" , "{{test}}" , "b"); // "a" has implicit key of "1"; overwritten by "1=b"; verified against MW + fxt.Test_parse_tmpl_str_test("{{tmpl_1|1=a|b}}" , "{{test}}" , "b"); // "b" has implicit key of "1"; overwritten by "1=b"; verified against MW + } + @Test public void Bang() { // PURPOSE: support new bang keyword; DATE:2014-08-05 + fxt.Test_parse_tmpl_str("{{!}}", "|"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__missing__tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__missing__tst.java new file mode 100644 index 000000000..33c650e5b --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__missing__tst.java @@ -0,0 +1,45 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*; +public class Xot_invk_wkr__missing__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Missing() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_template", "{{[[Template:{{{1}}}|{{{1}}}]]}}"); + fxt.Test_parse_tmpl_str("{{test_template|a}}", "{{[[Template:a|a]]}}"); + fxt.Init_defn_clear(); + } + @Test public void Missing__name_and_args() { // PURPOSE: missing title should return name + args; used to only return name; PAGE:en.w:Flag_of_Greenland; DATE:2016-06-21 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_template", "{{ {{{1}}} | a | b }}"); + fxt.Test_parse_tmpl_str("{{test_template}}", "{{{{{1}}}| a | b }}"); // NOTE: this should include spaces (" {{{1}}} "), but for now, ignore + fxt.Init_defn_clear(); + } + @Test public void Missing__evaluate_optional() { // PURPOSE: missing title should still evaulate optional args; "{{{a|}}}" -> ""; PAGE:en.w:Europe; en.w:Template:Country_data_Guernsey DATE:2016-10-13 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_template", "{{ {{{1}}} | {{{a|}}} | b }}"); + fxt.Test_parse_tmpl_str("{{test_template}}", "{{{{{1}}}| | b }}"); // NOTE: "| |" not "| {{{a|}}} |" + fxt.Init_defn_clear(); + } + @Test public void Missing_foreign() { + Xow_ns ns = fxt.Wiki().Ns_mgr().Ns_template(); + byte[] old_ns = ns.Name_db(); + ns.Name_bry_(Bry_.new_a7("Template_foreign")); + fxt.Test_parse_tmpl_str("{{Missing}}", "[[:Template_foreign:Missing]]"); + ns.Name_bry_(old_ns); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__prepend_nl__tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__prepend_nl__tst.java new file mode 100644 index 000000000..33632fb9a --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__prepend_nl__tst.java @@ -0,0 +1,119 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_invk_wkr__prepend_nl__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @Test public void Basic() { // PURPOSE: if {| : ; # *, auto add new_line REF.MW:Parser.php|braceSubstitution + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_inner", "# a"); + fxt.Test_parse_tmpl_str_test("{{test_inner}}" , "z {{test}}" , "z \n# a"); + fxt.Init_defn_clear(); + } + @Test public void Skip_if_nl_exists() { + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_inner", "# a"); + fxt.Test_parse_tmpl_str_test("{{test_inner}}" , "z \n{{test}}" , "z \n# a"); // NOTE: no \n + fxt.Init_defn_clear(); + } + @Test public void Skip_if_nl_exists_2() { // PURPOSE: \n inside template args should not print \n\n; PAGE:bn.w:লিওনেল_মেসি |ko.w:도쿄_지하철_히비야_선|DATE:2014-05-27 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test_list", "# a"); + fxt.Init_defn_add("test_print", "{{{1}}}"); + fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last + ( "{{test_print|" + , "{{test_list}}" // note that there is a "\n" here, but test_list will return "#"; "#" should not be prepended with \n + , "{{test_list}}" + , "}}" + ), "{{test}}" + , String_.Concat_lines_nl_skip_last + ( "" // NOTE: \n still prints b/c of \n between "{{test_print|" and "{{test_list}}"; should trim ws at start; + , "# a" + , "# a" + )); + fxt.Init_defn_clear(); + } + @Test public void Pfunc() {// PURPOSE: if {| : ; # *, auto add new_line; parser_function variant; PAGE:en.w:Soviet Union; Infobox former country + fxt.Test_parse_tmpl_str_test("" , "z {{#if:true|#a|n}}" , "z \n#a"); + } + @Test public void Bos() { // PURPOSE: function should expand "*a" to "\n*a" even if "*a" is bos; SEE:NOTE_1 PAGE:en.w:Rome and Panoramas; DATE:2014-02-05 + fxt.Test_parse_page_tmpl_str("{{#if:x|*a}}", "\n*a"); + } + @Test public void Tmpl_arg() { // PURPOSE: tmpl arg should auto-create; PAGE:vi.w:Friedrich_II_của_Phổ; DATE:2014-04-26 + fxt.Init_defn_add("cquote" , "*b"); + fxt.Init_defn_add("blockquote" , "
      {{{1}}}
      "); + fxt.Test_html_full_str("a\n{{blockquote|{{cquote}}}}" + , String_.Concat_lines_nl_skip_last + ( "a" + , "
      " + , "
        " + , "
      • b" + , "
      • " + , "
      " + ) + ); + } + @Test public void Nested_1_n() { // PURPOSE: handled nested templates; PAGE:en.w:Central_Line en.w:Panama_Canal; DATE:2014-08-21 + fxt.Init_defn_clear(); + fxt.Init_defn_add("Nest_1" , "a{{Nest_1_1}}"); // 0: no \n + fxt.Init_defn_add("Nest_1_1" , "b\n{{Nest_1_1_1}}"); // 1: \n + fxt.Init_defn_add("Nest_1_1_1" , "*c"); // 2: "*" should not prepend \n b/c (1) has \n; used to only check (0) + fxt.Test_parse_tmpl_str_test("{{Nest_1}}", "{{test}}", String_.Concat_lines_nl_skip_last + ( "ab" // not prepended + , "*c" + )); + } + @Test public void Nested_1_y() { // PURPOSE: handled nested templates; PAGE:en.w:Lackawanna_Cut-Off; DATE:2014-08-21 + fxt.Init_defn_clear(); + fxt.Init_defn_add("Nest_1" , "a\n{{Nest_1_1}}"); // 0: no \n + fxt.Init_defn_add("Nest_1_1" , "b{{Nest_1_1_1}}"); // 1: char + fxt.Init_defn_add("Nest_1_1_1" , "*c"); // 2: "*" should prepend \n b/c (1) has char; used to check (0) and not prepend + fxt.Test_parse_tmpl_str_test("{{Nest_1}}", "{{test}}", String_.Concat_lines_nl_skip_last + ( "a" + , "b" // prepended + , "*c" + )); + } + @Test public void Nested_0_n() { // PURPOSE: handled nested templates variation of above; DATE:2014-08-21 + fxt.Init_defn_clear(); + fxt.Init_defn_add("Nest_1" , "a\n{{Nest_1_1}}"); // 0: \n + fxt.Init_defn_add("Nest_1_1" , "{{Nest_1_1_1}}"); // 1: "" + fxt.Init_defn_add("Nest_1_1_1" , "*b"); // 2: "*" should not prepend \n b/c (1) is empty and (0) has \n + fxt.Test_parse_tmpl_str_test("{{Nest_1}}", "{{test}}", String_.Concat_lines_nl_skip_last + ( "a" // not prepended + , "*b" + )); + } + @Test public void Nested_0_y() { // PURPOSE: handled nested templates variation of above; DATE:2014-08-21 + fxt.Init_defn_clear(); + fxt.Init_defn_add("Nest_1" , "a{{Nest_1_1}}"); // 0: no \n + fxt.Init_defn_add("Nest_1_1" , "{{Nest_1_1_1}}"); // 1: "" + fxt.Init_defn_add("Nest_1_1_1" , "*b"); // 2: "*" should prepend \n b/c (1) is empty and (0) has char + fxt.Test_parse_tmpl_str_test("{{Nest_1}}", "{{test}}", String_.Concat_lines_nl_skip_last + ( "a" // prepended + , "*b" + )); + } +} +/* +NOTE_1: function should expand "*a" to "\n*a" even if "*a" is bos +consider following +Template:Test with text of "#a" +a) "a{{test}}" would return "a\n#a" b/c of rule for auto-adding \n +b) bug was that "{{test}}" would return "#a" b/c "#a" was at bos which would expand to list later + however, needs to be "\n#a" b/c appended to other strings wherein bos would be irrelevant. +Actual situation was very complicated. PAGE:en.w:Rome; +*/ diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__raw_msg__tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__raw_msg__tst.java new file mode 100644 index 000000000..d0326ad68 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__raw_msg__tst.java @@ -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.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_invk_wkr__raw_msg__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_defn_clear();} + @Test public void Raw() { // PURPOSE: {{raw:A}} is same as {{A}}; EX.WIKT:android; {{raw:ja/script}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("Test 1", "{{#if:|y|{{{1}}}}}"); + fxt.Test_parse_tmpl_str("{{raw:Test 1|a}}", "a"); + fxt.Init_defn_clear(); + } + @Test public void Raw_spanish() { // PURPOSE.fix: {{raw}} should not fail; EX:es.s:Carta_a_Silvia; DATE:2014-02-11 + fxt.Test_parse_tmpl_str("{{raw}}", "[[:Template:raw]]"); // used to fail; now tries to get Template:Raw which doesn't exist + } + @Test public void Special() { // PURPOSE: {{Special:Whatlinkshere}} is same as [[:Special:Whatlinkshere]]; EX.WIKT:android; isValidPageName + fxt.Test_parse_page_tmpl_str("{{Special:Whatlinkshere}}", "[[:Special:Whatlinkshere]]"); + } + @Test public void Special_arg() { // PURPOSE: make sure Special still works with {{{1}}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("Test1", "{{Special:Whatlinkshere/{{{1}}}}}"); + fxt.Test_parse_tmpl_str("{{Test1|-1}}", "[[:Special:Whatlinkshere/-1]]"); + fxt.Init_defn_clear(); + } + @Test public void Raw_special() { // PURPOSE: {{raw:A}} is same as {{A}}; EX.WIKT:android; {{raw:ja/script}} + fxt.Test_parse_tmpl_str("{{raw:Special:Whatlinkshere}}", "[[:Special:Whatlinkshere]]"); + fxt.Init_defn_clear(); + } + @Test public void Msg() { + fxt.Init_defn_add("CURRENTMONTH", "a"); + fxt.Test_parse_tmpl_str("{{msg:CURRENTMONTH}}", "a"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__transclude__tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__transclude__tst.java new file mode 100644 index 000000000..df1073f1f --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_invk_wkr__transclude__tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_invk_wkr__transclude__tst { + @Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_defn_clear();} + @Test public void Basic() { // PURPOSE: {{:Template:Test}} is same as {{Template:Test}}; EX.WIKT:android; japanese and {{:Template:ja/script}} + fxt.Init_defn_add("Test_1", "{{#if:|y|n}}"); // NOTE: must be of form "Test 1"; test_1 will fail + fxt.Test_parse_tmpl_str("{{:Template:Test 1}}", "n"); + } + @Test public void Arguments() { // PURPOSE: transclusion test with arguments + fxt.Init_page_create("PageToTransclude", "a{{{key}}}c"); + fxt.Test_parse_tmpl_str("some text to make this page longer than transclusion {{:PageToTransclude|key=b}}" , "some text to make this page longer than transclusion abc"); + } + @Test public void Redirect() { // PURPOSE: StackOverflowError when transcluded sub-page redirects back to root_page; DATE:2014-01-07 + fxt.Init_page_create("Root/Leaf", "#REDIRECT [[Root]]"); + fxt.Init_page_create("Root", "A.png|a{{/Leaf}}b"); // NOTE: gallery neeeded for XOWA to fail; MW fails if just {{/Leaf}} + fxt.Test_parse_page("Root", "A.png|a{{/Leaf}}b"); + } + @Test public void Missing__sub_page() { // PURPOSE: transclusion of a missing page should create a link, not print an empty String; EX: it.u:Dipartimento:Design; DATE:2014-02-12 + fxt.Page_ttl_("Test_Page"); + fxt.Test_parse_tmpl_str("{{/Sub}}", "[[Test_Page/Sub]]"); + } + @Test public void Missing__colon_prefix() {// PURPOSE: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24 + fxt.Test_parse_tmpl_str("{{:a}}", "[[:a]]"); // ":a", not "Template:A" or "A" + } + @Test public void Colon_by_safesubst() { // SUPPORT: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24 + fxt.Init_defn_add("Test_2", "{{safesubst:Template:{{{1}}}}}"); + fxt.Test_parse_tmpl_str("{{Test 2|b}}", "[[Template:b]]"); + } + @Test public void Colon_w_template() { // SUPPORT: page with colon_prefix should not add Template: PAGE:en.d:a; DATE:2016-06-24 + fxt.Init_defn_add("Test_3", "{{:Template:{{{1}}}}}"); + fxt.Test_parse_tmpl_str("{{Test 3|b}}", "[[:Template:b]]"); + } + @Test public void Toc() { // PURPOSE: __TOC__ in transcluded page should be ignored; PAGE:de.w:Game_of_Thrones DATE:2016-11-21 + fxt.Init_page_create("TranscludedToc", "__TOC__\na"); + fxt.Parser().Expand_tmpl(Bry_.new_u8("{{:TranscludedToc}}")); + Tfds.Eq(false, fxt.Page().Wtxt().Toc().Flag__toc()); // transcluded page is true, but current page should still be false + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_prm_tkn_tst.java b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_prm_tkn_tst.java new file mode 100644 index 000000000..424375851 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/tmpls/Xot_prm_tkn_tst.java @@ -0,0 +1,55 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xot_prm_tkn_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Idx_1() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{test|a|b}}" , "a");} + @Test public void Idx_2() {fxt.Test_parse_tmpl_str_test("{{{2}}}" , "{{test|a|b}}" , "b");} + @Test public void Idx_3_nil() {fxt.Test_parse_tmpl_str_test("{{{3}}}" , "{{test|a|b}}" , "{{{3}}}");} + @Test public void Idx_3_dflt() {fxt.Test_parse_tmpl_str_test("{{{3|c}}}" , "{{test|a|b}}" , "c");} + @Test public void Idx_3_dflt_len0() {fxt.Test_parse_tmpl_str_test("{{{1|}}}" , "{{test}}" , "");} + @Test public void Idx_1_and_2() {fxt.Test_parse_tmpl_str_test("({{{1}}} {{{2}}})" , "{{test|a|b}}" , "(a b)");} + @Test public void Idx_2_len0() {fxt.Test_parse_tmpl_str_test("{{{1}}}" , "{{test||b}}" , "");}// should not fail + @Test public void Key() {fxt.Test_parse_tmpl_str_test("{{{k1}}}" , "{{test|k1=a|k2=b}}" , "a");} + @Test public void Key_nil() {fxt.Test_parse_tmpl_str_test("{{{k3|c}}}" , "{{test|k1=a|k2=b}}" , "c");} + @Test public void Key_exact() {fxt.Test_parse_tmpl_str_test("{{{k|}}}{{{k2|}}}" , "{{test|k=a}}" , "a");} // only {{{k}}} matched + @Test public void Var() {fxt.Test_parse_tmpl_str_test("{{{1|-{{PAGENAME}}-}}}" , "{{test}}" , "-Test page-");} + @Test public void Newline_bgn() {fxt.Test_parse_tmpl_str_test("{{{1}}} {{{2}}}" , "{{test|a|\nb}}" , "a \nb");} + @Test public void Newline_end() {fxt.Test_parse_tmpl_str_test("{{{1}}} {{{2}}}" , "{{test|a|b\n}}" , "a b\n");} + @Test public void Exc_lkp_nil() {fxt.Test_parse_tmpl_str_test("{{{}}}" , "{{test|a|b}}" , "{{{}}}");} + @Test public void Exc_lkp_and_args1() {fxt.Test_parse_tmpl_str_test("{{{|}}}" , "{{test|a|b}}" , "");} + @Test public void Exc_lkp_nil_args1_txt() {fxt.Test_parse_tmpl_str_test("{{{|a}}}" , "{{test|a|b}}" , "a");} + @Test public void Ws_idx() {fxt.Test_parse_tmpl_str_test("{{{ 1 }}}" , "{{test|a|b}}" , "a");} + @Test public void Ws_idx_nil() {fxt.Test_parse_tmpl_str_test("{{{ 1 }}}" , "{{test}}" , "{{{ 1 }}}");} + @Test public void Ws_key() {fxt.Test_parse_tmpl_str_test("{{{ k1 }}}" , "{{test|k1=a|k2=b}}" , "a");} + @Test public void Ws_dflt() {fxt.Test_parse_tmpl_str_test("{{{1| a }}}" , "{{test}}" , " a ");} + @Test public void Dflt_multiple() {fxt.Test_parse_tmpl_str_test("{{{1|a|b}}}" , "{{test}}" , "a");} + @Test public void Keyd_not_idxd() {fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|a|key=b}}" , "a{{{2}}}");} + @Test public void Keyd_not_idxd_ints() {fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|1=a|2=b}}" , "ab");} + @Test public void Recurse_1() {fxt.Test_parse_tmpl_str_test("{{{1{{{2|}}}|}}}" , "{{test|a}}" , "a");} // used in {{See}} to test if argument 2 is last + @Test public void Recurse_2() {fxt.Test_parse_tmpl_str_test("{{{1{{{2|}}}|}}}" , "{{test|a|b}}" , "");} + @Test public void Keyd_int() {fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|2=a|b}}" , "ba");} + @Test public void Keyd_int2() {fxt.Test_parse_tmpl_str_test("{{{1}}}{{{2}}}" , "{{test|2=a|1=b}}" , "ba");} + @Test public void Keyd_int3() {fxt.Test_parse_tmpl_str_test("{{{12}}}" , "{{test|12=a}}" , "a");} + @Test public void Equal_ignored() {fxt.Test_parse_tmpl_str_test("{{{1|b=c}}}" , "{{test}}" , "b=c");} + @Test public void Unresolved() {fxt.Test_parse_tmpl_str_test("" , "{{{a|b}}}" , "b");} + @Test public void Six_ltr() {fxt.Test_parse_tmpl_str_test("{{{{{{1}}}}}}" , "{{test|a}}" , "{{{a}}}");} + @Test public void Six_num() {fxt.Test_parse_tmpl_str_test("{{{{{{1}}}}}}" , "{{test|1}}" , "1");} +} +/* +*/ diff --git a/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__parse__tst.java b/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__parse__tst.java new file mode 100644 index 000000000..af033a38f --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__parse__tst.java @@ -0,0 +1,26 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.uniqs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_uniq_mgr__parse__tst { + private final Xop_fxt fxt = Xop_fxt.New_app_html(); + @Before public void init() {fxt.Reset();} + @Test public void Ref_becomes_UNIQ() { + String wikitext = "b"; + fxt.Init_defn_add("test", "{{#ifeq:{{{1}}}|a" + wikitext + "c|fail|pass}}"); // fail if {{{1}}} is still wikitext; should be UNIQ + fxt.Test__parse__tmpl_to_html("{{test|a" + wikitext + "c}}", "pass"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__tst.java b/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__tst.java new file mode 100644 index 000000000..4f5ae25d4 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/uniqs/Xop_uniq_mgr__tst.java @@ -0,0 +1,79 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.uniqs; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.tests.*; +public class Xop_uniq_mgr__tst { + private final Xop_uniq_mgr__fxt fxt = new Xop_uniq_mgr__fxt(); + @Before public void init() {fxt.Init();} + @Test public void Test__random_bry() { + fxt.Init_random_int_ary(Int_ary_.New(240563374, 22728940, 1451248133)); + fxt.Test__uniq_bry_new("'\"`UNIQ-E56B4AE15AD0EC68"); + + fxt.Init_random_int_ary(Int_ary_.New(1363621437, 426295411, 421041101)); + fxt.Test__uniq_bry_new("'\"`UNIQ-147363D968C07391"); + } + @Test public void Add_and_get() { + String expd_key = "'\"`UNIQ--item-0-QINU`\"'"; + fxt.Test__add("a", expd_key); + fxt.Test__get(expd_key, "a"); + } + @Test public void Parse__basic() { + String expd_key = "'\"`UNIQ--item-0-QINU`\"'"; + fxt.Test__add("_b_", expd_key); + fxt.Test__parse("a" + expd_key + "c", "a_b_c"); + } + @Test public void Parse__recurse() { + String key_0 = "'\"`UNIQ--item-0-QINU`\"'"; + String key_1 = "'\"`UNIQ--item-1-QINU`\"'"; + String key_2 = "'\"`UNIQ--item-2-QINU`\"'"; + fxt.Test__add("0", key_0); + fxt.Test__add("1-" + key_0 + "-1", key_1); + fxt.Test__add("2-" + key_1 + "-2", key_2); + fxt.Test__parse("3-" + key_2 + "-3", "3-2-1-0-1-2-3"); + } + @Test public void Convert() { + String key = "'\"`UNIQ--item-0-QINU`\"'"; + fxt.Test__add("2", key); + fxt.Test__convert("1" + key + "3", "123"); + } + @Test public void Convert__many() { + String key_0 = "'\"`UNIQ--item-0-QINU`\"'"; + String key_1 = "'\"`UNIQ--item-1-QINU`\"'"; + fxt.Test__add("0", key_0); + fxt.Test__add("1", key_1); + fxt.Test__convert("a " + key_0 + " b " + key_1 + " c", "a 0 b 1 c"); + } +} +class Xop_uniq_mgr__fxt { + private final Xop_uniq_mgr mgr = new Xop_uniq_mgr(); + public Xop_uniq_mgr__fxt Init_random_int_ary(int... v) {mgr.Random_int_ary_(v); return this;} + public void Init() {mgr.Clear();} + public void Test__uniq_bry_new(String expd) { + Gftest.Eq__str(expd, String_.new_a7(mgr.Uniq_bry_new()), "unique_bry"); + } + public void Test__add(String raw, String expd) { + Gftest.Eq__str(expd, String_.new_a7(mgr.Add(Bool_.Y, Bry_.new_a7("item"), Bry_.new_a7(raw))), "add"); + } + public void Test__get(String key, String expd) { + Gftest.Eq__str(expd, String_.new_a7(mgr.Get(Bry_.new_a7(key))), "get"); + } + public void Test__parse(String raw, String expd) { + Gftest.Eq__str(expd, String_.new_a7(mgr.Parse(Bry_.new_a7(raw))), "parse"); + } + public void Test__convert(String raw, String expd) { + Gftest.Eq__str(expd, String_.new_a7(mgr.Parse(Bry_.new_a7(raw))), "convert"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/utils/TstObj_tst.java b/400_xowa/src/gplx/xowa/parsers/utils/TstObj_tst.java new file mode 100644 index 000000000..394dad529 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/utils/TstObj_tst.java @@ -0,0 +1,231 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.strings.*; import gplx.core.type_xtns.*; import gplx.core.stores.*; import gplx.core.envs.*; +interface TstRuleMgr { + boolean SkipChkVal(String expdTypeKey, TstAtr expd); + boolean SkipChkObj(String expdTypeKey, String atrKey, TstObj expd); +} +class Xop_rule_mgr implements TstRuleMgr { + public boolean SkipChkVal(String expdTypeKey, TstAtr expd) { + String key = expdTypeKey + "." + expd.Key(); + Xop_rule_dat ruleDat = (Xop_rule_dat)hash.Get_by(key); if (ruleDat == null) return false; + if (expd.ValType().Eq(expd.Val(), ruleDat.SkipVal())) return true; + return false; + } + public boolean SkipChkObj(String expdTypeKey, String atrKey, TstObj expd) { + String key = expdTypeKey + "." + atrKey; + Xop_rule_dat ruleDat = (Xop_rule_dat)hash.Get_by(key); if (ruleDat == null) return false; + TstAtr expdAtr = (TstAtr)expd.Atrs().Get_by(ruleDat.SubKey()); + if (expdAtr == null) return false; + if (expdAtr.ValType().Eq(expdAtr.Val(), ruleDat.SkipVal())) return true; + return false; + } + public Xop_rule_mgr TypeKey_(String v) {typeKey = v; return this;} private String typeKey; + public Xop_rule_mgr SkipIf_double(String atrKey, double v) {return SkipIfObj(atrKey, null, v);} + public Xop_rule_mgr SkipIf(String atrKey, String v) {return SkipIfObj(atrKey, null, v);} + public Xop_rule_mgr SkipIf(String atrKey, byte v) {return SkipIfObj(atrKey, null, v);} + public Xop_rule_mgr SkipIf(String atrKey, int v) {return SkipIfObj(atrKey, null, v);} + public Xop_rule_mgr SkipIf(String atrKey, boolean v) {return SkipIfObj(atrKey, null, v);} + public Xop_rule_mgr SkipIf(String atrKey, String subKey, Object o) {return SkipIfObj(atrKey, subKey, o);} + public Xop_rule_mgr SkipIfObj_many(String[] atrKeys, String subKey, Object o) {for (String atrKey : atrKeys) SkipIfObj(atrKey, subKey, o); return this;} + Xop_rule_mgr SkipIfObj(String atrKey, String subKey, Object skipVal) { + String key = typeKey + "." + atrKey; + Xop_rule_dat ruleDat = new Xop_rule_dat(key, subKey, skipVal); + hash.Add(key, ruleDat); + return this; + } + public String Reg() {return typeKey;} + Ordered_hash hash = Ordered_hash_.New(); + public static final Xop_rule_mgr Instance = new Xop_rule_mgr(); +} +class Xop_rule_dat { + public String AtrKey() {return atrKey;} private String atrKey; + public String SubKey() {return subKey;} private String subKey; + public Object SkipVal() {return skipVal;} Object skipVal; + public Xop_rule_dat(String atrKey, String subKey, Object skipVal) {this.atrKey = atrKey; this.subKey = subKey; this.skipVal = skipVal;} +} +public class TstObj_tst { + @Test public void Basic() { + tst_(mock_().Val1_(1).Val2_("a"), mock_().Val1_(1).Val2_("a")); +// tst_(mock_().Val1_(3).Val2_("a"), mock_().Val1_(1).Val2_("b")); + } + MockObj mock_() {return new MockObj();} + private void tst_(MockObj expd, MockObj actl) { + TstObj expdChk = TstObj.new_(), actlChk = TstObj.new_(); + expd.SrlObj_Srl(expdChk); + actl.SrlObj_Srl(actlChk); + Eval("", expdChk, actlChk, new Xop_rule_mgr()); + } + private static void Max(int[] ary, int idx, String val) { + int len = String_.Len(val); + if (len > ary[idx]) ary[idx] = len; + } + private static int Add(int[] ary) {int rv = 0; for (int i = 0; i < ary.length; i++) rv += ary[i]; return rv;} + @gplx.Internal protected static void Eval(String raw, TstObj expdChk, TstObj actlChk, TstRuleMgr ruleMgr) { + List_adp rslts = List_adp_.New(); + Eval(rslts, ruleMgr, Ordered_hash_.New(), "", expdChk, actlChk); + + String_bldr sb = String_bldr_.new_(); + sb.Add(raw).Add(Op_sys.Lnx.Nl_str()); + boolean pass = true; + int[] cols = new int[3]; + for (int i = 0; i < rslts.Count(); i++) { + TstRslt rslt = (TstRslt)rslts.Get_at(i); + Max(cols, 0, rslt.EvalStr()); + Max(cols, 1, rslt.Id()); + Max(cols, 2, rslt.Key()); + } + String hdr = String_.Repeat(" ", Add(cols) + 3); + for (int i = 0; i < rslts.Count(); i++) { + TstRslt rslt = (TstRslt)rslts.Get_at(i); +// if (rslt.EvalPass()) continue; + sb .Add(String_.PadEnd(rslt.EvalStr(), cols[0] + 1, " ")) + .Add(String_.PadEnd(rslt.Id(), cols[1] + 1, " ")) + .Add(String_.PadEnd(rslt.Key(), cols[2] + 1, " ")) + .Add(rslt.ExpdStr()).Add(Op_sys.Lnx.Nl_str()); + if (!rslt.EvalPass()) { + sb.Add(hdr).Add(rslt.ActlStr()).Add(Op_sys.Lnx.Nl_str()); + pass = false; + } + } + if (pass) return; + throw Err_.new_wo_type(Op_sys.Lnx.Nl_str() + sb.To_str()); + } + private static void Eval(List_adp rslts, TstRuleMgr ruleMgr, Ordered_hash props, String idx, TstObj expd, TstObj actl) { + int expdLen = expd.Atrs().Count(); + props.Clear(); + for (int i = 0; i < expdLen; i++) { + TstAtr expdAtr = (TstAtr)expd.Atrs().Get_at(i); + String key = expdAtr.Key(); + TstAtr actlAtr = (TstAtr)actl.Atrs().Get_by(key); + if (expdAtr.ValType() == ObjectClassXtn.Instance) { + SrlObj expdSrl = (SrlObj)expdAtr.Val(); + TstObj expdTst = TstObj.new_(); + expdSrl.SrlObj_Srl(expdTst); + TstObj actlTst = TstObj.new_(); + if (actlAtr != null) ((SrlObj)actlAtr.Val()).SrlObj_Srl(actlTst); + if (ruleMgr.SkipChkObj(expdAtr.TypeKey(), key, expdTst)) continue; + Eval(rslts, ruleMgr, Ordered_hash_.New(), idx + "." + key, expdTst, actlTst); + } + else { + if (actlAtr == null) actlAtr = new TstAtr(); + if (ruleMgr.SkipChkVal(expdAtr.TypeKey(), expdAtr)) continue; + Eval(rslts, idx, key, expdAtr, actlAtr, true); + } + props.Add(key, key); + } + int expdSubsLen = expd.Subs().Count(), actlSubsLen = actl.Subs().Count(); + int maxLen = expdSubsLen > actlSubsLen ? expdSubsLen : actlSubsLen; + for (int i = 0; i < maxLen; i++) { + TstObj expdSub = i < expdSubsLen ? (TstObj)expd.Subs().Get_at(i) : TstObj.Null; + TstObj actlSub = i < actlSubsLen ? (TstObj)actl.Subs().Get_at(i) : TstObj.Null; +// if (ruleMgr != null) ruleMgr.Eval(expd.TypeKey(), expdSub.PropName(), expdAtr, actlAtr, skip); + String iAsStr = Int_.To_str(i); + String subId = String_.Eq(idx, "") ? iAsStr : idx + "." + iAsStr; + if (expdSub == TstObj.Null && actlSub != TstObj.Null) { + TstAtr mis = new TstAtr().Key_("idx").Val_(i).ValType_(IntClassXtn.Instance); + rslts.Add(new TstRslt().Expd_(mis).Actl_(mis).EvalPass_(false).EvalStr_("!=") + .Id_(subId).Key_("sub_ref") + .ExpdStr_("null").ActlStr_("not null")); + continue; + } + Eval(rslts, ruleMgr, props, subId, expdSub, actlSub); + } + } + private static void Eval(List_adp rslts, String id, String key, TstAtr expd, TstAtr actl, boolean srcIsExpd) { + int evalType = 0; + boolean evalPass = false; String evalStr = ""; + switch (evalType) { + case 0: + if (expd.ValType().Eq(expd.Val(), actl.Val())) { + evalPass = true; + evalStr = "=="; + } + else { + evalPass = false; + evalStr = "!="; + } + break; + } + TstRslt rslt = new TstRslt().Expd_(expd).Actl_(actl) + .Id_(id).Key_(key) + .EvalType_(evalType).EvalPass_(evalPass).EvalStr_(evalStr) + .ExpdStr_(Object_.Xto_str_strict_or_null_mark(expd.Val())).ActlStr_(Object_.Xto_str_strict_or_null_mark(actl.Val())) + ; + rslts.Add(rslt); + } +} +class MockObj { + public int Val1() {return val1;} public MockObj Val1_(int v) {val1 = v; return this;} private int val1; + public String Val2() {return val2;} public MockObj Val2_(String v) {val2 = v; return this;} private String val2; + public void SrlObj_Srl(SrlMgr mgr) { + mgr.TypeKey_("MockObj"); + val1 = mgr.SrlIntOr("val1", val1); + val2 = mgr.SrlStrOr("val2", val2); + } +} +class TstObj implements SrlMgr { + public boolean Type_rdr() {return false;} + public Ordered_hash Atrs() {return atrs;} private Ordered_hash atrs = Ordered_hash_.New(); + public Object StoreRoot(SrlObj root, String key) {return null;} + public boolean SrlBoolOr(String key, boolean v) {Atrs_add(key, v, BoolClassXtn.Instance); return v;} + public byte SrlByteOr(String key, byte v) {Atrs_add(key, v, ByteClassXtn.Instance); return v;} + public int SrlIntOr(String key, int v) {Atrs_add(key, v, IntClassXtn.Instance); return v;} + public long SrlLongOr(String key, long v) {Atrs_add(key, v, LongClassXtn.Instance); return v;} + public String SrlStrOr(String key, String v) {Atrs_add(key, v, StringClassXtn.Instance); return v;} + public Decimal_adp SrlDecimalOr(String key, Decimal_adp v) {Atrs_add(key, v, DecimalAdpClassXtn.Instance); return v;} + public DateAdp SrlDateOr(String key, DateAdp v) {Atrs_add(key, v, DateAdpClassXtn.Instance); return v;} + public double SrlDoubleOr(String key, double v) {Atrs_add(key, v, DoubleClassXtn.Instance); return v;} + public Object SrlObjOr(String key, Object v) { + Atrs_add(key, v, ObjectClassXtn.Instance); + return v; + } + public void SrlList(String key, List_adp list, SrlObj proto, String itmKey) {} + public String TypeKey() {return typeKey;} public void TypeKey_(String v) {typeKey = v;} private String typeKey; + private void Atrs_add(String key, Object val, ClassXtn valType) { + atrs.Add(key, new TstAtr().TypeKey_(typeKey).Key_(key).Val_(val).ValType_(valType)); + } + public List_adp Subs() {return subs;} List_adp subs = List_adp_.Noop; + public SrlMgr SrlMgr_new(Object o) {return Subs_new();} + public TstObj Subs_new() { + if (subs == List_adp_.Noop) subs = List_adp_.New(); + TstObj rv = TstObj.new_(); + subs.Add(rv); + return rv; + } + public static TstObj new_() {return new TstObj();} TstObj() {} + public static final TstObj Null = new TstObj(); +} +class TstAtr { + public String TypeKey() {return typeKey;} public TstAtr TypeKey_(String v) {typeKey = v; return this;} private String typeKey; + public String Key() {return key;} public TstAtr Key_(String v) {key = v; return this;} private String key; + public Object Val() {return val;} public TstAtr Val_(Object v) {val = v; return this;} Object val; + public ClassXtn ValType() {return valType;} public TstAtr ValType_(ClassXtn v) {valType = v; return this;} ClassXtn valType; +} +class TstRslt { + public TstAtr Expd() {return expd;} public TstRslt Expd_(TstAtr v) {expd = v; return this;} TstAtr expd; + public TstAtr Actl() {return actl;} public TstRslt Actl_(TstAtr v) {actl = v; return this;} TstAtr actl; + public boolean Ignore() {return ignore;} public TstRslt Ignore_y_(boolean v) {ignore = v; return this;} private boolean ignore; + public int EvalType() {return evalType;} public TstRslt EvalType_(int v) {evalType = v; return this;} private int evalType; + public boolean EvalPass() {return evalPass;} public TstRslt EvalPass_(boolean v) {evalPass = v; return this;} private boolean evalPass; + public String EvalStr() {return evalStr;} public TstRslt EvalStr_(String v) {evalStr = v; return this;} private String evalStr; + public String Id() {return id;} public TstRslt Id_(String v) {id = v; return this;} private String id; + public String Key() {return key;} public TstRslt Key_(String v) {key = v; return this;} private String key; + public String ActlStr() {return actlStr;} public TstRslt ActlStr_(String v) {actlStr = v; return this;} private String actlStr; + public String ExpdStr() {return expdStr;} public TstRslt ExpdStr_(String v) {expdStr = v; return this;} private String expdStr; + public static final Object Ignore_null = new Object(); +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr_tst.java b/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr_tst.java new file mode 100644 index 000000000..cda2c374a --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/utils/Xop_redirect_mgr_tst.java @@ -0,0 +1,84 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.parsers.tmpls.*; +public class Xop_redirect_mgr_tst { + @Before public void init() {fxt.Clear();} private Xop_redirect_mgr_fxt fxt = new Xop_redirect_mgr_fxt(); + @Test public void Basic() {fxt.Test_redirect("#REDIRECT [[a]]", "A");} + @Test public void Basic_colon() {fxt.Test_redirect("#REDIRECT:[[a]]", "A");} + @Test public void Ns_help() {fxt.Test_redirect("#REDIRECT [[Help:a]]", "Help:A");} + @Test public void First() {fxt.Test_redirect("#REDIRECT [[a]] [[b]]", "A");} + @Test public void Exc_false_match() {fxt.Test_redirect("#REDIRECTA [[a]]", "");} + @Test public void Exc_lnki_not_found() {fxt.Test_redirect("#REDIRECT test", "");} + @Test public void Ws() {fxt.Test_redirect("\n#REDIRECT [[a]]", "A");} // PAGE:en.w:Germany; {{Template group}} -> \n#REDIRECT [[Template:Navboxes]] + @Test public void U8() { + fxt.Init_u8(); + fxt.Init_kwds(Bool_.N, "#REDIRECT", "#перенаправление"); + fxt.Test_redirect("#REDIRECT [[A]]", "A"); + fxt.Test_redirect("#reDirect [[A]]", "A"); + fxt.Test_redirect("#перенаправление [[A]]", "A"); + fxt.Test_redirect("#ПЕРЕНАПРАВЛЕНИЕ [[A]]", "A"); + } + @Test public void Url_decode() {fxt.Test_redirect("#REDIRECT [[A%28B%29]]" , "A(B)");} // PURPOSE: url-decode links; PAGE:en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18 + @Test public void Url_decode_plus() {fxt.Test_redirect("#REDIRECT [[A%28B%29+]]", "A(B)+");} // PURPOSE: do not url-decode +; PAGE:en.w:Template:Positionskarte+; DATE:2014-08-22 + @Test public void Amp() {fxt.Test_redirect("#REDIRECT [[A & B]]", "A & B");} // PURPOSE: & -> &; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23 + @Test public void Frame_ttl() { // PURPOSE: redirect should set invk frame title to redirect_trg, not original; PAGE:en.w:Statutory_city DATE:2014-08-22 + fxt.Test_frame_ttl("Template:A", "#REDIRECT [[Template:B]]", "Template:B", "Template:B"); + } + @Test public void State_collapsed() { // PURPOSE: state=collapsed broke redirects; PAGE:da.w:Middelaldercentret; DATE:2015-11-06 + fxt.Test_redirect("#REDIRECT [[Template:A|state=collapsed]]", "Template:A"); + } + @Test public void Parse_1st_link_only() { // PURPOSE: do not take pipe from 2nd lnki; PAGE:en.w:Template:pp-semi; DATE:2015-11-14 + fxt.Test_redirect("#REDIRECT [[Template:A]][[Category:B|b]]", "Template:A"); + } + @Test public void Redirected_html() { // PURPOSE: "Redirected from" message was using "_" instead of " "; PAGE:en.w:Summer_Solstice; DATE:2015-12-29 + fxt.Test__redirected_html("A_B", "(Redirected from A B)"); + } +} +class Xop_redirect_mgr_fxt { + private final Xop_fxt fxt = new Xop_fxt(); + public void Clear() { + fxt.Reset(); + } + public void Init_kwds(boolean case_match, String... kwds) {fxt.Init_lang_kwds(Xol_kwd_grp_.Id_redirect, case_match, kwds);} + public void Init_u8() { + fxt.Wiki().Lang().Case_mgr_u8_(); + } + public void Test_frame_ttl(String tmpl_ttl_str, String tmpl_wtxt_str, String redirect_ttl, String expd_frame_ttl) { + fxt.Init_page_create(tmpl_ttl_str, tmpl_wtxt_str); // create redirect_src + fxt.Init_page_create(redirect_ttl, "test"); // create redirect_trg + fxt.Test_parse_page_tmpl_tkn("{{" + tmpl_ttl_str + "}}"); // parse {{redirect_src}} + Xoa_ttl tmpl_ttl = Xoa_ttl.Parse(fxt.Wiki(), Bry_.new_u8(tmpl_ttl_str)); + Xot_defn_tmpl defn_tmpl = (Xot_defn_tmpl)fxt.Wiki().Cache_mgr().Defn_cache().Get_by_key(tmpl_ttl.Page_db()); // get defn (which parse should have created) + Tfds.Eq(expd_frame_ttl, String_.new_u8(defn_tmpl.Frame_ttl())); // check frame_ttl + } + public void Test_redirect(String raw_str, String expd_str) { + Xop_redirect_mgr redirect_mgr = fxt.Ctx().Wiki().Redirect_mgr(); + redirect_mgr.Clear(); + byte[] raw_bry = Bry_.new_u8(raw_str); + Xoa_ttl actl_ttl = redirect_mgr.Extract_redirect(raw_bry); + byte[] actl_bry = actl_ttl == null ? Bry_.Empty : actl_ttl.Full_txt_w_ttl_case(); + Tfds.Eq(expd_str, String_.new_u8(actl_bry)); + } + public void Test__redirected_html(String page_str, String expd_str) { + gplx.xowa.wikis.pages.redirects.Xopg_redirect_mgr redirect_mgr = new gplx.xowa.wikis.pages.redirects.Xopg_redirect_mgr(); + Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(page_str)); + Xoa_url url = Xoa_url.New(fxt.Wiki(), ttl); + redirect_mgr.Itms__add__article(url, ttl, Bry_.Empty); + byte[] actl_bry = Xop_redirect_mgr.Bld_redirect_msg(fxt.App(), fxt.Wiki(), redirect_mgr); + Tfds.Eq_str(expd_str, String_.new_u8(actl_bry)); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/utils/Xop_sanitizer_tst.java b/400_xowa/src/gplx/xowa/parsers/utils/Xop_sanitizer_tst.java new file mode 100644 index 000000000..fcb941895 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/utils/Xop_sanitizer_tst.java @@ -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.parsers.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.core.log_msgs.*; import gplx.xowa.parsers.amps.*; +public class Xop_sanitizer_tst { + Xop_sanitizer_fxt fxt = new Xop_sanitizer_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Space() {fxt.tst_Escape_id("a b" , "a_b");} + @Test public void Colon() {fxt.tst_Escape_id("a%3Ab" , "a:b");} + @Test public void Percent() {fxt.tst_Escape_id("a%b" , "a%b");} + @Test public void Amp_eos() {fxt.tst_Escape_id("a&" , "a&");} + @Test public void Amp_unrecognized() {fxt.tst_Escape_id("a&bcd" , "a&bcd");} + @Test public void Amp_name() {fxt.tst_Escape_id("a<b" , "ahkhk", "cncncn"); + } + @Test public void Attribs() { + fxt.Test_parse(rule + "hk", "cn"); + } + @Test public void Attribs__title() { + fxt.Test_parse(rule + "hk", "cn"); + } + @Test public void Attribs__alt() { + fxt.Test_parse(rule + "hk", "cn"); + } + @Test public void Attribs__alt_w_embedded_vnt() { // PURPOSE: handle embedded variants inside attribute tags; PAGE:sr.n:Проглашени_победници_„Вики_воли_Земљу" DATE:2015-10-13 + fxt.Test_parse(rule + "hk-{hk}-hk", "cnhkcn"); + } + @Test public void Attribs__skip_url() { + fxt.Test_parse(rule + "hk", "cn"); + } + @Test public void Node__script() { + fxt.Test_parse(rule + "hkhk", "cncn"); + } + @Test public void Node__code() { + fxt.Test_parse(rule + "hkhkhk", "cnhkcn"); + } + @Test public void Node__pre() { + fxt.Test_parse(rule + "hk
      hk
      hk", "cn
      hk
      cn"); + } + @Test public void Node__pre__nested() { + fxt.Test_parse(rule + "hk
      hk
      hk", "cn
      hk
      cn"); + } + @Test public void Recursive__deep() { + fxt.Test_parse("a-{b-{c-{d}-e}-f}-g", "abcdefg"); + } + @Test public void Recursive__many() { + fxt.Test_parse("a-{b-{c}-d-{e}-f}-g", "abcdefg"); + } + @Test public void Recursive__unclosed() { + fxt.Test_parse("a-{b-{c", "a-{b-{c"); + } + @Test public void Recursive__unclosed_2() { + fxt.Test_parse("a-{b-{c}-", "a-{bc"); + } + @Test public void Recursive__failed() { // PURPOSE: handle out of bounds exception; PAGE:zh.w:重庆市 ;DATE:2015-10-01 + fxt.Test_parse("-{zh-cn:a-{b}-c; zh-tw:d-{e}-f; }-", "abc"); + } + @Test public void Unclosed() { + fxt.Test_parse("a-{bc", "a-{bc"); + } + @Test public void Entity__body() { + fxt.Test_parse("-{H|zh-cn:nbsp-cn;zh-hk:nbsp;}-" + " nbsp", " nbsp-cn"); + } + @Test public void Entity__atr() { + fxt.Test_parse("-{H|zh-cn:nbsp-cn;zh-hk:nbsp;}-" + "
      " , "
      "); + } + @Test public void Node__example() { + fxt.Test_parse(rule + String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|A
      " + , "|B
      " + , "-{zh-hans:C;zh-hant:D;}-" + , "|}") + , String_.Concat_lines_nl_skip_last + ( "{|" + , "|-" + , "|A
      " + , "|B
      " + , "C" + , "|}" + )); + } + @Test public void Attribs__title__w_vnt() { + fxt.Init_cur("zh-tw"); + fxt.Test_parse("cn", "cn"); // cn not converted to hk + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang__syntax__tst.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang__syntax__tst.java new file mode 100644 index 000000000..8a05fd733 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang__syntax__tst.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*; +public class Vnt_convert_lang__syntax__tst { // REF: https://www.mediawiki.org/wiki/Writing_systems/Syntax + private final Vnt_convert_lang_fxt fxt = new Vnt_convert_lang_fxt(); + @Test public void Bidi() { + String text = "-{zh-hans:a;zh-hant:b}-"; + fxt.Test_parse_many(text, "a", "zh-hans", "zh-cn", "zh-sg", "zh"); + fxt.Test_parse_many(text, "b", "zh-hant", "zh-hk", "zh-tw"); + } + @Test public void Undi() { + String text = "-{H|cn_k=>zh-cn:cn_v}-cn_k"; + fxt.Test_parse_many(text, "cn_k", "zh", "zh-hans", "zh-hant", "zh-hk", "zh-my", "zh-mo", "zh-sg", "zh-tw"); + fxt.Test_parse_many(text, "cn_v", "zh-cn"); + } + @Test public void Raw() { + fxt.Test_parse_many("-{a}-", "a", "zh-hans", "zh-cn", "zh-sg", "zh", "zh-hant", "zh-hk", "zh-tw"); + fxt.Test_parse_many("-{R|a}-", "a", "zh-hans", "zh-cn", "zh-sg", "zh", "zh-hant", "zh-hk", "zh-tw"); + } + @Test public void Hide() { + String text = "-{H|zh-cn:cn;zh-hk:hk;zh-tw:tw}-cn hk tw"; + fxt.Test_parse_many(text, "cn cn cn", "zh-cn", "zh-sg"); + fxt.Test_parse_many(text, "hk hk hk", "zh-hk"); + fxt.Test_parse_many(text, "tw tw tw", "zh-tw"); + fxt.Test_parse_many(text, "cn hk tw", "zh", "zh-hans", "zh-hant"); + } + @Test public void Aout() { + String text = "-{A|zh-cn:cn;zh-hk:hk;zh-tw:tw}- cn hk tw"; + fxt.Test_parse_many(text, "cn cn cn cn", "zh-cn", "zh-sg"); + fxt.Test_parse_many(text, "hk hk hk hk", "zh-hk"); + fxt.Test_parse_many(text, "tw tw tw tw", "zh-tw"); + fxt.Test_parse_many(text, "cn cn hk tw", "zh", "zh-hans"); + fxt.Test_parse_many(text, "tw cn hk tw", "zh-hant"); + fxt.Test_parse_many("h-{}-k", "hk", "zh-cn"); // semi-disabled + } + @Test public void Del() { + String text = "-{H|zh-cn:cn;zh-hk:hk;zh-tw:tw}-cn hk tw-{-|zh-cn:cn;zh-hk:hk;zh-tw:tw}- cn hk tw"; + fxt.Test_parse_many(text, "cn cn cn cn hk tw", "zh-cn", "zh-sg"); + fxt.Test_parse_many(text, "hk hk hk cn hk tw", "zh-hk"); + fxt.Test_parse_many(text, "tw tw tw cn hk tw", "zh-tw"); + fxt.Test_parse_many(text, "cn hk tw cn hk tw", "zh", "zh-hans", "zh-hant"); + } + @Test public void Title() { + fxt.Test_parse_title("-{}-", null, "", "zh-cn"); + String text = "-{T|zh-cn:cn;zh-hk:hk;zh-tw:tw}-cn hk tw"; + fxt.Test_parse_title(text, "cn", "cn hk tw", "zh-cn"); + fxt.Test_parse_title(text, "cn", "cn hk tw", "zh-sg"); + fxt.Test_parse_title(text, "hk", "cn hk tw", "zh-hk"); + fxt.Test_parse_title(text, "tw", "cn hk tw", "zh-tw"); + fxt.Test_parse_title(text, "cn", "cn hk tw", "zh-hans"); + fxt.Test_parse_title(text, "tw", "cn hk tw", "zh-hant"); + fxt.Test_parse_title(text, null, "cn hk tw", "zh"); + } + @Test public void Descrip() { + String text = "-{D|zh-cn:cn;zh-hk:hk;zh-tw:tw}-"; + fxt.Test_parse_many(text, "ZH-CN:cn;ZH-HK:hk;ZH-TW:tw;", "zh", "zh-hans", "zh-hant", "zh-cn", "zh-hk", "zh-my", "zh-mo", "zh-sg", "zh-tw"); + } + @Test public void Mixture() { + String text = "-{H|zh-cn:cn;zh-hk:hk;zh-tw:tw}--{zh;zh-hans;zh-hant|cn hk tw}- -{zh;zh-cn;zh-hk;zh-tw|cn hk tw}-"; + fxt.Test_parse_many(text, "cn hk tw cn cn cn", "zh-cn", "zh-sg", "zh-hans"); + fxt.Test_parse_many(text, "cn hk tw hk hk hk", "zh-hk"); + fxt.Test_parse_many(text, "cn hk tw tw tw tw", "zh-tw", "zh-hant"); + fxt.Test_parse_many(text, "cn hk tw cn hk tw", "zh"); + } + @Test public void Descrip__undi() {fxt.Test_parse("-{D|cn_k=>zh-cn:cn_v;hk_k=>zh-hk:hk_v}-", "cn_k⇒ZH-CN:cn_v;hk_k⇒ZH-HK:hk_v;");} + @Test public void Descrip__mixd() {fxt.Test_parse("-{D|zh-tw:tw_v;cn_k=>zh-cn:cn_v;hk_k=>zh-hk:hk_v;zh-mo:mo_v}-", "ZH-TW:tw_v;ZH-MO:mo_v;cn_k⇒ZH-CN:cn_v;hk_k⇒ZH-HK:hk_v;");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang_fxt.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang_fxt.java new file mode 100644 index 000000000..9d526e4c5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_convert_lang_fxt.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*; +class Vnt_convert_lang_fxt { + private final Vnt_convert_lang converter_lang; + private final Xol_convert_mgr convert_mgr = new Xol_convert_mgr(); + private final Xol_vnt_regy vnt_regy = Xol_vnt_regy_fxt.new_chinese(); + private Xol_vnt_itm vnt_itm; + public Vnt_convert_lang_fxt() { + converter_lang = new Vnt_convert_lang(convert_mgr, vnt_regy); + this.Clear(); + } + public void Clear() { + convert_mgr.Init(vnt_regy); + Init_cur("zh-cn"); + } + public Vnt_convert_lang_fxt Init_cur(String vnt) { + byte[] cur_vnt = Bry_.new_a7(vnt); + this.vnt_itm = vnt_regy.Get_by(cur_vnt); + return this; + } + public void Test_parse(String raw, String expd) { + Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt_itm, -1, Bry_.new_u8(raw)))); + } + public void Test_parse_many(String raw, String expd, String... vnts) { + int len = vnts.length; + for (int i = 0; i < len; ++i) { + String vnt_key = vnts[i]; + Init_cur(vnt_key); + Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key)); + Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key); + } + } + public void Test_parse_title(String raw, String expd_title, String expd_text, String vnt_key) { + Init_cur(vnt_key); + Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key)); + Tfds.Eq_str(expd_text, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key); + Tfds.Eq_str(expd_title, converter_lang.Converted_title()); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser_tst.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser_tst.java new file mode 100644 index 000000000..0332b3ed2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_flag_parser_tst.java @@ -0,0 +1,54 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.langs.vnts.*; +public class Vnt_flag_parser_tst { + private final Vnt_flag_parser_fxt fxt = new Vnt_flag_parser_fxt(); + @Test public void Basic() {fxt.Test_parse("D" , "D");} + @Test public void Multiple() {fxt.Test_parse("+;S;E" , "+;S;E");} + @Test public void Ws() {fxt.Test_parse(" + ; S ; E " , "+;S;E");} + @Test public void None() {fxt.Test_parse("" , "S");} + @Test public void Wrong() {fxt.Test_parse("XYZ" , "S");} + @Test public void Raw__limit() {fxt.Test_parse("R;S" , "R");} + @Test public void Name__limit() {fxt.Test_parse("N;S" , "N");} + @Test public void Del_limit() {fxt.Test_parse("-;S" , "-");} + @Test public void Title__also_macro_y() {fxt.Test_parse("T" , "H;T");} + @Test public void Title__also_macro_n() {fxt.Test_parse("T;S" , "S;T");} + @Test public void Hide__remove_all() {fxt.Test_parse("H;S" , "+;H");} + @Test public void Hide__keep_descrip() {fxt.Test_parse("H;S;D" , "+;H;D");} + @Test public void Hide__keep_title() {fxt.Test_parse("H;S;T" , "+;H;T");} + @Test public void Aout__also_show_all() {fxt.Test_parse("A" , "+;A;S");} + @Test public void Descrip__remove_show() {fxt.Test_parse("D;S" , "D");} + @Test public void Aout_w_descrip() {fxt.Test_parse("A;D;S" , "+;A;D");} + @Test public void Lang__one() {fxt.Test_parse("zh-hans" , "S;zh-hans");} + @Test public void Lang__many() {fxt.Test_parse("zh-cn;zh-hk" , "S;zh-cn;zh-hk");} + @Test public void Lang__many__ws() {fxt.Test_parse(" zh-cn ; zh-hk " , "S;zh-cn;zh-hk");} + @Test public void Lang__many__dupe() {fxt.Test_parse("zh-cn;zh-cn" , "S;zh-cn");} + @Test public void Lang__zap__codes() {fxt.Test_parse("+;S;zh-hans;" , "zh-hans");} +} +class Vnt_flag_parser_fxt { + private final Vnt_flag_parser parser = new Vnt_flag_parser(); + private final Vnt_flag_code_mgr codes = new Vnt_flag_code_mgr(); private final Vnt_flag_lang_mgr langs = new Vnt_flag_lang_mgr(); + private final Xol_vnt_regy vnt_regy = Xol_vnt_regy_fxt.new_chinese(); + private final Bry_bfr bfr = Bry_bfr_.New(); + public void Test_parse(String raw, String expd) { + byte[] src = Bry_.new_u8(raw); + parser.Parse(codes, langs, vnt_regy, src, 0, src.length); + codes.To_bfr__dbg(bfr); + langs.To_bfr__dbg(bfr); + Tfds.Eq_str(expd, bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__bidi_tst.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__bidi_tst.java new file mode 100644 index 000000000..3bcee3248 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__bidi_tst.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Vnt_rule_parser__bidi_tst { + private final Vnt_rule_parser_fxt fxt = new Vnt_rule_parser_fxt(); + @Test public void Basic() {fxt.Test_parse("x1:v1;" , "x1:v1");} + @Test public void Ws() {fxt.Test_parse(" x1 : v1 ;" , "x1:v1");} + @Test public void Entity() {fxt.Test_parse("x1:a x2:b;x2:b;" , "x1:a x2:b" , "x2:b");} + @Test public void Unknown__nth() {fxt.Test_parse("x1:a;wx2:b;x2:b;" , "x1:a;wx2:b" , "x2:b");} + @Test public void Unknown__1st() {fxt.Test_parse("wx1:a;x1:b;" , "");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__undi_tst.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__undi_tst.java new file mode 100644 index 000000000..6fd73403e --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser__undi_tst.java @@ -0,0 +1,22 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Vnt_rule_parser__undi_tst { + private final Vnt_rule_parser_fxt fxt = new Vnt_rule_parser_fxt(); + @Test public void One() {fxt.Test_parse("k1=>x1:v1;" , "x1:k1=v1");} + @Test public void Many() {fxt.Test_parse("k1=>x1:v1;k2=>x2:v2;" , "x1:k1=v1", "x2:k2=v2");} +} diff --git a/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser_fxt.java b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser_fxt.java new file mode 100644 index 000000000..d8aca9683 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/vnts/Vnt_rule_parser_fxt.java @@ -0,0 +1,35 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import gplx.xowa.langs.vnts.*; +class Vnt_rule_parser_fxt { + private final Vnt_rule_parser parser = new Vnt_rule_parser(); private final Vnt_rule_undi_mgr undis = new Vnt_rule_undi_mgr(); private final Vnt_rule_bidi_mgr bidis = new Vnt_rule_bidi_mgr(); + private final Bry_bfr bfr = Bry_bfr_.New_w_size(255); + public Vnt_rule_parser_fxt() { + Xol_vnt_regy vnt_regy = new Xol_vnt_regy(); + vnt_regy.Add(Bry_.new_a7("x1"), Bry_.new_a7("lang1")); + vnt_regy.Add(Bry_.new_a7("x2"), Bry_.new_a7("lang2")); + vnt_regy.Add(Bry_.new_a7("x3"), Bry_.new_a7("lang3")); + parser.Init(null, vnt_regy); + } + public void Test_parse(String raw, String... expd_ary) { + byte[] src = Bry_.new_u8(raw); + parser.Clear(undis, bidis, src); + parser.Parse(src, 0, src.length); + parser.To_bry__dbg(bfr); + Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd_ary), bfr.To_str_and_clear()); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xatr_whitelist_mgr_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xatr_whitelist_mgr_tst.java new file mode 100644 index 000000000..9fb8408a0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xatr_whitelist_mgr_tst.java @@ -0,0 +1,73 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.htmls.*; +public class Xop_xatr_whitelist_mgr_tst { + private final Xop_xatr_whitelist_fxt fxt = new Xop_xatr_whitelist_fxt(); + @Before public void init() {fxt.Clear();} + @Test public void Basic() { + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "style" , true); + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "xstyle" , false); + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "stylex" , false); + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "styl" , false); + fxt.Whitelist(Xop_xnde_tag_.Tid__img , "alt" , true); + fxt.Whitelist(Xop_xnde_tag_.Tid__img , "span" , false); + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "data-sort-type" , true); + fxt.Whitelist(Xop_xnde_tag_.Tid__data , "value" , true); + fxt.Whitelist(Xop_xnde_tag_.Tid__data , "valuex" , false); + } + @Test public void Role() { + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "role" , "presentation", true); + fxt.Whitelist(Xop_xnde_tag_.Tid__div , "role" , "other", false); + } + @Test public void Scrub() { + fxt.Scrub_style_fail("expression"); + fxt.Scrub_style_fail("filter:a"); + fxt.Scrub_style_fail("filter\t \n:a"); + fxt.Scrub_style_fail("accelerator:a"); + fxt.Scrub_style_fail("url()"); + fxt.Scrub_style_fail("urls()"); + fxt.Scrub_style_pass("filterx"); + } +} +class Xop_xatr_whitelist_fxt { + private Xop_xatr_whitelist_mgr whitelist_mgr; + public void Clear() { + if (whitelist_mgr == null) whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini(); + } + public void Whitelist(int tag_id, String key_str, boolean expd) { + Mwh_atr_itm atr_itm = New_atr_itm(key_str, null); + Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, atr_itm), key_str); + } + public void Whitelist(int tag_id, String key_str, String val_str, boolean expd) { + Mwh_atr_itm atr_itm = New_atr_itm(key_str, val_str); + Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, atr_itm), key_str); + } + public void Scrub_style_pass(String style_val_str) {Scrub_style(style_val_str, style_val_str);} + public void Scrub_style_fail(String val_str) {Scrub_style(val_str, "");} + public void Scrub_style(String val_str, String expd) { + byte[] val_bry = Bry_.new_a7(val_str); + Mwh_atr_itm atr_itm = New_atr_itm(null, val_str); + whitelist_mgr.Scrub_style(atr_itm, val_bry); + Tfds.Eq(expd, String_.new_a7(atr_itm.Val_bry())); + } + private static Mwh_atr_itm New_atr_itm(String key_str, String val_str) { + byte[] key_bry = key_str == null ? null : Bry_.new_u8(key_str); + byte[] val_bry = val_str == null ? null : Bry_.new_u8(val_str); + Mwh_atr_itm rv = new Mwh_atr_itm(key_bry, false, false, false, -1, -1, -1, -1, key_bry, -1, -1, val_bry, -1, 0); + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__basic_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__basic_tst.java new file mode 100644 index 000000000..3dc3489cb --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__basic_tst.java @@ -0,0 +1,151 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.wikis.nss.*; +public class Xop_xnde_wkr__basic_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Escape_lt() { // PURPOSE: some templates have unknown tags; PAGE:en.w:PHP + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str("ab", String_.Concat_lines_nl_skip_last + ( "

      a<?b" + , "

      " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Inline() { + fxt.Test_parse_page_wiki("" , fxt.tkn_xnde_(0, 6).CloseMode_(Xop_xnde_tkn.CloseMode_inline).Name_rng_(1, 4)); + } + @Test public void Pair() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 11).CloseMode_(Xop_xnde_tkn.CloseMode_pair).Name_rng_(1, 4)); + } + @Test public void Pair_text() { + fxt.Test_parse_page_wiki("
      b
      ", fxt.tkn_xnde_(0, 12).Subs_(fxt.tkn_txt_(5, 6))); + } + @Test public void Deep1_pair1() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 22).Name_rng_(1, 4) + .Subs_(fxt.tkn_xnde_(5, 16).Name_rng_(6, 9))); + } + @Test public void Deep1_inline1() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 17).Name_rng_(1, 4) + .Subs_(fxt.tkn_xnde_(5, 11).Name_rng_(6, 9)) ); + } + @Test public void Deep1_pair2() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 33).Name_rng_(1, 4) + .Subs_ + ( fxt.tkn_xnde_( 5, 16).Name_rng_( 6, 9) + , fxt.tkn_xnde_(16, 27).Name_rng_(17, 20) + )); + } + @Test public void Deep2_pair1() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 33).Name_rng_(1, 4) + .Subs_ + ( fxt.tkn_xnde_( 5, 27).Name_rng_( 6, 9) + .Subs_ + ( fxt.tkn_xnde_(10, 21).Name_rng_(11, 14)) + )); + } + @Test public void Slash() {// b/c mw allows unquoted attributes + fxt.Test_parse_page_wiki("a", fxt.tkn_xnde_(0, 15).Atrs_rng_(5, 7).Subs_(fxt.tkn_txt_(8, 9))); + fxt.Test_parse_page_wiki("", fxt.tkn_xnde_(0, 15).Atrs_rng_(5, 13)); + } + @Test public void Escaped() { + fxt.Init_log_(Xop_xnde_log.Escaped_xnde).Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 18).Subs_(fxt.tkn_bry_(5, 12)));// TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + } + @Test public void Xtn() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 18).Subs_(fxt.tkn_txt_(6, 11))); // NOTE: no dangling nde b/c .Xtn skips + } + @Test public void Xtn_ref() { + fxt.Test_parse_page_wiki("b", fxt.tkn_xnde_(0, 21).Name_rng_(1, 4).Atrs_rng_(5, 13).Subs_(fxt.tkn_txt_(14, 15))); + } + @Test public void Lnki() { + fxt.Test_parse_page_wiki("[[Image:a|b
      d]]" + , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Tid__file).Trg_tkn_(fxt.tkn_arg_nde_().Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9)))) + .Caption_tkn_(fxt.tkn_arg_nde_(10, 17).Val_tkn_(fxt.tkn_arg_itm_(fxt.tkn_txt_(10, 11), fxt.tkn_xnde_(11, 16), fxt.tkn_txt_(16, 17)))) + ); + } + @Test public void Br_converted_to_reguar_br() { + fxt.Test_parse_page_wiki("
      a" , fxt.tkn_xnde_(0, 5), fxt.tkn_txt_(5, 6)); + fxt.Test_parse_page_wiki("
      a" , fxt.tkn_xnde_(0, 5), fxt.tkn_txt_(5, 6)); + fxt.Test_parse_page_wiki("
      a" , fxt.tkn_xnde_(0, 6), fxt.tkn_txt_(6, 7)); + } + @Test public void CaseSensitivity() { + fxt.Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 11).CloseMode_(Xop_xnde_tkn.CloseMode_pair).Name_rng_(1, 4)); + } + @Test public void CaseSensitivity_xtn_1() { + fxt.Test_parse_page_wiki_str + ( "abc" + , "b" + ); + } + @Test public void CaseSensitivity_xtn_2() { // PURPOSE: xtn end_tag may not match bgn_tag; EX: w:Ehrenfest_paradox; + fxt.Test_parse_page_all_str("ac", String_.Concat_lines_nl + ( "a[1]
        " + , "
      1. ^ c
      2. " + , "
      " + )); + } + @Test public void CaseSensitivity_xtn_3() {// PURPOSE: xtn xnde must do case-insensitive match DATE:2013-12-02 + fxt.Test_parse_page_all_str + ( "a b c" // should match not + , "a b c" + ); + } + @Test public void Whitelist() { + fxt.Test_parse_page_all_str("", ""); + } + @Test public void Whitelist_pre() { // PURPOSE:
      a
      somehow becoming a
      ; Template:Infobox_country; ISSUE: old xatr code being triggered; PURPOSE:(2) style being stripped when it shouldn't be + fxt.Test_parse_page_all_str("
      a
      ", "
      a
      "); + } + @Test public void Whitelist_style() { + fxt.Test_parse_page_all_str("
      ", "
      "); + } + @Test public void Script() { // PURPOSE: nested script should (a) write attributes; (b) write close tag; DATE:2014-01-24 + fxt.Test_parse_page_all_str("", "<script src='a'>b</script>"); + } + @Test public void Script_in_syntaxhighlight() { + fxt.Test_parse_page_all_str("", "
      <script>alert('fail');</script>
      "); + } + @Test public void Html5_time() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted) + fxt.Test_parse_page_wiki_str("", ""); + } + @Test public void Html5_bdi() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted); DATE:2013-12-07 + fxt.Test_parse_page_wiki_str("a", "a"); + } + @Test public void Html5_mark() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted); DATE:2014-01-03 + fxt.Test_parse_page_wiki_str("a", "a"); + } + @Test public void Html5_mark_span() {// PURPOSE: should close tag; EX: zh.wikipedia.org/wiki/异体字; DATE:2014-01-03 + fxt.Test_parse_page_wiki_str("a", "a"); + } + @Test public void Html5_wbr() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted); DATE:2014-01-03 + fxt.Test_parse_page_wiki_str("abc", "abc"); + } + @Test public void Html5_bdo() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted); DATE:2014-01-03 + fxt.Test_parse_page_wiki_str("a", "a"); + } + @Test public void Pre_always_parsed() { // PURPOSE: pre should not interpret templates; DATE:2014-04-10 + fxt.Init_defn_clear(); + fxt.Init_defn_add("a", "a"); + fxt.Init_defn_add("test", "
      {{a}}
      "); + fxt.Test_parse_page_all_str("{{test}}", "
      {{a}}
      "); + fxt.Init_defn_clear(); + } + @Test public void Quote() {// PURPOSE: handle element; DATE:2015-05-29 + fxt.Test_parse_page_wiki_str("a", "a"); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__blockquote_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__blockquote_tst.java new file mode 100644 index 000000000..0fd5ba7ad --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__blockquote_tst.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__blockquote_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Pre() { // PURPOSE: preserve leading spaces within blockquote; PAGE:en.w:Tenerife_airport_disaster + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      " + , " a" + , "
      " + ), String_.Concat_lines_nl_skip_last + ( "
      " + , " a" + , "
      " + )); + fxt.Init_para_n_(); + } + @Test public void Trailing_nls() { // PURPOSE: para/pre not working after blockquote; PAGE:en.w:Snappy_(software); DATE:2014-04-25 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "
      a" + , "
      " + , "" + , "b" + , "" + , " c" + ), String_.Concat_lines_nl_skip_last + ( "
      a" + , "
      " + , "" + , "

      b" + , "

      " + , "" + , "
      c"
      +		, "
      " + )); + fxt.Init_para_n_(); + } + @Test public void Dangling_multiple() { // PURPOSE: handle multiple dangling; PAGE:en.w:Ring_a_Ring_o'_Roses DATE:2014-06-26 + fxt.Test_parse_page_wiki_str("
      a
      b", "
      a
      b
      "); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_dangling_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_dangling_tst.java new file mode 100644 index 000000000..fbf199589 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_dangling_tst.java @@ -0,0 +1,204 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; import gplx.xowa.parsers.lists.*; +public class Xop_xnde_wkr__err_dangling_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Basic() { + fxt.Init_log_(Xop_xnde_log.Dangling_xnde) + .Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 5)); + } + @Test public void Many() { + fxt.Init_log_(Xop_xnde_log.Dangling_xnde, Xop_xnde_log.Dangling_xnde, Xop_xnde_log.Dangling_xnde) + .Test_parse_page_wiki("
      ", fxt.tkn_xnde_(0, 15).Subs_(fxt.tkn_xnde_(5, 15).Subs_(fxt.tkn_xnde_(10, 15)))); + } + @Test public void Nested() { + fxt.Test_parse_page_wiki_str + ( "
      a
      " + , "
      a
      " + ); + } + @Test public void Center() { + fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("a
      b" + , fxt.tkn_txt_(0, 1) + , fxt.tkn_xnde_(1, 10).CloseMode_(Xop_xnde_tkn.CloseMode_open).Subs_(fxt.tkn_txt_(9, 10)) + ); + } + @Test public void P() { + fxt.Init_log_(Xop_xnde_log.Auto_closing_section).Test_parse_page_wiki("a

      b

      c

      " + , fxt.tkn_txt_ (0, 1) + , fxt.tkn_xnde_ (1, 4).Subs_(fxt.tkn_txt_(4, 5)) + , fxt.tkn_xnde_ (5, 13).Subs_(fxt.tkn_txt_(8, 9)) + ); + } + @Test public void Alternating() { // PURPOSE: confirmation test for alternating dangling nodes; PAGE:en.w:Portal:Pornography/Selected_historical_image/Archive; DATE:2014-09-24 + fxt.Test_parse_page_wiki_str + ( "cde" + , "cde" + ); + } + @Test public void Li() { // PURPOSE: auto-close
    • ; NOTE: no longer encloses in
        ; DATE:2014-06-26 + fxt.Test_parse_page_wiki_str + ( "
      • a
      • b" + , String_.Concat_lines_nl_skip_last + ( "
      • a
      • " + , "
      • b
      • " + )); + } + @Test public void Br() { + fxt.Test_parse_page_wiki("
        a" , fxt.tkn_xnde_(0, 4), fxt.tkn_txt_(4, 5)); + fxt.Test_parse_page_wiki("a
        c", fxt.tkn_txt_(0, 1), fxt.tkn_xnde_(1, 12), fxt.tkn_txt_(12, 13)); + } + @Test public void Td_and_td() { // PURPOSE: when "a", 2nd should auto-close + fxt.Test_parse_page_wiki("
        a
        b
        " + , fxt.tkn_tblw_tb_(0, 52).Subs_ + ( fxt.tkn_tblw_tr_(7, 25).Subs_ + ( fxt.tkn_tblw_td_(11, 16).Subs_(fxt.tkn_txt_(15, 16)) // FUTURE: change to 11,20 + , fxt.tkn_tblw_td_(16, 25) // FUTURE: change this to 16, 20 + ) + , fxt.tkn_tblw_tr_(25, 44).Subs_ + ( fxt.tkn_tblw_td_(29, 39).Subs_(fxt.tkn_txt_(33, 34)) + ) + ) + ); + } + @Test public void Tblw_and_tr() {// PURPOSE: should auto-close |-; EX:fr.wikipedia.org/wiki/Napoléon_Ier; DATE:2013-12-09 + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl + ( "{|" + , "|-" + , "row1" + , "row2" + , "|}" + ) + , String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
        row1" + , "
        row2" + , "
        " + ) + ); + } + @Test public void Tblx_and_b() { + fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("
        a
        " + , fxt.tkn_tblw_tb_(0, 36).Subs_ + ( fxt.tkn_tblw_tr_(7, 28).Subs_ + ( fxt.tkn_tblw_td_(11, 19).Subs_ // FUTURE: change to 11,23 + ( fxt.tkn_xnde_(15, 36).Subs_(fxt.tkn_txt_(18, 19)) // FUTURE: should be 19, but xnde.Close() is passing in src_len + ) + , fxt.tkn_tblw_td_(19, 28) // FUTURE: should be 23 + ) + ) + ); + } + @Test public void Tblx_and_li() { // PURPOSE: should close list; see Stamp Act 1765 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "
        " + , "*abc
        bcd
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
        " + , "" + , "
          " + , "
        • abc" + , "
        • " + , "
        " + , "
        bcd" + , "
        " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Tblx_and_small() { // PURPOSE: should close correctly; see Stamp Act 1765 + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "
        " + , "abc
        bcd
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
        " + , "abc" + , "
        bcd" + , "
        " + , "" + ) + ); + fxt.Init_para_n_(); + } + @Test public void Blockquote_and_p() { + fxt.Init_log_(Xop_xnde_log.Auto_closing_section).Test_parse_page_wiki("
        a

        b

        " + , fxt.tkn_xnde_(0, 30).Subs_ + ( fxt.tkn_txt_(12, 13) + , fxt.tkn_xnde_(13, 17).Subs_(fxt.tkn_txt_(16, 17)) + )); + } + @Test public void List_and_b() { + fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("*a\n*" + , fxt.tkn_list_bgn_(0, 1, Xop_list_tkn_.List_itmTyp_ul).List_path_(0) + , fxt.tkn_xnde_(1, 7).Subs_(fxt.tkn_txt_(4, 5)) + , fxt.tkn_list_end_(5).List_path_(0) + , fxt.tkn_list_bgn_(5, 7, Xop_list_tkn_.List_itmTyp_ul).List_path_(1) + , fxt.tkn_list_end_(7).List_path_(1) + ); + } + @Test public void Underline() { // PURPOSE: 2nd should auto-close; PAGE:en.b:Textbook_of_Psychiatry/Alcoholism_and_Psychoactive_Substance_Use_Disorders DATE:2014-09-05 + fxt.Test_html_full_str("abc", "abc"); + } + @Test public void Xtn_template() { // PURPOSE: dangling xtns within templates should be auto-closed inside template, not in calling page; PAGE:en.w:Provinces_and_territories_of_Canada DATE:2014-11-13 + fxt.Init_page_create("Template:A", "A"); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "{{A}}" + , " b" // poem should not extend to " b" + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "

        " + , "A" + , "

        " + , "
        " // poem ends here + , " b" + )); + } + @Test public void Section_inline() { // PURPOSE.FIX:do not output trailing '' after '' PAGE:en.w:National_Popular_Vote_Interstate_Compact DATE:2017-04-10 + fxt.Init_page_create("Template:Abc", "
        val
        "); + fxt.Test_parse_page_tmpl_str(String_.Concat_lines_nl_skip_last + ( "{{Abc}}" + ), String_.Concat_lines_nl_skip_last + ( "
        val
        " // fails if "
        val
        " + )); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_malformed_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_malformed_tst.java new file mode 100644 index 000000000..6043ba927 --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__err_malformed_tst.java @@ -0,0 +1,72 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__err_malformed_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @After public void term() {fxt.Init_para_n_();} + @Test public void Lt_only() { + fxt.Test_parse_page_wiki("<", fxt.tkn_txt_(0, 1)); + } + @Test public void Eos_while_closing_tag() { + fxt.Init_log_(Xop_xnde_log.Eos_while_closing_tag).Test_parse_page_wiki("

        ; DATE:2014-01-18 + fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki()); + fxt.Test_parse_page_all_str("

        ", String_.Concat_lines_nl_skip_last + ( "

        " + , "

        " // NOTE: technically MW / WP does not add this

        ; however, easier to hardcode

        ; no "visual" effect; DATE:2014-04-27 + , "

        </p<

        " + , "

        " + , "
        " + )); + } + @Test public void Incomplete_tag_div() { // PURPOSE: handle broken tags; EX:
        -> <div a; DATE:2014-02-03 + fxt.Test_parse_page_all_str("
        ", "<div a
        "); // note that "
        " is literally printed; // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + } + @Test public void Incomplete_tag_ref() {// PURPOSE: invalid tag shouldn't break parser; EX:w:Cullen_(surname); "http://www.surnamedb.com/Surname/Cullen to be ; EX: w:Exchange_value + fxt.Init_log_(Xop_xnde_log.No_inline); + fxt.Test_parse_page_all_str("", ""); + } + @Test public void Tblw() { // PURPOSE.fix: don't auto-close past tblw PAGE:ro.b:Pagina_principala DATE:2014-06-26 + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "
        " + , "{|" // this should stop xnde search + , "
        " + , "
        " // this should not find
        as its bgn_tag; note that it will "drop out" below + , "|}" + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "
        " + , "
        " // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + , "
        " + , " " + , " " + , "" + , "
        " + , "
        " + , "
        " + )); + } + @Test public void Incomplete_tag() { // PURPOSE: handle incomplete tag sequences; DATE:2014-10-22 + fxt.Test_parse_page_all_str("<", "<"); + fxt.Test_parse_page_all_str("" + , " " + , " a
        b" + , " " + , " " + , "" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        a
        b" + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Div_should_not_pop_past_td() { // PURPOSE: extra
        should not close
        that is outside of ; PAGE:en.w:Rome en.w:Ankara + fxt.Init_para_y_(); + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
        " + , "
        " // this is
        #1 + , "" + , "" + , "" + , "" + , "" + , "" + , "
        " + , "
        " // this is
        #2 + , "
        " + , "a" + , "
        " + , "
        " + , "
        " + , "b" + , "
        " + , "" // this was supposed to pop
        #2, but can't (b/c of HTML rules); however, do not try to pop
        #1; + , "
        " + , "
        " + , "c" + , "
        " + , "
        " + , "
        " + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        " + , "
        " + , " " + , " " + , " " + , " " + , " " + , " " + , "
        " + , "
        " + , "
        " + , "" + , "

        a" + , "

        " + , "
        " + , "
        " + , "
        " + , "
        " + , "" + , "

        b" + , "

        " + , "
        " + , "" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 + , "
        " + , "
        " + , "" + , "

        c" + , "

        " + , "
        " + , "
        " + , "
        " + , "
        " + , "" + )); + fxt.Init_para_n_(); + } + @Test public void Xnde_pops() { // PURPOSE: somehow xnde pops upper nde; PAGE:en.w:Greek government debt crisis; "History of government debt" + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "{|" + , "|-" + , "|a" + , "|}" + , "" + ), String_.Concat_lines_nl_skip_last + ( "" + , "" + , " " + , " " + , " " + , "
        a" + , "
        " + , "
        " + )); + } + @Test public void Err_inline_extension() { + fxt.Test_parse_page_all_str + ( "" + , "" + ); + } + @Test public void Xnde_para() { // PURPOSE: buggy code caused

        to close everything; keeping test b/c of

        logic + fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last + ( "" + , "" + , "" + , "" + , "
        " + , "
        " + , "

        " + , "" + , "" + , "

        " + , "
        " + , "
        " + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
        " + , "
        " + , "

        " + , "" + , "" + , "

        " + , "
        " + , "
        " + , "" + ) + ); + } + @Test public void Sup_bug() { // PURPOSE: occurred at ref of UK; a {{cite web|url=http://www.abc.gov/{{dead link|date=December 2011}}|title=UK}} b + fxt.Test_parse_page_wiki_str("x y z", "x y z"); + } + @Test public void Br_backslash() { // PURPOSE: allow ; EX:w:Mosquito; [[Acalyptratae|Acalyptratae]] + fxt.Test_parse_page_all_str("", "
        "); + } + @Test public void Tt_does_not_repeat() { // PURPOSE: handle a; EX:w:Domain name registry + fxt.Test_parse_page_all_str("a", "a"); + } + @Test public void Loose_xnde_names() { // PURPOSE: MW allows and other variations; EX:w:2012_in_film + fxt.Test_parse_page_all_str("a", "a"); + } + @Test public void Anchor_nested() { + fxt.Test_parse_page_all_str("bcd [[e]] f", "b<a>c<a>d e f"); + } + @Test public void Img_should_not_be_xtn() { // PURPOSE: marked as .xtn; unclosed was escaping rest of text; PAGE:de.w:Wikipedia:Technik/Archiv/2014 DATE:2014-11-06 + fxt.Test_parse_page_all_str("''a''", "<img>a"); + } + @Test public void Invalid__percent() { // PURPOSE: invalidate xml tags with %; EX:; PAGE:pl.w:Scynk_nadrzewny; DATE:2016-08-07 + fxt.Test_parse_page_all_str("a
        ", "<b%>a
        "); // NOTE: should be literally printed as , not transformed to + } + @Test public void Meta_link() { // PURPOSE: meta and link tags should not print; EX: ; PAGE:fr.s:La_Dispute; DATE:2017-05-28 + fxt.Test_parse_page_all_str("", ""); + } +} diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_basic_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_basic_tst.java new file mode 100644 index 000000000..0326a5c5e --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_basic_tst.java @@ -0,0 +1,81 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__include_basic_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Tmpl_includeonly() {fxt.Test_parse_tmpl_str_test("abc" , "{{test}}", "abc");} + @Test public void Tmpl_noinclude() {fxt.Test_parse_tmpl_str_test("abc" , "{{test}}", "ac");} + @Test public void Tmpl_onlyinclude() {fxt.Test_parse_tmpl_str_test("abc" , "{{test}}", "b");} + @Test public void Tmpl_onlyinclude_nest() {fxt.Test_parse_tmpl_str_test("{{#ifeq:y|y|abc|n}}" , "{{test}}", "b");} // PURPOSE: check that onlyinclude handles (a) inside {{#if}} function (old engine did not); and (b) that abc are correctly added together + @Test public void Tmpl_onlyinclude_page() {// PURPOSE: handle scenario similar to {{FA Number}} where # of articles is buried in page between onlyinclude tags; added noinclude as additional stress test + fxt.Init_page_create("Transclude_1", "abcd"); + fxt.Test_parse_tmpl_str_test("{{:Transclude_1}}" , "{{test}}", "b"); + } + @Test public void Tmpl_onlyinclude_page2() { // PURPOSE: handle scenario similar to PS3 wherein onlyinclude was being skipped (somewhat correctly) but following text (

        ) was also included
        +		fxt.Init_page_create("Transclude_2", "abcde
        f
        g"); + fxt.Test_parse_tmpl_str_test("{{:Transclude_2}}" , "{{test}}", "bcd"); + } + @Test public void Tmpl_noinclude_unmatched() { // PURPOSE.fix: ignore unmatched ; EX:fi.w:Sergio_Leone; DATE:2014-05-02 + fxt.Test_parse_tmpl_str_test("{{{1|}}}", "{{test|a}}", "a"); // was "{{{test|" + } + + @Test public void Wiki_includeonly() {fxt.Test_parse_page_all_str("abc" , "ac");} + @Test public void Wiki_noinclude() {fxt.Test_parse_page_all_str("abc" , "abc");} + @Test public void Wiki_onlyinclude() {fxt.Test_parse_page_all_str("abc" , "abc");} + @Test public void Wiki_oi_io() {fxt.Test_parse_page_all_str("abcde" , "abde");} + @Test public void Wiki_oi_io_tblw() { + fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last + ( "" + , "{|" + , "|-" + , "|a" + , "|}" + , "|-" + , "|b" + , "|}" + ), String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , " " + , " " + , " " + , "
        a" + , "
        b" + , "
        " + , "" + )); + } +} +/* +-({{{1}}}={{{1}}}round-5)-({{{1}}}={{{1}}}round-4)-({{{1}}}={{{1}}}round-3)-({{{1}}}={{{1}}}round-2)-({{{1}}}={{{1}}}round-1) +{{pp-template}}Called by {{lt|precision/0}} + +==includeonly -- aka: do not eval in template == +main: abc
        +tmpl: {{mwo_include_only|a|b|c}} + +==noinclude -- aka: eval in template only== +main: abc
        +tmpl: {{mwo_no_include|a|b|c}} + +==onlyinclude -- aka: only include in template only (ignore everything else) == +main: abc
        +tmpl: {{mwo_only_include|a|b|c}} +*/ \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_uncommon_tst.java b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_uncommon_tst.java new file mode 100644 index 000000000..2c4ea782c --- /dev/null +++ b/400_xowa/src/gplx/xowa/parsers/xndes/Xop_xnde_wkr__include_uncommon_tst.java @@ -0,0 +1,192 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: 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.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; +import org.junit.*; +public class Xop_xnde_wkr__include_uncommon_tst { + private final Xop_fxt fxt = new Xop_fxt(); + @Before public void init() {fxt.Reset();} + @Test public void Ex_Tmpl_io_oi() { // PURPOSE: not parsing internals; PAGE:en.w:[[Template:MONTHNAME]] + fxt.Test_parse_tmpl_str_test("{{#if:{{{1}}}|a|b}}c", "{{test|1}}", "a"); + } + @Test public void Ex_Tmpl_io_subst() { // PURPOSE: and @gplx.Internal protected subst; PAGE:en.w:[[Template:Dubious]] + fxt.Init_defn_clear(); + fxt.Init_defn_add("mwo_print", "{{{1}}}"); + fxt.Init_defn_add("substcheck", "SUBST"); + fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last + ( "{{mwo_print" + , "|{{subst:substcheck}}" + , "}}" + ), "{{test}}" + , "{{subst:substcheck}}\n" + ); + fxt.Reset(); + fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last + ( "{{mwo_print" + , "|{{safesubst:substcheck}}" + , "}}" + ), "{{test}}" + , "SUBST\n"); + fxt.Init_defn_clear(); + } + @Test public void Ex_Tmpl_noinclude_prm_1() { // PURPOSE: should not process @gplx.Internal protected tkns; PAGE:en.w:[[Template:See]] + fxt.Init_defn_clear(); + fxt.Init_defn_add("mwo_print", "{{{1}}}{{{2}}}"); + fxt.Test_parse_tmpl_str_test + ( "{{mwo_print|{{{1|not_seen}}}|{{{2}}}}}" + , "{{test|a|b}}" + , "ab" + ); + fxt.Init_defn_clear(); + } + @Test public void Ex_Tmpl_noinclude_prm_2() { // PURPOSE: should not process default tkn; + fxt.Test_parse_tmpl_str_test + ( "{{#if: {{{x|y}}} | visible | hidden}}" // {{#if: {{{x|y}}} -> {{#if: {{{x|}} -> hidden + , "{{test}}" + , "hidden" + ); + } + @Test public void Ex_Tmpl_noinclude2() { // PURPOSE: should be separate from tkns {{convert|50|km|0|abbr=on}} + fxt.Init_defn_clear(); + fxt.Init_defn_add("mwo_print", "{{{1}}}{{{2}}}"); + fxt.Test_parse_tmpl_str_test + ( "{{mwo_print{{{?}}}|a|b}}" + , "{{test}}" + , "ab" + ); + fxt.Init_defn_clear(); + } + @Test public void Exception_incompleteTag_matchNext() { // PURPOSE: "bde" + , "{{test}}" + , "ae" + ); + } + @Test public void Exception_noCloseTag() { + fxt.Test_parse_tmpl_str_test + ( "abcde" + , "{{test}}" + , "a" + ); + } + @Test public void Exception_inline() { + fxt.Test_parse_tmpl_str_test + ( "abcde" + , "{{test}}" + , "abcde" + ); + } + @Test public void Exception_inline_2() { + fxt.Test_parse_tmpl_str_test + ( "abcde" + , "{{test}}" + , "abcde" + ); + } + @Test public void Defect_onlyinclude_inside_template() { // PURPOSE: was eating up next template; PAGE:en.w:Wikipedia:Featured_articles + fxt.Test_parse_page_all_str + ( "{{formatnum: 1}} {{formatnum:2}}" + , "1 2" + ); + } + @Test public void Only_include_preserves_nl() { // PURPOSE: given "a\n{|\n", "{|" should be table; PAGE:en.w:Wikipedia:Reference_desk + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "==b==" + , "c" + ) +// , "{{test}}" + , String_.Concat_lines_nl + ( "a" + , "" + , "

        b

        " + , "c" + )); + } + @Test public void Only_include_interprets_template() { // PURPOSE: should interpret templates + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "see_me"); + fxt.Test_parse_page_all_str(String_.Concat_lines_nl + ( "a" + , "{{test}}" + , "c" + ) + , String_.Concat_lines_nl + ( "a" + , "see_me" + , "c" + )); + } + @Test public void Include_only_in_template_name() {// PURPOSE: includeonly in tmpl_name should be ignored; EX:de.w:Wikipedia:Projektdiskussion; DATE:2014-01-24 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "abc"); + fxt.Test_parse_page_all_str("{{test}}", "abc"); + } + @Test public void Include_only_in_transcluded_page() {// PURPOSE: include only in transcluded page should be ignored; EX:de.w:Wikipedia:Projektdiskussion; DATE:2014-01-24; DATE:2014-05-10 + fxt.Init_page_create("page", "abc"); // create page in main ns + fxt.Test_parse_page_all_str("{{:safesubst:page}}", "abc"); // will become {{:page}} which should then transclude page + } + @Test public void Include_only_subst_in_function() {// PURPOSE: includeonly and subst inside function should be ignored; PAGE:en.w:WikiProject_Articles_for_creation/BLD_Preload; DATE:2014-04-29 + fxt.Test_parse_page_all_str("{{subst:#expr:0}}", "0"); + } + @Test public void Hdr() { // PURPOSE: includeonly should be evaluated during template parse; EX: es.b:Billar/T�cnica/Clases_de_puentes; DATE:2014-02-12 + fxt.Test_parse_page_all_str("==A==", "

        A

        \n"); + } +// @Test public void Noinclude_nested() { // PURPOSE: nested noincludes don't work; th.w:ISO_3166-1;DATE:2014-04-06 +// fxt.Init_defn_clear(); +// fxt.Init_defn_add("test", "abcde"); +// fxt.Test_parse_page_all_str("{{test}}", "ae"); +// } + +// @Test public void Wiki_includeonly_ignore() {fxt.Test_parse_wiki_text("[[abc]]", "[[ac]]");} // FUTURE: ttl parses by idx, and ignores includeonly: WHEN: upon encountering; may need to redo in other parsers? + @Test public void Defect_noinclude_inside_main() { // PURPOSE: inside main was not returning content; PAGE:en.w:Wikipedia:Featured_articles + fxt.Init_defn_clear(); + fxt.Init_defn_add("Test_tmpl", "{{:Test_page}}"); + fxt.Data_create("Test_page", "a{{#expr:1}}c"); + fxt.Test_parse_page_all_str + ( "{{Test_tmpl}}" + , "1" + ); + fxt.Init_defn_clear(); + } + @Test public void Pre_and_includeonly() { // PAGE:https://en.wikipedia.org/wiki/BSD_licenses DATE:2014-05-23 + fxt.Init_defn_add("pre2", "
        >{{{1}}}
        "); + fxt.Test_parse_page_all_str + ( "{{pre2|a}}" + , String_.Concat_lines_nl_skip_last + ( "
        a
        " + )); + } +// @Test public void Pre_and_includeonly2() { +// fxt.Init_defn_add("pre2", ">{{{1}}}