<commit_before>import test from 'blue-tape';


import cloverfield from '../../lib/cloverfield';


test('Cloverfield CLI', (assert) => new Promise((resolve) => {
  assert.ok(cloverfield);

  resolve();
}));

<commit_msg>Tests for cloverfield CLI<commit_after>import test from 'blue-tape';
import {spy} from 'sinon';
import nomnom from 'nomnom';


import cloverfield from '../../lib/cloverfield';


const commands = [
  {
    command: 'build',
    options: {
      scaffold: {
        position: 1,
        choices: ['package']
      }
    },
    callback: spy(),
    help: 'Test command'
  }
];


const before = () => {
  const parser = nomnom();
  const printer = spy();

  parser.printer(printer);
  return {parser, printer};
};


const after = ({printer}) => {
  commands[0].callback.reset();
  printer.reset();
};


test('Cloverfield', assert => {
  assert.ok(cloverfield instanceof Function, 'should be function');
  assert.end();
});


test('Incorrect command', assert => {
  const {parser, printer} = before();

  cloverfield(parser)(commands);

  parser.parse(['unknownCommand']);
  assert.ok(printer.calledWithMatch('cf:'), 'should set script name to cf');
  assert.ok(printer.calledWithMatch('no such command'),
    'should show error if unknown command passed');

  after({printer});
  assert.end();
});


test('Wrong option provided', assert => {
  const {parser, printer} = before();


  cloverfield(parser)(commands);

  parser.parse(['build', 'test']);
  assert.ok(printer.calledWithMatch('scaffold must be one of'),
    'should show error for wrong option');

  after({printer});
  assert.end();
});


test('Correct option', assert => {
  const {parser, printer} = before();

  cloverfield(parser)(commands);

  parser.parse(['build', 'package']);
  assert.ok(commands[0].callback.calledOnce, 'should call provided callback');

  after({printer});
  assert.end();
});


{'fraction_non_alphanumeric': 0.17790759426447159, 'fraction_numerical': 0.0015932023366967605, 'mean_word_length': 4.037433155080214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7522778', 'n_tokens_mistral': 607, 'n_tokens_neox': 583, 'n_words': 144}