Skip to content

Commit

Permalink
feat: give Workspaces the files() function
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Mar 1, 2023
1 parent 46b67d7 commit 352039b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -5,3 +5,4 @@
// Ways to query all the files in a given workspace

pub mod workspace;
pub mod workspace_traverse;
38 changes: 38 additions & 0 deletions src/workspace_traverse.rs
@@ -0,0 +1,38 @@
use crate::workspace::Workspace;
use std::path::PathBuf;

impl Workspace {
pub fn files(&self) -> Vec<PathBuf> {
walkdir::WalkDir::new(&self.path)
.into_iter()
.filter(|e| {
e.is_ok()
&& !e
.as_ref()
.unwrap()
.file_name()
.to_str()
.unwrap_or(".")
.starts_with('.')
})
.map(|file| file.unwrap().into_path())
.collect()
}
}

mod tests {
#[allow(unused_imports)]
use super::*;

#[test]
// TODO: Tests be failing 😭
fn test_files() {
let workspace = Workspace {
name: "example workspace".to_string(),
path: PathBuf::from("test/example_workspace"),
};

let files = workspace.files();
assert_eq!(files.len(), 2);
}
}
1 change: 1 addition & 0 deletions test/example_workspace/.hidden-file.norg
@@ -0,0 +1 @@
* This is hidden hehe
1 change: 1 addition & 0 deletions test/example_workspace/file1.norg
@@ -0,0 +1 @@
* Hello World!
1 change: 1 addition & 0 deletions test/example_workspace/file2.norg
@@ -0,0 +1 @@
* Biology Notes

0 comments on commit 352039b

Please sign in to comment.