Преглед изворни кода

goprotobuf: Assortment of small cleanups.

Some are some style improvements due to the new "error" type.
Others are gofmt-driven changes.
One is a small fix for recent changes to the go/printer library.

R=r
CC=golang-dev
http://codereview.appspot.com/5434078
David Symonds пре 14 година
родитељ
комит
5ed980c16f
4 измењених фајлова са 35 додато и 36 уклоњено
  1. 4 4
      compiler/generator/generator.go
  2. 1 1
      compiler/testdata/test.pb.go.golden
  3. 0 1
      proto/text_parser.go
  4. 30 30
      proto/text_parser_test.go

+ 4 - 4
compiler/generator/generator.go

@@ -48,9 +48,9 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
-	"goprotobuf.googlecode.com/hg/proto"
-	plugin "goprotobuf.googlecode.com/hg/compiler/plugin"
 	descriptor "goprotobuf.googlecode.com/hg/compiler/descriptor"
 	descriptor "goprotobuf.googlecode.com/hg/compiler/descriptor"
+	plugin "goprotobuf.googlecode.com/hg/compiler/plugin"
+	"goprotobuf.googlecode.com/hg/proto"
 )
 )
 
 
 // A Plugin provides functionality to add to the output during Go code generation,
 // A Plugin provides functionality to add to the output during Go code generation,
@@ -784,7 +784,7 @@ func (g *Generator) generate(file *FileDescriptor) {
 		return
 		return
 	}
 	}
 	g.Reset()
 	g.Reset()
-	_, err = (&printer.Config{printer.TabIndent | printer.UseSpaces, 8}).Fprint(g, fset, ast)
+	err = (&printer.Config{printer.TabIndent | printer.UseSpaces, 8}).Fprint(g, fset, ast)
 	if err != nil {
 	if err != nil {
 		g.Fail("generated Go source code could not be reformatted:", err.Error())
 		g.Fail("generated Go source code could not be reformatted:", err.Error())
 	}
 	}
@@ -846,7 +846,7 @@ func (g *Generator) generateImports() {
 		p.GenerateImports(g.file)
 		p.GenerateImports(g.file)
 		g.P()
 		g.P()
 	}
 	}
-	g.P("// Reference proto & math imports to suppress error if they are not otherwise used.")
+	g.P("// Reference proto and math imports to suppress error if they are not otherwise used.")
 	g.P("var _ = ", g.ProtoPkg, ".GetString")
 	g.P("var _ = ", g.ProtoPkg, ".GetString")
 	g.P("var _ = math.Inf")
 	g.P("var _ = math.Inf")
 	g.P()
 	g.P()

+ 1 - 1
compiler/testdata/test.pb.go.golden

@@ -8,7 +8,7 @@ import "math"
 import imp1 "imp.pb"
 import imp1 "imp.pb"
 // discarding unused import multitest2 "multi1.pb"
 // discarding unused import multitest2 "multi1.pb"
 
 
-// Reference proto & math imports to suppress error if they are not otherwise used.
+// Reference proto and math imports to suppress error if they are not otherwise used.
 var _ = proto.GetString
 var _ = proto.GetString
 var _ = math.Inf
 var _ = math.Inf
 
 

+ 0 - 1
proto/text_parser.go

@@ -40,7 +40,6 @@ import (
 	"strconv"
 	"strconv"
 )
 )
 
 
