Debian Codegraph @

cmd/go-fix-acronym/rewrite_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package mainscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/
18
19 import (
20 "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/"
21 "go/formatscip-go gomod github.com/golang/go/src go1.13 `go/format`/"
22 "go/parserscip-go gomod github.com/golang/go/src go1.13 `go/parser`/"
23 "go/tokenscip-go gomod github.com/golang/go/src go1.13 `go/token`/"
24 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
25 "testingscip-go gomod github.com/golang/go/src go1.13 testing/"
26 )
27
28 func testRewritescip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/testRewrite().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#, input, expected string, c configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#) {
29 fset := tokenscip-go gomod github.com/golang/go/src go1.13 `go/token`/.NewFileSetscip-go gomod github.com/golang/go/src go1.13 `go/token`/NewFileSet().()
30 n, err := parserscip-go gomod github.com/golang/go/src go1.13 `go/parser`/.ParseFilescip-go gomod github.com/golang/go/src go1.13 `go/parser`/ParseFile().(fset, "", input, parserscip-go gomod github.com/golang/go/src go1.13 `go/parser`/.ParseCommentsscip-go gomod github.com/golang/go/src go1.13 `go/parser`/ParseComments.)
31 if err != nil {
32 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("failed to parse: %s", err)
33 }
34
35 p, err := compilePatternscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/compilePattern().(c)
36 if err != nil {
37 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("failed to compile: %s", err)
38 }
39
40 rewriteNodescip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/rewriteNode().(p, n)
41
42 out := &bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#{}
43 formatscip-go gomod github.com/golang/go/src go1.13 `go/format`/.Nodescip-go gomod github.com/golang/go/src go1.13 `go/format`/Node().(out, fset, n)
44 if out.Stringscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#String().() != expected {
45 t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("expected %q, but got %q", expected, out)
46 }
47 }
48
49 func TestRewritescip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/TestRewrite().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
50 testcases := []struct {
51 name string
52 input string
53 expected string
54 c configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#
55 }{
56 {
57 name: "Simple",
58 c: configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#{acronymsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#acronyms.: []string{"Cpu"}},
•59 input: "// hello\npackage main\nfunc GetCpu(){}",
60 expected: "// hello\npackage main\n\nfunc GetCPU() {}",
61 },
62 {
63 name: "Multiple matches",
64 c: configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#{acronymsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#acronyms.: []string{"Cpu"}},
65 input: `package main
66
67 func GetCpuFromCpuList() {}`,
68 expected: `package main
69
70 func GetCPUFromCPUList() {}`,
71 },
72 {
73 name: "Submatches",
74 c: configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#{acronymsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#acronyms.: []string{"Runtime(Ns)"}},
75 input: `package main
76
77 func KernelTime_100Ns() {}
78 func RuntimeNsAndNsAndSomeSuffix() {}`,
79 expected: `package main
80
81 func KernelTime_100Ns() {}
82 func RuntimeNSAndNsAndSomeSuffix() {}`,
83 },
84 {
85 name: "Multiple submatches",
86 c: configscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#{acronymsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/config#acronyms.: []string{"(Id|Vm)$", "[a-z](Ns)$"}},
87 input: `package main
88
89 func Vm() {}
90 func Time_100Ns() {}
91 func RuntimeNs() {}
92 `,
93 expected: `package main
94
95 func VM() {}
96 func Time_100Ns() {}
97 func RuntimeNS() {}`,
98 },
99 }
100 for _, tc := range testcases {
101 t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) {
102 testRewritescip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild/cmd/go-fix-acronym`/testRewrite().(t, tc.input, stringsscip-go gomod github.com/golang/go/src go1.13 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.13 strings/ReplaceAll().(tc.expected, "\t", "")+"\n", tc.c)
103 })
104 }
105 }