All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Law <objecting@objecting.org>
To: Kuan-Wei Chiu <visitorckw@gmail.com>,
	Josh Law <objecting@objecting.org>,
	David Gow <david@davidgow.net>, Kir Chou <note351@hotmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>
Subject: [PATCH] lib/glob: add more KUnit tests for glob
Date: Fri,  3 Apr 2026 15:28:53 +0000	[thread overview]
Message-ID: <20260403152853.61870-1-objecting@objecting.org> (raw)

Since there isnt much tests for lib/glob.c, lets go ahead and add some more tests

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/tests/glob_kunit.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/tests/glob_kunit.c b/lib/tests/glob_kunit.c
index 362b1eda8e5b..73d4f72fa824 100644
--- a/lib/tests/glob_kunit.c
+++ b/lib/tests/glob_kunit.c
@@ -90,6 +90,31 @@ static const struct glob_test_case glob_test_cases[] = {
 	{ .pat = "*abcd*abcdef*", .str = "abcabcdabcdeabcdefg", .expected = true },
 	{ .pat = "*abcd*", .str = "abcabcabcabcefg", .expected = false },
 	{ .pat = "*ab*cd*", .str = "abcabcabcabcefg", .expected = false },
+	/* backslash escaping */
+	{ .pat = "\\a", .str = "a", .expected = true },
+	{ .pat = "\\a", .str = "\\a", .expected = false },
+	{ .pat = "\\*", .str = "*", .expected = true },
+	{ .pat = "\\*", .str = "a", .expected = false },
+	{ .pat = "\\?", .str = "?", .expected = true },
+	{ .pat = "\\?", .str = "a", .expected = false },
+	{ .pat = "\\[a]", .str = "[a]", .expected = true },
+	{ .pat = "\\\\", .str = "\\", .expected = true },
+	{ .pat = "a\\*b", .str = "a*b", .expected = true },
+	{ .pat = "a\\*b", .str = "aXb", .expected = false },
+	/* trailing backslash */
+	{ .pat = "a\\", .str = "a", .expected = true },
+	{ .pat = "\\", .str = "", .expected = true },
+	/* backwards ranges */
+	{ .pat = "[z-a]", .str = "m", .expected = false },
+	{ .pat = "[!z-a]", .str = "m", .expected = true },
+	/* high-bit characters */
+	{ .pat = "\xc0", .str = "\xc0", .expected = true },
+	{ .pat = "\xc0", .str = "\x80", .expected = false },
+	{ .pat = "[\x80-\xff]", .str = "\xc0", .expected = true },
+	{ .pat = "[\x80-\xff]", .str = "\x7f", .expected = false },
+	/* unclosed bracket as literal */
+	{ .pat = "[abc", .str = "[abc", .expected = true },
+	{ .pat = "[abc", .str = "a", .expected = false },
 };
 
 static void glob_case_to_desc(const struct glob_test_case *t, char *desc)
-- 
2.34.1


             reply	other threads:[~2026-04-03 15:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03 15:28 Josh Law [this message]
2026-04-03 15:49 ` [PATCH] lib/glob: add more KUnit tests for glob Kuan-Wei Chiu
2026-04-03 15:50   ` Josh Law
2026-04-03 16:10     ` Kuan-Wei Chiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260403152853.61870-1-objecting@objecting.org \
    --to=objecting@objecting.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@davidgow.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=note351@hotmail.com \
    --cc=rostedt@goodmis.org \
    --cc=visitorckw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.