Skip to content

Commit 3af828f

Browse files
committedAug 22, 2020
updates to tests to ensure comments are working correctly
1 parent 08eadf7 commit 3af828f

File tree

12 files changed

+41
-81
lines changed

12 files changed

+41
-81
lines changed
 

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ type GreetRequest struct {
4141
Name string
4242
}
4343

44-
// GreetResponse is the response object for GreeterService.Greet.
44+
// GreetResponse is the response object containing a
45+
// person's greeting.
4546
type GreetResponse struct {
4647
// Greeting is the greeting that was generated.
4748
// example: "Hello Mat Ryer"

‎example/def/greeter_service.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type GreetRequest struct {
1212
Name string
1313
}
1414

15-
// GreetResponse is the response object for GreeterService.Greet.
15+
// GreetResponse is the response object containing a
16+
// person's greeting.
1617
type GreetResponse struct {
1718
// Greeting is a nice message welcoming somebody.
1819
Greeting string

‎example/server.gen.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go.mod

+1-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@ replace github.com/pacedotdev/oto/parser => ./parser
77
require (
88
github.com/dustin/go-humanize v1.0.0
99
github.com/fatih/structtag v1.2.0
10-
github.com/gobuffalo/envy v1.9.0 // indirect
11-
github.com/gobuffalo/flect v0.2.1 // indirect
1210
github.com/gobuffalo/helpers v0.6.1 // indirect
1311
github.com/gobuffalo/plush v3.8.3+incompatible
1412
github.com/gobuffalo/tags v2.1.7+incompatible // indirect
15-
github.com/gobuffalo/validate/v3 v3.3.0 // indirect
16-
github.com/gofrs/uuid v3.3.0+incompatible // indirect
1713
github.com/markbates/inflect v1.0.4
1814
github.com/matryer/is v1.4.0
19-
github.com/microcosm-cc/bluemonday v1.0.3 // indirect
20-
github.com/pacedotdev/oto/parser v0.0.0-00010101000000-000000000000
2115
github.com/pkg/errors v0.9.1
22-
github.com/rogpeppe/go-internal v1.6.0 // indirect
23-
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
24-
golang.org/x/tools v0.0.0-20200820180210-c8f393745106
16+
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b
2517
)

‎go.sum

+5-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
2-
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
3-
github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU=
4-
github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
51
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
62
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
73
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -13,11 +9,8 @@ github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4
139
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
1410
github.com/gobuffalo/envy v1.6.5 h1:X3is06x7v0nW2xiy2yFbbIjwHz57CD6z6MkvqULTCm8=
1511
github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
16-
github.com/gobuffalo/envy v1.9.0 h1:eZR0DuEgVLfeIb1zIKt3bT4YovIMf9O9LXQeCZLXpqE=
17-
github.com/gobuffalo/envy v1.9.0/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
12+
github.com/gobuffalo/flect v0.2.0 h1:EWCvMGGxOjsgwlWaP+f4+Hh6yrrte7JeFL2S6b+0hdM=
1813
github.com/gobuffalo/flect v0.2.0/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80=
19-
github.com/gobuffalo/flect v0.2.1 h1:GPoRjEN0QObosV4XwuoWvSd5uSiL0N3e91/xqyY4crQ=
20-
github.com/gobuffalo/flect v0.2.1/go.mod h1:vmkQwuZYhN5Pc4ljYQZzP+1sq+NEkK+lh20jmEmX3jc=
2114
github.com/gobuffalo/github_flavored_markdown v1.1.0 h1:8Zzj4fTRl/OP2R7sGerzSf6g2nEJnaBEJe7UAOiEvbQ=
2215
github.com/gobuffalo/github_flavored_markdown v1.1.0/go.mod h1:TSpTKWcRTI0+v7W3x8dkSKMLJSUpuVitlptCkpeY8ic=
2316
github.com/gobuffalo/helpers v0.6.1 h1:LLcL4BsiyDQYtMRUUpyFdBFvFXQ6hNYOpwrcYeilVWM=
@@ -30,14 +23,8 @@ github.com/gobuffalo/tags/v3 v3.1.0 h1:mzdCYooN2VsLRr8KIAdEZ1lh1Py7JSMsiEGCGata2
3023
github.com/gobuffalo/tags/v3 v3.1.0/go.mod h1:ZQeN6TCTiwAFnS0dNcbDtSgZDwNKSpqajvVtt6mlYpA=
3124
github.com/gobuffalo/validate/v3 v3.0.0 h1:dF7Bg8NMF9Zv8bZvUMXYJXxZdj+eSZ8z/lGM7/jVFUE=
3225
github.com/gobuffalo/validate/v3 v3.0.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
33-
github.com/gobuffalo/validate/v3 v3.3.0 h1:j++FFx9gtjTmIQeI9xlaIDZ0nV4x8YQZz4RJAlZNUxg=
34-
github.com/gobuffalo/validate/v3 v3.3.0/go.mod h1:HFpjq+AIiA2RHoQnQVTFKF/ZpUPXwyw82LgyDPxQ9r0=
3526
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
3627
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
37-
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
38-
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
39-
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
40-
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
4128
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
4229
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
4330
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -51,15 +38,10 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
5138
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
5239
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
5340
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
54-
github.com/microcosm-cc/bluemonday v1.0.3 h1:EjVH7OqbU219kdm8acbveoclh2zZFqPJTJw6VUlTLAQ=
55-
github.com/microcosm-cc/bluemonday v1.0.3/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
5641
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
5742
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5843
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5944
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
60-
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
61-
github.com/rogpeppe/go-internal v1.6.0 h1:IZRgg4sfrDH7nsAD1Y/Nwj+GzIfEwpJSLjCaNC3SbsI=
62-
github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
6345
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
6446
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
6547
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
@@ -69,6 +51,7 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
6951
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
7052
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
7153
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
54+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
7255
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
7356
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7457
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
@@ -85,9 +68,8 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
8568
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
8669
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8770
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
71+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
8872
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
89-
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
90-
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
9173
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
9274
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9375
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
@@ -97,20 +79,15 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
9779
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9880
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
9981
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
100-
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d h1:hYhnolbefSSt3WZp66sgmgnEOFv5PD6a5PIcnKJ8jdU=
101-
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
102-
golang.org/x/tools v0.0.0-20200820180210-c8f393745106 h1:42Zs/g7pjhSIE/wiAuKcp8zp20zv7W2diNU6arpshOA=
103-
golang.org/x/tools v0.0.0-20200820180210-c8f393745106/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
82+
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b h1:ob2Rprc4uPVPGKaYKm9lrGewYQJRu7KtuzGTICCM1X4=
83+
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
10484
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10585
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10686
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
10787
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10888
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
109-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
110-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11189
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
11290
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
113-
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
11491
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
11592
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
11693
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=

‎parser/go.mod

-9
This file was deleted.

‎parser/go.sum

-26
This file was deleted.

‎parser/parser.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func New(patterns ...string) *Parser {
146146
// Parse parses the files specified, returning the definition.
147147
func (p *Parser) Parse() (Definition, error) {
148148
cfg := &packages.Config{
149-
Mode: packages.NeedTypes | packages.NeedDeps | packages.NeedName | packages.NeedSyntax,
149+
Mode: packages.NeedTypes | packages.NeedName | packages.NeedTypesInfo | packages.NeedDeps | packages.NeedName | packages.NeedSyntax,
150150
Tests: false,
151151
}
152152
pkgs, err := packages.Load(cfg, p.patterns...)
@@ -161,7 +161,6 @@ func (p *Parser) Parse() (Definition, error) {
161161
if err != nil {
162162
panic(err)
163163
}
164-
165164
p.def.PackageName = pkg.Name
166165
scope := pkg.Types.Scope()
167166
for _, name := range scope.Names() {
@@ -541,7 +540,7 @@ func (p *Parser) extractCommentMetadata(comment string) (map[string]interface{},
541540
var val interface{}
542541
if err := json.Unmarshal([]byte(value), &val); err != nil {
543542
if p.Verbose {
544-
fmt.Printf("(skipping) failed to marshal JSON value (%s): %s", err, value)
543+
fmt.Printf("(skipping) failed to marshal JSON value (%s): %s\n", err, value)
545544
}
546545
continue
547546
}

‎parser/parser_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package parser
22

33
import (
4+
"bytes"
5+
"go/doc"
6+
"strings"
47
"testing"
58

69
"github.com/matryer/is"
@@ -10,6 +13,7 @@ func TestParse(t *testing.T) {
1013
is := is.New(t)
1114
patterns := []string{"./testdata/services/pleasantries"}
1215
parser := New(patterns...)
16+
parser.Verbose = testing.Verbose()
1317
parser.ExcludeInterfaces = []string{"Ignorer"}
1418
def, err := parser.Parse()
1519
is.NoErr(err)
@@ -43,6 +47,16 @@ You will love it.`)
4347
is.Equal(def.Services[0].Methods[1].OutputObject.Multiple, false)
4448
is.Equal(def.Services[0].Methods[1].OutputObject.Package, "")
4549

50+
formatCommentText := func(s string) string {
51+
var buf bytes.Buffer
52+
doc.ToText(&buf, s, "// ", "", 80)
53+
return buf.String()
54+
}
55+
greetResponseObject, err := def.Object(def.Services[0].Methods[1].OutputObject.TypeName)
56+
is.NoErr(err)
57+
actualComment := strings.TrimSpace(formatCommentText(greetResponseObject.Comment))
58+
is.Equal(actualComment, `// GreetResponse is the response object containing a person's greeting.`)
59+
4660
greetInputObject, err := def.Object(def.Services[0].Methods[0].InputObject.TypeName)
4761
is.NoErr(err)
4862
is.Equal(greetInputObject.Name, "GetGreetingsRequest")
@@ -169,6 +183,7 @@ func TestExtractCommentMetadata(t *testing.T) {
169183
is := is.New(t)
170184

171185
p := &Parser{}
186+
p.Verbose = testing.Verbose()
172187
metadata, comment, err := p.extractCommentMetadata(`
173188
This is a comment
174189
example: "With an example"

‎parser/testdata/services/pleasantries/greeter.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ type GreetRequest struct {
2323
Names []string
2424
}
2525

26-
// GreetResponse is the response object for GreeterService.Greet.
26+
// GreetResponse is the response object containing a
27+
// person's greeting.
2728
type GreetResponse struct {
28-
// Greeting is the generated Greeting.
29+
// Greeting is the greeted person's Greeting.
2930
Greeting Greeting
3031
}
3132

‎render/render_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ func TestFormatTags(t *testing.T) {
6767
is.Equal(trimBackticks(string(tagStr)), `json:"field,omitempty" monkey:"true"`)
6868

6969
}
70+
71+
func TestFormatCommentText(t *testing.T) {
72+
is := is.New(t)
73+
74+
actual := strings.TrimSpace(formatCommentText("card's"))
75+
is.Equal(actual, "// card's")
76+
}

‎testdata/services/pleasantries/greeter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ type GreetRequest struct {
2323
Names []string
2424
}
2525

26-
// GreetResponse is the response object for GreeterService.Greet.
26+
// GreetResponse is the response object containing a
27+
// person's greeting.
2728
type GreetResponse struct {
2829
// Greeting is the generated Greeting.
2930
Greeting Greeting

0 commit comments

Comments
 (0)
Please sign in to comment.