-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_basic.zig
More file actions
247 lines (214 loc) · 7.2 KB
/
test_basic.zig
File metadata and controls
247 lines (214 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
const std = @import("std");
const testing = std.testing;
const zlob = @import("zlob");
const zlob_flags = @import("zlob_flags");
const test_utils = @import("test_utils");
const zlobIsomorphicTest = test_utils.zlobIsomorphicTest;
const TestResult = test_utils.TestResult;
test "matchPaths - simple wildcard" {
const files = [_][]const u8{
"test.txt",
"main.zig",
"data.json",
"file.txt",
"readme.md",
};
try zlobIsomorphicTest(&files, "*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("test.txt"));
try testing.expect(result.hasPath("file.txt"));
}
}.assert, @src());
}
test "matchPaths - question mark" {
const files = [_][]const u8{
"a.txt",
"ab.txt",
"abc.txt",
"x.txt",
};
try zlobIsomorphicTest(&files, "?.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("a.txt"));
try testing.expect(result.hasPath("x.txt"));
}
}.assert, @src());
}
test "matchPaths - character class" {
const files = [_][]const u8{
"a1.txt",
"b2.txt",
"c3.txt",
"d4.txt",
};
try zlobIsomorphicTest(&files, "[ab]*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("a1.txt"));
try testing.expect(result.hasPath("b2.txt"));
}
}.assert, @src());
}
test "matchPaths - negated character class" {
const files = [_][]const u8{
"a1.txt",
"b2.txt",
"c3.txt",
};
try zlobIsomorphicTest(&files, "[!a]*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("b2.txt"));
try testing.expect(result.hasPath("c3.txt"));
}
}.assert, @src());
}
test "matchPaths - with paths" {
const files = [_][]const u8{
"src/main.zig",
"src/test.zig",
"lib/util.zig",
"docs/readme.md",
};
try zlobIsomorphicTest(&files, "src/*.zig", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("src/main.zig"));
try testing.expect(result.hasPath("src/test.zig"));
}
}.assert, @src());
}
test "matchPaths - recursive pattern" {
const files = [_][]const u8{
"src/test.txt",
"lib/test.txt",
"docs/readme.md",
};
try zlobIsomorphicTest(&files, "**/test.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("src/test.txt"));
try testing.expect(result.hasPath("lib/test.txt"));
}
}.assert, @src());
}
test "matchPaths - no matches" {
const files = [_][]const u8{
"test.txt",
"main.zig",
};
try zlobIsomorphicTest(&files, "*.log", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 0), result.count);
}
}.assert, @src());
}
test "matchPaths - empty file list" {
const files = [_][]const u8{};
try zlobIsomorphicTest(&files, "*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 0), result.count);
}
}.assert, @src());
}
test "matchPaths - exact match" {
const files = [_][]const u8{
"test.txt",
"main.txt",
"file.txt",
};
try zlobIsomorphicTest(&files, "test.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 1), result.count);
try testing.expect(result.hasPath("test.txt"));
}
}.assert, @src());
}
test "matchPaths - complex pattern" {
const files = [_][]const u8{
"test_01.txt",
"test_02.txt",
"file_03.txt",
"test_ab.txt",
};
try zlobIsomorphicTest(&files, "test_[0-9]*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 2), result.count);
try testing.expect(result.hasPath("test_01.txt"));
try testing.expect(result.hasPath("test_02.txt"));
}
}.assert, @src());
}
test "??? - question marks only" {
const files = [_][]const u8{
"abc.txt",
"fef.txt",
"q!@.txt",
"abcd.txt",
};
try zlobIsomorphicTest(&files, "???.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 3), result.count);
try testing.expect(result.hasPath("abc.txt"));
try testing.expect(result.hasPath("ef.txt"));
}
}.assert, @src());
}
test "matchPaths - sorted results" {
const files = [_][]const u8{
"c.txt",
"a.txt",
"b.txt",
};
try zlobIsomorphicTest(&files, "*.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 3), result.count);
// Should be sorted
try testing.expectEqualStrings("a.txt", result.paths[0]);
try testing.expectEqualStrings("b.txt", result.paths[1]);
try testing.expectEqualStrings("c.txt", result.paths[2]);
}
}.assert, @src());
}
test "matchPaths - NOSORT flag" {
// NOSORT is matchPaths-specific, no filesystem equivalent
const files = [_][]const u8{
"c.txt",
"a.txt",
"b.txt",
};
var result = try zlob.matchPaths(testing.allocator, "*.txt", &files, zlob_flags.ZLOB_NOSORT);
defer result.deinit();
try testing.expectEqual(@as(usize, 3), result.len());
// Order should match input order
}
test "matchPaths - large file list" {
// Large file list test - matchPaths only for performance
var files: [1000][]const u8 = undefined;
var file_buffers: [1000][20]u8 = undefined;
for (0..1000) |i| {
const name = std.fmt.bufPrint(&file_buffers[i], "file_{d}.txt", .{i}) catch unreachable;
files[i] = name;
}
var result = try zlob.matchPaths(testing.allocator, "file_5*.txt", &files, 0);
defer result.deinit();
// Should match file_5.txt, file_50.txt, file_51.txt, ..., file_599.txt
// That's 111 files (5, 50-59, 500-599)
try testing.expect(result.len() > 0);
}
test "matchPaths - SIMD fast path" {
const files = [_][]const u8{
"very_long_filename_that_triggers_simd.txt",
"another_long_filename_for_testing.txt",
"short.txt",
};
// Long literal pattern should use SIMD fast path
try zlobIsomorphicTest(&files, "very_long_filename_that_triggers_simd.txt", 0, struct {
fn assert(result: TestResult) !void {
try testing.expectEqual(@as(usize, 1), result.count);
try testing.expect(result.hasPath("very_long_filename_that_triggers_simd.txt"));
}
}.assert, @src());
}