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

Unified Diff: tests/language/void_type5_test.dart

Issue 2707933002: Tests for `void`.
Patch Set: Address comments. Created 3 years, 10 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
« tests/language/void_type4_test.dart ('K') | « tests/language/void_type4_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/void_type5_test.dart
diff --git a/tests/language/void_type5_test.dart b/tests/language/void_type5_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..31f789ec430d3f24890899aa1c52c6e39f6159bf
--- /dev/null
+++ b/tests/language/void_type5_test.dart
@@ -0,0 +1,37 @@
+// Copyright (c) 2017, 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 for type checks involving the void type.
+
+import 'package:expect/expect.dart';
+
+class A<T> {
+ T x;
+ foo(T x) {}
+ T bar(T f()) {
+ T tmp = f();
+ return tmp;
+ }
+
+ gee(T f()) {
+ x = bar(f);
+ }
+
+ Object xAsObject() => x;
+}
+
+void voidFun() => 499;
+int intFun() => 42;
+
+main() {
+ A<void> a = new A<void>();
+ a.foo(a.x); /// 00: error
+ a.bar(voidFun);
+ Expect.equals(null, a.xAsObject());
+ a.x = a.bar(voidFun); /// 01: error
+ a.gee(voidFun); // But we can do it through `gee`.
+ Expect.equals(499, a.xAsObject());
+ a.gee(intFun); // We can also pass in an int function.
+ Expect.equals(42, a.xAsObject());
+}
« tests/language/void_type4_test.dart ('K') | « tests/language/void_type4_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698