Add test cases for const Location

This commit is contained in:
woppopo 2022-09-27 19:09:32 +00:00
parent 4e3b9ed337
commit 834cab7244
3 changed files with 34 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#![feature(const_assume)]
#![feature(const_black_box)]
#![feature(const_bool_to_option)]
#![feature(const_caller_location)]
#![feature(const_cell_into_inner)]
#![feature(const_convert)]
#![feature(const_heap)]
@ -131,6 +132,7 @@ mod num;
mod ops;
mod option;
mod pattern;
mod panic;
mod pin;
mod pin_macro;
mod ptr;

View file

@ -0,0 +1 @@
mod location;

View file

@ -0,0 +1,31 @@
use core::panic::Location;
// Note: Some of the following tests depend on the source location,
// so please be careful when editing this file.
#[test]
fn location_const_caller() {
const _CALLER_REFERENCE: &Location<'static> = Location::caller();
const _CALLER: Location<'static> = *Location::caller();
}
#[test]
fn location_const_file() {
const CALLER: &Location<'static> = Location::caller();
const FILE: &str = CALLER.file();
assert_eq!(FILE, "library/core/tests/panic/location.rs");
}
#[test]
fn location_const_line() {
const CALLER: &Location<'static> = Location::caller();
const LINE: u32 = CALLER.line();
assert_eq!(LINE, 21);
}
#[test]
fn location_const_column() {
const CALLER: &Location<'static> = Location::caller();
const COLUMN: u32 = CALLER.column();
assert_eq!(COLUMN, 39);
}