]> git.lizzy.rs Git - rust.git/commitdiff
Added some tests
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 7 Jul 2017 22:58:33 +0000 (00:58 +0200)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 28 Jul 2017 13:46:23 +0000 (15:46 +0200)
src/test/compile-fail/generator/const-yield.rs [deleted file]
src/test/compile-fail/generator/generator-not-fnmut.rs [deleted file]
src/test/compile-fail/generator/invalid-positions.rs [new file with mode: 0644]
src/test/compile-fail/generator/no-arguments-on-generators.rs [new file with mode: 0644]
src/test/run-pass/generator/implicit-argument-dead-when-suspended.rs [new file with mode: 0644]

diff --git a/src/test/compile-fail/generator/const-yield.rs b/src/test/compile-fail/generator/const-yield.rs
deleted file mode 100644 (file)
index fa99e85..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(generators)]
-
-const A: u8 = { yield 3u8; 3u8}; //~ ERROR yield statement outside of function body
-static B: u8 = { yield 3u8; 3u8}; //~ ERROR yield statement outside of function body
-
-fn main() {}
\ No newline at end of file
diff --git a/src/test/compile-fail/generator/generator-not-fnmut.rs b/src/test/compile-fail/generator/generator-not-fnmut.rs
deleted file mode 100644 (file)
index 460db8e..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(generators)]
-
-fn main() {
-    let mut a = Vec::<bool>::new();
-
-    let mut test = || {
-        let _: () = gen arg;
-        yield 3;
-        a.push(true);
-        2
-    };
-
-    let a1 = test();
-    let a2 = test(); //~ ERROR use of moved value
-}
diff --git a/src/test/compile-fail/generator/invalid-positions.rs b/src/test/compile-fail/generator/invalid-positions.rs
new file mode 100644 (file)
index 0000000..c2f5b20
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(generators)]
+
+const A: u8 = { yield 3u8; gen arg; 3u8};
+//~^ ERROR yield statement outside
+//~| ERROR gen arg expression outside
+
+static B: u8 = { yield 3u8; gen arg; 3u8};
+//~^ ERROR yield statement outside
+//~| ERROR gen arg expression outside
+
+fn main() { yield; gen arg; }
+//~^ ERROR yield statement outside
+//~| ERROR gen arg expression outside
diff --git a/src/test/compile-fail/generator/no-arguments-on-generators.rs b/src/test/compile-fail/generator/no-arguments-on-generators.rs
new file mode 100644 (file)
index 0000000..9c68fe4
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(generators)]
+
+fn main() {
+    let gen = |start| { //~ ERROR generators cannot have explicit arguments
+        yield;
+    }; 
+}
\ No newline at end of file
diff --git a/src/test/run-pass/generator/implicit-argument-dead-when-suspended.rs b/src/test/run-pass/generator/implicit-argument-dead-when-suspended.rs
new file mode 100644 (file)
index 0000000..722ec24
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(generators)]
+
+use std::cell::Cell;
+
+struct Flag<'a>(&'a Cell<bool>);
+
+impl<'a> Drop for Flag<'a> {
+    fn drop(&mut self) {
+        self.0.set(false)
+    }
+}
+
+fn main() {
+    let alive = Cell::new(true);
+
+    let gen = || {
+        yield;
+    };
+
+    gen.resume(Flag(&alive));
+
+    assert_eq!(alive.get(), false);
+}