Repository: carbon-language/carbon-lang
File: common/string_helpers_test.cpp (C++)

Code before:
}

TEST(BuildCStrArgs, MultipleArgs) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("arg1"));
  EXPECT_THAT(result[2], StrEq("arg2"));
}

TEST(BuildCStrArgsWithPrefix, NoArgs) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {}, {}, storage);
  ASSERT_THAT(result.size(), Eq(1));
  EXPECT_THAT(result[0], StrEq("tool"));
}

TEST(BuildCStrArgsWithPrefix, PrefixOnly) {
  llvm::OwningArrayRef<char> storage;
  std::string prefix_args[] = {"p_arg1", "p_arg2"};
  auto result = BuildCStrArgs("tool", prefix_args, {}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("p_arg1"));
  EXPECT_THAT(result[2], StrEq("p_arg2"));
}

TEST(BuildCStrArgsWithPrefix, ArgsOnly) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {}, {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("arg1"));
  EXPECT_THAT(result[2], StrEq("arg2"));
}

TEST(BuildCStrArgsWithPrefix, BothPrefixAndArgs) {
  llvm::OwningArrayRef<char> storage;
  std::string prefix_args[] = {"p_arg1", "p_arg2"};
  auto result = BuildCStrArgs("tool", prefix_args, {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(5));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("p_arg1"));
  EXPECT_THAT(result[2], StrEq("p_arg2"));
  EXPECT_THAT(result[3], StrEq("arg1"));
  EXPECT_THAT(result[4], StrEq("arg2"));
}

}  // namespace
}  // namespace Carbon

Review comment (suggestion):
Might it make sense to compare the addresses, to validate that they aren't being copied?

```suggestion
  EXPECT_EQ(result[1], prefix_args[0].c_str());
  EXPECT_EQ(result[2], prefix_args[1].c_str());
```

Code after:
}

TEST(BuildCStrArgs, MultipleArgs) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("arg1"));
  EXPECT_THAT(result[2], StrEq("arg2"));
}

TEST(BuildCStrArgsWithPrefix, NoArgs) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {}, {}, storage);
  ASSERT_THAT(result.size(), Eq(1));
  EXPECT_THAT(result[0], StrEq("tool"));
}

TEST(BuildCStrArgsWithPrefix, PrefixOnly) {
  llvm::OwningArrayRef<char> storage;
  std::string prefix_args[] = {"p_arg1", "p_arg2"};
  auto result = BuildCStrArgs("tool", prefix_args, {}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], Eq(prefix_args[0].c_str()));
  EXPECT_THAT(result[2], Eq(prefix_args[1].c_str()));
}

TEST(BuildCStrArgsWithPrefix, ArgsOnly) {
  llvm::OwningArrayRef<char> storage;
  auto result = BuildCStrArgs("tool", {}, {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(3));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], StrEq("arg1"));
  EXPECT_THAT(result[2], StrEq("arg2"));
}

TEST(BuildCStrArgsWithPrefix, BothPrefixAndArgs) {
  llvm::OwningArrayRef<char> storage;
  std::string prefix_args[] = {"p_arg1", "p_arg2"};
  auto result = BuildCStrArgs("tool", prefix_args, {"arg1", "arg2"}, storage);
  ASSERT_THAT(result.size(), Eq(5));
  EXPECT_THAT(result[0], StrEq("tool"));
  EXPECT_THAT(result[1], Eq(prefix_args[0].c_str()));
  EXPECT_THAT(result[2], Eq(prefix_args[1].c_str()));
  EXPECT_THAT(result[3], StrEq("arg1"));
  EXPECT_THAT(result[4], StrEq("arg2"));
}

}  // namespace
}  // namespace Carbon