1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Command-line: Fix curid argument not working 2

This commit is contained in:
gnosygnu
2017-02-22 08:44:14 -05:00
parent 0e85cc90ff
commit 5bd3371802
896 changed files with 1 additions and 69011 deletions

View File

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

View File

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

View File

@@ -1,62 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("&amp;" , "&");}
@Test public void Name_w_text() {fxt.Test__decode_as_bry("a&amp;b" , "a&b");}
@Test public void Name_fail_semic_missing() {fxt.Test__decode_as_bry("a&ampb" , "a&ampb");}
@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("&#0931;" , "Σ");}
@Test public void Num_zero_padded() {fxt.Test__decode_as_bry("&#00931;" , "Σ");}
@Test public void Hex_upper() {fxt.Test__decode_as_bry("&#x3A3;" , "Σ");}
@Test public void Hex_lower() {fxt.Test__decode_as_bry("&#x3a3;" , "Σ");}
@Test public void Hex_zero_padded() {fxt.Test__decode_as_bry("&#x03a3;" , "Σ");}
@Test public void Hex_upper_x() {fxt.Test__decode_as_bry("&#X3A3;" , "Σ");}
@Test public void Num_fail_large_codepoint() {fxt.Test__decode_as_bry("&#538189831;" , "&#538189831;");}
@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);
}
}

View File

@@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("&amp;" , "&amp;");} // 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("&#x3A3;" , 931);} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference
@Test public void Num__dec() {fxt.Test__parse_tkn__ncr("&#931;" , 931);}
@Test public void Num__fail() {fxt.Test__parse_tkn__txt("&#" , 1);}
}

View File

@@ -1,35 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("&amp;" , "&amp;");} // note that &amp; is printed, not &
@Test public void Convert_to_named_amp() {fxt.Test_parse_page_wiki_str("&" , "&amp;");} // PURPOSE: html_wtr was not handling & only
@Test public void Convert_to_numeric() {fxt.Test_parse_page_wiki_str("&aacute;" , "&#225;");} // testing that &#225; 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=<p>&#10;</p>]]" // basically checks amp parsing inside xnde inside lnki's alt (which uses different parsing code
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"&#10;\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
@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 <code>&#60;iframe&#62;</code>) b"
, "a <code>&#60;iframe&#62;</code>) b" // &#60; should not become <
);
}
}

View File

@@ -1,151 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 href=\"/wiki/%27%27a%27%27%27\">''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==", "<i>a</i>\n\n<h2>b</h2>");
}
@Test public void Apos_broken_by_tblw_th() { // DATE:2013-04-24
fxt.Test_parse_page_all_str("A ''[[b!!]]'' c", "A <i><a href=\"/wiki/B!!\">b!!</a></i> c");
}
@Test public void Nowiki() { // PAGE:en.w:Wiki; DATE:2013-05-13
fxt.Test_parse_page_all_str("<nowiki>''a''</nowiki>", "''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 ]]"
)
, "<a href=\"/wiki/A\">b <i> c d </i> e</a>"); // 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'<i>A</i>; DATE:2014-01-06
fxt.Test_parse_page_all_str("L''''A'''", "L'<b>A</b>");
fxt.Test_parse_page_all_str("L'''A''", "L'<i>A</i>");
}
// @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)
// );
// }
}
/*
*/

View File

@@ -1,125 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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==" , "<h2>a</h2>\n");}
@Test public void H3() {fxt.Test_parse_page_wiki_str("===a===" , "<h3>a</h3>\n");}
@Test public void H6_limit() {fxt.Test_parse_page_wiki_str("=======a=======" , "<h6>=a=</h6>\n");}
@Test public void Mismatch_bgn() {fxt.Test_parse_page_wiki_str("=====a==" , "<h2>===a</h2>\n");}
@Test public void Mismatch_end() {fxt.Test_parse_page_wiki_str("==a=====" , "<h2>a===</h2>\n");}
@Test public void Dangling() {fxt.Test_parse_page_wiki_str("==a" , "==a");}
@Test public void Comment_bgn() {fxt.Test_parse_page_all_str ("<!--b-->==a==" , "<h2>a</h2>\n");}
@Test public void Comment_end() {fxt.Test_parse_page_all_str ("==a==<!--b-->" , "<h2>a</h2>\n");}
@Test public void Ws_end() { // PURPOSE: "==\n" merges all ws following it; \n\n\n is not transformed by Para_wkr to "<br/>"
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "==a== \t"
, ""
, ""
, ""
, "b"
), String_.Concat_lines_nl_skip_last
( "<h2>a</h2>"
, "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
( "<h2>a</h2>"
, ""
, "<h3>b</h3>"
, ""
));
}
@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
( "<h2>a</h2>"
, "<table>"
, " <caption>"
, " </caption>"
, "</table>"
, ""
));
}
@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
( "<h2>a</h2>"
, "<hr/>"
));
}
@Test public void Mix_apos_dangling() {fxt.Test_parse_page_wiki_str("==''a==" , "<h2><i>a</i></h2>\n");}
@Test public void Mix_xnde_dangling() {fxt.Test_parse_page_wiki_str("==<i>a==" , "<h2><i>a</i></h2>\n");}
@Test public void Mix_tblw_cell() {fxt.Test_parse_page_wiki_str("==a!!==" , "<h2>a!!</h2>\n");}
@Test public void Ws() {fxt.Test_parse_page_wiki_str("== a b ==" , "<h2> a b </h2>\n");}
@Test public void Err_hdr() {fxt.Init_log_(Xop_hdr_log.Mismatched) .Test_parse_page_wiki_str("====a== ==" , "<h2>==a== </h2>\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=" , "<h1>=a</h1>\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
( "<h2><span class='mw-headline' id='a'>a</span></h2>"
, ""
, "<h2><span class='mw-headline' id='a_2'>a</span></h2>"
, ""
, "<h2><span class='mw-headline' id='a_3'>a</span></h2>"
, ""
));
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|}"
, ""
, "<h2>b</h2>"
, ""
));
}
@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
( "<h2>a</h2>"
, ""
));
}
// @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="
// , ""
// ));
// }
}

View File

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

View File

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

View File

@@ -1,160 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "== <i>Hdr 1</i> =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__slice_bry_or_null("Hdr_1", String_.Concat_lines_nl_skip_last
( "== <i>Hdr 1</i> =="
, "Para 1"
));
}
@Test public void Math() {
fxt.Exec__parse
( "== <math>\\delta</math> =="
, "Para 1"
, ""
, "== Hdr 2 =="
, "Para 2"
);
fxt.Test__slice_bry_or_null(".5Cdelta", String_.Concat_lines_nl_skip_last
( "== <math>\\delta</math> =="
, "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);
}
}

View File

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

View File

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

View File

@@ -1,76 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<nowiki>a=b</nowiki>" , fxt.Make_pair("a", "b").Atr_rng(8, 20));}
@Test public void Nowiki__key() {fxt.Test_parse("a<nowiki>b</nowiki>c=d" , fxt.Make_pair("abc", "d").Atr_rng(0, 22));}
@Test public void Nowiki__eql() {fxt.Test_parse("a<nowiki>=</nowiki>\"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=b<nowiki>c</nowiki>d" , fxt.Make_pair("a", "bcd").Atr_rng(0, 22));}
@Test public void Nowiki__val__quote() {fxt.Test_parse("a=<nowiki>'b'</nowiki>" , fxt.Make_pair("a", "b").Atr_rng(0, 22));}
@Test public void Nowiki__val__quote_2() {fxt.Test_parse("a=\"b<nowiki>c</nowiki>d<nowiki>e</nowiki>f\"", 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='<sup id='cite_ref-a_1-0' class='reference'><a href='#cite_note-a-1'>[1]</a></sup> c'"
// , fxt.Make_fail(0, 11) // "title='<sup" invalid b/c of "<"
// , fxt.Make_pair("id", "cite_ref-a_1-0")
// , fxt.Make_fail(31, 52) // "class='reference'><a" invalid b/c no ws after '
// , fxt.Make_fail(53, 88) // "href='#cite_note-a-1'>[1]</a></sup>" invalid b/c no ws after '
// , fxt.Make_fail(89, 91) // " c'" invalid b/c name (c) cannot have apos
// );
// }
}

View File

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

View File

@@ -1,59 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("a<!--b-->c" , fxt.Make_txt("a"), fxt.Make_comment("<!--b-->"), fxt.Make_txt("c"));}
@Test public void Entity() {fxt.Test_parse("a&nbsp;b" , fxt.Make_txt("a"), fxt.Make_entity("&nbsp;"), fxt.Make_txt("b"));}
@Test public void Fail__inline_eos() {fxt.Test_parse("a<b/" , fxt.Make_txt("a<b/"));}
@Test public void Fail__unknown() {fxt.Test_parse("a<bc/>d" , fxt.Make_txt("a<bc/>d"));}
@Test public void Node__inline() {fxt.Test_parse("a<b/>c" , fxt.Make_txt("a"), fxt.Make_nde_head("<b/>") , fxt.Make_txt("c"));}
@Test public void Node__pair() {fxt.Test_parse("a<b>c</b>d" , fxt.Make_txt("a"), fxt.Make_nde_head("<b>") , fxt.Make_txt("c"), fxt.Make_nde_tail("</b>"), fxt.Make_txt("d"));}
@Test public void Atrs__pair() {
fxt.Test_parse("<div id='1'>a</div>"
, fxt.Make_nde_head("<div id='1'>")
, fxt.Make_txt("a")
, fxt.Make_nde_tail("</div>"));
}
@Test public void Atrs__inline() {
fxt.Test_parse("a<div id='1'/>b"
, fxt.Make_txt("a")
, fxt.Make_nde_head("<div id='1'/>")
, fxt.Make_txt("b"));
}
@Test public void Node__single_only() {
fxt.Test_parse("<b>a<br>b</b>c"
, fxt.Make_nde_head("<b>")
, fxt.Make_txt("a", Xop_xnde_tag_.Tid__b)
, fxt.Make_nde_head("<br>")
, fxt.Make_txt("b", Xop_xnde_tag_.Tid__b) // <b> not <br>
, fxt.Make_nde_tail("</b>")
, fxt.Make_txt("c", Xop_xnde_tag_.Tid__null)
);
}
@Test public void Node__pre() {
fxt.Test_parse("<pre>a<div>b</pre>c"
, fxt.Make_nde_head("<pre>")
, fxt.Make_txt("a", Xop_xnde_tag_.Tid__pre)
, fxt.Make_nde_head("<div>")
, fxt.Make_txt("b", Xop_xnde_tag_.Tid__pre) // <pre> not <div>
, fxt.Make_nde_tail("</pre>")
, fxt.Make_txt("c", Xop_xnde_tag_.Tid__null)
);
}
}

View File

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

View File

@@ -1,351 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, ""
, "<h2>a</h2>"
));
}
@Test public void Mix_1ul_1hdr_1ul() {
fxt.Test_parse_page_wiki_str("*a\n==a==\n*b", String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, ""
, "<h2>a</h2>"
, ""
, "<ul>"
, " <li>b"
, " </li>"
, "</ul>"
));
}
@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
( "<dl>"
, " <dd>"
, " <table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " </table>"
, " </dd>"
, "</dl>"
));
}
@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
( "<ul>"
, " <li>1"
, " <ul>"
, " <li>"
, " <ul>"
, " <li>3"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li>1"
, " </li>"
, "</ul>"
));
}
@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
( "<ul>"
, " <li>1"
, " <ul>"
, " <li>"
, " <ul>"
, " <li>3"
, " </li>"
, " </ul>"
, " </li>"
, " <li>2"
, " </li>"
, " </ul>"
, " </li>"
, "</ul>"
));
}
@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
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, ""
, "<ul>"
, " <li>"
, " <ul>"
, " <li>b"
, " </li>"
, " </ul>"
, " </li>"
, "</ul>"
, ""
, "<ul>"
, " <li>"
, " <ul>"
, " <li>c"
, " </li>"
, " </ul>"
, " </li>"
, "</ul>"
));
}
}

View File

@@ -1,86 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, ""
)
);
}
@Test public void Multiple() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "*a"
, "*b"
) , String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li>a"
, " </li>"
, " <li>b"
, " </li>"
, "</ul>"
)
);
}
@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
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, ""
, "<ul>"
, " <li>b"
, " </li>"
, "</ul>"
)
);
}
@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 <pre> opened by b
) , String_.Concat_lines_nl_skip_last
( "<ol>"
, " <li>a"
, " </li>"
, "</ol>"
, ""
, "<pre>b"
, "</pre>"
, ""
, "<ol>"
, " <li>c"
, " </li>"
, "</ol>"
)
);
}
}

View File

