OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library mock.log_entry; | |
6 | |
7 import 'package:matcher/matcher.dart'; | |
8 | |
9 import 'action.dart'; | |
10 import 'util.dart'; | |
11 | |
12 /** | |
13 * Every call to a [Mock] object method is logged. The logs are | |
14 * kept in instances of [LogEntry]. | |
15 */ | |
16 class LogEntry { | |
17 /** The time of the event. */ | |
18 DateTime time; | |
19 | |
20 /** The mock object name, if any. */ | |
21 final String mockName; | |
22 | |
23 /** The method name. */ | |
24 final String methodName; | |
25 | |
26 /** The parameters. */ | |
27 final List args; | |
28 | |
29 /** The behavior that resulted. */ | |
30 final Action action; | |
31 | |
32 /** The value that was returned (if no throw). */ | |
33 final value; | |
34 | |
35 LogEntry(this.mockName, this.methodName, | |
36 this.args, this.action, [this.value]) { | |
37 time = new DateTime.now(); | |
38 } | |
39 | |
40 String _pad2(int val) => (val >= 10 ? '$val' : '0$val'); | |
41 | |
42 String toString([DateTime baseTime]) { | |
43 Description d = new StringDescription(); | |
44 if (baseTime == null) { | |
45 // Show absolute time. | |
46 d.add('${time.hour}:${_pad2(time.minute)}:' | |
47 '${_pad2(time.second)}.${time.millisecond}> '); | |
48 } else { | |
49 // Show relative time. | |
50 int delta = time.millisecondsSinceEpoch - baseTime.millisecondsSinceEpoch; | |
51 int secs = delta ~/ 1000; | |
52 int msecs = delta % 1000; | |
53 d.add('$secs.$msecs> '); | |
54 } | |
55 d.add('${qualifiedName(mockName, methodName)}('); | |
56 if (args != null) { | |
57 for (var i = 0; i < args.length; i++) { | |
58 if (i != 0) d.add(', '); | |
59 d.addDescriptionOf(args[i]); | |
60 } | |
61 } | |
62 d.add(') ${action == Action.THROW ? "threw" : "returned"} '); | |
63 d.addDescriptionOf(value); | |
64 return d.toString(); | |
65 } | |
66 } | |
OLD | NEW |