]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/while-let.rs
Merge tag 'upstream-tar/1.0.0_0alpha'
[rustc.git] / src / test / run-pass / while-let.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::collections::BinaryHeap;
12
13 fn make_pq() -> BinaryHeap<int> {
14 BinaryHeap::from_vec(vec![1i,2,3])
15 }
16
17 pub fn main() {
18 let mut pq = make_pq();
19 let mut sum = 0i;
20 while let Some(x) = pq.pop() {
21 sum += x;
22 }
23 assert_eq!(sum, 6i);
24
25 pq = make_pq();
26 sum = 0;
27 'a: while let Some(x) = pq.pop() {
28 sum += x;
29 if x == 2 {
30 break 'a;
31 }
32 }
33 assert_eq!(sum, 5i);
34
35 pq = make_pq();
36 sum = 0;
37 'a: while let Some(x) = pq.pop() {
38 if x == 3 {
39 continue 'a;
40 }
41 sum += x;
42 }
43 assert_eq!(sum, 3i);
44
45 let mut pq1 = make_pq();
46 sum = 0;
47 while let Some(x) = pq1.pop() {
48 let mut pq2 = make_pq();
49 while let Some(y) = pq2.pop() {
50 sum += x * y;
51 }
52 }
53 assert_eq!(sum, 6i + 12 + 18);
54 }