mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-09 08:03:50 +00:00
Allow empty lines in annotations (#7394)
This commit is contained in:
@@ -51,13 +51,15 @@ pub fn annotations(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let mut lines = code.lines();
|
||||
|
||||
while let Some(line) = lines.next() {
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
if !line.starts_with(#comm_lit) {
|
||||
break;
|
||||
}
|
||||
let line = line[#comm_lit.len()..].trim();
|
||||
let (key, value) = line.split_once('=').unwrap_or((line, ""));
|
||||
|
||||
|
||||
match key {
|
||||
#(
|
||||
stringify!(#custom_field_names) => {
|
||||
|
||||
@@ -102,12 +102,12 @@ mod annotations_tests {
|
||||
|
||||
#[test]
|
||||
fn spacing_integration() {
|
||||
// First line is ignored and not used
|
||||
// First line is ignored
|
||||
{
|
||||
let cont = "
|
||||
# ann2";
|
||||
let expected = Annotations { ..Default::default() };
|
||||
assert_eq!(expected, old(cont));
|
||||
let expected = Annotations { ann2: true, ..Default::default() };
|
||||
// assert_eq!(expected, old(cont));
|
||||
assert_eq!(expected, Annotations::parse(cont));
|
||||
}
|
||||
// Wrong spacing for ann3
|
||||
@@ -139,11 +139,10 @@ mod annotations_tests {
|
||||
# Actual annotation next line:
|
||||
# ann5
|
||||
|
||||
# Should be ignored
|
||||
# ann3
|
||||
";
|
||||
let expected = Annotations { ann2: true, ann5: true, ..Default::default() };
|
||||
assert_eq!(expected, old(cont));
|
||||
let expected = Annotations { ann2: true, ann5: true, ann3: true, ..Default::default() };
|
||||
// assert_eq!(expected, old(cont));
|
||||
assert_eq!(expected, Annotations::parse(cont));
|
||||
}
|
||||
|
||||
@@ -168,6 +167,17 @@ mod annotations_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newline_between() {
|
||||
let cont = "// ann1
|
||||
|
||||
// ann2";
|
||||
assert_eq!(
|
||||
SlashedAnnotations { ann1: true, ann2: true, ann3: false, ann4: false },
|
||||
SlashedAnnotations::parse(cont)
|
||||
);
|
||||
}
|
||||
|
||||
// // #[derive(serde_derive::Serialize, serde_derive::Deserialize, Eq, PartialEq)]
|
||||
// // #[annotations("#")]
|
||||
// // pub struct SerAnnotations {
|
||||
|
||||
Reference in New Issue
Block a user