Added more tests

This commit is contained in:
Eduard Urbach 2024-06-04 15:51:31 +02:00
parent 8974b8b0aa
commit 453b4d8956
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
5 changed files with 42 additions and 33 deletions

View File

@ -1,19 +0,0 @@
import sys
main() {
let f = fibonacci(11)
sys.exit(f)
}
fibonacci(n Int) -> Int {
mut b = 0
mut c = 1
for 0..n {
let a = b
b = c
c = a + b
}
return b
}

View File

@ -5,7 +5,8 @@ import "bytes"
// Data represents the static read-only data.
type Data []byte
// Add adds the given bytes to the data block and returns the address relative to the start of the data section.
// Add adds the given bytes to the data block if this sequence of bytes doesn't exist yet.
// It returns the address relative to the start of the data section.
func (data *Data) Add(block []byte) Address {
position := bytes.Index(*data, block)

View File

@ -1,6 +1,7 @@
package main_test
package cli_test
import (
"fmt"
"io"
"os"
"testing"
@ -27,23 +28,17 @@ func TestCLI(t *testing.T) {
{[]string{"invalid"}, 2},
{[]string{"system"}, 0},
{[]string{"build", "non-existing-directory"}, 1},
{[]string{"build", "examples/hello/hello.q"}, 1},
{[]string{"build", "examples/hello", "--invalid"}, 2},
{[]string{"build", "examples/hello", "--dry"}, 0},
{[]string{"build", "examples/hello", "--dry", "--verbose"}, 0},
{[]string{"build", "../../examples/hello/hello.q"}, 1},
{[]string{"build", "../../examples/hello", "--invalid"}, 2},
{[]string{"build", "../../examples/hello", "--dry"}, 0},
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
}
for _, test := range tests {
t.Log(test.arguments)
directory, _ := os.Getwd()
fmt.Println(directory)
exitCode := cli.Main(test.arguments)
assert.Equal(t, exitCode, test.expectedExitCode)
}
}
func BenchmarkBuild(b *testing.B) {
args := []string{"build", "examples/hello", "--dry"}
for i := 0; i < b.N; i++ {
cli.Main(args)
}
}

View File

@ -0,0 +1,19 @@
package directory_test
import (
"testing"
"git.akyoto.dev/cli/q/src/directory"
"git.akyoto.dev/go/assert"
)
func TestWalk(t *testing.T) {
var files []string
directory.Walk(".", func(file string) {
files = append(files, file)
})
assert.Contains(t, files, "Walk.go")
assert.Contains(t, files, "Walk_test.go")
}

13
src/elf/ELF_test.go Normal file
View File

@ -0,0 +1,13 @@
package elf_test
import (
"io"
"testing"
"git.akyoto.dev/cli/q/src/elf"
)
func TestELF(t *testing.T) {
exe := elf.New(nil, nil)
exe.Write(io.Discard)
}