Chromium Code Reviews| Index: pkg/testing/lib/src/expectation.dart |
| diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b61a59dd65718e96ec51b3279487f118bb0fc99e |
| --- /dev/null |
| +++ b/pkg/testing/lib/src/expectation.dart |
| @@ -0,0 +1,112 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE.md file. |
| + |
| +library testing.expectation; |
| + |
|
karlklose
2017/01/16 08:09:20
Please add some documentation that explains the di
ahe
2017/01/16 08:53:04
Done.
|
| +class Expectation { |
| + static const Expectation Pass = |
| + const Expectation("Pass", ExpectationGroup.Pass); |
| + |
| + static const Expectation Crash = |
| + const Expectation("Crash", ExpectationGroup.Crash); |
| + |
| + static const Expectation Timeout = |
| + const Expectation("Timeout", ExpectationGroup.Timeout); |
| + |
| + static const Expectation Fail = |
| + const Expectation("Fail", ExpectationGroup.Fail); |
| + |
| + static const Expectation Skip = |
| + const Expectation("Skip", ExpectationGroup.Skip); |
| + |
| + final String name; |
| + |
| + final ExpectationGroup group; |
| + |
| + const Expectation(this.name, this.group); |
| + |
| + String toString() => name; |
| +} |
| + |
| +class ExpectationSet { |
| + static const ExpectationSet Default = const ExpectationSet( |
| + const <String, Expectation>{ |
| + "pass": Expectation.Pass, |
| + "crash": Expectation.Crash, |
| + "timeout": Expectation.Timeout, |
| + "fail": Expectation.Fail, |
| + "skip": Expectation.Skip, |
| + "missingcompiletimeerror": |
| + const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), |
| + "missingruntimeerror": |
| + const Expectation("MissingRuntimeError", ExpectationGroup.Fail), |
| + }); |
| + |
| + final Map<String, Expectation> internalMap; |
| + |
| + const ExpectationSet(this.internalMap); |
| + |
| + operator[] (String name) { |
| + return internalMap[name.toLowerCase()] |
| + ?? (throw "No expectation named: '$name'."); |
| + } |
| + |
| + factory ExpectationSet.fromJsonList(List data) { |
| + Map<String, Expectation> internalMap = |
| + new Map<String, Expectation>.from(Default.internalMap); |
| + for (Map map in data) { |
| + String name; |
| + String group; |
| + map.forEach((String key, String value) { |
| + switch (key) { |
| + case "name": |
| + name = value; |
| + break; |
| + |
| + case "group": |
| + group = value; |
| + break; |
| + |
| + default: |
| + throw "Unrecoginized key: '$key' in '$map'."; |
| + } |
| + }); |
| + if (name == null) { |
| + throw "No name provided in '$map'"; |
| + } |
| + if (group == null) { |
| + throw "No group provided in '$map'"; |
| + } |
| + Expectation expectation = new Expectation(name, groupFromString(group)); |
| + name = name.toLowerCase(); |
| + if (internalMap.containsKey(name)) { |
| + throw "Duplicated expectation name: '$name'."; |
| + } |
| + internalMap[name] = expectation; |
| + } |
| + return new ExpectationSet(internalMap); |
| + } |
| +} |
| + |
| +enum ExpectationGroup { |
| + Crash, |
| + Fail, |
| + Meta, |
| + Pass, |
| + Skip, |
| + Timeout, |
| +} |
| + |
| +ExpectationGroup groupFromString(String name) { |
| + switch (name) { |
| + case "Crash": return ExpectationGroup.Crash; |
| + case "Fail": return ExpectationGroup.Fail; |
| + case "Meta": return ExpectationGroup.Meta; |
| + case "Pass": return ExpectationGroup.Pass; |
| + case "Skip": return ExpectationGroup.Skip; |
| + case "Timeout": return ExpectationGroup.Timeout; |
| + default: |
| + throw "Unrecoginized group: '$name'."; |
|
karlklose
2017/01/16 08:09:20
'Unrecoginized' -> 'Unrecognized'
ahe
2017/01/16 08:53:04
Done.
|
| + } |
| +} |