mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.3.3
This commit is contained in:
@@ -20,7 +20,8 @@ import gplx.core.primitives.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.net.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
public class Xoa_url_parser {
|
||||
private final Url_encoder encoder = Url_encoder.new_html_href_mw_().Itms_raw_same_many(Byte_ascii.Underline); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Url_encoder encoder = Url_encoder.new_html_href_mw_().Itms_raw_same_many(Byte_ascii.Underline);
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public Gfo_url_parser Url_parser() {return url_parser;} private Gfo_url_parser url_parser = new Gfo_url_parser(); private Gfo_url gfo_url = new Gfo_url();
|
||||
public String Build_str(Xoa_url url) { // transform to "canonical" form that fits url box for both XOWA and Mozilla Firefox
|
||||
tmp_bfr.Add(url.Wiki_bry()); // add wiki; EX: "en.wikipedia.org"
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xoa_url_parser_basic_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_url_parser_chkr fxt = new Xoa_url_parser_chkr();
|
||||
@Test public void Basic() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("en.wikipedia.org/wiki/A");
|
||||
}
|
||||
@Test public void Abrv() { // deprecate; no longer needed with shortcuts
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("en.wikipedia.org/A");
|
||||
}
|
||||
@Test public void Commons() { // PURPOSE: "C" was being picked up as an xwiki to commons; PAGE:no.b:C/Variabler; DATE:2014-10-14
|
||||
fxt.Init_xwiki("c", "commons.wikimedia.org"); // add alias of "C"
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("C/D").Test_parse_w_wiki("C/D"); // should use default wiki of enwiki, not commons; also, page should be "C/D", not "D"
|
||||
}
|
||||
@Test public void Http_basic() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("http://en.wikipedia.org/wiki/A");
|
||||
}
|
||||
@Test public void Relative() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("//en.wikipedia.org/wiki/A");
|
||||
}
|
||||
@Test public void Name() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("A");
|
||||
}
|
||||
@Test public void Sub_1() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A/b").Test_parse_w_wiki("A/b");
|
||||
}
|
||||
@Test public void Sub_2() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A/b/c").Test_parse_w_wiki("A/b/c");
|
||||
}
|
||||
@Test public void Sub_3() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A/b").Test_parse_w_wiki("en.wikipedia.org/wiki/A/b");
|
||||
}
|
||||
@Test public void Ns_category() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("Category:A").Test_parse_w_wiki("Category:A");
|
||||
}
|
||||
@Test public void Ns_file() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("File:A").Test_parse_w_wiki("File:A");
|
||||
}
|
||||
@Test public void Anchor() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_anchor("b").Test_parse_w_wiki("A#b");
|
||||
}
|
||||
@Test public void Upload() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("commons.wikimedia.org", "commons.wikimedia.org");
|
||||
fxt.Reset().Expd_wiki("commons.wikimedia.org").Expd_page("File:C.svg").Test_parse_w_wiki("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg");
|
||||
fxt.Reset().Expd_wiki("commons.wikimedia.org").Expd_page("File:A.png").Test_parse_w_wiki("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png");
|
||||
}
|
||||
@Test public void Parse_lang() {
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("fr"), Bry_.new_a7("fr.wikipedia.org"), Bry_.new_a7("http://fr.wikipedia.org/~{0}"));
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("A").Test_parse_w_wiki("http://en.wikipedia.org/wiki/fr:A");
|
||||
}
|
||||
@Test public void Alias_wiki() {
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("s"), Bry_.new_a7("en.wikisource.org"));
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("A/b/c").Test_parse_w_wiki("s: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
|
||||
Xow_xwiki_mgr xwiki_mgr = fxt.Wiki_en_w().Xwiki_mgr();
|
||||
xwiki_mgr.Add_full(Bry_.new_a7("s"), Bry_.new_a7("en.wikisource.org"));
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("Project:A").Test_parse_w_wiki("s:Project:A");
|
||||
}
|
||||
@Test public void Domain_only() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("fr.wikipedia.org");
|
||||
}
|
||||
@Test public void Domain_and_wiki() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("fr.wikipedia.org/wiki");
|
||||
}
|
||||
@Test public void Domain_and_wiki_w_http() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikipedia.org", "fr.wikipedia.org");
|
||||
fxt.Expd_wiki("fr.wikipedia.org").Expd_page("").Test_parse_w_wiki("http://fr.wikipedia.org/wiki");
|
||||
}
|
||||
@Test public void Redirect() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Test_parse_w_wiki("A?redirect=no");
|
||||
}
|
||||
@Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki
|
||||
fxt.Expd_wiki("en.wikisource.org").Expd_page("Category:A").Test_parse_w_wiki(fxt.Wiki_en_s(), "Category:A");
|
||||
}
|
||||
@Test public void Action_is_edit() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_action_is_edit_y().Test_parse_w_wiki("A?action=edit");
|
||||
}
|
||||
@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
|
||||
byte[] raw = Bry_.new_a7("A?action=edit");
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki_en_w(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(true, url.Action_is_edit());
|
||||
raw = Bry_.new_a7("B");
|
||||
Xoa_url_parser.Parse_url(url, fxt.App(), fxt.Wiki_en_w(), raw, 0, raw.length, false);
|
||||
Tfds.Eq(false, url.Action_is_edit());
|
||||
}
|
||||
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
|
||||
byte[] raw = Bry_.new_a7("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes");
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(fxt.App(), fxt.Wiki_en_w(), raw, 0, raw.length, false);
|
||||
Xoa_url_parser parser = new Xoa_url_parser();
|
||||
Tfds.Eq("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes", parser.Build_str(url));
|
||||
}
|
||||
@Test public void Anchor_with_slash() { // PURPOSE: A/b#c/d was not parsing correctly
|
||||
fxt.Expd_page("A/b").Expd_anchor("c.2Fd").Test_parse_w_wiki("A/b#c/d");
|
||||
}
|
||||
@Test public void Slash() {
|
||||
fxt.Reset().Expd_wiki("en.wikipedia.org").Expd_page("/A").Test_parse_w_wiki("en.wikipedia.org/wiki//A");
|
||||
fxt.Reset().Expd_wiki("en.wikipedia.org").Expd_page("A//b").Test_parse_w_wiki("en.wikipedia.org/wiki/A//b");
|
||||
fxt.Reset().Expd_wiki("en.wikipedia.org").Expd_page("//A").Test_parse_w_wiki("en.wikipedia.org/wiki///A");
|
||||
}
|
||||
@Test public void Question_is_page() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A?B").Expd_anchor(null).Test_parse_w_wiki("A?B");
|
||||
}
|
||||
@Test public void Question_is_anchor() {
|
||||
fxt.Expd_wiki("en.wikipedia.org").Expd_page("A").Expd_anchor("b.3Fc").Test_parse_w_wiki("A#b?c");
|
||||
}
|
||||
}
|
||||
class Xoa_url_parser_chkr implements Tst_chkr {
|
||||
public Xoa_url_parser_chkr Reset() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki_en_w = Xoa_app_fxt.wiki_(app, "en.wikipedia.org");
|
||||
wiki_en_s = Xoa_app_fxt.wiki_(app, "en.wikisource.org");
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org");
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_full("en.wikisource.org", "en.wikisource.org");
|
||||
}
|
||||
expd_wiki_str = expd_page = expd_anchor = null;
|
||||
expd_anchor_is_edit = Bool_.__byte;
|
||||
return this;
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki_en_w() {return wiki_en_w;} private Xowe_wiki wiki_en_w;
|
||||
public Xowe_wiki Wiki_en_s() {return wiki_en_s;} private Xowe_wiki wiki_en_s;
|
||||
public Class<?> TypeOf() {return Xoa_url.class;}
|
||||
public Xoa_url_parser_chkr Expd_wiki(String v) {this.expd_wiki_str = v; return this;} private String expd_wiki_str;
|
||||
public Xoa_url_parser_chkr Expd_page(String v) {this.expd_page = v; return this;} private String expd_page;
|
||||
public Xoa_url_parser_chkr Expd_anchor(String v) {this.expd_anchor = v; return this;} private String expd_anchor;
|
||||
public Xoa_url_parser_chkr Expd_action_is_edit_y() {this.expd_anchor_is_edit = Bool_.Y_byte; return this;} private byte expd_anchor_is_edit = Bool_.__byte;
|
||||
public Xoa_url_parser_chkr Expd_action_is_edit_n() {this.expd_anchor_is_edit = Bool_.N_byte; return this;}
|
||||
public void Init_xwiki(String alias, String domain) {app.Usere().Wiki().Xwiki_mgr().Add_full(alias, domain);}
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Xoa_url actl = (Xoa_url)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(expd_wiki_str == null, path, "wiki", expd_wiki_str, String_.new_u8(actl.Wiki_bry()));
|
||||
rv += mgr.Tst_val(expd_page == null, path, "page", expd_page, String_.new_u8(actl.Page_bry()));
|
||||
rv += mgr.Tst_val(expd_anchor == null, path, "anchor", expd_anchor, String_.new_u8(actl.Anchor_bry()));
|
||||
rv += mgr.Tst_val(expd_anchor_is_edit == Bool_.__byte, path, "anchor_is_edit", expd_anchor_is_edit == Bool_.Y_byte, actl.Action_is_edit());
|
||||
return rv;
|
||||
}
|
||||
public Xoa_url_parser_chkr Test_parse_from_url_bar(String raw, String expd) {
|
||||
Xoa_url actl_url = Xoa_url_parser.Parse_from_url_bar(app, wiki_en_w, raw);
|
||||
Tfds.Eq(expd, actl_url.Xto_full_str());
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_w_wiki(String raw) {Test_parse_w_wiki(wiki_en_w, raw);}
|
||||
public void Test_parse_w_wiki(Xowe_wiki w, String raw) {
|
||||
Xoa_url url = Xoa_url_parser.Parse_url(app, w, raw);
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
tst_mgr.Tst_obj(this, url);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_url_parser_mw_links_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_url_parser_chkr fxt = new Xoa_url_parser_chkr();
|
||||
@Test public void Title_remove_w() { // PURPOSE: fix /w/ showing up as seg; DATE:2014-05-30
|
||||
fxt.Expd_page("A").Expd_wiki("en.wikipedia.org").Test_parse_w_wiki("http://en.wikipedia.org/w/index.php?title=A");
|
||||
}
|
||||
}
|
||||
170
400_xowa/src_310_url/gplx/xowa/Xoa_url_parser_tst.java
Normal file
170
400_xowa/src_310_url/gplx/xowa/Xoa_url_parser_tst.java
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xoa_url_parser_tst {
|
||||
private final Xoa_url_parser_fxt fxt = new Xoa_url_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Run_parse("en.wikipedia.org/wiki/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void No_wiki() { // PURPOSE: no "/wiki/"
|
||||
fxt.Run_parse("en.wikipedia.org/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Commons() { // PURPOSE: "C" was being picked up as an xwiki to commons; PAGE:no.b:C/Variabler; DATE:2014-10-14
|
||||
fxt.Prep_add_xwiki_to_user("c", "commons.wikimedia.org"); // add alias of "c"
|
||||
fxt.Run_parse("C/D").Chk_wiki("en.wikipedia.org").Chk_page("C/D"); // should use current wiki (enwiki), not xwiki to commons; also, page should be "C/D", not "D"
|
||||
}
|
||||
@Test public void Http_basic() {
|
||||
fxt.Run_parse("http://en.wikipedia.org/wiki/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Relative() {
|
||||
fxt.Run_parse("//en.wikipedia.org/wiki/A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Name() {
|
||||
fxt.Run_parse("A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Sub_1() {
|
||||
fxt.Run_parse("A/b").Chk_wiki("en.wikipedia.org").Chk_page("A/b");
|
||||
}
|
||||
@Test public void Sub_2() {
|
||||
fxt.Run_parse("A/b/c").Chk_wiki("en.wikipedia.org").Chk_page("A/b/c");
|
||||
}
|
||||
@Test public void Sub_3() {
|
||||
fxt.Run_parse("en.wikipedia.org/wiki/A/b").Chk_wiki("en.wikipedia.org").Chk_page("A/b");
|
||||
}
|
||||
@Test public void Ns_category() {
|
||||
fxt.Run_parse("Category:A").Chk_wiki("en.wikipedia.org").Chk_page("Category:A");
|
||||
}
|
||||
@Test public void Ns_file() {
|
||||
fxt.Run_parse("File:A").Chk_wiki("en.wikipedia.org").Chk_page("File:A");
|
||||
}
|
||||
@Test public void Anchor() {
|
||||
fxt.Run_parse("A#b").Chk_wiki("en.wikipedia.org").Chk_page("A").Chk_anchor("b");
|
||||
}
|
||||
@Test public void Upload() {
|
||||
fxt.Prep_add_xwiki_to_user("commons.wikimedia.org"); // NOTE: need to add xwiki to be able to resolve "/commons/"
|
||||
fxt.Run_parse("http://upload.wikimedia.org/wikipedia/commons/a/ab/C.svg").Chk_wiki("commons.wikimedia.org").Chk_page("File:C.svg");
|
||||
fxt.Run_parse("http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.png").Chk_wiki("commons.wikimedia.org").Chk_page("File:A.png");
|
||||
}
|
||||
@Test public void Parse_lang() {
|
||||
fxt.Prep_add_xwiki_to_wiki("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/~{0}");
|
||||
fxt.Run_parse("http://en.wikipedia.org/wiki/fr:A").Chk_wiki("fr.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Alias_wiki() {
|
||||
fxt.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
|
||||
fxt.Run_parse("s:A/b/c").Chk_wiki("en.wikisource.org").Chk_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
|
||||
fxt.Prep_add_xwiki_to_wiki("s", "en.wikisource.org");
|
||||
fxt.Run_parse("s:Project:A").Chk_wiki("en.wikisource.org").Chk_page("Project:A");
|
||||
}
|
||||
@Test public void Domain_only() {
|
||||
fxt.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
fxt.Run_parse("fr.wikipedia.org").Chk_wiki("fr.wikipedia.org").Chk_page("");
|
||||
}
|
||||
@Test public void Domain_and_wiki() {
|
||||
fxt.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
fxt.Run_parse("fr.wikipedia.org/wiki").Chk_wiki("fr.wikipedia.org").Chk_page("");
|
||||
}
|
||||
@Test public void Domain_and_wiki_w_http() {
|
||||
fxt.Prep_add_xwiki_to_user("fr.wikipedia.org");
|
||||
fxt.Run_parse("http://fr.wikipedia.org/wiki").Chk_wiki("fr.wikipedia.org").Chk_page("");
|
||||
}
|
||||
@Test public void Redirect() {
|
||||
fxt.Run_parse("A?redirect=no").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
@Test public void Namespace_in_different_wiki() { // PURPOSE.fix: namespaced titles would default to default_wiki instead of current_wiki
|
||||
Xowe_wiki en_s = fxt.Prep_create_wiki("en.wikisource.org");
|
||||
fxt.Run_parse(en_s, "Category:A").Chk_wiki("en.wikisource.org").Chk_page("Category:A");
|
||||
}
|
||||
@Test public void Action_is_edit() {
|
||||
fxt.Run_parse("A?action=edit").Chk_wiki("en.wikipedia.org").Chk_page("A").Chk_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.Run_parse("A?action=edit") .Chk_action_is_edit_y();
|
||||
fxt.Run_parse_reuse("B") .Chk_action_is_edit_n();
|
||||
}
|
||||
@Test public void Query_arg() { // PURPOSE.fix: query args were not printing out
|
||||
fxt.Run_parse("en.wikipedia.org/wiki/Special:Search/Earth?fulltext=yes").Chk_build_str_is_same();
|
||||
}
|
||||
@Test public void Anchor_with_slash() { // PURPOSE: A/b#c/d was not parsing correctly
|
||||
fxt.Run_parse("A/b#c/d").Chk_page("A/b").Chk_anchor("c.2Fd");
|
||||
}
|
||||
@Test public void Slash() {
|
||||
fxt.Run_parse("en.wikipedia.org/wiki//A").Chk_wiki("en.wikipedia.org").Chk_page("/A");
|
||||
fxt.Run_parse("en.wikipedia.org/wiki/A//b").Chk_wiki("en.wikipedia.org").Chk_page("A//b");
|
||||
fxt.Run_parse("en.wikipedia.org/wiki///A").Chk_wiki("en.wikipedia.org").Chk_page("//A");
|
||||
}
|
||||
@Test public void Question_is_page() {
|
||||
fxt.Run_parse("A?B").Chk_wiki("en.wikipedia.org").Chk_page("A?B").Chk_anchor(null);
|
||||
}
|
||||
@Test public void Question_is_anchor() {
|
||||
fxt.Run_parse("A#b?c").Chk_wiki("en.wikipedia.org").Chk_page("A").Chk_anchor("b.3Fc");
|
||||
}
|
||||
@Test public void Title_remove_w() { // PURPOSE: fix /w/ showing up as seg; DATE:2014-05-30
|
||||
fxt.Run_parse("http://en.wikipedia.org/w/index.php?title=A").Chk_wiki("en.wikipedia.org").Chk_page("A");
|
||||
}
|
||||
}
|
||||
class Xoa_url_parser_fxt {
|
||||
private final Xoae_app app; private final Xowe_wiki cur_wiki;
|
||||
private Xoa_url actl_url;
|
||||
public Xoa_url_parser_fxt() {
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
this.cur_wiki = Prep_create_wiki("en.wikipedia.org");
|
||||
}
|
||||
public Xowe_wiki Prep_create_wiki(String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.wiki_(app, domain);
|
||||
Prep_add_xwiki_to_user(domain);
|
||||
return rv;
|
||||
}
|
||||
public Xoa_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain) {return Prep_xwiki(cur_wiki, alias, domain, null);}
|
||||
public Xoa_url_parser_fxt Prep_add_xwiki_to_wiki(String alias, String domain, String fmt) {return Prep_xwiki(cur_wiki, alias, domain, fmt);}
|
||||
public Xoa_url_parser_fxt Prep_add_xwiki_to_user(String domain) {return Prep_xwiki(app.Usere().Wiki(), domain, domain, null);}
|
||||
public Xoa_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, null);}
|
||||
public Xoa_url_parser_fxt Prep_add_xwiki_to_user(String alias, String domain, String fmt) {return Prep_xwiki(app.Usere().Wiki(), alias, domain, fmt);}
|
||||
private Xoa_url_parser_fxt Prep_xwiki(Xow_wiki wiki, String alias, String domain, String fmt) {
|
||||
wiki.Xwiki_mgr().Add_full(Bry_.new_u8(alias), Bry_.new_u8(domain), Bry_.new_u8_safe(fmt));
|
||||
return this;
|
||||
}
|
||||
public Xoa_url_parser_fxt Run_parse(String actl_str) {return Run_parse(cur_wiki, actl_str);}
|
||||
public Xoa_url_parser_fxt Run_parse(Xow_wiki wiki, String actl_str) {
|
||||
this.actl_url = Xoa_url_parser.Parse_url(app, wiki, actl_str);
|
||||
return this;
|
||||
}
|
||||
public Xoa_url_parser_fxt Run_parse_reuse(String actl_str) {
|
||||
byte[] actl_bry = Bry_.new_u8(actl_str);
|
||||
Xoa_url_parser.Parse_url(actl_url, app, cur_wiki, actl_bry, 0, actl_bry.length, false);
|
||||
return this;
|
||||
}
|
||||
public Xoa_url_parser_fxt Run_parse_from_url_bar(String raw) {
|
||||
this.actl_url = Xoa_url_parser.Parse_from_url_bar(app, cur_wiki, raw);
|
||||
return this;
|
||||
}
|
||||
public Xoa_url_parser_fxt Chk_wiki(String v) {Tfds.Eq_str(v, actl_url.Wiki_bry() , "wiki"); return this;}
|
||||
public Xoa_url_parser_fxt Chk_page(String v) {Tfds.Eq_str(v, actl_url.Page_bry() , "page"); return this;}
|
||||
public Xoa_url_parser_fxt Chk_anchor(String v) {Tfds.Eq_str(v, actl_url.Anchor_bry(), "anch"); return this;}
|
||||
public Xoa_url_parser_fxt Chk_action_is_edit_y() {return Chk_action_is_edit_(Bool_.Y);}
|
||||
public Xoa_url_parser_fxt Chk_action_is_edit_n() {return Chk_action_is_edit_(Bool_.N);}
|
||||
private Xoa_url_parser_fxt Chk_action_is_edit_(boolean v) {Tfds.Eq_bool(v, actl_url.Action_is_edit(), "action_is_edit"); return this;}
|
||||
public Xoa_url_parser_fxt Chk_to_str(String v) {Tfds.Eq_str(v, actl_url.Xto_full_str(), "Xto_full_str"); return this;}
|
||||
public Xoa_url_parser_fxt Chk_build_str_is_same() {
|
||||
Xoa_url_parser parser = new Xoa_url_parser();
|
||||
Tfds.Eq_str(actl_url.Raw(), parser.Build_str(actl_url), "build_str");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -18,52 +18,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_url_parser_url_bar_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_url_parser_chkr fxt = new Xoa_url_parser_chkr();
|
||||
private final Xoa_url_parser_fxt fxt = new Xoa_url_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_from_url_bar("Page_1" , "en.wikipedia.org/wiki/Page_1"); // basic
|
||||
fxt.Run_parse_from_url_bar("Page_1").Chk_to_str("en.wikipedia.org/wiki/Page_1"); // basic
|
||||
}
|
||||
@Test public void Lang() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("uk", "uk.wikipedia.org");
|
||||
fxt.Test_parse_from_url_bar("uk" , "en.wikipedia.org/wiki/uk"); // lang-like page (uk=Ukraine) should not try to open wiki; DATE:2014-02-07
|
||||
fxt.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org");
|
||||
fxt.Run_parse_from_url_bar("uk").Chk_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() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full(Bry_.new_a7("uk"), Bry_.new_a7("uk.wikipedia.org"), Bry_.new_a7("http://~{1}.wikipedia.org")); // NOTE: fmt needed for Type_is_lang
|
||||
fxt.Test_parse_from_url_bar("uk/A" , "en.wikipedia.org/wiki/uk/A"); // uk/A should not try be interpreted as wiki="uk" page="A"; DATE:2014-04-26
|
||||
fxt.Prep_add_xwiki_to_user("uk", "uk.wikipedia.org", "http://~{1}.wikipedia.org"); // NOTE: fmt needed for Type_is_lang
|
||||
fxt.Run_parse_from_url_bar("uk/A").Chk_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() {
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("fr.wikisource.org", "fr.wikisource.org");
|
||||
fxt.Test_parse_from_url_bar("fr.s:Auteur:Shakespeare" , "fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
|
||||
fxt.Prep_add_xwiki_to_user("fr.wikisource.org");
|
||||
fxt.Run_parse_from_url_bar("fr.s:Auteur:Shakespeare").Chk_to_str("fr.wikisource.org/wiki/Auteur:Shakespeare"); // url_macros
|
||||
}
|
||||
@Test public void Home() {
|
||||
Init_db(fxt.App().Usere().Wiki());
|
||||
fxt.Test_parse_from_url_bar("home" , "en.wikipedia.org/wiki/home"); // home should go to current wiki's home; DATE:2014-02-09
|
||||
fxt.Test_parse_from_url_bar("home/wiki/Main_Page" , "home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09
|
||||
@Test public void Main_page__home() {
|
||||
fxt.Run_parse_from_url_bar("home").Chk_to_str("en.wikipedia.org/wiki/home"); // home should go to current wiki's home; DATE:2014-02-09
|
||||
fxt.Run_parse_from_url_bar("home/wiki/Main_Page").Chk_to_str("home/wiki/Main_Page"); // home Main_Page should go to home; DATE:2014-02-09
|
||||
}
|
||||
@Test public void Custom() {
|
||||
// fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
// gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(fxt.App(), "zh.wikipedia.org");
|
||||
// fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("zh.wikipedia.org")).Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
fxt.App().Usere().Wiki().Xwiki_mgr().Add_full("zh.wikipedia.org", "zh.wikipedia.org");
|
||||
Xowe_wiki zh_wiki = fxt.App().Wiki_mgr().Get_by_key_or_make(Bry_.new_a7("zh.wikipedia.org"));
|
||||
Init_db(zh_wiki);
|
||||
gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(fxt.App(), "zh.wikipedia.org");
|
||||
@Test public void Main_page__zhw() {
|
||||
Xowe_wiki zh_wiki = fxt.Prep_create_wiki("zh.wikipedia.org");
|
||||
gplx.xowa.wikis.Xoa_wiki_regy.Make_wiki_dir(zh_wiki.App(), "zh.wikipedia.org"); // HACK: needed for to_url_bar
|
||||
zh_wiki.Props().Main_page_(Bry_.new_a7("Zh_Main_Page"));
|
||||
fxt.Test_parse_from_url_bar("zh.w:" , "zh.wikipedia.org/wiki/Zh_Main_Page");
|
||||
fxt.Test_parse_from_url_bar("zh.w:Main_Page" , "zh.wikipedia.org/wiki/Main_Page");
|
||||
fxt.Run_parse_from_url_bar("zh.w:").Chk_to_str("zh.wikipedia.org/wiki/Zh_Main_Page");
|
||||
fxt.Run_parse_from_url_bar("zh.w:Main_Page").Chk_to_str("zh.wikipedia.org/wiki/Main_Page");
|
||||
}
|
||||
@Test public void Mobile() { // PURPOSE: handle mobile links; DATE:2014-05-03
|
||||
fxt.Test_parse_from_url_bar("en.m.wikipedia.org/wiki/A" , "en.wikipedia.org/wiki/A"); // basic
|
||||
fxt.Test_parse_from_url_bar("en.M.wikipedia.org/wiki/A" , "en.wikipedia.org/wiki/A"); // upper
|
||||
fxt.Test_parse_from_url_bar("A" , "en.wikipedia.org/wiki/A"); // bounds-check: 0
|
||||
fxt.Test_parse_from_url_bar("A." , "en.wikipedia.org/wiki/A."); // bounds-check: 1
|
||||
fxt.Test_parse_from_url_bar("A.b" , "en.wikipedia.org/wiki/A.b"); // bounds-check: 2
|
||||
fxt.Test_parse_from_url_bar("A.b.m." , "en.wikipedia.org/wiki/A.b.m."); // false-match
|
||||
fxt.Test_parse_from_url_bar("en.x.wikipedia.org/wiki/A" , "en.wikipedia.org/wiki/en.x.wikipedia.org/A"); // fail
|
||||
}
|
||||
public static void Init_db(Xowe_wiki wiki) {
|
||||
Xoa_test_.Db_init(true, Xoa_test_.Url_root());
|
||||
wiki.Ns_mgr().Init_w_defaults();
|
||||
Xowe_wiki_bldr.Create(wiki, 1, "dump.xml");
|
||||
wiki.Data__core_mgr().Db__core().Tbl__ns().Insert(wiki.Ns_mgr());
|
||||
fxt.Run_parse_from_url_bar("en.m.wikipedia.org/wiki/A" ).Chk_to_str("en.wikipedia.org/wiki/A"); // basic
|
||||
fxt.Run_parse_from_url_bar("en.M.wikipedia.org/wiki/A" ).Chk_to_str("en.wikipedia.org/wiki/A"); // upper
|
||||
fxt.Run_parse_from_url_bar("A" ).Chk_to_str("en.wikipedia.org/wiki/A"); // bounds-check: 0
|
||||
fxt.Run_parse_from_url_bar("A." ).Chk_to_str("en.wikipedia.org/wiki/A."); // bounds-check: 1
|
||||
fxt.Run_parse_from_url_bar("A.b" ).Chk_to_str("en.wikipedia.org/wiki/A.b"); // bounds-check: 2
|
||||
fxt.Run_parse_from_url_bar("A.b.m." ).Chk_to_str("en.wikipedia.org/wiki/A.b.m."); // false-match
|
||||
fxt.Run_parse_from_url_bar("en.x.wikipedia.org/wiki/A" ).Chk_to_str("en.wikipedia.org/wiki/en.x.wikipedia.org/A"); // fail
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user