<commit_before>assert  = require 'assert'
leveldb = require '../lib'
path    = require 'path'




describe 'db', ->
  db = new leveldb.DB
  filename = "#{__dirname}/../tmp/db-test-file"

  itShouldBehaveLikeAKeyValueStore = (key, val) ->

    it 'should open database', (done) ->
      db.open filename, { create_if_missing: true, paranoid_checks: true }, done

    it 'should put key/value pair', (done) ->
      db.put key, val, done

    it 'should get key/value pair', (done) ->
      db.get key, (err, result) ->
        assert.ifError err
        assert.equal result, val.toString()
        done()

    it 'should delete key', (done) ->
      db.del key, done

    it 'should not get key/value pair', (done) ->
      db.get key, (err, result) ->
        assert.ifError err
        assert.equal result, undefined
        done()

    it 'should close database', (done) ->
      db.close done

    it 'should repair database', ->
      result = leveldb.DB.repairDB filename
      assert.equal result, 'OK'
      assert path.existsSync filename

    it 'should destroy database', ->
      result = leveldb.DB.destroyDB filename
      assert.equal result, 'OK'

  describe 'ascii', ->
    itShouldBehaveLikeAKeyValueStore "Hello", "World"

  describe 'buffer', ->
    key = new Buffer [1,9,9,9]
    val = new Buffer [1,2,3,4]
    itShouldBehaveLikeAKeyValueStore key, val<commit_msg>Better test descriptions<commit_after>assert  = require 'assert'
leveldb = require '../lib'
path    = require 'path'




describe 'db', ->
  db = new leveldb.DB
  filename = "#{__dirname}/../tmp/db-test-file"

  itShouldBehaveLikeAKeyValueStore = (key, val) ->

    it 'should open database', (done) ->
      db.open filename, { create_if_missing: true, paranoid_checks: true }, done

    it 'should put key/value pair', (done) ->
      db.put key, val, done

    it 'should get key/value pair', (done) ->
      db.get key, (err, result) ->
        assert.ifError err
        assert.equal result, val.toString()
        done()

    it 'should delete key', (done) ->
      db.del key, done

    it 'should not get key/value pair', (done) ->
      db.get key, (err, result) ->
        assert.ifError err
        assert.equal result, undefined
        done()

    it 'should close database', (done) ->
      db.close done

    it 'should repair database', ->
      result = leveldb.DB.repairDB filename
      assert.equal result, 'OK'
      assert path.existsSync filename

    it 'should destroy database', ->
      result = leveldb.DB.destroyDB filename
      assert.equal result, 'OK'

  describe 'with ascii values', ->
    itShouldBehaveLikeAKeyValueStore "Hello", "World"

  describe 'with buffer values', ->
    key = new Buffer [1,9,9,9]
    val = new Buffer [1,2,3,4]
    itShouldBehaveLikeAKeyValueStore key, val
{'fraction_non_alphanumeric': 0.12843382090617195, 'fraction_numerical': 0.005708169818052087, 'mean_word_length': 2.5448798988621997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '7180799', 'n_tokens_mistral': 897, 'n_tokens_neox': 857, 'n_words': 265}