|
1 | | -import { NumericValue } from "@smithy/core/serde"; |
| 1 | +import { NumericValue, nv } from "@smithy/core/serde"; |
2 | 2 | import * as fs from "fs"; |
3 | 3 | // @ts-ignore |
4 | 4 | import JSONbig from "json-bigint"; |
@@ -219,12 +219,19 @@ describe("cbor", () => { |
219 | 219 | name: "object containing big numbers", |
220 | 220 | data: { |
221 | 221 | map: { |
222 | | - items: [BigInt(1e80)], |
| 222 | + items: [BigInt(1e80), BigInt(1e80), nv("0.0000000001234000000001234"), nv("0.0000000001234000000001234")], |
| 223 | + bigint: BigInt(1e80), |
| 224 | + bigDecimal: nv("0.0000000001234000000001234"), |
223 | 225 | }, |
224 | 226 | }, |
225 | 227 | cbor: allocByteArray([ |
226 | | - 161, 99, 109, 97, 112, 161, 101, 105, 116, 101, 109, 115, 129, 194, 88, 34, 3, 95, 157, 234, 62, 31, 107, 224, |
227 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 228 | + 161, 99, 109, 97, 112, 163, 101, 105, 116, 101, 109, 115, 132, 194, 88, 34, 3, 95, 157, 234, 62, 31, 107, 224, |
| 229 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 194, 88, 34, 3, 95, 157, 234, 62, |
| 230 | + 31, 107, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 130, 56, 24, |
| 231 | + 27, 0, 4, 98, 81, 3, 167, 36, 210, 196, 130, 56, 24, 27, 0, 4, 98, 81, 3, 167, 36, 210, 102, 98, 105, 103, 105, |
| 232 | + 110, 116, 194, 88, 34, 3, 95, 157, 234, 62, 31, 107, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 233 | + 0, 0, 0, 0, 0, 0, 0, 0, 106, 98, 105, 103, 68, 101, 99, 105, 109, 97, 108, 196, 130, 56, 24, 27, 0, 4, 98, 81, |
| 234 | + 3, 167, 36, 210, |
228 | 235 | ]), |
229 | 236 | }, |
230 | 237 | ]; |
@@ -305,6 +312,69 @@ describe("cbor", () => { |
305 | 312 | } |
306 | 313 | }); |
307 | 314 |
|
| 315 | + it("should round-trip sequences of big numbers", () => { |
| 316 | + const sequence = { |
| 317 | + map: { |
| 318 | + items1: [ |
| 319 | + BigInt(1e20), |
| 320 | + BigInt(2e30), |
| 321 | + BigInt(3e40), |
| 322 | + BigInt(4e50), |
| 323 | + BigInt(5e60), |
| 324 | + BigInt(6e70), |
| 325 | + BigInt(7e80), |
| 326 | + BigInt(8e90), |
| 327 | + ], |
| 328 | + items2: [ |
| 329 | + nv("111.00000000000000000001"), |
| 330 | + nv("0.000000000000000000002"), |
| 331 | + nv("333.0000000000000000000003"), |
| 332 | + nv("0.00000000000000000000004"), |
| 333 | + nv("-555.000000000000000000000005"), |
| 334 | + nv("-0.0000000000000000000000006"), |
| 335 | + nv("-777.00000000000000000000000007"), |
| 336 | + nv("-0.000000000000000000000000008"), |
| 337 | + ], |
| 338 | + items3: [nv("0.0000000001234000000001234"), nv("0.00000000678678001234"), BigInt(1e20), BigInt(2e30)], |
| 339 | + items4: [ |
| 340 | + BigInt(1e20), |
| 341 | + BigInt(2e30), |
| 342 | + nv("0.0000000001234000000001234"), |
| 343 | + nv("0.0000067867867801234"), |
| 344 | + BigInt(1e20), |
| 345 | + BigInt(2e30), |
| 346 | + nv("0.0000000001234000000001234"), |
| 347 | + nv("1.000000000123678678678234"), |
| 348 | + ], |
| 349 | + items5: [ |
| 350 | + nv("0.0000000001234000000001234"), |
| 351 | + nv("0.00006786781234678678678"), |
| 352 | + BigInt(1e20), |
| 353 | + BigInt(2e30), |
| 354 | + nv("0.0000000001234000000001234"), |
| 355 | + nv("0.000000000123400000087678634"), |
| 356 | + BigInt(1e20), |
| 357 | + BigInt(2e30), |
| 358 | + ], |
| 359 | + items6: [ |
| 360 | + nv("0.0000000001234000000001234"), |
| 361 | + nv("0.00006786781234678678678"), |
| 362 | + nv("0.0000000001234000000001234"), |
| 363 | + nv("0.000000000123400000087678634"), |
| 364 | + nv("0.0000000001234000000001234"), |
| 365 | + nv("0.00006786781234678678678"), |
| 366 | + nv("0.0000000001234000000001234"), |
| 367 | + nv("0.000000000123400000087678634"), |
| 368 | + ], |
| 369 | + }, |
| 370 | + }; |
| 371 | + |
| 372 | + const serialized = cbor.serialize(sequence); |
| 373 | + const deserialized = cbor.deserialize(serialized); |
| 374 | + |
| 375 | + expect(deserialized).toEqual(sequence); |
| 376 | + }); |
| 377 | + |
308 | 378 | it("should throw an error if serializing a tag with missing properties", () => { |
309 | 379 | expect(() => |
310 | 380 | cbor.serialize({ |
|
0 commit comments