@@ -83,6 +83,118 @@ TEST_CASE("construct")
83
83
REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::Flush);
84
84
REQUIRE_EQ (macro_metadata.has_named_args (), false );
85
85
}
86
+
87
+ // Test block for a case with no named arguments (escaped braces only)
88
+ {
89
+ constexpr MacroMetadata macro_metadata{
90
+ " src/NoNamed.cpp:100" , // source_location
91
+ " NoNamedFunc" , // caller_function
92
+ " Test with no named args {{value}}" , // message_format (escaped, so no named arg)
93
+ " unit_test_tag" , // tags
94
+ quill::LogLevel::Debug, // log_level
95
+ MacroMetadata::Event::Log // event
96
+ };
97
+
98
+ REQUIRE_STREQ (macro_metadata.message_format (), " Test with no named args {{value}}" );
99
+ REQUIRE_EQ (macro_metadata.log_level (), quill::LogLevel::Debug);
100
+ REQUIRE_STREQ (macro_metadata.line (), " 100" );
101
+ REQUIRE_EQ (macro_metadata.full_path (), std::string_view{" src/NoNamed.cpp" });
102
+ REQUIRE_EQ (macro_metadata.file_name (), std::string_view{" NoNamed.cpp" });
103
+ REQUIRE_STREQ (macro_metadata.short_source_location (), " NoNamed.cpp:100" );
104
+ REQUIRE_STREQ (macro_metadata.caller_function (), " NoNamedFunc" );
105
+ REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::Log);
106
+ REQUIRE_EQ (macro_metadata.has_named_args (), false );
107
+ }
108
+
109
+ // Test block for a case with multiple named arguments
110
+ {
111
+ constexpr MacroMetadata macro_metadata{
112
+ " MacroMetadataTest.cpp:51" , // source_location
113
+ " DOCTEST_ANON_FUNC_3" , // caller_function
114
+ " Test another fmt {name} and {surname} and {{age}}" , // message_format with named args {name} and {surname}
115
+ nullptr , // tags
116
+ quill::LogLevel::Info, // log_level
117
+ MacroMetadata::Event::Flush // event
118
+ };
119
+
120
+ REQUIRE_STREQ (macro_metadata.message_format (),
121
+ " Test another fmt {name} and {surname} and {{age}}" );
122
+ REQUIRE_EQ (macro_metadata.log_level (), quill::LogLevel::Info);
123
+ REQUIRE_STREQ (macro_metadata.line (), " 51" );
124
+ REQUIRE_EQ (macro_metadata.full_path (), std::string_view{" MacroMetadataTest.cpp" });
125
+ REQUIRE_EQ (macro_metadata.file_name (), std::string_view{" MacroMetadataTest.cpp" });
126
+ REQUIRE_STREQ (macro_metadata.short_source_location (), " MacroMetadataTest.cpp:51" );
127
+ REQUIRE_STREQ (macro_metadata.caller_function (), " DOCTEST_ANON_FUNC_3" );
128
+ REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::Flush);
129
+ REQUIRE_EQ (macro_metadata.has_named_args (), true );
130
+ }
131
+
132
+ // Test block for a case with empty braces (which should not count as named args)
133
+ {
134
+ constexpr MacroMetadata macro_metadata{
135
+ " folder/EmptyBraces.cpp:77" , // source_location
136
+ " EmptyArgsFunc" , // caller_function
137
+ " Curly braces with no name: {} and also {{}}" , // message_format with empty {}
138
+ " tag_empty" , // tags
139
+ quill::LogLevel::Warning, // log_level
140
+ MacroMetadata::Event::FlushBacktrace // event
141
+ };
142
+
143
+ REQUIRE_STREQ (macro_metadata.message_format (), " Curly braces with no name: {} and also {{}}" );
144
+ REQUIRE_EQ (macro_metadata.log_level (), quill::LogLevel::Warning);
145
+ REQUIRE_STREQ (macro_metadata.line (), " 77" );
146
+ REQUIRE_EQ (macro_metadata.full_path (), std::string_view{" folder/EmptyBraces.cpp" });
147
+ REQUIRE_EQ (macro_metadata.file_name (), std::string_view{" EmptyBraces.cpp" });
148
+ REQUIRE_STREQ (macro_metadata.short_source_location (), " EmptyBraces.cpp:77" );
149
+ REQUIRE_STREQ (macro_metadata.caller_function (), " EmptyArgsFunc" );
150
+ REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::FlushBacktrace);
151
+ // Since {} does not contain a valid letter and {{}} is escaped, no named arg should be detected.
152
+ REQUIRE_EQ (macro_metadata.has_named_args (), false );
153
+ }
154
+
155
+ // Test block for a case with a single valid named argument
156
+ {
157
+ constexpr MacroMetadata macro_metadata{
158
+ " lib/SingleArg.cpp:300" , // source_location
159
+ " SingleArgFunc" , // caller_function
160
+ " Value is {x}" , // message_format with a single named argument {x}
161
+ " tag_single" , // tags
162
+ quill::LogLevel::Error, // log_level
163
+ MacroMetadata::Event::LogWithRuntimeMetadata // event
164
+ };
165
+
166
+ REQUIRE_STREQ (macro_metadata.message_format (), " Value is {x}" );
167
+ REQUIRE_EQ (macro_metadata.log_level (), quill::LogLevel::Error);
168
+ REQUIRE_STREQ (macro_metadata.line (), " 300" );
169
+ REQUIRE_EQ (macro_metadata.full_path (), std::string_view{" lib/SingleArg.cpp" });
170
+ REQUIRE_EQ (macro_metadata.file_name (), std::string_view{" SingleArg.cpp" });
171
+ REQUIRE_STREQ (macro_metadata.short_source_location (), " SingleArg.cpp:300" );
172
+ REQUIRE_STREQ (macro_metadata.caller_function (), " SingleArgFunc" );
173
+ REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::LogWithRuntimeMetadata);
174
+ REQUIRE_EQ (macro_metadata.has_named_args (), true );
175
+ }
176
+
177
+ // Test block for an edge case with a deep path
178
+ {
179
+ constexpr MacroMetadata macro_metadata{
180
+ " a/b/c/directory/DeepFile.cpp:999" , // source_location with a deep path
181
+ " DeepFunc" , // caller_function
182
+ " No named args here" , // message_format with no named arguments
183
+ " deep_tag" , // tags
184
+ quill::LogLevel::Info, // log_level
185
+ MacroMetadata::Event::InitBacktrace // event
186
+ };
187
+
188
+ REQUIRE_STREQ (macro_metadata.message_format (), " No named args here" );
189
+ REQUIRE_EQ (macro_metadata.log_level (), quill::LogLevel::Info);
190
+ REQUIRE_STREQ (macro_metadata.line (), " 999" );
191
+ REQUIRE_EQ (macro_metadata.full_path (), std::string_view{" a/b/c/directory/DeepFile.cpp" });
192
+ REQUIRE_EQ (macro_metadata.file_name (), std::string_view{" DeepFile.cpp" });
193
+ REQUIRE_STREQ (macro_metadata.short_source_location (), " DeepFile.cpp:999" );
194
+ REQUIRE_STREQ (macro_metadata.caller_function (), " DeepFunc" );
195
+ REQUIRE_EQ (macro_metadata.event (), MacroMetadata::Event::InitBacktrace);
196
+ REQUIRE_EQ (macro_metadata.has_named_args (), false );
197
+ }
86
198
}
87
199
88
200
TEST_SUITE_END ();
0 commit comments