@@ -1,407 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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: </div> was not clearing state for lnki; PAGE:en.w:Ananke (moon)
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<div>"
, "#<i>a"
, "</div>"
, "*b"
), String_.Concat_lines_nl_skip_last
( "<div>"
, "<ol>"
, " <li><i>a"
, "</i>"
, " </li>"
, "</ol></div>"
, "<ul>"
, " <li>b"
, " </li>"
, "</ul>"
));
}
@Test public void Bug_mismatched() { // FIX: </div> 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
( "<dl>"
, " <dd>"
, " <dl>"
, " <dd>a"
, " <dl>"
, " <dd>1"
, " <dl>"
, " <dd>11"
, " <dl>"
, " <dd>111"
, " </dd>"
, " </dl>"
, " </dd>"
, " </dl>"
, " </dd>"
, " </dl>"
, " </dd>"
, " <dd>b"
, " </dd>"
, " </dl>"
, " </dd>"
, "</dl>"
));
}
@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
( "<ul>"
, " <li>a"
, " </li>"
, " <li> "
, " </li>"
, " <li>b"
, " </li>"
, " <li>c"
, " </li>"
, "</ul>"
, ""
));
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
( "<ul>"
, " <li>a"
, " </li>"
, "</ul>"
, "<table>"
, " <tr>"
, " <td>b"
, ""
, " <dl>"
, " <dd>"
, " <dl>"
, " <dd>c"
, " </dd>"
, " </dl>"
, " </dd>"
, " </dl>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Dt_dd_colon_at_eol() { // PURPOSE: dangling ":" should not put next line in <dt>; PAGE:en.w:Stein; b was being wrapped in <dt>b</dt>; 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
( "<dl>"
, " <dt>a"
, " </dt>"
, " <dd>"
, " </dd>"
, "</dl>"
, "<ul>"
, " <li>b"
, " </li>"
, "</ul>"
, ""
, "<dl>"
, " <dt>c"
, " </dt>"
, "</dl>"
, "<ul>"
, " <li>d"
, " </li>"
, "</ul>"
, ""
));
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
( "<dl>"
, " <dt>a"
, " </dt>"
, " <dd>"
, " </dd>"
, "</dl>"
, "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
( "<dl>"
, " <dt><a href=\"/wiki/Portal:A\">Portal:A</a>"
, " </dt>"
, "</dl>"
, ""
));
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
( "<ol>"
, " <li>A"
, ""
, " <ul>"
, " <li>Aa"
, ""
, " <ul>"
, " <li>Aaa"
, " </li>"
, " </ul>"
, " </li>"
, " <li>Ab"
, " </li>"
, " </ul>" // was showing as </ol>
, " </li>"
, " <li>B"
, " </li>"
, "</ol>"
, ""
));
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
( "<dl>"
, " <dd>"
, " <table>"
, " <tr>"
, " <td>"
, " <ul>"
, " <li>a"
, " </li>"
, " </ul>"
, " </td>"
, " <td>b"
, " </td>"
, " </tr>"
, " </table>"
, " </dd>"
, "</dl>"
));
}
@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(";<b>a</b>:c"
, String_.Concat_lines_nl_skip_last
( "<dl>"
, " <dt><b>a</b>"
, " </dt>"
, " <dd>c"
, " </dd>"
, "</dl>"
));
}
@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
( "<ul>"
, " <li>"
, " <ul>"
, " <li>"
, " <ul>"
, " <li> "
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, "</ul>"
, ""
));
}
@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
( "<ul>"
, " <li> a"
, " <ul>"
, " <li> "
, " <ul>"
, " <li> b"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li> c"
, " </li>"
, "</ul>"
));
}
@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
( "<ol>"
, " <li>a"
, " </li>"
, "</ol>"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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"
, "# <table><tr><td>b</td></tr></table>"
, "c"
), String_.Concat_lines_nl
( "<ol>"
, " <li>a"
, " </li>"
, " <li> "
, " <table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, " </table>"
, " </li>"
, "</ol>"
, "c"
));
}
@Test public void Li_disappears() { // PURPOSE: "\n*" disappears when followed by "<li>"; PAGE:en.w:Bristol_Bullfinch; DATE:2014-06-24
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
( "a"
, "*b<li>"
), String_.Concat_lines_nl_skip_last // NOTE: tag sequence matches MW output
( "a"
, "<ul>"
, " <li>b"
, "<li>"
, "</li>"
, " </li>"
, "</ul>"
));
}
@Test public void Ul_should_end_wlst() { // PURPOSE: </ul> should end wiki_list; PAGE:en.w:Bristol_Bullfinch; DATE:2014-06-24
fxt.Test_parse_page_all_str
( "*a</ul>b"
, String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li>a</ul>b" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22
, " </li>"
, "</ul>"
));
}
@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"
, "<dl>"
, " <dt>c"
, " </dt>"
, "</dl>"
));
}
@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
( "<ul>"
, " <li>a"
, ""
, " <ul>"
, " <li>b"
, " </li>"
, " </ul>"
, " </li>"
, "</ul>"
, ""
, "<pre>c"
, "</pre>"
, ""
, "<ul>"
, " <li>d"
, " </li>"
, "</ul>"
, ""
));
fxt.Init_para_n_();
}
}

View File

@@ -1,92 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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://a<b c]", fxt.tkn_lnke_(0, 13).Lnke_rng_(1, 8).Subs_(fxt.tkn_txt_(8, 10), fxt.tkn_space_(10, 11), fxt.tkn_txt_(11, 12)));
}
@Test public void Brace_xnde_bgn() {// 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
( "[http://b.org<sup>c</sup>]"
, "<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\"><sup>c</sup></a>"
);
}
@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]", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Apos() {
fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "<a href=\"http://www.a.org\" rel=\"nofollow\" class=\"external text\"><i>b</i></a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "<a href=\"http://www.a.org'b\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Nowiki() {
fxt.Test_parse_page_all_str
( "<nowiki>http://a.org</nowiki>"
, "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
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">b <a href=\"/wiki/C\">C</a> d</a>"
));
}
@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]"
, "<a href='/site/commons.wikimedia.org/wiki/%22%3E_A'>B</a>" // '%22%3E' not '">'
);
fxt.Test__parse__wtxt_to_html // encode args
( "[http://commons.wikimedia.org/A?b=%22%3E_C D]"
, "<a href='/site/commons.wikimedia.org/wiki/A?b=%22%3E_C'>D</a>" // '%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]"
, "<a href=\"http://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[http://a.org/A?b=%22%3E_C D]"
, "<a href=\"http://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%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]"
, "<a href=\"https://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[//a.org/A?b=%22%3E_C D]"
, "<a href=\"https://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%22%3E' not '">'
);
}
}

View File

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

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 href='https://www.a.org' rel='nofollow' class='external text'>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]", "<a href='/site/en.wikipedia.org/wiki/'>Wikipedia</a>");
}
@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 href='/site/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 href='/site/en.wikipedia.org/wiki/'>a</a>]");
}
}

View File

@@ -1,97 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</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 = "<a href=\"tel:a\" rel=\"nofollow\" class=\"external free\">tel:a</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 <dd>; 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
( "<dl>"
, " <dt> atel"
, " </dt>"
, " <dd> b"
, " </dd>"
, "</dl>"
));
}
@Test public void Xnde() {// NOTE: compare to Brace_lt
fxt.Test_parse_page_wiki("<span>irc://a</span>"
, 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
( "<ul>"
, " <li><a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>"
, " </li>"
, " <li><a href=\"irc://b\" rel=\"nofollow\" class=\"external free\">irc://b</a>"
, " </li>"
, "</ul>"
));
}
@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 <a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</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
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a><a href=\"/wiki/B\">B</a>"
));
}
@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," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,"); // basic
fxt.Test_parse_page_wiki_str("http://a.org,," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,,"); // many
fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "<a href=\"http://a.org/b,c\" rel=\"nofollow\" class=\"external free\">http://a.org/b,c</a>"); // do not ignore if in middle
fxt.Test_parse_page_wiki_str("http://a.org:" , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>:"); // 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)" , "(<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>)"); // trim=y
fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "<a href=\"http://a.org/b(c)\" rel=\"nofollow\" class=\"external free\">http://a.org/b(c)</a>"); // 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", "<a href=\"http://a.org/b\" rel=\"nofollow\" class=\"external free\">http://a.org/b</a>&quot;c");
}
}

View File

@@ -1,47 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">a</a>] [<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\">b</a>]"
));
}
}

View File

@@ -1,61 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 href='/site/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 href='/site/en.wikipedia.org/wiki/'>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", "<a href='/site/en.wikipedia.org/wiki/Special:Allpages?from=Earth'>http://en.wikipedia.org/wiki/Special:Allpages?from=Earth</a>");
}
@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 href='/site/fr.wikipedia.org/wiki/A' rel='nofollow' class='external text'>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 href='/site/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]", "<a href='http://en.wikipedia.org/w/index.php?title&diff=1&oldid=2' rel='nofollow' class='external text'>abc</a>");
}
@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]", "<a href='mailto:a' rel='nofollow' class='external text'>b</a>");// 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]", "<a href='https://w/b' rel='nofollow' class='external text'>c</a>");// 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&#61;edit&preload&#61;Template:Afd2+starter&editintro&#61;Template:Afd3+starter&title&#61;Wikipedia:Articles+for+deletion/Template_standardisation/demometa]"
// CHANGED: lnke_now decodes html_entities; DATE:2016-10-10
//, "<a href='/site/en.wikipedia.org/wiki/index.php?action=&#61;edit=&preload=&#61;Template:Afd2+starter=&editintro=&#61;Template:Afd3+starter=&title=&='>[1]</a>"
, "<a href='/site/en.wikipedia.org/wiki/Wikipedia:Articles+for+deletion/Template_standardisation/demometa?action=edit&preload=Template:Afd2+starter&editintro=Template:Afd3+starter&title=Wikipedia:Articles+for+deletion/Template_standardisation/demometa'>[1]</a>"
);
}
}

View File

@@ -1,315 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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&amp;b]]"
, "<a href=\"/wiki/A%26b\">a&amp;b</a>"
);
}
@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 href=\"/wiki/A_b\">A b</a>");
}
@Test public void Url_encode_plus() { // PURPOSE:do not decode plus; DATE:2013-08-26
fxt.Test_parse_page_all_str("[[A+b]]", "<a href=\"/wiki/A%2Bb\">A+b</a>");
}
@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 href=\"/wiki/A\">a &amp; b</a>");}
@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
, "<table>"
, " <tr>"
, " <td>d"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<p>a <a href=\"/wiki/B\">c d</a>" // NOTE: this depends on html viewer to collapse multiple spaces into 1
, "</p>"
, ""
));
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
( "<p>a"
, "</p>"
, ""
, "<p>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
, "</p>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Caption_ref() { // PURPOSE: <ref> 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 <ref>c</ref>]]"
), String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"inte" +"rnal\" title=\"Enlarge\"></a></div>b <sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
, " </div>"
, " </div>"
, "</div>"
, ""
));
}
@Test public void Html_ent_pound() {
fxt.Test_parse_page_wiki_str
( "[[A&#35;b|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A#b\">c</a>"
));
}
@Test public void Html_ent_ltr_a() {
fxt.Test_parse_page_wiki_str
( "[[A&#98;|c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/Ab\">c</a>"
));
}
@Test public void Pipe_trick() {
fxt.Test_parse_page_wiki_str("[[Page1|]]" , "<a href=\"/wiki/Page1\">Page1</a>");
fxt.Test_parse_page_wiki_str("[[Help:Page1|]]" , "<a href=\"/wiki/Help:Page1\">Page1</a>");
}
@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|=]]", "<a href=\"/wiki/B\">=</a>");
}
@Test public void Href_encode_anchor() { // PURPOSE: test separate encoding for ttl (%) and anchor (.)
fxt.Test_parse_page_all_str("[[^#^]]", "<a href=\"/wiki/%5E#.5E\">^#^</a>");
}
@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 href=\"/wiki/A%3F\">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 href=\"/wiki/A%3Faction%3Dedit\">A?action=edit</a>");
}
@Test public void Href_question_3() { // PURPOSE.fix: DATE:2014-01-16
fxt.Test_parse_page_all_str("[[A?b]]", "<a href=\"/wiki/A%3Fb\">A?b</a>");
}
@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]]"
, "<a href=\"/site/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\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>");
}
@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
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link__html_ent() {// PURPOSE:html entities should be converted to chars; EX:&nbsp; -> _; DATE:2013-12-16
fxt.Test_parse_page_wiki_str
( "[[File:A.png|link=b&nbsp;c]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/B_c\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
));
}
@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
( "<a href=\"/wiki/File:A_b_%C3%A7.ogg\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
));
}
@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 href=\"/wiki/A#b\">A #b</a>");
}
@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]]", "<a href=\"/wiki/Help:A#b\">Help:A#b</a>");
}
@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 href=\"/wiki/A#b\">A#b</a>");
}
@Test public void Trail_en() {
fxt.Test_parse_page_all_str("[[Ab]]cd e", "<a href=\"/wiki/Ab\">Abcd</a> 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", "<a href=\"/wiki/Ab\">Abçd</a> 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]]" , "<a href=\"/wiki/Src\" class=\"xowa-visited\">Src</a>"); // show [[Src]] as visited since it exists in history
fxt.Test_parse_page_all_str("[[Other]]" , "<a href=\"/wiki/Other\">Other</a>"); // show other pages as not visited
}
}

View File

@@ -1,130 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<p>a"
, "c"
, "</p>"
, ""
));
}
@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
( "<p>a"
, "x "
, "c"
, "</p>"
, ""
));
}
@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
( "<ul>"
, " <li>a"
, " </li>"
, " <li>b"
, " </li>"
, " <li>d"
, " </li>"
, "</ul>"
));
}
@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
( "<ul>"
, " <li> <a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>"
, " </li>"
, "</ul>"
, ""
));
}
@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
( "<ul>"
, " <li>a c"
, " </li>"
, "</ul>"
, ""
));
}
@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
( "<p>"
, "</p>"
));
}
@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
( "<p><a href=\"/wiki/Category:A\">Category:A</a>" // NOTE: technically WP converts to "</a> <a>" not "</a>\n<a>" (via HtmlTidy?)
, "<a href=\"/wiki/Category:B\">Category:B</a>"
, "</p>"
));
}
@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
( "<h2>a</h2>"
, ""
));
}
@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
( "<h2>a</h2>"
, ""
));
}
@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"
, ""
));
}
}

