diff options
Diffstat (limited to 'js/message_test.js')
-rw-r--r-- | js/message_test.js | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/js/message_test.js b/js/message_test.js index a2c5763d..1be41093 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -33,6 +33,8 @@ goog.setTestOnly(); goog.require('goog.json'); +goog.require('goog.string'); +goog.require('goog.testing.PropertyReplacer'); goog.require('goog.testing.asserts'); goog.require('goog.userAgent'); @@ -40,6 +42,7 @@ goog.require('goog.userAgent'); goog.require('jspb.Message'); // CommonJS-LoadFromFile: test8_pb proto.jspb.exttest.nested +goog.require('proto.jspb.exttest.nested.TestNestedExtensionsMessage'); goog.require('proto.jspb.exttest.nested.TestOuterMessage'); // CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta @@ -82,9 +85,17 @@ goog.require('proto.jspb.test.ExtensionMessage'); goog.require('proto.jspb.test.TestExtensionsMessage'); +describe('Message test suite', function() { + var stubs = new goog.testing.PropertyReplacer(); + beforeEach(function() { + stubs.set(jspb.Message, 'SERIALIZE_EMPTY_TRAILING_FIELDS', false); + }); + + afterEach(function() { + stubs.reset(); + }); -describe('Message test suite', function() { it('testEmptyProto', function() { var empty1 = new proto.jspb.test.Empty([]); var empty2 = new proto.jspb.test.Empty([]); @@ -272,12 +283,6 @@ describe('Message test suite', function() { assertFalse(response.hasEnumField()); }); - it('testMessageRegistration', /** @suppress {visibility} */ function() { - // goog.require(SomeResponse) will include its library, which will in - // turn add SomeResponse to the message registry. - assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse); - }); - it('testClearFields', function() { var data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; var foo = new proto.jspb.test.OptionalFields(data); @@ -413,6 +418,18 @@ describe('Message test suite', function() { ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); }); + it('testEqualsNonFinite', function() { + assertTrue(jspb.Message.compareFields(NaN, NaN)); + assertTrue(jspb.Message.compareFields(NaN, 'NaN')); + assertTrue(jspb.Message.compareFields('NaN', NaN)); + assertTrue(jspb.Message.compareFields(Infinity, Infinity)); + assertTrue(jspb.Message.compareFields(Infinity, 'Infinity')); + assertTrue(jspb.Message.compareFields('-Infinity', -Infinity)); + assertTrue(jspb.Message.compareFields([NaN], ['NaN'])); + assertFalse(jspb.Message.compareFields(undefined, NaN)); + assertFalse(jspb.Message.compareFields(NaN, undefined)); + }); + it('testToMap', function() { var p1 = new proto.jspb.test.Simple1(['k', ['v']]); var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]); @@ -660,12 +677,7 @@ describe('Message test suite', function() { it('testInitialization_emptyArray', function() { var msg = new proto.jspb.test.HasExtensions([]); - if (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) { - assertArrayEquals([], msg.toArray()); - } else { - // Extension object is created past all regular fields. - assertArrayEquals([,,, {}], msg.toArray()); - } + assertArrayEquals([], msg.toArray()); }); it('testInitialization_justExtensionObject', function() { @@ -693,10 +705,11 @@ describe('Message test suite', function() { }); it('testToObject_hasExtensionField', function() { - var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); + var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1'], 102: ''}]); var obj = data.toObject(); assertEquals('str1', obj.str1); assertEquals('ext1', obj.extField.ext1); + assertEquals('', obj.str); }); it('testGetExtension', function() { |