def check(expr: str, truthyness: bool): check_expression(f'not not {expr}', str(truthyness))
def test_booleans(): check_expression('True', 'True') check_expression('False', 'False')
def test_print(): check_expression("'abc'", 'abc')
def test_print_tuples(): # In the end, Python's __str__() is called, just check that we get what # we expected. check_expression('("a", "b")', "('a', 'b')")
def test_equality(): check_expression('type(True) == type(False)', 'True') check_expression('type(()) == type((False, True))', 'True') check_expression('type("foo") == str', 'True') check_expression('type(print) == type("bar")', 'False')
def test_repr(): check_expression('type(True)', 'bool') check_expression('type(())', 'tuple') check_expression('type("foo")', 'str') check_expression('type(print)', 'callable')
def test_equals(): check_expression('True == True', 'True') check_expression('True == False', 'False') check_expression("'foo' == 'foo'", 'True') check_expression("'foo' == 'bar'", 'False') check_expression("((), ('a', 'b')) == ((), ('a', 'b'))", 'True') check_expression("((), ('a', 'b', ())) == ((), ('a', 'b'))", 'False') check_expression('False == ()', 'False') check_expression("'foo' == ('foo',)", 'False')
def test_multiple_ops(): check_expression("'a' == 'a' != 'b'", 'True') check_expression("'a' == 'b' == 'b'", 'False') check_expression("'a' != 'b' != 'a'", 'True')
def test_not_equals(): check_expression('True != False', 'True') check_expression('False != ()', 'True') check_expression('() != ()', 'False')
def test_non_booleans(): check_expression("True and 'a'", 'a') check_expression("False and 'a'", 'False') check_expression("True or 'a'", 'Tr' 'ue') check_expression("False or 'a'", 'a')
def test_chain(): check_expression('True and True and True', 'True') check_expression('True and False and True', 'False')