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 "math" | 8 "math" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 }) | 109 }) |
110 Convey("time gets rounded", func() { | 110 Convey("time gets rounded", func() { |
111 pv := Property{} | 111 pv := Property{} |
112 now := time.Now().In(time.UTC) | 112 now := time.Now().In(time.UTC) |
113 now = now.Round(time.Microsecond).Add(time.Nanos
econd * 313) | 113 now = now.Round(time.Microsecond).Add(time.Nanos
econd * 313) |
114 So(pv.SetValue(now, ShouldIndex), ShouldBeNil) | 114 So(pv.SetValue(now, ShouldIndex), ShouldBeNil) |
115 So(pv.Value(), ShouldHappenBefore, now) | 115 So(pv.Value(), ShouldHappenBefore, now) |
116 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 116 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
117 So(pv.Type().String(), ShouldEqual, "PTTime") | 117 So(pv.Type().String(), ShouldEqual, "PTTime") |
118 }) | 118 }) |
| 119 Convey("zero time", func() { |
| 120 now := time.Time{} |
| 121 So(now.IsZero(), ShouldBeTrue) |
| 122 |
| 123 pv := Property{} |
| 124 So(pv.SetValue(now, ShouldIndex), ShouldBeNil) |
| 125 So(pv.Value(), ShouldResemble, now) |
| 126 v, err := pv.Project(PTInt) |
| 127 So(err, ShouldBeNil) |
| 128 So(v, ShouldEqual, 0) |
| 129 |
| 130 So(pv.SetValue(0, ShouldIndex), ShouldBeNil) |
| 131 So(pv.Value(), ShouldEqual, 0) |
| 132 v, err = pv.Project(PTTime) |
| 133 So(err, ShouldBeNil) |
| 134 So(v.(time.Time).IsZero(), ShouldBeTrue) |
| 135 }) |
119 Convey("[]byte allows IndexSetting", func() { | 136 Convey("[]byte allows IndexSetting", func() { |
120 pv := Property{} | 137 pv := Property{} |
121 So(pv.SetValue([]byte("hello"), ShouldIndex), Sh
ouldBeNil) | 138 So(pv.SetValue([]byte("hello"), ShouldIndex), Sh
ouldBeNil) |
122 So(pv.Value(), ShouldResemble, []byte("hello")) | 139 So(pv.Value(), ShouldResemble, []byte("hello")) |
123 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 140 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
124 So(pv.Type().String(), ShouldEqual, "PTBytes") | 141 So(pv.Type().String(), ShouldEqual, "PTBytes") |
125 }) | 142 }) |
126 }) | 143 }) |
| 144 |
| 145 Convey("Comparison", func() { |
| 146 Convey(`A []byte property should equal a string property
with the same value.`, func() { |
| 147 a := MkProperty([]byte("ohaithere")) |
| 148 b := MkProperty("ohaithere") |
| 149 So(a.Equal(&b), ShouldBeTrue) |
| 150 }) |
| 151 }) |
127 }) | 152 }) |
128 } | 153 } |
129 | 154 |
130 func TestDSPropertyMapImpl(t *testing.T) { | 155 func TestDSPropertyMapImpl(t *testing.T) { |
131 t.Parallel() | 156 t.Parallel() |
132 | 157 |
133 Convey("PropertyMap load/save err conditions", t, func() { | 158 Convey("PropertyMap load/save err conditions", t, func() { |
134 Convey("empty", func() { | 159 Convey("empty", func() { |
135 pm := PropertyMap{} | 160 pm := PropertyMap{} |
136 err := pm.Load(PropertyMap{"hello": {Property{}}}) | 161 err := pm.Load(PropertyMap{"hello": {Property{}}}) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Convey("errors", func() { | 198 Convey("errors", func() { |
174 | 199 |
175 Convey("weird value", func() { | 200 Convey("weird value", func() { |
176 pm := PropertyMap{} | 201 pm := PropertyMap{} |
177 So(pm.SetMeta("sup", complex(100, 20)),
ShouldBeFalse) | 202 So(pm.SetMeta("sup", complex(100, 20)),
ShouldBeFalse) |
178 }) | 203 }) |
179 }) | 204 }) |
180 }) | 205 }) |
181 }) | 206 }) |
182 } | 207 } |
OLD | NEW |