mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Tests: read the active nightly id assignment in either quote style
The nightly-ids test now reads the last uncommented IDENTIFIER and MAC_NIGHTLY_ID assignment and accepts single or double quotes, so a commented-out old line no longer satisfies it.
This commit is contained in:
1 parent
7330cf12d8
commit
d73142fbd2
1 file changed
+22
-2
@@ -124,9 +124,29 @@ mod tests {
|
||||
assert_eq!(NIGHTLY_APP_ID.strip_suffix("-v1"), Some(NIGHTLY_PACKAGE_ID), "the window id is the package id plus -v1");
|
||||
// The packaging publishes the same package id.
|
||||
let plist = include_str!("../../../packaging/macos/nightly_plist.py");
|
||||
assert!(plist.contains(&format!("IDENTIFIER = \"{NIGHTLY_PACKAGE_ID}\"")), "nightly_plist.py");
|
||||
assert_eq!(assigned(plist, "IDENTIFIER"), Some(NIGHTLY_PACKAGE_ID), "nightly_plist.py");
|
||||
let lib = include_str!("../../../packaging/macos/nightly-lib.sh");
|
||||
assert!(lib.contains(&format!("MAC_NIGHTLY_ID='{NIGHTLY_PACKAGE_ID}'")), "nightly-lib.sh");
|
||||
assert_eq!(assigned(lib, "MAC_NIGHTLY_ID"), Some(NIGHTLY_PACKAGE_ID), "nightly-lib.sh");
|
||||
}
|
||||
|
||||
/// The value of the last uncommented top-level `name = value` or `name=value` line, with one pair of
|
||||
/// single or double quotes removed.
|
||||
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))
|
||||
})
|
||||
.next_back()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assigned_reads_the_active_line_in_either_quote_style() {
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user