summaryrefslogtreecommitdiffstats
path: root/rust-cli/grrs/tests
diff options
context:
space:
mode:
Diffstat (limited to 'rust-cli/grrs/tests')
-rw-r--r--rust-cli/grrs/tests/finds_correct_matches.rs4
-rw-r--r--rust-cli/grrs/tests/finds_matches.rs12
-rw-r--r--rust-cli/grrs/tests/test_utils.rs20
3 files changed, 36 insertions, 0 deletions
diff --git a/rust-cli/grrs/tests/finds_correct_matches.rs b/rust-cli/grrs/tests/finds_correct_matches.rs
new file mode 100644
index 0000000..db5228a
--- /dev/null
+++ b/rust-cli/grrs/tests/finds_correct_matches.rs
@@ -0,0 +1,4 @@
+#[test]
+fn finds_correct_matches() {
+
+} \ No newline at end of file
diff --git a/rust-cli/grrs/tests/finds_matches.rs b/rust-cli/grrs/tests/finds_matches.rs
new file mode 100644
index 0000000..5f301fc
--- /dev/null
+++ b/rust-cli/grrs/tests/finds_matches.rs
@@ -0,0 +1,12 @@
+use std::fs::File;
+
+#[test]
+fn finds_matches() {
+ let mut test_file = File::create("finds_matches.txt").unwrap();
+ std::io::Write::write_all(&mut test_file, b"asdf\ntesting").unwrap();
+ std::io::Write::flush(&mut test_file).unwrap();
+ let file_to_test = File::open("finds_matches.txt").expect("could not read test file");
+ let matches = grrs::find_matches(&file_to_test, "asdf").unwrap();
+ assert_eq!(matches.len(), 1);
+ std::fs::remove_file("finds_matches.txt").unwrap();
+} \ No newline at end of file
diff --git a/rust-cli/grrs/tests/test_utils.rs b/rust-cli/grrs/tests/test_utils.rs
new file mode 100644
index 0000000..d408e87
--- /dev/null
+++ b/rust-cli/grrs/tests/test_utils.rs
@@ -0,0 +1,20 @@
+use std::{fs::{File}, path::Path};
+
+pub fn get_test_file_with_contents(name: &str, contents:&str) -> &File {
+ let path = get_unused_filename();
+ return File::open(path);
+}
+
+fn get_unused_filename() -> String {
+ let files = std::fs::read_dir(Path::new(".")).unwrap();
+ let file_suffix = "-testing.txt";
+ let mut file_no = 1;
+ for file in files {
+ let dir = file.unwrap();
+ }
+
+ return file_no
+ .to_string()
+ .to_owned()
+ .push_str(&file_suffix);
+} \ No newline at end of file