This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
56 lines (50 loc) · 1.7 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
const expect = require("chai").expect,
path = require("path"),
PBJ = require("./");
describe("PBJ", () => {
it("should read a gzipped pbj from disk and let the user look up bits", done => {
PBJ.readFile(path.join(__dirname, "var/1.pbjz"), (err, pbj) => {
expect(err).to.be.null;
expect(pbj).to.be.an.instanceOf(PBJ);
expect(pbj.width).to.equal(128);
expect(pbj.height).to.equal(128);
expect(pbj.bitAt(0, 0)).to.be.false;
expect(pbj.bitAt(32, 0)).to.be.true;
expect(pbj.bitAt(32, -1)).to.be.false;
expect(pbj.bitAt(30, 49)).to.be.false;
expect(pbj.bitAt(28, 80)).to.be.true;
done();
});
});
it("should read a different gzipped pbj from disk and let the user look up bits", done => {
PBJ.readFile(path.join(__dirname, "var/2.pbjz"), (err, pbj) => {
expect(err).to.be.null;
expect(pbj).to.be.an.instanceOf(PBJ);
expect(pbj.width).to.equal(128);
expect(pbj.height).to.equal(128);
expect(pbj.bitAt(68, 67)).to.be.true;
expect(pbj.bitAt(68, 67)).to.be.true;
expect(pbj.bitAt(67, 68)).to.be.true;
expect(pbj.bitAt(67, 68)).to.be.true;
done();
});
});
it("should fail to read a nonexistent PBJ", done => {
PBJ.readFile(path.join(__dirname, "var/3.pbjz"), (err, pbj) => {
expect(err).
to.be.an.instanceOf(Error).
that.has.a.property("code").
that.equals("ENOENT");
done();
});
});
it("should allow setting bits", done => {
PBJ.readFile(path.join(__dirname, "var/1.pbjz"), (err, pbj) => {
expect(pbj.get(0, 0)).to.be.false;
pbj.set(0, 0);
expect(pbj.get(0, 0)).to.be.true;
done();
});
});
});