mirror of
https://github.com/hanzoai/numscript.git
synced 2026-10-30 18:26:57 +00:00
* feat: feature flag syntax * feat: change syntax * feat: reject invalid features * feat: add static check of unknown features * feat: more defensive args handling * fix: fix typo
99 lines
1.9 KiB
Go
99 lines
1.9 KiB
Go
package parser_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/formancehq/numscript/internal/parser"
|
|
|
|
"github.com/gkampitakis/go-snaps/snaps"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFaultToleranceVarName(t *testing.T) {
|
|
p := parser.Parse(`vars { monetary 42 }`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
assert.NotEmpty(t, p.Errors)
|
|
}
|
|
|
|
func TestFaultToleranceSend(t *testing.T) {
|
|
p := parser.Parse(`send `)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceMonetary(t *testing.T) {
|
|
p := parser.Parse(`send [COIN]`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceNoAddr(t *testing.T) {
|
|
p := parser.Parse(`send (
|
|
source = {
|
|
@
|
|
}
|
|
destination = @
|
|
)`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceInvalidDest(t *testing.T) {
|
|
p := parser.Parse(`send [COIN 10] (
|
|
source = @a
|
|
destination =
|
|
)`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceInvalidSrcTk(t *testing.T) {
|
|
p := parser.Parse(`send [COIN 10] (
|
|
source = max
|
|
destination = @d
|
|
)`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceTrailingComma(t *testing.T) {
|
|
p := parser.Parse(`set_tx_meta(1, )`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceDestinationNoRemainingMispelledFrom(t *testing.T) {
|
|
p := parser.Parse(`send [COIN 10] (
|
|
source = @a
|
|
destination = {
|
|
max [COIN 10] from @x
|
|
}
|
|
)
|
|
`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceIncompleteOrigin(t *testing.T) {
|
|
p := parser.Parse(`
|
|
vars {
|
|
asset $a =
|
|
}
|
|
`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceIncompleteSave(t *testing.T) {
|
|
p := parser.Parse(`
|
|
save
|
|
`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceIncompleteSave2(t *testing.T) {
|
|
p := parser.Parse(`
|
|
save [COIN 10]
|
|
`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|
|
|
|
func TestFaultToleranceIncompleteSave3(t *testing.T) {
|
|
p := parser.Parse(`
|
|
save [COIN 10] from
|
|
`)
|
|
snaps.MatchSnapshot(t, p.Value)
|
|
}
|