var assert = require('assert')
var fs = require('fs')
var path = require('path')
var rcedit = require('..')
var rcinfo = require('rcinfo')
var temp = require('temp').track()
var textgrep = require('textgrep')

var beforeEach = global.beforeEach
var describe = global.describe
var it = global.it

describe('rcedit(exePath, options, callback)', function () {
  this.timeout(60000)

  var exePath = null
  var tempPath = null

  beforeEach(function () {
    tempPath = temp.mkdirSync('node-rcedit-')
    exePath = path.join(tempPath, 'electron.exe')
    var fixturesExePath = path.join(__dirname, 'fixtures', 'electron.exe')
    fs.writeFileSync(exePath, fs.readFileSync(fixturesExePath))
  })

  it('updates the information in the executable', function (done) {
    var options = {
      'version-string': {
        CompanyName: 'Umbrella',
        FileDescription: 'Vanhouten',
        LegalCopyright: 'Maritime',
        ProductName: 'Millhouse'
      },
      'file-version': '3.4.5.6',
      'product-version': '4.5.6.7',
      icon: path.join(__dirname, 'fixtures', 'app.ico')
    }

    rcedit(exePath, options, function (error) {
      if (error != null) return done(error)

      rcinfo(exePath, function (error, info) {
        if (error != null) return done(error)

        assert.equal(info.CompanyName, 'Umbrella')
        assert.equal(info.FileDescription, 'Vanhouten')
        assert.equal(info.LegalCopyright, 'Maritime')
        assert.equal(info.ProductName, 'Millhouse')
        assert.equal(info.FileVersion, '3.4.5.6')
        assert.equal(info.ProductVersion, '4.5.6.7')

        done()
      })
    })
  })

  it('supports non-ASCII characters in the .exe path', function (done) {
    var unicodePath = path.join(path.dirname(exePath), 'äeiöü.exe')
    fs.renameSync(exePath, unicodePath)

    var options = {
      'version-string': {
        FileDescription: 'foo',
        ProductName: 'bar'
      },
      'file-version': '8.0.8'
    }

    rcedit(unicodePath, options, function (error) {
      if (error != null) return done(error)
      done()
    })
  })

  it('supports a product version of 1', function (done) {
    var options = {
      'product-version': '1'
    }

    rcedit(exePath, options, function (error) {
      if (error != null) return done(error)

      rcinfo(exePath, function (error, info) {
        if (error != null) return done(error)

        assert.equal(info.ProductVersion, '1.0.0.0')

        done()
      })
    })
  })

  it('supports a product version of 1.0', function (done) {
    var options = {
      'product-version': '1.0'
    }

    rcedit(exePath, options, function (error) {
      if (error != null) return done(error)

      rcinfo(exePath, function (error, info) {
        if (error != null) return done(error)

        assert.equal(info.ProductVersion, '1.0.0.0')

        done()
      })
    })
  })

  it('supports setting requestedExecutionLevel to requireAdministrator', function (done) {
    var options = {
      'requested-execution-level': 'requireAdministrator'
    }

    rcedit(exePath, options, function (error) {
      if (error != null) return done(error)

      // read in the exe as text
      var text = fs.readFileSync(exePath, 'utf8')
      var response = textgrep.grep(text, '(requireAdministrator)', '{1}', 'gm')

      assert.equal(response, 'requireAdministrator')

      done()
    })
  })

  it('reports an error when the .exe path does not exist', function (done) {
    rcedit(path.join(tempPath, 'does-not-exist.exe'), {'file-version': '3.4.5.6'}, function (error) {
      assert.ok(error instanceof Error)
      assert.notEqual(error.message.indexOf('rcedit.exe failed with exit code 1.'), -1)
      assert.notEqual(error.message.indexOf('Fatal error: Unable to load file'), -1)

      done()
    })
  })

  it('reports an error when the icon path does not exist', function (done) {
    rcedit(exePath, {icon: path.join(tempPath, 'does-not-exist.ico')}, function (error) {
      assert.ok(error instanceof Error)
      assert.notEqual(error.message.indexOf('Fatal error: Unable to set icon'), -1)

      done()
    })
  })
})

@@ -3032,32 +3032,290 @@
 strator'%0A    %7D%0A%0A
+%09// first read in the file and test that requireAdministrator is not present%0A    var text = fs.readFileSync(exePath, 'utf8')%0A    var response = textgrep.grep(text, '(requireAdministrator)', '%7B1%7D', 'gm')%0A    assert.notEqual(response, 'requireAdministrator')%0A%0A
     rcedit(exePa
@@ -3426,28 +3426,24 @@
  text%0A      
-var 
 text = fs.re
@@ -3472,28 +3472,24 @@
 tf8')%0A      
-var 
 response = t

Add negative test