2020-01-16 17:45:26 -07:00
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-05-09 06:54:23 -06:00
|
|
|
type data struct {
|
|
|
|
input, want string
|
2020-01-16 17:45:26 -07:00
|
|
|
}
|
|
|
|
|
2020-05-09 06:54:23 -06:00
|
|
|
func TestImportPrefix(t *testing.T) {
|
|
|
|
var tdata = []data{
|
2020-07-14 12:15:32 -06:00
|
|
|
{"package foo", "package foo"},
|
2020-05-09 06:54:23 -06:00
|
|
|
{"package foo\n", "package foo\n"},
|
|
|
|
{"package foo\n\nfunc f(){}\n", "package foo\n"},
|
|
|
|
{"package foo\n\nimport \"fmt\"\n", "package foo\n\nimport \"fmt\""},
|
|
|
|
{"package foo\nimport (\n\"fmt\"\n)\n", "package foo\nimport (\n\"fmt\"\n)"},
|
|
|
|
{"\n\n\npackage foo\n", "\n\n\npackage foo\n"},
|
|
|
|
{"// hi \n\npackage foo //xx\nfunc _(){}\n", "// hi \n\npackage foo //xx\n"},
|
|
|
|
{"package foo //hi\n", "package foo //hi\n"},
|
|
|
|
{"//hi\npackage foo\n//a\n\n//b\n", "//hi\npackage foo\n//a\n\n//b\n"},
|
2020-05-19 13:51:07 -06:00
|
|
|
{"package a\n\nimport (\n \"fmt\"\n)\n//hi\n",
|
|
|
|
"package a\n\nimport (\n \"fmt\"\n)\n//hi\n"},
|
2020-05-09 06:54:23 -06:00
|
|
|
}
|
|
|
|
for i, x := range tdata {
|
2020-05-19 13:51:07 -06:00
|
|
|
got := importPrefix([]byte(x.input))
|
2020-05-09 06:54:23 -06:00
|
|
|
if got != x.want {
|
2020-07-14 12:15:32 -06:00
|
|
|
t.Errorf("%d: got\n%q, wanted\n%q for %q", i, got, x.want, x.input)
|
2020-05-09 06:54:23 -06:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 17:45:26 -07:00
|
|
|
}
|