jenkins-bot has submitted this change and it was merged.

Change subject: T128319: Fix fragile tests for non-block-format transclusions
......................................................................


T128319: Fix fragile tests for non-block-format transclusions

* The tests for non-block-format transclusions was too fragile
  and was testing for a newline as the last character.
  This expectation is broken in scenarios where the original
  transclusion had non-standard spacing / comments after the
  newline and this was recorded in data-parsoid.

* Added new tests to capture this expectation.

Change-Id: I24aa1b7eda6103f54371aca7249d46c3e8bf7349
---
M lib/html2wt/WikitextSerializer.js
M tests/mocha/templatedata.js
2 files changed, 22 insertions(+), 7 deletions(-)

Approvals:
  Arlolra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/html2wt/WikitextSerializer.js 
b/lib/html2wt/WikitextSerializer.js
index e40e00f..ac60914 100644
--- a/lib/html2wt/WikitextSerializer.js
+++ b/lib/html2wt/WikitextSerializer.js
@@ -370,6 +370,10 @@
        }
 };
 
+var TRAILING_COMMENT_OR_WS_AFTER_NL_REGEXP = JSUtils.rejoin(
+               '\\n(\\s|', Util.COMMENT_REGEXP, ')*$'
+       );
+
 // See 
https://github.com/wikimedia/mediawiki-extensions-TemplateData/blob/master/Specification.md
 // for the templatedata specification.
 WSP._serializeTemplate = function(node, tpl, isTpl, tplData) {
@@ -536,7 +540,7 @@
                var useBlockFormat = (format === 'block');
                var useInlineFormat = (format === 'inline' || 
DU.isNewElt(node));
                if (useBlockFormat) {
-                       if (buf[buf.length - 1] !== '\n') {
+                       if (!TRAILING_COMMENT_OR_WS_AFTER_NL_REGEXP.test(buf)) {
                                buf += '\n';
                        }
                } else if (useInlineFormat) {
@@ -575,7 +579,7 @@
                                        buf += ' ';
                                }
                                buf += val;
-                               if (val[val.length - 1] !== '\n') {
+                               if 
(!TRAILING_COMMENT_OR_WS_AFTER_NL_REGEXP.test(val)) {
                                        buf += '\n';
                                }
                        } else if (useInlineFormat && name !== null) {
@@ -587,7 +591,7 @@
                        }
                }
 
-               if (useBlockFormat && buf[buf.length - 1] !== '\n') {
+               if (useBlockFormat && 
!TRAILING_COMMENT_OR_WS_AFTER_NL_REGEXP.test(buf)) {
                        buf += '\n';
                }
 
diff --git a/tests/mocha/templatedata.js b/tests/mocha/templatedata.js
index c217cf5..7ab73c9 100644
--- a/tests/mocha/templatedata.js
+++ b/tests/mocha/templatedata.js
@@ -117,7 +117,18 @@
                },
        },
 
-       // 6. inline-tpl (but written in block format originally); with param 
order
+       // 6. block-tpl (with non-standard spaces before pipe); no param order
+       {
+               'name': 'Enforce block format (while preserving non-standard 
space before pipes)',
+               'html': '<span about="#mwt1" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f1","spc":[" ", " ", " ", "\\n <!--ha--> 
"]},{"k":"f2","spc":[" ", " ", " ", ""]}]]}' + "' data-mw='" + 
'{"parts":[{"template":{"target":{"wt":"BlockTplNoParamOrder\\n 
","href":"./Template:BlockTplNoParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}}]}'
 + "'" + '>foo</span>',
+               'wt': {
+                       'no_selser':   '{{BlockTplNoParamOrder\n | f1 = foo\n 
<!--ha--> | f2 = foo}}',
+                       'new_content': '{{BlockTplNoParamOrder\n | f1 = foo\n| 
f2 = foo\n}}',
+                       'edited':      '{{BlockTplNoParamOrder\n | f1 = BAR\n 
<!--ha--> | f2 = foo\n}}',
+               },
+       },
+
+       // 7. inline-tpl (but written in block format originally); with param 
order
        {
                'name': 'Enforce inline format + param order',
                'html': '<span about="#mwt1" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f2","spc":[""," "," 
","\\n"]},{"k":"f1","spc":[""," "," ","\\n"]}]]}' + "' data-mw='" + 
'{"parts":[{"template":{"target":{"wt":"InlineTplWithParamOrder\\n","href":"./Template:InlineTplWithParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}}]}'
 + "'" + '>foo</span>',
@@ -128,7 +139,7 @@
                },
        },
 
-       // 7. block-tpl (but written in inline format originally); with param 
order
+       // 8. block-tpl (but written in inline format originally); with param 
order
        {
                'name': 'Enforce block format + param order',
                'html': '<span about="#mwt1" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f2"},{"k":"f1"}]]}' + "'" + ' data-mw=' + 
"'" + 
'{"parts":[{"template":{"target":{"wt":"BlockTplWithParamOrder","href":"./Template:BlockTplWithParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}}]}'
 + "'" + '>foo</span>',
@@ -139,7 +150,7 @@
                },
        },
 
-       // 8. Multiple transclusions
+       // 9. Multiple transclusions
        {
                'name': 'Multiple transclusions',
                'html': '<span about="#mwt1" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f2","spc":[""," "," 
","\\n"]},{"k":"f1","spc":[""," "," ","\\n"]}]]}' + "' data-mw='" + 
'{"parts":[{"template":{"target":{"wt":"TplWithoutTemplateData\\n","href":"./Template:TplWithoutTemplateData"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}}]}'
 + "'" + '>foo</span>' + ' <span about="#mwt2" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f2"},{"k":"f1"}]]}' + "'" + ' data-mw=' + 
"'" + 
'{"parts":[{"template":{"target":{"wt":"BlockTplWithParamOrder","href":"./Template:BlockTplWithParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}}]}'
 + "'" + '>foo</span>',
@@ -150,7 +161,7 @@
                },
        },
 
-       // 9. data-mw with multiple transclusions
+       // 10. data-mw with multiple transclusions
        {
                'name': 'Multiple transclusions',
                'html': '<span about="#mwt1" typeof="mw:Transclusion" 
data-parsoid=' + "'" + '{"pi":[[{"k":"f2"},{"k":"f1"}], [{"k":"f2","spc":[""," 
"," ","\\n"]},{"k":"f1","spc":[""," "," ","\\n"]}]]}' + "' data-mw='" + 
'{"parts":[{"template":{"target":{"wt":"BlockTplWithParamOrder","href":"./Template:BlockTplWithParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":0}},"SOME
 
TEXT",{"template":{"target":{"wt":"InlineTplNoParamOrder\\n","href":"./Template:InlineTplNoParamOrder"},"params":{"f1":{"wt":"foo"},"f2":{"wt":"foo"}},"i":1}}]}'
 + "'" + '>foo</span>',

-- 
To view, visit https://gerrit.wikimedia.org/r/273975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I24aa1b7eda6103f54371aca7249d46c3e8bf7349
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to