VM improvements, tests + bugfixes (#61)

* changed vm commands to match more of the standard

* fixed Uint16 jmp bug in VM

* moved test to vm + fixed numnotequal bug

* fixed broken tests

* moved compiler tests to vm tests

* added basic for support + inc and dec stmts

* bumped version
This commit is contained in:
Anthony De Meulemeester 2018-04-02 17:04:42 +02:00 committed by GitHub
parent 931388b687
commit 69c3e645b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 521 additions and 159 deletions

View file

@ -170,7 +170,51 @@ func TestIteration(t *testing.T) {
}
func TestPushVal(t *testing.T) {
s := NewStack("test")
// integer
s.PushVal(2)
elem := s.Pop()
assert.Equal(t, int64(2), elem.BigInt().Int64())
// byteArray
s.PushVal([]byte("foo"))
elem = s.Pop()
assert.Equal(t, "foo", string(elem.Bytes()))
// boolean
s.PushVal(true)
elem = s.Pop()
assert.Equal(t, true, elem.Bool())
// array
s.PushVal([]StackItem{&BoolItem{true}, &BoolItem{false}, &BoolItem{true}})
elem = s.Pop()
assert.IsType(t, elem.value, &ArrayItem{})
}
func TestSwapElemValues(t *testing.T) {
s := NewStack("test")
s.PushVal(2)
s.PushVal(4)
a := s.Peek(0)
b := s.Peek(1)
// [ 4 ] -> a
// [ 2 ] -> b
aval := a.value
bval := b.value
a.value = bval
b.value = aval
// [ 2 ] -> a
// [ 4 ] -> b
assert.Equal(t, int64(2), s.Pop().BigInt().Int64())
assert.Equal(t, int64(4), s.Pop().BigInt().Int64())
}
func makeElements(n int) []*Element {