Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcbe638

Browse files
committedNov 23, 2020
Make ui test that are run-pass and do not test the compiler itself library tests
1 parent d9a105f commit fcbe638

38 files changed

+811
-823
lines changed
 

‎library/alloc/tests/str.rs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::borrow::Cow;
22
use std::cmp::Ordering::{Equal, Greater, Less};
3-
use std::str::from_utf8;
3+
use std::str::{from_utf8, from_utf8_unchecked};
44

55
#[test]
66
fn test_le() {
@@ -1971,3 +1971,97 @@ fn test_str_escapes() {
19711971
";
19721972
assert_eq!(x, r"\\"); // extraneous whitespace stripped
19731973
}
1974+
1975+
#[test]
1976+
fn const_str_ptr() {
1977+
const A: [u8; 2] = ['h' as u8, 'i' as u8];
1978+
const B: &'static [u8; 2] = &A;
1979+
const C: *const u8 = B as *const u8;
1980+
1981+
unsafe {
1982+
let foo = &A as *const u8;
1983+
assert_eq!(foo, C);
1984+
assert_eq!(from_utf8_unchecked(&A), "hi");
1985+
assert_eq!(*C, A[0]);
1986+
assert_eq!(*(&B[0] as *const u8), A[0]);
1987+
}
1988+
}
1989+
1990+
#[test]
1991+
fn utf8() {
1992+
let yen: char = '¥'; // 0xa5
1993+
let c_cedilla: char = 'ç'; // 0xe7
1994+
let thorn: char = 'þ'; // 0xfe
1995+
let y_diaeresis: char = 'ÿ'; // 0xff
1996+
let pi: char = 'Π'; // 0x3a0
1997+
1998+
assert_eq!(yen as isize, 0xa5);
1999+
assert_eq!(c_cedilla as isize, 0xe7);
2000+
assert_eq!(thorn as isize, 0xfe);
2001+
assert_eq!(y_diaeresis as isize, 0xff);
2002+
assert_eq!(pi as isize, 0x3a0);
2003+
2004+
assert_eq!(pi as isize, '\u{3a0}' as isize);
2005+
assert_eq!('\x0a' as isize, '\n' as isize);
2006+
2007+
let bhutan: String = "འབྲུག་ཡུལ།".to_string();
2008+
let japan: String = "日本".to_string();
2009+
let uzbekistan: String = "Ўзбекистон".to_string();
2010+
let austria: String = "Österreich".to_string();
2011+
2012+
let bhutan_e: String =
2013+
"\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string();
2014+
let japan_e: String = "\u{65e5}\u{672c}".to_string();
2015+
let uzbekistan_e: String =
2016+
"\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string();
2017+
let austria_e: String = "\u{d6}sterreich".to_string();
2018+
2019+
let oo: char = 'Ö';
2020+
assert_eq!(oo as isize, 0xd6);
2021+
2022+
fn check_str_eq(a: String, b: String) {
2023+
let mut i: isize = 0;
2024+
for ab in a.bytes() {
2025+
println!("{}", i);
2026+
println!("{}", ab);
2027+
let bb: u8 = b.as_bytes()[i as usize];
2028+
println!("{}", bb);
2029+
assert_eq!(ab, bb);
2030+
i += 1;
2031+
}
2032+
}
2033+
2034+
check_str_eq(bhutan, bhutan_e);
2035+
check_str_eq(japan, japan_e);
2036+
check_str_eq(uzbekistan, uzbekistan_e);
2037+
check_str_eq(austria, austria_e);
2038+
}
2039+
2040+
#[test]
2041+
fn utf8_chars() {
2042+
// Chars of 1, 2, 3, and 4 bytes
2043+
let chs: Vec<char> = vec!['e', 'é', '€', '\u{10000}'];
2044+
let s: String = chs.iter().cloned().collect();
2045+
let schs: Vec<char> = s.chars().collect();
2046+
2047+
assert_eq!(s.len(), 10);
2048+
assert_eq!(s.chars().count(), 4);
2049+
assert_eq!(schs.len(), 4);
2050+
assert_eq!(schs.iter().cloned().collect::<String>(), s);
2051+
2052+
assert!((from_utf8(s.as_bytes()).is_ok()));
2053+
// invalid prefix
2054+
assert!((!from_utf8(&[0x80]).is_ok()));
2055+
// invalid 2 byte prefix
2056+
assert!((!from_utf8(&[0xc0]).is_ok()));
2057+
assert!((!from_utf8(&[0xc0, 0x10]).is_ok()));
2058+
// invalid 3 byte prefix
2059+
assert!((!from_utf8(&[0xe0]).is_ok()));
2060+
assert!((!from_utf8(&[0xe0, 0x10]).is_ok()));
2061+
assert!((!from_utf8(&[0xe0, 0xff, 0x10]).is_ok()));
2062+
// invalid 4 byte prefix
2063+
assert!((!from_utf8(&[0xf0]).is_ok()));
2064+
assert!((!from_utf8(&[0xf0, 0x10]).is_ok()));
2065+
assert!((!from_utf8(&[0xf0, 0xff, 0x10]).is_ok()));
2066+
assert!((!from_utf8(&[0xf0, 0xff, 0xff, 0x10]).is_ok()));
2067+
}

‎library/core/tests/ascii.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,56 @@ fn ascii_const() {
408408
const BYTE_IS_ASCII: bool = 97u8.is_ascii();
409409
assert!(BYTE_IS_ASCII);
410410
}
411+
412+
#[test]
413+
fn ascii_ctype_const() {
414+
macro_rules! suite {
415+
( $( $fn:ident => [$a:ident, $A:ident, $nine:ident, $dot:ident, $space:ident]; )* ) => {
416+
$(
417+
mod $fn {
418+
const CHAR_A_LOWER: bool = 'a'.$fn();
419+
const CHAR_A_UPPER: bool = 'A'.$fn();
420+
const CHAR_NINE: bool = '9'.$fn();
421+
const CHAR_DOT: bool = '.'.$fn();
422+
const CHAR_SPACE: bool = ' '.$fn();
423+
424+
const U8_A_LOWER: bool = b'a'.$fn();
425+
const U8_A_UPPER: bool = b'A'.$fn();
426+
const U8_NINE: bool = b'9'.$fn();
427+
const U8_DOT: bool = b'.'.$fn();
428+
const U8_SPACE: bool = b' '.$fn();
429+
430+
pub fn run() {
431+
assert_eq!(CHAR_A_LOWER, $a);
432+
assert_eq!(CHAR_A_UPPER, $A);
433+
assert_eq!(CHAR_NINE, $nine);
434+
assert_eq!(CHAR_DOT, $dot);
435+
assert_eq!(CHAR_SPACE, $space);
436+
437+
assert_eq!(U8_A_LOWER, $a);
438+
assert_eq!(U8_A_UPPER, $A);
439+
assert_eq!(U8_NINE, $nine);
440+
assert_eq!(U8_DOT, $dot);
441+
assert_eq!(U8_SPACE, $space);
442+
}
443+
}
444+
)*
445+
446+
$( $fn::run(); )*
447+
}
448+
}
449+
450+
suite! {
451+
// 'a' 'A' '9' '.' ' '
452+
is_ascii_alphabetic => [true, true, false, false, false];
453+
is_ascii_uppercase => [false, true, false, false, false];
454+
is_ascii_lowercase => [true, false, false, false, false];
455+
is_ascii_alphanumeric => [true, true, true, false, false];
456+
is_ascii_digit => [false, false, true, false, false];
457+
is_ascii_hexdigit => [true, true, true, false, false];
458+
is_ascii_punctuation => [false, false, false, true, false];
459+
is_ascii_graphic => [true, true, true, true, false];
460+
is_ascii_whitespace => [false, false, false, false, true];
461+
is_ascii_control => [false, false, false, false, false];
462+
}
463+
}

‎library/core/tests/atomic.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,82 @@ fn static_init() {
101101
assert!(S_INT.fetch_add(1, SeqCst) == 0);
102102
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
103103
}
104+
105+
#[test]
106+
fn atomic_access_bool() {
107+
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
108+
109+
unsafe {
110+
assert_eq!(*ATOMIC.get_mut(), false);
111+
ATOMIC.store(true, SeqCst);
112+
assert_eq!(*ATOMIC.get_mut(), true);
113+
ATOMIC.fetch_or(false, SeqCst);
114+
assert_eq!(*ATOMIC.get_mut(), true);
115+
ATOMIC.fetch_and(false, SeqCst);
116+
assert_eq!(*ATOMIC.get_mut(), false);
117+
ATOMIC.fetch_nand(true, SeqCst);
118+
assert_eq!(*ATOMIC.get_mut(), true);
119+
ATOMIC.fetch_xor(true, SeqCst);
120+
assert_eq!(*ATOMIC.get_mut(), false);
121+
}
122+
}
123+
124+
#[test]
125+
fn atomic_alignment() {
126+
use std::mem::{align_of, size_of};
127+
128+
#[cfg(target_has_atomic = "8")]
129+
assert_eq!(align_of::<AtomicBool>(), size_of::<AtomicBool>());
130+
#[cfg(target_has_atomic = "ptr")]
131+
assert_eq!(align_of::<AtomicPtr<u8>>(), size_of::<AtomicPtr<u8>>());
132+
#[cfg(target_has_atomic = "8")]
133+
assert_eq!(align_of::<AtomicU8>(), size_of::<AtomicU8>());
134+
#[cfg(target_has_atomic = "8")]
135+
assert_eq!(align_of::<AtomicI8>(), size_of::<AtomicI8>());
136+
#[cfg(target_has_atomic = "16")]
137+
assert_eq!(align_of::<AtomicU16>(), size_of::<AtomicU16>());
138+
#[cfg(target_has_atomic = "16")]
139+
assert_eq!(align_of::<AtomicI16>(), size_of::<AtomicI16>());
140+
#[cfg(target_has_atomic = "32")]
141+
assert_eq!(align_of::<AtomicU32>(), size_of::<AtomicU32>());
142+
#[cfg(target_has_atomic = "32")]
143+
assert_eq!(align_of::<AtomicI32>(), size_of::<AtomicI32>());
144+
#[cfg(target_has_atomic = "64")]
145+
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
146+
#[cfg(target_has_atomic = "64")]
147+
assert_eq!(align_of::<AtomicI64>(), size_of::<AtomicI64>());
148+
#[cfg(target_has_atomic = "128")]
149+
assert_eq!(align_of::<AtomicU128>(), size_of::<AtomicU128>());
150+
#[cfg(target_has_atomic = "128")]
151+
assert_eq!(align_of::<AtomicI128>(), size_of::<AtomicI128>());
152+
#[cfg(target_has_atomic = "ptr")]
153+
assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>());
154+
#[cfg(target_has_atomic = "ptr")]
155+
assert_eq!(align_of::<AtomicIsize>(), size_of::<AtomicIsize>());
156+
}
157+
158+
#[test]
159+
fn atomic_compare_exchange() {
160+
use Ordering::*;
161+
162+
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
163+
164+
ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok();
165+
ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok();
166+
ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok();
167+
ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok();
168+
ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok();
169+
ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok();
170+
ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok();
171+
ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok();
172+
ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok();
173+
ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
174+
ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
175+
ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok();
176+
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
177+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
178+
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
179+
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
180+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
181+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
182+
}

