<commit_before><html>
<head>
  <script src="../lib/OpenLayers.js"></script>
  <script type="text/javascript"><!--
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var map; 
    
    function test_01_Events_constructor (t) {
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        var browserTypes = OpenLayers.Events.prototype.BROWSER_EVENTS;

        var totalTests = 5 + eventTypes.length + browserTypes.length;

        t.plan( totalTests );

        events = new OpenLayers.Events(obj, mapDiv, eventTypes);

        t.ok( events instanceof OpenLayers.Events, "new OpenLayers.Control returns object" );

        t.ok(events.object ==obj, " 'object' property correctly set");
        t.ok(events.element == mapDiv, " 'element' property correctly set");
        t.ok(events.eventTypes == eventTypes, " 'eventTypes' property correctly set");


        for (var i = 0; i < browserTypes.length; i++) {
            t.ok( events.listeners[browserTypes[i]] instanceof Array, 
                  "browser event: " + browserTypes[i] + " correctly registered" );
        }
        for (var i = 0; i < eventTypes.length; i++) {
            t.ok( events.listeners[eventTypes[i]] instanceof Array, 
                  "custom event: " + eventTypes[i] + " correctly registered");
        }

        // default/nulls
        events = new OpenLayers.Events(null, null, null);
        t.ok( events.listeners != null,
              "init of Events with null object/element/eventTypes still creates listeners array" );
    }

    function test_02_Events_register_unregister(t) {
 
        t.plan( 15 );
 
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        
        events = new OpenLayers.Events(obj, mapDiv, eventTypes);
        
        var func = function () { this.result++ }
        events.register( "doThingA", obj, func );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 1, "register correctly adds to event.listeners" );
        t.ok( listenerList[0].obj == obj, "obj property correctly registered");
        t.ok( listenerList[0].func == func, "func property correctly registered");

        var func2 = function () { this.result-- }
        events.register( "doThingA", obj, func2 );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 2, "register correctly appends new callback to event.listeners[doThingA]" );
        t.ok( listenerList[1].obj == obj, "obj property correctly registered");
        t.ok( listenerList[1].func == func2, "func property correctly registered");

        var func3 = function () { this.result = this.result + 3; }
        events.register( "doThingA", null, func3 );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "register correctly appends new callback to event.listeners[doThingA] even when obj passed in is null" );
        t.ok( listenerList[2].obj == obj, "obj is correctly set to Events.object default when null is passed in.");
        t.ok( listenerList[2].func == func3, "func property correctly registered");

        events.register( "doThingA", obj, null);

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "register correctly does not append null callback to event.listeners[doThingA] even when obj passed in is null" );

        events.register( "chicken", obj, func);
        t.ok( events.listeners["chicken"] == null, "register() does nothing on attempt to register un-enabled event");

        events.unregister("doThingA", obj, null);
        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "trying to unregister a null callback does nothing -- but doesnt crash :-)" );
    
        events.unregister("doThingA", obj, func);
        var found = false;
        for (var i = 0; i < listenerList.length; i++) {
            var listener = listenerList[i];
            if (listener.obj == obj && listener.func == func) {
                found = true;
            }
        }                
        t.ok( (listenerList.length == 2) && !found, "unregister correctly removes callback" );

        events.unregister("doThingA", null, func3);
        var found = false;
        for (var i = 0; i < listenerList.length; i++) {
            var listener = listenerList[i];
            if (listener.obj == obj && listener.func == func) {
                found = true;
            }
        }                
        t.ok( (listenerList.length == 1) && !found, "unregister correctly removes callback when no obj specified" );
        
        events.unregister("chicken", null, func3);
        t.ok( events.listeners["chicken"] == null, "unregistering an event that is not enabled does not wierdly enable it -- or cause a script error")
    }

    function test_03_Events_remove(t) {

        t.plan( 2 );
 
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        
        events = new OpenLayers.Events(obj, mapDiv, eventTypes);
        
        var func = function () { this.result++ }
        var func2 = function () { this.result-- }
        var func3 = function () { this.result = this.result + 3; }

        events.register( "doThingA", obj, func );
        events.register( "doThingA", obj, func2 );
        events.register( "doThingA", null, func3 );

        events.remove("doThingA");

        t.eq( events.listeners["doThingA"].length, 0, "remove() correctly clears the event listeners" );
<commit_msg>added some more just-in-case tests to test the unregister() function<commit_after><html>
<head>
  <script src="../lib/OpenLayers.js"></script>
  <script type="text/javascript"><!--
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var map; 
    
    function test_01_Events_constructor (t) {
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        var browserTypes = OpenLayers.Events.prototype.BROWSER_EVENTS;

        var totalTests = 5 + eventTypes.length + browserTypes.length;

        t.plan( totalTests );

        events = new OpenLayers.Events(obj, mapDiv, eventTypes);

        t.ok( events instanceof OpenLayers.Events, "new OpenLayers.Control returns object" );

        t.ok(events.object ==obj, " 'object' property correctly set");
        t.ok(events.element == mapDiv, " 'element' property correctly set");
        t.ok(events.eventTypes == eventTypes, " 'eventTypes' property correctly set");


        for (var i = 0; i < browserTypes.length; i++) {
            t.ok( events.listeners[browserTypes[i]] instanceof Array, 
                  "browser event: " + browserTypes[i] + " correctly registered" );
        }
        for (var i = 0; i < eventTypes.length; i++) {
            t.ok( events.listeners[eventTypes[i]] instanceof Array, 
                  "custom event: " + eventTypes[i] + " correctly registered");
        }

        // default/nulls
        events = new OpenLayers.Events(null, null, null);
        t.ok( events.listeners != null,
              "init of Events with null object/element/eventTypes still creates listeners array" );
    }

    function test_02_Events_register_unregister(t) {
 
        t.plan( 18 );
 
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        
        events = new OpenLayers.Events(obj, mapDiv, eventTypes);
        
        var func = function () { this.result++ }
        events.register( "doThingA", obj, func );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 1, "register correctly adds to event.listeners" );
        t.ok( listenerList[0].obj == obj, "obj property correctly registered");
        t.ok( listenerList[0].func == func, "func property correctly registered");

        var func2 = function () { this.result-- }
        events.register( "doThingA", obj, func2 );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 2, "register correctly appends new callback to event.listeners[doThingA]" );
        t.ok( listenerList[1].obj == obj, "obj property correctly registered");
        t.ok( listenerList[1].func == func2, "func property correctly registered");

        var func3 = function () { this.result = this.result + 3; }
        events.register( "doThingA", null, func3 );

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "register correctly appends new callback to event.listeners[doThingA] even when obj passed in is null" );
        t.ok( listenerList[2].obj == obj, "obj is correctly set to Events.object default when null is passed in.");
        t.ok( listenerList[2].func == func3, "func property correctly registered");

        events.register( "doThingA", obj, null);

        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "register correctly does not append null callback to event.listeners[doThingA] even when obj passed in is null" );

        events.register( "chicken", obj, func);
        t.ok( events.listeners["chicken"] == null, "register() does nothing on attempt to register un-enabled event");

        events.unregister("doThingA", obj, null);
        var listenerList = events.listeners["doThingA"];
        t.eq( listenerList.length, 3, "trying to unregister a null callback does nothing -- but doesnt crash :-)" );
    
        events.unregister("doThingA", obj, func);
        var found = false;
        for (var i = 0; i < listenerList.length; i++) {
            var listener = listenerList[i];
            if (listener.obj == obj && listener.func == func) {
                found = true;
            }
        }                
        t.ok( (listenerList.length == 2) && !found, "unregister correctly removes callback" );

        events.unregister("doThingA", null, func3);
        var found = false;
        for (var i = 0; i < listenerList.length; i++) {
            var listener = listenerList[i];
            if (listener.obj == obj && listener.func == func) {
                found = true;
            }
        }                
        t.ok( (listenerList.length == 1) && !found, "unregister correctly removes callback when no obj specified" );
        
        var func4 = function () { this.result = "chicken"; }
        events.unregister("doThingA", obj, func4);
        t.ok( (listenerList.length == 1), "unregister does not bomb if you try to remove an unregistered callback" );

        var obj2 = { chicken: 151 };
        events.unregister("doThingA", obj2, func2);
        t.ok( (listenerList.length == 1), "unregister does not bomb or accidntally remove if you try to remove a valid callback on a valid event type, but with the wrong context object" );

        events.unregister("doThingA", obj, null);
        t.ok( (listenerList.length == 1), "unregister does not bomb if you try to remove a null callback" );

        events.unregister("chicken", null, func3);
        t.ok( events.listeners["chicken"] == null, "unregistering an event that is not enabled does not wierdly enable it -- or cause a script error")


    }

    function test_03_Events_remove(t) {

        t.plan( 2 );
 
        var mapDiv = $('map');
        var obj = {result: 0};
        var eventTypes = ["doThingA", "doThingB", "doThingC"];
        
        events = new OpenLayers.Events(obj, mapDiv, eventTypes);
        
        var func = function () { this.result++ }
        var func2 = function () { this.result-- }
        var func3 = function () { this.result = this.result + 3; }

        events.register( "doThingA", obj, func );
        events.register( "doThingA", obj, func2 );
        events.register( "doThingA", null, func3 );

        events.remove("doThingA");

        t.eq( events.listeners["doThingA"].length, 0, "remove() correctly clears the event listeners" );

{'fraction_non_alphanumeric': 0.13164598570137234, 'fraction_numerical': 0.008464130166817322, 'mean_word_length': 2.4831139095592443, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 13, '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': '1514052', 'n_tokens_mistral': 3605, 'n_tokens_neox': 3458, 'n_words': 1022}