Project import generated by Copybara

PiperOrigin-RevId: 297637283
pull/7259/head
Protobuf Team 5 years ago committed by Copybara-Service
parent 743a4322ba
commit d2727a2ce3
  1. 2
      js/experimental/runtime/kernel/writer.js
  2. 21
      js/experimental/runtime/kernel/writer_test.js

@ -93,7 +93,7 @@ class Writer {
checkFieldNumber(fieldNumber);
checkWireType(wireType);
const tag = fieldNumber << 3 | wireType;
this.writeUnsignedVarint32_(tag);
this.writeUnsignedVarint32_(tag >>> 0);
}
/**

@ -60,6 +60,18 @@ describe('Writer does', () => {
const writer = new Writer();
writer.writeTag(1, WireType.VARINT);
expect(writer.getAndResetResultBuffer()).toEqual(createArrayBuffer(0x08));
writer.writeTag(0x0FFFFFFF, WireType.VARINT);
expect(writer.getAndResetResultBuffer())
.toEqual(createArrayBuffer(0xF8, 0xFF, 0xFF, 0xFF, 0x7));
writer.writeTag(0x10000000, WireType.VARINT);
expect(writer.getAndResetResultBuffer())
.toEqual(createArrayBuffer(0x80, 0x80, 0x80, 0x80, 0x08));
writer.writeTag(0x1FFFFFFF, WireType.VARINT);
expect(writer.getAndResetResultBuffer())
.toEqual(createArrayBuffer(0xF8, 0xFF, 0xFF, 0xFF, 0x0F));
});
it('reset after calling getAndResetResultBuffer', () => {
@ -95,7 +107,8 @@ describe('Writer does', () => {
// These values might change at any point and are not considered
// what the implementation should be doing here.
writer.writeTag(-1, WireType.VARINT);
expect(writer.getAndResetResultBuffer()).toEqual(createArrayBuffer(0xF8));
expect(writer.getAndResetResultBuffer())
.toEqual(createArrayBuffer(0xF8, 0xFF, 0xFF, 0xFF, 0xF));
}
});
@ -504,7 +517,11 @@ describe('Writer.writeString does', () => {
expect(new Uint8Array(writer.getAndResetResultBuffer()))
.toEqual(new Uint8Array(createArrayBuffer(
-6, // invalid tag
1, // string length
0xff,
0xff,
0xff,
0x0f,
1, // string length
'a'.charCodeAt(0),
)));
}

Loading…
Cancel
Save