-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
119 additions
and
125 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 |
---|---|---|
|
@@ -36,4 +36,4 @@ jobs: | |
${{ runner.os }}-cargo-build- | ||
- name: Run Tests | ||
run: cargo test | ||
run: cargo test --color always |
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
use crate::*; | ||
|
||
#[cfg(test)] | ||
mod integration { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_filter() { | ||
let arg = "--patterns=*.rs,!*..txt"; | ||
let files = vec![ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
String::from("test.txt"), | ||
]; | ||
#[test] | ||
fn test_filter() { | ||
let arg = "--patterns=*.rs,!*..txt"; | ||
let files = vec![ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
String::from("test.txt"), | ||
]; | ||
|
||
let filters = create_patterns_filters(arg); | ||
let filters = create_patterns_filters(arg); | ||
|
||
let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); | ||
let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); | ||
|
||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
|
||
let count = get_count(filtered_files.clone()); | ||
let count = get_count(filtered_files.clone()); | ||
|
||
let expected_filtered_files = HashSet::from([ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
]); | ||
let expected_filtered_files = HashSet::from([ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
]); | ||
|
||
assert_eq!(filtered_files, expected_filtered_files); | ||
assert_eq!(count, 2); | ||
} | ||
assert_eq!(filtered_files, expected_filtered_files); | ||
assert_eq!(count, 2); | ||
} |
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 |
---|---|---|
@@ -1,118 +1,115 @@ | ||
use crate::*; | ||
|
||
#[cfg(test)] | ||
mod unit { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_create_patterns_filters_single_line() { | ||
let arg = "--patterns=*.rs,!test/*.rs"; | ||
let filters = create_patterns_filters(arg); | ||
assert_eq!(filters.len(), 2); | ||
assert_eq!(filters[0].pattern, "*.rs"); | ||
assert_eq!( | ||
filters[0].exclude, false, | ||
"Expected 'exclude' to be false for pattern '*.rs'" | ||
); | ||
assert_eq!(filters[1].pattern, "test/*.rs"); | ||
assert_eq!(filters[1].exclude, true); | ||
} | ||
#[test] | ||
fn test_create_patterns_filters_single_line() { | ||
let arg = "--patterns=*.rs,!test/*.rs"; | ||
let filters = create_patterns_filters(arg); | ||
assert_eq!(filters.len(), 2); | ||
assert_eq!(filters[0].pattern, "*.rs"); | ||
assert_eq!( | ||
filters[0].exclude, false, | ||
"Expected 'exclude' to be false for pattern '*.rs'" | ||
); | ||
assert_eq!(filters[1].pattern, "test/*.rs"); | ||
assert_eq!(filters[1].exclude, true); | ||
} | ||
|
||
#[test] | ||
fn test_create_patterns_filters_multiple_lines() { | ||
let arg = "--patterns=*.rs | ||
!test/*.rs | ||
.gitignore | ||
"; | ||
let filters = create_patterns_filters(arg); | ||
#[test] | ||
fn test_create_patterns_filters_multiple_lines() { | ||
let arg = "--patterns=*.rs | ||
!test/*.rs | ||
.gitignore | ||
"; | ||
let filters = create_patterns_filters(arg); | ||
|
||
assert_eq!(filters.len(), 3); | ||
assert_eq!(filters[0].pattern, "*.rs"); | ||
assert_eq!(filters[0].exclude, false); | ||
assert_eq!(filters[1].pattern, "test/*.rs"); | ||
assert_eq!(filters[1].exclude, true); | ||
assert_eq!(filters[2].pattern, ".gitignore"); | ||
assert_eq!(filters[2].exclude, false); | ||
} | ||
assert_eq!(filters.len(), 3); | ||
assert_eq!(filters[0].pattern, "*.rs"); | ||
assert_eq!(filters[0].exclude, false); | ||
assert_eq!(filters[1].pattern, "test/*.rs"); | ||
assert_eq!(filters[1].exclude, true); | ||
assert_eq!(filters[2].pattern, ".gitignore"); | ||
assert_eq!(filters[2].exclude, false); | ||
} | ||
|
||
#[test] | ||
fn test_categorize_filters() { | ||
let filters = vec![ | ||
PatternFilter { | ||
pattern: String::from("*.rs"), | ||
exclude: false, | ||
}, | ||
PatternFilter { | ||
pattern: String::from("test/*.rs"), | ||
exclude: true, | ||
}, | ||
]; | ||
let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); | ||
assert_eq!(include_patterns_filters.len(), 1); | ||
assert_eq!(exclude_patterns_filters.len(), 1); | ||
assert_eq!(include_patterns_filters.contains("*.rs"), true); | ||
assert_eq!(exclude_patterns_filters.contains("test/*.rs"), true); | ||
} | ||
#[test] | ||
fn test_categorize_filters() { | ||
let filters = vec![ | ||
PatternFilter { | ||
pattern: String::from("*.rs"), | ||
exclude: false, | ||
}, | ||
PatternFilter { | ||
pattern: String::from("test/*.rs"), | ||
exclude: true, | ||
}, | ||
]; | ||
let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); | ||
assert_eq!(include_patterns_filters.len(), 1); | ||
assert_eq!(exclude_patterns_filters.len(), 1); | ||
assert_eq!(include_patterns_filters.contains("*.rs"), true); | ||
assert_eq!(exclude_patterns_filters.contains("test/*.rs"), true); | ||
} | ||
|
||
#[test] | ||
fn test_filter() { | ||
let files = vec![ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
String::from("test.txt"), | ||
]; | ||
let include_patterns_filters = HashSet::from([ | ||
String::from("*.rs"), | ||
String::from("src/**"), | ||
String::from("*.txt"), | ||
]); | ||
let exclude_patterns_filters = HashSet::from([ | ||
String::from("test.txt") | ||
]); | ||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
let expected_filtered_files = HashSet::from([ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
]); | ||
#[test] | ||
fn test_filter() { | ||
let files = vec![ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
String::from("test.txt"), | ||
]; | ||
let include_patterns_filters = HashSet::from([ | ||
String::from("*.rs"), | ||
String::from("src/**"), | ||
String::from("*.txt"), | ||
]); | ||
let exclude_patterns_filters = HashSet::from([ | ||
String::from("test.txt") | ||
]); | ||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
let expected_filtered_files = HashSet::from([ | ||
String::from("src/main.rs"), | ||
String::from("lib.rs"), | ||
]); | ||
|
||
assert_eq!(filtered_files, expected_filtered_files); | ||
} | ||
assert_eq!(filtered_files, expected_filtered_files); | ||
} | ||
|
||
#[test] | ||
fn test_filter_exclude_files_exclusion() { | ||
let exclude_patterns_filters = HashSet::from([ | ||
String::from("test.txt"), | ||
]); | ||
let include_patterns_filters = HashSet::from([ | ||
String::from("*.rs"), | ||
String::from("*.txt"), | ||
]); | ||
#[test] | ||
fn test_filter_exclude_files_exclusion() { | ||
let exclude_patterns_filters = HashSet::from([ | ||
String::from("test.txt"), | ||
]); | ||
let include_patterns_filters = HashSet::from([ | ||
String::from("*.rs"), | ||
String::from("*.txt"), | ||
]); | ||
|
||
let files = vec![ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
String::from("test.txt"), | ||
]; | ||
let files = vec![ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
String::from("test.txt"), | ||
]; | ||
|
||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
let expected_filtered_files = HashSet::from([ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
]); | ||
let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); | ||
let expected_filtered_files = HashSet::from([ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
]); | ||
|
||
assert_eq!(filtered_files, expected_filtered_files); | ||
} | ||
assert_eq!(filtered_files, expected_filtered_files); | ||
} | ||
|
||
#[test] | ||
fn test_get_count() { | ||
let files = HashSet::from([ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
]); | ||
let count = get_count(files); | ||
assert_eq!(count, 3); | ||
} | ||
#[test] | ||
fn test_get_count() { | ||
let files = HashSet::from([ | ||
String::from("main.rs"), | ||
String::from("lib.rs"), | ||
String::from("version.txt"), | ||
]); | ||
let count = get_count(files); | ||
assert_eq!(count, 3); | ||
} |