Skip to content

Commit

Permalink
Escape empty strings when printing symbols
Browse files Browse the repository at this point in the history
Otherwise they are not re-readable!

Fixes #484.
  • Loading branch information
garfieldnate committed Sep 25, 2024
1 parent 4a07705 commit 5b7b46a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Core/SoarKernel/src/soar_representation/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, '|');
Expand Down
18 changes: 18 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <s> ^superstate nil) --> (<s> ^one 1 ^two 2.0 ^three 3.0e0 ^foo bar ^|| hi ^|<bar>| bar ^|^baz| baz ^1 one ^|2.0| two)}");
no_agent_assertTrue(agent->GetLastCommandLineResult());
std::string spMessage = agent->ExecuteCommandLine("print foo");
// sp {foo
// (state <s> ^superstate nil)
// -->
// (<s> ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|<bar>| bar
// ^|^baz| baz ^1 one ^|2.0| two)
// }
//
no_agent_assertTrue(spMessage == "sp {foo\n (state <s> ^superstate nil)\n -->\n (<s> ^one 1 ^two 2.000000 ^three 3.000000 ^foo bar ^|| hi ^|<bar>| bar\n ^|^baz| baz ^1 one ^|2.0| two)\n}\n\n");
}

//void MiscTests::testSoarDebugger()
//{
// bool result = agent->SpawnDebugger();
Expand Down
3 changes: 3 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b7b46a

Please sign in to comment.