Skip to content

Commit

Permalink
Update tests since ? macro op is supported on 2015.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed May 18, 2019
1 parent 51b9dc3 commit 695b601
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 87 deletions.
33 changes: 33 additions & 0 deletions src/test/run-pass/macros/macro-at-most-once-rep-2015.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// run-pass
#![allow(unused_mut)]
// The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
// Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
// ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
// exercise that logic in the macro parser.
//
// Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
// included for consistency with `+` and `*`.
//
// This test focuses on non-error cases and making sure the correct number of repetitions happen.

// edition:2015

macro_rules! foo {
($($a:ident)? ; $num:expr) => { {
let mut x = 0;

$(
x += $a;
)?

assert_eq!(x, $num);
} }
}

pub fn main() {
let a = 1;

// accept 0 or 1 repetitions
foo!( ; 0);
foo!(a ; 1);
}
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-39388.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_macros)]

macro_rules! assign {
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+`
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected one of: `*`, `+`, or `?`
$($a)* = $($b)*
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-39388.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected `*` or `+`
error: expected one of: `*`, `+`, or `?`
--> $DIR/issue-39388.rs:4:22
|
LL | (($($a:tt)*) = ($($b:tt))*) => {
Expand Down
13 changes: 0 additions & 13 deletions src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.stderr

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs

This file was deleted.

24 changes: 0 additions & 24 deletions src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr

This file was deleted.

41 changes: 41 additions & 0 deletions src/test/ui/macros/macro-at-most-once-rep-2015.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Tests that `?` is a Kleene op and not a macro separator in the 2015 edition.

// edition:2015

macro_rules! foo {
($(a)?) => {};
}

macro_rules! baz {
($(a),?) => {}; //~ERROR the `?` macro repetition operator
}

macro_rules! barplus {
($(a)?+) => {}; // ok. matches "a+" and "+"
}

macro_rules! barstar {
($(a)?*) => {}; // ok. matches "a*" and "*"
}

pub fn main() {
foo!();
foo!(a);
foo!(a?); //~ ERROR no rules expected the token `?`
foo!(a?a); //~ ERROR no rules expected the token `?`
foo!(a?a?a); //~ ERROR no rules expected the token `?`

barplus!(); //~ERROR unexpected end of macro invocation
barplus!(a); //~ERROR unexpected end of macro invocation
barplus!(a?); //~ ERROR no rules expected the token `?`
barplus!(a?a); //~ ERROR no rules expected the token `?`
barplus!(a+);
barplus!(+);

barstar!(); //~ERROR unexpected end of macro invocation
barstar!(a); //~ERROR unexpected end of macro invocation
barstar!(a?); //~ ERROR no rules expected the token `?`
barstar!(a?a); //~ ERROR no rules expected the token `?`
barstar!(a*);
barstar!(*);
}
107 changes: 107 additions & 0 deletions src/test/ui/macros/macro-at-most-once-rep-2015.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
error: the `?` macro repetition operator does not take a separator
--> $DIR/macro-at-most-once-rep-2015.rs:10:10
|
LL | ($(a),?) => {};
| ^

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:24:11
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?);
| ^ no rules expected this token in macro call

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:25:11
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a);
| ^ no rules expected this token in macro call

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:26:11
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a?a);
| ^ no rules expected this token in macro call

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2015.rs:28:5
|
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!();
| ^^^^^^^^^^^ missing tokens in macro arguments

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2015.rs:29:15
|
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a);
| ^ missing tokens in macro arguments

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:30:15
|
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a?);
| ^ no rules expected this token in macro call

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:31:15
|
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a?a);
| ^ no rules expected this token in macro call

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2015.rs:35:5
|
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!();
| ^^^^^^^^^^^ missing tokens in macro arguments

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2015.rs:36:15
|
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a);
| ^ missing tokens in macro arguments

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:37:15
|
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a?);
| ^ no rules expected this token in macro call

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2015.rs:38:15
|
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a?a);
| ^ no rules expected this token in macro call

error: aborting due to 12 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/parser/macro/issue-33569.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro_rules! foo {
{ $+ } => { //~ ERROR expected identifier, found `+`
//~^ ERROR missing fragment specifier
$(x)(y) //~ ERROR expected `*` or `+`
$(x)(y) //~ ERROR expected one of: `*`, `+`, or `?`
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/macro/issue-33569.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: expected identifier, found `+`
LL | { $+ } => {
| ^

error: expected `*` or `+`
error: expected one of: `*`, `+`, or `?`
--> $DIR/issue-33569.rs:4:13
|
LL | $(x)(y)
Expand Down

0 comments on commit 695b601

Please sign in to comment.