‎library/core/tests/bool.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1+
use core::cmp::Ordering::{Equal, Greater, Less};
2+
use core::ops::{BitAnd, BitOr, BitXor};
3+
4+
#[test]
5+
fn test_bool() {
6+
assert_eq!(false.eq(&true), false);
7+
assert_eq!(false == false, true);
8+
assert_eq!(false != true, true);
9+
assert_eq!(false.ne(&false), false);
10+
11+
assert_eq!(false.bitand(false), false);
12+
assert_eq!(true.bitand(false), false);
13+
assert_eq!(false.bitand(true), false);
14+
assert_eq!(true.bitand(true), true);
15+
16+
assert_eq!(false & false, false);
17+
assert_eq!(true & false, false);
18+
assert_eq!(false & true, false);
19+
assert_eq!(true & true, true);
20+
21+
assert_eq!(false.bitor(false), false);
22+
assert_eq!(true.bitor(false), true);
23+
assert_eq!(false.bitor(true), true);
24+
assert_eq!(true.bitor(true), true);
25+
26+
assert_eq!(false | false, false);
27+
assert_eq!(true | false, true);
28+
assert_eq!(false | true, true);
29+
assert_eq!(true | true, true);
30+
31+
assert_eq!(false.bitxor(false), false);
32+
assert_eq!(true.bitxor(false), true);
33+
assert_eq!(false.bitxor(true), true);
34+
assert_eq!(true.bitxor(true), false);
35+
36+
assert_eq!(false ^ false, false);
37+
assert_eq!(true ^ false, true);
38+
assert_eq!(false ^ true, true);
39+
assert_eq!(true ^ true, false);
40+
41+
assert_eq!(!true, false);
42+
assert_eq!(!false, true);
43+
44+
let s = false.to_string();
45+
assert_eq!(s, "false");
46+
let s = true.to_string();
47+
assert_eq!(s, "true");
48+
49+
assert!(true > false);
50+
assert!(!(false > true));
51+
52+
assert!(false < true);
53+
assert!(!(true < false));
54+
55+
assert!(false <= false);
56+
assert!(false >= false);
57+
assert!(true <= true);
58+
assert!(true >= true);
59+
60+
assert!(false <= true);
61+
assert!(!(false >= true));
62+
assert!(true >= false);
63+
assert!(!(true <= false));
64+
65+
assert_eq!(true.cmp(&true), Equal);
66+
assert_eq!(false.cmp(&false), Equal);
67+
assert_eq!(true.cmp(&false), Greater);
68+
assert_eq!(false.cmp(&true), Less);
69+
}
70+
71+
#[test]
72+
pub fn test_bool_not() {
73+
if !false {
74+
assert!((true));
75+
} else {
76+
assert!((false));
77+
}
78+
if !true {
79+
assert!((false));
80+
} else {
81+
assert!((true));
82+
}
83+
}
84+
185
#[test]
286
fn test_bool_to_option() {
387
assert_eq!(false.then_some(0), None);

‎library/core/tests/cmp.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,74 @@ fn ordering_const() {
132132
const THEN: Ordering = Equal.then(ORDERING);
133133
assert_eq!(THEN, Greater);
134134
}
135+
136+
#[test]
137+
fn cmp_default() {
138+
// Test default methods in PartialOrd and PartialEq
139+
140+
#[derive(Debug)]
141+
struct Fool(bool);
142+
143+
impl PartialEq for Fool {
144+
fn eq(&self, other: &Fool) -> bool {
145+
let Fool(this) = *self;
146+
let Fool(other) = *other;
147+
this != other
148+
}
149+
}
150+
151+
struct Int(isize);
152+
153+
impl PartialEq for Int {
154+
fn eq(&self, other: &Int) -> bool {
155+
let Int(this) = *self;
156+
let Int(other) = *other;
157+
this == other
158+
}
159+
}
160+
161+
impl PartialOrd for Int {
162+
fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
163+
let Int(this) = *self;
164+
let Int(other) = *other;
165+
this.partial_cmp(&other)
166+
}
167+
}
168+
169+
struct RevInt(isize);
170+
171+
impl PartialEq for RevInt {
172+
fn eq(&self, other: &RevInt) -> bool {
173+
let RevInt(this) = *self;
174+
let RevInt(other) = *other;
175+
this == other
176+
}
177+
}
178+
179+
impl PartialOrd for RevInt {
180+
fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
181+
let RevInt(this) = *self;
182+
let RevInt(other) = *other;
183+
other.partial_cmp(&this)
184+
}
185+
}
186+
187+
assert!(Int(2) > Int(1));
188+
assert!(Int(2) >= Int(1));
189+
assert!(Int(1) >= Int(1));
190+
assert!(Int(1) < Int(2));
191+
assert!(Int(1) <= Int(2));
192+
assert!(Int(1) <= Int(1));
193+
194+
assert!(RevInt(2) < RevInt(1));
195+
assert!(RevInt(2) <= RevInt(1));
196+
assert!(RevInt(1) <= RevInt(1));
197+
assert!(RevInt(1) > RevInt(2));
198+
assert!(RevInt(1) >= RevInt(2));
199+
assert!(RevInt(1) >= RevInt(1));
200+
201+
assert_eq!(Fool(true), Fool(false));
202+
assert!(Fool(true) != Fool(true));
203+
assert!(Fool(false) != Fool(false));
204+
assert_eq!(Fool(false), Fool(true));
205+
}

