Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

AuthorsFile Updates - Allow Commented line, international tests. #216

Merged
merged 1 commit into from

3 participants

Ed Frey Sean M. Collins Matt Burke
Ed Frey

*Added ability to comment a line in AuthorsFile. (Was requested in the comments on the initial pull request by @rbirkby)
*Renamed tests to start with AuthorsFile instead of "Test" (seemed a lot more in sync with the rest of the code base)
*Added tests for international characters. (was requested in a pull request for issue #210 )

Ed Frey edwinf Added ability to comment line in AuthorsFile.
Renamed tests to start with AuthorsFile instead of "Test"
Added tests for international author names.
db9044d
Sean M. Collins

Awesome! :beer:

Sean M. Collins sc68cal referenced this pull request
Merged

Use xUnit.net #218

Matt Burke spraints referenced this pull request from a commit
Matt Burke spraints Merge and update tests in #216
Conflicts:
	GitTfsTest/Util/AuthorsFileUnitTest.cs
62a6ab4
Matt Burke spraints referenced this pull request from a commit
Matt Burke spraints Merge #216 and #218. ff364f8
Matt Burke spraints merged commit db9044d into from
Thomas Würtz thomaswurtz referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Thomas Würtz thomaswurtz referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2012
  1. Ed Frey

    Added ability to comment line in AuthorsFile.

    edwinf authored
    Renamed tests to start with AuthorsFile instead of "Test"
    Added tests for international author names.
This page is out of date. Refresh to see the latest.
Showing with 96 additions and 18 deletions.
  1. +14 −12 GitTfs/Util/AuthorsFile.cs
  2. +82 −6 GitTfsTest/Util/AuthorsFileUnitTest.cs
26 GitTfs/Util/AuthorsFile.cs
View
@@ -38,22 +38,24 @@ public void Parse(TextReader authorsFileStream)
while (line != null)
{
lineCount++;
- //regex pulled from git svn script here: https://github.com/git/git/blob/master/git-svn.perl
- Regex ex = new Regex(@"^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$");
- Match match = ex.Match(line);
- if (match.Groups.Count != 4 || String.IsNullOrWhiteSpace(match.Groups[1].Value) || String.IsNullOrWhiteSpace(match.Groups[2].Value) || String.IsNullOrWhiteSpace(match.Groups[3].Value))
+ if (!line.StartsWith("#"))
{
- throw new GitTfsException("Invalid format of Authors file on line " + lineCount + ".");
- }
- else
- {
- if (!authors.ContainsKey(match.Groups[1].Value))
+ //regex pulled from git svn script here: https://github.com/git/git/blob/master/git-svn.perl
+ Regex ex = new Regex(@"^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$");
+ Match match = ex.Match(line);
+ if (match.Groups.Count != 4 || String.IsNullOrWhiteSpace(match.Groups[1].Value) || String.IsNullOrWhiteSpace(match.Groups[2].Value) || String.IsNullOrWhiteSpace(match.Groups[3].Value))
{
- //git svn doesn't trim, but maybe this should?
- authors.Add(match.Groups[1].Value, new Author() { Name = match.Groups[2].Value, Email = match.Groups[3].Value });
+ throw new GitTfsException("Invalid format of Authors file on line " + lineCount + ".");
+ }
+ else
+ {
+ if (!authors.ContainsKey(match.Groups[1].Value))
+ {
+ //git svn doesn't trim, but maybe this should?
+ authors.Add(match.Groups[1].Value, new Author() { Name = match.Groups[2].Value, Email = match.Groups[3].Value });
+ }
}
}
-
line = authorsFileStream.ReadLine();
}
}
88 GitTfsTest/Util/AuthorsFileUnitTest.cs
View
@@ -42,7 +42,7 @@ public TestContext TestContext
[TestMethod]
- public void TestEmptyFile()
+ public void AuthorsFileEmptyFile()
{
MemoryStream ms = new MemoryStream();
StreamReader sr = new StreamReader(ms);
@@ -53,7 +53,7 @@ public void TestEmptyFile()
}
[TestMethod]
- public void TestSimpleRecord()
+ public void AuthorsFileSimpleRecord()
{
string author = @"Domain\Test.User = Test User <TestUser@example.com>";
AuthorsFile authFile = new AuthorsFile();
@@ -67,7 +67,7 @@ public void TestSimpleRecord()
}
[TestMethod]
- public void TestCaseInsensitiveRecord()
+ public void AuthorsFileCaseInsensitiveRecord()
{
string author = @"DOMAIN\Test.User = Test User <TestUser@example.com>";
AuthorsFile authFile = new AuthorsFile();
@@ -81,7 +81,7 @@ public void TestCaseInsensitiveRecord()
}
[TestMethod]
- public void TestMultiLineRecord()
+ public void AuthorsFileMultiLineRecord()
{
string author =
@"Domain\Test.User = Test User <TestUser@example.com>
@@ -104,7 +104,7 @@ public void TestMultiLineRecord()
[TestMethod]
[ExpectedException(typeof(GitTfsException))]
- public void TestMultiLineRecordWithBlankLine()
+ public void AuthorsFileMultiLineRecordWithBlankLine()
{
string author =
@"Domain\Test.User = Test User <TestUser@example.com>
@@ -116,12 +116,88 @@ public void TestMultiLineRecordWithBlankLine()
[TestMethod]
[ExpectedException(typeof(GitTfsException))]
- public void TestBadRecord()
+ public void AuthorsFileTestBadRecord()
{
string author =
@"Domain\Test.User = Test User";
AuthorsFile authFile = new AuthorsFile();
authFile.Parse(new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(author))));
}
+
+ [TestMethod]
+ public void AuthorsFileCommentCharacterStartOfLine()
+ {
+ string author =
+@"Domain\Test.User = Test User <TestUser@example.com>
+#Domain\Different.User = Three Name User < TestUser@example.com >";
+ AuthorsFile authFile = new AuthorsFile();
+ authFile.Parse(new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(author))));
+ Assert.IsNotNull(authFile.Authors);
+ Assert.AreEqual<int>(1, authFile.Authors.Count);
+
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"Domain\Test.User"));
+ Assert.IsFalse(authFile.Authors.ContainsKey(@"Domain\Different.User"));
+ }
+
+ [TestMethod]
+ public void AuthorsFileCommentCharacterMiddleOfLine()
+ {
+ string author =
+@"Domain\Test.User = Test User <TestUser@example.com>
+D#omain\Different.User = Three Name User < TestUser@example.com >";
+ AuthorsFile authFile = new AuthorsFile();
+ authFile.Parse(new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(author))));
+ Assert.IsNotNull(authFile.Authors);
+ Assert.AreEqual<int>(2, authFile.Authors.Count);
+
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"Domain\Test.User"));
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"D#omain\Different.User"));
+ }
+
+ [TestMethod]
+ public void AuthorsFileInternationalCharacters()
+ {
+ string author = @"DOMAIN\Blåbærsyltetøy = ÆØÅ User <ÆØÅ@example.com>";
+ AuthorsFile authFile = new AuthorsFile();
+ authFile.Parse(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(author))));
+ Assert.IsNotNull(authFile.Authors);
+ Assert.AreEqual<int>(1, authFile.Authors.Count);
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"domain\Blåbærsyltetøy"));
+ Author auth = authFile.Authors[@"domain\Blåbærsyltetøy"];
+ Assert.AreEqual<string>("ÆØÅ User", auth.Name);
+ Assert.AreEqual<string>("ÆØÅ@example.com", auth.Email);
+ }
+
+ [TestMethod]
+ public void AuthorsFileInternationalCharactersMultiLine()
+ {
+ string author = @"DOMAIN\Blåbærsyltetøy = ÆØÅ User <ÆØÅ@example.com>
+differentDomain\Blåbærsyltetøy = ÆØÅ User <ÆØÅ@example.com>";
+ AuthorsFile authFile = new AuthorsFile();
+ authFile.Parse(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(author))));
+ Assert.IsNotNull(authFile.Authors);
+ Assert.AreEqual<int>(2, authFile.Authors.Count);
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"domain\Blåbærsyltetøy"));
+ Author auth = authFile.Authors[@"domain\Blåbærsyltetøy"];
+ Assert.AreEqual<string>("ÆØÅ User", auth.Name);
+ Assert.AreEqual<string>("ÆØÅ@example.com", auth.Email);
+
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"differentDomain\Blåbærsyltetøy"));
+ auth = authFile.Authors[@"differentDomain\Blåbærsyltetøy"];
+ Assert.AreEqual<string>("ÆØÅ User", auth.Name);
+ Assert.AreEqual<string>("ÆØÅ@example.com", auth.Email);
+ }
+
+ [TestMethod]
+ public void AuthorsFileInternationalCharactersCommented()
+ {
+ string author = @"DOMAIN\Blåbærsyltetøy = ÆØÅ User <ÆØÅ@example.com>
+#DifferentDomain\Blåbærsyltetøy = ÆØÅ User <ÆØÅ@example.com>";
+ AuthorsFile authFile = new AuthorsFile();
+ authFile.Parse(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(author))));
+ Assert.IsNotNull(authFile.Authors);
+ Assert.AreEqual<int>(1, authFile.Authors.Count);
+ Assert.IsTrue(authFile.Authors.ContainsKey(@"domain\Blåbærsyltetøy"));
+ }
}
}
Something went wrong with that request. Please try again.