View Javadoc
1   /*
2    * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> 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  package org.eclipse.jgit.ignore.internal;
11  
12  import static org.junit.Assert.assertEquals;
13  
14  import org.junit.Test;
15  
16  public class StringsTest {
17  
18  	private void testString(String string, int n, int m) {
19  		assertEquals(string, n, Strings.count(string, '/', false));
20  		assertEquals(string, m, Strings.count(string, '/', true));
21  	}
22  
23  	@Test
24  	public void testCount() {
25  		testString("", 0, 0);
26  		testString("/", 1, 0);
27  		testString("//", 2, 0);
28  		testString("///", 3, 1);
29  		testString("////", 4, 2);
30  		testString("foo", 0, 0);
31  		testString("/foo", 1, 0);
32  		testString("foo/", 1, 0);
33  		testString("/foo/", 2, 0);
34  		testString("foo/bar", 1, 1);
35  		testString("/foo/bar/", 3, 1);
36  		testString("/foo/bar//", 4, 2);
37  		testString("/foo//bar/", 4, 2);
38  		testString(" /foo/ ", 2, 2);
39  	}
40  }