From 5b7b46af4d38d049ea58e7e2c54f697ef72fe7c2 Mon Sep 17 00:00:00 2001 From: Nathan Glenn Date: Wed, 25 Sep 2024 17:16:01 -0500 Subject: [PATCH] Escape empty strings when printing symbols Otherwise they are not re-readable! Fixes #484. --- .../src/soar_representation/symbol.cpp | 2 +- UnitTests/SoarUnitTests/MiscTests.cpp | 18 ++++++++++++++++++ UnitTests/SoarUnitTests/MiscTests.hpp | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Core/SoarKernel/src/soar_representation/symbol.cpp b/Core/SoarKernel/src/soar_representation/symbol.cpp index 2fc5686f3c..9c9558f167 100644 --- a/Core/SoarKernel/src/soar_representation/symbol.cpp +++ b/Core/SoarKernel/src/soar_representation/symbol.cpp @@ -90,7 +90,7 @@ bool make_string_rereadable(std::string &pStr) // bool has_angle_bracket = pCStr[0] == '<' || pCStr[pLength - 1] == '>'; - if ((!possible_sc) || possible_var || possible_ic || possible_fc || possible_id || (!is_rereadable)) + if ((!possible_sc) || possible_var || possible_ic || possible_fc || possible_id || (!is_rereadable) || (!pLength) ) { /* BUGBUG - if in context where id's could occur, should check possible_id flag here also */ pStr = string_to_escaped_string(pCStr, '|'); diff --git a/UnitTests/SoarUnitTests/MiscTests.cpp b/UnitTests/SoarUnitTests/MiscTests.cpp index 1a2ea188d6..12617af934 100644 --- a/UnitTests/SoarUnitTests/MiscTests.cpp +++ b/UnitTests/SoarUnitTests/MiscTests.cpp @@ -369,6 +369,24 @@ void MiscTests::testStopPhaseRetrieval() assertTrue(response.GetArgInt(sml::sml_Names::kParamPhase, -1) == sml::smlPhase::sml_APPLY_PHASE); } + + +void MiscTests::testProductionPrinting() +{ + // Tries to fully exercise Symbol::to_string + agent->ExecuteCommandLine("sp {foo (state ^superstate nil) --> ( ^one 1 ^two 2.0 ^three 3.0e0 ^foo bar ^|| hi ^|| bar ^|^baz| baz ^1 one ^|2.0| two)}"); + no_agent_assertTrue(agent->GetLastCommandLineResult()); + std::string spMessage = agent->ExecuteCommandLine("print foo"); +// sp {foo +// (state ^superstate nil) +// --> +// ( ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|| bar +// ^|^baz| baz ^1 one ^|2.0| two) +// } +// + no_agent_assertTrue(spMessage == "sp {foo\n (state ^superstate nil)\n -->\n ( ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|| bar\n ^|^baz| baz ^1 one ^|2.0| two)\n}\n\n"); +} + //void MiscTests::testSoarDebugger() //{ // bool result = agent->SpawnDebugger(); diff --git a/UnitTests/SoarUnitTests/MiscTests.hpp b/UnitTests/SoarUnitTests/MiscTests.hpp index 12770cc4fe..de4bea32c0 100644 --- a/UnitTests/SoarUnitTests/MiscTests.hpp +++ b/UnitTests/SoarUnitTests/MiscTests.hpp @@ -63,6 +63,9 @@ class MiscTests : public FunctionalTestHarness void testNegated_Operator_Crash(); void testOp_Augmentation_Crash(); + TEST(testProductionPrinting, -1) + void testProductionPrinting(); + // If you would like to test the Soar Debugger Spawning, uncomment below. // It may or may not work but should unless you're running without a GUI. // TEST(testSoarDebugger, -1)