OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "encoding/json" | 8 "encoding/json" |
9 "fmt" | 9 "fmt" |
10 "testing" | 10 "testing" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 So(k1.Equal(k2), ShouldBeTrue) | 148 So(k1.Equal(k2), ShouldBeTrue) |
149 k3 := MakeKey("a", "n", "knd", 2) | 149 k3 := MakeKey("a", "n", "knd", 2) |
150 So(k1.Equal(k3), ShouldBeFalse) | 150 So(k1.Equal(k3), ShouldBeFalse) |
151 }) | 151 }) |
152 | 152 |
153 Convey("KeyString", t, func() { | 153 Convey("KeyString", t, func() { |
154 k1 := MakeKey("a", "n", "knd", 1, "other", "wat") | 154 k1 := MakeKey("a", "n", "knd", 1, "other", "wat") |
155 So(k1.String(), ShouldEqual, "a:n:/knd,1/other,\"wat\"") | 155 So(k1.String(), ShouldEqual, "a:n:/knd,1/other,\"wat\"") |
156 }) | 156 }) |
157 | 157 |
| 158 Convey("HasAncestor", t, func() { |
| 159 k1 := MakeKey("a", "n", "kind", 1) |
| 160 k2 := MakeKey("a", "n", "kind", 1, "other", "wat") |
| 161 k3 := MakeKey("a", "n", "kind", 1, "other", "wat", "extra", "dat
a") |
| 162 k4 := MakeKey("something", "n", "kind", 1) |
| 163 k5 := MakeKey("a", "n", "kind", 1, "other", "meep") |
| 164 |
| 165 So(k1.HasAncestor(k1), ShouldBeTrue) |
| 166 So(k1.HasAncestor(k2), ShouldBeFalse) |
| 167 So(k2.HasAncestor(k5), ShouldBeFalse) |
| 168 So(k5.HasAncestor(k2), ShouldBeFalse) |
| 169 So(k2.HasAncestor(k1), ShouldBeTrue) |
| 170 So(k3.HasAncestor(k2), ShouldBeTrue) |
| 171 So(k3.HasAncestor(k1), ShouldBeTrue) |
| 172 So(k3.HasAncestor(k4), ShouldBeFalse) |
| 173 }) |
| 174 |
158 Convey("*GenericKey supports json encoding", t, func() { | 175 Convey("*GenericKey supports json encoding", t, func() { |
159 type TestStruct struct { | 176 type TestStruct struct { |
160 Key *Key | 177 Key *Key |
161 } | 178 } |
162 t := &TestStruct{ | 179 t := &TestStruct{ |
163 NewKey("aid", "ns", "kind", "id", 0, | 180 NewKey("aid", "ns", "kind", "id", 0, |
164 NewKey("aid", "ns", "parent", "", 1, nil), | 181 NewKey("aid", "ns", "parent", "", 1, nil), |
165 )} | 182 )} |
166 d, err := json.Marshal(t) | 183 d, err := json.Marshal(t) |
167 So(err, ShouldBeNil) | 184 So(err, ShouldBeNil) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 240 } |
224 | 241 |
225 for i := 1; i < len(s); i++ { | 242 for i := 1; i < len(s); i++ { |
226 So(s[i-1], shouldBeLess, s[i]) | 243 So(s[i-1], shouldBeLess, s[i]) |
227 So(s[i-1], shouldNotBeEqual, s[i]) | 244 So(s[i-1], shouldNotBeEqual, s[i]) |
228 So(s[i], shouldNotBeEqual, s[i-1]) | 245 So(s[i], shouldNotBeEqual, s[i-1]) |
229 So(s[i], shouldNotBeLess, s[i-1]) | 246 So(s[i], shouldNotBeLess, s[i-1]) |
230 } | 247 } |
231 }) | 248 }) |
232 } | 249 } |
OLD | NEW |