From b2ba646fd4e50589fbe12a8e2faf56413ee7e109 Mon Sep 17 00:00:00 2001 From: famfo Date: Tue, 6 Feb 2024 00:49:37 +0100 Subject: [PATCH] Implement empty before for QuerySet --- parsers/src/rsm.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/parsers/src/rsm.rs b/parsers/src/rsm.rs index 9eb11dd0..af3aa744 100644 --- a/parsers/src/rsm.rs +++ b/parsers/src/rsm.rs @@ -78,10 +78,13 @@ impl From for Element { set.after .map(|after| Element::builder("after", ns::RSM).append(after)), ) - .append_all( - set.before - .map(|before| Element::builder("before", ns::RSM).append(before)), - ) + .append_all(set.before.map(|before| { + let mut builder = Element::builder("before", ns::RSM); + if !before.is_empty() { + builder = builder.append(before); + } + builder + })) .append_all( set.index .map(|index| Element::builder("index", ns::RSM).append(format!("{}", index))), @@ -278,6 +281,21 @@ mod tests { assert_eq!(elem, elem2); } + #[test] + fn test_serialise_empty_before() { + let elem: Element = "" + .parse() + .unwrap(); + let rsm = SetQuery { + max: None, + after: None, + before: Some("".into()), + index: None, + }; + let elem2 = rsm.into(); + assert_eq!(elem, elem2); + } + #[test] fn test_first_index() { let elem: Element =