Added more tests
This commit is contained in:
parent
1d50720c28
commit
feacc27f49
@ -26,9 +26,8 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
||||
}
|
||||
|
||||
s.files <- file
|
||||
i := 0
|
||||
|
||||
for i < len(tokens) {
|
||||
for i := 0; i < len(tokens); i++ {
|
||||
switch tokens[i].Kind {
|
||||
case token.NewLine:
|
||||
case token.Comment:
|
||||
@ -49,8 +48,6 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
return nil
|
||||
|
55
src/types/types_test.go
Normal file
55
src/types/types_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/types"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
assert.Equal(t, types.Int.Name(), "Int64")
|
||||
assert.Equal(t, types.PointerAny.Name(), "Pointer")
|
||||
assert.Equal(t, (&types.Pointer{To: types.Int}).Name(), "Pointer:Int64")
|
||||
}
|
||||
|
||||
func TestSize(t *testing.T) {
|
||||
assert.Equal(t, types.Int.Size(), 8)
|
||||
assert.Equal(t, types.Int8.Size(), 1)
|
||||
assert.Equal(t, types.Int16.Size(), 2)
|
||||
assert.Equal(t, types.Int32.Size(), 4)
|
||||
assert.Equal(t, types.Int64.Size(), 8)
|
||||
assert.Equal(t, types.PointerAny.Size(), 8)
|
||||
assert.Equal(t, (&types.Pointer{To: types.Int}).Size(), 8)
|
||||
}
|
||||
|
||||
func TestStruct(t *testing.T) {
|
||||
s := types.NewStruct("Test")
|
||||
assert.Equal(t, s.Name(), "Test")
|
||||
assert.Equal(t, s.Size(), 0)
|
||||
field := &types.Field{Name: "TestField", TypeName: "Int8"}
|
||||
s.AddField(field)
|
||||
s.Update(map[string]types.Type{"Int8": types.Int8})
|
||||
assert.Equal(t, s.Size(), 1)
|
||||
assert.Equal(t, s.FieldByName("TestField"), field)
|
||||
assert.Nil(t, s.FieldByName("does-not-exist"))
|
||||
}
|
||||
|
||||
func TestBasics(t *testing.T) {
|
||||
assert.True(t, types.Is(types.Int, types.Int))
|
||||
assert.True(t, types.Is(types.PointerAny, types.PointerAny))
|
||||
assert.False(t, types.Is(types.Int, types.Float))
|
||||
assert.False(t, types.Is(&types.Pointer{To: types.Int}, &types.Pointer{To: types.Float}))
|
||||
}
|
||||
|
||||
func TestSpecialCases(t *testing.T) {
|
||||
// Case #1:
|
||||
// For syscalls whose return type is `nil` we currently allow casting them to anything.
|
||||
assert.True(t, types.Is(nil, types.Int))
|
||||
assert.True(t, types.Is(nil, types.Float))
|
||||
|
||||
// Case #2:
|
||||
// A pointer pointing to a known type fulfills the requirement of a pointer to anything.
|
||||
assert.True(t, types.Is(&types.Pointer{To: types.Int}, &types.Pointer{To: nil}))
|
||||
assert.True(t, types.Is(&types.Pointer{To: types.Float}, &types.Pointer{To: nil}))
|
||||
}
|
@ -7,7 +7,7 @@ import (
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestX64(t *testing.T) {
|
||||
func TestX86(t *testing.T) {
|
||||
assert.DeepEqual(t, x86.AlignStack(nil), []byte{0x48, 0x83, 0xE4, 0xF0})
|
||||
assert.DeepEqual(t, x86.Call(nil, 1), []byte{0xE8, 0x01, 0x00, 0x00, 0x00})
|
||||
assert.DeepEqual(t, x86.CallAtAddress(nil, 1), []byte{0xFF, 0x15, 0x01, 0x00, 0x00, 0x00})
|
Loading…
x
Reference in New Issue
Block a user