Skip to content

Commit 7f973c9

Browse files
committed
More tests
1 parent 5902da5 commit 7f973c9

File tree

3 files changed

+132
-95
lines changed

3 files changed

+132
-95
lines changed

mypyc/test-data/irbuild-tuple.test

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -281,36 +281,6 @@ L5:
281281
L6:
282282
return r6
283283

284-
[case testTupleOperatorInFinalTuple]
285-
from typing import Final
286-
287-
tt: Final = (1, 2)
288-
289-
def f(x: int) -> bool:
290-
return x in tt
291-
[out]
292-
def f(x):
293-
x :: int
294-
r0 :: tuple[int, int]
295-
r1 :: bool
296-
r2, r3 :: object
297-
r4 :: i32
298-
r5 :: bit
299-
r6 :: bool
300-
L0:
301-
r0 = __main__.tt :: static
302-
if is_error(r0) goto L1 else goto L2
303-
L1:
304-
r1 = raise NameError('value for final name "tt" was not set')
305-
unreachable
306-
L2:
307-
r2 = box(int, x)
308-
r3 = box(tuple[int, int], r0)
309-
r4 = PySequence_Contains(r3, r2)
310-
r5 = r4 >= 0 :: signed
311-
r6 = truncate r4: i32 to builtins.bool
312-
return r6
313-
314284
[case testTupleBuiltFromList]
315285
def f(val: int) -> bool:
316286
return val % 2 == 0

mypyc/test-data/run-lists.test

Lines changed: 123 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def test_multiply() -> None:
364364
assert l1 == [1, 1, 1]
365365

366366
[case testOperatorInExpression]
367+
from typing import Final
367368

368369
def tuple_in_int0(i: int) -> bool:
369370
return i in []
@@ -416,71 +417,128 @@ def list_not_in_str(s: "str") -> bool:
416417
def list_in_mixed(i: object):
417418
return i in [[], (), "", 0, 0.0, False, 0j, {}, set(), type]
418419

419-
[file driver.py]
420-
421-
from native import *
422-
423-
assert not tuple_in_int0(0)
424-
assert not tuple_in_int1(0)
425-
assert tuple_in_int1(1)
426-
assert not tuple_in_int3(0)
427-
assert tuple_in_int3(1)
428-
assert tuple_in_int3(2)
429-
assert tuple_in_int3(3)
430-
assert not tuple_in_int3(4)
431-
432-
assert tuple_not_in_int0(0)
433-
assert tuple_not_in_int1(0)
434-
assert not tuple_not_in_int1(1)
435-
assert tuple_not_in_int3(0)
436-
assert not tuple_not_in_int3(1)
437-
assert not tuple_not_in_int3(2)
438-
assert not tuple_not_in_int3(3)
439-
assert tuple_not_in_int3(4)
440-
441-
assert tuple_in_str("foo")
442-
assert tuple_in_str("bar")
443-
assert tuple_in_str("baz")
444-
assert not tuple_in_str("apple")
445-
assert not tuple_in_str("pie")
446-
assert not tuple_in_str("\0")
447-
assert not tuple_in_str("")
448-
449-
assert not list_in_int0(0)
450-
assert not list_in_int1(0)
451-
assert list_in_int1(1)
452-
assert not list_in_int3(0)
453-
assert list_in_int3(1)
454-
assert list_in_int3(2)
455-
assert list_in_int3(3)
456-
assert not list_in_int3(4)
457-
458-
assert list_not_in_int0(0)
459-
assert list_not_in_int1(0)
460-
assert not list_not_in_int1(1)
461-
assert list_not_in_int3(0)
462-
assert not list_not_in_int3(1)
463-
assert not list_not_in_int3(2)
464-
assert not list_not_in_int3(3)
465-
assert list_not_in_int3(4)
466-
467-
assert list_in_str("foo")
468-
assert list_in_str("bar")
469-
assert list_in_str("baz")
470-
assert not list_in_str("apple")
471-
assert not list_in_str("pie")
472-
assert not list_in_str("\0")
473-
assert not list_in_str("")
474-
475-
assert list_in_mixed(0)
476-
assert list_in_mixed([])
477-
assert list_in_mixed({})
478-
assert list_in_mixed(())
479-
assert list_in_mixed(False)
480-
assert list_in_mixed(0.0)
481-
assert not list_in_mixed([1])
482-
assert not list_in_mixed(object)
483-
assert list_in_mixed(type)
420+
def test_in_operator_various_cases() -> None:
421+
assert not tuple_in_int0(0)
422+
assert not tuple_in_int1(0)
423+
assert tuple_in_int1(1)
424+
assert not tuple_in_int3(0)
425+
assert tuple_in_int3(1)
426+
assert tuple_in_int3(2)
427+
assert tuple_in_int3(3)
428+
assert not tuple_in_int3(4)
429+
430+
assert tuple_not_in_int0(0)
431+
assert tuple_not_in_int1(0)
432+
assert not tuple_not_in_int1(1)
433+
assert tuple_not_in_int3(0)
434+
assert not tuple_not_in_int3(1)
435+
assert not tuple_not_in_int3(2)
436+
assert not tuple_not_in_int3(3)
437+
assert tuple_not_in_int3(4)
438+
439+
assert tuple_in_str("foo")
440+
assert tuple_in_str("bar")
441+
assert tuple_in_str("baz")
442+
assert not tuple_in_str("apple")
443+
assert not tuple_in_str("pie")
444+
assert not tuple_in_str("\0")
445+
assert not tuple_in_str("")
446+
447+
assert not list_in_int0(0)
448+
assert not list_in_int1(0)
449+
assert list_in_int1(1)
450+
assert not list_in_int3(0)
451+
assert list_in_int3(1)
452+
assert list_in_int3(2)
453+
assert list_in_int3(3)
454+
assert not list_in_int3(4)
455+
456+
assert list_not_in_int0(0)
457+
assert list_not_in_int1(0)
458+
assert not list_not_in_int1(1)
459+
assert list_not_in_int3(0)
460+
assert not list_not_in_int3(1)
461+
assert not list_not_in_int3(2)
462+
assert not list_not_in_int3(3)
463+
assert list_not_in_int3(4)
464+
465+
assert list_in_str("foo")
466+
assert list_in_str("bar")
467+
assert list_in_str("baz")
468+
assert not list_in_str("apple")
469+
assert not list_in_str("pie")
470+
assert not list_in_str("\0")
471+
assert not list_in_str("")
472+
473+
assert list_in_mixed(0)
474+
assert list_in_mixed([])
475+
assert list_in_mixed({})
476+
assert list_in_mixed(())
477+
assert list_in_mixed(False)
478+
assert list_in_mixed(0.0)
479+
assert not list_in_mixed([1])
480+
assert not list_in_mixed(object)
481+
assert list_in_mixed(type)
482+
483+
TUP2: Final = ('x', 'y')
484+
TUP1: Final = ('x',)
485+
TUP0: Final = ()
486+
487+
def test_final_tuple_in() -> None:
488+
assert 'x' + str() in TUP2
489+
assert 'y' + str() in TUP2
490+
b: object = 'z' + str() in TUP2
491+
assert not b
492+
493+
assert 'x' + str() in TUP1
494+
b2: object = 'y' in TUP1
495+
assert not b2
496+
497+
b3: object = 'x' in TUP0
498+
assert not b3
499+
500+
def test_final_tuple_not_in() -> None:
501+
assert 'z' + str() not in TUP2
502+
b: object = 'x' + str() not in TUP2
503+
assert not b
504+
b2: object = 'y' + str() not in TUP2
505+
assert not b2
506+
507+
assert 'y' + str() not in TUP1
508+
b3: object = 'x' not in TUP1
509+
assert not b2
510+
511+
assert 'x' not in TUP0
512+
513+
log = []
514+
515+
def f_a() -> str:
516+
log.append('f_a')
517+
return 'a'
518+
519+
def f_a2() -> str:
520+
log.append('f_a2')
521+
return 'a'
522+
523+
def f_b() -> str:
524+
log.append('f_b')
525+
return 'b'
526+
527+
def f_c() -> str:
528+
log.append('f_c')
529+
return 'c'
530+
531+
def test_tuple_in_order_of_evaluation() -> None:
532+
assert f_a() in (f_b(), f_a2())
533+
assert log ==["f_a", "f_b", "f_a2"]
534+
535+
log.clear()
536+
assert f_a() not in (f_b(), f_c())
537+
assert log ==["f_a", "f_b", "f_c"]
538+
539+
log.clear()
540+
assert f_a() in (f_b(), f_a2(), f_c())
541+
assert log ==["f_a", "f_b", "f_a2", "f_c"]
484542

485543
[case testListBuiltFromGenerator]
486544
def test_from_gen() -> None:

mypyc/test-data/run-tuples.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ TUPLE: Final[Tuple[str, ...]] = ('x', 'y')
292292
def test_final_boxed_tuple() -> None:
293293
t = TUPLE
294294
assert t == ('x', 'y')
295+
assert 'x' in TUPLE
296+
assert 'y' in TUPLE
297+
b: object = 'z' in TUPLE
298+
assert not b
299+
assert 'z' not in TUPLE
300+
b2: object = 'x' not in TUPLE
301+
assert not b2
302+
b3: object = 'y' not in TUPLE
303+
assert not b3
295304

296305
def test_add() -> None:
297306
res = (1, 2, 3, 4)

0 commit comments

Comments
 (0)