@@ -3,6 +3,8 @@ const Allocator = std.mem.Allocator;
33const assert = std .debug .assert ;
44const testing = std .testing ;
55
6+ const test_suites = @import ("test_cases.zig" ).test_suites ;
7+
68pub fn StringFinder (comptime T : type ) type {
79 assert (std .meta .trait .isIndexable (T ));
810 const ElemType = std .meta .Elem (T );
@@ -128,41 +130,15 @@ pub fn StringFinder(comptime T: type) type {
128130 };
129131}
130132
131- test "empty pattern" {
132- const allocator = testing .allocator ;
133-
134- var sf = try StringFinder ([]const u8 ).init (allocator , "" );
135- defer sf .deinit ();
136-
137- testing .expectEqual (@as (? usize , 0 ), sf .next ("zig" ));
138- testing .expectEqual (@as (? usize , 0 ), sf .next ("" ));
139- testing .expectEqual (@as (? usize , 0 ), sf .next ("a" ));
140- testing .expectEqual (@as (? usize , 0 ), sf .next ("lang" ));
141- }
142-
143- test "pattern with length 1" {
133+ test "boyer moore" {
144134 const allocator = testing .allocator ;
145135
146- var sf = try StringFinder ([]const u8 ).init (allocator , "a" );
147- defer sf .deinit ();
136+ for (test_suites ) | suite | {
137+ var sf = try StringFinder ([]const u8 ).init (allocator , suite .pattern );
138+ defer sf .deinit ();
148139
149- testing .expectEqual (@as (? usize , null ), sf .next ("zig" ));
150- testing .expectEqual (@as (? usize , null ), sf .next ("" ));
151- testing .expectEqual (@as (? usize , 0 ), sf .next ("a" ));
152- testing .expectEqual (@as (? usize , 1 ), sf .next ("lang" ));
153- }
154-
155- test "test matching" {
156- const allocator = testing .allocator ;
157-
158- var sf = try StringFinder ([]const u8 ).init (allocator , "zig" );
159- defer sf .deinit ();
160-
161- testing .expectEqual (@as (? usize , 0 ), sf .next ("zig" ));
162- testing .expectEqual (@as (? usize , 0 ), sf .next ("ziglang" ));
163- testing .expectEqual (@as (? usize , 4 ), sf .next ("langzig" ));
164- testing .expectEqual (@as (? usize , 4 ), sf .next ("langziglang" ));
165- testing .expectEqual (@as (? usize , null ), sf .next ("" ));
166- testing .expectEqual (@as (? usize , null ), sf .next ("firefox" ));
167- testing .expectEqual (@as (? usize , 8 ), sf .next ("abc abc ziglang" ));
140+ for (suite .cases ) | case | {
141+ testing .expectEqual (case .expected , sf .next (case .text ));
142+ }
143+ }
168144}
0 commit comments