aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-09-29 14:59:00 +0000
committers-ol <s-ol@users.noreply.github.com>2019-09-29 14:59:00 +0000
commit7cb951d05eb9f2408ee34f7c5f0b49907a03bbfc (patch)
tree67a077382fd8984ff216824f713df0c38c5dc5a1 /spec
parentinitial sqlite support (diff)
downloadmmm-7cb951d05eb9f2408ee34f7c5f0b49907a03bbfc.tar.gz
mmm-7cb951d05eb9f2408ee34f7c5f0b49907a03bbfc.zip
add busted spec for driver
Diffstat (limited to 'spec')
-rw-r--r--spec/driver_spec.moon88
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/driver_spec.moon b/spec/driver_spec.moon
new file mode 100644
index 0000000..60cd574
--- /dev/null
+++ b/spec/driver_spec.moon
@@ -0,0 +1,88 @@
+import TreeStore 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 = TreeStore!
+
+ 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", ->
+ ts\create_fileder nil, 'hello'
+ assert.are.same {'/hello'}, toseq ts\list_all_fileders!
+
+ it "can create and list child fileders recursively", ->
+ ts\create_fileder '/hello', 'world'
+ 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!