Chromium Code Reviews| 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 /// Helpers for defining input/output based unittests through (constant) data. | |
| 6 | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 | |
| 9 /// A unittest group with a name and a list of input/output results. | |
| 10 class Group { | |
| 11 final String name; | |
| 12 final List<Result> results; | |
| 13 | |
| 14 const Group(this.name, this.results); | |
| 15 } | |
| 16 | |
| 17 /// A input/output pair that defines the expected [output] of when processing | |
| 18 /// the [input]. | |
| 19 class Result { | |
|
Paul Berry
2014/10/22 13:03:50
The name "Result" is confusing because it's not th
Johnni Winther
2014/10/23 06:44:02
Done.
| |
| 20 final String input; | |
| 21 final String output; | |
| 22 | |
| 23 const Result(this.input, this.output); | |
| 24 } | |
| 25 | |
| 26 typedef TestGroup(Group group, CheckResult check); | |
| 27 typedef CheckResult(Result result); | |
|
Paul Berry
2014/10/22 13:03:50
Similarly, "CheckResult" sounds like a function wh
Johnni Winther
2014/10/23 06:44:02
Done.
| |
| 28 | |
| 29 /// Test [data] using [testGroup] and [check]. | |
| 30 void performTests(List<Group> data, TestGroup testGroup, CheckResult check) { | |
| 31 for (Group group in data) { | |
| 32 testGroup(group, check); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 /// Test group using unittest. | |
| 37 unittester(Group group, CheckResult check) { | |
| 38 test(group.name, () { | |
| 39 for (Result result in group.results) { | |
| 40 check(result); | |
| 41 } | |
| 42 }); | |
| 43 } | |
| OLD | NEW |