Chromium Code Reviews| Index: pkg/analyzer2dart/test/test_helper.dart |
| diff --git a/pkg/analyzer2dart/test/test_helper.dart b/pkg/analyzer2dart/test/test_helper.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..75565775f1d68f7d1b5cc551a9b07d4b766477ba |
| --- /dev/null |
| +++ b/pkg/analyzer2dart/test/test_helper.dart |
| @@ -0,0 +1,43 @@ |
| +// Copyright (c) 2014, 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 file. |
| + |
| +/// Helpers for defining input/output based unittests through (constant) data. |
| + |
| +import 'package:unittest/unittest.dart'; |
| + |
| +/// A unittest group with a name and a list of input/output results. |
| +class Group { |
| + final String name; |
| + final List<Result> results; |
| + |
| + const Group(this.name, this.results); |
| +} |
| + |
| +/// A input/output pair that defines the expected [output] of when processing |
| +/// the [input]. |
| +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.
|
| + final String input; |
| + final String output; |
| + |
| + const Result(this.input, this.output); |
| +} |
| + |
| +typedef TestGroup(Group group, CheckResult check); |
| +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.
|
| + |
| +/// Test [data] using [testGroup] and [check]. |
| +void performTests(List<Group> data, TestGroup testGroup, CheckResult check) { |
| + for (Group group in data) { |
| + testGroup(group, check); |
| + } |
| +} |
| + |
| +/// Test group using unittest. |
| +unittester(Group group, CheckResult check) { |
| + test(group.name, () { |
| + for (Result result in group.results) { |
| + check(result); |
| + } |
| + }); |
| +} |