@@ -29,7 +29,7 @@ func init() {
29
29
time .Local = time .UTC
30
30
}
31
31
32
- func TestReadQuotedFilename (t * testing.T ) {
32
+ func TestReadQuotedFilename_Success (t * testing.T ) {
33
33
tests := []string {
34
34
`""` , "" , "" ,
35
35
`"aaa"` , "aaa" , "" ,
@@ -50,7 +50,21 @@ func TestReadQuotedFilename(t *testing.T) {
50
50
}
51
51
}
52
52
53
- func TestParseDiffGitArgs (t * testing.T ) {
53
+ func TestReadQuotedFilename_Error (t * testing.T ) {
54
+ tests := []string {
55
+ `"` ,
56
+ `"\"` ,
57
+ `"\xxx"` ,
58
+ }
59
+ for _ , input := range tests {
60
+ _ , _ , err := readQuotedFilename (input )
61
+ if err == nil {
62
+ t .Errorf ("readQuotedFilename(`%s`): expected error" , input )
63
+ }
64
+ }
65
+ }
66
+
67
+ func TestParseDiffGitArgs_Success (t * testing.T ) {
54
68
tests := []string {
55
69
`aaa bbb` , "aaa" , "bbb" ,
56
70
`"aaa" bbb` , "aaa" , "bbb" ,
@@ -72,6 +86,28 @@ func TestParseDiffGitArgs(t *testing.T) {
72
86
}
73
87
}
74
88
89
+ func TestParseDiffGitArgs_Unsuccessful (t * testing.T ) {
90
+ tests := []string {
91
+ `` ,
92
+ `hello_world.txt` ,
93
+ `word ` ,
94
+ ` word` ,
95
+ `"a/bad_quoting b/bad_quoting` ,
96
+ `a/bad_quoting "b/bad_quoting` ,
97
+ `a/bad_quoting b/bad_quoting"` ,
98
+ `"a/bad_quoting b/bad_quoting"` ,
99
+ `"a/bad""b/bad"` ,
100
+ `"a/bad" "b/bad" "c/bad"` ,
101
+ `a/bad "b/bad" "c/bad"` ,
102
+ }
103
+ for _ , input := range tests {
104
+ success , first , second := parseDiffGitArgs (input )
105
+ if success {
106
+ t .Errorf ("`diff --git %s`: expected unsuccessful; got `%s` and `%s`" , input , first , second )
107
+ }
108
+ }
109
+ }
110
+
75
111
func TestParseHunkNoChunksize (t * testing.T ) {
76
112
filename := "sample_no_chunksize.diff"
77
113
diffData , err := ioutil .ReadFile (filepath .Join ("testdata" , filename ))
0 commit comments