Files
zeekayandClaude Opus 5 2c2f0e6bf3 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers, and the interpreter's parseArg, evaluateExprAs and
evaluateOptExprAs are now generic methods on the parser and program state
they take. omitzero is not applied, since it changes what the JSON says.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-09-16 19:52:45 -07:00

70 lines
1.3 KiB
Go

package interpreter
import (
"math/big"
"testing"
"github.com/formancehq/numscript/internal/parser"
"github.com/stretchr/testify/require"
)
func TestParseEmptyArgsValidArity(t *testing.T) {
t.Parallel()
p := NewArgsParser([]Value{})
err := p.parse()
require.Nil(t, err)
}
func TestParseInvalidArity(t *testing.T) {
t.Parallel()
p := NewArgsParser([]Value{})
p.parseArg(parser.Range{}, expectAccount)
p.parseArg(parser.Range{}, expectAsset)
err := p.parse()
require.Equal(t, err, BadArityErr{
ExpectedArity: 2,
GivenArguments: 0,
})
}
func TestParseValid(t *testing.T) {
t.Parallel()
p := NewArgsParser([]Value{
NewMonetaryInt(42),
AccountAddress("user:001"),
})
a1 := p.parseArg(parser.Range{}, expectNumber)
a2 := p.parseArg(parser.Range{}, expectAccount)
err := p.parse()
require.Nil(t, err)
require.NotNil(t, a1, "a1 should not be nil")
require.NotNil(t, a2, "a2 should not be nil")
require.Equal(t, *a1, *big.NewInt(42))
require.Equal(t, *a2, "user:001")
}
func TestParseBadType(t *testing.T) {
t.Parallel()
p := NewArgsParser([]Value{
NewMonetaryInt(42),
AccountAddress("user:001"),
})
p.parseArg(parser.Range{}, expectMonetary)
p.parseArg(parser.Range{}, expectAccount)
err := p.parse()
require.Equal(t, err, TypeError{
Expected: "monetary",
Value: NewMonetaryInt(42),
})
}