<commit_before>var assert = require('assert');
var bcp = require('../');

describe('module export', function() {
  it('creates a listener when called', function() {
    var listener = bcp({});

    assert(listener);
  });
});

describe('listener', function() {
  var listener, host;

  beforeEach(function() {
    host = {};
    listener = bcp(host);
  });

  describe('.listen()', function() {
    it('adds getters to host object based on option keys', function() {
      listener.listen({
        answers: ['a', 'b']
      });

      assert('a' in host);
      assert('b' in host);
    });

    it('invokes callback when a getter on host is accessed', function() {
      var callbackInvoked = false;

      listener.listen({
        answers: ['a', 'b'],
        callback: function() {
          callbackInvoked = true;
        }
      });

      host.a;

      assert(callbackInvoked);
    });

    it('passes object of selected option when invoking callback', function() {
      var selectedOption;

      listener.listen({
        answers: ['a', 'b'],
        callback: function(selected) {
          selectedOption = selected;
        }
      });

      host.b;

      assert.equal(selectedOption, 'b');
    });

    it('only invokes callback for first getter accessed', function() {<commit_msg>rename tests to reflect recent changes<commit_after>var assert = require('assert');
var bcp = require('../');

describe('module export', function() {
  it('creates a listener when called', function() {
    var listener = bcp({});

    assert(listener);
  });
});

describe('listener', function() {
  var listener, host;

  beforeEach(function() {
    host = {};
    listener = bcp(host);
  });

  describe('.listen()', function() {
    it('adds a getter to host object for each answer', function() {
      listener.listen({
        answers: ['a', 'b']
      });

      assert('a' in host);
      assert('b' in host);
    });

    it('invokes callback when a getter on host is accessed', function() {
      var callbackInvoked = false;

      listener.listen({
        answers: ['a', 'b'],
        callback: function() {
          callbackInvoked = true;
        }
      });

      host.a;

      assert(callbackInvoked);
    });

    it('passes selected answer when invoking callback', function() {
      var selectedOption;

      listener.listen({
        answers: ['a', 'b'],
        callback: function(selected) {
          selectedOption = selected;
        }
      });

      host.b;

      assert.equal(selectedOption, 'b');
    });

    it('only invokes callback for first getter accessed', function() {
{'fraction_non_alphanumeric': 0.1554959785522788, 'fraction_numerical': 0.0, 'mean_word_length': 2.473404255319149, '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': '6147329', 'n_tokens_mistral': 754, 'n_tokens_neox': 728, 'n_words': 209}