<commit_before>'use strict';

var pugI18n = require('../index');
var path = require('path');
var fs = require('fs-extra');
var sassert = require('stream-assert');
var assert = require('assert');
var gulp = require('gulp');
require('mocha');

var fixtures = function (glob) { return path.join(__dirname, './fixtures', glob); }

describe('gulp-pug-i18n', function () {

  afterEach(function (done) {
    fs.remove('./.tmp', done);
  });

  describe('Translate directory:', function () {

    it('should translate the template into english', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*'
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/en_US/sample.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/en_US/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });

    it('should translate the template into spanish', function (done) {

      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*'
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/es_ES/sample.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/es_ES/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
  });

  describe('Translate file:', function () {
    it('should translate the template into english', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*',
          localeExtension: true
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.en_us.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/template.en_us.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
    it('should translate the template into spanish', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*',
          localeExtension: true
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.es_es.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/template.es_es.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
  });

  xdescribe('Without i18n:', function () {
    it('should generate the template without i18n task options', function (done) {
      var options = {
        i18n: {
          dest: '.tmp'
        },
        data: {
          $i18n: {
            message: 'Hello world!',
            nested: {
              msg: 'and hello to you'
            }
          }
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest('.tmp'))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.html')).toString();
          var actual = fs.readFileSync(path.join(__dirname, '../', '.tmp/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));
    });
  });
});<commit_msg>style(test.js): format code<commit_after>'use strict';

var pugI18n = require('../index');
var path = require('path');
var fs = require('fs-extra');
var sassert = require('stream-assert');
var assert = require('assert');
var gulp = require('gulp');
require('mocha');

var fixtures = function (glob) { return path.join(__dirname, './fixtures', glob); }

describe('gulp-pug-i18n', function () {

  afterEach(function (done) {
    fs.remove('./.tmp', done);
  });

  describe('Translate directory:', function () {

    it('should translate the template into english', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*'
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/en_US/sample.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/en_US/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });

    it('should translate the template into spanish', function (done) {

      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*'
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/es_ES/sample.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/es_ES/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
  });

  describe('Translate file:', function () {
    it('should translate the template into english', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*',
          localeExtension: true
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.en_us.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/template.en_us.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
    it('should translate the template into spanish', function (done) {
      var options = {
        i18n: {
          dest: '.tmp',
          locales: 'test/locales/*.*',
          localeExtension: true
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.es_es.html')).toString();
          var actual = fs.readFileSync(path.join('./.tmp/template.es_es.html')).toString();
          assert.equal(actual, expected);
          done();
        }));

    });
  });

  describe('Without i18n:', function () {
    it('should generate the template without i18n task options', function (done) {
      var options = {
        i18n: {
          dest: '.tmp'
        },
        data: {
          $i18n: {
            message: 'Hello world!',
            nested: {
              msg: 'and hello to you'
            }
          }
        },
        pretty: true
      };
      gulp.src(fixtures('directory/*.pug'))
        .pipe(pugI18n(options))
        .pipe(gulp.dest(options.i18n.dest))
        .pipe(sassert.end(function () {
          var expected = fs.readFileSync(path.join(__dirname, 'expected/template.html')).toString();
          var actual = fs.readFileSync(path.join(__dirname, '../', '.tmp/template.html')).toString();
          assert.equal(actual, expected);
          done();
        }));
    });
  });
});
{'fraction_non_alphanumeric': 0.17107518981141318, 'fraction_numerical': 0.009551800146950772, 'mean_word_length': 2.1279203370356186, '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': '6559095', 'n_tokens_mistral': 2533, 'n_tokens_neox': 2488, 'n_words': 432}