From 2cc21194aa290af338917702bde416ca149bf847 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 20 May 2024 17:16:27 +1000 Subject: [PATCH] test(bytes): add test for negative `start` index for `indexOfNeedle()` (#4768) tests(bytes): add test for negative `start` index for `indexOfNeedle()` --- bytes/index_of_needle_test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bytes/index_of_needle_test.ts b/bytes/index_of_needle_test.ts index 7d369b1e5..5a2b92960 100644 --- a/bytes/index_of_needle_test.ts +++ b/bytes/index_of_needle_test.ts @@ -62,3 +62,22 @@ Deno.test("indexOfNeedle() handles start index less than 0", () => { -1, ); }); + +Deno.test("indexOfNeedle() handles negative start index", () => { + assertEquals( + indexOfNeedle( + new Uint8Array([0, 1, 2, 0, 1, 2]), + new Uint8Array([0, 1]), + -3, + ), + 3, + ); + assertEquals( + indexOfNeedle( + new Uint8Array([0, 1, 2, 1, 1, 2]), + new Uint8Array([0, 1]), + -3, + ), + -1, + ); +});