Beispiel #1
0
    def test_if_else_if_else(self):
        model = get_model('''\
*** Test Cases ***
Example
    IF    True
        K1
    ELSE IF    False
        K2
    ELSE
        K3
    END
    ''',
                          data_only=True)
        node = model.sections[0].body[0].body[0]
        expected = If(
            header=IfHeader([
                Token(Token.IF, 'IF', 3, 4),
                Token(Token.ARGUMENT, 'True', 3, 10),
            ]),
            body=[KeywordCall([Token(Token.KEYWORD, 'K1', 4, 8)])],
            orelse=If(
                header=ElseIfHeader([
                    Token(Token.ELSE_IF, 'ELSE IF', 5, 4),
                    Token(Token.ARGUMENT, 'False', 5, 15),
                ]),
                body=[KeywordCall([Token(Token.KEYWORD, 'K2', 6, 8)])],
                orelse=If(
                    header=ElseHeader([
                        Token(Token.ELSE, 'ELSE', 7, 4),
                    ]),
                    body=[KeywordCall([Token(Token.KEYWORD, 'K3', 8, 8)])],
                )),
            end=End([Token(Token.END, 'END', 9, 4)]))
        assert_model(node, expected)
Beispiel #2
0
    def test_invalid(self):
        model = get_model('''\
*** Test Cases ***
Example
    IF    too    many
    ELSE    ooops
    ELSE IF
''',
                          data_only=True)
        node = model.sections[0].body[0].body[0]
        expected = If(
            header=IfHeader([
                Token(Token.IF, 'IF', 3, 4),
                Token(Token.ARGUMENT, 'too', 3, 10),
                Token(Token.ARGUMENT, 'many', 3, 17),
            ]),
            orelse=If(header=ElseHeader([
                Token(Token.ELSE, 'ELSE', 4, 4),
                Token(Token.ARGUMENT, 'ooops', 4, 12)
            ]),
                      orelse=If(header=ElseIfHeader(
                          [Token(Token.ELSE_IF, 'ELSE IF', 5, 4)]),
                                errors=[
                                    'ELSE IF has no condition.',
                                    'ELSE IF has empty body.'
                                ]),
                      errors=['ELSE has condition.', 'ELSE has empty body.']),
            errors=[
                'IF has more than one condition.', 'IF has empty body.',
                'ELSE IF after ELSE.', 'IF has no closing END.'
            ])
        assert_model(node, expected)
Beispiel #3
0
    def test_if_else_if_else(self):
        data = '''
*** Test Cases ***
Example
    IF    True
        K1
    ELSE IF    False
        K2
    ELSE
        K3
    END
    '''
        expected = If(
            header=IfHeader([
                Token(Token.IF, 'IF', 3, 4),
                Token(Token.ARGUMENT, 'True', 3, 10),
            ]),
            body=[KeywordCall([Token(Token.KEYWORD, 'K1', 4, 8)])],
            orelse=If(
                header=ElseIfHeader([
                    Token(Token.ELSE_IF, 'ELSE IF', 5, 4),
                    Token(Token.ARGUMENT, 'False', 5, 15),
                ]),
                body=[KeywordCall([Token(Token.KEYWORD, 'K2', 6, 8)])],
                orelse=If(
                    header=ElseHeader([
                        Token(Token.ELSE, 'ELSE', 7, 4),
                    ]),
                    body=[KeywordCall([Token(Token.KEYWORD, 'K3', 8, 8)])],
                )),
            end=End([Token(Token.END, 'END', 9, 4)]))
        get_and_assert_model(data, expected)
    def test_invalid(self):
        model = get_model('''\
*** Test Cases ***
Example
    IF    too    many
    ELSE    ooops
    ELSE IF
    END    ooops

    IF
''', data_only=True)
        if1, if2 = model.sections[0].body[0].body
        expected1 = If(
            header=IfHeader(
                tokens=[Token(Token.IF, 'IF', 3, 4),
                        Token(Token.ARGUMENT, 'too', 3, 10),
                        Token(Token.ARGUMENT, 'many', 3, 17)],
                errors=('IF has more than one condition.',)
            ),
            orelse=If(
                header=ElseHeader(
                    tokens=[Token(Token.ELSE, 'ELSE', 4, 4),
                            Token(Token.ARGUMENT, 'ooops', 4, 12)],
                    errors=('ELSE has condition.',)
                ),
                orelse=If(
                    header=ElseIfHeader(
                        tokens=[Token(Token.ELSE_IF, 'ELSE IF', 5, 4)],
                        errors=('ELSE IF has no condition.',)
                    ),
                    errors=('ELSE IF has empty body.',)
                ),
                errors=('ELSE has empty body.',)
            ),
            end=End(
                tokens=[Token(Token.END, 'END', 6, 4),
                        Token(Token.ARGUMENT, 'ooops', 6, 11)],
                errors=('END does not accept arguments.',)
            ),
            errors=('IF has empty body.',
                    'ELSE IF after ELSE.')
        )
        expected2 = If(
            header=IfHeader(
                tokens=[Token(Token.IF, 'IF', 8, 4)],
                errors=('IF has no condition.',)
            ),
            errors=('IF has empty body.',
                    'IF has no closing END.')
        )
        assert_model(if1, expected1)
        assert_model(if2, expected2)
