def test_nested(self): model = get_model('''\ *** Test Cases *** Example IF ${x} IF ${y} K1 ELSE IF ${z} K2 ''', data_only=True) node = model.sections[0].body[0].body[0] expected = If( header=InlineIfHeader([Token(Token.INLINE_IF, 'IF', 3, 4), Token(Token.ARGUMENT, '${x}', 3, 10)]), body=[If( header=InlineIfHeader([Token(Token.INLINE_IF, 'IF', 3, 18), Token(Token.ARGUMENT, '${y}', 3, 24)]), body=[KeywordCall([Token(Token.KEYWORD, 'K1', 3, 32)])], orelse=If( header=ElseHeader([Token(Token.ELSE, 'ELSE', 3, 38)]), body=[If( header=InlineIfHeader([Token(Token.INLINE_IF, 'IF', 3, 46), Token(Token.ARGUMENT, '${z}', 3, 52)]), body=[KeywordCall([Token(Token.KEYWORD, 'K2', 3, 60)])], end=End([Token(Token.END, '', 3, 62)]), )], ), errors=('Inline IF cannot be nested.',), )], errors=('Inline IF cannot be nested.',), ) assert_model(node, expected)
def test_if_else_if_else(self): model = get_model('''\ *** Test Cases *** Example IF True K1 ELSE IF False K2 ELSE K3 ''', data_only=True) node = model.sections[0].body[0].body[0] 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)])) assert_model(node, expected)
def test_nested(self): data = ''' *** Test Cases *** Example IF ${x} IF ${y} K1 ELSE IF ${z} K2 ''' expected = If( header=InlineIfHeader([ Token(Token.INLINE_IF, 'IF', 3, 4), Token(Token.ARGUMENT, '${x}', 3, 10) ]), body=[ If( header=InlineIfHeader([ Token(Token.INLINE_IF, 'IF', 3, 18), Token(Token.ARGUMENT, '${y}', 3, 24) ]), body=[KeywordCall([Token(Token.KEYWORD, 'K1', 3, 32)])], orelse=If( header=ElseHeader([Token(Token.ELSE, 'ELSE', 3, 38)]), body=[ If( header=InlineIfHeader([ Token(Token.INLINE_IF, 'IF', 3, 46), Token(Token.ARGUMENT, '${z}', 3, 52) ]), body=[ KeywordCall( [Token(Token.KEYWORD, 'K2', 3, 60)]) ], end=End([Token(Token.END, '', 3, 62)]), ) ], ), errors=('Inline IF cannot be nested.', ), ) ], errors=('Inline IF cannot be nested.', ), ) get_and_assert_model(data, expected)
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)
def test_if(self): data = ''' *** Test Cases *** Example IF True Keyword ''' expected = If( header=InlineIfHeader([ Token(Token.INLINE_IF, 'IF', 3, 4), Token(Token.ARGUMENT, 'True', 3, 10) ]), body=[KeywordCall([Token(Token.KEYWORD, 'Keyword', 3, 18)])], end=End([Token(Token.END, '', 3, 25)])) get_and_assert_model(data, expected)
def test_if(self): model = get_model('''\ *** Test Cases *** Example IF True Keyword ''', data_only=True) node = model.sections[0].body[0].body[0] expected = If( header=InlineIfHeader([Token(Token.INLINE_IF, 'IF', 3, 4), Token(Token.ARGUMENT, 'True', 3, 10)]), body=[KeywordCall([Token(Token.KEYWORD, 'Keyword', 3, 18)])], end=End([Token(Token.END, '', 3, 25)]) ) assert_model(node, expected)
def test_assign_only_inside(self): data = ''' *** Test Cases *** Example IF ${cond} ${assign} ''' expected = If( header=InlineIfHeader([ Token(Token.INLINE_IF, 'IF', 3, 4), Token(Token.ARGUMENT, '${cond}', 3, 10) ]), body=[KeywordCall([Token(Token.ASSIGN, '${assign}', 3, 21)])], end=End([Token(Token.END, '', 3, 30)]), errors=('Inline IF branches cannot contain assignments.', )) get_and_assert_model(data, expected)
def test_assign(self): data = ''' *** Test Cases *** Example ${x} = IF True K1 ELSE K2 ''' expected = If( header=InlineIfHeader([ Token(Token.ASSIGN, '${x} =', 3, 4), Token(Token.INLINE_IF, 'IF', 3, 14), Token(Token.ARGUMENT, 'True', 3, 20) ]), body=[KeywordCall([Token(Token.KEYWORD, 'K1', 3, 28)])], orelse=If( header=ElseHeader([Token(Token.ELSE, 'ELSE', 3, 34)]), body=[KeywordCall([Token(Token.KEYWORD, 'K2', 3, 42)])], ), end=End([Token(Token.END, '', 3, 44)])) get_and_assert_model(data, expected)
def test_assign(self): model = get_model('''\ *** Test Cases *** Example ${x} = IF True K1 ELSE K2 ''', data_only=True) node = model.sections[0].body[0].body[0] expected = If( header=InlineIfHeader([Token(Token.ASSIGN, '${x} =', 3, 4), Token(Token.INLINE_IF, 'IF', 3, 14), Token(Token.ARGUMENT, 'True', 3, 20)]), body=[KeywordCall([Token(Token.KEYWORD, 'K1', 3, 28)])], orelse=If( header=ElseHeader([Token(Token.ELSE, 'ELSE', 3, 34)]), body=[KeywordCall([Token(Token.KEYWORD, 'K2', 3, 42)])], ), end=End([Token(Token.END, '', 3, 44)]) ) assert_model(node, expected)
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)
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)