Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Fields and message expansion feature #290

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
coverage
  • Loading branch information
pamburus committed Jun 29, 2024
commit 04ed3f2c6512ee9feba0ee6268e9783bb0ea2d9a
50 changes: 50 additions & 0 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2741,4 +2741,54 @@ mod tests {
assert_eq!(buf, br#""""#);
assert_eq!(result.is_ok(), true);
}

#[test]
fn test_expand_inline() {
let rec = |value| Record {
fields: RecordFields {
head: heapless::Vec::from_slice(&[("a", EncodedString::raw(value).into())]).unwrap(),
..Default::default()
},
..Default::default()
};

let formatter = RecordFormatter::new(settings().with(|s| {
s.theme = Default::default();
s.expansion.mode = ExpansionMode::Inline;
}));

assert_eq!(
formatter.format_to_string(&rec("some single-line message")),
r#"a="some single-line message""#
);
assert_eq!(
formatter.format_to_string(&rec("some\nmultiline\nmessage")),
"a=`some\nmultiline\nmessage`"
);
}

#[test]
fn test_expand_low() {
let rec = |value| Record {
fields: RecordFields {
head: heapless::Vec::from_slice(&[("a", EncodedString::raw(value).into())]).unwrap(),
..Default::default()
},
..Default::default()
};

let formatter = RecordFormatter::new(settings().with(|s| {
s.theme = Default::default();
s.expansion.mode = ExpansionMode::Low;
}));

assert_eq!(
formatter.format_to_string(&rec("some single-line message")),
r#"a="some single-line message""#
);
assert_eq!(
formatter.format_to_string(&rec("some\nmultiline\nmessage")),
"~\n > a=|=>\n \tsome\n \tmultiline\n \tmessage"
);
}
}