minor lint fixes (#182)
This commit is contained in:
parent
3eebecb2a4
commit
719e269cb1
10 changed files with 17 additions and 31 deletions
|
@ -106,7 +106,7 @@ func Equal(t *testing.T, expected, actual interface{}, msg ...interface{}) bool
|
|||
return failExpectedActual(t, expected, actual, msg...)
|
||||
}
|
||||
case []byte:
|
||||
if bytes.Compare(expected, actual.([]byte)) != 0 {
|
||||
if !bytes.Equal(expected, actual.([]byte)) {
|
||||
return failExpectedActual(t, string(expected), string(actual.([]byte)), msg...)
|
||||
}
|
||||
case []string:
|
||||
|
@ -156,7 +156,7 @@ func Equal(t *testing.T, expected, actual interface{}, msg ...interface{}) bool
|
|||
case *objects.ImmutableArray:
|
||||
return equalObjectSlice(t, expected.Value, actual.(*objects.ImmutableArray).Value, msg...)
|
||||
case *objects.Bytes:
|
||||
if bytes.Compare(expected.Value, actual.(*objects.Bytes).Value) != 0 {
|
||||
if !bytes.Equal(expected.Value, actual.(*objects.Bytes).Value) {
|
||||
return failExpectedActual(t, string(expected.Value), string(actual.(*objects.Bytes).Value), msg...)
|
||||
}
|
||||
case *objects.Map:
|
||||
|
|
|
@ -13,7 +13,7 @@ func MakeInstruction(opcode Opcode, operands ...int) []byte {
|
|||
totalLen += w
|
||||
}
|
||||
|
||||
instruction := make([]byte, totalLen, totalLen)
|
||||
instruction := make([]byte, totalLen)
|
||||
instruction[0] = byte(opcode)
|
||||
|
||||
offset := 1
|
||||
|
|
|
@ -6,7 +6,7 @@ type SymbolScope string
|
|||
// List of symbol scopes
|
||||
const (
|
||||
ScopeGlobal SymbolScope = "GLOBAL"
|
||||
ScopeLocal = "LOCAL"
|
||||
ScopeBuiltin = "BUILTIN"
|
||||
ScopeFree = "FREE"
|
||||
ScopeLocal SymbolScope = "LOCAL"
|
||||
ScopeBuiltin SymbolScope = "BUILTIN"
|
||||
ScopeFree SymbolScope = "FREE"
|
||||
)
|
||||
|
|
|
@ -57,7 +57,7 @@ func (o *Bytes) Equals(x Object) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return bytes.Compare(o.Value, t.Value) == 0
|
||||
return bytes.Equal(o.Value, t.Value)
|
||||
}
|
||||
|
||||
// IndexGet returns an element (as Int) at a given index.
|
||||
|
|
|
@ -254,7 +254,7 @@ func FromInterface(v interface{}) (Object, error) {
|
|||
case []Object:
|
||||
return &Array{Value: v}, nil
|
||||
case []interface{}:
|
||||
arr := make([]Object, len(v), len(v))
|
||||
arr := make([]Object, len(v))
|
||||
for i, e := range v {
|
||||
vo, err := FromInterface(e)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,8 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func TestObject_TypeName(t *testing.T) {
|
||||
var o objects.Object
|
||||
o = &objects.Int{}
|
||||
var o objects.Object = &objects.Int{}
|
||||
assert.Equal(t, "int", o.TypeName())
|
||||
o = &objects.Float{}
|
||||
assert.Equal(t, "float", o.TypeName())
|
||||
|
@ -47,8 +46,7 @@ func TestObject_TypeName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestObject_IsFalsy(t *testing.T) {
|
||||
var o objects.Object
|
||||
o = &objects.Int{Value: 0}
|
||||
var o objects.Object = &objects.Int{Value: 0}
|
||||
assert.True(t, o.IsFalsy())
|
||||
o = &objects.Int{Value: 1}
|
||||
assert.False(t, o.IsFalsy())
|
||||
|
@ -95,8 +93,7 @@ func TestObject_IsFalsy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestObject_String(t *testing.T) {
|
||||
var o objects.Object
|
||||
o = &objects.Int{Value: 0}
|
||||
var o objects.Object = &objects.Int{Value: 0}
|
||||
assert.Equal(t, "0", o.String())
|
||||
o = &objects.Int{Value: 1}
|
||||
assert.Equal(t, "1", o.String())
|
||||
|
@ -135,8 +132,7 @@ func TestObject_String(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestObject_BinaryOp(t *testing.T) {
|
||||
var o objects.Object
|
||||
o = &objects.Char{}
|
||||
var o objects.Object = &objects.Char{}
|
||||
_, err := o.BinaryOp(token.Add, objects.UndefinedValue)
|
||||
assert.Error(t, err)
|
||||
o = &objects.Bool{}
|
||||
|
|
|
@ -707,9 +707,7 @@ func (v *VM) run() {
|
|||
|
||||
case objects.Callable:
|
||||
var args []objects.Object
|
||||
for _, arg := range v.stack[v.sp-numArgs : v.sp] {
|
||||
args = append(args, arg)
|
||||
}
|
||||
args = append(args, v.stack[v.sp-numArgs:v.sp]...)
|
||||
|
||||
ret, e := callee.Call(args...)
|
||||
v.sp -= numArgs + 1
|
||||
|
|
|
@ -183,12 +183,3 @@ func (s *Script) prepCompile() (symbolTable *compiler.SymbolTable, globals []obj
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Script) copyVariables() map[string]*Variable {
|
||||
vars := make(map[string]*Variable)
|
||||
for n, v := range s.variables {
|
||||
vars[n] = v
|
||||
}
|
||||
|
||||
return vars
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func fmtPrintf(args ...objects.Object) (ret objects.Object, err error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
formatArgs := make([]interface{}, numArgs-1, numArgs-1)
|
||||
formatArgs := make([]interface{}, numArgs-1)
|
||||
for idx, arg := range args[1:] {
|
||||
switch arg := arg.(type) {
|
||||
case *objects.Int, *objects.Float, *objects.Bool, *objects.Char, *objects.String, *objects.Bytes:
|
||||
|
@ -89,7 +89,7 @@ func fmtSprintf(args ...objects.Object) (ret objects.Object, err error) {
|
|||
return format, nil // okay to return 'format' directly as String is immutable
|
||||
}
|
||||
|
||||
formatArgs := make([]interface{}, numArgs-1, numArgs-1)
|
||||
formatArgs := make([]interface{}, numArgs-1)
|
||||
for idx, arg := range args[1:] {
|
||||
switch arg := arg.(type) {
|
||||
case *objects.Int, *objects.Float, *objects.Bool, *objects.Char, *objects.String, *objects.Bytes:
|
||||
|
|
|
@ -30,7 +30,8 @@ func TestTimes(t *testing.T) {
|
|||
module(t, "times").call("month_string", 12).expect("December")
|
||||
|
||||
module(t, "times").call("date", 1982, 9, 28, 19, 21, 44, 999).expect(time1)
|
||||
assert.True(t, module(t, "times").call("now").o.(*objects.Time).Value.Sub(time.Now()).Nanoseconds() < 100000000) // within 100ms
|
||||
nowD := time.Until(module(t, "times").call("now").o.(*objects.Time).Value).Nanoseconds()
|
||||
assert.True(t, 0 > nowD && nowD > -100000000) // within 100ms
|
||||
parsed, _ := time.Parse(time.RFC3339, "1982-09-28T19:21:44+07:00")
|
||||
module(t, "times").call("parse", time.RFC3339, "1982-09-28T19:21:44+07:00").expect(parsed)
|
||||
module(t, "times").call("unix", 1234325, 94493).expect(time.Unix(1234325, 94493))
|
||||
|
|
Loading…
Reference in a new issue