1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00
This commit is contained in:
lana-k
2025-03-20 22:04:15 +01:00
parent 5e2b34a856
commit 0c1b91ab2f
146 changed files with 3317 additions and 2438 deletions

View File

@@ -62,7 +62,9 @@ describe('_sql.js', () => {
const data = tempDb.export()
const sql = await Sql.build()
sql.open(data)
expect(() => { sql.exec() }).to.throw('exec: Missing query string')
expect(() => {
sql.exec()
}).to.throw('exec: Missing query string')
})
it('imports', async () => {

View File

@@ -19,8 +19,9 @@ describe('_statements.js', () => {
it('getInsertStmt', () => {
const columns = ['id', 'name']
expect(stmts.getInsertStmt('foo', columns))
.to.equal('INSERT INTO "foo" ("id", "name") VALUES (?, ?);')
expect(stmts.getInsertStmt('foo', columns)).to.equal(
'INSERT INTO "foo" ("id", "name") VALUES (?, ?);'
)
})
it('getCreateStatement', () => {

View File

@@ -71,10 +71,12 @@ describe('database.js', () => {
type: 'INTEGER'
})
expect(schema[1].columns).to.eql([{
name: 'amount',
type: 'INTEGER'
}])
expect(schema[1].columns).to.eql([
{
name: 'amount',
type: 'INTEGER'
}
])
})
it('creates empty db with name database', async () => {
@@ -114,7 +116,9 @@ describe('database.js', () => {
buffer.name = 'foo.sqlite'
await db.loadDb(buffer)
const result = await db.execute('SELECT * from test limit 1; SELECT * from test;')
const result = await db.execute(
'SELECT * from test limit 1; SELECT * from test;'
)
expect(result.values).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
@@ -141,7 +145,9 @@ describe('database.js', () => {
const buffer = new Blob([data])
buffer.name = 'foo.sqlite'
await db.loadDb(buffer)
await expect(db.execute('SELECT * from foo')).to.be.rejectedWith(/^no such table: foo$/)
await expect(db.execute('SELECT * from foo')).to.be.rejectedWith(
/^no such table: foo$/
)
})
it('adds table from csv', async () => {
@@ -186,37 +192,44 @@ describe('database.js', () => {
}
const progressHandler = sinon.stub()
const progressCounterId = db.createProgressCounter(progressHandler)
await expect(db.addTableFromCsv('foo', data, progressCounterId)).to.be.rejected
await expect(db.addTableFromCsv('foo', data, progressCounterId)).to.be
.rejected
})
it('progressCounters', () => {
const firstHandler = sinon.stub()
const firstId = db.createProgressCounter(firstHandler)
db.worker.dispatchEvent(new MessageEvent('message', {
data: {
progress: 50,
id: firstId
}
}))
db.worker.dispatchEvent(
new MessageEvent('message', {
data: {
progress: 50,
id: firstId
}
})
)
expect(firstHandler.calledOnceWith(50)).to.equal(true)
const secondHandler = sinon.stub()
const secondId = db.createProgressCounter(secondHandler)
db.worker.dispatchEvent(new MessageEvent('message', {
data: {
progress: 70,
id: secondId
}
}))
db.worker.dispatchEvent(
new MessageEvent('message', {
data: {
progress: 70,
id: secondId
}
})
)
expect(firstId).to.not.equals(secondId)
expect(secondHandler.calledOnceWith(70)).to.equal(true)
db.worker.dispatchEvent(new MessageEvent('message', {
data: {
progress: 80,
id: firstId
}
}))
db.worker.dispatchEvent(
new MessageEvent('message', {
data: {
progress: 80,
id: firstId
}
})
)
expect(firstHandler.calledTwice).to.equal(true)
expect(firstHandler.secondCall.calledWith(80)).to.equal(true)
@@ -268,12 +281,17 @@ describe('database.js', () => {
it('validateTableName', async () => {
await db.execute('CREATE TABLE foo(id)')
await expect(db.validateTableName('foo')).to.be.rejectedWith('table "foo" already exists')
await expect(db.validateTableName('1foo'))
.to.be.rejectedWith("Table name can't start with a digit")
await expect(db.validateTableName('foo(05.08.2020)'))
.to.be.rejectedWith('Table name can contain only letters, digits and underscores')
await expect(db.validateTableName('sqlite_foo'))
.to.be.rejectedWith("Table name can't start with sqlite_")
await expect(db.validateTableName('foo')).to.be.rejectedWith(
'table "foo" already exists'
)
await expect(db.validateTableName('1foo')).to.be.rejectedWith(
"Table name can't start with a digit"
)
await expect(db.validateTableName('foo(05.08.2020)')).to.be.rejectedWith(
'Table name can contain only letters, digits and underscores'
)
await expect(db.validateTableName('sqlite_foo')).to.be.rejectedWith(
"Table name can't start with sqlite_"
)
})
})

View File

@@ -80,7 +80,6 @@ describe('SQLite extensions', function () {
'sqrt(square(16))': [16],
'ceil(-1.95) + ceil(1.95)': [1],
'floor(-1.95) + floor(1.95)': [-1]
})
})
@@ -452,7 +451,15 @@ describe('SQLite extensions', function () {
FROM dataset;
`)
expect(actual.values).to.eql({
xx: [1], xy: [0], xz: [1], yx: [0], yy: [1], yz: [1], zx: [1], zy: [1], zz: [1]
xx: [1],
xy: [0],
xz: [1],
yx: [0],
yy: [1],
yz: [1],
zx: [1],
zy: [1],
zz: [1]
})
})
@@ -475,7 +482,10 @@ describe('SQLite extensions', function () {
SELECT lua_inline(1), lua_full(1) - 1 < 0.000001;
`)
expect(actual.values).to.eql({ 'lua_inline(1)': [2], 'lua_full(1) - 1 < 0.000001': [1] })
expect(actual.values).to.eql({
'lua_inline(1)': [2],
'lua_full(1) - 1 < 0.000001': [1]
})
})
it('supports aggregate Lua functions', async function () {
@@ -534,6 +544,9 @@ describe('SQLite extensions', function () {
SELECT * FROM lua_match('%w+', 'hello world from Lua');
`)
expect(actual.values).to.eql({ idx: [1, 2, 3, 4], elm: ['hello', 'world', 'from', 'Lua'] })
expect(actual.values).to.eql({
idx: [1, 2, 3, 4],
elm: ['hello', 'world', 'from', 'Lua']
})
})
})