github.com/prysmaticlabs/prysm@v1.4.4/tools/analyzers/slicedirect/testdata/slice.go (about)

     1  package testdata
     2  
     3  // NoIndexProvided --
     4  func NoIndexProvided() {
     5  	x := []byte{'f', 'o', 'o'}
     6  	y := x[:] // want "Expression is already a slice."
     7  	if len(y) == 3 {
     8  	}
     9  }
    10  
    11  // StartindexprovidedNodiagnostic --
    12  func StartindexprovidedNodiagnostic() {
    13  	x := []byte{'f', 'o', 'o'}
    14  	y := x[1:]
    15  	if len(y) == 3 {
    16  	}
    17  }
    18  
    19  // EndindexprovidedNodiagnostic --
    20  func EndindexprovidedNodiagnostic() {
    21  	x := []byte{'f', 'o', 'o'}
    22  	y := x[:2]
    23  	if len(y) == 3 {
    24  	}
    25  }
    26  
    27  // BothindicesprovidedNodiagnostic --
    28  func BothindicesprovidedNodiagnostic() {
    29  	x := []byte{'f', 'o', 'o'}
    30  	y := x[1:2]
    31  	if len(y) == 3 {
    32  	}
    33  }
    34  
    35  // StringSlice --
    36  func StringSlice() {
    37  	x := "foo"
    38  	y := x[:] // want "Expression is already a slice."
    39  	if len(y) == 3 {
    40  	}
    41  }
    42  
    43  // SliceFromFunction --
    44  func SliceFromFunction() {
    45  	x := slice()[:] // want "Expression is already a slice."
    46  	if len(x) == 3 {
    47  	}
    48  }
    49  
    50  func slice() []string {
    51  	return []string{"bar"}
    52  }