Skip to content

Commit 303f640

Browse files
author
ochafik
committed
test groups of common_chat_msg_parser.try_consume_regex
1 parent 2f55571 commit 303f640

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

tests/test-chat-parser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ static void test_regex() {
126126
}
127127
{
128128
common_chat_msg_parser builder("Hello,", /* is_partial= */ false, {});
129-
assert_equals(true, builder.try_consume_regex(common_regex("Hell(o, world!)?")).has_value());
129+
auto res = builder.try_consume_regex(common_regex("H(el)l(?:o, world!)?"));
130+
assert_equals(true, res.has_value());
131+
// Verify captures
132+
assert_equals<size_t>(2, res->groups.size());
133+
assert_equals("Hell", builder.str(res->groups[0]));
134+
assert_equals("el", builder.str(res->groups[1]));
135+
// Verify position is after the match
130136
assert_equals<size_t>(4, builder.pos());
131137
assert_equals("o,", builder.consume_rest());
132138
}

tests/test-regex-partial.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct test_case {
2525
};
2626

2727
static void test_regex() {
28-
28+
printf("[%s]\n", __func__);
2929
auto test = [](const test_case & test_case) {
3030
common_regex cr(test_case.pattern);
3131
std::cout << "Testing pattern: /" << test_case.pattern << "/\n";
@@ -152,6 +152,7 @@ static void test_regex() {
152152
}
153153

154154
static void test_regex_to_reversed_partial_regex() {
155+
printf("[%s]\n", __func__);
155156
assert_equals<std::string>(
156157
"(a+).*",
157158
regex_to_reversed_partial_regex("a+"));
@@ -199,12 +200,7 @@ static void test_regex_to_reversed_partial_regex() {
199200
}
200201

201202
int main() {
202-
try {
203-
test_regex_to_reversed_partial_regex();
204-
test_regex();
205-
} catch (const std::exception & e) {
206-
std::cerr << "Test failed: " << e.what() << '\n';
207-
return 1;
208-
}
203+
test_regex_to_reversed_partial_regex();
204+
test_regex();
209205
std::cout << "All tests passed.\n";
210206
}

0 commit comments

Comments
 (0)