|
1 | 1 | use crate::*;
|
2 | 2 |
|
3 | 3 | #[cfg(test)]
|
4 |
| -mod unit { |
5 |
| - use super::*; |
6 | 4 |
|
7 |
| - #[test] |
8 |
| - fn test_create_patterns_filters_single_line() { |
9 |
| - let arg = "--patterns=*.rs,!test/*.rs"; |
10 |
| - let filters = create_patterns_filters(arg); |
11 |
| - assert_eq!(filters.len(), 2); |
12 |
| - assert_eq!(filters[0].pattern, "*.rs"); |
13 |
| - assert_eq!( |
14 |
| - filters[0].exclude, false, |
15 |
| - "Expected 'exclude' to be false for pattern '*.rs'" |
16 |
| - ); |
17 |
| - assert_eq!(filters[1].pattern, "test/*.rs"); |
18 |
| - assert_eq!(filters[1].exclude, true); |
19 |
| - } |
| 5 | +#[test] |
| 6 | +fn test_create_patterns_filters_single_line() { |
| 7 | + let arg = "--patterns=*.rs,!test/*.rs"; |
| 8 | + let filters = create_patterns_filters(arg); |
| 9 | + assert_eq!(filters.len(), 2); |
| 10 | + assert_eq!(filters[0].pattern, "*.rs"); |
| 11 | + assert_eq!( |
| 12 | + filters[0].exclude, false, |
| 13 | + "Expected 'exclude' to be false for pattern '*.rs'" |
| 14 | + ); |
| 15 | + assert_eq!(filters[1].pattern, "test/*.rs"); |
| 16 | + assert_eq!(filters[1].exclude, true); |
| 17 | +} |
20 | 18 |
|
21 |
| - #[test] |
22 |
| - fn test_create_patterns_filters_multiple_lines() { |
23 |
| - let arg = "--patterns=*.rs |
24 |
| - !test/*.rs |
25 |
| - .gitignore |
26 |
| - "; |
27 |
| - let filters = create_patterns_filters(arg); |
| 19 | +#[test] |
| 20 | +fn test_create_patterns_filters_multiple_lines() { |
| 21 | + let arg = "--patterns=*.rs |
| 22 | + !test/*.rs |
| 23 | + .gitignore |
| 24 | + "; |
| 25 | + let filters = create_patterns_filters(arg); |
28 | 26 |
|
29 |
| - assert_eq!(filters.len(), 3); |
30 |
| - assert_eq!(filters[0].pattern, "*.rs"); |
31 |
| - assert_eq!(filters[0].exclude, false); |
32 |
| - assert_eq!(filters[1].pattern, "test/*.rs"); |
33 |
| - assert_eq!(filters[1].exclude, true); |
34 |
| - assert_eq!(filters[2].pattern, ".gitignore"); |
35 |
| - assert_eq!(filters[2].exclude, false); |
36 |
| - } |
| 27 | + assert_eq!(filters.len(), 3); |
| 28 | + assert_eq!(filters[0].pattern, "*.rs"); |
| 29 | + assert_eq!(filters[0].exclude, false); |
| 30 | + assert_eq!(filters[1].pattern, "test/*.rs"); |
| 31 | + assert_eq!(filters[1].exclude, true); |
| 32 | + assert_eq!(filters[2].pattern, ".gitignore"); |
| 33 | + assert_eq!(filters[2].exclude, false); |
| 34 | +} |
37 | 35 |
|
38 |
| - #[test] |
39 |
| - fn test_categorize_filters() { |
40 |
| - let filters = vec![ |
41 |
| - PatternFilter { |
42 |
| - pattern: String::from("*.rs"), |
43 |
| - exclude: false, |
44 |
| - }, |
45 |
| - PatternFilter { |
46 |
| - pattern: String::from("test/*.rs"), |
47 |
| - exclude: true, |
48 |
| - }, |
49 |
| - ]; |
50 |
| - let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); |
51 |
| - assert_eq!(include_patterns_filters.len(), 1); |
52 |
| - assert_eq!(exclude_patterns_filters.len(), 1); |
53 |
| - assert_eq!(include_patterns_filters.contains("*.rs"), true); |
54 |
| - assert_eq!(exclude_patterns_filters.contains("test/*.rs"), true); |
55 |
| - } |
| 36 | +#[test] |
| 37 | +fn test_categorize_filters() { |
| 38 | + let filters = vec![ |
| 39 | + PatternFilter { |
| 40 | + pattern: String::from("*.rs"), |
| 41 | + exclude: false, |
| 42 | + }, |
| 43 | + PatternFilter { |
| 44 | + pattern: String::from("test/*.rs"), |
| 45 | + exclude: true, |
| 46 | + }, |
| 47 | + ]; |
| 48 | + let (include_patterns_filters, exclude_patterns_filters) = categorize_filters(filters); |
| 49 | + assert_eq!(include_patterns_filters.len(), 1); |
| 50 | + assert_eq!(exclude_patterns_filters.len(), 1); |
| 51 | + assert_eq!(include_patterns_filters.contains("*.rs"), true); |
| 52 | + assert_eq!(exclude_patterns_filters.contains("test/*.rs"), true); |
| 53 | +} |
56 | 54 |
|
57 |
| - #[test] |
58 |
| - fn test_filter() { |
59 |
| - let files = vec![ |
60 |
| - String::from("src/main.rs"), |
61 |
| - String::from("lib.rs"), |
62 |
| - String::from("test.txt"), |
63 |
| - ]; |
64 |
| - let include_patterns_filters = HashSet::from([ |
65 |
| - String::from("*.rs"), |
66 |
| - String::from("src/**"), |
67 |
| - String::from("*.txt"), |
68 |
| - ]); |
69 |
| - let exclude_patterns_filters = HashSet::from([ |
70 |
| - String::from("test.txt") |
71 |
| - ]); |
72 |
| - let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); |
73 |
| - let expected_filtered_files = HashSet::from([ |
74 |
| - String::from("src/main.rs"), |
75 |
| - String::from("lib.rs"), |
76 |
| - ]); |
| 55 | +#[test] |
| 56 | +fn test_filter() { |
| 57 | + let files = vec![ |
| 58 | + String::from("src/main.rs"), |
| 59 | + String::from("lib.rs"), |
| 60 | + String::from("test.txt"), |
| 61 | + ]; |
| 62 | + let include_patterns_filters = HashSet::from([ |
| 63 | + String::from("*.rs"), |
| 64 | + String::from("src/**"), |
| 65 | + String::from("*.txt"), |
| 66 | + ]); |
| 67 | + let exclude_patterns_filters = HashSet::from([ |
| 68 | + String::from("test.txt") |
| 69 | + ]); |
| 70 | + let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); |
| 71 | + let expected_filtered_files = HashSet::from([ |
| 72 | + String::from("src/main.rs"), |
| 73 | + String::from("lib.rs"), |
| 74 | + ]); |
77 | 75 |
|
78 |
| - assert_eq!(filtered_files, expected_filtered_files); |
79 |
| - } |
| 76 | + assert_eq!(filtered_files, expected_filtered_files); |
| 77 | +} |
80 | 78 |
|
81 |
| - #[test] |
82 |
| - fn test_filter_exclude_files_exclusion() { |
83 |
| - let exclude_patterns_filters = HashSet::from([ |
84 |
| - String::from("test.txt"), |
85 |
| - ]); |
86 |
| - let include_patterns_filters = HashSet::from([ |
87 |
| - String::from("*.rs"), |
88 |
| - String::from("*.txt"), |
89 |
| - ]); |
| 79 | +#[test] |
| 80 | +fn test_filter_exclude_files_exclusion() { |
| 81 | + let exclude_patterns_filters = HashSet::from([ |
| 82 | + String::from("test.txt"), |
| 83 | + ]); |
| 84 | + let include_patterns_filters = HashSet::from([ |
| 85 | + String::from("*.rs"), |
| 86 | + String::from("*.txt"), |
| 87 | + ]); |
90 | 88 |
|
91 |
| - let files = vec![ |
92 |
| - String::from("main.rs"), |
93 |
| - String::from("lib.rs"), |
94 |
| - String::from("version.txt"), |
95 |
| - String::from("test.txt"), |
96 |
| - ]; |
| 89 | + let files = vec![ |
| 90 | + String::from("main.rs"), |
| 91 | + String::from("lib.rs"), |
| 92 | + String::from("version.txt"), |
| 93 | + String::from("test.txt"), |
| 94 | + ]; |
97 | 95 |
|
98 |
| - let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); |
99 |
| - let expected_filtered_files = HashSet::from([ |
100 |
| - String::from("main.rs"), |
101 |
| - String::from("lib.rs"), |
102 |
| - String::from("version.txt"), |
103 |
| - ]); |
| 96 | + let filtered_files = filter_files(files, include_patterns_filters, exclude_patterns_filters); |
| 97 | + let expected_filtered_files = HashSet::from([ |
| 98 | + String::from("main.rs"), |
| 99 | + String::from("lib.rs"), |
| 100 | + String::from("version.txt"), |
| 101 | + ]); |
104 | 102 |
|
105 |
| - assert_eq!(filtered_files, expected_filtered_files); |
106 |
| - } |
| 103 | + assert_eq!(filtered_files, expected_filtered_files); |
| 104 | +} |
107 | 105 |
|
108 |
| - #[test] |
109 |
| - fn test_get_count() { |
110 |
| - let files = HashSet::from([ |
111 |
| - String::from("main.rs"), |
112 |
| - String::from("lib.rs"), |
113 |
| - String::from("version.txt"), |
114 |
| - ]); |
115 |
| - let count = get_count(files); |
116 |
| - assert_eq!(count, 3); |
117 |
| - } |
| 106 | +#[test] |
| 107 | +fn test_get_count() { |
| 108 | + let files = HashSet::from([ |
| 109 | + String::from("main.rs"), |
| 110 | + String::from("lib.rs"), |
| 111 | + String::from("version.txt"), |
| 112 | + ]); |
| 113 | + let count = get_count(files); |
| 114 | + assert_eq!(count, 3); |
118 | 115 | }
|
0 commit comments