1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:48:32 -06:00
go/cmd/stringer/testdata/num.go
Rob Pike d0448f16e3 go.tools/cmd/stringer: add end-to-end test that compiles, runs, and verifies the generated method
In the process, fix a bug in one of the method generators.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/141130043
2014-09-05 15:42:23 -07:00

36 lines
504 B
Go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Signed integers spanning zero.
package main
import "fmt"
type Num int
const (
m_2 Num = -2 + iota
m_1
m0
m1
m2
)
func main() {
ck(-3, "Num(-3)")
ck(m_2, "m_2")
ck(m_1, "m_1")
ck(m0, "m0")
ck(m1, "m1")
ck(m2, "m2")
ck(3, "Num(3)")
}
func ck(num Num, str string) {
if fmt.Sprint(num) != str {
panic("num.go: " + str)
}
}