github.com/google/skylark@v0.0.0-20181101142754-a5f7082aabed/testdata/bool.sky (about)

     1  # Tests of Skylark 'bool'
     2  
     3  load("assert.sky", "assert")
     4  
     5  # truth
     6  assert.true(True)
     7  assert.true(not False)
     8  assert.true(not not True)
     9  assert.true(not not 1 >= 1)
    10  
    11  # bool conversion
    12  assert.eq(
    13      [bool(), bool(1), bool(0), bool("hello"), bool("")],
    14      [False, True, False, True, False],
    15  )
    16  
    17  # comparison
    18  assert.true(None == None)
    19  assert.true(None != False)
    20  assert.true(None != True)
    21  assert.eq(1 == 1, True)
    22  assert.eq(1 == 2, False)
    23  assert.true(False == False)
    24  assert.true(True == True)
    25  
    26  # ordered comparison
    27  assert.true(False < True)
    28  assert.true(False <= True)
    29  assert.true(False <= False)
    30  assert.true(True > False)
    31  assert.true(True >= False)
    32  assert.true(True >= True)
    33  
    34  # conditional expression
    35  assert.eq(1 if 3 > 2 else 0, 1)
    36  assert.eq(1 if "foo" else 0, 1)
    37  assert.eq(1 if "" else 0, 0)
    38  
    39  # short-circuit evaluation of 'and' and 'or':
    40  # 'or' yields the first true operand, or the last if all are false.
    41  assert.eq(0 or "" or [] or 0, 0)
    42  assert.eq(0 or "" or [] or 123 or 1 / 0, 123)
    43  assert.fails(lambda : 0 or "" or [] or 0 or 1 / 0, "division by zero")
    44  
    45  # 'and' yields the first false operand, or the last if all are true.
    46  assert.eq(1 and "a" and [1] and 123, 123)
    47  assert.eq(1 and "a" and [1] and 0 and 1 / 0, 0)
    48  assert.fails(lambda : 1 and "a" and [1] and 123 and 1 / 0, "division by zero")