<commit_before>var test = require('tape')
  , Vinyl = require('vinyl')
  , through2 = require('through2')
  , eos = require('end-of-stream')
  , concat = require('concat-stream')
  , create = require('./util-create-db')
  , path = require('path')
  , unixify = require('unixify')
  , fromFile = require('vinyl-file')

test.skip('dest() resets streams', function(){
  // TODO
})

test.skip('watch()', function(){
  // TODO
})

test.skip('no conflicts between sublevel blobs', function(){
  // TODO
})

test.skip('src should pass through writes', function(t){})

test('src with opts.since', function(t){
  var vinylDb = create()

  var file1 = new Vinyl({
    path: __dirname+'/file1',
    contents: new Buffer('one'),
    stat: { mtime: new Date('1980-01-01') }
  })

  var file2 = new Vinyl({
    path: __dirname+'/file2',
    contents: new Buffer('two'),
    stat: { mtime: new Date }
  })

  t.plan(1)

  var ws = vinylDb.dest()

  eos(ws, function(err){
    var opts = { since: new Date('1990-01-01') }
    vinylDb.src('**', opts).pipe(concat(function(files){
      if (files.length!==1) return t.fail()
      t.equal(files[0].relative, file2.relative)
    }))
  })

  ws.write(file1)
  ws.end(file2)
})

test('stat', function(t){
  var vinylDb = create()

  t.test('stat is copied', function(t){
    t.plan(3)
    fromFile.read(path.join(__dirname, 'fixtures/text.md'), function(err, actual){
      vinylDb.put(actual, function(){
        vinylDb.src('**/*.md').pipe(concat(function(files){
          var file = files[0], stat = file && file.stat
          if (!stat) return t.fail()

          t.equal(stat.isFile(), true, 'is a file')
          t.ok(stat.ctime.getTime() >= actual.stat.ctime.getTime(), 'has ctime')
          t.equal(stat.mtime.getTime(), actual.stat.mtime.getTime(), 'mtime copied')
        }))
      })
    })
  })

  t.test('stat is created and updated', function(t){
    var file = new Vinyl({
      path: __dirname+'/img/test.jpg',
      contents: new Buffer('foo')
    })

    t.plan(7)
    vinylDb.put(file, function(){
      vinylDb.src('**/*.jpg').pipe(concat(function(files){
        var file = files[0], stat = file && file.stat
        if (!stat) return t.fail()

        t.equal(stat.isFile(), true, 'is a file')

        var now = Date.now()
          , ctime = stat.ctime.getTime()
          , mtime = stat.mtime.getTime()

        t.ok(ctime <= now, 'has ctime Date')
        t.ok(mtime <= now, 'has mtime Date')

        setTimeout(function(){
          vinylDb.put(file, function(){
            var ctime2 = file.stat.ctime.getTime()
              , mtime2 = file.stat.mtime.getTime()

            t.ok(ctime<ctime2, 'ctime changed')
            t.equal(mtime, mtime2, 'mtime unchanged')

            file.contents = new Buffer('baz')

            vinylDb.put(file, function(){
              var ctime3 = file.stat.ctime.getTime()
                , mtime3 = file.stat.mtime.getTime()

              t.ok(ctime2<ctime3, 'ctime changed')
              t.ok(mtime2<mtime3, 'mtime changed after content change')
            })
          })
        }, 1)
      }))
    })
  })
})

test('throws on invalid glob', function(t){
  var vinylDb = create()

  t.throws(vinylDb.src, 'no arguments')
  t.throws(vinylDb.src.bind(vinylDb, 123), 'number')
  t.throws(vinylDb.src.bind(vinylDb, ''), 'empty string')
  t.throws(vinylDb.src.bind(vinylDb, null), 'null')
  t.throws(vinylDb.src.bind(vinylDb, [123]), 'array with number')
  t.throws(vinylDb.src.bind(vinylDb, [null]), 'array with null')
  t.end()
})

