|
@@ -67,7 +67,6 @@ goog.require('proto.jspb.test.Simple1');
|
|
|
goog.require('proto.jspb.test.Simple2');
|
|
|
goog.require('proto.jspb.test.SpecialCases');
|
|
|
goog.require('proto.jspb.test.TestClone');
|
|
|
-goog.require('proto.jspb.test.TestEndsWithBytes');
|
|
|
goog.require('proto.jspb.test.TestGroup');
|
|
|
goog.require('proto.jspb.test.TestGroup1');
|
|
|
goog.require('proto.jspb.test.TestMessageWithOneof');
|
|
@@ -77,7 +76,7 @@ goog.require('proto.jspb.test.TestReservedNamesExtension');
|
|
|
// CommonJS-LoadFromFile: test2_pb proto.jspb.test
|
|
|
goog.require('proto.jspb.test.ExtensionMessage');
|
|
|
goog.require('proto.jspb.test.TestExtensionsMessage');
|
|
|
-
|
|
|
+goog.require('proto.jspb.test.simple1');
|
|
|
|
|
|
|
|
|
|
|
@@ -102,59 +101,59 @@ describe('Message test suite', function() {
|
|
|
});
|
|
|
|
|
|
it('testComplexConversion', function() {
|
|
|
- var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, true];
|
|
|
- var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, true];
|
|
|
+ var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , true];
|
|
|
+ var data2 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , true];
|
|
|
var foo = new proto.jspb.test.Complex(data1);
|
|
|
var bar = new proto.jspb.test.Complex(data2);
|
|
|
var result = foo.toObject();
|
|
|
- assertObjectEquals({
|
|
|
- aString: 'a',
|
|
|
- anOutOfOrderBool: true,
|
|
|
- aNestedMessage: {
|
|
|
- anInt: 11
|
|
|
- },
|
|
|
- aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
|
|
|
- aRepeatedStringList: ['s1', 's2']
|
|
|
- }, result);
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ aString: 'a',
|
|
|
+ anOutOfOrderBool: true,
|
|
|
+ aNestedMessage: {anInt: 11},
|
|
|
+ aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
|
|
|
+ aRepeatedStringList: ['s1', 's2']
|
|
|
+ },
|
|
|
+ result);
|
|
|
|
|
|
// Now test with the jspb instances included.
|
|
|
result = foo.toObject(true /* opt_includeInstance */);
|
|
|
- assertObjectEquals({
|
|
|
- aString: 'a',
|
|
|
- anOutOfOrderBool: true,
|
|
|
- aNestedMessage: {
|
|
|
- anInt: 11,
|
|
|
- $jspbMessageInstance: foo.getANestedMessage()
|
|
|
- },
|
|
|
- aRepeatedMessageList: [
|
|
|
- {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
|
|
|
- {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
|
|
|
- ],
|
|
|
- aRepeatedStringList: ['s1', 's2'],
|
|
|
- $jspbMessageInstance: foo
|
|
|
- }, result);
|
|
|
-
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ aString: 'a',
|
|
|
+ anOutOfOrderBool: true,
|
|
|
+ aNestedMessage:
|
|
|
+ {anInt: 11, $jspbMessageInstance: foo.getANestedMessage()},
|
|
|
+ aRepeatedMessageList: [
|
|
|
+ {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
|
|
|
+ {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
|
|
|
+ ],
|
|
|
+ aRepeatedStringList: ['s1', 's2'],
|
|
|
+ $jspbMessageInstance: foo
|
|
|
+ },
|
|
|
+ result);
|
|
|
});
|
|
|
|
|
|
it('testMissingFields', function() {
|
|
|
var foo = new proto.jspb.test.Complex([
|
|
|
- undefined, undefined, undefined, [],
|
|
|
- undefined, undefined, undefined, undefined]);
|
|
|
+ undefined, undefined, undefined, [], undefined, undefined, undefined,
|
|
|
+ undefined
|
|
|
+ ]);
|
|
|
var bar = new proto.jspb.test.Complex([
|
|
|
- undefined, undefined, undefined, [],
|
|
|
- undefined, undefined, undefined, undefined]);
|
|
|
+ undefined, undefined, undefined, [], undefined, undefined, undefined,
|
|
|
+ undefined
|
|
|
+ ]);
|
|
|
var result = foo.toObject();
|
|
|
- assertObjectEquals({
|
|
|
- aString: undefined,
|
|
|
- anOutOfOrderBool: undefined,
|
|
|
- aNestedMessage: {
|
|
|
- anInt: undefined
|
|
|
- },
|
|
|
- // Note: JsPb converts undefined repeated fields to empty arrays.
|
|
|
- aRepeatedMessageList: [],
|
|
|
- aRepeatedStringList: []
|
|
|
- }, result);
|
|
|
-
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ aString: undefined,
|
|
|
+ anOutOfOrderBool: undefined,
|
|
|
+ aNestedMessage: {anInt: undefined},
|
|
|
+ // Note: JsPb converts undefined repeated fields to empty arrays.
|
|
|
+ aRepeatedMessageList: [],
|
|
|
+ aRepeatedStringList: []
|
|
|
+ },
|
|
|
+ result);
|
|
|
});
|
|
|
|
|
|
it('testNestedComplexMessage', function() {
|
|
@@ -167,20 +166,21 @@ describe('Message test suite', function() {
|
|
|
it('testSpecialCases', function() {
|
|
|
// Note: Some property names are reserved in JavaScript.
|
|
|
// These names are converted to the Js property named pb_<reserved_name>.
|
|
|
- var special =
|
|
|
- new proto.jspb.test.SpecialCases(['normal', 'default', 'function',
|
|
|
- 'var']);
|
|
|
+ var special = new proto.jspb.test.SpecialCases(
|
|
|
+ ['normal', 'default', 'function', 'var']);
|
|
|
var result = special.toObject();
|
|
|
- assertObjectEquals({
|
|
|
- normal: 'normal',
|
|
|
- pb_default: 'default',
|
|
|
- pb_function: 'function',
|
|
|
- pb_var: 'var'
|
|
|
- }, result);
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ normal: 'normal',
|
|
|
+ pb_default: 'default',
|
|
|
+ pb_function: 'function',
|
|
|
+ pb_var: 'var'
|
|
|
+ },
|
|
|
+ result);
|
|
|
});
|
|
|
|
|
|
it('testDefaultValues', function() {
|
|
|
- var defaultString = "default<>\'\"abc";
|
|
|
+ var defaultString = 'default<>\'"abc';
|
|
|
var response = new proto.jspb.test.DefaultValues();
|
|
|
|
|
|
// Test toObject
|
|
@@ -244,8 +244,10 @@ describe('Message test suite', function() {
|
|
|
|
|
|
// Test that clearing the values reverts them to the default state.
|
|
|
response = makeDefault(['blah', false, 111, 77]);
|
|
|
- response.clearStringField(); response.clearBoolField();
|
|
|
- response.clearIntField(); response.clearEnumField();
|
|
|
+ response.clearStringField();
|
|
|
+ response.clearBoolField();
|
|
|
+ response.clearIntField();
|
|
|
+ response.clearEnumField();
|
|
|
assertEquals(defaultString, response.getStringField());
|
|
|
assertEquals(true, response.getBoolField());
|
|
|
assertEquals(11, response.getIntField());
|
|
@@ -257,8 +259,10 @@ describe('Message test suite', function() {
|
|
|
|
|
|
// Test that setFoo(null) clears the values.
|
|
|
response = makeDefault(['blah', false, 111, 77]);
|
|
|
- response.setStringField(null); response.setBoolField(null);
|
|
|
- response.setIntField(undefined); response.setEnumField(undefined);
|
|
|
+ response.setStringField(null);
|
|
|
+ response.setBoolField(null);
|
|
|
+ response.setIntField(undefined);
|
|
|
+ response.setEnumField(undefined);
|
|
|
assertEquals(defaultString, response.getStringField());
|
|
|
assertEquals(true, response.getBoolField());
|
|
|
assertEquals(11, response.getIntField());
|
|
@@ -288,15 +292,15 @@ describe('Message test suite', function() {
|
|
|
// but we actually get a sparse array instead. We could use something
|
|
|
// like [1,undefined,2] to avoid this, except that this is still
|
|
|
// sparse on IE. No comment...
|
|
|
- var expected = [,,, [], []];
|
|
|
+ var expected = [, , , [], []];
|
|
|
expected[0] = expected[1] = expected[2] = undefined;
|
|
|
assertObjectEquals(expected, foo.toArray());
|
|
|
});
|
|
|
|
|
|
it('testDifferenceRawObject', /** @suppress {visibility} */ function() {
|
|
|
var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]);
|
|
|
- var p2 = new proto.jspb.test.HasExtensions(['hi', 'what',
|
|
|
- {1000: 'unique'}]);
|
|
|
+ var p2 =
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', 'what', {1000: 'unique'}]);
|
|
|
var diff = /** @type {proto.jspb.test.HasExtensions} */
|
|
|
(jspb.Message.difference(p1, p2));
|
|
|
assertEquals('', diff.getStr1());
|
|
@@ -310,13 +314,13 @@ describe('Message test suite', function() {
|
|
|
assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi'])));
|
|
|
assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye'])));
|
|
|
var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]);
|
|
|
- assertTrue(jspb.Message.equals(s1b,
|
|
|
- new proto.jspb.test.Simple1(['hi', ['hello']])));
|
|
|
- assertTrue(jspb.Message.equals(s1b,
|
|
|
- new proto.jspb.test.Simple1(['hi', ['hello', undefined,
|
|
|
- undefined, undefined]])));
|
|
|
- assertFalse(jspb.Message.equals(s1b,
|
|
|
- new proto.jspb.test.Simple1(['no', ['hello']])));
|
|
|
+ assertTrue(jspb.Message.equals(
|
|
|
+ s1b, new proto.jspb.test.Simple1(['hi', ['hello']])));
|
|
|
+ assertTrue(jspb.Message.equals(s1b, new proto.jspb.test.Simple1([
|
|
|
+ 'hi', ['hello', undefined, undefined, undefined]
|
|
|
+ ])));
|
|
|
+ assertFalse(jspb.Message.equals(
|
|
|
+ s1b, new proto.jspb.test.Simple1(['no', ['hello']])));
|
|
|
// Test with messages of different types
|
|
|
var s2 = new proto.jspb.test.Simple2(['hi']);
|
|
|
assertFalse(jspb.Message.equals(s1, s2));
|
|
@@ -324,18 +328,18 @@ describe('Message test suite', function() {
|
|
|
|
|
|
it('testEquals_softComparison', function() {
|
|
|
var s1 = new proto.jspb.test.Simple1(['hi', [], null]);
|
|
|
- assertTrue(jspb.Message.equals(s1,
|
|
|
- new proto.jspb.test.Simple1(['hi', []])));
|
|
|
+ assertTrue(
|
|
|
+ jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi', []])));
|
|
|
|
|
|
var s1b = new proto.jspb.test.Simple1(['hi', [], true]);
|
|
|
- assertTrue(jspb.Message.equals(s1b,
|
|
|
- new proto.jspb.test.Simple1(['hi', [], 1])));
|
|
|
+ assertTrue(
|
|
|
+ jspb.Message.equals(s1b, new proto.jspb.test.Simple1(['hi', [], 1])));
|
|
|
});
|
|
|
|
|
|
it('testEqualsComplex', function() {
|
|
|
- var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
|
|
|
- var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1];
|
|
|
- var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1];
|
|
|
+ var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1];
|
|
|
+ var data2 = ['a', , , [, 11], [[, 22], [, 34]], , ['s1', 's2'], , 1];
|
|
|
+ var data3 = ['a', , , [, 11], [[, 22]], , ['s1', 's2'], , 1];
|
|
|
var data4 = ['hi'];
|
|
|
var c1a = new proto.jspb.test.Complex(data1);
|
|
|
var c1b = new proto.jspb.test.Complex(data1);
|
|
@@ -352,42 +356,34 @@ describe('Message test suite', function() {
|
|
|
it('testEqualsExtensionsConstructed', function() {
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions([]),
|
|
|
- new proto.jspb.test.HasExtensions([{}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions([{}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])));
|
|
|
assertFalse(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
- new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]),
|
|
|
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}])));
|
|
|
assertTrue(jspb.Message.equals(
|
|
|
- new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]),
|
|
|
- new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
|
|
|
- ));
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]),
|
|
|
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])));
|
|
|
});
|
|
|
|
|
|
it('testEqualsExtensionsUnconstructed', function() {
|
|
|
assertTrue(jspb.Message.compareFields([], [{}]));
|
|
|
- assertTrue(jspb.Message.compareFields([,,, {}], []));
|
|
|
- assertTrue(jspb.Message.compareFields([,,, {}], [,, {}]));
|
|
|
+ assertTrue(jspb.Message.compareFields([, , , {}], []));
|
|
|
+ assertTrue(jspb.Message.compareFields([, , , {}], [, , {}]));
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
|
|
assertFalse(jspb.Message.compareFields(
|
|
@@ -395,25 +391,25 @@ describe('Message test suite', function() {
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
[{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
- [{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}]));
|
|
|
+ [{100: [{200: 'a'}]}], [, , , {100: [{200: 'a'}]}]));
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
- [,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
|
|
+ [, , , {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
- ['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}]));
|
|
|
+ ['hi', {100: [{200: 'a'}]}], ['hi', , , {100: [{200: 'a'}]}]));
|
|
|
assertTrue(jspb.Message.compareFields(
|
|
|
- ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
|
|
+ ['hi', , , {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
|
|
});
|
|
|
|
|
|
it('testToMap', function() {
|
|
|
var p1 = new proto.jspb.test.Simple1(['k', ['v']]);
|
|
|
var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]);
|
|
|
- var soymap = jspb.Message.toMap([p1, p2],
|
|
|
- proto.jspb.test.Simple1.prototype.getAString,
|
|
|
+ var soymap = jspb.Message.toMap(
|
|
|
+ [p1, p2], proto.jspb.test.Simple1.prototype.getAString,
|
|
|
proto.jspb.test.Simple1.prototype.toObject);
|
|
|
assertEquals('k', soymap['k'].aString);
|
|
|
assertArrayEquals(['v'], soymap['k'].aRepeatedStringList);
|
|
|
- var protomap = jspb.Message.toMap([p1, p2],
|
|
|
- proto.jspb.test.Simple1.prototype.getAString);
|
|
|
+ var protomap = jspb.Message.toMap(
|
|
|
+ [p1, p2], proto.jspb.test.Simple1.prototype.getAString);
|
|
|
assertEquals('k', protomap['k'].getAString());
|
|
|
assertArrayEquals(['v'], protomap['k'].getARepeatedStringList());
|
|
|
});
|
|
@@ -434,8 +430,12 @@ describe('Message test suite', function() {
|
|
|
extension.setExt('e1');
|
|
|
original.setExtension(proto.jspb.test.IsExtension.extField, extension);
|
|
|
var clone = original.clone();
|
|
|
- assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
|
|
|
- [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
|
|
|
+ assertArrayEquals(
|
|
|
+ [
|
|
|
+ 'v1', , ['x1', ['y1', 'z1']], ,
|
|
|
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, ,
|
|
|
+ {100: [, 'e1']}
|
|
|
+ ],
|
|
|
clone.toArray());
|
|
|
clone.setStr('v2');
|
|
|
var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]);
|
|
@@ -452,11 +452,19 @@ describe('Message test suite', function() {
|
|
|
var newExtension = new proto.jspb.test.CloneExtension();
|
|
|
newExtension.setExt('e2');
|
|
|
clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension);
|
|
|
- assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],,
|
|
|
- [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }],
|
|
|
+ assertArrayEquals(
|
|
|
+ [
|
|
|
+ 'v2', , ['a1', ['b1', 'c1']], ,
|
|
|
+ [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2, ,
|
|
|
+ {100: [, 'e2']}
|
|
|
+ ],
|
|
|
clone.toArray());
|
|
|
- assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
|
|
|
- [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
|
|
|
+ assertArrayEquals(
|
|
|
+ [
|
|
|
+ 'v1', , ['x1', ['y1', 'z1']], ,
|
|
|
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, ,
|
|
|
+ {100: [, 'e1']}
|
|
|
+ ],
|
|
|
original.toArray());
|
|
|
});
|
|
|
|
|
@@ -488,11 +496,12 @@ describe('Message test suite', function() {
|
|
|
jspb.Message.copyInto(original, dest);
|
|
|
assertArrayEquals(original.toArray(), dest.toArray());
|
|
|
assertEquals('x1', dest.getSimple1().getAString());
|
|
|
- assertEquals('e1',
|
|
|
+ assertEquals(
|
|
|
+ 'e1',
|
|
|
dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt());
|
|
|
dest.getSimple1().setAString('new value');
|
|
|
- assertNotEquals(dest.getSimple1().getAString(),
|
|
|
- original.getSimple1().getAString());
|
|
|
+ assertNotEquals(
|
|
|
+ dest.getSimple1().getAString(), original.getSimple1().getAString());
|
|
|
if (supportsUint8Array) {
|
|
|
dest.getBytesField()[0] = 7;
|
|
|
assertObjectEquals(bytes1, original.getBytesField());
|
|
@@ -502,12 +511,12 @@ describe('Message test suite', function() {
|
|
|
assertObjectEquals(bytes1, original.getBytesField());
|
|
|
assertObjectEquals('789', dest.getBytesField());
|
|
|
}
|
|
|
- dest.getExtension(proto.jspb.test.CloneExtension.extField).
|
|
|
- setExt('new value');
|
|
|
+ dest.getExtension(proto.jspb.test.CloneExtension.extField)
|
|
|
+ .setExt('new value');
|
|
|
assertNotEquals(
|
|
|
dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(),
|
|
|
- original.getExtension(
|
|
|
- proto.jspb.test.CloneExtension.extField).getExt());
|
|
|
+ original.getExtension(proto.jspb.test.CloneExtension.extField)
|
|
|
+ .getExt());
|
|
|
});
|
|
|
|
|
|
it('testCopyInto_notSameType', function() {
|
|
@@ -525,26 +534,32 @@ describe('Message test suite', function() {
|
|
|
var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
|
|
|
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
|
|
extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
|
|
|
- extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
|
|
|
- extension2);
|
|
|
+ extendable.setExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.simple, extension2);
|
|
|
extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
|
|
|
- extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
|
|
|
- ['a', 'b']);
|
|
|
+ extendable.setExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']);
|
|
|
var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
|
|
|
var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]);
|
|
|
extendable.setExtension(
|
|
|
- proto.jspb.test.IndirectExtension.repeatedSimpleList,
|
|
|
- [s1, s2]);
|
|
|
- assertObjectEquals(extension1,
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]);
|
|
|
+ assertObjectEquals(
|
|
|
+ extension1,
|
|
|
extendable.getExtension(proto.jspb.test.IsExtension.extField));
|
|
|
- assertObjectEquals(extension2,
|
|
|
+ assertObjectEquals(
|
|
|
+ extension2,
|
|
|
extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
|
|
|
- assertObjectEquals('xyzzy',
|
|
|
+ assertObjectEquals(
|
|
|
+ 'xyzzy',
|
|
|
extendable.getExtension(proto.jspb.test.IndirectExtension.str));
|
|
|
- assertObjectEquals(['a', 'b'], extendable.getExtension(
|
|
|
- proto.jspb.test.IndirectExtension.repeatedStrList));
|
|
|
- assertObjectEquals([s1, s2], extendable.getExtension(
|
|
|
- proto.jspb.test.IndirectExtension.repeatedSimpleList));
|
|
|
+ assertObjectEquals(
|
|
|
+ ['a', 'b'],
|
|
|
+ extendable.getExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedStrList));
|
|
|
+ assertObjectEquals(
|
|
|
+ [s1, s2],
|
|
|
+ extendable.getExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedSimpleList));
|
|
|
// Not supported yet, but it should work...
|
|
|
extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null);
|
|
|
assertNull(
|
|
@@ -563,18 +578,18 @@ describe('Message test suite', function() {
|
|
|
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
|
|
var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
|
|
|
extendable.setExtension(proto.jspb.test.simple1, extension);
|
|
|
- assertObjectEquals(extension,
|
|
|
- extendable.getExtension(proto.jspb.test.simple1));
|
|
|
+ assertObjectEquals(
|
|
|
+ extension, extendable.getExtension(proto.jspb.test.simple1));
|
|
|
|
|
|
// From _lib mode.
|
|
|
extension = new proto.jspb.test.ExtensionMessage(['s1']);
|
|
|
extendable = new proto.jspb.test.TestExtensionsMessage([16]);
|
|
|
extendable.setExtension(proto.jspb.test.floatingMsgField, extension);
|
|
|
extendable.setExtension(proto.jspb.test.floatingStrField, 's2');
|
|
|
- assertObjectEquals(extension,
|
|
|
- extendable.getExtension(proto.jspb.test.floatingMsgField));
|
|
|
- assertObjectEquals('s2',
|
|
|
- extendable.getExtension(proto.jspb.test.floatingStrField));
|
|
|
+ assertObjectEquals(
|
|
|
+ extension, extendable.getExtension(proto.jspb.test.floatingMsgField));
|
|
|
+ assertObjectEquals(
|
|
|
+ 's2', extendable.getExtension(proto.jspb.test.floatingStrField));
|
|
|
assertNotUndefined(proto.jspb.exttest.floatingMsgField);
|
|
|
assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo);
|
|
|
assertNotUndefined(proto.jspb.exttest.beta.floatingStrField);
|
|
@@ -585,60 +600,72 @@ describe('Message test suite', function() {
|
|
|
var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]);
|
|
|
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
|
|
extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
|
|
|
- extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
|
|
|
- extension2);
|
|
|
+ extendable.setExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.simple, extension2);
|
|
|
extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
|
|
|
- extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
|
|
|
- ['a', 'b']);
|
|
|
+ extendable.setExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']);
|
|
|
var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]);
|
|
|
var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]);
|
|
|
extendable.setExtension(
|
|
|
- proto.jspb.test.IndirectExtension.repeatedSimpleList,
|
|
|
- [s1, s2]);
|
|
|
- assertObjectEquals({
|
|
|
- str1: 'v1', str2: 'v2', str3: 'v3',
|
|
|
- extField: { ext1: 'ext1field' },
|
|
|
- simple: {
|
|
|
- aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true
|
|
|
- },
|
|
|
- str: 'xyzzy',
|
|
|
- repeatedStrList: ['a', 'b'],
|
|
|
- repeatedSimpleList: [
|
|
|
- { aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
|
|
|
- { aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
|
|
|
- ]
|
|
|
- }, extendable.toObject());
|
|
|
+ proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]);
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ str1: 'v1',
|
|
|
+ str2: 'v2',
|
|
|
+ str3: 'v3',
|
|
|
+ extField: {ext1: 'ext1field'},
|
|
|
+ simple: {
|
|
|
+ aString: 'str',
|
|
|
+ aRepeatedStringList: ['s1', 's2'],
|
|
|
+ aBoolean: true
|
|
|
+ },
|
|
|
+ str: 'xyzzy',
|
|
|
+ repeatedStrList: ['a', 'b'],
|
|
|
+ repeatedSimpleList: [
|
|
|
+ {aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
|
|
|
+ {aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ extendable.toObject());
|
|
|
|
|
|
// Now, with instances included.
|
|
|
- assertObjectEquals({
|
|
|
- str1: 'v1', str2: 'v2', str3: 'v3',
|
|
|
- extField: {
|
|
|
- ext1: 'ext1field',
|
|
|
- $jspbMessageInstance:
|
|
|
- extendable.getExtension(proto.jspb.test.IsExtension.extField)
|
|
|
- },
|
|
|
- simple: {
|
|
|
- aString: 'str',
|
|
|
- aRepeatedStringList: ['s1', 's2'],
|
|
|
- aBoolean: true,
|
|
|
- $jspbMessageInstance:
|
|
|
- extendable.getExtension(proto.jspb.test.IndirectExtension.simple)
|
|
|
- },
|
|
|
- str: 'xyzzy',
|
|
|
- repeatedStrList: ['a', 'b'],
|
|
|
- repeatedSimpleList: [{
|
|
|
- aString: 'foo',
|
|
|
- aRepeatedStringList: ['s1', 's2'],
|
|
|
- aBoolean: true,
|
|
|
- $jspbMessageInstance: s1
|
|
|
- }, {
|
|
|
- aString: 'bar',
|
|
|
- aRepeatedStringList: ['t1', 't2'],
|
|
|
- aBoolean: false,
|
|
|
- $jspbMessageInstance: s2
|
|
|
- }],
|
|
|
- $jspbMessageInstance: extendable
|
|
|
- }, extendable.toObject(true /* opt_includeInstance */));
|
|
|
+ assertObjectEquals(
|
|
|
+ {
|
|
|
+ str1: 'v1',
|
|
|
+ str2: 'v2',
|
|
|
+ str3: 'v3',
|
|
|
+ extField: {
|
|
|
+ ext1: 'ext1field',
|
|
|
+ $jspbMessageInstance:
|
|
|
+ extendable.getExtension(proto.jspb.test.IsExtension.extField)
|
|
|
+ },
|
|
|
+ simple: {
|
|
|
+ aString: 'str',
|
|
|
+ aRepeatedStringList: ['s1', 's2'],
|
|
|
+ aBoolean: true,
|
|
|
+ $jspbMessageInstance: extendable.getExtension(
|
|
|
+ proto.jspb.test.IndirectExtension.simple)
|
|
|
+ },
|
|
|
+ str: 'xyzzy',
|
|
|
+ repeatedStrList: ['a', 'b'],
|
|
|
+ repeatedSimpleList: [
|
|
|
+ {
|
|
|
+ aString: 'foo',
|
|
|
+ aRepeatedStringList: ['s1', 's2'],
|
|
|
+ aBoolean: true,
|
|
|
+ $jspbMessageInstance: s1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ aString: 'bar',
|
|
|
+ aRepeatedStringList: ['t1', 't2'],
|
|
|
+ aBoolean: false,
|
|
|
+ $jspbMessageInstance: s2
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ $jspbMessageInstance: extendable
|
|
|
+ },
|
|
|
+ extendable.toObject(true /* opt_includeInstance */));
|
|
|
});
|
|
|
|
|
|
it('testInitialization_emptyArray', function() {
|
|
@@ -690,8 +717,7 @@ describe('Message test suite', function() {
|
|
|
var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']);
|
|
|
data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage);
|
|
|
var obj = data.toObject();
|
|
|
- assertNotNull(
|
|
|
- data.getExtension(proto.jspb.test.IsExtension.extField));
|
|
|
+ assertNotNull(data.getExtension(proto.jspb.test.IsExtension.extField));
|
|
|
assertEquals('is_extension', obj.extField.ext1);
|
|
|
});
|
|
|
|
|
@@ -708,16 +734,18 @@ describe('Message test suite', function() {
|
|
|
var groups = group.getRepeatedGroupList();
|
|
|
assertEquals('g1', groups[0].getId());
|
|
|
assertObjectEquals([true, false], groups[0].getSomeBoolList());
|
|
|
- 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
|
|
|
- }, group.toObject());
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ group.toObject());
|
|
|
var group1 = new proto.jspb.test.TestGroup1();
|
|
|
group1.setGroup(someGroup);
|
|
|
assertEquals(someGroup, group1.getGroup());
|
|
@@ -734,25 +762,26 @@ describe('Message test suite', function() {
|
|
|
message.setExtension$(11);
|
|
|
message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12);
|
|
|
assertEquals(11, message.getExtension$());
|
|
|
- assertEquals(12, message.getExtension(
|
|
|
- proto.jspb.test.TestReservedNamesExtension.foo));
|
|
|
+ assertEquals(
|
|
|
+ 12,
|
|
|
+ message.getExtension(proto.jspb.test.TestReservedNamesExtension.foo));
|
|
|
assertObjectEquals({extension: 11, foo: 12}, message.toObject());
|
|
|
});
|
|
|
|
|
|
it('testInitializeMessageWithUnsetOneof', function() {
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof([]);
|
|
|
assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
|
|
- PARTIAL_ONEOF_NOT_SET,
|
|
|
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
|
|
+ .PARTIAL_ONEOF_NOT_SET,
|
|
|
message.getPartialOneofCase());
|
|
|
assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
|
|
|
- RECURSIVE_ONEOF_NOT_SET,
|
|
|
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase
|
|
|
+ .RECURSIVE_ONEOF_NOT_SET,
|
|
|
message.getRecursiveOneofCase());
|
|
|
});
|
|
|
|
|
|
it('testInitializeMessageWithSingleValueSetInOneof', function() {
|
|
|
- var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']);
|
|
|
+ var message = new proto.jspb.test.TestMessageWithOneof([, , 'x']);
|
|
|
|
|
|
assertEquals('x', message.getPone());
|
|
|
assertEquals('', message.getPthree());
|
|
@@ -762,7 +791,7 @@ describe('Message test suite', function() {
|
|
|
});
|
|
|
|
|
|
it('testKeepsLastWireValueSetInUnion_multipleValues', function() {
|
|
|
- var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']);
|
|
|
+ var message = new proto.jspb.test.TestMessageWithOneof([, , 'x', , 'y']);
|
|
|
|
|
|
assertEquals('', message.getPone());
|
|
|
assertEquals('y', message.getPthree());
|
|
@@ -819,8 +848,8 @@ describe('Message test suite', function() {
|
|
|
it('testUnsetsOneofCaseWhenFieldIsCleared', function() {
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof;
|
|
|
assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
|
|
- PARTIAL_ONEOF_NOT_SET,
|
|
|
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
|
|
+ .PARTIAL_ONEOF_NOT_SET,
|
|
|
message.getPartialOneofCase());
|
|
|
|
|
|
message.setPone('hi');
|
|
@@ -830,8 +859,8 @@ describe('Message test suite', function() {
|
|
|
|
|
|
message.clearPone();
|
|
|
assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
|
|
- PARTIAL_ONEOF_NOT_SET,
|
|
|
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
|
|
+ .PARTIAL_ONEOF_NOT_SET,
|
|
|
message.getPartialOneofCase());
|
|
|
});
|
|
|
|
|
@@ -934,39 +963,39 @@ describe('Message test suite', function() {
|
|
|
});
|
|
|
|
|
|
it('testInitializeMessageWithOneofDefaults_defaultNotSetOnFirstField',
|
|
|
- function() {
|
|
|
- var message;
|
|
|
-
|
|
|
- message =
|
|
|
- new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
|
|
|
- assertEquals(567, message.getBone());
|
|
|
- assertEquals(1234, message.getBtwo());
|
|
|
- assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
|
|
|
- message.getDefaultOneofBCase());
|
|
|
-
|
|
|
- message =
|
|
|
- new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
|
|
|
- assertEquals(0, message.getBone());
|
|
|
- assertEquals(890, message.getBtwo());
|
|
|
- assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
|
|
- message.getDefaultOneofBCase());
|
|
|
-
|
|
|
- message = new proto.jspb.test.TestMessageWithOneof(
|
|
|
- new Array(11).concat(567, 890));
|
|
|
- assertEquals(0, message.getBone());
|
|
|
- assertEquals(890, message.getBtwo());
|
|
|
- assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
|
|
- message.getDefaultOneofBCase());
|
|
|
- });
|
|
|
+ function() {
|
|
|
+ var message;
|
|
|
+
|
|
|
+ message =
|
|
|
+ new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
|
|
|
+ assertEquals(567, message.getBone());
|
|
|
+ assertEquals(1234, message.getBtwo());
|
|
|
+ assertEquals(
|
|
|
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
|
|
|
+ message.getDefaultOneofBCase());
|
|
|
+
|
|
|
+ message =
|
|
|
+ new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
|
|
|
+ assertEquals(0, message.getBone());
|
|
|
+ assertEquals(890, message.getBtwo());
|
|
|
+ assertEquals(
|
|
|
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
|
|
+ message.getDefaultOneofBCase());
|
|
|
+
|
|
|
+ message = new proto.jspb.test.TestMessageWithOneof(
|
|
|
+ new Array(11).concat(567, 890));
|
|
|
+ assertEquals(0, message.getBone());
|
|
|
+ assertEquals(890, message.getBtwo());
|
|
|
+ assertEquals(
|
|
|
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
|
|
+ message.getDefaultOneofBCase());
|
|
|
+ });
|
|
|
|
|
|
it('testOneofContainingAnotherMessage', function() {
|
|
|
var message = new proto.jspb.test.TestMessageWithOneof;
|
|
|
assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
|
|
|
- RECURSIVE_ONEOF_NOT_SET,
|
|
|
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase
|
|
|
+ .RECURSIVE_ONEOF_NOT_SET,
|
|
|
message.getRecursiveOneofCase());
|
|
|
|
|
|
var other = new proto.jspb.test.TestMessageWithOneof;
|
|
@@ -987,25 +1016,25 @@ describe('Message test suite', function() {
|
|
|
|
|
|
it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray',
|
|
|
function() {
|
|
|
- var message = new proto.jspb.test.TestMessageWithOneof;
|
|
|
- message.setPone('x');
|
|
|
- assertEquals('x', message.getPone());
|
|
|
- assertEquals('', message.getPthree());
|
|
|
- assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
|
|
|
- message.getPartialOneofCase());
|
|
|
-
|
|
|
- var array = message.toArray();
|
|
|
- assertEquals('x', array[2]);
|
|
|
- assertUndefined(array[4]);
|
|
|
- array[4] = 'y';
|
|
|
-
|
|
|
- assertEquals(
|
|
|
- proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
|
|
|
- message.getPartialOneofCase());
|
|
|
- assertUndefined(array[2]);
|
|
|
- assertEquals('y', array[4]);
|
|
|
- });
|
|
|
+ var message = new proto.jspb.test.TestMessageWithOneof;
|
|
|
+ message.setPone('x');
|
|
|
+ assertEquals('x', message.getPone());
|
|
|
+ assertEquals('', message.getPthree());
|
|
|
+ assertEquals(
|
|
|
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
|
|
|
+ message.getPartialOneofCase());
|
|
|
+
|
|
|
+ var array = message.toArray();
|
|
|
+ assertEquals('x', array[2]);
|
|
|
+ assertUndefined(array[4]);
|
|
|
+ array[4] = 'y';
|
|
|
+
|
|
|
+ assertEquals(
|
|
|
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
|
|
|
+ message.getPartialOneofCase());
|
|
|
+ assertUndefined(array[2]);
|
|
|
+ assertEquals('y', array[4]);
|
|
|
+ });
|
|
|
|
|
|
it('testFloatingPointFieldsSupportNan', function() {
|
|
|
var assertNan = function(x) {
|
|
@@ -1015,8 +1044,7 @@ describe('Message test suite', function() {
|
|
|
};
|
|
|
|
|
|
var message = new proto.jspb.test.FloatingPointFields([
|
|
|
- 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN',
|
|
|
- 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN'
|
|
|
+ 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN'
|
|
|
]);
|
|
|
assertNan(message.getOptionalFloatField());
|
|
|
assertNan(message.getRequiredFloatField());
|
|
@@ -1029,5 +1057,4 @@ describe('Message test suite', function() {
|
|
|
assertNan(message.getRepeatedDoubleFieldList()[1]);
|
|
|
assertNan(message.getDefaultDoubleField());
|
|
|
});
|
|
|
-
|
|
|
});
|