View File

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

View File

@@ -1,95 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 <a>; EX: fr.w:Bordetella;
fxt.Test_parse_page_all_str("[[%GC]]", "<a href=\"/wiki/%25GC\">%GC</a>");
}
@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'']]" , "[[|<i>a</i>]]");
}
@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]'']]" , "[[<i>[a]</i>]]");
}
@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: [[a<b>c</b>|d]] reparse should start at <b>; DATE:2014-03-30
fxt.Test_parse_page_all_str_and_chk("[[a<b>c</b>|d]]" , "[[a<b>c</b>|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"
, "<table>|b]]"
, "</table>"
, ""
), 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]]", "<a href=\"/wiki/A\">-b</a>");
}
@Test public void Nl() { // PURPOSE: invalidate if nl; DATE:2014-04-03
fxt.Test_parse_page_all_str_and_chk("''[[\n]]", "<i>[[</i>\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]]", "<i>[[</i>\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
( "<pre>[[</i>" // NOTE: should be <i> but scan_bwd can't undo previous apos
, "[["
, " |"
, "</pre>"
, ""
, "<p>]]"
, "</p>"
, ""
));
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]]");
}
}

View File

@@ -1,81 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@Test public void Link_blank() {
fxt.Test_parse_page_wiki_str
( "[[File:A.png|12x10px|link=|c]]", String_.Concat_lines_nl_skip_last
( "<img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" />"
));
}
@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
( "<a href=\"http://www.b.org\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"file:///C/B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"https://fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"http://fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"https://a.org?b=http://c.org\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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]]"
, "<a href=\"https://b?c%22%3E\" rel=\"nofollow\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"d\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
@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]]"
, "<a href=\"/wiki/Test_page#b\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
);
}
}

View File

@@ -1,102 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"/site/fr.wikipedia.org/wiki/\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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|20102011 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
( "<a href=\"/site/commons.wikimedia.org/wiki/File:A.png\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"/site/fr.wikipedia.org/wiki/A/b\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
}
@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
( "<a href=\"/site/commons.wikimedia.org/wiki/B\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
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
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
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
( "<a href=\"/site/commons.wikimedia.org/wiki/Special:Search/B\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
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
( "<a href=\"/site/commons.wikimedia.org/wiki/A/B\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
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
( "<a href=\"/site/commons.wikimedia.org/wiki/Test:Commons_main_page\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
fxt.Init_xwiki_clear();
}
}

View File

@@ -1,102 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<p>a"
, "</p>"
, ""
, "<pre>b" // NOTE: pre is ended; " b\n[[" -> <pre>b</pre><div>"
, "</pre>"
, ""
, Html_A_png
, ""
, "<p>c"
, "</p>"
, ""
));
}
@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
( "<p>a"
, "</p>"
, "" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, Html_A_png
, ""
, "<p>b"
, "</p>"
, ""
));
}
@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
( "<p>a"
, "</p>"
, "<div class=\"floatright\">" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a></div>"
, ""
, "<p>b"
, "</p>"
, ""
));
}
@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
( "<p>a"
, "</p>"
, ""
, "<pre> <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>" // NOTE: capture " "; confirmed against MW; DATE:2014-04-14
, "</pre>"
, ""
, "<p>b"
, "</p>"
, ""
));
}
private static final String Html_A_png = String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"0\" height=\"0\" /></a>"
, " <div class=\"thumbcaption\">"
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>"
, " </div>"
, " </div>"
, "</div>"
);
}

View File

@@ -1,61 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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|<b>c|40px]]" , fxt.tkn_lnki_().Width_(40).Height_(-1));
}
@Test public void Ws_para() { // PURPOSE: <p> 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
}
}

View File

@@ -1,66 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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]]", "<a href=\"/wiki//dev/null\">/dev/null</a>");
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 ...]]"
, "<a href=\"/wiki/.../compare_...\">.../compare ...</a>"
);
}
@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 href=\"/wiki/A/c\">A/c</a>"
);
}
@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/]]"
, "<a href=\"/wiki/A/c\">c</a>"
);
}
@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
( "<a href=\"/wiki/A/B\">/B</a>"
));
}
@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
( "<a href=\"/wiki/A/B\">B</a>"
));
}
@Test public void Leaf_w_ncr() { // PURPOSE: /B&#x63; should not encode &#x63; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B&#x63;|B]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/Bc\">B</a>"
));
}
}

View File

@@ -1,58 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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]]]]" , "[[<a href=\"/wiki/Test_1\">Test_1</a>]]");
}
@Test public void Single_bracket() { // PURPOSE: handle [[A|[b]]] PAGE:en.w:Aubervilliers DATE:2014-06-25
fxt.Test_html_full_str("[[A|[B]]]", "<a href=\"/wiki/A\">[B]</a>");
}
@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 href=\"/wiki/A\">A</a>]"); // title only
fxt.Test_parse_page_all_str("[[A|B]]]" , "<a href=\"/wiki/A\">B]</a>"); // title + caption; note that ] should be outside </a> 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]]]"
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
);
}
@Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/00000FFF; DATE:2014-05-05
fxt.Test_parse_page_all_str("[[A|B|C|D]]" , "<a href=\"/wiki/A\">B|C|D</a>");
}
@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]]" , "</div>D\n </div>");
}
@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]]", "<a href=\"/wiki/A\">b|c d e</a>"); // 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("== <i>[[A]]</i> ==", "<h2> <i><a href=\"/wiki/A\">A</a></i> </h2>\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\"");
}
}

View File

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

View File

@@ -1,113 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/12px.png\" width=\"12\" height=\"10\" /></a>"
));
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
( "<a href=\"/site/test.wikimedia.org/wiki/A#b\">test:A#b</a>"
));
}
@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
( "<a href=\"/site/test.wikimedia.org/wiki/\">test:</a>"
));
}
@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
( "<a href=\"/site/test.wikimedia.org/wiki/\">test:</a>"
));
}
@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 href=\"https://test.wikimedia.org/wiki/A\">A</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 href=\"/site/fr.wikipedia.org/wiki/A\">A</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]]"
, "<a href=\"/site/commons.wikimedia.org/wiki/A\">commons:A</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]]"
, "<a href=\"/site/simple.wikipedia.org/wiki/A\">w:A</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);
}
}

View File

@@ -1,100 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("a<!-- b -->c", "ac");
}
@Test public void Err() {
fxt.Init_log_(Xop_comm_log.Eos).Test_parse_page_all_str("<!-- ", "");
}
@Test public void Ws_end() {
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "a"
, "<!-- b --> "
, "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"
, " <!-- b --> "
, "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 <!-- b -->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 <!-<noinclude></noinclude>- 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"
, " <!-- b -->c"
, "d"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, ""
, "<pre>c"
, "</pre>"
, ""
, "<p>d"
, "</p>"
, ""
));
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"
, " <!-- b -->"
, "c"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "c"
, "</p>"
, ""
));
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
( "<p>a"
, "b"
, "</p>"
, ""
));
fxt.Init_para_n_();
}
}

View File

@@ -1,29 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("----" , "<hr/>");}
@Test public void Html_extended() {fxt.Test_parse_page_wiki_str("------" , "<hr/>");}
@Test public void Nl_bgn() {fxt.Test_parse_page_wiki_str("a\n----" , "a\n<hr/>");}
@Test public void Nl_end() {fxt.Test_parse_page_wiki_str("----\na" , "<hr/>\na");}
}

View File

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

View File

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

View File

@@ -1,190 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<h2><span class='mw-headline' id='a'>a</span></h2>"
, ""
, "<h2><span class='mw-headline' id='b'>b</span></h2>"
, ""
, "<h2><span class='mw-headline' id='c'>c</span></h2>"
, ""
, "<h2><span class='mw-headline' id='d'>d</span></h2>"
));
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
( "<p>a"
, "</p>" // NOTE: do not capture " " in front of __NOTOC__; confirmed against MW; DATE:2014-02-19
, ""
, "<p><br/>"
, "</p>"
));
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
( "<p>a"
, "</p>"
, "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
, "</div>"
, ""
, "<h2><span class=\"mw-headline\" id=\"b\">b</span></h2>"
);
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
( "<p>a"
, "</p>" // NOTE: do not capture " "; confirmed against MW; DATE:2014-02-19
, ""
, "<p>b"
, "</p>"
));
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.wikis.pages.htmls.Xopg_html_data html_data = fxt.Page().Html_data();
Tfds.Eq(html_data.Lang_convert_content(), true);
Tfds.Eq(html_data.Lang_convert_title(), true);
fxt.Test_parse_page_all_str("__NOCONTENTCONVERT__ __NOTITLECONVERT__", " ");
Tfds.Eq(html_data.Lang_convert_content(), false);
Tfds.Eq(html_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
( "<p>a"
, "</p>"
, " " // NOTE: \s should not be captured, but leaving for now
, ""
, "<p>b"
, "</p>"
));
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
( "<p>a"
, "</p>"
, ""
, "<p>b"
, "</p>"
));
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
}
}

View File

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

View File

@@ -1,107 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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<pre>c"
, "d</pre>"
, "e"
), String_.Concat_lines_nl_skip_last
( "<pre>a"
, "</pre>"
, "b<pre>c"
, "d</pre>"
, ""
, "<p>e"
, "</p>"
, ""
));
}
@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
( "<dl>"
, " <dd> a"
, ""
, " <ul>"
, " <li> b"
, " </li>"
, " </ul>"
, " </dd>"
, "</dl>"
, ""
, "<dl>"
, " <dd> c"
, ""
, " <ul>"
, " <li> d"
, " </li>"
, " </ul>"
, " </dd>"
, "</dl>"
, ""
));
}
@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
( "<table><tr><td>a"
, "</td>"
, ""
, ""
, ""
, ""
, ""
, "</tr></table>"
)
, String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<p>a"
, "</p>"
, ""
, "<p>b"
, "</p>"
, ""
)
);
}
}

View File

@@ -1,256 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<p>"
, "b"
, "</p>"
));
}
@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
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Ignore_bos_xnde() { // PURPOSE: space at bgn shouldn't create pre; EX:commons.wikimedia.org; " <center>a\n</center>"; DATE:2013-11-28
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( " <center>a" // NOTE: leading " " matches MW; DATE:2014-06-23
, "</center>"
), String_.Concat_lines_nl_skip_last
( " <center>a"
, "</center>"
, ""
));
}
@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"
, ""
, " <gallery>"
, " File:A.png"
, " </gallery>"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, " <ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class=\"thumb\" style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"A.png\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\">"
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
,""
));
gplx.xowa.xtns.gallery.Gallery_mgr_wtr.File_found_mode = Bool_.N_byte;
}
@Test public void Pre_xnde_gallery() { // PURPOSE: <gallery> 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
( " <gallery>"
, "File:A.png|b"
, "</gallery>"
);
fxt.Test_parse_page_wiki_str(raw, String_.Concat_lines_nl_skip_last
( " <ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">" // NOTE: leading " " matches MW; DATE:2014-06-23
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class=\"thumb\" style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p>b"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
));
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"
, " <center>b"
, " </center>"
, "d"
), String_.Concat_lines_nl_skip_last
( "<p>a"
, "</p>"
, " <center>b"
, " </center>"
, ""
, "<p>d"
, "</p>"
)
);
}
@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
( "<pre> a"
, " b"
, " c"
, "</pre>"
)
);
}
@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
( ""
, "<pre> a"
, " b"
, "</pre>"
)
);
}
@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
( "<pre>a"
, "|"
, "b"
, "</pre>"
)
);
}
@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
( "<pre>\ta"
, "</pre>"
));
}
@Test public void Style() { // PURPOSE: " <style>" was not being put in pre; PAGE:en.w:Cascading_Style_Sheets DATE:2014-06-23
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
( " <style>"
, " </style>"
), String_.Concat_lines_nl
( "<pre>&lt;style>"
, "&lt;/style>"
, "</pre>"
));
}
@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
( "<pre>a"
, "" // make sure it's still there
, "b"
, "</pre>"
));
}
@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
( "<pre>a"
, " " // 1 space
, "b"
, "</pre>"
));
}
@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
( "<pre>a"
, ""
, "b"
, ""
, "c"
, "</pre>"
));
}
@Test public void Source() { // PURPOSE: " <source>" 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
( " "
, " <source>"
, " a"
, " </source>"
, " "
), String_.Concat_lines_nl
( "<p>" // this is wrong, but will be stripped by tidy
, "</p>"
, " <div class=\"mw-highlight\"><pre style=\"overflow:auto\">"
, " a"
, "</pre></div>"
, ""
, "<p><br/>" // also wrong, but leave for now
, "</p>"
));
}
@Test public void False_match_xnde() { // PURPOSE: "\s<trk>" being evaluted as "\s<tr>"; PAGE:de.v:Via_Jutlandica/Gpx DATE:2014-11-29
fxt.Init_para_y_();
fxt.Test_html_wiki_str(String_.Concat_lines_nl
( ""
, " <trk>"
), String_.Concat_lines_nl
( ""
, "<pre>&lt;trk&gt;"
, "</pre>"
));
}
}

View File

