Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58557
Change subject: Repeatable selser changes for parserTests.
......................................................................
Repeatable selser changes for parserTests.
We use the seedable random-number generator from the alea package
(npm install after you pull this commit).
The random number generator is seeded with the test case title, so
that the changes generated are repeatable, even if tests are rearranged
or new tests added.
Change-Id: If7eaf44d55a77d985afc0ee94b7e7eaa97b3ce6b
---
M js/package.json
M js/tests/parserTests.js
2 files changed, 15 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/57/58557/1
diff --git a/js/package.json b/js/package.json
index e787040..e0728d5 100644
--- a/js/package.json
+++ b/js/package.json
@@ -3,6 +3,7 @@
"description": "Mediawiki parser for the VisualEditor.",
"version": "0.0.1",
"dependencies": {
+ "alea": "~0.0.9",
"entities": "0.1.x",
"events": "0.x.x",
"request": "2.x.x",
diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js
index 6498415..321e844 100644
--- a/js/tests/parserTests.js
+++ b/js/tests/parserTests.js
@@ -25,6 +25,7 @@
util = require( 'util' ),
async = require( 'async' ),
PEG = require('pegjs'),
+ alea = require('alea'),
// Handle options/arguments with optimist module
optimist = require('optimist');
@@ -482,6 +483,9 @@
* @param {Node} cb.document
*/
ParserTests.prototype.makeChanges = function ( item, content, changelist, cb )
{
+ // Seed the random-number generator based on the item title
+ var random = new alea(item.title);
+
cb = cb || function () {};
var initContent = content;
@@ -503,7 +507,7 @@
// Helper function for getting a random change marker
function getRandomChange() {
var o = {};
- o[changes[Math.floor( Math.random() * changes.length )]] = 1;
+ o[changes[Math.floor( random() * changes.length )]] = 1;
return o;
}
@@ -557,6 +561,9 @@
* @param {Array} cb.changelist
*/
ParserTests.prototype.generateChanges = function ( options, nonRandomChanges,
item, content, cb ) {
+ // Seed the random-number generator based on the item title
+ var random = new alea(item.title);
+
// This function won't actually change anything, but it will add change
// markers to random elements.
var child, i, changeObj, node, changelist = [], numAttempts = 0;
@@ -574,8 +581,6 @@
changeObj = 0;
}
};
-
- item = item || {};
do {
node = content.cloneNode( true );
@@ -596,10 +601,13 @@
if ( nonRandomChanges === null) {
if ( DOMUtils.isNodeEditable( this.env, child )
) {
- if ( Math.random() < 0.5 ) {
- changeObj = Math.floor(
Math.random() * 4 ) + 1;
+ if ( random() < 0.5 ) {
+ changeObj = Math.floor(
random() * 4 ) + 1;
} else {
- this.generateChanges( options,
null, null, child, setChange );
+ this.generateChanges( options,
null,
+ // ensure
the subtree has a seed
+ { title:
''+random.uint32() },
+ child,
setChange );
}
} else {
changeObj = 0;
--
To view, visit https://gerrit.wikimedia.org/r/58557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If7eaf44d55a77d985afc0ee94b7e7eaa97b3ce6b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits