message_test.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Test suite is written using Jasmine -- see http://jasmine.github.io/
  31. goog.setTestOnly();
  32. goog.require('goog.json');
  33. goog.require('goog.testing.asserts');
  34. // CommonJS-LoadFromFile: google-protobuf
  35. goog.require('jspb.Message');
  36. // CommonJS-LoadFromFile: test5_pb
  37. goog.require('proto.jspb.exttest.beta.floatingStrField');
  38. // CommonJS-LoadFromFile: test3_pb
  39. goog.require('proto.jspb.exttest.floatingMsgField');
  40. // CommonJS-LoadFromFile: test4_pb
  41. goog.require('proto.jspb.exttest.floatingMsgFieldTwo');
  42. // CommonJS-LoadFromFile: test_pb
  43. goog.require('proto.jspb.test.CloneExtension');
  44. goog.require('proto.jspb.test.Complex');
  45. goog.require('proto.jspb.test.DefaultValues');
  46. goog.require('proto.jspb.test.Empty');
  47. goog.require('proto.jspb.test.EnumContainer');
  48. goog.require('proto.jspb.test.floatingStrField');
  49. goog.require('proto.jspb.test.HasExtensions');
  50. goog.require('proto.jspb.test.IndirectExtension');
  51. goog.require('proto.jspb.test.IsExtension');
  52. goog.require('proto.jspb.test.OptionalFields');
  53. goog.require('proto.jspb.test.OuterEnum');
  54. goog.require('proto.jspb.test.simple1');
  55. goog.require('proto.jspb.test.Simple1');
  56. goog.require('proto.jspb.test.Simple2');
  57. goog.require('proto.jspb.test.SpecialCases');
  58. goog.require('proto.jspb.test.TestClone');
  59. goog.require('proto.jspb.test.TestGroup');
  60. goog.require('proto.jspb.test.TestGroup1');
  61. goog.require('proto.jspb.test.TestMessageWithOneof');
  62. goog.require('proto.jspb.test.TestReservedNames');
  63. goog.require('proto.jspb.test.TestReservedNamesExtension');
  64. // CommonJS-LoadFromFile: test2_pb
  65. goog.require('proto.jspb.test.ExtensionMessage');
  66. goog.require('proto.jspb.test.TestExtensionsMessage');
  67. goog.require('proto.jspb.test.floatingMsgField');
  68. describe('Message test suite', function() {
  69. it('testEmptyProto', function() {
  70. var empty1 = new proto.jspb.test.Empty([]);
  71. var empty2 = new proto.jspb.test.Empty([]);
  72. assertObjectEquals({}, empty1.toObject());
  73. assertObjectEquals('Message should not be corrupted:', empty2, empty1);
  74. });
  75. it('testTopLevelEnum', function() {
  76. var response = new proto.jspb.test.EnumContainer([]);
  77. response.setOuterEnum(proto.jspb.test.OuterEnum.FOO);
  78. assertEquals(proto.jspb.test.OuterEnum.FOO, response.getOuterEnum());
  79. });
  80. it('testByteStrings', function() {
  81. var data = new proto.jspb.test.DefaultValues([]);
  82. data.setBytesField('some_bytes');
  83. assertEquals('some_bytes', data.getBytesField());
  84. });
  85. it('testComplexConversion', function() {
  86. var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
  87. var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
  88. var foo = new proto.jspb.test.Complex(data1);
  89. var bar = new proto.jspb.test.Complex(data2);
  90. var result = foo.toObject();
  91. assertObjectEquals({
  92. aString: 'a',
  93. anOutOfOrderBool: 1,
  94. aNestedMessage: {
  95. anInt: 11
  96. },
  97. aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
  98. aRepeatedStringList: ['s1', 's2']
  99. }, result);
  100. // Now test with the jspb instances included.
  101. result = foo.toObject(true /* opt_includeInstance */);
  102. assertObjectEquals({
  103. aString: 'a',
  104. anOutOfOrderBool: 1,
  105. aNestedMessage: {
  106. anInt: 11,
  107. $jspbMessageInstance: foo.getANestedMessage()
  108. },
  109. aRepeatedMessageList: [
  110. {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
  111. {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
  112. ],
  113. aRepeatedStringList: ['s1', 's2'],
  114. $jspbMessageInstance: foo
  115. }, result);
  116. });
  117. it('testMissingFields', function() {
  118. var foo = new proto.jspb.test.Complex([
  119. undefined, undefined, undefined, [],
  120. undefined, undefined, undefined, undefined]);
  121. var bar = new proto.jspb.test.Complex([
  122. undefined, undefined, undefined, [],
  123. undefined, undefined, undefined, undefined]);
  124. var result = foo.toObject();
  125. assertObjectEquals({
  126. aString: undefined,
  127. anOutOfOrderBool: undefined,
  128. aNestedMessage: {
  129. anInt: undefined
  130. },
  131. // Note: JsPb converts undefined repeated fields to empty arrays.
  132. aRepeatedMessageList: [],
  133. aRepeatedStringList: []
  134. }, result);
  135. });
  136. it('testSpecialCases', function() {
  137. // Note: Some property names are reserved in JavaScript.
  138. // These names are converted to the Js property named pb_<reserved_name>.
  139. var special =
  140. new proto.jspb.test.SpecialCases(['normal', 'default', 'function',
  141. 'var']);
  142. var result = special.toObject();
  143. assertObjectEquals({
  144. normal: 'normal',
  145. pb_default: 'default',
  146. pb_function: 'function',
  147. pb_var: 'var'
  148. }, result);
  149. });
  150. it('testDefaultValues', function() {
  151. var defaultString = "default<>\'\"abc";
  152. var response = new proto.jspb.test.DefaultValues();
  153. // Test toObject
  154. var expectedObject = {
  155. stringField: defaultString,
  156. boolField: true,
  157. intField: 11,
  158. enumField: 13,
  159. emptyField: '',
  160. bytesField: 'bW9v'
  161. };
  162. assertObjectEquals(expectedObject, response.toObject());
  163. // Test getters
  164. response = new proto.jspb.test.DefaultValues();
  165. assertEquals(defaultString, response.getStringField());
  166. assertEquals(true, response.getBoolField());
  167. assertEquals(11, response.getIntField());
  168. assertEquals(13, response.getEnumField());
  169. assertEquals('', response.getEmptyField());
  170. assertEquals('bW9v', response.getBytesField());
  171. function makeDefault(values) {
  172. return new proto.jspb.test.DefaultValues(values);
  173. }
  174. // Test with undefined values,
  175. // Use push to workaround IE treating undefined array elements as holes.
  176. response = makeDefault([undefined, undefined, undefined, undefined]);
  177. assertEquals(defaultString, response.getStringField());
  178. assertEquals(true, response.getBoolField());
  179. assertEquals(11, response.getIntField());
  180. assertEquals(13, response.getEnumField());
  181. // Test with null values, as would be returned by a JSON serializer.
  182. response = makeDefault([null, null, null, null]);
  183. assertEquals(defaultString, response.getStringField());
  184. assertEquals(true, response.getBoolField());
  185. assertEquals(11, response.getIntField());
  186. assertEquals(13, response.getEnumField());
  187. // Test with false-like values.
  188. response = makeDefault(['', false, 0, 0]);
  189. assertEquals('', response.getStringField());
  190. assertEquals(false, response.getBoolField());
  191. assertEquals(true, response.getIntField() == 0);
  192. assertEquals(true, response.getEnumField() == 0);
  193. // Test that clearing the values reverts them to the default state.
  194. response = makeDefault(['blah', false, 111, 77]);
  195. response.clearStringField(); response.clearBoolField();
  196. response.clearIntField(); response.clearEnumField();
  197. assertEquals(defaultString, response.getStringField());
  198. assertEquals(true, response.getBoolField());
  199. assertEquals(11, response.getIntField());
  200. assertEquals(13, response.getEnumField());
  201. // Test that setFoo(null) clears the values.
  202. response = makeDefault(['blah', false, 111, 77]);
  203. response.setStringField(null); response.setBoolField(null);
  204. response.setIntField(undefined); response.setEnumField(undefined);
  205. assertEquals(defaultString, response.getStringField());
  206. assertEquals(true, response.getBoolField());
  207. assertEquals(11, response.getIntField());
  208. assertEquals(13, response.getEnumField());
  209. });
  210. it('testMessageRegistration', function() {
  211. // goog.require(SomeResponse) will include its library, which will in
  212. // turn add SomeResponse to the message registry.
  213. assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse);
  214. });
  215. it('testClearFields', function() {
  216. // We don't set 'proper' defaults, rather, bools, strings,
  217. // etc, are cleared to undefined or null and take on the Javascript
  218. // meaning for that value. Repeated fields are set to [] when cleared.
  219. var data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
  220. var foo = new proto.jspb.test.OptionalFields(data);
  221. foo.clearAString();
  222. foo.clearABool();
  223. foo.clearANestedMessage();
  224. foo.clearARepeatedMessageList();
  225. foo.clearARepeatedStringList();
  226. assertUndefined(foo.getAString());
  227. assertUndefined(foo.getABool());
  228. assertUndefined(foo.getANestedMessage());
  229. assertObjectEquals([], foo.getARepeatedMessageList());
  230. assertObjectEquals([], foo.getARepeatedStringList());
  231. // NOTE: We want the missing fields in 'expected' to be undefined,
  232. // but we actually get a sparse array instead. We could use something
  233. // like [1,undefined,2] to avoid this, except that this is still
  234. // sparse on IE. No comment...
  235. var expected = [,,, [], []];
  236. expected[0] = expected[1] = expected[2] = undefined;
  237. assertObjectEquals(expected, foo.toArray());
  238. // Test set(null). We could deprecated this in favor of clear(), but
  239. // it's also convenient to have.
  240. data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
  241. foo = new proto.jspb.test.OptionalFields(data);
  242. foo.setAString(null);
  243. foo.setABool(null);
  244. foo.setANestedMessage(null);
  245. foo.setARepeatedMessageList(null);
  246. foo.setARepeatedStringList(null);
  247. assertNull(foo.getAString());
  248. assertNull(foo.getABool());
  249. assertNull(foo.getANestedMessage());
  250. assertObjectEquals([], foo.getARepeatedMessageList());
  251. assertObjectEquals([], foo.getARepeatedStringList());
  252. assertObjectEquals([null, null, null, [], []], foo.toArray());
  253. // Test set(undefined). Again, not something we really need, and not
  254. // supported directly by our typing, but it should 'do the right thing'.
  255. data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
  256. foo = new proto.jspb.test.OptionalFields(data);
  257. foo.setAString(undefined);
  258. foo.setABool(undefined);
  259. foo.setANestedMessage(undefined);
  260. foo.setARepeatedMessageList(undefined);
  261. foo.setARepeatedStringList(undefined);
  262. assertUndefined(foo.getAString());
  263. assertUndefined(foo.getABool());
  264. assertUndefined(foo.getANestedMessage());
  265. assertObjectEquals([], foo.getARepeatedMessageList());
  266. assertObjectEquals([], foo.getARepeatedStringList());
  267. expected = [,,, [], []];
  268. expected[0] = expected[1] = expected[2] = undefined;
  269. assertObjectEquals(expected, foo.toArray());
  270. });
  271. it('testDifferenceRawObject', function() {
  272. var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]);
  273. var p2 = new proto.jspb.test.HasExtensions(['hi', 'what',
  274. {1000: 'unique'}]);
  275. var diff = /** @type {proto.jspb.test.HasExtensions} */
  276. (jspb.Message.difference(p1, p2));
  277. assertUndefined(diff.getStr1());
  278. assertEquals('what', diff.getStr2());
  279. assertUndefined(diff.getStr3());
  280. assertEquals('unique', diff.extensionObject_[1000]);
  281. });
  282. it('testEqualsSimple', function() {
  283. var s1 = new proto.jspb.test.Simple1(['hi']);
  284. assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi'])));
  285. assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye'])));
  286. var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]);
  287. assertTrue(jspb.Message.equals(s1b,
  288. new proto.jspb.test.Simple1(['hi', ['hello']])));
  289. assertTrue(jspb.Message.equals(s1b,
  290. new proto.jspb.test.Simple1(['hi', ['hello', undefined,
  291. undefined, undefined]])));
  292. assertFalse(jspb.Message.equals(s1b,
  293. new proto.jspb.test.Simple1(['no', ['hello']])));
  294. // Test with messages of different types
  295. var s2 = new proto.jspb.test.Simple2(['hi']);
  296. assertFalse(jspb.Message.equals(s1, s2));
  297. });
  298. it('testEquals_softComparison', function() {
  299. var s1 = new proto.jspb.test.Simple1(['hi', [], null]);
  300. assertTrue(jspb.Message.equals(s1,
  301. new proto.jspb.test.Simple1(['hi', []])));
  302. var s1b = new proto.jspb.test.Simple1(['hi', [], true]);
  303. assertTrue(jspb.Message.equals(s1b,
  304. new proto.jspb.test.Simple1(['hi', [], 1])));
  305. });
  306. it('testEqualsComplex', function() {
  307. var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
  308. var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1];
  309. var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1];
  310. var data4 = ['hi'];
  311. var c1a = new proto.jspb.test.Complex(data1);
  312. var c1b = new proto.jspb.test.Complex(data1);
  313. var c2 = new proto.jspb.test.Complex(data2);
  314. var c3 = new proto.jspb.test.Complex(data3);
  315. var s1 = new proto.jspb.test.Simple1(data4);
  316. assertTrue(jspb.Message.equals(c1a, c1b));
  317. assertFalse(jspb.Message.equals(c1a, c2));
  318. assertFalse(jspb.Message.equals(c2, c3));
  319. assertFalse(jspb.Message.equals(c1a, s1));
  320. });
  321. it('testEqualsExtensionsConstructed', function() {
  322. assertTrue(jspb.Message.equals(
  323. new proto.jspb.test.HasExtensions([]),
  324. new proto.jspb.test.HasExtensions([{}])
  325. ));
  326. assertTrue(jspb.Message.equals(
  327. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
  328. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
  329. ));
  330. assertFalse(jspb.Message.equals(
  331. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
  332. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])
  333. ));
  334. assertTrue(jspb.Message.equals(
  335. new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
  336. new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
  337. ));
  338. assertTrue(jspb.Message.equals(
  339. new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
  340. new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}])
  341. ));
  342. assertTrue(jspb.Message.equals(
  343. new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]),
  344. new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
  345. ));
  346. assertTrue(jspb.Message.equals(
  347. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
  348. new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}])
  349. ));
  350. assertTrue(jspb.Message.equals(
  351. new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]),
  352. new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
  353. ));
  354. });
  355. it('testEqualsExtensionsUnconstructed', function() {
  356. assertTrue(jspb.Message.compareFields([], [{}]));
  357. assertTrue(jspb.Message.compareFields([,,, {}], []));
  358. assertTrue(jspb.Message.compareFields([,,, {}], [,, {}]));
  359. assertTrue(jspb.Message.compareFields(
  360. ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
  361. assertFalse(jspb.Message.compareFields(
  362. ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'b'}]}]));
  363. assertTrue(jspb.Message.compareFields(
  364. [{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
  365. assertTrue(jspb.Message.compareFields(
  366. [{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}]));
  367. assertTrue(jspb.Message.compareFields(
  368. [,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
  369. assertTrue(jspb.Message.compareFields(
  370. ['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}]));
  371. assertTrue(jspb.Message.compareFields(
  372. ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
  373. });
  374. it('testToMap', function() {
  375. var p1 = new proto.jspb.test.Simple1(['k', ['v']]);
  376. var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]);
  377. var soymap = jspb.Message.toMap([p1, p2],
  378. proto.jspb.test.Simple1.prototype.getAString,
  379. proto.jspb.test.Simple1.prototype.toObject);
  380. assertEquals('k', soymap['k'].aString);
  381. assertArrayEquals(['v'], soymap['k'].aRepeatedStringList);
  382. var protomap = jspb.Message.toMap([p1, p2],
  383. proto.jspb.test.Simple1.prototype.getAString);
  384. assertEquals('k', protomap['k'].getAString());
  385. assertArrayEquals(['v'], protomap['k'].getARepeatedStringList());
  386. });
  387. it('testClone', function() {
  388. var original = new proto.jspb.test.TestClone();
  389. original.setStr('v1');
  390. var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]);
  391. var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]);
  392. var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]);
  393. original.setSimple1(simple1);
  394. original.setSimple2List([simple2, simple3]);
  395. var extension = new proto.jspb.test.CloneExtension();
  396. extension.setExt('e1');
  397. original.setExtension(proto.jspb.test.IsExtension.extField, extension);
  398. var clone = original.cloneMessage();
  399. assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
  400. [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }],
  401. clone.toArray());
  402. clone.setStr('v2');
  403. var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]);
  404. var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]);
  405. var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]);
  406. clone.setSimple1(simple4);
  407. clone.setSimple2List([simple5, simple6]);
  408. var newExtension = new proto.jspb.test.CloneExtension();
  409. newExtension.setExt('e2');
  410. clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension);
  411. assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],,
  412. [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]],,, { 100: [, 'e2'] }],
  413. clone.toArray());
  414. assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
  415. [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }],
  416. original.toArray());
  417. });
  418. it('testCopyInto', function() {
  419. var original = new proto.jspb.test.TestClone();
  420. original.setStr('v1');
  421. var dest = new proto.jspb.test.TestClone();
  422. dest.setStr('override');
  423. var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]);
  424. var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]);
  425. var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]);
  426. var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]);
  427. var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]);
  428. var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]);
  429. original.setSimple1(simple1);
  430. original.setSimple2List([simple2, simple3]);
  431. dest.setSimple1(destSimple1);
  432. dest.setSimple2List([destSimple2, destSimple3]);
  433. var extension = new proto.jspb.test.CloneExtension();
  434. extension.setExt('e1');
  435. original.setExtension(proto.jspb.test.CloneExtension.extField, extension);
  436. jspb.Message.copyInto(original, dest);
  437. assertArrayEquals(original.toArray(), dest.toArray());
  438. assertEquals('x1', dest.getSimple1().getAString());
  439. assertEquals('e1',
  440. dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt());
  441. dest.getSimple1().setAString('new value');
  442. assertNotEquals(dest.getSimple1().getAString(),
  443. original.getSimple1().getAString());
  444. dest.getExtension(proto.jspb.test.CloneExtension.extField).
  445. setExt('new value');
  446. assertNotEquals(
  447. dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(),
  448. original.getExtension(
  449. proto.jspb.test.CloneExtension.extField).getExt());
  450. });
  451. it('testCopyInto_notSameType', function() {
  452. var a = new proto.jspb.test.TestClone();
  453. var b = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
  454. var e = assertThrows(function() {
  455. jspb.Message.copyInto(a, b);
  456. });
  457. assertContains('should have the same type', e.message);
  458. });
  459. it('testExtensions', function() {
  460. var extension1 = new proto.jspb.test.IsExtension(['ext1field']);
  461. var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
  462. var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
  463. extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
  464. extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
  465. extension2);
  466. extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
  467. extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
  468. ['a', 'b']);
  469. var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
  470. var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]);
  471. extendable.setExtension(
  472. proto.jspb.test.IndirectExtension.repeatedSimpleList,
  473. [s1, s2]);
  474. assertObjectEquals(extension1,
  475. extendable.getExtension(proto.jspb.test.IsExtension.extField));
  476. assertObjectEquals(extension2,
  477. extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
  478. assertObjectEquals('xyzzy',
  479. extendable.getExtension(proto.jspb.test.IndirectExtension.str));
  480. assertObjectEquals(['a', 'b'], extendable.getExtension(
  481. proto.jspb.test.IndirectExtension.repeatedStrList));
  482. assertObjectEquals([s1, s2], extendable.getExtension(
  483. proto.jspb.test.IndirectExtension.repeatedSimpleList));
  484. // Not supported yet, but it should work...
  485. extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null);
  486. assertNull(
  487. extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
  488. extendable.setExtension(proto.jspb.test.IndirectExtension.str, null);
  489. assertNull(extendable.getExtension(proto.jspb.test.IndirectExtension.str));
  490. // These assertions will only work properly in uncompiled mode.
  491. // Extension fields defined on proto2 Descriptor messages are filtered out.
  492. // TODO(haberman): codegen changes to properly ignore descriptor.proto
  493. // extensions need to be merged from google3.
  494. // assertUndefined(proto.jspb.test.IsExtension['simpleOption']);
  495. // Extension fields with jspb.ignore = true are ignored.
  496. assertUndefined(proto.jspb.test.IndirectExtension['ignored']);
  497. assertUndefined(proto.jspb.test.HasExtensions['ignoredFloating']);
  498. });
  499. it('testFloatingExtensions', function() {
  500. // From an autogenerated container.
  501. var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
  502. var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
  503. extendable.setExtension(proto.jspb.test.simple1, extension);
  504. assertObjectEquals(extension,
  505. extendable.getExtension(proto.jspb.test.simple1));
  506. // From _lib mode.
  507. extension = new proto.jspb.test.ExtensionMessage(['s1']);
  508. extendable = new proto.jspb.test.TestExtensionsMessage([16]);
  509. extendable.setExtension(proto.jspb.test.floatingMsgField, extension);
  510. extendable.setExtension(proto.jspb.test.floatingStrField, 's2');
  511. assertObjectEquals(extension,
  512. extendable.getExtension(proto.jspb.test.floatingMsgField));
  513. assertObjectEquals('s2',
  514. extendable.getExtension(proto.jspb.test.floatingStrField));
  515. assertNotUndefined(proto.jspb.exttest.floatingMsgField);
  516. assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo);
  517. assertNotUndefined(proto.jspb.exttest.beta.floatingStrField);
  518. });
  519. it('testToObject_extendedObject', function() {
  520. var extension1 = new proto.jspb.test.IsExtension(['ext1field']);
  521. var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]);
  522. var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
  523. extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
  524. extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
  525. extension2);
  526. extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
  527. extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
  528. ['a', 'b']);
  529. var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]);
  530. var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]);
  531. extendable.setExtension(
  532. proto.jspb.test.IndirectExtension.repeatedSimpleList,
  533. [s1, s2]);
  534. assertObjectEquals({
  535. str1: 'v1', str2: 'v2', str3: 'v3',
  536. extField: { ext1: 'ext1field' },
  537. simple: {
  538. aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true
  539. },
  540. str: 'xyzzy',
  541. repeatedStrList: ['a', 'b'],
  542. repeatedSimpleList: [
  543. { aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
  544. { aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
  545. ]
  546. }, extendable.toObject());
  547. // Now, with instances included.
  548. assertObjectEquals({
  549. str1: 'v1', str2: 'v2', str3: 'v3',
  550. extField: {
  551. ext1: 'ext1field',
  552. $jspbMessageInstance:
  553. extendable.getExtension(proto.jspb.test.IsExtension.extField)
  554. },
  555. simple: {
  556. aString: 'str',
  557. aRepeatedStringList: ['s1', 's2'],
  558. aBoolean: true,
  559. $jspbMessageInstance:
  560. extendable.getExtension(proto.jspb.test.IndirectExtension.simple)
  561. },
  562. str: 'xyzzy',
  563. repeatedStrList: ['a', 'b'],
  564. repeatedSimpleList: [{
  565. aString: 'foo',
  566. aRepeatedStringList: ['s1', 's2'],
  567. aBoolean: true,
  568. $jspbMessageInstance: s1
  569. }, {
  570. aString: 'bar',
  571. aRepeatedStringList: ['t1', 't2'],
  572. aBoolean: false,
  573. $jspbMessageInstance: s2
  574. }],
  575. $jspbMessageInstance: extendable
  576. }, extendable.toObject(true /* opt_includeInstance */));
  577. });
  578. it('testInitialization_emptyArray', function() {
  579. var msg = new proto.jspb.test.HasExtensions([]);
  580. if (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) {
  581. assertArrayEquals([], msg.toArray());
  582. } else {
  583. // Extension object is created past all regular fields.
  584. assertArrayEquals([,,, {}], msg.toArray());
  585. }
  586. });
  587. it('testInitialization_justExtensionObject', function() {
  588. var msg = new proto.jspb.test.Empty([{1: 'hi'}]);
  589. // The extensionObject is not moved from its original location.
  590. assertArrayEquals([{1: 'hi'}], msg.toArray());
  591. });
  592. it('testInitialization_incompleteList', function() {
  593. var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]);
  594. // The extensionObject is not moved from its original location.
  595. assertArrayEquals([1, {4: 'hi'}], msg.toArray());
  596. });
  597. it('testInitialization_forwardCompatible', function() {
  598. var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]);
  599. assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray());
  600. });
  601. it('testExtendedMessageEnsureObject', function() {
  602. var data = new proto.jspb.test.HasExtensions(['str1',
  603. {'a_key': 'an_object'}]);
  604. assertEquals('an_object', data.extensionObject_['a_key']);
  605. });
  606. it('testToObject_hasExtensionField', function() {
  607. var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]);
  608. var obj = data.toObject();
  609. assertEquals('str1', obj.str1);
  610. assertEquals('ext1', obj.extField.ext1);
  611. });
  612. it('testGetExtension', function() {
  613. var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]);
  614. assertEquals('str1', data.getStr1());
  615. var extension = data.getExtension(proto.jspb.test.IsExtension.extField);
  616. assertNotNull(extension);
  617. assertEquals('ext1', extension.getExt1());
  618. });
  619. it('testSetExtension', function() {
  620. var data = new proto.jspb.test.HasExtensions();
  621. var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']);
  622. data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage);
  623. var obj = data.toObject();
  624. assertNotNull(
  625. data.getExtension(proto.jspb.test.IsExtension.extField));
  626. assertEquals('is_extension', obj.extField.ext1);
  627. });
  628. /**
  629. * Note that group is long deprecated, we only support it because JsPb has
  630. * a goal of being able to generate JS classes for all proto descriptors.
  631. */
  632. it('testGroups', function() {
  633. var group = new proto.jspb.test.TestGroup();
  634. var someGroup = new proto.jspb.test.TestGroup.RepeatedGroup();
  635. someGroup.setId('g1');
  636. someGroup.setSomeBoolList([true, false]);
  637. group.setRepeatedGroupList([someGroup]);
  638. var groups = group.getRepeatedGroupList();
  639. assertEquals('g1', groups[0].getId());
  640. assertObjectEquals([true, false], groups[0].getSomeBoolList());
  641. assertObjectEquals({id: 'g1', someBoolList: [true, false]},
  642. groups[0].toObject());
  643. assertObjectEquals({
  644. repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}],
  645. requiredGroup: {id: undefined},
  646. optionalGroup: undefined,
  647. requiredSimple: {aRepeatedStringList: [], aString: undefined},
  648. optionalSimple: undefined,
  649. id: undefined
  650. }, group.toObject());
  651. var group1 = new proto.jspb.test.TestGroup1();
  652. group1.setGroup(someGroup);
  653. assertEquals(someGroup, group1.getGroup());
  654. });
  655. it('testNonExtensionFieldsAfterExtensionRange', function() {
  656. var data = [{'1': 'a_string'}];
  657. var message = new proto.jspb.test.Complex(data);
  658. assertArrayEquals([], message.getARepeatedStringList());
  659. });
  660. it('testReservedGetterNames', function() {
  661. var message = new proto.jspb.test.TestReservedNames();
  662. message.setExtension$(11);
  663. message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12);
  664. assertEquals(11, message.getExtension$());
  665. assertEquals(12, message.getExtension(
  666. proto.jspb.test.TestReservedNamesExtension.foo));
  667. assertObjectEquals({extension: 11, foo: 12}, message.toObject());
  668. });
  669. it('testInitializeMessageWithUnsetOneof', function() {
  670. var message = new proto.jspb.test.TestMessageWithOneof([]);
  671. assertEquals(
  672. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
  673. PARTIAL_ONEOF_NOT_SET,
  674. message.getPartialOneofCase());
  675. assertEquals(
  676. proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
  677. RECURSIVE_ONEOF_NOT_SET,
  678. message.getRecursiveOneofCase());
  679. });
  680. it('testInitializeMessageWithSingleValueSetInOneof', function() {
  681. var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']);
  682. assertEquals('x', message.getPone());
  683. assertUndefined(message.getPthree());
  684. assertEquals(
  685. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
  686. message.getPartialOneofCase());
  687. });
  688. it('testKeepsLastWireValueSetInUnion_multipleValues', function() {
  689. var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']);
  690. assertUndefined('x', message.getPone());
  691. assertEquals('y', message.getPthree());
  692. assertEquals(
  693. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
  694. message.getPartialOneofCase());
  695. });
  696. it('testSettingOneofFieldClearsOthers', function() {
  697. var message = new proto.jspb.test.TestMessageWithOneof;
  698. assertUndefined(message.getPone());
  699. assertUndefined(message.getPthree());
  700. message.setPone('hi');
  701. assertEquals('hi', message.getPone());
  702. assertUndefined(message.getPthree());
  703. message.setPthree('bye');
  704. assertUndefined(message.getPone());
  705. assertEquals('bye', message.getPthree());
  706. });
  707. it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() {
  708. var other = new proto.jspb.test.TestMessageWithOneof;
  709. var message = new proto.jspb.test.TestMessageWithOneof;
  710. assertUndefined(message.getPone());
  711. assertUndefined(message.getPthree());
  712. assertUndefined(message.getRone());
  713. message.setPone('hi');
  714. message.setRone(other);
  715. assertEquals('hi', message.getPone());
  716. assertUndefined(message.getPthree());
  717. assertEquals(other, message.getRone());
  718. message.setPthree('bye');
  719. assertUndefined(message.getPone());
  720. assertEquals('bye', message.getPthree());
  721. assertEquals(other, message.getRone());
  722. });
  723. it('testUnsetsOneofCaseWhenFieldIsCleared', function() {
  724. var message = new proto.jspb.test.TestMessageWithOneof;
  725. assertEquals(
  726. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
  727. PARTIAL_ONEOF_NOT_SET,
  728. message.getPartialOneofCase());
  729. message.setPone('hi');
  730. assertEquals(
  731. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
  732. message.getPartialOneofCase());
  733. message.clearPone();
  734. assertEquals(
  735. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
  736. PARTIAL_ONEOF_NOT_SET,
  737. message.getPartialOneofCase());
  738. });
  739. it('testMessageWithDefaultOneofValues', function() {
  740. var message = new proto.jspb.test.TestMessageWithOneof;
  741. assertEquals(1234, message.getAone());
  742. assertUndefined(message.getAtwo());
  743. assertEquals(
  744. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
  745. .DEFAULT_ONEOF_A_NOT_SET,
  746. message.getDefaultOneofACase());
  747. message.setAone(567);
  748. assertEquals(567, message.getAone());
  749. assertUndefined(message.getAtwo());
  750. assertEquals(
  751. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
  752. message.getDefaultOneofACase());
  753. message.setAtwo(890);
  754. assertEquals(1234, message.getAone());
  755. assertEquals(890, message.getAtwo());
  756. assertEquals(
  757. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
  758. message.getDefaultOneofACase());
  759. message.clearAtwo();
  760. assertEquals(1234, message.getAone());
  761. assertUndefined(message.getAtwo());
  762. assertEquals(
  763. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
  764. .DEFAULT_ONEOF_A_NOT_SET,
  765. message.getDefaultOneofACase());
  766. });
  767. it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() {
  768. var message = new proto.jspb.test.TestMessageWithOneof;
  769. assertUndefined(message.getBone());
  770. assertEquals(1234, message.getBtwo());
  771. assertEquals(
  772. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
  773. .DEFAULT_ONEOF_B_NOT_SET,
  774. message.getDefaultOneofBCase());
  775. message.setBone(2);
  776. assertEquals(2, message.getBone());
  777. assertEquals(1234, message.getBtwo());
  778. assertEquals(
  779. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
  780. message.getDefaultOneofBCase());
  781. message.setBtwo(3);
  782. assertUndefined(message.getBone());
  783. assertEquals(3, message.getBtwo());
  784. assertEquals(
  785. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
  786. message.getDefaultOneofBCase());
  787. message.clearBtwo();
  788. assertUndefined(message.getBone());
  789. assertEquals(1234, message.getBtwo());
  790. assertEquals(
  791. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
  792. .DEFAULT_ONEOF_B_NOT_SET,
  793. message.getDefaultOneofBCase());
  794. });
  795. it('testInitializeMessageWithOneofDefaults', function() {
  796. var message =
  797. new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567));
  798. assertEquals(567, message.getAone());
  799. assertUndefined(message.getAtwo());
  800. assertEquals(
  801. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
  802. message.getDefaultOneofACase());
  803. message =
  804. new proto.jspb.test.TestMessageWithOneof(new Array(10).concat(890));
  805. assertEquals(1234, message.getAone());
  806. assertEquals(890, message.getAtwo());
  807. assertEquals(
  808. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
  809. message.getDefaultOneofACase());
  810. message =
  811. new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567,890));
  812. assertEquals(1234, message.getAone());
  813. assertEquals(890, message.getAtwo());
  814. assertEquals(
  815. proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
  816. message.getDefaultOneofACase());
  817. });
  818. it('testInitializeMessageWithOneofDefaults_defaultNotSetOnFirstField',
  819. function() {
  820. var message;
  821. message =
  822. new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
  823. assertEquals(567, message.getBone());
  824. assertEquals(1234, message.getBtwo());
  825. assertEquals(
  826. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
  827. message.getDefaultOneofBCase());
  828. message =
  829. new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
  830. assertUndefined(message.getBone());
  831. assertEquals(890, message.getBtwo());
  832. assertEquals(
  833. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
  834. message.getDefaultOneofBCase());
  835. message = new proto.jspb.test.TestMessageWithOneof(
  836. new Array(11).concat(567,890));
  837. assertUndefined(message.getBone());
  838. assertEquals(890, message.getBtwo());
  839. assertEquals(
  840. proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
  841. message.getDefaultOneofBCase());
  842. });
  843. it('testOneofContainingAnotherMessage', function() {
  844. var message = new proto.jspb.test.TestMessageWithOneof;
  845. assertEquals(
  846. proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
  847. RECURSIVE_ONEOF_NOT_SET,
  848. message.getRecursiveOneofCase());
  849. var other = new proto.jspb.test.TestMessageWithOneof;
  850. message.setRone(other);
  851. assertEquals(other, message.getRone());
  852. assertUndefined(message.getRtwo());
  853. assertEquals(
  854. proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE,
  855. message.getRecursiveOneofCase());
  856. message.setRtwo('hi');
  857. assertUndefined(message.getRone());
  858. assertEquals('hi', message.getRtwo());
  859. assertEquals(
  860. proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RTWO,
  861. message.getRecursiveOneofCase());
  862. });
  863. it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray',
  864. function() {
  865. var message = new proto.jspb.test.TestMessageWithOneof;
  866. message.setPone('x');
  867. assertEquals('x', message.getPone());
  868. assertUndefined(message.getPthree());
  869. assertEquals(
  870. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
  871. message.getPartialOneofCase());
  872. var array = message.toArray();
  873. assertEquals('x', array[2]);
  874. assertUndefined(array[4]);
  875. array[4] = 'y';
  876. assertEquals(
  877. proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
  878. message.getPartialOneofCase());
  879. assertUndefined(array[2]);
  880. assertEquals('y', array[4]);
  881. });
  882. });