MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / testDecode

Function testDecode

tests/unit/string_decoder.test.ts:11–32  ·  view source on GitHub ↗
(
      encoding: BufferEncoding,
      input: Buffer,
      expected: string,
      singleSequence?: Array<Array<number>>
    )

Source from the content-addressed store, hash-verified

9 // singleSequence allows for easy debugging of a specific sequence which is
10 // useful in case of testDecode failures.
11 function testDecode(
12 encoding: BufferEncoding,
13 input: Buffer,
14 expected: string,
15 singleSequence?: Array<Array<number>>
16 ) {
17 let sequences;
18 if (!singleSequence) {
19 sequences = writeSequences(input.length);
20 } else {
21 sequences = [singleSequence];
22 }
23 sequences.forEach((sequence) => {
24 const decoder = new StringDecoder(encoding);
25 let output = "";
26 sequence.forEach((write) => {
27 output += decoder.write(input.slice(write[0], write[1]));
28 });
29 output += decoder.end();
30 expect(output).toEqual(expected);
31 });
32 }
33
34 // writeSequences returns an array of arrays that describes all possible ways a
35 // buffer of the given length could be split up and passed to sequential write

Callers 1

Calls 4

writeMethod · 0.95
endMethod · 0.95
writeSequencesFunction · 0.85
sliceMethod · 0.45

Tested by

no test coverage detected