Skip to content

Commit 7e104fd

Browse files
ClSlaidsmoelius
authored andcommitted
patch: more tests
Signed-off-by: cl <[email protected]>
1 parent bda492f commit 7e104fd

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

internal/src/rustup.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ pub fn active_toolchain(path: &Path) -> Result<String> {
3434
parse_active_toolchain(stdout)
3535
}
3636

37+
// Split from the first whitespace character
38+
//
39+
// Note:
40+
// Unicode whitespace characters are not considered as whitespace characters.
3741
fn parse_active_toolchain(active: &str) -> Result<String> {
3842
active
3943
.split_ascii_whitespace()
40-
.take(1)
41-
.map(|s| s.to_owned())
4244
.next()
45+
.map(str::to_owned)
4346
.ok_or_else(|| anyhow!("Could not determine active toolchain"))
4447
}
4548

@@ -74,12 +77,23 @@ mod rustup_test {
7477

7578
#[test]
7679
fn test_parse_active_toolchain() {
77-
let output = r#"nightly-aarch64-apple-darwin
78-
active because: it's the default toolchain
79-
"#;
80-
assert_eq!(
81-
parse_active_toolchain(output).unwrap(),
82-
"nightly-aarch64-apple-darwin".to_owned()
83-
);
80+
let outputs = [
81+
"nightly-aarch64-apple-darwin\ractive because: it's the default toolchain",
82+
"nightly-x86_64-pc-windows-msvc (default)\r\nactive toolchain",
83+
"1.85.0-rv64gc-unknown-linux-gnu\nactive because: overridden by '/home/user/rust-with-riscv/rust-toolchain'",
84+
// allow full width space (\u3000)
85+
"自定义 rust\nactive because: overridden by '/root/app/rust-toolchain.toml'",
86+
"私の rust\r\nactive because: overridden by 'C:\\Users\\watashi\\rust-練習\\rust-toolchain.toml'",
87+
];
88+
let expects = [
89+
"nightly-aarch64-apple-darwin",
90+
"nightly-x86_64-pc-windows-msvc",
91+
"1.85.0-rv64gc-unknown-linux-gnu",
92+
"自定义 rust",
93+
"私の rust",
94+
];
95+
for (output, expect) in outputs.iter().zip(expects.iter()) {
96+
assert_eq!(parse_active_toolchain(output).unwrap(), *expect);
97+
}
8498
}
8599
}

0 commit comments

Comments
 (0)