OLD | NEW |
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 Expect.equals(42, Class.fisk()); | 16 Expect.equals(42, Class.fisk()); |
17 Expect.equals(null, foo(Class.fisk())); | 17 Expect.equals(null, foo(Class.fisk())); |
18 | 18 |
19 // Verify references to a class literal are allowed. | 19 // Verify references to a class literal are allowed. |
20 Class; | 20 Class; |
21 var x = Class; | 21 var x = Class; |
22 foo(Class); | 22 foo(Class); |
23 Expect.isFalse(Class == null); | 23 Expect.isFalse(Class == null); |
24 | 24 |
25 // 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); /// 01: static
type warning | 26 Expect.throws(() { Class(); }, (e) => e is NoSuchMethodError); //# 01: static
type warning |
27 Expect.throws(() { Class[0]; }, (e) => e is NoSuchMethodError); /// 02: static
type warning | 27 Expect.throws(() { Class[0]; }, (e) => e is NoSuchMethodError); //# 02: static
type warning |
28 Expect.throws(() { var x = Class(); }, (e) => e is NoSuchMethodError); /// 03:
static type warning | 28 Expect.throws(() { var x = Class(); }, (e) => e is NoSuchMethodError); //# 03:
static type warning |
29 Expect.throws(() { var x = Class[0]; }, (e) => e is NoSuchMethodError); /// 04
: static type warning | 29 Expect.throws(() { var x = Class[0]; }, (e) => e is NoSuchMethodError); //# 04
: static type warning |
30 Expect.throws(() { var x = Class[0].field; }, (e) => e is NoSuchMethodError);
/// 05: static type warning | 30 Expect.throws(() { var x = Class[0].field; }, (e) => e is NoSuchMethodError);
//# 05: static type warning |
31 Expect.throws(() { var x = Class[0].method(); }, (e) => e is NoSuchMethodError
); /// 06: static type warning | 31 Expect.throws(() { var x = Class[0].method(); }, (e) => e is NoSuchMethodError
); //# 06: static type warning |
32 Expect.throws(() { foo(Class()); }, (e) => e is NoSuchMethodError); /// 07: st
atic type warning | 32 Expect.throws(() { foo(Class()); }, (e) => e is NoSuchMethodError); //# 07: st
atic type warning |
33 Expect.throws(() { foo(Class[0]); }, (e) => e is NoSuchMethodError); /// 08: s
tatic type warning | 33 Expect.throws(() { foo(Class[0]); }, (e) => e is NoSuchMethodError); //# 08: s
tatic type warning |
34 Expect.throws(() { foo(Class[0].field); }, (e) => e is NoSuchMethodError); ///
09: static type warning | 34 Expect.throws(() { foo(Class[0].field); }, (e) => e is NoSuchMethodError); //#
09: static type warning |
35 Expect.throws(() { foo(Class[0].method()); }, (e) => e is NoSuchMethodError);
/// 10: static type warning | 35 Expect.throws(() { foo(Class[0].method()); }, (e) => e is NoSuchMethodError);
//# 10: static type warning |
36 Expect.throws(() { Class[0] = 91; }, (e) => e is NoSuchMethodError); /// 11: s
tatic type warning | 36 Expect.throws(() { Class[0] = 91; }, (e) => e is NoSuchMethodError); //# 11: s
tatic type warning |
37 Expect.throws(() { Class++; }, (e) => e is NoSuchMethodError); /// 12: static
type warning | 37 Expect.throws(() { Class++; }, (e) => e is NoSuchMethodError); //# 12: static
type warning |
38 Expect.throws(() { ++Class; }, (e) => e is NoSuchMethodError); /// 13: static
type warning | 38 Expect.throws(() { ++Class; }, (e) => e is NoSuchMethodError); //# 13: static
type warning |
39 Expect.throws(() { Class[0] += 3; }, (e) => e is NoSuchMethodError); /// 14: s
tatic type warning | 39 Expect.throws(() { Class[0] += 3; }, (e) => e is NoSuchMethodError); //# 14: s
tatic type warning |
40 Expect.throws(() { ++Class[0]; }, (e) => e is NoSuchMethodError); /// 15: stat
ic type warning | 40 Expect.throws(() { ++Class[0]; }, (e) => e is NoSuchMethodError); //# 15: stat
ic type warning |
41 Expect.throws(() { Class[0]++; }, (e) => e is NoSuchMethodError); /// 16: stat
ic type warning | 41 Expect.throws(() { Class[0]++; }, (e) => e is NoSuchMethodError); //# 16: stat
ic type warning |
42 Expect.throws(() { Class.method(); }, (e) => e is NoSuchMethodError); /// 17:
static type warning | 42 Expect.throws(() { Class.method(); }, (e) => e is NoSuchMethodError); //# 17:
static type warning |
43 Expect.throws(() { Class.field; }, (e) => e is NoSuchMethodError); /// 18: sta
tic type warning | 43 Expect.throws(() { Class.field; }, (e) => e is NoSuchMethodError); //# 18: sta
tic type warning |
44 Expect.throws(() { var x = Class.method(); }, (e) => e is NoSuchMethodError);
/// 19: static type warning | 44 Expect.throws(() { var x = Class.method(); }, (e) => e is NoSuchMethodError);
//# 19: static type warning |
45 Expect.throws(() { var x = Class.field; }, (e) => e is NoSuchMethodError); ///
20: static type warning | 45 Expect.throws(() { var x = Class.field; }, (e) => e is NoSuchMethodError); //#
20: static type warning |
46 Expect.throws(() { foo(Class.method()); }, (e) => e is NoSuchMethodError); ///
21: static type warning | 46 Expect.throws(() { foo(Class.method()); }, (e) => e is NoSuchMethodError); //#
21: static type warning |
47 Expect.throws(() { foo(Class.field); }, (e) => e is NoSuchMethodError); /// 22
: static type warning | 47 Expect.throws(() { foo(Class.field); }, (e) => e is NoSuchMethodError); //# 22
: static type warning |
48 Expect.throws(() { Class / 3; }, (e) => e is NoSuchMethodError); /// 23: stati
c type warning | 48 Expect.throws(() { Class / 3; }, (e) => e is NoSuchMethodError); //# 23: stati
c type warning |
49 Expect.throws(() { Class += 3; }, (e) => e is NoSuchMethodError); /// 24: stat
ic type warning | 49 Expect.throws(() { Class += 3; }, (e) => e is NoSuchMethodError); //# 24: stat
ic type warning |
50 | 50 |
51 // Verify that a class literal isn't a string literal. | 51 // Verify that a class literal isn't a string literal. |
52 Expect.notEquals(Class, "Class"); | 52 Expect.notEquals(Class, "Class"); |
53 | 53 |
54 // Verify toString() works for class literals. | 54 // Verify toString() works for class literals. |
55 Expect.isTrue((Class).toString() is String); | 55 Expect.isTrue((Class).toString() is String); |
56 var y = Class; | 56 var y = Class; |
57 Expect.isTrue(y.toString() is String); | 57 Expect.isTrue(y.toString() is String); |
58 | 58 |
59 Expect.throws(() { Class.toString(); }, (e) => e is NoSuchMethodError); /// 25
: static type warning | 59 Expect.throws(() { Class.toString(); }, (e) => e is NoSuchMethodError); //# 25
: static type warning |
60 } | 60 } |
OLD | NEW |