golang.org/x/tools@v0.21.1-0.20240520172518-788d39e776b1/go/analysis/passes/appends/testdata/src/a/a.go (about)

     1  // Copyright 2023 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  // This file contains tests for the appends checker.
     6  
     7  package a
     8  
     9  func badAppendSlice1() {
    10  	sli := []string{"a", "b", "c"}
    11  	sli = append(sli) // want "append with no values"
    12  }
    13  
    14  func badAppendSlice2() {
    15  	_ = append([]string{"a"}) // want "append with no values"
    16  }
    17  
    18  func goodAppendSlice1() {
    19  	sli := []string{"a", "b", "c"}
    20  	sli = append(sli, "d")
    21  }
    22  
    23  func goodAppendSlice2() {
    24  	sli1 := []string{"a", "b", "c"}
    25  	sli2 := []string{"d", "e", "f"}
    26  	sli1 = append(sli1, sli2...)
    27  }
    28  
    29  func goodAppendSlice3() {
    30  	sli := []string{"a", "b", "c"}
    31  	sli = append(sli, "d", "e", "f")
    32  }