diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2016-04-28 14:34:59 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2016-04-28 14:34:59 -0700 |
commit | cf14183bcd5485b4a71541599ddce0b35eb71352 (patch) | |
tree | 12f6e5eb731d7a70cdac4cdafc8b3131629413e2 /js/binary/utils_test.js | |
parent | f00300d7f04f1c38a7d70e271f9232b94dd0e326 (diff) | |
download | protobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.tar.gz protobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.tar.bz2 protobuf-cf14183bcd5485b4a71541599ddce0b35eb71352.zip |
Down integrate from Google internal.
Diffstat (limited to 'js/binary/utils_test.js')
-rw-r--r-- | js/binary/utils_test.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/js/binary/utils_test.js b/js/binary/utils_test.js index 518d7597..d27e5ea2 100644 --- a/js/binary/utils_test.js +++ b/js/binary/utils_test.js @@ -197,6 +197,41 @@ describe('binaryUtilsTest', function() { assertEquals('123456789123456789', result[2]); }); + /* + * Going from decimal strings to hash strings should be lossless. + */ + it('testDecimalToHashConversion', function() { + var result; + var convert = jspb.utils.decimalStringToHash64; + + result = convert('0'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result); + + result = convert('-1'); + assertEquals(String.fromCharCode.apply(null, + [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); + + result = convert('18446744073709551615'); + assertEquals(String.fromCharCode.apply(null, + [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); + + result = convert('9223372036854775808'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); + + result = convert('-9223372036854775808'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); + + result = convert('123456789123456789'); + assertEquals(String.fromCharCode.apply(null, + [0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result); + + result = convert('-123456789123456789'); + assertEquals(String.fromCharCode.apply(null, + [0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result); + }); /** * Going from hash strings to hex strings should be lossless. |