| 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         "fmt" | 
| 8         "math" | 9         "math" | 
|  | 10         "sort" | 
| 9         "testing" | 11         "testing" | 
| 10         "time" | 12         "time" | 
| 11 | 13 | 
| 12         "github.com/luci/gae/service/blobstore" | 14         "github.com/luci/gae/service/blobstore" | 
| 13         . "github.com/smartystreets/goconvey/convey" | 15         . "github.com/smartystreets/goconvey/convey" | 
| 14 ) | 16 ) | 
| 15 | 17 | 
| 16 type myint int | 18 type myint int | 
| 17 type mybool bool | 19 type mybool bool | 
| 18 type mystring string | 20 type mystring string | 
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 211                         Convey("errors", func() { | 213                         Convey("errors", func() { | 
| 212 | 214 | 
| 213                                 Convey("weird value", func() { | 215                                 Convey("weird value", func() { | 
| 214                                         pm := PropertyMap{} | 216                                         pm := PropertyMap{} | 
| 215                                         So(pm.SetMeta("sup", complex(100, 20)), 
     ShouldBeFalse) | 217                                         So(pm.SetMeta("sup", complex(100, 20)), 
     ShouldBeFalse) | 
| 216                                 }) | 218                                 }) | 
| 217                         }) | 219                         }) | 
| 218                 }) | 220                 }) | 
| 219         }) | 221         }) | 
| 220 } | 222 } | 
|  | 223 | 
|  | 224 func TestByteSequences(t *testing.T) { | 
|  | 225         t.Parallel() | 
|  | 226 | 
|  | 227         conversions := []struct { | 
|  | 228                 desc string | 
|  | 229                 conv func(v string) (byteSequence, interface{}) | 
|  | 230         }{ | 
|  | 231                 {"string", func(v string) (byteSequence, interface{}) { return s
     tringByteSequence(v), v }}, | 
|  | 232                 {"[]byte", func(v string) (byteSequence, interface{}) { return b
     ytesByteSequence(v), []byte(v) }}, | 
|  | 233         } | 
|  | 234 | 
|  | 235         testCases := map[string][]struct { | 
|  | 236                 assertion func(interface{}, ...interface{}) string | 
|  | 237                 cmpS      string | 
|  | 238         }{ | 
|  | 239                 "": { | 
|  | 240                         {ShouldEqual, ""}, | 
|  | 241                         {ShouldBeLessThan, "foo"}, | 
|  | 242                 }, | 
|  | 243                 "bar": { | 
|  | 244                         {ShouldEqual, "bar"}, | 
|  | 245                         {ShouldBeGreaterThan, "ba"}, | 
|  | 246                 }, | 
|  | 247                 "ba": { | 
|  | 248                         {ShouldBeLessThan, "bar"}, | 
|  | 249                         {ShouldBeLessThan, "z"}, | 
|  | 250                 }, | 
|  | 251                 "foo": { | 
|  | 252                         {ShouldBeGreaterThan, ""}, | 
|  | 253                 }, | 
|  | 254                 "bz": { | 
|  | 255                         {ShouldBeGreaterThan, "bar"}, | 
|  | 256                 }, | 
|  | 257                 "qux": { | 
|  | 258                         {ShouldBeGreaterThan, "bar"}, | 
|  | 259                 }, | 
|  | 260         } | 
|  | 261 | 
|  | 262         keys := make([]string, 0, len(testCases)) | 
|  | 263         for k := range testCases { | 
|  | 264                 keys = append(keys, k) | 
|  | 265         } | 
|  | 266         sort.Strings(keys) | 
|  | 267 | 
|  | 268         Convey(`When testing byte sequences`, t, func() { | 
|  | 269                 for _, s := range keys { | 
|  | 270                         for _, c := range conversions { | 
|  | 271                                 Convey(fmt.Sprintf(`A %s sequence with test data
      %q`, c.desc, s), func() { | 
|  | 272                                         bs, effectiveValue := c.conv(s) | 
|  | 273 | 
|  | 274                                         Convey(`Basic stuff works.`, func() { | 
|  | 275                                                 So(bs.len(), ShouldEqual, len(s)
     ) | 
|  | 276                                                 for i, c := range s { | 
|  | 277                                                         So(bs.get(i), ShouldEqua
     l, c) | 
|  | 278                                                 } | 
|  | 279                                                 So(bs.value(), ShouldResemble, e
     ffectiveValue) | 
|  | 280                                                 So(bs.string(), ShouldEqual, s) | 
|  | 281                                                 So(bs.bytes(), ShouldResemble, [
     ]byte(s)) | 
|  | 282                                         }) | 
|  | 283 | 
|  | 284                                         // Test comparison with other byteSequen
     ce types. | 
|  | 285                                         for _, tc := range testCases[s] { | 
|  | 286                                                 for _, c := range conversions { | 
|  | 287                                                         Convey(fmt.Sprintf(`Comp
     ares properly with %s %q`, c.desc, tc.cmpS), func() { | 
|  | 288                                                                 cmpBS, _ := c.co
     nv(tc.cmpS) | 
|  | 289                                                                 So(cmpByteSequen
     ce(bs, cmpBS), tc.assertion, 0) | 
|  | 290                                                         }) | 
|  | 291                                                 } | 
|  | 292                                         } | 
|  | 293                                 }) | 
|  | 294                         } | 
|  | 295                 } | 
|  | 296         }) | 
|  | 297 } | 
| OLD | NEW | 
|---|