<commit_before>'use strict';

var pluginPath = '../index';
var checktextdomain = require(pluginPath);
var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs-extra');
var path = require('path');
var should = require('should');
var assert = require('assert');
var sassert = require('stream-assert');
require('mocha');

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

var keywords = [
	'__:1,2d',
	'_e:1,2d',
	'_x:1,2c,3d',
	'esc_html__:1,2d',
	'esc_html_e:1,2d',
	'esc_html_x:1,2c,3d',
	'esc_attr__:1,2d', 
	'esc_attr_e:1,2d', 
	'esc_attr_x:1,2c,3d', 
	'_ex:1,2c,3d',
	'_n:1,2,4d', 
	'_nx:1,2,4c,5d',
	'_n_noop:1,2,3d',
	'_nx_noop:1,2,3c,4d'
];


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

function fileExists(filePath) {
  try {
    return fs.statSync(filePath).isFile();
  } catch (err) {
    return false;
  }
}

describe('gulp-checktextdomain', function() {
  
  var tmpFolder = path.join(__dirname, 'temp');

  beforeEach(function(done) {
    var folder = path.join(__dirname, './fixtures/');
    fs.copy(folder, tmpFolder, function(err) {
      done();
    });
  });

  // We'll delete it when we're done.
  afterEach(function(done) {
    fs.remove(tmpFolder, done);
  });


  it('1) Domain should have been corrected', function(done) {
    
      var actual;
      var corrected;
      var expected;
      var options = {
        force: true,
        text_domain: 'my-domain',
        correct_domain: true,
        create_report_file: true,
        keywords: keywords
      };
      
      gulp.src(fixtures('incorrect-domain-autocorrect.php'))
      .pipe(checktextdomain(options))
      .pipe(sassert.first(function(d) {
        //There are 14 missing domains
        actual = JSON.parse(fs.readFileSync( '.incorrect-domain-autocorrect.json' ) );
        actual[path.join(__dirname, 'temp/incorrect-domain-autocorrect.php')].length.should.equal(14);
        
        //Test corrected file
        corrected = fs.readFileSync( 'test/temp/incorrect-domain-autocorrect.php' ).toString();
        expected = fs.readFileSync( 'test/expected/incorrect-domain-autocorrect.php' ).toString();
        corrected.should.equal(expected);
        
        //Clean up: Delete report file
        fs.remove( '.incorrect-domain-autocorrect.json' );
      }))
      .pipe(sassert.end(done));
      

  });

  xit('2) variable_domain_autocomplete', function(done) {
    
  });

  xit('3) missing_domain', function(done) {
    


  });

  xit('4) missing_domain_ignore_missing', function(done) {

   
  });
  
  xit('5) correct_domain', function(done) {

   
  });
  
  xit('6) plurals', function(done) {<commit_msg>test(test.js): enable test number 2<commit_after>'use strict';

var pluginPath = '../index';
var checktextdomain = require(pluginPath);
var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs-extra');
var path = require('path');
var should = require('should');
var assert = require('assert');
var sassert = require('stream-assert');
require('mocha');

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

var keywords = [
	'__:1,2d',
	'_e:1,2d',
	'_x:1,2c,3d',
	'esc_html__:1,2d',
	'esc_html_e:1,2d',
	'esc_html_x:1,2c,3d',
	'esc_attr__:1,2d', 
	'esc_attr_e:1,2d', 
	'esc_attr_x:1,2c,3d', 
	'_ex:1,2c,3d',
	'_n:1,2,4d', 
	'_nx:1,2,4c,5d',
	'_n_noop:1,2,3d',
	'_nx_noop:1,2,3c,4d'
];


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

function fileExists(filePath) {
  try {
    return fs.statSync(filePath).isFile();
  } catch (err) {
    return false;
  }
}

describe('gulp-checktextdomain', function() {
  
  var tmpFolder = path.join(__dirname, 'temp');

  beforeEach(function(done) {
    var folder = path.join(__dirname, './fixtures/');
    fs.copy(folder, tmpFolder, function(err) {
      done();
    });
  });

  // We'll delete it when we're done.
  afterEach(function(done) {
    fs.remove(tmpFolder, done);
  });


  it('1) Domain should have been corrected', function(done) {
    
      var actual;
      var corrected;
      var expected;
      var options = {
        force: true,
        text_domain: 'my-domain',
        correct_domain: true,
        create_report_file: true,
        keywords: keywords
      };
      
      gulp.src(fixtures('incorrect-domain-autocorrect.php'))
      .pipe(checktextdomain(options))
      .pipe(sassert.first(function(d) {
        //There are 14 missing domains
        actual = JSON.parse(fs.readFileSync( '.incorrect-domain-autocorrect.json' ) );
        actual[path.join(__dirname, 'temp/incorrect-domain-autocorrect.php')].length.should.equal(14);
        
        //Test corrected file
        corrected = fs.readFileSync( 'test/temp/incorrect-domain-autocorrect.php' ).toString();
        expected = fs.readFileSync( 'test/expected/incorrect-domain-autocorrect.php' ).toString();
        corrected.should.equal(expected);
        
        //Clean up: Delete report file
        fs.remove( '.incorrect-domain-autocorrect.json' );
      }))
      .pipe(sassert.end(done));
      

  });

  it('2) Domain should have been corrected', function(done) {
      var actual;
      var corrected;
      var expected;
      var options = {
        force: true,
        text_domain: 'my-domain',
        correct_domain: true,
        create_report_file: true,
        keywords: keywords
      };

      gulp.src(fixtures('variable-domain-autocorrect.php'))
      .pipe(checktextdomain(options))
      .pipe(sassert.first(function(d) {
        //There are 14 missing domains
        actual = JSON.parse(fs.readFileSync( '.variable-domain-autocorrect.json' ) );
        actual[path.join(__dirname, 'temp/variable-domain-autocorrect.php')].length.should.equal(14);
        
        //Test corrected file
        corrected = fs.readFileSync( 'test/temp/variable-domain-autocorrect.php' ).toString();
        expected = fs.readFileSync( 'test/expected/variable-domain-autocorrect.php' ).toString();
        corrected.should.equal(expected);
        
        //Clean up: Delete report file
        fs.remove( '.variable-domain-autocorrect.json' );
      }))
      .pipe(sassert.end(done));
  });

  xit('3) missing_domain', function(done) {
    


  });

  xit('4) missing_domain_ignore_missing', function(done) {

   
  });
  
  xit('5) correct_domain', function(done) {

   
  });
  
  xit('6) plurals', function(done) {
{'fraction_non_alphanumeric': 0.1642624476500698, 'fraction_numerical': 0.015666201333953775, 'mean_word_length': 3.0578980490874765, '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': '597939', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2225, 'n_words': 391}