<commit_before>'use strict';

var test = require('tape');
var enUS = require('dictionary-en-us');
var enGB = require('dictionary-en-gb');
var retext = require('retext');
var spell = require('./');

test('should throw when without `options`', function (t) {
  t.throws(
    function () {
      retext().use(spell).freeze();
    },
    /^Error: Expected `Object`, got `undefined`$/,
    'should throw'
  );

  t.end();
});

test('should fail load errors on the VFile', function (t) {
  var processor = retext().use(spell, failingLoader);

  t.plan(3);

  processor.process('', function (err) {
    var failed;

    t.equal(err.message, 'load error');

    /* Coverage: future files can fail immediatly. */
    processor.process('', function (err) {
      t.equal(err.message, 'load error');
      failed = true;
    });

    t.equal(failed, true);
  });

  /* Fixture for a loader which fails. */
  function failingLoader(callback) {
    setImmediate(function () {
      callback(new Error('load error'));
    });
  }
});

test('should warn for misspelt words', function (t) {
  t.plan(3);

  retext().use(spell, enGB).process('color', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:6: `color` is misspelt; did you mean `colon`, `colour`?'
    ]);
  });

  retext().use(spell, enUS).process('colour and utilise', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:7: `colour` is misspelt; did you mean `color`?',
      '1:12-1:19: `utilise` is misspelt; did you mean `utilize`?'
    ]);
  });

  retext().use(spell, enUS).process('colour and colour and colour', function (_, file) {
    t.deepEqual(
      file.messages.map(String),
      [
        '1:1-1:7: `colour` is misspelt; did you mean `color`?',
        '1:12-1:18: `colour` is misspelt; did you mean `color`?',
        '1:23-1:29: `colour` is misspelt; did you mean `color`?'
      ]
    );
  });
});

test('should warn for invalid words (coverage)', function (t) {
  var english = retext().use(spell, enGB);

  t.plan(2);

  english.process('color', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:6: `color` is misspelt; did you mean `colon`, `colour`?'
    ]);

    /* Coverage: future files can start faster. */
    english.process('colour', function (_, file) {
      t.deepEqual(file.messages.map(String), []);
    });
  });
});

test('should support `max`, for maximum suggestions', function (t) {
  t.plan(1);

  retext()
    .use(spell, {dictionary: enGB, max: 1})
    .process('Some useles mispelt documeant', function (_, file) {
      t.deepEqual(
        file.messages.map(String),
        [
          '1:6-1:12: `useles` is misspelt',
          '1:13-1:20: Too many misspellings; no further spell suggestions are given',
          '1:13-1:20: `mispelt` is misspelt',
          '1:21-1:30: `documeant` is misspelt'
        ]
      );
    });
});

