{"size": 2574, "ext": "js", "max_stars_repo_path": "test/configTest.js", "max_stars_repo_name": "Nick-Pearson/node-jekyll", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/configTest.js", "max_issues_repo_name": "Nick-Pearson/node-jekyll", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/configTest.js", "max_forks_repo_name": "Nick-Pearson/node-jekyll", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.5360824742, "max_line_length": 88, "alphanum_fraction": 0.5998445998}
'use strict';

const assert = require('assert');
const path = require('path');

const Config = require('../src/config.js');

describe('config', function()
{
  describe('#Config(configString)', function()
  {
    it('returns default config if no parameter', function()
    {
      const cfg = new Config();
      assert.notEqual(cfg, null);
      assert.deepEqual(cfg.data, {});
    });

    it('returns config with yaml data if yaml string parameter', function()
    {
      const cfg = new Config('exclude: [myfile]');
      assert.notEqual(cfg, null);
      assert.deepEqual(cfg.data, {exclude: ['myfile']});
    });

    it('throws on invalid yaml string parameter', function()
    {
      try
      {
        new Config('*:');
        assert.fail();
      }
      catch (e)
      {
        assert.deepEqual(e.name, 'YAMLException');
      }
    });
  });

  describe('#isFileExcluded(file)', function()
  {
    it('false for file not in exclude list ', function()
    {
      const cfg = new Config();
      assert.strictEqual(false, cfg.isFileExcluded('/blog/index.html'));
    });

    it('true for file in exclude list ', function()
    {
      const cfg = new Config('exclude: [/blog/index.html]');
      assert.strictEqual(true, cfg.isFileExcluded('/blog/index.html'));
    });

    it('true for file that starts with underscore', function()
    {
      const cfg = new Config();
      assert.strictEqual(true, cfg.isFileExcluded('/blog/_index.html'));
    });

    it('true for file in directory that starts with underscore', function()
    {
      const cfg = new Config();
      assert.strictEqual(true, cfg.isFileExcluded('/blog/_post/index.html'));
    });
  });

  describe('#getSourceDir', function()
  {
    it('current working directory if source not specified', function()
    {
      const cfg = new Config();
      assert.strictEqual(path.normalize(process.cwd()), cfg.getSourceDir());
    });

    it('subdirectory if specified', function()
    {
      const cfg = new Config('source: ./subdir');
      assert.strictEqual(path.normalize(process.cwd() + '/subdir'), cfg.getSourceDir());
    });
  });

  describe('#getBuildDir', function()
  {
    it('_site directory if source not specified', function()
    {
      const cfg = new Config();
      assert.strictEqual(path.normalize(process.cwd() + '/_site'), cfg.getBuildDir());
    });

    it('subdirectory if specified', function()
    {
      const cfg = new Config('destination: ./_other');
      assert.strictEqual(path.normalize(process.cwd() + '/_other'), cfg.getBuildDir());
    });
  });
});
