mirror of
https://github.com/openharmony/third_party_rust_static-assertions-rs.git
synced 2026-07-20 01:04:23 -04:00
[Tests] Add const fn and associated const tests
This commit is contained in:
@@ -10,3 +10,8 @@ description = "Compile-time assertions to ensure that invariants are met."
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "nvzqz/static-assertions-rs" }
|
||||
|
||||
[features]
|
||||
# For testing
|
||||
const_fn = []
|
||||
nightly = ["const_fn"]
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![no_std]
|
||||
|
||||
#![cfg_attr(feature = "const_fn", feature(const_fn))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate static_assertions;
|
||||
|
||||
@@ -10,3 +12,29 @@ fn const_assert() {
|
||||
const_assert!(FIVE * 2 == 10);
|
||||
const_assert!(FIVE > 2);
|
||||
}
|
||||
|
||||
#[cfg(feature = "const_fn")]
|
||||
#[test]
|
||||
fn const_fn() {
|
||||
const VALUE: usize = 4;
|
||||
|
||||
const fn value() -> usize {
|
||||
VALUE
|
||||
}
|
||||
|
||||
const_assert!(value() == VALUE);
|
||||
}
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
#[test]
|
||||
fn assoc_const() {
|
||||
const FOUR: usize = 4;
|
||||
trait Assoc { const VAL: usize; }
|
||||
struct Concrete;
|
||||
|
||||
impl Assoc for Concrete {
|
||||
const VAL: usize = FOUR;
|
||||
}
|
||||
|
||||
const_assert!(Concrete::VAL == FOUR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user