|
|
|
@ -145,11 +145,7 @@ describe('Message test suite', function() { |
|
|
|
|
undefined, undefined, undefined, undefined]); |
|
|
|
|
var result = foo.toObject(); |
|
|
|
|
assertObjectEquals({ |
|
|
|
|
aString: undefined, |
|
|
|
|
anOutOfOrderBool: undefined, |
|
|
|
|
aNestedMessage: { |
|
|
|
|
anInt: undefined |
|
|
|
|
}, |
|
|
|
|
aNestedMessage: {}, |
|
|
|
|
// Note: JsPb converts undefined repeated fields to empty arrays.
|
|
|
|
|
aRepeatedMessageList: [], |
|
|
|
|
aRepeatedStringList: [] |
|
|
|
@ -184,14 +180,7 @@ describe('Message test suite', function() { |
|
|
|
|
var response = new proto.jspb.test.DefaultValues(); |
|
|
|
|
|
|
|
|
|
// Test toObject
|
|
|
|
|
var expectedObject = { |
|
|
|
|
stringField: defaultString, |
|
|
|
|
boolField: true, |
|
|
|
|
intField: 11, |
|
|
|
|
enumField: 13, |
|
|
|
|
emptyField: '', |
|
|
|
|
bytesField: 'bW9v' |
|
|
|
|
}; |
|
|
|
|
var expectedObject = {}; |
|
|
|
|
assertObjectEquals(expectedObject, response.toObject()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -276,9 +265,6 @@ describe('Message test suite', function() { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('testClearFields', function() { |
|
|
|
|
// We don't set 'proper' defaults, rather, bools, strings,
|
|
|
|
|
// etc, are cleared to undefined or null and take on the Javascript
|
|
|
|
|
// meaning for that value. Repeated fields are set to [] when cleared.
|
|
|
|
|
var data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; |
|
|
|
|
var foo = new proto.jspb.test.OptionalFields(data); |
|
|
|
|
foo.clearAString(); |
|
|
|
@ -286,8 +272,8 @@ describe('Message test suite', function() { |
|
|
|
|
foo.clearANestedMessage(); |
|
|
|
|
foo.clearARepeatedMessageList(); |
|
|
|
|
foo.clearARepeatedStringList(); |
|
|
|
|
assertUndefined(foo.getAString()); |
|
|
|
|
assertUndefined(foo.getABool()); |
|
|
|
|
assertEquals('', foo.getAString()); |
|
|
|
|
assertEquals(false, foo.getABool()); |
|
|
|
|
assertUndefined(foo.getANestedMessage()); |
|
|
|
|
assertFalse(foo.hasAString()); |
|
|
|
|
assertFalse(foo.hasABool()); |
|
|
|
@ -310,8 +296,8 @@ describe('Message test suite', function() { |
|
|
|
|
foo.setANestedMessage(null); |
|
|
|
|
foo.setARepeatedMessageList(null); |
|
|
|
|
foo.setARepeatedStringList(null); |
|
|
|
|
assertNull(foo.getAString()); |
|
|
|
|
assertNull(foo.getABool()); |
|
|
|
|
assertEquals('', foo.getAString()); |
|
|
|
|
assertEquals(false, foo.getABool()); |
|
|
|
|
assertNull(foo.getANestedMessage()); |
|
|
|
|
assertFalse(foo.hasAString()); |
|
|
|
|
assertFalse(foo.hasABool()); |
|
|
|
@ -328,8 +314,8 @@ describe('Message test suite', function() { |
|
|
|
|
foo.setANestedMessage(undefined); |
|
|
|
|
foo.setARepeatedMessageList(undefined); |
|
|
|
|
foo.setARepeatedStringList(undefined); |
|
|
|
|
assertUndefined(foo.getAString()); |
|
|
|
|
assertUndefined(foo.getABool()); |
|
|
|
|
assertEquals('', foo.getAString()); |
|
|
|
|
assertEquals(false, foo.getABool()); |
|
|
|
|
assertUndefined(foo.getANestedMessage()); |
|
|
|
|
assertFalse(foo.hasAString()); |
|
|
|
|
assertFalse(foo.hasABool()); |
|
|
|
@ -346,9 +332,9 @@ describe('Message test suite', function() { |
|
|
|
|
{1000: 'unique'}]); |
|
|
|
|
var diff = /** @type {proto.jspb.test.HasExtensions} */ |
|
|
|
|
(jspb.Message.difference(p1, p2)); |
|
|
|
|
assertUndefined(diff.getStr1()); |
|
|
|
|
assertEquals('', diff.getStr1()); |
|
|
|
|
assertEquals('what', diff.getStr2()); |
|
|
|
|
assertUndefined(diff.getStr3()); |
|
|
|
|
assertEquals('', diff.getStr3()); |
|
|
|
|
assertEquals('unique', diff.extensionObject_[1000]); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -762,12 +748,7 @@ describe('Message test suite', function() { |
|
|
|
|
assertObjectEquals({id: 'g1', someBoolList: [true, false]}, |
|
|
|
|
groups[0].toObject()); |
|
|
|
|
assertObjectEquals({ |
|
|
|
|
repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}], |
|
|
|
|
requiredGroup: {id: undefined}, |
|
|
|
|
optionalGroup: undefined, |
|
|
|
|
requiredSimple: {aRepeatedStringList: [], aString: undefined}, |
|
|
|
|
optionalSimple: undefined, |
|
|
|
|
id: undefined |
|
|
|
|
repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}] |
|
|
|
|
}, group.toObject()); |
|
|
|
|
var group1 = new proto.jspb.test.TestGroup1(); |
|
|
|
|
group1.setGroup(someGroup); |
|
|
|
@ -806,7 +787,7 @@ describe('Message test suite', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']); |
|
|
|
|
|
|
|
|
|
assertEquals('x', message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, |
|
|
|
|
message.getPartialOneofCase()); |
|
|
|
@ -815,7 +796,7 @@ describe('Message test suite', function() { |
|
|
|
|
it('testKeepsLastWireValueSetInUnion_multipleValues', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']); |
|
|
|
|
|
|
|
|
|
assertUndefined('x', message.getPone()); |
|
|
|
|
assertEquals('', message.getPone()); |
|
|
|
|
assertEquals('y', message.getPthree()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE, |
|
|
|
@ -824,19 +805,19 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
it('testSettingOneofFieldClearsOthers', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
assertUndefined(message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPone()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertFalse(message.hasPone()); |
|
|
|
|
assertFalse(message.hasPthree()); |
|
|
|
|
|
|
|
|
|
message.setPone('hi'); |
|
|
|
|
assertEquals('hi', message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertTrue(message.hasPone()); |
|
|
|
|
assertFalse(message.hasPthree()); |
|
|
|
|
|
|
|
|
|
message.setPthree('bye'); |
|
|
|
|
assertUndefined(message.getPone()); |
|
|
|
|
assertEquals('', message.getPone()); |
|
|
|
|
assertEquals('bye', message.getPthree()); |
|
|
|
|
assertFalse(message.hasPone()); |
|
|
|
|
assertTrue(message.hasPthree()); |
|
|
|
@ -845,8 +826,8 @@ describe('Message test suite', function() { |
|
|
|
|
it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() { |
|
|
|
|
var other = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
assertUndefined(message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPone()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertUndefined(message.getRone()); |
|
|
|
|
assertFalse(message.hasPone()); |
|
|
|
|
assertFalse(message.hasPthree()); |
|
|
|
@ -854,13 +835,13 @@ describe('Message test suite', function() { |
|
|
|
|
message.setPone('hi'); |
|
|
|
|
message.setRone(other); |
|
|
|
|
assertEquals('hi', message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertEquals(other, message.getRone()); |
|
|
|
|
assertTrue(message.hasPone()); |
|
|
|
|
assertFalse(message.hasPthree()); |
|
|
|
|
|
|
|
|
|
message.setPthree('bye'); |
|
|
|
|
assertUndefined(message.getPone()); |
|
|
|
|
assertEquals('', message.getPone()); |
|
|
|
|
assertEquals('bye', message.getPthree()); |
|
|
|
|
assertEquals(other, message.getRone()); |
|
|
|
|
assertFalse(message.hasPone()); |
|
|
|
@ -889,7 +870,7 @@ describe('Message test suite', function() { |
|
|
|
|
it('testMessageWithDefaultOneofValues', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
assertEquals(1234, message.getAone()); |
|
|
|
|
assertUndefined(message.getAtwo()); |
|
|
|
|
assertEquals(0, message.getAtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase |
|
|
|
|
.DEFAULT_ONEOF_A_NOT_SET, |
|
|
|
@ -897,7 +878,7 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
message.setAone(567); |
|
|
|
|
assertEquals(567, message.getAone()); |
|
|
|
|
assertUndefined(message.getAtwo()); |
|
|
|
|
assertEquals(0, message.getAtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, |
|
|
|
|
message.getDefaultOneofACase()); |
|
|
|
@ -911,7 +892,7 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
message.clearAtwo(); |
|
|
|
|
assertEquals(1234, message.getAone()); |
|
|
|
|
assertUndefined(message.getAtwo()); |
|
|
|
|
assertEquals(0, message.getAtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase |
|
|
|
|
.DEFAULT_ONEOF_A_NOT_SET, |
|
|
|
@ -920,7 +901,7 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
assertUndefined(message.getBone()); |
|
|
|
|
assertEquals(0, message.getBone()); |
|
|
|
|
assertEquals(1234, message.getBtwo()); |
|
|
|
|
assertFalse(message.hasBone()); |
|
|
|
|
assertFalse(message.hasBtwo()); |
|
|
|
@ -939,7 +920,7 @@ describe('Message test suite', function() { |
|
|
|
|
message.getDefaultOneofBCase()); |
|
|
|
|
|
|
|
|
|
message.setBtwo(3); |
|
|
|
|
assertUndefined(message.getBone()); |
|
|
|
|
assertEquals(0, message.getBone()); |
|
|
|
|
assertFalse(message.hasBone()); |
|
|
|
|
assertTrue(message.hasBtwo()); |
|
|
|
|
assertEquals(3, message.getBtwo()); |
|
|
|
@ -948,7 +929,7 @@ describe('Message test suite', function() { |
|
|
|
|
message.getDefaultOneofBCase()); |
|
|
|
|
|
|
|
|
|
message.clearBtwo(); |
|
|
|
|
assertUndefined(message.getBone()); |
|
|
|
|
assertEquals(0, message.getBone()); |
|
|
|
|
assertFalse(message.hasBone()); |
|
|
|
|
assertFalse(message.hasBtwo()); |
|
|
|
|
assertEquals(1234, message.getBtwo()); |
|
|
|
@ -962,7 +943,7 @@ describe('Message test suite', function() { |
|
|
|
|
var message = |
|
|
|
|
new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567)); |
|
|
|
|
assertEquals(567, message.getAone()); |
|
|
|
|
assertUndefined(message.getAtwo()); |
|
|
|
|
assertEquals(0, message.getAtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, |
|
|
|
|
message.getDefaultOneofACase()); |
|
|
|
@ -998,7 +979,7 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
message = |
|
|
|
|
new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890)); |
|
|
|
|
assertUndefined(message.getBone()); |
|
|
|
|
assertEquals(0, message.getBone()); |
|
|
|
|
assertEquals(890, message.getBtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, |
|
|
|
@ -1006,7 +987,7 @@ describe('Message test suite', function() { |
|
|
|
|
|
|
|
|
|
message = new proto.jspb.test.TestMessageWithOneof( |
|
|
|
|
new Array(11).concat(567, 890)); |
|
|
|
|
assertUndefined(message.getBone()); |
|
|
|
|
assertEquals(0, message.getBone()); |
|
|
|
|
assertEquals(890, message.getBtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, |
|
|
|
@ -1023,7 +1004,7 @@ describe('Message test suite', function() { |
|
|
|
|
var other = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
message.setRone(other); |
|
|
|
|
assertEquals(other, message.getRone()); |
|
|
|
|
assertUndefined(message.getRtwo()); |
|
|
|
|
assertEquals('', message.getRtwo()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE, |
|
|
|
|
message.getRecursiveOneofCase()); |
|
|
|
@ -1041,7 +1022,7 @@ describe('Message test suite', function() { |
|
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof; |
|
|
|
|
message.setPone('x'); |
|
|
|
|
assertEquals('x', message.getPone()); |
|
|
|
|
assertUndefined(message.getPthree()); |
|
|
|
|
assertEquals('', message.getPthree()); |
|
|
|
|
assertEquals( |
|
|
|
|
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, |
|
|
|
|
message.getPartialOneofCase()); |
|
|
|
|