Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.backend.group; | 5 library test.backend.group; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'metadata.dart'; | 9 import 'metadata.dart'; |
| 10 import 'operating_system.dart'; | 10 import 'operating_system.dart'; |
| 11 import 'suite_entry.dart'; | 11 import 'group_entry.dart'; |
| 12 import 'test.dart'; | 12 import 'test.dart'; |
| 13 import 'test_platform.dart'; | 13 import 'test_platform.dart'; |
| 14 | 14 |
| 15 /// A group contains one or more tests and subgroups. | 15 /// A group contains one or more tests and subgroups. |
| 16 /// | 16 /// |
| 17 /// It includes metadata that applies to all contained tests. | 17 /// It includes metadata that applies to all contained tests. |
| 18 class Group implements SuiteEntry { | 18 class Group implements GroupEntry { |
| 19 final String name; | 19 final String name; |
| 20 | 20 |
| 21 final Metadata metadata; | 21 final Metadata metadata; |
| 22 | 22 |
| 23 /// The children of this group. | 23 /// The children of this group. |
| 24 final List<SuiteEntry> entries; | 24 final List<GroupEntry> entries; |
| 25 | 25 |
| 26 Group(this.name, this.metadata, Iterable<SuiteEntry> entries) | 26 /// Returns a new root-level group. |
| 27 : entries = new UnmodifiableListView<SuiteEntry>(entries.toList()); | 27 Group.root(Iterable<GroupEntry> entries, {Metadata metadata}) |
| 28 : this(null, entries, metadata: metadata); | |
| 29 | |
| 30 Group(this.name, Iterable<GroupEntry> entries, {Metadata metadata}) | |
| 31 : entries = new UnmodifiableListView<GroupEntry>(entries.toList()), | |
|
kevmoo
2015/10/07 00:59:51
using new List.unmodifiable(..) instead?
Copies e
nweiz
2015/10/07 19:22:18
Done.
| |
| 32 metadata = metadata == null ? new Metadata() : metadata; | |
| 28 | 33 |
| 29 Group forPlatform(TestPlatform platform, {OperatingSystem os}) { | 34 Group forPlatform(TestPlatform platform, {OperatingSystem os}) { |
| 30 if (!metadata.testOn.evaluate(platform, os: os)) return null; | 35 if (!metadata.testOn.evaluate(platform, os: os)) return null; |
| 31 var newMetadata = metadata.forPlatform(platform, os: os); | 36 var newMetadata = metadata.forPlatform(platform, os: os); |
| 32 var filtered = _map((entry) => entry.forPlatform(platform, os: os)); | 37 var filtered = _map((entry) => entry.forPlatform(platform, os: os)); |
| 33 if (filtered.isEmpty) return null; | 38 if (filtered.isEmpty) return null; |
| 34 return new Group(name, newMetadata, filtered); | 39 return new Group(name, filtered, metadata: newMetadata); |
| 35 } | 40 } |
| 36 | 41 |
| 37 Group filter(bool callback(Test test)) { | 42 Group filter(bool callback(Test test)) { |
| 38 var filtered = _map((entry) => entry.filter(callback)); | 43 var filtered = _map((entry) => entry.filter(callback)); |
| 39 if (filtered.isEmpty) return null; | 44 if (filtered.isEmpty) return null; |
| 40 return new Group(name, metadata, filtered); | 45 return new Group(name, filtered, metadata: metadata); |
| 41 } | 46 } |
| 42 | 47 |
| 43 /// Returns the entries of this group mapped using [callback]. | 48 /// Returns the entries of this group mapped using [callback]. |
| 44 /// | 49 /// |
| 45 /// Any `null` values returned by [callback] will be removed. | 50 /// Any `null` values returned by [callback] will be removed. |
| 46 List<SuiteEntry> _map(SuiteEntry callback(SuiteEntry entry)) { | 51 List<GroupEntry> _map(GroupEntry callback(GroupEntry entry)) { |
| 47 return entries | 52 return entries |
| 48 .map((entry) => callback(entry)) | 53 .map((entry) => callback(entry)) |
| 49 .where((entry) => entry != null) | 54 .where((entry) => entry != null) |
| 50 .toList(); | 55 .toList(); |
| 51 } | 56 } |
| 52 } | 57 } |
| OLD | NEW |