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
pub mod client;
pub mod codec;
pub mod error;
#[macro_export]
macro_rules! topic {
( $sep:expr, $( $x:expr ),+ ) => {
{
let mut segments = Vec::new();
$(
segments.push($x.to_string());
)+
segments.join(&$sep.to_string())
}
};
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn single_segment_topic_generates_correctly() {
assert_eq!("topic", topic!('/', "topic"));
}
#[test]
fn multi_segment_topic_generates_correctly() {
assert_eq!("some/test/topic", topic!('/', "some", "test", "topic"));
}
#[test]
fn wildcard_topic_generates_correctly() {
assert_eq!("some/?/topic/#", topic!('/', "some", '?', "topic", '#'));
}
#[test]
fn topic_with_postfix_generates_correctly() {
let sep = '_';
let postfix = topic!(sep, "some", "predefined", "postfix");
assert_eq!(
"topic_with_some_predefined_postfix",
topic!(sep, "topic", "with", postfix)
);
}
#[test]
fn topic_with_prefix_generates_correctly() {
let sep = '_';
let prefix = topic!(sep, "some", "predefined", "prefix");
assert_eq!(
"some_predefined_prefix_with_topic",
topic!(sep, prefix, "with", "topic")
);
}
}