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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
use libquassel_derive::Network;
#[derive(Clone, Debug, std::cmp::PartialEq, Network)]
#[network(repr = "list")]
pub struct AliasManager {
#[network(rename = "Aliases", variant = "VariantMap", network)]
pub aliases: Vec<Alias>,
}
#[derive(Clone, Debug, std::cmp::PartialEq, Network)]
#[network(repr = "maplist")]
pub struct Alias {
#[network(rename = "names", variant = "StringList")]
name: String,
#[network(rename = "expansions", variant = "StringList")]
expansion: String,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::message::signalproxy::translation::Network;
use crate::primitive::{Variant, VariantList};
fn get_src() -> AliasManager {
AliasManager {
aliases: vec![
Alias {
name: s!("j"),
expansion: s!("/join $0"),
},
Alias {
name: s!("ns"),
expansion: s!("/msg nickserv $0"),
},
],
}
}
fn get_dest() -> VariantList {
vec![
Variant::ByteArray(s!("Aliases")),
Variant::VariantMap(map! {
s!("names") => Variant::StringList(
vec![
s!("j"),
s!("ns"),
],
),
s!("expansions") => Variant::StringList(
vec![
s!("/join $0"),
s!("/msg nickserv $0"),
],
),
}),
]
}
// #[bench]
// fn alias_to_network(b: &mut test::Bencher) {
// b.iter(|| test::black_box(get_src()).to_network())
// }
// #[bench]
// fn alias_from_network(b: &mut test::Bencher) {
// b.iter(|| AliasManager::from_network(&mut test::black_box(get_dest())))
// }
#[test]
fn aliasmanager_to_network() {
assert_eq!(get_src().to_network(), get_dest())
}
#[test]
fn aliasmanager_from_network() {
assert_eq!(AliasManager::from_network(&mut get_dest()), get_src())
}
}
// impl AliasManager {
// /// Client to Server
// ///
// /// Replaces all properties of the object with the content of the
// /// "properties" parameter. This parameter is in network representation.
// ///
// fn request_update(self: &mut Self, properties: VariantMap) {
// self.update(properties);
// }
// /// Server to Client
// fn add_alias(self: &mut Self, name: String, expansion: String) {
// self.aliases.push(Alias { name, expansion });
// }
// /// Server to Client
// ///
// /// Replaces all properties of the object with the content of the
// /// "properties" parameter. This parameter is in network representation.
// ///
// fn update(self: &mut Self, properties: VariantMap) {
// let mut alias: Vec<Alias> = Vec::new();
// // for (i, name) in match_variant!(properties[&"Aliases".to_string()], Variant::String) {
// // alias.push(Alias {
// // name,
// // expansion: match_variant!(properties["Aliases"], Variant::String)["expansions"][i],
// // })
// // }
// self.aliases = alias
// }
// }
|