Added more tests
This commit is contained in:
parent
8974b8b0aa
commit
453b4d8956
@ -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
|
|
||||||
}
|
|
@ -5,7 +5,8 @@ import "bytes"
|
|||||||
// Data represents the static read-only data.
|
// Data represents the static read-only data.
|
||||||
type Data []byte
|
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 {
|
func (data *Data) Add(block []byte) Address {
|
||||||
position := bytes.Index(*data, block)
|
position := bytes.Index(*data, block)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -27,23 +28,17 @@ func TestCLI(t *testing.T) {
|
|||||||
{[]string{"invalid"}, 2},
|
{[]string{"invalid"}, 2},
|
||||||
{[]string{"system"}, 0},
|
{[]string{"system"}, 0},
|
||||||
{[]string{"build", "non-existing-directory"}, 1},
|
{[]string{"build", "non-existing-directory"}, 1},
|
||||||
{[]string{"build", "examples/hello/hello.q"}, 1},
|
{[]string{"build", "../../examples/hello/hello.q"}, 1},
|
||||||
{[]string{"build", "examples/hello", "--invalid"}, 2},
|
{[]string{"build", "../../examples/hello", "--invalid"}, 2},
|
||||||
{[]string{"build", "examples/hello", "--dry"}, 0},
|
{[]string{"build", "../../examples/hello", "--dry"}, 0},
|
||||||
{[]string{"build", "examples/hello", "--dry", "--verbose"}, 0},
|
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Log(test.arguments)
|
t.Log(test.arguments)
|
||||||
|
directory, _ := os.Getwd()
|
||||||
|
fmt.Println(directory)
|
||||||
exitCode := cli.Main(test.arguments)
|
exitCode := cli.Main(test.arguments)
|
||||||
assert.Equal(t, exitCode, test.expectedExitCode)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
19
src/directory/Walk_test.go
Normal file
19
src/directory/Walk_test.go
Normal 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
13
src/elf/ELF_test.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user