@@ -1,210 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<table>"
, " <tr>"
, " <td>"
, " <table>"
, " <tr>"
, " <td id='1'>"
, " </td>"
, " <td id='2'>a"
, " </td>"
, " <td id='3'>"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
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
( "<table id='1'>"
, " <caption id='2'>a"
, " </caption>"
, "</table>"
, ""
)
);
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|<small>Indic</small><br/><small>0800*</small><br/>'''''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
( "<table>"
, " <tr>"
, " <td bgcolor=\"#eeeeee\">a"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
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'<p></p>"
, "|a"
, "|}"), String_.Concat_lines_nl_skip_last
( "<table id='1'><p></p>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "{|"
, "|-<b>c</b>id='d'<br/>" // note that id='d' should not show up since <b> invalidates entire line
, "|a"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Xnde_mix_tblw_tblx() { // PURPOSE: issue with </tr> somehow rolling up everything after <td>; PAGE:en.w:20th_century; {{Decades and years}}
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table><tr><td>a"
, "{|id=1"
, "|-"
, "|b"
, "|}</td></tr></table>"
)
, String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " <table id=\"1\">"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
}

View File

@@ -1,812 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<table id='1' class='a'>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "{|"
, "|-"
, "<tr><td>a</td></tr>"
, "|-"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Tr_dupe_xnde_2() { // <td></th> causes problems
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "<tr><th>a</td></tr>"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <th>a"
, " </th>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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("<table>", " <tr>", " <td>a!b" , " </td>", " </tr>", "</table>", ""));
}
@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("<table>", " <tr>", " <td>a!!b" , " </td>", " </tr>", "</table>", ""));
}
@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("<table>", " <tr>", " <th>a!b" , " </th>", " </tr>", "</table>", ""));
}
@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
( "<table>"
, " <tr>"
, " <th>a"
, " </th>"
, " <th>b"
, " </th>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<table>"
, " <tr>"
, " <th>a"
, " </th>"
, " <th>b"
, " </th>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<table>"
, " <tr>"
, " <th id='1'>a"
, " </th>"
, " <td>"
, " </td>"
, " <th id='2'>b"
, " </th>"
, " </tr>"
, " <tr>"
, " <td>a1"
, " </td>"
, " <td> "
, " </td>"
, " <td>b1"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
@Test public void Nl_td() { // PURPOSE: <p> inside <td> does not get enclosed
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, "<tr>"
, "<td>"
, ""
, ""
, "a"
, ""
, ""
, "</td>"
, "</tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, ""
, "<p><br/>"
, "a"
, "</p>"
, ""
, "<p><br/>"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
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
( "<table>"
, "<tr>"
, "<td>"
, "</td>"
, "</tr>"
, ""
, ""
, "a"
, ""
, ""
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "a"
, "</table>"
, ""
)
);
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
( "<table>"
, "<tr>"
, "<td>"
, "</td>"
, "</tr>"
, ""
, ""
, ""
, ""
, "<tr>"
, "<td>"
, "</td>"
, "</tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
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
( "<table>"
, "<tr>"
, "<td>"
, ""
, ""
, "a"
, ""
, ""
, "</td>"
, "</tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, ""
, "<p><br/>"
, "a"
, "</p>"
, ""
, "<p><br/>"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
@Test public void No_wiki_3() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|style=<nowiki>'a[b]c'</nowiki>|d"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td style='a[b]c'>d"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
, "<p>b"
, "</p>"
, ""
, "<p>c"
, "</p>"
, ""
));
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
( "<table>"
, " <tr>"
, " <td>a"
, ""
, "<p>b"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
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
( "<table>"
, " <tr>"
, " <td>a"
, ""
, "<p>b"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
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("'''<table><tr><td>a</td></tr></table>", String_.Concat_lines_nl_skip_last
( "<b></b>"
, "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
fxt.Init_defn_clear();
}
@Test public void Orphaned_tr_breaks_nested_tables() { // PUPRPOSE: </tr> should not match <tr> outside scope; EX:w:Enthalpy_of_fusion; {{States of matter}}
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<table>"
, "<tr>"
, "<td>"
, "<table>"
, "</tr>"
, "</table>"
, "</td>"
, "<td>a"
, "</td>"
, "</tr>"
, "</table>"
),
String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, " <table>"
, " </table>"
, " </td>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Space_causes_extra_p() {// PURPOSE: "\n\s</td>" should be equivalent to "\n</td>"; EX: w:Earth
fxt.Init_para_y_();
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<table><tr><td>"
, "b"
, "<br/>c"
, " </td></tr></table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, ""
, "<p>b" // used to close <p> here; <p>b</p>
, "<br/>c"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Br_should_not_be_ignored() {// PURPOSE: document <br />'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"
, "|}"
, "<br />"
, "{|"
, "|-"
, "|b"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, "<br />" // was being ignored
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
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
( "<table>"
, ""
, "<h2>a</h2>" // NOTE: malformed html matches MW
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@Test public void Auto_create_table() {// PURPOSE: <td> should create table; EX:w:Hatfield-McCoy_feud; DATE:20121226
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<td>a"
, "</td>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<ul>"
, " <li>a !! b"
, " </li>"
, "</ul>"
));
}
@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
( "<table>"
, " <tr style='a'>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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
( "<table>"
, " <tr>"
, " <td>"
, "a!!b"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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
( "{|"
, "|-"
, "| <poem>!!</poem>" // note that "!!" is eos inside the <poem> src
, "|}"
), String_.Concat_lines_nl
( "<table>"
, " <tr>"
, " <td> <div class=\"poem\">"
, "<p>"
, "!!"
, "</p>"
, "</div>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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("<tr><td>a"
, String_.Concat_lines_nl
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Tblx_should_not_close_tblw() {// PURPOSE: </table> 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
( "{|"
, "|-"
, "|"
, "</table>"
, "|}"
)
, String_.Concat_lines_nl
( "<table>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Tblx_should_not_close_tblw_2() {// PURPOSE: </table> should close {|; ignore latter |}; EX:ru.q:Авель; DATE:2014-02-22
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "|a"
, "</table>"
, "{|"
, "|-"
, "|b"
, "</table>"
, "{|"
, "|-"
, "|c"
, "</table>"
, "|}"
)
, String_.Concat_lines_nl
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, "<table>"
, " <tr>"
, " <td>c"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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
( "<table>"
, " <tr>"
, " <td>"
, " <ul>"
, " <li> a || b"
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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
( "<table>"
, " <tr>"
, " <td>"
, " <table>"
, " <ul>" // NOTE: this should probably be inside <tr>, but this matches MW behavior; DATE:2014-02-22
, " <li>a"
, " </li>"
, " </ul>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
}
// @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
// ( "<table>"
// , " <tr id=\"b\">"
// , " <td>b"
// , " </td>"
// , " </tr>"
// , "</table>"
// , ""
// ));
// }
// @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: <p> 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
// ( "<table>"
// , " <tr>"
// , " <td>"
// , ""
// , "<p>a"
// , "</p>"
// , " </td>"
// , " </tr>"
// , "</table>"
// , ""
// ));
// 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
// ( "<table id='1'>"
// , " <tr id='3'>"
// , " <td>a"
// , " </td>"
// , " </tr>"
// , "</table>"
// , ""
// ));
// }
// @Test public void Tb_tb_2() {
// fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
// ( "{|id='1'"
// , "{|id='2' <table id='3'>"
// , "|a"
// , "</table>"
// , "|}"
// , "|}"), String_.Concat_lines_nl_skip_last
// ( "<table id='1'>"
// , " <tr id='3'>"
// , " <td>a"
// , " </td>"
// , " </tr>"
// , "</table>"
// , ""
// ));
// }

View File

@@ -1,55 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 </xnde>; PAGE:en.w:Atlanta_Olympics; DATE:2014-03-18
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<div align='center'>"
, "{|"
, "|-"
, "|"
, "{|"
, "|-"
, "|a"
, "|}"
, "</div>"
, "b"
)
, String_.Concat_lines_nl
( "<div align='center'>"
, "<table>"
, " <tr>"
, " <td>"
, " <table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " </table>"
, "</div>" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22
, ""
, "<p>b"
, " </td>"
, " </tr>"
, "</table>"
, "</div>"
, "</p>"
));
}
}

View File

@@ -1,106 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<p><a href=\"/wiki/A\">b|c</a>" // NOTE: technically this should be "|b|c", but difficult to implement; DATE:2014-05-06
, "</p>"
, ""
));
}
@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
( "<table>"
, " <tr>"
, " <td><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <td>"
, ""
, " <ul>"
, " <li><a href=\"/wiki/A\">b</a>" // NOTE: technically this should be "|b", but difficult to implement; DATE:2014-05-06
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <td>"
, ""
, "<p><a href=\"/wiki/A!!b\">A!!b</a>"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <ul>"
, " <li> a !! b"
, " </li>"
, " </ul>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "</table>"
, "</p>" // NOTE: </p> is incorrect, but benign
)
);
}
}

View File

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

View File

@@ -1,163 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<table id='a'>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " <tr>"
, " <td id='b'>"
, " <table id='c'>"
, " <tr>"
, " <td>d"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
@Test public void Tblx_tblw() { // PURPOSE: if <table> 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
( "<table cellpadding=\"0\">"
, "{| cellspacing=\"0\""
, "|a"
, "|}"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table cellpadding=\"0\">"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@Test public void Caption_and_tblw() { // TIDY: don't try to fix <caption><table> 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
( "<table>"
, " <caption>"
, " <table>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, " </table>"
, " </caption>"
, "</table>"
, ""
));
}
@Test public void Tb_tr_tb() { // PURPOSE: if <tr><table>, auto-create <tr><td>; 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
( "<table>"
, " <tr>"
, " <table>"
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, " </table>"
, " </tr>"
, "</table>"
, ""
));
}
// @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
// ( "<table>"
// , " <tr>"
// , " <td>a"
// , " </td>"
// , " <td>[[b|c"
// , " </td>"
// , " </tr>"
// , "</table>"
// , ""
// , "<p>d"
// , "</p>"
// ));
// }
}

View File

@@ -1,154 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "{|"
, "<p></p>"
, "|a"
, "<p></p>"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table><p></p>"
, " <tr>"
, " <td>a"
, "<p></p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <th>a"
, " </th>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Unnecessary_para() { // PURPOSE: tblw causes unnecessary <p>; home/wiki/Dashboard/Image_databases; DATE:2014-02-20
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "|"
, "a<br/>"
, "b"
, "|"
, "c<br/>"
, "d"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, ""
, "<p>a<br/>"
, "b"
, "</p>"
, " </td>"
, " <td>"
, ""
, "<p>c<br/>"
, "d"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <th>a"
, " </th>"
, " <th>b"
, " </th>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " <th style=\"color:blue\">b"
, " </th>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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
( "<table>"
, " <tr>"
, " <th id='1'> a "
, " </th>"
, " <th id='2'> b"
, " </th>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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", "<p>a||b\n</p>");
}
}

View File

@@ -1,152 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 <table>; EX:ru.w:Сочи; DATE:2014-02-22
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, "| b"
, " </td>"
, " </tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, "| b"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Ignore_tr() { // PURPOSE: do not parse "\n|-", "\n!" if in <table>; EX:s.w:Uranus; DATE:2014-05-05
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, "|-"
, "! b"
, "| c"
, " </td>"
, " </tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, ""
, "<p>|-"
, "! b"
, "| c"
, "</p>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Tblw_tblx_tblw_fails() { // PURPOSE: {| -> <table> -> \n| was not rendering as <td>; PAGE:en.w:Paris#Demographics; DATE:2014-03-18
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "|a"
, "</td></tr>"
, "<tr><td><table>"
, "<tr><td>b</td>"
, "</tr>"
, "|c"
, "</td></tr></table>"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>"
, " <table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>c"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Auto_tr_after_td() { // PURPOSE: "<tr><td>\n|" -> "<tr><td><tr><td>"; PAGE:fi.w:Salibandyn_maailmanmestaruuskilpailut_2012 DATE:2015-09-07
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, " <tr>"
, " <td>a"
, " </td>"
, " <td>"
, "|b"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " <td>" // NOTE: dangling <td> from above just gets auto-closed; no logic in tblw_wkr to actually remove it
, " </td>"
, " </tr>"
, " <tr>" // <tr> inserted by transition from <td> to "\n|"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@Test public void Ignore_tr_in_lnki() { // PURPOSE: <tr> 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
( "<table>"
, "<tr>"
, "<td>[[A|B<tr><td>t_1</td></tr>]]"
, "</td>"
, "</tr>"
, "</table>"
) , String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td><a href=\"/wiki/A\">B"
, " <tr>"
, " <td>t_1"
, " </td>"
, " </tr>"
, "</a>"
, " </td>"
, " </tr>"
, "</table>"
));
}
}

View File

