feat
This commit is contained in:
1 parent
8e28bca775
commit
1172a6bd3d
100 files changed
+8305
-6025
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { analyzeSource } from '../../src/ast/analyzer';
|
||||
import { schemaRegistry as analyzeSource } from '../upstream/schema';
|
||||
import { generateCode } from '../../src/codegen/generator';
|
||||
import { protobuf_getUnknownFieldMetadata } from '../../src/runtime';
|
||||
import { loadFixture } from '../helpers';
|
||||
@@ -72,8 +72,8 @@ describe('code generator', () => {
|
||||
|
||||
it('generates nested message code', () => {
|
||||
const gen = generateCode(analyzeSource(loadFixture('nested.ts'), 't.ts'));
|
||||
expect(gen).toContain('protobuf_encode_Inner(');
|
||||
expect(gen).toContain('protobuf_decode_Inner(data, offset, _end)');
|
||||
expect(gen).toContain('__write_Inner(');
|
||||
expect(gen).toContain('protobuf_decode_Inner(data, offset, offset + _len)');
|
||||
});
|
||||
|
||||
it('round-trip uint_32', () => {
|
||||
@@ -212,23 +212,21 @@ interface Int32Msg {
|
||||
|
||||
// Compatibility applies only to complete uint64 varints. Truncated input
|
||||
// and values wider than 64 bits must still fail loudly.
|
||||
expect(() => dec(Uint8Array.from([0x08, 0x80]))).toThrow(/truncated uint64 varint/);
|
||||
expect(() => dec(Uint8Array.from([0x08, 0x80]))).toThrow(/[Tt]runcated.*varint/);
|
||||
expect(() =>
|
||||
dec(
|
||||
Uint8Array.from([0x08, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02]),
|
||||
),
|
||||
).toThrow(/uint64 varint overflow/);
|
||||
).toThrow(/Invalid protobuf varint/);
|
||||
});
|
||||
|
||||
it('rejects malformed length-delimited fields without leaving parent bounds', () => {
|
||||
const schema = `interface BytesMsg { data: pb<1, bytes>; }`;
|
||||
const gen = generateCode(analyzeSource(schema, 'BytesMsg.ts'));
|
||||
const { dec } = makeRoundTripFromSchema(schema, 'BytesMsg');
|
||||
|
||||
expect(gen).toContain('const _end = __checkedEnd(offset, _len, end);');
|
||||
expect(() => dec(Uint8Array.from([0x0a, 0x80]))).toThrow(/truncated uint32 varint/);
|
||||
expect(() => dec(Uint8Array.from([0x0a, 0x80]))).toThrow(/[Tt]runcated.*varint/);
|
||||
expect(() => dec(Uint8Array.from([0x0a, 0x80, 0x80, 0x80, 0x80, 0x10]))).toThrow(
|
||||
/uint32 varint overflow/,
|
||||
/Invalid protobuf varint/,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user