@@ -329,6 +329,31 @@ mod tests {
329
329
330
330
use super :: reverse_fixups;
331
331
332
+ // The following three functions are only meant to check partial structural equivalence of
333
+ // `TokenTree`s, see the last assertion in `check()`.
334
+ fn check_leaf_eq ( a : & tt:: Leaf , b : & tt:: Leaf ) -> bool {
335
+ match ( a, b) {
336
+ ( tt:: Leaf :: Literal ( a) , tt:: Leaf :: Literal ( b) ) => a. text == b. text ,
337
+ ( tt:: Leaf :: Punct ( a) , tt:: Leaf :: Punct ( b) ) => a. char == b. char ,
338
+ ( tt:: Leaf :: Ident ( a) , tt:: Leaf :: Ident ( b) ) => a. text == b. text ,
339
+ _ => false ,
340
+ }
341
+ }
342
+
343
+ fn check_subtree_eq ( a : & tt:: Subtree , b : & tt:: Subtree ) -> bool {
344
+ a. delimiter . map ( |it| it. kind ) == b. delimiter . map ( |it| it. kind )
345
+ && a. token_trees . len ( ) == b. token_trees . len ( )
346
+ && a. token_trees . iter ( ) . zip ( & b. token_trees ) . all ( |( a, b) | check_tt_eq ( a, b) )
347
+ }
348
+
349
+ fn check_tt_eq ( a : & tt:: TokenTree , b : & tt:: TokenTree ) -> bool {
350
+ match ( a, b) {
351
+ ( tt:: TokenTree :: Leaf ( a) , tt:: TokenTree :: Leaf ( b) ) => check_leaf_eq ( a, b) ,
352
+ ( tt:: TokenTree :: Subtree ( a) , tt:: TokenTree :: Subtree ( b) ) => check_subtree_eq ( a, b) ,
353
+ _ => false ,
354
+ }
355
+ }
356
+
332
357
#[ track_caller]
333
358
fn check ( ra_fixture : & str , mut expect : Expect ) {
334
359
let parsed = syntax:: SourceFile :: parse ( ra_fixture) ;
@@ -341,8 +366,7 @@ mod tests {
341
366
fixups. append ,
342
367
) ;
343
368
344
- let mut actual = tt. to_string ( ) ;
345
- actual. push ( '\n' ) ;
369
+ let actual = format ! ( "{}\n " , tt) ;
346
370
347
371
expect. indent ( false ) ;
348
372
expect. assert_eq ( & actual) ;
@@ -358,9 +382,12 @@ mod tests {
358
382
reverse_fixups ( & mut tt, & tmap, & fixups. undo_info ) ;
359
383
360
384
// the fixed-up + reversed version should be equivalent to the original input
361
- // (but token IDs don't matter)
385
+ // modulo token IDs and `Punct`s' spacing.
362
386
let ( original_as_tt, _) = mbe:: syntax_node_to_token_tree ( & parsed. syntax_node ( ) ) ;
363
- assert_eq ! ( tt. to_string( ) , original_as_tt. to_string( ) ) ;
387
+ assert ! (
388
+ check_subtree_eq( & tt, & original_as_tt) ,
389
+ "different token tree: {tt:?}, {original_as_tt:?}"
390
+ ) ;
364
391
}
365
392
366
393
#[ test]
@@ -483,7 +510,6 @@ fn foo () {a . __ra_fixup}
483
510
}
484
511
485
512
#[ test]
486
- #[ ignore]
487
513
fn incomplete_field_expr_2 ( ) {
488
514
check (
489
515
r#"
@@ -492,13 +518,12 @@ fn foo() {
492
518
}
493
519
"# ,
494
520
expect ! [ [ r#"
495
- fn foo () {a .__ra_fixup ;}
521
+ fn foo () {a . __ra_fixup ;}
496
522
"# ] ] ,
497
523
)
498
524
}
499
525
500
526
#[ test]
501
- #[ ignore]
502
527
fn incomplete_field_expr_3 ( ) {
503
528
check (
504
529
r#"
@@ -508,7 +533,7 @@ fn foo() {
508
533
}
509
534
"# ,
510
535
expect ! [ [ r#"
511
- fn foo () {a .__ra_fixup ; bar () ;}
536
+ fn foo () {a . __ra_fixup ; bar () ;}
512
537
"# ] ] ,
513
538
)
514
539
}
0 commit comments