@@ -1,127 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "{|"
, "<caption>a"
, "|b"
, "|-"
, "|c"
, "|}"
)
, String_.Concat_lines_nl
( "<table>"
, " <caption>a"
, " </caption>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>c"
, " </td>"
, " </tr>"
, "</table>"
));
}
@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<b\""
, "|a"
, "|}"), String_.Concat_lines_nl_skip_last
( "<table id=\"a.3Cb\">"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " <td>[[b|c"
, " </td>"
, " </tr>"
, "</table>"
, ""
, "<p>d"
, "</p>"
));
}
@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
( "<table>"
, " <tr>"
, " <td> [[A | b"
, " </td>"
, " </tr>"
, " <tr>"
, " <td> B"
, " </td>"
, " </tr>"
, "</table>"
));
}
@Test public void Tr_with_pipe_ignores_content() { // PURPOSE: "|-" followed by "|" ignores rest of content; EX: {|\n|-|<b>a</b>\n|} PAGE:lv.w:Starptautiska_kosmosa_stacija; DATE:2015-11-21
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "{|"
, "|- |<b>a</b>"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, "</table>"
));
}
@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
( "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
));
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,129 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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]]&#32;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]]&#32;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.&#32;&#32;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.&#32;&#32;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|}}}|,&#32;|&#32;and&#32;}}[[{{{2}}}|{{{l2|{{{2}}}}}}]]}}{{#if:{{{3|}}}"
, " |{{#if:{{{4|}}}|,&#32;|,&#32;and&#32;}}[[{{{3}}}|{{{l3|{{{3}}}}}}]]}}{{#if:{{{4|}}}"
, " |{{#if:{{{5|}}}|,&#32;|,&#32;and&#32;}}[[{{{4}}}|{{{l4|{{{4}}}}}}]]}}{{#if:{{{5|}}}"
, " |{{#if:{{{6|}}}|,&#32;|,&#32;and&#32;}}[[{{{5}}}|{{{l5|{{{5}}}}}}]]}}{{#if:{{{6|}}}"
, " |{{#if:{{{7|}}}|,&#32;|,&#32;and&#32;}}[[{{{6}}}|{{{l6|{{{6}}}}}}]]}}{{#if:{{{7|}}}"
, " |{{#if:{{{8|}}}|,&#32;|,&#32;and&#32;}}[[{{{7}}}|{{{l7|{{{7}}}}}}]]}}{{#if:{{{8|}}}"
, " |{{#if:{{{9|}}}|,&#32;|,&#32;and&#32;}}[[{{{8}}}|{{{l8|{{{8}}}}}}]]}}{{#if:{{{9|}}}"
, " |{{#if:{{{10|}}}|,&#32;|,&#32;and&#32;}}[[{{{9}}}|{{{l9|{{{9}}}}}}]]}}{{#if:{{{10|}}}"
, " |, and [[{{{10}}}|{{{l10|{{{10}}}}}}]]}}{{#if:{{{11| }}}|&#32; (too many parameters in &#123;&#123;[[Template:main|main]]&#125;&#125;)}}"
));
}
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}}}]]}}|&#32;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}}}.&#32;&#32;}}<!--"
, "-->For {{#if:{{{2|}}}|{{{2}}}|other uses}}, see {{#if:{{{3|}}}|[[{{{3}}}]]{{#ifeq:{{{4|}}}|and|&#32;and {{#if:{{{5|}}}|[[{{{5}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.<!--"
, "-->{{#if:{{{2|}}}|{{#if:{{{4|}}}|<!--"
, " -->{{#ifeq:{{{4|}}}|and||<!-- 'and' is a special word, don't output 'For and, ...'"
, " -->&#32;&#32;For {{#ifeq:{{{4}}}|1|other uses|{{{4}}}}}, see {{#if:{{{5|}}}|[[{{{5}}}]]{{#ifeq:{{{6|}}}|and|&#32;and {{#if:{{{7|}}}|[[{{{7}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.}}<!--"
, " -->{{#if:{{{6|}}}|<!--"
, " -->{{#ifeq:{{{6|}}}|and||<!--"
, " -->&#32;&#32;For {{#ifeq:{{{6}}}|1|other uses|{{{6}}}}}, see {{#if:{{{7|}}}|[[{{{7}}}]]{{#ifeq:{{{8|}}}|and|&#32;and {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{PAGENAME}} (disambiguation)]]}}}}|[[{{PAGENAME}} (disambiguation)]]}}.}}<!--"
, " -->{{#if:{{{8|}}}|<!--"
, " -->{{#ifeq:{{{8|}}}|and||<!--"
, " -->&#32;&#32;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<includeonly>|</includeonly>}}} |<!--then:-->[[{{{1}}}{{#if:{{{label 1|{{{l1|}}}}}}|{{!}}{{{label 1|{{{l1}}}}}}}}]] |<!--else:-->'''Error: [[Template:See also|Template must be given at least one article name]]'''"
, "}}{{#if:{{{2|}}}|{{#if:{{{3|}}}|, |&nbsp;and }} [[{{{2}}}{{#if:{{{label 2|{{{l2|}}}}}}|{{!}}{{{label 2|{{{l2}}}}}}}}]]"
, "}}{{#if:{{{3|}}}|{{#if:{{{4|}}}|, |,&nbsp;and }} [[{{{3}}}{{#if:{{{label 3|{{{l3|}}}}}}|{{!}}{{{label 3|{{{l3}}}}}}}}]]"
, "}}{{#if:{{{4|}}}|{{#if:{{{5|}}}|, |,&nbsp;and }} [[{{{4}}}{{#if:{{{label 4|{{{l4|}}}}}}|{{!}}{{{label 4|{{{l4}}}}}}}}]]"
, "}}{{#if:{{{5|}}}|{{#if:{{{6|}}}|, |,&nbsp;and }} [[{{{5}}}{{#if:{{{label 5|{{{l5|}}}}}}|{{!}}{{{label 5|{{{l5}}}}}}}}]]"
, "}}{{#if:{{{6|}}}|{{#if:{{{7|}}}|, |,&nbsp;and }} [[{{{6}}}{{#if:{{{label 6|{{{l6|}}}}}}|{{!}}{{{label 6|{{{l6}}}}}}}}]]"
, "}}{{#if:{{{7|}}}|{{#if:{{{8|}}}|, |,&nbsp;and }} [[{{{7}}}{{#if:{{{label 7|{{{l7|}}}}}}|{{!}}{{{label 7|{{{l7}}}}}}}}]]"
, "}}{{#if:{{{8|}}}|{{#if:{{{9|}}}|, |,&nbsp;and }} [[{{{8}}}{{#if:{{{label 8|{{{l8|}}}}}}|{{!}}{{{label 8|{{{l8}}}}}}}}]]"
, "}}{{#if:{{{9|}}}|{{#if:{{{10|}}}|, |,&nbsp;and }} [[{{{9}}}{{#if:{{{label 9|{{{l9|}}}}}}|{{!}}{{{label 9|{{{l9}}}}}}}}]]"
, "}}{{#if:{{{10|}}}|{{#if:{{{11|}}}|, |,&nbsp;and }} [[{{{10}}}{{#if:{{{label 10|{{{l10|}}}}}}|{{!}}{{{label 10|{{{l10}}}}}}}}]]"
, "}}{{#if:{{{11|}}}|{{#if:{{{12|}}}|, |,&nbsp;and }} [[{{{11}}}{{#if:{{{label 11|{{{l11|}}}}}}|{{!}}{{{label 11|{{{l11}}}}}}}}]]"
, "}}{{#if:{{{12|}}}|{{#if:{{{13|}}}|, |,&nbsp;and }} [[{{{12}}}{{#if:{{{label 12|{{{l12|}}}}}}|{{!}}{{{label 12|{{{l12}}}}}}}}]]"
, "}}{{#if:{{{13|}}}|{{#if:{{{14|}}}|, |,&nbsp;and }} [[{{{13}}}{{#if:{{{label 13|{{{l13|}}}}}}|{{!}}{{{label 13|{{{l13}}}}}}}}]]"
, "}}{{#if:{{{14|}}}|{{#if:{{{15|}}}|, |,&nbsp;and }} [[{{{14}}}{{#if:{{{label 14|{{{l14||}}}}}}|{{!}}{{{label 14|{{{l14}}}}}}}}]]"
, "}}{{#if:{{{15|}}}|,&nbsp;and [[{{{15}}}{{#if:{{{label 15|{{{l15}}}}}}|{{!}}{{{label 15|{{{l15}}}}}}}}]]"
, "}}{{#if:{{{16|}}}| &mdash; '''<br/>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|&#32;and {{#if:{{{5|}}}|[[{{{5}}}]]|[[{{{1}}} (disambiguation)]]}}}}|[[{{{1}}} (disambiguation)]]}}.<!--"
, "-->{{#if:{{{2|}}}|{{#if:{{{4|}}}|<!--"
, " -->{{#ifeq:{{{4|}}}|and||<!-- \"and\" is a special word, don't output \"For and, ...\""
, " -->&#32;&#32;For {{#ifeq:{{{4}}}|1|other uses|{{{4}}}}}, see {{#if:{{{5|}}}|[[{{{5}}}]]{{#ifeq:{{{6|}}}|and|&#32;and {{#if:{{{7|}}}|[[{{{7}}}]]|[[{{{4}}} (disambiguation)]]}}}}|[[{{{4}}} (disambiguation)]]}}.}}<!--"
, " -->{{#if:{{{6|}}}|<!--"
, " -->{{#ifeq:{{{6|}}}|and||<!--"
, " -->&#32;&#32;For {{#ifeq:{{{6}}}|1|other uses|{{{6}}}}}, see {{#if:{{{7|}}}|[[{{{7}}}]]{{#ifeq:{{{8|}}}|and|&#32;and {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{{6}}} (disambiguation)]]}}}}|[[{{{6}}} (disambiguation)]]}}.}}<!--"
, " -->{{#if:{{{8|}}}|<!--"
, " -->{{#ifeq:{{{8|}}}|and||<!--"
, " -->&#32;&#32;For {{#ifeq:{{{8}}}|1|other uses|{{{8}}}}}, see {{#if:{{{9|}}}|[[{{{9}}}]]|[[{{{8}}} (disambiguation)]]}}.}}<!--"
, " -->}}<!--"
, " -->}}<!--"
, "-->}}}}"
));
}
}

View File

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

View File

@@ -1,438 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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<!--a-->}}" , "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("<div <nowiki>class='a'</nowiki> />" , "{{test}}" , "<div <nowiki>class='a'</nowiki> />");
}
@Test public void Nowiki_if() { // PURPOSE: templates and functions inside nowiki should not be evaluated
fxt.Test_parse_tmpl_str_test("a <nowiki>{{#if:|y|n}}</nowiki> b" , "{{test}}" , "a <nowiki>{{#if:|y|n}}</nowiki> b");
}
@Test public void Nowiki_endtag() { // PURPOSE: <nowiki/> should not match </nowiki>
fxt.Test_parse_page_all_str("<nowiki /> ''b'' <nowiki>c</nowiki>" , " <i>b</i> 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("<nowiki><pre></nowiki>{{#expr:1}}<pre>b</pre>" , "&lt;pre&gt;1<pre>b</pre>");
}
@Test public void Nowiki_lnki() { // PURPOSE: nowiki should noop lnkis; DATE:2013-01-27
fxt.Test_parse_page_all_str("<nowiki>[[A]]</nowiki>" , "[[A]]");
}
@Test public void Nowiki_underscore() { // PURPOSE: nowiki did not handle __DISAMBIG__; DATE:2013-07-28
fxt.Test_parse_page_all_str("<nowiki>__DISAMBIG__</nowiki>" , "__DISAMBIG__");
}
@Test public void Nowiki_asterisk() { // PURPOSE: nowiki should noop lists; DATE:2013-08-26
fxt.Test_parse_page_all_str("<nowiki>*a</nowiki>", "*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<nowiki> </nowiki>b", "<p>a\n b\n</p>\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"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
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|a<source>1</source>b}}", "a<div class=\"mw-highlight\"><pre style=\"overflow:auto\">1</pre></div>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: <ref name= should not be interpreted as arg; EX: {{tmp|a<ref name="b"/>}}; arg1 is a<ref name="b"/> 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<ref name=b />}}", "a<ref name=b />");
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
( "{|"
, "|-"
, "|<nowiki>{{ #time:M|Jan}}</nowiki>"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>{{ #time:M|Jan}}"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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("{{!}}", "|");
}
}

View File

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

View File

@@ -1,119 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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" , "<blockquote>{{{1}}}</blockquote>");
fxt.Test_html_full_str("a\n{{blockquote|{{cquote}}}}"
, String_.Concat_lines_nl_skip_last
( "a"
, "<blockquote>"
, "<ul>"
, " <li>b"
, " </li>"
, "</ul></blockquote>"
)
);
}
@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;
*/

View File

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

View File

@@ -1,54 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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", "<gallery>A.png|a{{/Leaf}}b</gallery>"); // NOTE: gallery neeeded for XOWA to fail; MW fails if just {{/Leaf}}
fxt.Test_parse_page("Root", "<gallery>A.png|a{{/Leaf}}b</gallery>");
}
@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
}
}

View File

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

View File

@@ -1,79 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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(240563374, 22728940, 1451248133));
fxt.Test__uniq_bry_new("UNIQE56B4AE15AD0EC68");
fxt.Init_random_int_ary(Int_.Ary(1363621437, 426295411, 421041101));
fxt.Test__uniq_bry_new("UNIQ147363D968C07391");
}
@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(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.Convert(Bry_.new_a7(raw))), "convert");
}
}

View File

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

View File

@@ -1,84 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 &amp; B]]", "A & B");} // PURPOSE: &amp; -> &; 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 href=\"/wiki/A_B?redirect=no\" title=\"A B\">A B</a>)");
}
}
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));
}
}

View File