Beispiel #5
0
    def test_invalid(self):
        data1 = '''
*** Test Cases ***
Example
    IF
    ELSE    ooops
        # Empty
    ELSE IF

    END    ooops
'''
        data2 = '''
*** Test Cases ***
Example
    IF
'''
        expected1 = If(
            header=IfHeader(tokens=[Token(Token.IF, 'IF', 3, 4)],
                            errors=('IF must have a condition.', )),
            orelse=If(header=ElseHeader(
                tokens=[
                    Token(Token.ELSE, 'ELSE', 4, 4),
                    Token(Token.ARGUMENT, 'ooops', 4, 12)
                ],
                errors=("ELSE does not accept arguments, got 'ooops'.", )),
                      orelse=If(header=ElseIfHeader(
                          tokens=[Token(Token.ELSE_IF, 'ELSE IF', 6, 4)],
                          errors=('ELSE IF must have a condition.', )),
                                errors=('ELSE IF branch cannot be empty.', )),
                      errors=('ELSE branch cannot be empty.', )),
            end=End(tokens=[
                Token(Token.END, 'END', 8, 4),
                Token(Token.ARGUMENT, 'ooops', 8, 11)
            ],
                    errors=("END does not accept arguments, got 'ooops'.", )),
            errors=('IF branch cannot be empty.',
                    'ELSE IF not allowed after ELSE.'))
        expected2 = If(header=IfHeader(tokens=[Token(Token.IF, 'IF', 3, 4)],
                                       errors=('IF must have a condition.', )),
                       errors=('IF branch cannot be empty.',
                               'IF must have closing END.'))
        get_and_assert_model(data1, expected1)
        get_and_assert_model(data2, expected2)
Beispiel #6
0
    def test_invalid(self):
        model = get_model('''\
*** Test Cases ***
Example
    ${x} =    ${y}    IF    ELSE    ooops    ELSE IF
''', data_only=True)
        node = model.sections[0].body[0].body[0]
        expected = If(
            header=InlineIfHeader([Token(Token.ASSIGN, '${x} =', 3, 4),
                                   Token(Token.ASSIGN, '${y}', 3, 14),
                                   Token(Token.INLINE_IF, 'IF', 3, 22),
                                   Token(Token.ARGUMENT, 'ELSE', 3, 28)]),
            body=[KeywordCall([Token(Token.KEYWORD, 'ooops', 3, 36)])],
            orelse=If(
                header=ElseIfHeader([Token(Token.ELSE_IF, 'ELSE IF', 3, 45)],
                                    errors=('ELSE IF must have a condition.',)),
                errors=('ELSE IF branch cannot be empty.',),
            ),
            end=End([Token(Token.END, '', 3, 52)])
        )
        assert_model(node, expected)
