GoPLS Viewer

Home|gopls/go/analysis/passes/buildssa/buildssa_test.go
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
5package buildssa_test
6
7import (
8    "fmt"
9    "os"
10    "testing"
11
12    "golang.org/x/tools/go/analysis/analysistest"
13    "golang.org/x/tools/go/analysis/passes/buildssa"
14    "golang.org/x/tools/internal/typeparams"
15)
16
17func Test(t *testing.T) {
18    testdata := analysistest.TestData()
19    result := analysistest.Run(ttestdatabuildssa.Analyzer"a")[0].Result
20
21    ssainfo := result.(*buildssa.SSA)
22    got := fmt.Sprint(ssainfo.SrcFuncs)
23    want := `[a.Fib (a.T).fib]`
24    if got != want {
25        t.Errorf("SSA.SrcFuncs = %s, want %s"gotwant)
26        for _f := range ssainfo.SrcFuncs {
27            f.WriteTo(os.Stderr)
28        }
29    }
30}
31
32func TestGenericDecls(t *testing.T) {
33    if !typeparams.Enabled {
34        t.Skip("TestGenericDecls requires type parameters.")
35    }
36    testdata := analysistest.TestData()
37    result := analysistest.Run(ttestdatabuildssa.Analyzer"b")[0].Result
38
39    ssainfo := result.(*buildssa.SSA)
40    got := fmt.Sprint(ssainfo.SrcFuncs)
41    want := `[(*b.Pointer[T]).Load b.Load b.LoadPointer]`
42    if got != want {
43        t.Errorf("SSA.SrcFuncs = %s, want %s"gotwant)
44        for _f := range ssainfo.SrcFuncs {
45            f.WriteTo(os.Stderr)
46        }
47    }
48}
49
50func TestImporting(t *testing.T) {
51    if !typeparams.Enabled {
52        t.Skip("TestImporting depends on testdata/b/b/go which uses type parameters.")
53    }
54    testdata := analysistest.TestData()
55    result := analysistest.Run(ttestdatabuildssa.Analyzer"c")[0].Result
56
57    ssainfo := result.(*buildssa.SSA)
58    got := fmt.Sprint(ssainfo.SrcFuncs)
59    want := `[c.A c.B]`
60    if got != want {
61        t.Errorf("SSA.SrcFuncs = %s, want %s"gotwant)
62        for _f := range ssainfo.SrcFuncs {
63            f.WriteTo(os.Stderr)
64        }
65    }
66}
67
MembersX
Test.result
TestGenericDecls.got
typeparams
TestGenericDecls
os
Test.t
TestGenericDecls.testdata
Test.want
TestImporting
TestImporting.t
TestImporting.want
testing
TestImporting.got
TestGenericDecls.want
TestGenericDecls.BlockStmt.RangeStmt_1177.f
Test.BlockStmt.RangeStmt_672.f
buildssa
Test.testdata
Test.got
TestImporting.testdata
TestImporting.result
TestImporting.BlockStmt.RangeStmt_1671.f
fmt
Test
TestGenericDecls.t
TestGenericDecls.result
analysistest
Members
X