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 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
9 | 9 |
10 const String TEST_1 = r""" | 10 const String TEST_1 = r""" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 main() { | 61 main() { |
62 RegExp directivePattern = new RegExp( | 62 RegExp directivePattern = new RegExp( |
63 // \1 \2 \3 | 63 // \1 \2 \3 |
64 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''', | 64 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''', |
65 multiLine: true); | 65 multiLine: true); |
66 | 66 |
67 Future check(String test) { | 67 Future check(String test) { |
68 Uri uri = new Uri(scheme: 'dart', path: 'test'); | 68 Uri uri = new Uri(scheme: 'dart', path: 'test'); |
69 var compiler = compilerFor(test, uri, expectedErrors: 0); | 69 var compiler = compilerFor(test, uri, expectedErrors: 0); |
70 return compiler.runCompiler(uri).then((_) { | 70 return compiler.run(uri).then((_) { |
71 var element = findElement(compiler, 'main'); | 71 var element = findElement(compiler, 'main'); |
72 var backend = compiler.backend; | 72 var backend = compiler.backend; |
73 String generated = backend.getGeneratedCode(element); | 73 String generated = backend.getGeneratedCode(element); |
74 | 74 |
75 for (Match match in directivePattern.allMatches(test)) { | 75 for (Match match in directivePattern.allMatches(test)) { |
76 String directive = match.group(1); | 76 String directive = match.group(1); |
77 String pattern = match.groups([2, 3]).where((s) => s != null).single; | 77 String pattern = match.groups([2, 3]).where((s) => s != null).single; |
78 if (directive == 'present') { | 78 if (directive == 'present') { |
79 Expect.isTrue(generated.contains(pattern), | 79 Expect.isTrue(generated.contains(pattern), |
80 "Cannot find '$pattern' in:\n$generated"); | 80 "Cannot find '$pattern' in:\n$generated"); |
81 } else { | 81 } else { |
82 assert(directive == 'absent'); | 82 assert(directive == 'absent'); |
83 Expect.isFalse(generated.contains(pattern), | 83 Expect.isFalse(generated.contains(pattern), |
84 "Must not find '$pattern' in:\n$generated"); | 84 "Must not find '$pattern' in:\n$generated"); |
85 } | 85 } |
86 } | 86 } |
87 }); | 87 }); |
88 } | 88 } |
89 | 89 |
90 asyncTest(() => Future.wait([ | 90 asyncTest(() => Future.wait([ |
91 check(TEST_1), | 91 check(TEST_1), |
92 check(TEST_2), | 92 check(TEST_2), |
93 check(TEST_3), | 93 check(TEST_3), |
94 ])); | 94 ])); |
95 } | 95 } |
OLD | NEW |