github.com/alash3al/go@v0.0.0-20150827002835-d497eeb00540/src/cmd/vet/testdata/composite.go (about)

     1  // Copyright 2012 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 untagged struct literal checker.
     6  
     7  // This file contains the test for untagged struct literals.
     8  
     9  package testdata
    10  
    11  import (
    12  	"flag"
    13  	"go/scanner"
    14  )
    15  
    16  var Okay1 = []string{
    17  	"Name",
    18  	"Usage",
    19  	"DefValue",
    20  }
    21  
    22  var Okay2 = map[string]bool{
    23  	"Name":     true,
    24  	"Usage":    true,
    25  	"DefValue": true,
    26  }
    27  
    28  var Okay3 = struct {
    29  	X string
    30  	Y string
    31  	Z string
    32  }{
    33  	"Name",
    34  	"Usage",
    35  	"DefValue",
    36  }
    37  
    38  type MyStruct struct {
    39  	X string
    40  	Y string
    41  	Z string
    42  }
    43  
    44  var Okay4 = MyStruct{
    45  	"Name",
    46  	"Usage",
    47  	"DefValue",
    48  }
    49  
    50  // Testing is awkward because we need to reference things from a separate package
    51  // to trigger the warnings.
    52  
    53  var BadStructLiteralUsedInTests = flag.Flag{ // ERROR "unkeyed fields"
    54  	"Name",
    55  	"Usage",
    56  	nil, // Value
    57  	"DefValue",
    58  }
    59  
    60  // Used to test the check for slices and arrays: If that test is disabled and
    61  // vet is run with --compositewhitelist=false, this line triggers an error.
    62  // Clumsy but sufficient.
    63  var scannerErrorListTest = scanner.ErrorList{nil, nil}