Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Unified Diff: render/render_test.go

Issue 1716743002: Better rendering for implicit types. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/go-render.git@master
Patch Set: Normalize copyright Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « render/render.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: render/render_test.go
diff --git a/render/render_test.go b/render/render_test.go
index 1737cb702aed78b0da5a64dce45a697df2670dd8..bb2af4b8a63a7bae2cac79e202b931abdcd90523 100644
--- a/render/render_test.go
+++ b/render/render_test.go
@@ -1,4 +1,4 @@
-// Copyright 2015 Google Inc. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@ package render
import (
"bytes"
"fmt"
+ "reflect"
"regexp"
"runtime"
"testing"
@@ -81,7 +82,7 @@ func TestRenderList(t *testing.T) {
{struct {
a int
b string
- }{123, "foo"}, `struct { a int; b string }{a:123, b:"foo"}`},
+ }{123, "foo"}, `struct { a int; b string }{123, "foo"}`},
{[]string{"foo", "foo", "bar", "baz", "qux", "qux"},
`[]string{"foo", "foo", "bar", "baz", "qux", "qux"}`},
{[...]int{1, 2, 3}, `[3]int{1, 2, 3}`},
@@ -133,14 +134,48 @@ func TestRenderRecursiveMap(t *testing.T) {
v := []map[string]interface{}{m, m}
assertRendersLike(t, "Recursive map", v,
- `[]map[string]interface{}{map[string]interface{}{`+
+ `[]map[string]interface{}{{`+
`"bar":[]*string{(*string)("foo"), (*string)("foo")}, `+
- `"foo":<REC(map[string]interface{})>}, `+
- `map[string]interface{}{`+
+ `"foo":<REC(map[string]interface{})>}, {`+
`"bar":[]*string{(*string)("foo"), (*string)("foo")}, `+
`"foo":<REC(map[string]interface{})>}}`)
}
+func TestRenderImplicitType(t *testing.T) {
+ type namedStruct struct{ a, b int }
+ type namedInt int
+
+ tcs := []struct {
+ in interface{}
+ expect string
+ }{
+ {
+ []struct{ a, b int }{{1, 2}},
+ "[]struct { a int; b int }{{1, 2}}",
+ },
+ {
+ map[string]struct{ a, b int }{"hi": {1, 2}},
+ `map[string]struct { a int; b int }{"hi":{1, 2}}`,
+ },
+ {
+ map[namedInt]struct{}{10: {}},
+ `map[render.namedInt]struct {}{10:{}}`,
+ },
+ {
+ struct{ a, b int }{1, 2},
+ `struct { a int; b int }{1, 2}`,
+ },
+ {
+ namedStruct{1, 2},
+ "render.namedStruct{a:1, b:2}",
+ },
+ }
+
+ for _, tc := range tcs {
+ assertRendersLike(t, reflect.TypeOf(tc.in).String(), tc.in, tc.expect)
+ }
+}
+
func ExampleInReadme() {
type customType int
type testStruct struct {
« no previous file with comments | « render/render.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698