source: trip-planner-front/node_modules/randombytes/test.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[6a3a178]1var test = require('tape')
2var randomBytes = require('./')
3var MAX_BYTES = 65536
4var MAX_UINT32 = 4294967295
5
6test('sync', function (t) {
7 t.plan(9)
8 t.equals(randomBytes(0).length, 0, 'len: ' + 0)
9 t.equals(randomBytes(3).length, 3, 'len: ' + 3)
10 t.equals(randomBytes(30).length, 30, 'len: ' + 30)
11 t.equals(randomBytes(300).length, 300, 'len: ' + 300)
12 t.equals(randomBytes(17 + MAX_BYTES).length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
13 t.equals(randomBytes(MAX_BYTES * 100).length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
14 t.throws(function () {
15 randomBytes(MAX_UINT32 + 1)
16 })
17 t.throws(function () {
18 t.equals(randomBytes(-1))
19 })
20 t.throws(function () {
21 t.equals(randomBytes('hello'))
22 })
23})
24
25test('async', function (t) {
26 t.plan(9)
27
28 randomBytes(0, function (err, resp) {
29 if (err) throw err
30
31 t.equals(resp.length, 0, 'len: ' + 0)
32 })
33
34 randomBytes(3, function (err, resp) {
35 if (err) throw err
36
37 t.equals(resp.length, 3, 'len: ' + 3)
38 })
39
40 randomBytes(30, function (err, resp) {
41 if (err) throw err
42
43 t.equals(resp.length, 30, 'len: ' + 30)
44 })
45
46 randomBytes(300, function (err, resp) {
47 if (err) throw err
48
49 t.equals(resp.length, 300, 'len: ' + 300)
50 })
51
52 randomBytes(17 + MAX_BYTES, function (err, resp) {
53 if (err) throw err
54
55 t.equals(resp.length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
56 })
57
58 randomBytes(MAX_BYTES * 100, function (err, resp) {
59 if (err) throw err
60
61 t.equals(resp.length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
62 })
63
64 t.throws(function () {
65 randomBytes(MAX_UINT32 + 1, function () {
66 t.ok(false, 'should not get here')
67 })
68 })
69
70 t.throws(function () {
71 randomBytes(-1, function () {
72 t.ok(false, 'should not get here')
73 })
74 })
75
76 t.throws(function () {
77 randomBytes('hello', function () {
78 t.ok(false, 'should not get here')
79 })
80 })
81})
Note: See TracBrowser for help on using the repository browser.