mtrubs / intellibot

IntelliJ/PyCharm plugin for Robot Automation Framework
https://github.com/millennialmedia/intellibot/wiki
MIT License
158 stars 109 forks source link

Add proofing for math operations inside variables' curly braces #142

Open jimni opened 8 years ago

jimni commented 8 years ago

I am using Pycharm CE + plugin v.0.6.7.

I would like the proofing tool to correctly parse mathematical operations inside curly braces of a variable, e.g.:

*** Variables ***
${var_1}    23

*** Test Cases ***
Plugin Test
    [Tags]  run
    ${var_1}=  Convert To Integer  ${var_1}
    ${var_2}=  Set Variable  ${var_1 + 1}
    ${var_3}=  Convert To String  ${var_1 + 1}

Now results in:

2016-01-09 00 03 57
mtrubs commented 8 years ago

I can see this growing quickly beyond my knowledge.

${var1 + 1}, sure as you point out ${1 + var1} ? ${var1 + var2} ?

Is there a general rule? or everything inside the ${} split by spaces is fair game at some kind of declaration?

jimni commented 8 years ago

Here goes the documentation for this case: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extended-variable-syntax

If it was up to me I would use something like

/keyword([ ]?(\+|\-|\*|\/)[ ]?(([\d]+\.?[\d]*)|(\.[\d]+))[ ]?)*/

Elucidation being here.

I have to mention, that strings with .method() work fine already: ${var_3}= Convert To String ${var_1.__abs__()} I reckon plugin thinks its a case of extended assignment (next chapter in the same doc). I can't think of when this might be a bad thing, but I'm not that good with RF either.

Here are also some examples of appropriate syntax:

${var_2}=  Set Variable  ${var_1 +.1}
${var_2}=  Set Variable  ${var_1 +1.}
${var_2}=  Set Variable  ${var_1 +1.1}
${var_2}=  Set Variable  ${var_1+1}
${var_2}=  Set Variable  ${var_1 + 1}
${var_2}=  Set Variable  ${var_1 + 1 }  # trailing space
${var_2}=  Set Variable  ${var_1 + 1 - 1 / 1 * 1}
${var_2}=  Set Variable  ${var_1.method()}
${var_2}=  Set Variable  ${var_1.method() }  # trailing space
${var_2}=  Set Variable  ${var_1.method() + 1}
${var_2}=  Set Variable  ${var_1.method(arg1, arg2)}
${var_2}=  Set Variable  ${var_1.method1().method2()}

And some bad uses (will cause error):

${var_2}=  Set Variable  ${var_1 +.}
${var_2}=  Set Variable  ${var_1 +}
${var_2}=  Set Variable  ${var_1 + }  # trailing space
${var_2}=  Set Variable  ${var_1 + var_3}
${var_2}=  Set Variable  ${1 + var_1}
${var_2}=  Set Variable  ${method(var_1)}

There is also a case of immediate trailing space after var, which will not cause any error: ${var_2}= Set Variable ${var_1 } # trailing space but I don't this it's worth adding to the plugin due to its utter uselessness.