-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathobject_get.js
35 lines (35 loc) · 1.83 KB
/
object_get.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
module.exports=require('../../theory')
('hash',function(a){
describe('objects',function(){
beforeEach(function(done){ // IE6 stack release
setTimeout(function(){done()}, 0);
});
it('get',function(){
expect(theory.obj({a:1,b:2,c:3}).get('b')).to.be(2);
expect(theory.obj.get({a:1,b:2,c:3},'b')).to.be(2);
expect(theory.obj({a:1,b:{x:{z:7}},c:3}).get('b.pow.z.x')).to.be(undefined);
expect(theory.obj.get({a:1,b:{x:{z:7}},c:3},'b.pow.z.x')).to.be(undefined);
expect(theory.obj({a:1,b:{x:{z:7}},c:3}).get('b.x.z')).to.be(7);
expect(theory.obj.get({a:1,b:{x:{z:7}},c:3},'b.x.z')).to.be(7);
expect(theory.obj({a:1,b:[[1,2],[3,4],[{x:9}]],c:3}).get('b.x')).to.be(9);
expect(theory.obj.get({a:1,b:[[1,2],[3,4],[{x:9}]],c:3},'b.x')).to.be(9);
expect(theory.obj({a:1,b:[[1,2],[3,4],{x:9}],c:3}).get('b.1.x')).to.be(undefined);
expect(theory.obj.get({a:1,b:[[1,2],[3,4],{x:9}],c:3},'b.1.x')).to.be(undefined);
expect(theory.obj({a:1,b:[[1,2],[3,4],{x:9}],c:3}).get('b.3.x')).to.be(9);
expect(theory.obj.get({a:1,b:[[1,2],[3,4],{x:9}],c:3},'b.3.x')).to.be(9);
expect(theory.obj({a:1,b:[[1,2],[3,4],{x:9}],c:3}).get('b.-1.x')).to.be(9);
expect(theory.obj.get({a:1,b:[[1,2],[3,4],{x:9}],c:3},'b.-1.x')).to.be(9);
expect(theory.obj({a:{b:{c:null}}}).get('a.b.c')).to.be(null);
expect(theory.obj.get({a:{b:{c:null}}},'a.b.c')).to.be(null);
expect(theory.obj({a:{b:{c:null}}}).get('a.b.c->')).to.be.a('function');
expect(theory.obj.get({a:{b:{c:null}}},'a.b.c->')).to.be.a('function');
expect(theory.obj({a:{b:{c:function(){return 1}}}}).get('a.b.c->')()).to.be(1);
expect(theory.obj.get({a:{b:{c:function(){return 1}}}},'a.b.c->')()).to.be(1);
});
});
//var s='',i;for(i in a){s+=i+', '};alert('get: '+s);
return {has:{status:'done'}};
},{
'./object_has':'has'
,'./object_copy':''
})