From c96c2a39bb09da48b3af63de58f65fdc82865746 Mon Sep 17 00:00:00 2001 From: LotusFenn Date: Sat, 7 Jul 2018 09:21:04 +0800 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/bytes/compare_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bytes/compare_test.go b/src/bytes/compare_test.go index 3e33c27c9c9..a321f2e0861 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) + } } } }