Skip to content

Commit 6005ea5

Browse files
bors[bot]matklad
andauthored
Merge #10497
10497: internal: move tests r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents b2b703b + de136a5 commit 6005ea5

File tree

2 files changed

+232
-217
lines changed

2 files changed

+232
-217
lines changed

crates/hir_def/src/macro_expansion_tests/mbe.rs

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,235 @@ fn baz() -> bool {
383383
"#]],
384384
);
385385
}
386+
387+
#[test]
388+
fn test_match_group_zero_match() {
389+
check(
390+
r#"
391+
macro_rules! m { ( $($i:ident)* ) => (); }
392+
m!();
393+
"#,
394+
expect![[r#"
395+
macro_rules! m { ( $($i:ident)* ) => (); }
396+
397+
"#]],
398+
);
399+
}
400+
401+
#[test]
402+
fn test_match_group_in_group() {
403+
check(
404+
r#"
405+
macro_rules! m {
406+
[ $( ( $($i:ident)* ) )* ] => [ x![$( ( $($i)* ) )*]; ]
407+
}
408+
m! ( (a b) );
409+
"#,
410+
expect![[r#"
411+
macro_rules! m {
412+
[ $( ( $($i:ident)* ) )* ] => [ x![$( ( $($i)* ) )*]; ]
413+
}
414+
x![(a b)];
415+
"#]],
416+
)
417+
}
418+
419+
#[test]
420+
fn test_expand_to_item_list() {
421+
check(
422+
r#"
423+
macro_rules! structs {
424+
($($i:ident),*) => { $(struct $i { field: u32 } )* }
425+
}
426+
427+
// +tree
428+
structs!(Foo, Bar);
429+
"#,
430+
expect![[r#"
431+
macro_rules! structs {
432+
($($i:ident),*) => { $(struct $i { field: u32 } )* }
433+
}
434+
435+
struct Foo {
436+
field:u32
437+
}
438+
struct Bar {
439+
field:u32
440+
}
441+
442+
443+
// [email protected] "struct"
444+
445+
446+
447+
448+
449+
450+
451+
452+
453+
454+
455+
456+
457+
458+
459+
// [email protected] "struct"
460+
461+
462+
463+
464+
465+
466+
467+
468+
469+
470+
471+
472+
473+
474+
475+
"#]],
476+
);
477+
}
478+
479+
#[test]
480+
fn test_two_idents() {
481+
check(
482+
r#"
483+
macro_rules! m {
484+
($i:ident, $j:ident) => { fn foo() { let a = $i; let b = $j; } }
485+
}
486+
m! { foo, bar }
487+
"#,
488+
expect![[r#"
489+
macro_rules! m {
490+
($i:ident, $j:ident) => { fn foo() { let a = $i; let b = $j; } }
491+
}
492+
fn foo() {
493+
let a = foo;
494+
let b = bar;
495+
}
496+
"#]],
497+
);
498+
}
499+
500+
#[test]
501+
fn test_tt_to_stmts() {
502+
check(
503+
r#"
504+
macro_rules! m {
505+
() => {
506+
let a = 0;
507+
a = 10 + 1;
508+
a
509+
}
510+
}
511+
512+
fn f() -> i32 {
513+
// +tree
514+
m!{}
515+
}
516+
"#,
517+
expect![[r#"
518+
macro_rules! m {
519+
() => {
520+
let a = 0;
521+
a = 10 + 1;
522+
a
523+
}
524+
}
525+
526+
fn f() -> i32 {
527+
let a = 0;
528+
a = 10+1;
529+
a
530+
531+
532+
533+
534+
535+
536+
537+
538+
539+
540+
541+
542+
543+
544+
545+
546+
547+
548+
549+
550+
551+
552+
553+
554+
555+
556+
557+
558+
559+
560+
561+
}
562+
"#]],
563+
);
564+
}
565+
566+
#[test]
567+
fn test_match_literal() {
568+
check(
569+
r#"
570+
macro_rules! m {
571+
('(') => { fn l_paren() {} }
572+
}
573+
m!['('];
574+
"#,
575+
expect![[r#"
576+
macro_rules! m {
577+
('(') => { fn l_paren() {} }
578+
}
579+
fn l_paren() {}
580+
"#]],
581+
);
582+
}
583+
584+
#[test]
585+
fn test_parse_macro_def_simple() {
586+
cov_mark::check!(parse_macro_def_simple);
587+
check(
588+
r#"
589+
macro m($id:ident) { fn $id() {} }
590+
m!(bar);
591+
"#,
592+
expect![[r#"
593+
macro m($id:ident) { fn $id() {} }
594+
fn bar() {}
595+
"#]],
596+
);
597+
}
598+
599+
#[test]
600+
fn test_parse_macro_def_rules() {
601+
cov_mark::check!(parse_macro_def_rules);
602+
603+
check(
604+
r#"
605+
macro m {
606+
($id:ident) => { fn $id() {} }
607+
}
608+
m!(bar);
609+
"#,
610+
expect![[r#"
611+
macro m {
612+
($id:ident) => { fn $id() {} }
613+
}
614+
fn bar() {}
615+
"#]],
616+
);
617+
}

0 commit comments

Comments
 (0)