field_stringify.js
1.77 KB
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
'use strict';
var test = require('tap').test;
var stringifyField = require('../lib/field_stringify');
test('stringify astrix', function (t) {
try {
var str = stringifyField([1, 2, 3, 4], 1, 4);
t.equal(str, '*');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify astrix step', function (t) {
try {
var str = stringifyField([0, 2, 4, 6], 0, 7);
t.equal(str, '*/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify single value', function (t) {
try {
var str = stringifyField([2], 0, 7);
t.equal(str, '2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify multiple single values', function (t) {
try {
var str = stringifyField([2, 5, 9], 0, 7);
t.equal(str, '2,5,9');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify range', function (t) {
try {
var str = stringifyField([2, 3, 4], 0, 7);
t.equal(str, '2-4');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify range step', function (t) {
try {
var str = stringifyField([2, 4, 6], 0, 8);
t.equal(str, '2-6/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify semi range step', function (t) {
try {
var str = stringifyField([4, 6, 8], 0, 9);
t.equal(str, '4/2');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});
test('stringify multi types', function (t) {
try {
var str = stringifyField([1, 2, 4, 5, 6, 7, 8, 9, 10, 20, 25, 30, 35, 57], 0, 59);
t.equal(str, '1,2,4-10,20-35/5,57');
} catch (err) {
t.error(err, 'stringify field error');
}
t.end();
});