-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
58 lines (52 loc) · 2.05 KB
/
Copy pathlib.rs
File metadata and controls
58 lines (52 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Pure platform → GitHub-release-asset mapping for the SchemaLock Zed
//! extension. This crate has no `zed_extension_api` dependency so it is
//! unit-testable on the host with plain `cargo test`.
/// A resolved host platform, expressed as the lowercase strings the Zed glue
/// derives from `zed::current_platform()`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Platform {
/// "mac" | "linux" | "windows"
pub os: &'static str,
/// "aarch64" | "x86" | "x8664"
pub arch: &'static str,
}
/// Returns the GitHub release asset name for `platform`, or `None` if SchemaLock
/// publishes no prebuilt binary for that os/arch combination.
///
/// Asset names are the exact `schemalock/schemalock` release asset filenames.
pub fn asset_name(platform: &Platform) -> Option<&'static str> {
match (platform.os, platform.arch) {
("mac", "aarch64") => Some("schemalock-darwin-arm64"),
("mac", "x8664") => Some("schemalock-darwin-x64"),
("linux", "aarch64") => Some("schemalock-linux-arm64"),
("linux", "x8664") => Some("schemalock-linux-x64"),
("windows", "x8664") => Some("schemalock-win32-x64.exe"),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
fn p(os: &'static str, arch: &'static str) -> Platform {
Platform { os, arch }
}
#[test]
fn maps_supported_platforms() {
let cases = [
(("mac", "aarch64"), "schemalock-darwin-arm64"),
(("mac", "x8664"), "schemalock-darwin-x64"),
(("linux", "aarch64"), "schemalock-linux-arm64"),
(("linux", "x8664"), "schemalock-linux-x64"),
(("windows", "x8664"), "schemalock-win32-x64.exe"),
];
for ((os, arch), want) in cases {
assert_eq!(asset_name(&p(os, arch)), Some(want), "for {os}/{arch}");
}
}
#[test]
fn unsupported_platforms_return_none() {
assert_eq!(asset_name(&p("linux", "x86")), None);
assert_eq!(asset_name(&p("windows", "aarch64")), None);
assert_eq!(asset_name(&p("freebsd", "x8664")), None);
}
}