Index: pkg/unittest/lib/mock.dart |
=================================================================== |
--- pkg/unittest/lib/mock.dart (revision 22128) |
+++ pkg/unittest/lib/mock.dart (working copy) |
@@ -1236,8 +1236,12 @@ |
/** The mock name. Needed if the log is shared; optional otherwise. */ |
final String name; |
- /** The set of [Behavior]s supported. */ |
- Map<String,Behavior> _behaviors; |
+ /** |
+ * The set of [Behavior]s supported. Behaviors are ordered, but are |
+ * also keyed, so we keep a hash table of indices pointing to a List. |
+ */ |
+ Map<String,int> _behaviorIndices; |
+ List<Behavior> _behaviors; |
/** The [log] of calls made. Only used if [name] is null. */ |
LogEntryList log; |
@@ -1262,7 +1266,8 @@ |
*/ |
Mock() : _throwIfNoBehavior = false, log = null, name = null { |
logging = true; |
- _behaviors = new Map<String,Behavior>(); |
+ _behaviorIndices = new Map<String,int>(); |
Siggi Cherem (dart-lang)
2013/04/30 03:25:31
what about using LinkedHashMap instead of Map?
Th
gram
2013/04/30 16:53:39
Done.
|
+ _behaviors = new List<Behavior>(); |
} |
/** |
@@ -1281,7 +1286,8 @@ |
throw new Exception("Mocks with shared logs must have a name."); |
} |
logging = enableLogging; |
- _behaviors = new Map<String,Behavior>(); |
+ _behaviorIndices = new Map<String,int>(); |
+ _behaviors = new List<Behavior>(); |
} |
/** |
@@ -1295,12 +1301,13 @@ |
*/ |
Behavior when(CallMatcher logFilter) { |
String key = logFilter.toString(); |
- if (!_behaviors.containsKey(key)) { |
+ if (!_behaviorIndices.containsKey(key)) { |
Behavior b = new Behavior(logFilter); |
- _behaviors[key] = b; |
+ _behaviorIndices[key] = _behaviors.length; |
+ _behaviors.add(b); |
return b; |
} else { |
- return _behaviors[key]; |
+ return _behaviors[_behaviorIndices[key]]; |
} |
} |
@@ -1325,8 +1332,8 @@ |
} |
bool matchedMethodName = false; |
MatchState matchState = new MatchState(); |
- for (String k in _behaviors.keys) { |
- Behavior b = _behaviors[k]; |
+ for (var i = 0; i < _behaviors.length; i++) { |
+ Behavior b = _behaviors[i]; |
if (b.matcher.nameFilter.matches(method, matchState)) { |
matchedMethodName = true; |
} |
@@ -1486,7 +1493,10 @@ |
arg5, arg6, arg7, arg8, arg9)); |
/** Clear the behaviors for the Mock. */ |
- void resetBehavior() => _behaviors.clear(); |
+ void resetBehavior() { |
+ _behaviorIndices.clear(); |
+ _behaviors.clear(); |
+ } |
/** Clear the logs for the Mock. */ |
void clearLogs() { |