github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/cmd/stringer/testdata/conv.go (about) 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 // Check that constants defined as a conversion are accepted. 6 7 package main 8 9 import "fmt" 10 11 type Other int // Imagine this is in another package. 12 13 const ( 14 alpha Other = iota 15 beta 16 gamma 17 delta 18 ) 19 20 type Conv int 21 22 const ( 23 Alpha = Conv(alpha) 24 Beta = Conv(beta) 25 Gamma = Conv(gamma) 26 Delta = Conv(delta) 27 ) 28 29 func main() { 30 ck(Alpha, "Alpha") 31 ck(Beta, "Beta") 32 ck(Gamma, "Gamma") 33 ck(Delta, "Delta") 34 ck(42, "Conv(42)") 35 } 36 37 func ck(c Conv, str string) { 38 if fmt.Sprint(c) != str { 39 panic("conv.go: " + str) 40 } 41 }