File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -259,3 +259,51 @@ impl FilePatcher {
259
259
visitor. 1
260
260
}
261
261
}
262
+
263
+ #[ cfg( test) ]
264
+ mod tests {
265
+ use insta:: assert_debug_snapshot;
266
+
267
+ use super :: * ;
268
+ use std:: path:: PathBuf ;
269
+
270
+ #[ test]
271
+ fn test_find_snapshot_macro ( ) {
272
+ let content = r######"
273
+ use insta::assert_snapshot;
274
+
275
+ fn test_function() {
276
+ assert_snapshot!("test\ntest", @r###"
277
+ test
278
+ test
279
+ "###);
280
+ }
281
+ "###### ;
282
+
283
+ let file_patcher = FilePatcher {
284
+ filename : PathBuf :: new ( ) ,
285
+ lines : content. lines ( ) . map ( String :: from) . collect ( ) ,
286
+ source : syn:: parse_file ( content) . unwrap ( ) ,
287
+ inline_snapshots : vec ! [ ] ,
288
+ } ;
289
+
290
+ // The snapshot macro starts on line 5 (1-based index)
291
+ let snapshot = file_patcher. find_snapshot_macro ( 5 ) . unwrap ( ) ;
292
+
293
+ // Extract the snapshot content
294
+ let snapshot_content: Vec < String > =
295
+ file_patcher. lines [ snapshot. start . 0 ..=snapshot. end . 0 ] . to_vec ( ) ;
296
+
297
+ assert_debug_snapshot ! ( snapshot_content, @r####"
298
+ [
299
+ " assert_snapshot!(\"test\\ntest\", @r###\"",
300
+ " test",
301
+ " test",
302
+ " \"###);",
303
+ ]
304
+ "#### ) ;
305
+
306
+ // Assert the indentation
307
+ assert_debug_snapshot ! ( snapshot. indentation, @"4" ) ;
308
+ }
309
+ }
You can’t perform that action at this time.
0 commit comments