Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Unified Diff: context/context_test.go

Issue 104480044: code review 104480044: go.net/context: remove the Key type; replace it with st... (Closed)
Patch Set: diff -r 28ff664507e4 https://code.google.com/p/go.net Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « context/context.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: context/context_test.go
===================================================================
--- a/context/context_test.go
+++ b/context/context_test.go
@@ -249,41 +249,55 @@
}
}
-var k1, k2 = NewKey("k1"), NewKey("k2")
+type key1 int
+type key2 int
+
+var k1 = key1(1)
+var k2 = key2(1) // same int as k1, different type
+var k3 = key2(3) // same type as k2, different int
func TestValues(t *testing.T) {
- check := func(c Context, nm, v1, v2 string) {
+ check := func(c Context, nm, v1, v2, v3 string) {
if v, ok := c.Value(k1).(string); ok == (len(v1) == 0) || v != v1 {
t.Errorf(`%s.Value(k1).(string) = %q, %t want %q, %t`, nm, v, ok, v1, len(v1) != 0)
}
if v, ok := c.Value(k2).(string); ok == (len(v2) == 0) || v != v2 {
t.Errorf(`%s.Value(k2).(string) = %q, %t want %q, %t`, nm, v, ok, v2, len(v2) != 0)
}
+ if v, ok := c.Value(k3).(string); ok == (len(v3) == 0) || v != v3 {
+ t.Errorf(`%s.Value(k3).(string) = %q, %t want %q, %t`, nm, v, ok, v3, len(v3) != 0)
+ }
}
c0 := Background()
- check(c0, "c0", "", "")
+ check(c0, "c0", "", "", "")
c1 := WithValue(nil, k1, "c1k1")
- check(c1, "c1", "c1k1", "")
+ check(c1, "c1", "c1k1", "", "")
c2 := WithValue(c1, k2, "c2k2")
- check(c2, "c2", "c1k1", "c2k2")
+ check(c2, "c2", "c1k1", "c2k2", "")
- c3 := WithValue(c2, k1, nil)
- check(c3, "c3", "", "c2k2")
+ c3 := WithValue(c2, k3, "c3k3")
+ check(c3, "c2", "c1k1", "c2k2", "c3k3")
+
+ c4 := WithValue(c3, k1, nil)
+ check(c4, "c4", "", "c2k2", "c3k3")
o0 := otherContext{Background()}
- check(o0, "o0", "", "")
+ check(o0, "o0", "", "", "")
o1 := otherContext{WithValue(nil, k1, "c1k1")}
- check(o1, "o1", "c1k1", "")
+ check(o1, "o1", "c1k1", "", "")
o2 := WithValue(o1, k2, "o2k2")
- check(o2, "o2", "c1k1", "o2k2")
+ check(o2, "o2", "c1k1", "o2k2", "")
- o3 := otherContext{c3}
- check(o3, "o3", "", "c2k2")
+ o3 := otherContext{c4}
+ check(o3, "o3", "", "c2k2", "c3k3")
+
+ o4 := WithValue(o3, k3, nil)
+ check(o4, "o4", "", "c2k2", "")
}
func TestAllocs(t *testing.T) {
« no previous file with comments | « context/context.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b