<commit_before>
var should = require('should');
var assert = require('assert');

var is = require('..')

function req(type) {
  return {
    headers: {
      'content-type': type || '',
      'transfer-encoding': 'chunked'
    }
  }
}

describe('is(req, type)', function(){
  it('should ignore params', function(){
    is(req('text/html; charset=utf-8'), ['text/*'])
    .should.equal('text/html');
  })

  describe('when no body is given', function(){
    it('should return null', function(){
      var req = {headers: {}}

      assert(null == is(req));
      assert(null == is(req, ['image/*']));
      assert(null == is(req, 'image/*', 'text/*'));
    })
  })

  describe('when no content type is given', function(){
    it('should return false', function(){
      is(req()).should.be.false;
      is(req(), ['image/*']).should.be.false;
      is(req(), ['text/*', 'image/*']).should.be.false;
    })
  })

  describe('give no types', function(){
    it('should return the mime type', function(){
      is(req('image/png')).should.equal('image/png');
    })
  })

  describe('given one type', function(){
    it('should return the type or false', function(){
      var r = req('image/png')

      is(r, ['png']).should.equal('png');
      is(r, ['.png']).should.equal('.png');
      is(r, ['image/png']).should.equal('image/png');
      is(r, ['image/*']).should.equal('image/png');
      is(r, ['*/png']).should.equal('image/png');

      is(r, ['jpeg']).should.be.false;
      is(r, ['.jpeg']).should.be.false;
      is(r, ['image/jpeg']).should.be.false;
      is(r, ['text/*']).should.be.false;
      is(r, ['*/jpeg']).should.be.false;

      is(r, ['bogus']).should.be.false;
    })
  })

  describe('given multiple types', function(){
    it('should return the first match or false', function(){
      var r = req('image/png')

      is(r, ['png']).should.equal('png');
      is(r, '.png').should.equal('.png');
      is(r, ['text/*', 'image/*']).should.equal('image/png');
      is(r, ['image/*', 'text/*']).should.equal('image/png');
      is(r, ['image/*', 'image/png']).should.equal('image/png');
      is(r, 'image/png', 'image/*').should.equal('image/png');

      is(r, ['jpeg']).should.be.false;
      is(r, ['.jpeg']).should.be.false;
      is(r, ['text/*', 'application/*']).should.be.false;
      is(r, ['text/html', 'text/plain', 'application/json']).should.be.false;
    })
  })

  describe('given +suffix', function(){
    it('should match suffix types', function(){
      var r = req('application/vnd+json')

      is(r, '+json').should.equal('application/vnd+json')
      is(r, 'application/vnd+json').should.equal('application/vnd+json')
      is(r, 'application/*+json').should.equal('application/vnd+json')
      is(r, '*/vnd+json').should.equal('application/vnd+json')
      is(r, 'application/json').should.be.false
      is(r, 'text/*+json').should.be.false
    })
  })

  describe('when Content-Type: application/x-www-form-urlencoded', function(){
    it('should match "urlencoded"', function(){
      var r = req('application/x-www-form-urlencoded')

      is(r, ['urlencoded']).should.equal('urlencoded');
      is(r, ['json', 'urlencoded']).should.equal('urlencoded');
      is(r, ['urlencoded', 'json']).should.equal('urlencoded');
    })
  })

  describe('when Content-Type: multipart/form-data', function(){
    it('should match "multipart/*"', function(){
      var r = req('multipart/form-data');

      is(r, ['multipart/*']).should.equal('multipart/form-data');
    })

    it('should match "multipart"', function(){
      var r = req('multipart/form-data');

      is(r, ['multipart']).should.equal('multipart');
    })
  })
})<commit_msg>test: rename export in test<commit_after>
var should = require('should');
var assert = require('assert');

var typeis = require('..')

function req(type) {
  return {
    headers: {
      'content-type': type || '',
      'transfer-encoding': 'chunked'
    }
  }
}

