Skip to content

Commit

Permalink
Added BinaryExpr logic with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostiam committed Sep 6, 2023
1 parent b1ab76a commit 6e63dcc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ func (c *Checker) Check(expr ast.Expr) {
c.Check(x.Index)
c.write("]")

case *ast.BinaryExpr:
c.Check(x.X)
c.write(" ")
c.write(x.Op.String())
c.write(" ")
c.Check(x.Y)

default:
c.err = fmt.Errorf("checker not implemented for type: %s", reflect.TypeOf(x))
}
Expand Down
6 changes: 6 additions & 0 deletions testdata/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func testInvalid(t *proto.Test) {

other := proto.Other{}
_ = other.MyMethod(nil).S // want "proto field read without getter:"

ems := t.RepeatedEmbeddeds // want "proto field read without getter:"
_ = ems[len(ems)-1].S // want "proto field read without getter:"
}

func testValid(t *proto.Test) {
Expand Down Expand Up @@ -113,4 +116,7 @@ func testValid(t *proto.Test) {
var tt Test
_ = tt.Embedded.GetS()
_ = tt.Embedded.GetEmbedded().GetS()

ems := t.GetRepeatedEmbeddeds()
_ = ems[len(ems)-1].GetS()
}
6 changes: 6 additions & 0 deletions testdata/test.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func testInvalid(t *proto.Test) {

other := proto.Other{}
_ = other.MyMethod(nil).GetS() // want "proto field read without getter:"

ems := t.GetRepeatedEmbeddeds() // want "proto field read without getter:"
_ = ems[len(ems)-1].GetS() // want "proto field read without getter:"
}

func testValid(t *proto.Test) {
Expand Down Expand Up @@ -113,4 +116,7 @@ func testValid(t *proto.Test) {
var tt Test
_ = tt.Embedded.GetS()
_ = tt.Embedded.GetEmbedded().GetS()

ems := t.GetRepeatedEmbeddeds()
_ = ems[len(ems)-1].GetS()
}

0 comments on commit 6e63dcc

Please sign in to comment.