asunit4 4.2.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. data/Gemfile +5 -0
  2. data/MIT-LICENSE.txt +22 -0
  3. data/README.textile +6 -0
  4. data/air/AIR2Runner.mxml +22 -0
  5. data/air/AIR2RunnerDescriptor.xml +38 -0
  6. data/asunit4.gemspec +20 -0
  7. data/asunit4.rb +16 -0
  8. data/bin/AsUnit-4.1.pre.swc +0 -0
  9. data/bin/AsUnitRunner.swf +0 -0
  10. data/build.xml +46 -0
  11. data/lib/Reflection.swc +0 -0
  12. data/rakefile.rb +169 -0
  13. data/script/generate +21 -0
  14. data/src/asunit/asserts/assertEquals.as +5 -0
  15. data/src/asunit/asserts/assertEqualsArrays.as +5 -0
  16. data/src/asunit/asserts/assertEqualsArraysIgnoringOrder.as +5 -0
  17. data/src/asunit/asserts/assertEqualsFloat.as +5 -0
  18. data/src/asunit/asserts/assertFalse.as +5 -0
  19. data/src/asunit/asserts/assertNotNull.as +5 -0
  20. data/src/asunit/asserts/assertNotSame.as +5 -0
  21. data/src/asunit/asserts/assertNull.as +5 -0
  22. data/src/asunit/asserts/assertSame.as +5 -0
  23. data/src/asunit/asserts/assertThrows.as +5 -0
  24. data/src/asunit/asserts/assertTrue.as +5 -0
  25. data/src/asunit/asserts/fail.as +5 -0
  26. data/src/asunit/core/AsUnitCore.as +177 -0
  27. data/src/asunit/core/FlashBuilderCore.as +22 -0
  28. data/src/asunit/core/FlashDevelopCore.as +21 -0
  29. data/src/asunit/core/TextCore.as +54 -0
  30. data/src/asunit/errors/AbstractError.as +10 -0
  31. data/src/asunit/errors/AssertionFailedError.as +10 -0
  32. data/src/asunit/errors/ClassNotFoundError.as +11 -0
  33. data/src/asunit/errors/InstanceNotFoundError.as +10 -0
  34. data/src/asunit/errors/UnimplementedFeatureError.as +10 -0
  35. data/src/asunit/errors/UsageError.as +11 -0
  36. data/src/asunit/events/TimeoutCommandEvent.as +27 -0
  37. data/src/asunit/framework/Assert.as +408 -0
  38. data/src/asunit/framework/Async.as +138 -0
  39. data/src/asunit/framework/CallbackBridge.as +175 -0
  40. data/src/asunit/framework/Command.as +6 -0
  41. data/src/asunit/framework/ErrorEvent.as +20 -0
  42. data/src/asunit/framework/IAsync.as +21 -0
  43. data/src/asunit/framework/IResult.as +36 -0
  44. data/src/asunit/framework/IRunListener.as +11 -0
  45. data/src/asunit/framework/IRunner.as +15 -0
  46. data/src/asunit/framework/IRunnerFactory.as +9 -0
  47. data/src/asunit/framework/ITestFailure.as +32 -0
  48. data/src/asunit/framework/ITestListener.as +15 -0
  49. data/src/asunit/framework/ITestResult.as +21 -0
  50. data/src/asunit/framework/ITestSuccess.as +22 -0
  51. data/src/asunit/framework/ITestWarning.as +14 -0
  52. data/src/asunit/framework/InjectionDelegate.as +96 -0
  53. data/src/asunit/framework/LegacyTestIterator.as +40 -0
  54. data/src/asunit/framework/MessageBridge.as +24 -0
  55. data/src/asunit/framework/Method.as +80 -0
  56. data/src/asunit/framework/Result.as +181 -0
  57. data/src/asunit/framework/RunnerFactory.as +179 -0
  58. data/src/asunit/framework/SuiteIterator.as +71 -0
  59. data/src/asunit/framework/TestCase.as +106 -0
  60. data/src/asunit/framework/TestFailure.as +65 -0
  61. data/src/asunit/framework/TestIterator.as +282 -0
  62. data/src/asunit/framework/TestObserver.as +12 -0
  63. data/src/asunit/framework/TestSuccess.as +38 -0
  64. data/src/asunit/framework/TestWarning.as +40 -0
  65. data/src/asunit/framework/TimeoutCommand.as +103 -0
  66. data/src/asunit/printers/FlashBuilderPrinter.as +134 -0
  67. data/src/asunit/printers/FlashDevelopPrinter.as +81 -0
  68. data/src/asunit/printers/TextPrinter.as +324 -0
  69. data/src/asunit/runners/LegacyRunner.as +13 -0
  70. data/src/asunit/runners/SuiteRunner.as +125 -0
  71. data/src/asunit/runners/TestRunner.as +403 -0
  72. data/src/asunit/util/ArrayIterator.as +30 -0
  73. data/src/asunit/util/Iterator.as +10 -0
  74. data/test/AllTests.as +73 -0
  75. data/test/AsUnitRunner.as +15 -0
  76. data/test/Flex3Runner.mxml +24 -0
  77. data/test/Flex4Runner.mxml +27 -0
  78. data/test/asunit/core/AsUnitCoreTest.as +97 -0
  79. data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +88 -0
  80. data/test/asunit/framework/AssertEqualsArraysTest.as +102 -0
  81. data/test/asunit/framework/AssertTest.as +184 -0
  82. data/test/asunit/framework/AssertThrowsTest.as +42 -0
  83. data/test/asunit/framework/AsyncMethodTest.as +69 -0
  84. data/test/asunit/framework/AsyncTest.as +104 -0
  85. data/test/asunit/framework/CallbackBridgeTest.as +73 -0
  86. data/test/asunit/framework/InjectionDelegateTest.as +79 -0
  87. data/test/asunit/framework/MockData.xml +8 -0
  88. data/test/asunit/framework/NestedSuiteIteratorTest.as +59 -0
  89. data/test/asunit/framework/ProceedOnEventTest.as +109 -0
  90. data/test/asunit/framework/ResultTest.as +92 -0
  91. data/test/asunit/framework/RunnerFactoryTest.as +54 -0
  92. data/test/asunit/framework/SuiteIteratorTest.as +67 -0
  93. data/test/asunit/framework/TestCaseMock.as +24 -0
  94. data/test/asunit/framework/TestIteratorIgnoredMethodTest.as +62 -0
  95. data/test/asunit/framework/TestIteratorMethodByNameTest.as +50 -0
  96. data/test/asunit/framework/TestIteratorMultiMethodTest.as +186 -0
  97. data/test/asunit/framework/TestIteratorOrderedTestMethodTest.as +57 -0
  98. data/test/asunit/framework/TestIteratorSingleMethodTest.as +56 -0
  99. data/test/asunit/framework/VisualTestCaseTest.as +43 -0
  100. data/test/asunit/framework/assertAssertionFailed.as +19 -0
  101. data/test/asunit/printers/TextPrinterTest.as +122 -0
  102. data/test/asunit/runners/LegacyRunnerTest.as +40 -0
  103. data/test/asunit/runners/SuiteRunnerTest.as +40 -0
  104. data/test/asunit/runners/TestRunnerAsyncMethodTest.as +107 -0
  105. data/test/asunit/runners/TestRunnerErrorMethodTest.as +56 -0
  106. data/test/asunit/runners/TestRunnerExpectsErrorTest.as +98 -0
  107. data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +42 -0
  108. data/test/asunit/runners/TestRunnerTest.as +171 -0
  109. data/test/asunit/support/AnnotatedSubClass.as +18 -0
  110. data/test/asunit/support/AnnotatedSuperClass.as +15 -0
  111. data/test/asunit/support/CustomParameters.as +13 -0
  112. data/test/asunit/support/CustomTestRunner.as +22 -0
  113. data/test/asunit/support/DoubleFailSuite.as +8 -0
  114. data/test/asunit/support/DoubleNestedSuite.as +14 -0
  115. data/test/asunit/support/ErrorInMethod.as +11 -0
  116. data/test/asunit/support/FailAssertEquals.as +29 -0
  117. data/test/asunit/support/FailAssertTrue.as +28 -0
  118. data/test/asunit/support/FakeObserver.as +42 -0
  119. data/test/asunit/support/FakeRunner.as +32 -0
  120. data/test/asunit/support/IgnoredMethod.as +26 -0
  121. data/test/asunit/support/InjectTimeoutOnAsync.as +14 -0
  122. data/test/asunit/support/InjectionFailure.as +18 -0
  123. data/test/asunit/support/InjectionVerification.as +69 -0
  124. data/test/asunit/support/LegacyTestCase.as +38 -0
  125. data/test/asunit/support/MultiMethod.as +77 -0
  126. data/test/asunit/support/OrderedTestMethod.as +36 -0
  127. data/test/asunit/support/RunWithButNoType.as +14 -0
  128. data/test/asunit/support/RunWithSuiteButNoType.as +11 -0
  129. data/test/asunit/support/SingleErrorSuite.as +7 -0
  130. data/test/asunit/support/SingleSuccessSuite.as +7 -0
  131. data/test/asunit/support/SucceedAssertTrue.as +31 -0
  132. data/test/asunit/support/SuiteOfTwoSuites.as +8 -0
  133. data/test/asunit/support/SuiteWithCustomRunner.as +12 -0
  134. data/test/asunit/support/SuiteWithOneCustomChildSuite.as +10 -0
  135. data/test/asunit/support/TestForFakeRunner.as +14 -0
  136. data/test/asunit/util/ArrayIteratorTest.as +65 -0
  137. data/vendor/as3reflection/README +7 -0
  138. data/vendor/as3reflection/p2/reflect/Reflection.as +417 -0
  139. data/vendor/as3reflection/p2/reflect/ReflectionAccessor.as +14 -0
  140. data/vendor/as3reflection/p2/reflect/ReflectionBase.as +52 -0
  141. data/vendor/as3reflection/p2/reflect/ReflectionMember.as +16 -0
  142. data/vendor/as3reflection/p2/reflect/ReflectionMetaData.as +69 -0
  143. data/vendor/as3reflection/p2/reflect/ReflectionMethod.as +36 -0
  144. data/vendor/as3reflection/p2/reflect/ReflectionMethodParameter.as +19 -0
  145. data/vendor/as3reflection/p2/reflect/ReflectionVariable.as +15 -0
  146. data/vendor/as3reflection/p2/reflect/findFirst.as +14 -0
  147. data/vendor/generators/suite/USAGE +0 -0
  148. data/vendor/generators/suite/suite_generator.rb +17 -0
  149. data/vendor/generators/suite/templates/TestSuite.as +17 -0
  150. metadata +216 -0
