2021-03-05 20:16:14 +00:00
|
|
|
import { Bytes, Decoder, encode, Reader } from '../src/index';
|
|
|
|
import './test-utils';
|
2021-03-12 19:41:35 +00:00
|
|
|
import { decodePointer, encodePointer, readPointer } from './test-utils';
|
2021-03-05 20:16:14 +00:00
|
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
|
|
|
describe('reading common test suite', () => {
|
2021-03-10 18:24:20 +00:00
|
|
|
const samples_bin = fs.readFileSync(__dirname + '/../../../../../tests/samples.bin');
|
2021-03-17 08:08:07 +00:00
|
|
|
const samples_pr = fs.readFileSync(__dirname + '/../../../../../tests/samples.pr', 'utf-8');
|
2021-03-05 20:16:14 +00:00
|
|
|
|
|
|
|
it('should read equal to decoded binary without annotations', () => {
|
2021-03-17 08:08:07 +00:00
|
|
|
const s1 = new Reader(samples_pr, { decodePointer: readPointer, includeAnnotations: false }).next();
|
2021-03-12 19:41:35 +00:00
|
|
|
const s2 = new Decoder(samples_bin, { includeAnnotations: false }).withPointerDecoder(
|
|
|
|
decodePointer,
|
|
|
|
d => d.next());
|
2021-03-05 20:16:14 +00:00
|
|
|
expect(s1).is(s2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should read equal to decoded binary with annotations', () => {
|
2021-03-17 08:08:07 +00:00
|
|
|
const s1 = new Reader(samples_pr, { decodePointer: readPointer, includeAnnotations: true }).next();
|
2021-03-12 19:41:35 +00:00
|
|
|
const s2 = new Decoder(samples_bin, { includeAnnotations: true }).withPointerDecoder(
|
|
|
|
decodePointer,
|
|
|
|
d => d.next());
|
2021-03-05 20:16:14 +00:00
|
|
|
expect(s1).is(s2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should read and encode back to binary with annotations', () => {
|
2021-03-17 08:08:07 +00:00
|
|
|
const s = new Reader(samples_pr, { decodePointer: readPointer, includeAnnotations: true }).next();
|
2021-03-05 20:16:14 +00:00
|
|
|
const bs = Bytes.toIO(encode(s, {
|
|
|
|
encodePointer,
|
|
|
|
includeAnnotations: true,
|
|
|
|
canonical: true,
|
|
|
|
}));
|
|
|
|
expect(bs).toEqual(new Uint8Array(samples_bin));
|
|
|
|
});
|
|
|
|
});
|