Ejemplo n.º 1
0
def test_use_seq_if_multiple_overloads_equivalence():
    items = [pt.Pop(pt.Int(1)), pt.Int(2)]
    expr = _use_seq_if_multiple(items)

    expected = pt.Seq(items).__teal__(options)
    actual = expr.__teal__(options)

    assert actual == expected
Ejemplo n.º 2
0
def test_use_seq_if_multiple():
    # Test a single expression
    items = [pt.Int(1)]
    expr = _use_seq_if_multiple(*items)

    expected = items[0].__teal__(options)
    actual = expr.__teal__(options)

    assert actual == expected

    # Test multiple expressions
    items = [pt.Pop(pt.Int(1)), pt.Int(2)]
    expr = _use_seq_if_multiple(*items)

    expected = pt.Seq(items).__teal__(options)
    actual = expr.__teal__(options)

    assert actual == expected
Ejemplo n.º 3
0
    def Do(self, doBlock: Expr, *do_block_multi: Expr):
        if self.doBlock is not None:
            raise TealCompileError("While expression already has a doBlock",
                                   self)

        doBlock = _use_seq_if_multiple(doBlock, *do_block_multi)

        require_type(doBlock, TealType.none)
        self.doBlock = doBlock
        return self
Ejemplo n.º 4
0
    def Then(self, thenBranch: Expr, *then_branch_multi: Expr):
        if not self.alternateSyntaxFlag:
            raise TealInputError("Cannot mix two different If syntax styles")

        thenBranch = _use_seq_if_multiple(thenBranch, *then_branch_multi)

        if not self.elseBranch:
            self.thenBranch = thenBranch
        else:
            if not isinstance(self.elseBranch, If):
                raise TealInputError("Else-Then block is malformed")
            self.elseBranch.Then(thenBranch)
        return self
Ejemplo n.º 5
0
    def Else(self, elseBranch: Expr, *else_branch_multi: Expr):
        if not self.alternateSyntaxFlag:
            raise TealInputError("Cannot mix two different If syntax styles")

        if not self.thenBranch:
            raise TealInputError("Must set Then branch before Else branch")

        elseBranch = _use_seq_if_multiple(elseBranch, *else_branch_multi)

        if not self.elseBranch:
            require_type(elseBranch, self.thenBranch.type_of())
            self.elseBranch = elseBranch
        else:
            if not isinstance(self.elseBranch, If):
                raise TealInputError("Else-Else block is malformed")
            self.elseBranch.Else(elseBranch)
        return self