Skip to content

Commit e840e49

Browse files
committed
Tests
1 parent 17826e1 commit e840e49

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/test/compile-fail/range-1.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Test range syntax - type errors.
12+
13+
pub fn main() {
14+
// Mixed types.
15+
let _ = 0u..10i;
16+
//~^ ERROR mismatched types: expected `uint`, found `int`
17+
18+
// Float => does not implement iterator.
19+
for i in 0f32..42f32 {}
20+
//~^ ERROR `for` loop expression has type `core::ops::Range<f32>` which does not implement
21+
22+
// Unsized type.
23+
let arr: &[_] = &[1u, 2, 3];
24+
let range = (*arr)..;
25+
//~^ ERROR the trait `core::kinds::Sized` is not implemented
26+
}

src/test/compile-fail/range-2.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Test range syntax - borrow errors.
12+
13+
pub fn main() {
14+
let x = &42i;
15+
{
16+
let y = 42i;
17+
let r = x..&y;
18+
//~^ ERROR `y` does not live long enough
19+
}
20+
21+
let r = {
22+
(&42i)..&42
23+
//~^ ERROR borrowed value does not live long enough
24+
//~^^ ERROR borrowed value does not live long enough
25+
};
26+
}

src/test/run-pass/range.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
// Test range syntax.
12+
13+
fn foo() -> int { 42 }
14+
15+
pub fn main() {
16+
let mut count = 0;
17+
for i in 0u..10 {
18+
assert!(i >= 0 && i < 10);
19+
count += i;
20+
}
21+
assert!(count == 45);
22+
23+
let mut count = 0;
24+
let mut range = 0u..10;
25+
for i in range {
26+
assert!(i >= 0 && i < 10);
27+
count += i;
28+
}
29+
assert!(count == 45);
30+
31+
let mut count = 0;
32+
let mut rf = 3u..;
33+
for i in rf.take(10) {
34+
assert!(i >= 3 && i < 13);
35+
count += i;
36+
}
37+
assert!(count == 75);
38+
39+
let _ = 0u..4+4-3;
40+
let _ = 0..foo();
41+
}

0 commit comments

Comments
 (0)