Small syntax hack for nested things

This commit is contained in:
Alex 2022-11-18 18:06:43 +01:00
parent 790aac7f75
commit 24c7a9bbb5
Signed by: lx
GPG key ID: 0E496D15096376BE
3 changed files with 34 additions and 11 deletions

View file

@ -266,10 +266,14 @@ impl<'a> T<'a> {
if d.is_empty() { if d.is_empty() {
buf.extend_from_slice(b"{}"); buf.extend_from_slice(b"{}");
} else if d.len() == 1 { } else if d.len() == 1 {
buf.extend_from_slice(b"{ ");
let (k, v) = d.into_iter().next().unwrap(); let (k, v) = d.into_iter().next().unwrap();
if k.as_ref() == b"." {
buf.extend_from_slice(b"{.= ");
} else {
buf.extend_from_slice(b"{ ");
buf.extend_from_slice(k.borrow()); buf.extend_from_slice(k.borrow());
buf.extend_from_slice(b" = "); buf.extend_from_slice(b" = ");
}
v.encode_aux(buf, indent + 2, false); v.encode_aux(buf, indent + 2, false);
buf.extend_from_slice(b" }"); buf.extend_from_slice(b" }");
} else { } else {

View file

@ -39,6 +39,25 @@ mod tests {
seq = YQ Yg, seq = YQ Yg,
}"#; }"#;
test_bidir(input, expected); test_bidir(input, expected);
let input = vec![
Test {
int: 1,
seq: vec!["a".to_string(), "b".to_string()],
},
Test {
int: 2,
seq: vec!["c".to_string(), "d".to_string()],
},
];
let expected = br#"{.= Test {
int = 1,
seq = YQ Yg,
} } {.= Test {
int = 2,
seq = Yw ZA,
} }"#;
test_bidir(input, expected);
} }
#[test] #[test]