-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed negative small int CBOR de-serializing (#64)
- Loading branch information
1 parent
957d42f
commit fbf4176
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Package : Cbor | ||
* Author : Alex Dochioiu <[email protected]> | ||
* Date : 19/06/2024 | ||
* Copyright : Alex Dochioiu | ||
*/ | ||
|
||
import 'package:cbor/cbor.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group("Int Numbers Test", () { | ||
final numbersToTest = [ | ||
BigInt.parse("0"), | ||
BigInt.parse("1"), | ||
BigInt.parse("2656159029"), | ||
BigInt.parse("4294967295"), | ||
BigInt.parse("4294967296"), | ||
BigInt.parse("4294967299"), | ||
BigInt.parse("5294967590"), | ||
BigInt.parse("91234567890"), | ||
BigInt.parse("912345678901234567890"), | ||
]; | ||
|
||
group("positive numbers", () { | ||
for (final number in numbersToTest) { | ||
test(number.toString(), () { | ||
final cborInt = CborInt(number); | ||
final serialized = cborEncode(cborInt); | ||
final deserialized = cborDecode(serialized); | ||
expect(cborInt.toBigInt(), number); | ||
expect(deserialized, isA<CborInt>()); | ||
expect((deserialized as CborInt).toBigInt(), number); | ||
}); | ||
} | ||
}); | ||
|
||
group("negative numbers", () { | ||
for (final positiveNumber in numbersToTest) { | ||
final number = BigInt.zero - positiveNumber; | ||
test(number.toString(), () { | ||
final cborInt = CborInt(number); | ||
final serialized = cborEncode(cborInt); | ||
final deserialized = cborDecode(serialized); | ||
expect(cborInt.toBigInt(), number); | ||
expect(deserialized, isA<CborInt>()); | ||
expect((deserialized as CborInt).toBigInt(), number); | ||
}); | ||
} | ||
}); | ||
}); | ||
} |