-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
100 lines (97 loc) · 3.27 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const randomString = require('./lib/index');
describe('testing using provide length', () => {
test('the string should return alphanumeric values', () => {
let random = randomString.generate(9);
expect(random.match(/^[a-zA-Z0-9]+$/)).toBeTruthy();
});
test('length should be 16', () => {
let random = randomString.generate();
expect(random.length === 16).toBeTruthy();
});
});
describe('testing with given options', () => {
test('should generate with the given charset', () => {
let random = randomString.generate({ range: '2846', length: 6 });
expect(random.match(/[^2846]/)).toBeFalsy();
});
test('should generate with the given charset', () => {
let random = randomString.generate({ range: 'abcdef', length: 10 });
expect(random.match(/[a-f]/)).toBeTruthy();
});
test('should be a number only', () => {
let random = randomString.generate({ charset: 'number', length: 6 });
expect(random.match(/^[0-9]+$/)).toBeTruthy();
});
test('should be an alphabet only', () => {
let random = randomString.generate({ charset: 'alphabet', length: 6 });
expect(random.match(/^[a-zA-Z]+$/)).toBeTruthy();
});
test('should be Binary only', () => {
let random = randomString.generate({ charset: 'binary', length: 6 });
expect(random.match(/[0-1]+$/)).toBeTruthy();
});
test('should be octal only', () => {
let random = randomString.generate({ charset: 'octal', length: 6 });
expect(random.match(/[0-7]+$/)).toBeTruthy();
});
test('should be hexa only', () => {
let random = randomString.generate({ charset: 'hex', length: 6 });
expect(random.match(/[0-9a-fA-F]+$/)).toBeTruthy();
});
test('should be alphabet with small Letters only', () => {
let random = randomString.generate({
charset: 'alphabet',
length: 6,
lowerCaseOnly: true,
});
expect(random.match(/[0-9a-z]+$/)).toBeTruthy();
});
test('should be alphabet with capital Letters only', () => {
let random = randomString.generate({
charset: 'alphabet',
length: 6,
upperCaseOnly: true,
});
expect(random.match(/[0-9A-Z]+$/)).toBeTruthy();
});
test('should be symbols with number only', () => {
let random = randomString.generate({
insertSymbol: true,
charset: 'number',
});
console.log('Symbol and number : ' + random);
expect(
random.match(/[-!$%^&*()_+|~=`{}\[\]:";<>?,.\/+0-9]+$/)
).toBeTruthy();
});
test('should be symbols with alphanumeric small letters only', () => {
let random = randomString.generate({
insertSymbol: true,
lowerCaseOnly: true,
});
console.log(random);
expect(
random.match(/[-!$%^&*()_+|~=`{}\[\]:";<>?,.\/0-9a-z]+$/)
).toBeTruthy();
});
test('should be symbols with alphanumeric capital letters only', () => {
let random = randomString.generate({
insertSymbol: true,
upperCaseOnly: true,
length: 5,
});
expect(
random.match(/[-!$%^&*()_+|~=`{}\[\]:";<>?,.\/0-9A-Z]/)
).toBeTruthy();
});
test('should be symbols with given provided number', () => {
let random = randomString.generate({
insertSymbol: true,
range: '123abc',
length: 6,
});
expect(
random.match(/[-!$%^&*()_+|~=`{}\[\]:";<>?,.\/1-3a-c]/)
).toBeTruthy();
});
});