var expect = require('chai').expect;
var clierr = require('../..'),
  define = clierr.define,
  definition = clierr.ErrorDefinition,
  config = clierr.config;

describe('cli-error:', function() {
  beforeEach(function(done) {
    clierr.clear();
    done();
  });
  afterEach(function(done) {
    clierr.clear();
    done();
  });
  it('should define errors', function(done) {
    var errors = clierr.errors;
    var key = 'EARGLENGTH';
    var message = 'too few arguments';
    var def = define(key, message);
    expect(def).to.be.an.instanceof(definition);
    var keys = Object.keys(errors);
    expect(keys.length).to.be.a('number').that.equals(1);
    expect(def.key).to.be.a('string').that.equals(key);
    expect(def.message).to.be.a('string').that.equals(message);
    expect(errors[key]).to.be.an.instanceof(definition).that.equals(def);
    expect(def.code).to.be.a('number').that.equals(config.start);
    done();
  });
  it('should define error with specific code (no parameters)', function(done) {
    var errors = clierr.errors;
    var key = 'EARGLENGTH';
    var message = 'too few arguments';
    var def = define(key, message, 256);
    expect(def.key).to.be.a('string').that.equals(key);
    expect(def.message).to.be.a('string').that.equals(message);
    expect(def.code).to.be.a('number').that.equals(256);
    done();
  });
  it('should define error with parameters and code', function(done) {
    var errors = clierr.errors;
    var key = 'EARGLENGTH';
    var message = 'too few arguments, got %s';
    var params = ['-xvf'];
    var def = define(key, message, params, 256);
    expect(def.key).to.be.a('string').that.equals(key);
    expect(def.message).to.be.a('string').that.equals(message);
    expect(def.parameters).to.eql(params);
    expect(def.code).to.be.a('number').that.equals(256);
    done();
  });
  it('should define with default start (invalid start)', function(done) {
    var config = {
      start: false
    }
    clierr(config);
    var key = 'EARGLENGTH';
    var message = 'too few arguments, got %s';
    var params = ['-xvf'];
    var def = define(key, message, params, 256);
    // reset so other tests do not break
    clierr({start: 128, lang: 'en'});
    done();
  });
})

@@ -1138,25 +1138,25 @@
  message, 25
-6
+5
 );%0A    expec
@@ -1311,33 +1311,33 @@
 ).that.equals(25
-6
+5
 );%0A    done();%0A 
@@ -1586,25 +1586,25 @@
 , params, 25
-6
+5
 );%0A    expec
@@ -1810,17 +1810,17 @@
 quals(25
-6
+5
 );%0A    d
@@ -2121,9 +2121,9 @@
 , 25
-6
+5
 );%0A 
@@ -2218,11 +2218,325 @@
 ;%0A  %7D);%0A
+  it('should clamp error code to 255', function(done) %7B%0A    var errors = clierr.errors;%0A    var key = 'EARGLENGTH';%0A    var message = 'too few arguments, got %25s';%0A    var params = %5B'-xvf'%5D;%0A    var def = define(key, message, params, 256);%0A    expect(def.code).to.be.a('number').that.equals(255);%0A    done();%0A  %7D);%0A
 %7D)%0A

Update tests.