View Javadoc
1   /*
2    * Copyright (C) 2009, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.util;
12  
13  import static org.junit.Assert.assertTrue;
14  
15  import org.eclipse.jgit.lib.Constants;
16  import org.junit.Test;
17  
18  public class RawParseUtils_MatchTest {
19  	@Test
20  	public void testMatch_Equal() {
21  		final byte[] src = Constants.encodeASCII(" differ\n");
22  		final byte[] dst = Constants.encodeASCII("foo differ\n");
23  		assertTrue(RawParseUtils.match(dst, 3, src) == 3 + src.length);
24  	}
25  
26  	@Test
27  	public void testMatch_NotEqual() {
28  		final byte[] src = Constants.encodeASCII(" differ\n");
29  		final byte[] dst = Constants.encodeASCII("a differ\n");
30  		assertTrue(RawParseUtils.match(dst, 2, src) < 0);
31  	}
32  
33  	@Test
34  	public void testMatch_Prefix() {
35  		final byte[] src = Constants.encodeASCII("author ");
36  		final byte[] dst = Constants.encodeASCII("author A. U. Thor");
37  		assertTrue(RawParseUtils.match(dst, 0, src) == src.length);
38  		assertTrue(RawParseUtils.match(dst, 1, src) < 0);
39  	}
40  
41  	@Test
42  	public void testMatch_TooSmall() {
43  		final byte[] src = Constants.encodeASCII("author ");
44  		final byte[] dst = Constants.encodeASCII("author autho");
45  		assertTrue(RawParseUtils.match(dst, src.length + 1, src) < 0);
46  	}
47  }