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

Side by Side Diff: tests/language/closure_type_test.dart

Issue 3002573002: Migrating another batch of tests to dart 2. (Closed)
Patch Set: Removed library closure_type_test from test_file Created 3 years, 4 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
« no previous file with comments | « tests/language/closure_test.dart ('k') | tests/language/closure_type_variable_test.dart » ('j') | 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Dart test for a closure result type test that cannot be eliminated at compile
6 // time.
7
8 library closure_type_test;
9
10 import "package:expect/expect.dart";
11 import 'dart:math' as math;
12
13 class Math {
14 static
15 int // //# 01: static type warning
16 sqrt(x) => math.sqrt(x);
17 }
18
19 isCheckedMode() {
20 try {
21 var i = 1;
22 String s = i;
23 return false;
24 } catch (e) {
25 return true;
26 }
27 }
28
29 void test(int func(int value), int value) {
30 bool got_type_error = false;
31 try {
32 // Because of function subtyping rules, the static return type of a closure
33 // call cannot be relied upon for static type analysis. For example, a
34 // function returning dynamic (function 'root') can be assigned to a closure
35 // variable declared to return int (closure 'func') and may actually return
36 // a double at run-time.
37 // Therefore, eliminating the run-time type check would be wrong.
38 int x = func(value);
39 Expect.equals(value, x * x);
40 } on TypeError catch (error) {
41 got_type_error = true;
42 }
43 // Type error expected in checked mode only.
44 Expect.isTrue(got_type_error == isCheckedMode());
45 }
46
47 root(x) => Math.sqrt(x);
48
49 main() => test(root, 4);
OLDNEW
« no previous file with comments | « tests/language/closure_test.dart ('k') | tests/language/closure_type_variable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698