Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where last part of the key is discarded and replaced with default filename #17

Merged
merged 4 commits into from
Feb 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub trait Preferences: Sized {
fn compute_file_path<S: AsRef<str>>(app: &AppInfo, key: S) -> Result<PathBuf, PreferencesError> {
let mut path = get_app_dir(DATA_TYPE, app, key.as_ref())?;
let new_name = match path.file_name() {
Some(name) if name.is_empty() => {
Some(name) if !name.is_empty() => {
let mut new_name = OsString::with_capacity(name.len() + PREFS_FILE_EXTENSION.len());
new_name.push(name);
new_name.push(PREFS_FILE_EXTENSION);
Expand Down Expand Up @@ -384,14 +384,19 @@ mod tests {
}
#[test]
fn test_save_load() {
let name = gen_test_name("save-load");
let sample = gen_sample_prefs();
let save_result = sample.save(&APP_INFO, &name);
println!("Save result: {:?}", save_result);
assert!(save_result.is_ok());
let load_result = PreferencesMap::load(&APP_INFO, &name);
println!("Load result: {:?}", load_result);
assert!(load_result.is_ok());
assert_eq!(load_result.unwrap(), sample);
let sample_map = gen_sample_prefs();
let sample_other: i32 = 4;
let name_map = gen_test_name("save-load-map");
let name_other = gen_test_name("save-load-other");
let save_map_result = sample_map.save(&APP_INFO, &name_map);
let save_other_result = sample_other.save(&APP_INFO, &name_other);
assert!(save_map_result.is_ok());
assert!(save_other_result.is_ok());
let load_map_result = PreferencesMap::load(&APP_INFO, &name_map);
let load_other_result = i32::load(&APP_INFO, &name_other);
assert!(load_map_result.is_ok());
assert!(load_other_result.is_ok());
assert_eq!(load_map_result.unwrap(), sample_map);
assert_eq!(load_other_result.unwrap(), sample_other);
}
}