diff --git a/tests/script_parser_test.cpp b/tests/script_parser_test.cpp index ee120fc14..ee8a545d9 100644 --- a/tests/script_parser_test.cpp +++ b/tests/script_parser_test.cpp @@ -483,6 +483,44 @@ TEST(ParserTest, ValidateScriptLargeError_Issue923) auto result = BT::ValidateScript(script); EXPECT_FALSE(result); // invalid script, but no crash } + +// https://github.com/BehaviorTree/BehaviorTree.CPP/issues/832 +TEST(ParserTest, CompareWithNegativeNumber_Issue832) +{ + BT::Ast::Environment environment = { BT::Blackboard::create(), {} }; + + auto GetResult = [&environment](const char* text) -> BT::Any { + return GetScriptResult(environment, text); + }; + + // "A != -1" should parse and evaluate correctly + EXPECT_EQ(GetResult("A:=0; A!=-1").cast(), 1); // 0 != -1 is true + EXPECT_EQ(GetResult("A:=-1; A!=-1").cast(), 0); // -1 != -1 is false + EXPECT_EQ(GetResult("A:=0; A==-1").cast(), 0); // 0 == -1 is false + EXPECT_EQ(GetResult("A:=0; A>-1").cast(), 1); // 0 > -1 is true + EXPECT_EQ(GetResult("A:=0; A<-1").cast(), 0); // 0 < -1 is false + + // Also test that ValidateScript accepts these expressions + EXPECT_TRUE(BT::ValidateScript("A:=0; A!=-1")); + EXPECT_TRUE(BT::ValidateScript("A:=0; A>-1")); + + // Reproducer from the issue: precondition with negative literal + BT::BehaviorTreeFactory factory; + const std::string xml_text = R"( + + + +