<commit_before>package openfl.events;


import massive.munit.Assert;
import openfl.display.Sprite;


class EventDispatcherTest {
	
	
	@Test public function new_ () {
		
		var dispatcher = new EventDispatcher ();
		
		Assert.isNotNull (dispatcher);
		
		var dispatcher2 = new EventDispatcher (dispatcher);
		
		Assert.isNotNull (dispatcher2);
		
	}
	
	
	@Test public function addEventListener () {
		
		var dispatcher = new EventDispatcher ();
		dispatcher.addEventListener ("event", function (_) {});
		
		Assert.isTrue (dispatcher.hasEventListener ("event"));
		
	}
	
	
	@Test public function dispatchEvent () {
		
		// Standard
		
		var caughtEvent = false;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) { 
			
			caughtEvent = true;
			
		};
		
		dispatcher.addEventListener ("event", listener);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (caughtEvent);
		
		// Capture is true
		
		var correctPhase = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (event:Event) {
			
			correctPhase = (event.eventPhase == EventPhase.CAPTURING_PHASE);
			
		}
		
		dispatcher.addEventListener ("event", listener, true);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (correctPhase);
		
		// Capture is false
		
		var correctPhase = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (event:Event) { 
			
			if (event.eventPhase == EventPhase.CAPTURING_PHASE) {
				
				correctPhase = false;
				
			}
			
		}
		
		dispatcher.addEventListener ("event", listener, false);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (correctPhase);
		
		// First in, first out standard order
		
		var correctOrder = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) {
			
			correctOrder = false;
			
		}
		
		var listener2 = function (_) {
			
			correctOrder = true;
			
		}
		
		dispatcher.addEventListener ("event", listener);
		dispatcher.addEventListener ("event", listener2);
		
		Assert.isTrue (correctOrder);
		
		// Order by priority
		
		var correctOrder = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) {
			
			correctOrder = false;
			
		}
		
		var listener2 = function (_) {
			
			correctOrder = true;
			
		}
		
		dispatcher.addEventListener ("event", listener2, false, 10);
		dispatcher.addEventListener ("event", listener, false, 20);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (correctOrder);
		
		// Bubbling
		
		var sprite = new Sprite ();
		var sprite2 = new Sprite ();
		
		var spriteEvent = false;
		var sprite2Event = false;
		
		var listener = function (_) {
			
			spriteEvent = true;
			correctOrder = true;
			
		}
		
		var listener2 = function (_) {
			
			sprite2Event = true;
			correctOrder = false;
			
		}
		
		sprite.addEventListener ("event", listener);
		sprite2.addEventListener ("event", listener2);
		sprite.addChild (sprite2);
		sprite2.dispatchEvent (new Event ("event"));
		
		Assert.isFalse (spriteEvent);
		Assert.isTrue (sprite2Event);
		
		sprite2Event = false;
		
		sprite2.dispatchEvent (new Event ("event", true));
		
		Assert.isTrue (spriteEvent);
		Assert.isTrue (sprite2Event);
		Assert.isTrue (correctOrder);
		
		// Capture event bubbling
		
		#if flash // todo
		var sprite = new Sprite ();
		var sprite2 = new Sprite ();
		
		var spriteEvent = false;
		var sprite2Event = false;
		
		var listener = function (_) {
			
			spriteEvent = true;
			correctOrder = true;
			
		}
		
		var listener2 = function (_) {
			
			sprite2Event = true;
			correctOrder = false;
			
		}
		
		sprite.addEventListener ("event", listener, true);
		sprite2.addEventListener ("event", listener2, true);
		sprite.addChild (sprite2);
		sprite2.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (spriteEvent);
		Assert.isFalse (sprite2Event);
		
		sprite2Event = false;
		
		sprite2.dispatchEvent (new Event ("event", true));
		
		Assert.isTrue (spriteEvent);
		Assert.isFalse (sprite2Event);
		Assert.isTrue (correctOrder);
		#end
		
	}
	
	
	@Test public function hasEventListener () {
		
		
		
	}
	
	
	@Test public function removeEventListener () {
		
		var dispatcher = new EventDispatcher ();
		var listener = function (_) {};
		dispatcher.addEventListener ("event", listener);
		dispatcher.removeEventListener ("event", listener);
		
		Assert.isFalse (dispatcher.hasEventListener ("event"));
		
	}
	
	
	/*public function toString () {
		
		
		
	}*/
	
	
	@Test public function willTrigger () {
		
		
		
	}
	
	
}<commit_msg>EventDispatcherTest: comment out ineffective `useCapture=true` test.<commit_after>package openfl.events;


import massive.munit.Assert;
import openfl.display.Sprite;


