• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Tests for repeated methods in kernel.js.
3 */
4goog.module('protobuf.runtime.KernelTest');
5
6goog.setTestOnly();
7
8const ByteString = goog.require('protobuf.ByteString');
9const Int64 = goog.require('protobuf.Int64');
10const InternalMessage = goog.require('protobuf.binary.InternalMessage');
11const Kernel = goog.require('protobuf.runtime.Kernel');
12const TestMessage = goog.require('protobuf.testing.binary.TestMessage');
13// Note to the reader:
14// Since the lazy accessor behavior changes with the checking level some of the
15// tests in this file have to know which checking level is enable to make
16// correct assertions.
17const {CHECK_CRITICAL_STATE} = goog.require('protobuf.internal.checks');
18
19/**
20 * @param {...number} bytes
21 * @return {!ArrayBuffer}
22 */
23function createArrayBuffer(...bytes) {
24  return new Uint8Array(bytes).buffer;
25}
26
27/**
28 * Expects the Iterable instance yield the same values as the expected array.
29 * @param {!Iterable<T>} iterable
30 * @param {!Array<T>} expected
31 * @template T
32 * TODO: Implement this as a custom matcher.
33 */
34function expectEqualToArray(iterable, expected) {
35  const array = Array.from(iterable);
36  expect(array).toEqual(expected);
37}
38
39/**
40 * Expects the Iterable instance yield qualified values.
41 * @param {!Iterable<T>} iterable
42 * @param {(function(T): boolean)=} verify
43 * @template T
44 */
45function expectQualifiedIterable(iterable, verify) {
46  if (verify) {
47    for (const value of iterable) {
48      expect(verify(value)).toBe(true);
49    }
50  }
51}
52
53/**
54 * Expects the Iterable instance yield the same values as the expected array of
55 * messages.
56 * @param {!Iterable<!TestMessage>} iterable
57 * @param {!Array<!TestMessage>} expected
58 * @template T
59 * TODO: Implement this as a custom matcher.
60 */
61function expectEqualToMessageArray(iterable, expected) {
62  const array = Array.from(iterable);
63  expect(array.length).toEqual(expected.length);
64  for (let i = 0; i < array.length; i++) {
65    const value = array[i].getBoolWithDefault(1, false);
66    const expectedValue = expected[i].getBoolWithDefault(1, false);
67    expect(value).toBe(expectedValue);
68  }
69}
70
71describe('Kernel for repeated boolean does', () => {
72  it('return empty array for the empty input', () => {
73    const accessor = Kernel.createEmpty();
74    expectEqualToArray(accessor.getRepeatedBoolIterable(1), []);
75  });
76
77  it('ensure not the same instance returned for the empty input', () => {
78    const accessor = Kernel.createEmpty();
79    const list1 = accessor.getRepeatedBoolIterable(1);
80    const list2 = accessor.getRepeatedBoolIterable(1);
81    expect(list1).not.toBe(list2);
82  });
83
84  it('return size for the empty input', () => {
85    const accessor = Kernel.createEmpty();
86    expect(accessor.getRepeatedBoolSize(1)).toEqual(0);
87  });
88
89  it('return unpacked values from the input', () => {
90    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
91    const accessor = Kernel.fromArrayBuffer(bytes);
92    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
93  });
94
95  it('ensure not the same instance returned for unpacked values', () => {
96    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
97    const accessor = Kernel.fromArrayBuffer(bytes);
98    const list1 = accessor.getRepeatedBoolIterable(1);
99    const list2 = accessor.getRepeatedBoolIterable(1);
100    expect(list1).not.toBe(list2);
101  });
102
103  it('return unpacked multibytes values from the input', () => {
104    const bytes = createArrayBuffer(0x08, 0x80, 0x01, 0x08, 0x80, 0x00);
105    const accessor = Kernel.fromArrayBuffer(bytes);
106    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
107  });
108
109  it('return for adding single unpacked value', () => {
110    const accessor = Kernel.createEmpty();
111    accessor.addUnpackedBoolElement(1, true);
112    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
113    accessor.addUnpackedBoolElement(1, false);
114    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
115  });
116
117  it('return for adding unpacked values', () => {
118    const accessor = Kernel.createEmpty();
119    accessor.addUnpackedBoolIterable(1, [true]);
120    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
121    accessor.addUnpackedBoolIterable(1, [false]);
122    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
123  });
124
125  it('return for setting single unpacked value', () => {
126    const accessor =
127        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
128    accessor.setUnpackedBoolElement(1, 0, true);
129    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, true]);
130  });
131
132  it('return for setting unpacked values', () => {
133    const accessor = Kernel.createEmpty();
134    accessor.setUnpackedBoolIterable(1, [true]);
135    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
136    accessor.setUnpackedBoolIterable(1, [false]);
137    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false]);
138  });
139
140  it('encode for adding single unpacked value', () => {
141    const accessor = Kernel.createEmpty();
142    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
143    accessor.addUnpackedBoolElement(1, true);
144    accessor.addUnpackedBoolElement(1, false);
145    expect(accessor.serialize()).toEqual(bytes);
146  });
147
148  it('encode for adding unpacked values', () => {
149    const accessor = Kernel.createEmpty();
150    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
151    accessor.addUnpackedBoolIterable(1, [true, false]);
152    expect(accessor.serialize()).toEqual(bytes);
153  });
154
155  it('encode for setting single unpacked value', () => {
156    const accessor =
157        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x00, 0x01));
158    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x01);
159    accessor.setUnpackedBoolElement(1, 0, true);
160    expect(accessor.serialize()).toEqual(bytes);
161  });
162
163  it('encode for setting unpacked values', () => {
164    const accessor = Kernel.createEmpty();
165    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
166    accessor.setUnpackedBoolIterable(1, [true, false]);
167    expect(accessor.serialize()).toEqual(bytes);
168  });
169
170  it('return packed values from the input', () => {
171    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
172    const accessor = Kernel.fromArrayBuffer(bytes);
173    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
174  });
175
176  it('ensure not the same instance returned for packed values', () => {
177    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
178    const accessor = Kernel.fromArrayBuffer(bytes);
179    const list1 = accessor.getRepeatedBoolIterable(1);
180    const list2 = accessor.getRepeatedBoolIterable(1);
181    expect(list1).not.toBe(list2);
182  });
183
184  it('return packed multibytes values from the input', () => {
185    const bytes = createArrayBuffer(0x0A, 0x04, 0x80, 0x01, 0x80, 0x00);
186    const accessor = Kernel.fromArrayBuffer(bytes);
187    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
188  });
189
190  it('return for adding single packed value', () => {
191    const accessor = Kernel.createEmpty();
192    accessor.addPackedBoolElement(1, true);
193    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
194    accessor.addPackedBoolElement(1, false);
195    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
196  });
197
198  it('return for adding packed values', () => {
199    const accessor = Kernel.createEmpty();
200    accessor.addPackedBoolIterable(1, [true]);
201    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
202    accessor.addPackedBoolIterable(1, [false]);
203    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, false]);
204  });
205
206  it('return for setting single packed value', () => {
207    const accessor =
208        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
209    accessor.setPackedBoolElement(1, 0, true);
210    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true, true]);
211  });
212
213  it('return for setting packed values', () => {
214    const accessor = Kernel.createEmpty();
215    accessor.setPackedBoolIterable(1, [true]);
216    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
217    accessor.setPackedBoolIterable(1, [false]);
218    expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false]);
219  });
220
221  it('encode for adding single packed value', () => {
222    const accessor = Kernel.createEmpty();
223    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
224    accessor.addPackedBoolElement(1, true);
225    accessor.addPackedBoolElement(1, false);
226    expect(accessor.serialize()).toEqual(bytes);
227  });
228
229  it('encode for adding packed values', () => {
230    const accessor = Kernel.createEmpty();
231    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
232    accessor.addPackedBoolIterable(1, [true, false]);
233    expect(accessor.serialize()).toEqual(bytes);
234  });
235
236  it('encode for setting single packed value', () => {
237    const accessor =
238        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00, 0x08, 0x01));
239    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x01);
240    accessor.setPackedBoolElement(1, 0, true);
241    expect(accessor.serialize()).toEqual(bytes);
242  });
243
244  it('encode for setting packed values', () => {
245    const accessor = Kernel.createEmpty();
246    const bytes = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
247    accessor.setPackedBoolIterable(1, [true, false]);
248    expect(accessor.serialize()).toEqual(bytes);
249  });
250
251  it('return combined values from the input', () => {
252    const bytes =
253        createArrayBuffer(0x08, 0x01, 0x0A, 0x02, 0x01, 0x00, 0x08, 0x00);
254    const accessor = Kernel.fromArrayBuffer(bytes);
255    expectEqualToArray(
256        accessor.getRepeatedBoolIterable(1), [true, true, false, false]);
257  });
258
259  it('return the repeated field element from the input', () => {
260    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
261    const accessor = Kernel.fromArrayBuffer(bytes);
262    expect(accessor.getRepeatedBoolElement(
263               /* fieldNumber= */ 1, /* index= */ 0))
264        .toEqual(true);
265    expect(accessor.getRepeatedBoolElement(
266               /* fieldNumber= */ 1, /* index= */ 1))
267        .toEqual(false);
268  });
269
270  it('return the size from the input', () => {
271    const bytes = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
272    const accessor = Kernel.fromArrayBuffer(bytes);
273    expect(accessor.getRepeatedBoolSize(1)).toEqual(2);
274  });
275
276  it('fail when getting unpacked bool value with other wire types', () => {
277    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
278        0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
279    if (CHECK_CRITICAL_STATE) {
280      expect(() => {
281        accessor.getRepeatedBoolIterable(1);
282      }).toThrowError('Expected wire type: 0 but found: 1');
283    } else {
284      // Note in unchecked mode we produce invalid output for invalid inputs.
285      // This test just documents our behavior in those cases.
286      // These values might change at any point and are not considered
287      // what the implementation should be doing here.
288      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [true]);
289    }
290  });
291
292  it('fail when adding unpacked bool values with number value', () => {
293    const accessor = Kernel.createEmpty();
294    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
295    if (CHECK_CRITICAL_STATE) {
296      expect(() => accessor.addUnpackedBoolIterable(1, [fakeBoolean]))
297          .toThrowError('Must be a boolean, but got: 2');
298    } else {
299      // Note in unchecked mode we produce invalid output for invalid inputs.
300      // This test just documents our behavior in those cases.
301      // These values might change at any point and are not considered
302      // what the implementation should be doing here.
303      accessor.addUnpackedBoolIterable(1, [fakeBoolean]);
304      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
305    }
306  });
307
308  it('fail when adding single unpacked bool value with number value', () => {
309    const accessor = Kernel.createEmpty();
310    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
311    if (CHECK_CRITICAL_STATE) {
312      expect(() => accessor.addUnpackedBoolElement(1, fakeBoolean))
313          .toThrowError('Must be a boolean, but got: 2');
314    } else {
315      // Note in unchecked mode we produce invalid output for invalid inputs.
316      // This test just documents our behavior in those cases.
317      // These values might change at any point and are not considered
318      // what the implementation should be doing here.
319      accessor.addUnpackedBoolElement(1, fakeBoolean);
320      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
321    }
322  });
323
324  it('fail when setting unpacked bool values with number value', () => {
325    const accessor = Kernel.createEmpty();
326    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
327    if (CHECK_CRITICAL_STATE) {
328      expect(() => accessor.setUnpackedBoolIterable(1, [fakeBoolean]))
329          .toThrowError('Must be a boolean, but got: 2');
330    } else {
331      // Note in unchecked mode we produce invalid output for invalid inputs.
332      // This test just documents our behavior in those cases.
333      // These values might change at any point and are not considered
334      // what the implementation should be doing here.
335      accessor.setUnpackedBoolIterable(1, [fakeBoolean]);
336      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
337    }
338  });
339
340  it('fail when setting single unpacked bool value with number value', () => {
341    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
342    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
343    if (CHECK_CRITICAL_STATE) {
344      expect(() => accessor.setUnpackedBoolElement(1, 0, fakeBoolean))
345          .toThrowError('Must be a boolean, but got: 2');
346    } else {
347      // Note in unchecked mode we produce invalid output for invalid inputs.
348      // This test just documents our behavior in those cases.
349      // These values might change at any point and are not considered
350      // what the implementation should be doing here.
351      accessor.setUnpackedBoolElement(1, 0, fakeBoolean);
352      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
353    }
354  });
355
356  it('fail when adding packed bool values with number value', () => {
357    const accessor = Kernel.createEmpty();
358    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
359    if (CHECK_CRITICAL_STATE) {
360      expect(() => accessor.addPackedBoolIterable(1, [fakeBoolean]))
361          .toThrowError('Must be a boolean, but got: 2');
362    } else {
363      // Note in unchecked mode we produce invalid output for invalid inputs.
364      // This test just documents our behavior in those cases.
365      // These values might change at any point and are not considered
366      // what the implementation should be doing here.
367      accessor.addPackedBoolIterable(1, [fakeBoolean]);
368      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
369    }
370  });
371
372  it('fail when adding single packed bool value with number value', () => {
373    const accessor = Kernel.createEmpty();
374    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
375    if (CHECK_CRITICAL_STATE) {
376      expect(() => accessor.addPackedBoolElement(1, fakeBoolean))
377          .toThrowError('Must be a boolean, but got: 2');
378    } else {
379      // Note in unchecked mode we produce invalid output for invalid inputs.
380      // This test just documents our behavior in those cases.
381      // These values might change at any point and are not considered
382      // what the implementation should be doing here.
383      accessor.addPackedBoolElement(1, fakeBoolean);
384      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
385    }
386  });
387
388  it('fail when setting packed bool values with number value', () => {
389    const accessor = Kernel.createEmpty();
390    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
391    if (CHECK_CRITICAL_STATE) {
392      expect(() => accessor.setPackedBoolIterable(1, [fakeBoolean]))
393          .toThrowError('Must be a boolean, but got: 2');
394    } else {
395      // Note in unchecked mode we produce invalid output for invalid inputs.
396      // This test just documents our behavior in those cases.
397      // These values might change at any point and are not considered
398      // what the implementation should be doing here.
399      accessor.setPackedBoolIterable(1, [fakeBoolean]);
400      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
401    }
402  });
403
404  it('fail when setting single packed bool value with number value', () => {
405    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
406    const fakeBoolean = /** @type {boolean} */ (/** @type {*} */ (2));
407    if (CHECK_CRITICAL_STATE) {
408      expect(() => accessor.setPackedBoolElement(1, 0, fakeBoolean))
409          .toThrowError('Must be a boolean, but got: 2');
410    } else {
411      // Note in unchecked mode we produce invalid output for invalid inputs.
412      // This test just documents our behavior in those cases.
413      // These values might change at any point and are not considered
414      // what the implementation should be doing here.
415      accessor.setPackedBoolElement(1, 0, fakeBoolean);
416      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [fakeBoolean]);
417    }
418  });
419
420  it('fail when setting single unpacked with out-of-bound index', () => {
421    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
422    if (CHECK_CRITICAL_STATE) {
423      expect(() => accessor.setUnpackedBoolElement(1, 1, true))
424          .toThrowError('Index out of bounds: index: 1 size: 1');
425    } else {
426      // Note in unchecked mode we produce invalid output for invalid inputs.
427      // This test just documents our behavior in those cases.
428      // These values might change at any point and are not considered
429      // what the implementation should be doing here.
430      accessor.setUnpackedBoolElement(1, 1, true);
431      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false, true]);
432    }
433  });
434
435  it('fail when setting single packed with out-of-bound index', () => {
436    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
437    if (CHECK_CRITICAL_STATE) {
438      expect(() => accessor.setPackedBoolElement(1, 1, true))
439          .toThrowError('Index out of bounds: index: 1 size: 1');
440    } else {
441      // Note in unchecked mode we produce invalid output for invalid inputs.
442      // This test just documents our behavior in those cases.
443      // These values might change at any point and are not considered
444      // what the implementation should be doing here.
445      accessor.setPackedBoolElement(1, 1, true);
446      expectEqualToArray(accessor.getRepeatedBoolIterable(1), [false, true]);
447    }
448  });
449
450  it('fail when getting element with out-of-range index', () => {
451    const accessor = Kernel.createEmpty();
452    if (CHECK_CRITICAL_STATE) {
453      expect(() => {
454        accessor.getRepeatedBoolElement(
455            /* fieldNumber= */ 1, /* index= */ 0);
456      }).toThrowError('Index out of bounds: index: 0 size: 0');
457    } else {
458      // Note in unchecked mode we produce invalid output for invalid inputs.
459      // This test just documents our behavior in those cases.
460      // These values might change at any point and are not considered
461      // what the implementation should be doing here.
462      expect(accessor.getRepeatedBoolElement(
463                 /* fieldNumber= */ 1, /* index= */ 0))
464          .toBe(undefined);
465    }
466  });
467});
468
469describe('Kernel for repeated double does', () => {
470  const value1 = 1;
471  const value2 = 0;
472
473  const unpackedValue1Value2 = createArrayBuffer(
474      0x09,
475      0x00,
476      0x00,
477      0x00,
478      0x00,
479      0x00,
480      0x00,
481      0xF0,
482      0x3F,  // value1
483      0x09,
484      0x00,
485      0x00,
486      0x00,
487      0x00,
488      0x00,
489      0x00,
490      0x00,
491      0x00,  // value2
492  );
493  const unpackedValue2Value1 = createArrayBuffer(
494      0x09,
495      0x00,
496      0x00,
497      0x00,
498      0x00,
499      0x00,
500      0x00,
501      0x00,
502      0x00,  // value1
503      0x09,
504      0x00,
505      0x00,
506      0x00,
507      0x00,
508      0x00,
509      0x00,
510      0xF0,
511      0x3F,  // value2
512  );
513
514  const packedValue1Value2 = createArrayBuffer(
515      0x0A,
516      0x10,  // tag
517      0x00,
518      0x00,
519      0x00,
520      0x00,
521      0x00,
522      0x00,
523      0xF0,
524      0x3F,  // value1
525      0x00,
526      0x00,
527      0x00,
528      0x00,
529      0x00,
530      0x00,
531      0x00,
532      0x00,  // value2
533  );
534  const packedValue2Value1 = createArrayBuffer(
535      0x0A,
536      0x10,  // tag
537      0x00,
538      0x00,
539      0x00,
540      0x00,
541      0x00,
542      0x00,
543      0x00,
544      0x00,  // value1
545      0x00,
546      0x00,
547      0x00,
548      0x00,
549      0x00,
550      0x00,
551      0xF0,
552      0x3F,  // value2
553  );
554
555  it('return empty array for the empty input', () => {
556    const accessor = Kernel.createEmpty();
557
558    const list = accessor.getRepeatedDoubleIterable(1);
559
560    expectEqualToArray(list, []);
561  });
562
563  it('ensure not the same instance returned for the empty input', () => {
564    const accessor = Kernel.createEmpty();
565
566    const list1 = accessor.getRepeatedDoubleIterable(1);
567    const list2 = accessor.getRepeatedDoubleIterable(1);
568
569    expect(list1).not.toBe(list2);
570  });
571
572  it('return size for the empty input', () => {
573    const accessor = Kernel.createEmpty();
574
575    const size = accessor.getRepeatedDoubleSize(1);
576
577    expect(size).toEqual(0);
578  });
579
580  it('return unpacked values from the input', () => {
581    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
582
583    const list = accessor.getRepeatedDoubleIterable(1);
584
585    expectEqualToArray(list, [value1, value2]);
586  });
587
588  it('ensure not the same instance returned for unpacked values', () => {
589    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
590
591    const list1 = accessor.getRepeatedDoubleIterable(1);
592    const list2 = accessor.getRepeatedDoubleIterable(1);
593
594    expect(list1).not.toBe(list2);
595  });
596
597  it('add single unpacked value', () => {
598    const accessor = Kernel.createEmpty();
599
600    accessor.addUnpackedDoubleElement(1, value1);
601    const list1 = accessor.getRepeatedDoubleIterable(1);
602    accessor.addUnpackedDoubleElement(1, value2);
603    const list2 = accessor.getRepeatedDoubleIterable(1);
604
605    expectEqualToArray(list1, [value1]);
606    expectEqualToArray(list2, [value1, value2]);
607  });
608
609  it('add unpacked values', () => {
610    const accessor = Kernel.createEmpty();
611
612    accessor.addUnpackedDoubleIterable(1, [value1]);
613    const list1 = accessor.getRepeatedDoubleIterable(1);
614    accessor.addUnpackedDoubleIterable(1, [value2]);
615    const list2 = accessor.getRepeatedDoubleIterable(1);
616
617    expectEqualToArray(list1, [value1]);
618    expectEqualToArray(list2, [value1, value2]);
619  });
620
621  it('set a single unpacked value', () => {
622    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
623
624    accessor.setUnpackedDoubleElement(1, 1, value1);
625    const list = accessor.getRepeatedDoubleIterable(1);
626
627    expectEqualToArray(list, [value1, value1]);
628  });
629
630  it('set unpacked values', () => {
631    const accessor = Kernel.createEmpty();
632
633    accessor.setUnpackedDoubleIterable(1, [value1]);
634    const list = accessor.getRepeatedDoubleIterable(1);
635
636    expectEqualToArray(list, [value1]);
637  });
638
639  it('encode for adding single unpacked value', () => {
640    const accessor = Kernel.createEmpty();
641
642    accessor.addUnpackedDoubleElement(1, value1);
643    accessor.addUnpackedDoubleElement(1, value2);
644    const serialized = accessor.serialize();
645
646    expect(serialized).toEqual(unpackedValue1Value2);
647  });
648
649  it('encode for adding unpacked values', () => {
650    const accessor = Kernel.createEmpty();
651
652    accessor.addUnpackedDoubleIterable(1, [value1]);
653    accessor.addUnpackedDoubleIterable(1, [value2]);
654    const serialized = accessor.serialize();
655
656    expect(serialized).toEqual(unpackedValue1Value2);
657  });
658
659  it('encode for setting single unpacked value', () => {
660    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
661
662    accessor.setUnpackedDoubleElement(1, 0, value2);
663    accessor.setUnpackedDoubleElement(1, 1, value1);
664    const serialized = accessor.serialize();
665
666    expect(serialized).toEqual(unpackedValue2Value1);
667  });
668
669  it('encode for setting unpacked values', () => {
670    const accessor = Kernel.createEmpty();
671
672    accessor.setUnpackedDoubleIterable(1, [value1, value2]);
673    const serialized = accessor.serialize();
674
675    expect(serialized).toEqual(unpackedValue1Value2);
676  });
677
678  it('return packed values from the input', () => {
679    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
680
681    const list = accessor.getRepeatedDoubleIterable(1);
682
683    expectEqualToArray(list, [value1, value2]);
684  });
685
686  it('ensure not the same instance returned for packed values', () => {
687    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
688
689    const list1 = accessor.getRepeatedDoubleIterable(1);
690    const list2 = accessor.getRepeatedDoubleIterable(1);
691
692    expect(list1).not.toBe(list2);
693  });
694
695  it('add single packed value', () => {
696    const accessor = Kernel.createEmpty();
697
698    accessor.addPackedDoubleElement(1, value1);
699    const list1 = accessor.getRepeatedDoubleIterable(1);
700    accessor.addPackedDoubleElement(1, value2);
701    const list2 = accessor.getRepeatedDoubleIterable(1);
702
703    expectEqualToArray(list1, [value1]);
704    expectEqualToArray(list2, [value1, value2]);
705  });
706
707  it('add packed values', () => {
708    const accessor = Kernel.createEmpty();
709
710    accessor.addPackedDoubleIterable(1, [value1]);
711    const list1 = accessor.getRepeatedDoubleIterable(1);
712    accessor.addPackedDoubleIterable(1, [value2]);
713    const list2 = accessor.getRepeatedDoubleIterable(1);
714
715    expectEqualToArray(list1, [value1]);
716    expectEqualToArray(list2, [value1, value2]);
717  });
718
719  it('set a single packed value', () => {
720    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
721
722    accessor.setPackedDoubleElement(1, 1, value1);
723    const list = accessor.getRepeatedDoubleIterable(1);
724
725    expectEqualToArray(list, [value1, value1]);
726  });
727
728  it('set packed values', () => {
729    const accessor = Kernel.createEmpty();
730
731    accessor.setPackedDoubleIterable(1, [value1]);
732    const list1 = accessor.getRepeatedDoubleIterable(1);
733    accessor.setPackedDoubleIterable(1, [value2]);
734    const list2 = accessor.getRepeatedDoubleIterable(1);
735
736    expectEqualToArray(list1, [value1]);
737    expectEqualToArray(list2, [value2]);
738  });
739
740  it('encode for adding single packed value', () => {
741    const accessor = Kernel.createEmpty();
742
743    accessor.addPackedDoubleElement(1, value1);
744    accessor.addPackedDoubleElement(1, value2);
745    const serialized = accessor.serialize();
746
747    expect(serialized).toEqual(packedValue1Value2);
748  });
749
750  it('encode for adding packed values', () => {
751    const accessor = Kernel.createEmpty();
752
753    accessor.addPackedDoubleIterable(1, [value1, value2]);
754    const serialized = accessor.serialize();
755
756    expect(serialized).toEqual(packedValue1Value2);
757  });
758
759  it('encode for setting single packed value', () => {
760    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
761
762    accessor.setPackedDoubleElement(1, 0, value2);
763    accessor.setPackedDoubleElement(1, 1, value1);
764
765    const serialized = accessor.serialize();
766
767    expect(serialized).toEqual(packedValue2Value1);
768  });
769
770  it('encode for setting packed values', () => {
771    const accessor = Kernel.createEmpty();
772
773    accessor.setPackedDoubleIterable(1, [value1, value2]);
774    const serialized = accessor.serialize();
775
776    expect(serialized).toEqual(packedValue1Value2);
777  });
778
779  it('return combined values from the input', () => {
780    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
781        0x09,
782        0x00,
783        0x00,
784        0x00,
785        0x00,
786        0x00,
787        0x00,
788        0xF0,
789        0x3F,  // value1
790        0x0A,
791        0x10,  // tag
792        0x00,
793        0x00,
794        0x00,
795        0x00,
796        0x00,
797        0x00,
798        0xF0,
799        0x3F,  // value1
800        0x00,
801        0x00,
802        0x00,
803        0x00,
804        0x00,
805        0x00,
806        0x00,
807        0x00,  // value2
808        0x09,
809        0x00,
810        0x00,
811        0x00,
812        0x00,
813        0x00,
814        0x00,
815        0x00,
816        0x00,  // value2
817        ));
818
819    const list = accessor.getRepeatedDoubleIterable(1);
820
821    expectEqualToArray(list, [value1, value1, value2, value2]);
822  });
823
824  it('return the repeated field element from the input', () => {
825    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
826
827    const result1 = accessor.getRepeatedDoubleElement(
828        /* fieldNumber= */ 1, /* index= */ 0);
829    const result2 = accessor.getRepeatedDoubleElement(
830        /* fieldNumber= */ 1, /* index= */ 1);
831
832    expect(result1).toEqual(value1);
833    expect(result2).toEqual(value2);
834  });
835
836  it('return the size from the input', () => {
837    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
838
839    const size = accessor.getRepeatedDoubleSize(1);
840
841    expect(size).toEqual(2);
842  });
843
844  it('fail when getting unpacked double value with other wire types', () => {
845    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
846        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
847    if (CHECK_CRITICAL_STATE) {
848      expect(() => {
849        accessor.getRepeatedDoubleIterable(1);
850      }).toThrowError('Expected wire type: 1 but found: 0');
851    } else {
852      // Note in unchecked mode we produce invalid output for invalid inputs.
853      // This test just documents our behavior in those cases.
854      // These values might change at any point and are not considered
855      // what the implementation should be doing here.
856      expectEqualToArray(
857          accessor.getRepeatedDoubleIterable(1), [2.937446524422997e-306]);
858    }
859  });
860
861  it('fail when adding unpacked double values with null value', () => {
862    const accessor = Kernel.createEmpty();
863    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
864    if (CHECK_CRITICAL_STATE) {
865      expect(() => accessor.addUnpackedDoubleIterable(1, [fakeDouble]))
866          .toThrowError('Must be a number, but got: null');
867    } else {
868      // Note in unchecked mode we produce invalid output for invalid inputs.
869      // This test just documents our behavior in those cases.
870      // These values might change at any point and are not considered
871      // what the implementation should be doing here.
872      accessor.addUnpackedDoubleIterable(1, [fakeDouble]);
873      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
874    }
875  });
876
877  it('fail when adding single unpacked double value with null value', () => {
878    const accessor = Kernel.createEmpty();
879    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
880    if (CHECK_CRITICAL_STATE) {
881      expect(() => accessor.addUnpackedDoubleElement(1, fakeDouble))
882          .toThrowError('Must be a number, but got: null');
883    } else {
884      // Note in unchecked mode we produce invalid output for invalid inputs.
885      // This test just documents our behavior in those cases.
886      // These values might change at any point and are not considered
887      // what the implementation should be doing here.
888      accessor.addUnpackedDoubleElement(1, fakeDouble);
889      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
890    }
891  });
892
893  it('fail when setting unpacked double values with null value', () => {
894    const accessor = Kernel.createEmpty();
895    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
896    if (CHECK_CRITICAL_STATE) {
897      expect(() => accessor.setUnpackedDoubleIterable(1, [fakeDouble]))
898          .toThrowError('Must be a number, but got: null');
899    } else {
900      // Note in unchecked mode we produce invalid output for invalid inputs.
901      // This test just documents our behavior in those cases.
902      // These values might change at any point and are not considered
903      // what the implementation should be doing here.
904      accessor.setUnpackedDoubleIterable(1, [fakeDouble]);
905      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
906    }
907  });
908
909  it('fail when setting single unpacked double value with null value', () => {
910    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
911        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
912    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
913    if (CHECK_CRITICAL_STATE) {
914      expect(() => accessor.setUnpackedDoubleElement(1, 0, fakeDouble))
915          .toThrowError('Must be a number, but got: null');
916    } else {
917      // Note in unchecked mode we produce invalid output for invalid inputs.
918      // This test just documents our behavior in those cases.
919      // These values might change at any point and are not considered
920      // what the implementation should be doing here.
921      accessor.setUnpackedDoubleElement(1, 0, fakeDouble);
922      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
923    }
924  });
925
926  it('fail when adding packed double values with null value', () => {
927    const accessor = Kernel.createEmpty();
928    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
929    if (CHECK_CRITICAL_STATE) {
930      expect(() => accessor.addPackedDoubleIterable(1, [fakeDouble]))
931          .toThrowError('Must be a number, but got: null');
932    } else {
933      // Note in unchecked mode we produce invalid output for invalid inputs.
934      // This test just documents our behavior in those cases.
935      // These values might change at any point and are not considered
936      // what the implementation should be doing here.
937      accessor.addPackedDoubleIterable(1, [fakeDouble]);
938      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
939    }
940  });
941
942  it('fail when adding single packed double value with null value', () => {
943    const accessor = Kernel.createEmpty();
944    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
945    if (CHECK_CRITICAL_STATE) {
946      expect(() => accessor.addPackedDoubleElement(1, fakeDouble))
947          .toThrowError('Must be a number, but got: null');
948    } else {
949      // Note in unchecked mode we produce invalid output for invalid inputs.
950      // This test just documents our behavior in those cases.
951      // These values might change at any point and are not considered
952      // what the implementation should be doing here.
953      accessor.addPackedDoubleElement(1, fakeDouble);
954      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
955    }
956  });
957
958  it('fail when setting packed double values with null value', () => {
959    const accessor = Kernel.createEmpty();
960    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
961    if (CHECK_CRITICAL_STATE) {
962      expect(() => accessor.setPackedDoubleIterable(1, [fakeDouble]))
963          .toThrowError('Must be a number, but got: null');
964    } else {
965      // Note in unchecked mode we produce invalid output for invalid inputs.
966      // This test just documents our behavior in those cases.
967      // These values might change at any point and are not considered
968      // what the implementation should be doing here.
969      accessor.setPackedDoubleIterable(1, [fakeDouble]);
970      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
971    }
972  });
973
974  it('fail when setting single packed double value with null value', () => {
975    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
976        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
977    const fakeDouble = /** @type {number} */ (/** @type {*} */ (null));
978    if (CHECK_CRITICAL_STATE) {
979      expect(() => accessor.setPackedDoubleElement(1, 0, fakeDouble))
980          .toThrowError('Must be a number, but got: null');
981    } else {
982      // Note in unchecked mode we produce invalid output for invalid inputs.
983      // This test just documents our behavior in those cases.
984      // These values might change at any point and are not considered
985      // what the implementation should be doing here.
986      accessor.setPackedDoubleElement(1, 0, fakeDouble);
987      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [fakeDouble]);
988    }
989  });
990
991  it('fail when setting single unpacked with out-of-bound index', () => {
992    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
993        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
994    if (CHECK_CRITICAL_STATE) {
995      expect(() => accessor.setUnpackedDoubleElement(1, 1, 1))
996          .toThrowError('Index out of bounds: index: 1 size: 1');
997    } else {
998      // Note in unchecked mode we produce invalid output for invalid inputs.
999      // This test just documents our behavior in those cases.
1000      // These values might change at any point and are not considered
1001      // what the implementation should be doing here.
1002      accessor.setUnpackedDoubleElement(1, 1, 1);
1003      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [0, 1]);
1004    }
1005  });
1006
1007  it('fail when setting single packed with out-of-bound index', () => {
1008    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
1009        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
1010    if (CHECK_CRITICAL_STATE) {
1011      expect(() => accessor.setPackedDoubleElement(1, 1, 1))
1012          .toThrowError('Index out of bounds: index: 1 size: 1');
1013    } else {
1014      // Note in unchecked mode we produce invalid output for invalid inputs.
1015      // This test just documents our behavior in those cases.
1016      // These values might change at any point and are not considered
1017      // what the implementation should be doing here.
1018      accessor.setPackedDoubleElement(1, 1, 1);
1019      expectEqualToArray(accessor.getRepeatedDoubleIterable(1), [0, 1]);
1020    }
1021  });
1022
1023  it('fail when getting element with out-of-range index', () => {
1024    const accessor = Kernel.createEmpty();
1025    if (CHECK_CRITICAL_STATE) {
1026      expect(() => {
1027        accessor.getRepeatedDoubleElement(
1028            /* fieldNumber= */ 1, /* index= */ 0);
1029      }).toThrowError('Index out of bounds: index: 0 size: 0');
1030    } else {
1031      // Note in unchecked mode we produce invalid output for invalid inputs.
1032      // This test just documents our behavior in those cases.
1033      // These values might change at any point and are not considered
1034      // what the implementation should be doing here.
1035      expect(accessor.getRepeatedDoubleElement(
1036                 /* fieldNumber= */ 1, /* index= */ 0))
1037          .toBe(undefined);
1038    }
1039  });
1040});
1041
1042describe('Kernel for repeated fixed32 does', () => {
1043  const value1 = 1;
1044  const value2 = 0;
1045
1046  const unpackedValue1Value2 = createArrayBuffer(
1047      0x0D, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00);
1048  const unpackedValue2Value1 = createArrayBuffer(
1049      0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x00, 0x00);
1050
1051  const packedValue1Value2 = createArrayBuffer(
1052      0x0A, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
1053  const packedValue2Value1 = createArrayBuffer(
1054      0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
1055
1056  it('return empty array for the empty input', () => {
1057    const accessor = Kernel.createEmpty();
1058
1059    const list = accessor.getRepeatedFixed32Iterable(1);
1060
1061    expectEqualToArray(list, []);
1062  });
1063
1064  it('ensure not the same instance returned for the empty input', () => {
1065    const accessor = Kernel.createEmpty();
1066
1067    const list1 = accessor.getRepeatedFixed32Iterable(1);
1068    const list2 = accessor.getRepeatedFixed32Iterable(1);
1069
1070    expect(list1).not.toBe(list2);
1071  });
1072
1073  it('return size for the empty input', () => {
1074    const accessor = Kernel.createEmpty();
1075
1076    const size = accessor.getRepeatedFixed32Size(1);
1077
1078    expect(size).toEqual(0);
1079  });
1080
1081  it('return unpacked values from the input', () => {
1082    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1083
1084    const list = accessor.getRepeatedFixed32Iterable(1);
1085
1086    expectEqualToArray(list, [value1, value2]);
1087  });
1088
1089  it('ensure not the same instance returned for unpacked values', () => {
1090    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1091
1092    const list1 = accessor.getRepeatedFixed32Iterable(1);
1093    const list2 = accessor.getRepeatedFixed32Iterable(1);
1094
1095    expect(list1).not.toBe(list2);
1096  });
1097
1098  it('add single unpacked value', () => {
1099    const accessor = Kernel.createEmpty();
1100
1101    accessor.addUnpackedFixed32Element(1, value1);
1102    const list1 = accessor.getRepeatedFixed32Iterable(1);
1103    accessor.addUnpackedFixed32Element(1, value2);
1104    const list2 = accessor.getRepeatedFixed32Iterable(1);
1105
1106    expectEqualToArray(list1, [value1]);
1107    expectEqualToArray(list2, [value1, value2]);
1108  });
1109
1110  it('add unpacked values', () => {
1111    const accessor = Kernel.createEmpty();
1112
1113    accessor.addUnpackedFixed32Iterable(1, [value1]);
1114    const list1 = accessor.getRepeatedFixed32Iterable(1);
1115    accessor.addUnpackedFixed32Iterable(1, [value2]);
1116    const list2 = accessor.getRepeatedFixed32Iterable(1);
1117
1118    expectEqualToArray(list1, [value1]);
1119    expectEqualToArray(list2, [value1, value2]);
1120  });
1121
1122  it('set a single unpacked value', () => {
1123    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1124
1125    accessor.setUnpackedFixed32Element(1, 1, value1);
1126    const list = accessor.getRepeatedFixed32Iterable(1);
1127
1128    expectEqualToArray(list, [value1, value1]);
1129  });
1130
1131  it('set unpacked values', () => {
1132    const accessor = Kernel.createEmpty();
1133
1134    accessor.setUnpackedFixed32Iterable(1, [value1]);
1135    const list = accessor.getRepeatedFixed32Iterable(1);
1136
1137    expectEqualToArray(list, [value1]);
1138  });
1139
1140  it('encode for adding single unpacked value', () => {
1141    const accessor = Kernel.createEmpty();
1142
1143    accessor.addUnpackedFixed32Element(1, value1);
1144    accessor.addUnpackedFixed32Element(1, value2);
1145    const serialized = accessor.serialize();
1146
1147    expect(serialized).toEqual(unpackedValue1Value2);
1148  });
1149
1150  it('encode for adding unpacked values', () => {
1151    const accessor = Kernel.createEmpty();
1152
1153    accessor.addUnpackedFixed32Iterable(1, [value1]);
1154    accessor.addUnpackedFixed32Iterable(1, [value2]);
1155    const serialized = accessor.serialize();
1156
1157    expect(serialized).toEqual(unpackedValue1Value2);
1158  });
1159
1160  it('encode for setting single unpacked value', () => {
1161    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1162
1163    accessor.setUnpackedFixed32Element(1, 0, value2);
1164    accessor.setUnpackedFixed32Element(1, 1, value1);
1165    const serialized = accessor.serialize();
1166
1167    expect(serialized).toEqual(unpackedValue2Value1);
1168  });
1169
1170  it('encode for setting unpacked values', () => {
1171    const accessor = Kernel.createEmpty();
1172
1173    accessor.setUnpackedFixed32Iterable(1, [value1, value2]);
1174    const serialized = accessor.serialize();
1175
1176    expect(serialized).toEqual(unpackedValue1Value2);
1177  });
1178
1179  it('return packed values from the input', () => {
1180    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1181
1182    const list = accessor.getRepeatedFixed32Iterable(1);
1183
1184    expectEqualToArray(list, [value1, value2]);
1185  });
1186
1187  it('ensure not the same instance returned for packed values', () => {
1188    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1189
1190    const list1 = accessor.getRepeatedFixed32Iterable(1);
1191    const list2 = accessor.getRepeatedFixed32Iterable(1);
1192
1193    expect(list1).not.toBe(list2);
1194  });
1195
1196  it('add single packed value', () => {
1197    const accessor = Kernel.createEmpty();
1198
1199    accessor.addPackedFixed32Element(1, value1);
1200    const list1 = accessor.getRepeatedFixed32Iterable(1);
1201    accessor.addPackedFixed32Element(1, value2);
1202    const list2 = accessor.getRepeatedFixed32Iterable(1);
1203
1204    expectEqualToArray(list1, [value1]);
1205    expectEqualToArray(list2, [value1, value2]);
1206  });
1207
1208  it('add packed values', () => {
1209    const accessor = Kernel.createEmpty();
1210
1211    accessor.addPackedFixed32Iterable(1, [value1]);
1212    const list1 = accessor.getRepeatedFixed32Iterable(1);
1213    accessor.addPackedFixed32Iterable(1, [value2]);
1214    const list2 = accessor.getRepeatedFixed32Iterable(1);
1215
1216    expectEqualToArray(list1, [value1]);
1217    expectEqualToArray(list2, [value1, value2]);
1218  });
1219
1220  it('set a single packed value', () => {
1221    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1222
1223    accessor.setPackedFixed32Element(1, 1, value1);
1224    const list = accessor.getRepeatedFixed32Iterable(1);
1225
1226    expectEqualToArray(list, [value1, value1]);
1227  });
1228
1229  it('set packed values', () => {
1230    const accessor = Kernel.createEmpty();
1231
1232    accessor.setPackedFixed32Iterable(1, [value1]);
1233    const list1 = accessor.getRepeatedFixed32Iterable(1);
1234    accessor.setPackedFixed32Iterable(1, [value2]);
1235    const list2 = accessor.getRepeatedFixed32Iterable(1);
1236
1237    expectEqualToArray(list1, [value1]);
1238    expectEqualToArray(list2, [value2]);
1239  });
1240
1241  it('encode for adding single packed value', () => {
1242    const accessor = Kernel.createEmpty();
1243
1244    accessor.addPackedFixed32Element(1, value1);
1245    accessor.addPackedFixed32Element(1, value2);
1246    const serialized = accessor.serialize();
1247
1248    expect(serialized).toEqual(packedValue1Value2);
1249  });
1250
1251  it('encode for adding packed values', () => {
1252    const accessor = Kernel.createEmpty();
1253
1254    accessor.addPackedFixed32Iterable(1, [value1, value2]);
1255    const serialized = accessor.serialize();
1256
1257    expect(serialized).toEqual(packedValue1Value2);
1258  });
1259
1260  it('encode for setting single packed value', () => {
1261    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1262
1263    accessor.setPackedFixed32Element(1, 0, value2);
1264    accessor.setPackedFixed32Element(1, 1, value1);
1265
1266    const serialized = accessor.serialize();
1267
1268    expect(serialized).toEqual(packedValue2Value1);
1269  });
1270
1271  it('encode for setting packed values', () => {
1272    const accessor = Kernel.createEmpty();
1273
1274    accessor.setPackedFixed32Iterable(1, [value1, value2]);
1275    const serialized = accessor.serialize();
1276
1277    expect(serialized).toEqual(packedValue1Value2);
1278  });
1279
1280  it('return combined values from the input', () => {
1281    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
1282        0x0D,
1283        0x01,
1284        0x00,
1285        0x00,
1286        0x00,  // value1
1287        0x0A,
1288        0x08,  // tag
1289        0x01,
1290        0x00,
1291        0x00,
1292        0x00,  // value1
1293        0x00,
1294        0x00,
1295        0x00,
1296        0x00,  // value2
1297        0x0D,
1298        0x00,
1299        0x00,
1300        0x00,
1301        0x00,  // value2
1302        ));
1303
1304    const list = accessor.getRepeatedFixed32Iterable(1);
1305
1306    expectEqualToArray(list, [value1, value1, value2, value2]);
1307  });
1308
1309  it('return the repeated field element from the input', () => {
1310    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1311
1312    const result1 = accessor.getRepeatedFixed32Element(
1313        /* fieldNumber= */ 1, /* index= */ 0);
1314    const result2 = accessor.getRepeatedFixed32Element(
1315        /* fieldNumber= */ 1, /* index= */ 1);
1316
1317    expect(result1).toEqual(value1);
1318    expect(result2).toEqual(value2);
1319  });
1320
1321  it('return the size from the input', () => {
1322    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1323
1324    const size = accessor.getRepeatedFixed32Size(1);
1325
1326    expect(size).toEqual(2);
1327  });
1328
1329  it('fail when getting unpacked fixed32 value with other wire types', () => {
1330    const accessor =
1331        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
1332    if (CHECK_CRITICAL_STATE) {
1333      expect(() => {
1334        accessor.getRepeatedFixed32Iterable(1);
1335      }).toThrowError('Expected wire type: 5 but found: 0');
1336    } else {
1337      // Note in unchecked mode we produce invalid output for invalid inputs.
1338      // This test just documents our behavior in those cases.
1339      // These values might change at any point and are not considered
1340      // what the implementation should be doing here.
1341      expectQualifiedIterable(
1342          accessor.getRepeatedFixed32Iterable(1),
1343          (value) => Number.isInteger(value));
1344    }
1345  });
1346
1347  it('fail when adding unpacked fixed32 values with null value', () => {
1348    const accessor = Kernel.createEmpty();
1349    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1350    if (CHECK_CRITICAL_STATE) {
1351      expect(() => accessor.addUnpackedFixed32Iterable(1, [fakeFixed32]))
1352          .toThrowError('Must be a number, but got: null');
1353    } else {
1354      // Note in unchecked mode we produce invalid output for invalid inputs.
1355      // This test just documents our behavior in those cases.
1356      // These values might change at any point and are not considered
1357      // what the implementation should be doing here.
1358      accessor.addUnpackedFixed32Iterable(1, [fakeFixed32]);
1359      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1360    }
1361  });
1362
1363  it('fail when adding single unpacked fixed32 value with null value', () => {
1364    const accessor = Kernel.createEmpty();
1365    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1366    if (CHECK_CRITICAL_STATE) {
1367      expect(() => accessor.addUnpackedFixed32Element(1, fakeFixed32))
1368          .toThrowError('Must be a number, but got: null');
1369    } else {
1370      // Note in unchecked mode we produce invalid output for invalid inputs.
1371      // This test just documents our behavior in those cases.
1372      // These values might change at any point and are not considered
1373      // what the implementation should be doing here.
1374      accessor.addUnpackedFixed32Element(1, fakeFixed32);
1375      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1376    }
1377  });
1378
1379  it('fail when setting unpacked fixed32 values with null value', () => {
1380    const accessor = Kernel.createEmpty();
1381    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1382    if (CHECK_CRITICAL_STATE) {
1383      expect(() => accessor.setUnpackedFixed32Iterable(1, [fakeFixed32]))
1384          .toThrowError('Must be a number, but got: null');
1385    } else {
1386      // Note in unchecked mode we produce invalid output for invalid inputs.
1387      // This test just documents our behavior in those cases.
1388      // These values might change at any point and are not considered
1389      // what the implementation should be doing here.
1390      accessor.setUnpackedFixed32Iterable(1, [fakeFixed32]);
1391      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1392    }
1393  });
1394
1395  it('fail when setting single unpacked fixed32 value with null value', () => {
1396    const accessor =
1397        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
1398    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1399    if (CHECK_CRITICAL_STATE) {
1400      expect(() => accessor.setUnpackedFixed32Element(1, 0, fakeFixed32))
1401          .toThrowError('Must be a number, but got: null');
1402    } else {
1403      // Note in unchecked mode we produce invalid output for invalid inputs.
1404      // This test just documents our behavior in those cases.
1405      // These values might change at any point and are not considered
1406      // what the implementation should be doing here.
1407      accessor.setUnpackedFixed32Element(1, 0, fakeFixed32);
1408      expectQualifiedIterable(
1409          accessor.getRepeatedFixed32Iterable(1),
1410      );
1411    }
1412  });
1413
1414  it('fail when adding packed fixed32 values with null value', () => {
1415    const accessor = Kernel.createEmpty();
1416    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1417    if (CHECK_CRITICAL_STATE) {
1418      expect(() => accessor.addPackedFixed32Iterable(1, [fakeFixed32]))
1419          .toThrowError('Must be a number, but got: null');
1420    } else {
1421      // Note in unchecked mode we produce invalid output for invalid inputs.
1422      // This test just documents our behavior in those cases.
1423      // These values might change at any point and are not considered
1424      // what the implementation should be doing here.
1425      accessor.addPackedFixed32Iterable(1, [fakeFixed32]);
1426      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1427    }
1428  });
1429
1430  it('fail when adding single packed fixed32 value with null value', () => {
1431    const accessor = Kernel.createEmpty();
1432    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1433    if (CHECK_CRITICAL_STATE) {
1434      expect(() => accessor.addPackedFixed32Element(1, fakeFixed32))
1435          .toThrowError('Must be a number, but got: null');
1436    } else {
1437      // Note in unchecked mode we produce invalid output for invalid inputs.
1438      // This test just documents our behavior in those cases.
1439      // These values might change at any point and are not considered
1440      // what the implementation should be doing here.
1441      accessor.addPackedFixed32Element(1, fakeFixed32);
1442      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1443    }
1444  });
1445
1446  it('fail when setting packed fixed32 values with null value', () => {
1447    const accessor = Kernel.createEmpty();
1448    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1449    if (CHECK_CRITICAL_STATE) {
1450      expect(() => accessor.setPackedFixed32Iterable(1, [fakeFixed32]))
1451          .toThrowError('Must be a number, but got: null');
1452    } else {
1453      // Note in unchecked mode we produce invalid output for invalid inputs.
1454      // This test just documents our behavior in those cases.
1455      // These values might change at any point and are not considered
1456      // what the implementation should be doing here.
1457      accessor.setPackedFixed32Iterable(1, [fakeFixed32]);
1458      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1459    }
1460  });
1461
1462  it('fail when setting single packed fixed32 value with null value', () => {
1463    const accessor =
1464        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
1465    const fakeFixed32 = /** @type {number} */ (/** @type {*} */ (null));
1466    if (CHECK_CRITICAL_STATE) {
1467      expect(() => accessor.setPackedFixed32Element(1, 0, fakeFixed32))
1468          .toThrowError('Must be a number, but got: null');
1469    } else {
1470      // Note in unchecked mode we produce invalid output for invalid inputs.
1471      // This test just documents our behavior in those cases.
1472      // These values might change at any point and are not considered
1473      // what the implementation should be doing here.
1474      accessor.setPackedFixed32Element(1, 0, fakeFixed32);
1475      expectQualifiedIterable(accessor.getRepeatedFixed32Iterable(1));
1476    }
1477  });
1478
1479  it('fail when setting single unpacked with out-of-bound index', () => {
1480    const accessor = Kernel.fromArrayBuffer(
1481        createArrayBuffer(0x0A, 0x04, 0x00, 0x00, 0x00, 0x00));
1482    if (CHECK_CRITICAL_STATE) {
1483      expect(() => accessor.setUnpackedFixed32Element(1, 1, 1))
1484          .toThrowError('Index out of bounds: index: 1 size: 1');
1485    } else {
1486      // Note in unchecked mode we produce invalid output for invalid inputs.
1487      // This test just documents our behavior in those cases.
1488      // These values might change at any point and are not considered
1489      // what the implementation should be doing here.
1490      accessor.setUnpackedFixed32Element(1, 1, 1);
1491      expectQualifiedIterable(
1492          accessor.getRepeatedFixed32Iterable(1),
1493          (value) => Number.isInteger(value));
1494    }
1495  });
1496
1497  it('fail when setting single packed with out-of-bound index', () => {
1498    const accessor =
1499        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
1500    if (CHECK_CRITICAL_STATE) {
1501      expect(() => accessor.setPackedFixed32Element(1, 1, 1))
1502          .toThrowError('Index out of bounds: index: 1 size: 1');
1503    } else {
1504      // Note in unchecked mode we produce invalid output for invalid inputs.
1505      // This test just documents our behavior in those cases.
1506      // These values might change at any point and are not considered
1507      // what the implementation should be doing here.
1508      accessor.setPackedFixed32Element(1, 1, 1);
1509      expectQualifiedIterable(
1510          accessor.getRepeatedFixed32Iterable(1),
1511          (value) => Number.isInteger(value));
1512    }
1513  });
1514
1515  it('fail when getting element with out-of-range index', () => {
1516    const accessor = Kernel.createEmpty();
1517    if (CHECK_CRITICAL_STATE) {
1518      expect(() => {
1519        accessor.getRepeatedFixed32Element(
1520            /* fieldNumber= */ 1, /* index= */ 0);
1521      }).toThrowError('Index out of bounds: index: 0 size: 0');
1522    } else {
1523      // Note in unchecked mode we produce invalid output for invalid inputs.
1524      // This test just documents our behavior in those cases.
1525      // These values might change at any point and are not considered
1526      // what the implementation should be doing here.
1527      expect(accessor.getRepeatedFixed32Element(
1528                 /* fieldNumber= */ 1, /* index= */ 0))
1529          .toBe(undefined);
1530    }
1531  });
1532});
1533
1534describe('Kernel for repeated fixed64 does', () => {
1535  const value1 = Int64.fromInt(1);
1536  const value2 = Int64.fromInt(0);
1537
1538  const unpackedValue1Value2 = createArrayBuffer(
1539      0x09,
1540      0x01,
1541      0x00,
1542      0x00,
1543      0x00,
1544      0x00,
1545      0x00,
1546      0x00,
1547      0x00,  // value1
1548      0x09,
1549      0x00,
1550      0x00,
1551      0x00,
1552      0x00,
1553      0x00,
1554      0x00,
1555      0x00,
1556      0x00,  // value2
1557  );
1558  const unpackedValue2Value1 = createArrayBuffer(
1559      0x09,
1560      0x00,
1561      0x00,
1562      0x00,
1563      0x00,
1564      0x00,
1565      0x00,
1566      0x00,
1567      0x00,  // value1
1568      0x09,
1569      0x01,
1570      0x00,
1571      0x00,
1572      0x00,
1573      0x00,
1574      0x00,
1575      0x00,
1576      0x00,  // value2
1577  );
1578
1579  const packedValue1Value2 = createArrayBuffer(
1580      0x0A,
1581      0x10,  // tag
1582      0x01,
1583      0x00,
1584      0x00,
1585      0x00,
1586      0x00,
1587      0x00,
1588      0x00,
1589      0x00,  // value1
1590      0x00,
1591      0x00,
1592      0x00,
1593      0x00,
1594      0x00,
1595      0x00,
1596      0x00,
1597      0x00,  // value2
1598  );
1599  const packedValue2Value1 = createArrayBuffer(
1600      0x0A,
1601      0x10,  // tag
1602      0x00,
1603      0x00,
1604      0x00,
1605      0x00,
1606      0x00,
1607      0x00,
1608      0x00,
1609      0x00,  // value2
1610      0x01,
1611      0x00,
1612      0x00,
1613      0x00,
1614      0x00,
1615      0x00,
1616      0x00,
1617      0x00,  // value1
1618  );
1619
1620  it('return empty array for the empty input', () => {
1621    const accessor = Kernel.createEmpty();
1622
1623    const list = accessor.getRepeatedFixed64Iterable(1);
1624
1625    expectEqualToArray(list, []);
1626  });
1627
1628  it('ensure not the same instance returned for the empty input', () => {
1629    const accessor = Kernel.createEmpty();
1630
1631    const list1 = accessor.getRepeatedFixed64Iterable(1);
1632    const list2 = accessor.getRepeatedFixed64Iterable(1);
1633
1634    expect(list1).not.toBe(list2);
1635  });
1636
1637  it('return size for the empty input', () => {
1638    const accessor = Kernel.createEmpty();
1639
1640    const size = accessor.getRepeatedFixed64Size(1);
1641
1642    expect(size).toEqual(0);
1643  });
1644
1645  it('return unpacked values from the input', () => {
1646    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1647
1648    const list = accessor.getRepeatedFixed64Iterable(1);
1649
1650    expectEqualToArray(list, [value1, value2]);
1651  });
1652
1653  it('ensure not the same instance returned for unpacked values', () => {
1654    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1655
1656    const list1 = accessor.getRepeatedFixed64Iterable(1);
1657    const list2 = accessor.getRepeatedFixed64Iterable(1);
1658
1659    expect(list1).not.toBe(list2);
1660  });
1661
1662  it('add single unpacked value', () => {
1663    const accessor = Kernel.createEmpty();
1664
1665    accessor.addUnpackedFixed64Element(1, value1);
1666    const list1 = accessor.getRepeatedFixed64Iterable(1);
1667    accessor.addUnpackedFixed64Element(1, value2);
1668    const list2 = accessor.getRepeatedFixed64Iterable(1);
1669
1670    expectEqualToArray(list1, [value1]);
1671    expectEqualToArray(list2, [value1, value2]);
1672  });
1673
1674  it('add unpacked values', () => {
1675    const accessor = Kernel.createEmpty();
1676
1677    accessor.addUnpackedFixed64Iterable(1, [value1]);
1678    const list1 = accessor.getRepeatedFixed64Iterable(1);
1679    accessor.addUnpackedFixed64Iterable(1, [value2]);
1680    const list2 = accessor.getRepeatedFixed64Iterable(1);
1681
1682    expectEqualToArray(list1, [value1]);
1683    expectEqualToArray(list2, [value1, value2]);
1684  });
1685
1686  it('set a single unpacked value', () => {
1687    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1688
1689    accessor.setUnpackedFixed64Element(1, 1, value1);
1690    const list = accessor.getRepeatedFixed64Iterable(1);
1691
1692    expectEqualToArray(list, [value1, value1]);
1693  });
1694
1695  it('set unpacked values', () => {
1696    const accessor = Kernel.createEmpty();
1697
1698    accessor.setUnpackedFixed64Iterable(1, [value1]);
1699    const list = accessor.getRepeatedFixed64Iterable(1);
1700
1701    expectEqualToArray(list, [value1]);
1702  });
1703
1704  it('encode for adding single unpacked value', () => {
1705    const accessor = Kernel.createEmpty();
1706
1707    accessor.addUnpackedFixed64Element(1, value1);
1708    accessor.addUnpackedFixed64Element(1, value2);
1709    const serialized = accessor.serialize();
1710
1711    expect(serialized).toEqual(unpackedValue1Value2);
1712  });
1713
1714  it('encode for adding unpacked values', () => {
1715    const accessor = Kernel.createEmpty();
1716
1717    accessor.addUnpackedFixed64Iterable(1, [value1]);
1718    accessor.addUnpackedFixed64Iterable(1, [value2]);
1719    const serialized = accessor.serialize();
1720
1721    expect(serialized).toEqual(unpackedValue1Value2);
1722  });
1723
1724  it('encode for setting single unpacked value', () => {
1725    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1726
1727    accessor.setUnpackedFixed64Element(1, 0, value2);
1728    accessor.setUnpackedFixed64Element(1, 1, value1);
1729    const serialized = accessor.serialize();
1730
1731    expect(serialized).toEqual(unpackedValue2Value1);
1732  });
1733
1734  it('encode for setting unpacked values', () => {
1735    const accessor = Kernel.createEmpty();
1736
1737    accessor.setUnpackedFixed64Iterable(1, [value1, value2]);
1738    const serialized = accessor.serialize();
1739
1740    expect(serialized).toEqual(unpackedValue1Value2);
1741  });
1742
1743  it('return packed values from the input', () => {
1744    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1745
1746    const list = accessor.getRepeatedFixed64Iterable(1);
1747
1748    expectEqualToArray(list, [value1, value2]);
1749  });
1750
1751  it('ensure not the same instance returned for packed values', () => {
1752    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
1753
1754    const list1 = accessor.getRepeatedFixed64Iterable(1);
1755    const list2 = accessor.getRepeatedFixed64Iterable(1);
1756
1757    expect(list1).not.toBe(list2);
1758  });
1759
1760  it('add single packed value', () => {
1761    const accessor = Kernel.createEmpty();
1762
1763    accessor.addPackedFixed64Element(1, value1);
1764    const list1 = accessor.getRepeatedFixed64Iterable(1);
1765    accessor.addPackedFixed64Element(1, value2);
1766    const list2 = accessor.getRepeatedFixed64Iterable(1);
1767
1768    expectEqualToArray(list1, [value1]);
1769    expectEqualToArray(list2, [value1, value2]);
1770  });
1771
1772  it('add packed values', () => {
1773    const accessor = Kernel.createEmpty();
1774
1775    accessor.addPackedFixed64Iterable(1, [value1]);
1776    const list1 = accessor.getRepeatedFixed64Iterable(1);
1777    accessor.addPackedFixed64Iterable(1, [value2]);
1778    const list2 = accessor.getRepeatedFixed64Iterable(1);
1779
1780    expectEqualToArray(list1, [value1]);
1781    expectEqualToArray(list2, [value1, value2]);
1782  });
1783
1784  it('set a single packed value', () => {
1785    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1786
1787    accessor.setPackedFixed64Element(1, 1, value1);
1788    const list = accessor.getRepeatedFixed64Iterable(1);
1789
1790    expectEqualToArray(list, [value1, value1]);
1791  });
1792
1793  it('set packed values', () => {
1794    const accessor = Kernel.createEmpty();
1795
1796    accessor.setPackedFixed64Iterable(1, [value1]);
1797    const list1 = accessor.getRepeatedFixed64Iterable(1);
1798    accessor.setPackedFixed64Iterable(1, [value2]);
1799    const list2 = accessor.getRepeatedFixed64Iterable(1);
1800
1801    expectEqualToArray(list1, [value1]);
1802    expectEqualToArray(list2, [value2]);
1803  });
1804
1805  it('encode for adding single packed value', () => {
1806    const accessor = Kernel.createEmpty();
1807
1808    accessor.addPackedFixed64Element(1, value1);
1809    accessor.addPackedFixed64Element(1, value2);
1810    const serialized = accessor.serialize();
1811
1812    expect(serialized).toEqual(packedValue1Value2);
1813  });
1814
1815  it('encode for adding packed values', () => {
1816    const accessor = Kernel.createEmpty();
1817
1818    accessor.addPackedFixed64Iterable(1, [value1, value2]);
1819    const serialized = accessor.serialize();
1820
1821    expect(serialized).toEqual(packedValue1Value2);
1822  });
1823
1824  it('encode for setting single packed value', () => {
1825    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1826
1827    accessor.setPackedFixed64Element(1, 0, value2);
1828    accessor.setPackedFixed64Element(1, 1, value1);
1829
1830    const serialized = accessor.serialize();
1831
1832    expect(serialized).toEqual(packedValue2Value1);
1833  });
1834
1835  it('encode for setting packed values', () => {
1836    const accessor = Kernel.createEmpty();
1837
1838    accessor.setPackedFixed64Iterable(1, [value1, value2]);
1839    const serialized = accessor.serialize();
1840
1841    expect(serialized).toEqual(packedValue1Value2);
1842  });
1843
1844  it('return combined values from the input', () => {
1845    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
1846        0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // value1
1847        0x0A, 0x10,                                            // tag
1848        0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        // value1
1849        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        // value2
1850        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // value2
1851        ));
1852
1853    const list = accessor.getRepeatedFixed64Iterable(1);
1854
1855    expectEqualToArray(list, [value1, value1, value2, value2]);
1856  });
1857
1858  it('return the repeated field element from the input', () => {
1859    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1860
1861    const result1 = accessor.getRepeatedFixed64Element(
1862        /* fieldNumber= */ 1, /* index= */ 0);
1863    const result2 = accessor.getRepeatedFixed64Element(
1864        /* fieldNumber= */ 1, /* index= */ 1);
1865
1866    expect(result1).toEqual(value1);
1867    expect(result2).toEqual(value2);
1868  });
1869
1870  it('return the size from the input', () => {
1871    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
1872
1873    const size = accessor.getRepeatedFixed64Size(1);
1874
1875    expect(size).toEqual(2);
1876  });
1877
1878  it('fail when getting unpacked fixed64 value with other wire types', () => {
1879    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
1880        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
1881    if (CHECK_CRITICAL_STATE) {
1882      expect(() => {
1883        accessor.getRepeatedFixed64Iterable(1);
1884      }).toThrowError('Expected wire type: 1 but found: 0');
1885    } else {
1886      // Note in unchecked mode we produce invalid output for invalid inputs.
1887      // This test just documents our behavior in those cases.
1888      // These values might change at any point and are not considered
1889      // what the implementation should be doing here.
1890      expectQualifiedIterable(
1891          accessor.getRepeatedFixed64Iterable(1),
1892          (value) => value instanceof Int64);
1893    }
1894  });
1895
1896  it('fail when adding unpacked fixed64 values with null value', () => {
1897    const accessor = Kernel.createEmpty();
1898    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1899    if (CHECK_CRITICAL_STATE) {
1900      expect(() => accessor.addUnpackedFixed64Iterable(1, [fakeFixed64]))
1901          .toThrowError('Must be Int64 instance, but got: null');
1902    } else {
1903      // Note in unchecked mode we produce invalid output for invalid inputs.
1904      // This test just documents our behavior in those cases.
1905      // These values might change at any point and are not considered
1906      // what the implementation should be doing here.
1907      accessor.addUnpackedFixed64Iterable(1, [fakeFixed64]);
1908      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1909    }
1910  });
1911
1912  it('fail when adding single unpacked fixed64 value with null value', () => {
1913    const accessor = Kernel.createEmpty();
1914    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1915    if (CHECK_CRITICAL_STATE) {
1916      expect(() => accessor.addUnpackedFixed64Element(1, fakeFixed64))
1917          .toThrowError('Must be Int64 instance, but got: null');
1918    } else {
1919      // Note in unchecked mode we produce invalid output for invalid inputs.
1920      // This test just documents our behavior in those cases.
1921      // These values might change at any point and are not considered
1922      // what the implementation should be doing here.
1923      accessor.addUnpackedFixed64Element(1, fakeFixed64);
1924      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1925    }
1926  });
1927
1928  it('fail when setting unpacked fixed64 values with null value', () => {
1929    const accessor = Kernel.createEmpty();
1930    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1931    if (CHECK_CRITICAL_STATE) {
1932      expect(() => accessor.setUnpackedFixed64Iterable(1, [fakeFixed64]))
1933          .toThrowError('Must be Int64 instance, but got: null');
1934    } else {
1935      // Note in unchecked mode we produce invalid output for invalid inputs.
1936      // This test just documents our behavior in those cases.
1937      // These values might change at any point and are not considered
1938      // what the implementation should be doing here.
1939      accessor.setUnpackedFixed64Iterable(1, [fakeFixed64]);
1940      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1941    }
1942  });
1943
1944  it('fail when setting single unpacked fixed64 value with null value', () => {
1945    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
1946        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
1947    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1948    if (CHECK_CRITICAL_STATE) {
1949      expect(() => accessor.setUnpackedFixed64Element(1, 0, fakeFixed64))
1950          .toThrowError('Must be Int64 instance, but got: null');
1951    } else {
1952      // Note in unchecked mode we produce invalid output for invalid inputs.
1953      // This test just documents our behavior in those cases.
1954      // These values might change at any point and are not considered
1955      // what the implementation should be doing here.
1956      accessor.setUnpackedFixed64Element(1, 0, fakeFixed64);
1957      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1958    }
1959  });
1960
1961  it('fail when adding packed fixed64 values with null value', () => {
1962    const accessor = Kernel.createEmpty();
1963    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1964    if (CHECK_CRITICAL_STATE) {
1965      expect(() => accessor.addPackedFixed64Iterable(1, [fakeFixed64]))
1966          .toThrowError('Must be Int64 instance, but got: null');
1967    } else {
1968      // Note in unchecked mode we produce invalid output for invalid inputs.
1969      // This test just documents our behavior in those cases.
1970      // These values might change at any point and are not considered
1971      // what the implementation should be doing here.
1972      accessor.addPackedFixed64Iterable(1, [fakeFixed64]);
1973      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1974    }
1975  });
1976
1977  it('fail when adding single packed fixed64 value with null value', () => {
1978    const accessor = Kernel.createEmpty();
1979    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1980    if (CHECK_CRITICAL_STATE) {
1981      expect(() => accessor.addPackedFixed64Element(1, fakeFixed64))
1982          .toThrowError('Must be Int64 instance, but got: null');
1983    } else {
1984      // Note in unchecked mode we produce invalid output for invalid inputs.
1985      // This test just documents our behavior in those cases.
1986      // These values might change at any point and are not considered
1987      // what the implementation should be doing here.
1988      accessor.addPackedFixed64Element(1, fakeFixed64);
1989      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
1990    }
1991  });
1992
1993  it('fail when setting packed fixed64 values with null value', () => {
1994    const accessor = Kernel.createEmpty();
1995    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
1996    if (CHECK_CRITICAL_STATE) {
1997      expect(() => accessor.setPackedFixed64Iterable(1, [fakeFixed64]))
1998          .toThrowError('Must be Int64 instance, but got: null');
1999    } else {
2000      // Note in unchecked mode we produce invalid output for invalid inputs.
2001      // This test just documents our behavior in those cases.
2002      // These values might change at any point and are not considered
2003      // what the implementation should be doing here.
2004      accessor.setPackedFixed64Iterable(1, [fakeFixed64]);
2005      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
2006    }
2007  });
2008
2009  it('fail when setting single packed fixed64 value with null value', () => {
2010    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
2011        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
2012    const fakeFixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
2013    if (CHECK_CRITICAL_STATE) {
2014      expect(() => accessor.setPackedFixed64Element(1, 0, fakeFixed64))
2015          .toThrowError('Must be Int64 instance, but got: null');
2016    } else {
2017      // Note in unchecked mode we produce invalid output for invalid inputs.
2018      // This test just documents our behavior in those cases.
2019      // These values might change at any point and are not considered
2020      // what the implementation should be doing here.
2021      accessor.setPackedFixed64Element(1, 0, fakeFixed64);
2022      expectQualifiedIterable(accessor.getRepeatedFixed64Iterable(1));
2023    }
2024  });
2025
2026  it('fail when setting single unpacked with out-of-bound index', () => {
2027    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
2028        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
2029    if (CHECK_CRITICAL_STATE) {
2030      expect(() => accessor.setUnpackedFixed64Element(1, 1, Int64.fromInt(1)))
2031          .toThrowError('Index out of bounds: index: 1 size: 1');
2032    } else {
2033      // Note in unchecked mode we produce invalid output for invalid inputs.
2034      // This test just documents our behavior in those cases.
2035      // These values might change at any point and are not considered
2036      // what the implementation should be doing here.
2037      accessor.setUnpackedFixed64Element(1, 1, Int64.fromInt(1));
2038      expectQualifiedIterable(
2039          accessor.getRepeatedFixed64Iterable(1),
2040          (value) => value instanceof Int64);
2041    }
2042  });
2043
2044  it('fail when setting single packed with out-of-bound index', () => {
2045    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
2046        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
2047    if (CHECK_CRITICAL_STATE) {
2048      expect(() => accessor.setPackedFixed64Element(1, 1, Int64.fromInt(1)))
2049          .toThrowError('Index out of bounds: index: 1 size: 1');
2050    } else {
2051      // Note in unchecked mode we produce invalid output for invalid inputs.
2052      // This test just documents our behavior in those cases.
2053      // These values might change at any point and are not considered
2054      // what the implementation should be doing here.
2055      accessor.setPackedFixed64Element(1, 1, Int64.fromInt(1));
2056      expectQualifiedIterable(
2057          accessor.getRepeatedFixed64Iterable(1),
2058          (value) => value instanceof Int64);
2059    }
2060  });
2061
2062  it('fail when getting element with out-of-range index', () => {
2063    const accessor = Kernel.createEmpty();
2064    if (CHECK_CRITICAL_STATE) {
2065      expect(() => {
2066        accessor.getRepeatedFixed64Element(
2067            /* fieldNumber= */ 1, /* index= */ 0);
2068      }).toThrowError('Index out of bounds: index: 0 size: 0');
2069    } else {
2070      // Note in unchecked mode we produce invalid output for invalid inputs.
2071      // This test just documents our behavior in those cases.
2072      // These values might change at any point and are not considered
2073      // what the implementation should be doing here.
2074      expect(accessor.getRepeatedFixed64Element(
2075                 /* fieldNumber= */ 1, /* index= */ 0))
2076          .toBe(undefined);
2077    }
2078  });
2079});
2080
2081describe('Kernel for repeated float does', () => {
2082  const value1 = 1.6;
2083  const value1Float = Math.fround(1.6);
2084  const value2 = 0;
2085
2086  const unpackedValue1Value2 = createArrayBuffer(
2087      0x0D, 0xCD, 0xCC, 0xCC, 0x3F, 0x0D, 0x00, 0x00, 0x00, 0x00);
2088  const unpackedValue2Value1 = createArrayBuffer(
2089      0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0xCD, 0xCC, 0xCC, 0x3F);
2090
2091  const packedValue1Value2 = createArrayBuffer(
2092      0x0A, 0x08, 0xCD, 0xCC, 0xCC, 0x3F, 0x00, 0x00, 0x00, 0x00);
2093  const packedValue2Value1 = createArrayBuffer(
2094      0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0xCD, 0xCC, 0xCC, 0x3F);
2095
2096  it('return empty array for the empty input', () => {
2097    const accessor = Kernel.createEmpty();
2098
2099    const list = accessor.getRepeatedFloatIterable(1);
2100
2101    expectEqualToArray(list, []);
2102  });
2103
2104  it('ensure not the same instance returned for the empty input', () => {
2105    const accessor = Kernel.createEmpty();
2106
2107    const list1 = accessor.getRepeatedFloatIterable(1);
2108    const list2 = accessor.getRepeatedFloatIterable(1);
2109
2110    expect(list1).not.toBe(list2);
2111  });
2112
2113  it('return size for the empty input', () => {
2114    const accessor = Kernel.createEmpty();
2115
2116    const size = accessor.getRepeatedFloatSize(1);
2117
2118    expect(size).toEqual(0);
2119  });
2120
2121  it('return unpacked values from the input', () => {
2122    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2123
2124    const list = accessor.getRepeatedFloatIterable(1);
2125
2126    expectEqualToArray(list, [value1Float, value2]);
2127  });
2128
2129  it('ensure not the same instance returned for unpacked values', () => {
2130    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2131
2132    const list1 = accessor.getRepeatedFloatIterable(1);
2133    const list2 = accessor.getRepeatedFloatIterable(1);
2134
2135    expect(list1).not.toBe(list2);
2136  });
2137
2138  it('add single unpacked value', () => {
2139    const accessor = Kernel.createEmpty();
2140
2141    accessor.addUnpackedFloatElement(1, value1);
2142    const list1 = accessor.getRepeatedFloatIterable(1);
2143    accessor.addUnpackedFloatElement(1, value2);
2144    const list2 = accessor.getRepeatedFloatIterable(1);
2145
2146    expectEqualToArray(list1, [value1Float]);
2147    expectEqualToArray(list2, [value1Float, value2]);
2148  });
2149
2150  it('add unpacked values', () => {
2151    const accessor = Kernel.createEmpty();
2152
2153    accessor.addUnpackedFloatIterable(1, [value1]);
2154    const list1 = accessor.getRepeatedFloatIterable(1);
2155    accessor.addUnpackedFloatIterable(1, [value2]);
2156    const list2 = accessor.getRepeatedFloatIterable(1);
2157
2158    expectEqualToArray(list1, [value1Float]);
2159    expectEqualToArray(list2, [value1Float, value2]);
2160  });
2161
2162  it('set a single unpacked value', () => {
2163    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2164
2165    accessor.setUnpackedFloatElement(1, 1, value1);
2166    const list = accessor.getRepeatedFloatIterable(1);
2167
2168    expectEqualToArray(list, [value1Float, value1Float]);
2169  });
2170
2171  it('set unpacked values', () => {
2172    const accessor = Kernel.createEmpty();
2173
2174    accessor.setUnpackedFloatIterable(1, [value1]);
2175    const list = accessor.getRepeatedFloatIterable(1);
2176
2177    expectEqualToArray(list, [value1Float]);
2178  });
2179
2180  it('encode for adding single unpacked value', () => {
2181    const accessor = Kernel.createEmpty();
2182
2183    accessor.addUnpackedFloatElement(1, value1);
2184    accessor.addUnpackedFloatElement(1, value2);
2185    const serialized = accessor.serialize();
2186
2187    expect(serialized).toEqual(unpackedValue1Value2);
2188  });
2189
2190  it('encode for adding unpacked values', () => {
2191    const accessor = Kernel.createEmpty();
2192
2193    accessor.addUnpackedFloatIterable(1, [value1]);
2194    accessor.addUnpackedFloatIterable(1, [value2]);
2195    const serialized = accessor.serialize();
2196
2197    expect(serialized).toEqual(unpackedValue1Value2);
2198  });
2199
2200  it('encode for setting single unpacked value', () => {
2201    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2202
2203    accessor.setUnpackedFloatElement(1, 0, value2);
2204    accessor.setUnpackedFloatElement(1, 1, value1);
2205    const serialized = accessor.serialize();
2206
2207    expect(serialized).toEqual(unpackedValue2Value1);
2208  });
2209
2210  it('encode for setting unpacked values', () => {
2211    const accessor = Kernel.createEmpty();
2212
2213    accessor.setUnpackedFloatIterable(1, [value1, value2]);
2214    const serialized = accessor.serialize();
2215
2216    expect(serialized).toEqual(unpackedValue1Value2);
2217  });
2218
2219  it('return packed values from the input', () => {
2220    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2221
2222    const list = accessor.getRepeatedFloatIterable(1);
2223
2224    expectEqualToArray(list, [value1Float, value2]);
2225  });
2226
2227  it('ensure not the same instance returned for packed values', () => {
2228    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2229
2230    const list1 = accessor.getRepeatedFloatIterable(1);
2231    const list2 = accessor.getRepeatedFloatIterable(1);
2232
2233    expect(list1).not.toBe(list2);
2234  });
2235
2236  it('add single packed value', () => {
2237    const accessor = Kernel.createEmpty();
2238
2239    accessor.addPackedFloatElement(1, value1);
2240    const list1 = accessor.getRepeatedFloatIterable(1);
2241    accessor.addPackedFloatElement(1, value2);
2242    const list2 = accessor.getRepeatedFloatIterable(1);
2243
2244    expectEqualToArray(list1, [value1Float]);
2245    expectEqualToArray(list2, [value1Float, value2]);
2246  });
2247
2248  it('add packed values', () => {
2249    const accessor = Kernel.createEmpty();
2250
2251    accessor.addPackedFloatIterable(1, [value1]);
2252    const list1 = accessor.getRepeatedFloatIterable(1);
2253    accessor.addPackedFloatIterable(1, [value2]);
2254    const list2 = accessor.getRepeatedFloatIterable(1);
2255
2256    expectEqualToArray(list1, [value1Float]);
2257    expectEqualToArray(list2, [value1Float, value2]);
2258  });
2259
2260  it('set a single packed value', () => {
2261    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2262
2263    accessor.setPackedFloatElement(1, 1, value1);
2264    const list = accessor.getRepeatedFloatIterable(1);
2265
2266    expectEqualToArray(list, [value1Float, value1Float]);
2267  });
2268
2269  it('set packed values', () => {
2270    const accessor = Kernel.createEmpty();
2271
2272    accessor.setPackedFloatIterable(1, [value1]);
2273    const list1 = accessor.getRepeatedFloatIterable(1);
2274    accessor.setPackedFloatIterable(1, [value2]);
2275    const list2 = accessor.getRepeatedFloatIterable(1);
2276
2277    expectEqualToArray(list1, [value1Float]);
2278    expectEqualToArray(list2, [value2]);
2279  });
2280
2281  it('encode for adding single packed value', () => {
2282    const accessor = Kernel.createEmpty();
2283
2284    accessor.addPackedFloatElement(1, value1);
2285    accessor.addPackedFloatElement(1, value2);
2286    const serialized = accessor.serialize();
2287
2288    expect(serialized).toEqual(packedValue1Value2);
2289  });
2290
2291  it('encode for adding packed values', () => {
2292    const accessor = Kernel.createEmpty();
2293
2294    accessor.addPackedFloatIterable(1, [value1, value2]);
2295    const serialized = accessor.serialize();
2296
2297    expect(serialized).toEqual(packedValue1Value2);
2298  });
2299
2300  it('encode for setting single packed value', () => {
2301    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2302
2303    accessor.setPackedFloatElement(1, 0, value2);
2304    accessor.setPackedFloatElement(1, 1, value1);
2305
2306    const serialized = accessor.serialize();
2307
2308    expect(serialized).toEqual(packedValue2Value1);
2309  });
2310
2311  it('encode for setting packed values', () => {
2312    const accessor = Kernel.createEmpty();
2313
2314    accessor.setPackedFloatIterable(1, [value1, value2]);
2315    const serialized = accessor.serialize();
2316
2317    expect(serialized).toEqual(packedValue1Value2);
2318  });
2319
2320  it('return combined values from the input', () => {
2321    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
2322        0x0D,
2323        0xCD,
2324        0xCC,
2325        0xCC,
2326        0x3F,  // value1
2327        0x0A,
2328        0x08,  // tag
2329        0xCD,
2330        0xCC,
2331        0xCC,
2332        0x3F,  // value1
2333        0x00,
2334        0x00,
2335        0x00,
2336        0x00,  // value2
2337        0x0D,
2338        0x00,
2339        0x00,
2340        0x00,
2341        0x00,  // value2
2342        ));
2343
2344    const list = accessor.getRepeatedFloatIterable(1);
2345
2346    expectEqualToArray(list, [value1Float, value1Float, value2, value2]);
2347  });
2348
2349  it('return the repeated field element from the input', () => {
2350    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2351
2352    const result1 = accessor.getRepeatedFloatElement(
2353        /* fieldNumber= */ 1, /* index= */ 0);
2354    const result2 = accessor.getRepeatedFloatElement(
2355        /* fieldNumber= */ 1, /* index= */ 1);
2356
2357    expect(result1).toEqual(value1Float);
2358    expect(result2).toEqual(value2);
2359  });
2360
2361  it('return the size from the input', () => {
2362    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2363
2364    const size = accessor.getRepeatedFloatSize(1);
2365
2366    expect(size).toEqual(2);
2367  });
2368
2369  it('fail when getting unpacked float value with other wire types', () => {
2370    const accessor =
2371        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
2372    if (CHECK_CRITICAL_STATE) {
2373      expect(() => {
2374        accessor.getRepeatedFloatIterable(1);
2375      }).toThrowError('Expected wire type: 5 but found: 0');
2376    } else {
2377      // Note in unchecked mode we produce invalid output for invalid inputs.
2378      // This test just documents our behavior in those cases.
2379      // These values might change at any point and are not considered
2380      // what the implementation should be doing here.
2381      expectQualifiedIterable(
2382          accessor.getRepeatedFloatIterable(1),
2383          (value) => typeof value === 'number');
2384    }
2385  });
2386
2387  it('fail when adding unpacked float values with null value', () => {
2388    const accessor = Kernel.createEmpty();
2389    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2390    if (CHECK_CRITICAL_STATE) {
2391      expect(() => accessor.addUnpackedFloatIterable(1, [fakeFloat]))
2392          .toThrowError('Must be a number, but got: null');
2393    } else {
2394      // Note in unchecked mode we produce invalid output for invalid inputs.
2395      // This test just documents our behavior in those cases.
2396      // These values might change at any point and are not considered
2397      // what the implementation should be doing here.
2398      accessor.addUnpackedFloatIterable(1, [fakeFloat]);
2399      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2400    }
2401  });
2402
2403  it('fail when adding single unpacked float value with null value', () => {
2404    const accessor = Kernel.createEmpty();
2405    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2406    if (CHECK_CRITICAL_STATE) {
2407      expect(() => accessor.addUnpackedFloatElement(1, fakeFloat))
2408          .toThrowError('Must be a number, but got: null');
2409    } else {
2410      // Note in unchecked mode we produce invalid output for invalid inputs.
2411      // This test just documents our behavior in those cases.
2412      // These values might change at any point and are not considered
2413      // what the implementation should be doing here.
2414      accessor.addUnpackedFloatElement(1, fakeFloat);
2415      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2416    }
2417  });
2418
2419  it('fail when setting unpacked float values with null value', () => {
2420    const accessor = Kernel.createEmpty();
2421    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2422    if (CHECK_CRITICAL_STATE) {
2423      expect(() => accessor.setUnpackedFloatIterable(1, [fakeFloat]))
2424          .toThrowError('Must be a number, but got: null');
2425    } else {
2426      // Note in unchecked mode we produce invalid output for invalid inputs.
2427      // This test just documents our behavior in those cases.
2428      // These values might change at any point and are not considered
2429      // what the implementation should be doing here.
2430      accessor.setUnpackedFloatIterable(1, [fakeFloat]);
2431      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2432    }
2433  });
2434
2435  it('fail when setting single unpacked float value with null value', () => {
2436    const accessor =
2437        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
2438    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2439    if (CHECK_CRITICAL_STATE) {
2440      expect(() => accessor.setUnpackedFloatElement(1, 0, fakeFloat))
2441          .toThrowError('Must be a number, but got: null');
2442    } else {
2443      // Note in unchecked mode we produce invalid output for invalid inputs.
2444      // This test just documents our behavior in those cases.
2445      // These values might change at any point and are not considered
2446      // what the implementation should be doing here.
2447      accessor.setUnpackedFloatElement(1, 0, fakeFloat);
2448      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2449    }
2450  });
2451
2452  it('fail when adding packed float values with null value', () => {
2453    const accessor = Kernel.createEmpty();
2454    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2455    if (CHECK_CRITICAL_STATE) {
2456      expect(() => accessor.addPackedFloatIterable(1, [fakeFloat]))
2457          .toThrowError('Must be a number, but got: null');
2458    } else {
2459      // Note in unchecked mode we produce invalid output for invalid inputs.
2460      // This test just documents our behavior in those cases.
2461      // These values might change at any point and are not considered
2462      // what the implementation should be doing here.
2463      accessor.addPackedFloatIterable(1, [fakeFloat]);
2464      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2465    }
2466  });
2467
2468  it('fail when adding single packed float value with null value', () => {
2469    const accessor = Kernel.createEmpty();
2470    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2471    if (CHECK_CRITICAL_STATE) {
2472      expect(() => accessor.addPackedFloatElement(1, fakeFloat))
2473          .toThrowError('Must be a number, but got: null');
2474    } else {
2475      // Note in unchecked mode we produce invalid output for invalid inputs.
2476      // This test just documents our behavior in those cases.
2477      // These values might change at any point and are not considered
2478      // what the implementation should be doing here.
2479      accessor.addPackedFloatElement(1, fakeFloat);
2480      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2481    }
2482  });
2483
2484  it('fail when setting packed float values with null value', () => {
2485    const accessor = Kernel.createEmpty();
2486    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2487    if (CHECK_CRITICAL_STATE) {
2488      expect(() => accessor.setPackedFloatIterable(1, [fakeFloat]))
2489          .toThrowError('Must be a number, but got: null');
2490    } else {
2491      // Note in unchecked mode we produce invalid output for invalid inputs.
2492      // This test just documents our behavior in those cases.
2493      // These values might change at any point and are not considered
2494      // what the implementation should be doing here.
2495      accessor.setPackedFloatIterable(1, [fakeFloat]);
2496      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2497    }
2498  });
2499
2500  it('fail when setting single packed float value with null value', () => {
2501    const accessor =
2502        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
2503    const fakeFloat = /** @type {number} */ (/** @type {*} */ (null));
2504    if (CHECK_CRITICAL_STATE) {
2505      expect(() => accessor.setPackedFloatElement(1, 0, fakeFloat))
2506          .toThrowError('Must be a number, but got: null');
2507    } else {
2508      // Note in unchecked mode we produce invalid output for invalid inputs.
2509      // This test just documents our behavior in those cases.
2510      // These values might change at any point and are not considered
2511      // what the implementation should be doing here.
2512      accessor.setPackedFloatElement(1, 0, fakeFloat);
2513      expectQualifiedIterable(accessor.getRepeatedFloatIterable(1));
2514    }
2515  });
2516
2517  it('fail when setting single unpacked with out-of-bound index', () => {
2518    const accessor =
2519        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
2520    if (CHECK_CRITICAL_STATE) {
2521      expect(() => accessor.setUnpackedFloatElement(1, 1, 1))
2522          .toThrowError('Index out of bounds: index: 1 size: 1');
2523    } else {
2524      // Note in unchecked mode we produce invalid output for invalid inputs.
2525      // This test just documents our behavior in those cases.
2526      // These values might change at any point and are not considered
2527      // what the implementation should be doing here.
2528      accessor.setUnpackedFloatElement(1, 1, 1);
2529      expectQualifiedIterable(
2530          accessor.getRepeatedFloatIterable(1),
2531          (value) => typeof value === 'number');
2532    }
2533  });
2534
2535  it('fail when setting single packed with out-of-bound index', () => {
2536    const accessor =
2537        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
2538    if (CHECK_CRITICAL_STATE) {
2539      expect(() => accessor.setPackedFloatElement(1, 1, 1))
2540          .toThrowError('Index out of bounds: index: 1 size: 1');
2541    } else {
2542      // Note in unchecked mode we produce invalid output for invalid inputs.
2543      // This test just documents our behavior in those cases.
2544      // These values might change at any point and are not considered
2545      // what the implementation should be doing here.
2546      accessor.setPackedFloatElement(1, 1, 1);
2547      expectQualifiedIterable(
2548          accessor.getRepeatedFloatIterable(1),
2549          (value) => typeof value === 'number');
2550    }
2551  });
2552
2553  it('fail when getting element with out-of-range index', () => {
2554    const accessor = Kernel.createEmpty();
2555    if (CHECK_CRITICAL_STATE) {
2556      expect(() => {
2557        accessor.getRepeatedFloatElement(
2558            /* fieldNumber= */ 1, /* index= */ 0);
2559      }).toThrowError('Index out of bounds: index: 0 size: 0');
2560    } else {
2561      // Note in unchecked mode we produce invalid output for invalid inputs.
2562      // This test just documents our behavior in those cases.
2563      // These values might change at any point and are not considered
2564      // what the implementation should be doing here.
2565      expect(accessor.getRepeatedFloatElement(
2566                 /* fieldNumber= */ 1, /* index= */ 0))
2567          .toBe(undefined);
2568    }
2569  });
2570});
2571
2572describe('Kernel for repeated int32 does', () => {
2573  const value1 = 1;
2574  const value2 = 0;
2575
2576  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
2577  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
2578
2579  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
2580  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
2581
2582  it('return empty array for the empty input', () => {
2583    const accessor = Kernel.createEmpty();
2584
2585    const list = accessor.getRepeatedInt32Iterable(1);
2586
2587    expectEqualToArray(list, []);
2588  });
2589
2590  it('ensure not the same instance returned for the empty input', () => {
2591    const accessor = Kernel.createEmpty();
2592
2593    const list1 = accessor.getRepeatedInt32Iterable(1);
2594    const list2 = accessor.getRepeatedInt32Iterable(1);
2595
2596    expect(list1).not.toBe(list2);
2597  });
2598
2599  it('return size for the empty input', () => {
2600    const accessor = Kernel.createEmpty();
2601
2602    const size = accessor.getRepeatedInt32Size(1);
2603
2604    expect(size).toEqual(0);
2605  });
2606
2607  it('return unpacked values from the input', () => {
2608    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2609
2610    const list = accessor.getRepeatedInt32Iterable(1);
2611
2612    expectEqualToArray(list, [value1, value2]);
2613  });
2614
2615  it('ensure not the same instance returned for unpacked values', () => {
2616    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2617
2618    const list1 = accessor.getRepeatedInt32Iterable(1);
2619    const list2 = accessor.getRepeatedInt32Iterable(1);
2620
2621    expect(list1).not.toBe(list2);
2622  });
2623
2624  it('add single unpacked value', () => {
2625    const accessor = Kernel.createEmpty();
2626
2627    accessor.addUnpackedInt32Element(1, value1);
2628    const list1 = accessor.getRepeatedInt32Iterable(1);
2629    accessor.addUnpackedInt32Element(1, value2);
2630    const list2 = accessor.getRepeatedInt32Iterable(1);
2631
2632    expectEqualToArray(list1, [value1]);
2633    expectEqualToArray(list2, [value1, value2]);
2634  });
2635
2636  it('add unpacked values', () => {
2637    const accessor = Kernel.createEmpty();
2638
2639    accessor.addUnpackedInt32Iterable(1, [value1]);
2640    const list1 = accessor.getRepeatedInt32Iterable(1);
2641    accessor.addUnpackedInt32Iterable(1, [value2]);
2642    const list2 = accessor.getRepeatedInt32Iterable(1);
2643
2644    expectEqualToArray(list1, [value1]);
2645    expectEqualToArray(list2, [value1, value2]);
2646  });
2647
2648  it('set a single unpacked value', () => {
2649    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2650
2651    accessor.setUnpackedInt32Element(1, 1, value1);
2652    const list = accessor.getRepeatedInt32Iterable(1);
2653
2654    expectEqualToArray(list, [value1, value1]);
2655  });
2656
2657  it('set unpacked values', () => {
2658    const accessor = Kernel.createEmpty();
2659
2660    accessor.setUnpackedInt32Iterable(1, [value1]);
2661    const list = accessor.getRepeatedInt32Iterable(1);
2662
2663    expectEqualToArray(list, [value1]);
2664  });
2665
2666  it('encode for adding single unpacked value', () => {
2667    const accessor = Kernel.createEmpty();
2668
2669    accessor.addUnpackedInt32Element(1, value1);
2670    accessor.addUnpackedInt32Element(1, value2);
2671    const serialized = accessor.serialize();
2672
2673    expect(serialized).toEqual(unpackedValue1Value2);
2674  });
2675
2676  it('encode for adding unpacked values', () => {
2677    const accessor = Kernel.createEmpty();
2678
2679    accessor.addUnpackedInt32Iterable(1, [value1]);
2680    accessor.addUnpackedInt32Iterable(1, [value2]);
2681    const serialized = accessor.serialize();
2682
2683    expect(serialized).toEqual(unpackedValue1Value2);
2684  });
2685
2686  it('encode for setting single unpacked value', () => {
2687    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2688
2689    accessor.setUnpackedInt32Element(1, 0, value2);
2690    accessor.setUnpackedInt32Element(1, 1, value1);
2691    const serialized = accessor.serialize();
2692
2693    expect(serialized).toEqual(unpackedValue2Value1);
2694  });
2695
2696  it('encode for setting unpacked values', () => {
2697    const accessor = Kernel.createEmpty();
2698
2699    accessor.setUnpackedInt32Iterable(1, [value1, value2]);
2700    const serialized = accessor.serialize();
2701
2702    expect(serialized).toEqual(unpackedValue1Value2);
2703  });
2704
2705  it('return packed values from the input', () => {
2706    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2707
2708    const list = accessor.getRepeatedInt32Iterable(1);
2709
2710    expectEqualToArray(list, [value1, value2]);
2711  });
2712
2713  it('ensure not the same instance returned for packed values', () => {
2714    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
2715
2716    const list1 = accessor.getRepeatedInt32Iterable(1);
2717    const list2 = accessor.getRepeatedInt32Iterable(1);
2718
2719    expect(list1).not.toBe(list2);
2720  });
2721
2722  it('add single packed value', () => {
2723    const accessor = Kernel.createEmpty();
2724
2725    accessor.addPackedInt32Element(1, value1);
2726    const list1 = accessor.getRepeatedInt32Iterable(1);
2727    accessor.addPackedInt32Element(1, value2);
2728    const list2 = accessor.getRepeatedInt32Iterable(1);
2729
2730    expectEqualToArray(list1, [value1]);
2731    expectEqualToArray(list2, [value1, value2]);
2732  });
2733
2734  it('add packed values', () => {
2735    const accessor = Kernel.createEmpty();
2736
2737    accessor.addPackedInt32Iterable(1, [value1]);
2738    const list1 = accessor.getRepeatedInt32Iterable(1);
2739    accessor.addPackedInt32Iterable(1, [value2]);
2740    const list2 = accessor.getRepeatedInt32Iterable(1);
2741
2742    expectEqualToArray(list1, [value1]);
2743    expectEqualToArray(list2, [value1, value2]);
2744  });
2745
2746  it('set a single packed value', () => {
2747    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2748
2749    accessor.setPackedInt32Element(1, 1, value1);
2750    const list = accessor.getRepeatedInt32Iterable(1);
2751
2752    expectEqualToArray(list, [value1, value1]);
2753  });
2754
2755  it('set packed values', () => {
2756    const accessor = Kernel.createEmpty();
2757
2758    accessor.setPackedInt32Iterable(1, [value1]);
2759    const list1 = accessor.getRepeatedInt32Iterable(1);
2760    accessor.setPackedInt32Iterable(1, [value2]);
2761    const list2 = accessor.getRepeatedInt32Iterable(1);
2762
2763    expectEqualToArray(list1, [value1]);
2764    expectEqualToArray(list2, [value2]);
2765  });
2766
2767  it('encode for adding single packed value', () => {
2768    const accessor = Kernel.createEmpty();
2769
2770    accessor.addPackedInt32Element(1, value1);
2771    accessor.addPackedInt32Element(1, value2);
2772    const serialized = accessor.serialize();
2773
2774    expect(serialized).toEqual(packedValue1Value2);
2775  });
2776
2777  it('encode for adding packed values', () => {
2778    const accessor = Kernel.createEmpty();
2779
2780    accessor.addPackedInt32Iterable(1, [value1, value2]);
2781    const serialized = accessor.serialize();
2782
2783    expect(serialized).toEqual(packedValue1Value2);
2784  });
2785
2786  it('encode for setting single packed value', () => {
2787    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2788
2789    accessor.setPackedInt32Element(1, 0, value2);
2790    accessor.setPackedInt32Element(1, 1, value1);
2791
2792    const serialized = accessor.serialize();
2793
2794    expect(serialized).toEqual(packedValue2Value1);
2795  });
2796
2797  it('encode for setting packed values', () => {
2798    const accessor = Kernel.createEmpty();
2799
2800    accessor.setPackedInt32Iterable(1, [value1, value2]);
2801    const serialized = accessor.serialize();
2802
2803    expect(serialized).toEqual(packedValue1Value2);
2804  });
2805
2806  it('return combined values from the input', () => {
2807    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
2808        0x08,
2809        0x01,  // unpacked value1
2810        0x0A,
2811        0x02,
2812        0x01,
2813        0x00,  // packed value1 and value2
2814        0x08,
2815        0x00,  // unpacked value2
2816        ));
2817
2818    const list = accessor.getRepeatedInt32Iterable(1);
2819
2820    expectEqualToArray(list, [value1, value1, value2, value2]);
2821  });
2822
2823  it('return the repeated field element from the input', () => {
2824    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2825
2826    const result1 = accessor.getRepeatedInt32Element(
2827        /* fieldNumber= */ 1, /* index= */ 0);
2828    const result2 = accessor.getRepeatedInt32Element(
2829        /* fieldNumber= */ 1, /* index= */ 1);
2830
2831    expect(result1).toEqual(value1);
2832    expect(result2).toEqual(value2);
2833  });
2834
2835  it('return the size from the input', () => {
2836    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
2837
2838    const size = accessor.getRepeatedInt32Size(1);
2839
2840    expect(size).toEqual(2);
2841  });
2842
2843  it('fail when getting unpacked int32 value with other wire types', () => {
2844    const accessor =
2845        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
2846    if (CHECK_CRITICAL_STATE) {
2847      expect(() => {
2848        accessor.getRepeatedInt32Iterable(1);
2849      }).toThrowError('Expected wire type: 0 but found: 5');
2850    } else {
2851      // Note in unchecked mode we produce invalid output for invalid inputs.
2852      // This test just documents our behavior in those cases.
2853      // These values might change at any point and are not considered
2854      // what the implementation should be doing here.
2855      expectQualifiedIterable(
2856          accessor.getRepeatedInt32Iterable(1),
2857          (value) => Number.isInteger(value));
2858    }
2859  });
2860
2861  it('fail when adding unpacked int32 values with null value', () => {
2862    const accessor = Kernel.createEmpty();
2863    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2864    if (CHECK_CRITICAL_STATE) {
2865      expect(() => accessor.addUnpackedInt32Iterable(1, [fakeInt32]))
2866          .toThrowError('Must be a number, but got: null');
2867    } else {
2868      // Note in unchecked mode we produce invalid output for invalid inputs.
2869      // This test just documents our behavior in those cases.
2870      // These values might change at any point and are not considered
2871      // what the implementation should be doing here.
2872      accessor.addUnpackedInt32Iterable(1, [fakeInt32]);
2873      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2874    }
2875  });
2876
2877  it('fail when adding single unpacked int32 value with null value', () => {
2878    const accessor = Kernel.createEmpty();
2879    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2880    if (CHECK_CRITICAL_STATE) {
2881      expect(() => accessor.addUnpackedInt32Element(1, fakeInt32))
2882          .toThrowError('Must be a number, but got: null');
2883    } else {
2884      // Note in unchecked mode we produce invalid output for invalid inputs.
2885      // This test just documents our behavior in those cases.
2886      // These values might change at any point and are not considered
2887      // what the implementation should be doing here.
2888      accessor.addUnpackedInt32Element(1, fakeInt32);
2889      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2890    }
2891  });
2892
2893  it('fail when setting unpacked int32 values with null value', () => {
2894    const accessor = Kernel.createEmpty();
2895    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2896    if (CHECK_CRITICAL_STATE) {
2897      expect(() => accessor.setUnpackedInt32Iterable(1, [fakeInt32]))
2898          .toThrowError('Must be a number, but got: null');
2899    } else {
2900      // Note in unchecked mode we produce invalid output for invalid inputs.
2901      // This test just documents our behavior in those cases.
2902      // These values might change at any point and are not considered
2903      // what the implementation should be doing here.
2904      accessor.setUnpackedInt32Iterable(1, [fakeInt32]);
2905      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2906    }
2907  });
2908
2909  it('fail when setting single unpacked int32 value with null value', () => {
2910    const accessor =
2911        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
2912    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2913    if (CHECK_CRITICAL_STATE) {
2914      expect(() => accessor.setUnpackedInt32Element(1, 0, fakeInt32))
2915          .toThrowError('Must be a number, but got: null');
2916    } else {
2917      // Note in unchecked mode we produce invalid output for invalid inputs.
2918      // This test just documents our behavior in those cases.
2919      // These values might change at any point and are not considered
2920      // what the implementation should be doing here.
2921      accessor.setUnpackedInt32Element(1, 0, fakeInt32);
2922      expectQualifiedIterable(
2923          accessor.getRepeatedInt32Iterable(1),
2924      );
2925    }
2926  });
2927
2928  it('fail when adding packed int32 values with null value', () => {
2929    const accessor = Kernel.createEmpty();
2930    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2931    if (CHECK_CRITICAL_STATE) {
2932      expect(() => accessor.addPackedInt32Iterable(1, [fakeInt32]))
2933          .toThrowError('Must be a number, but got: null');
2934    } else {
2935      // Note in unchecked mode we produce invalid output for invalid inputs.
2936      // This test just documents our behavior in those cases.
2937      // These values might change at any point and are not considered
2938      // what the implementation should be doing here.
2939      accessor.addPackedInt32Iterable(1, [fakeInt32]);
2940      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2941    }
2942  });
2943
2944  it('fail when adding single packed int32 value with null value', () => {
2945    const accessor = Kernel.createEmpty();
2946    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2947    if (CHECK_CRITICAL_STATE) {
2948      expect(() => accessor.addPackedInt32Element(1, fakeInt32))
2949          .toThrowError('Must be a number, but got: null');
2950    } else {
2951      // Note in unchecked mode we produce invalid output for invalid inputs.
2952      // This test just documents our behavior in those cases.
2953      // These values might change at any point and are not considered
2954      // what the implementation should be doing here.
2955      accessor.addPackedInt32Element(1, fakeInt32);
2956      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2957    }
2958  });
2959
2960  it('fail when setting packed int32 values with null value', () => {
2961    const accessor = Kernel.createEmpty();
2962    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2963    if (CHECK_CRITICAL_STATE) {
2964      expect(() => accessor.setPackedInt32Iterable(1, [fakeInt32]))
2965          .toThrowError('Must be a number, but got: null');
2966    } else {
2967      // Note in unchecked mode we produce invalid output for invalid inputs.
2968      // This test just documents our behavior in those cases.
2969      // These values might change at any point and are not considered
2970      // what the implementation should be doing here.
2971      accessor.setPackedInt32Iterable(1, [fakeInt32]);
2972      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2973    }
2974  });
2975
2976  it('fail when setting single packed int32 value with null value', () => {
2977    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
2978    const fakeInt32 = /** @type {number} */ (/** @type {*} */ (null));
2979    if (CHECK_CRITICAL_STATE) {
2980      expect(() => accessor.setPackedInt32Element(1, 0, fakeInt32))
2981          .toThrowError('Must be a number, but got: null');
2982    } else {
2983      // Note in unchecked mode we produce invalid output for invalid inputs.
2984      // This test just documents our behavior in those cases.
2985      // These values might change at any point and are not considered
2986      // what the implementation should be doing here.
2987      accessor.setPackedInt32Element(1, 0, fakeInt32);
2988      expectQualifiedIterable(accessor.getRepeatedInt32Iterable(1));
2989    }
2990  });
2991
2992  it('fail when setting single unpacked with out-of-bound index', () => {
2993    const accessor =
2994        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
2995    if (CHECK_CRITICAL_STATE) {
2996      expect(() => accessor.setUnpackedInt32Element(1, 1, 1))
2997          .toThrowError('Index out of bounds: index: 1 size: 1');
2998    } else {
2999      // Note in unchecked mode we produce invalid output for invalid inputs.
3000      // This test just documents our behavior in those cases.
3001      // These values might change at any point and are not considered
3002      // what the implementation should be doing here.
3003      accessor.setUnpackedInt32Element(1, 1, 1);
3004      expectQualifiedIterable(
3005          accessor.getRepeatedInt32Iterable(1),
3006          (value) => Number.isInteger(value));
3007    }
3008  });
3009
3010  it('fail when setting single packed with out-of-bound index', () => {
3011    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
3012    if (CHECK_CRITICAL_STATE) {
3013      expect(() => accessor.setPackedInt32Element(1, 1, 1))
3014          .toThrowError('Index out of bounds: index: 1 size: 1');
3015    } else {
3016      // Note in unchecked mode we produce invalid output for invalid inputs.
3017      // This test just documents our behavior in those cases.
3018      // These values might change at any point and are not considered
3019      // what the implementation should be doing here.
3020      accessor.setPackedInt32Element(1, 1, 1);
3021      expectQualifiedIterable(
3022          accessor.getRepeatedInt32Iterable(1),
3023          (value) => Number.isInteger(value));
3024    }
3025  });
3026
3027  it('fail when getting element with out-of-range index', () => {
3028    const accessor = Kernel.createEmpty();
3029    if (CHECK_CRITICAL_STATE) {
3030      expect(() => {
3031        accessor.getRepeatedInt32Element(
3032            /* fieldNumber= */ 1, /* index= */ 0);
3033      }).toThrowError('Index out of bounds: index: 0 size: 0');
3034    } else {
3035      // Note in unchecked mode we produce invalid output for invalid inputs.
3036      // This test just documents our behavior in those cases.
3037      // These values might change at any point and are not considered
3038      // what the implementation should be doing here.
3039      expect(accessor.getRepeatedInt32Element(
3040                 /* fieldNumber= */ 1, /* index= */ 0))
3041          .toBe(undefined);
3042    }
3043  });
3044});
3045
3046describe('Kernel for repeated int64 does', () => {
3047  const value1 = Int64.fromInt(1);
3048  const value2 = Int64.fromInt(0);
3049
3050  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
3051  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
3052
3053  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
3054  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
3055
3056  it('return empty array for the empty input', () => {
3057    const accessor = Kernel.createEmpty();
3058
3059    const list = accessor.getRepeatedInt64Iterable(1);
3060
3061    expectEqualToArray(list, []);
3062  });
3063
3064  it('ensure not the same instance returned for the empty input', () => {
3065    const accessor = Kernel.createEmpty();
3066
3067    const list1 = accessor.getRepeatedInt64Iterable(1);
3068    const list2 = accessor.getRepeatedInt64Iterable(1);
3069
3070    expect(list1).not.toBe(list2);
3071  });
3072
3073  it('return size for the empty input', () => {
3074    const accessor = Kernel.createEmpty();
3075
3076    const size = accessor.getRepeatedInt64Size(1);
3077
3078    expect(size).toEqual(0);
3079  });
3080
3081  it('return unpacked values from the input', () => {
3082    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3083
3084    const list = accessor.getRepeatedInt64Iterable(1);
3085
3086    expectEqualToArray(list, [value1, value2]);
3087  });
3088
3089  it('ensure not the same instance returned for unpacked values', () => {
3090    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3091
3092    const list1 = accessor.getRepeatedInt64Iterable(1);
3093    const list2 = accessor.getRepeatedInt64Iterable(1);
3094
3095    expect(list1).not.toBe(list2);
3096  });
3097
3098  it('add single unpacked value', () => {
3099    const accessor = Kernel.createEmpty();
3100
3101    accessor.addUnpackedInt64Element(1, value1);
3102    const list1 = accessor.getRepeatedInt64Iterable(1);
3103    accessor.addUnpackedInt64Element(1, value2);
3104    const list2 = accessor.getRepeatedInt64Iterable(1);
3105
3106    expectEqualToArray(list1, [value1]);
3107    expectEqualToArray(list2, [value1, value2]);
3108  });
3109
3110  it('add unpacked values', () => {
3111    const accessor = Kernel.createEmpty();
3112
3113    accessor.addUnpackedInt64Iterable(1, [value1]);
3114    const list1 = accessor.getRepeatedInt64Iterable(1);
3115    accessor.addUnpackedInt64Iterable(1, [value2]);
3116    const list2 = accessor.getRepeatedInt64Iterable(1);
3117
3118    expectEqualToArray(list1, [value1]);
3119    expectEqualToArray(list2, [value1, value2]);
3120  });
3121
3122  it('set a single unpacked value', () => {
3123    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3124
3125    accessor.setUnpackedInt64Element(1, 1, value1);
3126    const list = accessor.getRepeatedInt64Iterable(1);
3127
3128    expectEqualToArray(list, [value1, value1]);
3129  });
3130
3131  it('set unpacked values', () => {
3132    const accessor = Kernel.createEmpty();
3133
3134    accessor.setUnpackedInt64Iterable(1, [value1]);
3135    const list = accessor.getRepeatedInt64Iterable(1);
3136
3137    expectEqualToArray(list, [value1]);
3138  });
3139
3140  it('encode for adding single unpacked value', () => {
3141    const accessor = Kernel.createEmpty();
3142
3143    accessor.addUnpackedInt64Element(1, value1);
3144    accessor.addUnpackedInt64Element(1, value2);
3145    const serialized = accessor.serialize();
3146
3147    expect(serialized).toEqual(unpackedValue1Value2);
3148  });
3149
3150  it('encode for adding unpacked values', () => {
3151    const accessor = Kernel.createEmpty();
3152
3153    accessor.addUnpackedInt64Iterable(1, [value1]);
3154    accessor.addUnpackedInt64Iterable(1, [value2]);
3155    const serialized = accessor.serialize();
3156
3157    expect(serialized).toEqual(unpackedValue1Value2);
3158  });
3159
3160  it('encode for setting single unpacked value', () => {
3161    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3162
3163    accessor.setUnpackedInt64Element(1, 0, value2);
3164    accessor.setUnpackedInt64Element(1, 1, value1);
3165    const serialized = accessor.serialize();
3166
3167    expect(serialized).toEqual(unpackedValue2Value1);
3168  });
3169
3170  it('encode for setting unpacked values', () => {
3171    const accessor = Kernel.createEmpty();
3172
3173    accessor.setUnpackedInt64Iterable(1, [value1, value2]);
3174    const serialized = accessor.serialize();
3175
3176    expect(serialized).toEqual(unpackedValue1Value2);
3177  });
3178
3179  it('return packed values from the input', () => {
3180    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3181
3182    const list = accessor.getRepeatedInt64Iterable(1);
3183
3184    expectEqualToArray(list, [value1, value2]);
3185  });
3186
3187  it('ensure not the same instance returned for packed values', () => {
3188    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3189
3190    const list1 = accessor.getRepeatedInt64Iterable(1);
3191    const list2 = accessor.getRepeatedInt64Iterable(1);
3192
3193    expect(list1).not.toBe(list2);
3194  });
3195
3196  it('add single packed value', () => {
3197    const accessor = Kernel.createEmpty();
3198
3199    accessor.addPackedInt64Element(1, value1);
3200    const list1 = accessor.getRepeatedInt64Iterable(1);
3201    accessor.addPackedInt64Element(1, value2);
3202    const list2 = accessor.getRepeatedInt64Iterable(1);
3203
3204    expectEqualToArray(list1, [value1]);
3205    expectEqualToArray(list2, [value1, value2]);
3206  });
3207
3208  it('add packed values', () => {
3209    const accessor = Kernel.createEmpty();
3210
3211    accessor.addPackedInt64Iterable(1, [value1]);
3212    const list1 = accessor.getRepeatedInt64Iterable(1);
3213    accessor.addPackedInt64Iterable(1, [value2]);
3214    const list2 = accessor.getRepeatedInt64Iterable(1);
3215
3216    expectEqualToArray(list1, [value1]);
3217    expectEqualToArray(list2, [value1, value2]);
3218  });
3219
3220  it('set a single packed value', () => {
3221    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3222
3223    accessor.setPackedInt64Element(1, 1, value1);
3224    const list = accessor.getRepeatedInt64Iterable(1);
3225
3226    expectEqualToArray(list, [value1, value1]);
3227  });
3228
3229  it('set packed values', () => {
3230    const accessor = Kernel.createEmpty();
3231
3232    accessor.setPackedInt64Iterable(1, [value1]);
3233    const list1 = accessor.getRepeatedInt64Iterable(1);
3234    accessor.setPackedInt64Iterable(1, [value2]);
3235    const list2 = accessor.getRepeatedInt64Iterable(1);
3236
3237    expectEqualToArray(list1, [value1]);
3238    expectEqualToArray(list2, [value2]);
3239  });
3240
3241  it('encode for adding single packed value', () => {
3242    const accessor = Kernel.createEmpty();
3243
3244    accessor.addPackedInt64Element(1, value1);
3245    accessor.addPackedInt64Element(1, value2);
3246    const serialized = accessor.serialize();
3247
3248    expect(serialized).toEqual(packedValue1Value2);
3249  });
3250
3251  it('encode for adding packed values', () => {
3252    const accessor = Kernel.createEmpty();
3253
3254    accessor.addPackedInt64Iterable(1, [value1, value2]);
3255    const serialized = accessor.serialize();
3256
3257    expect(serialized).toEqual(packedValue1Value2);
3258  });
3259
3260  it('encode for setting single packed value', () => {
3261    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3262
3263    accessor.setPackedInt64Element(1, 0, value2);
3264    accessor.setPackedInt64Element(1, 1, value1);
3265
3266    const serialized = accessor.serialize();
3267
3268    expect(serialized).toEqual(packedValue2Value1);
3269  });
3270
3271  it('encode for setting packed values', () => {
3272    const accessor = Kernel.createEmpty();
3273
3274    accessor.setPackedInt64Iterable(1, [value1, value2]);
3275    const serialized = accessor.serialize();
3276
3277    expect(serialized).toEqual(packedValue1Value2);
3278  });
3279
3280  it('return combined values from the input', () => {
3281    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
3282        0x08,
3283        0x01,  // unpacked value1
3284        0x0A,
3285        0x02,
3286        0x01,
3287        0x00,  // packed value1 and value2
3288        0x08,
3289        0x00,  // unpacked value2
3290        ));
3291
3292    const list = accessor.getRepeatedInt64Iterable(1);
3293
3294    expectEqualToArray(list, [value1, value1, value2, value2]);
3295  });
3296
3297  it('return the repeated field element from the input', () => {
3298    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3299
3300    const result1 = accessor.getRepeatedInt64Element(
3301        /* fieldNumber= */ 1, /* index= */ 0);
3302    const result2 = accessor.getRepeatedInt64Element(
3303        /* fieldNumber= */ 1, /* index= */ 1);
3304
3305    expect(result1).toEqual(value1);
3306    expect(result2).toEqual(value2);
3307  });
3308
3309  it('return the size from the input', () => {
3310    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3311
3312    const size = accessor.getRepeatedInt64Size(1);
3313
3314    expect(size).toEqual(2);
3315  });
3316
3317  it('fail when getting unpacked int64 value with other wire types', () => {
3318    const accessor =
3319        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
3320    if (CHECK_CRITICAL_STATE) {
3321      expect(() => {
3322        accessor.getRepeatedInt64Iterable(1);
3323      }).toThrowError('Expected wire type: 0 but found: 5');
3324    } else {
3325      // Note in unchecked mode we produce invalid output for invalid inputs.
3326      // This test just documents our behavior in those cases.
3327      // These values might change at any point and are not considered
3328      // what the implementation should be doing here.
3329      expectQualifiedIterable(
3330          accessor.getRepeatedInt64Iterable(1),
3331          (value) => value instanceof Int64);
3332    }
3333  });
3334
3335  it('fail when adding unpacked int64 values with null value', () => {
3336    const accessor = Kernel.createEmpty();
3337    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3338    if (CHECK_CRITICAL_STATE) {
3339      expect(() => accessor.addUnpackedInt64Iterable(1, [fakeInt64]))
3340          .toThrowError('Must be Int64 instance, but got: null');
3341    } else {
3342      // Note in unchecked mode we produce invalid output for invalid inputs.
3343      // This test just documents our behavior in those cases.
3344      // These values might change at any point and are not considered
3345      // what the implementation should be doing here.
3346      accessor.addUnpackedInt64Iterable(1, [fakeInt64]);
3347      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3348    }
3349  });
3350
3351  it('fail when adding single unpacked int64 value with null value', () => {
3352    const accessor = Kernel.createEmpty();
3353    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3354    if (CHECK_CRITICAL_STATE) {
3355      expect(() => accessor.addUnpackedInt64Element(1, fakeInt64))
3356          .toThrowError('Must be Int64 instance, but got: null');
3357    } else {
3358      // Note in unchecked mode we produce invalid output for invalid inputs.
3359      // This test just documents our behavior in those cases.
3360      // These values might change at any point and are not considered
3361      // what the implementation should be doing here.
3362      accessor.addUnpackedInt64Element(1, fakeInt64);
3363      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3364    }
3365  });
3366
3367  it('fail when setting unpacked int64 values with null value', () => {
3368    const accessor = Kernel.createEmpty();
3369    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3370    if (CHECK_CRITICAL_STATE) {
3371      expect(() => accessor.setUnpackedInt64Iterable(1, [fakeInt64]))
3372          .toThrowError('Must be Int64 instance, but got: null');
3373    } else {
3374      // Note in unchecked mode we produce invalid output for invalid inputs.
3375      // This test just documents our behavior in those cases.
3376      // These values might change at any point and are not considered
3377      // what the implementation should be doing here.
3378      accessor.setUnpackedInt64Iterable(1, [fakeInt64]);
3379      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3380    }
3381  });
3382
3383  it('fail when setting single unpacked int64 value with null value', () => {
3384    const accessor =
3385        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
3386    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3387    if (CHECK_CRITICAL_STATE) {
3388      expect(() => accessor.setUnpackedInt64Element(1, 0, fakeInt64))
3389          .toThrowError('Must be Int64 instance, but got: null');
3390    } else {
3391      // Note in unchecked mode we produce invalid output for invalid inputs.
3392      // This test just documents our behavior in those cases.
3393      // These values might change at any point and are not considered
3394      // what the implementation should be doing here.
3395      accessor.setUnpackedInt64Element(1, 0, fakeInt64);
3396      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3397    }
3398  });
3399
3400  it('fail when adding packed int64 values with null value', () => {
3401    const accessor = Kernel.createEmpty();
3402    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3403    if (CHECK_CRITICAL_STATE) {
3404      expect(() => accessor.addPackedInt64Iterable(1, [fakeInt64]))
3405          .toThrowError('Must be Int64 instance, but got: null');
3406    } else {
3407      // Note in unchecked mode we produce invalid output for invalid inputs.
3408      // This test just documents our behavior in those cases.
3409      // These values might change at any point and are not considered
3410      // what the implementation should be doing here.
3411      accessor.addPackedInt64Iterable(1, [fakeInt64]);
3412      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3413    }
3414  });
3415
3416  it('fail when adding single packed int64 value with null value', () => {
3417    const accessor = Kernel.createEmpty();
3418    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3419    if (CHECK_CRITICAL_STATE) {
3420      expect(() => accessor.addPackedInt64Element(1, fakeInt64))
3421          .toThrowError('Must be Int64 instance, but got: null');
3422    } else {
3423      // Note in unchecked mode we produce invalid output for invalid inputs.
3424      // This test just documents our behavior in those cases.
3425      // These values might change at any point and are not considered
3426      // what the implementation should be doing here.
3427      accessor.addPackedInt64Element(1, fakeInt64);
3428      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3429    }
3430  });
3431
3432  it('fail when setting packed int64 values with null value', () => {
3433    const accessor = Kernel.createEmpty();
3434    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3435    if (CHECK_CRITICAL_STATE) {
3436      expect(() => accessor.setPackedInt64Iterable(1, [fakeInt64]))
3437          .toThrowError('Must be Int64 instance, but got: null');
3438    } else {
3439      // Note in unchecked mode we produce invalid output for invalid inputs.
3440      // This test just documents our behavior in those cases.
3441      // These values might change at any point and are not considered
3442      // what the implementation should be doing here.
3443      accessor.setPackedInt64Iterable(1, [fakeInt64]);
3444      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3445    }
3446  });
3447
3448  it('fail when setting single packed int64 value with null value', () => {
3449    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
3450    const fakeInt64 = /** @type {!Int64} */ (/** @type {*} */ (null));
3451    if (CHECK_CRITICAL_STATE) {
3452      expect(() => accessor.setPackedInt64Element(1, 0, fakeInt64))
3453          .toThrowError('Must be Int64 instance, but got: null');
3454    } else {
3455      // Note in unchecked mode we produce invalid output for invalid inputs.
3456      // This test just documents our behavior in those cases.
3457      // These values might change at any point and are not considered
3458      // what the implementation should be doing here.
3459      accessor.setPackedInt64Element(1, 0, fakeInt64);
3460      expectQualifiedIterable(accessor.getRepeatedInt64Iterable(1));
3461    }
3462  });
3463
3464  it('fail when setting single unpacked with out-of-bound index', () => {
3465    const accessor =
3466        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
3467    if (CHECK_CRITICAL_STATE) {
3468      expect(() => accessor.setUnpackedInt64Element(1, 1, Int64.fromInt(1)))
3469          .toThrowError('Index out of bounds: index: 1 size: 1');
3470    } else {
3471      // Note in unchecked mode we produce invalid output for invalid inputs.
3472      // This test just documents our behavior in those cases.
3473      // These values might change at any point and are not considered
3474      // what the implementation should be doing here.
3475      accessor.setUnpackedInt64Element(1, 1, Int64.fromInt(1));
3476      expectQualifiedIterable(
3477          accessor.getRepeatedInt64Iterable(1),
3478          (value) => value instanceof Int64);
3479    }
3480  });
3481
3482  it('fail when setting single packed with out-of-bound index', () => {
3483    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
3484    if (CHECK_CRITICAL_STATE) {
3485      expect(() => accessor.setPackedInt64Element(1, 1, Int64.fromInt(1)))
3486          .toThrowError('Index out of bounds: index: 1 size: 1');
3487    } else {
3488      // Note in unchecked mode we produce invalid output for invalid inputs.
3489      // This test just documents our behavior in those cases.
3490      // These values might change at any point and are not considered
3491      // what the implementation should be doing here.
3492      accessor.setPackedInt64Element(1, 1, Int64.fromInt(1));
3493      expectQualifiedIterable(
3494          accessor.getRepeatedInt64Iterable(1),
3495          (value) => value instanceof Int64);
3496    }
3497  });
3498
3499  it('fail when getting element with out-of-range index', () => {
3500    const accessor = Kernel.createEmpty();
3501    if (CHECK_CRITICAL_STATE) {
3502      expect(() => {
3503        accessor.getRepeatedInt64Element(
3504            /* fieldNumber= */ 1, /* index= */ 0);
3505      }).toThrowError('Index out of bounds: index: 0 size: 0');
3506    } else {
3507      // Note in unchecked mode we produce invalid output for invalid inputs.
3508      // This test just documents our behavior in those cases.
3509      // These values might change at any point and are not considered
3510      // what the implementation should be doing here.
3511      expect(accessor.getRepeatedInt64Element(
3512                 /* fieldNumber= */ 1, /* index= */ 0))
3513          .toBe(undefined);
3514    }
3515  });
3516});
3517
3518describe('Kernel for repeated sfixed32 does', () => {
3519  const value1 = 1;
3520  const value2 = 0;
3521
3522  const unpackedValue1Value2 = createArrayBuffer(
3523      0x0D, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00);
3524  const unpackedValue2Value1 = createArrayBuffer(
3525      0x0D, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x01, 0x00, 0x00, 0x00);
3526
3527  const packedValue1Value2 = createArrayBuffer(
3528      0x0A, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
3529  const packedValue2Value1 = createArrayBuffer(
3530      0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
3531
3532  it('return empty array for the empty input', () => {
3533    const accessor = Kernel.createEmpty();
3534
3535    const list = accessor.getRepeatedSfixed32Iterable(1);
3536
3537    expectEqualToArray(list, []);
3538  });
3539
3540  it('ensure not the same instance returned for the empty input', () => {
3541    const accessor = Kernel.createEmpty();
3542
3543    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3544    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3545
3546    expect(list1).not.toBe(list2);
3547  });
3548
3549  it('return size for the empty input', () => {
3550    const accessor = Kernel.createEmpty();
3551
3552    const size = accessor.getRepeatedSfixed32Size(1);
3553
3554    expect(size).toEqual(0);
3555  });
3556
3557  it('return unpacked values from the input', () => {
3558    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3559
3560    const list = accessor.getRepeatedSfixed32Iterable(1);
3561
3562    expectEqualToArray(list, [value1, value2]);
3563  });
3564
3565  it('ensure not the same instance returned for unpacked values', () => {
3566    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3567
3568    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3569    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3570
3571    expect(list1).not.toBe(list2);
3572  });
3573
3574  it('add single unpacked value', () => {
3575    const accessor = Kernel.createEmpty();
3576
3577    accessor.addUnpackedSfixed32Element(1, value1);
3578    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3579    accessor.addUnpackedSfixed32Element(1, value2);
3580    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3581
3582    expectEqualToArray(list1, [value1]);
3583    expectEqualToArray(list2, [value1, value2]);
3584  });
3585
3586  it('add unpacked values', () => {
3587    const accessor = Kernel.createEmpty();
3588
3589    accessor.addUnpackedSfixed32Iterable(1, [value1]);
3590    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3591    accessor.addUnpackedSfixed32Iterable(1, [value2]);
3592    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3593
3594    expectEqualToArray(list1, [value1]);
3595    expectEqualToArray(list2, [value1, value2]);
3596  });
3597
3598  it('set a single unpacked value', () => {
3599    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3600
3601    accessor.setUnpackedSfixed32Element(1, 1, value1);
3602    const list = accessor.getRepeatedSfixed32Iterable(1);
3603
3604    expectEqualToArray(list, [value1, value1]);
3605  });
3606
3607  it('set unpacked values', () => {
3608    const accessor = Kernel.createEmpty();
3609
3610    accessor.setUnpackedSfixed32Iterable(1, [value1]);
3611    const list = accessor.getRepeatedSfixed32Iterable(1);
3612
3613    expectEqualToArray(list, [value1]);
3614  });
3615
3616  it('encode for adding single unpacked value', () => {
3617    const accessor = Kernel.createEmpty();
3618
3619    accessor.addUnpackedSfixed32Element(1, value1);
3620    accessor.addUnpackedSfixed32Element(1, value2);
3621    const serialized = accessor.serialize();
3622
3623    expect(serialized).toEqual(unpackedValue1Value2);
3624  });
3625
3626  it('encode for adding unpacked values', () => {
3627    const accessor = Kernel.createEmpty();
3628
3629    accessor.addUnpackedSfixed32Iterable(1, [value1]);
3630    accessor.addUnpackedSfixed32Iterable(1, [value2]);
3631    const serialized = accessor.serialize();
3632
3633    expect(serialized).toEqual(unpackedValue1Value2);
3634  });
3635
3636  it('encode for setting single unpacked value', () => {
3637    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3638
3639    accessor.setUnpackedSfixed32Element(1, 0, value2);
3640    accessor.setUnpackedSfixed32Element(1, 1, value1);
3641    const serialized = accessor.serialize();
3642
3643    expect(serialized).toEqual(unpackedValue2Value1);
3644  });
3645
3646  it('encode for setting unpacked values', () => {
3647    const accessor = Kernel.createEmpty();
3648
3649    accessor.setUnpackedSfixed32Iterable(1, [value1, value2]);
3650    const serialized = accessor.serialize();
3651
3652    expect(serialized).toEqual(unpackedValue1Value2);
3653  });
3654
3655  it('return packed values from the input', () => {
3656    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3657
3658    const list = accessor.getRepeatedSfixed32Iterable(1);
3659
3660    expectEqualToArray(list, [value1, value2]);
3661  });
3662
3663  it('ensure not the same instance returned for packed values', () => {
3664    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
3665
3666    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3667    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3668
3669    expect(list1).not.toBe(list2);
3670  });
3671
3672  it('add single packed value', () => {
3673    const accessor = Kernel.createEmpty();
3674
3675    accessor.addPackedSfixed32Element(1, value1);
3676    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3677    accessor.addPackedSfixed32Element(1, value2);
3678    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3679
3680    expectEqualToArray(list1, [value1]);
3681    expectEqualToArray(list2, [value1, value2]);
3682  });
3683
3684  it('add packed values', () => {
3685    const accessor = Kernel.createEmpty();
3686
3687    accessor.addPackedSfixed32Iterable(1, [value1]);
3688    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3689    accessor.addPackedSfixed32Iterable(1, [value2]);
3690    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3691
3692    expectEqualToArray(list1, [value1]);
3693    expectEqualToArray(list2, [value1, value2]);
3694  });
3695
3696  it('set a single packed value', () => {
3697    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3698
3699    accessor.setPackedSfixed32Element(1, 1, value1);
3700    const list = accessor.getRepeatedSfixed32Iterable(1);
3701
3702    expectEqualToArray(list, [value1, value1]);
3703  });
3704
3705  it('set packed values', () => {
3706    const accessor = Kernel.createEmpty();
3707
3708    accessor.setPackedSfixed32Iterable(1, [value1]);
3709    const list1 = accessor.getRepeatedSfixed32Iterable(1);
3710    accessor.setPackedSfixed32Iterable(1, [value2]);
3711    const list2 = accessor.getRepeatedSfixed32Iterable(1);
3712
3713    expectEqualToArray(list1, [value1]);
3714    expectEqualToArray(list2, [value2]);
3715  });
3716
3717  it('encode for adding single packed value', () => {
3718    const accessor = Kernel.createEmpty();
3719
3720    accessor.addPackedSfixed32Element(1, value1);
3721    accessor.addPackedSfixed32Element(1, value2);
3722    const serialized = accessor.serialize();
3723
3724    expect(serialized).toEqual(packedValue1Value2);
3725  });
3726
3727  it('encode for adding packed values', () => {
3728    const accessor = Kernel.createEmpty();
3729
3730    accessor.addPackedSfixed32Iterable(1, [value1, value2]);
3731    const serialized = accessor.serialize();
3732
3733    expect(serialized).toEqual(packedValue1Value2);
3734  });
3735
3736  it('encode for setting single packed value', () => {
3737    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3738
3739    accessor.setPackedSfixed32Element(1, 0, value2);
3740    accessor.setPackedSfixed32Element(1, 1, value1);
3741
3742    const serialized = accessor.serialize();
3743
3744    expect(serialized).toEqual(packedValue2Value1);
3745  });
3746
3747  it('encode for setting packed values', () => {
3748    const accessor = Kernel.createEmpty();
3749
3750    accessor.setPackedSfixed32Iterable(1, [value1, value2]);
3751    const serialized = accessor.serialize();
3752
3753    expect(serialized).toEqual(packedValue1Value2);
3754  });
3755
3756  it('return combined values from the input', () => {
3757    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
3758        0x0D,
3759        0x01,
3760        0x00,
3761        0x00,
3762        0x00,  // value1
3763        0x0A,
3764        0x08,  // tag
3765        0x01,
3766        0x00,
3767        0x00,
3768        0x00,  // value1
3769        0x00,
3770        0x00,
3771        0x00,
3772        0x00,  // value2
3773        0x0D,
3774        0x00,
3775        0x00,
3776        0x00,
3777        0x00,  // value2
3778        ));
3779
3780    const list = accessor.getRepeatedSfixed32Iterable(1);
3781
3782    expectEqualToArray(list, [value1, value1, value2, value2]);
3783  });
3784
3785  it('return the repeated field element from the input', () => {
3786    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3787
3788    const result1 = accessor.getRepeatedSfixed32Element(
3789        /* fieldNumber= */ 1, /* index= */ 0);
3790    const result2 = accessor.getRepeatedSfixed32Element(
3791        /* fieldNumber= */ 1, /* index= */ 1);
3792
3793    expect(result1).toEqual(value1);
3794    expect(result2).toEqual(value2);
3795  });
3796
3797  it('return the size from the input', () => {
3798    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
3799
3800    const size = accessor.getRepeatedSfixed32Size(1);
3801
3802    expect(size).toEqual(2);
3803  });
3804
3805  it('fail when getting unpacked sfixed32 value with other wire types', () => {
3806    const accessor =
3807        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
3808    if (CHECK_CRITICAL_STATE) {
3809      expect(() => {
3810        accessor.getRepeatedSfixed32Iterable(1);
3811      }).toThrowError('Expected wire type: 5 but found: 0');
3812    } else {
3813      // Note in unchecked mode we produce invalid output for invalid inputs.
3814      // This test just documents our behavior in those cases.
3815      // These values might change at any point and are not considered
3816      // what the implementation should be doing here.
3817      expectQualifiedIterable(
3818          accessor.getRepeatedSfixed32Iterable(1),
3819          (value) => typeof value === 'number');
3820    }
3821  });
3822
3823  it('fail when adding unpacked sfixed32 values with null value', () => {
3824    const accessor = Kernel.createEmpty();
3825    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3826    if (CHECK_CRITICAL_STATE) {
3827      expect(() => accessor.addUnpackedSfixed32Iterable(1, [fakeSfixed32]))
3828          .toThrowError('Must be a number, but got: null');
3829    } else {
3830      // Note in unchecked mode we produce invalid output for invalid inputs.
3831      // This test just documents our behavior in those cases.
3832      // These values might change at any point and are not considered
3833      // what the implementation should be doing here.
3834      accessor.addUnpackedSfixed32Iterable(1, [fakeSfixed32]);
3835      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3836    }
3837  });
3838
3839  it('fail when adding single unpacked sfixed32 value with null value', () => {
3840    const accessor = Kernel.createEmpty();
3841    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3842    if (CHECK_CRITICAL_STATE) {
3843      expect(() => accessor.addUnpackedSfixed32Element(1, fakeSfixed32))
3844          .toThrowError('Must be a number, but got: null');
3845    } else {
3846      // Note in unchecked mode we produce invalid output for invalid inputs.
3847      // This test just documents our behavior in those cases.
3848      // These values might change at any point and are not considered
3849      // what the implementation should be doing here.
3850      accessor.addUnpackedSfixed32Element(1, fakeSfixed32);
3851      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3852    }
3853  });
3854
3855  it('fail when setting unpacked sfixed32 values with null value', () => {
3856    const accessor = Kernel.createEmpty();
3857    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3858    if (CHECK_CRITICAL_STATE) {
3859      expect(() => accessor.setUnpackedSfixed32Iterable(1, [fakeSfixed32]))
3860          .toThrowError('Must be a number, but got: null');
3861    } else {
3862      // Note in unchecked mode we produce invalid output for invalid inputs.
3863      // This test just documents our behavior in those cases.
3864      // These values might change at any point and are not considered
3865      // what the implementation should be doing here.
3866      accessor.setUnpackedSfixed32Iterable(1, [fakeSfixed32]);
3867      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3868    }
3869  });
3870
3871  it('fail when setting single unpacked sfixed32 value with null value', () => {
3872    const accessor =
3873        Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x80, 0x80, 0x80, 0x00));
3874    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3875    if (CHECK_CRITICAL_STATE) {
3876      expect(() => accessor.setUnpackedSfixed32Element(1, 0, fakeSfixed32))
3877          .toThrowError('Must be a number, but got: null');
3878    } else {
3879      // Note in unchecked mode we produce invalid output for invalid inputs.
3880      // This test just documents our behavior in those cases.
3881      // These values might change at any point and are not considered
3882      // what the implementation should be doing here.
3883      accessor.setUnpackedSfixed32Element(1, 0, fakeSfixed32);
3884      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3885    }
3886  });
3887
3888  it('fail when adding packed sfixed32 values with null value', () => {
3889    const accessor = Kernel.createEmpty();
3890    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3891    if (CHECK_CRITICAL_STATE) {
3892      expect(() => accessor.addPackedSfixed32Iterable(1, [fakeSfixed32]))
3893          .toThrowError('Must be a number, but got: null');
3894    } else {
3895      // Note in unchecked mode we produce invalid output for invalid inputs.
3896      // This test just documents our behavior in those cases.
3897      // These values might change at any point and are not considered
3898      // what the implementation should be doing here.
3899      accessor.addPackedSfixed32Iterable(1, [fakeSfixed32]);
3900      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3901    }
3902  });
3903
3904  it('fail when adding single packed sfixed32 value with null value', () => {
3905    const accessor = Kernel.createEmpty();
3906    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3907    if (CHECK_CRITICAL_STATE) {
3908      expect(() => accessor.addPackedSfixed32Element(1, fakeSfixed32))
3909          .toThrowError('Must be a number, but got: null');
3910    } else {
3911      // Note in unchecked mode we produce invalid output for invalid inputs.
3912      // This test just documents our behavior in those cases.
3913      // These values might change at any point and are not considered
3914      // what the implementation should be doing here.
3915      accessor.addPackedSfixed32Element(1, fakeSfixed32);
3916      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3917    }
3918  });
3919
3920  it('fail when setting packed sfixed32 values with null value', () => {
3921    const accessor = Kernel.createEmpty();
3922    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3923    if (CHECK_CRITICAL_STATE) {
3924      expect(() => accessor.setPackedSfixed32Iterable(1, [fakeSfixed32]))
3925          .toThrowError('Must be a number, but got: null');
3926    } else {
3927      // Note in unchecked mode we produce invalid output for invalid inputs.
3928      // This test just documents our behavior in those cases.
3929      // These values might change at any point and are not considered
3930      // what the implementation should be doing here.
3931      accessor.setPackedSfixed32Iterable(1, [fakeSfixed32]);
3932      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3933    }
3934  });
3935
3936  it('fail when setting single packed sfixed32 value with null value', () => {
3937    const accessor =
3938        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
3939    const fakeSfixed32 = /** @type {number} */ (/** @type {*} */ (null));
3940    if (CHECK_CRITICAL_STATE) {
3941      expect(() => accessor.setPackedSfixed32Element(1, 0, fakeSfixed32))
3942          .toThrowError('Must be a number, but got: null');
3943    } else {
3944      // Note in unchecked mode we produce invalid output for invalid inputs.
3945      // This test just documents our behavior in those cases.
3946      // These values might change at any point and are not considered
3947      // what the implementation should be doing here.
3948      accessor.setPackedSfixed32Element(1, 0, fakeSfixed32);
3949      expectQualifiedIterable(accessor.getRepeatedSfixed32Iterable(1));
3950    }
3951  });
3952
3953  it('fail when setting single unpacked with out-of-bound index', () => {
3954    const accessor =
3955        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
3956    if (CHECK_CRITICAL_STATE) {
3957      expect(() => accessor.setUnpackedSfixed32Element(1, 1, 1))
3958          .toThrowError('Index out of bounds: index: 1 size: 1');
3959    } else {
3960      // Note in unchecked mode we produce invalid output for invalid inputs.
3961      // This test just documents our behavior in those cases.
3962      // These values might change at any point and are not considered
3963      // what the implementation should be doing here.
3964      accessor.setUnpackedSfixed32Element(1, 1, 1);
3965      expectQualifiedIterable(
3966          accessor.getRepeatedSfixed32Iterable(1),
3967          (value) => typeof value === 'number');
3968    }
3969  });
3970
3971  it('fail when setting single packed with out-of-bound index', () => {
3972    const accessor =
3973        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x00, 0x00, 0x00, 0x00));
3974    if (CHECK_CRITICAL_STATE) {
3975      expect(() => accessor.setPackedSfixed32Element(1, 1, 1))
3976          .toThrowError('Index out of bounds: index: 1 size: 1');
3977    } else {
3978      // Note in unchecked mode we produce invalid output for invalid inputs.
3979      // This test just documents our behavior in those cases.
3980      // These values might change at any point and are not considered
3981      // what the implementation should be doing here.
3982      accessor.setPackedSfixed32Element(1, 1, 1);
3983      expectQualifiedIterable(
3984          accessor.getRepeatedSfixed32Iterable(1),
3985          (value) => typeof value === 'number');
3986    }
3987  });
3988
3989  it('fail when getting element with out-of-range index', () => {
3990    const accessor = Kernel.createEmpty();
3991    if (CHECK_CRITICAL_STATE) {
3992      expect(() => {
3993        accessor.getRepeatedSfixed32Element(
3994            /* fieldNumber= */ 1, /* index= */ 0);
3995      }).toThrowError('Index out of bounds: index: 0 size: 0');
3996    } else {
3997      // Note in unchecked mode we produce invalid output for invalid inputs.
3998      // This test just documents our behavior in those cases.
3999      // These values might change at any point and are not considered
4000      // what the implementation should be doing here.
4001      expect(accessor.getRepeatedSfixed32Element(
4002                 /* fieldNumber= */ 1, /* index= */ 0))
4003          .toBe(undefined);
4004    }
4005  });
4006});
4007
4008describe('Kernel for repeated sfixed64 does', () => {
4009  const value1 = Int64.fromInt(1);
4010  const value2 = Int64.fromInt(0);
4011
4012  const unpackedValue1Value2 = createArrayBuffer(
4013      0x09,
4014      0x01,
4015      0x00,
4016      0x00,
4017      0x00,
4018      0x00,
4019      0x00,
4020      0x00,
4021      0x00,  // value1
4022      0x09,
4023      0x00,
4024      0x00,
4025      0x00,
4026      0x00,
4027      0x00,
4028      0x00,
4029      0x00,
4030      0x00,  // value2
4031  );
4032  const unpackedValue2Value1 = createArrayBuffer(
4033      0x09,
4034      0x00,
4035      0x00,
4036      0x00,
4037      0x00,
4038      0x00,
4039      0x00,
4040      0x00,
4041      0x00,  // value1
4042      0x09,
4043      0x01,
4044      0x00,
4045      0x00,
4046      0x00,
4047      0x00,
4048      0x00,
4049      0x00,
4050      0x00,  // value2
4051  );
4052
4053  const packedValue1Value2 = createArrayBuffer(
4054      0x0A,
4055      0x10,  // tag
4056      0x01,
4057      0x00,
4058      0x00,
4059      0x00,
4060      0x00,
4061      0x00,
4062      0x00,
4063      0x00,  // value1
4064      0x00,
4065      0x00,
4066      0x00,
4067      0x00,
4068      0x00,
4069      0x00,
4070      0x00,
4071      0x00,  // value2
4072  );
4073  const packedValue2Value1 = createArrayBuffer(
4074      0x0A,
4075      0x10,  // tag
4076      0x00,
4077      0x00,
4078      0x00,
4079      0x00,
4080      0x00,
4081      0x00,
4082      0x00,
4083      0x00,  // value2
4084      0x01,
4085      0x00,
4086      0x00,
4087      0x00,
4088      0x00,
4089      0x00,
4090      0x00,
4091      0x00,  // value1
4092  );
4093
4094  it('return empty array for the empty input', () => {
4095    const accessor = Kernel.createEmpty();
4096
4097    const list = accessor.getRepeatedSfixed64Iterable(1);
4098
4099    expectEqualToArray(list, []);
4100  });
4101
4102  it('ensure not the same instance returned for the empty input', () => {
4103    const accessor = Kernel.createEmpty();
4104
4105    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4106    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4107
4108    expect(list1).not.toBe(list2);
4109  });
4110
4111  it('return size for the empty input', () => {
4112    const accessor = Kernel.createEmpty();
4113
4114    const size = accessor.getRepeatedSfixed64Size(1);
4115
4116    expect(size).toEqual(0);
4117  });
4118
4119  it('return unpacked values from the input', () => {
4120    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4121
4122    const list = accessor.getRepeatedSfixed64Iterable(1);
4123
4124    expectEqualToArray(list, [value1, value2]);
4125  });
4126
4127  it('ensure not the same instance returned for unpacked values', () => {
4128    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4129
4130    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4131    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4132
4133    expect(list1).not.toBe(list2);
4134  });
4135
4136  it('add single unpacked value', () => {
4137    const accessor = Kernel.createEmpty();
4138
4139    accessor.addUnpackedSfixed64Element(1, value1);
4140    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4141    accessor.addUnpackedSfixed64Element(1, value2);
4142    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4143
4144    expectEqualToArray(list1, [value1]);
4145    expectEqualToArray(list2, [value1, value2]);
4146  });
4147
4148  it('add unpacked values', () => {
4149    const accessor = Kernel.createEmpty();
4150
4151    accessor.addUnpackedSfixed64Iterable(1, [value1]);
4152    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4153    accessor.addUnpackedSfixed64Iterable(1, [value2]);
4154    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4155
4156    expectEqualToArray(list1, [value1]);
4157    expectEqualToArray(list2, [value1, value2]);
4158  });
4159
4160  it('set a single unpacked value', () => {
4161    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4162
4163    accessor.setUnpackedSfixed64Element(1, 1, value1);
4164    const list = accessor.getRepeatedSfixed64Iterable(1);
4165
4166    expectEqualToArray(list, [value1, value1]);
4167  });
4168
4169  it('set unpacked values', () => {
4170    const accessor = Kernel.createEmpty();
4171
4172    accessor.setUnpackedSfixed64Iterable(1, [value1]);
4173    const list = accessor.getRepeatedSfixed64Iterable(1);
4174
4175    expectEqualToArray(list, [value1]);
4176  });
4177
4178  it('encode for adding single unpacked value', () => {
4179    const accessor = Kernel.createEmpty();
4180
4181    accessor.addUnpackedSfixed64Element(1, value1);
4182    accessor.addUnpackedSfixed64Element(1, value2);
4183    const serialized = accessor.serialize();
4184
4185    expect(serialized).toEqual(unpackedValue1Value2);
4186  });
4187
4188  it('encode for adding unpacked values', () => {
4189    const accessor = Kernel.createEmpty();
4190
4191    accessor.addUnpackedSfixed64Iterable(1, [value1]);
4192    accessor.addUnpackedSfixed64Iterable(1, [value2]);
4193    const serialized = accessor.serialize();
4194
4195    expect(serialized).toEqual(unpackedValue1Value2);
4196  });
4197
4198  it('encode for setting single unpacked value', () => {
4199    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4200
4201    accessor.setUnpackedSfixed64Element(1, 0, value2);
4202    accessor.setUnpackedSfixed64Element(1, 1, value1);
4203    const serialized = accessor.serialize();
4204
4205    expect(serialized).toEqual(unpackedValue2Value1);
4206  });
4207
4208  it('encode for setting unpacked values', () => {
4209    const accessor = Kernel.createEmpty();
4210
4211    accessor.setUnpackedSfixed64Iterable(1, [value1, value2]);
4212    const serialized = accessor.serialize();
4213
4214    expect(serialized).toEqual(unpackedValue1Value2);
4215  });
4216
4217  it('return packed values from the input', () => {
4218    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4219
4220    const list = accessor.getRepeatedSfixed64Iterable(1);
4221
4222    expectEqualToArray(list, [value1, value2]);
4223  });
4224
4225  it('ensure not the same instance returned for packed values', () => {
4226    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4227
4228    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4229    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4230
4231    expect(list1).not.toBe(list2);
4232  });
4233
4234  it('add single packed value', () => {
4235    const accessor = Kernel.createEmpty();
4236
4237    accessor.addPackedSfixed64Element(1, value1);
4238    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4239    accessor.addPackedSfixed64Element(1, value2);
4240    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4241
4242    expectEqualToArray(list1, [value1]);
4243    expectEqualToArray(list2, [value1, value2]);
4244  });
4245
4246  it('add packed values', () => {
4247    const accessor = Kernel.createEmpty();
4248
4249    accessor.addPackedSfixed64Iterable(1, [value1]);
4250    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4251    accessor.addPackedSfixed64Iterable(1, [value2]);
4252    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4253
4254    expectEqualToArray(list1, [value1]);
4255    expectEqualToArray(list2, [value1, value2]);
4256  });
4257
4258  it('set a single packed value', () => {
4259    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4260
4261    accessor.setPackedSfixed64Element(1, 1, value1);
4262    const list = accessor.getRepeatedSfixed64Iterable(1);
4263
4264    expectEqualToArray(list, [value1, value1]);
4265  });
4266
4267  it('set packed values', () => {
4268    const accessor = Kernel.createEmpty();
4269
4270    accessor.setPackedSfixed64Iterable(1, [value1]);
4271    const list1 = accessor.getRepeatedSfixed64Iterable(1);
4272    accessor.setPackedSfixed64Iterable(1, [value2]);
4273    const list2 = accessor.getRepeatedSfixed64Iterable(1);
4274
4275    expectEqualToArray(list1, [value1]);
4276    expectEqualToArray(list2, [value2]);
4277  });
4278
4279  it('encode for adding single packed value', () => {
4280    const accessor = Kernel.createEmpty();
4281
4282    accessor.addPackedSfixed64Element(1, value1);
4283    accessor.addPackedSfixed64Element(1, value2);
4284    const serialized = accessor.serialize();
4285
4286    expect(serialized).toEqual(packedValue1Value2);
4287  });
4288
4289  it('encode for adding packed values', () => {
4290    const accessor = Kernel.createEmpty();
4291
4292    accessor.addPackedSfixed64Iterable(1, [value1, value2]);
4293    const serialized = accessor.serialize();
4294
4295    expect(serialized).toEqual(packedValue1Value2);
4296  });
4297
4298  it('encode for setting single packed value', () => {
4299    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4300
4301    accessor.setPackedSfixed64Element(1, 0, value2);
4302    accessor.setPackedSfixed64Element(1, 1, value1);
4303
4304    const serialized = accessor.serialize();
4305
4306    expect(serialized).toEqual(packedValue2Value1);
4307  });
4308
4309  it('encode for setting packed values', () => {
4310    const accessor = Kernel.createEmpty();
4311
4312    accessor.setPackedSfixed64Iterable(1, [value1, value2]);
4313    const serialized = accessor.serialize();
4314
4315    expect(serialized).toEqual(packedValue1Value2);
4316  });
4317
4318  it('return combined values from the input', () => {
4319    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4320        0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // value1
4321        0x0A, 0x10,                                            // tag
4322        0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        // value1
4323        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        // value2
4324        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // value2
4325        ));
4326
4327    const list = accessor.getRepeatedSfixed64Iterable(1);
4328
4329    expectEqualToArray(list, [value1, value1, value2, value2]);
4330  });
4331
4332  it('return the repeated field element from the input', () => {
4333    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4334
4335    const result1 = accessor.getRepeatedSfixed64Element(
4336        /* fieldNumber= */ 1, /* index= */ 0);
4337    const result2 = accessor.getRepeatedSfixed64Element(
4338        /* fieldNumber= */ 1, /* index= */ 1);
4339
4340    expect(result1).toEqual(value1);
4341    expect(result2).toEqual(value2);
4342  });
4343
4344  it('return the size from the input', () => {
4345    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4346
4347    const size = accessor.getRepeatedSfixed64Size(1);
4348
4349    expect(size).toEqual(2);
4350  });
4351
4352  it('fail when getting unpacked sfixed64 value with other wire types', () => {
4353    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4354        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
4355    if (CHECK_CRITICAL_STATE) {
4356      expect(() => {
4357        accessor.getRepeatedSfixed64Iterable(1);
4358      }).toThrowError('Expected wire type: 1 but found: 0');
4359    } else {
4360      // Note in unchecked mode we produce invalid output for invalid inputs.
4361      // This test just documents our behavior in those cases.
4362      // These values might change at any point and are not considered
4363      // what the implementation should be doing here.
4364      expectQualifiedIterable(
4365          accessor.getRepeatedSfixed64Iterable(1),
4366          (value) => value instanceof Int64);
4367    }
4368  });
4369
4370  it('fail when adding unpacked sfixed64 values with null value', () => {
4371    const accessor = Kernel.createEmpty();
4372    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4373    if (CHECK_CRITICAL_STATE) {
4374      expect(() => accessor.addUnpackedSfixed64Iterable(1, [fakeSfixed64]))
4375          .toThrowError('Must be Int64 instance, but got: null');
4376    } else {
4377      // Note in unchecked mode we produce invalid output for invalid inputs.
4378      // This test just documents our behavior in those cases.
4379      // These values might change at any point and are not considered
4380      // what the implementation should be doing here.
4381      accessor.addUnpackedSfixed64Iterable(1, [fakeSfixed64]);
4382      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4383    }
4384  });
4385
4386  it('fail when adding single unpacked sfixed64 value with null value', () => {
4387    const accessor = Kernel.createEmpty();
4388    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4389    if (CHECK_CRITICAL_STATE) {
4390      expect(() => accessor.addUnpackedSfixed64Element(1, fakeSfixed64))
4391          .toThrowError('Must be Int64 instance, but got: null');
4392    } else {
4393      // Note in unchecked mode we produce invalid output for invalid inputs.
4394      // This test just documents our behavior in those cases.
4395      // These values might change at any point and are not considered
4396      // what the implementation should be doing here.
4397      accessor.addUnpackedSfixed64Element(1, fakeSfixed64);
4398      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4399    }
4400  });
4401
4402  it('fail when setting unpacked sfixed64 values with null value', () => {
4403    const accessor = Kernel.createEmpty();
4404    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4405    if (CHECK_CRITICAL_STATE) {
4406      expect(() => accessor.setUnpackedSfixed64Iterable(1, [fakeSfixed64]))
4407          .toThrowError('Must be Int64 instance, but got: null');
4408    } else {
4409      // Note in unchecked mode we produce invalid output for invalid inputs.
4410      // This test just documents our behavior in those cases.
4411      // These values might change at any point and are not considered
4412      // what the implementation should be doing here.
4413      accessor.setUnpackedSfixed64Iterable(1, [fakeSfixed64]);
4414      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4415    }
4416  });
4417
4418  it('fail when setting single unpacked sfixed64 value with null value', () => {
4419    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4420        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
4421    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4422    if (CHECK_CRITICAL_STATE) {
4423      expect(() => accessor.setUnpackedSfixed64Element(1, 0, fakeSfixed64))
4424          .toThrowError('Must be Int64 instance, but got: null');
4425    } else {
4426      // Note in unchecked mode we produce invalid output for invalid inputs.
4427      // This test just documents our behavior in those cases.
4428      // These values might change at any point and are not considered
4429      // what the implementation should be doing here.
4430      accessor.setUnpackedSfixed64Element(1, 0, fakeSfixed64);
4431      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4432    }
4433  });
4434
4435  it('fail when adding packed sfixed64 values with null value', () => {
4436    const accessor = Kernel.createEmpty();
4437    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4438    if (CHECK_CRITICAL_STATE) {
4439      expect(() => accessor.addPackedSfixed64Iterable(1, [fakeSfixed64]))
4440          .toThrowError('Must be Int64 instance, but got: null');
4441    } else {
4442      // Note in unchecked mode we produce invalid output for invalid inputs.
4443      // This test just documents our behavior in those cases.
4444      // These values might change at any point and are not considered
4445      // what the implementation should be doing here.
4446      accessor.addPackedSfixed64Iterable(1, [fakeSfixed64]);
4447      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4448    }
4449  });
4450
4451  it('fail when adding single packed sfixed64 value with null value', () => {
4452    const accessor = Kernel.createEmpty();
4453    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4454    if (CHECK_CRITICAL_STATE) {
4455      expect(() => accessor.addPackedSfixed64Element(1, fakeSfixed64))
4456          .toThrowError('Must be Int64 instance, but got: null');
4457    } else {
4458      // Note in unchecked mode we produce invalid output for invalid inputs.
4459      // This test just documents our behavior in those cases.
4460      // These values might change at any point and are not considered
4461      // what the implementation should be doing here.
4462      accessor.addPackedSfixed64Element(1, fakeSfixed64);
4463      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4464    }
4465  });
4466
4467  it('fail when setting packed sfixed64 values with null value', () => {
4468    const accessor = Kernel.createEmpty();
4469    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4470    if (CHECK_CRITICAL_STATE) {
4471      expect(() => accessor.setPackedSfixed64Iterable(1, [fakeSfixed64]))
4472          .toThrowError('Must be Int64 instance, but got: null');
4473    } else {
4474      // Note in unchecked mode we produce invalid output for invalid inputs.
4475      // This test just documents our behavior in those cases.
4476      // These values might change at any point and are not considered
4477      // what the implementation should be doing here.
4478      accessor.setPackedSfixed64Iterable(1, [fakeSfixed64]);
4479      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4480    }
4481  });
4482
4483  it('fail when setting single packed sfixed64 value with null value', () => {
4484    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4485        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
4486    const fakeSfixed64 = /** @type {!Int64} */ (/** @type {*} */ (null));
4487    if (CHECK_CRITICAL_STATE) {
4488      expect(() => accessor.setPackedSfixed64Element(1, 0, fakeSfixed64))
4489          .toThrowError('Must be Int64 instance, but got: null');
4490    } else {
4491      // Note in unchecked mode we produce invalid output for invalid inputs.
4492      // This test just documents our behavior in those cases.
4493      // These values might change at any point and are not considered
4494      // what the implementation should be doing here.
4495      accessor.setPackedSfixed64Element(1, 0, fakeSfixed64);
4496      expectQualifiedIterable(accessor.getRepeatedSfixed64Iterable(1));
4497    }
4498  });
4499
4500  it('fail when setting single unpacked with out-of-bound index', () => {
4501    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4502        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
4503    if (CHECK_CRITICAL_STATE) {
4504      expect(() => accessor.setUnpackedSfixed64Element(1, 1, Int64.fromInt(1)))
4505          .toThrowError('Index out of bounds: index: 1 size: 1');
4506    } else {
4507      // Note in unchecked mode we produce invalid output for invalid inputs.
4508      // This test just documents our behavior in those cases.
4509      // These values might change at any point and are not considered
4510      // what the implementation should be doing here.
4511      accessor.setUnpackedSfixed64Element(1, 1, Int64.fromInt(1));
4512      expectQualifiedIterable(
4513          accessor.getRepeatedSfixed64Iterable(1),
4514          (value) => value instanceof Int64);
4515    }
4516  });
4517
4518  it('fail when setting single packed with out-of-bound index', () => {
4519    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4520        0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
4521    if (CHECK_CRITICAL_STATE) {
4522      expect(() => accessor.setPackedSfixed64Element(1, 1, Int64.fromInt(1)))
4523          .toThrowError('Index out of bounds: index: 1 size: 1');
4524    } else {
4525      // Note in unchecked mode we produce invalid output for invalid inputs.
4526      // This test just documents our behavior in those cases.
4527      // These values might change at any point and are not considered
4528      // what the implementation should be doing here.
4529      accessor.setPackedSfixed64Element(1, 1, Int64.fromInt(1));
4530      expectQualifiedIterable(
4531          accessor.getRepeatedSfixed64Iterable(1),
4532          (value) => value instanceof Int64);
4533    }
4534  });
4535
4536  it('fail when getting element with out-of-range index', () => {
4537    const accessor = Kernel.createEmpty();
4538    if (CHECK_CRITICAL_STATE) {
4539      expect(() => {
4540        accessor.getRepeatedSfixed64Element(
4541            /* fieldNumber= */ 1, /* index= */ 0);
4542      }).toThrowError('Index out of bounds: index: 0 size: 0');
4543    } else {
4544      // Note in unchecked mode we produce invalid output for invalid inputs.
4545      // This test just documents our behavior in those cases.
4546      // These values might change at any point and are not considered
4547      // what the implementation should be doing here.
4548      expect(accessor.getRepeatedSfixed64Element(
4549                 /* fieldNumber= */ 1, /* index= */ 0))
4550          .toBe(undefined);
4551    }
4552  });
4553});
4554
4555describe('Kernel for repeated sint32 does', () => {
4556  const value1 = -1;
4557  const value2 = 0;
4558
4559  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
4560  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
4561
4562  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
4563  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
4564
4565  it('return empty array for the empty input', () => {
4566    const accessor = Kernel.createEmpty();
4567
4568    const list = accessor.getRepeatedSint32Iterable(1);
4569
4570    expectEqualToArray(list, []);
4571  });
4572
4573  it('ensure not the same instance returned for the empty input', () => {
4574    const accessor = Kernel.createEmpty();
4575
4576    const list1 = accessor.getRepeatedSint32Iterable(1);
4577    const list2 = accessor.getRepeatedSint32Iterable(1);
4578
4579    expect(list1).not.toBe(list2);
4580  });
4581
4582  it('return size for the empty input', () => {
4583    const accessor = Kernel.createEmpty();
4584
4585    const size = accessor.getRepeatedSint32Size(1);
4586
4587    expect(size).toEqual(0);
4588  });
4589
4590  it('return unpacked values from the input', () => {
4591    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4592
4593    const list = accessor.getRepeatedSint32Iterable(1);
4594
4595    expectEqualToArray(list, [value1, value2]);
4596  });
4597
4598  it('ensure not the same instance returned for unpacked values', () => {
4599    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4600
4601    const list1 = accessor.getRepeatedSint32Iterable(1);
4602    const list2 = accessor.getRepeatedSint32Iterable(1);
4603
4604    expect(list1).not.toBe(list2);
4605  });
4606
4607  it('add single unpacked value', () => {
4608    const accessor = Kernel.createEmpty();
4609
4610    accessor.addUnpackedSint32Element(1, value1);
4611    const list1 = accessor.getRepeatedSint32Iterable(1);
4612    accessor.addUnpackedSint32Element(1, value2);
4613    const list2 = accessor.getRepeatedSint32Iterable(1);
4614
4615    expectEqualToArray(list1, [value1]);
4616    expectEqualToArray(list2, [value1, value2]);
4617  });
4618
4619  it('add unpacked values', () => {
4620    const accessor = Kernel.createEmpty();
4621
4622    accessor.addUnpackedSint32Iterable(1, [value1]);
4623    const list1 = accessor.getRepeatedSint32Iterable(1);
4624    accessor.addUnpackedSint32Iterable(1, [value2]);
4625    const list2 = accessor.getRepeatedSint32Iterable(1);
4626
4627    expectEqualToArray(list1, [value1]);
4628    expectEqualToArray(list2, [value1, value2]);
4629  });
4630
4631  it('set a single unpacked value', () => {
4632    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4633
4634    accessor.setUnpackedSint32Element(1, 1, value1);
4635    const list = accessor.getRepeatedSint32Iterable(1);
4636
4637    expectEqualToArray(list, [value1, value1]);
4638  });
4639
4640  it('set unpacked values', () => {
4641    const accessor = Kernel.createEmpty();
4642
4643    accessor.setUnpackedSint32Iterable(1, [value1]);
4644    const list = accessor.getRepeatedSint32Iterable(1);
4645
4646    expectEqualToArray(list, [value1]);
4647  });
4648
4649  it('encode for adding single unpacked value', () => {
4650    const accessor = Kernel.createEmpty();
4651
4652    accessor.addUnpackedSint32Element(1, value1);
4653    accessor.addUnpackedSint32Element(1, value2);
4654    const serialized = accessor.serialize();
4655
4656    expect(serialized).toEqual(unpackedValue1Value2);
4657  });
4658
4659  it('encode for adding unpacked values', () => {
4660    const accessor = Kernel.createEmpty();
4661
4662    accessor.addUnpackedSint32Iterable(1, [value1]);
4663    accessor.addUnpackedSint32Iterable(1, [value2]);
4664    const serialized = accessor.serialize();
4665
4666    expect(serialized).toEqual(unpackedValue1Value2);
4667  });
4668
4669  it('encode for setting single unpacked value', () => {
4670    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4671
4672    accessor.setUnpackedSint32Element(1, 0, value2);
4673    accessor.setUnpackedSint32Element(1, 1, value1);
4674    const serialized = accessor.serialize();
4675
4676    expect(serialized).toEqual(unpackedValue2Value1);
4677  });
4678
4679  it('encode for setting unpacked values', () => {
4680    const accessor = Kernel.createEmpty();
4681
4682    accessor.setUnpackedSint32Iterable(1, [value1, value2]);
4683    const serialized = accessor.serialize();
4684
4685    expect(serialized).toEqual(unpackedValue1Value2);
4686  });
4687
4688  it('return packed values from the input', () => {
4689    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4690
4691    const list = accessor.getRepeatedSint32Iterable(1);
4692
4693    expectEqualToArray(list, [value1, value2]);
4694  });
4695
4696  it('ensure not the same instance returned for packed values', () => {
4697    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
4698
4699    const list1 = accessor.getRepeatedSint32Iterable(1);
4700    const list2 = accessor.getRepeatedSint32Iterable(1);
4701
4702    expect(list1).not.toBe(list2);
4703  });
4704
4705  it('add single packed value', () => {
4706    const accessor = Kernel.createEmpty();
4707
4708    accessor.addPackedSint32Element(1, value1);
4709    const list1 = accessor.getRepeatedSint32Iterable(1);
4710    accessor.addPackedSint32Element(1, value2);
4711    const list2 = accessor.getRepeatedSint32Iterable(1);
4712
4713    expectEqualToArray(list1, [value1]);
4714    expectEqualToArray(list2, [value1, value2]);
4715  });
4716
4717  it('add packed values', () => {
4718    const accessor = Kernel.createEmpty();
4719
4720    accessor.addPackedSint32Iterable(1, [value1]);
4721    const list1 = accessor.getRepeatedSint32Iterable(1);
4722    accessor.addPackedSint32Iterable(1, [value2]);
4723    const list2 = accessor.getRepeatedSint32Iterable(1);
4724
4725    expectEqualToArray(list1, [value1]);
4726    expectEqualToArray(list2, [value1, value2]);
4727  });
4728
4729  it('set a single packed value', () => {
4730    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4731
4732    accessor.setPackedSint32Element(1, 1, value1);
4733    const list = accessor.getRepeatedSint32Iterable(1);
4734
4735    expectEqualToArray(list, [value1, value1]);
4736  });
4737
4738  it('set packed values', () => {
4739    const accessor = Kernel.createEmpty();
4740
4741    accessor.setPackedSint32Iterable(1, [value1]);
4742    const list1 = accessor.getRepeatedSint32Iterable(1);
4743    accessor.setPackedSint32Iterable(1, [value2]);
4744    const list2 = accessor.getRepeatedSint32Iterable(1);
4745
4746    expectEqualToArray(list1, [value1]);
4747    expectEqualToArray(list2, [value2]);
4748  });
4749
4750  it('encode for adding single packed value', () => {
4751    const accessor = Kernel.createEmpty();
4752
4753    accessor.addPackedSint32Element(1, value1);
4754    accessor.addPackedSint32Element(1, value2);
4755    const serialized = accessor.serialize();
4756
4757    expect(serialized).toEqual(packedValue1Value2);
4758  });
4759
4760  it('encode for adding packed values', () => {
4761    const accessor = Kernel.createEmpty();
4762
4763    accessor.addPackedSint32Iterable(1, [value1, value2]);
4764    const serialized = accessor.serialize();
4765
4766    expect(serialized).toEqual(packedValue1Value2);
4767  });
4768
4769  it('encode for setting single packed value', () => {
4770    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4771
4772    accessor.setPackedSint32Element(1, 0, value2);
4773    accessor.setPackedSint32Element(1, 1, value1);
4774
4775    const serialized = accessor.serialize();
4776
4777    expect(serialized).toEqual(packedValue2Value1);
4778  });
4779
4780  it('encode for setting packed values', () => {
4781    const accessor = Kernel.createEmpty();
4782
4783    accessor.setPackedSint32Iterable(1, [value1, value2]);
4784    const serialized = accessor.serialize();
4785
4786    expect(serialized).toEqual(packedValue1Value2);
4787  });
4788
4789  it('return combined values from the input', () => {
4790    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
4791        0x08,
4792        0x01,  // unpacked value1
4793        0x0A,
4794        0x02,
4795        0x01,
4796        0x00,  // packed value1 and value2
4797        0x08,
4798        0x00,  // unpacked value2
4799        ));
4800
4801    const list = accessor.getRepeatedSint32Iterable(1);
4802
4803    expectEqualToArray(list, [value1, value1, value2, value2]);
4804  });
4805
4806  it('return the repeated field element from the input', () => {
4807    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4808
4809    const result1 = accessor.getRepeatedSint32Element(
4810        /* fieldNumber= */ 1, /* index= */ 0);
4811    const result2 = accessor.getRepeatedSint32Element(
4812        /* fieldNumber= */ 1, /* index= */ 1);
4813
4814    expect(result1).toEqual(value1);
4815    expect(result2).toEqual(value2);
4816  });
4817
4818  it('return the size from the input', () => {
4819    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
4820
4821    const size = accessor.getRepeatedSint32Size(1);
4822
4823    expect(size).toEqual(2);
4824  });
4825
4826  it('fail when getting unpacked sint32 value with other wire types', () => {
4827    const accessor =
4828        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
4829    if (CHECK_CRITICAL_STATE) {
4830      expect(() => {
4831        accessor.getRepeatedSint32Iterable(1);
4832      }).toThrowError('Expected wire type: 0 but found: 5');
4833    } else {
4834      // Note in unchecked mode we produce invalid output for invalid inputs.
4835      // This test just documents our behavior in those cases.
4836      // These values might change at any point and are not considered
4837      // what the implementation should be doing here.
4838      expectQualifiedIterable(
4839          accessor.getRepeatedSint32Iterable(1),
4840          (value) => Number.isInteger(value));
4841    }
4842  });
4843
4844  it('fail when adding unpacked sint32 values with null value', () => {
4845    const accessor = Kernel.createEmpty();
4846    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4847    if (CHECK_CRITICAL_STATE) {
4848      expect(() => accessor.addUnpackedSint32Iterable(1, [fakeSint32]))
4849          .toThrowError('Must be a number, but got: null');
4850    } else {
4851      // Note in unchecked mode we produce invalid output for invalid inputs.
4852      // This test just documents our behavior in those cases.
4853      // These values might change at any point and are not considered
4854      // what the implementation should be doing here.
4855      accessor.addUnpackedSint32Iterable(1, [fakeSint32]);
4856      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4857    }
4858  });
4859
4860  it('fail when adding single unpacked sint32 value with null value', () => {
4861    const accessor = Kernel.createEmpty();
4862    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4863    if (CHECK_CRITICAL_STATE) {
4864      expect(() => accessor.addUnpackedSint32Element(1, fakeSint32))
4865          .toThrowError('Must be a number, but got: null');
4866    } else {
4867      // Note in unchecked mode we produce invalid output for invalid inputs.
4868      // This test just documents our behavior in those cases.
4869      // These values might change at any point and are not considered
4870      // what the implementation should be doing here.
4871      accessor.addUnpackedSint32Element(1, fakeSint32);
4872      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4873    }
4874  });
4875
4876  it('fail when setting unpacked sint32 values with null value', () => {
4877    const accessor = Kernel.createEmpty();
4878    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4879    if (CHECK_CRITICAL_STATE) {
4880      expect(() => accessor.setUnpackedSint32Iterable(1, [fakeSint32]))
4881          .toThrowError('Must be a number, but got: null');
4882    } else {
4883      // Note in unchecked mode we produce invalid output for invalid inputs.
4884      // This test just documents our behavior in those cases.
4885      // These values might change at any point and are not considered
4886      // what the implementation should be doing here.
4887      accessor.setUnpackedSint32Iterable(1, [fakeSint32]);
4888      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4889    }
4890  });
4891
4892  it('fail when setting single unpacked sint32 value with null value', () => {
4893    const accessor =
4894        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
4895    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4896    if (CHECK_CRITICAL_STATE) {
4897      expect(() => accessor.setUnpackedSint32Element(1, 0, fakeSint32))
4898          .toThrowError('Must be a number, but got: null');
4899    } else {
4900      // Note in unchecked mode we produce invalid output for invalid inputs.
4901      // This test just documents our behavior in those cases.
4902      // These values might change at any point and are not considered
4903      // what the implementation should be doing here.
4904      accessor.setUnpackedSint32Element(1, 0, fakeSint32);
4905      expectQualifiedIterable(
4906          accessor.getRepeatedSint32Iterable(1),
4907      );
4908    }
4909  });
4910
4911  it('fail when adding packed sint32 values with null value', () => {
4912    const accessor = Kernel.createEmpty();
4913    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4914    if (CHECK_CRITICAL_STATE) {
4915      expect(() => accessor.addPackedSint32Iterable(1, [fakeSint32]))
4916          .toThrowError('Must be a number, but got: null');
4917    } else {
4918      // Note in unchecked mode we produce invalid output for invalid inputs.
4919      // This test just documents our behavior in those cases.
4920      // These values might change at any point and are not considered
4921      // what the implementation should be doing here.
4922      accessor.addPackedSint32Iterable(1, [fakeSint32]);
4923      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4924    }
4925  });
4926
4927  it('fail when adding single packed sint32 value with null value', () => {
4928    const accessor = Kernel.createEmpty();
4929    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4930    if (CHECK_CRITICAL_STATE) {
4931      expect(() => accessor.addPackedSint32Element(1, fakeSint32))
4932          .toThrowError('Must be a number, but got: null');
4933    } else {
4934      // Note in unchecked mode we produce invalid output for invalid inputs.
4935      // This test just documents our behavior in those cases.
4936      // These values might change at any point and are not considered
4937      // what the implementation should be doing here.
4938      accessor.addPackedSint32Element(1, fakeSint32);
4939      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4940    }
4941  });
4942
4943  it('fail when setting packed sint32 values with null value', () => {
4944    const accessor = Kernel.createEmpty();
4945    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4946    if (CHECK_CRITICAL_STATE) {
4947      expect(() => accessor.setPackedSint32Iterable(1, [fakeSint32]))
4948          .toThrowError('Must be a number, but got: null');
4949    } else {
4950      // Note in unchecked mode we produce invalid output for invalid inputs.
4951      // This test just documents our behavior in those cases.
4952      // These values might change at any point and are not considered
4953      // what the implementation should be doing here.
4954      accessor.setPackedSint32Iterable(1, [fakeSint32]);
4955      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4956    }
4957  });
4958
4959  it('fail when setting single packed sint32 value with null value', () => {
4960    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
4961    const fakeSint32 = /** @type {number} */ (/** @type {*} */ (null));
4962    if (CHECK_CRITICAL_STATE) {
4963      expect(() => accessor.setPackedSint32Element(1, 0, fakeSint32))
4964          .toThrowError('Must be a number, but got: null');
4965    } else {
4966      // Note in unchecked mode we produce invalid output for invalid inputs.
4967      // This test just documents our behavior in those cases.
4968      // These values might change at any point and are not considered
4969      // what the implementation should be doing here.
4970      accessor.setPackedSint32Element(1, 0, fakeSint32);
4971      expectQualifiedIterable(accessor.getRepeatedSint32Iterable(1));
4972    }
4973  });
4974
4975  it('fail when setting single unpacked with out-of-bound index', () => {
4976    const accessor =
4977        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
4978    if (CHECK_CRITICAL_STATE) {
4979      expect(() => accessor.setUnpackedSint32Element(1, 1, 1))
4980          .toThrowError('Index out of bounds: index: 1 size: 1');
4981    } else {
4982      // Note in unchecked mode we produce invalid output for invalid inputs.
4983      // This test just documents our behavior in those cases.
4984      // These values might change at any point and are not considered
4985      // what the implementation should be doing here.
4986      accessor.setUnpackedSint32Element(1, 1, 1);
4987      expectQualifiedIterable(
4988          accessor.getRepeatedSint32Iterable(1),
4989          (value) => Number.isInteger(value));
4990    }
4991  });
4992
4993  it('fail when setting single packed with out-of-bound index', () => {
4994    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
4995    if (CHECK_CRITICAL_STATE) {
4996      expect(() => accessor.setPackedSint32Element(1, 1, 1))
4997          .toThrowError('Index out of bounds: index: 1 size: 1');
4998    } else {
4999      // Note in unchecked mode we produce invalid output for invalid inputs.
5000      // This test just documents our behavior in those cases.
5001      // These values might change at any point and are not considered
5002      // what the implementation should be doing here.
5003      accessor.setPackedSint32Element(1, 1, 1);
5004      expectQualifiedIterable(
5005          accessor.getRepeatedSint32Iterable(1),
5006          (value) => Number.isInteger(value));
5007    }
5008  });
5009
5010  it('fail when getting element with out-of-range index', () => {
5011    const accessor = Kernel.createEmpty();
5012    if (CHECK_CRITICAL_STATE) {
5013      expect(() => {
5014        accessor.getRepeatedSint32Element(
5015            /* fieldNumber= */ 1, /* index= */ 0);
5016      }).toThrowError('Index out of bounds: index: 0 size: 0');
5017    } else {
5018      // Note in unchecked mode we produce invalid output for invalid inputs.
5019      // This test just documents our behavior in those cases.
5020      // These values might change at any point and are not considered
5021      // what the implementation should be doing here.
5022      expect(accessor.getRepeatedSint32Element(
5023                 /* fieldNumber= */ 1, /* index= */ 0))
5024          .toBe(undefined);
5025    }
5026  });
5027});
5028
5029describe('Kernel for repeated sint64 does', () => {
5030  const value1 = Int64.fromInt(-1);
5031  const value2 = Int64.fromInt(0);
5032
5033  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
5034  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
5035
5036  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
5037  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
5038
5039  it('return empty array for the empty input', () => {
5040    const accessor = Kernel.createEmpty();
5041
5042    const list = accessor.getRepeatedSint64Iterable(1);
5043
5044    expectEqualToArray(list, []);
5045  });
5046
5047  it('ensure not the same instance returned for the empty input', () => {
5048    const accessor = Kernel.createEmpty();
5049
5050    const list1 = accessor.getRepeatedSint64Iterable(1);
5051    const list2 = accessor.getRepeatedSint64Iterable(1);
5052
5053    expect(list1).not.toBe(list2);
5054  });
5055
5056  it('return size for the empty input', () => {
5057    const accessor = Kernel.createEmpty();
5058
5059    const size = accessor.getRepeatedSint64Size(1);
5060
5061    expect(size).toEqual(0);
5062  });
5063
5064  it('return unpacked values from the input', () => {
5065    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5066
5067    const list = accessor.getRepeatedSint64Iterable(1);
5068
5069    expectEqualToArray(list, [value1, value2]);
5070  });
5071
5072  it('ensure not the same instance returned for unpacked values', () => {
5073    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5074
5075    const list1 = accessor.getRepeatedSint64Iterable(1);
5076    const list2 = accessor.getRepeatedSint64Iterable(1);
5077
5078    expect(list1).not.toBe(list2);
5079  });
5080
5081  it('add single unpacked value', () => {
5082    const accessor = Kernel.createEmpty();
5083
5084    accessor.addUnpackedSint64Element(1, value1);
5085    const list1 = accessor.getRepeatedSint64Iterable(1);
5086    accessor.addUnpackedSint64Element(1, value2);
5087    const list2 = accessor.getRepeatedSint64Iterable(1);
5088
5089    expectEqualToArray(list1, [value1]);
5090    expectEqualToArray(list2, [value1, value2]);
5091  });
5092
5093  it('add unpacked values', () => {
5094    const accessor = Kernel.createEmpty();
5095
5096    accessor.addUnpackedSint64Iterable(1, [value1]);
5097    const list1 = accessor.getRepeatedSint64Iterable(1);
5098    accessor.addUnpackedSint64Iterable(1, [value2]);
5099    const list2 = accessor.getRepeatedSint64Iterable(1);
5100
5101    expectEqualToArray(list1, [value1]);
5102    expectEqualToArray(list2, [value1, value2]);
5103  });
5104
5105  it('set a single unpacked value', () => {
5106    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5107
5108    accessor.setUnpackedSint64Element(1, 1, value1);
5109    const list = accessor.getRepeatedSint64Iterable(1);
5110
5111    expectEqualToArray(list, [value1, value1]);
5112  });
5113
5114  it('set unpacked values', () => {
5115    const accessor = Kernel.createEmpty();
5116
5117    accessor.setUnpackedSint64Iterable(1, [value1]);
5118    const list = accessor.getRepeatedSint64Iterable(1);
5119
5120    expectEqualToArray(list, [value1]);
5121  });
5122
5123  it('encode for adding single unpacked value', () => {
5124    const accessor = Kernel.createEmpty();
5125
5126    accessor.addUnpackedSint64Element(1, value1);
5127    accessor.addUnpackedSint64Element(1, value2);
5128    const serialized = accessor.serialize();
5129
5130    expect(serialized).toEqual(unpackedValue1Value2);
5131  });
5132
5133  it('encode for adding unpacked values', () => {
5134    const accessor = Kernel.createEmpty();
5135
5136    accessor.addUnpackedSint64Iterable(1, [value1]);
5137    accessor.addUnpackedSint64Iterable(1, [value2]);
5138    const serialized = accessor.serialize();
5139
5140    expect(serialized).toEqual(unpackedValue1Value2);
5141  });
5142
5143  it('encode for setting single unpacked value', () => {
5144    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5145
5146    accessor.setUnpackedSint64Element(1, 0, value2);
5147    accessor.setUnpackedSint64Element(1, 1, value1);
5148    const serialized = accessor.serialize();
5149
5150    expect(serialized).toEqual(unpackedValue2Value1);
5151  });
5152
5153  it('encode for setting unpacked values', () => {
5154    const accessor = Kernel.createEmpty();
5155
5156    accessor.setUnpackedSint64Iterable(1, [value1, value2]);
5157    const serialized = accessor.serialize();
5158
5159    expect(serialized).toEqual(unpackedValue1Value2);
5160  });
5161
5162  it('return packed values from the input', () => {
5163    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5164
5165    const list = accessor.getRepeatedSint64Iterable(1);
5166
5167    expectEqualToArray(list, [value1, value2]);
5168  });
5169
5170  it('ensure not the same instance returned for packed values', () => {
5171    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5172
5173    const list1 = accessor.getRepeatedSint64Iterable(1);
5174    const list2 = accessor.getRepeatedSint64Iterable(1);
5175
5176    expect(list1).not.toBe(list2);
5177  });
5178
5179  it('add single packed value', () => {
5180    const accessor = Kernel.createEmpty();
5181
5182    accessor.addPackedSint64Element(1, value1);
5183    const list1 = accessor.getRepeatedSint64Iterable(1);
5184    accessor.addPackedSint64Element(1, value2);
5185    const list2 = accessor.getRepeatedSint64Iterable(1);
5186
5187    expectEqualToArray(list1, [value1]);
5188    expectEqualToArray(list2, [value1, value2]);
5189  });
5190
5191  it('add packed values', () => {
5192    const accessor = Kernel.createEmpty();
5193
5194    accessor.addPackedSint64Iterable(1, [value1]);
5195    const list1 = accessor.getRepeatedSint64Iterable(1);
5196    accessor.addPackedSint64Iterable(1, [value2]);
5197    const list2 = accessor.getRepeatedSint64Iterable(1);
5198
5199    expectEqualToArray(list1, [value1]);
5200    expectEqualToArray(list2, [value1, value2]);
5201  });
5202
5203  it('set a single packed value', () => {
5204    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5205
5206    accessor.setPackedSint64Element(1, 1, value1);
5207    const list = accessor.getRepeatedSint64Iterable(1);
5208
5209    expectEqualToArray(list, [value1, value1]);
5210  });
5211
5212  it('set packed values', () => {
5213    const accessor = Kernel.createEmpty();
5214
5215    accessor.setPackedSint64Iterable(1, [value1]);
5216    const list1 = accessor.getRepeatedSint64Iterable(1);
5217    accessor.setPackedSint64Iterable(1, [value2]);
5218    const list2 = accessor.getRepeatedSint64Iterable(1);
5219
5220    expectEqualToArray(list1, [value1]);
5221    expectEqualToArray(list2, [value2]);
5222  });
5223
5224  it('encode for adding single packed value', () => {
5225    const accessor = Kernel.createEmpty();
5226
5227    accessor.addPackedSint64Element(1, value1);
5228    accessor.addPackedSint64Element(1, value2);
5229    const serialized = accessor.serialize();
5230
5231    expect(serialized).toEqual(packedValue1Value2);
5232  });
5233
5234  it('encode for adding packed values', () => {
5235    const accessor = Kernel.createEmpty();
5236
5237    accessor.addPackedSint64Iterable(1, [value1, value2]);
5238    const serialized = accessor.serialize();
5239
5240    expect(serialized).toEqual(packedValue1Value2);
5241  });
5242
5243  it('encode for setting single packed value', () => {
5244    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5245
5246    accessor.setPackedSint64Element(1, 0, value2);
5247    accessor.setPackedSint64Element(1, 1, value1);
5248
5249    const serialized = accessor.serialize();
5250
5251    expect(serialized).toEqual(packedValue2Value1);
5252  });
5253
5254  it('encode for setting packed values', () => {
5255    const accessor = Kernel.createEmpty();
5256
5257    accessor.setPackedSint64Iterable(1, [value1, value2]);
5258    const serialized = accessor.serialize();
5259
5260    expect(serialized).toEqual(packedValue1Value2);
5261  });
5262
5263  it('return combined values from the input', () => {
5264    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
5265        0x08,
5266        0x01,  // unpacked value1
5267        0x0A,
5268        0x02,
5269        0x01,
5270        0x00,  // packed value1 and value2
5271        0x08,
5272        0x00,  // unpacked value2
5273        ));
5274
5275    const list = accessor.getRepeatedSint64Iterable(1);
5276
5277    expectEqualToArray(list, [value1, value1, value2, value2]);
5278  });
5279
5280  it('return the repeated field element from the input', () => {
5281    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5282
5283    const result1 = accessor.getRepeatedSint64Element(
5284        /* fieldNumber= */ 1, /* index= */ 0);
5285    const result2 = accessor.getRepeatedSint64Element(
5286        /* fieldNumber= */ 1, /* index= */ 1);
5287
5288    expect(result1).toEqual(value1);
5289    expect(result2).toEqual(value2);
5290  });
5291
5292  it('return the size from the input', () => {
5293    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5294
5295    const size = accessor.getRepeatedSint64Size(1);
5296
5297    expect(size).toEqual(2);
5298  });
5299
5300  it('fail when getting unpacked sint64 value with other wire types', () => {
5301    const accessor =
5302        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
5303    if (CHECK_CRITICAL_STATE) {
5304      expect(() => {
5305        accessor.getRepeatedSint64Iterable(1);
5306      }).toThrowError('Expected wire type: 0 but found: 5');
5307    } else {
5308      // Note in unchecked mode we produce invalid output for invalid inputs.
5309      // This test just documents our behavior in those cases.
5310      // These values might change at any point and are not considered
5311      // what the implementation should be doing here.
5312      expectQualifiedIterable(
5313          accessor.getRepeatedSint64Iterable(1),
5314          (value) => value instanceof Int64);
5315    }
5316  });
5317
5318  it('fail when adding unpacked sint64 values with null value', () => {
5319    const accessor = Kernel.createEmpty();
5320    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5321    if (CHECK_CRITICAL_STATE) {
5322      expect(() => accessor.addUnpackedSint64Iterable(1, [fakeSint64]))
5323          .toThrowError('Must be Int64 instance, but got: null');
5324    } else {
5325      // Note in unchecked mode we produce invalid output for invalid inputs.
5326      // This test just documents our behavior in those cases.
5327      // These values might change at any point and are not considered
5328      // what the implementation should be doing here.
5329      accessor.addUnpackedSint64Iterable(1, [fakeSint64]);
5330      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5331    }
5332  });
5333
5334  it('fail when adding single unpacked sint64 value with null value', () => {
5335    const accessor = Kernel.createEmpty();
5336    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5337    if (CHECK_CRITICAL_STATE) {
5338      expect(() => accessor.addUnpackedSint64Element(1, fakeSint64))
5339          .toThrowError('Must be Int64 instance, but got: null');
5340    } else {
5341      // Note in unchecked mode we produce invalid output for invalid inputs.
5342      // This test just documents our behavior in those cases.
5343      // These values might change at any point and are not considered
5344      // what the implementation should be doing here.
5345      accessor.addUnpackedSint64Element(1, fakeSint64);
5346      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5347    }
5348  });
5349
5350  it('fail when setting unpacked sint64 values with null value', () => {
5351    const accessor = Kernel.createEmpty();
5352    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5353    if (CHECK_CRITICAL_STATE) {
5354      expect(() => accessor.setUnpackedSint64Iterable(1, [fakeSint64]))
5355          .toThrowError('Must be Int64 instance, but got: null');
5356    } else {
5357      // Note in unchecked mode we produce invalid output for invalid inputs.
5358      // This test just documents our behavior in those cases.
5359      // These values might change at any point and are not considered
5360      // what the implementation should be doing here.
5361      accessor.setUnpackedSint64Iterable(1, [fakeSint64]);
5362      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5363    }
5364  });
5365
5366  it('fail when setting single unpacked sint64 value with null value', () => {
5367    const accessor =
5368        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
5369    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5370    if (CHECK_CRITICAL_STATE) {
5371      expect(() => accessor.setUnpackedSint64Element(1, 0, fakeSint64))
5372          .toThrowError('Must be Int64 instance, but got: null');
5373    } else {
5374      // Note in unchecked mode we produce invalid output for invalid inputs.
5375      // This test just documents our behavior in those cases.
5376      // These values might change at any point and are not considered
5377      // what the implementation should be doing here.
5378      accessor.setUnpackedSint64Element(1, 0, fakeSint64);
5379      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5380    }
5381  });
5382
5383  it('fail when adding packed sint64 values with null value', () => {
5384    const accessor = Kernel.createEmpty();
5385    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5386    if (CHECK_CRITICAL_STATE) {
5387      expect(() => accessor.addPackedSint64Iterable(1, [fakeSint64]))
5388          .toThrowError('Must be Int64 instance, but got: null');
5389    } else {
5390      // Note in unchecked mode we produce invalid output for invalid inputs.
5391      // This test just documents our behavior in those cases.
5392      // These values might change at any point and are not considered
5393      // what the implementation should be doing here.
5394      accessor.addPackedSint64Iterable(1, [fakeSint64]);
5395      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5396    }
5397  });
5398
5399  it('fail when adding single packed sint64 value with null value', () => {
5400    const accessor = Kernel.createEmpty();
5401    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5402    if (CHECK_CRITICAL_STATE) {
5403      expect(() => accessor.addPackedSint64Element(1, fakeSint64))
5404          .toThrowError('Must be Int64 instance, but got: null');
5405    } else {
5406      // Note in unchecked mode we produce invalid output for invalid inputs.
5407      // This test just documents our behavior in those cases.
5408      // These values might change at any point and are not considered
5409      // what the implementation should be doing here.
5410      accessor.addPackedSint64Element(1, fakeSint64);
5411      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5412    }
5413  });
5414
5415  it('fail when setting packed sint64 values with null value', () => {
5416    const accessor = Kernel.createEmpty();
5417    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5418    if (CHECK_CRITICAL_STATE) {
5419      expect(() => accessor.setPackedSint64Iterable(1, [fakeSint64]))
5420          .toThrowError('Must be Int64 instance, but got: null');
5421    } else {
5422      // Note in unchecked mode we produce invalid output for invalid inputs.
5423      // This test just documents our behavior in those cases.
5424      // These values might change at any point and are not considered
5425      // what the implementation should be doing here.
5426      accessor.setPackedSint64Iterable(1, [fakeSint64]);
5427      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5428    }
5429  });
5430
5431  it('fail when setting single packed sint64 value with null value', () => {
5432    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
5433    const fakeSint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
5434    if (CHECK_CRITICAL_STATE) {
5435      expect(() => accessor.setPackedSint64Element(1, 0, fakeSint64))
5436          .toThrowError('Must be Int64 instance, but got: null');
5437    } else {
5438      // Note in unchecked mode we produce invalid output for invalid inputs.
5439      // This test just documents our behavior in those cases.
5440      // These values might change at any point and are not considered
5441      // what the implementation should be doing here.
5442      accessor.setPackedSint64Element(1, 0, fakeSint64);
5443      expectQualifiedIterable(accessor.getRepeatedSint64Iterable(1));
5444    }
5445  });
5446
5447  it('fail when setting single unpacked with out-of-bound index', () => {
5448    const accessor =
5449        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
5450    if (CHECK_CRITICAL_STATE) {
5451      expect(() => accessor.setUnpackedSint64Element(1, 1, Int64.fromInt(1)))
5452          .toThrowError('Index out of bounds: index: 1 size: 1');
5453    } else {
5454      // Note in unchecked mode we produce invalid output for invalid inputs.
5455      // This test just documents our behavior in those cases.
5456      // These values might change at any point and are not considered
5457      // what the implementation should be doing here.
5458      accessor.setUnpackedSint64Element(1, 1, Int64.fromInt(1));
5459      expectQualifiedIterable(
5460          accessor.getRepeatedSint64Iterable(1),
5461          (value) => value instanceof Int64);
5462    }
5463  });
5464
5465  it('fail when setting single packed with out-of-bound index', () => {
5466    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
5467    if (CHECK_CRITICAL_STATE) {
5468      expect(() => accessor.setPackedSint64Element(1, 1, Int64.fromInt(1)))
5469          .toThrowError('Index out of bounds: index: 1 size: 1');
5470    } else {
5471      // Note in unchecked mode we produce invalid output for invalid inputs.
5472      // This test just documents our behavior in those cases.
5473      // These values might change at any point and are not considered
5474      // what the implementation should be doing here.
5475      accessor.setPackedSint64Element(1, 1, Int64.fromInt(1));
5476      expectQualifiedIterable(
5477          accessor.getRepeatedSint64Iterable(1),
5478          (value) => value instanceof Int64);
5479    }
5480  });
5481
5482  it('fail when getting element with out-of-range index', () => {
5483    const accessor = Kernel.createEmpty();
5484    if (CHECK_CRITICAL_STATE) {
5485      expect(() => {
5486        accessor.getRepeatedSint64Element(
5487            /* fieldNumber= */ 1, /* index= */ 0);
5488      }).toThrowError('Index out of bounds: index: 0 size: 0');
5489    } else {
5490      // Note in unchecked mode we produce invalid output for invalid inputs.
5491      // This test just documents our behavior in those cases.
5492      // These values might change at any point and are not considered
5493      // what the implementation should be doing here.
5494      expect(accessor.getRepeatedSint64Element(
5495                 /* fieldNumber= */ 1, /* index= */ 0))
5496          .toBe(undefined);
5497    }
5498  });
5499});
5500
5501describe('Kernel for repeated uint32 does', () => {
5502  const value1 = 1;
5503  const value2 = 0;
5504
5505  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
5506  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
5507
5508  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
5509  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
5510
5511  it('return empty array for the empty input', () => {
5512    const accessor = Kernel.createEmpty();
5513
5514    const list = accessor.getRepeatedUint32Iterable(1);
5515
5516    expectEqualToArray(list, []);
5517  });
5518
5519  it('ensure not the same instance returned for the empty input', () => {
5520    const accessor = Kernel.createEmpty();
5521
5522    const list1 = accessor.getRepeatedUint32Iterable(1);
5523    const list2 = accessor.getRepeatedUint32Iterable(1);
5524
5525    expect(list1).not.toBe(list2);
5526  });
5527
5528  it('return size for the empty input', () => {
5529    const accessor = Kernel.createEmpty();
5530
5531    const size = accessor.getRepeatedUint32Size(1);
5532
5533    expect(size).toEqual(0);
5534  });
5535
5536  it('return unpacked values from the input', () => {
5537    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5538
5539    const list = accessor.getRepeatedUint32Iterable(1);
5540
5541    expectEqualToArray(list, [value1, value2]);
5542  });
5543
5544  it('ensure not the same instance returned for unpacked values', () => {
5545    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5546
5547    const list1 = accessor.getRepeatedUint32Iterable(1);
5548    const list2 = accessor.getRepeatedUint32Iterable(1);
5549
5550    expect(list1).not.toBe(list2);
5551  });
5552
5553  it('add single unpacked value', () => {
5554    const accessor = Kernel.createEmpty();
5555
5556    accessor.addUnpackedUint32Element(1, value1);
5557    const list1 = accessor.getRepeatedUint32Iterable(1);
5558    accessor.addUnpackedUint32Element(1, value2);
5559    const list2 = accessor.getRepeatedUint32Iterable(1);
5560
5561    expectEqualToArray(list1, [value1]);
5562    expectEqualToArray(list2, [value1, value2]);
5563  });
5564
5565  it('add unpacked values', () => {
5566    const accessor = Kernel.createEmpty();
5567
5568    accessor.addUnpackedUint32Iterable(1, [value1]);
5569    const list1 = accessor.getRepeatedUint32Iterable(1);
5570    accessor.addUnpackedUint32Iterable(1, [value2]);
5571    const list2 = accessor.getRepeatedUint32Iterable(1);
5572
5573    expectEqualToArray(list1, [value1]);
5574    expectEqualToArray(list2, [value1, value2]);
5575  });
5576
5577  it('set a single unpacked value', () => {
5578    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5579
5580    accessor.setUnpackedUint32Element(1, 1, value1);
5581    const list = accessor.getRepeatedUint32Iterable(1);
5582
5583    expectEqualToArray(list, [value1, value1]);
5584  });
5585
5586  it('set unpacked values', () => {
5587    const accessor = Kernel.createEmpty();
5588
5589    accessor.setUnpackedUint32Iterable(1, [value1]);
5590    const list = accessor.getRepeatedUint32Iterable(1);
5591
5592    expectEqualToArray(list, [value1]);
5593  });
5594
5595  it('encode for adding single unpacked value', () => {
5596    const accessor = Kernel.createEmpty();
5597
5598    accessor.addUnpackedUint32Element(1, value1);
5599    accessor.addUnpackedUint32Element(1, value2);
5600    const serialized = accessor.serialize();
5601
5602    expect(serialized).toEqual(unpackedValue1Value2);
5603  });
5604
5605  it('encode for adding unpacked values', () => {
5606    const accessor = Kernel.createEmpty();
5607
5608    accessor.addUnpackedUint32Iterable(1, [value1]);
5609    accessor.addUnpackedUint32Iterable(1, [value2]);
5610    const serialized = accessor.serialize();
5611
5612    expect(serialized).toEqual(unpackedValue1Value2);
5613  });
5614
5615  it('encode for setting single unpacked value', () => {
5616    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5617
5618    accessor.setUnpackedUint32Element(1, 0, value2);
5619    accessor.setUnpackedUint32Element(1, 1, value1);
5620    const serialized = accessor.serialize();
5621
5622    expect(serialized).toEqual(unpackedValue2Value1);
5623  });
5624
5625  it('encode for setting unpacked values', () => {
5626    const accessor = Kernel.createEmpty();
5627
5628    accessor.setUnpackedUint32Iterable(1, [value1, value2]);
5629    const serialized = accessor.serialize();
5630
5631    expect(serialized).toEqual(unpackedValue1Value2);
5632  });
5633
5634  it('return packed values from the input', () => {
5635    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5636
5637    const list = accessor.getRepeatedUint32Iterable(1);
5638
5639    expectEqualToArray(list, [value1, value2]);
5640  });
5641
5642  it('ensure not the same instance returned for packed values', () => {
5643    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
5644
5645    const list1 = accessor.getRepeatedUint32Iterable(1);
5646    const list2 = accessor.getRepeatedUint32Iterable(1);
5647
5648    expect(list1).not.toBe(list2);
5649  });
5650
5651  it('add single packed value', () => {
5652    const accessor = Kernel.createEmpty();
5653
5654    accessor.addPackedUint32Element(1, value1);
5655    const list1 = accessor.getRepeatedUint32Iterable(1);
5656    accessor.addPackedUint32Element(1, value2);
5657    const list2 = accessor.getRepeatedUint32Iterable(1);
5658
5659    expectEqualToArray(list1, [value1]);
5660    expectEqualToArray(list2, [value1, value2]);
5661  });
5662
5663  it('add packed values', () => {
5664    const accessor = Kernel.createEmpty();
5665
5666    accessor.addPackedUint32Iterable(1, [value1]);
5667    const list1 = accessor.getRepeatedUint32Iterable(1);
5668    accessor.addPackedUint32Iterable(1, [value2]);
5669    const list2 = accessor.getRepeatedUint32Iterable(1);
5670
5671    expectEqualToArray(list1, [value1]);
5672    expectEqualToArray(list2, [value1, value2]);
5673  });
5674
5675  it('set a single packed value', () => {
5676    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5677
5678    accessor.setPackedUint32Element(1, 1, value1);
5679    const list = accessor.getRepeatedUint32Iterable(1);
5680
5681    expectEqualToArray(list, [value1, value1]);
5682  });
5683
5684  it('set packed values', () => {
5685    const accessor = Kernel.createEmpty();
5686
5687    accessor.setPackedUint32Iterable(1, [value1]);
5688    const list1 = accessor.getRepeatedUint32Iterable(1);
5689    accessor.setPackedUint32Iterable(1, [value2]);
5690    const list2 = accessor.getRepeatedUint32Iterable(1);
5691
5692    expectEqualToArray(list1, [value1]);
5693    expectEqualToArray(list2, [value2]);
5694  });
5695
5696  it('encode for adding single packed value', () => {
5697    const accessor = Kernel.createEmpty();
5698
5699    accessor.addPackedUint32Element(1, value1);
5700    accessor.addPackedUint32Element(1, value2);
5701    const serialized = accessor.serialize();
5702
5703    expect(serialized).toEqual(packedValue1Value2);
5704  });
5705
5706  it('encode for adding packed values', () => {
5707    const accessor = Kernel.createEmpty();
5708
5709    accessor.addPackedUint32Iterable(1, [value1, value2]);
5710    const serialized = accessor.serialize();
5711
5712    expect(serialized).toEqual(packedValue1Value2);
5713  });
5714
5715  it('encode for setting single packed value', () => {
5716    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5717
5718    accessor.setPackedUint32Element(1, 0, value2);
5719    accessor.setPackedUint32Element(1, 1, value1);
5720
5721    const serialized = accessor.serialize();
5722
5723    expect(serialized).toEqual(packedValue2Value1);
5724  });
5725
5726  it('encode for setting packed values', () => {
5727    const accessor = Kernel.createEmpty();
5728
5729    accessor.setPackedUint32Iterable(1, [value1, value2]);
5730    const serialized = accessor.serialize();
5731
5732    expect(serialized).toEqual(packedValue1Value2);
5733  });
5734
5735  it('return combined values from the input', () => {
5736    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
5737        0x08,
5738        0x01,  // unpacked value1
5739        0x0A,
5740        0x02,
5741        0x01,
5742        0x00,  // packed value1 and value2
5743        0x08,
5744        0x00,  // unpacked value2
5745        ));
5746
5747    const list = accessor.getRepeatedUint32Iterable(1);
5748
5749    expectEqualToArray(list, [value1, value1, value2, value2]);
5750  });
5751
5752  it('return the repeated field element from the input', () => {
5753    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5754
5755    const result1 = accessor.getRepeatedUint32Element(
5756        /* fieldNumber= */ 1, /* index= */ 0);
5757    const result2 = accessor.getRepeatedUint32Element(
5758        /* fieldNumber= */ 1, /* index= */ 1);
5759
5760    expect(result1).toEqual(value1);
5761    expect(result2).toEqual(value2);
5762  });
5763
5764  it('return the size from the input', () => {
5765    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
5766
5767    const size = accessor.getRepeatedUint32Size(1);
5768
5769    expect(size).toEqual(2);
5770  });
5771
5772  it('fail when getting unpacked uint32 value with other wire types', () => {
5773    const accessor =
5774        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
5775    if (CHECK_CRITICAL_STATE) {
5776      expect(() => {
5777        accessor.getRepeatedUint32Iterable(1);
5778      }).toThrowError('Expected wire type: 0 but found: 5');
5779    } else {
5780      // Note in unchecked mode we produce invalid output for invalid inputs.
5781      // This test just documents our behavior in those cases.
5782      // These values might change at any point and are not considered
5783      // what the implementation should be doing here.
5784      expectQualifiedIterable(
5785          accessor.getRepeatedUint32Iterable(1),
5786          (value) => Number.isInteger(value));
5787    }
5788  });
5789
5790  it('fail when adding unpacked uint32 values with null value', () => {
5791    const accessor = Kernel.createEmpty();
5792    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5793    if (CHECK_CRITICAL_STATE) {
5794      expect(() => accessor.addUnpackedUint32Iterable(1, [fakeUint32]))
5795          .toThrowError('Must be a number, but got: null');
5796    } else {
5797      // Note in unchecked mode we produce invalid output for invalid inputs.
5798      // This test just documents our behavior in those cases.
5799      // These values might change at any point and are not considered
5800      // what the implementation should be doing here.
5801      accessor.addUnpackedUint32Iterable(1, [fakeUint32]);
5802      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5803    }
5804  });
5805
5806  it('fail when adding single unpacked uint32 value with null value', () => {
5807    const accessor = Kernel.createEmpty();
5808    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5809    if (CHECK_CRITICAL_STATE) {
5810      expect(() => accessor.addUnpackedUint32Element(1, fakeUint32))
5811          .toThrowError('Must be a number, but got: null');
5812    } else {
5813      // Note in unchecked mode we produce invalid output for invalid inputs.
5814      // This test just documents our behavior in those cases.
5815      // These values might change at any point and are not considered
5816      // what the implementation should be doing here.
5817      accessor.addUnpackedUint32Element(1, fakeUint32);
5818      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5819    }
5820  });
5821
5822  it('fail when setting unpacked uint32 values with null value', () => {
5823    const accessor = Kernel.createEmpty();
5824    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5825    if (CHECK_CRITICAL_STATE) {
5826      expect(() => accessor.setUnpackedUint32Iterable(1, [fakeUint32]))
5827          .toThrowError('Must be a number, but got: null');
5828    } else {
5829      // Note in unchecked mode we produce invalid output for invalid inputs.
5830      // This test just documents our behavior in those cases.
5831      // These values might change at any point and are not considered
5832      // what the implementation should be doing here.
5833      accessor.setUnpackedUint32Iterable(1, [fakeUint32]);
5834      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5835    }
5836  });
5837
5838  it('fail when setting single unpacked uint32 value with null value', () => {
5839    const accessor =
5840        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
5841    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5842    if (CHECK_CRITICAL_STATE) {
5843      expect(() => accessor.setUnpackedUint32Element(1, 0, fakeUint32))
5844          .toThrowError('Must be a number, but got: null');
5845    } else {
5846      // Note in unchecked mode we produce invalid output for invalid inputs.
5847      // This test just documents our behavior in those cases.
5848      // These values might change at any point and are not considered
5849      // what the implementation should be doing here.
5850      accessor.setUnpackedUint32Element(1, 0, fakeUint32);
5851      expectQualifiedIterable(
5852          accessor.getRepeatedUint32Iterable(1),
5853      );
5854    }
5855  });
5856
5857  it('fail when adding packed uint32 values with null value', () => {
5858    const accessor = Kernel.createEmpty();
5859    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5860    if (CHECK_CRITICAL_STATE) {
5861      expect(() => accessor.addPackedUint32Iterable(1, [fakeUint32]))
5862          .toThrowError('Must be a number, but got: null');
5863    } else {
5864      // Note in unchecked mode we produce invalid output for invalid inputs.
5865      // This test just documents our behavior in those cases.
5866      // These values might change at any point and are not considered
5867      // what the implementation should be doing here.
5868      accessor.addPackedUint32Iterable(1, [fakeUint32]);
5869      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5870    }
5871  });
5872
5873  it('fail when adding single packed uint32 value with null value', () => {
5874    const accessor = Kernel.createEmpty();
5875    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5876    if (CHECK_CRITICAL_STATE) {
5877      expect(() => accessor.addPackedUint32Element(1, fakeUint32))
5878          .toThrowError('Must be a number, but got: null');
5879    } else {
5880      // Note in unchecked mode we produce invalid output for invalid inputs.
5881      // This test just documents our behavior in those cases.
5882      // These values might change at any point and are not considered
5883      // what the implementation should be doing here.
5884      accessor.addPackedUint32Element(1, fakeUint32);
5885      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5886    }
5887  });
5888
5889  it('fail when setting packed uint32 values with null value', () => {
5890    const accessor = Kernel.createEmpty();
5891    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5892    if (CHECK_CRITICAL_STATE) {
5893      expect(() => accessor.setPackedUint32Iterable(1, [fakeUint32]))
5894          .toThrowError('Must be a number, but got: null');
5895    } else {
5896      // Note in unchecked mode we produce invalid output for invalid inputs.
5897      // This test just documents our behavior in those cases.
5898      // These values might change at any point and are not considered
5899      // what the implementation should be doing here.
5900      accessor.setPackedUint32Iterable(1, [fakeUint32]);
5901      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5902    }
5903  });
5904
5905  it('fail when setting single packed uint32 value with null value', () => {
5906    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
5907    const fakeUint32 = /** @type {number} */ (/** @type {*} */ (null));
5908    if (CHECK_CRITICAL_STATE) {
5909      expect(() => accessor.setPackedUint32Element(1, 0, fakeUint32))
5910          .toThrowError('Must be a number, but got: null');
5911    } else {
5912      // Note in unchecked mode we produce invalid output for invalid inputs.
5913      // This test just documents our behavior in those cases.
5914      // These values might change at any point and are not considered
5915      // what the implementation should be doing here.
5916      accessor.setPackedUint32Element(1, 0, fakeUint32);
5917      expectQualifiedIterable(accessor.getRepeatedUint32Iterable(1));
5918    }
5919  });
5920
5921  it('fail when setting single unpacked with out-of-bound index', () => {
5922    const accessor =
5923        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
5924    if (CHECK_CRITICAL_STATE) {
5925      expect(() => accessor.setUnpackedUint32Element(1, 1, 1))
5926          .toThrowError('Index out of bounds: index: 1 size: 1');
5927    } else {
5928      // Note in unchecked mode we produce invalid output for invalid inputs.
5929      // This test just documents our behavior in those cases.
5930      // These values might change at any point and are not considered
5931      // what the implementation should be doing here.
5932      accessor.setUnpackedUint32Element(1, 1, 1);
5933      expectQualifiedIterable(
5934          accessor.getRepeatedUint32Iterable(1),
5935          (value) => Number.isInteger(value));
5936    }
5937  });
5938
5939  it('fail when setting single packed with out-of-bound index', () => {
5940    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
5941    if (CHECK_CRITICAL_STATE) {
5942      expect(() => accessor.setPackedUint32Element(1, 1, 1))
5943          .toThrowError('Index out of bounds: index: 1 size: 1');
5944    } else {
5945      // Note in unchecked mode we produce invalid output for invalid inputs.
5946      // This test just documents our behavior in those cases.
5947      // These values might change at any point and are not considered
5948      // what the implementation should be doing here.
5949      accessor.setPackedUint32Element(1, 1, 1);
5950      expectQualifiedIterable(
5951          accessor.getRepeatedUint32Iterable(1),
5952          (value) => Number.isInteger(value));
5953    }
5954  });
5955
5956  it('fail when getting element with out-of-range index', () => {
5957    const accessor = Kernel.createEmpty();
5958    if (CHECK_CRITICAL_STATE) {
5959      expect(() => {
5960        accessor.getRepeatedUint32Element(
5961            /* fieldNumber= */ 1, /* index= */ 0);
5962      }).toThrowError('Index out of bounds: index: 0 size: 0');
5963    } else {
5964      // Note in unchecked mode we produce invalid output for invalid inputs.
5965      // This test just documents our behavior in those cases.
5966      // These values might change at any point and are not considered
5967      // what the implementation should be doing here.
5968      expect(accessor.getRepeatedUint32Element(
5969                 /* fieldNumber= */ 1, /* index= */ 0))
5970          .toBe(undefined);
5971    }
5972  });
5973});
5974
5975describe('Kernel for repeated uint64 does', () => {
5976  const value1 = Int64.fromInt(1);
5977  const value2 = Int64.fromInt(0);
5978
5979  const unpackedValue1Value2 = createArrayBuffer(0x08, 0x01, 0x08, 0x00);
5980  const unpackedValue2Value1 = createArrayBuffer(0x08, 0x00, 0x08, 0x01);
5981
5982  const packedValue1Value2 = createArrayBuffer(0x0A, 0x02, 0x01, 0x00);
5983  const packedValue2Value1 = createArrayBuffer(0x0A, 0x02, 0x00, 0x01);
5984
5985  it('return empty array for the empty input', () => {
5986    const accessor = Kernel.createEmpty();
5987
5988    const list = accessor.getRepeatedUint64Iterable(1);
5989
5990    expectEqualToArray(list, []);
5991  });
5992
5993  it('ensure not the same instance returned for the empty input', () => {
5994    const accessor = Kernel.createEmpty();
5995
5996    const list1 = accessor.getRepeatedUint64Iterable(1);
5997    const list2 = accessor.getRepeatedUint64Iterable(1);
5998
5999    expect(list1).not.toBe(list2);
6000  });
6001
6002  it('return size for the empty input', () => {
6003    const accessor = Kernel.createEmpty();
6004
6005    const size = accessor.getRepeatedUint64Size(1);
6006
6007    expect(size).toEqual(0);
6008  });
6009
6010  it('return unpacked values from the input', () => {
6011    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6012
6013    const list = accessor.getRepeatedUint64Iterable(1);
6014
6015    expectEqualToArray(list, [value1, value2]);
6016  });
6017
6018  it('ensure not the same instance returned for unpacked values', () => {
6019    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6020
6021    const list1 = accessor.getRepeatedUint64Iterable(1);
6022    const list2 = accessor.getRepeatedUint64Iterable(1);
6023
6024    expect(list1).not.toBe(list2);
6025  });
6026
6027  it('add single unpacked value', () => {
6028    const accessor = Kernel.createEmpty();
6029
6030    accessor.addUnpackedUint64Element(1, value1);
6031    const list1 = accessor.getRepeatedUint64Iterable(1);
6032    accessor.addUnpackedUint64Element(1, value2);
6033    const list2 = accessor.getRepeatedUint64Iterable(1);
6034
6035    expectEqualToArray(list1, [value1]);
6036    expectEqualToArray(list2, [value1, value2]);
6037  });
6038
6039  it('add unpacked values', () => {
6040    const accessor = Kernel.createEmpty();
6041
6042    accessor.addUnpackedUint64Iterable(1, [value1]);
6043    const list1 = accessor.getRepeatedUint64Iterable(1);
6044    accessor.addUnpackedUint64Iterable(1, [value2]);
6045    const list2 = accessor.getRepeatedUint64Iterable(1);
6046
6047    expectEqualToArray(list1, [value1]);
6048    expectEqualToArray(list2, [value1, value2]);
6049  });
6050
6051  it('set a single unpacked value', () => {
6052    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
6053
6054    accessor.setUnpackedUint64Element(1, 1, value1);
6055    const list = accessor.getRepeatedUint64Iterable(1);
6056
6057    expectEqualToArray(list, [value1, value1]);
6058  });
6059
6060  it('set unpacked values', () => {
6061    const accessor = Kernel.createEmpty();
6062
6063    accessor.setUnpackedUint64Iterable(1, [value1]);
6064    const list = accessor.getRepeatedUint64Iterable(1);
6065
6066    expectEqualToArray(list, [value1]);
6067  });
6068
6069  it('encode for adding single unpacked value', () => {
6070    const accessor = Kernel.createEmpty();
6071
6072    accessor.addUnpackedUint64Element(1, value1);
6073    accessor.addUnpackedUint64Element(1, value2);
6074    const serialized = accessor.serialize();
6075
6076    expect(serialized).toEqual(unpackedValue1Value2);
6077  });
6078
6079  it('encode for adding unpacked values', () => {
6080    const accessor = Kernel.createEmpty();
6081
6082    accessor.addUnpackedUint64Iterable(1, [value1]);
6083    accessor.addUnpackedUint64Iterable(1, [value2]);
6084    const serialized = accessor.serialize();
6085
6086    expect(serialized).toEqual(unpackedValue1Value2);
6087  });
6088
6089  it('encode for setting single unpacked value', () => {
6090    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6091
6092    accessor.setUnpackedUint64Element(1, 0, value2);
6093    accessor.setUnpackedUint64Element(1, 1, value1);
6094    const serialized = accessor.serialize();
6095
6096    expect(serialized).toEqual(unpackedValue2Value1);
6097  });
6098
6099  it('encode for setting unpacked values', () => {
6100    const accessor = Kernel.createEmpty();
6101
6102    accessor.setUnpackedUint64Iterable(1, [value1, value2]);
6103    const serialized = accessor.serialize();
6104
6105    expect(serialized).toEqual(unpackedValue1Value2);
6106  });
6107
6108  it('return packed values from the input', () => {
6109    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
6110
6111    const list = accessor.getRepeatedUint64Iterable(1);
6112
6113    expectEqualToArray(list, [value1, value2]);
6114  });
6115
6116  it('ensure not the same instance returned for packed values', () => {
6117    const accessor = Kernel.fromArrayBuffer(packedValue1Value2);
6118
6119    const list1 = accessor.getRepeatedUint64Iterable(1);
6120    const list2 = accessor.getRepeatedUint64Iterable(1);
6121
6122    expect(list1).not.toBe(list2);
6123  });
6124
6125  it('add single packed value', () => {
6126    const accessor = Kernel.createEmpty();
6127
6128    accessor.addPackedUint64Element(1, value1);
6129    const list1 = accessor.getRepeatedUint64Iterable(1);
6130    accessor.addPackedUint64Element(1, value2);
6131    const list2 = accessor.getRepeatedUint64Iterable(1);
6132
6133    expectEqualToArray(list1, [value1]);
6134    expectEqualToArray(list2, [value1, value2]);
6135  });
6136
6137  it('add packed values', () => {
6138    const accessor = Kernel.createEmpty();
6139
6140    accessor.addPackedUint64Iterable(1, [value1]);
6141    const list1 = accessor.getRepeatedUint64Iterable(1);
6142    accessor.addPackedUint64Iterable(1, [value2]);
6143    const list2 = accessor.getRepeatedUint64Iterable(1);
6144
6145    expectEqualToArray(list1, [value1]);
6146    expectEqualToArray(list2, [value1, value2]);
6147  });
6148
6149  it('set a single packed value', () => {
6150    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6151
6152    accessor.setPackedUint64Element(1, 1, value1);
6153    const list = accessor.getRepeatedUint64Iterable(1);
6154
6155    expectEqualToArray(list, [value1, value1]);
6156  });
6157
6158  it('set packed values', () => {
6159    const accessor = Kernel.createEmpty();
6160
6161    accessor.setPackedUint64Iterable(1, [value1]);
6162    const list1 = accessor.getRepeatedUint64Iterable(1);
6163    accessor.setPackedUint64Iterable(1, [value2]);
6164    const list2 = accessor.getRepeatedUint64Iterable(1);
6165
6166    expectEqualToArray(list1, [value1]);
6167    expectEqualToArray(list2, [value2]);
6168  });
6169
6170  it('encode for adding single packed value', () => {
6171    const accessor = Kernel.createEmpty();
6172
6173    accessor.addPackedUint64Element(1, value1);
6174    accessor.addPackedUint64Element(1, value2);
6175    const serialized = accessor.serialize();
6176
6177    expect(serialized).toEqual(packedValue1Value2);
6178  });
6179
6180  it('encode for adding packed values', () => {
6181    const accessor = Kernel.createEmpty();
6182
6183    accessor.addPackedUint64Iterable(1, [value1, value2]);
6184    const serialized = accessor.serialize();
6185
6186    expect(serialized).toEqual(packedValue1Value2);
6187  });
6188
6189  it('encode for setting single packed value', () => {
6190    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6191
6192    accessor.setPackedUint64Element(1, 0, value2);
6193    accessor.setPackedUint64Element(1, 1, value1);
6194
6195    const serialized = accessor.serialize();
6196
6197    expect(serialized).toEqual(packedValue2Value1);
6198  });
6199
6200  it('encode for setting packed values', () => {
6201    const accessor = Kernel.createEmpty();
6202
6203    accessor.setPackedUint64Iterable(1, [value1, value2]);
6204    const serialized = accessor.serialize();
6205
6206    expect(serialized).toEqual(packedValue1Value2);
6207  });
6208
6209  it('return combined values from the input', () => {
6210    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
6211        0x08,
6212        0x01,  // unpacked value1
6213        0x0A,
6214        0x02,
6215        0x01,
6216        0x00,  // packed value1 and value2
6217        0x08,
6218        0x00,  // unpacked value2
6219        ));
6220
6221    const list = accessor.getRepeatedUint64Iterable(1);
6222
6223    expectEqualToArray(list, [value1, value1, value2, value2]);
6224  });
6225
6226  it('return the repeated field element from the input', () => {
6227    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6228
6229    const result1 = accessor.getRepeatedUint64Element(
6230        /* fieldNumber= */ 1, /* index= */ 0);
6231    const result2 = accessor.getRepeatedUint64Element(
6232        /* fieldNumber= */ 1, /* index= */ 1);
6233
6234    expect(result1).toEqual(value1);
6235    expect(result2).toEqual(value2);
6236  });
6237
6238  it('return the size from the input', () => {
6239    const accessor = Kernel.fromArrayBuffer(unpackedValue1Value2);
6240
6241    const size = accessor.getRepeatedUint64Size(1);
6242
6243    expect(size).toEqual(2);
6244  });
6245
6246  it('fail when getting unpacked uint64 value with other wire types', () => {
6247    const accessor =
6248        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
6249    if (CHECK_CRITICAL_STATE) {
6250      expect(() => {
6251        accessor.getRepeatedUint64Iterable(1);
6252      }).toThrowError('Expected wire type: 0 but found: 5');
6253    } else {
6254      // Note in unchecked mode we produce invalid output for invalid inputs.
6255      // This test just documents our behavior in those cases.
6256      // These values might change at any point and are not considered
6257      // what the implementation should be doing here.
6258      expectQualifiedIterable(
6259          accessor.getRepeatedUint64Iterable(1),
6260          (value) => value instanceof Int64);
6261    }
6262  });
6263
6264  it('fail when adding unpacked uint64 values with null value', () => {
6265    const accessor = Kernel.createEmpty();
6266    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6267    if (CHECK_CRITICAL_STATE) {
6268      expect(() => accessor.addUnpackedUint64Iterable(1, [fakeUint64]))
6269          .toThrowError('Must be Int64 instance, but got: null');
6270    } else {
6271      // Note in unchecked mode we produce invalid output for invalid inputs.
6272      // This test just documents our behavior in those cases.
6273      // These values might change at any point and are not considered
6274      // what the implementation should be doing here.
6275      accessor.addUnpackedUint64Iterable(1, [fakeUint64]);
6276      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6277    }
6278  });
6279
6280  it('fail when adding single unpacked uint64 value with null value', () => {
6281    const accessor = Kernel.createEmpty();
6282    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6283    if (CHECK_CRITICAL_STATE) {
6284      expect(() => accessor.addUnpackedUint64Element(1, fakeUint64))
6285          .toThrowError('Must be Int64 instance, but got: null');
6286    } else {
6287      // Note in unchecked mode we produce invalid output for invalid inputs.
6288      // This test just documents our behavior in those cases.
6289      // These values might change at any point and are not considered
6290      // what the implementation should be doing here.
6291      accessor.addUnpackedUint64Element(1, fakeUint64);
6292      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6293    }
6294  });
6295
6296  it('fail when setting unpacked uint64 values with null value', () => {
6297    const accessor = Kernel.createEmpty();
6298    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6299    if (CHECK_CRITICAL_STATE) {
6300      expect(() => accessor.setUnpackedUint64Iterable(1, [fakeUint64]))
6301          .toThrowError('Must be Int64 instance, but got: null');
6302    } else {
6303      // Note in unchecked mode we produce invalid output for invalid inputs.
6304      // This test just documents our behavior in those cases.
6305      // These values might change at any point and are not considered
6306      // what the implementation should be doing here.
6307      accessor.setUnpackedUint64Iterable(1, [fakeUint64]);
6308      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6309    }
6310  });
6311
6312  it('fail when setting single unpacked uint64 value with null value', () => {
6313    const accessor =
6314        Kernel.fromArrayBuffer(createArrayBuffer(0x0D, 0x80, 0x80, 0x80, 0x00));
6315    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6316    if (CHECK_CRITICAL_STATE) {
6317      expect(() => accessor.setUnpackedUint64Element(1, 0, fakeUint64))
6318          .toThrowError('Must be Int64 instance, but got: null');
6319    } else {
6320      // Note in unchecked mode we produce invalid output for invalid inputs.
6321      // This test just documents our behavior in those cases.
6322      // These values might change at any point and are not considered
6323      // what the implementation should be doing here.
6324      accessor.setUnpackedUint64Element(1, 0, fakeUint64);
6325      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6326    }
6327  });
6328
6329  it('fail when adding packed uint64 values with null value', () => {
6330    const accessor = Kernel.createEmpty();
6331    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6332    if (CHECK_CRITICAL_STATE) {
6333      expect(() => accessor.addPackedUint64Iterable(1, [fakeUint64]))
6334          .toThrowError('Must be Int64 instance, but got: null');
6335    } else {
6336      // Note in unchecked mode we produce invalid output for invalid inputs.
6337      // This test just documents our behavior in those cases.
6338      // These values might change at any point and are not considered
6339      // what the implementation should be doing here.
6340      accessor.addPackedUint64Iterable(1, [fakeUint64]);
6341      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6342    }
6343  });
6344
6345  it('fail when adding single packed uint64 value with null value', () => {
6346    const accessor = Kernel.createEmpty();
6347    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6348    if (CHECK_CRITICAL_STATE) {
6349      expect(() => accessor.addPackedUint64Element(1, fakeUint64))
6350          .toThrowError('Must be Int64 instance, but got: null');
6351    } else {
6352      // Note in unchecked mode we produce invalid output for invalid inputs.
6353      // This test just documents our behavior in those cases.
6354      // These values might change at any point and are not considered
6355      // what the implementation should be doing here.
6356      accessor.addPackedUint64Element(1, fakeUint64);
6357      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6358    }
6359  });
6360
6361  it('fail when setting packed uint64 values with null value', () => {
6362    const accessor = Kernel.createEmpty();
6363    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6364    if (CHECK_CRITICAL_STATE) {
6365      expect(() => accessor.setPackedUint64Iterable(1, [fakeUint64]))
6366          .toThrowError('Must be Int64 instance, but got: null');
6367    } else {
6368      // Note in unchecked mode we produce invalid output for invalid inputs.
6369      // This test just documents our behavior in those cases.
6370      // These values might change at any point and are not considered
6371      // what the implementation should be doing here.
6372      accessor.setPackedUint64Iterable(1, [fakeUint64]);
6373      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6374    }
6375  });
6376
6377  it('fail when setting single packed uint64 value with null value', () => {
6378    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
6379    const fakeUint64 = /** @type {!Int64} */ (/** @type {*} */ (null));
6380    if (CHECK_CRITICAL_STATE) {
6381      expect(() => accessor.setPackedUint64Element(1, 0, fakeUint64))
6382          .toThrowError('Must be Int64 instance, but got: null');
6383    } else {
6384      // Note in unchecked mode we produce invalid output for invalid inputs.
6385      // This test just documents our behavior in those cases.
6386      // These values might change at any point and are not considered
6387      // what the implementation should be doing here.
6388      accessor.setPackedUint64Element(1, 0, fakeUint64);
6389      expectQualifiedIterable(accessor.getRepeatedUint64Iterable(1));
6390    }
6391  });
6392
6393  it('fail when setting single unpacked with out-of-bound index', () => {
6394    const accessor =
6395        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x00));
6396    if (CHECK_CRITICAL_STATE) {
6397      expect(() => accessor.setUnpackedUint64Element(1, 1, Int64.fromInt(1)))
6398          .toThrowError('Index out of bounds: index: 1 size: 1');
6399    } else {
6400      // Note in unchecked mode we produce invalid output for invalid inputs.
6401      // This test just documents our behavior in those cases.
6402      // These values might change at any point and are not considered
6403      // what the implementation should be doing here.
6404      accessor.setUnpackedUint64Element(1, 1, Int64.fromInt(1));
6405      expectQualifiedIterable(
6406          accessor.getRepeatedUint64Iterable(1),
6407          (value) => value instanceof Int64);
6408    }
6409  });
6410
6411  it('fail when setting single packed with out-of-bound index', () => {
6412    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x00));
6413    if (CHECK_CRITICAL_STATE) {
6414      expect(() => accessor.setPackedUint64Element(1, 1, Int64.fromInt(1)))
6415          .toThrowError('Index out of bounds: index: 1 size: 1');
6416    } else {
6417      // Note in unchecked mode we produce invalid output for invalid inputs.
6418      // This test just documents our behavior in those cases.
6419      // These values might change at any point and are not considered
6420      // what the implementation should be doing here.
6421      accessor.setPackedUint64Element(1, 1, Int64.fromInt(1));
6422      expectQualifiedIterable(
6423          accessor.getRepeatedUint64Iterable(1),
6424          (value) => value instanceof Int64);
6425    }
6426  });
6427
6428  it('fail when getting element with out-of-range index', () => {
6429    const accessor = Kernel.createEmpty();
6430    if (CHECK_CRITICAL_STATE) {
6431      expect(() => {
6432        accessor.getRepeatedUint64Element(
6433            /* fieldNumber= */ 1, /* index= */ 0);
6434      }).toThrowError('Index out of bounds: index: 0 size: 0');
6435    } else {
6436      // Note in unchecked mode we produce invalid output for invalid inputs.
6437      // This test just documents our behavior in those cases.
6438      // These values might change at any point and are not considered
6439      // what the implementation should be doing here.
6440      expect(accessor.getRepeatedUint64Element(
6441                 /* fieldNumber= */ 1, /* index= */ 0))
6442          .toBe(undefined);
6443    }
6444  });
6445});
6446
6447describe('Kernel for repeated bytes does', () => {
6448  const value1 = ByteString.fromArrayBuffer((createArrayBuffer(0x61)));
6449  const value2 = ByteString.fromArrayBuffer((createArrayBuffer(0x62)));
6450
6451  const repeatedValue1Value2 = createArrayBuffer(
6452      0x0A,
6453      0x01,
6454      0x61,  // value1
6455      0x0A,
6456      0x01,
6457      0x62,  // value2
6458  );
6459  const repeatedValue2Value1 = createArrayBuffer(
6460      0x0A,
6461      0x01,
6462      0x62,  // value2
6463      0x0A,
6464      0x01,
6465      0x61,  // value1
6466  );
6467
6468  it('return empty array for the empty input', () => {
6469    const accessor = Kernel.createEmpty();
6470
6471    const list = accessor.getRepeatedBytesIterable(1);
6472
6473    expectEqualToArray(list, []);
6474  });
6475
6476  it('ensure not the same instance returned for the empty input', () => {
6477    const accessor = Kernel.createEmpty();
6478
6479    const list1 = accessor.getRepeatedBytesIterable(1);
6480    const list2 = accessor.getRepeatedBytesIterable(1);
6481
6482    expect(list1).not.toBe(list2);
6483  });
6484
6485  it('return size for the empty input', () => {
6486    const accessor = Kernel.createEmpty();
6487
6488    const size = accessor.getRepeatedBytesSize(1);
6489
6490    expect(size).toEqual(0);
6491  });
6492
6493  it('return values from the input', () => {
6494    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6495
6496    const list = accessor.getRepeatedBytesIterable(1);
6497
6498    expectEqualToArray(list, [value1, value2]);
6499  });
6500
6501  it('ensure not the same instance returned for values', () => {
6502    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6503
6504    const list1 = accessor.getRepeatedBytesIterable(1);
6505    const list2 = accessor.getRepeatedBytesIterable(1);
6506
6507    expect(list1).not.toBe(list2);
6508  });
6509
6510  it('add single value', () => {
6511    const accessor = Kernel.createEmpty();
6512
6513    accessor.addRepeatedBytesElement(1, value1);
6514    const list1 = accessor.getRepeatedBytesIterable(1);
6515    accessor.addRepeatedBytesElement(1, value2);
6516    const list2 = accessor.getRepeatedBytesIterable(1);
6517
6518    expectEqualToArray(list1, [value1]);
6519    expectEqualToArray(list2, [value1, value2]);
6520  });
6521
6522  it('add values', () => {
6523    const accessor = Kernel.createEmpty();
6524
6525    accessor.addRepeatedBytesIterable(1, [value1]);
6526    const list1 = accessor.getRepeatedBytesIterable(1);
6527    accessor.addRepeatedBytesIterable(1, [value2]);
6528    const list2 = accessor.getRepeatedBytesIterable(1);
6529
6530    expectEqualToArray(list1, [value1]);
6531    expectEqualToArray(list2, [value1, value2]);
6532  });
6533
6534  it('set a single value', () => {
6535    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6536
6537    accessor.setRepeatedBytesElement(1, 1, value1);
6538    const list = accessor.getRepeatedBytesIterable(1);
6539
6540    expectEqualToArray(list, [value1, value1]);
6541  });
6542
6543  it('set values', () => {
6544    const accessor = Kernel.createEmpty();
6545
6546    accessor.setRepeatedBytesIterable(1, [value1]);
6547    const list = accessor.getRepeatedBytesIterable(1);
6548
6549    expectEqualToArray(list, [value1]);
6550  });
6551
6552  it('encode for adding single value', () => {
6553    const accessor = Kernel.createEmpty();
6554
6555    accessor.addRepeatedBytesElement(1, value1);
6556    accessor.addRepeatedBytesElement(1, value2);
6557    const serialized = accessor.serialize();
6558
6559    expect(serialized).toEqual(repeatedValue1Value2);
6560  });
6561
6562  it('encode for adding values', () => {
6563    const accessor = Kernel.createEmpty();
6564
6565    accessor.addRepeatedBytesIterable(1, [value1]);
6566    accessor.addRepeatedBytesIterable(1, [value2]);
6567    const serialized = accessor.serialize();
6568
6569    expect(serialized).toEqual(repeatedValue1Value2);
6570  });
6571
6572  it('encode for setting single value', () => {
6573    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6574
6575    accessor.setRepeatedBytesElement(1, 0, value2);
6576    accessor.setRepeatedBytesElement(1, 1, value1);
6577    const serialized = accessor.serialize();
6578
6579    expect(serialized).toEqual(repeatedValue2Value1);
6580  });
6581
6582  it('encode for setting values', () => {
6583    const accessor = Kernel.createEmpty();
6584
6585    accessor.setRepeatedBytesIterable(1, [value1, value2]);
6586    const serialized = accessor.serialize();
6587
6588    expect(serialized).toEqual(repeatedValue1Value2);
6589  });
6590
6591  it('return the repeated field element from the input', () => {
6592    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6593
6594    const result1 = accessor.getRepeatedBytesElement(
6595        /* fieldNumber= */ 1, /* index= */ 0);
6596    const result2 = accessor.getRepeatedBytesElement(
6597        /* fieldNumber= */ 1, /* index= */ 1);
6598
6599    expect(result1).toEqual(value1);
6600    expect(result2).toEqual(value2);
6601  });
6602
6603  it('return the size from the input', () => {
6604    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6605
6606    const size = accessor.getRepeatedBytesSize(1);
6607
6608    expect(size).toEqual(2);
6609  });
6610
6611  it('fail when getting bytes value with other wire types', () => {
6612    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
6613        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
6614    if (CHECK_CRITICAL_STATE) {
6615      expect(() => {
6616        accessor.getRepeatedBytesIterable(1);
6617      }).toThrowError('Expected wire type: 2 but found: 0');
6618    } else {
6619      // Note in unchecked mode we produce invalid output for invalid inputs.
6620      // This test just documents our behavior in those cases.
6621      // These values might change at any point and are not considered
6622      // what the implementation should be doing here.
6623      expectQualifiedIterable(
6624          accessor.getRepeatedBytesIterable(1),
6625          (value) => value instanceof ByteString);
6626    }
6627  });
6628
6629  it('fail when adding bytes values with null value', () => {
6630    const accessor = Kernel.createEmpty();
6631    const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
6632    if (CHECK_CRITICAL_STATE) {
6633      expect(() => accessor.addRepeatedBytesIterable(1, [fakeBytes]))
6634          .toThrowError('Must be a ByteString, but got: null');
6635    } else {
6636      // Note in unchecked mode we produce invalid output for invalid inputs.
6637      // This test just documents our behavior in those cases.
6638      // These values might change at any point and are not considered
6639      // what the implementation should be doing here.
6640      accessor.addRepeatedBytesIterable(1, [fakeBytes]);
6641      expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
6642    }
6643  });
6644
6645  it('fail when adding single bytes value with null value', () => {
6646    const accessor = Kernel.createEmpty();
6647    const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
6648    if (CHECK_CRITICAL_STATE) {
6649      expect(() => accessor.addRepeatedBytesElement(1, fakeBytes))
6650          .toThrowError('Must be a ByteString, but got: null');
6651    } else {
6652      // Note in unchecked mode we produce invalid output for invalid inputs.
6653      // This test just documents our behavior in those cases.
6654      // These values might change at any point and are not considered
6655      // what the implementation should be doing here.
6656      accessor.addRepeatedBytesElement(1, fakeBytes);
6657      expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
6658    }
6659  });
6660
6661  it('fail when setting bytes values with null value', () => {
6662    const accessor = Kernel.createEmpty();
6663    const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
6664    if (CHECK_CRITICAL_STATE) {
6665      expect(() => accessor.setRepeatedBytesIterable(1, [fakeBytes]))
6666          .toThrowError('Must be a ByteString, but got: null');
6667    } else {
6668      // Note in unchecked mode we produce invalid output for invalid inputs.
6669      // This test just documents our behavior in those cases.
6670      // These values might change at any point and are not considered
6671      // what the implementation should be doing here.
6672      accessor.setRepeatedBytesIterable(1, [fakeBytes]);
6673      expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
6674    }
6675  });
6676
6677  it('fail when setting single bytes value with null value', () => {
6678    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
6679        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
6680    const fakeBytes = /** @type {!ByteString} */ (/** @type {*} */ (null));
6681    if (CHECK_CRITICAL_STATE) {
6682      expect(() => accessor.setRepeatedBytesElement(1, 0, fakeBytes))
6683          .toThrowError('Must be a ByteString, but got: null');
6684    } else {
6685      // Note in unchecked mode we produce invalid output for invalid inputs.
6686      // This test just documents our behavior in those cases.
6687      // These values might change at any point and are not considered
6688      // what the implementation should be doing here.
6689      accessor.setRepeatedBytesElement(1, 0, fakeBytes);
6690      expectQualifiedIterable(accessor.getRepeatedBytesIterable(1));
6691    }
6692  });
6693
6694  it('fail when setting single with out-of-bound index', () => {
6695    const accessor =
6696        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x61));
6697    if (CHECK_CRITICAL_STATE) {
6698      expect(() => accessor.setRepeatedBytesElement(1, 1, value1))
6699          .toThrowError('Index out of bounds: index: 1 size: 1');
6700    } else {
6701      // Note in unchecked mode we produce invalid output for invalid inputs.
6702      // This test just documents our behavior in those cases.
6703      // These values might change at any point and are not considered
6704      // what the implementation should be doing here.
6705      accessor.setRepeatedBytesElement(1, 1, value1);
6706      expectQualifiedIterable(
6707          accessor.getRepeatedBytesIterable(1),
6708          (value) => value instanceof ByteString);
6709    }
6710  });
6711
6712  it('fail when getting element with out-of-range index', () => {
6713    const accessor = Kernel.createEmpty();
6714    if (CHECK_CRITICAL_STATE) {
6715      expect(() => {
6716        accessor.getRepeatedBytesElement(
6717            /* fieldNumber= */ 1, /* index= */ 0);
6718      }).toThrowError('Index out of bounds: index: 0 size: 0');
6719    } else {
6720      // Note in unchecked mode we produce invalid output for invalid inputs.
6721      // This test just documents our behavior in those cases.
6722      // These values might change at any point and are not considered
6723      // what the implementation should be doing here.
6724      expect(accessor.getRepeatedBytesElement(
6725                 /* fieldNumber= */ 1, /* index= */ 0))
6726          .toBe(undefined);
6727    }
6728  });
6729});
6730
6731describe('Kernel for repeated string does', () => {
6732  const value1 = 'a';
6733  const value2 = 'b';
6734
6735  const repeatedValue1Value2 = createArrayBuffer(
6736      0x0A,
6737      0x01,
6738      0x61,  // value1
6739      0x0A,
6740      0x01,
6741      0x62,  // value2
6742  );
6743  const repeatedValue2Value1 = createArrayBuffer(
6744      0x0A,
6745      0x01,
6746      0x62,  // value2
6747      0x0A,
6748      0x01,
6749      0x61,  // value1
6750  );
6751
6752  it('return empty array for the empty input', () => {
6753    const accessor = Kernel.createEmpty();
6754
6755    const list = accessor.getRepeatedStringIterable(1);
6756
6757    expectEqualToArray(list, []);
6758  });
6759
6760  it('ensure not the same instance returned for the empty input', () => {
6761    const accessor = Kernel.createEmpty();
6762
6763    const list1 = accessor.getRepeatedStringIterable(1);
6764    const list2 = accessor.getRepeatedStringIterable(1);
6765
6766    expect(list1).not.toBe(list2);
6767  });
6768
6769  it('return size for the empty input', () => {
6770    const accessor = Kernel.createEmpty();
6771
6772    const size = accessor.getRepeatedStringSize(1);
6773
6774    expect(size).toEqual(0);
6775  });
6776
6777  it('return values from the input', () => {
6778    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6779
6780    const list = accessor.getRepeatedStringIterable(1);
6781
6782    expectEqualToArray(list, [value1, value2]);
6783  });
6784
6785  it('ensure not the same instance returned for values', () => {
6786    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6787
6788    const list1 = accessor.getRepeatedStringIterable(1);
6789    const list2 = accessor.getRepeatedStringIterable(1);
6790
6791    expect(list1).not.toBe(list2);
6792  });
6793
6794  it('add single value', () => {
6795    const accessor = Kernel.createEmpty();
6796
6797    accessor.addRepeatedStringElement(1, value1);
6798    const list1 = accessor.getRepeatedStringIterable(1);
6799    accessor.addRepeatedStringElement(1, value2);
6800    const list2 = accessor.getRepeatedStringIterable(1);
6801
6802    expectEqualToArray(list1, [value1]);
6803    expectEqualToArray(list2, [value1, value2]);
6804  });
6805
6806  it('add values', () => {
6807    const accessor = Kernel.createEmpty();
6808
6809    accessor.addRepeatedStringIterable(1, [value1]);
6810    const list1 = accessor.getRepeatedStringIterable(1);
6811    accessor.addRepeatedStringIterable(1, [value2]);
6812    const list2 = accessor.getRepeatedStringIterable(1);
6813
6814    expectEqualToArray(list1, [value1]);
6815    expectEqualToArray(list2, [value1, value2]);
6816  });
6817
6818  it('set a single value', () => {
6819    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6820
6821    accessor.setRepeatedStringElement(1, 1, value1);
6822    const list = accessor.getRepeatedStringIterable(1);
6823
6824    expectEqualToArray(list, [value1, value1]);
6825  });
6826
6827  it('set values', () => {
6828    const accessor = Kernel.createEmpty();
6829
6830    accessor.setRepeatedStringIterable(1, [value1]);
6831    const list = accessor.getRepeatedStringIterable(1);
6832
6833    expectEqualToArray(list, [value1]);
6834  });
6835
6836  it('encode for adding single value', () => {
6837    const accessor = Kernel.createEmpty();
6838
6839    accessor.addRepeatedStringElement(1, value1);
6840    accessor.addRepeatedStringElement(1, value2);
6841    const serialized = accessor.serialize();
6842
6843    expect(serialized).toEqual(repeatedValue1Value2);
6844  });
6845
6846  it('encode for adding values', () => {
6847    const accessor = Kernel.createEmpty();
6848
6849    accessor.addRepeatedStringIterable(1, [value1]);
6850    accessor.addRepeatedStringIterable(1, [value2]);
6851    const serialized = accessor.serialize();
6852
6853    expect(serialized).toEqual(repeatedValue1Value2);
6854  });
6855
6856  it('encode for setting single value', () => {
6857    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6858
6859    accessor.setRepeatedStringElement(1, 0, value2);
6860    accessor.setRepeatedStringElement(1, 1, value1);
6861    const serialized = accessor.serialize();
6862
6863    expect(serialized).toEqual(repeatedValue2Value1);
6864  });
6865
6866  it('encode for setting values', () => {
6867    const accessor = Kernel.createEmpty();
6868
6869    accessor.setRepeatedStringIterable(1, [value1, value2]);
6870    const serialized = accessor.serialize();
6871
6872    expect(serialized).toEqual(repeatedValue1Value2);
6873  });
6874
6875  it('return the repeated field element from the input', () => {
6876    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6877
6878    const result1 = accessor.getRepeatedStringElement(
6879        /* fieldNumber= */ 1, /* index= */ 0);
6880    const result2 = accessor.getRepeatedStringElement(
6881        /* fieldNumber= */ 1, /* index= */ 1);
6882
6883    expect(result1).toEqual(value1);
6884    expect(result2).toEqual(value2);
6885  });
6886
6887  it('return the size from the input', () => {
6888    const accessor = Kernel.fromArrayBuffer(repeatedValue1Value2);
6889
6890    const size = accessor.getRepeatedStringSize(1);
6891
6892    expect(size).toEqual(2);
6893  });
6894
6895  it('fail when getting string value with other wire types', () => {
6896    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
6897        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
6898    if (CHECK_CRITICAL_STATE) {
6899      expect(() => {
6900        accessor.getRepeatedStringIterable(1);
6901      }).toThrowError('Expected wire type: 2 but found: 0');
6902    } else {
6903      // Note in unchecked mode we produce invalid output for invalid inputs.
6904      // This test just documents our behavior in those cases.
6905      // These values might change at any point and are not considered
6906      // what the implementation should be doing here.
6907      expectQualifiedIterable(
6908          accessor.getRepeatedStringIterable(1),
6909          (value) => typeof value === 'string');
6910    }
6911  });
6912
6913  it('fail when adding string values with null value', () => {
6914    const accessor = Kernel.createEmpty();
6915    const fakeString = /** @type {string} */ (/** @type {*} */ (null));
6916    if (CHECK_CRITICAL_STATE) {
6917      expect(() => accessor.addRepeatedStringIterable(1, [fakeString]))
6918          .toThrowError('Must be string, but got: null');
6919    } else {
6920      // Note in unchecked mode we produce invalid output for invalid inputs.
6921      // This test just documents our behavior in those cases.
6922      // These values might change at any point and are not considered
6923      // what the implementation should be doing here.
6924      accessor.addRepeatedStringIterable(1, [fakeString]);
6925      expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
6926    }
6927  });
6928
6929  it('fail when adding single string value with null value', () => {
6930    const accessor = Kernel.createEmpty();
6931    const fakeString = /** @type {string} */ (/** @type {*} */ (null));
6932    if (CHECK_CRITICAL_STATE) {
6933      expect(() => accessor.addRepeatedStringElement(1, fakeString))
6934          .toThrowError('Must be string, but got: null');
6935    } else {
6936      // Note in unchecked mode we produce invalid output for invalid inputs.
6937      // This test just documents our behavior in those cases.
6938      // These values might change at any point and are not considered
6939      // what the implementation should be doing here.
6940      accessor.addRepeatedStringElement(1, fakeString);
6941      expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
6942    }
6943  });
6944
6945  it('fail when setting string values with null value', () => {
6946    const accessor = Kernel.createEmpty();
6947    const fakeString = /** @type {string} */ (/** @type {*} */ (null));
6948    if (CHECK_CRITICAL_STATE) {
6949      expect(() => accessor.setRepeatedStringIterable(1, [fakeString]))
6950          .toThrowError('Must be string, but got: null');
6951    } else {
6952      // Note in unchecked mode we produce invalid output for invalid inputs.
6953      // This test just documents our behavior in those cases.
6954      // These values might change at any point and are not considered
6955      // what the implementation should be doing here.
6956      accessor.setRepeatedStringIterable(1, [fakeString]);
6957      expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
6958    }
6959  });
6960
6961  it('fail when setting single string value with null value', () => {
6962    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
6963        0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
6964    const fakeString = /** @type {string} */ (/** @type {*} */ (null));
6965    if (CHECK_CRITICAL_STATE) {
6966      expect(() => accessor.setRepeatedStringElement(1, 0, fakeString))
6967          .toThrowError('Must be string, but got: null');
6968    } else {
6969      // Note in unchecked mode we produce invalid output for invalid inputs.
6970      // This test just documents our behavior in those cases.
6971      // These values might change at any point and are not considered
6972      // what the implementation should be doing here.
6973      accessor.setRepeatedStringElement(1, 0, fakeString);
6974      expectQualifiedIterable(accessor.getRepeatedStringIterable(1));
6975    }
6976  });
6977
6978  it('fail when setting single with out-of-bound index', () => {
6979    const accessor =
6980        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x01, 0x61));
6981    if (CHECK_CRITICAL_STATE) {
6982      expect(() => accessor.setRepeatedStringElement(1, 1, value1))
6983          .toThrowError('Index out of bounds: index: 1 size: 1');
6984    } else {
6985      // Note in unchecked mode we produce invalid output for invalid inputs.
6986      // This test just documents our behavior in those cases.
6987      // These values might change at any point and are not considered
6988      // what the implementation should be doing here.
6989      accessor.setRepeatedStringElement(1, 1, value1);
6990      expectQualifiedIterable(
6991          accessor.getRepeatedStringIterable(1),
6992          (value) => typeof value === 'string');
6993    }
6994  });
6995
6996  it('fail when getting element with out-of-range index', () => {
6997    const accessor = Kernel.createEmpty();
6998    if (CHECK_CRITICAL_STATE) {
6999      expect(() => {
7000        accessor.getRepeatedStringElement(
7001            /* fieldNumber= */ 1, /* index= */ 0);
7002      }).toThrowError('Index out of bounds: index: 0 size: 0');
7003    } else {
7004      // Note in unchecked mode we produce invalid output for invalid inputs.
7005      // This test just documents our behavior in those cases.
7006      // These values might change at any point and are not considered
7007      // what the implementation should be doing here.
7008      expect(accessor.getRepeatedStringElement(
7009                 /* fieldNumber= */ 1, /* index= */ 0))
7010          .toBe(undefined);
7011    }
7012  });
7013});
7014
7015describe('Kernel for repeated message does', () => {
7016  it('return empty array for the empty input', () => {
7017    const accessor = Kernel.createEmpty();
7018    expectEqualToArray(
7019        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
7020        []);
7021  });
7022
7023  it('return empty accessor array for the empty input', () => {
7024    const accessor = Kernel.createEmpty();
7025    expectEqualToArray(accessor.getRepeatedMessageAccessorIterable(1), []);
7026  });
7027
7028  it('ensure not the same instance returned for the empty input', () => {
7029    const accessor = Kernel.createEmpty();
7030    const list1 =
7031        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7032    const list2 =
7033        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7034    expect(list1).not.toBe(list2);
7035  });
7036
7037  it('return size for the empty input', () => {
7038    const accessor = Kernel.createEmpty();
7039    expect(accessor.getRepeatedMessageSize(1, TestMessage.instanceCreator))
7040        .toEqual(0);
7041  });
7042
7043  it('return values from the input', () => {
7044    const bytes1 = createArrayBuffer(0x08, 0x01);
7045    const bytes2 = createArrayBuffer(0x08, 0x00);
7046    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7047    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7048
7049    const bytes =
7050        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7051    const accessor = Kernel.fromArrayBuffer(bytes);
7052    expectEqualToMessageArray(
7053        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
7054        [msg1, msg2]);
7055  });
7056
7057  it('ensure not the same array instance returned', () => {
7058    const bytes =
7059        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7060    const accessor = Kernel.fromArrayBuffer(bytes);
7061    const list1 =
7062        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7063    const list2 =
7064        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7065    expect(list1).not.toBe(list2);
7066  });
7067
7068  it('ensure the same array element returned for get iterable', () => {
7069    const bytes =
7070        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7071    const accessor = Kernel.fromArrayBuffer(bytes);
7072    const list1 =
7073        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7074    const list2 = accessor.getRepeatedMessageIterable(
7075        1, TestMessage.instanceCreator, /* pivot= */ 0);
7076    const array1 = Array.from(list1);
7077    const array2 = Array.from(list2);
7078    for (let i = 0; i < array1.length; i++) {
7079      expect(array1[i]).toBe(array2[i]);
7080    }
7081  });
7082
7083  it('return accessors from the input', () => {
7084    const bytes =
7085        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7086    const accessor = Kernel.fromArrayBuffer(bytes);
7087    const [accessor1, accessor2] =
7088        [...accessor.getRepeatedMessageAccessorIterable(1)];
7089    expect(accessor1.getInt32WithDefault(1)).toEqual(1);
7090    expect(accessor2.getInt32WithDefault(1)).toEqual(0);
7091  });
7092
7093  it('return accessors from the input when pivot is set', () => {
7094    const bytes =
7095        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7096    const accessor = Kernel.fromArrayBuffer(bytes);
7097    const [accessor1, accessor2] =
7098        [...accessor.getRepeatedMessageAccessorIterable(1, /* pivot= */ 0)];
7099    expect(accessor1.getInt32WithDefault(1)).toEqual(1);
7100    expect(accessor2.getInt32WithDefault(1)).toEqual(0);
7101  });
7102
7103  it('return the repeated field element from the input', () => {
7104    const bytes =
7105        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7106    const accessor = Kernel.fromArrayBuffer(bytes);
7107    const msg1 = accessor.getRepeatedMessageElement(
7108        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7109        /* index= */ 0);
7110    const msg2 = accessor.getRepeatedMessageElement(
7111        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7112        /* index= */ 1, /* pivot= */ 0);
7113    expect(msg1.getBoolWithDefault(
7114               /* fieldNumber= */ 1, /* default= */ false))
7115        .toEqual(true);
7116    expect(msg2.getBoolWithDefault(
7117               /* fieldNumber= */ 1, /* default= */ false))
7118        .toEqual(false);
7119  });
7120
7121  it('ensure the same array element returned', () => {
7122    const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
7123    const accessor = Kernel.fromArrayBuffer(bytes);
7124    const msg1 = accessor.getRepeatedMessageElement(
7125        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7126        /* index= */ 0);
7127    const msg2 = accessor.getRepeatedMessageElement(
7128        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7129        /* index= */ 0);
7130    expect(msg1).toBe(msg2);
7131  });
7132
7133  it('return the size from the input', () => {
7134    const bytes =
7135        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7136    const accessor = Kernel.fromArrayBuffer(bytes);
7137    expect(accessor.getRepeatedMessageSize(1, TestMessage.instanceCreator))
7138        .toEqual(2);
7139  });
7140
7141  it('encode repeated message from the input', () => {
7142    const bytes =
7143        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7144    const accessor = Kernel.fromArrayBuffer(bytes);
7145    expect(accessor.serialize()).toEqual(bytes);
7146  });
7147
7148  it('add a single value', () => {
7149    const accessor = Kernel.createEmpty();
7150    const bytes1 = createArrayBuffer(0x08, 0x01);
7151    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7152    const bytes2 = createArrayBuffer(0x08, 0x00);
7153    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7154
7155    accessor.addRepeatedMessageElement(1, msg1, TestMessage.instanceCreator);
7156    accessor.addRepeatedMessageElement(1, msg2, TestMessage.instanceCreator);
7157    const result =
7158        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7159
7160    expect(Array.from(result)).toEqual([msg1, msg2]);
7161  });
7162
7163  it('add values', () => {
7164    const accessor = Kernel.createEmpty();
7165    const bytes1 = createArrayBuffer(0x08, 0x01);
7166    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7167    const bytes2 = createArrayBuffer(0x08, 0x00);
7168    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7169
7170    accessor.addRepeatedMessageIterable(1, [msg1], TestMessage.instanceCreator);
7171    accessor.addRepeatedMessageIterable(1, [msg2], TestMessage.instanceCreator);
7172    const result =
7173        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7174
7175    expect(Array.from(result)).toEqual([msg1, msg2]);
7176  });
7177
7178  it('set a single value', () => {
7179    const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
7180    const accessor = Kernel.fromArrayBuffer(bytes);
7181    const subbytes = createArrayBuffer(0x08, 0x01);
7182    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7183
7184    accessor.setRepeatedMessageElement(
7185        /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
7186        /* index= */ 0);
7187    const result =
7188        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7189
7190    expect(Array.from(result)).toEqual([submsg]);
7191  });
7192
7193  it('write submessage changes made via getRepeatedMessagElement', () => {
7194    const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x05);
7195    const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
7196    const accessor = Kernel.fromArrayBuffer(bytes);
7197    const submsg = accessor.getRepeatedMessageElement(
7198        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7199        /* index= */ 0);
7200    expect(submsg.getInt32WithDefault(1, 0)).toEqual(5);
7201    submsg.setInt32(1, 0);
7202
7203    expect(accessor.serialize()).toEqual(expected);
7204  });
7205
7206  it('set values', () => {
7207    const accessor = Kernel.createEmpty();
7208    const subbytes = createArrayBuffer(0x08, 0x01);
7209    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7210
7211    accessor.setRepeatedMessageIterable(1, [submsg]);
7212    const result =
7213        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7214
7215    expect(Array.from(result)).toEqual([submsg]);
7216  });
7217
7218  it('encode for adding single value', () => {
7219    const accessor = Kernel.createEmpty();
7220    const bytes1 = createArrayBuffer(0x08, 0x01);
7221    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7222    const bytes2 = createArrayBuffer(0x08, 0x00);
7223    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7224    const expected =
7225        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7226
7227    accessor.addRepeatedMessageElement(1, msg1, TestMessage.instanceCreator);
7228    accessor.addRepeatedMessageElement(1, msg2, TestMessage.instanceCreator);
7229    const result = accessor.serialize();
7230
7231    expect(result).toEqual(expected);
7232  });
7233
7234  it('encode for adding values', () => {
7235    const accessor = Kernel.createEmpty();
7236    const bytes1 = createArrayBuffer(0x08, 0x01);
7237    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7238    const bytes2 = createArrayBuffer(0x08, 0x00);
7239    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7240    const expected =
7241        createArrayBuffer(0x0A, 0x02, 0x08, 0x01, 0x0A, 0x02, 0x08, 0x00);
7242
7243    accessor.addRepeatedMessageIterable(
7244        1, [msg1, msg2], TestMessage.instanceCreator);
7245    const result = accessor.serialize();
7246
7247    expect(result).toEqual(expected);
7248  });
7249
7250  it('encode for setting single value', () => {
7251    const bytes = createArrayBuffer(0x0A, 0x02, 0x08, 0x00);
7252    const accessor = Kernel.fromArrayBuffer(bytes);
7253    const subbytes = createArrayBuffer(0x08, 0x01);
7254    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7255    const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
7256
7257    accessor.setRepeatedMessageElement(
7258        /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
7259        /* index= */ 0);
7260    const result = accessor.serialize();
7261
7262    expect(result).toEqual(expected);
7263  });
7264
7265  it('encode for setting values', () => {
7266    const accessor = Kernel.createEmpty();
7267    const subbytes = createArrayBuffer(0x08, 0x01);
7268    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7269    const expected = createArrayBuffer(0x0A, 0x02, 0x08, 0x01);
7270
7271    accessor.setRepeatedMessageIterable(1, [submsg]);
7272    const result = accessor.serialize();
7273
7274    expect(result).toEqual(expected);
7275  });
7276
7277  it('get accessors from set values.', () => {
7278    const accessor = Kernel.createEmpty();
7279    const bytes1 = createArrayBuffer(0x08, 0x01);
7280    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7281    const bytes2 = createArrayBuffer(0x08, 0x00);
7282    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7283
7284    accessor.addRepeatedMessageIterable(
7285        1, [msg1, msg2], TestMessage.instanceCreator);
7286
7287    const [accessor1, accessor2] =
7288        [...accessor.getRepeatedMessageAccessorIterable(1)];
7289    expect(accessor1.getInt32WithDefault(1)).toEqual(1);
7290    expect(accessor2.getInt32WithDefault(1)).toEqual(0);
7291
7292    // Retrieved accessors are the exact same accessors as the added messages.
7293    expect(accessor1).toBe(
7294        (/** @type {!InternalMessage} */ (msg1)).internalGetKernel());
7295    expect(accessor2).toBe(
7296        (/** @type {!InternalMessage} */ (msg2)).internalGetKernel());
7297  });
7298
7299  it('fail when getting message value with other wire types', () => {
7300    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
7301        0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
7302    if (CHECK_CRITICAL_STATE) {
7303      expect(() => {
7304        accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7305      }).toThrow();
7306    } else {
7307      // Note in unchecked mode we produce invalid output for invalid inputs.
7308      // This test just documents our behavior in those cases.
7309      // These values might change at any point and are not considered
7310      // what the implementation should be doing here.
7311      const [msg1] =
7312          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7313      expect(msg1.serialize()).toEqual(createArrayBuffer());
7314    }
7315  });
7316
7317  it('fail when adding message values with wrong type value', () => {
7318    const accessor = Kernel.createEmpty();
7319    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7320    if (CHECK_CRITICAL_STATE) {
7321      expect(
7322          () => accessor.addRepeatedMessageIterable(
7323              1, [fakeValue], TestMessage.instanceCreator))
7324          .toThrowError('Given value is not a message instance: null');
7325    } else {
7326      // Note in unchecked mode we produce invalid output for invalid inputs.
7327      // This test just documents our behavior in those cases.
7328      // These values might change at any point and are not considered
7329      // what the implementation should be doing here.
7330      accessor.addRepeatedMessageIterable(
7331          1, [fakeValue], TestMessage.instanceCreator);
7332      const list =
7333          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7334      expect(Array.from(list)).toEqual([null]);
7335    }
7336  });
7337
7338  it('fail when adding single message value with wrong type value', () => {
7339    const accessor = Kernel.createEmpty();
7340    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7341    if (CHECK_CRITICAL_STATE) {
7342      expect(
7343          () => accessor.addRepeatedMessageElement(
7344              1, fakeValue, TestMessage.instanceCreator))
7345          .toThrowError('Given value is not a message instance: null');
7346    } else {
7347      // Note in unchecked mode we produce invalid output for invalid inputs.
7348      // This test just documents our behavior in those cases.
7349      // These values might change at any point and are not considered
7350      // what the implementation should be doing here.
7351      accessor.addRepeatedMessageElement(
7352          1, fakeValue, TestMessage.instanceCreator);
7353      const list =
7354          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7355      expect(Array.from(list)).toEqual([null]);
7356    }
7357  });
7358
7359  it('fail when setting message values with wrong type value', () => {
7360    const accessor = Kernel.createEmpty();
7361    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7362    if (CHECK_CRITICAL_STATE) {
7363      expect(() => accessor.setRepeatedMessageIterable(1, [fakeValue]))
7364          .toThrowError('Given value is not a message instance: null');
7365    } else {
7366      // Note in unchecked mode we produce invalid output for invalid inputs.
7367      // This test just documents our behavior in those cases.
7368      // These values might change at any point and are not considered
7369      // what the implementation should be doing here.
7370      accessor.setRepeatedMessageIterable(1, [fakeValue]);
7371      const list =
7372          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7373      expect(Array.from(list)).toEqual([null]);
7374    }
7375  });
7376
7377  it('fail when setting single value with wrong type value', () => {
7378    const accessor =
7379        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x08, 0x00));
7380    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7381    if (CHECK_CRITICAL_STATE) {
7382      expect(
7383          () => accessor.setRepeatedMessageElement(
7384              /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
7385              /* index= */ 0))
7386          .toThrowError('Given value is not a message instance: null');
7387    } else {
7388      // Note in unchecked mode we produce invalid output for invalid inputs.
7389      // This test just documents our behavior in those cases.
7390      // These values might change at any point and are not considered
7391      // what the implementation should be doing here.
7392      accessor.setRepeatedMessageElement(
7393          /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
7394          /* index= */ 0);
7395      const list =
7396          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator);
7397      expect(Array.from(list).length).toEqual(1);
7398    }
7399  });
7400
7401  it('fail when setting single value with out-of-bound index', () => {
7402    const accessor =
7403        Kernel.fromArrayBuffer(createArrayBuffer(0x0A, 0x02, 0x08, 0x00));
7404    const msg1 =
7405        accessor.getRepeatedMessageElement(1, TestMessage.instanceCreator, 0);
7406    const bytes2 = createArrayBuffer(0x08, 0x01);
7407    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7408    if (CHECK_CRITICAL_STATE) {
7409      expect(
7410          () => accessor.setRepeatedMessageElement(
7411              /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
7412              /* index= */ 1))
7413          .toThrowError('Index out of bounds: index: 1 size: 1');
7414    } else {
7415      // Note in unchecked mode we produce invalid output for invalid inputs.
7416      // This test just documents our behavior in those cases.
7417      // These values might change at any point and are not considered
7418      // what the implementation should be doing here.
7419      accessor.setRepeatedMessageElement(
7420          /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
7421          /* index= */ 1);
7422      expectEqualToArray(
7423          accessor.getRepeatedMessageIterable(1, TestMessage.instanceCreator),
7424          [msg1, msg2]);
7425    }
7426  });
7427});
7428
7429describe('Kernel for repeated groups does', () => {
7430  it('return empty array for the empty input', () => {
7431    const accessor = Kernel.createEmpty();
7432    expectEqualToArray(
7433        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator), []);
7434  });
7435
7436  it('ensure not the same instance returned for the empty input', () => {
7437    const accessor = Kernel.createEmpty();
7438    const list1 =
7439        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7440    const list2 =
7441        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7442    expect(list1).not.toBe(list2);
7443  });
7444
7445  it('return size for the empty input', () => {
7446    const accessor = Kernel.createEmpty();
7447    expect(accessor.getRepeatedGroupSize(1, TestMessage.instanceCreator))
7448        .toEqual(0);
7449  });
7450
7451  it('return values from the input', () => {
7452    const bytes1 = createArrayBuffer(0x08, 0x01);
7453    const bytes2 = createArrayBuffer(0x08, 0x02);
7454    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7455    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7456
7457    const bytes =
7458        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7459    const accessor = Kernel.fromArrayBuffer(bytes);
7460    expectEqualToMessageArray(
7461        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator),
7462        [msg1, msg2]);
7463  });
7464
7465  it('ensure not the same array instance returned', () => {
7466    const bytes =
7467        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7468    const accessor = Kernel.fromArrayBuffer(bytes);
7469    const list1 =
7470        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7471    const list2 =
7472        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7473    expect(list1).not.toBe(list2);
7474  });
7475
7476  it('ensure the same array element returned for get iterable', () => {
7477    const bytes =
7478        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7479    const accessor = Kernel.fromArrayBuffer(bytes);
7480    const list1 =
7481        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7482    const list2 = accessor.getRepeatedGroupIterable(
7483        1, TestMessage.instanceCreator, /* pivot= */ 0);
7484    const array1 = Array.from(list1);
7485    const array2 = Array.from(list2);
7486    for (let i = 0; i < array1.length; i++) {
7487      expect(array1[i]).toBe(array2[i]);
7488    }
7489  });
7490
7491  it('return accessors from the input', () => {
7492    const bytes =
7493        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7494    const accessor = Kernel.fromArrayBuffer(bytes);
7495    const [accessor1, accessor2] =
7496        [...accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator)];
7497    expect(accessor1.getInt32WithDefault(1)).toEqual(1);
7498    expect(accessor2.getInt32WithDefault(1)).toEqual(2);
7499  });
7500
7501  it('return accessors from the input when pivot is set', () => {
7502    const bytes =
7503        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7504    const accessor = Kernel.fromArrayBuffer(bytes);
7505    const [accessor1, accessor2] = [...accessor.getRepeatedGroupIterable(
7506        1, TestMessage.instanceCreator, /* pivot= */ 0)];
7507    expect(accessor1.getInt32WithDefault(1)).toEqual(1);
7508    expect(accessor2.getInt32WithDefault(1)).toEqual(2);
7509  });
7510
7511  it('return the repeated field element from the input', () => {
7512    const bytes =
7513        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7514    const accessor = Kernel.fromArrayBuffer(bytes);
7515    const msg1 = accessor.getRepeatedGroupElement(
7516        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7517        /* index= */ 0);
7518    const msg2 = accessor.getRepeatedGroupElement(
7519        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7520        /* index= */ 1, /* pivot= */ 0);
7521    expect(msg1.getInt32WithDefault(
7522               /* fieldNumber= */ 1, /* default= */ 0))
7523        .toEqual(1);
7524    expect(msg2.getInt32WithDefault(
7525               /* fieldNumber= */ 1, /* default= */ 0))
7526        .toEqual(2);
7527  });
7528
7529  it('ensure the same array element returned', () => {
7530    const bytes =
7531        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7532    const accessor = Kernel.fromArrayBuffer(bytes);
7533    const msg1 = accessor.getRepeatedGroupElement(
7534        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7535        /* index= */ 0);
7536    const msg2 = accessor.getRepeatedGroupElement(
7537        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7538        /* index= */ 0);
7539    expect(msg1).toBe(msg2);
7540  });
7541
7542  it('return the size from the input', () => {
7543    const bytes =
7544        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7545    const accessor = Kernel.fromArrayBuffer(bytes);
7546    expect(accessor.getRepeatedGroupSize(1, TestMessage.instanceCreator))
7547        .toEqual(2);
7548  });
7549
7550  it('encode repeated message from the input', () => {
7551    const bytes =
7552        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x02, 0x0C);
7553    const accessor = Kernel.fromArrayBuffer(bytes);
7554    expect(accessor.serialize()).toEqual(bytes);
7555  });
7556
7557  it('add a single value', () => {
7558    const accessor = Kernel.createEmpty();
7559    const bytes1 = createArrayBuffer(0x08, 0x01);
7560    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7561    const bytes2 = createArrayBuffer(0x08, 0x02);
7562    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7563
7564    accessor.addRepeatedGroupElement(1, msg1, TestMessage.instanceCreator);
7565    accessor.addRepeatedGroupElement(1, msg2, TestMessage.instanceCreator);
7566    const result =
7567        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7568
7569    expect(Array.from(result)).toEqual([msg1, msg2]);
7570  });
7571
7572  it('add values', () => {
7573    const accessor = Kernel.createEmpty();
7574    const bytes1 = createArrayBuffer(0x08, 0x01);
7575    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7576    const bytes2 = createArrayBuffer(0x08, 0x02);
7577    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7578
7579    accessor.addRepeatedGroupIterable(1, [msg1], TestMessage.instanceCreator);
7580    accessor.addRepeatedGroupIterable(1, [msg2], TestMessage.instanceCreator);
7581    const result =
7582        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7583
7584    expect(Array.from(result)).toEqual([msg1, msg2]);
7585  });
7586
7587  it('set a single value', () => {
7588    const bytes = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
7589    const accessor = Kernel.fromArrayBuffer(bytes);
7590    const subbytes = createArrayBuffer(0x08, 0x01);
7591    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7592
7593    accessor.setRepeatedGroupElement(
7594        /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
7595        /* index= */ 0);
7596    const result =
7597        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7598
7599    expect(Array.from(result)).toEqual([submsg]);
7600  });
7601
7602  it('write submessage changes made via getRepeatedGroupElement', () => {
7603    const bytes = createArrayBuffer(0x0B, 0x08, 0x05, 0x0C);
7604    const expected = createArrayBuffer(0x0B, 0x08, 0x00, 0x0C);
7605    const accessor = Kernel.fromArrayBuffer(bytes);
7606    const submsg = accessor.getRepeatedGroupElement(
7607        /* fieldNumber= */ 1, TestMessage.instanceCreator,
7608        /* index= */ 0);
7609    expect(submsg.getInt32WithDefault(1, 0)).toEqual(5);
7610    submsg.setInt32(1, 0);
7611
7612    expect(accessor.serialize()).toEqual(expected);
7613  });
7614
7615  it('set values', () => {
7616    const accessor = Kernel.createEmpty();
7617    const subbytes = createArrayBuffer(0x08, 0x01);
7618    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7619
7620    accessor.setRepeatedGroupIterable(1, [submsg]);
7621    const result =
7622        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7623
7624    expect(Array.from(result)).toEqual([submsg]);
7625  });
7626
7627  it('encode for adding single value', () => {
7628    const accessor = Kernel.createEmpty();
7629    const bytes1 = createArrayBuffer(0x08, 0x01);
7630    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7631    const bytes2 = createArrayBuffer(0x08, 0x00);
7632    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7633    const expected =
7634        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x00, 0x0C);
7635
7636    accessor.addRepeatedGroupElement(1, msg1, TestMessage.instanceCreator);
7637    accessor.addRepeatedGroupElement(1, msg2, TestMessage.instanceCreator);
7638    const result = accessor.serialize();
7639
7640    expect(result).toEqual(expected);
7641  });
7642
7643  it('encode for adding values', () => {
7644    const accessor = Kernel.createEmpty();
7645    const bytes1 = createArrayBuffer(0x08, 0x01);
7646    const msg1 = new TestMessage(Kernel.fromArrayBuffer(bytes1));
7647    const bytes2 = createArrayBuffer(0x08, 0x00);
7648    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7649    const expected =
7650        createArrayBuffer(0x0B, 0x08, 0x01, 0x0C, 0x0B, 0x08, 0x00, 0x0C);
7651
7652    accessor.addRepeatedGroupIterable(
7653        1, [msg1, msg2], TestMessage.instanceCreator);
7654    const result = accessor.serialize();
7655
7656    expect(result).toEqual(expected);
7657  });
7658
7659  it('encode for setting single value', () => {
7660    const bytes = createArrayBuffer(0x0B, 0x08, 0x00, 0x0C);
7661    const accessor = Kernel.fromArrayBuffer(bytes);
7662    const subbytes = createArrayBuffer(0x08, 0x01);
7663    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7664    const expected = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
7665
7666    accessor.setRepeatedGroupElement(
7667        /* fieldNumber= */ 1, submsg, TestMessage.instanceCreator,
7668        /* index= */ 0);
7669    const result = accessor.serialize();
7670
7671    expect(result).toEqual(expected);
7672  });
7673
7674  it('encode for setting values', () => {
7675    const accessor = Kernel.createEmpty();
7676    const subbytes = createArrayBuffer(0x08, 0x01);
7677    const submsg = new TestMessage(Kernel.fromArrayBuffer(subbytes));
7678    const expected = createArrayBuffer(0x0B, 0x08, 0x01, 0x0C);
7679
7680    accessor.setRepeatedGroupIterable(1, [submsg]);
7681    const result = accessor.serialize();
7682
7683    expect(result).toEqual(expected);
7684  });
7685
7686  it('fail when getting groups value with other wire types', () => {
7687    const accessor = Kernel.fromArrayBuffer(createArrayBuffer(
7688        0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
7689
7690    if (CHECK_CRITICAL_STATE) {
7691      expect(() => {
7692        accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7693      }).toThrow();
7694    }
7695  });
7696
7697  it('fail when adding group values with wrong type value', () => {
7698    const accessor = Kernel.createEmpty();
7699    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7700    if (CHECK_CRITICAL_STATE) {
7701      expect(
7702          () => accessor.addRepeatedGroupIterable(
7703              1, [fakeValue], TestMessage.instanceCreator))
7704          .toThrowError('Given value is not a message instance: null');
7705    } else {
7706      // Note in unchecked mode we produce invalid output for invalid inputs.
7707      // This test just documents our behavior in those cases.
7708      // These values might change at any point and are not considered
7709      // what the implementation should be doing here.
7710      accessor.addRepeatedGroupIterable(
7711          1, [fakeValue], TestMessage.instanceCreator);
7712      const list =
7713          accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7714      expect(Array.from(list)).toEqual([null]);
7715    }
7716  });
7717
7718  it('fail when adding single group value with wrong type value', () => {
7719    const accessor = Kernel.createEmpty();
7720    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7721    if (CHECK_CRITICAL_STATE) {
7722      expect(
7723          () => accessor.addRepeatedGroupElement(
7724              1, fakeValue, TestMessage.instanceCreator))
7725          .toThrowError('Given value is not a message instance: null');
7726    } else {
7727      // Note in unchecked mode we produce invalid output for invalid inputs.
7728      // This test just documents our behavior in those cases.
7729      // These values might change at any point and are not considered
7730      // what the implementation should be doing here.
7731      accessor.addRepeatedGroupElement(
7732          1, fakeValue, TestMessage.instanceCreator);
7733      const list =
7734          accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7735      expect(Array.from(list)).toEqual([null]);
7736    }
7737  });
7738
7739  it('fail when setting message values with wrong type value', () => {
7740    const accessor = Kernel.createEmpty();
7741    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7742    if (CHECK_CRITICAL_STATE) {
7743      expect(() => accessor.setRepeatedGroupIterable(1, [fakeValue]))
7744          .toThrowError('Given value is not a message instance: null');
7745    } else {
7746      // Note in unchecked mode we produce invalid output for invalid inputs.
7747      // This test just documents our behavior in those cases.
7748      // These values might change at any point and are not considered
7749      // what the implementation should be doing here.
7750      accessor.setRepeatedGroupIterable(1, [fakeValue]);
7751      const list =
7752          accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7753      expect(Array.from(list)).toEqual([null]);
7754    }
7755  });
7756
7757  it('fail when setting single value with wrong type value', () => {
7758    const accessor =
7759        Kernel.fromArrayBuffer(createArrayBuffer(0x0B, 0x08, 0x00, 0x0C));
7760    const fakeValue = /** @type {!TestMessage} */ (/** @type {*} */ (null));
7761    if (CHECK_CRITICAL_STATE) {
7762      expect(
7763          () => accessor.setRepeatedGroupElement(
7764              /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
7765              /* index= */ 0))
7766          .toThrowError('Given value is not a message instance: null');
7767    } else {
7768      // Note in unchecked mode we produce invalid output for invalid inputs.
7769      // This test just documents our behavior in those cases.
7770      // These values might change at any point and are not considered
7771      // what the implementation should be doing here.
7772      accessor.setRepeatedGroupElement(
7773          /* fieldNumber= */ 1, fakeValue, TestMessage.instanceCreator,
7774          /* index= */ 0);
7775      const list =
7776          accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator);
7777      expect(Array.from(list).length).toEqual(1);
7778    }
7779  });
7780
7781  it('fail when setting single value with out-of-bound index', () => {
7782    const accessor =
7783        Kernel.fromArrayBuffer(createArrayBuffer(0x0B, 0x08, 0x00, 0x0C));
7784    const msg1 =
7785        accessor.getRepeatedGroupElement(1, TestMessage.instanceCreator, 0);
7786    const bytes2 = createArrayBuffer(0x08, 0x01);
7787    const msg2 = new TestMessage(Kernel.fromArrayBuffer(bytes2));
7788    if (CHECK_CRITICAL_STATE) {
7789      expect(
7790          () => accessor.setRepeatedGroupElement(
7791              /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
7792              /* index= */ 1))
7793          .toThrowError('Index out of bounds: index: 1 size: 1');
7794    } else {
7795      // Note in unchecked mode we produce invalid output for invalid inputs.
7796      // This test just documents our behavior in those cases.
7797      // These values might change at any point and are not considered
7798      // what the implementation should be doing here.
7799      accessor.setRepeatedGroupElement(
7800          /* fieldNumber= */ 1, msg2, TestMessage.instanceCreator,
7801          /* index= */ 1);
7802      expectEqualToArray(
7803          accessor.getRepeatedGroupIterable(1, TestMessage.instanceCreator),
7804          [msg1, msg2]);
7805    }
7806  });
7807});
7808