Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: lib/src/backend/platform_selector.dart

Issue 1027193004: Respect top-level @TestOn declarations. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Add another test. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/backend/platform_selector.dart
diff --git a/lib/src/backend/platform_selector.dart b/lib/src/backend/platform_selector.dart
index 46e4db27aabc796340893b94f8db261585d2ac9e..d614dec3f44b2e79b287e734c9b56809057606a2 100644
--- a/lib/src/backend/platform_selector.dart
+++ b/lib/src/backend/platform_selector.dart
@@ -23,25 +23,57 @@ final _validVariables =
/// and browsers.
///
/// The syntax is mostly Dart's expression syntax restricted to boolean
-/// operations. See the README for full details.
-class PlatformSelector {
- /// The parsed AST.
- final Node _selector;
+/// operations. See [the README][] for full details.
+///
+/// [the README]: https://github.com/dart-lang/unittest/#platform-selector-syntax
kevmoo 2015/03/25 08:06:55 nit: provide a shortname for the URL so it doesn't
nweiz 2015/03/25 22:40:55 I don't think there's any reason to try to shorten
+abstract class PlatformSelector {
+ /// A selector that declares that a test can be run on all platforms.
+ ///
+ /// This isn't representable in the platform selector syntax but it is the
+ /// default selector.
+ static const all = const _AllPlatforms();
/// Parses [selector].
///
/// This will throw a [SourceSpanFormatException] if the selector is
/// malformed or if it uses an undefined variable.
- PlatformSelector.parse(String selector)
- : _selector = new Parser(selector).parse() {
- _selector.accept(const _VariableValidator());
- }
+ factory PlatformSelector.parse(String selector) =>
+ new _PlatformSelector.parse(selector);
/// Returns whether the selector matches the given [platform] and [os].
///
/// [os] defaults to [OperatingSystem.none].
+ bool evaluate(TestPlatform platform, {OperatingSystem os});
+}
+
+/// The concrete implementation of a [PlatformSelector] parsed from a string.
+///
+/// This is separate from [PlatformSelector] so that [_AllPlatforms] can
+/// implement [PlatformSelector] without having to implement private members.
+class _PlatformSelector implements PlatformSelector{
+ /// The parsed AST.
+ final Node _selector;
+
+ _PlatformSelector.parse(String selector)
+ : _selector = new Parser(selector).parse() {
+ _selector.accept(const _VariableValidator());
+ }
+
+ _PlatformSelector(this._selector);
+
bool evaluate(TestPlatform platform, {OperatingSystem os}) =>
_selector.accept(new Evaluator(platform, os: os));
+
+ String toString() => _selector.toString();
+}
+
+/// A selector that matches all platforms.
+class _AllPlatforms implements PlatformSelector {
+ const _AllPlatforms();
+
+ bool evaluate(TestPlatform platform, {OperatingSystem os}) => true;
+
+ String toString() => "*";
}
/// An AST visitor that ensures that all variables are valid.

Powered by Google App Engine
This is Rietveld 408576698