| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:expect/expect.dart"; | 5 import 'dart:async'; |
| 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; |
| 6 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
| 7 | 9 |
| 8 const String FIB = r""" | 10 const String FIB = r""" |
| 9 fib(n) { | 11 fib(n) { |
| 10 if (n <= 1) return 1; | 12 if (n <= 1) return 1; |
| 11 return add(fib(n - 1), fib(n - 2)); | 13 return add(fib(n - 1), fib(n - 2)); |
| 12 } | 14 } |
| 13 | 15 |
| 14 // We need this artificial add method because | 16 // We need this artificial add method because |
| 15 // our optimizer will actually add type checks | 17 // our optimizer will actually add type checks |
| (...skipping 26 matching lines...) Expand all Loading... |
| 42 // snippet). | 44 // snippet). |
| 43 const String TEST = r""" | 45 const String TEST = r""" |
| 44 foo(a) { | 46 foo(a) { |
| 45 if (a is !int) throw a; | 47 if (a is !int) throw a; |
| 46 if (a < 0) throw a; | 48 if (a < 0) throw a; |
| 47 return a + a; | 49 return a + a; |
| 48 } | 50 } |
| 49 """; | 51 """; |
| 50 | 52 |
| 51 main() { | 53 main() { |
| 52 // Make sure we don't introduce a new variable. | 54 asyncTest(() => Future.wait([ |
| 53 RegExp regexp = new RegExp("var $anyIdentifier ="); | 55 // Make sure we don't introduce a new variable. |
| 54 compileAndDoNotMatch(FIB, 'fib', regexp); | 56 compileAndDoNotMatch(FIB, 'fib', new RegExp("var $anyIdentifier =")), |
| 55 | 57 |
| 56 regexp = new RegExp("isLeaf"); | 58 compileAndDoNotMatch(BAR, 'bar', new RegExp("isLeaf")), |
| 57 compileAndDoNotMatch(BAR, 'bar', regexp); | |
| 58 | 59 |
| 59 String generated = compile(TEST, entry: 'foo'); | 60 compile(TEST, entry: 'foo', check: (String generated) { |
| 60 Expect.isFalse(generated.contains('else')); | 61 Expect.isFalse(generated.contains('else')); |
| 61 // Regression check to ensure that there is no floating variable | 62 // Regression check to ensure that there is no floating variable |
| 62 // expression. | 63 // expression. |
| 63 Expect.isFalse(new RegExp('^[ ]*a;').hasMatch(generated)); | 64 Expect.isFalse(new RegExp('^[ ]*a;').hasMatch(generated)); |
| 65 }), |
| 66 ])); |
| 64 } | 67 } |
| OLD | NEW |