<commit_before>/*global text,expect,ok,module,notEqual,Paladin,test,window,start,stop,console*/
(function (window, document, undefined, Paladin) {

  var game;

  module("Paladin event subsystem", {
    setup: function () {

      // set up a game with some event listeners
      function Game() {
  
        var entity1 = new Paladin.Entity();
        entity1.count = 0;
        entity1.listen( {
          event: 'escape-up',
          callback: function( parameters ) {
            ok(true, "escape-up event triggered");
            start();
          }
        } );

        entity1.listen( {
          event: 'mouse1-up',
          callback: function( parameters ) {
            ok(true, "mouse1-up event triggered");
            start();
          }
        } );
         
        this.run = function () {
          Paladin.run();
        };
      }

      game = new Game();

    },

    teardown: function () {
    }
  });

  /* Initialize a keyboard event for either Gecko or WebKit) */
  function newKbdEvent(charCode) {
    var evt = document.createEvent("KeyboardEvent");
    if ("initKeyEvent" in evt) {
      // vestigial DOM2 method still in use by Gecko
      evt.initKeyEvent("keyup", true, true, window, 0, 0, 0, 0, 
                       charCode, charCode);       
    } else {
      // otherwise assume DOM3
      evt.initKeyboardEvent("keyup", 0, 0, window, charCode);
    }
    return evt;
  }

  function simulateKeyEvent(charCode) {

    var evt = newKbdEvent(charCode.charCodeAt(0));
    var canceled = !window.dispatchEvent(evt);
    if(canceled) {
      // A handler called preventDefault
      console.log("simulated key event " + charCode + " canceled");
    }
  } 

  function simulateClick() {
    var evt = document.createEvent("MouseEvent");
    evt.initMouseEvent("mouseup", true, true, window,
      1, 50, 50, 50, 50, false, false, false, false, 0, null);
    var canceled = !document.documentElement.dispatchEvent(evt);
    if (canceled) {
      // A handler called preventDefault
      console.log("mouseup event cancelled");
    }
  }


  test("escape keypress fires an up event", function () {
    expect(1);
    stop();
    game.run();
    simulateKeyEvent("\x1b");
    Paladin.tasker.terminate();
  });

  test("mouse click fires an up event", function () { 
    expect(1);
    stop();
    game.run();
    simulateClick();
    Paladin.tasker.terminate();
  });

})(window, document, undefined, Paladin);<commit_msg>Use entity.ignore to workaround current lack of game teardown<commit_after>/*global text,expect,ok,module,notEqual,Paladin,test,window,start,stop,console*/
(function (window, document, undefined, Paladin) {

  var game;
  var entity1;
  module("Paladin event subsystem", {
    setup: function () {

      // set up a game with some event listeners
      function Game() {

        entity1 = new Paladin.Entity();
        entity1.count = 0;
        entity1.listen( {
          event: 'escape-up',
          callback: function escapeUp( parameters ) {
            console.log("entering escapeUp");
            ok(true, "escape-up event triggered");
            start();
          }
        } );

        entity1.listen( {
          event: 'mouse1-up',
          callback: function mouse1Up( parameters ) {
            console.log("entering mouse1Up");
            ok(true, "mouse1-up event triggered");
            start();
          }
        } );
         
        this.run = function () {
          Paladin.run();
        };
      }

      game = new Game();

    },

    teardown: function () {
      entity1.ignore( {event: 'mouse1-up'});
      entity1.ignore( {event: 'escape-up'});
      game = null; // force as much to be GCed as we can
    }
  });

  /* Initialize a keyboard event for either Gecko or WebKit) */
  function newKbdEvent(charCode) {
    var evt = document.createEvent("KeyboardEvent");
    if ("initKeyEvent" in evt) {
      // vestigial DOM2 method still in use by Gecko
      evt.initKeyEvent("keyup", true, true, window, 0, 0, 0, 0, 
                       charCode, charCode);       
    } else {
      // otherwise assume DOM3
      evt.initKeyboardEvent("keyup", 0, 0, window, charCode);
    }
    return evt;
  }

  function simulateKeyEvent(charCode) {

    var evt = newKbdEvent(charCode.charCodeAt(0));
    var canceled = !window.dispatchEvent(evt);
    if (canceled) {
      // A handler called preventDefault
      console.log("simulated key event " + charCode + " canceled");
    }
  } 

  function simulateClick() {
    var evt = document.createEvent("MouseEvent");
    evt.initMouseEvent("mouseup", true, true, window,
      1, 50, 50, 50, 50, false, false, false, false, 0, null);
    var canceled = !document.documentElement.dispatchEvent(evt);
    if (canceled) {
      // A handler called preventDefault
      console.log("simulated mouseup event cancelled");
    }
  }

  asyncTest("escape keypress fires an up event", function () {
    expect(1);
    simulateKeyEvent("\x1b");
  });

  asyncTest("mouse click fires an up event", function () { 
    expect(1);
    simulateClick();
  });

})(window, document, undefined, Paladin);
{'fraction_non_alphanumeric': 0.13096862210095497, 'fraction_numerical': 0.012473202104852855, 'mean_word_length': 2.2982005141388173, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4174504', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1517, 'n_words': 397}