Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Split item and expr position tests
Browse files Browse the repository at this point in the history
The item ones can run on older compilers.
  • Loading branch information
dtolnay committed Jul 26, 2020
1 parent ce0fd00 commit 624eca6
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 202 deletions.
201 changes: 201 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
use paste::paste;

#[test]
fn test_shared_hygiene() {
paste! {
let [<a a>] = 1;
assert_eq!([<a a>], 1);
}
}

#[test]
fn test_repeat() {
const ROCKET_A: &'static str = "/a";
const ROCKET_B: &'static str = "/b";

macro_rules! routes {
($($route:ident),*) => {{
paste! {
vec![$( [<ROCKET_ $route>] ),*]
}
}}
}

let routes = routes!(A, B);
assert_eq!(routes, vec!["/a", "/b"]);
}

#[test]
fn test_integer() {
const CONST0: &'static str = "const0";

let pasted = paste!([<CONST 0>]);
assert_eq!(pasted, CONST0);
}

#[test]
fn test_underscore() {
paste! {
const A_B: usize = 0;
assert_eq!([<A _ B>], 0);
}
}

#[test]
fn test_lifetime() {
paste! {
#[allow(dead_code)]
struct S<[<'d e>]> {
q: &[<'d e>] str,
}
}
}

#[test]
fn test_keyword() {
paste! {
struct [<F move>];

let _ = Fmove;
}
}

#[test]
fn test_literal_str() {
paste! {
#[allow(non_camel_case_types)]
struct [<Foo "Bar-Baz">];

let _ = FooBar_Baz;
}
}

#[test]
fn test_env_literal() {
paste! {
struct [<Lib env bar>];

let _ = Libenvbar;
}
}

#[test]
fn test_env_present() {
paste! {
struct [<Lib env!("CARGO_PKG_NAME")>];

let _ = Libpaste;
}
}

#[test]
fn test_raw_identifier() {
paste! {
struct [<F r#move>];

let _ = Fmove;
}
}

#[test]
fn test_false_start() {
trait Trait {
fn f() -> usize;
}

struct S;

impl Trait for S {
fn f() -> usize {
0
}
}

paste! {
let x = [<S as Trait>::f()];
assert_eq!(x[0], 0);
}
}

#[test]
fn test_local_variable() {
let yy = 0;

paste! {
assert_eq!([<y y>], 0);
}
}

#[test]
fn test_empty() {
paste! {
assert_eq!(stringify!([<y y>]), "yy");
assert_eq!(stringify!([<>]).replace(' ', ""), "[<>]");
}
}

#[test]
fn test_env_to_lower() {
paste! {
struct [<Lib env!("CARGO_PKG_NAME"):lower>];

let _ = Libpaste;
}
}

#[test]
fn test_env_to_upper() {
paste! {
const [<LIB env!("CARGO_PKG_NAME"):upper>]: &str = "libpaste";

let _ = LIBPASTE;
}
}

#[test]
fn test_env_to_snake() {
paste! {
const [<LIB env!("CARGO_PKG_NAME"):snake:upper>]: &str = "libpaste";

let _ = LIBPASTE;
}
}

#[test]
fn test_env_to_camel() {
paste! {
#[allow(non_upper_case_globals)]
const [<LIB env!("CARGO_PKG_NAME"):camel>]: &str = "libpaste";

let _ = LIBPaste;
}
}

mod test_x86_feature_literal {
// work around https://github.com/rust-lang/rust/issues/72726

use paste::paste;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
macro_rules! my_is_x86_feature_detected {
($feat:literal) => {
paste! {
#[test]
fn test() {
let _ = is_x86_feature_detected!($feat);
}
}
};
}

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
macro_rules! my_is_x86_feature_detected {
($feat:literal) => {
#[ignore]
#[test]
fn test() {}
};
}

my_is_x86_feature_detected!("mmx");
}
Loading

0 comments on commit 624eca6

Please sign in to comment.