<commit_before>'use strict';

const erector = require('erector-set');
const path = require('path');
const sinon = require('sinon');
const tap = require('tap');

const directive = require('../commands/directive');
const logging = require('../tools/logging');
const utilities = require('../tools/utilities');

const caseConvert = utilities.caseConvert;
const files = utilities.files;
const opts = utilities.options;
const sandbox = sinon.sandbox.create();

const make = function() {
    return directive.apply(directive, ['./'].concat(Array.from(arguments)));
};

let checkForExamples;
let construct;
let creator;
let dashToCap;
let getTemplates;
let filesSelectorPrefix;
let inquire;
let log;
let logger;
let parseOptions;
let rooter;
let testDashFormat;

tap.test('command: directive', (suite) => {
    suite.beforeEach((done) => {
        erector.construct.setTestMode(true);

        checkForExamples = sandbox.stub(opts, 'checkIsForExamples');
        construct = sandbox.stub(erector, 'construct');
        creator = sandbox.stub(files.resolver, 'create');
        filesSelectorPrefix = sandbox.stub(files, 'selectorPrefix');
        getTemplates = sandbox.stub(files, 'getTemplates');
        inquire = sandbox.stub(erector, 'inquire');
        logger = sandbox.stub(logging, 'create');
        log = sandbox.spy();
        parseOptions = sandbox.stub(opts, 'parseOptions');
        rooter = sandbox.stub(files.resolver, 'root');

        creator.callsFake(function() {
            const createPath = Array.from(arguments).join('/');
            return function() {
                return `/created/${ createPath }/` + Array.from(arguments).join('/');
            };
        });
        getTemplates.returns('fake-templates');
        inquire.rejects();
        logger.returns({
            info: log,
            log: log,
            error: log,
            warning: log
        });
        parseOptions.returns({});
        rooter.callsFake(function() {
            return '/root/' + Array.from(arguments).join('/');
        });

        done();
    });

    suite.afterEach((done) => {
        sandbox.restore();
        done();
    });

    suite.test('should create a Directive logger', (test) => {
        test.plan(1);

        make().catch(() => {
            test.ok(logger.calledWith('Directive'));
            test.end();
        });
    });

    suite.test('should parse options from arguments to check for examples', (test) => {
        const options = { pizza: [], p: [], i: [], steak: ['sauce'] };
        test.plan(2);

        parseOptions.resetBehavior();
        parseOptions.returns(options);

        make('--pizza', '--steak', '-pie').catch(() => {
            test.ok(parseOptions.calledWith(
                ['--pizza', '--steak', '-pie'],
                ['example', 'examples', 'x']
            ));
            test.ok(checkForExamples.calledWith(options));
            test.end();
        });
    });

    suite.test('should ask no questions if a dash-case directive name is provided', (test) => {
        const answers = [
            { answer: 'bacon-blast', name: 'directiveName' },
            { answer: 'PascalCaseDirective', name: 'className' },
            { answer: 'camelCase', name: 'selector' }
        ];
        const checkDashFormat = sandbox.stub(caseConvert, 'checkIsDashFormat');
        const dashToCamel = sandbox.stub(caseConvert, 'dashToCamel');
        const dashToCap = sandbox.stub(caseConvert, 'dashToCap');

        checkForExamples.returns(false);
        dashToCamel.returns('camelCase');
        dashToCap.returns('PascalCase');
        checkDashFormat.returns(true);
<commit_msg>Make sure the directive prefix is tested<commit_after>'use strict';

const erector = require('erector-set');
const path = require('path');
const sinon = require('sinon');
const tap = require('tap');

const directive = require('../commands/directive');
const logging = require('../tools/logging');
const utilities = require('../tools/utilities');

const caseConvert = utilities.caseConvert;
const files = utilities.files;
const opts = utilities.options;
const sandbox = sinon.sandbox.create();

const make = function() {
    return directive.apply(directive, ['./'].concat(Array.from(arguments)));
};

let checkForExamples;
let construct;
let creator;
let getTemplates;
let inquire;
let log;
let logger;
let parseOptions;
let rooter;

tap.test('command: directive', (suite) => {
    suite.beforeEach((done) => {
        erector.construct.setTestMode(true);

        checkForExamples = sandbox.stub(opts, 'checkIsForExamples');
        construct = sandbox.stub(erector, 'construct');
        creator = sandbox.stub(files.resolver, 'create');
        getTemplates = sandbox.stub(files, 'getTemplates');
        inquire = sandbox.stub(erector, 'inquire');
        logger = sandbox.stub(logging, 'create');
        log = sandbox.spy();
        parseOptions = sandbox.stub(opts, 'parseOptions');
        rooter = sandbox.stub(files.resolver, 'root');

        creator.callsFake(function() {
            const createPath = Array.from(arguments).join('/');
            return function() {
                return `/created/${ createPath }/` + Array.from(arguments).join('/');
            };
        });
        getTemplates.returns('fake-templates');
        inquire.rejects();
        logger.returns({
            info: log,
            log: log,
            error: log,
            warning: log
        });
        parseOptions.returns({});
        rooter.callsFake(function() {
            return '/root/' + Array.from(arguments).join('/');
        });

        done();
    });

    suite.afterEach((done) => {
        sandbox.restore();
        done();
    });

    suite.test('should create a Directive logger', (test) => {
        test.plan(1);

        make().catch(() => {
            test.ok(logger.calledWith('Directive'));
            test.end();
        });
    });

    suite.test('should parse options from arguments to check for examples', (test) => {
        const options = { pizza: [], p: [], i: [], steak: ['sauce'] };
        test.plan(2);

        parseOptions.resetBehavior();
        parseOptions.returns(options);

        make('--pizza', '--steak', '-pie').catch(() => {
            test.ok(parseOptions.calledWith(
                ['--pizza', '--steak', '-pie'],
                ['example', 'examples', 'x']
            ));
            test.ok(checkForExamples.calledWith(options));
            test.end();
        });
    });

    suite.test('should ask no questions if a dash-case directive name is provided', (test) => {
        const answers = [
            { answer: 'bacon-blast', name: 'directiveName' },
            { answer: 'PascalCaseDirective', name: 'className' },
            { answer: 'camelCase', name: 'selector' }
        ];
        const checkDashFormat = sandbox.stub(caseConvert, 'checkIsDashFormat');
        const dashToCamel = sandbox.stub(caseConvert, 'dashToCamel');
        const dashToCap = sandbox.stub(caseConvert, 'dashToCap');

        checkForExamples.returns(false);
        dashToCamel.returns('camelCase');
        dashToCap.returns('PascalCase');
        checkDashFormat.returns(true);

        test.plan(2);
        make('bacon-blast').then(() => {
            test.notOk(inquire.called);
            test.ok(construct.calledWith(
                answers,
                'fake-templates'
            ));
            test.end();
        });
    });

    suite.test('should prefix the `selector` answer if one has been set', (test) => {
        const answers = [
            { answer: 'bacon-blast', name: 'directiveName' },
            { answer: 'PascalCaseDirective', name: 'className' },
            { answer: 'myPascalSelector', name: 'selector' }
        ];
        const checkDashFormat = sandbox.stub(caseConvert, 'checkIsDashFormat');
        const dashToCap = sandbox.stub(caseConvert, 'dashToCap');
        const dashToPascal = sandbox.stub(caseConvert, 'dashToPascal');

        sandbox.stub(files, 'getSelectorPrefix').returns('my');

        checkForExamples.returns(false);
        dashToCap.returns('PascalCase');
        dashToPascal.returns('PascalSelector');
        checkDashFormat.returns(true);

{'fraction_non_alphanumeric': 0.15696541646371165, 'fraction_numerical': 0.0006088650754992694, 'mean_word_length': 2.484514212982605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2189657', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2330, 'n_words': 473}