Marcoil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/135575

Change subject: WIP: Selser round-trip testing
......................................................................

WIP: Selser round-trip testing

Change-Id: I071000eacc9eabe4120a0ff2a0101b70e74d8c1b
---
M tests/roundtrip-test.js
1 file changed, 42 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/75/135575/1

diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index cb79a4b..a745654 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -29,14 +29,14 @@
 
                        output += testDivider;
                        if ( result.type === 'fail' ) {
-                               output += 'Semantic difference:\n\n';
+                               output += 'Semantic difference' + 
(result.selser ? ' (selser)' : '') + ':\n\n';
                                output += result.wtDiff + '\n';
                                output += diffDivider;
                                output += 'HTML diff:\n\n';
                                output += result.htmlDiff + '\n';
                                semanticDiffs++;
                        } else {
-                               output += 'Syntactic difference:\n\n';
+                               output += 'Syntactic difference' + 
(result.selser ? ' (selser)' : '') + ':\n\n';
                                output += result.wtDiff + '\n';
                                syntacticDiffs++;
                        }
@@ -85,7 +85,12 @@
                for ( i = 0; i < results.length; i++ ) {
                        result = results[i];
 
-                       output += '<testcase name="' + encodeAttribute( prefix 
+ ':' + title ) + ' character ' + result.offset[0].start + '">';
+                       output += '<testcase name="' + encodeAttribute( prefix 
+ ':' + title );
+                       output += ' character ' + result.offset[0].start;
+                       if (result.selser) {
+                               output += ' (selser)';
+                       }
+                       output += '">';
 
                        if ( result.type === 'fail' ) {
                                output += '<failure 
type="significantHtmlDiff">\n';
@@ -506,7 +511,7 @@
                                                if ( err ) {
                                                        cb( err, env, [] );
                                                } else {
-                                                       // And now, request the 
wikitext for the obtained HTML
+                                                       // Now, request the 
wikitext for the obtained HTML
                                                        parsoidPost( env, 
options.parsoidURL, prefix, page,
                                                                htmlBody, 
src_and_metadata.revision.revid, function ( err, wtBody ) {
                                                                        if ( 
err ) {
@@ -517,7 +522,39 @@
                                                                                
        env.profile.time.total += new Date() - env.profile.time.total_timer;
                                                                                
        delete( env.profile.time.total_timer );
                                                                                
}
-                                                                               
roundTripDiff( env, htmlBody, wtBody, cb );
+
+                                                                               
// Modify the obtained HTML and then request
+                                                                               
// the wt again to compare with selser
+                                                                               
var diffCb = function (err, env, diffs) {
+                                                                               
        if (err) {
+                                                                               
                cb(err, env, diffs);
+                                                                               
        } else {
+                                                                               
                var newDocument = DU.parseHTML(htmlBody),
+                                                                               
                        newNode = 
newDocument.createComment('rtSelserEditTestComment');
+                                                                               
                newDocument.body.appendChild(newNode);
+                                                                               
                parsoidPost(env, options.parsoidURL, prefix, page,
+                                                                               
                        newDocument.body.innerHTML, 
src_and_metadata.revision.revid,
+                                                                               
                        function (err, wtSelserBody) {
+                                                                               
                                if (err) {
+                                                                               
                                        cb(err, env, []);
+                                                                               
                                } else {
+                                                                               
                                        // Remove the selser trigger comment
+                                                                               
                                        wtSelserBody = 
wtSelserBody.replace(/<!--rtSelserEditTestComment-->\n*$/, '');
+                                                                               
                                        roundTripDiff(env, htmlBody, 
wtSelserBody,
+                                                                               
                                                function (err, env, 
selserDiffs) {
+                                                                               
                                                        for (var sD in 
selserDiffs) {
+                                                                               
                                                                
selserDiffs[sD].selser = true;
+                                                                               
                                                        }
+                                                                               
                                                        if (selserDiffs.length) 
{
+                                                                               
                                                                diffs = 
diffs.concat(selserDiffs);
+                                                                               
                                                        }
+                                                                               
                                                        cb(null, env, diffs);
+                                                                               
                                                });
+                                                                               
                                }
+                                                                               
                        });
+                                                                               
        }
+                                                                               
};
+                                                                               
roundTripDiff(env, htmlBody, wtBody, diffCb);
                                                                        }
                                                                } );
                                                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I071000eacc9eabe4120a0ff2a0101b70e74d8c1b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to