Skip to content
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

使用 "=" 在执行策略的时候 会抛出 com.ql.util.express.exception.QLException: run QlExpress Exception at line 1 :指令错误:2 不是Boolean 异常, 但是使用"=="不会 #370

Open
HYKINGDOM opened this issue Jan 15, 2025 · 1 comment

Comments

@HYKINGDOM
Copy link

version
<dependency> <groupId>com.alibaba</groupId> <artifactId>QLExpress</artifactId> <version>3.3.4</version> </dependency>

test code
`
@test
public void contextLoads_01() throws Exception {

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("a", 1);
    context.put("b", 2);
    context.put("c", 3);
    String express = "a + b * c + a";
    Object r = runner.execute(express, context, null, true, false);
    assertEquals("8", r.toString(), r.toString());
}

@Test
public void contextLoads_03() throws Exception {

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("b", 2);
    context.put("c", 3);
    context.put("a", 5);
    String express = "(a == 1) || ( b = 2) && ( c = 3 ) ";
    // 会抛出异常 com.ql.util.express.exception.QLException: run QlExpress Exception at line 1 :指令错误:2 不是Boolean
    Object r = runner.execute(express, context, null, true, false);
    assertEquals("true", r.toString(), r.toString());
}

@Test
public void contextLoads_04() throws Exception {

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("a", 1);
    context.put("b", 2);
    context.put("c", 3);
    String express = "(a == 1) || ( b = 2) && ( c = 3 ) ";
    //执行正常
    Object r = runner.execute(express, context, null, true, false);
    assertEquals("true", r.toString(), r.toString());
}

@Test
public void contextLoads_04_01() throws Exception {

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("a", 1);
    context.put("b", 2);
    context.put("c", 3);
    String express = "(a == 1) || ( b == 2) && ( c == 3 ) ";
    //执行正常
    Object r = runner.execute(express, context, null, true, false);
    assertEquals("true", r.toString(), r.toString());
}

@Test
public void contextLoads_05() throws Exception {

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("a", 1);
    context.put("b", 2);
    context.put("c", 3);
    String express = "(a == 5) || ( b = 2) && ( c = 3 ) ";
    //执行异常 com.ql.util.express.exception.QLException: run QlExpress Exception at line 1 :指令错误:2 不是Boolean
    Object r = runner.execute(express, context, null, true, false);
    assertEquals("true", r.toString(), r.toString());
}

`

@DQinYuan
Copy link
Collaborator

= 是赋值,会返回被赋予的值。 == 才是判断相等

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants