git.sr.ht/~sircmpwn/gqlgen@v0.0.0-20200522192042-c84d29a1c940/internal/rewrite/rewriter_test.go (about) 1 package rewrite 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestRewriter(t *testing.T) { 11 t.Run("default", func(t *testing.T) { 12 r, err := New("git.sr.ht/~sircmpwn/gqlgen/internal/rewrite/testdata") 13 require.NoError(t, err) 14 15 body := r.GetMethodBody("Foo", "Method") 16 require.Equal(t, ` 17 // leading comment 18 19 // field comment 20 m.Field++ 21 22 // trailing comment 23 `, body) 24 25 imps := r.ExistingImports("testdata/example.go") 26 require.Len(t, imps, 2) 27 assert.Equal(t, []Import{ 28 { 29 Alias: "", 30 ImportPath: "fmt", 31 }, 32 { 33 Alias: "lol", 34 ImportPath: "bytes", 35 }, 36 }, imps) 37 38 }) 39 40 t.Run("out of scope dir", func(t *testing.T) { 41 _, err := New("../../../out-of-gomod/package") 42 require.Error(t, err) 43 }) 44 }