/*jslint node: true */
"use strict";

var H = require('../index').EventEmitter;
var _ = require('lodash');
var assert = require('assert');

describe('HevEmitter callback order', function () {

    it('should trigger .on/.once callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.on(['duras'], function () {
            reports.push('on');
        });
        h.once(['duras'], function () {
            reports.push('once');
        });
        h.emit(['duras']);
        assert.deepEqual(['on', 'once'], reports);
    });

    it('should trigger .once/.on callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.once(['duras'], function () {
            reports.push('once');
        });
        h.on(['duras'], function () {
            reports.push('on');
        });
        h.emit(['duras']);
        assert.deepEqual(['once', 'on'], reports);
    });

    it('should trigger .on/promise callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.on(['kales'], function () {
            reports.push('on');
        });
        h.on(['kales'], function () {
            reports.push('promise');
        });
        h.emit(['kales']);
        assert.deepEqual(['on', 'promise'], reports);
    });

    it('should trigger promise/.on callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.on(['kales'], function () {
            reports.push('promise');
        });
        h.on(['kales'], function () {
            reports.push('on');
        });
        h.emit(['kales']);
        assert.deepEqual(['promise', 'on'], reports);
    });


    it('should trigger .once/promise callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.once(['kitamer'], function () {
            reports.push('once');
        });
        h.on(['kitamer'], function () {
            reports.push('promise');
        });
        h.emit(['kitamer']);
        assert.deepEqual(['once', 'promise'], reports);
    });

    it('should trigger promise/.once callback in order of addition', function () {
        var h = new H();
        var reports = [];
        h.on(['kitamer'], function () {
            reports.push('promise');
        });
        h.once(['kitamer'], function () {
            reports.push('once');
        });
        h.emit(['kitamer']);
        assert.deepEqual(['promise', 'once'], reports);
    });
});

@@ -35,50 +35,8 @@
 %22;%0A%0A
-var H = require('../index').EventEmitter;%0A
 var 
@@ -95,478 +95,105 @@
 );%0A%0A
-describe('HevEmitter callback order', function () %7B%0A%0A    it('should trigger .on/.once callback in order of addition', function () %7B%0A        var h = new H();%0A        var reports = %5B%5D;%0A        h.on(%5B'duras'%5D, function () %7B%0A            reports.push('on');%0A        %7D);%0A        h.once(%5B'duras'%5D, function () %7B%0A            reports.push('once');%0A        %7D);%0A        h.emit(%5B'duras'%5D);%0A        assert.deepEqual(%5B'on', 'once'%5D, reports);%0A    %7D);%0A%0A    it('should trigger .once/.on
+var H = require('../index').EventEmitter;%0Avar routes = require('./routes');%0A%0Adescribe('HevEmitter
  cal
@@ -198,36 +198,21 @@
 allback 
-in 
 order
- of addition
 ', funct
@@ -216,32 +216,33 @@
 nction () %7B%0A    
+%0A
     var h = new 
@@ -238,911 +238,318 @@
 ar h
- = new H();%0A        var reports = %5B%5D;%0A        h.once(%5B'duras'%5D, function () %7B%0A            reports.push('once'
+;%0A    beforeEach(function () %7B%0A        h = new H(
 );%0A    
-    
 %7D);%0A
-  
+%0A
     
-  h.on(%5B'duras'%5D, function () %7B%0A            reports.push('on');%0A        %7D);%0A        h.emit(%5B'duras'%5D);%0A        assert.deepEqual(%5B'once', 'on'%5D, reports);%0A    %7D);%0A%0A    it('should trigger .on/promise callback in order of addition', function () %7B%0A        var h = new H();%0A        var reports = %5B%5D;%0A        h.on(%5B'kales'%5D, function () %7B%0A            reports.push('on');%0A        %7D);%0A        h.on(%5B'kales'%5D, function () %7B%0A            reports.push('promise');%0A        %7D);%0A        h.emit(%5B'kales'%5D);%0A        assert.deepEqual(%5B'on', 'promise'%5D, reports);%0A    %7D);%0A%0A    it('should trigger promise/.on callback in order of addition', function () %7B%0A        var h = new H();%0A        var reports = %5B%5D;%0A        h.on(%5B'kales'%5D, function () %7B%0A            reports.push('promise')
+var calledInOrderOfAddition = function (onRoute, emitRoute) %7B%0A        it('should trigger in order of adding to %22' + onRoute.join('/') + '%22 when emitting to %22' + emitRoute.join('/') + '%22', function () %7B%0A            var msg = %7B emitted: %5B%5D %7D
 ;%0A    
-    %7D);%0A
     
@@ -557,25 +557,23 @@
    h.on(
-%5B'kales'%5D
+onRoute
 , functi
@@ -568,32 +568,35 @@
 oute, function (
+msg
 ) %7B%0A            
@@ -599,27 +599,34 @@
     
-reports
+    msg.emitted
 .push('
-on');
+a') 
 %0A   
@@ -634,170 +634,40 @@
     
-%7D);%0A        h.emit(%5B'kales'%5D);%0A        assert.deepEqual(%5B'promise', 'on'%5D, reports);%0A    %7D);%0A%0A%0A    it('should trigger .once/promise callback in order of addition'
+    %7D);%0A            h.on(onRoute
 , fu
@@ -666,32 +666,35 @@
 oute, function (
+msg
 ) %7B%0A        var 
@@ -693,126 +693,38 @@
     
-var h = new H();%0A        var reports = %5B%5D;%0A        h.once(%5B'kitamer'%5D, function () %7B%0A            reports
+        msg.emitted
 .push('
-once');
+b') 
 %0A   
@@ -732,587 +732,232 @@
     
-%7D);%0A        h.on(%5B'kitamer'%5D, function () %7B%0A            reports.push('promise');%0A        %7D);%0A        h.emit(%5B'kitamer'%5D);%0A        assert.deepEqual(%5B'once', 'promise'%5D, reports);%0A    %7D);%0A%0A    it('should trigger promise/.once callback in order of addition', function () %7B%0A        var h = new H();%0A        var reports = %5B%5D;%0A        h.on(%5B'kitamer'%5D, function () %7B%0A            reports.push('promise');%0A        %7D);%0A        h.once(%5B'kitamer'%5D, function () %7B%0A            reports.push('once');%0A        %7D);%0A        h.emit(%5B'kitamer'%5D);%0A        assert.deepEqual(%5B'promise', 'once'%5D, report
+    %7D);%0A            assert(h.emit(emitRoute, msg));%0A            assert.deepEqual(%5B'a', 'b'%5D, msg.emitted);%0A        %7D);%0A    %7D;%0A%0A%0A    _.each(routes.matchRoutes, function (args) %7B%0A        calledInOrderOfAddition.apply(null, arg
 s);%0A
@@ -964,12 +964,13 @@
     %7D);%0A
+%0A
 %7D);%0A

Add same route ordering tests.