@@ -37,6 +37,7 @@ import {
3737 internal ,
3838 vector ,
3939 json ,
40+ UnsupportedType ,
4041 ProtocolVersion
4142} from 'neo4j-driver-core'
4243
@@ -1186,6 +1187,89 @@ describe('#unit BoltProtocolV6x0', () => {
11861187 const unpacked = protocol . unpack ( buffer )
11871188 expect ( unpacked ) . toEqual ( struct )
11881189 } )
1190+
1191+ it . each ( [
1192+ [
1193+ 'float32' ,
1194+ new structure . Structure ( 0x56 , [ [ 0xC6 ] , new Int8Array ( Float32Array . from ( [ 13 , Infinity , - Infinity , NaN ] ) . buffer ) ] ) ,
1195+ vector ( Float32Array . from ( [ 13 , Infinity , - Infinity , NaN ] ) )
1196+ ] ,
1197+ [
1198+ 'float64' ,
1199+ new structure . Structure ( 0x56 , [ [ 0xC1 ] , new Int8Array ( Float64Array . from ( [ 13 , Infinity , - Infinity , NaN ] ) . buffer ) ] ) ,
1200+ vector ( Float64Array . from ( [ 13 , Infinity , - Infinity , NaN ] ) )
1201+ ] ,
1202+ [
1203+ 'int8' ,
1204+ new structure . Structure ( 0x56 , [ [ 0xC8 ] , Int8Array . from ( [ - 128 , 127 ] ) ] ) ,
1205+ vector ( Int8Array . from ( [ - 128 , 127 ] ) )
1206+ ] ,
1207+ [
1208+ 'int16' ,
1209+ new structure . Structure ( 0x56 , [ [ 0xC9 ] , new Int8Array ( Int16Array . from ( [ - 32768 , 32767 ] ) . buffer ) ] ) ,
1210+ vector ( Int16Array . from ( [ - 32768 , 32767 ] ) )
1211+ ] ,
1212+ [
1213+ 'int32' ,
1214+ new structure . Structure ( 0x56 , [ [ 0xCA ] , new Int8Array ( Int32Array . from ( [ - 2147483648 , 2147483647 ] ) . buffer ) ] ) ,
1215+ vector ( Int32Array . from ( [ - 2147483648 , 2147483647 ] ) )
1216+ ] ,
1217+ [
1218+ 'int64' ,
1219+ new structure . Structure ( 0x56 , [ [ 0xCB ] , new Int8Array ( BigInt64Array . from ( [ - 9223372036854775808n , 9223372036854775807n ] ) . buffer ) ] ) ,
1220+ vector ( BigInt64Array . from ( [ - 9223372036854775808n , 9223372036854775807n ] ) )
1221+ ]
1222+ ] ) ( 'should unpack (%s) vector' , ( _ , struct , object ) => {
1223+ const buffer = alloc ( 256 )
1224+ const protocol = new BoltProtocolV6x0 (
1225+ new utils . MessageRecordingConnection ( ) ,
1226+ buffer ,
1227+ {
1228+ disableLosslessIntegers : true
1229+ }
1230+ )
1231+
1232+ const packable = protocol . packable ( struct )
1233+
1234+ expect ( packable ) . not . toThrow ( )
1235+
1236+ buffer . reset ( )
1237+
1238+ const unpacked = protocol . unpack ( buffer )
1239+ expect ( unpacked . asTypedArray ( ) . buffer ) . toEqual ( object . asTypedArray ( ) . buffer ) // compares buffers to successfully compare BigInts
1240+ expect ( unpacked . getType ( ) ) . toEqual ( object . getType ( ) )
1241+ } )
1242+
1243+ it . each ( [
1244+ [
1245+ 'without message' ,
1246+ new structure . Structure ( 0x3F , [ 'Quantum Integer' , 6 , 10 , { } ] ) ,
1247+ new UnsupportedType ( 'Quantum Integer' , 6 , 10 )
1248+ ] ,
1249+ [
1250+ 'with message' ,
1251+ new structure . Structure ( 0x3F , [ 'Quantum Integer' , 6 , 10 , { message : 'Quantum computing is always 10 years away' } ] ) ,
1252+ new UnsupportedType ( 'Quantum Integer' , 6 , 10 , 'Quantum computing is always 10 years away' )
1253+ ]
1254+ ] ) ( 'should unpack unknown type (%s)' , ( _ , struct , object ) => {
1255+ const buffer = alloc ( 256 )
1256+ const protocol = new BoltProtocolV6x0 (
1257+ new utils . MessageRecordingConnection ( ) ,
1258+ buffer ,
1259+ {
1260+ disableLosslessIntegers : true
1261+ }
1262+ )
1263+
1264+ const packable = protocol . packable ( struct )
1265+
1266+ expect ( packable ) . not . toThrow ( )
1267+
1268+ buffer . reset ( )
1269+
1270+ const unpacked = protocol . unpack ( buffer )
1271+ expect ( unpacked ) . toEqual ( object )
1272+ } )
11891273 } )
11901274
11911275 describe ( 'result metadata enrichment' , ( ) => {
0 commit comments