UNPKG

1.44 kBJavaScriptView Raw
1var assert = require('assert'),
2 nodeuuid = require('../'),
3 uuidjs = require('uuid-js'),
4 util = require('util'),
5 exec = require('child_process').exec,
6 os = require('os');
7
8// On Mac Os X / macports there's only the ossp-uuid package that provides uuid
9// On Linux there's uuid-runtime which provides uuidgen
10var uuidCmd = os.type() === 'Darwin' ? 'uuid -1' : 'uuidgen -t';
11
12function compare(ids) {
13 console.log(ids);
14 for (var i = 0; i < ids.length; i++) {
15 var id = ids[i].split('-');
16 id = [id[2], id[1], id[0]].join('');
17 ids[i] = id;
18 }
19 var sorted = ([].concat(ids)).sort();
20
21 if (sorted.toString() !== ids.toString()) {
22 console.log('Warning: sorted !== ids');
23 } else {
24 console.log('everything in order!');
25 }
26}
27
28// Test time order of v1 uuids
29var ids = [];
30while (ids.length < 10e3) ids.push(nodeuuid.v1());
31
32var max = 10;
33console.log('node-uuid:');
34ids = [];
35for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
36compare(ids);
37
38console.log('');
39console.log('uuidjs:');
40ids = [];
41for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
42compare(ids);
43
44console.log('');
45console.log('libuuid:');
46ids = [];
47var count = 0;
48var last = function() {
49 compare(ids);
50}
51var cb = function(err, stdout, stderr) {
52 ids.push(stdout.substring(0, stdout.length-1));
53 count++;
54 if (count < max) {
55 return next();
56 }
57 last();
58};
59var next = function() {
60 exec(uuidCmd, cb);
61};
62next();