Fixed everything

master
Keith Irwin 2018-02-23 19:13:35 +00:00
parent 336b5a701b
commit 5d27d4e516
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
2 changed files with 23 additions and 20 deletions

View File

@ -1,11 +1,13 @@
const crypto = require('crypto') 'use strict'
/* froth /**
* num: number of test strings to return * Returns an array of random strings for fuzzing
* max: maximum length of test string * @param {number} num: number of test strings to return
* opt: options object * @param {number} max: maximum length of test string
* @param {object} opt: options
* @return {array}
*/ */
exports.froth = function(num, max, opt={ module.exports = function(num=10, max=20, opt={
// Set to true to include tests with... // Set to true to include tests with...
none: true, // Empty string none: true, // Empty string
whitespace: true, // Various whitespace chars whitespace: true, // Various whitespace chars
@ -16,10 +18,11 @@ exports.froth = function(num, max, opt={
alphanumeric: true, // Ordinary letters and numbers alphanumeric: true, // Ordinary letters and numbers
} ){ } ){
let (chars,tests) = [] let chars = []
let tests = []
// Whitespace characters // Whitespace characters
if (opt.whitespace) chars.concat([ if (opt.whitespace!==false) chars = chars.concat([
' ', // Space ' ', // Space
' ', // Tab ' ', // Tab
'\n', // Newline '\n', // Newline
@ -28,45 +31,45 @@ exports.froth = function(num, max, opt={
]) ])
// Quotation characters // Quotation characters
if (opt.quotes) chars.concat([ if (opt.quotes!==false) chars = chars.concat([
'\'', '\'\'', '\'\'\'', // Single quotes '\'', '\'\'', '\'\'\'', // Single quotes
'"', '""', '"""', // Double quotes '"', '""', '"""', // Double quotes
'`', '``', '```', // Backticks '`', '``', '```', // Backticks
]) ])
// Backslashes // Backslashes
if (opt.backslashing) chars.concat([ if (opt.backslashing!==false) chars = chars.concat([
'\\', '\\\\', '\\', '\\\\',
]) ])
// Symbols // Symbols
if (opt.symbols) chars.concat( if (opt.symbols!==false) chars = chars.concat(
'°~!@#$%€^&*()-_─=+[]{}|;:,./<>?¿¹²³¼½¬ł€¶ŧ←↓→»«¢„“”·…–'.split('') '°~!@#$%€^&*()-_─=+[]{}|;:,./<>?¿¹²³¼½¬€¶←↓→»«¢„“”·…–'.split('')
) )
// Foreign characters // Foreign characters
if (opt.foreign) chars.concat( if (opt.foreign!==false) chars = chars.concat(
'ßöäüñáóíúýéâêîôûŷàèìòùảẻỉỏỷÿïøþłĸŋđðſæµёйцукенгшщзхъэждлорпавыфячсмитьбюЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ'.split('') 'ŧłßöäüñáóíúýéâêîôûŷàèìòùảẻỉỏỷÿïøþłĸŋđðſæµёйцукенгшщзхъэждлорпавыфячсмитьбюЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ'.split('')
) )
// Ordinary letters and numbers // Ordinary letters and numbers
if (opt.alphanumeric) chars.concat( if (opt.alphanumeric!==false) chars = chars.concat(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(''), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(''),
) )
const min = (none)? 0 : 1 const min = (opt.none!==false)? 0 : 1
// Add tests until we have enough tests // Add tests until we have enough tests
for (let n=0; n<num; n++) { for (let n=0; n<num; n++) {
// Pick a random number from min to max // Pick a random number from min to max
len = Math.floor(Math.random() * (max - min + 1)) + min const len = Math.floor(Math.random() * (max - min + 1)) + min
// Create a string of that length // Create a string of that length
let s = '' let s = ''
for (let l=0; l<len; l++) { for (let l=0; l<len; l++) {
s += chars[Math.floor(Math.random()*chars.length)] s += chars[Math.floor(Math.random()*chars.length)]
} }
// Add that string to the tests // Add that string to the tests if not already
tests.push(s) if (!tests.includes(s)) tests.push(s)
} }
return tests return tests

View File

@ -1,6 +1,6 @@
{ {
"name": "mocha-froth", "name": "mocha-froth",
"version": "0.0.0", "version": "0.1.0",
"description": "Fuzzer for mocha testing", "description": "Fuzzer for mocha testing",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {