Skip to content

Commit

Permalink
Add unit tests for #1420
Browse files Browse the repository at this point in the history
Also fixed that the pendingRemove array was not being emptied
  • Loading branch information
Gama11 committed Mar 27, 2015
1 parent e7f3ea5 commit e12d199
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
5 changes: 3 additions & 2 deletions flixel/util/FlxSignal.hx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private class FlxBaseSignal<T> implements IFlxSignal<T>
if (listener != null)
{
var handler = getHandler(listener);

if (handler != null)
{
if (processingListeners)
Expand All @@ -136,7 +135,6 @@ private class FlxBaseSignal<T> implements IFlxSignal<T>
{
handlers.remove(handler);
handler.destroy();
handler = null;
}
}
}
Expand All @@ -159,6 +157,7 @@ private class FlxBaseSignal<T> implements IFlxSignal<T>
{
removeAll();
handlers = null;
pendingRemove = null;
}

private function registerListener(listener:T, dispatchOnce:Bool):FlxSignalHandler<T>
Expand Down Expand Up @@ -303,6 +302,8 @@ private class Macro
{
remove(handler.listener);
}
if (pendingRemove.length > 0)
pendingRemove = [];
}
}
}
31 changes: 31 additions & 0 deletions tests/src/flixel/util/FlxSignalTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,35 @@ class FlxSignalTest extends FlxTest
signal0.add(null);
Assert.isFalse(signal0.has(null));
}

@Test // issue 1420
function testRemoveCurrentDuringDispatch()
{
signal0.addOnce(callbackEmpty1);
signal0.add(callbackSetFlagTrue);
signal0.dispatch();

Assert.isTrue(flag);
Assert.isTrue(signal0.has(callbackSetFlagTrue));
Assert.isFalse(signal0.has(callbackEmpty1));
}

@Test // issue 1420
function testRemovePreviousDuringDispatch()
{
var timesCalled = 0;
var removePrevious = function()
{
timesCalled++;
signal0.remove(callbackSetFlagTrue);
};

signal0.add(callbackSetFlagTrue);
signal0.add(removePrevious);
signal0.dispatch();

Assert.areEqual(1, timesCalled);
Assert.isTrue(signal0.has(removePrevious));
Assert.isFalse(signal0.has(callbackSetFlagTrue));
}
}
8 changes: 4 additions & 4 deletions tests/test.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
-swf-version 11.8
-swf bin/as3_test.swf

-cmd haxelib run lime build html5
--next
#-cmd haxelib run lime build html5
#--next

## HTML5

-js bin/html5/bin/TestMain.js
--no-output
#-js bin/html5/bin/TestMain.js
#--no-output

0 comments on commit e12d199

Please sign in to comment.