-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathgit2consul_array_handler_test.js
More file actions
73 lines (61 loc) · 2.67 KB
/
Copy pathgit2consul_array_handler_test.js
File metadata and controls
73 lines (61 loc) · 2.67 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
var _ = require('underscore');
var should = require('should');
// We want this above any git2consul module to make sure logging gets configured
require('./git2consul_bootstrap_test.js');
var array_key_formatter = require('../lib/array_handler.js');
describe('Array Formatter', function() {
it ('should ignore non-string values', function() {
array_key_formatter.create_formatter(false).should.equal(false);
array_key_formatter.create_formatter(true).should.equal(false);
array_key_formatter.create_formatter(0).should.equal(false);
array_key_formatter.create_formatter(NaN).should.equal(false);
array_key_formatter.create_formatter('none').should.equal(false);
});
it ('should format json', function() {
var format = array_key_formatter.create_formatter('json');
_.isFunction(format).should.equal(true);
var arr = ['foo', 'bar'];
format(arr).should.equal(JSON.stringify(arr));
});
it ('should format comma-separated lists', function() {
var format = array_key_formatter.create_formatter(',');
_.isFunction(format).should.equal(true);
var arr = ['foo', 'bar'];
format(arr).should.equal('foo,bar');
});
it ('should format un-separated lists', function() {
var format = array_key_formatter.create_formatter('');
_.isFunction(format).should.equal(true);
var arr = ['foo', 'bar'];
format(arr).should.equal('foobar');
});
});
describe('Array Key Formatter', function() {
it ('should ignore non-format values', function() {
array_key_formatter.create_key_formatter(false).should.equal(false);
array_key_formatter.create_key_formatter(true).should.equal(false);
array_key_formatter.create_key_formatter(0).should.equal(false);
array_key_formatter.create_key_formatter(NaN).should.equal(false);
array_key_formatter.create_key_formatter('').should.equal(false);
});
it ('should format _#', function() {
var format = array_key_formatter.create_key_formatter('_#');
_.isFunction(format).should.equal(true);
format('foo', 3).should.equal('foo3');
});
it ('should format pre_inner#post', function() {
var format = array_key_formatter.create_key_formatter('pre_inner#post');
_.isFunction(format).should.equal(true);
format('foo', 3).should.equal('prefooinner3post');
});
it ('should format #_#/_#', function() {
var format = array_key_formatter.create_key_formatter('#_#/_#');
_.isFunction(format).should.equal(true);
format('foo', 3).should.equal('3foo3/foo3');
});
it ('should format #_\\#\\_#', function() {
var format = array_key_formatter.create_key_formatter('#_\\#\\_#');
_.isFunction(format).should.equal(true);
format('foo', 3).should.equal('3foo#_3');
});
});