From 446f6c1f8145c2164699207fbf201542f27545cb Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 31 Aug 2020 16:31:48 +0900 Subject: [PATCH] Update tests --- .github/workflows/ci.yml | 1 + test_suite/build.rs | 3 + test_suite/tests/test.rs | 122 ++++++++++++++++----------------------- 3 files changed, 54 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f7cf72..63e3ab4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: - 1.31.0 - 1.33.0 - 1.39.0 + - 1.46.0 - stable - beta - nightly diff --git a/test_suite/build.rs b/test_suite/build.rs index e486587..4b0aea7 100644 --- a/test_suite/build.rs +++ b/test_suite/build.rs @@ -17,6 +17,9 @@ fn main() { if minor >= 39 || nightly { println!("cargo:rustc-cfg=has_const_vec_new"); } + if minor >= 46 || nightly { + println!("cargo:rustc-cfg=has_const_match"); + } if nightly { println!("cargo:rustc-cfg=const_unstable"); } diff --git a/test_suite/tests/test.rs b/test_suite/tests/test.rs index 1a3ac10..d0c106f 100644 --- a/test_suite/tests/test.rs +++ b/test_suite/tests/test.rs @@ -4,31 +4,15 @@ pub mod version { use const_fn::const_fn; - #[test] - fn test_variables() { - assert!(const_min("variables") == "variables"); - assert_eq!(const_let("variables"), "variables"); - assert_eq!(const_vec_new::(), Vec::new()); - assert_eq!(A::const_unstable(const_vec_new::()), A(Vec::new())); - } - - // min_const_fn (rust 1.31+) + // min_const_fn (1.31+) #[const_fn("1.31")] const fn const_min(x: T) -> T { x } + const _CONST_MIN: &str = const_min("min_const_fn"); - const CONST_MIN: &str = const_min("min_const_fn"); - - #[test] - fn test_const_min() { - assert!(CONST_MIN == "min_const_fn"); - assert_eq!(const_let("min_const_fn"), "min_const_fn"); - assert_eq!(const_vec_new::(), Vec::new()); - } - - // const_let (rust 1.33+) + // const_let (1.33+) #[allow(clippy::let_and_return)] #[const_fn("1.33")] @@ -36,34 +20,31 @@ pub mod version { let y = const_min(x); y } - #[rustversion::since(1.33)] - const CONST_LET: &str = const_let("const_let"); + const _CONST_LET: &str = const_let("const_let"); - #[rustversion::since(1.33)] - #[test] - fn test_const_let() { - assert!(CONST_LET == "const_let"); - assert_eq!(const_vec_new::(), Vec::new()); - } - - // const_vec_new (rust 1.39+) + // const_vec_new (1.39+) #[const_fn("1.39")] const fn const_vec_new() -> Vec { Vec::new() } - #[rustversion::since(1.39)] - const CONST_VEC_NEW: Vec = const_vec_new(); + const _: Vec = const_vec_new(); - #[rustversion::since(1.39)] - #[test] - fn test_const_vec_new() { - assert_eq!(CONST_VEC_NEW, Vec::new()); + // const_match, const_loop (1.46+) + + #[const_fn("1.46")] + const fn const_match(x: u8) -> Option { + match x { + 0 => None, + x => Some(x), + } } + #[rustversion::since(1.46)] + const _: Option = const_match(1); - // const_fn (rust nightly) + // const_fn (nightly) #[derive(Debug, Eq, PartialEq)] pub struct A(T); @@ -74,39 +55,31 @@ pub mod version { A(x) } } - #[rustversion::nightly] - pub const CONST_UNSTABLE: A> = A::const_unstable(const_vec_new()); -} - -pub mod cfg { - use const_fn::const_fn; + const _: A> = A::const_unstable(const_vec_new()); #[test] - fn test_variables() { + fn test() { assert!(const_min("variables") == "variables"); assert_eq!(const_let("variables"), "variables"); assert_eq!(const_vec_new::(), Vec::new()); + assert_eq!(const_match(1), Some(1)); assert_eq!(A::const_unstable(const_vec_new::()), A(Vec::new())); } +} + +pub mod cfg { + use const_fn::const_fn; - // min_const_fn (rust 1.31+) + // min_const_fn (1.31+) #[const_fn(cfg(has_min_const_fn))] const fn const_min(x: T) -> T { x } + const _CONST_MIN: &str = const_min("min_const_fn"); - pub const CONST_MIN: &str = const_min("min_const_fn"); - - #[test] - fn test_const_min() { - assert!(CONST_MIN == "min_const_fn"); - assert_eq!(const_let("min_const_fn"), "min_const_fn"); - assert_eq!(const_vec_new::(), Vec::new()); - } - - // const_let (rust 1.33+) + // const_let (1.33+) #[allow(clippy::let_and_return)] #[const_fn(cfg(has_const_let))] @@ -114,34 +87,31 @@ pub mod cfg { let y = const_min(x); y } - #[rustversion::since(1.33)] - const CONST_LET: &str = const_let("const_let"); - - #[rustversion::since(1.33)] - #[test] - fn test_const_let() { - assert!(CONST_LET == "const_let"); - assert_eq!(const_vec_new::(), Vec::new()); - } + const _CONST_LET: &str = const_let("const_let"); - // const_vec_new (rust 1.39+) + // const_vec_new (1.39+) #[const_fn(cfg(has_const_vec_new))] const fn const_vec_new() -> Vec { Vec::new() } - #[rustversion::since(1.39)] - const CONST_VEC_NEW: Vec = const_vec_new(); + const _: Vec = const_vec_new(); - #[rustversion::since(1.39)] - #[test] - fn test_const_vec_new() { - assert_eq!(CONST_VEC_NEW, Vec::new()); + // const_match, const_loop (1.46+) + + #[const_fn(cfg(has_const_match))] + const fn const_match(x: u8) -> Option { + match x { + 0 => None, + x => Some(x), + } } + #[rustversion::since(1.46)] + const _: Option = const_match(1); - // const_fn (rust nightly) + // const_fn (nightly) #[derive(Debug, Eq, PartialEq)] pub struct A(T); @@ -152,7 +122,15 @@ pub mod cfg { A(x) } } - #[rustversion::nightly] pub const CONST_UNSTABLE: A> = A::const_unstable(const_vec_new()); + + #[test] + fn test() { + assert!(const_min("variables") == "variables"); + assert_eq!(const_let("variables"), "variables"); + assert_eq!(const_vec_new::(), Vec::new()); + assert_eq!(const_match(1), Some(1)); + assert_eq!(A::const_unstable(const_vec_new::()), A(Vec::new())); + } }