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