<commit_before>/**
 * Copyright (c) 2009 Digital Primates IT Consulting Group
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author     <NAME> 
 * @version    
 **/ 
package org.flexunit.internals.runners.statements {
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import mx.events.PropertyChangeEvent;
	import mx.rpc.IResponder;
	
	import org.flexunit.Assert;
	import org.flexunit.AssertionError;
	import org.flexunit.async.AsyncHandler;
	import org.flexunit.async.AsyncLocator;
	import org.flexunit.async.AsyncTestResponder;
	import org.flexunit.async.IAsyncTestResponder;
	import org.flexunit.async.ITestResponder;
	import org.flexunit.events.AsyncEvent;
	import org.flexunit.events.AsyncResponseEvent;
	import org.flexunit.internals.flexunit_internal;
	import org.flexunit.runners.model.FrameworkMethod;
	import org.flexunit.runners.model.TestClass;
	import org.flexunit.token.AsyncTestToken;
	import org.flexunit.token.ChildResult;
	import org.flexunit.utils.ClassNameUtil;
	import org.fluint.sequence.SequenceBindingWaiter;
	import org.fluint.sequence.SequenceRunner;
	
	use namespace flexunit_internal;
	
	/**
	 * The <code>ExpectAsync</code> is a decorator that is responsible for determing 
	 * whether a specific test method is expecting an asynchronous response.  As this 
	 * infrastructure carries overhead, we only create it when the user specifics a 
	 * given test is asynchronous.  The class implements <code>IAsyncHandlingStatement</code> 
	 * and works with the <code>Async</code> class.<br/>
	 * 
	 * In order to expect an asynchronous response, a test method must include metadata indicating 
	 * it is expecting asynchronous functionality.<br/>
	 * 
	 * <pre><code>
	 * [Test(async)]
	 * public function asyncTest():void {
	 * 	//Test with asynchronous functionality
	 * }
	 * </code></pre>
	 * 
	 * @see org.flexunit.async.Async
	 */
	public class ExpectAsync extends AsyncStatementBase implements IAsyncStatement, IAsyncHandlingStatement {
		/**
		 * @private
		 */
		private var objectUnderTest:Object;
		/**
		 * @private
		 */
		private var statement:IAsyncStatement;
		/**
		 * @private
		 */
		private var returnMessageSent:Boolean = false;
		
		/**
		 * @private
		 */
		private var testComplete:Boolean;
		/**
		 * @private
		 */
		private var pendingAsyncCalls:Array;
		/**
		 * @private
		 */
		private var asyncFailureConditions:Dictionary;
		
		/**
		 * @private
		 */
		private var methodBodyExecuting:Boolean = false;
		
		/**
		 * Returns a Boolean value indicating whether the test method is current executing.
		 */
		public function get bodyExecuting():Boolean {
			return methodBodyExecuting;
		}
		
		/**
		 * Returns a Boolean value indicating whether there are still any pending asynchronous calls.
		 */
		public function get hasPendingAsync():Boolean {
			return ( pendingAsyncCalls.length > 0 );
		}
		
		/**
		 * Attempts to call the provided <code>method</code> with the provided <code>rest</code> parameters.
		 * 
		 * @param method The Function to call with the provided <code>rest</code> parameters.
		 * @param rest The parameters supplied to the <code>method</code>.
		 */
		private function protect( method:Function, ... rest ):void {
			try {
				if ( rest && rest.length>0 ) {
					method.apply( this, rest );
				} else {
					method();
				}
			} catch (error:Error) {
				sendComplete( error );
			}
			
			//Adding this line 
			if ( hasPendingAsync ) { 
				startAsyncTimers(); 
			} 
			
		}
		
		/**
		 * Removes asynchronous event listeners from the provided <code>asyncHandler</code>.
		 * 
		 * @param asyncHandler The <code>AsyncHandler</code> from which to remove the event listeners.
		 */
		private function removeAsyncEventListeners( asyncHandler:AsyncHandler ):void {
			asyncHandler.removeEventListener( AsyncHandler.EVENT_FIRED, handleAsyncEventFired, false );
			asyncHandler.removeEventListener( AsyncHandler.TIMER_EXPIRED, handleAsyncTimeOut, false );
		}
		
		/**
		 * Removes asynchronous error event listeners from the provided <code>asyncHandler</code>.
		 * 
		 * @param asyncHandler The <code>AsyncHandler</code> from which to remove the error event listeners.
		 */
		private function removeAsyncErrorEventListeners( asyncHandler:AsyncHandler ):void {
			asyncHandler.removeEventListener( AsyncHandler.EVENT_FIRED, handleAsyncErrorFired, false );<commit_msg>removed the comment form ExpectAsync<commit_after>/**
 * Copyright (c) 2009 Digital Primates IT Consulting Group
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author     <NAME> 
 * @version    
 **/ 
package org.flexunit.internals.runners.statements {
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import mx.events.PropertyChangeEvent;
	import mx.rpc.IResponder;
	
	import org.flexunit.Assert;
	import org.flexunit.AssertionError;
	import org.flexunit.async.AsyncHandler;
	import org.flexunit.async.AsyncLocator;
	import org.flexunit.async.AsyncTestResponder;
	import org.flexunit.async.IAsyncTestResponder;
	import org.flexunit.async.ITestResponder;
	import org.flexunit.events.AsyncEvent;
	import org.flexunit.events.AsyncResponseEvent;
	import org.flexunit.internals.flexunit_internal;
	import org.flexunit.runners.model.FrameworkMethod;
	import org.flexunit.runners.model.TestClass;
	import org.flexunit.token.AsyncTestToken;
	import org.flexunit.token.ChildResult;
	import org.flexunit.utils.ClassNameUtil;
	import org.fluint.sequence.SequenceBindingWaiter;
	import org.fluint.sequence.SequenceRunner;
	
	use namespace flexunit_internal;
	
	/**
	 * The <code>ExpectAsync</code> is a decorator that is responsible for determing 
	 * whether a specific test method is expecting an asynchronous response.  As this 
	 * infrastructure carries overhead, we only create it when the user specifics a 
	 * given test is asynchronous.  The class implements <code>IAsyncHandlingStatement</code> 
	 * and works with the <code>Async</code> class.<br/>
	 * 
	 * In order to expect an asynchronous response, a test method must include metadata indicating 
	 * it is expecting asynchronous functionality.<br/>
	 * 
	 * <pre><code>
	 * [Test(async)]
	 * public function asyncTest():void {
	 * 	//Test with asynchronous functionality
	 * }
	 * </code></pre>
	 * 
	 * @see org.flexunit.async.Async
	 */
	public class ExpectAsync extends AsyncStatementBase implements IAsyncStatement, IAsyncHandlingStatement {
		/**
		 * @private
		 */
		private var objectUnderTest:Object;
		/**
		 * @private
		 */
		private var statement:IAsyncStatement;
		/**
		 * @private
		 */
		private var returnMessageSent:Boolean = false;
		
		/**
		 * @private
		 */
		private var testComplete:Boolean;
		/**
		 * @private
		 */
		private var pendingAsyncCalls:Array;
		/**
		 * @private
		 */
		private var asyncFailureConditions:Dictionary;
		
		/**
		 * @private
		 */
		private var methodBodyExecuting:Boolean = false;
		
		/**
		 * Returns a Boolean value indicating whether the test method is current executing.
		 */
		public function get bodyExecuting():Boolean {
			return methodBodyExecuting;
		}
		
		/**
		 * Returns a Boolean value indicating whether there are still any pending asynchronous calls.
		 */
		public function get hasPendingAsync():Boolean {
			return ( pendingAsyncCalls.length > 0 );
		}
		
		/**
		 * Attempts to call the provided <code>method</code> with the provided <code>rest</code> parameters.
		 * 
		 * @param method The Function to call with the provided <code>rest</code> parameters.
		 * @param rest The parameters supplied to the <code>method</code>.
		 */
		private function protect( method:Function, ... rest ):void {
			try {
				if ( rest && rest.length>0 ) {
					method.apply( this, rest );
				} else {
					method();
				}
			} catch (error:Error) {
				sendComplete( error );
			}
			
			if ( hasPendingAsync ) { 
				startAsyncTimers(); 
			} 
			
		}
		
		/**
		 * Removes asynchronous event listeners from the provided <code>asyncHandler</code>.
		 * 
		 * @param asyncHandler The <code>AsyncHandler</code> from which to remove the event listeners.
		 */
		private function removeAsyncEventListeners( asyncHandler:AsyncHandler ):void {
			asyncHandler.removeEventListener( AsyncHandler.EVENT_FIRED, handleAsyncEventFired, false );
			asyncHandler.removeEventListener( AsyncHandler.TIMER_EXPIRED, handleAsyncTimeOut, false );
		}
		
		/**
		 * Removes asynchronous error event listeners from the provided <code>asyncHandler</code>.
		 * 
		 * @param asyncHandler The <code>AsyncHandler</code> from which to remove the error event listeners.
		 */
		private function removeAsyncErrorEventListeners( asyncHandler:AsyncHandler ):void {
			asyncHandler.removeEventListener( AsyncHandler.EVENT_FIRED, handleAsyncErrorFired, false );
{'fraction_non_alphanumeric': 0.08948049547051211, 'fraction_numerical': 0.0011092623405435386, 'mean_word_length': 3.8041740674955595, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, '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': '6615789', 'n_tokens_mistral': 3314, 'n_tokens_neox': 2833, 'n_words': 987}