mirror of
https://github.com/cupcakearmy/memiens.git
synced 2024-12-22 07:56:26 +00:00
reformatted
This commit is contained in:
parent
920fbf41e5
commit
52ba538e82
197
test/main.js
197
test/main.js
@ -1,134 +1,135 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const {
|
const {
|
||||||
unlinkSync
|
unlinkSync,
|
||||||
} = require('fs')
|
} = require('fs')
|
||||||
const memento = require('../').default
|
const Memiens = require('../').default
|
||||||
|
|
||||||
const filename = 'test.yaml'
|
const filename = './test.yaml'
|
||||||
const deleteFile = () => {
|
const deleteFile = () => {
|
||||||
try {
|
try {
|
||||||
// Remove the test file
|
// Remove the test file
|
||||||
unlinkSync(filename)
|
unlinkSync(filename)
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Memento', () => {
|
describe('Memiens', () => {
|
||||||
|
|
||||||
after(deleteFile)
|
after(deleteFile)
|
||||||
|
|
||||||
describe('Basics', () => {
|
describe('Basics', () => {
|
||||||
deleteFile()
|
deleteFile()
|
||||||
it('Instantiating without existing file', () => {
|
it('Instantiating without existing file', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Saving simple string', () => {
|
it('Saving simple string', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
|
|
||||||
const key = 'test'
|
const key = 'test'
|
||||||
const value = 'ok'
|
const value = 'ok'
|
||||||
Settings.set(key, value)
|
Settings.set(key, value)
|
||||||
|
|
||||||
assert.strictEqual(Settings.get(key), value)
|
assert.strictEqual(Settings.get(key), value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Preserve types', () => {
|
describe('Preserve types', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
const key = 'key'
|
const key = 'key'
|
||||||
|
|
||||||
const test = (value) => {
|
const test = (value) => {
|
||||||
Settings.set(key, value)
|
Settings.set(key, value)
|
||||||
const saved = Settings.get(key)
|
const saved = Settings.get(key)
|
||||||
assert.strictEqual(saved, value)
|
assert.strictEqual(saved, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
it('string', () => {
|
it('string', () => {
|
||||||
test('my string')
|
test('my string')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('string array', () => {
|
it('string array', () => {
|
||||||
test(['my string', 'ohlala'])
|
test(['my string', 'ohlala'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('number', () => {
|
it('number', () => {
|
||||||
test(42)
|
test(42)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('number array', () => {
|
it('number array', () => {
|
||||||
test([42, 8])
|
test([42, 8])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('boolean', () => {
|
it('boolean', () => {
|
||||||
test(true)
|
test(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('boolean array', () => {
|
it('boolean array', () => {
|
||||||
test([true, false])
|
test([true, false])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('mixed', () => {
|
it('mixed', () => {
|
||||||
test(['a', 42, true])
|
test(['a', 42, true])
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Persist', () => {
|
describe('Persist', () => {
|
||||||
deleteFile()
|
deleteFile()
|
||||||
|
|
||||||
const key = 'test'
|
const key = 'test'
|
||||||
const value = 42
|
const value = 42
|
||||||
|
|
||||||
it('Write', () => {
|
it('Write', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
Settings.set(key, value)
|
Settings.set(key, value)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Read', () => {
|
it('Read', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
assert.strictEqual(Settings.get(key), value)
|
assert.strictEqual(Settings.get(key), value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Nested properties', () => {
|
describe('Nested properties', () => {
|
||||||
deleteFile()
|
deleteFile()
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
a: {
|
a: {
|
||||||
b: {
|
b: {
|
||||||
c: [8, false]
|
c: [8, false],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Write', () => {
|
it('Write', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
Settings.set('a.b.c', data.a.b.c)
|
Settings.set('a.b.c', data.a.b.c)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Read', () => {
|
it('Read', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
assert.deepStrictEqual(Settings.get('a'), data.a)
|
assert.deepStrictEqual(Settings.get('a'), data.a)
|
||||||
assert.deepStrictEqual(Settings.get('a.b'), data.a.b)
|
assert.deepStrictEqual(Settings.get('a.b'), data.a.b)
|
||||||
assert.deepStrictEqual(Settings.get('a.b.c'), data.a.b.c)
|
assert.deepStrictEqual(Settings.get('a.b.c'), data.a.b.c)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Get with initializer', ()=> {
|
describe('Get with initializer', () => {
|
||||||
deleteFile()
|
deleteFile()
|
||||||
|
|
||||||
const key = 'initialized'
|
const key = 'initialized.nested'
|
||||||
const value = true
|
const value = 42
|
||||||
|
|
||||||
it('Getting', () => {
|
it('Getting', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
assert.strictEqual(Settings.get(key, value), value)
|
assert.strictEqual(Settings.get(key, value), value)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Verify it was written', () => {
|
it('Verify it was written', () => {
|
||||||
const Settings = new memento(filename)
|
const Settings = new Memiens(filename)
|
||||||
assert.strictEqual(Settings.get(key), value)
|
assert.strictEqual(Settings.get(key), value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user