Skip to content

Commit

Permalink
Merge pull request #967 from zeenix/parsed-signature-follow-ups
Browse files Browse the repository at this point in the history
Forgotten changes from PR #966
  • Loading branch information
zeenix authored Sep 2, 2024
2 parents 3f19f40 + 3828116 commit 89f31ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
31 changes: 31 additions & 0 deletions zvariant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,37 @@ mod tests {
}
}

#[test]
fn parsed_signature() {
use crate::parsed;
use std::str::FromStr;

let sig = parsed::Signature::from_str("yys").unwrap();
// parsed::Structure will always add () around the signature if it's a struct.
basic_type_test!(LE, DBus, sig, 7, parsed::Signature, 1);

#[cfg(feature = "gvariant")]
{
let encoded = basic_type_test!(LE, GVariant, sig, 6, parsed::Signature, 1);
decode_with_gvariant::<_, String>(encoded, Some(String::from("yys")));
}

// As Value
let v: Value<'_> = sig.into();
assert_eq!(v.value_signature(), "g");
let encoded = value_test!(LE, DBus, v, 10);
let v = encoded.deserialize::<Value<'_>>().unwrap().0;
assert_eq!(v, Value::Signature(Signature::try_from("yys").unwrap()));

// GVariant format now
#[cfg(feature = "gvariant")]
{
let encoded = value_test!(LE, GVariant, v, 8);
let v = encoded.deserialize::<Value<'_>>().unwrap().0;
assert_eq!(v, Value::Signature(Signature::try_from("yys").unwrap()));
}
}

#[test]
fn object_path_value() {
let o = ObjectPath::try_from("/hello/world").unwrap();
Expand Down
13 changes: 12 additions & 1 deletion zvariant/src/parsed/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
str::FromStr,
};

use crate::{serialized::Format, Type};
use crate::{serialized::Format, Basic, Type};

/// A D-Bus signature in parsed form.
///
Expand Down Expand Up @@ -735,3 +735,14 @@ impl<'de> Deserialize<'de> for Signature {
})
}
}

impl Basic for Signature {
const SIGNATURE_CHAR: char = 'g';
const SIGNATURE_STR: &'static str = "g";
}

impl From<Signature> for crate::Value<'static> {
fn from(value: Signature) -> Self {
crate::Value::Signature(value.into())
}
}

0 comments on commit 89f31ec

Please sign in to comment.