‎library/core/tests/iter.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,3 +3482,15 @@ fn test_flatten_non_fused_inner() {
34823482
assert_eq!(iter.next(), Some(1));
34833483
assert_eq!(iter.next(), None);
34843484
}
3485+
3486+
#[test]
3487+
pub fn extend_for_unit() {
3488+
let mut x = 0;
3489+
{
3490+
let iter = (0..5).map(|_| {
3491+
x += 1;
3492+
});
3493+
().extend(iter);
3494+
}
3495+
assert_eq!(x, 5);
3496+
}

‎library/core/tests/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(bound_cloned)]
99
#![feature(box_syntax)]
1010
#![feature(cell_update)]
11+
#![feature(cfg_target_has_atomic)]
1112
#![feature(const_assume)]
1213
#![feature(const_cell_into_inner)]
1314
#![feature(core_intrinsics)]
@@ -81,6 +82,7 @@ mod hash;
8182
mod intrinsics;
8283
mod iter;
8384
mod lazy;
85+
mod macros;
8486
mod manually_drop;
8587
mod mem;
8688
mod nonzero;
@@ -97,3 +99,4 @@ mod str_lossy;
9799
mod task;
98100
mod time;
99101
mod tuple;
102+
mod unicode;

‎library/core/tests/macros.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[test]
2+
fn assert_eq_trailing_comma() {
3+
assert_eq!(1, 1,);
4+
}
5+
6+
#[test]
7+
fn assert_escape() {
8+
assert!(r#"☃\backslash"#.contains("\\"));
9+
}
10+
11+
#[test]
12+
fn assert_ne_trailing_comma() {
13+
assert_ne!(1, 2,);
14+
}

‎library/core/tests/num/wrapping.rs

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,236 @@ wrapping_test!(u64, u64::MIN, u64::MAX);
7474
#[cfg(not(target_os = "emscripten"))]
7575
wrapping_test!(u128, u128::MIN, u128::MAX);
7676
wrapping_test!(usize, usize::MIN, usize::MAX);
77+
78+
// Don't warn about overflowing ops on 32-bit platforms
79+
#[cfg_attr(target_pointer_width = "32", allow(const_err))]
80+
fn wrapping_int_api() {
81+
assert_eq!(i8::MAX.wrapping_add(1), i8::MIN);
82+
assert_eq!(i16::MAX.wrapping_add(1), i16::MIN);
83+
assert_eq!(i32::MAX.wrapping_add(1), i32::MIN);
84+
assert_eq!(i64::MAX.wrapping_add(1), i64::MIN);
85+
assert_eq!(isize::MAX.wrapping_add(1), isize::MIN);
86+
87+
assert_eq!(i8::MIN.wrapping_sub(1), i8::MAX);
88+
assert_eq!(i16::MIN.wrapping_sub(1), i16::MAX);
89+
assert_eq!(i32::MIN.wrapping_sub(1), i32::MAX);
90+
assert_eq!(i64::MIN.wrapping_sub(1), i64::MAX);
91+
assert_eq!(isize::MIN.wrapping_sub(1), isize::MAX);
92+
93+
assert_eq!(u8::MAX.wrapping_add(1), u8::MIN);
94+
assert_eq!(u16::MAX.wrapping_add(1), u16::MIN);
95+
assert_eq!(u32::MAX.wrapping_add(1), u32::MIN);
96+
assert_eq!(u64::MAX.wrapping_add(1), u64::MIN);
97+
assert_eq!(usize::MAX.wrapping_add(1), usize::MIN);
98+
99+
assert_eq!(u8::MIN.wrapping_sub(1), u8::MAX);
100+
assert_eq!(u16::MIN.wrapping_sub(1), u16::MAX);
101+
assert_eq!(u32::MIN.wrapping_sub(1), u32::MAX);
102+
assert_eq!(u64::MIN.wrapping_sub(1), u64::MAX);
103+
assert_eq!(usize::MIN.wrapping_sub(1), usize::MAX);
104+
105+
assert_eq!((0xfe_u8 as i8).wrapping_mul(16), (0xe0_u8 as i8));
106+
assert_eq!((0xfedc_u16 as i16).wrapping_mul(16), (0xedc0_u16 as i16));
107+
assert_eq!((0xfedc_ba98_u32 as i32).wrapping_mul(16), (0xedcb_a980_u32 as i32));
108+
assert_eq!(
109+
(0xfedc_ba98_7654_3217_u64 as i64).wrapping_mul(16),
110+
(0xedcb_a987_6543_2170_u64 as i64)
111+
);
112+
113+
match () {
114+
#[cfg(target_pointer_width = "32")]
115+
() => {
116+
assert_eq!((0xfedc_ba98_u32 as isize).wrapping_mul(16), (0xedcb_a980_u32 as isize));
117+
}
118+
#[cfg(target_pointer_width = "64")]
119+
() => {
120+
assert_eq!(
121+
(0xfedc_ba98_7654_3217_u64 as isize).wrapping_mul(16),
122+
(0xedcb_a987_6543_2170_u64 as isize)
123+
);
124+
}
125+
}
126+
127+
assert_eq!((0xfe as u8).wrapping_mul(16), (0xe0 as u8));
128+
assert_eq!((0xfedc as u16).wrapping_mul(16), (0xedc0 as u16));
129+
assert_eq!((0xfedc_ba98 as u32).wrapping_mul(16), (0xedcb_a980 as u32));
130+
assert_eq!((0xfedc_ba98_7654_3217 as u64).wrapping_mul(16), (0xedcb_a987_6543_2170 as u64));
131+
132+
match () {
133+
#[cfg(target_pointer_width = "32")]
134+
() => {
135+
assert_eq!((0xfedc_ba98 as usize).wrapping_mul(16), (0xedcb_a980 as usize));
136+
}
137+
#[cfg(target_pointer_width = "64")]
138+
() => {
139+
assert_eq!(
140+
(0xfedc_ba98_7654_3217 as usize).wrapping_mul(16),
141+
(0xedcb_a987_6543_2170 as usize)
142+
);
143+
}
144+
}
145+
146+
macro_rules! check_mul_no_wrap {
147+
($e:expr, $f:expr) => {
148+
assert_eq!(($e).wrapping_mul($f), ($e) * $f);
149+
};
150+
}
151+
macro_rules! check_mul_wraps {
152+
($e:expr, $f:expr) => {
153+
assert_eq!(($e).wrapping_mul($f), $e);
154+
};
155+
}
156+
157+
check_mul_no_wrap!(0xfe_u8 as i8, -1);
158+
check_mul_no_wrap!(0xfedc_u16 as i16, -1);
159+
check_mul_no_wrap!(0xfedc_ba98_u32 as i32, -1);
160+
check_mul_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -1);
161+
check_mul_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, -1);
162+
163+
check_mul_no_wrap!(0xfe_u8 as i8, -2);
164+
check_mul_no_wrap!(0xfedc_u16 as i16, -2);
165+
check_mul_no_wrap!(0xfedc_ba98_u32 as i32, -2);
166+
check_mul_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -2);
167+
check_mul_no_wrap!(0xfedc_ba98_fedc_ba98_u64 as u64 as isize, -2);
168+
169+
check_mul_no_wrap!(0xfe_u8 as i8, 2);
170+
check_mul_no_wrap!(0xfedc_u16 as i16, 2);
171+
check_mul_no_wrap!(0xfedc_ba98_u32 as i32, 2);
172+
check_mul_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, 2);
173+
check_mul_no_wrap!(0xfedc_ba98_fedc_ba98_u64 as u64 as isize, 2);
174+
175+
check_mul_wraps!(0x80_u8 as i8, -1);
176+
check_mul_wraps!(0x8000_u16 as i16, -1);
177+
check_mul_wraps!(0x8000_0000_u32 as i32, -1);
178+
check_mul_wraps!(0x8000_0000_0000_0000_u64 as i64, -1);
179+
match () {
180+
#[cfg(target_pointer_width = "32")]
181+
() => {
182+
check_mul_wraps!(0x8000_0000_u32 as isize, -1);
183+
}
184+
#[cfg(target_pointer_width = "64")]
185+
() => {
186+
check_mul_wraps!(0x8000_0000_0000_0000_u64 as isize, -1);
187+
}
188+
}
189+
190+
macro_rules! check_div_no_wrap {
191+
($e:expr, $f:expr) => {
192+
assert_eq!(($e).wrapping_div($f), ($e) / $f);
193+
};
194+
}
195+
macro_rules! check_div_wraps {
196+
($e:expr, $f:expr) => {
197+
assert_eq!(($e).wrapping_div($f), $e);
198+
};
199+
}
200+
201+
check_div_no_wrap!(0xfe_u8 as i8, -1);
202+
check_div_no_wrap!(0xfedc_u16 as i16, -1);
203+
check_div_no_wrap!(0xfedc_ba98_u32 as i32, -1);
204+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -1);
205+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, -1);
206+
207+
check_div_no_wrap!(0xfe_u8 as i8, -2);
208+
check_div_no_wrap!(0xfedc_u16 as i16, -2);
209+
check_div_no_wrap!(0xfedc_ba98_u32 as i32, -2);
210+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -2);
211+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, -2);
212+
213+
check_div_no_wrap!(0xfe_u8 as i8, 2);
214+
check_div_no_wrap!(0xfedc_u16 as i16, 2);
215+
check_div_no_wrap!(0xfedc_ba98_u32 as i32, 2);
216+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, 2);
217+
check_div_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, 2);
218+
219+
check_div_wraps!(-128 as i8, -1);
220+
check_div_wraps!(0x8000_u16 as i16, -1);
221+
check_div_wraps!(0x8000_0000_u32 as i32, -1);
222+
check_div_wraps!(0x8000_0000_0000_0000_u64 as i64, -1);
223+
match () {
224+
#[cfg(target_pointer_width = "32")]
225+
() => {
226+
check_div_wraps!(0x8000_0000_u32 as isize, -1);
227+
}
228+
#[cfg(target_pointer_width = "64")]
229+
() => {
230+
check_div_wraps!(0x8000_0000_0000_0000_u64 as isize, -1);
231+
}
232+
}
233+
234+
macro_rules! check_rem_no_wrap {
235+
($e:expr, $f:expr) => {
236+
assert_eq!(($e).wrapping_rem($f), ($e) % $f);
237+
};
238+
}
239+
macro_rules! check_rem_wraps {
240+
($e:expr, $f:expr) => {
241+
assert_eq!(($e).wrapping_rem($f), 0);
242+
};
243+
}
244+
245+
check_rem_no_wrap!(0xfe_u8 as i8, -1);
246+
check_rem_no_wrap!(0xfedc_u16 as i16, -1);
247+
check_rem_no_wrap!(0xfedc_ba98_u32 as i32, -1);
248+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -1);
249+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, -1);
250+
251+
check_rem_no_wrap!(0xfe_u8 as i8, -2);
252+
check_rem_no_wrap!(0xfedc_u16 as i16, -2);
253+
check_rem_no_wrap!(0xfedc_ba98_u32 as i32, -2);
254+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, -2);
255+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, -2);
256+
257+
check_rem_no_wrap!(0xfe_u8 as i8, 2);
258+
check_rem_no_wrap!(0xfedc_u16 as i16, 2);
259+
check_rem_no_wrap!(0xfedc_ba98_u32 as i32, 2);
260+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64, 2);
261+
check_rem_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize, 2);
262+
263+
check_rem_wraps!(0x80_u8 as i8, -1);
264+
check_rem_wraps!(0x8000_u16 as i16, -1);
265+
check_rem_wraps!(0x8000_0000_u32 as i32, -1);
266+
check_rem_wraps!(0x8000_0000_0000_0000_u64 as i64, -1);
267+
match () {
268+
#[cfg(target_pointer_width = "32")]
269+
() => {
270+
check_rem_wraps!(0x8000_0000_u32 as isize, -1);
271+
}
272+
#[cfg(target_pointer_width = "64")]
273+
() => {
274+
check_rem_wraps!(0x8000_0000_0000_0000_u64 as isize, -1);
275+
}
276+
}
277+
278+
macro_rules! check_neg_no_wrap {
279+
($e:expr) => {
280+
assert_eq!(($e).wrapping_neg(), -($e));
281+
};
282+
}
283+
macro_rules! check_neg_wraps {
284+
($e:expr) => {
285+
assert_eq!(($e).wrapping_neg(), ($e));
286+
};
287+
}
288+
289+
check_neg_no_wrap!(0xfe_u8 as i8);
290+
check_neg_no_wrap!(0xfedc_u16 as i16);
291+
check_neg_no_wrap!(0xfedc_ba98_u32 as i32);
292+
check_neg_no_wrap!(0xfedc_ba98_7654_3217_u64 as i64);
293+
check_neg_no_wrap!(0xfedc_ba98_7654_3217_u64 as u64 as isize);
294+
295+
check_neg_wraps!(0x80_u8 as i8);
296+
check_neg_wraps!(0x8000_u16 as i16);
297+
check_neg_wraps!(0x8000_0000_u32 as i32);
298+
check_neg_wraps!(0x8000_0000_0000_0000_u64 as i64);
299+
match () {
300+
#[cfg(target_pointer_width = "32")]
301+
() => {
302+
check_neg_wraps!(0x8000_0000_u32 as isize);
303+
}
304+
#[cfg(target_pointer_width = "64")]
305+
() => {
306+
check_neg_wraps!(0x8000_0000_0000_0000_u64 as isize);
307+
}
308+
}
309+
}

