aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec_test.go
diff options
context:
space:
mode:
authorAriel Mashraki <ariel@mashraki.co.il>2019-09-06 18:04:51 +0300
committerRob Pike <r@golang.org>2019-09-25 09:13:11 +0000
commit95cbcc5c1c5db05e659b769784e57db777c4cd6a (patch)
treea028407ef631d037c48274e4495d02c2840745f7 /src/text/template/exec_test.go
parent434e4caf1b93530b225494ba30d9e39ba15ecf4f (diff)
downloadgo-95cbcc5c1c5db05e659b769784e57db777c4cd6a.tar.xz
text/template: support all comparable types in eq
Extends the built-in eq function to support all Go comparable types. Fixes #33740 Change-Id: I522310e313e251c4dc6a013d33d7c2034fe2ec8e Reviewed-on: https://go-review.googlesource.com/c/go/+/193837 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/exec_test.go')
-rw-r--r--src/text/template/exec_test.go36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
index 81f9e04476..7f2305ace0 100644
--- a/src/text/template/exec_test.go
+++ b/src/text/template/exec_test.go
@@ -1156,19 +1156,41 @@ var cmpTests = []cmpTest{
{"ge .Uthree .NegOne", "true", true},
{"eq (index `x` 0) 'x'", "true", true}, // The example that triggered this rule.
{"eq (index `x` 0) 'y'", "false", true},
+ {"eq .V1 .V2", "true", true},
+ {"eq .Ptr .Ptr", "true", true},
+ {"eq .Ptr .NilPtr", "false", true},
+ {"eq .NilPtr .NilPtr", "true", true},
+ {"eq .Iface1 .Iface1", "true", true},
+ {"eq .Iface1 .Iface2", "false", true},
+ {"eq .Iface2 .Iface2", "true", true},
// Errors
- {"eq `xy` 1", "", false}, // Different types.
- {"eq 2 2.0", "", false}, // Different types.
- {"lt true true", "", false}, // Unordered types.
- {"lt 1+0i 1+0i", "", false}, // Unordered types.
+ {"eq `xy` 1", "", false}, // Different types.
+ {"eq 2 2.0", "", false}, // Different types.
+ {"lt true true", "", false}, // Unordered types.
+ {"lt 1+0i 1+0i", "", false}, // Unordered types.
+ {"eq .Ptr 1", "", false}, // Incompatible types.
+ {"eq .Ptr .NegOne", "", false}, // Incompatible types.
+ {"eq .Map .Map", "", false}, // Uncomparable types.
+ {"eq .Map .V1", "", false}, // Uncomparable types.
}
func TestComparison(t *testing.T) {
b := new(bytes.Buffer)
var cmpStruct = struct {
- Uthree, Ufour uint
- NegOne, Three int
- }{3, 4, -1, 3}
+ Uthree, Ufour uint
+ NegOne, Three int
+ Ptr, NilPtr *int
+ Map map[int]int
+ V1, V2 V
+ Iface1, Iface2 fmt.Stringer
+ }{
+ Uthree: 3,
+ Ufour: 4,
+ NegOne: -1,
+ Three: 3,
+ Ptr: new(int),
+ Iface1: b,
+ }
for _, test := range cmpTests {
text := fmt.Sprintf("{{if %s}}true{{else}}false{{end}}", test.expr)
tmpl, err := New("empty").Parse(text)