Skip to content

Commit 9d3f927

Browse files
authored
Merge pull request #59 from githubnext/autoloop/python-to-go-migration
[Autoloop: python-to-go-migration]
2 parents ef30ee4 + ff46757 commit 9d3f927

367 files changed

Lines changed: 43844 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/migration-status.json

Lines changed: 2160 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package base_test
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
7+
"github.com/githubnext/apm/internal/adapters/client/base"
8+
)
9+
10+
func TestInputVarRE_NoMatch_PlainText(t *testing.T) {
11+
if base.InputVarRE.MatchString("plain text without vars") {
12+
t.Error("should not match plain text")
13+
}
14+
}
15+
16+
func TestInputVarRE_NoMatch_EmptyBraces(t *testing.T) {
17+
if base.InputVarRE.MatchString("${}") {
18+
t.Error("should not match empty braces")
19+
}
20+
}
21+
22+
func TestInputVarRE_Match_SimpleInput(t *testing.T) {
23+
if !base.InputVarRE.MatchString("${input:myvar}") {
24+
t.Error("should match input var")
25+
}
26+
}
27+
28+
func TestInputVarRE_CaptureGroup(t *testing.T) {
29+
m := base.InputVarRE.FindStringSubmatch("${input:TOKEN}")
30+
if len(m) < 2 || m[1] != "TOKEN" {
31+
t.Errorf("capture group expected TOKEN, got %v", m)
32+
}
33+
}
34+
35+
func TestInputVarRE_Multiword(t *testing.T) {
36+
m := base.InputVarRE.FindAllStringSubmatch("use ${input:a} and ${input:b}", -1)
37+
if len(m) != 2 {
38+
t.Errorf("expected 2 matches, got %d", len(m))
39+
}
40+
names := []string{m[0][1], m[1][1]}
41+
if names[0] != "a" || names[1] != "b" {
42+
t.Errorf("unexpected names %v", names)
43+
}
44+
}
45+
46+
func TestEnvVarRE_NoMatchEmptyBraces(t *testing.T) {
47+
if base.EnvVarRE.MatchString("${}") {
48+
t.Error("should not match empty braces")
49+
}
50+
}
51+
52+
func TestEnvVarRE_NoMatchInputPrefix(t *testing.T) {
53+
if base.EnvVarRE.MatchString("${input:MYVAR}") {
54+
t.Error("should not match input: prefix")
55+
}
56+
}
57+
58+
func TestEnvVarRE_Match_PlainBraces(t *testing.T) {
59+
if !base.EnvVarRE.MatchString("${MYVAR}") {
60+
t.Error("should match ${MYVAR}")
61+
}
62+
}
63+
64+
func TestEnvVarRE_Match_EnvPrefix(t *testing.T) {
65+
if !base.EnvVarRE.MatchString("${env:MYVAR}") {
66+
t.Error("should match ${env:MYVAR}")
67+
}
68+
}
69+
70+
func TestEnvVarRE_NoMatchGitHubExpressions(t *testing.T) {
71+
// GitHub Actions ${{ ... }} should not be matched.
72+
if base.EnvVarRE.MatchString("${{ secrets.TOKEN }}") {
73+
t.Error("should not match GitHub Actions expressions")
74+
}
75+
}
76+
77+
func TestEnvVarRE_CaptureGroupPlain(t *testing.T) {
78+
m := base.EnvVarRE.FindStringSubmatch("${TOKEN}")
79+
if len(m) < 2 || m[1] != "TOKEN" {
80+
t.Errorf("expected TOKEN, got %v", m)
81+
}
82+
}
83+
84+
func TestEnvVarRE_CaptureGroupEnvPrefix(t *testing.T) {
85+
m := base.EnvVarRE.FindStringSubmatch("${env:TOKEN}")
86+
if len(m) < 2 || m[1] != "TOKEN" {
87+
t.Errorf("expected TOKEN, got %v", m)
88+
}
89+
}
90+
91+
func TestInputVarRE_IsCompiled(t *testing.T) {
92+
if base.InputVarRE == nil {
93+
t.Fatal("InputVarRE should not be nil")
94+
}
95+
if _, ok := interface{}(base.InputVarRE).(*regexp.Regexp); !ok {
96+
t.Error("InputVarRE should be *regexp.Regexp")
97+
}
98+
}
99+
100+
func TestEnvVarRE_IsCompiled(t *testing.T) {
101+
if base.EnvVarRE == nil {
102+
t.Fatal("EnvVarRE should not be nil")
103+
}
104+
if _, ok := interface{}(base.EnvVarRE).(*regexp.Regexp); !ok {
105+
t.Error("EnvVarRE should be *regexp.Regexp")
106+
}
107+
}
108+
109+
func TestInputVarRE_WithHyphensInName(t *testing.T) {
110+
// hyphens are valid inside input var names
111+
if !base.InputVarRE.MatchString("${input:my-var}") {
112+
t.Error("should match input var with hyphens")
113+
}
114+
m := base.InputVarRE.FindStringSubmatch("${input:my-var}")
115+
if len(m) < 2 || m[1] != "my-var" {
116+
t.Errorf("capture expected 'my-var', got %v", m)
117+
}
118+
}
119+
120+
func TestEnvVarRE_NoMatchDigitStart(t *testing.T) {
121+
if base.EnvVarRE.MatchString("${1VAR}") {
122+
t.Error("should not match var starting with digit")
123+
}
124+
}
125+
126+
func TestEnvVarRE_MultipleMatches(t *testing.T) {
127+
ms := base.EnvVarRE.FindAllStringSubmatch("${A} text ${env:B}", -1)
128+
if len(ms) != 2 {
129+
t.Fatalf("expected 2 matches, got %d", len(ms))
130+
}
131+
if ms[0][1] != "A" || ms[1][1] != "B" {
132+
t.Errorf("expected A,B got %v %v", ms[0][1], ms[1][1])
133+
}
134+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package base_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/githubnext/apm/internal/adapters/client/base"
7+
)
8+
9+
func TestInputVarRE_NoMatchBraceOnly_Extra3(t *testing.T) {
10+
if base.InputVarRE.MatchString("${}") {
11+
t.Error("expected no match for ${}")
12+
}
13+
}
14+
15+
func TestInputVarRE_NoMatchEnvColon_Extra3(t *testing.T) {
16+
if base.InputVarRE.MatchString("${env:FOO}") {
17+
t.Error("expected no match for ${env:FOO}")
18+
}
19+
}
20+
21+
func TestInputVarRE_MatchWithDot_Extra3(t *testing.T) {
22+
m := base.InputVarRE.FindStringSubmatch("${input:my.var}")
23+
if m == nil {
24+
t.Fatal("expected match for ${input:my.var}")
25+
}
26+
if m[1] != "my.var" {
27+
t.Errorf("got %q want my.var", m[1])
28+
}
29+
}
30+
31+
func TestInputVarRE_MatchWithNumber_Extra3(t *testing.T) {
32+
m := base.InputVarRE.FindStringSubmatch("${input:var1}")
33+
if m == nil {
34+
t.Fatal("expected match")
35+
}
36+
if m[1] != "var1" {
37+
t.Errorf("got %q want var1", m[1])
38+
}
39+
}
40+
41+
func TestEnvVarRE_NoMatchDollarOnly_Extra3(t *testing.T) {
42+
if base.EnvVarRE.MatchString("$FOO") {
43+
t.Error("expected no match for plain $FOO")
44+
}
45+
}
46+
47+
func TestEnvVarRE_MatchLongName_Extra3(t *testing.T) {
48+
m := base.EnvVarRE.FindStringSubmatch("${VERY_LONG_VARIABLE_NAME_123}")
49+
if m == nil {
50+
t.Fatal("expected match for long name")
51+
}
52+
if m[1] != "VERY_LONG_VARIABLE_NAME_123" {
53+
t.Errorf("got %q", m[1])
54+
}
55+
}
56+
57+
func TestEnvVarRE_FindAllInSentence_Extra3(t *testing.T) {
58+
s := "prefix ${FOO} middle ${env:BAR} suffix"
59+
all := base.EnvVarRE.FindAllStringSubmatch(s, -1)
60+
if len(all) != 2 {
61+
t.Errorf("expected 2 matches, got %d", len(all))
62+
}
63+
}
64+
65+
func TestInputVarRE_FindAllMultiple_Extra3(t *testing.T) {
66+
s := "Use ${input:a} and ${input:b} in command"
67+
all := base.InputVarRE.FindAllString(s, -1)
68+
if len(all) != 2 {
69+
t.Errorf("expected 2 matches, got %d", len(all))
70+
}
71+
}
72+
73+
func TestEnvVarRE_EnvPrefixCapture_Extra3(t *testing.T) {
74+
m := base.EnvVarRE.FindStringSubmatch("${env:MY_TOKEN}")
75+
if m == nil {
76+
t.Fatal("expected match")
77+
}
78+
if m[1] != "MY_TOKEN" {
79+
t.Errorf("got %q want MY_TOKEN", m[1])
80+
}
81+
}
82+
83+
func TestMCPClientAdapter_InterfaceHasMethods_Extra3(t *testing.T) {
84+
// Compile-time check that MCPClientAdapter interface is usable as a type
85+
var _ base.MCPClientAdapter = (base.MCPClientAdapter)(nil)
86+
}
87+
88+
func TestEnvVarRE_NoMatchNumbers_Extra3(t *testing.T) {
89+
if base.EnvVarRE.MatchString("${123}") {
90+
t.Error("should not match numbers only")
91+
}
92+
}
93+
94+
func TestInputVarRE_EmptyInputName_Extra3(t *testing.T) {
95+
// ${input:} has empty name - depends on regex; confirm consistent
96+
got := base.InputVarRE.MatchString("${input:}")
97+
// Just ensure no panic; value may be true or false
98+
_ = got
99+
}
100+
101+
func TestEnvVarRE_UnderscoreStart_Extra3(t *testing.T) {
102+
m := base.EnvVarRE.FindStringSubmatch("${_PRIVATE}")
103+
if m == nil {
104+
t.Fatal("expected match for underscore-start")
105+
}
106+
if m[1] != "_PRIVATE" {
107+
t.Errorf("got %q", m[1])
108+
}
109+
}
110+
111+
func TestInputVarRE_WithSpaces_Extra3(t *testing.T) {
112+
// Spaces inside braces are not typical identifiers but pattern should handle
113+
has := base.InputVarRE.MatchString("${input:with space}")
114+
_ = has // no panic
115+
}
116+
117+
func TestEnvVarRE_ReplaceAll_Extra3(t *testing.T) {
118+
s := "cmd --token ${TOKEN}"
119+
result := base.EnvVarRE.ReplaceAllString(s, "REPLACED")
120+
if result == s {
121+
t.Error("expected replacement to occur")
122+
}
123+
}

0 commit comments

Comments
 (0)