‎library/core/tests/ops.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};
2+
use core::ops::{Deref, DerefMut};
23

34
// Test the Range structs and syntax.
45

@@ -197,3 +198,35 @@ fn range_structural_match() {
197198
_ => unreachable!(),
198199
}
199200
}
201+
202+
// Test Deref implementations
203+
204+
#[test]
205+
fn deref_mut_on_ref() {
206+
// Test that `&mut T` implements `DerefMut<T>`
207+
208+
fn inc<T: Deref<Target = isize> + DerefMut>(mut t: T) {
209+
*t += 1;
210+
}
211+
212+
let mut x: isize = 5;
213+
inc(&mut x);
214+
assert_eq!(x, 6);
215+
}
216+
217+
#[test]
218+
fn deref_on_ref() {
219+
// Test that `&T` and `&mut T` implement `Deref<T>`
220+
221+
fn deref<U: Copy, T: Deref<Target = U>>(t: T) -> U {
222+
*t
223+
}
224+
225+
let x: isize = 3;
226+
let y = deref(&x);
227+
assert_eq!(y, 3);
228+
229+
let mut x: isize = 4;
230+
let y = deref(&mut x);
231+
assert_eq!(y, 4);
232+
}

‎library/core/tests/option.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,13 @@ fn test_unwrap_drop() {
402402

403403
assert_eq!(x.get(), 0);
404404
}
405+
406+
#[test]
407+
pub fn option_ext() {
408+
let thing = "{{ f }}";
409+
let f = thing.find("{{");
410+
411+
if f.is_none() {
412+
println!("None!");
413+
}
414+
}

