/*global describe, it*/
"use strict";

var fs = require("fs"),
  es = require("event-stream"),
  should = require("should");

require("mocha");

delete require.cache[require.resolve("../")];

var gutil = require("gulp-util"),
  yuidoc = require("../");

describe("gulp-yuidoc", function () {

  var expectedFile = new gutil.File({
    path: "test/expected/hello.txt",
    cwd: "test/",
    base: "test/expected",
    contents: fs.readFileSync("test/expected/hello.txt")
  });

  it("should produce expected file via buffer", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.readFileSync("test/fixtures/hello.txt")
    });

    var stream = yuidoc.parser();

    stream.on("error", function(err) {
      should.exist(err);
      done(err);
    });

    stream.on("data", function (newFile) {

      should.exist(newFile);
      should.exist(newFile.contents);

      String(newFile.contents).should.equal(String(expectedFile.contents));
      done();
    });

    stream.write(srcFile);
    stream.end();
  });

  it("should error on stream", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.createReadStream("test/fixtures/hello.txt")
    });

    var stream = yuidoc.runner();

    stream.on("error", function(err) {
      should.exist(err);
      done();
    });

    stream.on("data", function (newFile) {
      newFile.contents.pipe(es.wait(function(err, data) {
        done(err);
      }));
    });

    stream.write(srcFile);
    stream.end();
  });

  /*
  it("should produce expected file via stream", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.createReadStream("test/fixtures/hello.txt")
    });

    var stream = yuidoc("World");

    stream.on("error", function(err) {
      should.exist(err);
      done();
    });

    stream.on("data", function (newFile) {

      should.exist(newFile);
      should.exist(newFile.contents);

      newFile.contents.pipe(es.wait(function(err, data) {
        should.not.exist(err);
        data.should.equal(String(expectedFile.contents));
        done();
      }));
    });

    stream.write(srcFile);
    stream.end();
  });
  */
});

/*global describe, it*/
"use strict";

var fs = require("fs"),
  es = require("event-stream"),
  should = require("should");

require("mocha");

delete require.cache[require.resolve("../")];

var gutil = require("gulp-util"),
  yuidoc = require("../");

describe("gulp-yuidoc", function () {

  var expectedFile = new gutil.File({
    path: "test/expected/hello.txt",
    cwd: "test/",
    base: "test/expected",
    contents: fs.readFileSync("test/expected/hello.txt")
  });

  it("should produce expected file via buffer", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.readFileSync("test/fixtures/hello.txt")
    });

    var stream = yuidoc.parser();

    stream.on("error", function(err) {
      should.exist(err);
      done(err);
    });

    stream.on("data", function (newFile) {

      should.exist(newFile);
      should.exist(newFile.contents);

      String(newFile.contents).should.equal(String(expectedFile.contents));
      done();
    });

    stream.write(srcFile);
    stream.end();
  });

  it("should error on stream", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.createReadStream("test/fixtures/hello.txt")
    });

    var stream = yuidoc();

    stream.on("error", function(err) {
      should.exist(err);
      done();
    });

    stream.on("data", function (newFile) {
      newFile.contents.pipe(es.wait(function(err, data) {
        done(err);
      }));
    });

    stream.write(srcFile);
    stream.end();
  });

  /*
  it("should produce expected file via stream", function (done) {

    var srcFile = new gutil.File({
      path: "test/fixtures/hello.txt",
      cwd: "test/",
      base: "test/fixtures",
      contents: fs.createReadStream("test/fixtures/hello.txt")
    });

    var stream = yuidoc("World");

    stream.on("error", function(err) {
      should.exist(err);
      done();
    });

    stream.on("data", function (newFile) {

      should.exist(newFile);
      should.exist(newFile.contents);

      newFile.contents.pipe(es.wait(function(err, data) {
        should.not.exist(err);
        data.should.equal(String(expectedFile.contents));
        done();
      }));
    });

    stream.write(srcFile);
    stream.end();
  });
  */
});

Update test for new signature