summaryrefslogtreecommitdiffstats
path: root/src/utils/fileutil.rs
diff options
context:
space:
mode:
authorVincent Breitmoser <look@my.amazin.horse>2019-01-20 12:48:24 +0100
committerVincent Breitmoser <look@my.amazin.horse>2019-01-20 12:48:24 +0100
commit7e84f2e6db1028f60193ecd40ee935fe629902cb (patch)
tree689f9bc55b2b62f9de2676e437fcf9ec79be6570 /src/utils/fileutil.rs
parentabac372c76be0c7be757de2f2f535d2c61d0d539 (diff)
introcue stdin buffer for tests
Diffstat (limited to 'src/utils/fileutil.rs')
-rw-r--r--src/utils/fileutil.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs
index c60ac51..fca810e 100644
--- a/src/utils/fileutil.rs
+++ b/src/utils/fileutil.rs
@@ -53,12 +53,6 @@ pub fn read_lines_from_file(filepath: &Path) -> io::Result<impl Iterator<Item =
lines.map(|result| result.into_iter())
}
-pub fn read_single_char_from_stdin() -> io::Result<char> {
- let stdin = std::io::stdin();
- let stdinlock = stdin.lock();
- read_single_char(stdinlock)
-}
-
pub fn read_single_char(mut source: impl BufRead) -> io::Result<char> {
let mut buf = String::new();
source.read_line(&mut buf)?;
@@ -66,13 +60,26 @@ pub fn read_single_char(mut source: impl BufRead) -> io::Result<char> {
buf.chars().next().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "calendar has no path"))
}
+pub fn read_single_char_from_stdin() -> io::Result<char> {
+ let stdin = std::io::stdin();
+ let stdinlock = stdin.lock();
+ read_single_char(stdinlock)
+}
+
+#[cfg(not(test))]
pub fn read_lines_from_stdin() -> io::Result<Vec<String>> {
let stdin = io::stdin();
let lines = stdin.lock().lines();
-
lines.collect()
}
+#[cfg(test)]
+pub fn read_lines_from_stdin() -> io::Result<Vec<String>> {
+ use testutils;
+ let lines = testutils::test_stdin_clear();
+ Ok(lines)
+}
+
pub fn read_file_to_string(path: &Path) -> io::Result<String> {
let mut file = fs::File::open(&path)?;
let mut contents = String::new();