<commit_before>
/**
 * Module dependencies.
 */

var fs = require('fs');
var assert = require('assert');
var jade = require('../');
var uglify = require('uglify-js');

// test cases

var cases = fs.readdirSync('test/cases').filter(function(file){
  return ~file.indexOf('.jade');
}).map(function(file){
  return file.replace('.jade', '');
});
try {
  fs.mkdirSync(__dirname + '/output');
} catch (ex) {
  if (ex.code !== 'EEXIST') {
    throw ex;
  }
}

var mixinsUnusedTestRan = false;
cases.forEach(function(test){
  var name = test.replace(/[-.]/g, ' ');
  it(name, function(){
    var path = 'test/cases/' + test + '.jade';
    var str = fs.readFileSync(path, 'utf8');
    var html = fs.readFileSync('test/cases/' + test + '.html', 'utf8').trim().replace(/\r/g, '');
    var fn = jade.compile(str, { filename: path, pretty: true, basedir: 'test/cases' });
    var actual = fn({ title: 'Jade' });

    fs.writeFileSync(__dirname + '/output/' + test + '.html', actual)
    var clientCode = uglify.minify(jade.compileClient(str, {
      filename: path,
      pretty: false,
      compileDebug: false,
      client: true,
      basedir: 'test/cases'
    }), {output: {beautify: true}, mangle: false, compress: false, fromString: true}).code;
    fs.writeFileSync(__dirname + '/output/' + test + '.js', clientCode);
    if (/filter/.test(test)) {
      actual = actual.replace(/\n| /g, '');
      html = html.replace(/\n| /g, '');
    }
    if (/mixins-unused/.test(test)) {
      mixinsUnusedTestRan = true;
      assert(/never-called/.test(str), 'never-called is in the jade file for mixins-unused');
      assert(!/never-called/.test(clientCode), 'never-called should be removed from the code');
    }
    JSON.stringify(actual.trim()).should.equal(JSON.stringify(html));
  })
});
after(function () {
  assert(mixinsUnusedTestRan, 'mixins-unused test should run');
})

// test cases

var anti = fs.readdirSync('test/anti-cases').filter(function(file){
  return ~file.indexOf('.jade');
}).map(function(file){
  return file.replace('.jade', '');
});

describe('certain syntax is not allowed and will throw a compile time error', function () {
  anti.forEach(function(test){
    var name = test.replace(/[-.]/g, ' ');
    it(name, function(){
      var path = 'test/anti-cases/' + test + '.jade';
      var str = fs.readFileSync(path, 'utf8');
      try {
        var fn = jade.compile(str, { filename: path, pretty: true, basedir: 'test/anti-cases' });
      } catch (ex) {
        ex.should.be.an.instanceof(Error);
        return;
      }
      throw new Error(test + ' should have thrown an error');
    })
  });
});<commit_msg>Ensure error messages contain filename and line no<commit_after>
/**
 * Module dependencies.
 */

var fs = require('fs');
var assert = require('assert');
var jade = require('../');
var uglify = require('uglify-js');

// test cases

var cases = fs.readdirSync('test/cases').filter(function(file){
  return ~file.indexOf('.jade');
}).map(function(file){
  return file.replace('.jade', '');
});
try {
  fs.mkdirSync(__dirname + '/output');
} catch (ex) {
  if (ex.code !== 'EEXIST') {
    throw ex;
  }
}

var mixinsUnusedTestRan = false;
cases.forEach(function(test){
  var name = test.replace(/[-.]/g, ' ');
  it(name, function(){
    var path = 'test/cases/' + test + '.jade';
    var str = fs.readFileSync(path, 'utf8');
    var html = fs.readFileSync('test/cases/' + test + '.html', 'utf8').trim().replace(/\r/g, '');
    var fn = jade.compile(str, { filename: path, pretty: true, basedir: 'test/cases' });
    var actual = fn({ title: 'Jade' });

    fs.writeFileSync(__dirname + '/output/' + test + '.html', actual)
    var clientCode = uglify.minify(jade.compileClient(str, {
      filename: path,
      pretty: false,
      compileDebug: false,
      client: true,
      basedir: 'test/cases'
    }), {output: {beautify: true}, mangle: false, compress: false, fromString: true}).code;
    fs.writeFileSync(__dirname + '/output/' + test + '.js', clientCode);
    if (/filter/.test(test)) {
      actual = actual.replace(/\n| /g, '');
      html = html.replace(/\n| /g, '');
    }
    if (/mixins-unused/.test(test)) {
      mixinsUnusedTestRan = true;
      assert(/never-called/.test(str), 'never-called is in the jade file for mixins-unused');
      assert(!/never-called/.test(clientCode), 'never-called should be removed from the code');
    }
    JSON.stringify(actual.trim()).should.equal(JSON.stringify(html));
  })
});
after(function () {
  assert(mixinsUnusedTestRan, 'mixins-unused test should run');
})

// test cases

var anti = fs.readdirSync('test/anti-cases').filter(function(file){
  return ~file.indexOf('.jade');
}).map(function(file){
  return file.replace('.jade', '');
});

describe('certain syntax is not allowed and will throw a compile time error', function () {
  anti.forEach(function(test){
    var name = test.replace(/[-.]/g, ' ');
    it(name, function(){
      var path = 'test/anti-cases/' + test + '.jade';
      var str = fs.readFileSync(path, 'utf8');
      try {
        var fn = jade.compile(str, { filename: path, pretty: true, basedir: 'test/anti-cases' });
      } catch (ex) {
        ex.should.be.an.instanceof(Error);
        ex.message.replace(/\\/g, '/').should.startWith(path);
        ex.message.replace(/\\/g, '/').should.match(/:\d+$/m);
        return;
      }
      throw new Error(test + ' should have thrown an error');
    })
  });
});
{'fraction_non_alphanumeric': 0.19686635944700462, 'fraction_numerical': 0.0011059907834101382, 'mean_word_length': 3.1706379707916987, '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': '5577551', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1810, 'n_words': 413}