From 12409ee075f97736edcd33f27a5df1de38173ff2 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Fri, 30 Jan 2026 19:43:49 +0100 Subject: [PATCH] Add regression test for #832: script compare with negative number Comparing against negative literals (e.g., "A!=-1") used to throw "operator cannot be mixed with previous operators" because the unary minus prefix was in a conflicting operator group. This was resolved by the #1029 fix (string_concat operand change). This commit adds a regression test covering both direct script evaluation and XML precondition usage. Co-Authored-By: Claude Opus 4.5 --- tests/script_parser_test.cpp | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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"( + + + +