Cargo format
This commit is contained in:
parent
9bab810b91
commit
8c0224e983
44 changed files with 1784 additions and 611 deletions
|
|
@ -1,12 +1,12 @@
|
|||
extern crate schematics;
|
||||
extern crate tempdir;
|
||||
|
||||
use schematics::symbols::file::File as FileSymbol;
|
||||
use schematics::symbols::Symbol;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use tempdir::TempDir;
|
||||
use schematics::symbols::Symbol;
|
||||
use schematics::symbols::file::File as FileSymbol;
|
||||
|
||||
fn get_dir(content: Option<&str>) -> TempDir {
|
||||
let tmp_dir = TempDir::new("unittest").expect("create temp dir");
|
||||
|
|
@ -15,12 +15,17 @@ fn get_dir(content: Option<&str>) -> TempDir {
|
|||
}
|
||||
let file_path = tmp_dir.path().join("filename");
|
||||
let mut tmp_file = File::create(file_path).expect("create temp file");
|
||||
tmp_file.write_all(content.unwrap().as_bytes()).expect("write temp file");
|
||||
tmp_file
|
||||
.write_all(content.unwrap().as_bytes())
|
||||
.expect("write temp file");
|
||||
tmp_dir
|
||||
}
|
||||
|
||||
fn get_symbol(path: &Path) -> FileSymbol<&str, String> {
|
||||
FileSymbol::new(String::from(path.join("filename").to_str().unwrap()), "target content")
|
||||
FileSymbol::new(
|
||||
String::from(path.join("filename").to_str().unwrap()),
|
||||
"target content",
|
||||
)
|
||||
}
|
||||
|
||||
// Normal cases
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ extern crate schematics;
|
|||
extern crate tempdir;
|
||||
|
||||
use regex::Regex;
|
||||
use schematics::storage::{SimpleStorage, Storage};
|
||||
use std::fs::{create_dir, File};
|
||||
use std::path::Path;
|
||||
use tempdir::TempDir;
|
||||
use schematics::storage::{SimpleStorage, Storage};
|
||||
|
||||
fn get_dir<'a, I: IntoIterator<Item=&'a &'a str>>(content: I) -> TempDir {
|
||||
fn get_dir<'a, I: IntoIterator<Item = &'a &'a str>>(content: I) -> TempDir {
|
||||
let tmp_dir = TempDir::new("unittest").expect("create temp dir");
|
||||
let storage_path = tmp_dir.path().join("_filename");
|
||||
create_dir(storage_path.clone()).unwrap();
|
||||
|
|
@ -30,8 +30,15 @@ fn single_file() {
|
|||
let dir = get_dir(&["12345"]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert_eq!(dir.path().join("_filename").join("12345"), Path::new(&storage.read_filename().unwrap()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert_eq!(
|
||||
dir.path().join("_filename").join("12345"),
|
||||
Path::new(&storage.read_filename().unwrap())
|
||||
);
|
||||
assert_eq!(storage.recent_date().unwrap(), 12345);
|
||||
}
|
||||
|
||||
|
|
@ -40,8 +47,15 @@ fn two_files() {
|
|||
let dir = get_dir(&["12345", "23456"]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert_eq!(dir.path().join("_filename").join("23456"), Path::new(&storage.read_filename().unwrap()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert_eq!(
|
||||
dir.path().join("_filename").join("23456"),
|
||||
Path::new(&storage.read_filename().unwrap())
|
||||
);
|
||||
assert_eq!(storage.recent_date().unwrap(), 23456);
|
||||
}
|
||||
|
||||
|
|
@ -50,8 +64,15 @@ fn another_two_files() {
|
|||
let dir = get_dir(&["23456", "12345"]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert_eq!(dir.path().join("_filename").join("23456"), Path::new(&storage.read_filename().unwrap()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert_eq!(
|
||||
dir.path().join("_filename").join("23456"),
|
||||
Path::new(&storage.read_filename().unwrap())
|
||||
);
|
||||
assert_eq!(storage.recent_date().unwrap(), 23456);
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +81,15 @@ fn three_files() {
|
|||
let dir = get_dir(&["23456", "9", "12345"]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert_eq!(dir.path().join("_filename").join("23456"), Path::new(&storage.read_filename().unwrap()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert_eq!(
|
||||
dir.path().join("_filename").join("23456"),
|
||||
Path::new(&storage.read_filename().unwrap())
|
||||
);
|
||||
assert_eq!(storage.recent_date().unwrap(), 23456);
|
||||
}
|
||||
|
||||
|
|
@ -72,11 +100,21 @@ fn empty_storage() {
|
|||
let dir = TempDir::new("unittest").expect("create temp dir");
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert!(storage.read_filename().is_err());
|
||||
assert_eq!(storage.read_filename().unwrap_err().description(), "entity not found");
|
||||
assert_eq!(
|
||||
storage.read_filename().unwrap_err().description(),
|
||||
"entity not found"
|
||||
);
|
||||
assert!(storage.recent_date().is_err());
|
||||
assert_eq!(storage.recent_date().unwrap_err().description(), "entity not found");
|
||||
assert_eq!(
|
||||
storage.recent_date().unwrap_err().description(),
|
||||
"entity not found"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -84,11 +122,21 @@ fn empty_storage_for_filename() {
|
|||
let dir = get_dir(&[]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert!(storage.read_filename().is_err());
|
||||
assert_eq!(storage.read_filename().unwrap_err().description(), "Not found");
|
||||
assert_eq!(
|
||||
storage.read_filename().unwrap_err().description(),
|
||||
"Not found"
|
||||
);
|
||||
assert!(storage.recent_date().is_err());
|
||||
assert_eq!(storage.recent_date().unwrap_err().description(), "Not found");
|
||||
assert_eq!(
|
||||
storage.recent_date().unwrap_err().description(),
|
||||
"Not found"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -96,9 +144,19 @@ fn bad_file() {
|
|||
let dir = get_dir(&["abba"]);
|
||||
let storage = get_storage(dir.path());
|
||||
|
||||
assert!(Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display())).unwrap().is_match(&storage.write_filename()));
|
||||
assert!(
|
||||
Regex::new(&format!("^{}/_filename/\\d+$", dir.path().display()))
|
||||
.unwrap()
|
||||
.is_match(&storage.write_filename())
|
||||
);
|
||||
assert!(storage.read_filename().is_err());
|
||||
assert_eq!(storage.read_filename().unwrap_err().description(), "Not found");
|
||||
assert_eq!(
|
||||
storage.read_filename().unwrap_err().description(),
|
||||
"Not found"
|
||||
);
|
||||
assert!(storage.recent_date().is_err());
|
||||
assert_eq!(storage.recent_date().unwrap_err().description(), "Not found");
|
||||
assert_eq!(
|
||||
storage.recent_date().unwrap_err().description(),
|
||||
"Not found"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue