...

Source file src/crypto/internal/alias/alias_test.go

Documentation: crypto/internal/alias

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package alias
     6  
     7  import "testing"
     8  
     9  var a, b [100]byte
    10  
    11  var aliasingTests = []struct {
    12  	x, y                       []byte
    13  	anyOverlap, inexactOverlap bool
    14  }{
    15  	{a[:], b[:], false, false},
    16  	{a[:], b[:0], false, false},
    17  	{a[:], b[:50], false, false},
    18  	{a[40:50], a[50:60], false, false},
    19  	{a[40:50], a[60:70], false, false},
    20  	{a[:51], a[50:], true, true},
    21  	{a[:], a[:], true, false},
    22  	{a[:50], a[:60], true, false},
    23  	{a[:], nil, false, false},
    24  	{nil, nil, false, false},
    25  	{a[:], a[:0], false, false},
    26  	{a[:10], a[:10:20], true, false},
    27  	{a[:10], a[5:10:20], true, true},
    28  }
    29  
    30  func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) {
    31  	any := AnyOverlap(x, y)
    32  	if any != anyOverlap {
    33  		t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any)
    34  	}
    35  	inexact := InexactOverlap(x, y)
    36  	if inexact != inexactOverlap {
    37  		t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any)
    38  	}
    39  }
    40  
    41  func TestAliasing(t *testing.T) {
    42  	for i, tt := range aliasingTests {
    43  		testAliasing(t, i, tt.x, tt.y, tt.anyOverlap, tt.inexactOverlap)
    44  		testAliasing(t, i, tt.y, tt.x, tt.anyOverlap, tt.inexactOverlap)
    45  	}
    46  }
    47  

View as plain text