|
| 1 | +package git |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestParseDiffStats(t *testing.T) { |
| 6 | + tests := map[string]Stats{ |
| 7 | + "1 file changed, 3 insertions(+), 1 deletion(-)": {1, 3, 1}, |
| 8 | + "2 files changed, 10 insertions(+)": {2, 10, 0}, |
| 9 | + "5 files changed, 7 deletions(-)": {5, 0, 7}, |
| 10 | + "3 files changed, 12 insertions(+), 8 deletions(-)": {3, 12, 8}, |
| 11 | + "1 file changed, 0 insertions(+), 5 deletions(-)": {1, 0, 5}, |
| 12 | + "12 files changed, 240 insertions(+), 198 deletions(-)": {12, 240, 198}, |
| 13 | + } |
| 14 | + |
| 15 | + for output, expectedStats := range tests { |
| 16 | + t.Run(output, func(t *testing.T) { |
| 17 | + stats, err := parseDiffStats(output) |
| 18 | + if err != nil { |
| 19 | + t.Fatal(err) |
| 20 | + } |
| 21 | + if *stats != expectedStats { |
| 22 | + t.Errorf("expected %v, got %v", expectedStats, stats) |
| 23 | + } |
| 24 | + }) |
| 25 | + } |
| 26 | +} |
0 commit comments