[Tests] Add const fn and associated const tests

This commit is contained in:
Nikolai Vazquez
2017-08-12 18:09:23 -04:00
parent 6fc86288b5
commit 9c40c746ac
2 changed files with 33 additions and 0 deletions
+5
View File
@@ -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"]
+28
View File
@@ -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);
}