import { Bytes, Decoder, encode, Reader } from '../src/index'; import './test-utils'; import { decodePointer, encodePointer } from './test-utils'; import * as fs from 'fs'; describe('reading common test suite', () => { const samples_bin = fs.readFileSync(__dirname + '/../../../../../tests/samples.bin'); const samples_txt = fs.readFileSync(__dirname + '/../../../../../tests/samples.txt', 'utf-8'); it('should read equal to decoded binary without annotations', () => { const s1 = new Reader(samples_txt, { decodePointer, includeAnnotations: false }).next(); const s2 = new Decoder(samples_bin, { decodePointer, includeAnnotations: false }).next(); expect(s1).is(s2); }); it('should read equal to decoded binary with annotations', () => { const s1 = new Reader(samples_txt, { decodePointer, includeAnnotations: true }).next(); const s2 = new Decoder(samples_bin, { decodePointer, includeAnnotations: true }).next(); expect(s1).is(s2); }); it('should read and encode back to binary with annotations', () => { const s = new Reader(samples_txt, { decodePointer, includeAnnotations: true }).next(); const bs = Bytes.toIO(encode(s, { encodePointer, includeAnnotations: true, canonical: true, })); expect(bs).toEqual(new Uint8Array(samples_bin)); }); });