Comparing version 0.1.3 to 0.2.0
@@ -6,59 +6,75 @@ /** | ||
/*global module*/ | ||
(function () { | ||
'use strict'; | ||
"use strict"; | ||
function TestClass(var1, var2) { | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
} | ||
/** | ||
* Class only for testing. | ||
* | ||
* @param {*} var1 | ||
* @param {*} var2 | ||
*/ | ||
function TestClass(var1, var2) { | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
} | ||
TestClass.prototype.passData = function (var1, var2) { | ||
this.passData2(var1, var2); | ||
}; | ||
TestClass.prototype.passData = function (var1, var2) { | ||
this.passData2(var1, var2); | ||
}; | ||
TestClass.prototype.passData2 = function (var1, var2) { | ||
this.passData3(var1, var2); | ||
}; | ||
TestClass.prototype.passData2 = function (var1, var2) { | ||
this.passData3(var1, var2); | ||
}; | ||
TestClass.prototype.passData3 = function (var1, var2) { | ||
return var1 + var2; | ||
}; | ||
TestClass.prototype.passData3 = function (var1, var2) { | ||
return var1 + var2; | ||
}; | ||
TestClass.prototype.viaObject = function () { | ||
this.viaObject2(); | ||
}; | ||
TestClass.prototype.viaObject = function () { | ||
this.viaObject2(); | ||
}; | ||
TestClass.prototype.viaObject2 = function () { | ||
this.viaObject3(); | ||
}; | ||
TestClass.prototype.viaObject2 = function () { | ||
this.viaObject3(); | ||
}; | ||
TestClass.prototype.viaObject3 = function () { | ||
return this.var1 + this.var2; | ||
}; | ||
TestClass.prototype.viaObject3 = function () { | ||
return this.var1 + this.var2; | ||
}; | ||
function test(method) { | ||
function run(var1, var2) { | ||
var context; | ||
context = new TestClass(var1, var2); | ||
context[method](var1, var2); | ||
} | ||
/** | ||
* Benchmark function factory. | ||
* | ||
* @param {string} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
/** | ||
* Testing function | ||
* | ||
* @param {string} var1 | ||
* @param {string} var2 | ||
*/ | ||
function run(var1, var2) { | ||
var context; | ||
return function () { | ||
run(1, 1); | ||
run(2, 2); | ||
run(3, 4); | ||
run('a', 'b'); | ||
run('c', 'd'); | ||
}; | ||
context = new TestClass(var1, var2); | ||
context[method](var1, var2); | ||
} | ||
module.exports = { | ||
name: "accessing information", | ||
tests: { | ||
'passing data': test('passData'), | ||
'via object': test('viaObject') | ||
} | ||
return function () { | ||
run(1, 1); | ||
run(2, 2); | ||
run(3, 4); | ||
run("a", "b"); | ||
run("c", "d"); | ||
}; | ||
}()); | ||
} | ||
module.exports = { | ||
name: "accessing information", | ||
tests: { | ||
"passing data": test("passData"), | ||
"via object": test("viaObject") | ||
} | ||
}; |
@@ -1,44 +0,52 @@ | ||
/*global module*/ | ||
(function () { | ||
'use strict'; | ||
"use strict"; | ||
function test(method) { | ||
var values; | ||
/** | ||
* Test function factory | ||
* | ||
* @param {string} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
var values; | ||
function addValue(str) { | ||
values.push(str[method](0)); | ||
} | ||
/** | ||
* Just adds a value using the specified method | ||
* | ||
* @param {string} str | ||
*/ | ||
function addValue(str) { | ||
values.push(str[method](0)); | ||
} | ||
values = []; | ||
addValue('a'); | ||
addValue('b'); | ||
addValue('m'); | ||
addValue('m'); | ||
addValue('T'); | ||
addValue('T'); | ||
addValue(' '); | ||
addValue('*'); | ||
values = []; | ||
addValue("a"); | ||
addValue("b"); | ||
addValue("m"); | ||
addValue("m"); | ||
addValue("T"); | ||
addValue("T"); | ||
addValue(" "); | ||
addValue("*"); | ||
return function () { | ||
var i, successCount; | ||
return function () { | ||
var i, successCount; | ||
successCount = 0; | ||
successCount = 0; | ||
for (i = 0; i < values.length; i += 2) { | ||
if (values[i] === values[i + 1]) { | ||
successCount += 1; | ||
} | ||
for (i = 0; i < values.length; i += 2) { | ||
if (values[i] === values[i + 1]) { | ||
successCount += 1; | ||
} | ||
} | ||
return successCount; | ||
}; | ||
return successCount; | ||
}; | ||
} | ||
module.exports = { | ||
name: "comparison of values", | ||
tests: { | ||
"char comparison": test("charAt"), | ||
"int comparison": test("charCodeAt") | ||
} | ||
module.exports = { | ||
name: "comparison of values", | ||
tests: { | ||
'char comparison': test('charAt'), | ||
'int comparison': test('charCodeAt') | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,20 +0,22 @@ | ||
/*global module*/ | ||
(function () { | ||
'use strict'; | ||
"use strict"; | ||
function myCallback() { | ||
return undefined; | ||
} | ||
/** | ||
* Test function | ||
* | ||
* @return {undefined} | ||
*/ | ||
function myCallback() { | ||
return undefined; // eslint-disable-line no-undefined | ||
} | ||
module.exports = { | ||
name: "calling a function", | ||
tests: { | ||
'direct': function () { | ||
myCallback(); | ||
}, | ||
'call': function () { | ||
myCallback.call(); | ||
} | ||
module.exports = { | ||
name: "calling a function", | ||
tests: { | ||
direct: function () { | ||
myCallback(); | ||
}, | ||
call: function () { | ||
myCallback.call(); | ||
} | ||
}; | ||
}()); | ||
} | ||
}; |
@@ -1,45 +0,46 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
var hash, i, letters; | ||
function test(method) { | ||
return function () { | ||
method('a'); | ||
method('z'); | ||
method(' '); | ||
}; | ||
} | ||
/** | ||
* Test function factory. | ||
* | ||
* @param {Function} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
return function () { | ||
method("a"); | ||
method("z"); | ||
method(" "); | ||
}; | ||
} | ||
var hash, i, letters; | ||
hash = {}; | ||
letters = "abcdefghijklmnopqrstuvwxyz"; | ||
hash = {}; | ||
letters = 'abcdefghijklmnopqrstuvwxyz'; | ||
for (i = 0; i < letters.length; i += 1) { | ||
hash[letters.charAt(0)] = true; | ||
} | ||
for (i = 0; i < letters.length; i += 1) { | ||
hash[letters.charAt(0)] = true; | ||
module.exports = { | ||
name: "find if a character is in a set", | ||
tests: { | ||
"indexOf !== -1": test(function (c) { | ||
return letters.indexOf(c) !== -1; | ||
}), | ||
"~indexOf": test(function (c) { | ||
return ~letters.indexOf(c); // eslint-disable-line no-bitwise | ||
}), | ||
/* eslint complexity:off */ | ||
"=== letter": test(function (c) { | ||
return c === "a" || c === "b" || c === "c" || c === "d" || c === "e" || c === "f" || c === "g" || c === "h" || c === "i" || c === "j" || c === "k" || c === "l" || c === "m" || c === "n" || c === "o" || c === "p" || c === "q" || c === "r" || c === "s" || c === "t" || c === "u" || c === "v" || c === "w" || c === "x" || c === "y" || c === "z"; | ||
}), | ||
">= a and <= z": test(function (c) { | ||
return c >= "a" && c <= "z"; | ||
}), | ||
hash: test(function (c) { | ||
return hash[c]; | ||
}) | ||
} | ||
module.exports = { | ||
name: "find if a character is in a set", | ||
tests: { | ||
'indexOf !== -1': test(function (c) { | ||
return letters.indexOf(c) !== -1; | ||
}), | ||
'~indexOf': test(function (c) { | ||
/*jslint bitwise:true*/ | ||
return ~letters.indexOf(c); | ||
}), | ||
'=== letter': test(function (c) { | ||
/*jslint bitwise:false*/ | ||
return c === 'a' || c === 'b' || c === 'c' || c === 'd' || c === 'e' || c === 'f' || c === 'g' || c === 'h' || c === 'i' || c === 'j' || c === 'k' || c === 'l' || c === 'm' || c === 'n' || c === 'o' || c === 'p' || c === 'q' || c === 'r' || c === 's' || c === 't' || c === 'u' || c === 'v' || c === 'w' || c === 'x' || c === 'y' || c === 'z'; | ||
}), | ||
'>= a and <= z': test(function (c) { | ||
return c >= 'a' && c <= 'z'; | ||
}), | ||
'hash': test(function (c) { | ||
return hash[c]; | ||
}) | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,127 +0,148 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
var hash, pattern; | ||
var hash, pattern; | ||
hash = { | ||
a: true, | ||
b: true, | ||
c: true, | ||
d: true, | ||
e: true, | ||
f: true, | ||
A: true, | ||
B: true, | ||
C: true, | ||
D: true, | ||
E: true, | ||
F: true, | ||
0: true, | ||
1: true, | ||
2: true, | ||
3: true, | ||
4: true, | ||
5: true, | ||
6: true, | ||
7: true, | ||
8: true, | ||
9: true | ||
}; | ||
pattern = /^[A-Za-z0-9]{4}/; | ||
hash = { | ||
a: true, | ||
b: true, | ||
c: true, | ||
d: true, | ||
e: true, | ||
f: true, | ||
A: true, | ||
B: true, | ||
C: true, | ||
D: true, | ||
E: true, | ||
F: true, | ||
0: true, | ||
1: true, | ||
2: true, | ||
3: true, | ||
4: true, | ||
5: true, | ||
6: true, | ||
7: true, | ||
8: true, | ||
9: true | ||
}; | ||
pattern = /^[A-Za-z0-9]{4}/; | ||
/** | ||
* Check if something is in a hash | ||
* | ||
* @param {*} c | ||
* @return {boolean} | ||
*/ | ||
function inHash(c) { | ||
return hash[c]; | ||
} | ||
function inHash(c) { | ||
return hash[c]; | ||
} | ||
/** | ||
* Check if a value is hex using character ranges. | ||
* | ||
* @param {*} c | ||
* @return {boolean} | ||
*/ | ||
function isHex(c) { | ||
return c >= "A" && c <= "F" || c <= "a" && c >= "f" || c >= "0" && c <= "9"; | ||
} | ||
function isHex(c) { | ||
return ((c >= 'A' && c <= 'F') || (c <= 'a' && c >= 'f') || (c >= '0' && c <= '9')); | ||
} | ||
/** | ||
* Check if a letter in a string is hex | ||
* | ||
* @param {string} str | ||
* @param {number} offset | ||
* @return {boolean} | ||
*/ | ||
function matchHex(str, offset) { | ||
var c; | ||
function matchHex(str, offset) { | ||
var c; | ||
c = str.charAt(offset); | ||
c = str.charAt(offset); | ||
if (c >= "A" && c <= "F" || c <= "a" && c >= "f" || c >= "0" && c <= "9") { | ||
return c; | ||
} | ||
if ((c >= 'A' && c <= 'F') || (c <= 'a' && c >= 'f') || (c >= '0' && c <= '9')) { | ||
return c; | ||
} | ||
return null; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Test function generator | ||
* | ||
* @param {Function} fn | ||
* @return {Function} | ||
*/ | ||
function test(fn) { | ||
return function () { | ||
fn("test"); | ||
fn("dead"); | ||
fn("Icing"); | ||
fn("8938 asdljhaf3"); | ||
}; | ||
} | ||
function test(fn) { | ||
return function () { | ||
fn("test"); | ||
fn("dead"); | ||
fn("Icing"); | ||
fn("8938 asdljhaf3"); | ||
}; | ||
} | ||
module.exports = { | ||
name: "hex characters", | ||
tests: { | ||
pattern: test(function (str) { | ||
// Just seeing if a pattern is faster | ||
return str.substr(0, 4).match(pattern); | ||
}), | ||
characters: test(function (str) { | ||
// Function that just returns true/false | ||
return isHex(str.charAt(0)) && isHex(str.charAt(1)) && isHex(str.charAt(2)) && isHex(str.charAt(3)); | ||
}), | ||
"characters as hash": test(function (str) { | ||
// Function that just returns true/false | ||
return inHash(str.charAt(0)) && inHash(str.charAt(1)) && inHash(str.charAt(2)) && inHash(str.charAt(3)); | ||
}), | ||
matchHex: test(function (str) { | ||
// Matcher function like what the tokenizer does | ||
return matchHex(str, 0) && matchHex(str, 1) && matchHex(str, 2) && matchHex(str, 3); | ||
}), | ||
"matchHex4 with isHex": test(function (str) { | ||
// Matching 4 and returning a string | ||
if (isHex(str.charAt(0)) && isHex(str.charAt(1)) && isHex(str.charAt(2)) && isHex(str.charAt(3))) { | ||
return str.substr(0, 4); | ||
} | ||
module.exports = { | ||
name: "hex characters", | ||
tests: { | ||
'pattern': test(function (str) { | ||
// Just seeing if a pattern is faster | ||
return str.substr(0, 4).match(pattern); | ||
}), | ||
'characters': test(function (str) { | ||
// Function that just returns true/false | ||
return isHex(str.charAt(0)) && isHex(str.charAt(1)) && isHex(str.charAt(2)) && isHex(str.charAt(3)); | ||
}), | ||
'characters as hash': test(function (str) { | ||
// Function that just returns true/false | ||
return inHash(str.charAt(0)) && inHash(str.charAt(1)) && inHash(str.charAt(2)) && inHash(str.charAt(3)); | ||
}), | ||
'matchHex': test(function (str) { | ||
// Matcher function like what the tokenizer does | ||
return matchHex(str, 0) && matchHex(str, 1) && matchHex(str, 2) && matchHex(str, 3); | ||
}), | ||
'matchHex4 with isHex': test(function (str) { | ||
// Matching 4 and returning a string | ||
if (isHex(str.charAt(0)) && isHex(str.charAt(1)) && isHex(str.charAt(2)) && isHex(str.charAt(3))) { | ||
return str.substr(0, 4); | ||
} | ||
return null; | ||
}), | ||
"matchHex4 with matchHex nested ifs": test(function (str) { | ||
// Another way of mixing up the matchers | ||
var a, b, c, d; | ||
return null; | ||
}), | ||
'matchHex4 with matchHex nested ifs': test(function (str) { | ||
// Another way of mixing up the matchers | ||
var a, b, c, d; | ||
a = matchHex(str, 0); | ||
a = matchHex(str, 0); | ||
if (a) { | ||
b = matchHex(str, 1); | ||
if (a) { | ||
b = matchHex(str, 1); | ||
if (b) { | ||
c = matchHex(str, 2); | ||
if (b) { | ||
c = matchHex(str, 2); | ||
if (c) { | ||
d = matchHex(str, 3); | ||
if (c) { | ||
d = matchHex(str, 3); | ||
if (d) { | ||
return a + b + c + d; | ||
} | ||
if (d) { | ||
return a + b + c + d; | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
}), | ||
'matchHex4 with matchHex concatenated': test(function (str) { | ||
// Another way of mixing up the matchers | ||
var c; | ||
return null; | ||
}), | ||
"matchHex4 with matchHex concatenated": test(function (str) { | ||
// Another way of mixing up the matchers | ||
var c; | ||
c = matchHex(str, 0) + matchHex(str, 1) + matchHex(str, 2) + matchHex(str, 3); | ||
if (c.length === 4) { | ||
return c; | ||
} | ||
c = matchHex(str, 0) + matchHex(str, 1) + matchHex(str, 2) + matchHex(str, 3); | ||
if (c.length === 4) { | ||
return c; | ||
} | ||
return null; | ||
}) | ||
} | ||
}; | ||
}()); | ||
return null; | ||
}) | ||
} | ||
}; |
@@ -1,33 +0,34 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Returns undefined. | ||
* | ||
* @return {undefined} | ||
*/ | ||
function myCallback() { | ||
return undefined; // eslint-disable-line no-undefined | ||
} | ||
function myCallback() { | ||
return undefined; | ||
module.exports = { | ||
name: "passing extra arguments to a function", | ||
tests: { | ||
0: function () { | ||
myCallback(); | ||
}, | ||
1: function () { | ||
myCallback(1); | ||
}, | ||
2: function () { | ||
myCallback(1, this); | ||
}, | ||
3: function () { | ||
myCallback(1, this, "str"); | ||
}, | ||
4: function () { | ||
myCallback(1, this, "str", myCallback); | ||
}, | ||
5: function () { | ||
myCallback(1, this, "str", myCallback, null); | ||
} | ||
} | ||
module.exports = { | ||
name: "passing extra arguments to a function", | ||
tests: { | ||
'0': function () { | ||
myCallback(); | ||
}, | ||
'1': function () { | ||
myCallback(1); | ||
}, | ||
'2': function () { | ||
myCallback(1, this); | ||
}, | ||
'3': function () { | ||
myCallback(1, this, 'str'); | ||
}, | ||
'4': function () { | ||
myCallback(1, this, 'str', myCallback); | ||
}, | ||
'5': function () { | ||
myCallback(1, this, 'str', myCallback, null); | ||
} | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,29 +0,31 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Test function factory. | ||
* | ||
* @param {Function} fn | ||
* @return {Function} | ||
*/ | ||
function test(fn) { | ||
return function () { | ||
fn("asfasdfksadlkfjasdflkj", 12); | ||
}; | ||
} | ||
function test(fn) { | ||
return function () { | ||
fn('asfasdfksadlkfjasdflkj', 12); | ||
}; | ||
module.exports = { | ||
name: "single letter substrings", | ||
tests: { | ||
"charAt()": test(function (string, index) { | ||
return string.charAt(index); | ||
}), | ||
"charCodeAt()": test(function (string, index) { | ||
return string.charCodeAt(index); | ||
}), | ||
"substr()": test(function (string, index) { | ||
return string.substr(index, 1); | ||
}), | ||
"array index": test(function (string, index) { | ||
return string[index]; | ||
}) | ||
} | ||
module.exports = { | ||
name: "single letter substrings", | ||
tests: { | ||
'charAt()': test(function (string, index) { | ||
return string.charAt(index); | ||
}), | ||
'charCodeAt()': test(function (string, index) { | ||
return string.charCodeAt(index); | ||
}), | ||
'substr()': test(function (string, index) { | ||
return string.substr(index, 1); | ||
}), | ||
'array index': test(function (string, index) { | ||
return string[index]; | ||
}) | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,27 +0,29 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Test function factory | ||
* | ||
* @param {Function} fn | ||
* @return {Function} | ||
*/ | ||
function test(fn) { | ||
return function () { | ||
fn("abcdabcd", "abcdabcd", "a"); | ||
}; | ||
} | ||
function test(fn) { | ||
return function () { | ||
fn("abcdabcd", "abcdabcd", 'a'); | ||
}; | ||
module.exports = { | ||
name: "string comparison", | ||
tests: { | ||
"full string": test(function (a, b) { | ||
return a === b; | ||
}), | ||
"first letter shortcut": test(function (a, b, firstLetter) { | ||
if (firstLetter !== a.charAt(0)) { | ||
return false; | ||
} | ||
return a === b; | ||
}) | ||
} | ||
module.exports = { | ||
name: "string comparison", | ||
tests: { | ||
'full string': test(function (a, b) { | ||
return a === b; | ||
}), | ||
'first letter shortcut': test(function (a, b, firstLetter) { | ||
if (firstLetter !== a.charAt(0)) { | ||
return; | ||
} | ||
return a === b; | ||
}) | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,48 +0,60 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Test function factory | ||
* | ||
* @param {Function} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
/** | ||
* Run the method with a token | ||
* | ||
* @param {string} type | ||
* @param {string} content | ||
* @param {number} offset | ||
* @param {number} line | ||
* @param {number} pos | ||
*/ | ||
function run(type, content, offset, line, pos) { | ||
var o; | ||
function test(method) { | ||
function run(type, content, offset, line, pos) { | ||
o = { | ||
type: type, | ||
content: content, | ||
offset: offset | ||
}; | ||
method(o, line, pos); | ||
} | ||
return function () { | ||
run("TEST", "asdfasdfasdfasdfasdfasdfasdfasdf", 231, 333, 333); | ||
run("ELEPHANT", "Wandering through the mire and darkness is something I sometimes do.", 123123, 22, 132); | ||
run("NUMBER", "123", 49284, 3214, 2); | ||
}; | ||
} | ||
module.exports = { | ||
name: "adding to a token object", | ||
tests: { | ||
"adding two properties": test(function (token, line, pos) { | ||
token.line = line; | ||
token.pos = pos; | ||
return token; | ||
}), | ||
"defining a new object": test(function (token, line, pos) { | ||
var o; | ||
o = { | ||
type: type, | ||
content: content, | ||
offset: offset | ||
type: token.type, | ||
content: token.content, | ||
offset: token.offset, | ||
line: line, | ||
pos: pos | ||
}; | ||
method(o, line, pos); | ||
} | ||
return function () { | ||
run('TEST', 'asdfasdfasdfasdfasdfasdfasdfasdf', 231, 333, 333); | ||
run('ELEPHANT', 'Wandering through the mire and darkness is something I sometimes do.', 123123, 22, 132); | ||
run('NUMBER', '123', 49284, 3214, 2); | ||
}; | ||
return o; | ||
}) | ||
} | ||
module.exports = { | ||
name: "adding to a token object", | ||
tests: { | ||
'adding two properties': test(function (token, line, pos) { | ||
token.line = line; | ||
token.pos = pos; | ||
return token; | ||
}), | ||
'defining a new object': test(function (token, line, pos) { | ||
var o; | ||
o = { | ||
type: token.type, | ||
content: token.content, | ||
offset: token.offset, | ||
line: line, | ||
pos: pos | ||
}; | ||
return o; | ||
}) | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,61 +0,68 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
var testData; | ||
var testData; | ||
/** | ||
* Test function factory | ||
* | ||
* @param {Function} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
return function () { | ||
testData.forEach(function (dataSet) { | ||
return method(dataSet[0], dataSet[1], dataSet[2]); | ||
}); | ||
}; | ||
} | ||
function test(method) { | ||
return function () { | ||
testData.forEach(function (dataSet) { | ||
return method(dataSet[0], dataSet[1], dataSet[2]); | ||
}); | ||
}; | ||
} | ||
/** | ||
* Sample class | ||
*/ | ||
function AAA() { | ||
this.type = AAA; | ||
this.typeStr = "AAA"; | ||
} | ||
function AAA() { | ||
this.type = AAA; | ||
this.typeStr = 'AAA'; | ||
} | ||
/** | ||
* Another sample class | ||
*/ | ||
function BBB() { | ||
this.type = BBB; | ||
this.typeStr = "BBB"; | ||
} | ||
function BBB() { | ||
this.type = BBB; | ||
this.typeStr = 'BBB'; | ||
testData = [ | ||
[ | ||
new AAA(), | ||
BBB, | ||
"BBB" | ||
], | ||
[ | ||
new BBB(), | ||
AAA, | ||
"AAA" | ||
], | ||
[ | ||
new AAA(), | ||
AAA, | ||
"AAA" | ||
] | ||
]; | ||
testData[0][3] = testData[1][0]; // Mismatch | ||
testData[1][3] = testData[0][0]; // Mismatch | ||
testData[2][3] = testData[2][0]; // Match | ||
module.exports = { | ||
name: "comparing token types", | ||
tests: { | ||
instanceof: test(function (obj, desiredType) { | ||
return obj instanceof desiredType; | ||
}), | ||
"object property": test(function (obj, desiredType) { | ||
return obj.type === desiredType; | ||
}), | ||
"string property": test(function (obj, desiredType, string) { | ||
return obj.typeStr === string; | ||
}) | ||
} | ||
testData = [ | ||
[ | ||
new AAA(), | ||
BBB, | ||
'BBB' | ||
], | ||
[ | ||
new BBB(), | ||
AAA, | ||
'AAA' | ||
], | ||
[ | ||
new AAA(), | ||
AAA, | ||
'AAA' | ||
] | ||
]; | ||
testData[0][3] = testData[1][0]; // Mismatch | ||
testData[1][3] = testData[0][0]; // Mismatch | ||
testData[2][3] = testData[2][0]; // Match | ||
module.exports = { | ||
name: "comparing token types", | ||
tests: { | ||
'instanceof': test(function (obj, desiredType) { | ||
return obj instanceof desiredType; | ||
}), | ||
'object property': test(function (obj, desiredType) { | ||
return obj.type === desiredType; | ||
}), | ||
'string property': test(function (obj, desiredType, string) { | ||
/*jslint unparam:true*/ | ||
return obj.typeStr === string; | ||
}) | ||
} | ||
}; | ||
}()); | ||
}; |
@@ -1,42 +0,44 @@ | ||
/*global module*/ | ||
"use strict"; | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Test function factory. | ||
* | ||
* @param {Function} method | ||
* @return {Function} | ||
*/ | ||
function test(method) { | ||
return function () { | ||
method("asdfasdfasdfasdfasdfasdfasdfasdf"); | ||
method("Wandering through the mire and darkness is something I sometimes do."); | ||
method("123"); | ||
}; | ||
} | ||
function test(method) { | ||
return function () { | ||
method('asdfasdfasdfasdfasdfasdfasdfasdf'); | ||
method('Wandering through the mire and darkness is something I sometimes do.'); | ||
method('123'); | ||
}; | ||
} | ||
module.exports = { | ||
name: "walking the length of a string", | ||
tests: { | ||
"using a variable": test(function (string) { | ||
var i, j, len; | ||
module.exports = { | ||
name: "walking the length of a string", | ||
tests: { | ||
'using a variable': test(function (string) { | ||
var i, j, len; | ||
j = 0; | ||
len = string.length; | ||
j = 0; | ||
len = string.length; | ||
for (i = 0; i < len; i += 1) { | ||
j += 1; | ||
} | ||
for (i = 0; i < len; i += 1) { | ||
j += 1; | ||
} | ||
return j; | ||
}), | ||
"using a property": test(function (string) { | ||
var i, j; | ||
return j; | ||
}), | ||
'using a property': test(function (string) { | ||
var i, j; | ||
j = 0; | ||
j = 0; | ||
for (i = 0; i < string.length; i += 1) { | ||
j += 1; | ||
} | ||
for (i = 0; i < string.length; i += 1) { | ||
j += 1; | ||
} | ||
return j; | ||
}) | ||
} | ||
}; | ||
}()); | ||
return j; | ||
}) | ||
} | ||
}; |
@@ -29,15 +29,32 @@ /** | ||
*/ | ||
/*global exports, module*/ | ||
// fid-umd {"jslint":1,"name":"Complexion"} | ||
/*global define, YUI*/ | ||
(function (n, r, f) { | ||
"use strict"; | ||
try { module.exports = f(); return; } catch (ignore) {} | ||
try { exports[n] = f(); return; } catch (ignore) {} | ||
try { return define.amd && define(n, [], f); } catch (ignore) {} | ||
try { return YUI.add(n, function (Y) { Y[n] = f(); }); } catch (ignore) {} | ||
try { r[n] = f(); return; } catch (ignore) {} | ||
throw new Error("Unable to export " + n); | ||
}("Complexion", this, function () { | ||
"use strict"; | ||
/* global exports, module */ | ||
// fid-umd {"name":"Complexion"} | ||
"use strict"; | ||
(function (name, root, factory) { | ||
/** | ||
* Determines if a thing is an object | ||
* | ||
* @param {*} x | ||
* @return {boolean} | ||
*/ | ||
function isObject(x) { | ||
return typeof x === "object"; | ||
} | ||
if (isObject(module) && isObject(module.exports)) { | ||
module.exports = factory(); | ||
} else if (isObject(exports)) { | ||
exports[name] = factory(); | ||
} else if (isObject(root.define) && root.define.amd) { | ||
root.define(name, [], factory); | ||
} else if (isObject(root.modulejs)) { | ||
root.modulejs.define(name, factory); | ||
} else if (isObject(root.YUI)) { | ||
root.YUI.add(name, function (Y) { | ||
Y[name] = factory(); | ||
}); | ||
} else { | ||
root[name] = factory(); | ||
} | ||
}("Complexion", this, function () { // eslint-disable-line no-invalid-this | ||
// fid-umd end | ||
@@ -48,2 +65,4 @@ | ||
* The tokenizer object. | ||
* | ||
* @return {Complexion} | ||
*/ | ||
@@ -89,4 +108,4 @@ function Complexion() { | ||
Complexion.prototype.defineToken = function (type, matcher) { | ||
if (typeof matcher !== 'function') { | ||
throw new Error('Matcher must be a function'); | ||
if (typeof matcher !== "function") { | ||
throw new Error("Matcher must be a function"); | ||
} | ||
@@ -103,2 +122,3 @@ | ||
* @param {string} name | ||
* @param {*} data | ||
*/ | ||
@@ -163,3 +183,2 @@ Complexion.prototype.emit = function (name, data) { | ||
return function (str, offset) { | ||
/*jslint unparam:true*/ | ||
if (str.charAt(offset) !== strToMatch) { | ||
@@ -235,3 +254,2 @@ return null; | ||
return function (str, offset) { | ||
/*jslint unparam:true*/ | ||
var c; | ||
@@ -386,3 +404,3 @@ | ||
Complexion.prototype.tokenize = function (parseStr) { | ||
var i, c, col, cr, lf, line, matchedContent, matchedContentLen, matchers, matchersLen, offset, parseLen, token, tokenFactory, tokenList, types; | ||
var c, col, cr, i, lf, line, matchedContent, matchedContentLen, matchers, matchersLen, offset, parseLen, token, tokenFactory, tokenList, types; | ||
@@ -423,5 +441,5 @@ /** | ||
// Position tracking | ||
offset = 0; // Byte offset | ||
line = 1; // Line number in file (any CR+LF, CR, LF counts) | ||
col = 1; // Column number in file (tabs = 1 character) | ||
offset = 0; // Byte offset | ||
line = 1; // Line number in file (any CR+LF, CR, LF counts) | ||
col = 1; // Column number in file (tabs = 1 character) | ||
@@ -442,3 +460,3 @@ // Shortcuts for faster loops | ||
// All set up | ||
this.emit('start', {}); | ||
this.emit("start", {}); | ||
@@ -451,3 +469,3 @@ while (offset < parseLen) { | ||
if (token === null) { | ||
throw new Error('Unable to match, starting at offset ' + offset + ' (line ' + line + ', col ' + col + ')'); | ||
throw new Error("Unable to match, starting at offset " + offset + " (line " + line + ", col " + col + ")"); | ||
} | ||
@@ -484,3 +502,3 @@ | ||
this.emit('end', { | ||
this.emit("end", { | ||
tokenList: tokenList | ||
@@ -487,0 +505,0 @@ }); |
{ | ||
"name": "complexion", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A fast tokenizer/lexer core that is well tested.", | ||
@@ -30,14 +30,11 @@ "author": "Tyler Akins <fidian@rumkin.com>", | ||
"devDependencies": { | ||
"fid-umd": "*", | ||
"grunt": "~0.4.1", | ||
"grunt-benchmark": "*", | ||
"grunt-cli": "*", | ||
"grunt-jasmine-node": "*", | ||
"grunt-jslint": "*" | ||
"eslint": "^4.3.0", | ||
"fid-umd": "^2.0.5", | ||
"jasmine": "^2.6.0" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "grunt test", | ||
"test": "jasmine && eslint .", | ||
"umd": "fid-umd lib/*.js" | ||
} | ||
} |
@@ -6,6 +6,6 @@ Complexion | ||
[![NPM][npm-image]][NPM] | ||
[![Build Status][travis-image]][Travis CI] | ||
[![Dependencies][dependencies-image]][Dependencies] | ||
[![Dev Dependencies][devdependencies-image]][Dev Dependencies] | ||
[![npm version][npm-badge]][npm-link] | ||
[![Build Status][travis-badge]][travis-link] | ||
[![Dependencies][dependencies-badge]][dependencies-link] | ||
[![Dev Dependencies][devdependencies-badge]][devdependencies-link] | ||
@@ -110,10 +110,10 @@ | ||
[Dev Dependencies]: https://david-dm.org/tests-always-included/complexion#info=devDependencies | ||
[devdependencies-image]: https://david-dm.org/tests-always-included/complexion/dev-status.png | ||
[Dependencies]: https://david-dm.org/tests-always-included/complexion | ||
[dependencies-image]: https://david-dm.org/tests-always-included/complexion.png | ||
[dependencies-badge]: https://img.shields.io/david/tests-always-included/complexion.svg | ||
[dependencies-link]: https://david-dm.org/tests-always-included/complexion | ||
[devdependencies-badge]: https://img.shields.io/david/dev/tests-always-included/complexion.svg | ||
[devdependencies-link]: https://david-dm.org/tests-always-included/complexion#info=devDependencies | ||
[FidUmd]: https://github.com/fidian/fid-umd/ | ||
[NPM]: https://npmjs.org/package/complexion | ||
[npm-image]: https://nodei.co/npm/complexion.png?downloads=true&stars=true | ||
[travis-image]: https://secure.travis-ci.org/tests-always-included/complexion.png | ||
[Travis CI]: http://travis-ci.org/tests-always-included/complexion | ||
[npm-badge]: https://img.shields.io/npm/v/complexion.svg | ||
[npm-link]: https://npmjs.org/package/complexion | ||
[travis-badge]: https://img.shields.io/travis/tests-always-included/complexion/master.svg | ||
[travis-link]: http://travis-ci.org/tests-always-included/complexion |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61638
3
23
1585
1