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

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

Issue 18801007: Support type parameters and classes as expression in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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/co19/co19-runtime.status ('k') | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "package:expect/expect.dart";
6 6
7 // Test class literal expressions. 7 // Test class literal expressions.
8 8
9 class Class { 9 class Class {
10 static fisk() => 42; 10 static fisk() => 42;
11 } 11 }
12 12
13 foo(x) {} 13 foo(x) {}
14 14
15 main() { 15 main() {
16 if (false) {
17 Class(); /// 02: compile-time error
18 Class[0]; /// 05: compile-time error
19 var x = Class(); /// 07: compile-time error
20 var x = Class[0]; /// 10: compile-time error
21 var x = Class[0].field; /// 11: compile-time error
22 var x = Class[0].method(); /// 12: compile-time error
23 foo(Class()); /// 14: compile-time error
24 foo(Class[0]); /// 17: compile-time error
25 foo(Class[0].field); /// 18: compile-time error
26 foo(Class[0].method()); /// 19: compile-time error
27 Class[0] = 91; /// 22: compile-time error
28 Class++; /// 23: compile-time error
29 ++Class; /// 24: compile-time error
30 Class[0] += 3; /// 27: compile-time error
31 ++Class[0]; /// 28: compile-time error
32 Class[0]++; /// 29: compile-time error
33 }
34 Expect.equals(42, Class.fisk()); 16 Expect.equals(42, Class.fisk());
35 Expect.equals(null, foo(Class.fisk())); 17 Expect.equals(null, foo(Class.fisk()));
36 18
37 // Verify references to a class literal are allowed. 19 // Verify references to a class literal are allowed.
38 Class; 20 Class;
39 var x = Class; 21 var x = Class;
40 foo(Class); 22 foo(Class);
41 Expect.isFalse(Class == null); 23 Expect.isFalse(Class == null);
42 24
43 // Verify that dereferencing a class literal is a runtime error. 25 // Verify that dereferencing a class literal is a runtime error.
26 Expect.throws(() { Class(); }, (e) => e is NoSuchMethodError);
27 Expect.throws(() { Class[0]; }, (e) => e is NoSuchMethodError);
28 Expect.throws(() { var x = Class(); }, (e) => e is NoSuchMethodError);
29 Expect.throws(() { var x = Class[0]; }, (e) => e is NoSuchMethodError);
30 Expect.throws(() { var x = Class[0].field; }, (e) => e is NoSuchMethodError);
31 Expect.throws(() { var x = Class[0].method(); }, (e) => e is NoSuchMethodError );
32 Expect.throws(() { foo(Class()); }, (e) => e is NoSuchMethodError);
33 Expect.throws(() { foo(Class[0]); }, (e) => e is NoSuchMethodError);
34 Expect.throws(() { foo(Class[0].field); }, (e) => e is NoSuchMethodError);
35 Expect.throws(() { foo(Class[0].method()); }, (e) => e is NoSuchMethodError);
36 Expect.throws(() { Class[0] = 91; }, (e) => e is NoSuchMethodError);
37 Expect.throws(() { Class++; }, (e) => e is NoSuchMethodError);
38 Expect.throws(() { ++Class; }, (e) => e is NoSuchMethodError);
39 Expect.throws(() { Class[0] += 3; }, (e) => e is NoSuchMethodError);
40 Expect.throws(() { ++Class[0]; }, (e) => e is NoSuchMethodError);
41 Expect.throws(() { Class[0]++; }, (e) => e is NoSuchMethodError);
44 Expect.throws(() { Class.method(); }, (e) => e is NoSuchMethodError); 42 Expect.throws(() { Class.method(); }, (e) => e is NoSuchMethodError);
45 Expect.throws(() { Class.field; }, (e) => e is NoSuchMethodError); 43 Expect.throws(() { Class.field; }, (e) => e is NoSuchMethodError);
46 Expect.throws(() { var x = Class.method(); }, (e) => e is NoSuchMethodError); 44 Expect.throws(() { var x = Class.method(); }, (e) => e is NoSuchMethodError);
47 Expect.throws(() { var x = Class.field; }, (e) => e is NoSuchMethodError); 45 Expect.throws(() { var x = Class.field; }, (e) => e is NoSuchMethodError);
48 Expect.throws(() { foo(Class.method()); }, (e) => e is NoSuchMethodError); 46 Expect.throws(() { foo(Class.method()); }, (e) => e is NoSuchMethodError);
49 Expect.throws(() { foo(Class.field); }, (e) => e is NoSuchMethodError); 47 Expect.throws(() { foo(Class.field); }, (e) => e is NoSuchMethodError);
50 Expect.throws(() { Class / 3; }, (e) => e is NoSuchMethodError); 48 Expect.throws(() { Class / 3; }, (e) => e is NoSuchMethodError);
51 Expect.throws(() { Class += 3; }, (e) => e is NoSuchMethodError); 49 Expect.throws(() { Class += 3; }, (e) => e is NoSuchMethodError);
52 50
53 // Verify that a class literal is its runtimeType. 51 // Verify that a class literal is its runtimeType.
54 var obj = new Class(); 52 var obj = new Class();
55 Expect.identical(Class, obj.runtimeType); 53 Expect.identical(Class, obj.runtimeType);
56 54
57 // Verify that a class literal isn't a string literal. 55 // Verify that a class literal isn't a string literal.
58 Expect.notEquals(Class, "Class"); 56 Expect.notEquals(Class, "Class");
59 57
60 // Verify toString() works for class literals. 58 // Verify toString() works for class literals.
61 Expect.equals((Class).toString(), "Class"); 59 Expect.equals((Class).toString(), "Class");
62 var y = Class; 60 var y = Class;
63 Expect.equals(y.toString(), "Class"); 61 Expect.equals(y.toString(), "Class");
64 62
65 Expect.throws(() { Class.toString(); }, (e) => e is NoSuchMethodError); 63 Expect.throws(() { Class.toString(); }, (e) => e is NoSuchMethodError);
66 } 64 }
OLDNEW
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698