'use strict';

describe('The CLI called', function () {
    var run = require('../src/run.js');
    var args;

    this.timeout(10000);

    // chai
    require('chai').should();

    // std-mocks
    var stdMocks = require('std-mocks');

    function stdout() {
        return stdMocks.flush().stdout.join('');
    }

    // mock-stdin
    var stdin = require('mock-stdin').stdin();

    // resources
    var fs = require('fs');
    var gv = fs.readFileSync('test/resources/source.gv', 'utf8');
    var dotXdot = fs.readFileSync('test/resources/dot.xdot', 'utf8');
    var circoXdot = fs.readFileSync('test/resources/circo.xdot', 'utf8');
    var dotSvg = fs.readFileSync('test/resources/dot.svg', 'utf8');

    beforeEach(function () {
        args = {K: null, T: 'xdot', V: false, o: null, files: [], prog: 'dot'};

        stdMocks.use();
    });

    afterEach(function () {
        stdMocks.restore();
        stdMocks.flush();

        stdin.reset(true);
    });

    describe('without arguments', function () {
        it('should produce stdout xdot from stdin dot', function () {
            run(args);
            stdin.send(gv);
            stdin.end();
            stdout().should.equal(dotXdot);
        });
        it('should use the layout of the called executable', function () {
            args.prog = 'circo';
            run(args);
            stdin.send(gv);
            stdin.end();
            stdout().should.equal(circoXdot);
        });
    });

    describe('with -K', function () {
        it('should use the specified layout regardless of the called executable', function () {
            args.prog = 'fdp';
            args.K = 'circo';
            run(args);
            stdin.send(gv);
            stdin.end();
            stdout().should.equal(circoXdot);
        })
    });

    describe('with -V', function () {
        beforeEach(function () {
            args.V = true;
        });

        it('should print version information', function () {
            run(args);
            stdout().should.equal('dot - graphviz version 2.38.0 (20140413.2041)\n');
        });
        it('should print the called executable name', function () {
            args.prog = 'circo';
            run(args);
            stdout().should.equal('circo - graphviz version 2.38.0 (20140413.2041)\n');
        });
    });
});

@@ -1794,32 +1794,302 @@
     %7D)%0A    %7D);%0A%0A
+    describe('with -T', function () %7B%0A        it('should produce the specified format', function () %7B%0A            args.T = 'svg';%0A            run(args);%0A            stdin.send(gv);%0A            stdin.end();%0A            stdout().should.equal(dotSvg);%0A        %7D);%0A    %7D);%0A%0A
     describe('wi

add -T test