6040abc836
The vm does what it needs to do (evaluate the result of passing an input to an operatio, where the input and the operation themselves may have sub-inputs/operations to evaluate), with many caveats/misgivings.
30 lines
412 B
Go
30 lines
412 B
Go
package vm
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/mediocregopher/ginger/gg"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestVM(t *testing.T) {
|
|
|
|
src := `
|
|
incr = { out = add < (1; in;); };
|
|
|
|
out = incr < incr < in;
|
|
`
|
|
|
|
var in int64 = 5
|
|
|
|
val, err := EvaluateSource(
|
|
bytes.NewBufferString(src),
|
|
gg.Value{Number: &in},
|
|
GlobalScope,
|
|
)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, in+2, *val.Number)
|
|
}
|