
var assert = require('assert')
var fs = require('fs')

var db = require('..')

describe('mime-db', function () {
  it('should not contain types not in src/', function () {
    var path = __dirname + '/../src'
    var types = []

    // collect all source types
    fs.readdirSync(path).forEach(function (file) {
      if (!/^\w+\.json$/.test(file)) return
      types.push.apply(types, Object.keys(require(path + '/' + file)))
    })

    Object.keys(db).forEach(function (name) {
      assert.ok(types.indexOf(name) !== -1, 'type "' + name + '" should be in src/')
    })
  })

  it('should all be mime types', function () {
    assert(Object.keys(db).every(function (name) {
      return ~name.indexOf('/') || console.log(name)
    }))
  })

  it('should not have any uppercased letters in names', function () {
    assert(Object.keys(db).every(function (name) {
      return name === name.toLowerCase()
    }))
  })

  it('should have .json and .js as having UTF-8 charsets', function () {
    assert.equal('UTF-8', db['application/json'].charset)
    assert.equal('UTF-8', db['application/javascript'].charset)
  })

  it('should set audio/x-flac with extension=flac', function () {
    assert.equal('flac', db['audio/x-flac'].extensions[0])
  })

  it('should have guessed application/mathml+xml', function () {
    // because it doesn't have a "template"
    assert(db['application/mathml+xml'])
  })

  it('should not have an empty .extensions', function () {
    assert(Object.keys(db).every(function (name) {
      var mime = db[name]
      if (!mime.extensions) return true
      return mime.extensions.length
    }))
  })

  it('should have the default .extension as the first', function () {
    assert.equal(db['text/plain'].extensions[0], 'txt')
    assert.equal(db['video/x-matroska'].extensions[0], 'mkv')
  })
})

@@ -804,39 +804,32 @@
 nction () %7B%0A    
-assert(
 Object.keys(db).
@@ -820,37 +820,39 @@
 Object.keys(db).
-every
+forEach
 (function (name)
@@ -864,23 +864,26 @@
     
-return name ===
+assert.equal(name,
  nam
@@ -897,24 +897,67 @@
 erCase()
+, 'type %22' + name + '%22 should be lowercase')
 %0A    %7D)
-)
 %0A  %7D)%0A%0A 

improve failed lowercase test message