[Pkg-javascript-commits] [node-abstract-leveldown] 03/06: Imported Upstream version 2.0.1

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Sep 12 15:34:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-abstract-leveldown.

commit c33edf7af0286da473e5b45bd48e38fbccac803d
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Fri Sep 12 15:29:24 2014 +0000

    Imported Upstream version 2.0.1
---
 CHANGELOG.md                   |  4 ++++
 LICENSE                        | 39 -------------------------------
 LICENSE.md                     | 11 +++++++++
 README.md                      | 12 +++++-----
 abstract-chained-batch.js      |  9 ++++---
 abstract-leveldown.js          | 53 +++++++++++++++++-------------------------
 abstract/batch-test.js         | 38 ++++++++++++++++++++++++++++--
 abstract/chained-batch-test.js | 16 ++-----------
 abstract/iterator-test.js      | 35 ++++++++++++++++++++++++++++
 abstract/leveldown-test.js     | 10 ++++++++
 abstract/open-test.js          | 16 +++++++++++++
 abstract/put-get-del-test.js   | 46 ++++++++++++++++++++++--------------
 abstract/util.js               |  4 +++-
 package.json                   |  2 +-
 test.js                        | 32 +++++++++++++++++--------
 15 files changed, 199 insertions(+), 128 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89c9013..dece6b0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+### 2.0.0 - Aug 26 2014
+ * Lots of stuff between 0.11.1 and now, omitted updating changelog
+ * Switch to allowing writes of empty values: null, undefined, '', []
+
 ### 0.11.1 - Nov 15 2013
  * Adjust approximate-size-test.js to account for snappy compression
 
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 76d07a0..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,39 +0,0 @@
-Copyright 2012, Rod Vagg (the "Original Author")
-All rights reserved.
-
-MIT +no-false-attribs License
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-Distributions of all or part of the Software intended to be used
-by the recipients as they would use the unmodified Software,
-containing modifications that substantially alter, remove, or
-disable functionality of the Software, outside of the documented
-configuration mechanisms provided by the Software, shall be
-modified such that the Original Author's bug reporting email
-addresses and urls are either replaced with the contact information
-of the parties responsible for the changes, or removed entirely.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-
-Except where noted, this license applies to any and all software
-programs and associated documentation files created by the
-Original Author, when distributed with the Software.
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..29b95e3
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,11 @@
+The MIT License (MIT)
+=====================
+
+Copyright (c) 2014 Rod Vagg
+---------------------------
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
index 1db6d6b..cae74f9 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 # Abstract LevelDOWN [![Build Status](https://secure.travis-ci.org/rvagg/abstract-leveldown.png)](http://travis-ci.org/rvagg/abstract-leveldown)
 
