Skip to content

Commit e27ae53

Browse files
Copilotstreamich
andcommitted
refactor: replace beforeEach with setup helper function in Avro tests
Co-authored-by: streamich <[email protected]>
1 parent d606e92 commit e27ae53

File tree

4 files changed

+112
-65
lines changed

4 files changed

+112
-65
lines changed

src/avro/AvroDecoder.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class AvroDecoder implements BinaryJsonDecoder {
5555
public readLong(): number | bigint {
5656
const zigzag = this.readVarLong();
5757
const decoded = this.decodeZigZag64(zigzag);
58-
58+
5959
// Return number if it fits in safe integer range, otherwise bigint
6060
if (decoded >= BigInt(Number.MIN_SAFE_INTEGER) && decoded <= BigInt(Number.MAX_SAFE_INTEGER)) {
6161
return Number(decoded);
@@ -106,16 +106,16 @@ export class AvroDecoder implements BinaryJsonDecoder {
106106
*/
107107
public readArray<T>(itemReader: () => T): T[] {
108108
const result: T[] = [];
109-
109+
110110
while (true) {
111111
const count = this.readVarIntUnsigned();
112112
if (count === 0) break; // End of array marker
113-
113+
114114
for (let i = 0; i < count; i++) {
115115
result.push(itemReader());
116116
}
117117
}
118-
118+
119119
return result;
120120
}
121121

@@ -125,18 +125,18 @@ export class AvroDecoder implements BinaryJsonDecoder {
125125
*/
126126
public readMap<T>(valueReader: () => T): Record<string, T> {
127127
const result: Record<string, T> = {};
128-
128+
129129
while (true) {
130130
const count = this.readVarIntUnsigned();
131131
if (count === 0) break; // End of map marker
132-
132+
133133
for (let i = 0; i < count; i++) {
134134
const key = this.readString();
135135
if (key === '__proto__') throw new Error('INVALID_KEY');
136136
result[key] = valueReader();
137137
}
138138
}
139-
139+
140140
return result;
141141
}
142142

@@ -149,7 +149,7 @@ export class AvroDecoder implements BinaryJsonDecoder {
149149
if (index < 0 || index >= schemaReaders.length) {
150150
throw new Error(`Invalid union index: ${index}`);
151151
}
152-
152+
153153
const value = schemaReaders[index]();
154154
return {index, value};
155155
}
@@ -193,19 +193,19 @@ export class AvroDecoder implements BinaryJsonDecoder {
193193
const reader = this.reader;
194194
let result = 0;
195195
let shift = 0;
196-
196+
197197
while (true) {
198198
const byte = reader.u8();
199199
result |= (byte & 0x7f) << shift;
200-
200+
201201
if ((byte & 0x80) === 0) break;
202-
202+
203203
shift += 7;
204204
if (shift >= 32) {
205205
throw new Error('Variable-length integer is too long');
206206
}
207207
}
208-
208+
209209
return result >>> 0; // Convert to unsigned 32-bit
210210
}
211211

@@ -216,19 +216,19 @@ export class AvroDecoder implements BinaryJsonDecoder {
216216
const reader = this.reader;
217217
let result = BigInt(0);
218218
let shift = BigInt(0);
219-
219+
220220
while (true) {
221221
const byte = BigInt(reader.u8());
222222
result |= (byte & BigInt(0x7f)) << shift;
223-
223+
224224
if ((byte & BigInt(0x80)) === BigInt(0)) break;
225-
225+
226226
shift += BigInt(7);
227227
if (shift >= BigInt(64)) {
228228
throw new Error('Variable-length long is too long');
229229
}
230230
}
231-
231+
232232
return result;
233233
}
234234

@@ -245,4 +245,4 @@ export class AvroDecoder implements BinaryJsonDecoder {
245245
private decodeZigZag64(value: bigint): bigint {
246246
return (value >> BigInt(1)) ^ -(value & BigInt(1));
247247
}
248-
}
248+
}

src/avro/AvroSchemaDecoder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class AvroSchemaDecoder {
9898
*/
9999
private readRecord(schema: AvroRecordSchema): Record<string, unknown> {
100100
const result: Record<string, unknown> = {};
101-
101+
102102
for (let i = 0; i < schema.fields.length; i++) {
103103
const field = schema.fields[i];
104104
try {
@@ -107,7 +107,7 @@ export class AvroSchemaDecoder {
107107
throw new Error(`Error reading field '${field.name}': ${(error as Error).message}`);
108108
}
109109
}
110-
110+
111111
return result;
112112
}
113113

@@ -116,11 +116,11 @@ export class AvroSchemaDecoder {
116116
*/
117117
private readEnum(schema: AvroEnumSchema): string {
118118
const index = this.decoder.readEnum();
119-
119+
120120
if (index < 0 || index >= schema.symbols.length) {
121121
throw new Error(`Invalid enum index ${index} for enum with ${schema.symbols.length} symbols`);
122122
}
123-
123+
124124
return schema.symbols[index];
125125
}
126126

@@ -142,7 +142,7 @@ export class AvroSchemaDecoder {
142142
* Reads a union value according to the union schema.
143143
*/
144144
private readUnion(schema: AvroUnionSchema): unknown {
145-
const schemaReaders = schema.map(subSchema => () => this.readValue(subSchema));
145+
const schemaReaders = schema.map((subSchema) => () => this.readValue(subSchema));
146146
const result = this.decoder.readUnion(schemaReaders);
147147
return result.value;
148148
}
@@ -280,4 +280,4 @@ export class AvroSchemaDecoder {
280280
private getFullName(name: string, namespace?: string): string {
281281
return namespace ? `${namespace}.${name}` : name;
282282
}
283-
}
283+
}

0 commit comments

Comments
 (0)