class EventDispatcherTest {
	
	
	@Test public function new_ () {
		
		var dispatcher = new EventDispatcher ();
		
		Assert.isNotNull (dispatcher);
		
		var dispatcher2 = new EventDispatcher (dispatcher);
		
		Assert.isNotNull (dispatcher2);
		
	}
	
	
	@Test public function addEventListener () {
		
		var dispatcher = new EventDispatcher ();
		dispatcher.addEventListener ("event", function (_) {});
		
		Assert.isTrue (dispatcher.hasEventListener ("event"));
		
	}
	
	
	@Test public function dispatchEvent () {
		
		// Standard
		
		var caughtEvent = false;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) { 
			
			caughtEvent = true;
			
		};
		
		dispatcher.addEventListener ("event", listener);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (caughtEvent);
		
		// Capture is true
		
		var correctPhase = false; // fail unless we see correct event
		var dispatcher = new EventDispatcher ();
		
		var listener = function (event:Event) {
			
			correctPhase = (event.eventPhase == EventPhase.CAPTURING_PHASE);
			
		}
		
		dispatcher.addEventListener ("event", listener, true);
		dispatcher.dispatchEvent (new Event ("event"));
		
		// TODO: this dispatchEvent will never go through CAPTURING_PHASE.
		// It needs to come from Stage
		// (or possibly through e.g. DisplayObject.__fireEvent)
		// See FocusEventTest for an example.
		//DISABLED//Assert.isTrue (correctPhase);
		
		// Capture is false
		
		var correctPhase = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (event:Event) { 
			
			if (event.eventPhase == EventPhase.CAPTURING_PHASE) {
				
				correctPhase = false;
				
			}
			
		}
		
		dispatcher.addEventListener ("event", listener, false);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (correctPhase);
		
		// First in, first out standard order
		
		var correctOrder = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) {
			
			correctOrder = false;
			
		}
		
		var listener2 = function (_) {
			
			correctOrder = true;
			
		}
		
		dispatcher.addEventListener ("event", listener);
		dispatcher.addEventListener ("event", listener2);
		
		Assert.isTrue (correctOrder);
		
		// Order by priority
		
		var correctOrder = true;
		var dispatcher = new EventDispatcher ();
		
		var listener = function (_) {
			
			correctOrder = false;
			
		}
		
		var listener2 = function (_) {
			
			correctOrder = true;
			
		}
		
		dispatcher.addEventListener ("event", listener2, false, 10);
		dispatcher.addEventListener ("event", listener, false, 20);
		dispatcher.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (correctOrder);
		
		// Bubbling
		
		var sprite = new Sprite ();
		var sprite2 = new Sprite ();
		
		var spriteEvent = false;
		var sprite2Event = false;
		
		var listener = function (_) {
			
			spriteEvent = true;
			correctOrder = true;
			
		}
		
		var listener2 = function (_) {
			
			sprite2Event = true;
			correctOrder = false;
			
		}
		
		sprite.addEventListener ("event", listener);
		sprite2.addEventListener ("event", listener2);
		sprite.addChild (sprite2);
		sprite2.dispatchEvent (new Event ("event"));
		
		Assert.isFalse (spriteEvent);
		Assert.isTrue (sprite2Event);
		
		sprite2Event = false;
		
		sprite2.dispatchEvent (new Event ("event", true));
		
		Assert.isTrue (spriteEvent);
		Assert.isTrue (sprite2Event);
		Assert.isTrue (correctOrder);
		
		// Capture event bubbling
		
		#if flash // todo
		var sprite = new Sprite ();
		var sprite2 = new Sprite ();
		
		var spriteEvent = false;
		var sprite2Event = false;
		
		var listener = function (_) {
			
			spriteEvent = true;
			correctOrder = true;
			
		}
		
		var listener2 = function (_) {
			
			sprite2Event = true;
			correctOrder = false;
			
		}
		
		sprite.addEventListener ("event", listener, true);
		sprite2.addEventListener ("event", listener2, true);
		sprite.addChild (sprite2);
		sprite2.dispatchEvent (new Event ("event"));
		
		Assert.isTrue (spriteEvent);
		Assert.isFalse (sprite2Event);
		
		sprite2Event = false;
		
		sprite2.dispatchEvent (new Event ("event", true));
		
		Assert.isTrue (spriteEvent);
		Assert.isFalse (sprite2Event);
		Assert.isTrue (correctOrder);
		#end
		
	}
	
	
	@Test public function hasEventListener () {
		
		
		
	}
	
	
	@Test public function removeEventListener () {
		
		var dispatcher = new EventDispatcher ();
		var listener = function (_) {};
		dispatcher.addEventListener ("event", listener);
		dispatcher.removeEventListener ("event", listener);
		
		Assert.isFalse (dispatcher.hasEventListener ("event"));
		
	}
	
	
	/*public function toString () {
		
		
		
	}*/
	
	
	@Test public function willTrigger () {
		
		
		
	}
	
	
}
{'fraction_non_alphanumeric': 0.11287942664418213, 'fraction_numerical': 0.007166947723440135, 'mean_word_length': 3.0021088148460566, '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': '7584917', 'n_tokens_mistral': 3571, 'n_tokens_neox': 2675, 'n_words': 721}