@@ -81,38 +81,53 @@ describe('class Binary', () => {
81
81
} ) ;
82
82
83
83
context ( 'inspect()' , ( ) => {
84
- it ( 'when value is default returns "new Binary( )"' , ( ) => {
85
- expect ( new Binary ( ) . inspect ( ) ) . to . equal ( 'new Binary( )' ) ;
84
+ it ( 'when value is default returns "Binary.createFromBase64("", 0 )"' , ( ) => {
85
+ expect ( new Binary ( ) . inspect ( ) ) . to . equal ( 'Binary.createFromBase64("", 0 )' ) ;
86
86
} ) ;
87
87
88
- it ( 'when value is empty returns "new Binary( )"' , ( ) => {
89
- expect ( new Binary ( new Uint8Array ( 0 ) ) . inspect ( ) ) . to . equal ( 'new Binary( )' ) ;
88
+ it ( 'when value is empty returns "Binary.createFromBase64("", 0 )"' , ( ) => {
89
+ expect ( new Binary ( new Uint8Array ( 0 ) ) . inspect ( ) ) . to . equal ( 'Binary.createFromBase64("", 0 )' ) ;
90
90
} ) ;
91
91
92
- it ( 'when value is default with a subtype returns "new Binary( )"' , ( ) => {
93
- expect ( new Binary ( null , 0x23 ) . inspect ( ) ) . to . equal ( 'new Binary(undefined , 35)' ) ;
92
+ it ( 'when value is default with a subtype returns "Binary.createFromBase64("", 35 )"' , ( ) => {
93
+ expect ( new Binary ( null , 0x23 ) . inspect ( ) ) . to . equal ( 'Binary.createFromBase64("" , 35)' ) ;
94
94
} ) ;
95
95
96
- it ( 'when value is empty with a subtype returns "new Binary(undefined, 35)"' , ( ) => {
97
- expect ( new Binary ( new Uint8Array ( 0 ) , 0x23 ) . inspect ( ) ) . to . equal ( 'new Binary(undefined, 35)' ) ;
96
+ it ( 'when value is empty with a subtype returns "Binary.createFromBase64("", 35)"' , ( ) => {
97
+ expect ( new Binary ( new Uint8Array ( 0 ) , 0x23 ) . inspect ( ) ) . to . equal (
98
+ 'Binary.createFromBase64("", 35)'
99
+ ) ;
98
100
} ) ;
99
101
100
- it ( 'when value is empty returns "Binary.createFromBase64("", 0)"' , ( ) => {
102
+ it ( 'when value has utf8 "abcdef" encoded returns "Binary.createFromBase64("YWJjZGVm ", 0)"' , ( ) => {
101
103
expect ( new Binary ( Buffer . from ( 'abcdef' , 'utf8' ) ) . inspect ( ) ) . to . equal (
102
104
'Binary.createFromBase64("YWJjZGVm", 0)'
103
105
) ;
104
106
} ) ;
105
107
106
108
context ( 'when result is executed' , ( ) => {
107
- it ( 'is deep equal with a Binary that has no data ' , ( ) => {
109
+ it ( 'has a position of zero when constructed with default space ' , ( ) => {
108
110
const bsonValue = new Binary ( ) ;
109
111
const ctx = { ...BSON , module : { exports : { result : null } } } ;
110
112
vm . runInNewContext ( `module.exports.result = ${ bsonValue . inspect ( ) } ` , ctx ) ;
113
+ expect ( ctx . module . exports . result ) . to . have . property ( 'position' , 0 ) ;
114
+ expect ( ctx . module . exports . result ) . to . have . property ( 'sub_type' , 0 ) ;
115
+
116
+ // While the default Binary has 256 bytes the newly constructed one will have 0
117
+ // both will have a position of zero so when serialized to BSON they are the equivalent.
118
+ expect ( ctx . module . exports . result ) . to . have . nested . property ( 'buffer.byteLength' , 0 ) ;
119
+ expect ( bsonValue ) . to . have . nested . property ( 'buffer.byteLength' , 256 ) ;
120
+ } ) ;
121
+
122
+ it ( 'is deep equal with a Binary that has no data' , ( ) => {
123
+ const bsonValue = new Binary ( new Uint8Array ( 0 ) ) ;
124
+ const ctx = { ...BSON , module : { exports : { result : null } } } ;
125
+ vm . runInNewContext ( `module.exports.result = ${ bsonValue . inspect ( ) } ` , ctx ) ;
111
126
expect ( ctx . module . exports . result ) . to . deep . equal ( bsonValue ) ;
112
127
} ) ;
113
128
114
129
it ( 'is deep equal with a Binary that has a subtype but no data' , ( ) => {
115
- const bsonValue = new Binary ( undefined , 0x23 ) ;
130
+ const bsonValue = new Binary ( new Uint8Array ( 0 ) , 0x23 ) ;
116
131
const ctx = { ...BSON , module : { exports : { result : null } } } ;
117
132
vm . runInNewContext ( `module.exports.result = ${ bsonValue . inspect ( ) } ` , ctx ) ;
118
133
expect ( ctx . module . exports . result ) . to . deep . equal ( bsonValue ) ;
0 commit comments