From 40b520ecc6bdad1ee5bb87c6a6e655db20729662 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Wed, 11 Jan 2017 18:18:46 -0500 Subject: [PATCH] Mw_parse.Prepro: Support more heading edge cases --- .../parsers/mws/prepros/Xomw_prepro_wkr.java | 8 ++- .../mws/prepros/Xomw_prepro_wkr__tst.java | 58 ++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr.java b/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr.java index 9f8d64738..23c7150a3 100644 --- a/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr.java +++ b/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr.java @@ -494,7 +494,9 @@ public class Xomw_prepro_wkr { // THREAD.UNSAFE: caching for repeated calls i++; } - int eq_end = Bry_find_.Find_fwd_while(src, i, i + 6, Byte_ascii.Eq); // PORTED:strspn( $src, '=', $i, 6 ); + // PORTED: $count = strspn( $text, '=', $i, 6 ); + int eq_end_max = i + 6; if (eq_end_max > src_len) eq_end_max = src_len; + int eq_end = Bry_find_.Find_fwd_while(src, i, eq_end_max, Byte_ascii.Eq); int count = eq_end - i; if (count == 1 && find_equals) { // EX: "{{a|\n=b=\n" // DWIM: This looks kind of like a name/value separator. @@ -529,10 +531,10 @@ public class Xomw_prepro_wkr { // THREAD.UNSAFE: caching for repeated calls // Comment found at line end // Search for equals signs before the comment search_bgn = part.visual_end; - search_bgn -= Bry_find_.Find_bwd__while_space_or_tab(src, search_bgn, 0); + search_bgn = Bry_find_.Find_bwd__while_space_or_tab(src, search_bgn, 0); } int count = piece.count; - int eq_len = Bry_find_.Find_bwd_while(src, search_bgn, 0, Byte_ascii.Eq); + int eq_len = search_bgn - Bry_find_.Find_bwd_while(src, search_bgn, 0, Byte_ascii.Eq) - 1; byte[] element = Bry_.Empty; if (eq_len > 0) { diff --git a/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr__tst.java b/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr__tst.java index 346162b02..f89295119 100644 --- a/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr__tst.java +++ b/400_xowa/src/gplx/xowa/parsers/mws/prepros/Xomw_prepro_wkr__tst.java @@ -117,7 +117,7 @@ public class Xomw_prepro_wkr__tst { , "z" )); } - @Test public void Heading__eq_1() { // COVERS: "DWIM: This looks kind of like a name/value separator." + @Test public void Heading__dwim__y() { // COVERS: "DWIM: This looks kind of like a name/value separator." fxt.Test__parse(String_.Concat_lines_nl_skip_last ( "a{{b|" , "=c=" @@ -128,7 +128,61 @@ public class Xomw_prepro_wkr__tst { , "d" )); } - + @Test public void Heading__dwim__n() { // COVERS: "DWIM: This looks kind of like a name/value separator." + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a{{b|" + , "==c==" + , "}}d" + ), String_.Concat_lines_nl_skip_last + ( "ad" + )); + } + @Test public void Heading__comment() { // COVERS: "Comment found at line end" + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a" + , "==b== " + , "" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "==b== <!--c-->" + , "" + )); + } + @Test public void Heading__consecutive__5() { // COVERS: "This is just a single String of equals signs on its own line" + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a" + , "=====" + , "" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "=====" + , "" + )); + } + @Test public void Heading__consecutive__1() { // COVERS: "Single equals sign on its own line, count=0" + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a" + , "=" + , "" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "=" + , "" + )); + } + @Test public void Heading__unclosed() { // COVERS: "No match, no , just pass down the inner src" + fxt.Test__parse(String_.Concat_lines_nl_skip_last + ( "a" + , "===b" + , "" + ), String_.Concat_lines_nl_skip_last + ( "a" + , "===b" + , "" + )); + } @Test public void Inclusion__n() { fxt.Init__for_inclusion_(Bool_.N); fxt.Test__parse("abc", "a<onlyinclude>b</onlyinclude>c");