diff options
author | Adam Cozzette <acozzette@google.com> | 2018-05-25 14:12:43 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2018-05-25 14:44:22 -0700 |
commit | d1af029104e9b594a99209484914b822addb08fa (patch) | |
tree | ea2c0cfe72f25c79e6bb0e0d7f8f4da320cc3c4a /js/maps_test.js | |
parent | 6f723a6624de0e0f9b1ae16ae002e678613e07b8 (diff) |
Fixed JS parsing of unspecified map keys
We need to use a default of 0 when parsing unspecified map keys, instead
of failing an assertion.
This change was written by Michael Aaron (michaelaaron@google.com) but I
am cherry-picking it directly instead of waiting for the next sync of
Google-internal changes.
Diffstat (limited to 'js/maps_test.js')
-rwxr-xr-x | js/maps_test.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/js/maps_test.js b/js/maps_test.js index e8dd2f21..e496f446 100755 --- a/js/maps_test.js +++ b/js/maps_test.js @@ -35,6 +35,11 @@ goog.require('goog.userAgent'); goog.require('proto.jspb.test.MapValueEnum'); goog.require('proto.jspb.test.MapValueMessage'); goog.require('proto.jspb.test.TestMapFields'); +goog.require('proto.jspb.test.TestMapFieldsOptionalKeys'); +goog.require('proto.jspb.test.MapEntryOptionalKeysStringKey'); +goog.require('proto.jspb.test.MapEntryOptionalKeysInt32Key'); +goog.require('proto.jspb.test.MapEntryOptionalKeysInt64Key'); +goog.require('proto.jspb.test.MapEntryOptionalKeysBoolKey'); // CommonJS-LoadFromFile: test_pb proto.jspb.test goog.require('proto.jspb.test.MapValueMessageNoBinary'); @@ -76,7 +81,7 @@ function toArray(iter) { * Helper: generate test methods for this TestMapFields class. * @param {?} msgInfo * @param {?} submessageCtor - * @param {!string} suffix + * @param {string} suffix */ function makeTests(msgInfo, submessageCtor, suffix) { /** @@ -260,6 +265,39 @@ function makeTests(msgInfo, submessageCtor, suffix) { var decoded = msgInfo.deserializeBinary(serialized); checkMapFields(decoded); }); + /** + * Tests deserialization of undefined map keys go to default values in binary format. + */ + it('testMapDeserializationForUndefinedKeys', function() { + var testMessageOptionalKeys = new proto.jspb.test.TestMapFieldsOptionalKeys(); + var mapEntryStringKey = new proto.jspb.test.MapEntryOptionalKeysStringKey(); + mapEntryStringKey.setValue("a"); + testMessageOptionalKeys.setMapStringString(mapEntryStringKey); + var mapEntryInt32Key = new proto.jspb.test.MapEntryOptionalKeysInt32Key(); + mapEntryInt32Key.setValue("b"); + testMessageOptionalKeys.setMapInt32String(mapEntryInt32Key); + var mapEntryInt64Key = new proto.jspb.test.MapEntryOptionalKeysInt64Key(); + mapEntryInt64Key.setValue("c"); + testMessageOptionalKeys.setMapInt64String(mapEntryInt64Key); + var mapEntryBoolKey = new proto.jspb.test.MapEntryOptionalKeysBoolKey(); + mapEntryBoolKey.setValue("d"); + testMessageOptionalKeys.setMapBoolString(mapEntryBoolKey); + var deserializedMessage = msgInfo.deserializeBinary( + testMessageOptionalKeys.serializeBinary() + ); + checkMapEquals(deserializedMessage.getMapStringStringMap(), [ + ['', 'a'] + ]); + checkMapEquals(deserializedMessage.getMapInt32StringMap(), [ + [0, 'b'] + ]); + checkMapEquals(deserializedMessage.getMapInt64StringMap(), [ + [0, 'c'] + ]); + checkMapEquals(deserializedMessage.getMapBoolStringMap(), [ + [false, 'd'] + ]); + }); } |