Skip to content

Commit f24447e

Browse files
committed
Set @ParametrizedTest for testDynamicInlineActions
1 parent 6a15cc3 commit f24447e

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

tool-testsuite/test/org/antlr/v4/test/tool/TestAttributeChecks.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
import org.antlr.runtime.RecognitionException;
1010
import org.antlr.v4.tool.ErrorType;
1111
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.params.ParameterizedTest;
13+
import org.junit.jupiter.params.provider.Arguments;
14+
import org.junit.jupiter.params.provider.MethodSource;
1215
import org.stringtemplate.v4.ST;
1316
import org.stringtemplate.v4.STGroup;
1417
import org.stringtemplate.v4.misc.ErrorBuffer;
1518

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.stream.Stream;
22+
1623
import static org.antlr.v4.test.tool.ToolTestUtils.testErrors;
1724

1825
/** */
@@ -145,7 +152,7 @@ public class TestAttributeChecks {
145152
"$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j = $S::k;\n",
146153
};
147154

148-
String[] dynInlineChecks = {
155+
static String[] dynInlineChecks = {
149156
"$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference a in $a\n",
150157
"$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference b in $b\n",
151158
"$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference lab in $lab\n",
@@ -214,8 +221,18 @@ public class TestAttributeChecks {
214221
testActions("inline", inlineChecks, attributeTemplate);
215222
}
216223

217-
@Test public void testDynamicInlineActions() throws RecognitionException {
218-
testActions("inline", dynInlineChecks, attributeTemplate);
224+
public static Stream<Arguments> testDynamicInlineActionsParams() {
225+
List<Arguments> arguments = new ArrayList<>();
226+
for (int i = 0; i < dynInlineChecks.length; i+=2) {
227+
arguments.add(Arguments.of(dynInlineChecks[i], dynInlineChecks[i+1]));
228+
}
229+
return arguments.stream();
230+
}
231+
232+
@ParameterizedTest
233+
@MethodSource("testDynamicInlineActionsParams")
234+
public void testDynamicInlineActions(String input, String expected) {
235+
testAction("inline", attributeTemplate, input, expected);
219236
}
220237

221238
@Test public void testBadInlineActions() throws RecognitionException {
@@ -244,12 +261,16 @@ private static void testActions(String location, String[] pairs, String template
244261
for (int i = 0; i < pairs.length; i += 2) {
245262
String action = pairs[i];
246263
String expected = pairs[i + 1];
247-
STGroup g = new STGroup('<', '>');
248-
g.setListener(new ErrorBuffer()); // hush warnings
249-
ST st = new ST(g, template);
250-
st.add(location, action);
251-
String grammar = st.render();
252-
testErrors(new String[]{grammar, expected}, false);
264+
testAction(location, template, action, expected);
253265
}
254266
}
267+
268+
private static void testAction(String location, String template, String action, String expected) {
269+
STGroup g = new STGroup('<', '>');
270+
g.setListener(new ErrorBuffer()); // hush warnings
271+
ST st = new ST(g, template);
272+
st.add(location, action);
273+
String grammar = st.render();
274+
testErrors(new String[]{grammar, expected}, false);
275+
}
255276
}

0 commit comments

Comments
 (0)