Skip to content

Commit 9262368

Browse files
committed
test: add mem search compatibility helpers for std versions
- Use std.mem.find/findScalar when available and fall back to indexOf/indexOfScalar. - Keep tests passing across Zig versions with different std.mem APIs. - Route test assertions through shared helpers to avoid version-specific calls.
1 parent 77fb816 commit 9262368

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/tests.zig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ const builtin = @import("builtin");
1515
const webui = @import("webui");
1616
const compat_tuple = @import("compat_tuple");
1717

18+
fn memFind(comptime T: type, haystack: []const T, needle: []const T) ?usize {
19+
if (comptime @hasDecl(std.mem, "find")) return std.mem.find(T, haystack, needle);
20+
return std.mem.indexOf(T, haystack, needle);
21+
}
22+
23+
fn memFindScalar(comptime T: type, haystack: []const T, needle: T) ?usize {
24+
if (comptime @hasDecl(std.mem, "findScalar")) return std.mem.findScalar(T, haystack, needle);
25+
return std.mem.indexOfScalar(T, haystack, needle);
26+
}
1827
// =============================================================================
1928
// Pure-Zig tests (no C calls)
2029
// =============================================================================
@@ -174,7 +183,7 @@ test "getMimeType resolves common extensions" {
174183
// a non-empty string that mentions javascript.
175184
const js_mime = webui.getMimeType("app.js");
176185
try std.testing.expect(js_mime.len > 0);
177-
try std.testing.expect(std.mem.indexOf(u8, js_mime, "javascript") != null);
186+
try std.testing.expect(memFind(u8, js_mime, "javascript") != null);
178187
}
179188

180189
test "encode then decode roundtrips" {
@@ -183,7 +192,7 @@ test "encode then decode roundtrips" {
183192
defer webui.free(encoded);
184193
try std.testing.expect(encoded.len > 0);
185194
// Base64 of ASCII has no NUL bytes embedded.
186-
try std.testing.expect(std.mem.indexOfScalar(u8, encoded, 0) == null);
195+
try std.testing.expect(memFindScalar(u8, encoded, 0) == null);
187196

188197
// Build a NUL-terminated copy for the decode call (the C API insists).
189198
var buf: [128]u8 = undefined;

0 commit comments

Comments
 (0)