diff options
author | LotusFenn <fenn.lotus@gmail.com> | 2018-07-07 09:21:04 +0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2018-10-11 04:45:18 +0000 |
commit | c96c2a39bb09da48b3af63de58f65fdc82865746 (patch) | |
tree | 35ed42d87a433ef024ab9626158327443d9cb0ba /src/bytes | |
parent | 9a9dc36f97bf57e186ab8183a27927abb9aecd61 (diff) | |
download | go-c96c2a39bb09da48b3af63de58f65fdc82865746.tar.gz go-c96c2a39bb09da48b3af63de58f65fdc82865746.zip |
bytes: vary the input alignment to Compare argument in compare_test.go
Currently there are no tests that vary the alignment of Compare arguments.
Since Compare is written in assembly on most platforms (in internal/bytealg)
we should be testing different input alignments. This change modifies TestCompare
to vary the alignment of the second argument of Compare.
Updates #26129
Change-Id: I4c30a5adf96a41225df748675f4e9beea413b35c
Reviewed-on: https://go-review.googlesource.com/c/122536
Reviewed-by: Lotus Fenn <fenn.lotus@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/bytes')
-rw-r--r-- | src/bytes/compare_test.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/bytes/compare_test.go b/src/bytes/compare_test.go index 3e33c27c9c..a321f2e086 100644 --- a/src/bytes/compare_test.go +++ b/src/bytes/compare_test.go @@ -41,9 +41,16 @@ var compareTests = []struct { func TestCompare(t *testing.T) { for _, tt := range compareTests { - cmp := Compare(tt.a, tt.b) - if cmp != tt.i { - t.Errorf(`Compare(%q, %q) = %v`, tt.a, tt.b, cmp) + numShifts := 16 + buffer := make([]byte, len(tt.b)+numShifts) + // vary the input alignment of tt.b + for offset := 0; offset <= numShifts; offset++ { + shiftedB := buffer[offset : len(tt.b)+offset] + copy(shiftedB, tt.b) + cmp := Compare(tt.a, shiftedB) + if cmp != tt.i { + t.Errorf(`Compare(%q, %q), offset %d = %v; want %v`, tt.a, tt.b, offset, cmp, tt.i) + } } } } |