Skip to content

Commit 4906ff5

Browse files
committed
[GR-11128] fix arity
PullRequest: graalpython/155
2 parents 5766f1d + e19e421 commit 4906ff5

File tree

86 files changed

+1934
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1934
-971
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/ArgumentsTests.java

Lines changed: 262 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
*/
2626
package com.oracle.graal.python.test.grammar;
2727

28-
import static com.oracle.graal.python.test.PythonTests.*;
28+
import static com.oracle.graal.python.test.PythonTests.assertLastLineErrorContains;
29+
import static com.oracle.graal.python.test.PythonTests.assertPrints;
2930

30-
import java.nio.file.*;
31+
import java.nio.file.Path;
32+
import java.nio.file.Paths;
3133

32-
import org.junit.*;
34+
import org.junit.Test;
3335

3436
public class ArgumentsTests {
3537

@@ -151,4 +153,261 @@ public void KwArgs2() {
151153
" print(F)\n" +
152154
"update(42)");
153155
}
156+
157+
private static String call(String source, String args) {
158+
return String.format("%s\nf(%s)", source, args);
159+
}
160+
161+
private static String mkEmptyFunc(String argsDef) {
162+
return String.format("def f(%s): pass", argsDef);
163+
}
164+
165+
@Test
166+
public void f0() {
167+
String source = mkEmptyFunc("");
168+
assertPrints("", call(source, ""));
169+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3"));
170+
assertLastLineErrorContains("TypeError", call(source, "a=1, b=1"));
171+
assertLastLineErrorContains("TypeError", call(source, "1,2,3,4, a=1, b=1"));
172+
}
173+
174+
@Test
175+
public void f1() {
176+
String source = mkEmptyFunc("*args");
177+
assertPrints("", call(source, ""));
178+
assertPrints("", call(source, "1, 2, 3"));
179+
assertLastLineErrorContains("TypeError", call(source, "a=1"));
180+
}
181+
182+
@Test
183+
public void f2() {
184+
String source = mkEmptyFunc("*args, **kw");
185+
assertPrints("", call(source, ""));
186+
assertPrints("", call(source, "1, 2, 3"));
187+
assertPrints("", call(source, "1, 2, 3, a=1, b=2"));
188+
assertPrints("", call(source, "a=1, b=2"));
189+
}
190+
191+
@Test
192+
public void f3() {
193+
String source = mkEmptyFunc("**kw");
194+
assertPrints("", call(source, ""));
195+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3"));
196+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3, a=1, b=2"));
197+
assertPrints("", call(source, "a=1, b=2"));
198+
}
199+
200+
@Test
201+
public void f4() {
202+
String source = mkEmptyFunc("foo=10");
203+
assertPrints("", call(source, ""));
204+
assertPrints("", call(source, "20"));
205+
assertPrints("", call(source, "foo=20"));
206+
assertLastLineErrorContains("TypeError", call(source, "a=10"));
207+
}
208+
209+
@Test
210+
public void f5() {
211+
String source = mkEmptyFunc("foo=10, *args");
212+
assertLastLineErrorContains("SyntaxError", call(source, "foo=1, 2, 3"));
213+
assertPrints("", call(source, "foo=20"));
214+
assertLastLineErrorContains("TypeError", call(source, "a=10"));
215+
assertPrints("", call(source, "1, 2, 3"));
216+
}
217+
218+
@Test
219+
public void f6() {
220+
String source = mkEmptyFunc("foo=10, *args, **kw");
221+
assertPrints("", call(source, "foo=20"));
222+
assertPrints("", call(source, "foo=20, a=2"));
223+
assertLastLineErrorContains("SyntaxError", call(source, "foo=1, 2, 3, a=2"));
224+
}
225+
226+
@Test
227+
public void f7() {
228+
String source = mkEmptyFunc("foo=10, **kw");
229+
assertLastLineErrorContains("TypeError", call(source, "1, 2"));
230+
assertPrints("", call(source, ""));
231+
assertPrints("", call(source, "1"));
232+
assertPrints("", call(source, "1, a=2"));
233+
assertPrints("", call(source, "foo=1, a=2"));
234+
}
235+
236+
@Test
237+
public void f8() {
238+
String source = mkEmptyFunc("a, b");
239+
assertLastLineErrorContains("TypeError", call(source, ""));
240+
assertLastLineErrorContains("TypeError", call(source, "1"));
241+
assertPrints("", call(source, "1, 2"));
242+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3"));
243+
assertLastLineErrorContains("TypeError", call(source, "c=1"));
244+
}
245+
246+
@Test
247+
public void f9() {
248+
String source = mkEmptyFunc("a, b, *args");
249+
assertLastLineErrorContains("TypeError", call(source, ""));
250+
assertPrints("", call(source, "1, 2, 3"));
251+
}
252+
253+
@Test
254+
public void f10() {
255+
String source = mkEmptyFunc("a, b, *args, **kw");
256+
assertPrints("", call(source, "1,2,3,4,c=1"));
257+
assertLastLineErrorContains("TypeError", call(source, "1,2,3,4,a=1"));
258+
}
259+
260+
@Test
261+
public void f11() {
262+
String source = mkEmptyFunc("a, b, **kw");
263+
assertPrints("", call(source, "a=1,b=2"));
264+
assertPrints("", call(source, "a=1,b=2,c=3"));
265+
// TODO
266+
// assertLastLineError("SyntaxError: keyword argument repeated", call(source, "a=1, b=2,
267+
// a=3"));
268+
assertLastLineErrorContains("TypeError", call(source, "1, b=2, a=3"));
269+
}
270+
271+
@Test
272+
public void f12() {
273+
String source = mkEmptyFunc("a, b, foo=10");
274+
assertPrints("", call(source, "1,2"));
275+
assertPrints("", call(source, "1,2,3"));
276+
assertLastLineErrorContains("TypeError", call(source, "a=1"));
277+
assertPrints("", call(source, "1,2,foo=3"));
278+
assertPrints("", call(source, "a=1,b=2,foo=3"));
279+
assertLastLineErrorContains("SyntaxError", call(source, "a=1, 2, foo=3"));
280+
}
281+
282+
@Test
283+
public void f13() {
284+
String source = mkEmptyFunc("a, b, foo=10, *args");
285+
assertPrints("", call(source, "1,2,3,4"));
286+
assertLastLineErrorContains("TypeError", call(source, "1, 2, foo=3, c=4"));
287+
}
288+
289+
@Test
290+
public void f14() {
291+
String source = mkEmptyFunc("a, b, foo=10, *args, **kw");
292+
assertPrints("", call(source, "1, 2, foo=3, c=4"));
293+
assertPrints("", call(source, "a=1, b=2, foo=3, c=4"));
294+
assertPrints("", call(source, "a=1, b=2, foo=3"));
295+
assertPrints("", call(source, "1, 2, 3, c=4"));
296+
assertPrints("", call(source, "1, 2, 3, 4, 5, 6, 7, d=1"));
297+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3, a=4"));
298+
}
299+
300+
@Test
301+
public void f15() {
302+
String source = mkEmptyFunc("a, b, foo=10, **kw");
303+
assertPrints("", call(source, "1, 2, foo=3, c=4"));
304+
assertPrints("", call(source, "a=1, b=2, foo=3, c=4"));
305+
assertPrints("", call(source, "a=1, b=2, foo=3"));
306+
assertPrints("", call(source, "1, 2, 3, c=4"));
307+
assertLastLineErrorContains("TypeError", call(source, "1, 2, 3, 4, 5, 6, 7, d=1"));
308+
}
309+
310+
@Test
311+
public void f16() {
312+
String source = mkEmptyFunc("*, a");
313+
assertLastLineErrorContains("TypeError", call(source, ""));
314+
assertLastLineErrorContains("TypeError", call(source, "1"));
315+
assertPrints("", call(source, "a=1"));
316+
assertLastLineErrorContains("TypeError", call(source, "a=1, b=1"));
317+
}
318+
319+
@Test
320+
public void f17() {
321+
String source = mkEmptyFunc("*, a=5");
322+
assertPrints("", call(source, ""));
323+
assertPrints("", call(source, "a=1"));
324+
assertLastLineErrorContains("TypeError", call(source, "b=1"));
325+
assertLastLineErrorContains("TypeError", call(source, "1"));
326+
}
327+
328+
@Test
329+
public void f18() {
330+
String source = mkEmptyFunc("*, a=5, b");
331+
assertLastLineErrorContains("TypeError", call(source, "1, 2"));
332+
assertLastLineErrorContains("SyntaxError", call(source, "a=1, 2"));
333+
assertPrints("", call(source, "a=1, b=2"));
334+
assertLastLineErrorContains("TypeError", call(source, "a=1,c=2"));
335+
assertLastLineErrorContains("TypeError", call(source, "1,b=2"));
336+
}
337+
338+
@Test
339+
public void f19() {
340+
String source = mkEmptyFunc("*, a, b=5");
341+
assertPrints("", call(source, "a=1"));
342+
assertPrints("", call(source, "a=1, b=2"));
343+
assertLastLineErrorContains("TypeError", call(source, "1,b=2"));
344+
assertLastLineErrorContains("TypeError", call(source, "1"));
345+
}
346+
347+
@Test
348+
public void f20() {
349+
String source = mkEmptyFunc("*, a, b=5, **kw");
350+
assertPrints("", call(source, "a=1"));
351+
assertPrints("", call(source, "a=1, b=2"));
352+
assertPrints("", call(source, "a=1, b=2, c=3"));
353+
// TODO
354+
// assertLastLineError("SyntaxError: keyword argument repeated", call(source,
355+
// "a=1,b=2,a=3"));
356+
assertLastLineErrorContains("TypeError", call(source, "1, b=2"));
357+
assertLastLineErrorContains("TypeError", call(source, "1"));
358+
}
359+
360+
@Test
361+
public void f21() {
362+
String source = mkEmptyFunc("*args, a");
363+
assertLastLineErrorContains("TypeError", call(source, "1,2,3"));
364+
assertPrints("", call(source, "1,2,a=3"));
365+
assertPrints("", call(source, "a=3"));
366+
}
367+
368+
@Test
369+
public void f22() {
370+
String source = mkEmptyFunc("*args, a=5");
371+
assertPrints("", call(source, ""));
372+
assertPrints("", call(source, "a=3"));
373+
assertPrints("", call(source, "1,2,a=3"));
374+
assertLastLineErrorContains("TypeError", call(source, "a=2, b=3"));
375+
}
376+
377+
@Test
378+
public void f23() {
379+
String source = mkEmptyFunc("*args, a=5, b");
380+
assertLastLineErrorContains("TypeError", call(source, "1,2,3"));
381+
assertPrints("", call(source, "1,2,3,b=4"));
382+
assertPrints("", call(source, "1,2,a=3,b=4"));
383+
assertPrints("", call(source, "1,2,b=4,a=3"));
384+
}
385+
386+
@Test
387+
public void f24() {
388+
String source = mkEmptyFunc("*args, a, b=5");
389+
assertLastLineErrorContains("TypeError", call(source, "1,2,3"));
390+
assertPrints("", call(source, "1,2,a=3"));
391+
assertPrints("", call(source, "1,2,a=3,b=4"));
392+
assertLastLineErrorContains("TypeError", call(source, "1,2, a=3, b=4, c=5"));
393+
assertPrints("", call(source, "a=1"));
394+
assertLastLineErrorContains("TypeError", call(source, "1"));
395+
assertPrints("", call(source, "a=1, b=2"));
396+
assertLastLineErrorContains("SyntaxError", call(source, "a=1, 2"));
397+
}
398+
399+
@Test
400+
public void f25() {
401+
String source = mkEmptyFunc("*args, a, b=5, **kw");
402+
assertLastLineErrorContains("TypeError", call(source, ""));
403+
assertLastLineErrorContains("TypeError", call(source, "1,2,3"));
404+
assertPrints("", call(source, "1,2,3,a=4"));
405+
assertPrints("", call(source, "1,2,3,a=4,b=5"));
406+
assertLastLineErrorContains("SyntaxError", call(source, "1,2,3,a=4,5"));
407+
assertPrints("", call(source, "1,2,3,a=4,b=5,c=6"));
408+
assertPrints("", call(source, "1,2,3,a=4,c=6"));
409+
assertLastLineErrorContains("TypeError", call(source, "1,2,3,c=6"));
410+
assertPrints("", call(source, "a=4,c=6"));
411+
assertPrints("", call(source, "a=4"));
412+
}
154413
}

0 commit comments

Comments
 (0)