2021-12-28 20:18:01 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mediocregopher/ginger/gg"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestVM(t *testing.T) {
|
|
|
|
|
2023-10-21 15:42:31 +00:00
|
|
|
src := `{
|
|
|
|
incr = { out = add < (1, in); };
|
2021-12-28 20:18:01 +00:00
|
|
|
|
|
|
|
out = incr < incr < in;
|
2023-10-21 15:42:31 +00:00
|
|
|
}`
|
2021-12-28 20:18:01 +00:00
|
|
|
|
|
|
|
var in int64 = 5
|
|
|
|
|
|
|
|
val, err := EvaluateSource(
|
|
|
|
bytes.NewBufferString(src),
|
2022-03-31 15:18:02 +00:00
|
|
|
Value{Value: gg.Number(in)},
|
2021-12-28 20:18:01 +00:00
|
|
|
GlobalScope,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, in+2, *val.Number)
|
|
|
|
}
|