backend-infra-engineer: Release v0.3.3 snapshot
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "cli/service/resources/command_context.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
@@ -16,7 +16,7 @@ class CommandContextTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// Initialize mock ROM for testing
|
||||
std::vector<uint8_t> test_data(1024, 0); // 1KB of empty data
|
||||
std::vector<uint8_t> test_data(1024, 0); // 1KB of empty data
|
||||
auto status = mock_rom_.SetTestData(test_data);
|
||||
ASSERT_TRUE(status.ok());
|
||||
}
|
||||
@@ -27,9 +27,9 @@ class CommandContextTest : public ::testing::Test {
|
||||
TEST_F(CommandContextTest, LoadsRomFromConfig) {
|
||||
CommandContext::Config config;
|
||||
config.use_mock_rom = true;
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
auto rom_or = context.GetRom();
|
||||
ASSERT_TRUE(rom_or.ok());
|
||||
EXPECT_TRUE(rom_or.value()->is_loaded());
|
||||
@@ -38,9 +38,9 @@ TEST_F(CommandContextTest, LoadsRomFromConfig) {
|
||||
TEST_F(CommandContextTest, UsesExternalRomContext) {
|
||||
CommandContext::Config config;
|
||||
config.external_rom_context = &mock_rom_;
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
auto rom_or = context.GetRom();
|
||||
ASSERT_TRUE(rom_or.ok());
|
||||
EXPECT_EQ(rom_or.value(), &mock_rom_);
|
||||
@@ -49,9 +49,9 @@ TEST_F(CommandContextTest, UsesExternalRomContext) {
|
||||
TEST_F(CommandContextTest, LoadsRomFromPath) {
|
||||
CommandContext::Config config;
|
||||
config.rom_path = "test_rom.sfc"; // This would need a real ROM file
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
// This test would need a real ROM file to pass
|
||||
// For now, we expect it to fail gracefully
|
||||
auto rom_or = context.GetRom();
|
||||
@@ -61,12 +61,12 @@ TEST_F(CommandContextTest, LoadsRomFromPath) {
|
||||
TEST_F(CommandContextTest, EnsuresLabelsLoaded) {
|
||||
CommandContext::Config config;
|
||||
config.use_mock_rom = true;
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
auto rom_or = context.GetRom();
|
||||
ASSERT_TRUE(rom_or.ok());
|
||||
|
||||
|
||||
auto status = context.EnsureLabelsLoaded(rom_or.value());
|
||||
EXPECT_TRUE(status.ok());
|
||||
}
|
||||
@@ -74,18 +74,18 @@ TEST_F(CommandContextTest, EnsuresLabelsLoaded) {
|
||||
TEST_F(CommandContextTest, GetFormatReturnsConfigFormat) {
|
||||
CommandContext::Config config;
|
||||
config.format = "text";
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
EXPECT_EQ(context.GetFormat(), "text");
|
||||
}
|
||||
|
||||
TEST_F(CommandContextTest, IsVerboseReturnsConfigVerbose) {
|
||||
CommandContext::Config config;
|
||||
config.verbose = true;
|
||||
|
||||
|
||||
CommandContext context(config);
|
||||
|
||||
|
||||
EXPECT_TRUE(context.IsVerbose());
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class ArgumentParserTest : public ::testing::Test {
|
||||
TEST_F(ArgumentParserTest, ParsesStringArguments) {
|
||||
std::vector<std::string> args = {"--type=dungeon", "--format", "json"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
EXPECT_EQ(parser.GetString("type").value(), "dungeon");
|
||||
EXPECT_EQ(parser.GetString("format").value(), "json");
|
||||
}
|
||||
@@ -106,11 +106,11 @@ TEST_F(ArgumentParserTest, ParsesStringArguments) {
|
||||
TEST_F(ArgumentParserTest, ParsesIntArguments) {
|
||||
std::vector<std::string> args = {"--room=0x12", "--count", "42"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
auto room_or = parser.GetInt("room");
|
||||
ASSERT_TRUE(room_or.ok());
|
||||
EXPECT_EQ(room_or.value(), 0x12);
|
||||
|
||||
|
||||
auto count_or = parser.GetInt("count");
|
||||
ASSERT_TRUE(count_or.ok());
|
||||
EXPECT_EQ(count_or.value(), 42);
|
||||
@@ -119,11 +119,11 @@ TEST_F(ArgumentParserTest, ParsesIntArguments) {
|
||||
TEST_F(ArgumentParserTest, ParsesHexArguments) {
|
||||
std::vector<std::string> args = {"--address=0x1234", "--value", "0xFF"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
auto addr_or = parser.GetHex("address");
|
||||
ASSERT_TRUE(addr_or.ok());
|
||||
EXPECT_EQ(addr_or.value(), 0x1234);
|
||||
|
||||
|
||||
auto value_or = parser.GetHex("value");
|
||||
ASSERT_TRUE(value_or.ok());
|
||||
EXPECT_EQ(value_or.value(), 0xFF);
|
||||
@@ -132,27 +132,29 @@ TEST_F(ArgumentParserTest, ParsesHexArguments) {
|
||||
TEST_F(ArgumentParserTest, DetectsFlags) {
|
||||
std::vector<std::string> args = {"--verbose", "--debug", "--format=json"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
EXPECT_TRUE(parser.HasFlag("verbose"));
|
||||
EXPECT_TRUE(parser.HasFlag("debug"));
|
||||
EXPECT_FALSE(parser.HasFlag("format")); // format is a value, not a flag
|
||||
}
|
||||
|
||||
TEST_F(ArgumentParserTest, GetsPositionalArguments) {
|
||||
std::vector<std::string> args = {"command", "--flag", "value", "positional1", "positional2"};
|
||||
std::vector<std::string> args = {"command", "--flag", "value", "positional1",
|
||||
"positional2"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
auto positional = parser.GetPositional();
|
||||
EXPECT_THAT(positional, ::testing::ElementsAre("command", "positional1", "positional2"));
|
||||
EXPECT_THAT(positional,
|
||||
::testing::ElementsAre("command", "positional1", "positional2"));
|
||||
}
|
||||
|
||||
TEST_F(ArgumentParserTest, ValidatesRequiredArguments) {
|
||||
std::vector<std::string> args = {"--type=dungeon"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
auto status = parser.RequireArgs({"type"});
|
||||
EXPECT_TRUE(status.ok());
|
||||
|
||||
|
||||
status = parser.RequireArgs({"type", "missing"});
|
||||
EXPECT_FALSE(status.ok());
|
||||
}
|
||||
@@ -160,10 +162,10 @@ TEST_F(ArgumentParserTest, ValidatesRequiredArguments) {
|
||||
TEST_F(ArgumentParserTest, HandlesMissingArguments) {
|
||||
std::vector<std::string> args = {"--type=dungeon"};
|
||||
ArgumentParser parser(args);
|
||||
|
||||
|
||||
auto missing = parser.GetString("missing");
|
||||
EXPECT_FALSE(missing.has_value());
|
||||
|
||||
|
||||
auto int_missing = parser.GetInt("missing");
|
||||
EXPECT_FALSE(int_missing.ok());
|
||||
}
|
||||
@@ -178,11 +180,11 @@ TEST_F(OutputFormatterTest, CreatesFromString) {
|
||||
auto json_formatter = OutputFormatter::FromString("json");
|
||||
ASSERT_TRUE(json_formatter.ok());
|
||||
EXPECT_TRUE(json_formatter.value().IsJson());
|
||||
|
||||
|
||||
auto text_formatter = OutputFormatter::FromString("text");
|
||||
ASSERT_TRUE(text_formatter.ok());
|
||||
EXPECT_TRUE(text_formatter.value().IsText());
|
||||
|
||||
|
||||
auto invalid_formatter = OutputFormatter::FromString("invalid");
|
||||
EXPECT_FALSE(invalid_formatter.ok());
|
||||
}
|
||||
@@ -191,22 +193,22 @@ TEST_F(OutputFormatterTest, GeneratesValidJson) {
|
||||
auto formatter_or = OutputFormatter::FromString("json");
|
||||
ASSERT_TRUE(formatter_or.ok());
|
||||
auto formatter = std::move(formatter_or.value());
|
||||
|
||||
|
||||
formatter.BeginObject("Test");
|
||||
formatter.AddField("string_field", "value");
|
||||
formatter.AddField("int_field", 42);
|
||||
formatter.AddField("bool_field", true);
|
||||
formatter.AddHexField("hex_field", 0x1234, 4);
|
||||
|
||||
|
||||
formatter.BeginArray("array_field");
|
||||
formatter.AddArrayItem("item1");
|
||||
formatter.AddArrayItem("item2");
|
||||
formatter.EndArray();
|
||||
|
||||
|
||||
formatter.EndObject();
|
||||
|
||||
|
||||
std::string output = formatter.GetOutput();
|
||||
|
||||
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\"string_field\": \"value\""));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\"int_field\": 42"));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\"bool_field\": true"));
|
||||
@@ -220,22 +222,22 @@ TEST_F(OutputFormatterTest, GeneratesValidText) {
|
||||
auto formatter_or = OutputFormatter::FromString("text");
|
||||
ASSERT_TRUE(formatter_or.ok());
|
||||
auto formatter = std::move(formatter_or.value());
|
||||
|
||||
|
||||
formatter.BeginObject("Test Object");
|
||||
formatter.AddField("string_field", "value");
|
||||
formatter.AddField("int_field", 42);
|
||||
formatter.AddField("bool_field", true);
|
||||
formatter.AddHexField("hex_field", 0x1234, 4);
|
||||
|
||||
|
||||
formatter.BeginArray("array_field");
|
||||
formatter.AddArrayItem("item1");
|
||||
formatter.AddArrayItem("item2");
|
||||
formatter.EndArray();
|
||||
|
||||
|
||||
formatter.EndObject();
|
||||
|
||||
|
||||
std::string output = formatter.GetOutput();
|
||||
|
||||
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("=== Test Object ==="));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("string_field : value"));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("int_field : 42"));
|
||||
@@ -250,15 +252,15 @@ TEST_F(OutputFormatterTest, EscapesJsonStrings) {
|
||||
auto formatter_or = OutputFormatter::FromString("json");
|
||||
ASSERT_TRUE(formatter_or.ok());
|
||||
auto formatter = std::move(formatter_or.value());
|
||||
|
||||
|
||||
formatter.BeginObject("Test");
|
||||
formatter.AddField("quotes", "He said \"Hello\"");
|
||||
formatter.AddField("newlines", "Line1\nLine2");
|
||||
formatter.AddField("backslashes", "Path\\to\\file");
|
||||
formatter.EndObject();
|
||||
|
||||
|
||||
std::string output = formatter.GetOutput();
|
||||
|
||||
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\\\""));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\\n"));
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\\\\"));
|
||||
@@ -268,10 +270,10 @@ TEST_F(OutputFormatterTest, HandlesEmptyObjects) {
|
||||
auto formatter_or = OutputFormatter::FromString("json");
|
||||
ASSERT_TRUE(formatter_or.ok());
|
||||
auto formatter = std::move(formatter_or.value());
|
||||
|
||||
|
||||
formatter.BeginObject("Empty");
|
||||
formatter.EndObject();
|
||||
|
||||
|
||||
std::string output = formatter.GetOutput();
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("{}"));
|
||||
}
|
||||
@@ -280,12 +282,12 @@ TEST_F(OutputFormatterTest, HandlesEmptyArrays) {
|
||||
auto formatter_or = OutputFormatter::FromString("json");
|
||||
ASSERT_TRUE(formatter_or.ok());
|
||||
auto formatter = std::move(formatter_or.value());
|
||||
|
||||
|
||||
formatter.BeginObject("Test");
|
||||
formatter.BeginArray("empty_array");
|
||||
formatter.EndArray();
|
||||
formatter.EndObject();
|
||||
|
||||
|
||||
std::string output = formatter.GetOutput();
|
||||
EXPECT_THAT(output, ::testing::HasSubstr("\"empty_array\": []"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user