describe('typeis(req, type)', function(){
  it('should ignore params', function(){
    typeis(req('text/html; charset=utf-8'), ['text/*'])
    .should.equal('text/html');
  })

  describe('when no body is given', function(){
    it('should return null', function(){
      var req = {headers: {}}

      assert(null == typeis(req));
      assert(null == typeis(req, ['image/*']));
      assert(null == typeis(req, 'image/*', 'text/*'));
    })
  })

  describe('when no content type is given', function(){
    it('should return false', function(){
      typeis(req()).should.be.false;
      typeis(req(), ['image/*']).should.be.false;
      typeis(req(), ['text/*', 'image/*']).should.be.false;
    })
  })

  describe('give no types', function(){
    it('should return the mime type', function(){
      typeis(req('image/png')).should.equal('image/png');
    })
  })

  describe('given one type', function(){
    it('should return the type or false', function(){
      var r = req('image/png')

      typeis(r, ['png']).should.equal('png');
      typeis(r, ['.png']).should.equal('.png');
      typeis(r, ['image/png']).should.equal('image/png');
      typeis(r, ['image/*']).should.equal('image/png');
      typeis(r, ['*/png']).should.equal('image/png');

      typeis(r, ['jpeg']).should.be.false;
      typeis(r, ['.jpeg']).should.be.false;
      typeis(r, ['image/jpeg']).should.be.false;
      typeis(r, ['text/*']).should.be.false;
      typeis(r, ['*/jpeg']).should.be.false;

      typeis(r, ['bogus']).should.be.false;
    })
  })

  describe('given multiple types', function(){
    it('should return the first match or false', function(){
      var r = req('image/png')

      typeis(r, ['png']).should.equal('png');
      typeis(r, '.png').should.equal('.png');
      typeis(r, ['text/*', 'image/*']).should.equal('image/png');
      typeis(r, ['image/*', 'text/*']).should.equal('image/png');
      typeis(r, ['image/*', 'image/png']).should.equal('image/png');
      typeis(r, 'image/png', 'image/*').should.equal('image/png');

      typeis(r, ['jpeg']).should.be.false;
      typeis(r, ['.jpeg']).should.be.false;
      typeis(r, ['text/*', 'application/*']).should.be.false;
      typeis(r, ['text/html', 'text/plain', 'application/json']).should.be.false;
    })
  })

  describe('given +suffix', function(){
    it('should match suffix types', function(){
      var r = req('application/vnd+json')

      typeis(r, '+json').should.equal('application/vnd+json')
      typeis(r, 'application/vnd+json').should.equal('application/vnd+json')
      typeis(r, 'application/*+json').should.equal('application/vnd+json')
      typeis(r, '*/vnd+json').should.equal('application/vnd+json')
      typeis(r, 'application/json').should.be.false
      typeis(r, 'text/*+json').should.be.false
    })
  })

  describe('when Content-Type: application/x-www-form-urlencoded', function(){
    it('should match "urlencoded"', function(){
      var r = req('application/x-www-form-urlencoded')

      typeis(r, ['urlencoded']).should.equal('urlencoded');
      typeis(r, ['json', 'urlencoded']).should.equal('urlencoded');
      typeis(r, ['urlencoded', 'json']).should.equal('urlencoded');
    })
  })

  describe('when Content-Type: multipart/form-data', function(){
    it('should match "multipart/*"', function(){
      var r = req('multipart/form-data');

      typeis(r, ['multipart/*']).should.equal('multipart/form-data');
    })

    it('should match "multipart"', function(){
      var r = req('multipart/form-data');

      typeis(r, ['multipart']).should.equal('multipart');
    })
  })
})
{'fraction_non_alphanumeric': 0.23748344370860927, 'fraction_numerical': 0.00026490066225165563, 'mean_word_length': 3.3371625502584723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1399648', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2503, 'n_words': 446}