From 2af8948f6843d7a72ed2df34b75e8980898d83db Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Tue, 4 Aug 2020 19:01:42 +0200 Subject: [PATCH] move duplicated code to helper.js --- .../easysync/attributionlinemutations.js | 13 +- tests/backend/specs/easysync/compose.js | 193 +-------------- tests/backend/specs/easysync/follow.js | 193 +-------------- tests/backend/specs/easysync/helper.js | 229 ++++++++++++++++++ tests/backend/specs/easysync/inverserandom.js | 225 +---------------- .../specs/easysync/makeattribsstring.js | 15 +- tests/backend/specs/easysync/other.js | 20 +- .../easysync/testSplitJoinAttributionLines.js | 32 +-- 8 files changed, 248 insertions(+), 672 deletions(-) diff --git a/tests/backend/specs/easysync/attributionlinemutations.js b/tests/backend/specs/easysync/attributionlinemutations.js index f717f776d..d5f503da8 100644 --- a/tests/backend/specs/easysync/attributionlinemutations.js +++ b/tests/backend/specs/easysync/attributionlinemutations.js @@ -3,6 +3,7 @@ var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; var assertEqualArrays = helper.assertEqualArrays; +var poolOrArray = helper.poolOrArray; describe("attribution line mutations",function(){ it("turns 123\\n 456\\n 789\\n into 123\\n 456\\n 789\\n",function(done){ @@ -92,18 +93,6 @@ var testPoolWithChars = (function () { })(); -function poolOrArray(attribs) { - if (attribs.getAttrib) { - return attribs; // it's already an attrib pool - } else { - // assume it's an array of attrib strings to be split and added - var p = new AttributePool(); - attribs.forEach(function (kv) { - p.putAttrib(kv.split(',')); - }); - return p; - } -} diff --git a/tests/backend/specs/easysync/compose.js b/tests/backend/specs/easysync/compose.js index 93e7be924..9586f801f 100644 --- a/tests/backend/specs/easysync/compose.js +++ b/tests/backend/specs/easysync/compose.js @@ -2,6 +2,10 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; +var random = helper.random; +var randomMultiline = helper.randomMultiline; +var randomInlineString = helper.randomInlineString; +var randomTestChangeset = helper.randomTestChangeset; describe("Changeset.compose",function(){ it("composes all the changesets - BUT THIS only calls applyToText?!?",function(done){ @@ -53,192 +57,3 @@ function testCompose(randomSeed) { assertEqualStrings(text3, Changeset.applyToText(change123, startText)); } -function random() { - this.nextInt = function (maxValue) { - return Math.floor(Math.random() * maxValue); - } - - // maxValue is not used - this.nextDouble = function (maxValue) { - return Math.random(); - } -} - function randomMultiline(approxMaxLines, approxMaxCols, rand) { - var numParts = rand.nextInt(approxMaxLines * 2) + 1; - var txt = Changeset.stringAssembler(); - txt.append(rand.nextInt(2) ? '\n' : ''); - for (var i = 0; i < numParts; i++) { - if ((i % 2) == 0) { - if (rand.nextInt(10)) { - txt.append(randomInlineString(rand.nextInt(approxMaxCols) + 1, rand)); - } else { - txt.append('\n'); - } - } else { - txt.append('\n'); - } - } - return txt.toString(); - } - function randomInlineString(len, rand) { - var assem = Changeset.stringAssembler(); - for (var i = 0; i < len; i++) { - assem.append(String.fromCharCode(rand.nextInt(26) + 97)); - } - return assem.toString(); - } - function randomTestChangeset(origText, rand, withAttribs) { - var charBank = Changeset.stringAssembler(); - var textLeft = origText; // always keep final newline - var outTextAssem = Changeset.stringAssembler(); - var opAssem = Changeset.smartOpAssembler(); - var oldLen = origText.length; - - var nextOp = Changeset.newOp(); - - function appendMultilineOp(opcode, txt) { - nextOp.opcode = opcode; - if (withAttribs) { - nextOp.attribs = randomTwoPropAttribs(opcode, rand); - } - txt.replace(/\n|[^\n]+/g, function (t) { - if (t == '\n') { - nextOp.chars = 1; - nextOp.lines = 1; - opAssem.append(nextOp); - } else { - nextOp.chars = t.length; - nextOp.lines = 0; - opAssem.append(nextOp); - } - return ''; - }); - } - - function doOp() { - var o = randomStringOperation(textLeft.length, rand); - if (o.insert) { - var txt = o.insert; - charBank.append(txt); - outTextAssem.append(txt); - appendMultilineOp('+', txt); - } else if (o.skip) { - txt = textLeft.substring(0, o.skip); - textLeft = textLeft.substring(o.skip); - outTextAssem.append(txt); - appendMultilineOp('=', txt); - } else if (o.remove) { - txt = textLeft.substring(0, o.remove); - textLeft = textLeft.substring(o.remove); - appendMultilineOp('-', txt); - } - } - - while (textLeft.length > 1) doOp(); - for (var i = 0; i < 5; i++) doOp(); // do some more (only insertions will happen) - var outText = outTextAssem.toString() + '\n'; - opAssem.endDocument(); - var cs = Changeset.pack(oldLen, outText.length, opAssem.toString(), charBank.toString()); - Changeset.checkRep(cs); - return [cs, outText]; - } - function randomStringOperation(numCharsLeft, rand) { - var result; - switch (rand.nextInt(9)) { - case 0: - { - // insert char - result = { - insert: randomInlineString(1, rand) - }; - break; - } - case 1: - { - // delete char - result = { - remove: 1 - }; - break; - } - case 2: - { - // skip char - result = { - skip: 1 - }; - break; - } - case 3: - { - // insert small - result = { - insert: randomInlineString(rand.nextInt(4) + 1, rand) - }; - break; - } - case 4: - { - // delete small - result = { - remove: rand.nextInt(4) + 1 - }; - break; - } - case 5: - { - // skip small - result = { - skip: rand.nextInt(4) + 1 - }; - break; - } - case 6: - { - // insert multiline; - result = { - insert: randomMultiline(5, 20, rand) - }; - break; - } - case 7: - { - // delete multiline - result = { - remove: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 8: - { - // skip multiline - result = { - skip: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 9: - { - // delete to end - result = { - remove: numCharsLeft - }; - break; - } - case 10: - { - // skip to end - result = { - skip: numCharsLeft - }; - break; - } - } - var maxOrig = numCharsLeft - 1; - if ('remove' in result) { - result.remove = Math.min(result.remove, maxOrig); - } else if ('skip' in result) { - result.skip = Math.min(result.skip, maxOrig); - } - return result; - } diff --git a/tests/backend/specs/easysync/follow.js b/tests/backend/specs/easysync/follow.js index a9c7d9210..580eee869 100644 --- a/tests/backend/specs/easysync/follow.js +++ b/tests/backend/specs/easysync/follow.js @@ -3,6 +3,10 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; var assertEqualArrays = helper.assertEqualArrays; +var random = helper.random; +var randomMultiline = helper.randomMultiline; +var randomInlineString = helper.randomInlineString; +var randomTestChangeset = helper.randomTestChangeset; describe("follow",function(){ it("follows",function(done){ @@ -50,192 +54,3 @@ describe("follow",function(){ assertEqualStrings(merge1, merge2); } -function random() { - this.nextInt = function (maxValue) { - return Math.floor(Math.random() * maxValue); - } - - // maxValue is not used - this.nextDouble = function (maxValue) { - return Math.random(); - } -} - function randomMultiline(approxMaxLines, approxMaxCols, rand) { - var numParts = rand.nextInt(approxMaxLines * 2) + 1; - var txt = Changeset.stringAssembler(); - txt.append(rand.nextInt(2) ? '\n' : ''); - for (var i = 0; i < numParts; i++) { - if ((i % 2) == 0) { - if (rand.nextInt(10)) { - txt.append(randomInlineString(rand.nextInt(approxMaxCols) + 1, rand)); - } else { - txt.append('\n'); - } - } else { - txt.append('\n'); - } - } - return txt.toString(); - } - function randomInlineString(len, rand) { - var assem = Changeset.stringAssembler(); - for (var i = 0; i < len; i++) { - assem.append(String.fromCharCode(rand.nextInt(26) + 97)); - } - return assem.toString(); - } - function randomTestChangeset(origText, rand, withAttribs) { - var charBank = Changeset.stringAssembler(); - var textLeft = origText; // always keep final newline - var outTextAssem = Changeset.stringAssembler(); - var opAssem = Changeset.smartOpAssembler(); - var oldLen = origText.length; - - var nextOp = Changeset.newOp(); - - function appendMultilineOp(opcode, txt) { - nextOp.opcode = opcode; - if (withAttribs) { - nextOp.attribs = randomTwoPropAttribs(opcode, rand); - } - txt.replace(/\n|[^\n]+/g, function (t) { - if (t == '\n') { - nextOp.chars = 1; - nextOp.lines = 1; - opAssem.append(nextOp); - } else { - nextOp.chars = t.length; - nextOp.lines = 0; - opAssem.append(nextOp); - } - return ''; - }); - } - - function doOp() { - var o = randomStringOperation(textLeft.length, rand); - if (o.insert) { - var txt = o.insert; - charBank.append(txt); - outTextAssem.append(txt); - appendMultilineOp('+', txt); - } else if (o.skip) { - txt = textLeft.substring(0, o.skip); - textLeft = textLeft.substring(o.skip); - outTextAssem.append(txt); - appendMultilineOp('=', txt); - } else if (o.remove) { - txt = textLeft.substring(0, o.remove); - textLeft = textLeft.substring(o.remove); - appendMultilineOp('-', txt); - } - } - - while (textLeft.length > 1) doOp(); - for (var i = 0; i < 5; i++) doOp(); // do some more (only insertions will happen) - var outText = outTextAssem.toString() + '\n'; - opAssem.endDocument(); - var cs = Changeset.pack(oldLen, outText.length, opAssem.toString(), charBank.toString()); - Changeset.checkRep(cs); - return [cs, outText]; - } - function randomStringOperation(numCharsLeft, rand) { - var result; - switch (rand.nextInt(9)) { - case 0: - { - // insert char - result = { - insert: randomInlineString(1, rand) - }; - break; - } - case 1: - { - // delete char - result = { - remove: 1 - }; - break; - } - case 2: - { - // skip char - result = { - skip: 1 - }; - break; - } - case 3: - { - // insert small - result = { - insert: randomInlineString(rand.nextInt(4) + 1, rand) - }; - break; - } - case 4: - { - // delete small - result = { - remove: rand.nextInt(4) + 1 - }; - break; - } - case 5: - { - // skip small - result = { - skip: rand.nextInt(4) + 1 - }; - break; - } - case 6: - { - // insert multiline; - result = { - insert: randomMultiline(5, 20, rand) - }; - break; - } - case 7: - { - // delete multiline - result = { - remove: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 8: - { - // skip multiline - result = { - skip: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 9: - { - // delete to end - result = { - remove: numCharsLeft - }; - break; - } - case 10: - { - // skip to end - result = { - skip: numCharsLeft - }; - break; - } - } - var maxOrig = numCharsLeft - 1; - if ('remove' in result) { - result.remove = Math.min(result.remove, maxOrig); - } else if ('skip' in result) { - result.skip = Math.min(result.skip, maxOrig); - } - return result; - } diff --git a/tests/backend/specs/easysync/helper.js b/tests/backend/specs/easysync/helper.js index e01980ed6..06b42307d 100644 --- a/tests/backend/specs/easysync/helper.js +++ b/tests/backend/specs/easysync/helper.js @@ -1,3 +1,6 @@ +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); +var Changeset = require("ep_etherpad-lite/static/js/Changeset") + exports.assert = function (code, optMsg) { if (!eval(code)) throw new Error("FALSE: " + (optMsg || code)); }; @@ -37,3 +40,229 @@ exports.throughSmartAssembler = function (opsStr) { assem.endDocument(); return assem.toString(); } +exports.poolOrArray = function (attribs) { + if (attribs.getAttrib) { + return attribs; // it's already an attrib pool + } else { + // assume it's an array of attrib strings to be split and added + var p = new AttributePool(); + attribs.forEach(function (kv) { + p.putAttrib(kv.split(',')); + }); + return p; + } +} +exports.random = function () { + this.nextInt = function (maxValue) { + return Math.floor(Math.random() * maxValue); + } + + // maxValue is not used + this.nextDouble = function (maxValue) { + return Math.random(); + } +} +exports.randomInlineString = function (len, rand) { + var assem = Changeset.stringAssembler(); + for (var i = 0; i < len; i++) { + assem.append(String.fromCharCode(rand.nextInt(26) + 97)); + } + return assem.toString(); +} + +exports.randomMultiline = function (approxMaxLines, approxMaxCols, rand) { + var numParts = rand.nextInt(approxMaxLines * 2) + 1; + var txt = Changeset.stringAssembler(); + txt.append(rand.nextInt(2) ? '\n' : ''); + for (var i = 0; i < numParts; i++) { + if ((i % 2) == 0) { + if (rand.nextInt(10)) { + txt.append(exports.randomInlineString(rand.nextInt(approxMaxCols) + 1, rand)); + } else { + txt.append('\n'); + } + } else { + txt.append('\n'); + } + } + return txt.toString(); +} + +exports.randomStringOperation = function (numCharsLeft, rand) { + var result; + switch (rand.nextInt(9)) { + case 0: + { + // insert char + result = { + insert: exports.randomInlineString(1, rand) + }; + break; + } + case 1: + { + // delete char + result = { + remove: 1 + }; + break; + } + case 2: + { + // skip char + result = { + skip: 1 + }; + break; + } + case 3: + { + // insert small + result = { + insert: exports.randomInlineString(rand.nextInt(4) + 1, rand) + }; + break; + } + case 4: + { + // delete small + result = { + remove: rand.nextInt(4) + 1 + }; + break; + } + case 5: + { + // skip small + result = { + skip: rand.nextInt(4) + 1 + }; + break; + } + case 6: + { + // insert multiline; + result = { + insert: exports.randomMultiline(5, 20, rand) + }; + break; + } + case 7: + { + // delete multiline + result = { + remove: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) + }; + break; + } + case 8: + { + // skip multiline + result = { + skip: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) + }; + break; + } + // this is never tested + case 9: + { + // delete to end + result = { + remove: numCharsLeft + }; + break; + } + // this is never tested + case 10: + { + // skip to end + result = { + skip: numCharsLeft + }; + break; + } + } + var maxOrig = numCharsLeft - 1; + if ('remove' in result) { + result.remove = Math.min(result.remove, maxOrig); + } else if ('skip' in result) { + result.skip = Math.min(result.skip, maxOrig); + } + return result; +} + +exports.randomTwoPropAttribs = function (opcode, rand) { + // assumes attrib pool like ['apple,','apple,true','banana,','banana,true'] + if (opcode == '-' || rand.nextInt(3)) { + return ''; + // always true + } else if (rand.nextInt(3)) { + if (opcode == '+' || rand.nextInt(2)) { + return '*' + Changeset.numToString(rand.nextInt(2) * 2 + 1); + } else { + return '*' + Changeset.numToString(rand.nextInt(2) * 2); + } + } else { + if (opcode == '+' || rand.nextInt(4) == 0) { + return '*1*3'; + } else { + return ['*0*2', '*0*3', '*1*2'][rand.nextInt(3)]; + } + } +} + +exports.randomTestChangeset = function (origText, rand, withAttribs) { + var charBank = Changeset.stringAssembler(); + var textLeft = origText; // always keep final newline + var outTextAssem = Changeset.stringAssembler(); + var opAssem = Changeset.smartOpAssembler(); + var oldLen = origText.length; + + var nextOp = Changeset.newOp(); + + function appendMultilineOp(opcode, txt) { + nextOp.opcode = opcode; + if (withAttribs) { + nextOp.attribs = exports.randomTwoPropAttribs(opcode, rand); + } + txt.replace(/\n|[^\n]+/g, function (t) { + if (t == '\n') { + nextOp.chars = 1; + nextOp.lines = 1; + opAssem.append(nextOp); + } else { + nextOp.chars = t.length; + nextOp.lines = 0; + opAssem.append(nextOp); + } + return ''; + }); + } + + function doOp() { + var o = exports.randomStringOperation(textLeft.length, rand); + if (o.insert) { + var txt = o.insert; + charBank.append(txt); + outTextAssem.append(txt); + appendMultilineOp('+', txt); + } else if (o.skip) { + var txt = textLeft.substring(0, o.skip); + textLeft = textLeft.substring(o.skip); + outTextAssem.append(txt); + appendMultilineOp('=', txt); + } else if (o.remove) { + var txt = textLeft.substring(0, o.remove); + textLeft = textLeft.substring(o.remove); + appendMultilineOp('-', txt); + } + } + + while (textLeft.length > 1) doOp(); + for (var i = 0; i < 5; i++) doOp(); // do some more (only insertions will happen) + var outText = outTextAssem.toString() + '\n'; + opAssem.endDocument(); + var cs = Changeset.pack(oldLen, outText.length, opAssem.toString(), charBank.toString()); + Changeset.checkRep(cs); + return [cs, outText]; +} diff --git a/tests/backend/specs/easysync/inverserandom.js b/tests/backend/specs/easysync/inverserandom.js index 999f41c69..751805053 100644 --- a/tests/backend/specs/easysync/inverserandom.js +++ b/tests/backend/specs/easysync/inverserandom.js @@ -2,6 +2,11 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var helper = require("./helper.js") var assertEqualArrays = helper.assertEqualArrays; +var random = helper.random; +var poolOrArray = helper.poolOrArray; +var randomMultiline = helper.randomMultiline; +var randomInlineString = helper.randomInlineString; +var randomTestChangeset = helper.randomTestChangeset; describe("inverseRandom",function(){ it("inverseRandom",function(done){ @@ -51,224 +56,4 @@ describe("inverseRandom",function(){ assertEqualArrays(origALines, alines); } -function random() { - this.nextInt = function (maxValue) { - return Math.floor(Math.random() * maxValue); - } - - // maxValue is not used - this.nextDouble = function (maxValue) { - return Math.random(); - } -} - function poolOrArray(attribs) { - if (attribs.getAttrib) { - return attribs; // it's already an attrib pool - } else { - // assume it's an array of attrib strings to be split and added - var p = new AttributePool(); - attribs.forEach(function (kv) { - p.putAttrib(kv.split(',')); - }); - return p; - } - } - function randomMultiline(approxMaxLines, approxMaxCols, rand) { - var numParts = rand.nextInt(approxMaxLines * 2) + 1; - var txt = Changeset.stringAssembler(); - txt.append(rand.nextInt(2) ? '\n' : ''); - for (var i = 0; i < numParts; i++) { - if ((i % 2) == 0) { - if (rand.nextInt(10)) { - txt.append(randomInlineString(rand.nextInt(approxMaxCols) + 1, rand)); - } else { - txt.append('\n'); - } - } else { - txt.append('\n'); - } - } - return txt.toString(); - } - function randomInlineString(len, rand) { - var assem = Changeset.stringAssembler(); - for (var i = 0; i < len; i++) { - assem.append(String.fromCharCode(rand.nextInt(26) + 97)); - } - return assem.toString(); - } - function randomTestChangeset(origText, rand, withAttribs) { - var charBank = Changeset.stringAssembler(); - var textLeft = origText; // always keep final newline - var outTextAssem = Changeset.stringAssembler(); - var opAssem = Changeset.smartOpAssembler(); - var oldLen = origText.length; - - var nextOp = Changeset.newOp(); - - function appendMultilineOp(opcode, txt) { - nextOp.opcode = opcode; - if (withAttribs) { - nextOp.attribs = randomTwoPropAttribs(opcode, rand); - } - txt.replace(/\n|[^\n]+/g, function (t) { - if (t == '\n') { - nextOp.chars = 1; - nextOp.lines = 1; - opAssem.append(nextOp); - } else { - nextOp.chars = t.length; - nextOp.lines = 0; - opAssem.append(nextOp); - } - return ''; - }); - } - - function doOp() { - var o = randomStringOperation(textLeft.length, rand); - if (o.insert) { - var txt = o.insert; - charBank.append(txt); - outTextAssem.append(txt); - appendMultilineOp('+', txt); - } else if (o.skip) { - txt = textLeft.substring(0, o.skip); - textLeft = textLeft.substring(o.skip); - outTextAssem.append(txt); - appendMultilineOp('=', txt); - } else if (o.remove) { - txt = textLeft.substring(0, o.remove); - textLeft = textLeft.substring(o.remove); - appendMultilineOp('-', txt); - } - } - - while (textLeft.length > 1) doOp(); - for (var i = 0; i < 5; i++) doOp(); // do some more (only insertions will happen) - var outText = outTextAssem.toString() + '\n'; - opAssem.endDocument(); - var cs = Changeset.pack(oldLen, outText.length, opAssem.toString(), charBank.toString()); - Changeset.checkRep(cs); - return [cs, outText]; - } - function randomStringOperation(numCharsLeft, rand) { - var result; - switch (rand.nextInt(9)) { - case 0: - { - // insert char - result = { - insert: randomInlineString(1, rand) - }; - break; - } - case 1: - { - // delete char - result = { - remove: 1 - }; - break; - } - case 2: - { - // skip char - result = { - skip: 1 - }; - break; - } - case 3: - { - // insert small - result = { - insert: randomInlineString(rand.nextInt(4) + 1, rand) - }; - break; - } - case 4: - { - // delete small - result = { - remove: rand.nextInt(4) + 1 - }; - break; - } - case 5: - { - // skip small - result = { - skip: rand.nextInt(4) + 1 - }; - break; - } - case 6: - { - // insert multiline; - result = { - insert: randomMultiline(5, 20, rand) - }; - break; - } - case 7: - { - // delete multiline - result = { - remove: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 8: - { - // skip multiline - result = { - skip: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) - }; - break; - } - case 9: - { - // delete to end - result = { - remove: numCharsLeft - }; - break; - } - case 10: - { - // skip to end - result = { - skip: numCharsLeft - }; - break; - } - } - var maxOrig = numCharsLeft - 1; - if ('remove' in result) { - result.remove = Math.min(result.remove, maxOrig); - } else if ('skip' in result) { - result.skip = Math.min(result.skip, maxOrig); - } - return result; - } - function randomTwoPropAttribs(opcode, rand) { - // assumes attrib pool like ['apple,','apple,true','banana,','banana,true'] - if (opcode == '-' || rand.nextInt(3)) { - return ''; - // always true - } else if (rand.nextInt(3)) { - if (opcode == '+' || rand.nextInt(2)) { - return '*' + Changeset.numToString(rand.nextInt(2) * 2 + 1); - } else { - return '*' + Changeset.numToString(rand.nextInt(2) * 2); - } - } else { - if (opcode == '+' || rand.nextInt(4) == 0) { - return '*1*3'; - } else { - return ['*0*2', '*0*3', '*1*2'][rand.nextInt(3)]; - } - } - } diff --git a/tests/backend/specs/easysync/makeattribsstring.js b/tests/backend/specs/easysync/makeattribsstring.js index b666a6b0a..87dcb27c9 100644 --- a/tests/backend/specs/easysync/makeattribsstring.js +++ b/tests/backend/specs/easysync/makeattribsstring.js @@ -1,8 +1,7 @@ - var Changeset = require("ep_etherpad-lite/static/js/Changeset"); -var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; +var poolOrArray = helper.poolOrArray; describe("make attribs string",function(){ it("make attribs string",function(done){ testMakeAttribsString(1, ['bold,'], '+', [ @@ -32,15 +31,3 @@ describe("make attribs string",function(){ assertEqualStrings(correctString, str); } - function poolOrArray(attribs) { - if (attribs.getAttrib) { - return attribs; // it's already an attrib pool - } else { - // assume it's an array of attrib strings to be split and added - var p = new AttributePool(); - attribs.forEach(function (kv) { - p.putAttrib(kv.split(',')); - }); - return p; - } - } diff --git a/tests/backend/specs/easysync/other.js b/tests/backend/specs/easysync/other.js index c5d6ab1ed..25ac0f090 100644 --- a/tests/backend/specs/easysync/other.js +++ b/tests/backend/specs/easysync/other.js @@ -1,10 +1,10 @@ - var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; var assertEqualArrays = helper.assertEqualArrays; var assert = helper.assert; +var poolOrArray = helper.poolOrArray; describe("other",function(){ @@ -147,21 +147,3 @@ describe("other",function(){ } - function poolOrArray(attribs) { - if (attribs.getAttrib) { - return attribs; // it's already an attrib pool - } else { - // assume it's an array of attrib strings to be split and added - var p = new AttributePool(); - attribs.forEach(function (kv) { - p.putAttrib(kv.split(',')); - }); - return p; - } - } - function literal(v) { - if ((typeof v) == "string") { - return '"' + v.replace(/[\\\"]/g, '\\$1').replace(/\n/g, '\\n') + '"'; - } else - return JSON.stringify(v); - } diff --git a/tests/backend/specs/easysync/testSplitJoinAttributionLines.js b/tests/backend/specs/easysync/testSplitJoinAttributionLines.js index 2a40ff045..fc9d2a49e 100644 --- a/tests/backend/specs/easysync/testSplitJoinAttributionLines.js +++ b/tests/backend/specs/easysync/testSplitJoinAttributionLines.js @@ -2,6 +2,9 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var helper = require("./helper.js") var assertEqualStrings = helper.assertEqualStrings; var assertEqualArrays = helper.assertEqualArrays; +var random = helper.random; +var randomMultiline = helper.randomMultiline; +var randomInlineString = helper.randomInlineString; describe("testSplitJoinAttributionLines",function(){ it("testSplitJoinAttributionLines",function(done){ @@ -35,32 +38,3 @@ describe("testSplitJoinAttributionLines",function(){ assertEqualStrings(theJoined, Changeset.joinAttributionLines(theSplit)); } -function random() { - this.nextInt = function (maxValue) { - return Math.floor(Math.random() * maxValue); - } -} - function randomMultiline(approxMaxLines, approxMaxCols, rand) { - var numParts = rand.nextInt(approxMaxLines * 2) + 1; - var txt = Changeset.stringAssembler(); - txt.append(rand.nextInt(2) ? '\n' : ''); - for (var i = 0; i < numParts; i++) { - if ((i % 2) == 0) { - if (rand.nextInt(10)) { - txt.append(randomInlineString(rand.nextInt(approxMaxCols) + 1, rand)); - } else { - txt.append('\n'); - } - } else { - txt.append('\n'); - } - } - return txt.toString(); - } - function randomInlineString(len, rand) { - var assem = Changeset.stringAssembler(); - for (var i = 0; i < len; i++) { - assem.append(String.fromCharCode(rand.nextInt(26) + 97)); - } - return assem.toString(); - }