| 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 import 'package:boolean_selector/boolean_selector.dart'; | 5 import 'package:boolean_selector/boolean_selector.dart'; |
| 6 import 'package:source_span/source_span.dart'; | 6 import 'package:source_span/source_span.dart'; |
| 7 | 7 |
| 8 import 'operating_system.dart'; | 8 import 'operating_system.dart'; |
| 9 import 'test_platform.dart'; | 9 import 'test_platform.dart'; |
| 10 | 10 |
| 11 /// The set of all valid variable names. | 11 /// The set of all valid variable names. |
| 12 final _validVariables = | 12 final _validVariables = |
| 13 new Set<String>.from(["posix", "dart-vm", "browser", "js", "blink"]) | 13 new Set<String>.from(["posix", "dart-vm", "browser", "js", "blink"]) |
| 14 ..addAll(TestPlatform.all.map((platform) => platform.identifier)) | 14 ..addAll(TestPlatform.all.map((platform) => platform.identifier)) |
| 15 ..addAll(OperatingSystem.all.map((os) => os.name)); | 15 ..addAll(OperatingSystem.all.map((os) => os.identifier)); |
| 16 | 16 |
| 17 /// An expression for selecting certain platforms, including operating systems | 17 /// An expression for selecting certain platforms, including operating systems |
| 18 /// and browsers. | 18 /// and browsers. |
| 19 /// | 19 /// |
| 20 /// This uses the [boolean selector][] syntax. | 20 /// This uses the [boolean selector][] syntax. |
| 21 /// | 21 /// |
| 22 /// [boolean selector]: https://pub.dartlang.org/packages/boolean_selector | 22 /// [boolean selector]: https://pub.dartlang.org/packages/boolean_selector |
| 23 class PlatformSelector { | 23 class PlatformSelector { |
| 24 /// A selector that declares that a test can be run on all platforms. | 24 /// A selector that declares that a test can be run on all platforms. |
| 25 static const all = const PlatformSelector._(BooleanSelector.all); | 25 static const all = const PlatformSelector._(BooleanSelector.all); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 const PlatformSelector._(this._inner); | 39 const PlatformSelector._(this._inner); |
| 40 | 40 |
| 41 /// Returns whether the selector matches the given [platform] and [os]. | 41 /// Returns whether the selector matches the given [platform] and [os]. |
| 42 /// | 42 /// |
| 43 /// [os] defaults to [OperatingSystem.none]. | 43 /// [os] defaults to [OperatingSystem.none]. |
| 44 bool evaluate(TestPlatform platform, {OperatingSystem os}) { | 44 bool evaluate(TestPlatform platform, {OperatingSystem os}) { |
| 45 os ??= OperatingSystem.none; | 45 os ??= OperatingSystem.none; |
| 46 | 46 |
| 47 return _inner.evaluate((variable) { | 47 return _inner.evaluate((variable) { |
| 48 if (variable == platform.identifier) return true; | 48 if (variable == platform.identifier) return true; |
| 49 if (variable == os.name) return true; | 49 if (variable == os.identifier) return true; |
| 50 switch (variable) { | 50 switch (variable) { |
| 51 case "dart-vm": return platform.isDartVM; | 51 case "dart-vm": return platform.isDartVM; |
| 52 case "browser": return platform.isBrowser; | 52 case "browser": return platform.isBrowser; |
| 53 case "js": return platform.isJS; | 53 case "js": return platform.isJS; |
| 54 case "blink": return platform.isBlink; | 54 case "blink": return platform.isBlink; |
| 55 case "posix": return os.isPosix; | 55 case "posix": return os.isPosix; |
| 56 default: return false; | 56 default: return false; |
| 57 } | 57 } |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | 60 |
| 61 /// Returns a new [PlatformSelector] that matches only platforms matched by | 61 /// Returns a new [PlatformSelector] that matches only platforms matched by |
| 62 /// both [this] and [other]. | 62 /// both [this] and [other]. |
| 63 PlatformSelector intersection(PlatformSelector other) { | 63 PlatformSelector intersection(PlatformSelector other) { |
| 64 if (other == PlatformSelector.all) return this; | 64 if (other == PlatformSelector.all) return this; |
| 65 return new PlatformSelector._(_inner.intersection(other._inner)); | 65 return new PlatformSelector._(_inner.intersection(other._inner)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 String toString() => _inner.toString(); | 68 String toString() => _inner.toString(); |
| 69 | 69 |
| 70 bool operator==(other) => other is PlatformSelector && _inner == other._inner; | 70 bool operator==(other) => other is PlatformSelector && _inner == other._inner; |
| 71 | 71 |
| 72 int get hashCode => _inner.hashCode; | 72 int get hashCode => _inner.hashCode; |
| 73 } | 73 } |
| OLD | NEW |