-[![NPM](https://nodei.co/npm/abstract-leveldown.png?downloads=true)](https://nodei.co/npm/abstract-leveldown/)
-[![NPM](https://nodei.co/npm-dl/abstract-leveldown.png?months=6)](https://nodei.co/npm/abstract-leveldown/)
+[![NPM](https://nodei.co/npm/abstract-leveldown.png?downloads=true&downloadRank=true)](https://nodei.co/npm/abstract-leveldown/)
+[![NPM](https://nodei.co/npm-dl/abstract-leveldown.png?months=6&height=3)](https://nodei.co/npm/abstract-leveldown/)
 
 An abstract prototype matching the **[LevelDOWN](https://github.com/rvagg/node-leveldown/)** API. Useful for extending **[LevelUP](https://github.com/rvagg/node-levelup)** functionality by providing a replacement to LevelDOWN.
 
@@ -150,10 +150,10 @@ Abstract LevelDOWN is only possible due to the excellent work of the following c
 <tr><th align="left">James Halliday</th><td><a href="https://github.com/substack">GitHub/substack</a></td><td><a href="https://twitter.com/substack">Twitter/@substack</a></td></tr>
 </tbody></table>
 
-<a name="licence"></a>
-Licence & copyright
+<a name="license"></a>
+License & copyright
 -------------------
 
-Copyright (c) 2012-2013 Abstract LevelDOWN contributors (listed above).
+Copyright (c) 2012-2014 Abstract LevelDOWN contributors (listed above).
 
-Abstract LevelDOWN is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
+Abstract LevelDOWN is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
diff --git a/abstract-chained-batch.js b/abstract-chained-batch.js
index 7e48059..b46278d 100644
--- a/abstract-chained-batch.js
+++ b/abstract-chained-batch.js
@@ -14,10 +14,9 @@ AbstractChainedBatch.prototype._checkWritten = function () {
 AbstractChainedBatch.prototype.put = function (key, value) {
   this._checkWritten()
 
-  var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer)
-  if (err) throw err
-  err = this._db._checkKeyValue(value, 'value', this._db._isBuffer)
-  if (err) throw err
+  var err = this._db._checkKey(key, 'key', this._db._isBuffer)
+  if (err)
+    throw err
 
   if (!this._db._isBuffer(key)) key = String(key)
   if (!this._db._isBuffer(value)) value = String(value)
@@ -33,7 +32,7 @@ AbstractChainedBatch.prototype.put = function (key, value) {
 AbstractChainedBatch.prototype.del = function (key) {
   this._checkWritten()
 
-  var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer)
+  var err = this._db._checkKey(key, 'key', this._db._isBuffer)
   if (err) throw err
 
   if (!this._db._isBuffer(key)) key = String(key)
diff --git a/abstract-leveldown.js b/abstract-leveldown.js
index e56a641..7936fae 100644
--- a/abstract-leveldown.js
+++ b/abstract-leveldown.js
@@ -24,6 +24,9 @@ AbstractLevelDOWN.prototype.open = function (options, callback) {
   if (typeof options != 'object')
     options = {}
 
+  options.createIfMissing = options.createIfMissing != false
+  options.errorIfExists = !!options.errorIfExists
+
   if (typeof this._open == 'function')
     return this._open(options, callback)
 
@@ -49,7 +52,7 @@ AbstractLevelDOWN.prototype.get = function (key, options, callback) {
   if (typeof callback != 'function')
     throw new Error('get() requires a callback argument')
 
-  if (err = this._checkKeyValue(key, 'key', this._isBuffer))
+  if (err = this._checkKey(key, 'key', this._isBuffer))
     return callback(err)
 
   if (!this._isBuffer(key))
@@ -58,6 +61,8 @@ AbstractLevelDOWN.prototype.get = function (key, options, callback) {
   if (typeof options != 'object')
     options = {}
 
+  options.asBuffer = options.asBuffer != false
+
   if (typeof this._get == 'function')
     return this._get(key, options, callback)
 
@@ -73,10 +78,7 @@ AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
   if (typeof callback != 'function')
     throw new Error('put() requires a callback argument')
 
-  if (err = this._checkKeyValue(key, 'key', this._isBuffer))
-    return callback(err)
-
-  if (err = this._checkKeyValue(value, 'value', this._isBuffer))
+  if (err = this._checkKey(key, 'key', this._isBuffer))
     return callback(err)
 
   if (!this._isBuffer(key))
@@ -84,7 +86,7 @@ AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
 
   // coerce value to string in node, don't touch it in browser
   // (indexeddb can store any JS type)
-  if (!this._isBuffer(value) && !process.browser)
+  if (value != null && !this._isBuffer(value) && !process.browser)
     value = String(value)
 
   if (typeof options != 'object')
@@ -105,7 +107,7 @@ AbstractLevelDOWN.prototype.del = function (key, options, callback) {
   if (typeof callback != 'function')
     throw new Error('del() requires a callback argument')
 
-  if (err = this._checkKeyValue(key, 'key', this._isBuffer))
+  if (err = this._checkKey(key, 'key', this._isBuffer))
     return callback(err)
 
   if (!this._isBuffer(key))
@@ -127,13 +129,16 @@ AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
   if (typeof options == 'function')
     callback = options
 
+  if (typeof array == 'function')
+    callback = array
+
   if (typeof callback != 'function')
     throw new Error('batch(array) requires a callback argument')
 
   if (!Array.isArray(array))
     return callback(new Error('batch(array) requires an array argument'))
 
-  if (typeof options != 'object')
+  if (!options || typeof options != 'object')
     options = {}
 
   var i = 0
@@ -146,16 +151,11 @@ AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
     if (typeof e != 'object')
       continue
 
-    if (err = this._checkKeyValue(e.type, 'type', this._isBuffer))
+    if (err = this._checkKey(e.type, 'type', this._isBuffer))
       return callback(err)
 
-    if (err = this._checkKeyValue(e.key, 'key', this._isBuffer))
+    if (err = this._checkKey(e.key, 'key', this._isBuffer))
       return callback(err)
-
-    if (e.type == 'put') {
-      if (err = this._checkKeyValue(e.value, 'value', this._isBuffer))
-        return callback(err)
-    }
   }
 
   if (typeof this._batch == 'function')
@@ -201,20 +201,11 @@ AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
   })
 
   options.reverse = !!options.reverse
-
-  // fix `start` so it takes into account gt, gte, lt, lte as appropriate
-  if (options.reverse && options.lt)
-    options.start = options.lt
-  if (options.reverse && options.lte)
-    options.start = options.lte
-  if (!options.reverse && options.gt)
-    options.start = options.gt
-  if (!options.reverse && options.gte)
-    options.start = options.gte
-
-  if ((options.reverse && options.lt && !options.lte)
-    || (!options.reverse && options.gt && !options.gte))
-    options.exclusiveStart = true // start should *not* include matching key
+  options.keys = options.keys != false
+  options.values = options.values != false
+  options.limit = 'limit' in options ? options.limit : -1
+  options.keyAsBuffer = options.keyAsBuffer != false
+  options.valueAsBuffer = options.valueAsBuffer != false
 
   return options
 }
@@ -239,9 +230,7 @@ AbstractLevelDOWN.prototype._isBuffer = function (obj) {
   return Buffer.isBuffer(obj)
 }
 
-AbstractLevelDOWN.prototype._checkKeyValue = function (obj, type) {
-  if (obj === null || obj === undefined)
-    return new Error(type + ' cannot be `null` or `undefined`')
+AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
 
   if (obj === null || obj === undefined)
     return new Error(type + ' cannot be `null` or `undefined`')
diff --git a/abstract/batch-test.js b/abstract/batch-test.js
index 4585840..085b794 100644
--- a/abstract/batch-test.js
+++ b/abstract/batch-test.js
@@ -18,20 +18,21 @@ module.exports.args = function (test) {
 
   test('test batch() with missing `value`', function (t) {
     db.batch([{ type: 'put', key: 'foo1' }], function (err) {
-      t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message')
+      t.notOk(err, 'no error')
       t.end()
     })
   })
 
   test('test batch() with null `value`', function (t) {
     db.batch([{ type: 'put', key: 'foo1', value: null }], function (err) {
-      t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message')
+      t.notOk(err, 'no error')
       t.end()
     })
   })
 
   test('test batch() with missing `key`', function (t) {
     db.batch([{ type: 'put', value: 'foo1' }], function (err) {
+      t.ok(err, 'got error')
       t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
       t.end()
     })
@@ -39,6 +40,7 @@ module.exports.args = function (test) {
 
   test('test batch() with null `key`', function (t) {
     db.batch([{ type: 'put', key: null, value: 'foo1' }], function (err) {
+      t.ok(err, 'got error')
       t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
       t.end()
     })
@@ -46,10 +48,42 @@ module.exports.args = function (test) {
 
   test('test batch() with missing `key` and `value`', function (t) {
     db.batch([{ type: 'put' }], function (err) {
+      t.ok(err, 'got error')
       t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
       t.end()
     })
   })
+
+  test('test batch() with missing array', function (t) {
+    db.batch(function (err) {
+      t.ok(err, 'got error')
+      t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
+      t.end()
+    })
+  })
+
+  test('test batch() with undefined array', function (t) {
+    db.batch(void 0, function (err) {
+      t.ok(err, 'got error')
+      t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
+      t.end()
+    })
+  })
+
+  test('test batch() with null array', function (t) {
+    db.batch(null, function (err) {
+      t.ok(err, 'got error')
+      t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
+      t.end()
+    })
+  })
+
+  test('test batch() with null options', function (t) {
+    db.batch([], null, function (err) {
+      t.notOk(err, 'no error')
+      t.end()
+    })
+  })
 }
 
 module.exports.batch = function (test) {
diff --git a/abstract/chained-batch-test.js b/abstract/chained-batch-test.js
index b38a68d..ab072af 100644
--- a/abstract/chained-batch-test.js
+++ b/abstract/chained-batch-test.js
@@ -10,24 +10,12 @@ module.exports.setUp = function (leveldown, test, testCommon) {
 
 module.exports.args = function (test) {
   test('test batch#put() with missing `value`', function (t) {
-    try {
-      db.batch().put('foo1')
-    } catch (err) {
-      t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message')
-      return t.end()
-    }
-    t.fail('should have thrown')
+    db.batch().put('foo1')
     t.end()
   })
 
   test('test batch#put() with null `value`', function (t) {
-    try {
-      db.batch().put('foo1', null)
-    } catch (err) {
-      t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message')
-      return t.end()
-    }
-    t.fail('should have thrown')
+    db.batch().put('foo1', null)
     t.end()
   })
 
diff --git a/abstract/iterator-test.js b/abstract/iterator-test.js
index ec85904..f90032e 100644
--- a/abstract/iterator-test.js
+++ b/abstract/iterator-test.js
@@ -122,6 +122,8 @@ module.exports.iterator = function (leveldown, test, testCommon, collectEntries)
         , fn = function (err, key, value) {
             t.notOk(err, 'no error')
             if (key && value) {
+              t.ok(Buffer.isBuffer(key), 'key argument is a Buffer')
+              t.ok(Buffer.isBuffer(value), 'value argument is a Buffer')
               t.equal(key.toString(), data[idx].key, 'correct key')
               t.equal(value.toString(), data[idx].value, 'correct value')
               process.nextTick(next)
@@ -357,6 +359,14 @@ module.exports.iterator = function (leveldown, test, testCommon, collectEntries)
     })
   })
 
+  test('test iterator with limit=0 should not iterate over anything', function (t) {
+    collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 0 }), function (err, data) {
+      t.notOk(err, 'no error')
+      t.equal(data.length, 0, 'correct number of entries')
+      t.end()
+    })
+  })
+
   test('test iterator with end after limit', function (t) {
     collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20, end: '50' }), function (err, data) {
       t.notOk(err, 'no error')
@@ -445,6 +455,30 @@ module.exports.iterator = function (leveldown, test, testCommon, collectEntries)
   )
 }
 
+module.exports.snapshot = function (leveldown, test, testCommon) {
+  test('setUp #3', function (t) {
+    db.close(function () {
+      db = leveldown(testCommon.location())
+      db.open(function () {
+        db.put('foobatch1', 'bar1', t.end.bind(t))
+      })
+    })
+  })
+
+  test('iterator create snapshot correctly', function (t) {
+    var iterator = db.iterator()
+    db.del('foobatch1', function () {
+      iterator.next(function (err, key, value) {
+        t.notOk(err, 'no error')
+        t.ok(key, 'got a key')
+        t.equal(key.toString(), 'foobatch1', 'correct key')
+        t.equal(value.toString(), 'bar1', 'correct value')
+        iterator.end(t.end.bind(t))
+      })
+    })
+  })
+}
+
 module.exports.tearDown = function (test, testCommon) {
   test('tearDown', function (t) {
     db.close(testCommon.tearDown.bind(null, t))
@@ -456,5 +490,6 @@ module.exports.all = function (leveldown, test, testCommon) {
   module.exports.args(test)
   module.exports.sequence(test)
   module.exports.iterator(leveldown, test, testCommon, testCommon.collectEntries)
+  module.exports.snapshot(leveldown, test, testCommon)
   module.exports.tearDown(test, testCommon)
 }
diff --git a/abstract/leveldown-test.js b/abstract/leveldown-test.js
index 205122b..1d4c23c 100644
--- a/abstract/leveldown-test.js
+++ b/abstract/leveldown-test.js
@@ -7,6 +7,16 @@ module.exports.args = function (leveldown, test) {
     )
     t.end()
   })
+  test('test database creation non-string location throws', function (t) {
+    t.throws(
+        function () {
+          leveldown({})
+        }
+      , { name: 'Error', message: 'constructor requires a location string argument' }
+      , 'non-string location leveldown() throws'
+    )
+    t.end()
+  })
 
   test('test database open no-arg throws', function (t) {
     var db = leveldown('foo')
diff --git a/abstract/open-test.js b/abstract/open-test.js
index 5bbeeb0..4f963a6 100644
--- a/abstract/open-test.js
+++ b/abstract/open-test.js
@@ -48,6 +48,22 @@ module.exports.open = function (leveldown, test, testCommon) {
         })
       })
   })
+  test('test database open, close and open', function (t) {
+    var db = leveldown(testCommon.location())
+
+    db.open(function (err) {
+      t.notOk(err, 'no error')
+      db.close(function (err) {
+        t.notOk(err, 'no error')
+        db.open(function (err) {
+          t.notOk(err, 'no error')
+          db.close(function () {
+            t.end()
+          })
+        })
+      })
+    })
+  })
 }
 
 module.exports.openAdvanced = function (leveldown, test, testCommon) {
diff --git a/abstract/put-get-del-test.js b/abstract/put-get-del-test.js
index e7e0935..a743413 100644
--- a/abstract/put-get-del-test.js
+++ b/abstract/put-get-del-test.js
@@ -5,7 +5,6 @@ var db
   , testBuffer
   , test
   , verifyNotFoundError = require('./util').verifyNotFoundError
-  , isTypedArray        = require('./util').isTypedArray
 
 function makeGetDelErrorTests (type, key, expectedError) {
   test('test get() with ' + type + ' causes error', function (t) {
@@ -38,18 +37,26 @@ function makePutErrorTest (type, key, value, expectedError) {
   })
 }
 
-function makePutGetDelSuccessfulTest (type, key, value) {
+function makePutGetDelSuccessfulTest (type, key, value, expectedResult) {
+  var hasExpectedResult = arguments.length == 4
   test('test put()/get()/del() with ' + type, function (t) {
     db.put(key, value, function (err) {
-      t.notOk(err, 'no error')
+      t.error(err)
       db.get(key, function (err, _value) {
-        t.notOk(err, 'no error, has key/value for `' + key + '`')
+        t.notOk(err, 'no error, has key/value for `' + type + '`')
         t.ok(Buffer.isBuffer(_value), 'is a Buffer')
-        var result = _value.toString()
-        value = value.toString()
-        t.equals(result, value)
+        var result = _value
+        if (hasExpectedResult) {
+          t.ok(result === expectedResult, 'got `' + expectedResult + '`')
+        } else {
+          if (result != null)
+            result = _value.toString()
+          if (value != null)
+            value = value.toString()
+          t.equals(result, value)
+        }
         db.del(key, function (err) {
-          t.notOk(err, 'no error, deleted key/value for `' + key + '`')
+          t.notOk(err, 'no error, deleted key/value for `' + type + '`')
           db.get(key, function (err,  value) {
             t.ok(err, 'entry propertly deleted')
             t.ok(verifyNotFoundError(err), 'should have correct error message')
@@ -80,7 +87,8 @@ module.exports.setUp = function (leveldown, test, testCommon) {
 /**** TEST ERROR KEYS ****/
 
 module.exports.errorKeys = function (testFunc, BufferType) {
-  if (!BufferType) BufferType = Buffer
+  if (!BufferType)
+    BufferType = Buffer
   test = testFunc
   makeErrorKeyTest('null key', null, /key cannot be `null` or `undefined`/)
   makeErrorKeyTest('undefined key', undefined, /key cannot be `null` or `undefined`/)
@@ -116,23 +124,25 @@ module.exports.nonErrorKeys = function (testFunc) {
 
 /**** TEST ERROR VALUES ****/
 
-module.exports.errorValues = function (testFunc, BufferType) {
-  if (!BufferType) BufferType = Buffer
-  test = testFunc
-  makePutErrorTest('null value', 'foo', null, /value cannot be `null` or `undefined`/)
-  makePutErrorTest('undefined value', 'foo', undefined, /value cannot be `null` or `undefined`/)
-  makePutErrorTest('empty String value', 'foo', '', /value cannot be an empty String/)
-  makePutErrorTest('empty Buffer value', 'foo', new BufferType(0), /value cannot be an empty \w*Buffer/)
-  makePutErrorTest('empty Array value', 'foo', [], /value cannot be an empty String/)
+module.exports.errorValues = function () {
 }
 
-module.exports.nonErrorKeys = function (testFunc) {
+module.exports.nonErrorValues = function (testFunc, BufferType) {
+  if (!BufferType) BufferType = Buffer
   // valid falsey values
   test = testFunc
   makePutGetDelSuccessfulTest('`false` value', 'foo false', false)
   makePutGetDelSuccessfulTest('`0` value', 'foo 0', 0)
   makePutGetDelSuccessfulTest('`NaN` value', 'foo NaN', NaN)
 
+  // all of the following result in an empty-string value:
+
+  makePutGetDelSuccessfulTest('`null` value', 'foo null', null, '')
+  makePutGetDelSuccessfulTest('`undefined` value', 'foo undefined', undefined, '')
+  makePutGetDelSuccessfulTest('empty String value', 'foo', '', '')
+  makePutGetDelSuccessfulTest('empty Buffer value', 'foo', new BufferType(0), '')
+  makePutGetDelSuccessfulTest('empty Array value', 'foo', [], '')
+
   // standard String value
   makePutGetDelSuccessfulTest(
       'long String value'
diff --git a/abstract/util.js b/abstract/util.js
index 82f155e..2ae5a4f 100644
--- a/abstract/util.js
+++ b/abstract/util.js
@@ -1,5 +1,7 @@
+var nfre = /NotFound/i
+
 module.exports.verifyNotFoundError = function verifyNotFoundError (err) {
-  return (/NotFound/i).test(err.message)
+  return nfre.test(err.message) || nfre.test(err.name)
 }
 
 module.exports.isTypedArray = function isTypedArray (value) {
diff --git a/package.json b/package.json
index d123c5a..632e057 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "abstract-leveldown",
   "description": "An abstract prototype matching the LevelDOWN API",
-  "version": "0.12.3",
+  "version": "2.0.1",
   "contributors": [
     "Rod Vagg <r at va.gg> (https://github.com/rvagg)",
     "John Chesley <john at chesl.es> (https://github.com/chesles/)",
diff --git a/test.js b/test.js
index 4ec2870..80d906a 100644
--- a/test.js
+++ b/test.js
@@ -64,7 +64,7 @@ tap.test('test core extensibility', function (t) {
 tap.test('test open() extensibility', function (t) {
   var spy = sinon.spy()
     , expectedCb = function () {}
-    , expectedOptions = { options: 1 }
+    , expectedOptions = { createIfMissing: true, errorIfExists: false }
     , test
 
   function Test (location) {
@@ -81,15 +81,17 @@ tap.test('test open() extensibility', function (t) {
   t.equal(spy.callCount, 1, 'got _open() call')
   t.equal(spy.getCall(0).thisValue, test, '`this` on _open() was correct')
   t.equal(spy.getCall(0).args.length, 2, 'got two arguments')
-  t.deepEqual(spy.getCall(0).args[0], {}, 'got blank options argument')
+  t.deepEqual(spy.getCall(0).args[0], expectedOptions, 'got default options argument')
   t.equal(spy.getCall(0).args[1], expectedCb, 'got expected cb argument')
 
-  test.open(expectedOptions, expectedCb)
+  test.open({ options: 1 }, expectedCb)
+
+  expectedOptions.options = 1
 
   t.equal(spy.callCount, 2, 'got _open() call')
   t.equal(spy.getCall(1).thisValue, test, '`this` on _open() was correct')
   t.equal(spy.getCall(1).args.length, 2, 'got two arguments')
-  t.deepEqual(spy.getCall(1).args[0], expectedOptions, 'got blank options argument')
+  t.deepEqual(spy.getCall(1).args[0], expectedOptions, 'got expected options argument')
   t.equal(spy.getCall(1).args[1], expectedCb, 'got expected cb argument')
   t.end()
 })
@@ -120,7 +122,7 @@ tap.test('test close() extensibility', function (t) {
 tap.test('test get() extensibility', function (t) {
   var spy = sinon.spy()
     , expectedCb = function () {}
-    , expectedOptions = { options: 1 }
+    , expectedOptions = { asBuffer: true }
     , expectedKey = 'a key'
     , test
 
@@ -139,16 +141,18 @@ tap.test('test get() extensibility', function (t) {
   t.equal(spy.getCall(0).thisValue, test, '`this` on _get() was correct')
   t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
   t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
-  t.deepEqual(spy.getCall(0).args[1], {}, 'got blank options argument')
+  t.deepEqual(spy.getCall(0).args[1], expectedOptions, 'got default options argument')
   t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
 
-  test.get(expectedKey, expectedOptions, expectedCb)
+  test.get(expectedKey, { options: 1 }, expectedCb)
+
+  expectedOptions.options = 1
 
   t.equal(spy.callCount, 2, 'got _get() call')
   t.equal(spy.getCall(1).thisValue, test, '`this` on _get() was correct')
   t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
   t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
-  t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got blank options argument')
+  t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
   t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
   t.end()
 })
@@ -184,7 +188,7 @@ tap.test('test del() extensibility', function (t) {
   t.equal(spy.getCall(1).thisValue, test, '`this` on _del() was correct')
   t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
   t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
-  t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got blank options argument')
+  t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
   t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
   t.end()
 })
@@ -290,6 +294,14 @@ tap.test('test batch() extensibility', function (t) {
   t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
   t.equal(spy.getCall(1).args[2], expectedCb, 'got expected callback argument')
 
+  test.batch(expectedArray, null, expectedCb)
+
+  t.equal(spy.callCount, 3, 'got _batch() call')
+  t.equal(spy.getCall(2).thisValue, test, '`this` on _batch() was correct')
+  t.equal(spy.getCall(2).args.length, 3, 'got three arguments')
+  t.equal(spy.getCall(2).args[0], expectedArray, 'got expected array argument')
+  t.ok(spy.getCall(2).args[1], 'options should not be null')
+  t.equal(spy.getCall(2).args[2], expectedCb, 'got expected callback argument')
   t.end()
 })
 
@@ -475,7 +487,7 @@ tap.test('test clear() extensibility', function (t) {
 
 tap.test('test iterator() extensibility', function (t) {
   var spy = sinon.spy()
-    , expectedOptions = { options: 1, reverse: false } // reverse now explicitly set
+    , expectedOptions = { options: 1, reverse: false, keys: true, values: true, limit: -1, keyAsBuffer: true, valueAsBuffer: true }
     , test
 
   function Test (location) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-abstract-leveldown.git



More information about the Pkg-javascript-commits mailing list