test('should ignore literal words', function (t) {
  t.plan(1);

  retext().use(spell, enGB).process('“color”', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});

test('...unless `ignoreLiteral` is false', function (t) {
  t.plan(1);

  retext()
    .use(spell, {dictionary: enGB, ignoreLiteral: false})
    .process('“color”', function (_, file) {
      t.deepEqual(
        file.messages.map(String),
        ['1:2-1:7: `color` is misspelt; did you mean `colon`, `colour`?']
      );
    });
});

test('should warn for misspelt hyphenated words', function (t) {
  t.plan(1);

  retext()
    .use(spell, {dictionary: enGB, ignoreDigits: false})
    .process('wrongely-spelled-word', function (_, file) {
      t.deepEqual(file.messages.map(String), [
        '1:1-1:22: `wrongely-spelled-word` is misspelt'
      ]);
    });
});

test('should not warn for correctly spelled hyphenated words', function (t) {
  t.plan(1);

  retext().use(spell, enGB).process('random-hyphenated-word', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});

test('should not warn for ignored words in hyphenated words', function (t) {
  t.plan(1);

  retext().use(spell, {
    dictionary: enGB,
    ignore: ['wrongely']
  }).process('wrongely-spelled-word', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});<commit_msg>Remove useless setting from tests<commit_after>'use strict';

var test = require('tape');
var enUS = require('dictionary-en-us');
var enGB = require('dictionary-en-gb');
var retext = require('retext');
var spell = require('./');

test('should throw when without `options`', function (t) {
  t.throws(
    function () {
      retext().use(spell).freeze();
    },
    /^Error: Expected `Object`, got `undefined`$/,
    'should throw'
  );

  t.end();
});

test('should fail load errors on the VFile', function (t) {
  var processor = retext().use(spell, failingLoader);

  t.plan(3);

  processor.process('', function (err) {
    var failed;

    t.equal(err.message, 'load error');

    /* Coverage: future files can fail immediatly. */
    processor.process('', function (err) {
      t.equal(err.message, 'load error');
      failed = true;
    });

    t.equal(failed, true);
  });

  /* Fixture for a loader which fails. */
  function failingLoader(callback) {
    setImmediate(function () {
      callback(new Error('load error'));
    });
  }
});

test('should warn for misspelt words', function (t) {
  t.plan(3);

  retext().use(spell, enGB).process('color', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:6: `color` is misspelt; did you mean `colon`, `colour`?'
    ]);
  });

  retext().use(spell, enUS).process('colour and utilise', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:7: `colour` is misspelt; did you mean `color`?',
      '1:12-1:19: `utilise` is misspelt; did you mean `utilize`?'
    ]);
  });

  retext().use(spell, enUS).process('colour and colour and colour', function (_, file) {
    t.deepEqual(
      file.messages.map(String),
      [
        '1:1-1:7: `colour` is misspelt; did you mean `color`?',
        '1:12-1:18: `colour` is misspelt; did you mean `color`?',
        '1:23-1:29: `colour` is misspelt; did you mean `color`?'
      ]
    );
  });
});

test('should warn for invalid words (coverage)', function (t) {
  var english = retext().use(spell, enGB);

  t.plan(2);

  english.process('color', function (_, file) {
    t.deepEqual(file.messages.map(String), [
      '1:1-1:6: `color` is misspelt; did you mean `colon`, `colour`?'
    ]);

    /* Coverage: future files can start faster. */
    english.process('colour', function (_, file) {
      t.deepEqual(file.messages.map(String), []);
    });
  });
});

test('should support `max`, for maximum suggestions', function (t) {
  t.plan(1);

  retext()
    .use(spell, {dictionary: enGB, max: 1})
    .process('Some useles mispelt documeant', function (_, file) {
      t.deepEqual(
        file.messages.map(String),
        [
          '1:6-1:12: `useles` is misspelt',
          '1:13-1:20: Too many misspellings; no further spell suggestions are given',
          '1:13-1:20: `mispelt` is misspelt',
          '1:21-1:30: `documeant` is misspelt'
        ]
      );
    });
});

test('should ignore literal words', function (t) {
  t.plan(1);

  retext().use(spell, enGB).process('“color”', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});

test('...unless `ignoreLiteral` is false', function (t) {
  t.plan(1);

  retext()
    .use(spell, {dictionary: enGB, ignoreLiteral: false})
    .process('“color”', function (_, file) {
      t.deepEqual(
        file.messages.map(String),
        ['1:2-1:7: `color` is misspelt; did you mean `colon`, `colour`?']
      );
    });
});

test('should warn for misspelt hyphenated words', function (t) {
  t.plan(1);

  retext()
    .use(spell, enGB)
    .process('wrongely-spelled-word', function (_, file) {
      t.deepEqual(file.messages.map(String), [
        '1:1-1:22: `wrongely-spelled-word` is misspelt'
      ]);
    });
});

test('should not warn for correctly spelled hyphenated words', function (t) {
  t.plan(1);

  retext().use(spell, enGB).process('random-hyphenated-word', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});

test('should not warn for ignored words in hyphenated words', function (t) {
  t.plan(1);

  retext().use(spell, {
    dictionary: enGB,
    ignore: ['wrongely']
  }).process('wrongely-spelled-word', function (_, file) {
    t.deepEqual(file.messages.map(String), []);
  });
});
{'fraction_non_alphanumeric': 0.18959281297398203, 'fraction_numerical': 0.01773422004433555, 'mean_word_length': 3.1531007751937983, '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': '4371218', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2987, 'n_words': 689}