@ -48,45 +48,45 @@ import static org.junit.Assert.assertNotNull;
import java.io.UnsupportedEncodingException ;
import java.io.UnsupportedEncodingException ;
import org.eclipse.jgit.errors.BinaryBlobException ;
import org.junit.Test ;
import org.junit.Test ;
public class RawParseUtils_LineMapTest {
public class RawParseUtils_LineMapTest {
@Test
@Test
public void testEmpty ( ) {
public void testEmpty ( ) throws Exception {
final IntList map = RawParseUtils . lineMap ( new byte [ ] { } , 0 , 0 ) ;
final IntList map = RawParseUtils . lineMap ( new byte [ ] { } , 0 , 0 ) ;
assertNotNull ( map ) ;
assertNotNull ( map ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 } , asInts ( map ) ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 } , asInts ( map ) ) ;
}
}
@Test
@Test
public void testOneBlankLine ( ) {
public void testOneBlankLine ( ) throws Exception {
final IntList map = RawParseUtils . lineMap ( new byte [ ] { '\n' } , 0 , 1 ) ;
final IntList map = RawParseUtils . lineMap ( new byte [ ] { '\n' } , 0 , 1 ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 1 } , asInts ( map ) ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 1 } , asInts ( map ) ) ;
}
}
@Test
@Test
public void testTwoLineFooBar ( ) throws UnsupportedEncoding Exception {
public void testTwoLineFooBar ( ) throws Exception {
final byte [ ] buf = "foo\nbar\n" . getBytes ( "ISO-8859-1" ) ;
final byte [ ] buf = "foo\nbar\n" . getBytes ( "ISO-8859-1" ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 4 , buf . length } , asInts ( map ) ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 4 , buf . length } , asInts ( map ) ) ;
}
}
@Test
@Test
public void testTwoLineNoLF ( ) throws UnsupportedEncoding Exception {
public void testTwoLineNoLF ( ) throws Exception {
final byte [ ] buf = "foo\nbar" . getBytes ( "ISO-8859-1" ) ;
final byte [ ] buf = "foo\nbar" . getBytes ( "ISO-8859-1" ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 4 , buf . length } , asInts ( map ) ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 0 , 4 , buf . length } , asInts ( map ) ) ;
}
}
@Test
@Test ( expected = BinaryBlobException . class )
public void testBinary ( ) throws UnsupportedEncoding Exception {
public void testBinary ( ) throws Exception {
final byte [ ] buf = "xxxfoo\nb\0ar" . getBytes ( "ISO-8859-1" ) ;
final byte [ ] buf = "xxxfoo\nb\0ar" . getBytes ( "ISO-8859-1" ) ;
final IntList map = RawParseUtils . lineMap ( buf , 3 , buf . length ) ;
RawParseUtils . lineMap ( buf , 3 , buf . length ) ;
assertArrayEquals ( new int [ ] { Integer . MIN_VALUE , 3 , buf . length } , asInts ( map ) ) ;
}
}
@Test
@Test
public void testFourLineBlanks ( ) throws UnsupportedEncoding Exception {
public void testFourLineBlanks ( ) throws Exception {
final byte [ ] buf = "foo\n\n\nbar\n" . getBytes ( "ISO-8859-1" ) ;
final byte [ ] buf = "foo\n\n\nbar\n" . getBytes ( "ISO-8859-1" ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;
final IntList map = RawParseUtils . lineMap ( buf , 0 , buf . length ) ;