@@ -1,41 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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&lt;b" , "a<b");}
@Test public void Amp_ncr_dec_pass() {fxt.tst_Escape_id("a&#33;b" , "a!b");}
@Test public void Amp_ncr_dec_fail() {fxt.tst_Escape_id("a&#33x;b" , "a&#33x;b");}
@Test public void Amp_ncr_hex_pass() {fxt.tst_Escape_id("a&#x21;b" , "a!b");}
}
class Xop_sanitizer_fxt {
public Xop_sanitizer sanitizer;
public void Clear() {
if (sanitizer != null) return;
sanitizer = new Xop_sanitizer(Xop_amp_mgr.Instance, new Gfo_msg_log(Xoa_app_.Name));
}
public void tst_Escape_id(String raw, String expd) {
byte[] raw_bry = Bry_.new_u8(raw);
Tfds.Eq(expd, String_.new_u8(sanitizer.Escape_id(raw_bry)));
}
}

View File

@@ -1,100 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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__html__tst { // REF: https://www.mediawiki.org/wiki/Writing_systems/Syntax
private final Vnt_convert_lang_fxt fxt = new Vnt_convert_lang_fxt();
private String rule;
@Before public void init() {
rule = "-{H|zh-cn:cn;zh-hk:hk;zh-tw:tw}-";
fxt.Clear();
}
@Test public void Node() {
fxt.Test_parse(rule + "hk<span>hk</span>hk", "cn<span>cn</span>cn");
}
@Test public void Attribs() {
fxt.Test_parse(rule + "<span class='hk'>hk</span>", "<span class='hk'>cn</span>");
}
@Test public void Attribs__title() {
fxt.Test_parse(rule + "<span title='hk'>hk</span>", "<span title='cn'>cn</span>");
}
@Test public void Attribs__alt() {
fxt.Test_parse(rule + "<span alt='hk'>hk</span>", "<span alt='cn'>cn</span>");
}
@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 + "<img id='hk' alt='hk-{hk}-hk' src='hk'>", "<img id='hk' alt='cnhkcn' src='hk'>");
}
@Test public void Attribs__skip_url() {
fxt.Test_parse(rule + "<span alt='http://hk.org'>hk</span>", "<span alt='http://hk.org'>cn</span>");
}
@Test public void Node__script() {
fxt.Test_parse(rule + "hk<script>hk</script>hk", "cn<script>hk</script>cn");
}
@Test public void Node__code() {
fxt.Test_parse(rule + "hk<code>hk</code>hk", "cn<code>hk</code>cn");
}
@Test public void Node__pre() {
fxt.Test_parse(rule + "hk<pre>hk</pre>hk", "cn<pre>hk</pre>cn");
}
@Test public void Node__pre__nested() {
fxt.Test_parse(rule + "hk<pre><span>hk</span></pre>hk", "cn<pre><span>hk</span></pre>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", "&nbsp;nbsp-cn");
}
@Test public void Entity__atr() {
fxt.Test_parse("-{H|zh-cn:nbsp-cn;zh-hk:nbsp;}-" + "<div title='nbsp&nbsp;nbsp'/>" , "<div title='nbsp-cn&nbsp;nbsp-cn'/>");
}
@Test public void Node__example() {
fxt.Test_parse(rule + String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "|A<br />"
, "|B<br/>"
, "<span style=''>-{zh-hans:C;zh-hant:D;}-</span>"
, "|}")
, String_.Concat_lines_nl_skip_last
( "{|"
, "|-"
, "|A<br />"
, "|B<br/>"
, "<span style=''>C</span>"
, "|}"
));
}
@Test public void Attribs__title__w_vnt() {
fxt.Init_cur("zh-tw");
fxt.Test_parse("<span title=\"-{zh-cn:cn;zh-hant:hk;}-cn\" style=\"color:red;\">cn</span>", "<span title=\"hkcn\" style=\"color:red;\">cn</span>"); // cn not converted to hk
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,73 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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;
private Mwh_atr_itm atr_itm = new Mwh_atr_itm(null, false, false, false, -1, -1, -1, -1, null, -1, -1, null, -1, 0);
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) {
byte[] key_bry = Bry_.new_a7(key_str);
// atr_itm.Key_rng_(0, key_bry.length);
atr_itm.Key_bry_(key_bry);
Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, key_bry, atr_itm), key_str);
}
public void Whitelist(int tag_id, String key_str, String val_str, boolean expd) {
byte[] key_bry = Bry_.new_a7(key_str);
// atr_itm.Key_rng_(0, key_bry.length);
atr_itm.Key_bry_(key_bry);
atr_itm.Val_bry_(Bry_.new_a7(val_str));
Tfds.Eq(expd, whitelist_mgr.Chk(tag_id, key_bry, 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);
atr_itm.Val_bry_(val_bry);
whitelist_mgr.Scrub_style(atr_itm, val_bry);
Tfds.Eq(expd, String_.new_a7(atr_itm.Val_bry()));
}
}

View File

@@ -1,151 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("a<code><?</code>b", String_.Concat_lines_nl_skip_last
( "<p>a<code>&lt;?</code>b"
, "</p>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Inline() {
fxt.Test_parse_page_wiki("<ref/>" , fxt.tkn_xnde_(0, 6).CloseMode_(Xop_xnde_tkn.CloseMode_inline).Name_rng_(1, 4));
}
@Test public void Pair() {
fxt.Test_parse_page_wiki("<div></div>", 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("<div>b</div>", fxt.tkn_xnde_(0, 12).Subs_(fxt.tkn_txt_(5, 6)));
}
@Test public void Deep1_pair1() {
fxt.Test_parse_page_wiki("<div><div></div></div>", 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("<div><ref/></div>", 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("<div><div></div><div></div></div>", 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("<div><div><div></div></div></div>", 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("<ref / >a</ref>", fxt.tkn_xnde_(0, 15).Atrs_rng_(5, 7).Subs_(fxt.tkn_txt_(8, 9)));
fxt.Test_parse_page_wiki("<ref name=a/b/>", 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("<div></span></div>", 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("<math><div></math>", 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("<ref name=\"a\">b</ref>", 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<br/>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("</br>a" , fxt.tkn_xnde_(0, 5), fxt.tkn_txt_(5, 6));
fxt.Test_parse_page_wiki("<br/>a" , fxt.tkn_xnde_(0, 5), fxt.tkn_txt_(5, 6));
fxt.Test_parse_page_wiki("</br/>a" , fxt.tkn_xnde_(0, 6), fxt.tkn_txt_(6, 7));
}
@Test public void CaseSensitivity() {
fxt.Test_parse_page_wiki("<DiV></dIv>", 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
( "<Inputbox>a</Inputbox>b<inputbox>c</inputbox>"
, "b"
);
}
@Test public void CaseSensitivity_xtn_2() { // PURPOSE: xtn end_tag may not match bgn_tag; EX: w:Ehrenfest_paradox; <References></references>
fxt.Test_parse_page_all_str("a<ref name=b /><References><ref name=b>c</ref></references>", String_.Concat_lines_nl
( "a<sup id=\"cite_ref-b_0-0\" class=\"reference\"><a href=\"#cite_note-b-0\">[1]</a></sup><ol class=\"references\">"
, "<li id=\"cite_note-b-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-b_0-0\">^</a></span> <span class=\"reference-text\">c</span></li>"
, "</ol>"
));
}
@Test public void CaseSensitivity_xtn_3() {// PURPOSE: xtn xnde must do case-insensitive match DATE:2013-12-02
fxt.Test_parse_page_all_str
( "<translatE>a</translate> b <translate>c</translatE>" // <translatE> should match </translate> not </translatE>
, "a b c"
);
}
@Test public void Whitelist() {
fxt.Test_parse_page_all_str("<span onload='alert()'></span>", "<span></span>");
}
@Test public void Whitelist_pre() { // PURPOSE: <pre style="overflow:auto">a</pre> somehow becoming <prestyle="overflow:auto">a</pre>; 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("<pre style=\"overflow:auto\">a</pre>", "<pre style=\"overflow:auto\">a</pre>");
}
@Test public void Whitelist_style() {
fxt.Test_parse_page_all_str("<div style=\"url(bad)\"></div>", "<div></div>");
}
@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("<code><script src='a'>b</script></code>", "<code>&lt;script src='a'>b&lt;/script></code>");
}
@Test public void Script_in_syntaxhighlight() {
fxt.Test_parse_page_all_str("<syntaxhighlight><script>alert('fail');</script></syntaxhighlight>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">&lt;script&gt;alert('fail');&lt;/script&gt;</pre></div>");
}
@Test public void Html5_time() {// PURPOSE: HTML5; should output self (i.e.: must be whitelisted)
fxt.Test_parse_page_wiki_str("<time class=\"dtstart\" datetime=\"2010-10-10\">10 October 2010</time>", "<time class=\"dtstart\" datetime=\"2010-10-10\">10 October 2010</time>");
}
@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("<bdi lang=\"en\">a</bdi>", "<bdi lang=\"en\">a</bdi>");
}
@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("<mark lang=\"en\">a</mark>", "<mark lang=\"en\">a</mark>");
}
@Test public void Html5_mark_span() {// PURPOSE: </span> should close <mark> tag; EX: zh.wikipedia.org/wiki/异体字; DATE:2014-01-03
fxt.Test_parse_page_wiki_str("<mark>a</span>", "<mark>a</mark>");
}
@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("a<wbr>b<wbr>c", "a<wbr></wbr>b<wbr></wbr>c");
}
@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("<bdo>a</bdo>", "<bdo>a</bdo>");
}
@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", "<pre>{{a}}</pre>");
fxt.Test_parse_page_all_str("{{test}}", "<pre>{{a}}</pre>");
fxt.Init_defn_clear();
}
@Test public void Quote() {// PURPOSE: handle <q> element; DATE:2015-05-29
fxt.Test_parse_page_wiki_str("<q>a</q>", "<q>a</q>");
}
}

View File

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

View File

@@ -1,196 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<div>", 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("<div><div><div>", 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
( "<div><div><center>a</div></div>"
, "<div><div><center>a</center></div></div>"
);
}
@Test public void Center() {
fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("a<center>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<p>b<p>c</p>"
, 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
( "c<b><i>d<b><i>e"
, "c<b><i>d<b><i>e</i></b></i></b>"
);
}
@Test public void Li() { // PURPOSE: auto-close <li>; NOTE: no longer encloses in <ul/>; DATE:2014-06-26
fxt.Test_parse_page_wiki_str
( "<li>a<li>b"
, String_.Concat_lines_nl_skip_last
( "<li>a</li>"
, "<li>b</li>"
));
}
@Test public void Br() {
fxt.Test_parse_page_wiki("<br>a" , fxt.tkn_xnde_(0, 4), fxt.tkn_txt_(4, 5));
fxt.Test_parse_page_wiki("a<br name=b>c", fxt.tkn_txt_(0, 1), fxt.tkn_xnde_(1, 12), fxt.tkn_txt_(12, 13));
}
@Test public void Td_and_td() { // PURPOSE: when "<td>a<td>", 2nd <td> should auto-close
fxt.Test_parse_page_wiki("<table><tr><td>a<td></tr><tr><td>b</td></tr></table>"
, 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: <tr> 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
( "{|"
, "|-"
, "<td>row1</td>"
, "<tr><td>row2</td>"
, "|}"
)
, String_.Concat_lines_nl
( "<table>"
, " <tr>"
, " <td>row1"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>row2"
, " </td>"
, " </tr>"
, "</table>"
)
);
}
@Test public void Tblx_and_b() {
fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("<table><tr><td><b>a<td></tr></table>"
, 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: </td> should close list; see Stamp Act 1765
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table><tr><td>"
, "*abc</td></tr><tr><td>bcd</td></tr>"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, ""
, " <ul>"
, " <li>abc"
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>bcd"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
@Test public void Tblx_and_small() { // PURPOSE: </td> should close <small> correctly; see Stamp Act 1765
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table><tr><td>"
, "<small>abc</td></tr><tr><td>bcd</td></tr>"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, "<small>abc</small>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>bcd"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
fxt.Init_para_n_();
}
@Test public void Blockquote_and_p() {
fxt.Init_log_(Xop_xnde_log.Auto_closing_section).Test_parse_page_wiki("<blockquote>a<p>b</blockquote>"
, 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("*<b>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 <u> should auto-close; PAGE:en.b:Textbook_of_Psychiatry/Alcoholism_and_Psychoactive_Substance_Use_Disorders DATE:2014-09-05
fxt.Test_html_full_str("a<u>b<u>c", "a<u>b</u>c");
}
@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", "<poem>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
( "<div class=\"poem\">"
, "<p>"
, "A"
, "</p>"
, "</div>" // poem ends here
, " b"
));
}
}

View File

@@ -1,72 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<ref [[a]]", fxt.tkn_txt_(0, 4), fxt.tkn_space_(4, 5), fxt.tkn_lnki_(5, 10));
}
@Test public void End_tag_broken() { // chk that name_bgn is less than src_len else arrayIndex error; EX: <ref><p></p<<ref/>; DATE:2014-01-18
fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());
fxt.Test_parse_page_all_str("<poem><p></p<</poem>", String_.Concat_lines_nl_skip_last
( "<div class=\"poem\">"
, "<p>" // NOTE: technically MW / WP does not add this <p>; however, easier to hardcode <p>; no "visual" effect; DATE:2014-04-27
, "<p>&lt;/p&lt;</p>"
, "</p>"
, "</div>"
));
}
@Test public void Incomplete_tag_div() { // PURPOSE: handle broken tags; EX: <div a </div> -> &lt;div a; DATE:2014-02-03
fxt.Test_parse_page_all_str("<div a </div>", "&lt;div a </div>"); // note that "<div a " is escaped (not considered xnde; while "</div>" 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<ref"
fxt.Test_parse_page_all_str("a<ref", "a&lt;ref");
}
@Test public void Inline_tag_fix() { // PURPOSE: force <b/> to be <b></b>; EX: w:Exchange_value
fxt.Init_log_(Xop_xnde_log.No_inline);
fxt.Test_parse_page_all_str("<b/>", "<b></b>");
}
@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
( "<div>"
, "{|" // this should stop xnde search
, "<center>"
, "</div>" // this should not find <div> as its bgn_tag; note that it will "drop out" below
, "|}"
, "</div>"
), String_.Concat_lines_nl_skip_last
( "<div>"
, "<table><center></div>" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22
, " <tr>"
, " <td>"
, " </td>"
, " </tr>"
, "</center>"
, "</table>"
, "</div>"
));
}
@Test public void Incomplete_tag() { // PURPOSE: handle incomplete tag sequences; DATE:2014-10-22
fxt.Test_parse_page_all_str("<", "&lt;");
fxt.Test_parse_page_all_str("</", "&lt;/");
fxt.Test_parse_page_all_str("</<", "&lt;/&lt;"); // this used to fail
}
}

View File

@@ -1,191 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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_misc_tst {
private final Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_();}
@Test public void Error_br_removed() {
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <th><span>a</span><br/><span>b</span>"
, " </th>"
, " </tr>"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <th><span>a</span><br/><span>b</span>"
, " </th>"
, " </tr>"
, "</table>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Div_should_not_pop_past_td() { // PURPOSE: extra </div> should not close <div> that is outside of <td>; PAGE:en.w:Rome en.w:Ankara
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, "<tr>"
, "<td>"
, "<div>" // this is <div> #1
, "<table>"
, "<tr>"
, "<td>"
, "<div>" // this is <div> #2
, "<div>"
, "a"
, "</div>"
, "</td>"
, "<td>"
, "<div>"
, "b"
, "</div>"
, "</div>" // this </div> was supposed to pop <div> #2, but can't (b/c of HTML rules); however, do not try to pop <div> #1;
, "</td>"
, "<td>"
, "<div>"
, "c"
, "</div>"
, "</td>"
, "</tr>"
, "</table>"
, "</div>"
, "</td>"
, "</tr>"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, "<div>"
, " <table>"
, " <tr>"
, " <td>"
, "<div>"
, "<div>"
, ""
, "<p>a"
, "</p>"
, "</div>"
, "</div>"
, " </td>"
, " <td>"
, "<div>"
, ""
, "<p>b"
, "</p>"
, "</div>"
, "</div>" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22
, " </td>"
, " <td>"
, "<div>"
, ""
, "<p>c"
, "</p>"
, "</div>"
, " </td>"
, " </tr>"
, " </table>"
, "</div>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
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
( "<i>"
, "{|"
, "|-"
, "|<i>a</i>"
, "|}"
, "</i>"
), String_.Concat_lines_nl_skip_last
( "<i>"
, "<table>"
, " <tr>"
, " <td><i>a</i>"
, " </td>"
, " </tr>"
, "</table>"
, "</i>"
));
}
@Test public void Err_inline_extension() {
fxt.Test_parse_page_all_str
( "<poem/>"
, ""
);
}
@Test public void Xnde_para() { // PURPOSE: buggy code caused </p> to close everything; keeping test b/c of <p> logic
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<table>"
, "<tr>"
, "<td>"
, "<div>"
, "<p>"
, "<span>"
, "</span>"
, "</p>"
, "</div>"
, "</td>"
, "</tr>"
, "</table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, "<div>"
, "<p>"
, "<span>"
, "</span>"
, "</p>"
, "</div>"
, " </td>"
, " </tr>"
, "</table>"
, ""
)
);
}
@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 <b><sup>y</b> z", "x <b><sup>y</sup></b> z");
}
@Test public void Br_backslash() { // PURPOSE: allow <br\>; EX:w:Mosquito; [[Acalyptratae|A<br\>c<br\>a<br\>l<br\>y<br\>p<br\>t<br\>r<br\>a<br\>t<br\>a<br\>e]]
fxt.Test_parse_page_all_str("<br\\>", "<br/>");
}
@Test public void Tt_does_not_repeat() { // PURPOSE: handle <tt>a<tt>; EX:w:Domain name registry
fxt.Test_parse_page_all_str("<tt>a<tt>", "<tt>a</tt>");
}
@Test public void Loose_xnde_names() { // PURPOSE: MW allows <font-> and other variations; EX:w:2012_in_film
fxt.Test_parse_page_all_str("<font-size='100%'>a</font>", "<font>a</font>");
}
@Test public void Anchor_nested() {
fxt.Test_parse_page_all_str("b<a>c<a>d [[e]] f", "b&lt;a>c&lt;a>d <a href=\"/wiki/E\">e</a> f");
}
@Test public void Img_should_not_be_xtn() { // PURPOSE:<img> marked as .xtn; unclosed <img> was escaping rest of text; PAGE:de.w:Wikipedia:Technik/Archiv/2014 DATE:2014-11-06
fxt.Test_parse_page_all_str("<img>''a''", "&lt;img><i>a</i>");
}
@Test public void Invalid__percent() { // PURPOSE: invalidate xml tags with %; EX:<ref%s>; PAGE:pl.w:Scynk_nadrzewny; DATE:2016-08-07
fxt.Test_parse_page_all_str("<b%>a</b>", "&lt;b%&gt;a</b>"); // NOTE: should be literally printed as <b%>, not transformed to <b>
}
}

