<commit_before>
var assert = require('assert');
var vows = require('vows');

var EventEmitter = require('../src/eventful.js').EventEmitter;

vows.describe('Basics').addBatch({

  'An event emitter' : {
    topic : function() {
      return new EventEmitter();
    },

    'should respond to on, off, emit, withNamespace, withoutNamespace' : function(topic) {
      assert.isFunction(topic.on);
      assert.isFunction(topic.off);
      assert.isFunction(topic.emit);
      assert.isFunction(topic.withNamespace);
      assert.isFunction(topic.withoutNamespace);
    },

    'when called' : {
      topic : function(ee) {
        var chainOne = ee.on('foo', function() {});
        var chainTwo = chainOne.off('foo');
        var chainThree = chainTwo.emit('foo');
        var chainFour = chainThree.withoutNamespace();
        // withNamespace is not tested as it returns a wrapper
        return {
          original: ee,
          chain: [ chainOne, chainTwo, chainThree, chainFour ]
        };
      },

      'should return itself' : function(topic) {
        for (var i in topic.chain) {
          assert.strictEqual(topic.original, topic.chain[i]);
        }
      }
    }
  },

  'An event emitter with a callback on foo' : {
    topic : function() {
      new EventEmitter().on('foo', this.callback).emit('foo');
    },

    'should call it back when emitting foo' : function() {}
  },

  'An event emitter with a callback on bar' : {
    topic : function() {
      var called = false;
      new EventEmitter().on('bar', function() {
        called = true;
      }).emit('foo');
      return called;
    },

    'should not call it back when emitting foo' : function(topic) {
      assert.isFalse(topic);
    }
  },

  'An event emitter which emits foo with arguments' : {
    topic : function() {
      new EventEmitter().on('foo', this.callback).emit('foo', 'b', 'a', 'r');
    },

    'should pass those arguments to foo callbacks' : function(arg1, arg2, arg3) {
      assert.equal(arg1, 'b');
      assert.equal(arg2, 'a');
      assert.equal(arg3, 'r');
    }
  },

  'An event emitter with several callbacks on foo' : {
    topic : function() {
<commit_msg>Improved basic callback spec.<commit_after>
var assert = require('assert');
var vows = require('vows');

var EventEmitter = require('../src/eventful.js').EventEmitter;

vows.describe('Basics').addBatch({

  'An event emitter' : {
    topic : function() {
      return new EventEmitter();
    },

    'should respond to on, off, emit, withNamespace, withoutNamespace' : function(topic) {
      assert.isFunction(topic.on);
      assert.isFunction(topic.off);
      assert.isFunction(topic.emit);
      assert.isFunction(topic.withNamespace);
      assert.isFunction(topic.withoutNamespace);
    },

    'when called' : {
      topic : function(ee) {
        var chainOne = ee.on('foo', function() {});
        var chainTwo = chainOne.off('foo');
        var chainThree = chainTwo.emit('foo');
        var chainFour = chainThree.withoutNamespace();
        // withNamespace is not tested as it returns a wrapper
        return {
          original: ee,
          chain: [ chainOne, chainTwo, chainThree, chainFour ]
        };
      },

      'should return itself' : function(topic) {
        for (var i in topic.chain) {
          assert.strictEqual(topic.original, topic.chain[i]);
        }
      }
    }
  },

  'An event emitter with a callback on foo' : {
    topic : function() {
      
      var called = false;

      new EventEmitter().on('foo', function() {
        called = true;
      }).emit('foo');

      return called;
    },

    'should call it back when emitting foo' : function(topic) {
      assert.isTrue(topic);
    }
  },

  'An event emitter with a callback on bar' : {
    topic : function() {

      var called = false;

      new EventEmitter().on('bar', function() {
        called = true;
      }).emit('foo');

      return called;
    },

    'should not call it back when emitting foo' : function(topic) {
      assert.isFalse(topic);
    }
  },

  'An event emitter which emits foo with arguments' : {
    topic : function() {
      new EventEmitter().on('foo', this.callback).emit('foo', 'b', 'a', 'r');
    },

    'should pass those arguments to foo callbacks' : function(arg1, arg2, arg3) {
      assert.equal(arg1, 'b');
      assert.equal(arg2, 'a');
      assert.equal(arg3, 'r');
    }
  },

  'An event emitter with several callbacks on foo' : {
    topic : function() {

{'fraction_non_alphanumeric': 0.14425863991081384, 'fraction_numerical': 0.0026755852842809363, 'mean_word_length': 2.482919254658385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3774760', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1338, 'n_words': 356}