Skip to content

Commit

Permalink
Make SVS scene names case-insensitive
Browse files Browse the repository at this point in the history
The rest of Soar doesn't care if we refer to a state as s1 or S1, so we
introduce logic that let's us use either one when referring to SVS scenes, e.g.
`svs s1.scene.world` now works as expected.

Fixes #426.
  • Loading branch information
garfieldnate committed Sep 27, 2024
1 parent e58a00a commit 67eb06d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Core/SVS/src/cliproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ void cliproxy::proxy_use(const std::string& path, const std::vector<std::string>
std::map<std::string, cliproxy*> c;

partition(path, child, rest);

if(proxy_uppercase_paths()) {
// uppercase child
std::transform(child.begin(), child.end(), child.begin(), ::toupper);
}

proxy_get_children(c);
if (has(c, child))
{
Expand All @@ -52,6 +58,7 @@ void cliproxy::proxy_use(const std::string& path, const std::vector<std::string>
os << "path not found" << std::endl;
}

// deallocate copy of children
std::map<std::string, cliproxy*>::const_iterator i, iend;
for (i = c.begin(), iend = c.end(); i != iend; ++i)
{
Expand Down
2 changes: 2 additions & 0 deletions Core/SVS/src/cliproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class cliproxy
{
list_children(0, os);
}
// return true if path should be uppercased before looking up children
virtual bool proxy_uppercase_paths() {return false;}

std::string help_text;
std::vector<std::string> args_help;
Expand Down
5 changes: 5 additions & 0 deletions Core/SVS/src/svs.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ class svs : public svs_interface, public cliproxy
void proc_input(svs_state* s);

void proxy_get_children(std::map<std::string, cliproxy*>& c);
// For consistency with the rest of Soar, we allow scene names to be lower or upper case (s1 or S1)
bool proxy_uppercase_paths()
{
return true;
}
void cli_connect_viewer(const std::vector<std::string>& args, std::ostream& os);
void cli_disconnect_viewer(const std::vector<std::string>& args, std::ostream& os);

Expand Down
16 changes: 16 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ void MiscTests::testProductionPrinting()
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::testSvsSceneCaseInsensitivity()
{
agent->ExecuteCommandLine("svs --enable");
no_agent_assertTrue_msg("failed to enable SVS", agent->GetLastCommandLineResult());

std::string result;
result = agent->ExecuteCommandLine("svs S1.scene.world");
no_agent_assertFalse_msg("could not find S1 scene", result == "path not found\n");

result = agent->ExecuteCommandLine("svs s1.scene.world");
no_agent_assertFalse_msg("lower-case s1 scene name not found", result == "path not found\n");

result = agent->ExecuteCommandLine("svs D34.scene.world");
no_agent_assertTrue_msg("D34 scene name found: " + result, result == "path not found\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 @@ -66,6 +66,9 @@ class MiscTests : public FunctionalTestHarness
TEST(testProductionPrinting, -1)
void testProductionPrinting();

TEST(testSvsSceneCaseInsensitivity, -1)
void testSvsSceneCaseInsensitivity();

// 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 67eb06d

Please sign in to comment.