github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/cmd/stringer/testdata/number.go (about)

     1  // Copyright 2014 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  // Enumeration with an offset.
     6  // Also includes a duplicate.
     7  
     8  package main
     9  
    10  import "fmt"
    11  
    12  type Number int
    13  
    14  const (
    15  	_ Number = iota
    16  	One
    17  	Two
    18  	Three
    19  	AnotherOne = One // Duplicate; note that AnotherOne doesn't appear below.
    20  )
    21  
    22  func main() {
    23  	ck(One, "One")
    24  	ck(Two, "Two")
    25  	ck(Three, "Three")
    26  	ck(AnotherOne, "One")
    27  	ck(127, "Number(127)")
    28  }
    29  
    30  func ck(num Number, str string) {
    31  	if fmt.Sprint(num) != str {
    32  		panic("number.go: " + str)
    33  	}
    34  }