<commit_before>// --------------------------------------------------
// kontra.pointer
// --------------------------------------------------
describe('kontra.pointer', function() {
  var object;
  var canvas = document.createElement('canvas');

  // reset canvas offsets
  canvas.style.position = 'absolute';
  canvas.style.top = 0;
  canvas.style.left = 0;

  /**
   * Simulate a mouse event.
   * @param {string} type - Type of mouse event.
   * @param {object} [config] - Additional settings for the event.
   * @param {number} [config.button]
   */
  function simulateEvent(type, config) {
    var evt;

    // PhantomJS <2.0.0 throws an error for the `new Event` call, so we need to supply an
    // alternative form of creating an event just for PhantomJS
    // @see https://github.com/ariya/phantomjs/issues/11289#issuecomment-38880333
    try {
      evt = new Event(type, {bubbles: true});
    } catch(e) {
      evt = document.createEvent('Event');
      evt.initEvent(type, true, false);
    }

    var config = config || {};
    for (var prop in config) {
      evt[prop] = config[prop];
    }

    canvas.dispatchEvent(evt);
  }

  // reset pressed buttons before each test
  beforeEach(function() {
    simulateEvent('blur');

    // set up and take down the canvas before each test so it doesn't leak
    // the canvas element for the kontra.core.init tests
    kontra.canvas = canvas;
    document.body.appendChild(canvas);

    object = {
      x: 100,
      y: 50,
      width: 10,
      height: 20,
      render: sinon.spy()
    };
    kontra.pointer.track(object);
    object.render();
    kontra._tick();
  });

  afterEach(function() {
    kontra.pointer.untrack(object);
    canvas.remove();
  });

<commit_msg>Pointer test calls _init<commit_after>// --------------------------------------------------
// kontra.pointer
// --------------------------------------------------
describe('kontra.pointer', function() {
  var object;
  var canvas = document.createElement('canvas');

  // reset canvas offsets
  canvas.style.position = 'absolute';
  canvas.style.top = 0;
  canvas.style.left = 0;

  /**
   * Simulate a mouse event.
   * @param {string} type - Type of mouse event.
   * @param {object} [config] - Additional settings for the event.
   * @param {number} [config.button]
   */
  function simulateEvent(type, config) {
    var evt;

    // PhantomJS <2.0.0 throws an error for the `new Event` call, so we need to supply an
    // alternative form of creating an event just for PhantomJS
    // @see https://github.com/ariya/phantomjs/issues/11289#issuecomment-38880333
    try {
      evt = new Event(type, {bubbles: true});
    } catch(e) {
      evt = document.createEvent('Event');
      evt.initEvent(type, true, false);
    }

    var config = config || {};
    for (var prop in config) {
      evt[prop] = config[prop];
    }

    canvas.dispatchEvent(evt);
  }

  // reset pressed buttons before each test
  beforeEach(function() {
    simulateEvent('blur');

    // set up and take down the canvas before each test so it doesn't leak
    // the canvas element for the kontra.core.init tests
    kontra.canvas = canvas;
    kontra._init();
    document.body.appendChild(canvas);

    object = {
      x: 100,
      y: 50,
      width: 10,
      height: 20,
      render: sinon.spy()
    };
    kontra.pointer.track(object);
    object.render();
    kontra._tick();
  });

  afterEach(function() {
    kontra.pointer.untrack(object);
    canvas.remove();
  });


{'fraction_non_alphanumeric': 0.18394744358754642, 'fraction_numerical': 0.015424164524421594, 'mean_word_length': 2.1436265709156195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3178313', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1047, 'n_words': 292}