Skip to content

Commit

Permalink
feat: add featureFlags param
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Nov 26, 2024
1 parent fd2a1e0 commit 778896f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func run(path string) {
result, err := interpreter.RunProgram(context.Background(), parseResult.Value, opt.Variables, interpreter.StaticStore{
Balances: opt.Balances,
Meta: opt.Meta,
})
}, nil)

Check warning on line 121 in internal/cmd/run.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/run.go#L121

Added line #L121 was not covered by tests

if err != nil {
rng := err.GetRange()
Expand Down
1 change: 1 addition & 0 deletions internal/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func RunProgram(
program parser.Program,
vars map[string]string,
store Store,
featureFlags map[string]struct{},
) (*ExecutionResult, InterpreterError) {
st := programState{
ParsedVars: make(map[string]Value),
Expand Down
2 changes: 1 addition & 1 deletion internal/interpreter/interpreter_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func matchErrWithSnapshots(t *testing.T, src string, vars map[string]string, runOpt interpreter.StaticStore) {
parsed := parser.Parse(src)
_, err := interpreter.RunProgram(context.Background(), parsed.Value, vars, runOpt)
_, err := interpreter.RunProgram(context.Background(), parsed.Value, vars, runOpt, nil)
require.NotNil(t, err)
snaps.MatchSnapshot(t, err.GetRange().ShowOnSource(parsed.Source))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func test(t *testing.T, testCase TestCase) {
execResult, err := machine.RunProgram(context.Background(), *prog, testCase.vars, machine.StaticStore{
testCase.balances,
testCase.meta,
})
}, nil)

expected := testCase.expected
if expected.Error != nil {
Expand Down
15 changes: 14 additions & 1 deletion numscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ type (
)

func (p ParseResult) Run(ctx context.Context, vars VariablesMap, store Store) (ExecutionResult, InterpreterError) {
res, err := interpreter.RunProgram(ctx, p.parseResult.Value, vars, store)
return p.RunWithFeatureFlags(ctx, vars, store, nil)
}

func (p ParseResult) RunWithFeatureFlags(
ctx context.Context,
vars VariablesMap,
store Store,
featureFlags map[string]struct{},
) (ExecutionResult, InterpreterError) {
if featureFlags == nil {
featureFlags = make(map[string]struct{})
}

res, err := interpreter.RunProgram(ctx, p.parseResult.Value, vars, store, featureFlags)
if err != nil {
return ExecutionResult{}, err
}
Expand Down

0 comments on commit 778896f

Please sign in to comment.