-
Notifications
You must be signed in to change notification settings - Fork 10
/
tests.rs
80 lines (65 loc) · 1.57 KB
/
tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#![feature(plugin)]
#![plugin(interpolate_idents)]
macro_rules! define_foo {
($x:ident) => ( interpolate_idents! {
fn [foo_ $x _1]() -> u32 { 1 }
struct [Foo $x] { [$x _30]: u32 }
impl [Foo $x] {
pub fn new() -> [Foo $x] {
[Foo $x] { [$x _30]: 30 }
}
}
} )
}
define_foo!(bar);
#[test]
fn test_macro() {
assert_eq!(foo_bar_1(), 1);
assert_eq!(Foobar::new().bar_30, 30);
}
macro_rules! define_brackets {
() => ( interpolate_idents! {
fn brackets(data: &[i32; 1]) -> Vec<i32> {
let mut b: Vec<i32> = vec![];
let c: Vec<i32> = vec![1, 2, 3];
let d: Vec<i32> = vec![1; 25];
b.push(c[1]);
b.push(d[1]);
b.push(data[0]);
b
}
} )
}
define_brackets!();
#[test]
fn test_brackets() {
let data = [1; 1];
assert_eq!(brackets(&data), vec![2, 1, 1]);
}
macro_rules! define_underscore_idents {
($x:ident) => ( interpolate_idents! {
fn [_ $x]() -> u32 { 1 }
fn [$x _]() -> u32 { 2 }
fn [_ $x _ $x _]() -> u32 { 3 }
} )
}
define_underscore_idents!(bar);
#[test]
fn test_underscores() {
assert_eq!(_bar(), 1);
assert_eq!(bar_(), 2);
assert_eq!(_bar_bar_(), 3);
}
macro_rules! define_attributes {
($x:ident) => ( interpolate_idents! {
#[inline]
fn [_ $x]() -> u32 { 1 }
#[allow(unreachable_code)]
fn [_ $x _2]() -> u32 { return 1; 2 }
} )
}
define_attributes!(attr);
#[test]
fn test_attributes() {
assert_eq!(_attr(), 1);
}