<commit_before>const assert = require('assert');
const { ChannelProcessor } = require('../src/channelProcessor');
const { describe, it, beforeEach } = require('mocha');

describe('ChannelProcessor', () => {
  const fiveSyllableMessage = {
    content: 'The first line has five.',
    author: 'authorFive',
  };

  const sevenSyllableMessage = {
    content: 'The second line has seven.',
    author: 'authorSeven',
  };

  let onHaikuCalled = false;
  let haikuMessages = [];
  let defaultProcessor;

  beforeEach(() => {
    onHaikuCalled = false;
    haikuMessages = [];
    defaultProcessor = new ChannelProcessor('channelID');
    defaultProcessor.setOnHaikuFunction((messages) => {
      onHaikuCalled = true;
      haikuMessages = messages;
    });
  });

  describe('#processMessage', () => {
    it('should call onHaiku when a haiku is sent through', () => {
      assert.ok(!onHaikuCalled);

      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);

      assert.ok(onHaikuCalled);
    });

    it('the arguments passed to onHaikuCalled should be the messages given to the processor', () => {
      assert.equal(haikuMessages.length, 0);

      const messages = [];
      messages.push(fiveSyllableMessage);
      messages.push(sevenSyllableMessage);
      messages.push(fiveSyllableMessage);

      messages.forEach((msg) => {
        defaultProcessor.processMessage(msg);
      });

      assert.deepEqual(haikuMessages, messages);
    });
  });
});
<commit_msg>Add more comprehensive tests to channel processor<commit_after>const assert = require('assert');
const { ChannelProcessor } = require('../src/channelProcessor');
const { describe, it, beforeEach } = require('mocha');

describe('ChannelProcessor', () => {
  const fiveSyllableMessage = {
    content: 'The first line has five.',
    author: 'authorFive',
  };

  const sevenSyllableMessage = {
    content: 'The second line has seven.',
    author: 'authorSeven',
  };

  let onHaikuCalled = false;
  let haikuMessages = [];
  let defaultProcessor;

  beforeEach(() => {
    onHaikuCalled = false;
    haikuMessages = [];
    defaultProcessor = new ChannelProcessor('channelID');
    defaultProcessor.setOnHaikuFunction((messages) => {
      onHaikuCalled = true;
      haikuMessages = messages;
    });
  });

  describe('#processMessage', () => {
    it('should call onHaiku when a haiku is sent through', () => {
      assert.ok(!onHaikuCalled);

      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);

      assert.ok(onHaikuCalled);
    });

    it('should pass the the messages given to the processor to onHaikuCalled', () => {
      assert.equal(haikuMessages.length, 0);

      const messages = [];
      messages.push(fiveSyllableMessage);
      messages.push(sevenSyllableMessage);
      messages.push(fiveSyllableMessage);

      messages.forEach((msg) => {
        defaultProcessor.processMessage(msg);
      });

      assert.deepEqual(haikuMessages, messages);
    });

    it('should not call onHaiku when a haiku is not found', () => {
      assert.ok(!onHaikuCalled);

      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);

      assert.ok(!onHaikuCalled);
    });

    it('should find haikus when many messages are passed through', () => {
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);

      assert.ok(!onHaikuCalled);
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);

      onHaikuCalled = false;
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(!onHaikuCalled);
    });

    it('should keep finding haikus after previously finding them', () => {
      assert.ok(!onHaikuCalled);
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
      onHaikuCalled = false;
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
      onHaikuCalled = false;
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
    });

    it('should even find a haiku that shares lines with a previous haiku', () => {
      assert.ok(!onHaikuCalled);
      defaultProcessor.processMessage(fiveSyllableMessage);
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
      onHaikuCalled = false;
      defaultProcessor.processMessage(sevenSyllableMessage);
      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
    });

    it('should not be interfered with if another processor is also receiving messages', () => {
      const secondProcessor = new ChannelProcessor('channelID2');
      secondProcessor.setOnHaikuFunction((messages) => {
        onHaikuCalled = true;
        haikuMessages = messages;
      });

      assert.ok(!onHaikuCalled);
      defaultProcessor.processMessage(fiveSyllableMessage);

      secondProcessor.processMessage(sevenSyllableMessage);
      secondProcessor.processMessage(fiveSyllableMessage);
      assert.ok(!onHaikuCalled);
      defaultProcessor.processMessage(sevenSyllableMessage);

      secondProcessor.processMessage(sevenSyllableMessage);
      secondProcessor.processMessage(sevenSyllableMessage);
      secondProcessor.processMessage(fiveSyllableMessage);
      assert.ok(!onHaikuCalled);

      defaultProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
      onHaikuCalled = false;
      secondProcessor.processMessage(sevenSyllableMessage);
      secondProcessor.processMessage(fiveSyllableMessage);
      assert.ok(onHaikuCalled);
    });
  });
});

{'fraction_non_alphanumeric': 0.10831122900088418, 'fraction_numerical': 0.0004420866489832007, 'mean_word_length': 4.0649253731343284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4540411', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1832, 'n_words': 308}