Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: service/datastore/properties_test.go

Issue 1620873004: Fix fast string comparison bug. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Less test dups. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/datastore/properties.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/properties_test.go
diff --git a/service/datastore/properties_test.go b/service/datastore/properties_test.go
index dcde889091af17a18a75ca74c1b0e863b1c77e6d..be47cae1a14173c2125cac30311df4729287bbc6 100644
--- a/service/datastore/properties_test.go
+++ b/service/datastore/properties_test.go
@@ -5,7 +5,9 @@
package datastore
import (
+ "fmt"
"math"
+ "sort"
"testing"
"time"
@@ -218,3 +220,78 @@ func TestDSPropertyMapImpl(t *testing.T) {
})
})
}
+
+func TestByteSequences(t *testing.T) {
+ t.Parallel()
+
+ conversions := []struct {
+ desc string
+ conv func(v string) (byteSequence, interface{})
+ }{
+ {"string", func(v string) (byteSequence, interface{}) { return stringByteSequence(v), v }},
+ {"[]byte", func(v string) (byteSequence, interface{}) { return bytesByteSequence(v), []byte(v) }},
+ }
+
+ testCases := map[string][]struct {
+ assertion func(interface{}, ...interface{}) string
+ cmpS string
+ }{
+ "": {
+ {ShouldEqual, ""},
+ {ShouldBeLessThan, "foo"},
+ },
+ "bar": {
+ {ShouldEqual, "bar"},
+ {ShouldBeGreaterThan, "ba"},
+ },
+ "ba": {
+ {ShouldBeLessThan, "bar"},
+ {ShouldBeLessThan, "z"},
+ },
+ "foo": {
+ {ShouldBeGreaterThan, ""},
+ },
+ "bz": {
+ {ShouldBeGreaterThan, "bar"},
+ },
+ "qux": {
+ {ShouldBeGreaterThan, "bar"},
+ },
+ }
+
+ keys := make([]string, 0, len(testCases))
+ for k := range testCases {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+
+ Convey(`When testing byte sequences`, t, func() {
+ for _, s := range keys {
+ for _, c := range conversions {
+ Convey(fmt.Sprintf(`A %s sequence with test data %q`, c.desc, s), func() {
+ bs, effectiveValue := c.conv(s)
+
+ Convey(`Basic stuff works.`, func() {
+ So(bs.len(), ShouldEqual, len(s))
+ for i, c := range s {
+ So(bs.get(i), ShouldEqual, c)
+ }
+ So(bs.value(), ShouldResemble, effectiveValue)
+ So(bs.string(), ShouldEqual, s)
+ So(bs.bytes(), ShouldResemble, []byte(s))
+ })
+
+ // Test comparison with other byteSequence types.
+ for _, tc := range testCases[s] {
+ for _, c := range conversions {
+ Convey(fmt.Sprintf(`Compares properly with %s %q`, c.desc, tc.cmpS), func() {
+ cmpBS, _ := c.conv(tc.cmpS)
+ So(cmpByteSequence(bs, cmpBS), tc.assertion, 0)
+ })
+ }
+ }
+ })
+ }
+ }
+ })
+}
« no previous file with comments | « service/datastore/properties.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698