Skip to content

Commit 232b9ba

Browse files
committed
Move range in ui test to ops test in library/core
1 parent 5629309 commit 232b9ba

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

library/core/tests/ops.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
22

3-
// Test the Range structs without the syntactic sugar.
3+
// Test the Range structs and syntax.
44

55
#[test]
66
fn test_range() {
@@ -94,3 +94,60 @@ fn test_bound_cloned_included() {
9494
fn test_bound_cloned_excluded() {
9595
assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3));
9696
}
97+
98+
#[test]
99+
#[allow(unused_comparisons)]
100+
#[allow(unused_mut)]
101+
fn test_range_syntax() {
102+
let mut count = 0;
103+
for i in 0_usize..10 {
104+
assert!(i >= 0 && i < 10);
105+
count += i;
106+
}
107+
assert_eq!(count, 45);
108+
109+
let mut count = 0;
110+
let mut range = 0_usize..10;
111+
for i in range {
112+
assert!(i >= 0 && i < 10);
113+
count += i;
114+
}
115+
assert_eq!(count, 45);
116+
117+
let mut count = 0;
118+
let mut rf = 3_usize..;
119+
for i in rf.take(10) {
120+
assert!(i >= 3 && i < 13);
121+
count += i;
122+
}
123+
assert_eq!(count, 75);
124+
125+
let _ = 0_usize..4 + 4 - 3;
126+
127+
fn foo() -> isize {
128+
42
129+
}
130+
let _ = 0..foo();
131+
132+
let _ = { &42..&100 }; // references to literals are OK
133+
let _ = ..42_usize;
134+
135+
// Test we can use two different types with a common supertype.
136+
let x = &42;
137+
{
138+
let y = 42;
139+
let _ = x..&y;
140+
}
141+
}
142+
143+
#[test]
144+
#[allow(dead_code)]
145+
fn test_range_syntax_in_return_statement() {
146+
fn return_range_to() -> RangeTo<i32> {
147+
return ..1;
148+
}
149+
fn return_full_range() -> RangeFull {
150+
return ..;
151+
}
152+
// Not much to test.
153+
}

src/test/ui/range.rs

-51
This file was deleted.

0 commit comments

Comments
 (0)