This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void CanParseMultipleLines() | |
{ | |
var result = ParseList<FileStats>( | |
"3\t8\tfile.txt\r\n" + | |
"5\t1\tanotherFile.txt\r\n", x => x.FullFile); | |
Assert.That(result.Count, Is.EqualTo(2)); | |
Assert.That(result[0].Filename, Is.EqualTo("file.txt")); | |
Assert.That(result[0].Additions, Is.EqualTo(3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ometa GitNumstatParser : Parser { | |
FileStats = LineStats:lines '\t' Filename:name NewLine -> { new FileStats(lines[0].As<int>(), lines[1].As<int>(), name.As<string>()) }, | |
LineStats = Number:adds '\t' Number:subs -> { adds, subs }, | |
Filename = LetterOrDigit+:name '.' LetterOrDigit+:ext -> { name.As<string>() + "." + ext.As<string>() }, | |
NewLine = '\r' '\n' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileStats | |
{ | |
public FileStats(int additions, int subtractions, string filename) | |
{ | |
Additions = additions; | |
Subtractions = subtractions; | |
Filename = filename; | |
} | |
public int Additions { get; private set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void ParsesFullFileLine() | |
{ | |
var result = Parse<FileStats>("3\t8\tmyFile.txt\r\n", x => x.FileStats); | |
Assert.That(result.Additions, Is.EqualTo(3)); | |
Assert.That(result.Subtractions, Is.EqualTo(8)); | |
Assert.That(result.Filename, Is.EqualTo("myFile.txt")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SharpDiff.FileStructure.Numstat; | |
using OMetaSharp; | |
ometa GitNumstatParser : Parser { | |
FileStats = Number:adds '\t' Number:subs -> { new FileStats(adds.As<int>(), subs.As<int>()) }, | |
Filename = LetterOrDigit+:name '.' LetterOrDigit+:ext -> { name.As<string>() + "." + ext.As<string>() } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void ParsesFilename() | |
{ | |
var result = Parse<string>("anotherFile.txt", x => x.Filename); | |
Assert.That(result, Is.EqualTo("anotherFile.txt")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SharpDiff.FileStructure.Numstat; | |
using OMetaSharp; | |
ometa GitNumstatParser : Parser { | |
FileStats = Number:adds '\t' Number:subs -> { new FileStats(adds.As<int>(), subs.As<int>()) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileStats | |
{ | |
public FileStats(int additions, int subtractions) | |
{ | |
Additions = additions; | |
Subtractions = subtractions; | |
} | |
public int Additions { get; private set; } | |
public int Subtractions { get; private set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void ParsesAdditionsAndSubtractionValues() | |
{ | |
var result = Parse<FileStats>("3\t8\tmyFile.txt\r\n", x => x.Number); | |
Assert.That(result.Additions, Is.EqualTo(3)); | |
Assert.That(result.Subtractions, Is.EqualTo(8)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected T Parse<T>(string text, Func<GitNumstatParser, Rule<char>> ruleFetcher) | |
{ | |
return Grammars.ParseWith(text, ruleFetcher).As<T>(); | |
} |