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_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_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)
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_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_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_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)
def test_if(self): data = ''' *** Test Cases *** Example IF True Keyword Another argument END ''' expected = If(header=IfHeader([ Token(Token.IF, 'IF', 3, 4), Token(Token.ARGUMENT, 'True', 3, 10), ]), body=[ KeywordCall([Token(Token.KEYWORD, 'Keyword', 4, 8)]), KeywordCall([ Token(Token.KEYWORD, 'Another', 5, 8), Token(Token.ARGUMENT, 'argument', 5, 19) ]) ], end=End([Token(Token.END, 'END', 6, 4)])) get_and_assert_model(data, expected)
def test_if(self): model = get_model('''\ *** Test Cases *** Example IF True Keyword Another argument 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, 'Keyword', 4, 8)]), KeywordCall([Token(Token.KEYWORD, 'Another', 5, 8), Token(Token.ARGUMENT, 'argument', 5, 19)]) ], end=End([Token(Token.END, 'END', 6, 4)]) ) assert_model(node, expected)