-// ParseError satisfies the error interface.
 type ParseError struct {
 type ParseError struct {
 	Message string
 	Message string
 	Line    int // 1-based line number
 	Line    int // 1-based line number

+ 30 - 30
proto/text_parser_test.go

@@ -32,16 +32,16 @@
 package proto_test
 package proto_test
 
 
 import (
 import (
-	. "goprotobuf.googlecode.com/hg/proto"
 	. "./testdata/_obj/test_proto"
 	. "./testdata/_obj/test_proto"
+	. "goprotobuf.googlecode.com/hg/proto"
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
 )
 )
 
 
 type UnmarshalTextTest struct {
 type UnmarshalTextTest struct {
-	in    string
-	error string // if "", no error expected
-	out   *MyMessage
+	in  string
+	err string // if "", no error expected
+	out *MyMessage
 }
 }
 
 
 var unMarshalTextTests = []UnmarshalTextTest{
 var unMarshalTextTests = []UnmarshalTextTest{
@@ -74,44 +74,44 @@ var unMarshalTextTests = []UnmarshalTextTest{
 
 
 	// Bad quoted string
 	// Bad quoted string
 	{
 	{
-		in:    `inner: < host: "\0" >` + "\n",
-		error: `line 1.15: invalid quoted string "\0"`,
+		in:  `inner: < host: "\0" >` + "\n",
+		err: `line 1.15: invalid quoted string "\0"`,
 	},
 	},
 
 
 	// Number too large for int64
 	// Number too large for int64
 	{
 	{
-		in:    "count: 123456789012345678901",
-		error: "line 1.7: invalid int32: 123456789012345678901",
+		in:  "count: 123456789012345678901",
+		err: "line 1.7: invalid int32: 123456789012345678901",
 	},
 	},
 
 
 	// Number too large for int32
 	// Number too large for int32
 	{
 	{
-		in:    "count: 1234567890123",
-		error: "line 1.7: invalid int32: 1234567890123",
+		in:  "count: 1234567890123",
+		err: "line 1.7: invalid int32: 1234567890123",
 	},
 	},
 
 
 	// Number too large for float32
 	// Number too large for float32
 	{
 	{
-		in:    "others:< weight: 12345678901234567890123456789012345678901234567890 >",
-		error: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
+		in:  "others:< weight: 12345678901234567890123456789012345678901234567890 >",
+		err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
 	},
 	},
 
 
 	// Number posing as a quoted string
 	// Number posing as a quoted string
 	{
 	{
-		in:    `inner: < host: 12 >` + "\n",
-		error: `line 1.15: invalid string: 12`,
+		in:  `inner: < host: 12 >` + "\n",
+		err: `line 1.15: invalid string: 12`,
 	},
 	},
 
 
 	// Quoted string posing as int32
 	// Quoted string posing as int32
 	{
 	{
-		in:    `count: "12"`,
-		error: `line 1.7: invalid int32: "12"`,
+		in:  `count: "12"`,
+		err: `line 1.7: invalid int32: "12"`,
 	},
 	},
 
 
 	// Quoted string posing a float32
 	// Quoted string posing a float32
 	{
 	{
-		in:    `others:< weight: "17.4" >`,
-		error: `line 1.17: invalid float32: "17.4"`,
+		in:  `others:< weight: "17.4" >`,
+		err: `line 1.17: invalid float32: "17.4"`,
 	},
 	},
 
 
 	// Enum
 	// Enum
@@ -159,26 +159,26 @@ var unMarshalTextTests = []UnmarshalTextTest{
 
 
 	// Missing colon for string field
 	// Missing colon for string field
 	{
 	{
-		in:    `name "Dave"`,
-		error: `line 1.5: expected ':', found "\"Dave\""`,
+		in:  `name "Dave"`,
+		err: `line 1.5: expected ':', found "\"Dave\""`,
 	},
 	},
 
 
 	// Missing colon for int32 field
 	// Missing colon for int32 field
 	{
 	{
-		in:    `count 42`,
-		error: `line 1.6: expected ':', found "42"`,
+		in:  `count 42`,
+		err: `line 1.6: expected ':', found "42"`,
 	},
 	},
 
 
 	// Missing required field
 	// Missing required field
 	{
 	{
-		in:    ``,
-		error: `line 1.0: message test_proto.MyMessage missing required field "count"`,
+		in:  ``,
+		err: `line 1.0: message test_proto.MyMessage missing required field "count"`,
 	},
 	},
 
 
 	// Repeated non-repeated field
 	// Repeated non-repeated field
 	{
 	{
-		in:    `name: "Rob" name: "Russ"`,
-		error: `line 1.12: non-repeated field "name" was repeated`,
+		in:  `name: "Rob" name: "Russ"`,
+		err: `line 1.12: non-repeated field "name" was repeated`,
 	},
 	},
 
 
 	// Group
 	// Group
@@ -247,7 +247,7 @@ func TestUnmarshalText(t *testing.T) {
 	for i, test := range unMarshalTextTests {
 	for i, test := range unMarshalTextTests {
 		pb := new(MyMessage)
 		pb := new(MyMessage)
 		err := UnmarshalText(test.in, pb)
 		err := UnmarshalText(test.in, pb)
-		if test.error == "" {
+		if test.err == "" {
 			// We don't expect failure.
 			// We don't expect failure.
 			if err != nil {
 			if err != nil {
 				t.Errorf("Test %d: Unexpected error: %v", i, err)
 				t.Errorf("Test %d: Unexpected error: %v", i, err)
@@ -258,10 +258,10 @@ func TestUnmarshalText(t *testing.T) {
 		} else {
 		} else {
 			// We do expect failure.
 			// We do expect failure.
 			if err == nil {
 			if err == nil {
-				t.Errorf("Test %d: Didn't get expected error: %v", i, test.error)
-			} else if err.Error() != test.error {
+				t.Errorf("Test %d: Didn't get expected error: %v", i, test.err)
+			} else if err.Error() != test.err {
 				t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
 				t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
-					i, err, test.error)
+					i, err.Error(), test.err)
 			}
 			}
 		}
 		}
 	}
 	}