Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Dec 12, 2023
1 parent 06a47cb commit 970d0f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,12 @@ pub fn bind<T: Timer>(linker: &mut Linker<Context<T>>) -> Result<(), CreationErr
let (memory, context) = memory_and_context(&mut caller);
let key = get_str(memory, key_ptr, key_len)?.into();
let description = get_str(memory, description_ptr, description_len)?.into();
let filter =
get_str(memory, filter_ptr, filter_len)?.into();
let filter = get_str(memory, filter_ptr, filter_len)?.into();
Arc::make_mut(&mut context.settings_widgets).push(settings::Widget {
key,
description,
tooltip: None,
kind: settings::WidgetKind::FileSelection {
filter,
},
kind: settings::WidgetKind::FileSelection { filter },
});
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/livesplit-auto-splitting/src/settings/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum WidgetKind {
/// A filter on which files are selectable,
/// for example `"*.txt"` for text files.
filter: Arc<str>,
}
},
}

/// An option for a choice setting.
Expand Down
31 changes: 23 additions & 8 deletions crates/livesplit-auto-splitting/src/wasi_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,61 @@ pub fn wasi_to_path(wasi_path_str: &str) -> Option<PathBuf> {
(2, Component::Normal(d)) if d.len() == 1 && d.to_ascii_lowercase() == d => {
let disk = d.to_string_lossy().to_ascii_uppercase();
path.push(format!("{}{}{}", r"\\?\", disk, r":\"));
},
}
(2, Component::Normal(c)) if !path.has_root() => {
if let Some(root) = [r"/", r"\"].into_iter().map(PathBuf::from).find(|p| p.has_root()) {
if let Some(root) = [r"/", r"\"]
.into_iter()
.map(PathBuf::from)
.find(|p| p.has_root())
{
path.push(root);
}
path.push(c);
},
}
(i, Component::Normal(c)) if 2 <= i => path.push(c),
_ => return None,
}
}
Some(path)
}


#[cfg(test)]
mod tests {
use super::*;

#[cfg(windows)]
#[test]
fn test_windows_to_wasi() {
assert_eq!(path_to_wasi(Path::new(r"C:\foo\bar.exe")), Some(r"/mnt/c/foo/bar.exe".into()));
assert_eq!(
path_to_wasi(Path::new(r"C:\foo\bar.exe")),
Some(r"/mnt/c/foo/bar.exe".into())
);
}

#[cfg(windows)]
#[test]
fn test_wasi_to_windows() {
assert_eq!(wasi_to_path(r"/mnt/c/foo/bar.exe"), Some(r"C:\foo\bar.exe".into()));
assert_eq!(
wasi_to_path(r"/mnt/c/foo/bar.exe"),
Some(r"C:\foo\bar.exe".into())
);
}

#[cfg(not(windows))]
#[test]
fn test_non_windows_to_wasi() {
assert_eq!(path_to_wasi(Path::new(r"/foo/bar.exe")), Some(r"/mnt/foo/bar.exe".into()));
assert_eq!(
path_to_wasi(Path::new(r"/foo/bar.exe")),
Some(r"/mnt/foo/bar.exe".into())
);
}

#[cfg(not(windows))]
#[test]
fn test_wasi_to_non_windows() {
assert_eq!(wasi_to_path(r"/mnt/foo/bar.exe"), Some(r"/foo/bar.exe".into()));
assert_eq!(
wasi_to_path(r"/mnt/foo/bar.exe"),
Some(r"/foo/bar.exe".into())
);
}
}

0 comments on commit 970d0f7

Please sign in to comment.