summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2019-01-12 18:39:45 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-17 12:30:32 +0100
commitb1247d2d0d51108c910a73891ff3116e5f032ab1 (patch)
treee9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go
parentefcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff)
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go')
-rw-r--r--vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go b/vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go
new file mode 100644
index 0000000..a47dbef
--- /dev/null
+++ b/vendor/golang.org/x/tools/go/ssa/ssautil/switch_test.go
@@ -0,0 +1,74 @@
+// Copyright 2013 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.
+
+// No testdata on Android.
+
+// +build !android
+
+package ssautil_test
+
+import (
+ "go/parser"
+ "strings"
+ "testing"
+
+ "golang.org/x/tools/go/loader"
+ "golang.org/x/tools/go/ssa"
+ "golang.org/x/tools/go/ssa/ssautil"
+)
+
+func TestSwitches(t *testing.T) {
+ conf := loader.Config{ParserMode: parser.ParseComments}
+ f, err := conf.ParseFile("testdata/switches.go", nil)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ conf.CreateFromFiles("main", f)
+ iprog, err := conf.Load()
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ prog := ssautil.CreateProgram(iprog, 0)
+ mainPkg := prog.Package(iprog.Created[0].Pkg)
+ mainPkg.Build()
+
+ for _, mem := range mainPkg.Members {
+ if fn, ok := mem.(*ssa.Function); ok {
+ if fn.Synthetic != "" {
+ continue // e.g. init()
+ }
+ // Each (multi-line) "switch" comment within
+ // this function must match the printed form
+ // of a ConstSwitch.
+ var wantSwitches []string
+ for _, c := range f.Comments {
+ if fn.Syntax().Pos() <= c.Pos() && c.Pos() < fn.Syntax().End() {
+ text := strings.TrimSpace(c.Text())
+ if strings.HasPrefix(text, "switch ") {
+ wantSwitches = append(wantSwitches, text)
+ }
+ }
+ }
+
+ switches := ssautil.Switches(fn)
+ if len(switches) != len(wantSwitches) {
+ t.Errorf("in %s, found %d switches, want %d", fn, len(switches), len(wantSwitches))
+ }
+ for i, sw := range switches {
+ got := sw.String()
+ if i >= len(wantSwitches) {
+ continue
+ }
+ want := wantSwitches[i]
+ if got != want {
+ t.Errorf("in %s, found switch %d: got <<%s>>, want <<%s>>", fn, i, got, want)
+ }
+ }
+ }
+ }
+}