Skip to content

Commit 6fa2678

Browse files
committed
Add tests
1 parent 19b1070 commit 6fa2678

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

library/coretests/tests/panic/location.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ use core::panic::Location;
33
// Note: Some of the following tests depend on the source location,
44
// so please be careful when editing this file.
55

6+
mod file_a;
7+
mod file_b;
8+
mod file_c;
9+
10+
// A small shuffled set of locations for testing, along with their true order.
11+
const LOCATIONS: [(usize, &'static Location<'_>); 9] = [
12+
(7, file_c::two()),
13+
(0, file_a::one()),
14+
(3, file_b::one()),
15+
(5, file_b::three()),
16+
(8, file_c::three()),
17+
(6, file_c::one()),
18+
(2, file_a::three()),
19+
(4, file_b::two()),
20+
(1, file_a::two()),
21+
];
22+
623
#[test]
724
fn location_const_caller() {
825
const _CALLER_REFERENCE: &Location<'static> = Location::caller();
@@ -20,7 +37,7 @@ fn location_const_file() {
2037
fn location_const_line() {
2138
const CALLER: &Location<'static> = Location::caller();
2239
const LINE: u32 = CALLER.line();
23-
assert_eq!(LINE, 21);
40+
assert_eq!(LINE, 38);
2441
}
2542

2643
#[test]
@@ -34,6 +51,28 @@ fn location_const_column() {
3451
fn location_debug() {
3552
let f = format!("{:?}", Location::caller());
3653
assert!(f.contains(&format!("{:?}", file!())));
37-
assert!(f.contains("35"));
54+
assert!(f.contains("52"));
3855
assert!(f.contains("29"));
3956
}
57+
58+
#[test]
59+
fn location_eq() {
60+
for (i, a) in LOCATIONS {
61+
for (j, b) in LOCATIONS {
62+
if i == j {
63+
assert_eq!(a, b);
64+
} else {
65+
assert_ne!(a, b);
66+
}
67+
}
68+
}
69+
}
70+
71+
#[test]
72+
fn location_ord() {
73+
let mut locations = LOCATIONS.clone();
74+
locations.sort_by_key(|(_o, l)| **l);
75+
for (correct, (order, _l)) in locations.iter().enumerate() {
76+
assert_eq!(correct, *order);
77+
}
78+
}

0 commit comments

Comments
 (0)