github.com/cockroachdb/tools@v0.0.0-20230222021103-a6d27438930d/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 }