@@ -5,52 +5,6 @@ use std::path::Path;
55
66use crate :: fs as rfs;
77
8- /// Gathers all files in the current working directory that have the extension `ext`, and counts
9- /// the number of lines within that contain a match with the regex pattern `re`.
10- pub fn count_regex_matches_in_files_with_extension ( re : & regex:: Regex , ext : & str ) -> usize {
11- let fetched_files = shallow_find_files ( cwd ( ) , |path| has_extension ( path, ext) ) ;
12-
13- let mut count = 0 ;
14- for file in fetched_files {
15- let content = rfs:: read_to_string ( file) ;
16- count += content. lines ( ) . filter ( |line| re. is_match ( & line) ) . count ( ) ;
17- }
18-
19- count
20- }
21-
22- /// Read the contents of a file that cannot simply be read by
23- /// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
24- /// that it contains `expected`.
25- #[ track_caller]
26- pub fn invalid_utf8_contains < P : AsRef < Path > , S : AsRef < str > > ( path : P , expected : S ) {
27- let buffer = rfs:: read ( path. as_ref ( ) ) ;
28- let expected = expected. as_ref ( ) ;
29- if !String :: from_utf8_lossy ( & buffer) . contains ( expected) {
30- eprintln ! ( "=== FILE CONTENTS (LOSSY) ===" ) ;
31- eprintln ! ( "{}" , String :: from_utf8_lossy( & buffer) ) ;
32- eprintln ! ( "=== SPECIFIED TEXT ===" ) ;
33- eprintln ! ( "{}" , expected) ;
34- panic ! ( "specified text was not found in file" ) ;
35- }
36- }
37-
38- /// Read the contents of a file that cannot simply be read by
39- /// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
40- /// that it does not contain `expected`.
41- #[ track_caller]
42- pub fn invalid_utf8_not_contains < P : AsRef < Path > , S : AsRef < str > > ( path : P , expected : S ) {
43- let buffer = rfs:: read ( path. as_ref ( ) ) ;
44- let expected = expected. as_ref ( ) ;
45- if String :: from_utf8_lossy ( & buffer) . contains ( expected) {
46- eprintln ! ( "=== FILE CONTENTS (LOSSY) ===" ) ;
47- eprintln ! ( "{}" , String :: from_utf8_lossy( & buffer) ) ;
48- eprintln ! ( "=== SPECIFIED TEXT ===" ) ;
49- eprintln ! ( "{}" , expected) ;
50- panic ! ( "specified text was unexpectedly found in file" ) ;
51- }
52- }
53-
548/// Assert that `actual` is equal to `expected`.
559#[ track_caller]
5610pub fn assert_equals < A : AsRef < str > , E : AsRef < str > > ( actual : A , expected : E ) {
0 commit comments