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

Html: Move get_elem_val to xo.elem

This commit is contained in:
gnosygnu
2017-02-22 09:41:37 -05:00
parent 5bd3371802
commit 12848b7cf5
896 changed files with 69011 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_amp_mgr__decode__tst {
@Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt();
@Test public void Text() {fxt.Test__decode_as_bry("a" , "a");}
@Test public void Name() {fxt.Test__decode_as_bry("&" , "&");}
@Test public void Name_w_text() {fxt.Test__decode_as_bry("a&b" , "a&b");}
@Test public void Name_fail_semic_missing() {fxt.Test__decode_as_bry("a&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("Σ" , "Σ");}
@Test public void Num_zero_padded() {fxt.Test__decode_as_bry("Σ" , "Σ");}
@Test public void Hex_upper() {fxt.Test__decode_as_bry("Σ" , "Σ");}
@Test public void Hex_lower() {fxt.Test__decode_as_bry("Σ" , "Σ");}
@Test public void Hex_zero_padded() {fxt.Test__decode_as_bry("Σ" , "Σ");}
@Test public void Hex_upper_x() {fxt.Test__decode_as_bry("Σ" , "Σ");}
@Test public void Num_fail_large_codepoint() {fxt.Test__decode_as_bry("�" , "�");}
@Test public void Num_ignore_extra_x() {fxt.Test__decode_as_bry("&#xx26D0;" , Char_.To_str(Char_.By_int(9936)));} // 2nd x is ignored
}
class Xop_amp_mgr_fxt {
private final Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance;
public void Test__decode_as_bry(String raw, String expd) {
Gftest.Eq__str(expd, String_.new_u8(amp_mgr.Decode_as_bry(Bry_.new_u8(raw))));
}
public void Test__parse_tkn__ent(String raw, String expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Xop_amp_tkn_ent tkn = (Xop_amp_tkn_ent)rv.Tkn();
Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ref, tkn.Tkn_tid());
Gftest.Eq__str(expd, tkn.Xml_name_bry());
}
public void Test__parse_tkn__ncr(String raw, int expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Xop_amp_tkn_num tkn = (Xop_amp_tkn_num)rv.Tkn();
Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ncr, tkn.Tkn_tid());
Gftest.Eq__int(expd, tkn.Val());
}
public void Test__parse_tkn__txt(String raw, int expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Gftest.Eq__null(Bool_.Y, rv.Tkn());
Gftest.Eq__int(expd, rv.Pos());
}
private Xop_amp_mgr_rslt Exec__parse_tkn(String raw) {
byte[] src = Bry_.new_u8(raw);
return amp_mgr.Parse_tkn(new Xop_tkn_mkr(), src, src.length, 0, 1);
}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_amp_mgr__parse_tkn__tst {
@Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt();
@Test public void Ent() {fxt.Test__parse_tkn__ent("&" , "&");} // check for html_ref
@Test public void Ent__fail() {fxt.Test__parse_tkn__txt("&nil;" , 1);}
@Test public void Num__nex() {fxt.Test__parse_tkn__ncr("Σ" , 931);} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference
@Test public void Num__dec() {fxt.Test__parse_tkn__ncr("Σ" , 931);}
@Test public void Num__fail() {fxt.Test__parse_tkn__txt("&#" , 1);}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_amp_wkr_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Convert_to_named() {fxt.Test_parse_page_wiki_str("&" , "&");} // note that & is printed, not &
@Test public void Convert_to_named_amp() {fxt.Test_parse_page_wiki_str("&" , "&");} // PURPOSE: html_wtr was not handling & only
@Test public void Convert_to_numeric() {fxt.Test_parse_page_wiki_str("á" , "á");} // testing that á is outputted, not á
@Test public void Defect_bad_code_fails() { // PURPOSE: early rewrite of Xop_amp_mgr caused Xoh_html_wtr_escaper to fail with array out of bounds error; EX:w:Czech_Republic; DATE:2014-05-11
fxt.Test_parse_page_wiki_str
( "[[File:A.png|alt=<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 <
);
}
}