3 var assert = require('assert');
4 var timeSafeCompare = require('../../lib/index');
6 process.on('error', function (e) {
7 console.log('caught: ' + e);
10 function testEqual(a, b) {
11 assert(timeSafeCompare(a, b));
13 // lets also do a parity check with the strict equal to operator
17 function testNotEqual(a, b) {
18 assert(!timeSafeCompare(a, b));
20 // lets also do a parity check with the strict not equal to operator
24 // note: lets also make sure tsscmp can be inline replaced for any types -
25 // just incase if anyone is interested
28 testEqual('127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',
29 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',
33 testEqual(undefined, undefined);
34 testEqual(true, true);
35 testEqual(false, false);
41 function f1() { return 1; };
47 testNotEqual('a', 'b');
48 testNotEqual('a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
49 testNotEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'a');
50 testNotEqual('alpha', 'beta');
51 testNotEqual(false, true);
52 testNotEqual(false, undefined);
53 testNotEqual(function () { }, function () { });
55 testNotEqual({ a: 1 }, { a: 1 });
56 testNotEqual({ a: 1 }, { a: 2 });
57 testNotEqual([1, 2], [1, 2]);
58 testNotEqual([1, 2], [1, 2, 3]);
65 function f1() { return 1; };
66 function f2() { return 1; };
69 console.log('Success: all tests complete.');