@@ -29,5 +29,46 @@ tape.test("util", function(test) {
2929 test . end ( ) ;
3030 } ) ;
3131
32+ test . test ( test . name + " - isset" , function ( test ) {
33+ // note that encoders don't check for default values either
34+ var neverPresent = [
35+ [ ] ,
36+ { } ,
37+ undefined ,
38+ null
39+ ] ;
40+ neverPresent . forEach ( function ( value ) {
41+ var proto = { } ;
42+ var instance = Object . create ( proto ) ;
43+ proto . p = value ;
44+ instance . i = value ;
45+ test . notOk ( util . isset ( proto , "p" ) , "should return that " + JSON . stringify ( value ) + " on the prototype is not present" ) ;
46+ test . notOk ( util . isset ( instance , "i" ) , "should return that " + JSON . stringify ( value ) + " on the instance is not present" ) ;
47+ } ) ;
48+ var cases = {
49+ "arrays" : [ [ ] , [ 0 ] ] ,
50+ "objects" : [ { } , { a :1 } ] ,
51+ "strings" : [ undefined , "" ] ,
52+ "numbers" : [ undefined , 0 ] ,
53+ "booleans" : [ undefined , false ]
54+ } ;
55+ Object . keys ( cases ) . forEach ( function ( name ) {
56+ var empty = cases [ name ] [ 0 ] ,
57+ value = cases [ name ] [ 1 ] ;
58+ var proto = { } ;
59+ var instance = Object . create ( proto ) ;
60+ proto . pe = instance . ie = empty ;
61+ proto . p = instance . i = value ;
62+ if ( empty !== undefined ) { // not present anyway
63+ test . notOk ( util . isset ( instance , "pe" ) , "should return that empty " + name + " on the prototype are not present" ) ;
64+ test . notOk ( util . isset ( instance , "ie" ) , "should return that empty " + name + " on the instance are not present" ) ;
65+ }
66+ test . notOk ( util . isset ( instance , "p" ) , "should return that " + name + " on the prototype are not present" ) ;
67+ test . ok ( util . isset ( instance , "i" ) , "should return that " + name + " on the instance ARE present" ) ;
68+ } ) ;
69+
70+ test . end ( ) ;
71+ } ) ;
72+
3273 test . end ( ) ;
3374} ) ;
0 commit comments