about summary refs log tree commit diff
path: root/absl/flags/flag_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/flags/flag_test.cc')
-rw-r--r--absl/flags/flag_test.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc
index 1e01b49cc4f2..3a0255769527 100644
--- a/absl/flags/flag_test.cc
+++ b/absl/flags/flag_test.cc
@@ -293,6 +293,18 @@ TEST_F(FlagTest, TestFlagDefinition) {
 // --------------------------------------------------------------------
 
 TEST_F(FlagTest, TestDefault) {
+  EXPECT_EQ(FLAGS_test_flag_01.DefaultValue(), "true");
+  EXPECT_EQ(FLAGS_test_flag_02.DefaultValue(), "1234");
+  EXPECT_EQ(FLAGS_test_flag_03.DefaultValue(), "-34");
+  EXPECT_EQ(FLAGS_test_flag_04.DefaultValue(), "189");
+  EXPECT_EQ(FLAGS_test_flag_05.DefaultValue(), "10765");
+  EXPECT_EQ(FLAGS_test_flag_06.DefaultValue(), "40000");
+  EXPECT_EQ(FLAGS_test_flag_07.DefaultValue(), "-1234567");
+  EXPECT_EQ(FLAGS_test_flag_08.DefaultValue(), "9876543");
+  EXPECT_EQ(FLAGS_test_flag_09.DefaultValue(), "-9.876e-50");
+  EXPECT_EQ(FLAGS_test_flag_10.DefaultValue(), "1.234e+12");
+  EXPECT_EQ(FLAGS_test_flag_11.DefaultValue(), "");
+
   EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_01), true);
   EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_02), 1234);
   EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_03), -34);
@@ -308,6 +320,61 @@ TEST_F(FlagTest, TestDefault) {
 
 // --------------------------------------------------------------------
 
+struct NonTriviallyCopyableAggregate {
+  NonTriviallyCopyableAggregate() = default;
+  NonTriviallyCopyableAggregate(const NonTriviallyCopyableAggregate& rhs)
+      : value(rhs.value) {}
+  NonTriviallyCopyableAggregate& operator=(
+      const NonTriviallyCopyableAggregate& rhs) {
+    value = rhs.value;
+    return *this;
+  }
+
+  int value;
+};
+bool AbslParseFlag(absl::string_view src, NonTriviallyCopyableAggregate* f,
+                   std::string* e) {
+  return absl::ParseFlag(src, &f->value, e);
+}
+std::string AbslUnparseFlag(const NonTriviallyCopyableAggregate& ntc) {
+  return absl::StrCat(ntc.value);
+}
+
+bool operator==(const NonTriviallyCopyableAggregate& ntc1,
+                const NonTriviallyCopyableAggregate& ntc2) {
+  return ntc1.value == ntc2.value;
+}
+
+}  // namespace
+
+ABSL_FLAG(bool, test_flag_eb_01, {}, "");
+ABSL_FLAG(int32_t, test_flag_eb_02, {}, "");
+ABSL_FLAG(int64_t, test_flag_eb_03, {}, "");
+ABSL_FLAG(double, test_flag_eb_04, {}, "");
+ABSL_FLAG(std::string, test_flag_eb_05, {}, "");
+ABSL_FLAG(NonTriviallyCopyableAggregate, test_flag_eb_06, {}, "");
+
+namespace {
+
+TEST_F(FlagTest, TestEmptyBracesDefault) {
+  EXPECT_EQ(FLAGS_test_flag_eb_01.DefaultValue(), "false");
+  EXPECT_EQ(FLAGS_test_flag_eb_02.DefaultValue(), "0");
+  EXPECT_EQ(FLAGS_test_flag_eb_03.DefaultValue(), "0");
+  EXPECT_EQ(FLAGS_test_flag_eb_04.DefaultValue(), "0");
+  EXPECT_EQ(FLAGS_test_flag_eb_05.DefaultValue(), "");
+  EXPECT_EQ(FLAGS_test_flag_eb_06.DefaultValue(), "0");
+
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_01), false);
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_02), 0);
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_03), 0);
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_04), 0.0);
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_05), "");
+  EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_eb_06),
+            NonTriviallyCopyableAggregate{});
+}
+
+// --------------------------------------------------------------------
+
 TEST_F(FlagTest, TestGetSet) {
   absl::SetFlag(&FLAGS_test_flag_01, false);
   EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_01), false);