feat(fs): add lines to reader
This commit is contained in:
parent
17221a06d8
commit
c45a2c2273
2 changed files with 21 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
path::Path,
|
path::Path, str::Lines,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::fs::Result;
|
use crate::fs::Result;
|
||||||
|
@ -19,6 +19,10 @@ impl ReaderReal {
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.contents
|
&self.contents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lines(&self) -> Lines<'_> {
|
||||||
|
self.contents.lines()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl Display for ReaderReal {
|
impl Display for ReaderReal {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
|
16
tests/fs.rs
16
tests/fs.rs
|
@ -114,6 +114,22 @@ mod file {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_file_lines() -> TestResult {
|
||||||
|
let fs = fs::temp().expect("temp fs");
|
||||||
|
|
||||||
|
let path = fs.base().join("foo");
|
||||||
|
let mut file = fs.file(&path);
|
||||||
|
file.write("line 1\nline 2").expect("write");
|
||||||
|
|
||||||
|
let reader = file.reader().expect("reader");
|
||||||
|
let lines = reader.lines().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
assert_eq!(lines, vec!["line 1", "line 2"]);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod dir_create {
|
mod dir_create {
|
||||||
|
|
Loading…
Reference in a new issue