View File

@@ -1,81 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("a<includeonly>b</includeonly>c" , "{{test}}", "abc");}
@Test public void Tmpl_noinclude() {fxt.Test_parse_tmpl_str_test("a<noinclude>b</noinclude>c" , "{{test}}", "ac");}
@Test public void Tmpl_onlyinclude() {fxt.Test_parse_tmpl_str_test("a<onlyinclude>b</onlyinclude>c" , "{{test}}", "b");}
@Test public void Tmpl_onlyinclude_nest() {fxt.Test_parse_tmpl_str_test("{{#ifeq:y|y|a<onlyinclude>b</onlyinclude>c|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", "<noinclude>a<onlyinclude>b</onlyinclude>c</noinclude>d");
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 (<pre>) was also included
fxt.Init_page_create("Transclude_2", "a<onlyinclude>b<includeonly>c</includeonly>d</onlyinclude>e<pre>f</pre>g");
fxt.Test_parse_tmpl_str_test("{{:Transclude_2}}" , "{{test}}", "bcd");
}
@Test public void Tmpl_noinclude_unmatched() { // PURPOSE.fix: ignore unmatched </noinclude>; EX:fi.w:Sergio_Leone; DATE:2014-05-02
fxt.Test_parse_tmpl_str_test("{{{1|</noinclude>}}}", "{{test|a}}", "a"); // was "{{{test|"
}
@Test public void Wiki_includeonly() {fxt.Test_parse_page_all_str("a<includeonly>b</includeonly>c" , "ac");}
@Test public void Wiki_noinclude() {fxt.Test_parse_page_all_str("a<noinclude>b</noinclude>c" , "abc");}
@Test public void Wiki_onlyinclude() {fxt.Test_parse_page_all_str("a<onlyinclude>b</onlyinclude>c" , "abc");}
@Test public void Wiki_oi_io() {fxt.Test_parse_page_all_str("a<onlyinclude>b<includeonly>c</includeonly>d</onlyinclude>e" , "abde");}
@Test public void Wiki_oi_io_tblw() {
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "<onlyinclude>"
, "{|"
, "|-"
, "|a<includeonly>"
, "|}</includeonly></onlyinclude>"
, "|-"
, "|b"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
}
/*
<includeonly>-({{{1}}}={{{1}}}round-5)-({{{1}}}={{{1}}}round-4)-({{{1}}}={{{1}}}round-3)-({{{1}}}={{{1}}}round-2)-({{{1}}}={{{1}}}round-1)</includeonly><noinclude>
{{pp-template}}Called by {{lt|precision/0}}</noinclude>
==includeonly -- aka: do not eval in template ==
main: a<includeonly>b</includeonly>c<br/>
tmpl: {{mwo_include_only|a|b|c}}
==noinclude -- aka: eval in template only==
main: a<noinclude>b</noinclude>c<br/>
tmpl: {{mwo_no_include|a|b|c}}
==onlyinclude -- aka: only include in template only (ignore everything else) ==
main: a<onlyinclude>b</onlyinclude>c<br/>
tmpl: {{mwo_only_include|a|b|c}}
*/

View File

@@ -1,192 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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: <includeonly> not parsing internals; PAGE:en.w:[[Template:MONTHNAME]]
fxt.Test_parse_tmpl_str_test("<includeonly>{{#if:{{{1}}}|a|b}}</includeonly><noinclude>c</noinclude>", "{{test|1}}", "a");
}
@Test public void Ex_Tmpl_io_subst() { // PURPOSE: <includeonly> 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"
, "|<includeonly>{{subst:</includeonly><includeonly>substcheck}}</includeonly>"
, "}}"
), "{{test}}"
, "{{subst:substcheck}}\n"
);
fxt.Reset();
fxt.Test_parse_tmpl_str_test(String_.Concat_lines_nl_skip_last
( "{{mwo_print"
, "|<includeonly>{{safesubst:</includeonly><includeonly>substcheck}}</includeonly>"
, "}}"
), "{{test}}"
, "SUBST\n");
fxt.Init_defn_clear();
}
@Test public void Ex_Tmpl_noinclude_prm_1() { // PURPOSE: <noinclude> 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<noinclude>|not_seen</noinclude>}}}|{{{2}}}}}"
, "{{test|a|b}}"
, "ab"
);
fxt.Init_defn_clear();
}
@Test public void Ex_Tmpl_noinclude_prm_2() { // PURPOSE: <noinclude> should not process default tkn;
fxt.Test_parse_tmpl_str_test
( "{{#if: {{{x|<noinclude>y</noinclude>}}} | visible | hidden}}" // {{#if: {{{x|<noinclude>y</noinclude>}}} -> {{#if: {{{x|}} -> hidden
, "{{test}}"
, "hidden"
);
}
@Test public void Ex_Tmpl_noinclude2() { // PURPOSE: <noinclude> 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<noinclude>{{{?}}}</noinclude>|a|b}}"
, "{{test}}"
, "ab"
);
fxt.Init_defn_clear();
}
@Test public void Exception_incompleteTag_matchNext() { // PURPOSE: "</noinclude" should not be matched;
fxt.Test_parse_tmpl_str_test
( "a<noinclude>b</noinclude c<noinclude>d</noinclude>e"
, "{{test}}"
, "ae"
);
}
@Test public void Exception_noCloseTag() {
fxt.Test_parse_tmpl_str_test
( "a<noinclude>bcde"
, "{{test}}"
, "a"
);
}
@Test public void Exception_inline() {
fxt.Test_parse_tmpl_str_test
( "a<noinclude/>bcde"
, "{{test}}"
, "abcde"
);
}
@Test public void Exception_inline_2() {
fxt.Test_parse_tmpl_str_test
( "a<noinclude/a/>bcde"
, "{{test}}"
, "a<noinclude/a/>bcde"
);
}
@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: <onlyinclude>1</onlyinclude>}} {{formatnum:2}}"
, "1 2"
);
}
@Test public void Only_include_preserves_nl() { // PURPOSE: given "a\n<onlyinclude>{|\n", "{|" should be table; PAGE:en.w:Wikipedia:Reference_desk
fxt.Test_parse_page_all_str(String_.Concat_lines_nl
( "a"
, "<onlyinclude>==b==</onlyinclude>"
, "c"
)
// , "{{test}}"
, String_.Concat_lines_nl
( "a"
, ""
, "<h2>b</h2>"
, "c"
));
}
@Test public void Only_include_interprets_template() { // PURPOSE: <oi> 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"
, "<onlyinclude>{{test}}</onlyinclude>"
, "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("{{<includeonly></includeonly>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("{{:<includeonly>safesubst:</includeonly>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("{{<includeonly>subst:</includeonly>#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("=<includeonly>=</includeonly>A=<includeonly>=</includeonly>", "<h1>A</h1>\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", "a<noinclude>b<noinclude>c</noinclude>d</noinclude>e");
// fxt.Test_parse_page_all_str("{{test}}", "ae");
// }
// @Test public void Wiki_includeonly_ignore() {fxt.Test_parse_wiki_text("[[a<includeonly>b</includeonly>c]]", "[[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: <onlyinclude> 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:<onlyinclude>1</onlyinclude>}}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", "<pre<includeonly></includeonly>>{{{1}}}</pre>");
fxt.Test_parse_page_all_str
( "{{pre2|a}}"
, String_.Concat_lines_nl_skip_last
( "<pre>a</pre>"
));
}
// @Test public void Pre_and_includeonly2() {
// fxt.Init_defn_add("pre2", "<pre<includeonly></includeonly>><nowiki>{{{1}}}</nowiki></pre>");
// fxt.Test_parse_page_all_str
// ( "{{pre2|a}}"
// , String_.Concat_lines_nl_skip_last
// ( "<pre>a</pre>"
// ));
// }
@Test public void Noinclude_inline_w_space_inside_safesubst() { // PURPOSE: "<noinclude />" 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:<noinclude />#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", "{{<includeonly>subst:</includeonly>#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", "{{<includeonly>#switch:</includeonly>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 <includeonly>
fxt.Test_parse_page_all_str("{{subst:test}}", "y"); // note that expression is evaluated b/c of subst:
}
}

View File

@@ -1,102 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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 <li> (EX: "<li>a<li>") was causing 3rd <li> to close incorrectly
fxt.Test_parse_page_wiki_str
( "<table><tr><td><ul><li>a</li><li>b</li><li>c</li></ul></td></tr></table>"
, String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td><ul>"
, "<li>a</li>"
, "<li>b</li>"
, "<li>c</li></ul>"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@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
( "<ul><li>a<ul><li>b</li></ul></li></ul>"
, String_.Concat_lines_nl_skip_last
( "<ul>"
, "<li>a<ul>"
, "<li>b</li></ul></li></ul>" // note that <li><li>b becomes <li>&lt;li>b but <li><ul><li>b should stay the same
));
}
@Test public void Empty_ignored() {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "<ul>"
, "<li>a"
, "</li><li>"
, "</li><li>b"
, "</li>"
, "</ul>"
), String_.Concat_lines_nl_skip_last
( "<ul>"
, "<li>a"
, "</li>"
, "<li>b"
, "</li>"
, "</ul>"
));
}
@Test public void Empty_ignored_error() { // PAGE:en.w:Sukhoi_Su-47; "* </li>" causes error b/c </li> tries to close non-existent node
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "* a"
, "* </li>"
), String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li> a"
, " </li>"
, " <li> </li>" // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22
, " </li>"
, "</ul>"
));
}
@Test public void Insert_nl() {// PURPOSE: <li> 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("<ul><li>a</li><li>b</li></ul>"
, String_.Concat_lines_nl_skip_last
( "<ul>"
, "<li>a</li>"
, "<li>b</li></ul>"
, ""
));
fxt.Init_para_n_();
}
@Test public void Duplicate() { // PURPOSE: redundant li; EX: "* <li>"; PAGE:it.w:Milano#Bibliographie; DATE:2013-07-23
fxt.Test_parse_page_all_str("* <li>x</li>", String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li> "
, "<li>x</li>" // TIDY: duplicate li will be stripped out; DATE:2014-06-26
, " </li>"
, "</ul>"
));
}
@Test public void Dangling_inside_xnde() { // PURPOSE.TIDY: handle "<li><span>a<li><span>b"; PAGE:ro.w:Pagina principala; DATE:2014-06-26
fxt.Test_parse_page_all_str("<li><span>a<li><span>b", String_.Concat_lines_nl_skip_last
( "<li><span>a"
, "<li><span>b</span></li></span></li>" // TIDY: will (a) move </span></li> to 1st line
));
}
}

