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

Unified Diff: tests/language/cast_test.dart

Issue 10540048: Implement 'as' operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: No entries in language.status, vm and dartc already implemented 'as'. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: tests/language/cast_test.dart
diff --git a/tests/language/cast_test.dart b/tests/language/cast_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b73d3c63e55aae69456c574049b3a2295386e448
--- /dev/null
+++ b/tests/language/cast_test.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// Dart test program for constructors and initializers.
+
+// Test 'expression as Type' casts.
+
+class C {
+ final int foo = 42;
+}
+
+class D extends C {
+ final int bar = 37;
+}
+
+Object createC() => new C();
+Object createD() => new D();
+Object getNull() => null;
+Object createList() => <int>[2];
+Object createInt() => 87;
+Object createString() => "a string";
+
+main() {
+ Object oc = createC();
+ Object od = createD();
+ Object on = getNull();
+ Object ol = createList();
+ Object oi = createInt();
+ Object os = createString();
+
+ Expect.equals(42, (oc as C).foo);
+ Expect.equals(42, (od as C).foo);
+ Expect.equals(42, (od as D).foo);
+ Expect.equals(37, (od as D).bar);
+ Expect.equals(37, ((od as C) as D).bar);
+ (oc as D).foo; /// 01: runtime error
+ (on as D).toString();
+ (on as D).foo; /// 02: runtime error
+ (on as C).foo; /// 03: runtime error
+ oc.foo; /// 04: static type warning
+ od.foo; /// 05: static type warning
+ (on as Object).toString();
+ (oc as Object).toString();
+ (od as Object).toString();
+ (on as Dynamic).toString();
+ (on as Dynamic).foo; /// 07: runtime error
+ (oc as Dynamic).foo;
+ (od as Dynamic).foo;
+ (oc as Dynamic).bar; /// 08: runtime error
+ (od as Dynamic).bar;
+ C c = oc as C;
+ c = od as C;
+ c = oc;
+ D d = od as D;
+ d = oc as D; /// 10: runtime error
+ d = od;
+
+ (ol as List)[0];
+ (ol as List<int>)[0];
+ (ol as Dynamic)[0];
+ (ol as String).length; /// 12: runtime error
+ int x = (ol as List<int>)[0];
+ (ol as List<int>)[0] = (oi as int);
+
+ (os as String).length;
+ (os as Dynamic).length;
+ (oi as String).length; /// 13: runtime error
+ (os as List).length; /// 14: runtime error
+
+ (oi as int) + 2;
+ (oi as List).length; /// 15: runtime error
+}
+
+
« lib/compiler/implementation/lib/js_helper.dart ('K') | « lib/compiler/implementation/ssa/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698