diff --git a/lib/logging/console.js b/lib/logging/console.js index 76dd9c8..7888977 100644 --- a/lib/logging/console.js +++ b/lib/logging/console.js @@ -61,7 +61,7 @@ var logger = (function () { // eslint-disable-line no-unused-vars } function comment (msg) { - dumpln('/* ' + msg + ' */') + dumpln('/*L*/ // ' + msg) } function separator () { diff --git a/lib/make/arrays.js b/lib/make/arrays.js index c7c8dae..50a25a6 100644 --- a/lib/make/arrays.js +++ b/lib/make/arrays.js @@ -5,10 +5,13 @@ make.arrays = { filledArray: function (fn, limit) { let array = [] - let size = limit || random.number(make.number.tiny) + let size = limit || random.number(make.number.tiny()) + 1 for (let i = 0; i < size; i++) { - array.push(random.pick(fn)) + let value = random.pick(fn) + if (value !== undefined) { + array.push(value) + } } return array diff --git a/lib/make/command.js b/lib/make/command.js index c92b2e3..c75cda6 100644 --- a/lib/make/command.js +++ b/lib/make/command.js @@ -6,32 +6,32 @@ make.command = { _data: { 'backcolor': function () { return make.colors.any() }, 'bold': null, - 'contentReadOnly': function () { random.bool() }, + 'contentReadOnly': function () { return random.bool() }, 'copy': null, - 'createlink': function () { make.uri.any() }, + 'createlink': function () { return make.uri.any() }, 'cut': null, 'decreasefontsize': null, 'delete': null, - 'enableInlineTableEditing': function () { random.bool() }, - 'enableObjectResizing': function () { random.bool() }, - 'fontname': function () { make.font.family() }, - 'fontsize': function () { make.font.relativeSize() }, + 'enableInlineTableEditing': function () { return random.bool() }, + 'enableObjectResizing': function () { return random.bool() }, + 'fontname': function () { return make.font.family() }, + 'fontsize': function () { return make.font.relativeSize() }, 'formatblock': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div'], 'forwarddelete': null, - 'forecolor': function () { make.colors.any() }, + 'forecolor': function () { return make.colors.any() }, 'gethtml': null, 'heading': null, - 'hilitecolor': function () { make.colors.any() }, + 'hilitecolor': function () { return make.colors.any() }, 'increasefontsize': null, 'indent': null, - 'insertBrOnReturn': function () { random.bool() }, + 'insertBrOnReturn': function () { return random.bool() }, 'inserthorizontalrule': null, // 'inserthtml': function () { }, 'insertlinebreak': null, - 'insertimage': function () { make.uri.any() }, + 'insertimage': function () { return make.uri.any() }, 'insertorderedlist': null, 'insertparagraph': null, - 'inserttext': function () { make.text.any() }, + 'inserttext': function () { return make.text.any() }, 'insertunorderedlist': null, 'italic': null, 'justifycenter': null, @@ -44,7 +44,7 @@ make.command = { 'removeformat': null, 'selectall': null, 'strikethrough': null, - 'styleWithCSS': function () { random.bool() }, + 'styleWithCSS': function () { return random.bool() }, 'subscript': null, 'superscript': null, 'underline': null, diff --git a/lib/make/network.js b/lib/make/network.js index c6a42da..32973cd 100644 --- a/lib/make/network.js +++ b/lib/make/network.js @@ -77,6 +77,24 @@ make.network = { '2001:db8::1:1:1:1:1' ] }, + hostname: function () { + return random.pick([this.randomIPv4, this.randomIPv6, this.goodHostnames, this.badHostnames]) + }, + port: function () { + return random.pick([80, 443, 21, 23, 9310]) + }, + hash: function () { + return random.pick(['', '#', '#main-content', function () { return '#' + make.text.any() }]) + }, + path: function () { + return random.pick(['', '/', '/index.html', function () { return '/' + make.text.any() }]) + }, + protocol: function () { + return random.pick(['http:', 'https:', 'ftp:', 'telnet:', 'chrome:', 'resource:']) + }, + search: function () { + return random.pick(['', '?', '?foo=bar', function () { return '?' + make.text.any() }]) + }, randomBitmask: function (list) { if (list.length <= 1) { return list.join('') diff --git a/lib/make/numbers.js b/lib/make/numbers.js index f7dfded..63c35bb 100644 --- a/lib/make/numbers.js +++ b/lib/make/numbers.js @@ -41,7 +41,7 @@ make.number = { if (random.chance(2)) { return Math.abs(make.number.any()) } - return Math.pow(2, random.number(65)) + random.number(3) - 1 + return Math.pow(2, random.number(random.number(65))) + random.number(3) - 1 }, even: function (number) { return number % 2 === 1 ? ++number : number diff --git a/lib/make/style.js b/lib/make/style.js new file mode 100644 index 0000000..ad24b1c --- /dev/null +++ b/lib/make/style.js @@ -0,0 +1,16 @@ +make.style = { + pseudoElement: function () { + return random.item([ + '::after', + '::before', + '::cue', + '::first-letter', + '::first-line', + '::selection', + '::backdrop', + '::placeholder', + '::marker', + '::spelling-error', + '::grammar-error']) + } +} diff --git a/lib/make/text.js b/lib/make/text.js index 9ebf77f..f243322 100644 --- a/lib/make/text.js +++ b/lib/make/text.js @@ -216,7 +216,7 @@ make.text = { // This might be too slow to used for all 'texts' uses let s = '' // TODO: Len calculation take from DOMFuzz - maybe we should revise this? - let len = random.number(1000) * random.number(10) + random.number(10) + let len = random.pick([make.number.tiny, make.number.range]) for (let i = 0; i < len; i++) { s += make.text.chars() } diff --git a/lib/make/time.js b/lib/make/time.js new file mode 100644 index 0000000..bf553e8 --- /dev/null +++ b/lib/make/time.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +make.time = { + unit: function () { + return random.pick([ + 's', 'ms' + ]) + }, + any: function () { + return make.number.any() + make.time.unit() + } +} diff --git a/lib/random/random.js b/lib/random/random.js index cac4191..3811eef 100644 --- a/lib/random/random.js +++ b/lib/random/random.js @@ -50,10 +50,11 @@ var random = { // eslint-disable-line no-unused-vars return Math.exp(this.float() * Math.log(limit)) }, item: function (list) { - if (!(Array.isArray(list) || (list !== undefined && typeof list !== 'string' && list.hasOwnProperty('length')))) { + if (list === undefined || typeof list === 'string' || list.length === undefined) { logger.traceback() - throw new TypeError('this.item() received a non array type: \'' + list + '\'') + throw new TypeError('random.item() received an invalid object: \'' + list + '\'') } + return list[this.number(list.length)] }, key: function (obj) { diff --git a/lib/utils/prototypes.js b/lib/utils/prototypes.js index 014449e..e50d95c 100644 --- a/lib/utils/prototypes.js +++ b/lib/utils/prototypes.js @@ -69,7 +69,7 @@ Object.defineProperty(Array.prototype, 'extend', { Object.defineProperty(Object, 'isObject', { value: function (obj) { - return (obj != null && typeof obj === 'object' && + return (obj !== null && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]') } }) diff --git a/tests/random/random.js b/tests/random/random.js index b0bedc5..bc0a4eb 100644 --- a/tests/random/random.js +++ b/tests/random/random.js @@ -179,10 +179,10 @@ QUnit.test("random.ludOneTo() distribution", function(assert) { }); QUnit.test("random.item() exception cases", function(assert) { - assert.throws(random.item, /non array type/); - assert.throws(function(){ return random.item(1); }, /non array type/); - assert.throws(function(){ return random.item("1"); }, /non array type/); - assert.throws(function(){ return random.item({}); }, /non array type/); + assert.throws(random.item, /received an invalid object/); + assert.throws(function(){ return random.item(1); }, /received an invalid object/); + assert.throws(function(){ return random.item("1"); }, /received an invalid object/); + assert.throws(function(){ return random.item({}); }, /received an invalid object/); }); QUnit.test("random.item() distribution with list", function(assert) {