-
Notifications
You must be signed in to change notification settings - Fork 4
/
mutate.js
51 lines (47 loc) · 1.4 KB
/
mutate.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
var test = require('tap').test,
fs = require('fs'),
fuzzer = require('../');
var REGENERATE = false;
test('mutate object', function(t) {
fuzzer.seed(0);
var mutator = fuzzer.mutate.object({
name: 'Tom',
height: 72
});
t.deepEqual(mutator(), {
name: "Tom",
height: 72
});
t.deepEqual(mutator(), {
name: "Tom",
height: 72
});
t.end();
});
test('fc', function(t) {
var inputObject = JSON.parse(fs.readFileSync(__dirname + '/data/fc.json'));
var fc = fuzzer.mutate.object(inputObject.input);
var outputs = [];
for (var i = 0; i < 10; i++) {
outputs.push(fc());
}
t.deepEqual(inputObject.output, outputs, 'generates correct output');
if (REGENERATE) {
inputObject.output = outputs;
fs.writeFileSync(__dirname + '/data/fc.json', JSON.stringify(inputObject, null, 4));
}
t.end();
});
test('mutate string', function(t) {
var inputObject = JSON.parse(fs.readFileSync(__dirname + '/data/string.json'));
var outputs = [];
for (var i = 0; i < 10; i++) {
outputs.push(fuzzer.mutate.string(inputObject.input));
}
t.deepEqual(inputObject.output, outputs, 'generates correct output');
if (REGENERATE) {
inputObject.output = outputs;
fs.writeFileSync(__dirname + '/data/string.json', JSON.stringify(inputObject, null, 4));
}
t.end();
});