@ -43,58 +43,97 @@
package org.eclipse.jgit.util ;
import java.io.UnsupportedEncodingException ;
import java.util.Date ;
import java.util.TimeZone ;
import org.eclipse.jgit.lib.PersonIdent ;
import junit.framework.TestCase ;
import org.eclipse.jgit.lib.PersonIdent ;
public class RawParseUtils_ParsePersonIdentTest extends TestCase {
public void testParsePersonIdent_legalCases ( )
throws UnsupportedEncodingException {
public void testParsePersonIdent_legalCases ( ) {
final Date when = new Date ( 1234567890000l ) ;
final TimeZone tz = TimeZone . getTimeZone ( "GMT-7" ) ;
assertPersonIdent ( "Me <me@example.com> 1234567890 -0700" , 0 ,
assertPersonIdent ( "Me <me@example.com> 1234567890 -0700" ,
new PersonIdent ( "Me" , "me@example.com" , when , tz ) ) ;
assertPersonIdent ( " Me <me@example.com> 1234567890 -0700" , 1 ,
new PersonIdent ( "Me" , "me@example.com" , when , tz ) ) ;
assertPersonIdent ( " Me <me@example.com> 1234567890 -0700" ,
new PersonIdent ( " Me" , "me@example.com" , when , tz ) ) ;
assertPersonIdent ( "Me <> 1234567890 -0700" , 0 , new PersonIdent ( "Me " ,
"" , when , tz ) ) ;
assertPersonIdent ( "A U Thor <author@example.com> 1234567890 -0700 " ,
new PersonIdent ( "A U Thor" , "author@example.com " , when , tz ) ) ;
assertPersonIdent ( " <me@example.com> 1234567890 -0700" , 0 ,
new PersonIdent ( "" , "me@example.com" , when , tz ) ) ;
assertPersonIdent ( "A U Thor<author@example.com> 1234567890 -0700" ,
new PersonIdent ( "A U Thor" , "author@example.com" , when , tz ) ) ;
assertPersonIdent ( "A U Thor<author@example.com>1234567890 -0700" ,
new PersonIdent ( "A U Thor" , "author@example.com" , when , tz ) ) ;
assertPersonIdent (
" A U Thor < author@example.com > 1234567890 -0700" ,
new PersonIdent ( " A U Thor " , " author@example.com " , when , tz ) ) ;
assertPersonIdent ( "A U Thor<author@example.com>1234567890 -0700" ,
new PersonIdent ( "A U Thor" , "author@example.com" , when , tz ) ) ;
}
public void testParsePersonIdent_fuzzyCases ( ) {
final Date when = new Date ( 1234567890000l ) ;
final TimeZone tz = TimeZone . getTimeZone ( "GMT-7" ) ;
assertPersonIdent (
"A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700" ,
new PersonIdent ( "A U Thor" , "author@example.com" , when , tz ) ) ;
assertPersonIdent (
"A U Thor <author@example.com> and others 1234567890 -0700" ,
new PersonIdent ( "A U Thor" , "author@example.com" , when , tz ) ) ;
}
public void testParsePersonIdent_incompleteCases ( ) {
final Date when = new Date ( 1234567890000l ) ;
final TimeZone tz = TimeZone . getTimeZone ( "GMT-7" ) ;
assertPersonIdent ( " <> 1234567890 -0700" , 0 , new PersonIdent ( "" , "" ,
assertPersonIdent ( "Me <> 1234567890 -0700" , new PersonIdent ( "Me " , "" ,
when , tz ) ) ;
assertPersonIdent ( " <me@example.com> 1234567890 -0700" ,
new PersonIdent ( "" , "me@example.com" , when , tz ) ) ;
assertPersonIdent ( " <> 1234567890 -0700" , new PersonIdent ( "" , "" , when ,
tz ) ) ;
assertPersonIdent ( "<>" , new PersonIdent ( "" , "" , 0 , 0 ) ) ;
assertPersonIdent ( " <>" , new PersonIdent ( "" , "" , 0 , 0 ) ) ;
assertPersonIdent ( "<me@example.com>" , new PersonIdent ( "" ,
"me@example.com" , 0 , 0 ) ) ;
assertPersonIdent ( " <me@example.com>" , new PersonIdent ( "" ,
"me@example.com" , 0 , 0 ) ) ;
assertPersonIdent ( "Me <>" , new PersonIdent ( "Me" , "" , 0 , 0 ) ) ;
assertPersonIdent ( "Me <me@example.com>" , new PersonIdent ( "Me" ,
"me@example.com" , 0 , 0 ) ) ;
assertPersonIdent ( "Me <me@example.com> 1234567890" , new PersonIdent (
"Me" , "me@example.com" , 0 , 0 ) ) ;
assertPersonIdent ( "Me <me@example.com> 1234567890 " , new PersonIdent (
"Me" , "me@example.com" , 0 , 0 ) ) ;
}
public void testParsePersonIdent_malformedCases ( )
throws UnsupportedEncodingException {
assertPersonIdent ( "Me me@example.com> 1234567890 -0700" , 0 , null ) ;
assertPersonIdent ( "Me <me@example.com 1234567890 -0700" , 0 , null ) ;
assertPersonIdent ( "<>" , 0 , null ) ;
assertPersonIdent ( "<me@example.com>" , 0 , null ) ;
assertPersonIdent ( " <>" , 0 , null ) ;
assertPersonIdent ( " <me@example.com>" , 0 , null ) ;
assertPersonIdent ( "Me <>" , 0 , null ) ;
assertPersonIdent ( "Me <me@example.com>" , 0 , null ) ;
assertPersonIdent ( "Me <me@example.com> 1234567890" , 0 , null ) ;
assertPersonIdent ( "<me@example.com> 1234567890 -0700" , 0 , null ) ;
assertPersonIdent ( "<> 1234567890 -0700" , 0 , null ) ;
public void testParsePersonIdent_malformedCases ( ) {
assertPersonIdent ( "Me me@example.com> 1234567890 -0700" , null ) ;
assertPersonIdent ( "Me <me@example.com 1234567890 -0700" , null ) ;
}
private void assertPersonIdent ( String line , int nameB , PersonIdent expected )
throws UnsupportedEncodingException {
PersonIdent actual = RawParseUtils . parsePersonIdent ( line
. getBytes ( "UTF-8" ) , nameB ) ;
private void assertPersonIdent ( String line , PersonIdent expected ) {
PersonIdent actual = RawParseUtils . parsePersonIdent ( line ) ;
assertEquals ( expected , actual ) ;
}
}