<commit_before>/**
 * Collection of test assertions helpers
 *
 * It mixes in the native node.js `assert` module. So you can just use this module as a
 * drop-in replacement.
 *
 * @mixes nodejs/assert
 * @example
 *   var assert = require('yeoman-assert');
 */
'use strict';

var fs = require('fs');
var _ = require('lodash');

function extractMethods(methods) {
  return _.isArray(methods) ? methods : Object.keys(methods).filter(function (method) {
    return _.isFunction(methods[method]);
  });
}

// Extend the native assert module
var assert = module.exports = require('assert');

/**
 * Assert that a file exists
 * @param  {String}       path     - path to a file
 * @example
 * assert.file('templates/user.hbs');
 *
 * @also
 *
 * Assert that each files in the array exists
 * @param {Array}         paths    - an array of paths to files
 * @example
 * assert.file(['templates/user.hbs', 'templates/user/edit.hbs']);
 */

assert.file = function () {
  var args = _.toArray(arguments);
  args = _.isString(args[0]) ? args : args[0];

  args.forEach(function (file) {
    var here = fs.existsSync(file);
    assert.ok(here, file + ', no such file or directory');
  });
};

/**
 * Assert that a file doesn't exist
 * @param  {String}       file     - path to a file
 * @example
 * assert.noFile('templates/user.hbs');
 *
 * @also
 *
 * Assert that each of an array of files doesn't exist
 * @param {Array}         pairs    - an array of paths to files
 * @example
 * assert.noFile(['templates/user.hbs', 'templates/user/edit.hbs']);
 */

assert.noFile = function () {
  var args = _.toArray(arguments);
  args = _.isString(args[0]) ? args : args[0];

  args.forEach(function (file) {
    var here = fs.existsSync(file);
    assert.ok(!here, file + ' exists');
  });
};

/**
 * Assert that a file's content matches a regex or string
 * @param  {String}       file     - path to a file
 * @param  {Regex|String} reg      - regex / string that will be used to search the file
 * @example
 * assert.fileContent('models/user.js', /App\.User = DS\.Model\.extend/);
 * assert.fileContent('models/user.js', 'App.User = DS.Model.extend');
 *
 * @also
 *
 * Assert that each file in an array of file-regex pairs matches its corresponding regex
 * @param {Array}         pairs    - an array of arrays, where each subarray is a [String, RegExp] pair
 * @example
 * var arg = [
 *   [ 'models/user.js', /App\.User = DS\.Model\.extend/ ],
 *   [ 'controllers/user.js', /App\.UserController = Ember\.ObjectController\.extend/ ]
 * ]
 * assert.fileContent(arg);
 */<commit_msg>Use `path-exists` as `fs.exists` is being deprecated<commit_after>/**
 * Collection of test assertions helpers
 *
 * It mixes in the native node.js `assert` module. So you can just use this module as a
 * drop-in replacement.
 *
 * @mixes nodejs/assert
 * @example
 *   var assert = require('yeoman-assert');
 */
'use strict';

var fs = require('fs');
var _ = require('lodash');
var pathExists = require('path-exists');

function extractMethods(methods) {
  return _.isArray(methods) ? methods : Object.keys(methods).filter(function (method) {
    return _.isFunction(methods[method]);
  });
}

// Extend the native assert module
var assert = module.exports = require('assert');

/**
 * Assert that a file exists
 * @param  {String}       path     - path to a file
 * @example
 * assert.file('templates/user.hbs');
 *
 * @also
 *
 * Assert that each files in the array exists
 * @param {Array}         paths    - an array of paths to files
 * @example
 * assert.file(['templates/user.hbs', 'templates/user/edit.hbs']);
 */

assert.file = function () {
  var args = _.toArray(arguments);
  args = _.isString(args[0]) ? args : args[0];

  args.forEach(function (file) {
    var here = pathExists.sync(file);
    assert.ok(here, file + ', no such file or directory');
  });
};

/**
 * Assert that a file doesn't exist
 * @param  {String}       file     - path to a file
 * @example
 * assert.noFile('templates/user.hbs');
 *
 * @also
 *
 * Assert that each of an array of files doesn't exist
 * @param {Array}         pairs    - an array of paths to files
 * @example
 * assert.noFile(['templates/user.hbs', 'templates/user/edit.hbs']);
 */

assert.noFile = function () {
  var args = _.toArray(arguments);
  args = _.isString(args[0]) ? args : args[0];

  args.forEach(function (file) {
    var here = pathExists.sync(file);
    assert.ok(!here, file + ' exists');
  });
};

/**
 * Assert that a file's content matches a regex or string
 * @param  {String}       file     - path to a file
 * @param  {Regex|String} reg      - regex / string that will be used to search the file
 * @example
 * assert.fileContent('models/user.js', /App\.User = DS\.Model\.extend/);
 * assert.fileContent('models/user.js', 'App.User = DS.Model.extend');
 *
 * @also
 *
 * Assert that each file in an array of file-regex pairs matches its corresponding regex
 * @param {Array}         pairs    - an array of arrays, where each subarray is a [String, RegExp] pair
 * @example
 * var arg = [
 *   [ 'models/user.js', /App\.User = DS\.Model\.extend/ ],
 *   [ 'controllers/user.js', /App\.UserController = Ember\.ObjectController\.extend/ ]
 * ]
 * assert.fileContent(arg);
 */
{'fraction_non_alphanumeric': 0.15383141762452107, 'fraction_numerical': 0.0015325670498084292, 'mean_word_length': 3.0852895148669797, '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': '3445255', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1625, 'n_words': 497}