Beispiel #7
0
    def test_invalid(self):
        data1 = '''
*** Test Cases ***
Example
    ${x} =    ${y}    IF    ELSE    ooops    ELSE IF
'''
        data2 = '''
*** Test Cases ***
Example
    IF    e    K    ELSE
'''
        expected1 = If(
            header=InlineIfHeader([
                Token(Token.ASSIGN, '${x} =', 3, 4),
                Token(Token.ASSIGN, '${y}', 3, 14),
                Token(Token.INLINE_IF, 'IF', 3, 22),
                Token(Token.ARGUMENT, 'ELSE', 3, 28)
            ]),
            body=[KeywordCall([Token(Token.KEYWORD, 'ooops', 3, 36)])],
            orelse=If(
                header=ElseIfHeader(
                    [Token(Token.ELSE_IF, 'ELSE IF', 3, 45)],
                    errors=('ELSE IF must have a condition.', )),
                errors=('ELSE IF branch cannot be empty.', ),
            ),
            end=End([Token(Token.END, '', 3, 52)]))
        expected2 = If(header=InlineIfHeader([
            Token(Token.INLINE_IF, 'IF', 3, 4),
            Token(Token.ARGUMENT, 'e', 3, 10)
        ]),
                       body=[KeywordCall([Token(Token.KEYWORD, 'K', 3, 15)])],
                       orelse=If(
                           header=ElseHeader(
                               [Token(Token.ELSE, 'ELSE', 3, 20)]),
                           errors=('ELSE branch cannot be empty.', ),
                       ),
                       end=End([Token(Token.END, '', 3, 24)]))
        get_and_assert_model(data1, expected1)
        get_and_assert_model(data2, expected2)
Beispiel #8
0
    def test_invalid(self):
        model = get_model('''\
*** Test Cases ***
Example
    IF
    ELSE    ooops
    ELSE IF
    END    ooops

    IF
''',
                          data_only=True)
        if1, if2 = model.sections[0].body[0].body
        expected1 = If(
            header=IfHeader(tokens=[Token(Token.IF, 'IF', 3, 4)],
                            errors=('IF must have a condition.', )),
            orelse=If(header=ElseHeader(
                tokens=[
                    Token(Token.ELSE, 'ELSE', 4, 4),
                    Token(Token.ARGUMENT, 'ooops', 4, 12)
                ],
                errors=("ELSE does not accept arguments, got 'ooops'.", )),
                      orelse=If(header=ElseIfHeader(
                          tokens=[Token(Token.ELSE_IF, 'ELSE IF', 5, 4)],
                          errors=('ELSE IF must have a condition.', )),
                                errors=('ELSE IF branch cannot be empty.', )),
                      errors=('ELSE branch cannot be empty.', )),
            end=End(tokens=[
                Token(Token.END, 'END', 6, 4),
                Token(Token.ARGUMENT, 'ooops', 6, 11)
            ],
                    errors=("END does not accept arguments, got 'ooops'.", )),
            errors=('IF branch cannot be empty.', 'ELSE IF after ELSE.'))
        expected2 = If(header=IfHeader(tokens=[Token(Token.IF, 'IF', 8, 4)],
                                       errors=('IF must have a condition.', )),
                       errors=('IF branch cannot be empty.',
                               'IF has no closing END.'))
        assert_model(if1, expected1)
        assert_model(if2, expected2)
Beispiel #9
0
    def test_if_else_if_else(self):
        data = '''
*** Test Cases ***
Example
    IF    True    K1    ELSE IF    False    K2    ELSE    K3
'''
        expected = If(
            header=InlineIfHeader([
                Token(Token.INLINE_IF, 'IF', 3, 4),
                Token(Token.ARGUMENT, 'True', 3, 10)
            ]),
            body=[KeywordCall([Token(Token.KEYWORD, 'K1', 3, 18)])],
            orelse=If(
                header=ElseIfHeader([
                    Token(Token.ELSE_IF, 'ELSE IF', 3, 24),
                    Token(Token.ARGUMENT, 'False', 3, 35)
                ]),
                body=[KeywordCall([Token(Token.KEYWORD, 'K2', 3, 44)])],
                orelse=If(
                    header=ElseHeader([Token(Token.ELSE, 'ELSE', 3, 50)]),
                    body=[KeywordCall([Token(Token.KEYWORD, 'K3', 3, 58)])],
                )),
            end=End([Token(Token.END, '', 3, 60)]))
        get_and_assert_model(data, expected)