Skip to content

Commit 903aba3

Browse files
committed
added pending Int64 tests
1 parent 9ea245b commit 903aba3

File tree

3 files changed

+83
-36
lines changed

3 files changed

+83
-36
lines changed

TODO

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
write tests
22
compare tests to node-sqlite3
3-
4-
5-
Int64 tests should cover the default safeIntegers state for statements and transactions

test/41.database.close.js

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
var expect = require('chai').expect;
22
var fs = require('fs');
33
var Database = require('../.');
4-
var db;
5-
6-
before(function (done) {
7-
db = new Database('temp/' + require('path').basename(__filename).split('.')[0] + '.db');
8-
db.on('open', done);
9-
});
4+
var util = (function () {
5+
var path = require('path');
6+
var dbId = 0;
7+
var obj;
8+
return obj = {
9+
current: function () {
10+
return 'temp/' + path.basename(__filename).split('.')[0] + '.' + dbId + '.db';
11+
},
12+
next: function () {++dbId; return obj.current();}
13+
};
14+
}());
1015

1116
describe('Database#close()', function () {
1217
it('should prevent statements and transactions from operating', function (done) {
13-
db.prepare('CREATE TABLE people (name TEXT)').run();
14-
var stmt1 = db.prepare('SELECT * FROM people');
15-
var stmt2 = db.prepare("INSERT INTO people VALUES ('foobar')");
16-
var trans = db.transaction(["INSERT INTO people VALUES ('foobar')"]);
17-
18-
db.prepare('SELECT * FROM people').bind();
19-
db.prepare("INSERT INTO people VALUES ('foobar')").bind();
20-
db.transaction(["INSERT INTO people VALUES ('foobar')"]).bind();
21-
db.prepare('SELECT * FROM people').get();
22-
db.prepare('SELECT * FROM people').all();
23-
db.prepare('SELECT * FROM people').each(function () {});
24-
db.prepare("INSERT INTO people VALUES ('foobar')").run();
25-
db.transaction(["INSERT INTO people VALUES ('foobar')"]).run();
26-
27-
db.close();
28-
29-
expect(function () {stmt1.bind();}).to.throw(Error);
30-
expect(function () {stmt2.bind();}).to.throw(Error);
31-
expect(function () {trans.bind();}).to.throw(Error);
32-
expect(function () {stmt1.get();}).to.throw(Error);
33-
expect(function () {stmt1.all();}).to.throw(Error);
34-
expect(function () {stmt1.each(function () {});}).to.throw(Error);
35-
expect(function () {stmt2.run();}).to.throw(Error);
36-
expect(function () {trans.run();}).to.throw(Error);
37-
38-
db.on('close', function () {
18+
var db = new Database(util.next());
19+
db.on('open', function () {
20+
db.prepare('CREATE TABLE people (name TEXT)').run();
21+
var stmt1 = db.prepare('SELECT * FROM people');
22+
var stmt2 = db.prepare("INSERT INTO people VALUES ('foobar')");
23+
var trans = db.transaction(["INSERT INTO people VALUES ('foobar')"]);
24+
25+
db.prepare('SELECT * FROM people').bind();
26+
db.prepare("INSERT INTO people VALUES ('foobar')").bind();
27+
db.transaction(["INSERT INTO people VALUES ('foobar')"]).bind();
28+
db.prepare('SELECT * FROM people').get();
29+
db.prepare('SELECT * FROM people').all();
30+
db.prepare('SELECT * FROM people').each(function () {});
31+
db.prepare("INSERT INTO people VALUES ('foobar')").run();
32+
db.transaction(["INSERT INTO people VALUES ('foobar')"]).run();
33+
34+
db.close();
35+
3936
expect(function () {stmt1.bind();}).to.throw(Error);
4037
expect(function () {stmt2.bind();}).to.throw(Error);
4138
expect(function () {trans.bind();}).to.throw(Error);
@@ -44,7 +41,36 @@ describe('Database#close()', function () {
4441
expect(function () {stmt1.each(function () {});}).to.throw(Error);
4542
expect(function () {stmt2.run();}).to.throw(Error);
4643
expect(function () {trans.run();}).to.throw(Error);
47-
done();
44+
45+
db.on('close', function () {
46+
expect(function () {stmt1.bind();}).to.throw(Error);
47+
expect(function () {stmt2.bind();}).to.throw(Error);
48+
expect(function () {trans.bind();}).to.throw(Error);
49+
expect(function () {stmt1.get();}).to.throw(Error);
50+
expect(function () {stmt1.all();}).to.throw(Error);
51+
expect(function () {stmt1.each(function () {});}).to.throw(Error);
52+
expect(function () {stmt2.run();}).to.throw(Error);
53+
expect(function () {trans.run();}).to.throw(Error);
54+
done();
55+
});
56+
});
57+
});
58+
it('should delete the database\'s associated temporary files', function (done) {
59+
var db = new Database(util.next());
60+
db.on('open', function () {
61+
fs.accessSync(util.current());
62+
db.pragma('journal_mode = WAL');
63+
db.prepare('CREATE TABLE people (name TEXT)').run();
64+
db.prepare('INSERT INTO people VALUES (?)').run('foobar');
65+
fs.accessSync(util.current() + '-wal');
66+
db.close();
67+
db.on('close', function (err) {
68+
fs.accessSync(util.current());
69+
expect(function () {
70+
fs.accessSync(util.current() + '-wal');
71+
}).to.throw();
72+
done();
73+
});
4874
});
4975
});
5076
});

test/50.int64.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var expect = require('chai').expect;
2+
var Database = require('../.');
3+
var Int64 = Database.Int64;
4+
var db;
5+
6+
before(function (done) {
7+
db = new Database('temp/' + require('path').basename(__filename).split('.')[0] + '.db');
8+
db.on('open', done);
9+
});
10+
11+
describe('Int64', function () {
12+
it('should throw if the low and high components are not numbers');
13+
it('should throw if the low and high components are not 32-bit integers');
14+
it('should default the high component to zero, if not provided');
15+
it('should expose the low and high components via getters');
16+
it('should reveal the full value via .toString()');
17+
it('should cast to its full value when the number is a safe number');
18+
it('should cast to a NaN when the number is not a safe number');
19+
it('should compare to other Int64s or other values via .equals()');
20+
it('should bind to statements and transactions');
21+
it('should get returned by operations after setting .safeIntegers()');
22+
it('should be able to change the default setting on the database');
23+
it('should return fully accurate round-trip results');
24+
});

0 commit comments

Comments
 (0)