mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 18:30:04 +02:00
initial commit
This commit is contained in:
53
tests.js
Normal file
53
tests.js
Normal file
@@ -0,0 +1,53 @@
|
||||
var securerandomstring = require('./lib/securerandomstring.js');
|
||||
|
||||
|
||||
//my awesome test framework
|
||||
var test = function(name, what, ref, c) {
|
||||
process.stdout.write(name);
|
||||
|
||||
if (typeof(c) !== 'boolean') {
|
||||
c = true;
|
||||
}
|
||||
|
||||
if (typeof(what) === 'function') {
|
||||
what = what();
|
||||
}
|
||||
if (typeof(ref) === 'function') {
|
||||
ref = ref();
|
||||
}
|
||||
|
||||
if ((what === ref) === c) {
|
||||
process.stdout.write(' ✓');
|
||||
} else {
|
||||
process.stdout.write(' ⛝\n');
|
||||
process.stdout.write(' ----> expected | ' + (typeof(ref) === 'string' ? ref.replace(/ /g, '·') + '\n' : ref + '\n'));
|
||||
process.stdout.write(' ----> got | ' + (typeof(what) === 'string' ? what.replace(/ /g, '·') + '\n' : what + '\n'));
|
||||
}
|
||||
process.stdout.write('\n');
|
||||
};
|
||||
|
||||
|
||||
|
||||
//the actual tests
|
||||
securerandomstring(function(sr) {
|
||||
test('generate a random string 32 chars long',
|
||||
sr.length,
|
||||
32
|
||||
);
|
||||
});
|
||||
|
||||
securerandomstring(function(sr) {
|
||||
test('generate a random string 1 char long',
|
||||
sr.length,
|
||||
1
|
||||
);
|
||||
}, {length: 1});
|
||||
|
||||
securerandomstring(function(sr) {
|
||||
test('generate a random string 256 chars long',
|
||||
sr.length,
|
||||
256
|
||||
);
|
||||
}, {length: 256});
|
||||
|
||||
|
Reference in New Issue
Block a user