<commit_before>'use strict';

var expect = require('chai').expect;
var generator = require('../');
var fs = require('fs');
var jf = require('jsonfile');

describe( 'generator(pkg, opts, callback)', function () {
  it( 'should generator files with pkg and opts',
    function ( done ) {
      var pkg = jf.readFileSync( 'test/fixtures/cortex1.json' );
      var opts = { 
        template: generator.availableTemplates()[0],
        cwd     : 'test/expected'
      };

      generator( pkg, opts, function ( err ) {
        var expected = fs.readFileSync( 'test/expected/index.js','utf-8' );
        expect( expected ).not.to.be.null;
        done();
      });
    }
  );

  it( 'should override files when opts.override is true',
    function ( done ) {
      var pkg = jf.readFileSync( 'test/fixtures/cortex2.json' );
      var opts = { 
        template: generator.availableTemplates()[0],
        cwd     : 'test/expected',
        override: true
      };

      generator( pkg, opts, function ( err ) {
        var genPkg = jf.readFileSync( 'test/expected/package.json' );
        expect( genPkg.name ).to.equal( pkg.name );
        done();
      });
    }
  );

  it( 'should only add cortex config in package.json when opts.override is false',
    function ( done ) {
      var packageJsonFile = fs.readFileSync( 'test/fixtures/package.json' );
      fs.writeFileSync( 'test/expected/package.json', packageJsonFile );

      var pkg = jf.readFileSync( 'test/fixtures/cortex2.json' );
      var opts = {
        template: generator.availableTemplates()[0],
        cwd     : 'test/expected',
        override: false
      };

      generator( pkg, opts, function (err) {
        var genPkg = jf.readFileSync( 'test/expected/package.json' );
        expect( genPkg.cortex ).not.to.be.null;
        done();
      });
    }
  );

  describe( '#availableLicenses()', function () {
    it( 'should return available licences array', function ( done ) {
      expect( generator.availableLicenses() ).to.be.a( 'array' );
      done();
    });
  });

  describe( '#availableTemplates', function () {
    it( 'should return available templates array', function ( done ) {
      expect(generator.availableTemplates() ).to.be.a( 'array' );
      done();
    });
  });
});
<commit_msg>fixes test cases: #18<commit_after>'use strict';

var expect = require('chai').expect;
var generator = require('../');
var fs = require('fs');
var fse = require('fs-extra');
var tmp = require('tmp-sync');
var node_path = require('path');
var jf = require('jsonfile');

var pkg = node_path.join(__dirname, 'fixtures', 'package.json');
pkg = jf.readFileSync(pkg);


var cases = [
  {
    // desc
    d: 'cortex.json file',
    // setup
    // s: function (to) {
      
    // },
    // expect
    e: function (to) {
      var new_pkg = jf.readFileSync( node_path.join(to, 'cortex.json') );
      expect(new_pkg).to.deep.equal(pkg);
    }
  },
  {
    d: 'rename files',
    e: function (to) {
      expect(fs.existsSync(node_path.join(to, 'lib', 'blah.js'))).to.equal(true);
    }
  },
  {
    d: 'test override',
    s: function (to) {
      var file = node_path.join(to, 'cortex.json');
      fs.writeFileSync(file, 'abc');
    },
    o: {

    },
    e: function (to) {
      var file = node_path.join(to, 'cortex.json');
      expect( fs.readFileSync(file).toString() ).to.equal('abc');
    }
  }
];

describe( 'generator(pkg, options, callback)', function (done) {
  cases.forEach(function (c) {
    var to = tmp.in(__dirname);
    c.s && c.s(to);
    it(c.d, function(done){
      var options = c.o || {};
      options.cwd = to;
      generator(pkg, options, function (err) {
        c.e(to);
        done();
      });
    });
  });
});


describe( 'generator.availableLicenses()', function () {
  it( 'should return available licences array', function ( done ) {
    expect( generator.availableLicenses() ).to.be.a( 'array' );
    done();
  });
});

describe( 'generator.availableTemplates', function () {
  it( 'should return available templates array', function ( done ) {
    expect(generator.availableTemplates() ).to.be.a( 'array' );
    done();
  });
});

{'fraction_non_alphanumeric': 0.17229729729729729, 'fraction_numerical': 0.002171814671814672, 'mean_word_length': 2.607484769364665, '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': '908741', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1336, 'n_words': 307}