‎library/core/tests/ptr.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,16 @@ fn align_offset_weird_strides() {
400400
}
401401
assert!(!x);
402402
}
403+
404+
#[test]
405+
fn offset_from() {
406+
let mut a = [0; 5];
407+
let ptr1: *mut i32 = &mut a[1];
408+
let ptr2: *mut i32 = &mut a[3];
409+
unsafe {
410+
assert_eq!(ptr2.offset_from(ptr1), 2);
411+
assert_eq!(ptr1.offset_from(ptr2), -2);
412+
assert_eq!(ptr1.offset(2), ptr2);
413+
assert_eq!(ptr2.offset(-2), ptr1);
414+
}
415+
}

‎library/core/tests/result.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,41 @@ fn result_const() {
320320
const IS_ERR: bool = RESULT.is_err();
321321
assert!(!IS_ERR)
322322
}
323+
324+
#[test]
325+
fn result_opt_conversions() {
326+
#[derive(Copy, Clone, Debug, PartialEq)]
327+
struct BadNumErr;
328+
329+
fn try_num(x: i32) -> Result<i32, BadNumErr> {
330+
if x <= 5 { Ok(x + 1) } else { Err(BadNumErr) }
331+
}
332+
333+
type ResOpt = Result<Option<i32>, BadNumErr>;
334+
type OptRes = Option<Result<i32, BadNumErr>>;
335+
336+
let mut x: ResOpt = Ok(Some(5));
337+
let mut y: OptRes = Some(Ok(5));
338+
assert_eq!(x, y.transpose());
339+
assert_eq!(x.transpose(), y);
340+
341+
x = Ok(None);
342+
y = None;
343+
assert_eq!(x, y.transpose());
344+
assert_eq!(x.transpose(), y);
345+
346+
x = Err(BadNumErr);
347+
y = Some(Err(BadNumErr));
348+
assert_eq!(x, y.transpose());
349+
assert_eq!(x.transpose(), y);
350+
351+
let res: Result<Vec<i32>, BadNumErr> = (0..10)
352+
.map(|x| {
353+
let y = try_num(x)?;
354+
Ok(if y % 2 == 0 { Some(y - 1) } else { None })
355+
})
356+
.filter_map(Result::transpose)
357+
.collect();
358+
359+
assert_eq!(res, Err(BadNumErr))
360+
}

