Commit a5eda99e authored by stratact's avatar stratact

Fix tests, take 3

parent 41bdf779
Pipeline #1567 passed with stage
in 1 minute and 34 seconds
......@@ -31,7 +31,7 @@ fn main() {
}
};
con.history.set_file_name_and_load_history(history_file);
con.history.set_file_name_and_load_history(history_file).unwrap();
loop {
// Reads the line, the first arg is the prompt, the second arg is a function called on every bit of text leaving liner, and the third is called on every key press
......
......@@ -30,7 +30,7 @@ fn main() {
}
};
con.history.set_file_name_and_load_history(history_file);
con.history.set_file_name_and_load_history(history_file).unwrap();
loop {
let res = con.read_line("[prompt]$ ",
......
......@@ -44,13 +44,15 @@ impl History {
}
/// Set history file name and at the same time load the history.
pub fn set_file_name_and_load_history<N: AsRef<Path>>(&mut self, name: N) {
let file = match File::open(name.as_ref()) {
Ok(file) => file,
Err(why) => {
eprintln!("{}", why);
return;
}
pub fn set_file_name_and_load_history<P: AsRef<Path>>(&mut self, path: P) -> io::Result<String> {
let status;
let path = path.as_ref();
let file = if path.exists() {
status = format!("opening {:?}", path);
File::open(path)?
} else {
status = format!("creating {:?}", path);
File::create(path)?
};
let reader = BufReader::new(file);
for line in reader.lines() {
......@@ -59,7 +61,8 @@ impl History {
Err(_) => break,
}
}
self.file_name = name.as_ref().to_str().map(|s| s.to_owned());
self.file_name = path.to_str().map(|s| s.to_owned());
Ok(status)
}
/// Set maximal number of buffers stored in memory
......
......@@ -90,10 +90,10 @@ fn test_in_file_history_truncating() {
{
let mut h = History::new();
h.set_file_name_and_load_history(&tmp_file);
let _ = h.set_file_name_and_load_history(&tmp_file).unwrap();
h.set_max_file_size(5);
for _ in 0..20 {
h.push(Buffer::from("a")).unwrap();
for bytes in b'a'..b'z' {
h.push(Buffer::from(format!("{}", bytes as char))).unwrap();
}
h.commit_to_file();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment