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

Side by Side Diff: tests/compiler/dart2js/tdiv_test.dart

Issue 1106443003: Optimize DateTime properties (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/compiler/dart2js/simple_inferrer_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library tdiv_test;
6
7 import 'dart:async';
8 import 'package:expect/expect.dart';
9 import 'package:async_helper/async_helper.dart';
10 import 'compiler_helper.dart';
11
12 const String TEST1 = r"""
13 foo(param) {
14 var a = param ? 0xFFFFFFFF : 1;
15 return a ~/ 2;
16 // Above can be compiled to division followed by truncate.
17 // present: ' / 2 | 0'
18 // absent: 'tdiv'
19 }
20 """;
21
22 const String TEST2 = r"""
23 foo(param) {
24 var a = param ? 0xFFFFFFFF : 1;
25 return a ~/ 3;
26 // Above can be compiled to division followed by truncate.
27 // present: ' / 3 | 0'
28 // absent: 'tdiv'
29 }
30 """;
31
32 const String TEST3 = r"""
33 foo(param) {
34 var a = param ? 0xFFFFFFFF : -1;
35 return a ~/ 2;
36 // Potentially negative inputs go via fast helper.
37 // present: '_tdivFast'
38 // absent: '/'
39 }
40 """;
41
42 const String TEST4 = r"""
43 foo(param1, param2) {
44 var a = param1 ? 0xFFFFFFFF : 0;
45 return a ~/ param2;
46 // Unknown divisor goes via full implementation.
47 // present: '$tdiv'
48 // absent: '/'
49 }
50 """;
51
52 const String TEST5 = r"""
53 foo(param1, param2) {
54 var a = param1 ? 0xFFFFFFFF : 0;
55 var b = param2 ? 3 : 4;
56 return a ~/ param2;
57 // We could optimize this with range analysis, but type inference summarizes
58 // '3 or 4' to uint31, which is not >= 2.
59 // present: '$tdiv'
60 // absent: '/'
61 }
62 """;
63
64 main() {
65 RegExp directivePattern = new RegExp(
66 // \1 \2 \3
67 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''',
68 multiLine: true);
69
70 Future check(String test) {
71 return compile(test, entry: 'foo', check: (String generated) {
72 for (Match match in directivePattern.allMatches(test)) {
73 String directive = match.group(1);
74 String pattern = match.groups([2, 3]).where((s) => s != null).single;
75 if (directive == 'present') {
76 Expect.isTrue(generated.contains(pattern),
77 "Cannot find '$pattern' in:\n$generated");
78 } else {
79 assert(directive == 'absent');
80 Expect.isFalse(generated.contains(pattern),
81 "Must not find '$pattern' in:\n$generated");
82 }
83 }
84 });
85 }
86
87 asyncTest(() => Future.wait([
88 check(TEST1),
89 check(TEST2),
90 check(TEST3),
91 check(TEST4),
92 check(TEST5),
93 ]));
94 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/simple_inferrer_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698