'use strict';

var should = require('should');
var path = require('path');
var fs = require('fs');
var rewire = require('rewire');
var pngdefry = rewire('../lib/index');
var Magic = require('mmmagic').Magic;
var magic = new Magic();

describe('Index', function() {

  describe('#pngdefry()', function() {
    it('should repair png success', function(done) {
      this.timeout(115000);
      var input = path.join(__dirname, 'img', 'icon.png');
      var output = path.join(__dirname, 'img', 'icon-new.png');

      pngdefry(input, output, function(err) {
        if (err) {
          return;
        }

        magic.detectFile(output, function(err, result) {
          if (err) {
            throw err;
          }

          // result=>PNG image data, 60 x 60, 8-bit/color RGBA, non-interlaced
          result.should.match(/non-interlaced/);
          fs.unlinkSync(output);
          setTimeout(done, 110000);
        });
      });
    });
  });

  describe('#getOutputDir()', function() {
    it('should return a path that not contain the file name', function() {
      var output = path.join('Users', 'forsigner', 'repos', 'icon-new.png');
      var ouputDir = pngdefry.__get__('getOutputDir')(output);
      ouputDir.should.equal(path.join('Users', 'forsigner', 'repos'));
    });
  });

  describe('#getOutputFilePath()', function() {
    it('should return a path that not contain the file name', function() {
      var input = path.join('Users', 'forsigner', 'repos', 'icon.png');
      var outputDir = path.join('Users', 'forsigner', 'repos');
      var suffix = '-new';
      var outputFilePath = pngdefry.__get__('getOutputFilePath')(input, outputDir, suffix);
      outputFilePath.should.equal(path.join('Users', 'forsigner', 'repos', 'icon-new.png'));
    });
  });
});

@@ -293,32 +293,35 @@
 function() %7B%0A   
+ //
  it('should repa
@@ -358,17 +358,69 @@
 ) %7B%0A    
- 
+it('should repair png success', function() %7B%0A      //
  this.ti
@@ -435,24 +435,27 @@
 5000);%0A     
+ //
  var input =
@@ -493,32 +493,35 @@
 con.png');%0A     
+ //
  var output = pa
@@ -569,16 +569,19 @@
 ;%0A%0A     
+ //
  pngdefr
@@ -614,24 +614,27 @@
 err) %7B%0A     
+ //
    if (err) 
@@ -636,24 +636,27 @@
 err) %7B%0A     
+ //
      return;
@@ -661,27 +661,41 @@
 n;%0A     
+ //
    %7D%0A
+      //
 %0A     
+ //
    magic
@@ -739,24 +739,27 @@
 ult) %7B%0A     
+ //
      if (err
@@ -763,24 +763,27 @@
 err) %7B%0A     
+ //
        throw
@@ -797,21 +797,35 @@
     
+ //
      %7D%0A
+      //
 %0A     
+ //
     
@@ -895,24 +895,27 @@
 rlaced%0A     
+ //
      result.
@@ -947,24 +947,27 @@
 ced/);%0A     
+ //
      fs.unli
@@ -988,20 +988,23 @@
 ;%0A      
+//
     
+ 
 setTimeo
@@ -1026,16 +1026,19 @@
 );%0A     
+ //
    %7D);%0A 
@@ -1041,16 +1041,19 @@
 );%0A     
+ //
  %7D);%0A   

comment test code temporary