44 lines
856 B
Go
Raw Normal View History

2024-07-03 09:39:24 +00:00
package tests_test
import (
"path/filepath"
"testing"
"git.akyoto.dev/cli/q/src/build"
"git.akyoto.dev/go/assert"
2024-07-03 09:39:24 +00:00
)
2024-07-03 09:59:36 +00:00
var examples = []struct {
2024-07-18 19:10:27 +00:00
Name string
Input string
Output string
ExitCode int
2024-07-03 09:59:36 +00:00
}{
2024-07-18 19:10:27 +00:00
{"hello", "", "Hello", 0},
{"factorial", "", "", 120},
{"fibonacci", "", "", 55},
2024-07-22 13:32:16 +00:00
{"array", "", "Hello", 0},
2024-07-26 10:50:47 +00:00
{"itoa", "", "2147483647", 0},
2024-07-03 09:59:36 +00:00
}
2024-07-03 09:39:24 +00:00
2024-07-03 09:59:36 +00:00
func TestExamples(t *testing.T) {
for _, test := range examples {
2024-07-03 09:39:24 +00:00
t.Run(test.Name, func(t *testing.T) {
2024-07-18 19:10:27 +00:00
run(t, filepath.Join("..", "examples", test.Name), test.Input, test.Output, test.ExitCode)
2024-07-03 09:39:24 +00:00
})
}
}
func BenchmarkExamples(b *testing.B) {
for _, test := range examples {
b.Run(test.Name, func(b *testing.B) {
compiler := build.New(filepath.Join("..", "examples", test.Name))
for i := 0; i < b.N; i++ {
_, err := compiler.Run()
assert.Nil(b, err)
}
})
}
}