test('dead stream if globs is empty array', function(t){<commit_msg>fix time<commit_after>var test = require('tape')
  , Vinyl = require('vinyl')
  , through2 = require('through2')
  , eos = require('end-of-stream')
  , concat = require('concat-stream')
  , create = require('./util-create-db')
  , path = require('path')
  , unixify = require('unixify')
  , fromFile = require('vinyl-file')

test.skip('dest() resets streams', function(){
  // TODO
})

test.skip('watch()', function(){
  // TODO
})

test.skip('no conflicts between sublevel blobs', function(){
  // TODO
})

test.skip('src should pass through writes', function(t){})

test('src with opts.since', function(t){
  var vinylDb = create()

  var file1 = new Vinyl({
    path: __dirname+'/file1',
    contents: new Buffer('one'),
    stat: { mtime: new Date('1980-01-01') }
  })

  var file2 = new Vinyl({
    path: __dirname+'/file2',
    contents: new Buffer('two'),
    stat: { mtime: new Date }
  })

  t.plan(1)

  var ws = vinylDb.dest()

  eos(ws, function(err){
    var opts = { since: new Date('1990-01-01') }
    vinylDb.src('**', opts).pipe(concat(function(files){
      if (files.length!==1) return t.fail()
      t.equal(files[0].relative, file2.relative)
    }))
  })

  ws.write(file1)
  ws.end(file2)
})

test('stat', function(t){
  var vinylDb = create()

  t.test('stat is copied', function(t){
    t.plan(3)
    fromFile.read(path.join(__dirname, 'fixtures/text.md'), function(err, actual){
      vinylDb.put(actual, function(){
        vinylDb.src('**/*.md').pipe(concat(function(files){
          var file = files[0], stat = file && file.stat
          if (!stat) return t.fail()

          t.equal(stat.isFile(), true, 'is a file')
          t.ok(stat.ctime.getTime() >= actual.stat.ctime.getTime(), 'has ctime')
          t.equal(stat.mtime.getTime(), actual.stat.mtime.getTime(), 'mtime copied')
        }))
      })
    })
  })

  t.test('stat is created and updated', function(t){
    var file = new Vinyl({
      path: __dirname+'/img/test.jpg',
      contents: new Buffer('foo')
    })

    t.plan(7)
    vinylDb.put(file, function(){
      vinylDb.src('**/*.jpg').pipe(concat(function(files){
        var file = files[0], stat = file && file.stat
        if (!stat) return t.fail()

        t.equal(stat.isFile(), true, 'is a file')

        var now = Date.now()
          , ctime = stat.ctime.getTime()
          , mtime = stat.mtime.getTime()

        t.ok(ctime <= now, 'has ctime Date')
        t.ok(mtime <= now, 'has mtime Date')

        setTimeout(function(){
          vinylDb.put(file, function(){
            var ctime2 = file.stat.ctime.getTime()
              , mtime2 = file.stat.mtime.getTime()

            t.ok(ctime<ctime2, 'ctime changed')
            t.equal(mtime, mtime2, 'mtime unchanged')

            file.contents = new Buffer('baz')

            setTimeout(function(){
              vinylDb.put(file, function(){
                var ctime3 = file.stat.ctime.getTime()
                  , mtime3 = file.stat.mtime.getTime()

                t.ok(ctime2<ctime3, 'ctime changed')
                t.ok(mtime2<mtime3, 'mtime changed after content change')
              })
            }, 2)
          })
        }, 2)
      }))
    })
  })
})

test('throws on invalid glob', function(t){
  var vinylDb = create()

  t.throws(vinylDb.src, 'no arguments')
  t.throws(vinylDb.src.bind(vinylDb, 123), 'number')
  t.throws(vinylDb.src.bind(vinylDb, ''), 'empty string')
  t.throws(vinylDb.src.bind(vinylDb, null), 'null')
  t.throws(vinylDb.src.bind(vinylDb, [123]), 'array with number')
  t.throws(vinylDb.src.bind(vinylDb, [null]), 'array with null')
  t.end()
})

test('dead stream if globs is empty array', function(t){
{'fraction_non_alphanumeric': 0.18042939719240297, 'fraction_numerical': 0.013625103220478944, 'mean_word_length': 2.620827105132038, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '5165381', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2469, 'n_words': 520}