@@ -0,0 +1,21 @@
1
+ package asunit.core {
2
+
3
+ import asunit.printers.FlashDevelopPrinter;
4
+
5
+ import flash.system.fscommand;
6
+
7
+ public class FlashDevelopCore extends TextCore {
8
+
9
+ override protected function initializeObservers():void {
10
+ super.initializeObservers();
11
+ addObserver(new FlashDevelopPrinter());
12
+ }
13
+
14
+ override protected function onRunCompleted():void {
15
+ super.onRunCompleted();
16
+ fscommand('quit'); // fails silently if not in debug player
17
+ //System.exit(0); // generates SecurityError if not in debug player
18
+ }
19
+ }
20
+ }
21
+
@@ -0,0 +1,54 @@
1
+ package asunit.core {
2
+
3
+ import asunit.printers.TextPrinter;
4
+
5
+ import flash.display.DisplayObjectContainer;
6
+
7
+ /**
8
+ * TextCore is just a simple helper class that
9
+ * configures the base class AsUnitCore to use the
10
+ * standard TextPrinter.
11
+ *
12
+ * The main idea is that you may want a completely
13
+ * different text output without the default TextPrinter,
14
+ * and if that's the case, you can go ahead and
15
+ * instantiate AsUnitCore and configure it however you
16
+ * wish.
17
+ */
18
+ public class TextCore extends AsUnitCore {
19
+
20
+ private var textPrinter:TextPrinter;
21
+
22
+ override protected function initializeObservers():void {
23
+ super.initializeObservers();
24
+
25
+ textPrinter = new TextPrinter();
26
+ addObserver(textPrinter);
27
+ }
28
+
29
+ /* Delegate some configuration to the TextPrinter */
30
+ public function set displayPerformanceDetails(show:Boolean):void {
31
+ textPrinter.displayPerformanceDetails = show;
32
+ }
33
+
34
+ public function get displayPerformanceDetails():Boolean {
35
+ return textPrinter.displayPerformanceDetails;
36
+ }
37
+
38
+ public function set traceOnComplete(should:Boolean):void {
39
+ textPrinter.traceOnComplete = should;
40
+ }
41
+
42
+ public function get traceOnComplete():Boolean {
43
+ return textPrinter.traceOnComplete;
44
+ }
45
+
46
+
47
+ override public function set visualContext(context:DisplayObjectContainer):void {
48
+ super.visualContext = context;
49
+ // Add the TextPrinter to the Display List:
50
+ visualContext.addChild(textPrinter);
51
+ }
52
+ }
53
+ }
54
+
@@ -0,0 +1,10 @@
1
+ package asunit.errors {
2
+
3
+ public class AbstractError extends Error {
4
+
5
+ public function AbstractError(message:String) {
6
+ super(message);
7
+ name = "AbstractError";
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ package asunit.errors {
2
+
3
+ public class AssertionFailedError extends Error {
4
+
5
+ public function AssertionFailedError(message:String) {
6
+ super(message);
7
+ name = "AssertionFailedError";
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ package asunit.errors {
2
+
3
+ public class ClassNotFoundError extends Error {
4
+
5
+ public function ClassNotFoundError(message:String) {
6
+ super(message);
7
+ name = "ClassNotFoundError";
8
+ }
9
+ }
10
+ }
11
+
@@ -0,0 +1,10 @@
1
+ package asunit.errors {
2
+
3
+ public class InstanceNotFoundError extends Error {
4
+
5
+ public function InstanceNotFoundError(message:String) {
6
+ super(message);
7
+ name = "InstanceNotFoundError";
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ package asunit.errors {
2
+
3
+ public class UnimplementedFeatureError extends Error {
4
+
5
+ public function UnimplementedFeatureError(message:String) {
6
+ super(message);
7
+ name = "UnimplementedFeatureError";
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ package asunit.errors {
2
+
3
+ public class UsageError extends Error {
4
+
5
+ public function UsageError(message:String) {
6
+ super(message);
7
+ name = "UsageError";
8
+ }
9
+ }
10
+ }
11
+
@@ -0,0 +1,27 @@
1
+ package asunit.events {
2
+
3
+ import asunit.framework.TimeoutCommand;
4
+
5
+ import flash.events.Event;
6
+
7
+ public class TimeoutCommandEvent extends Event {
8
+ public static const ADDED:String = 'added';
9
+ public static const CALLED:String = 'called';
10
+ public static const TIMED_OUT:String = 'timedOut';
11
+
12
+ public var command:TimeoutCommand;
13
+
14
+ public function TimeoutCommandEvent(type:String, command:TimeoutCommand, bubbles:Boolean=false, cancelable:Boolean=false) {
15
+ super(type, bubbles, cancelable);
16
+ this.command = command;
17
+ }
18
+
19
+ public override function clone():Event {
20
+ return new TimeoutCommandEvent(type, command, bubbles, cancelable);
21
+ }
22
+
23
+ public override function toString():String {
24
+ return formatToString("TimeoutCommandEvent", "command", "type", "bubbles", "cancelable", "eventPhase");
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,408 @@
1
+ package asunit.framework {
2
+ import asunit.errors.AssertionFailedError;
3
+
4
+ import flash.utils.getQualifiedClassName;
5
+
6
+ import flash.errors.IllegalOperationError;
7
+ import flash.events.EventDispatcher;
8
+
9
+ /**
10
+ * A set of assert methods. Messages are only displayed when an assert fails.
11
+ */
12
+
13
+ public class Assert extends EventDispatcher {
14
+ /**
15
+ * Protect constructor since it is a static only class
16
+ */
17
+ public function Assert() {
18
+ }
19
+
20
+ /**
21
+ * Asserts that a condition is true. If it isn't it throws
22
+ * an AssertionFailedError with the given message.
23
+ */
24
+ static public function assertTrue(...args:Array):void {
25
+ var message:String;
26
+ var actual:Object;
27
+
28
+ if(args.length == 1) {
29
+ message = "";
30
+ actual = args[0];
31
+ }
32
+ else if(args.length == 2) {
33
+ message = args[0];
34
+ actual = args[1];
35
+ }
36
+ else {
37
+ throw new IllegalOperationError("Invalid argument count");
38
+ }
39
+
40
+ if(!actual) {
41
+ throw new AssertionFailedError(format(message, true, actual));
42
+ }
43
+ }
44
+ /**
45
+ * Asserts that a condition is false. If it isn't it throws
46
+ * an AssertionFailedError with the given message.
47
+ */
48
+ static public function assertFalse(...args:Array):void {
49
+ var message:String;
50
+ var actual:Object;
51
+
52
+ if(args.length == 1) {
53
+ message = "";
54
+ actual = args[0];
55
+ }
56
+ else if(args.length == 2) {
57
+ message = args[0];
58
+ actual = args[1];
59
+ }
60
+ else {
61
+ throw new IllegalOperationError("Invalid argument count");
62
+ }
63
+
64
+ if(actual) {
65
+ throw new AssertionFailedError(format(message, false, actual));
66
+ }
67
+ }
68
+ /**
69
+ * Fails a test with the given message.
70
+ *
71
+ * @example This method can be called anytime you want to break out and fail
72
+ * the current test.
73
+ *
74
+ * <listing>
75
+ * public function testSomething():void {
76
+ * var instance:MyClass = new MyClass();
77
+ * if(instance.foo()) {
78
+ * fail('The foo should not have been there');
79
+ * }
80
+ * }
81
+ * </listing>
82
+ */
83
+ static public function fail(message:String):void {
84
+ throw new AssertionFailedError(message);
85
+ }
86
+
87
+ /**
88
+ * Asserts that the provided block throws an exception that matches
89
+ * the type provided.
90
+ *
91
+ * <listing>
92
+ * public function testFailingCode():void {
93
+ * assertThrows(CustomError, function():void {
94
+ * var instance:Sprite = new Sprite();
95
+ * instance.callMethodThatThrows();
96
+ * });
97
+ * }
98
+ * </listing>
99
+ **/
100
+ static public function assertThrows(errorType:Class, block:Function):void {
101
+ try {
102
+ block.call();
103
+ }
104
+ catch(e:Error) {
105
+ if(!(e is errorType)) {
106
+ throw new AssertionFailedError("expected error type:<" + getQualifiedClassName(errorType)
107
+ +"> but was:<" + getQualifiedClassName(e) + ">");
108
+ }
109
+ return;
110
+ }
111
+ throw new AssertionFailedError("expected error type:<" + getQualifiedClassName(errorType) + "> but none was thrown." );
112
+ }
113
+
114
+ /**
115
+ * Asserts that two objects are equal. If they are not
116
+ * an AssertionFailedError is thrown with the given message.
117
+ *
118
+ * This assertion should be (by far) the one you use the most.
119
+ * It automatically provides useful information about what
120
+ * the failing values were.
121
+ *
122
+ * <listing>
123
+ * public function testNames():void {
124
+ * var name1:String = "Federico Aubele";
125
+ * var name2:String = "Frederico Aubele";
126
+ *
127
+ * assertEquals(name1, name2);
128
+ * }
129
+ * </listing>
130
+ */
131
+ static public function assertEquals(...args:Array):void {
132
+ var message:String;
133
+ var expected:Object;
134
+ var actual:Object;
135
+
136
+ if(args.length == 2) {
137
+ message = "";
138
+ expected = args[0];
139
+ actual = args[1];
140
+ }
141
+ else if(args.length == 3) {
142
+ message = args[0];
143
+ expected = args[1];
144
+ actual = args[2];
145
+ }
146
+ else {
147
+ throw new IllegalOperationError("Invalid argument count");
148
+ }
149
+
150
+ if(expected == null && actual == null) {
151
+ return;
152
+ }
153
+
154
+ try {
155
+ if(expected != null && expected.equals(actual)) {
156
+ return;
157
+ }
158
+ }
159
+ catch(e:Error) {
160
+ if(expected != null && expected == actual) {
161
+ return;
162
+ }
163
+ }
164
+
165
+ throw new AssertionFailedError(format(message, expected, actual));
166
+ }
167
+ /**
168
+ * Asserts that an object isn't null. If it is
169
+ * an AssertionFailedError is thrown with the given message.
170
+ */
171
+ static public function assertNotNull(...args:Array):void {
172
+ var message:String;
173
+ var actual:Object;
174
+
175
+ if(args.length == 1) {
176
+ message = "";
177
+ actual = args[0];
178
+ }
179
+ else if(args.length == 2) {
180
+ message = args[0] + " ";
181
+ actual = args[1];
182
+ }
183
+ else {
184
+ throw new IllegalOperationError("Invalid argument count");
185
+ }
186
+
187
+ if(actual == null) {
188
+ throw new AssertionFailedError(message + "expected not null but was:<" + actual + ">");
189
+ }
190
+ }
191
+ /**
192
+ * Asserts that an object is null. If it is not
193
+ * an AssertionFailedError is thrown with the given message.
194
+ */
195
+ static public function assertNull(...args:Array):void {
196
+ var message:String;
197
+ var actual:Object;
198
+
199
+ if(args.length == 1) {
200
+ message = "";
201
+ actual = args[0];
202
+ }
203
+ else if(args.length == 2) {
204
+ message = args[0];
205
+ actual = args[1];
206
+ }
207
+ else {
208
+ throw new IllegalOperationError("Invalid argument count");
209
+ }
210
+
211
+ if(actual != null) {
212
+ throw new AssertionFailedError(format(message, null, actual));
213
+ }
214
+ }
215
+ /**
216
+ * Asserts that two objects refer to the same object. If they are not
217
+ * an AssertionFailedError is thrown with the given message.
218
+ */
219
+ static public function assertSame(...args:Array):void {
220
+ var message:String;
221
+ var expected:Object;
222
+ var actual:Object;
223
+
224
+ if(args.length == 2) {
225
+ message = "";
226
+ expected = args[0];
227
+ actual = args[1];
228
+ }
229
+ else if(args.length == 3) {
230
+ message = args[0] + " ";
231
+ expected = args[1];
232
+ actual = args[2];
233
+ }
234
+ else {
235
+ throw new IllegalOperationError("Invalid argument count");
236
+ }
237
+
238
+ if(expected !== actual) {
239
+ throw new AssertionFailedError(message + "expected same as:<" + expected + "> but was:<" + actual + ">");
240
+ }
241
+ }
242
+ /**
243
+ * Asserts that two objects do not refer to the same object. If they do,
244
+ * an AssertionFailedError is thrown with the given message.
245
+ */
246
+ static public function assertNotSame(...args:Array):void {
247
+ var message:String;
248
+ var expected:Object;
249
+ var actual:Object;
250
+
251
+ if(args.length == 2) {
252
+ message = "";
253
+ expected = args[0];
254
+ actual = args[1];
255
+ }
256
+ else if(args.length == 3) {
257
+ message = args[0] + " ";
258
+ expected = args[1];
259
+ actual = args[2];
260
+ }
261
+ else {
262
+ throw new IllegalOperationError("Invalid argument count");
263
+ }
264
+
265
+ if(expected === actual) {
266
+ throw new AssertionFailedError(message + "expected not same but both were:<" + actual + ">");
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Asserts that two numerical values are equal within a tolerance range.
272
+ * If they are not an AssertionFailedError is thrown with the given message.
273
+ */
274
+ static public function assertEqualsFloat(...args:Array):void {
275
+ var message:String;
276
+ var expected:Number;
277
+ var actual:Number;
278
+ var tolerance:Number = 0;
279
+
280
+ if(args.length == 3) {
281
+ message = "";
282
+ expected = args[0];
283
+ actual = args[1];
284
+ tolerance = args[2];
285
+ }
286
+ else if(args.length == 4) {
287
+ message = args[0];
288
+ expected = args[1];
289
+ actual = args[2];
290
+ tolerance = args[3];
291
+ }
292
+ else {
293
+ throw new IllegalOperationError("Invalid argument count");
294
+ }
295
+ if (isNaN(tolerance)) tolerance = 0;
296
+ if(Math.abs(expected - actual) <= tolerance) {
297
+ return;
298
+ }
299
+ throw new AssertionFailedError(format(message, expected, actual));
300
+ }
301
+
302
+ /**
303
+ * Asserts that two arrays have the same length and contain the same
304
+ * objects in the same order. If the arrays are not equal by this
305
+ * definition an AssertionFailedError is thrown with the given message.
306
+ */
307
+ static public function assertEqualsArrays(...args:Array):void {
308
+ var message:String;
309
+ var expected:Array;
310
+ var actual:Array;
311
+
312
+ if(args.length == 2) {
313
+ message = "";
314
+ expected = args[0];
315
+ actual = args[1];
316
+ }
317
+ else if(args.length == 3) {
318
+ message = args[0];
319
+ expected = args[1];
320
+ actual = args[2];
321
+ }
322
+ else {
323
+ throw new IllegalOperationError("Invalid argument count");
324
+ }
325
+
326
+ if (expected == null && actual == null) {
327
+ return;
328
+ }
329
+ if ((expected == null && actual != null) || (expected != null && actual == null)) {
330
+ failNotEquals(message, expected, actual);
331
+ }
332
+ // from here on: expected != null && actual != null
333
+ if (expected.length != actual.length) {
334
+ failNotEquals(message, expected, actual);
335
+ }
336
+ for (var i : int = 0; i < expected.length; i++) {
337
+ assertEquals(expected[i], actual[i]);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Asserts that two arrays have the same length and contain the same
343
+ * objects. The order of the objects in the arrays is ignored. If they
344
+ * are not equal by this definition an AssertionFailedError is thrown
345
+ * with the given message.
346
+ */
347
+ static public function assertEqualsArraysIgnoringOrder(...args:Array):void {
348
+ var message:String;
349
+ var expected:Array;
350
+ var actual:Array;
351
+
352
+ if(args.length == 2) {
353
+ message = "";
354
+ expected = args[0];
355
+ actual = args[1];
356
+ }
357
+ else if(args.length == 3) {
358
+ message = args[0];
359
+ expected = args[1];
360
+ actual = args[2];
361
+ }
362
+ else {
363
+ throw new IllegalOperationError("Invalid argument count");
364
+ }
365
+
366
+ if (expected == null && actual == null) {
367
+ return;
368
+ }
369
+ if ((expected == null && actual != null) || (expected != null && actual == null)) {
370
+ failNotEquals(message, expected, actual);
371
+ }
372
+ // from here on: expected != null && actual != null
373
+ if (expected.length != actual.length) {
374
+ failNotEquals(message, expected, actual);
375
+ }
376
+ for (var i : int = 0; i < expected.length; i++) {
377
+ var foundMatch : Boolean = false;
378
+ var expectedMember : Object = expected[i];
379
+ for (var j : int = 0; j < actual.length; j++) {
380
+ var actualMember : Object = actual[j];
381
+ try {
382
+ assertEquals(expectedMember, actualMember);
383
+ foundMatch = true;
384
+ break;
385
+ }
386
+ catch (e : AssertionFailedError) {
387
+ // no match, try next
388
+ }
389
+ }
390
+ if (!foundMatch) {
391
+ failNotEquals("Found no match for " + expectedMember + ";", expected, actual);
392
+ }
393
+ }
394
+ }
395
+
396
+ static private function failNotEquals(message:String, expected:Object, actual:Object):void {
397
+ fail(format(message, expected, actual));
398
+ }
399
+
400
+ static private function format(message:String, expected:Object, actual:Object):String {
401
+ var formatted:String = "";
402
+ if(message != null) {
403
+ formatted = message + " ";
404
+ }
405
+ return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
406
+ }
407
+ }
408
+ }