|
| 1 | +use crate::utils::helpers::{extract_beta_rev, hex_encode, make}; |
| 2 | +use std::path::PathBuf; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn test_make() { |
| 6 | + for (host, make_path) in vec![ |
| 7 | + ("dragonfly", PathBuf::from("gmake")), |
| 8 | + ("netbsd", PathBuf::from("gmake")), |
| 9 | + ("freebsd", PathBuf::from("gmake")), |
| 10 | + ("openbsd", PathBuf::from("gmake")), |
| 11 | + ("linux", PathBuf::from("make")), |
| 12 | + // for checking the default |
| 13 | + ("_", PathBuf::from("make")), |
| 14 | + ] { |
| 15 | + assert_eq!(make(host), make_path); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +#[cfg(unix)] |
| 20 | +#[test] |
| 21 | +fn test_absolute_unix() { |
| 22 | + use crate::utils::helpers::absolute_unix; |
| 23 | + |
| 24 | + // Test an absolute path |
| 25 | + let path = PathBuf::from("/home/user/file.txt"); |
| 26 | + assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("/home/user/file.txt")); |
| 27 | + |
| 28 | + // Test an absolute path with double leading slashes |
| 29 | + let path = PathBuf::from("//root//file.txt"); |
| 30 | + assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("//root/file.txt")); |
| 31 | + |
| 32 | + // Test a relative path |
| 33 | + let path = PathBuf::from("relative/path"); |
| 34 | + assert_eq!( |
| 35 | + absolute_unix(&path).unwrap(), |
| 36 | + std::env::current_dir().unwrap().join("relative/path") |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +#[test] |
| 41 | +fn test_beta_rev_parsing() { |
| 42 | + // single digit revision |
| 43 | + assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string())); |
| 44 | + // multiple digits |
| 45 | + assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string())); |
| 46 | + // nightly channel (no beta revision) |
| 47 | + assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None); |
| 48 | + // stable channel (no beta revision) |
| 49 | + assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None); |
| 50 | + // invalid string |
| 51 | + assert_eq!(extract_beta_rev("invalid"), None); |
| 52 | +} |
| 53 | + |
| 54 | +#[test] |
| 55 | +fn test_string_to_hex_encode() { |
| 56 | + let input_string = "Hello, World!"; |
| 57 | + let hex_string = hex_encode(input_string); |
| 58 | + assert_eq!(hex_string, "48656c6c6f2c20576f726c6421"); |
| 59 | +} |
0 commit comments