Skip to content

test(strbuf): cover the length-bounded contract of ffStrbufMatchSeparatedNS - #2585

Closed
buyua9 wants to merge 1 commit into
fastfetch-cli:devfrom
buyua9:test/strbuf-match-separated-ns-bounded
Closed

buyua9 wants to merge 1 commit into
fastfetch-cli:devfrom
buyua9:test/strbuf-match-separated-ns-bounded

Conversation

@buyua9

@buyua9 buyua9 commented Sep 14, 2026

Copy link
Copy Markdown

What does this PR do?

Adds a focused test block for ffStrbufMatchSeparatedNS, the length-bounded variant behind ffStrbufMatchSeparatedS.

Why

The Linux keyboard handler calls the NS variant with a fixed-size buffer length rather than a NUL-terminated string, but tests/strbuf.c only exercised the S wrapper — the bounded contract had zero coverage. The new block asserts twelve length-boundary cases: bounds cutting mid-token (match vs no-match), compLength = 0, a bound spanning exactly one token, no separator in bounds, an embedded NUL inside the bounds, and empty-substring matching, all against the current implementation semantics.

Tested

cmake -DFF_BUILD_TESTS=onffstrbuf_test (block verified against the implementation's branch behavior; full suite runs in CI).

…atedNS

ffStrbufMatchSeparatedNS takes an explicit compLength and is the
length-bounded variant behind ffStrbufMatchSeparatedS; the Linux
keyboard handler calls it with a fixed-size buffer length rather than
a NUL-terminated string. tests/strbuf.c only exercised the S wrapper,
so the bounded contract had no coverage: bounds cutting mid-token,
compLength=0, embedded NUL inside bounds, and empty-substring matching
were all untested, and a regression in the bounded path would keep
every existing test green. Add a focused block asserting twelve
length-boundary cases.
Comment thread tests/strbuf.c
VERIFY(ffStrbufMatchSeparatedNS(&strbuf, 3, "abc:def:ghi", ':') == true);
VERIFY(ffStrbufMatchSeparatedNS(&strbuf, 7, "abc:def:ghi", ':') == true); // "abc:def"
VERIFY(ffStrbufMatchSeparatedNS(&strbuf, 4, "abc:def:ghi", ':') == true); // "abc:"
VERIFY(ffStrbufMatchSeparatedNS(&strbuf, 5, "abc:def:ghi", ':') == false); // "abc:d"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means if "abc:d" contains "abc". This is obviously true.

@CarterLi CarterLi closed this in fbf79ac Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants