From ff14d442c9645c3ae955d2d433ba894d7668785c Mon Sep 17 00:00:00 2001 From: hjusforgues Date: Wed, 13 Jul 2016 13:50:58 +0700 Subject: [PATCH 1/3] Remove pointer-receivers for Marshalling func in bootstrap file --- bootstrap/bootstrap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index e9a1d21..3a83e94 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -59,11 +59,11 @@ func (g *Generator) writeStub() error { for _, t := range g.Types { fmt.Fprintln(f) if !g.NoStdMarshalers { - fmt.Fprintln(f, "func (*", t, ") MarshalJSON() ([]byte, error) { return nil, nil }") + fmt.Fprintln(f, "func (", t, ") MarshalJSON() ([]byte, error) { return nil, nil }") fmt.Fprintln(f, "func (*", t, ") UnmarshalJSON([]byte) error { return nil }") } - fmt.Fprintln(f, "func (*", t, ") MarshalEasyJSON(w *jwriter.Writer) {}") + fmt.Fprintln(f, "func (", t, ") MarshalEasyJSON(w *jwriter.Writer) {}") fmt.Fprintln(f, "func (*", t, ") UnmarshalEasyJSON(l *jlexer.Lexer) {}") fmt.Fprintln(f) fmt.Fprintln(f, "type EasyJSON_exporter_"+t+" *"+t) From d4d111339231b98aee2a3945b4e8f0571e831622 Mon Sep 17 00:00:00 2001 From: Victor Starodub Date: Wed, 13 Jul 2016 18:14:04 +0300 Subject: [PATCH 2/3] Fix flaky test. --- tests/data.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/data.go b/tests/data.go index d0e1e7a..1c4ae78 100644 --- a/tests/data.go +++ b/tests/data.go @@ -437,8 +437,9 @@ var mapsString = `{` + `}` type DeepNest struct { - SliceMap map[Str][]Str - MapSlice []map[Str]Str + SliceMap map[Str][]Str + SliceMap1 map[Str][]Str + MapSlice []map[Str]Str } var deepNestValue = DeepNest{ @@ -447,6 +448,8 @@ var deepNestValue = DeepNest{ "0", "1", }, + }, + SliceMap1: map[Str][]Str{ "testSliceMap2": nil, }, MapSlice: []map[Str]Str{ @@ -458,7 +461,9 @@ var deepNestValue = DeepNest{ var deepNestString = `{` + `"SliceMap":{` + - `"testSliceMap1":["0","1"],` + + `"testSliceMap1":["0","1"]` + + `},` + + `"SliceMap1":{` + `"testSliceMap2":[]` + `},` + `"MapSlice":[` + From 2b7d5bf36878e5f31ff9bbd098e3ae443f536e39 Mon Sep 17 00:00:00 2001 From: Vadim Petrov Date: Wed, 13 Jul 2016 18:17:55 +0300 Subject: [PATCH 3/3] Fix generating valid files with no types to marshal/unmarshal in file --- Makefile | 4 +++- bootstrap/bootstrap.go | 19 ++++++++++++------- gen/generator.go | 7 ++++++- tests/nothing.go | 3 +++ 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 tests/nothing.go diff --git a/Makefile b/Makefile index 420f306..39d52e3 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,11 @@ generate: root build .root/bin/easyjson -stubs \ .root/src/$(PKG)/tests/snake.go \ .root/src/$(PKG)/tests/data.go \ - .root/src/$(PKG)/tests/omitempty.go + .root/src/$(PKG)/tests/omitempty.go \ + .root/src/$(PKG)/tests/nothing.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go + .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go .root/bin/easyjson -snake_case .root/src/$(PKG)/tests/snake.go .root/bin/easyjson -omit_empty .root/src/$(PKG)/tests/omitempty.go .root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 3a83e94..04aaaad 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -50,11 +50,14 @@ func (g *Generator) writeStub() error { fmt.Fprintln(f, "// compilable during generation.") fmt.Fprintln(f) fmt.Fprintln(f, "package ", g.PkgName) - fmt.Fprintln(f) - fmt.Fprintln(f, "import (") - fmt.Fprintln(f, ` "`+pkgWriter+`"`) - fmt.Fprintln(f, ` "`+pkgLexer+`"`) - fmt.Fprintln(f, ")") + + if len(g.Types) > 0 { + fmt.Fprintln(f) + fmt.Fprintln(f, "import (") + fmt.Fprintln(f, ` "`+pkgWriter+`"`) + fmt.Fprintln(f, ` "`+pkgLexer+`"`) + fmt.Fprintln(f, ")") + } for _, t := range g.Types { fmt.Fprintln(f) @@ -90,8 +93,10 @@ func (g *Generator) writeMain() (path string, err error) { fmt.Fprintln(f, ` "os"`) fmt.Fprintln(f) fmt.Fprintf(f, " %q\n", genPackage) - fmt.Fprintln(f) - fmt.Fprintf(f, " pkg %q\n", g.PkgPath) + if len(g.Types) > 0 { + fmt.Fprintln(f) + fmt.Fprintf(f, " pkg %q\n", g.PkgPath) + } fmt.Fprintln(f, ")") fmt.Fprintln(f) fmt.Fprintln(f, "func main() {") diff --git a/gen/generator.go b/gen/generator.go index b6dc08e..8881063 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -156,7 +156,12 @@ func (g *Generator) printHeader() { fmt.Println(")") fmt.Println("") - fmt.Println("var _ = json.RawMessage{} // suppress unused package warning") + fmt.Println("// suppress unused package warning") + fmt.Println("var (") + fmt.Println(" _ = json.RawMessage{}") + fmt.Println(" _ = jlexer.Lexer{}") + fmt.Println(" _ = jwriter.Writer{}") + fmt.Println(")") fmt.Println() } diff --git a/tests/nothing.go b/tests/nothing.go new file mode 100644 index 0000000..35334f5 --- /dev/null +++ b/tests/nothing.go @@ -0,0 +1,3 @@ +package tests + +// No structs in this file