‎library/core/tests/unicode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[test]
2+
pub fn version() {
3+
let (major, _minor, _update) = core::unicode::UNICODE_VERSION;
4+
assert!(major >= 10);
5+
}

‎library/std/tests/env.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env::*;
22
use std::ffi::{OsStr, OsString};
3+
use std::path::PathBuf;
34

45
use rand::distributions::Alphanumeric;
56
use rand::{thread_rng, Rng};
@@ -76,3 +77,63 @@ fn test_env_set_var() {
7677

7778
assert!(vars_os().any(|(k, v)| { &*k == &*n && &*v == "VALUE" }));
7879
}
80+
81+
#[test]
82+
#[cfg_attr(any(target_os = "emscripten", target_env = "sgx"), ignore)]
83+
#[allow(deprecated)]
84+
fn env_home_dir() {
85+
fn var_to_os_string(var: Result<String, VarError>) -> Option<OsString> {
86+
match var {
87+
Ok(var) => Some(OsString::from(var)),
88+
Err(VarError::NotUnicode(var)) => Some(var),
89+
_ => None,
90+
}
91+
}
92+
93+
cfg_if::cfg_if! {
94+
if #[cfg(unix)] {
95+
let oldhome = var_to_os_string(var("HOME"));
96+
97+
set_var("HOME", "/home/MountainView");
98+
assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
99+
100+
remove_var("HOME");
101+
if cfg!(target_os = "android") {
102+
assert!(home_dir().is_none());
103+
} else {
104+
// When HOME is not set, some platforms return `None`,
105+
// but others return `Some` with a default.
106+
// Just check that it is not "/home/MountainView".
107+
assert_ne!(home_dir(), Some(PathBuf::from("/home/MountainView")));
108+
}
109+
110+
if let Some(oldhome) = oldhome { set_var("HOME", oldhome); }
111+
} else if #[cfg(windows)] {
112+
let oldhome = var_to_os_string(var("HOME"));
113+
let olduserprofile = var_to_os_string(var("USERPROFILE"));
114+
115+
remove_var("HOME");
116+
remove_var("USERPROFILE");
117+
118+
assert!(home_dir().is_some());
119+
120+
set_var("HOME", "/home/MountainView");
121+
assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
122+
123+
remove_var("HOME");
124+
125+
set_var("USERPROFILE", "/home/MountainView");
126+
assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
127+
128+
set_var("HOME", "/home/MountainView");
129+
set_var("USERPROFILE", "/home/PaloAlto");
130+
assert_eq!(home_dir(), Some(PathBuf::from("/home/MountainView")));
131+
132+
remove_var("HOME");
133+
remove_var("USERPROFILE");
134+
135+
if let Some(oldhome) = oldhome { set_var("HOME", oldhome); }
136+
if let Some(olduserprofile) = olduserprofile { set_var("USERPROFILE", olduserprofile); }
137+
}
138+
}
139+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
// run-pass
2-
// ignore-emscripten no threads support
3-
4-
use std::thread::{self, sleep};
5-
use std::time::Duration;
61
use std::sync::{Arc, Mutex};
2+
use std::thread;
3+
use std::time::Duration;
74
use std::u64;
85

