OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * A simple mocking/spy library. | 6 * A simple mocking/spy library. |
7 * | 7 * |
8 * To create a mock objects for some class T, create a new class using: | 8 * To create a mock objects for some class T, create a new class using: |
9 * | 9 * |
10 * class MockT extends Mock implements T {}; | 10 * class MockT extends Mock implements T {}; |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 // keep track of how many matching entries we can still add in the | 837 // keep track of how many matching entries we can still add in the |
838 // current segment (0 if we are doing doing following neighbors, until | 838 // current segment (0 if we are doing doing following neighbors, until |
839 // we get our first key match). | 839 // we get our first key match). |
840 List scratch = null; | 840 List scratch = null; |
841 int remainingCount = 0; | 841 int remainingCount = 0; |
842 if (isPreceding) { | 842 if (isPreceding) { |
843 scratch = new List(); | 843 scratch = new List(); |
844 remainingCount = logs.length; | 844 remainingCount = logs.length; |
845 } | 845 } |
846 | 846 |
847 var keyIterator = keys.logs.iterator(); | 847 var keyIterator = keys.logs.iterator; |
848 LogEntry keyEntry = keyIterator.next(); | 848 keyIterator.moveNext(); |
| 849 LogEntry keyEntry = keyIterator.current; |
849 MatchState matchState = new MatchState(); | 850 MatchState matchState = new MatchState(); |
850 | 851 |
851 for (LogEntry logEntry in logs) { | 852 for (LogEntry logEntry in logs) { |
852 // If we have a log entry match, copy the saved matches from the | 853 // If we have a log entry match, copy the saved matches from the |
853 // scratch buffer into the return list, as well as the matching entry, | 854 // scratch buffer into the return list, as well as the matching entry, |
854 // if appropriate, and reset the scratch buffer. Continue processing | 855 // if appropriate, and reset the scratch buffer. Continue processing |
855 // from the next key entry. | 856 // from the next key entry. |
856 if (keyEntry == logEntry) { | 857 if (keyEntry == logEntry) { |
857 if (scratch != null) { | 858 if (scratch != null) { |
858 int numToCopy = scratch.length; | 859 int numToCopy = scratch.length; |
859 if (distance > 0 && distance < numToCopy) { | 860 if (distance > 0 && distance < numToCopy) { |
860 numToCopy = distance; | 861 numToCopy = distance; |
861 } | 862 } |
862 for (var i = scratch.length - numToCopy; i < scratch.length; i++) { | 863 for (var i = scratch.length - numToCopy; i < scratch.length; i++) { |
863 rtn.logs.add(scratch[i]); | 864 rtn.logs.add(scratch[i]); |
864 } | 865 } |
865 scratch.clear(); | 866 scratch.clear(); |
866 } else { | 867 } else { |
867 remainingCount = distance > 0 ? distance : logs.length; | 868 remainingCount = distance > 0 ? distance : logs.length; |
868 } | 869 } |
869 if (includeKeys) { | 870 if (includeKeys) { |
870 rtn.logs.add(keyEntry); | 871 rtn.logs.add(keyEntry); |
871 } | 872 } |
872 if (keyIterator.hasNext) { | 873 if (keyIterator.moveNext()) { |
873 keyEntry = keyIterator.next(); | 874 keyEntry = keyIterator.current; |
874 } else if (isPreceding) { // We're done. | 875 } else if (isPreceding) { // We're done. |
875 break; | 876 break; |
876 } | 877 } |
877 } else if (remainingCount > 0 && | 878 } else if (remainingCount > 0 && |
878 mockNameFilter.matches(logEntry.mockName, matchState) && | 879 mockNameFilter.matches(logEntry.mockName, matchState) && |
879 logFilter(logEntry)) { | 880 logFilter(logEntry)) { |
880 if (scratch != null) { | 881 if (scratch != null) { |
881 scratch.add(logEntry); | 882 scratch.add(logEntry); |
882 } else { | 883 } else { |
883 rtn.logs.add(logEntry); | 884 rtn.logs.add(logEntry); |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 | 1454 |
1454 /** Clear the behaviors for the Mock. */ | 1455 /** Clear the behaviors for the Mock. */ |
1455 void resetBehavior() => _behaviors.clear(); | 1456 void resetBehavior() => _behaviors.clear(); |
1456 | 1457 |
1457 /** Clear the logs for the Mock. */ | 1458 /** Clear the logs for the Mock. */ |
1458 void clearLogs() { | 1459 void clearLogs() { |
1459 if (log != null) { | 1460 if (log != null) { |
1460 if (name == null) { // This log is not shared. | 1461 if (name == null) { // This log is not shared. |
1461 log.logs.clear(); | 1462 log.logs.clear(); |
1462 } else { // This log may be shared. | 1463 } else { // This log may be shared. |
1463 log.logs = log.logs.filter((e) => e.mockName != name); | 1464 log.logs = log.logs.where((e) => e.mockName != name).toList(); |
1464 } | 1465 } |
1465 } | 1466 } |
1466 } | 1467 } |
1467 | 1468 |
1468 /** Clear both logs and behavior. */ | 1469 /** Clear both logs and behavior. */ |
1469 void reset() { | 1470 void reset() { |
1470 resetBehavior(); | 1471 resetBehavior(); |
1471 clearLogs(); | 1472 clearLogs(); |
1472 } | 1473 } |
1473 } | 1474 } |
OLD | NEW |