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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
import SQLStore from require 'mmm.mmmfs.drivers.sql'
sort2 = (a, b) ->
{ax, ay}, {bx, by} = a, b
"#{ax}//#{ay}" < "#{bx}//#{by}"
toseq = (iter) -> with v = [x for x in iter]
table.sort v
toseq2 = (iter) -> with v = [{x, y} for x, y in iter]
table.sort v, sort2
describe "sql driver", ->
randomize false
ts = SQLStore memory: true
it "starts out empty", ->
assert.are.same {}, toseq ts\list_fileders_in!
assert.are.same {}, toseq ts\list_all_fileders!
it "can't create fileders without missing parents", ->
assert.has_error ->
ts\create_fileder '/hello', 'world'
it "can create root fileders", ->
assert.are.same '/hello', ts\create_fileder '', 'hello'
assert.are.same {'/hello'}, toseq ts\list_all_fileders!
it "can create and list child fileders recursively", ->
assert.are.same '/hello/world',
ts\create_fileder '/hello', 'world'
assert.are.same '/hello/world/again',
ts\create_fileder '/hello/world', 'again'
assert.are.same {'/hello', '/hello/world', '/hello/world/again'},
toseq ts\list_all_fileders!
it "can list immediate children", ->
assert.are.same {"/hello"}, toseq ts\list_fileders_in!
assert.are.same {"/hello/world"}, toseq ts\list_fileders_in "/hello"
assert.are.same {"/hello/world/again"}, toseq ts\list_fileders_in "/hello/world"
describe "can create and list facets", ->
ts\create_facet '/hello', 'name', 'alpha', 'hello'
ts\create_facet '/hello/world', 'name', 'alpha', 'world'
ts\create_facet '/hello/world', '', 'text/markdown', '# Helau World!'
it "can't create facet for nonexistant fileders", ->
assert.has_error -> ts\create_facet '/hello/orldw', 'name', 'alpha', 'foo'
it "can't create facet without value", ->
assert.has_error -> ts\create_facet '/hello/world', 'other', 'alpha', nil
it "can't create facet for duplicate keys", ->
assert.has_error -> ts\create_facet '/hello/world', 'name', 'alpha', 'foo'
assert.are.same {{'name', 'alpha'}}, toseq2 ts\list_facets '/hello'
assert.are.same {{'', 'text/markdown'}, {'name', 'alpha'}},
toseq2 ts\list_facets '/hello/world'
it "can load facets", ->
assert.are.equal 'hello', ts\load_facet '/hello', 'name', 'alpha'
assert.are.equal 'world', ts\load_facet '/hello/world', 'name', 'alpha'
assert.are.equal '# Helau World!', ts\load_facet '/hello/world', '', 'text/markdown'
assert.is_falsy ts\load_facet '/hello', 'nonexistant', 'facet'
it "can rename facets", ->
ts\rename_facet '/hello/world', 'name', 'alpha', 'gnome'
assert.are.same {{'', 'text/markdown'}, {'gnome', 'alpha'}},
toseq2 ts\list_facets '/hello/world'
assert.are.equal 'world', ts\load_facet '/hello/world', 'gnome', 'alpha'
it "can update facets", ->
ts\update_facet '/hello/world', '', 'text/markdown', '# Hello World!'
assert.are.same {{'', 'text/markdown'}, {'gnome', 'alpha'}},
toseq2 ts\list_facets '/hello/world'
assert.are.equal '# Hello World!', ts\load_facet '/hello/world', '', 'text/markdown'
it "can remove facets", ->
ts\remove_facet '/hello/world', 'gnome', 'alpha'
assert.are.same {{'', 'text/markdown'}}, toseq2 ts\list_facets '/hello/world'
assert.has_error -> ts\remove_facet '/hello/world', 'gnome', 'alpha'
it "can delete fileders", ->
ts\remove_fileder '/hello/world'
assert.is_falsy ts\load_facet '/hello/world', 'gnome', 'alpha'
assert.are.same {'/hello'}, toseq ts\list_all_fileders!
ts\remove_fileder '/hello'
assert.are.same {}, toseq ts\list_all_fileders!
|