40
40
*/
41
41
package com .oracle .graal .python .test .integration .interop ;
42
42
43
-
44
43
import static org .junit .Assert .assertEquals ;
45
44
import static org .junit .Assert .assertTrue ;
46
45
import static org .junit .Assert .fail ;
@@ -92,15 +91,15 @@ public void tearDown() {
92
91
}
93
92
94
93
public interface TestPositionalArgsLong {
95
- long fn (PositionalArguments args );
94
+ long fn (PositionalArguments args );
96
95
}
97
96
98
97
@ Test
99
98
public void testPositionalArgsLength () {
100
99
String source = """
101
- def fn (*args)->int:
102
- return len(args)
103
- """ ;
100
+ def fn (*args)->int:
101
+ return len(args)
102
+ """ ;
104
103
105
104
TestPositionalArgsLong module = context .eval (Source .create ("python" , source )).as (TestPositionalArgsLong .class );
106
105
assertEquals (1 , module .fn (PositionalArguments .of (22 )));
@@ -119,13 +118,13 @@ def fn (*args)->int:
119
118
@ Test
120
119
public void testPositionalArgsWithNoneValue () {
121
120
String source = """
122
- def fn (*args):
123
- result = 0;
124
- for arg in args:
125
- if arg is None:
126
- result = result + 1;
127
- return result
128
- """ ;
121
+ def fn (*args):
122
+ result = 0;
123
+ for arg in args:
124
+ if arg is None:
125
+ result = result + 1;
126
+ return result
127
+ """ ;
129
128
130
129
TestPositionalArgsLong module = context .eval (Source .create ("python" , source )).as (TestPositionalArgsLong .class );
131
130
assertEquals (0 , module .fn (PositionalArguments .of (22 )));
@@ -141,18 +140,18 @@ def fn (*args):
141
140
}
142
141
143
142
public interface TestPositionalArgs01 {
144
- String fn (Object a , Object b , PositionalArguments args );
143
+ String fn (Object a , Object b , PositionalArguments args );
145
144
}
146
145
147
146
@ Test
148
147
public void testPositionalArgs01 () {
149
148
String source = """
150
- def fn (a, b, *args):
151
- result = str(a) + str(b);
152
- for arg in args:
153
- result = result + str(arg);
154
- return result
155
- """ ;
149
+ def fn (a, b, *args):
150
+ result = str(a) + str(b);
151
+ for arg in args:
152
+ result = result + str(arg);
153
+ return result
154
+ """ ;
156
155
TestPositionalArgs01 module = context .eval (Source .create ("python" , source )).as (TestPositionalArgs01 .class );
157
156
assertEquals ("12" , module .fn (1 , 2 , PositionalArguments .of ()));
158
157
assertEquals ("123" , module .fn (1 , 2 , PositionalArguments .of (3 )));
@@ -162,22 +161,26 @@ def fn (a, b, *args):
162
161
}
163
162
164
163
public interface TestPositionalArgs02 {
165
- String fn (Object a );
166
- String fn (Object a , PositionalArguments args );
167
- String fn (PositionalArguments args );
168
- String fn (Object a , Object b );
169
- String fn (Object a , Object b , PositionalArguments args );
164
+ String fn (Object a );
165
+
166
+ String fn (Object a , PositionalArguments args );
167
+
168
+ String fn (PositionalArguments args );
169
+
170
+ String fn (Object a , Object b );
171
+
172
+ String fn (Object a , Object b , PositionalArguments args );
170
173
}
171
174
172
175
@ Test
173
176
public void testPositionalArgs02 () {
174
177
String source = """
175
- def fn (a, b="correct", *args):
176
- result = str(a) + str(b)
177
- for arg in args:
178
- result = result + str(arg)
179
- return result
180
- """ ;
178
+ def fn (a, b="correct", *args):
179
+ result = str(a) + str(b)
180
+ for arg in args:
181
+ result = result + str(arg)
182
+ return result
183
+ """ ;
181
184
TestPositionalArgs02 module = context .eval (Source .create ("python" , source )).as (TestPositionalArgs02 .class );
182
185
assertEquals ("1correct" , module .fn (1 ));
183
186
assertEquals ("12" , module .fn (1 , 2 ));
@@ -191,19 +194,20 @@ def fn (a, b="correct", *args):
191
194
}
192
195
193
196
public interface TestKeywordArgs01 {
194
- String fn ();
195
- String fn (KeywordArguments kwArgs );
197
+ String fn ();
198
+
199
+ String fn (KeywordArguments kwArgs );
196
200
}
197
201
198
202
@ Test
199
203
public void testKeywordArgs01 () {
200
204
String source = """
201
- def fn (**kwArgs):
202
- result = ''
203
- for key, value in kwArgs.items():
204
- result = result + f'[{key}:{str(value)}],'
205
- return result
206
- """ ;
205
+ def fn (**kwArgs):
206
+ result = ''
207
+ for key, value in kwArgs.items():
208
+ result = result + f'[{key}:{str(value)}],'
209
+ return result
210
+ """ ;
207
211
TestKeywordArgs01 module = context .eval (Source .create ("python" , source )).as (TestKeywordArgs01 .class );
208
212
assertEquals ("" , module .fn ());
209
213
assertEquals ("" , module .fn (KeywordArguments .from (new HashMap <>())));
0 commit comments