-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8ebb6f
commit c6daaa1
Showing
5 changed files
with
93 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
ci: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Format | ||
run: cargo fmt --check | ||
- name: Check | ||
run: cargo check | ||
- name: Clippy | ||
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used | ||
- name: Test | ||
run: cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
strsim = "0.11" | ||
strsim = "0.11" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::util; | ||
|
||
#[test] | ||
fn test_get_rust_files() { | ||
let files = util::rust_files(".").expect("rust files not found."); | ||
assert_eq!(3, files.len()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::PathBuf; | ||
use std::{fs, io}; | ||
|
||
/// This function gets all the .rs files from a directory, and returns a | ||
/// vector with all the paths of the .rs files. | ||
pub fn rust_files(dir: &str) -> Result<Vec<PathBuf>, io::Error> { | ||
let mut files = Vec::new(); | ||
// Gets all the entries from 'current|argument' dir. | ||
let entries = fs::read_dir(dir)?; | ||
|
||
for e in entries { | ||
let entry = e?; | ||
let path = entry.path(); | ||
|
||
if path.is_dir() { | ||
if let Some(file_name) = path.file_name() { | ||
if let Some(file_name_str) = file_name.to_str() { | ||
if file_name_str.contains("target") || file_name_str.contains("test") { | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
// Take a look at sub dir | ||
let temp = rust_files(&path.to_string_lossy())?; | ||
// .rs found ? Then add to the vector. | ||
files.extend(temp); | ||
} else if let Some(file_name) = path.file_name() { | ||
// Not a dir and .rs | ||
if file_name.to_string_lossy().ends_with(".rs") { | ||
// Then adds to the vector. | ||
files.push(path); | ||
} | ||
} | ||
} | ||
|
||
Ok(files) | ||
} | ||
|
||
// Reads file content. | ||
pub fn content(path: &str) -> Result<String, io::Error> { | ||
let mut f = File::open(path)?; | ||
let mut c = String::new(); | ||
f.read_to_string(&mut c)?; | ||
Ok(c) | ||
} |