From 39ab8f898318de2632d0b1d3b0cf6053e36ee357 Mon Sep 17 00:00:00 2001 From: TapTap Date: Mon, 20 Jul 2026 18:36:03 +0200 Subject: [PATCH] fix: add ** glob_match test cases (issue #67) --- tests/test_glob.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_glob.c b/tests/test_glob.c index 5658d06..7f2208f 100644 --- a/tests/test_glob.c +++ b/tests/test_glob.c @@ -49,6 +49,33 @@ static void test_glob_question_star() { EXPECT_TRUE(glob_match("?*.txt", "a.txt")); } +static void test_glob_doublestar_all() { + EXPECT_TRUE(glob_match("**", "anything")); + EXPECT_TRUE(glob_match("**", "path/to/file.txt")); + EXPECT_TRUE(glob_match("**", "")); +} + +static void test_glob_doublestar_prefix() { + EXPECT_TRUE(glob_match("a/**/b", "a/b")); + EXPECT_TRUE(glob_match("a/**/b", "a/x/b")); + EXPECT_TRUE(glob_match("a/**/b", "a/x/y/b")); + EXPECT_FALSE(glob_match("a/**/b", "a/x/y/c")); +} + +static void test_glob_doublestar_suffix() { + EXPECT_TRUE(glob_match("a/**", "a/b")); + EXPECT_TRUE(glob_match("a/**", "a/b/c/d")); + EXPECT_TRUE(glob_match("a/**", "a/")); + EXPECT_FALSE(glob_match("a/**", "b/a")); +} + +static void test_glob_doublestar_subdir() { + EXPECT_TRUE(glob_match("**/foo", "foo")); + EXPECT_TRUE(glob_match("**/foo", "bar/foo")); + EXPECT_TRUE(glob_match("**/foo", "a/b/c/foo")); + EXPECT_FALSE(glob_match("**/foo", "foobar")); +} + void test_glob() { test_glob_exact_match(); test_glob_question_mark(); @@ -60,4 +87,8 @@ void test_glob() { test_glob_slash_not_matched(); test_glob_complex(); test_glob_question_star(); + test_glob_doublestar_all(); + test_glob_doublestar_prefix(); + test_glob_doublestar_suffix(); + test_glob_doublestar_subdir(); }