OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.expectation; | 5 library testing.expectation; |
6 | 6 |
7 /// An expectation represents the expected outcome of a test (or if it should | 7 /// An expectation represents the expected outcome of a test (or if it should |
8 /// be skipped). | 8 /// be skipped). |
9 /// | 9 /// |
10 /// An expectation belongs to a group, for example, [ExpectationGroup.Fail]. | 10 /// An expectation belongs to a group, for example, [ExpectationGroup.Fail]. |
(...skipping 20 matching lines...) Expand all Loading... |
31 final String name; | 31 final String name; |
32 | 32 |
33 final ExpectationGroup group; | 33 final ExpectationGroup group; |
34 | 34 |
35 const Expectation(this.name, this.group); | 35 const Expectation(this.name, this.group); |
36 | 36 |
37 String toString() => name; | 37 String toString() => name; |
38 } | 38 } |
39 | 39 |
40 class ExpectationSet { | 40 class ExpectationSet { |
41 static const ExpectationSet Default = const ExpectationSet( | 41 static const ExpectationSet Default = |
42 const <String, Expectation>{ | 42 const ExpectationSet(const <String, Expectation>{ |
43 "pass": Expectation.Pass, | 43 "pass": Expectation.Pass, |
44 "crash": Expectation.Crash, | 44 "crash": Expectation.Crash, |
45 "timeout": Expectation.Timeout, | 45 "timeout": Expectation.Timeout, |
46 "fail": Expectation.Fail, | 46 "fail": Expectation.Fail, |
47 "skip": Expectation.Skip, | 47 "skip": Expectation.Skip, |
48 "missingcompiletimeerror": | 48 "missingcompiletimeerror": |
49 const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), | 49 const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), |
50 "missingruntimeerror": | 50 "missingruntimeerror": |
51 const Expectation("MissingRuntimeError", ExpectationGroup.Fail), | 51 const Expectation("MissingRuntimeError", ExpectationGroup.Fail), |
52 }); | 52 }); |
53 | 53 |
54 final Map<String, Expectation> internalMap; | 54 final Map<String, Expectation> internalMap; |
55 | 55 |
56 const ExpectationSet(this.internalMap); | 56 const ExpectationSet(this.internalMap); |
57 | 57 |
58 operator[] (String name) { | 58 operator [](String name) { |
59 return internalMap[name.toLowerCase()] | 59 return internalMap[name.toLowerCase()] ?? |
60 ?? (throw "No expectation named: '$name'."); | 60 (throw "No expectation named: '$name'."); |
61 } | 61 } |
62 | 62 |
63 factory ExpectationSet.fromJsonList(List data) { | 63 factory ExpectationSet.fromJsonList(List data) { |
64 Map<String, Expectation> internalMap = | 64 Map<String, Expectation> internalMap = |
65 new Map<String, Expectation>.from(Default.internalMap); | 65 new Map<String, Expectation>.from(Default.internalMap); |
66 for (Map map in data) { | 66 for (Map map in data) { |
67 String name; | 67 String name; |
68 String group; | 68 String group; |
69 map.forEach((String key, String value) { | 69 map.forEach((String key, String value) { |
70 switch (key) { | 70 switch (key) { |
(...skipping 30 matching lines...) Expand all Loading... |
101 Crash, | 101 Crash, |
102 Fail, | 102 Fail, |
103 Meta, | 103 Meta, |
104 Pass, | 104 Pass, |
105 Skip, | 105 Skip, |
106 Timeout, | 106 Timeout, |
107 } | 107 } |
108 | 108 |
109 ExpectationGroup groupFromString(String name) { | 109 ExpectationGroup groupFromString(String name) { |
110 switch (name) { | 110 switch (name) { |
111 case "Crash": return ExpectationGroup.Crash; | 111 case "Crash": |
112 case "Fail": return ExpectationGroup.Fail; | 112 return ExpectationGroup.Crash; |
113 case "Meta": return ExpectationGroup.Meta; | 113 case "Fail": |
114 case "Pass": return ExpectationGroup.Pass; | 114 return ExpectationGroup.Fail; |
115 case "Skip": return ExpectationGroup.Skip; | 115 case "Meta": |
116 case "Timeout": return ExpectationGroup.Timeout; | 116 return ExpectationGroup.Meta; |
| 117 case "Pass": |
| 118 return ExpectationGroup.Pass; |
| 119 case "Skip": |
| 120 return ExpectationGroup.Skip; |
| 121 case "Timeout": |
| 122 return ExpectationGroup.Timeout; |
117 default: | 123 default: |
118 throw "Unrecognized group: '$name'."; | 124 throw "Unrecognized group: '$name'."; |
119 } | 125 } |
120 } | 126 } |
OLD | NEW |