View File

@@ -1,142 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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
( "<nowiki>''a''</nowiki>b"
, "''a''b"
);
}
@Test public void Template() {
fxt.Init_para_y_();
fxt.Init_defn_add("nowiki_test", "<nowiki>#</nowiki>a");
fxt.Test_parse_page_all_str
( "{{nowiki_test}}"
, String_.Concat_lines_nl_skip_last
( "<p>#a"
, "</p>"
, ""
));
fxt.Init_para_n_();
}
@Test public void H2() { // PAGE:en.w:HTML
fxt.Test_parse_page_all_str
( "a<nowiki><h1>b<h6></nowiki>c"
, String_.Concat_lines_nl_skip_last
( "a&lt;h1&gt;b&lt;h6&gt;c"
));
}
@Test public void Lnke() { // PAGE:en.w:Doomsday_argument; <nowiki>[0,&nbsp;1]</nowiki>
fxt.Test_parse_page_wiki_str("a <nowiki>[0,&nbsp;1]</nowiki> b", "a [0,&nbsp;1] b"); // NOTE: not "0" + Byte_.To_str(160) + "1"; depend on browser to translate &nbsp;
}
@Test public void Xatrs_val_text() {
fxt.Test_parse_page_all_str
( "<div id=<nowiki>a</nowiki>>b</div>"
, String_.Concat_lines_nl_skip_last
( "<div id=\"a\">b</div>"
));
}
@Test public void Xatrs_val_quote() {
fxt.Test_parse_page_all_str
( "<div id='a<nowiki>b</nowiki>c'>d</div>"
, String_.Concat_lines_nl_skip_last
( "<div id='abc'>d</div>"
));
}
@Test public void Xatrs_eq() {
fxt.Test_parse_page_all_str("<ul id<nowiki>=</nowiki>\"a\" class<nowiki>=</nowiki>\"b\"><li><span class=\"c\">d</li></ul>", String_.Concat_lines_nl_skip_last
( "<ul id=\"a\" class=\"b\">"
, "<li><span class=\"c\">d</span></li></ul>"
));
}
@Test public void Tblw_atr() {// PURPOSE: nowiki breaks token
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "{|style=\"background-color:<nowiki>#</nowiki>FFCC99\""
, "|a"
, "|}"
) , String_.Concat_lines_nl_skip_last
( "<table style=\"background-color:#FFCC99\">"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
@Test public void Prex() { // PURPOSE: nowikis inside pre should be ignored; DATE:2013-03-30
fxt.Test_parse_page_all_str("<pre>a<nowiki>&lt;</nowiki>b</pre>" , "<pre>a&lt;b</pre>"); // basic
fxt.Test_parse_page_all_str("<pre>a<nowiki>&lt;<nowiki>b</pre>" , "<pre>a&lt;nowiki&gt;&lt;&lt;nowiki&gt;b</pre>"); // not closed
fxt.Test_parse_page_all_str("<pre><nowiki>a<nowiki>b</nowiki>c</nowiki></pre>" , "<pre>&lt;nowiki&gt;abc&lt;/nowiki&gt;</pre>"); // nested; this is wrong, but leave for now; should be a<nowiki>b</nowiki>c
}
@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<nowiki>"
, " <b></b></nowiki>" // note that "\s" must remain "\s" so that <pre> continues uninterrupted
), String_.Concat_lines_nl
( "<pre>a"
, "&lt;b&gt;&lt;/b&gt;"
, "</pre>"
)
);
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
( " <nowiki>a"
, "b</nowiki>" // note that "b" should be in pre b/c it is part of <nowiki> which is pre'd (even though there is no \n\s)
), String_.Concat_lines_nl
( "<pre>a"
, "b"
, "</pre>"
)
);
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("<code><nowiki>|:</nowiki></code>", "<code>|:</code>");
}
@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
( "<nowiki>[</nowiki>[[A]]<nowiki>]</nowiki>"
, "[<a href=\"/wiki/A\">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"
, "|<nowiki>-</nowiki>" // do not treat as "|-"
, "|}"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " <td>-" // "|" creates <td>; "-" is rendered literally
, " </td>"
, " </tr>"
, "</table>"
, ""
));
}
}

View File

@@ -1,78 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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<table><tr><td>b</td></tr></table>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
( " <table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, " </table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>a"
, " </td>"
, " </tr>"
, "</table>"
, ""
));
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
( "<table><tr><td>"
, "[[File:A.png|150px"
, "|B]]</td></tr></table>"
), String_.Concat_lines_nl_skip_last
( "<table>"
, " <tr>"
, " <td>"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"B\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/150px.png\" width=\"150\" height=\"0\" /></a>"
, " </td>"
, " </tr>"
, "</table>"
));
fxt.Init_para_n_();
}
@Test public void Nl() {
fxt.Init_para_y_();
fxt.Test_parse_page_wiki_str
( "<table>\n\n\n\n\n</table>"
, "<table>\n"
+ "</table>\n"
);
fxt.Init_para_n_();
}
}

View File

@@ -1,77 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<source>''a''</source>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">''a''</pre></div>");
}
@Test public void Source_nowiki() { // PURPOSE.ASSERT: onlyinclude should be rendered literally; DATE:2014-03-11
fxt.Test_parse_page_wiki_str("<source><onlyinclude>a</onlyinclude></source>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">&lt;onlyinclude&gt;a&lt;/onlyinclude&gt;</pre></div>");
}
@Test public void Source_escape() {
fxt.Test_parse_page_wiki_str("<source><b></source>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">&lt;b&gt;</pre></div>");
}
@Test public void Source_escape_amp() { // PURPOSE: &lt; should be rendered as &amp;lt; PAGE:uk.b:HTML; DATE:2014-03-11
fxt.Test_parse_page_wiki_str("<source>&lt;</source>", "<div class=\"mw-highlight\"><pre style=\"overflow:auto\">&amp;lt;</pre></div>");
}
@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
( " <source>"
, " a"
, " </source>"
), String_.Concat_lines_nl_skip_last
( " <div class=\"mw-highlight\"><pre style=\"overflow:auto\">"
, " a"
, "</pre></div>"
));
fxt.Init_para_n_();
}
@Test public void Code_dangling() { // PAGE:en.w:HTML; <code>&lt;i&gt;<code> and <code>&lt;center&gt;<code> tags. There are
fxt.Test_parse_page_wiki_str("a<code>b<code>c", "a<code>b</code>c");
}
@Test public void Code_do_not_escape() { // PURPOSE: <code> was mistakenly marked as escape, causing inner tags to be rendered incorrectly; PAGE:en.w:UTF8
fxt.Test_parse_page_all_str
( "<code><span style=\"color:red;\">0100100</span></code>"
, "<code><span style=\"color:red;\">0100100</span></code>"
);
}
@Test public void Pre_and_html_chars() {// PURPOSE: <pre> should handle '"<> according to context
fxt.Test_parse_page_all_str("<pre>a&#09;b</pre>" , "<pre>a&#09;b</pre>"); // known ncr/dec; embed and depend on browser transforming; EX: de.w:Wikipedia:Technik/Skin/Werkstatt
fxt.Test_parse_page_all_str("<pre>a&#9999999999;b</pre>" , "<pre>a&amp;#9999999999;b</pre>"); // unknown ncr/dec; escape & (since browser cannot render);
fxt.Test_parse_page_all_str("<pre>a&#af ;b</pre>" , "<pre>a&amp;#af ;b</pre>"); // unknown ncr/dec 2
fxt.Test_parse_page_all_str("<pre>a&#x9;b</pre>" , "<pre>a&#x9;b</pre>"); // known ncr/hex
fxt.Test_parse_page_all_str("<pre>a&apos;b</pre>" , "<pre>a&apos;b</pre>"); // known name; embed
fxt.Test_parse_page_all_str("<pre>a&apox;b</pre>" , "<pre>a&amp;apox;b</pre>"); // unknown name; escape
fxt.Test_parse_page_all_str("<pre>&\"<></pre>" , "<pre>&amp;&quot;&lt;&gt;</pre>"); // no ncr or name; escape; needed for <pre><img ...></pre>; PAGE:en.w:Alt attribute
}
@Test public void Pre_and_space() {// PURPOSE: make sure pre does not careate <p></p> 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
( "<pre>"
, " a"
, "</pre>"
), String_.Concat_lines_nl_skip_last
( "<pre>"
, " a"
, "</pre>"
));
fxt.Init_para_n_();
}
}

View File

@@ -1,44 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<sub>a</sup>b", "<sub>a</sub>b");
fxt.Test_parse_page_wiki_str("<sup>a</sub>b", "<sup>a</sup>b");
}
@Test public void Span_font_autocorrect() { // PURPOSE: force </font> to close <span>; EX:w:Rupee; DATE:2014-04-07
fxt.Test_parse_page_wiki_str("<span>a</font>b", "<span>a</span>b");
}
@Test public void Move_ws_char() {
fxt.Test_parse_page_all_str("a<i> b </i>c", "a <i>b</i> c");
}
@Test public void Move_ws_ent() {
fxt.Test_parse_page_all_str("a<i>&#32;b&#32;</i>c", "a&#32;<i>b</i>&#32;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<pre></pre>b", "ab");
}
// @Test public void Escaped_div() { // NOTE: WP <div><span>a</span></div><span>b</span>; MW: <div><span>a</div>b</span> // 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("<div><span></div></span>"
// , fxt.tkn_xnde_(0, 17).Subs_
// ( fxt.tkn_xnde_(5, 11))
// , fxt.tkn_ignore_(17, 24)
// );
// }
}

View File

@@ -1,58 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://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("<ref cd=\"ef\" />" , fxt.tkn_xnde_(0, 15).Atrs_rng_(5, 13));
fxt.Test_parse_page_wiki("<ref cd = \"e f\" />" , fxt.tkn_xnde_(0, 21).Atrs_rng_(5, 19)); // ws
}
@Test public void Bgn() {
fxt.Test_parse_page_wiki("<div cd=\"ef\"></div>" , 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("<span style='color:red' style='color:green'>a</span>" , "<span style='color:green'>a</span>"); // two
fxt.Test_parse_page_all_str("<span style='color:red' style='color:green' style='color:blue'>a</span>" , "<span style='color:blue'>a</span>"); // three
}
@Test public void Non_ws() { // PURPOSE: <br$2/> is valid; symbols function as ws
fxt.Test_parse_page_wiki("<br$2/>" , 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("<brx/>" , fxt.tkn_bry_(0, 1), fxt.tkn_txt_(1, 6));
}
@Test public void Id_encode() {
fxt.Test_parse_page_all_str("<div id=\"a b c\"></div>", "<div id=\"a_b_c\"></div>");
}
@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("<input value='a<'></input>", "<input value='a<'></input>"); // 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("<span style='background:&#x23;ffc0c0'>a</span>", "<span style='background:#ffc0c0'>a</span>");
}
// @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
// ( "<span id=\"1<>>a" // id="1<> -> key named 'id="1<>' which fails whitelist keys
// , "</span>"
// ), String_.Concat_lines_nl_skip_last
// ( "<span>a"
// , "</span>"
// ));
// }
}