<commit_before>var assert = require('assert')
var crypto = require('crypto')
var proxyquire = require('proxyquire')

var Promise = global.Promise || require('bluebird')

var randomBytes = proxyquire('..', {
  crypto: {
    randomBytes: cryptoRandomBytes
  }
})

// Add Promise to mocha's global list
global.Promise = global.Promise

describe('randomBytes(size)', function () {
  describe('with global Promise', function () {
    before(function () {
      global.Promise = Promise
    })

    after(function () {
      global.Promise = undefined
    })

    it('should return a Buffer of the correct length', function () {
      return randomBytes(18).then(function (buf) {
        assert.ok(Buffer.isBuffer(buf))
        assert.equal(18, buf.length)
      })
    })

    describe('when PRNG not seeded', function () {
      afterEach(function () {
        cryptoRandomBytes.seeded = undefined
      })

      it('should still generate bytes when later seeded', function () {
        cryptoRandomBytes.seeded = 1

        return randomBytes(18).then(function (buf) {
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
        })
      })

      it('should attempt generation three times', function () {
        cryptoRandomBytes.seeded = 2

        return randomBytes(18).then(function (buf) {
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
        })
      })

      it('should reject if never seeded', function () {
        cryptoRandomBytes.seeded = false

        return randomBytes(18).then(unexpectedResolve, function (err) {
          assert.notEqual(err.message.indexOf('PRNG not seeded'), -1)
        })
      })
    })
  })

  describe('without global Promise', function () {
    before(function () {
      global.Promise = undefined
    })

    after(function () {
      global.Promise = Promise
    })

    it('should require callback', function () {
      assert.throws(function () {
        randomBytes(18)
      }, /argument callback.*required/)
    })

    it('should error for bad callback', function () {
      assert.throws(function () {
        randomBytes(18, 'silly')
      }, /argument callback.*function/)
    })

    it('should return a Buffer of the correct length', function (done) {
      randomBytes(18, function (err, buf) {
        if (err) return done(err)
        assert.ok(Buffer.isBuffer(buf))
        assert.equal(18, buf.length)
        done()
      })
    })

    describe('when PRNG not seeded', function () {
      afterEach(function () {
        cryptoRandomBytes.seeded = undefined
      })

      it('should still generate bytes when later seeded', function () {
        cryptoRandomBytes.seeded = 1

        randomBytes(18, function (err, buf) {
          if (err) return done(err)
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
          done()
        })
      })

      it('should attempt generation three times', function () {
        cryptoRandomBytes.seeded = 2

        randomBytes(18, function (err, buf) {
          if (err) return done(err)
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
          done()
        })
      })

      it('should error if never seeded', function () {
        cryptoRandomBytes.seeded = false

        randomBytes(18, function (err) {
          assert.ok(err)
          assert.notEqual(err.message.indexOf('PRNG not seeded'), -1)
          done()
        })
      })
    })
  })
})

describe('randomBytes.sync()', function () {
  it('should return a Buffer of the correct length', function () {
    var buf = randomBytes.sync(18)
    assert.ok(Buffer.isBuffer(buf))
    assert.equal(18, buf.length)
  })

  describe('when PRNG not seeded', function () {
    afterEach(function () {
      cryptoRandomBytes.seeded = undefined
    })

    it('should still generate bytes when later seeded', function () {
      cryptoRandomBytes.seeded = 1

      var buf = randomBytes.sync(18)
      assert.ok(Buffer.isBuffer(buf))
      assert.equal(18, buf.length)
    })<commit_msg>tests: fix tests missing callback functions<commit_after>var assert = require('assert')
var crypto = require('crypto')
var proxyquire = require('proxyquire')

var Promise = global.Promise || require('bluebird')

var randomBytes = proxyquire('..', {
  crypto: {
    randomBytes: cryptoRandomBytes
  }
})

// Add Promise to mocha's global list
global.Promise = global.Promise

describe('randomBytes(size)', function () {
  describe('with global Promise', function () {
    before(function () {
      global.Promise = Promise
    })

    after(function () {
      global.Promise = undefined
    })

    it('should return a Buffer of the correct length', function () {
      return randomBytes(18).then(function (buf) {
        assert.ok(Buffer.isBuffer(buf))
        assert.equal(18, buf.length)
      })
    })

    describe('when PRNG not seeded', function () {
      afterEach(function () {
        cryptoRandomBytes.seeded = undefined
      })

      it('should still generate bytes when later seeded', function () {
        cryptoRandomBytes.seeded = 1

        return randomBytes(18).then(function (buf) {
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
        })
      })

      it('should attempt generation three times', function () {
        cryptoRandomBytes.seeded = 2

        return randomBytes(18).then(function (buf) {
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
        })
      })

      it('should reject if never seeded', function () {
        cryptoRandomBytes.seeded = false

        return randomBytes(18).then(unexpectedResolve, function (err) {
          assert.notEqual(err.message.indexOf('PRNG not seeded'), -1)
        })
      })
    })
  })

  describe('without global Promise', function () {
    before(function () {
      global.Promise = undefined
    })

    after(function () {
      global.Promise = Promise
    })

    it('should require callback', function () {
      assert.throws(function () {
        randomBytes(18)
      }, /argument callback.*required/)
    })

    it('should error for bad callback', function () {
      assert.throws(function () {
        randomBytes(18, 'silly')
      }, /argument callback.*function/)
    })

    it('should return a Buffer of the correct length', function (done) {
      randomBytes(18, function (err, buf) {
        if (err) return done(err)
        assert.ok(Buffer.isBuffer(buf))
        assert.equal(18, buf.length)
        done()
      })
    })

    describe('when PRNG not seeded', function () {
      afterEach(function () {
        cryptoRandomBytes.seeded = undefined
      })

      it('should still generate bytes when later seeded', function (done) {
        cryptoRandomBytes.seeded = 1

        randomBytes(18, function (err, buf) {
          if (err) return done(err)
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
          done()
        })
      })

      it('should attempt generation three times', function (done) {
        cryptoRandomBytes.seeded = 2

        randomBytes(18, function (err, buf) {
          if (err) return done(err)
          assert.ok(Buffer.isBuffer(buf))
          assert.equal(18, buf.length)
          done()
        })
      })

      it('should error if never seeded', function (done) {
        cryptoRandomBytes.seeded = false

        randomBytes(18, function (err) {
          assert.ok(err)
          assert.notEqual(err.message.indexOf('PRNG not seeded'), -1)
          done()
        })
      })
    })
  })
})

describe('randomBytes.sync()', function () {
  it('should return a Buffer of the correct length', function () {
    var buf = randomBytes.sync(18)
    assert.ok(Buffer.isBuffer(buf))
    assert.equal(18, buf.length)
  })

  describe('when PRNG not seeded', function () {
    afterEach(function () {
      cryptoRandomBytes.seeded = undefined
    })

    it('should still generate bytes when later seeded', function () {
      cryptoRandomBytes.seeded = 1

      var buf = randomBytes.sync(18)
      assert.ok(Buffer.isBuffer(buf))
      assert.equal(18, buf.length)
    })
{'fraction_non_alphanumeric': 0.12880818912990494, 'fraction_numerical': 0.011455032902754082, 'mean_word_length': 2.3857260726072607, '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': '3654402', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2260, 'n_words': 542}