 Chromium Code Reviews
 Chromium Code Reviews Issue 1004013002:
  Add support for evaluating platform selectors.  (Closed) 
  Base URL: git@github.com:dart-lang/unittest@master
    
  
    Issue 1004013002:
  Add support for evaluating platform selectors.  (Closed) 
  Base URL: git@github.com:dart-lang/unittest@master| Index: lib/src/backend/platform_selector/evaluator.dart | 
| diff --git a/lib/src/backend/platform_selector/evaluator.dart b/lib/src/backend/platform_selector/evaluator.dart | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..d01f0d9c54ba15d9a1eecf4ad8be46fe1187c9c7 | 
| --- /dev/null | 
| +++ b/lib/src/backend/platform_selector/evaluator.dart | 
| @@ -0,0 +1,60 @@ | 
| +// Copyright (c) 2015, 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. | 
| + | 
| +library unittest.backend.platform_selector.evaluator; | 
| + | 
| +import 'package:source_span/source_span.dart'; | 
| + | 
| +import '../operating_system.dart'; | 
| +import '../test_platform.dart'; | 
| +import 'ast.dart'; | 
| +import 'visitor.dart'; | 
| + | 
| +/// A visitor for evaluating platform selectors against a specific | 
| +/// [TestPlatform] and [OperatingSystem]. | 
| +class Evaluator implements Visitor<bool> { | 
| + /// The platform to test against. | 
| + final TestPlatform _platform; | 
| + | 
| + /// The operating system to test against. | 
| + final OperatingSystem _os; | 
| + | 
| + Evaluator(this._platform, {OperatingSystem os}) | 
| + : _os = os == null ? OperatingSystem.none : os; | 
| + | 
| + bool visitVariable(VariableNode node) { | 
| + if (node.name == _platform.identifier) return true; | 
| + if (TestPlatform.all.any((platform) => node.name == platform.identifier)) { | 
| + return false; | 
| + } | 
| 
Bob Nystrom
2015/03/16 16:54:26
Are these false cases needed?
 
nweiz
2015/03/24 01:03:28
Done.
 | 
| + | 
| + if (node.name == _os.name) return true; | 
| + if (OperatingSystem.all.any((os) => node.name == os.name)) { | 
| + return false; | 
| + } | 
| + | 
| + switch (node.name) { | 
| + case "dart-vm": return _platform.isDartVm; | 
| + case "browser": return _platform.isBrowser; | 
| + case "dart2js": return _platform.isDart2js; | 
| + case "blink": return _platform.isBlink; | 
| + case "posix": return _os.isPosix; | 
| + default: | 
| + throw new SourceSpanFormatException( | 
| + 'Undefined variable "${node.name}".', node.span); | 
| 
Bob Nystrom
2015/03/16 16:54:26
If you've already done the check for undefined var
 
nweiz
2015/03/24 01:03:28
Done.
 | 
| + } | 
| + } | 
| + | 
| + bool visitNot(NotNode node) => !node.child.accept(this); | 
| + | 
| + bool visitOr(OrNode node) => | 
| + node.left.accept(this) || node.right.accept(this); | 
| + | 
| + bool visitAnd(AndNode node) => | 
| + node.left.accept(this) && node.right.accept(this); | 
| + | 
| + bool visitConditional(ConditionalNode node) => node.condition.accept(this) | 
| + ? node.whenTrue.accept(this) | 
| + : node.whenFalse.accept(this); | 
| +} |