@@ -9,6 +9,37 @@ describe('Timestamp', () => {
9
9
} ) ;
10
10
} ) ;
11
11
12
+ describe ( 'get i() and get t()' , ( ) => {
13
+ it ( 'i returns lower bits' , ( ) => {
14
+ const l = new BSON . Long ( 1 , 2 ) ;
15
+ const ts = new BSON . Timestamp ( l ) ;
16
+ expect ( ts . i ) . to . equal ( l . low ) ;
17
+ } ) ;
18
+
19
+ it ( 't returns higher bits' , ( ) => {
20
+ const l = new BSON . Long ( 1 , 2 ) ;
21
+ const ts = new BSON . Timestamp ( l ) ;
22
+ expect ( ts . t ) . to . equal ( l . high ) ;
23
+ } ) ;
24
+
25
+ describe ( 'when signed negative input is provided to the constructor' , ( ) => {
26
+ it ( 't and i return unsigned values' , ( ) => {
27
+ const l = new BSON . Long ( - 1 , - 2 ) ;
28
+ // Check the assumption that Long did NOT change the values to unsigned.
29
+ expect ( l ) . to . have . property ( 'low' , - 1 ) ;
30
+ expect ( l ) . to . have . property ( 'high' , - 2 ) ;
31
+
32
+ const ts = new BSON . Timestamp ( l ) ;
33
+ expect ( ts ) . to . have . property ( 'i' , 0xffffffff ) ; // -1 unsigned
34
+ expect ( ts ) . to . have . property ( 't' , 0xfffffffe ) ; // -2 unsigned
35
+
36
+ // Timestamp is a subclass of Long, high and low do not change:
37
+ expect ( ts ) . to . have . property ( 'low' , - 1 ) ;
38
+ expect ( ts ) . to . have . property ( 'high' , - 2 ) ;
39
+ } ) ;
40
+ } ) ;
41
+ } ) ;
42
+
12
43
it ( 'should always be an unsigned value' , ( ) => {
13
44
let bigIntInputs : Timestamp [ ] = [ ] ;
14
45
if ( ! __noBigInt__ ) {
@@ -23,7 +54,8 @@ describe('Timestamp', () => {
23
54
new BSON . Timestamp ( { t : 0xffff_ffff , i : 0xffff_ffff } ) ,
24
55
// @ts -expect-error We do not advertise support for Int32 in the constructor of Timestamp
25
56
// We do expect it to work so that round tripping the Int32 instance inside a Timestamp works
26
- new BSON . Timestamp ( { t : new BSON . Int32 ( 0x7fff_ffff ) , i : new BSON . Int32 ( 0x7fff_ffff ) } )
57
+ new BSON . Timestamp ( { t : new BSON . Int32 ( 0x7fff_ffff ) , i : new BSON . Int32 ( 0x7fff_ffff ) } ) ,
58
+ new BSON . Timestamp ( new BSON . Timestamp ( { t : 0xffff_ffff , i : 0xffff_ffff } ) )
27
59
] ;
28
60
29
61
for ( const timestamp of table ) {
@@ -69,6 +101,12 @@ describe('Timestamp', () => {
69
101
expect ( timestamp . toExtendedJSON ( ) ) . to . deep . equal ( { $timestamp : input } ) ;
70
102
} ) ;
71
103
104
+ it ( 'accepts timestamp object as input' , ( ) => {
105
+ const input = new BSON . Timestamp ( { t : 89 , i : 144 } ) ;
106
+ const timestamp = new BSON . Timestamp ( input ) ;
107
+ expect ( timestamp . toExtendedJSON ( ) ) . to . deep . equal ( { $timestamp : { t : input . t , i : input . i } } ) ;
108
+ } ) ;
109
+
72
110
it ( 'accepts { t, i } object as input and coerce to integer' , ( ) => {
73
111
const input = { t : new BSON . Int32 ( 89 ) , i : new BSON . Int32 ( 144 ) } ;
74
112
// @ts -expect-error We do not advertise support for Int32 in the constructor of Timestamp
0 commit comments