Trim boilerplate in RawParseUtils_LineMapTest.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Ib003f7c8f2816dd57e941799a665e70ecd6645a2
This commit is contained in:
Han-Wen Nienhuys 2017-07-27 13:49:39 +02:00
parent 5b84e25fa3
commit ab0eedcead
1 changed files with 17 additions and 24 deletions

View File

@ -43,6 +43,7 @@
package org.eclipse.jgit.util;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -55,52 +56,44 @@ public class RawParseUtils_LineMapTest {
public void testEmpty() {
final IntList map = RawParseUtils.lineMap(new byte[] {}, 0, 0);
assertNotNull(map);
assertEquals(2, map.size());
assertEquals(Integer.MIN_VALUE, map.get(0));
assertEquals(0, map.get(1));
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0}, asInts(map));
}
@Test
public void testOneBlankLine() {
final IntList map = RawParseUtils.lineMap(new byte[] { '\n' }, 0, 1);
assertEquals(3, map.size());
assertEquals(Integer.MIN_VALUE, map.get(0));
assertEquals(0, map.get(1));
assertEquals(1, map.get(2));
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 1}, asInts(map));
}
@Test
public void testTwoLineFooBar() throws UnsupportedEncodingException {
final byte[] buf = "foo\nbar\n".getBytes("ISO-8859-1");
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertEquals(4, map.size());
assertEquals(Integer.MIN_VALUE, map.get(0));
assertEquals(0, map.get(1));
assertEquals(4, map.get(2));
assertEquals(buf.length, map.get(3));
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
}
@Test
public void testTwoLineNoLF() throws UnsupportedEncodingException {
final byte[] buf = "foo\nbar".getBytes("ISO-8859-1");
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertEquals(4, map.size());
assertEquals(Integer.MIN_VALUE, map.get(0));
assertEquals(0, map.get(1));
assertEquals(4, map.get(2));
assertEquals(buf.length, map.get(3));
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
}
@Test
public void testFourLineBlanks() throws UnsupportedEncodingException {
final byte[] buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1");
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertEquals(6, map.size());
assertEquals(Integer.MIN_VALUE, map.get(0));
assertEquals(0, map.get(1));
assertEquals(4, map.get(2));
assertEquals(5, map.get(3));
assertEquals(6, map.get(4));
assertEquals(buf.length, map.get(5));
assertArrayEquals(new int[]{
Integer.MIN_VALUE, 0, 4, 5, 6, buf.length
}, asInts(map));
}
private int[] asInts(IntList l) {
int[] result = new int[l.size()];
for (int i = 0; i < l.size(); i++) {
result[i] = l.get(i);
}
return result;
}
}