| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package cmd |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"path/filepath" |
| 10 |
"strings" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
func TestSpanFormat(t *testing.T) { |
| 15 |
formats := []string{"%v", "%#v", "%+v"} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
for _, test := range [][]string{ |
| 23 |
{"C:/file_a", "C:/file_a", "file:///C:/file_a:#0"}, |
| 24 |
{"C:/file_b:1:2", "C:/file_b:1:2", "file:///C:/file_b:1:2"}, |
| 25 |
{"C:/file_c:1000", "C:/file_c:1000", "file:///C:/file_c:1000:1"}, |
| 26 |
{"C:/file_d:14:9", "C:/file_d:14:9", "file:///C:/file_d:14:9"}, |
| 27 |
{"C:/file_e:1:2-7", "C:/file_e:1:2-7", "file:///C:/file_e:1:2-1:7"}, |
| 28 |
{"C:/file_f:500-502", "C:/file_f:500-502", "file:///C:/file_f:500:1-502:1"}, |
| 29 |
{"C:/file_g:3:7-8", "C:/file_g:3:7-8", "file:///C:/file_g:3:7-3:8"}, |
| 30 |
{"C:/file_h:3:7-4:8", "C:/file_h:3:7-4:8", "file:///C:/file_h:3:7-4:8"}, |
| 31 |
{"C:/file_i:#100", "C:/file_i:#100", "file:///C:/file_i:#100"}, |
| 32 |
{"C:/file_j:#26-#28", "C:/file_j:#26-#28", "file:///C:/file_j:#26-0#28"}, |
| 33 |
{"C:/file_h:3:7#26-4:8#37", |
| 34 |
"C:/file_h:3:7-4:8", "C:/file_h:#26-#37", "file:///C:/file_h:3:7#26-4:8#37"}} { |
| 35 |
input := test[0] |
| 36 |
spn := parseSpan(input) |
| 37 |
wants := test[0:3] |
| 38 |
if len(test) == 4 { |
| 39 |
wants = test[1:4] |
| 40 |
} |
| 41 |
for i, format := range formats { |
| 42 |
want := toPath(wants[i]) |
| 43 |
if got := fmt.Sprintf(format, spn); got != want { |
| 44 |
t.Errorf("Sprintf(%q, %q) = %q, want %q", format, input, got, want) |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func toPath(value string) string { |
| 51 |
if strings.HasPrefix(value, "file://") { |
| 52 |
return value |
| 53 |
} |
| 54 |
return filepath.FromSlash(value) |
| 55 |
} |