/* Copyright (c) 2010-2015 Richard Rodger, MIT License */
"use strict";


var assert = require('assert')

var seneca = require('seneca')

var shared = require('seneca-store-test')


var si = seneca({log:'silent'})
si.use('../mem-store.js')

si.__testcount = 0
var testcount = 0


describe('mem', function(){
  it('basic', function(fin){
    testcount++
    shared.basictest(si,fin)
  })

  it('custom', function(fin){
    si.options({errhandler:fin})
    si.make('foo',{id$:"0",q:1}).save$(function(err){

      si.act('role:mem-store,cmd:export',function(e,out){
        assert.ok( null == e )
        assert.equal( out.json, '{"undefined":{"foo":{"0":{"entity$":"-/-/foo"'+
                      ',"q":1,"id":"0"}}},"moon":{"bar":{}}}' )

        var data = JSON.parse(out.json)
        data["undefined"]["foo"]["1"] = {"entity$":"-/-/foo","z":2,"id":"1"} 

        si.act(
          'role:mem-store,cmd:import',{json:JSON.stringify(data)},
          function(e){
            si.make('foo').load$("1",function(e,f1){

              assert.equal(2,f1.z)
              fin()
            })
          })
      })
    })
  })

  it('close', function(fin){
    shared.closetest(si,testcount,fin)
  })
})

@@ -51,17 +51,17 @@
 ense */%0A
-%22
+'
 use stri
@@ -66,11 +66,9 @@
 rict
-%22;%0A
+'
 %0A%0Ava
@@ -96,22 +96,46 @@
 ssert')%0A
+var Lab = require('lab')
 %0Avar 
-s
+S
 eneca = 
@@ -152,22 +152,21 @@
 eneca')%0A
-%0A
 var 
-s
+S
 hared = 
@@ -199,38 +199,167 @@
 ')%0A%0A
-%0Avar si = s
+// Shortcults%0Avar lab = exports.lab = Lab.script()%0Avar describe = lab.describe%0Avar it = lab.it%0A%0Avar MemStore = require('..')%0A%0Avar si = S
 eneca(%7B
+%0A  
 log:
+ 
 'silent'
 %7D)%0As
@@ -358,75 +358,29 @@
 ent'
+%0A
 %7D)%0A
+%0A
 si.use(
-'../mem-store.js')%0A%0Asi.__testcount = 0%0Avar testcount = 0%0A
+MemStore)
 %0A%0Ade
@@ -405,85 +405,66 @@
 tion
+ 
 ()
+ 
 %7B%0A  
-it('basic', function(fin)%7B%0A    testcount++%0A    shared.basictest(si,fin)
+Shared.basictest(%7B%0A    seneca: si,%0A    script: lab
 %0A  %7D
@@ -478,16 +478,21 @@
 ('custom
+ test
 ', funct
@@ -490,29 +490,32 @@
 t', function
-(fin)
+ (done) 
 %7B%0A    si.opt
@@ -520,16 +520,23 @@
 ptions(%7B
+%0A      
 errhandl
@@ -542,14 +542,22 @@
 ler:
-fin
+ done%0A    
 %7D)%0A
+%0A
     
@@ -574,20 +574,42 @@
 oo',
-%7Bid$:%220%22,q:1
+ %7B%0A      id$: '0',%0A      q: 1%0A    
 %7D).s
@@ -625,15 +625,46 @@
 tion
+ 
 (err)
+ 
 %7B%0A
+      assert.ok(err === null)
 %0A   
@@ -701,24 +701,25 @@
 export',
+ 
 function
 (e,out)%7B
@@ -714,15 +714,18 @@
 tion
+ 
 (e,
+ 
 out)
+ 
 %7B%0A  
@@ -744,19 +744,17 @@
 .ok(
+e ==
  null
- == e 
 )%0A  
@@ -772,17 +772,16 @@
 t.equal(
- 
 out.json
@@ -833,22 +833,11 @@
 oo%22'
+ 
 +%0A
-            
     
@@ -865,29 +865,10 @@
 %22%7D%7D%7D
-,%22moon%22:%7B%22bar%22:%7B%7D%7D
 %7D'
- 
 )%0A%0A 
@@ -919,17 +919,17 @@
    data%5B
-%22
+'
 undefine
@@ -933,62 +933,102 @@
 ined
-%22%5D%5B%22foo%22%5D%5B%221%22
+'%5D%5B'foo'%5D%5B'1'
 %5D = %7B
-%22
+%0A          '
 entity$
-%22:%22
+': '
 -/-/foo
-%22,%22z%22:2,%22id%22:%221%22%7D 
+',%0A          z: 2,%0A          id: '1'%0A        %7D
 %0A%0A  
@@ -1083,14 +1083,29 @@
 rt',
-%7B
+ %7B%0A            
 json:
+ 
 JSON
@@ -1120,16 +1120,27 @@
 fy(data)
+%0A          
 %7D,%0A     
@@ -1156,11 +1156,13 @@
 tion
+ 
 (e)
+ 
 %7B%0A  
@@ -1196,20 +1196,21 @@
 ad$(
-%221%22,
+'1', 
 function
 (e,f
@@ -1209,16 +1209,18 @@
 tion
+ 
 (e,
+ 
 f1)
+ 
 %7B
-%0A
 %0A   
@@ -1245,16 +1245,17 @@
 equal(2,
+ 
 f1.z)%0A  
@@ -1266,19 +1266,20 @@
         
-fin
+done
 ()%0A     
@@ -1325,82 +1325,8 @@
   %7D)
-%0A%0A  it('close', function(fin)%7B%0A    shared.closetest(si,testcount,fin)%0A  %7D)
 %0A%7D)%0A

fix linting and start to use lab