UNPKG

@xogeny/mat-parser

Version:

A parser for MATLAB v4 files

85 lines 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const src_1 = require("../src"); const testing_1 = require("../src/testing"); class CountHandler { constructor() { this.tally = { ...testing_1.initialCounts }; } start(name) { this.tally["matrix"]++; } end(name) { this.tally["end"]++; return false; } column() { this.tally["column"]++; } eof() { this.tally["eof"]++; } error() { this.tally["error"]++; } } function aggregate(obs) { let ret = Buffer.alloc(0); return new Promise((resolve, reject) => { let sub = obs.subscribe(chunk => { ret = Buffer.concat([ret, chunk]); }, err => { sub.unsubscribe(); reject(err); }, () => { sub.unsubscribe(); resolve(ret); }); }); } describe("Test readers", () => { for (let i = 0; i < testing_1.files.length; i++) { let filename = testing_1.files[i]; it("should parse '" + filename + "' using chunk reader", async () => { let fullname = testing_1.sampleFile(filename); let blob = await aggregate(src_1.blobReader(fullname)); let chunked = await aggregate(src_1.chunkReader(fullname)); expect(blob.length).toEqual(chunked.length); expect(blob).toEqual(chunked); }); it("should get the same answer if invoked twice", async () => { let fullname = testing_1.sampleFile(filename); let blob1 = await aggregate(src_1.blobReader(fullname)); let blob2 = await aggregate(src_1.blobReader(fullname)); expect(blob1.length).toEqual(blob2.length); expect(blob1).toEqual(blob2); }); } }); describe("Test MATLAB parser", () => { for (let i = 0; i < testing_1.files.length; i++) { let filename = testing_1.files[i]; it("should parse '" + filename + "' as observable streams", async () => { let fullname = testing_1.sampleFile(filename); let obs = src_1.blobReader(fullname); let file = new src_1.MatFile(obs); let handler = new CountHandler(); await file.parse(handler); expect(handler.tally).toEqual(testing_1.counts[filename]); }); it("should get the same results if parsed twice", async () => { let fullname = testing_1.sampleFile(filename); let obs1 = src_1.blobReader(fullname); let file1 = new src_1.MatFile(obs1); let handler1 = new CountHandler(); await file1.parse(handler1); let obs2 = src_1.blobReader(fullname); let file2 = new src_1.MatFile(obs2); let handler2 = new CountHandler(); await file2.parse(handler2); expect(handler1.tally).toEqual(testing_1.counts[filename]); expect(handler2.tally).toEqual(testing_1.counts[filename]); }); } }); //# sourceMappingURL=parser.test.js.map