-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(express): 支持一元正负号运算符 #355
base: master
Are you sure you want to change the base?
Conversation
在 `OperatorFactory` 和 `OperatorInstructionFactory` 中增加了对一元正负号运算符的支持,并添加了相应的单元测试。同时更新了 `KeyWordDefine4Java` 以识别新的运算符。 - 新增 `OperatorUnaryPlus` 和 `OperatorUnaryMinus` 类 - 更新 `KeyWordDefine4Java` 以支持一元正负号运算符 - 添加 `Issue345NegativeNumberTest` 单元测试
@@ -18,6 +19,28 @@ public boolean createInstruction(ExpressRunner expressRunner, InstructionSet res | |||
Stack<ForRelBreakContinue> forStack, ExpressNode node, boolean isRoot) throws Exception { | |||
boolean returnVal = false; | |||
ExpressNode[] children = node.getChildrenArray(); | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释代码删除
if (list[0] instanceof Number) { | ||
return list[0]; | ||
} | ||
throw new Exception("Cannot apply unary plus to non-number type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抛 QLException
String express = "-b"; | ||
Object result = runner.execute(express, context, null, true, true); | ||
//Assert.assertTrue((Boolean)result); | ||
Assert.assertEquals(new BigDecimal("-12.22"), result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单元测试建议将所有的数字类型都进行一遍测试
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -97,7 +97,7 @@ public class KeyWordDefine4Java { | |||
"ARRAY_CALL_POST:TYPE=EXPRESS,DEFINE=(METHOD_CALL|FIELD_CALL)$([->ARRAY_CALL^$EXPRESS$]~)^*", | |||
|
|||
"CAST_CALL:TYPE=EXPRESS,DEFINE=(LEFT_BRACKET~$CONST_CLASS$RIGHT_BRACKET~#cast)^*$((LAMBDA#LAMBDA)|ARRAY_CALL)", | |||
"EXPRESS_OP_L1:TYPE=EXPRESS,DEFINE=OP_LEVEL1^*$CAST_CALL", | |||
"EXPRESS_OP_L1:TYPE=EXPRESS,DEFINE=(OP_LEVEL1^$CAST_CALL)^*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要从左边改成右边?如果使用原来的就能能通过大多数测试(和 addOperatorWithLevelOfReference
相关的依旧过不了,因为还有其他代码需要修改)
在
OperatorFactory
和OperatorInstructionFactory
中增加了对一元正负号运算符的支持,并添加了相应的单元测试。同时更新了KeyWordDefine4Java
以识别新的运算符。OperatorUnaryPlus
和OperatorUnaryMinus
类KeyWordDefine4Java
以支持一元正负号运算符Issue345NegativeNumberTest
单元测试