forked from stephenmathieson-boneyard/node-cpplint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend.js
91 lines (76 loc) · 2.06 KB
/
extend.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
'use strict';
var vows = require('vows');
var assert = require('assert');
var extend = require('../lib/extend.js');
var suite = vows.describe('extend');
suite.addBatch({
'extend two objects': {
topic: function () {
var a = {
'foo': 'bar',
'1': 2,
'false': true,
'cats': 'cats'
},
b = {
'foo': 'bar',
'1': 2,
'2': 2,
'false': false
};
this.callback(null, extend(a, b));
},
'should return an object': function (err, result) {
assert.isObject(result);
},
'should favor the second': function (err, result) {
assert.equal(result.false, false);
},
'should keep custom first properties': function (err, result) {
assert.equal(result.cats, 'cats');
},
'should keep custom second properties': function (err, result) {
assert.equal(result['2'], 2);
}
}
});
suite.addBatch({
'deep-extend two objects': {
topic: function () {
var first = {},
second = {};
first.the_letter_h = false;
first.first_specific = 'hi';
first.an_empty_object = {};
first.blah = {
'stuff': true,
'things': false,
'apples': 34
};
second.the_letter_h = true;
second.second_specific = 'bye';
second.an_empty_object = {};
second.blah = {
'stuff': true,
'things': true
};
this.callback(null, extend(first, second, true));
},
'should return an object': function (err, result) {
assert.isObject(result);
},
'should favor the second': function (err, result) {
assert.isTrue(result.the_letter_h);
},
'should keep custom properties': function (err, result) {
assert.equal(result.first_specific, 'hi');
assert.equal(result.second_specific, 'bye');
},
'should merge inner-object properties': function (err, result) {
assert.equal(result.blah.apples, 34);
assert.isTrue(result.blah.stuff);
assert.isTrue(result.blah.things);
}
}
});
suite.export(module);