|
9 | 9 | import org.antlr.runtime.RecognitionException; |
10 | 10 | import org.antlr.v4.tool.ErrorType; |
11 | 11 | 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; |
12 | 15 | import org.stringtemplate.v4.ST; |
13 | 16 | import org.stringtemplate.v4.STGroup; |
14 | 17 | import org.stringtemplate.v4.misc.ErrorBuffer; |
15 | 18 |
|
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
| 21 | +import java.util.stream.Stream; |
| 22 | + |
16 | 23 | import static org.antlr.v4.test.tool.ToolTestUtils.testErrors; |
17 | 24 |
|
18 | 25 | /** */ |
@@ -145,7 +152,7 @@ public class TestAttributeChecks { |
145 | 152 | "$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", |
146 | 153 | }; |
147 | 154 |
|
148 | | - String[] dynInlineChecks = { |
| 155 | + static String[] dynInlineChecks = { |
149 | 156 | "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference a in $a\n", |
150 | 157 | "$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference b in $b\n", |
151 | 158 | "$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 { |
214 | 221 | testActions("inline", inlineChecks, attributeTemplate); |
215 | 222 | } |
216 | 223 |
|
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); |
219 | 236 | } |
220 | 237 |
|
221 | 238 | @Test public void testBadInlineActions() throws RecognitionException { |
@@ -244,12 +261,16 @@ private static void testActions(String location, String[] pairs, String template |
244 | 261 | for (int i = 0; i < pairs.length; i += 2) { |
245 | 262 | String action = pairs[i]; |
246 | 263 | 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); |
253 | 265 | } |
254 | 266 | } |
| 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 | + } |
255 | 276 | } |
0 commit comments