9-
fn main() {
6+
#[test]
7+
#[cfg_attr(target_os = "emscripten", ignore)]
8+
fn sleep() {
109
let finished = Arc::new(Mutex::new(false));
1110
let t_finished = finished.clone();
1211
thread::spawn(move || {
13-
sleep(Duration::new(u64::MAX, 0));
12+
thread::sleep(Duration::new(u64::MAX, 0));
1413
*t_finished.lock().unwrap() = true;
1514
});
16-
sleep(Duration::from_millis(100));
15+
thread::sleep(Duration::from_millis(100));
1716
assert_eq!(*finished.lock().unwrap(), false);
1817
}

‎src/test/ui/assert-eq-trailing-comma.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎src/test/ui/assert-escape.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎src/test/ui/assert-ne-trailing-comma.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎src/test/ui/atomic-access-bool.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎src/test/ui/atomic-alignment.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎src/test/ui/atomic-compare_exchange.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎src/test/ui/bool-not.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎src/test/ui/bool.rs

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎src/test/ui/char_unicode.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎src/test/ui/cmp-default.rs

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎src/test/ui/consts/ascii_ctype.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

‎src/test/ui/consts/const-str-ptr.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/test/ui/deref-mut-on-ref.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎src/test/ui/deref-on-ref.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎src/test/ui/env-home-dir.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎src/test/ui/extend-for-unit.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/test/ui/offset_from.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎src/test/ui/option-ext.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎src/test/ui/result-opt-conversions.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎src/test/ui/utf8.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎src/test/ui/utf8_chars.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎src/test/ui/wrapping-int-api.rs

Lines changed: 0 additions & 228 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.