Fix alias modifier and add serialization tests
This commit is contained in:
parent
ca1a84eeee
commit
a078b9c322
|
@ -21,8 +21,9 @@ macro_rules! message_func {
|
|||
macro_rules! message_format {
|
||||
[ @st ( $name:ident $field:tt: $type:tt alias = $alias:tt, $($rest:tt)* ) -> ( $($out:tt)* ) ] => {
|
||||
message_format![ @st
|
||||
( $name $field: $type, $($rest)* ) -> (
|
||||
#[serde(rename = $alias)]
|
||||
( $name $($rest)* ) -> (
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename = $alias)]
|
||||
pub $field: Option<$type>,
|
||||
$($out)*
|
||||
)
|
||||
];
|
||||
|
|
|
@ -48,3 +48,55 @@ message_format![SetActivitySecrets
|
|||
spectate: String,
|
||||
game: String alias = "match",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn test_set_activity_serialize() {
|
||||
let activity = SetActivity::new()
|
||||
.state("rusting")
|
||||
.instance(true);
|
||||
let json = serde_json::to_string(&activity).unwrap();
|
||||
assert_eq![json, r#"{"instance":true,"state":"rusting"}"#];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_activity_timestamps_serialize() {
|
||||
let timestamps = SetActivityTimestamps::new()
|
||||
.start(1000)
|
||||
.end(2000);
|
||||
let json = serde_json::to_string(×tamps).unwrap();
|
||||
assert_eq![json, r#"{"end":2000,"start":1000}"#];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_activity_assets_serialize() {
|
||||
let assets = SetActivityAssets::new()
|
||||
.large_image("ferris")
|
||||
.small_image("rusting");
|
||||
let json = serde_json::to_string(&assets).unwrap();
|
||||
assert_eq![json, r#"{"small_image":"rusting","large_image":"ferris"}"#];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_activity_party_serialize() {
|
||||
let party = SetActivityParty::new()
|
||||
.id(1)
|
||||
.size((1, 10));
|
||||
let json = serde_json::to_string(&party).unwrap();
|
||||
assert_eq![json, r#"{"size":[1,10],"id":1}"#];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_activity_secrets_serialize() {
|
||||
let secrets = SetActivitySecrets::new()
|
||||
.join("j1")
|
||||
.spectate("s1")
|
||||
.game("g1");
|
||||
let json = serde_json::to_string(&secrets).unwrap();
|
||||
assert_eq![json, r#"{"match":"g1","spectate":"s1","join":"j1"}"#.to_string()];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue