This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,26 @@ pub fn collect_run_actions(ctx: &InitActionContext, file: &Path) -> Vec<RunActio
23
23
}
24
24
25
25
lazy_static ! {
26
- static ref TEST_FN_RE : Regex = Regex :: new( r"#\[test\]\s*\n\s*fn\s*(?P<name>\w+)" ) . unwrap( ) ;
26
+ /// __(a):__ `\#\[test\]` matches `#[test]`
27
+ ///
28
+ /// __(b):__ `^[^\/]*?fn\s+(?P<name>\w+)` matches any line which contains `fn name` before any comment is started and captures the word after fn.
29
+ /// The laziness of the quantifier is there to make the regex quicker (about 5 times less steps)
30
+ ///
31
+ /// __(c):__ `(\n|.)*?` will match anything lazilly, matching whatever shortest string exists between __(a)__ and __(b)__, ensuring
32
+ /// that whatever sits in between `#[test]` and the next function declaration doesn't interfere. It MUST be lazy, both for performance,
33
+ /// as well as to prevent matches with further declared functions.
34
+ ///
35
+ /// __(d):__ `(?m)` sets the and `m` regex flags to allow `^` to match line starts.
36
+ ///
37
+ /// This regex is still imperfect, for example:
38
+ /// ```rust
39
+ /// #[test] /*
40
+ /// But at this point it's pretty much a deliberate attempt
41
+ /// to make `fn wrong_function` be matched instead of */
42
+ /// fn right_function() {}
43
+ /// ```
44
+ static ref TEST_FN_RE : Regex =
45
+ Regex :: new( r"(?m)#\[test\](\n|.)*?^[^/]*?fn\s+(?P<name>\w+)" ) . unwrap( ) ;
27
46
}
28
47
29
48
let line_index = LineIndex :: new ( & text) ;
You can’t perform that action at this time.
0 commit comments