mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 14:51:20 -05:00
Tests: ignore a trailing comment after the nightly id assignment
The packaging check's `assigned` helper now drops a `#` comment that follows the value, quoted or bare, so `IDENTIFIER = "x" # bundle ID` still reads as `x`.
This commit is contained in:
@@ -130,14 +130,20 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The value of the last uncommented top-level `name = value` or `name=value` line, with one pair of
|
||||
/// single or double quotes removed.
|
||||
/// single or double quotes removed and a trailing `#` comment after the value ignored.
|
||||
fn assigned<'a>(source: &'a str, name: &str) -> Option<&'a str> {
|
||||
source
|
||||
.lines()
|
||||
.filter_map(|line| {
|
||||
let rest = line.strip_prefix(name)?.trim_start().strip_prefix('=')?.trim();
|
||||
let unquoted = ['\'', '"'].iter().find_map(|q| rest.strip_prefix(*q)?.strip_suffix(*q));
|
||||
Some(unquoted.unwrap_or(rest))
|
||||
let quoted = ['\'', '"'].iter().find_map(|q| {
|
||||
let inner = rest.strip_prefix(*q)?;
|
||||
let end = inner.find(*q)?;
|
||||
let after = inner[end + 1..].trim();
|
||||
(after.is_empty() || after.starts_with('#')).then(|| &inner[..end])
|
||||
});
|
||||
let bare = rest.split_once(" #").map_or(rest, |(value, _)| value.trim_end());
|
||||
Some(quoted.unwrap_or(bare))
|
||||
})
|
||||
.next_back()
|
||||
}
|
||||
@@ -147,6 +153,9 @@ mod tests {
|
||||
assert_eq!(assigned("# ID='old'\nID=\"new\"\n", "ID"), Some("new"));
|
||||
assert_eq!(assigned("ID = 'a'\n", "ID"), Some("a"));
|
||||
assert_eq!(assigned("IDX='a'\n", "ID"), None);
|
||||
assert_eq!(assigned("ID = 'a' # bundle ID\n", "ID"), Some("a"));
|
||||
assert_eq!(assigned("ID=\"a\" # bundle ID\n", "ID"), Some("a"));
|
||||
assert_eq!(assigned("ID=a # bundle ID\n", "ID"), Some("a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user