@@ -10,13 +10,47 @@ import (
10
10
"github.com/robbyt/go-polyscript/execution/data"
11
11
"github.com/robbyt/go-polyscript/execution/script"
12
12
{{- range .Types}}
13
- _ "github.com/robbyt/go-polyscript/machines/{{.Value}}"
13
+ {{.Value}}Compiler "github.com/robbyt/go-polyscript/machines/{{.Value}}/compiler "
14
14
{{- end}}
15
15
machineTypes "github.com/robbyt/go-polyscript/machines/types"
16
16
"github.com/stretchr/testify/mock"
17
17
"github.com/stretchr/testify/require"
18
18
)
19
19
20
+ type mockExecutableContent struct {
21
+ mock.Mock
22
+ }
23
+
24
+ func (m *mockExecutableContent) GetMachineType() machineTypes.Type {
25
+ args := m.Called()
26
+ return args.Get(0).(machineTypes.Type)
27
+ }
28
+
29
+ func (m *mockExecutableContent) GetSource() string {
30
+ args := m.Called()
31
+ return args.String(0)
32
+ }
33
+
34
+ func (m *mockExecutableContent) GetByteCode() any {
35
+ args := m.Called()
36
+ return args.Get(0)
37
+ }
38
+
39
+ // mockRisorOption is a mock option satisfying risorCompiler.FunctionalOption.
40
+ var mockRisorOption risorCompiler.FunctionalOption = func(c *risorCompiler.Compiler) error {
41
+ return nil
42
+ }
43
+
44
+ // mockStarlarkOption is a mock option satisfying starlarkCompiler.FunctionalOption.
45
+ var mockStarlarkOption starlarkCompiler.FunctionalOption = func(c *starlarkCompiler.Compiler) error {
46
+ return nil
47
+ }
48
+
49
+ // mockExtismOption is a mock option satisfying extismCompiler.FunctionalOption.
50
+ var mockExtismOption extismCompiler.FunctionalOption = func(c *extismCompiler.Compiler) error {
51
+ return nil
52
+ }
53
+
20
54
func TestNewEvaluator(t *testing.T) {
21
55
tests := []struct {
22
56
name string
@@ -69,21 +103,55 @@ func TestNewEvaluator(t *testing.T) {
69
103
}
70
104
}
71
105
72
- type mockExecutableContent struct {
73
- mock.Mock
74
- }
106
+ func TestNewCompiler(t *testing.T) {
107
+ tests := []struct {
108
+ name string
109
+ options []any
110
+ expectError bool
111
+ expectedErr string
112
+ }{
113
+ {
114
+ name: "No options provided",
115
+ options: []any{},
116
+ expectError: true,
117
+ expectedErr: "no options provided",
118
+ },
119
+ {
120
+ name: "Valid Risor options",
121
+ options: []any{mockRisorOption},
122
+ expectError: false,
123
+ },
124
+ {
125
+ name: "Valid Starlark options",
126
+ options: []any{mockStarlarkOption},
127
+ expectError: false,
128
+ },
129
+ {
130
+ name: "Valid Extism options",
131
+ options: []any{mockExtismOption},
132
+ expectError: false,
133
+ },
134
+ {
135
+ name: "Mixed options",
136
+ options: []any{mockRisorOption, mockStarlarkOption},
137
+ expectError: true,
138
+ expectedErr: "unable to determine compiler type",
139
+ },
140
+ }
75
141
76
- func (m *mockExecutableContent) GetMachineType() machineTypes.Type {
77
- args := m.Called()
78
- return args.Get(0).(machineTypes.Type)
142
+ for _, tt := range tests {
143
+ t.Run(tt.name, func(t *testing.T) {
144
+ comp, err := NewCompiler(tt.options...)
145
+ if tt.expectError {
146
+ require.Error(t, err)
147
+ require.Nil(t, comp)
148
+ require.Contains(t, err.Error(), tt.expectedErr)
149
+ } else {
150
+ require.NoError(t, err)
151
+ require.NotNil(t, comp)
152
+ }
153
+ })
154
+ }
79
155
}
80
156
81
- func (m *mockExecutableContent) GetSource() string {
82
- args := m.Called()
83
- return args.String(0)
84
- }
85
157
86
- func (m *mockExecutableContent) GetByteCode() any {
87
- args := m.Called()
88
- return args.Get(0)
89
- }
0 commit comments