fspl/compiler/compiler_test.go

178 lines
3.4 KiB
Go
Raw Normal View History

2024-02-26 18:46:30 +00:00
package compiler
import "testing"
import "runtime"
var nativeLineBreak = "\n"
func init () {
if runtime.GOOS == "windows" {
nativeLineBreak = "\r\n"
}
}
2024-02-26 18:46:30 +00:00
func TestHelloWorld (test *testing.T) {
testUnit (test,
"/test-data/data/hello", nil,
"", "Hello, world!" + nativeLineBreak,
2024-02-26 18:46:30 +00:00
0,
)}
2024-02-26 19:03:10 +00:00
func TestPuts (test *testing.T) {
testUnit (test,
"/test-data/data/puts", nil,
"", "hello" + nativeLineBreak,
0,
)}
2024-02-26 19:03:10 +00:00
func TestExitCode13 (test *testing.T) {
testUnit (test,
"/test-data/data/exit-code-13", nil,
2024-02-26 19:03:10 +00:00
"", "",
13,
)}
func TestSystemInclude (test *testing.T) {
testUnit (test,
"/test-data/data/system-include", nil,
"", "Hello, /usr/include!" + nativeLineBreak,
0,
)}
func TestSystemSrc (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/system-src", dependencies,
"", "Hello, /usr/src!" + nativeLineBreak,
0,
)}
2024-02-27 05:08:36 +00:00
func TestArgC (test *testing.T) {
testUnit (test,
"/test-data/data/argc", nil,
"", "",
2, "arg1", "arg2",
)}
// TODO: uncomment once #47 has been dealt with
// func TestArgV (test *testing.T) {
// testUnit (test,
// "/test-data/data/argv", nil,
// "", "This is an argument\n",
// 0, "This is an argument",
// )}
2024-02-27 07:36:21 +00:00
func TestSimpleInterface (test *testing.T) {
testUnit (test,
"/test-data/data/simple-interface", nil,
2024-02-27 07:36:21 +00:00
"", "",
9,
)}
func TestWriterInterface (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/writer", dependencies,
"", "well hello their" + nativeLineBreak,
2024-02-27 07:36:21 +00:00
0,
)}
2024-03-06 20:06:21 +00:00
func TestMatchExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/match-exit-code", nil,
2024-03-06 20:06:21 +00:00
"", "",
7,
)}
func TestMatchPrint (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/match-print", dependencies,
"", "F64" + nativeLineBreak,
2024-03-06 20:06:21 +00:00
0,
)}
2024-03-06 22:41:52 +00:00
2024-03-26 02:34:24 +00:00
func TestMatchDefaultPrint (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/match-default-print", dependencies,
"", "something else" + nativeLineBreak,
2024-03-26 02:34:24 +00:00
0,
)}
2024-03-26 04:42:27 +00:00
func TestSwitchExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/switch-exit-code", nil,
"", "",
4,
)}
2024-03-06 22:41:52 +00:00
func TestReturnAssign (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/return-assign", dependencies,
"", "false" + nativeLineBreak,
2024-03-06 22:41:52 +00:00
0,
)}
2024-03-20 15:35:14 +00:00
func TestLoopBreakExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/loop-break-exit-code", nil,
"", "",
5,
)}
func TestLoopBreakBranchExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/loop-break-branch-exit-code", nil,
"", "",
2,
)}
2024-03-20 16:38:46 +00:00
func TestForSimple (test *testing.T) {
testUnit (test,
"/test-data/data/for-simple", nil,
"", "",
0,
)}
2024-03-20 15:35:14 +00:00
func TestForStringArray (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/for-string-array", dependencies,
"", "a" + nativeLineBreak + "b" + nativeLineBreak + "c" + nativeLineBreak +
"a" + nativeLineBreak + "b" + nativeLineBreak + "c" + nativeLineBreak,
2024-03-20 15:35:14 +00:00
0,
)}
2024-03-24 07:09:33 +00:00
func TestForStringArrayOnce (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/for-string-array-once", dependencies,
"", "abc" + nativeLineBreak,
2024-03-24 07:09:33 +00:00
0,
)}
func TestForBreakBranch (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/for-break-branch", dependencies,
"", "iter" + nativeLineBreak + "iter" + nativeLineBreak,
2024-03-24 07:09:33 +00:00
0,
)}