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