Extended ByteArarySearcher API

This commit is contained in:
Philip Helger
2024-07-09 17:18:36 +02:00
parent fb7fe28eca
commit 7483a0e0d6
2 changed files with 51 additions and 18 deletions

View File

@@ -0,0 +1,24 @@
package org.mustangproject.validator;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
public class ByteArraySearcherTest {
@Test
public void testIndexOf () {
byte[] haystack = "Hello World".getBytes (StandardCharsets.ISO_8859_1);
assertEquals (0, ByteArraySearcher.indexOf (haystack, new byte[] {'H'}));
assertEquals (1, ByteArraySearcher.indexOf (haystack, new byte[] {'e'}));
assertEquals (0, ByteArraySearcher.indexOf (haystack, new byte[] {'H', 'e'}));
assertEquals (0, ByteArraySearcher.indexOf (haystack, new byte[] {'H', 'e'}));
assertEquals (0, ByteArraySearcher.indexOf (haystack, new byte[] {'H', 'e', 'l', 'l'}));
assertEquals (0, ByteArraySearcher.indexOf (haystack, haystack));
assertEquals (0, ByteArraySearcher.indexOf (haystack, new byte[0]));
assertEquals (-1, ByteArraySearcher.indexOf (haystack, new byte[] {'a'}));
assertEquals (-1, ByteArraySearcher.indexOf (haystack, new byte[] {'h'}));
assertEquals (-1, ByteArraySearcher.indexOf (haystack, new byte[] {'r', 'o'}));
}
}