<commit_before>'use strict'

var test = require('tape')
var abstract = require('abstract-leveldown')

function isAbstract (db) {
  if (!db || typeof db !== 'object') { return false }
  return Object.keys(abstract.AbstractLevelDOWN.prototype).filter(function (name) {
    return name[0] !== '_'
  }).every(function (name) {
    return typeof db[name] === 'function'
  })
}

function down (db, type) {
  if (typeof db.down === 'function') return db.down(type)
  if (type && db.type === type) return db
  if (isAbstract(db.db)) return down(db.db, type)
  if (isAbstract(db._db)) return down(db._db, type)
  return type ? null : db
}

exports.args = function (level, expectedDown) {
  test('without arguments', function (t) {
    t.plan(3)

    var db = level()

    db.on('open', function () {
      t.ok(down(db) instanceof expectedDown, 'got expected down')
    })

    db.put('foo', 'bar', function (err) {
      t.ifError(err)
      t.notOk(err)
    })
  })

  test('with options and callback', function (t) {
    t.plan(6)

    level({ valueEncoding: 'json' }, function (err, db) {
      t.ifError(err)
      t.ok(db.isOpen())
      t.ok(down(db) instanceof expectedDown, 'got expected down')

      var key = '' + Math.random()
      var value = { test_key: '' + new Date() }<commit_msg>Relax isAbstract check in tests (closes #125)<commit_after>'use strict'

var test = require('tape')

function isLooseAbstract (db) {
  if (!db || typeof db !== 'object') { return false }
  return typeof db._batch === 'function' && typeof db._iterator === 'function'
}

function down (db, type) {
  if (typeof db.down === 'function') return db.down(type)
  if (type && db.type === type) return db
  if (isLooseAbstract(db.db)) return down(db.db, type)
  if (isLooseAbstract(db._db)) return down(db._db, type)
  return type ? null : db
}

exports.args = function (level, expectedDown) {
  test('without arguments', function (t) {
    t.plan(3)

    var db = level()

    db.on('open', function () {
      t.ok(down(db) instanceof expectedDown, 'got expected down')
    })

    db.put('foo', 'bar', function (err) {
      t.ifError(err)
      t.notOk(err)
    })
  })

  test('with options and callback', function (t) {
    t.plan(6)

    level({ valueEncoding: 'json' }, function (err, db) {
      t.ifError(err)
      t.ok(db.isOpen())
      t.ok(down(db) instanceof expectedDown, 'got expected down')

      var key = '' + Math.random()
      var value = { test_key: '' + new Date() }
{'fraction_non_alphanumeric': 0.16976556184316896, 'fraction_numerical': 0.0032336297493936943, 'mean_word_length': 3.2235494880546076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522557', 'n_tokens_mistral': 843, 'n_tokens_neox': 827, 'n_words': 227}