Add define parameters and support aliases and definitions in action files
This commit is contained in:
1 parent
fb8ef636bd
commit
0a6193f68e
12 files changed
+291
-63
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "ActionFile.h"
|
||||
#include "ConsoleCommand.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
@@ -112,6 +113,44 @@ class ActionFileTest : public ::testing::Test
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ActionFileTest, ExpandsBindingsInSourceOrderAcrossImports)
|
||||
{
|
||||
Write("child.act", "# action: child\nhome\ndefine pos1 20 64 -8\nalias pause wait 1 s\n");
|
||||
const auto program = Parse("# action: root\ndefine pos1 1 1 1\nalias home goto $pos1\n"
|
||||
"define file child\nalias include import\ninclude $file\nhome\npause\n");
|
||||
ASSERT_EQ(program.commands.size(), 3u);
|
||||
const auto &first = program.commands[0];
|
||||
EXPECT_EQ(first.kind, ActionKind::Goto);
|
||||
EXPECT_EQ(first.x, 1);
|
||||
EXPECT_EQ(first.source.filename(), "child.act");
|
||||
EXPECT_EQ(first.line, 2u);
|
||||
EXPECT_EQ(program.commands[1].x, 20);
|
||||
EXPECT_EQ(program.commands[1].y, 64);
|
||||
EXPECT_EQ(program.commands[1].z, -8);
|
||||
EXPECT_EQ(program.commands[2].waitDuration, std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
TEST_F(ActionFileTest, RunInheritsConsoleBindingsAndKeepsOverridesLocal)
|
||||
{
|
||||
Bilicraft::ConsoleCommandParser console;
|
||||
console.Parse("define slot 1");
|
||||
console.Parse("alias pick sw $slot");
|
||||
const auto path = Write("test.act", "# action: test\npick\ndefine slot 3\npick\n");
|
||||
const auto program = LoadActionFile(path, console.GetBindings());
|
||||
ASSERT_EQ(program.commands.size(), 2u);
|
||||
EXPECT_EQ(program.commands[0].slot, 1);
|
||||
EXPECT_EQ(program.commands[1].slot, 3);
|
||||
EXPECT_EQ(console.Parse("pick").action->slot, 1);
|
||||
EXPECT_THROW(LoadActionFile(path), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_F(ActionFileTest, ReportsBindingErrorsAtTheSourceLine)
|
||||
{
|
||||
Reject("# action: test\ngoto $missing\n", "undefined parameter: $missing");
|
||||
Reject("# action: test\nalias a b\nalias b a\na\n", "alias cycle", 4);
|
||||
Reject("# action: test\ndefine name\n", "requires a name and value");
|
||||
}
|
||||
|
||||
TEST_F(ActionFileTest, ParsesEveryInstructionAndStoresSourceLocations)
|
||||
{
|
||||
const auto program = Parse("# action: farming\n"
|
||||
|
||||
Reference in new issue
Block a user