|
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,83 @@ 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("10469069930579305970359073950793057903597035970395069240692049609"), |
| 361 | + nv("99130490139501395091035901395031950.4928053468045683958609485649280534680456839586094856"), |
| 362 | + nv("1.000135135000103501305000000000004928053468045683958609485649280534680456839586094856"), |
| 363 | + nv("1.00013513500010350130500000000000"), |
| 364 | + nv("0.0000000001234000000001234"), |
| 365 | + nv("0.0000001"), |
| 366 | + nv("0.00001"), |
| 367 | + nv("0.001"), |
| 368 | + nv("0.000000"), |
| 369 | + nv("0.0000"), |
| 370 | + nv("0.00"), |
| 371 | + nv("0.0"), |
| 372 | + nv("0"), |
| 373 | + nv("-0.1"), |
| 374 | + nv("-0.01"), |
| 375 | + nv("-0.000000000123400000087678634"), |
| 376 | + nv("-0.0000000001234000000876786340000000000000000000000000000"), |
| 377 | + nv("-1.000135135000103501305000000000004928053468045683958609485649280534680456839586094856"), |
| 378 | + nv("-1.00013513500010350130500000000000"), |
| 379 | + nv("-100305096350939057390735093.0000000001234000000001234"), |
| 380 | + nv("-104695047960794069730590793057.0"), |
| 381 | + nv("-104695047960794069730590793057"), |
| 382 | + ], |
| 383 | + }, |
| 384 | + }; |
| 385 | + |
| 386 | + const serialized = cbor.serialize(sequence); |
| 387 | + const deserialized = cbor.deserialize(serialized); |
| 388 | + |
| 389 | + expect(deserialized).toEqual(sequence); |
| 390 | + }); |
| 391 | + |
308 | 392 | it("should throw an error if serializing a tag with missing properties", () => {
|
309 | 393 | expect(() =>
|
310 | 394 | cbor.serialize({
|
|
0 commit comments