Improved code style

This commit is contained in:
Eduard Urbach 2025-01-30 22:23:38 +01:00
parent 162824ec1c
commit 313302b9c8
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
12 changed files with 17 additions and 22 deletions

View File

@ -6,8 +6,8 @@ import (
// MemoryLabel operates with a memory address and a number.
type MemoryLabel struct {
Address Memory
Label string
Address Memory
}
// String returns a human readable version.

View File

@ -1,7 +1,7 @@
package expression_test
import (
"fmt"
"errors"
"testing"
"git.akyoto.dev/cli/q/src/expression"
@ -110,14 +110,11 @@ func TestParse(t *testing.T) {
}
for _, test := range tests {
test := test
t.Run(test.Name, func(t *testing.T) {
src := []byte(test.Expression)
tokens := token.Tokenize(src)
expr := expression.Parse(tokens)
defer expr.Reset()
assert.NotNil(t, expr)
assert.Equal(t, expr.String(src), test.Result)
})
@ -150,7 +147,7 @@ func TestEachLeaf(t *testing.T) {
assert.DeepEqual(t, leaves, []string{"1", "2", "3", "4", "5", "6", "7", "8"})
err = expr.EachLeaf(func(leaf *expression.Expression) error {
return fmt.Errorf("error")
return errors.New("error")
})
assert.NotNil(t, err)

View File

@ -11,7 +11,7 @@ func BenchmarkExpression(b *testing.B) {
src := []byte("(1+2-3*4)+(5*6-7+8)")
tokens := token.Tokenize(src)
for i := 0; i < b.N; i++ {
for range b.N {
expression.Parse(tokens)
}
}

View File

@ -117,8 +117,8 @@ func Write(writer io.Writer, code []byte, data []byte) {
binary.Write(writer, binary.LittleEndian, &m.DataHeader)
binary.Write(writer, binary.LittleEndian, &m.UnixThread)
writer.Write(bytes.Repeat([]byte{0x00}, int(codePadding)))
writer.Write(bytes.Repeat([]byte{0x00}, codePadding))
writer.Write(code)
writer.Write(bytes.Repeat([]byte{0x00}, int(dataPadding)))
writer.Write(bytes.Repeat([]byte{0x00}, dataPadding))
writer.Write(data)
}

View File

@ -31,7 +31,7 @@ const (
IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002
IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004
IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008
IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010
IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010
IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020
IMAGE_FILE_BYTES_REVERSED_LO = 0x0080
IMAGE_FILE_32BIT_MACHINE = 0x0100

View File

@ -189,11 +189,11 @@ func Write(writer io.Writer, code []byte, data []byte, dlls dll.List) {
binary.Write(writer, binary.LittleEndian, &pe.OptionalHeader64)
binary.Write(writer, binary.LittleEndian, &pe.Sections)
writer.Write(bytes.Repeat([]byte{0x00}, int(codePadding)))
writer.Write(bytes.Repeat([]byte{0x00}, codePadding))
writer.Write(code)
writer.Write(bytes.Repeat([]byte{0x00}, int(dataPadding)))
writer.Write(bytes.Repeat([]byte{0x00}, dataPadding))
writer.Write(data)
writer.Write(bytes.Repeat([]byte{0x00}, int(importsPadding)))
writer.Write(bytes.Repeat([]byte{0x00}, importsPadding))
binary.Write(writer, binary.LittleEndian, &imports)
binary.Write(writer, binary.LittleEndian, &dllData)
binary.Write(writer, binary.LittleEndian, &dllImports)

View File

@ -5,7 +5,7 @@ func Count(tokens []Token, buffer []byte, kind Kind, name string) uint8 {
count := uint8(0)
for _, t := range tokens {
if t.Kind == Identifier && t.Text(buffer) == name {
if t.Kind == kind && t.Text(buffer) == name {
count++
}
}

View File

@ -1,7 +1,7 @@
package token_test
import (
"fmt"
"errors"
"testing"
"git.akyoto.dev/cli/q/src/token"
@ -32,7 +32,7 @@ func TestSplit(t *testing.T) {
assert.DeepEqual(t, parameters, []string{"1+2", "3*4", "5*6", "7+8"})
err = tokens.Split(func(parameter token.List) error {
return fmt.Errorf("error")
return errors.New("error")
})
assert.NotNil(t, err)

View File

@ -19,7 +19,7 @@ func bench(n int) func(b *testing.B) {
return func(b *testing.B) {
input := bytes.Repeat(line, n)
for i := 0; i < b.N; i++ {
for range b.N {
token.Tokenize(input)
}
}

View File

@ -18,9 +18,7 @@ func memoryAccessDynamic(code []byte, opCode8 byte, opCode32 byte, destination c
}
if offset == RSP {
tmp := offset
offset = destination
destination = tmp
offset, destination = destination, offset
}
if numBytes == 8 {

View File

@ -48,7 +48,7 @@ func BenchmarkExamples(b *testing.B) {
b.Run(test.Name, func(b *testing.B) {
compiler := build.New(filepath.Join("..", "examples", test.Name))
for i := 0; i < b.N; i++ {
for range b.N {
_, err := compiler.Run()
assert.Nil(b, err)
}

View File

@ -82,7 +82,7 @@ func BenchmarkPrograms(b *testing.B) {
b.Run(test.Name, func(b *testing.B) {
compiler := build.New(filepath.Join("programs", test.Name+".q"))
for i := 0; i < b.N; i++ {
for range b.N {
_, err := compiler.Run()
assert.Nil(b, err)
}