mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-04 20:37:56 +00:00
Fix ruby version to not assume length (#1082)
This commit is contained in:
parent
b11fe2ad30
commit
19e8301ff1
@ -38,7 +38,10 @@ fn format_ruby_version(ruby_version: &str) -> Option<String> {
|
|||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
// return "2.6.0p0"
|
// return "2.6.0p0"
|
||||||
.nth(1)?
|
.nth(1)?
|
||||||
.get(0..5)?;
|
// split into ["2.6.0", "0"]
|
||||||
|
.split('p')
|
||||||
|
// return "2.6.0"
|
||||||
|
.next()?;
|
||||||
|
|
||||||
let mut formatted_version = String::with_capacity(version.len() + 1);
|
let mut formatted_version = String::with_capacity(version.len() + 1);
|
||||||
formatted_version.push('v');
|
formatted_version.push('v');
|
||||||
@ -104,6 +107,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_ruby_version() -> io::Result<()> {
|
fn test_format_ruby_version() -> io::Result<()> {
|
||||||
|
assert_eq!(
|
||||||
|
format_ruby_version("ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin19.0]"),
|
||||||
|
Some("v2.1.10".to_string())
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format_ruby_version("ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]"),
|
format_ruby_version("ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]"),
|
||||||
Some("v2.5.1".to_string())
|
Some("v2.5.1".to_string())
|
||||||
|
Loading…
Reference in New Issue
Block a user