Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50640 views
1
###############################################################################
2
#
3
# CoCalc: Collaborative web-based calculation
4
# Copyright (C) 2017, Sagemath Inc.
5
# AGPLv3
6
#
7
###############################################################################
8
9
expect = require('expect')
10
11
{key_value_store} = require('../key-value-store')
12
13
describe "create a simple key value store with various single keys -- ", ->
14
k = undefined
15
16
it 'creates the store', ->
17
k = key_value_store()
18
19
it 'saves "x":{foo:3}', ->
20
k.set('x', {foo:3})
21
expect(k.get('x')).toEqual({foo:3})
22
k.delete('x')
23
expect(k.get('x')).toEqual(undefined)
24
25
it "saves {foo:3, bar:5}:'x' (so non-string key)", ->
26
k.set({foo:3, bar:5}, 'x')
27
expect(k.get({bar:5, foo:3})).toEqual('x')
28
k.delete({bar:5, foo:3})
29
expect(k.get({bar:5, foo:3})).toEqual(undefined)
30
31
it "closes k", ->
32
expect(k._data?).toBe(true)
33
k.close()
34
expect(k._data?).toBe(false)
35
try
36
k.set('a',1)
37
expect(true).toBe(false)
38
catch
39
# good
40
try
41
k.get('a')
42
expect(true).toBe(false)
43
catch
44
# good
45
try
46
k.delete('a')
47
expect(true).toBe(false)
48
catch
49
# good
50
51
52
53
54
55