File tree Expand file tree Collapse file tree 1 file changed +62
-1
lines changed Expand file tree Collapse file tree 1 file changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ pub(super) async fn parse_input(
80
80
// Only mentions byte-for-byte matching content inside the patch.
81
81
files
82
82
. iter ( )
83
- . filter ( |f| f. patch . contains ( & * * entry) )
83
+ . filter ( |f| patch_contains ( & f. patch , & * * entry) )
84
84
. map ( |f| PathBuf :: from ( & f. filename ) )
85
85
. collect ( )
86
86
}
@@ -156,3 +156,64 @@ pub(super) async fn handle_input(
156
156
}
157
157
Ok ( ( ) )
158
158
}
159
+
160
+ fn patch_contains ( patch : & str , needle : & str ) -> bool {
161
+ for line in patch. lines ( ) {
162
+ if ( !line. starts_with ( "+++" ) && line. starts_with ( '+' ) )
163
+ || ( !line. starts_with ( "---" ) && line. starts_with ( '-' ) )
164
+ {
165
+ if line. contains ( needle) {
166
+ return true ;
167
+ }
168
+ }
169
+ }
170
+
171
+ false
172
+ }
173
+
174
+ #[ cfg( test) ]
175
+ mod tests {
176
+ use super :: * ;
177
+
178
+ #[ test]
179
+ fn finds_added_line ( ) {
180
+ let patch = "\
181
+ --- a/file.txt
182
+ +++ b/file.txt
183
+ +hello world
184
+ context line
185
+ " ;
186
+ assert ! ( patch_contains( patch, "hello" ) ) ;
187
+ }
188
+
189
+ #[ test]
190
+ fn finds_removed_line ( ) {
191
+ let patch = "\
192
+ --- a/file.txt
193
+ +++ b/file.txt
194
+ -old value
195
+ +new value
196
+ " ;
197
+ assert ! ( patch_contains( patch, "old value" ) ) ;
198
+ }
199
+
200
+ #[ test]
201
+ fn ignores_diff_headers ( ) {
202
+ let patch = "\
203
+ --- a/file.txt
204
+ +++ b/file.txt
205
+ context line
206
+ " ;
207
+ assert ! ( !patch_contains( patch, "file.txt" ) ) ; // should *not* match header
208
+ }
209
+
210
+ #[ test]
211
+ fn needle_not_present ( ) {
212
+ let patch = "\
213
+ --- a/file.txt
214
+ +++ b/file.txt
215
+ +added line
216
+ " ;
217
+ assert ! ( !patch_contains( patch, "missing" ) ) ;
218
+ }
219
+ }
You can’t perform that action at this time.
0 commit comments