Catrope has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350970 )

Change subject: [WIP] Convert a log file to a test case
......................................................................

[WIP] Convert a log file to a test case

Totally untested code

Change-Id: I0226bd5f3ed1323abd4de51e0c650553b4505333
---
A rebaser/logToTestCase.js
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/70/350970/1

diff --git a/rebaser/logToTestCase.js b/rebaser/logToTestCase.js
new file mode 100644
index 0000000..a814f8a
--- /dev/null
+++ b/rebaser/logToTestCase.js
@@ -0,0 +1,64 @@
+/* eslint-disable no-console */
+
+var ve = require( '../dist/ve-rebaser.js' );
+
+/**
+ * Parse log file contents.
+ *
+ * @param {string} log Newline-separated list of JSON objects
+ * @return {Object[]} Array of parsed objects
+ */
+function parseLog( log ) {
+       var i,
+               result = [],
+               lines = log.split( '\n' );
+       for ( i = 0; i < lines.length; i++ ) {
+               result.push( JSON.parse( lines[ i ] ) );
+       }
+       return result;
+}
+
+function toTestCase( parsedLog ) {
+       var i, type, author, changes, newChanges,
+               clients = [],
+               ops = [],
+               clientUnsentCounts = {};
+       for ( i = 0; i < parsedLog.length; i++ ) {
+               type = parsedLog[ i ].type;
+               author = parsedLog[ i ].author;
+               if ( type === 'newClient' ) {
+                       clients.push( author );
+                       clientUnsentCounts[ author ] = 0;
+               } else if ( type === 'applyChange' ) {
+                       ops.push( [ author, 'deliver' ] );
+               } else if ( type === 'acceptChange' ) {
+                       changes = ve.dm.Change.static.unserialize( parsedLog[ i 
].unsent, null, true );
+                       newChanges = changes.mostRecent( changes.start + 
clientUnsentCounts[ author ] );
+                       if ( newChanges.getLength() > 0 ) {
+                               ops.push( [ author, 'apply', 
newChanges.serialize( true ) ] );
+                               clientUnsentCounts[ author ] = 
changes.getLength();
+                       }
+
+                       ops.push( [ author, 'receive' ] );
+               } else if ( type === 'submitChange' ) {
+                       changes = ve.dm.Change.static.unserialize( parsedLog[ i 
].change );
+                       newChanges = changes.mostRecent( changes.start + 
clientUnsentCounts[ author ] );
+                       if ( newChanges.getLength() > 0 ) {
+                               ops.push( [ author, 'apply', 
newChanges.serialize( true ) ] );
+                               clientUnsentCounts[ author ] = 0;
+                       }
+                       ops.push( [ author, 'submit' ] );
+               }
+       }
+       return {
+               initialData: [],
+               clients: clients,
+               ops: ops
+       };
+}
+
+// acceptChange
+// submitChange
+// applyChange
+// newClient
+// disconnect

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0226bd5f3ed1323abd4de51e0c650553b4505333
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

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

Reply via email to