71
71
expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
72
72
} )
73
73
test ( 'Nested ternary' , ( ) => {
74
- const text = `1 if A else 2 if B else 3\n` ;
74
+ const text = `1 if a else 2 if b else 3\n` ;
75
75
expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
76
76
} )
77
77
} ) ;
@@ -113,6 +113,7 @@ def y(a, b, c):
113
113
`
114
114
expect ( toPythonAst ( text ) ) . toMatchObject ( { } ) ;
115
115
} ) ;
116
+
116
117
// @TODO fix me
117
118
// test('Function definition empty lines', () => {
118
119
// const text = `\
@@ -136,18 +137,187 @@ def y(a, b, c):
136
137
} ) ;
137
138
138
139
describe ( 'Conditional statements' , ( ) => {
139
- test ( 'If-elif- else' , ( ) => {
140
+ test ( 'If-else statement ' , ( ) => {
140
141
const text = `
141
- if x:
142
- pass
143
- elif y:
144
- pass
145
- elif z:
146
- pass
142
+ if x > 10:
143
+ print("x is greater than 10")
147
144
else:
148
- pass
145
+ print("x is less than or equal to 10")
149
146
` ;
150
147
expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
151
- } )
152
- } )
153
- } )
148
+ } ) ;
149
+
150
+ test ( 'If-elif-else statement' , ( ) => {
151
+ const text = `
152
+ if x > 10:
153
+ print("x is greater than 10")
154
+ elif x == 10:
155
+ print("x is equal to 10")
156
+ else:
157
+ print("x is less than 10")
158
+ ` ;
159
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
160
+ } ) ;
161
+ } ) ;
162
+
163
+ describe ( 'N-base numbers' , ( ) => {
164
+ test ( 'Binary number' , ( ) => {
165
+ const text = `0b101010\n` ;
166
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
167
+ } ) ;
168
+
169
+ test ( 'Octal number' , ( ) => {
170
+ const text = `0o1234567\n` ;
171
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
172
+ } ) ;
173
+
174
+ test ( 'Hexadecimal number' , ( ) => {
175
+ const text = `0xabcdef\n` ;
176
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
177
+ } ) ;
178
+ } ) ;
179
+
180
+ describe ( 'Binary operators' , ( ) => {
181
+ test ( 'Addition' , ( ) => {
182
+ const text = `1 + 1\n` ;
183
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
184
+ } ) ;
185
+
186
+ test ( 'Large Number Addition' , ( ) => {
187
+ const text = `100000000 ** 100000000 + 1\n` ;
188
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
189
+ } ) ;
190
+
191
+ test ( 'Subtraction' , ( ) => {
192
+ const text = `1 - 1\n` ;
193
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
194
+ } ) ;
195
+
196
+ test ( 'Multiplication' , ( ) => {
197
+ const text = `1 * 1\n` ;
198
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
199
+ } ) ;
200
+
201
+ test ( 'Large Number Multiplication' , ( ) => {
202
+ const text = `100000000 ** 100000000 * 5\n` ;
203
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
204
+ } ) ;
205
+
206
+ test ( 'Division' , ( ) => {
207
+ const text = `1 / 1\n` ;
208
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
209
+ } ) ;
210
+
211
+ test ( 'Modulus' , ( ) => {
212
+ const text = `1 % 1\n` ;
213
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
214
+ } ) ;
215
+
216
+ test ( 'Exponent' , ( ) => {
217
+ const text = `2 ** 2\n` ;
218
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
219
+ } ) ;
220
+
221
+ test ( 'Less than' , ( ) => {
222
+ const text = `1 < 2\n` ;
223
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
224
+ } ) ;
225
+
226
+ test ( 'Greater than' , ( ) => {
227
+ const text = `2 > 1\n` ;
228
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
229
+ } ) ;
230
+
231
+ test ( 'Less than or equal to' , ( ) => {
232
+ const text = `1 <= 2\n` ;
233
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
234
+ } ) ;
235
+
236
+ test ( 'Greater than or equal to' , ( ) => {
237
+ const text = `2 >= 1\n` ;
238
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
239
+ } ) ;
240
+
241
+ test ( 'Equality' , ( ) => {
242
+ const text = `1 == 2\n` ;
243
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
244
+ } ) ;
245
+
246
+ test ( 'Inequality' , ( ) => {
247
+ const text = `1 != 2\n` ;
248
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
249
+ } ) ;
250
+ } ) ;
251
+
252
+ describe ( 'Unary operators' , ( ) => {
253
+ test ( 'Negation' , ( ) => {
254
+ const text = `-1\n` ;
255
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
256
+ } ) ;
257
+
258
+ // TODO: FIX THIS
259
+ // test('Logical NOT', () => {
260
+ // const text = `not 1\n`;
261
+ // expect(toPythonAst(text)).toMatchObject({})
262
+ // });
263
+ } ) ;
264
+
265
+ describe ( 'Binary logical operators' , ( ) => {
266
+ test ( 'Logical AND' , ( ) => {
267
+ const text = `1 and 2\n` ;
268
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
269
+ } ) ;
270
+
271
+ test ( 'Logical OR' , ( ) => {
272
+ const text = `1 or 2\n` ;
273
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
274
+ } ) ;
275
+ } ) ;
276
+
277
+ describe ( 'Complex expressions' , ( ) => {
278
+ test ( 'Nested function call' , ( ) => {
279
+ const text = `
280
+ def f1(x, y):
281
+ return 1
282
+
283
+ def f2(x, y):
284
+ return y
285
+
286
+ f1(f2(1, 2), 2)
287
+ ` ;
288
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
289
+ } ) ;
290
+
291
+ test ( 'Binary operation with parentheses' , ( ) => {
292
+ const text = `(1 + 2) * 3\n` ;
293
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
294
+ } ) ;
295
+ } ) ;
296
+
297
+ describe ( 'Primitive expressions' , ( ) => {
298
+ test ( 'Number literal' , ( ) => {
299
+ const text = `42\n` ;
300
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
301
+ } ) ;
302
+
303
+ test ( 'Large Number literal' , ( ) => {
304
+ const text = `1000000000 ** 100000000\n` ;
305
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
306
+ } ) ;
307
+
308
+ test ( 'Boolean literal True' , ( ) => {
309
+ const text = `True\n` ;
310
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
311
+ } ) ;
312
+
313
+ test ( 'Boolean literal False' , ( ) => {
314
+ const text = `False\n` ;
315
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
316
+ } ) ;
317
+
318
+ test ( 'String literal' , ( ) => {
319
+ const text = `"Hello, World!"\n` ;
320
+ expect ( toPythonAst ( text ) ) . toMatchObject ( { } )
321
+ } ) ;
322
+ } ) ;
323
+ } ) ;
0 commit comments